Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

@sbcohen/ragged-blocks

Latest version: v0.4.0

Overview

Last scanned
30 Nov 2026
Published
30 Nov 2026
npm package Publisher: sbcohen
4 Versions
652 Downloads

Scan summary

@sbcohen/ragged-blocks was last scanned on 30 Nov 2026 at version 0.4.0. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 4 versions; the latest was published on 30 Nov 2026.
  • Findings: No rules fired in version 0.4.0.
  • Downloads: 652 downloads.

Versions

4 versions published
Versions and the rules that fired in each
VersionPublishedStatus
0.4.0 LATEST 30 Nov 2026 No rules fired
0.3.1 16 Nov 2026 No rules fired
0.3.0 16 Nov 2026 No rules fired
0.2.0 12 Nov 2026 Not shown

No rules fired in 0.4.0

Findings

Findings for v0.4.0. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 0.4.0; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

Ragged Blocks

This library is a re-write of this one which is designed to be far simpler and faster. The fundamental ideas of the implementation are discussed in Ragged Blocks1, however the implementation itself is closer to the one described in the appendix of Retrofitting Text Editors with Ragged Blocks2.

Usage

This library has two parts; a layout algorithm which is invoked by calls to layout, and a renderer which takes layout's results and renders them to a canvas rendering context.

Layout

The signature of the layout function is as follows:

export function layout<X extends Ann>(
  layoutTree: LayoutTree<WithMeasurements<X>>,
  settings: LayoutSettings
): Layout<WithMeasurements<X>, WithPositionedBoxes<X>> {
  ...
}

Several things about this signature probably deserve some explanation.

We might start with a simplified signature, introducing the hidden parts as they become relevant. Consider the following, which captures the essential idea of the layout function:

export function layout<_>(
  layoutTree: LayoutTree<_>,
  settings: LayoutSettings
): Layout<_, _> {
  ...
}

layout takes a LayoutTree, which is a tree of nodes describing the content and structure of the document to be laid out. As opposed to an ordinary text layout algorithm, which might take as input a list of strings, to encode the hierarchical structure of the text, we need a tree. We will start with a simplified definition of LayoutTrees:

export type LayoutTree<_> = Newline<_> | Atom<_> | Node<_>;

export type Node<_> = {
  type: "Node";
  sty?: Partial<NodeStyle>;
  children: LayoutTree<_>[];
};

export type Atom<_> = {
  type: "Atom";
  isSpacer: boolean;
};

export type Newline<_> = {
  type: "Newline";
};

It describes a rose tree where leaves are either Atoms or Newlines, and internal Nodes are represented with the Node constructor. The Nodes contain their children and a NodeStyle, which describes the border decorations---like padding---of the node. The Atoms are meant to describe fragments of text, while the Newlines indicate where the layout should wrap onto the next line (note that newlines within an Atom will have no effect, and must be explicitly written with Newline constructors).

However, looking at the definition of Atom, you may notice that there is nowhere to put the text! As written, the tree would seem to encode structure, but not content. The description of this content is the purpose of the type parameter which is elided in the above definition. It describes an annotation which can be attached to each node. In the case of an Atom, the real definition looks like:

export type Atom<X extends Ann = Ann> = {
  type: "Atom";
  isSpacer: boolean;
} & X["Atom"];

X is an object with one key for each kind of constructor. X["Atom"] is an object with additional properties which will be attached to each Atom (and X["Node"] are properties that appear in each Node, and so on). For example, in layout, each node is expected to be annotated WithMeasurements, which is defined as follows:

export type WithMeasurements<X = {}> = {
  Newline: {};
  Atom: { box: Box };
  Node: {};
} & X;

Hence, the type of Atom as expected by layout is actually something like:

export type Atom = {
  type: "Atom";
  isSpacer: boolean;
  box: Box;
};

In fact, the layout algorithm does not require that Atoms contain any text, only that they be annotated with a Box, which is a datatype that describes a width, height, and baseline.

The baseline of a box determines how it will connect to adjacent boxes: the baselines will be lined up so that all boxes on a line share the same baseline. The baseline also coincides with the "origin" of a box, which is always at the left edge.

At various points in the algorithm, our LayoutTrees will be annotated with different kinds of things, so it is useful to be able to talk about annotations explicitly. Though it makes our types a little more verbose, it means we don't need to re-define LayoutTree for every stage of the layout algorithm, and perhaps more importantly, it allows the library client to stuff their own information into the LayoutTree which will be carried-through layout.

At this point the following signature for layoutshould make sense:

export function layout<_>(
  layoutTree: LayoutTree<WithMeasurements<_>>,
  settings: LayoutSettings
): Layout<_, _> {
  ...
}

That is, the input to layout is a LayoutTree where each Atom has been annotated with its box.

The result of layout is effectively a 2D array whose elements represent the rows of the layout, each row containing the positions of the laid-out atoms. layout effectively erases the structure of the input layoutTree, flattening it into a 2D array whose elements now have positions. This Layout has some annotations of its own. For now, let's ignore the first annotation and focus on the second.

Here are simplified definitions for a Layout which ignore the first type parameter:

type Layout<_, Y extends Ann> = Line<X, Y>[];

interface Line<_, Y extends Ann> {
  leading: number;
  topPadding: number;
  contentHeight: number;
  region: Region<X, Y>;
}

type Region<_, Y extends Ann> = Stack<_, Y>[];

export interface Stack<_, Y extends Ann> {
  cells: Cell<_> | null;
  atom: Atom<Y>;
  leftPadding?: [number, number];
}

In other words, a Layout is a list of Lines, a Line is a list of Stacks (plus some metadata), and a Stack contains an Atom (plus some more metadata). These Atoms correspond to the same Atom leaves in the input LayoutTree, except they are annotated differently. Looking at the full type for layout, we can see that they are annotated WithPositionedBoxes, which, as the name suggests, is a Box which also has a position in addition to its size and baseline location.

Now we can understand most of the important parts of the signature for layout:

export function layout<_>(
  layoutTree: LayoutTree<WithMeasurements<_>>,
  settings: LayoutSettings
): Layout<_, WithPositionedBoxes<_>> {
  ...
}

However, Layout contains one additional type parameter. This first parameter is used in the cells of a Stack and records the same annotation as the input layoutTree. That is because the output Layout, in addition to containing the positioned, flattened boxes, contains references to the original nodes in the layout tree above each laid-out box. This additional information is necessary for rendering, and is useful in connecting elements of the layout back to the input tree when, for example, hit testing.

We can now almost understand the full type annotation. The last missing piece is that layout is generic in the type variable X, which stands in for an arbitrary annotation. This permits the client to specify their own annotation which will be passed through the layout algorithm and appear in the final layout.

For example, imagine that the client wanted to annotate each Atom in the layout tree with a magic: number, and each Node with a interesting: boolean. They might write the following definition which specifies the annotation:

type MyAnnotation<X = {}> = {
  Newline: {};
  Atom: { magic: number };
  Node: { interesting: boolean };
} & X;

and instantiate layout as follows (substituting X for MyAnnotation):

export function layout(
  layoutTree: LayoutTree<WithMeasurements<MyAnnotation>>,
  settings: LayoutSettings
): Layout<WithMeasurements<MyAnnotation>, WithPositionedBoxes<MyAnnotation>> {
  ...
}

Running layout results in a Layout where each Stack has an Atom which not only contains its position, but a magic number. Furthermore, the Cells inside a Stack contain references to the input LayoutTree, in which Atoms are annotated with magic numbers and Nodes are annotated with interesting booleans.

Rendering

For many applications, it may not be necessary to use the library's rendering faculties, but they are included as a useful debugging aid, and as a reference for writing more complex renderers.

Let's look at the type signature of the function we can use to render layouts:

export function renderToCanvasRenderingContext2D<X extends Ann, Y extends Ann>(
  ctx: CanvasRenderingContext2D,
  layout: Layout<X, WithText<WithPositionedBoxes<Y>>>,
  settings: Partial<RenderingSettings> = {},
) {
  ...
}

It expects a canvas rendering context from the canvas on which the layout will be drawn, the layout, and some rendering settings. Note that the Layout, though it places no constraints on the referenced layout tree, requires that the cells be annotated WithText, since the rendering function can render the text directly, if desired. This is most easily achieved by annotating the atoms with text prior to layout, the text being passed through. (See examples/simple/index.ts for an example of this.) Note that the text property on each atom can be set to null if text rendering is not desired.

Besides rendering views of the layouts, the code in render.ts is potentially informative of how to manipulate the ragged blocks data structures.

Examples

There is an example of how the library can be used in examples/simple/index.ts, which demonstrates how the HTML of a document can be synchronized with a ragged blocks layout. It produces the following in which the border decorations are rendered via an HTML canvas underlay, while the text itself is described with HTML elements:

Design

The design of this library differs from the original ragged blocks library in a few ways. Primarily, it is designed to be much more minimal; it only supports one variation of the algorithm, and does not contain benchmarks, a demo application, or simplification. These choices are made in order to make this library more suitable as a dependency on real projects.

There are also some technical differences:

  • The original ragged blocks library converted the union-of-rectangles representation into a polygon before rendering. This conversion was a big reason the library is slow, and so this library makes the choice to never explicitly represent the outline. This is a tradeoff because it's no longer possible to traverse and modify the outline itself, which was how the old version rendered borders, border radii, and simplified the rock outlines. The first two must now be performed at the rendering step. How to achieve simplification at the rendering step is not something that is clear to me at this point.
  • This library also records information about the padding placed between atoms and lines. In the case of atoms, these values are called H-Gadgets (terminology used in Code Style Sheets3, however the library calls this leftPadding), and in the case of lines, the library calls them leading (Code Style Sheets calls them V-Gadgets). These gadgets turn out to be useful when you want to overlay graphics produced by this library atop text which is managed by the DOM---they tell what kind of padding needs to be applied to the HTML elements so that they match up with the rendering.

Optimizations

Here are some optimizations which I have thought about, but which aren't actually implemented in the library.

  • It is possible to share some work between re-runs of the algorithm, considering that in the common case of text editing, only one line of the document will change at a time. The algorithm is written in such a way that the horizontal position of the lines is found before they are merged together. A simple way to share work would be to retain these pre-merged lines so that they could be merged back together only around the changed line.
  • I think it is possible to achieve an asymptotic speedup on the application of leading when merging lines together by using the following algorithm sketch: link.

References

  1. Ragged Blocks: Rendering Structured Text with Styleback
  2. Retrofitting Text editors with Ragged Blocksback
  3. Code Style Sheetsback

Publishing

  1. Increment the package version using npm version {patch,minor,major}.
  2. Run npm install inside /examples/simple to increment the example version. Add the changes generated by this command into the commit generated in step 1 with --amend.
  3. Login to npm using npm login, then run npm publish --access public.

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • npm @sbcohen/ragged-blocks

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Critical Apache HTTP Server Flaw Exposes Web Servers to RCE (1)
CVE

CVE-2026-119618: Critical Apache HTTP Server Flaw Exposes Web Servers to Remote Code Execution

Plug and Pray: Your AI Agents Are Taking Orders From Strangers
Research

Plug and Pray: Your AI Agents Are Taking Orders From Strangers

CVE

Java4Shell (CVE-2026-114938): Easy to Crash, Hard to Exploit — Less Than 0.12% of JVMs Estimated at Risk of RCE

Frame 2085668439 (1)
Group 1261154229