@weasel-js/diagram 1.7.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -858,5 +858,5 @@ var tree = (graph, opts = {}) => {
858
858
  };
859
859
 
860
860
  export { COMPASS, DEFAULT_NODE_GAP, DEFAULT_PORTS, DEFAULT_RANK_GAP, DIAGRAM_TRAIT_KEY, axesFor, backEdges, bodyOutline, bodyTrait, boxForContent, buildBody, canvasMeasure, center, contentBox, createDiagramNodes, dataKeyReader, diagramNodeOf, extent, force, forceRelaxation, forestOf, graphOrder, isPinned, layered, layoutBody, layoutRowPorts, measureBody, outlinePath, outlinePolyline, packAcross, pinnedSet, portOf, portsOf, portsOnOutline, ranksOf, rayHit, seededOrder, settle, sizeToBody, translated, tree };
861
- //# sourceMappingURL=chunk-AD7TY6TK.js.map
862
- //# sourceMappingURL=chunk-AD7TY6TK.js.map
861
+ //# sourceMappingURL=chunk-4KXQABRM.js.map
862
+ //# sourceMappingURL=chunk-4KXQABRM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/outline.ts","../src/onOutline.ts","../src/trait.ts","../src/ports.ts","../src/body.ts","../src/layout.ts","../src/force.ts","../src/layered.ts","../src/tree.ts"],"names":["left","right","top","bottom","center","cursor"],"mappings":";;;AA2BA,IAAM,IAAA,GAAO,GAAA;AAIb,IAAM,KAAA,GAAQ,kBAAA;AAIP,SAAS,WAAA,CAAY,SAAkB,MAAA,EAAsB;AAClE,EAAA,IAAI,OAAO,OAAA,KAAY,QAAA,EAAU,OAAO,OAAA;AACxC,EAAA,MAAM,EAAE,CAAA,EAAG,CAAA,EAAG,OAAO,CAAA,EAAG,MAAA,EAAQ,GAAE,GAAI,MAAA;AACtC,EAAA,IAAI,KAAK,CAAA,IAAK,CAAA,IAAK,CAAA,EAAG,OAAO,SAAS,CAAA,EAAG,CAAA,EAAG,IAAA,CAAK,GAAA,CAAI,GAAG,CAAC,CAAA,EAAG,K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KAAA,GAAQ,KAAA,IAAS,CAAA;AACtC,IAAA,KAAA,MAAW,SAAS,IAAA,EAAM;AACxB,MAAA,KAAA,CAAM,OAAOA,OAAM,CAAA;AACnB,MAAAA,OAAAA,IAAU,OAAA,CAAQ,KAAK,CAAA,GAAI,OAAA;AAAA,IAC7B;AAEA,IAAA,MAAM,GAAA,GAAM,MAAA,CAAO,IAAA,CAAK,MAAA,EAAQ,KAAK,KAAK,CAAA;AAC1C,IAAA,MAAM,EAAA,GAAK,KAAA,CAAM,GAAA,CAAI,IAAA,CAAK,EAAE,CAAA,IAAK,CAAA;AACjC,IAAA,KAAA,CAAM,GAAA,CAAI,KAAK,EAAA,EAAI;AAAA,MACjB,KAAA,EAAO,IAAA,GAAA,CAAQ,KAAA,GAAQ,GAAA,IAAO,CAAA;AAAA,MAC9B,IAAA,EAAM,SAAA,CAAU,GAAA,CAAI,EAAE,KAAM,KAAA,CAAM,GAAA,CAAI,EAAE,CAAA,GAAK,MAAA,CAAO,IAAA,CAAK,MAAA,EAAQ,IAAA,CAAK,IAAI,CAAA,IAAK;AAAA,KAChF,CAAA;AAAA,EACH,CAAA;AAEA,EAAA,IAAI,MAAA,GAAS,CAAA;AACb,EAAA,KAAA,MAAW,QAAQ,KAAA,EAAO;AACxB,IAAA,KAAA,CAAM,MAAM,MAAM,CAAA;AAClB,IAAA,MAAA,IAAU,OAAA,CAAQ,IAAI,CAAA,GAAI,OAAA;AAAA,EAC5B;AAEA,EAAA,OAAO,MAAA,CAAO,KAAA,EAAO,KAAA,EAAO,IAAI,CAAA;AAClC","file":"chunk-4KXQABRM.js","sourcesContent":["/**\n * The shapes a built body can wear, as paths in the node's bounds.\n *\n * These are the flowchart vocabulary — a decision is a diamond, an I/O step a\n * parallelogram, a terminator a stadium — plus `'rect'` for everything else and\n * a `Path` escape hatch for a shape the vocabulary does not have. The path is\n * built in world coordinates from the bounds it is given, the same way the\n * kit's own `clipFromPose` factories are.\n */\nimport { PathBuilder, polygonFromPoints, rectPath, type Path } from '@weasel-js/core/math';\n\n/** An axis-aligned box. This is `PoseDescriptor.getBounds`'s return shape\n * minus its optional `rotation`, deliberately: an outline is built in the\n * shape's own unrotated frame, and the caller reads rotation separately\n * through `getRotation` and applies it to the finished path. */\nexport interface Bounds {\n x: number;\n y: number;\n width: number;\n height: number;\n}\n\n/** A named flowchart shape, or a path a consumer built themselves. */\nexport type Outline = 'rect' | 'diamond' | 'stadium' | 'parallelogram' | Path;\n\n/** How far a parallelogram's top edge leans past its bottom one, as a\n * fraction of the box's width. The flowchart convention. */\nconst LEAN = 0.2;\n\n/** Cubic approximation of a quarter circle. A stadium's ends are two of these\n * each, which is the same construction `ellipsePath` uses. */\nconst KAPPA = 0.5522847498307936;\n\n/** The path `outline` describes inside `bounds`. A zero-area box gives a\n * zero-area rect rather than a degenerate polygon. */\nexport function outlinePath(outline: Outline, bounds: Bounds): Path {\n if (typeof outline !== 'string') return outline;\n const { x, y, width: w, height: h } = bounds;\n if (w <= 0 || h <= 0) return rectPath(x, y, Math.max(w, 0), Math.max(h, 0));\n\n switch (outline) {\n case 'rect':\n return rectPath(x, y, w, h);\n\n case 'diamond':\n return polygonFromPoints([\n { x: x + w / 2, y },\n { x: x + w, y: y + h / 2 },\n { x: x + w / 2, y: y + h },\n { x, y: y + h / 2 },\n ]);\n\n case 'parallelogram': {\n // The lean is clamped so a narrow box cannot fold through itself.\n const lean = Math.min(w * LEAN, w / 2);\n return polygonFromPoints([\n { x: x + lean, y },\n { x: x + w, y },\n { x: x + w - lean, y: y + h },\n { x, y: y + h },\n ]);\n }\n\n case 'stadium':\n return stadiumPath(x, y, w, h);\n }\n}\n\n/** A rect with semicircular ends — the Minkowski sum of a segment and a disc,\n * which puts the flat edges along the box's *longer* axis. A tall box is a\n * pill standing up, not an ellipse. */\nfunction stadiumPath(x: number, y: number, w: number, h: number): Path {\n const r = Math.min(w, h) / 2;\n const k = r * KAPPA;\n const b = new PathBuilder();\n\n if (w >= h) {\n const left = x + r;\n const right = x + w - r;\n const top = y;\n const bottom = y + h;\n const midY = y + h / 2;\n return b\n .moveTo(left, top)\n .lineTo(right, top)\n .curveTo(right + k, top, x + w, midY - k, x + w, midY)\n .curveTo(x + w, midY + k, right + k, bottom, right, bottom)\n .lineTo(left, bottom)\n .curveTo(left - k, bottom, x, midY + k, x, midY)\n .curveTo(x, midY - k, left - k, top, left, top)\n .close()\n .build();\n }\n\n const top = y + r;\n const bottom = y + h - r;\n const left = x;\n const right = x + w;\n const midX = x + w / 2;\n return b\n .moveTo(right, top)\n .lineTo(right, bottom)\n .curveTo(right, bottom + k, midX + k, y + h, midX, y + h)\n .curveTo(midX - k, y + h, left, bottom + k, left, bottom)\n .lineTo(left, top)\n .curveTo(left, top - k, midX - k, y, midX, y)\n .curveTo(midX + k, y, right, top - k, right, top)\n .close()\n .build();\n}\n\n/**\n * The largest axis-aligned box a shape's content can occupy without leaving\n * the shape. Rows lay out in here, not in the bounds — a diamond's corners and\n * a parallelogram's lean are outside its own box, and a label placed against\n * the bounding box lands there and gets clipped away by the silhouette.\n *\n * Conservative rather than exact: the inscribed rect of a rhombus is exact,\n * and a stadium reports the flat span between its rounded ends, which gives up\n * a little height near them.\n */\nexport function contentBox(outline: Outline, bounds: Bounds): Bounds {\n if (typeof outline !== 'string') return bounds;\n const { x, y, width: w, height: h } = bounds;\n switch (outline) {\n case 'rect':\n return bounds;\n case 'diamond':\n // Half the width and half the height, centered — the inscribed rect.\n return { x: x + w / 4, y: y + h / 4, width: w / 2, height: h / 2 };\n case 'parallelogram': {\n const lean = Math.min(w * LEAN, w / 2);\n return { x: x + lean, y, width: Math.max(w - lean * 2, 0), height: h };\n }\n case 'stadium': {\n const r = Math.min(w, h) / 2;\n return w >= h\n ? { x: x + r, y, width: Math.max(w - r * 2, 0), height: h }\n : { x, y: y + r, width: w, height: Math.max(h - r * 2, 0) };\n }\n }\n}\n\n/**\n * The box whose {@link contentBox} is at least `content` — the inverse, for\n * sizing a node to what its rows measured.\n *\n * The stadium case is the only inexact one: its inset depends on the height it\n * is solving for, so it assumes the wide orientation and adds one height's\n * worth of end caps.\n */\nexport function boxForContent(\n outline: Outline,\n content: { width: number; height: number },\n): { width: number; height: number } {\n if (typeof outline !== 'string') return content;\n switch (outline) {\n case 'rect':\n return content;\n case 'diamond':\n return { width: content.width * 2, height: content.height * 2 };\n case 'parallelogram':\n return { width: content.width / (1 - LEAN * 2), height: content.height };\n case 'stadium':\n return { width: content.width + content.height, height: content.height };\n }\n}\n","/**\n * Moving a port from the node's bounding box onto the shape it is drawn as.\n *\n * A port is placed as a fraction of the node's bounds, which is what makes it\n * survive a resize. For a rect that is already on the outline; for anything\n * else it can be well outside the ink — a parallelogram's west port floats in\n * the gap beside its leaning edge, and an edge that ends there ends in empty\n * space. So the point is cast back onto the outline along the ray from the\n * node's center, which is the direction an edge leaves anyway.\n */\nimport { PATH_C, PATH_L, PATH_M, PATH_Q, PATH_Z, flattenCubic, type Path } from '@weasel-js/core/math';\nimport { outlinePath, type Bounds, type Outline } from './outline';\nimport type { Port } from './types';\n\n/** Curve flattening tolerance, in world units. Finer than a port is wide. */\nconst TOLERANCE = 0.25;\n\n/** The outline as a closed polyline: `[x0, y0, x1, y1, …]`. */\nexport function outlinePolyline(outline: Outline, bounds: Bounds): number[] {\n const path = outlinePath(outline, bounds);\n return flattenPath(path);\n}\n\nfunction flattenPath(path: Path): number[] {\n if (path.kind === 'rect') {\n const { x, y, width: w, height: h } = path;\n return [x, y, x + w, y, x + w, y + h, x, y + h, x, y];\n }\n const out: number[] = [];\n const { commands, coords } = path as { commands: Uint8Array; coords: Float32Array };\n let ci = 0;\n let cx = 0;\n let cy = 0;\n let sx = 0;\n let sy = 0;\n for (const cmd of commands) {\n if (cmd === PATH_M) {\n cx = coords[ci]!; cy = coords[ci + 1]!; ci += 2;\n sx = cx; sy = cy;\n out.push(cx, cy);\n } else if (cmd === PATH_L) {\n cx = coords[ci]!; cy = coords[ci + 1]!; ci += 2;\n out.push(cx, cy);\n } else if (cmd === PATH_C) {\n const x1 = coords[ci]!, y1 = coords[ci + 1]!;\n const x2 = coords[ci + 2]!, y2 = coords[ci + 3]!;\n const x3 = coords[ci + 4]!, y3 = coords[ci + 5]!;\n ci += 6;\n flattenCubic(cx, cy, x1, y1, x2, y2, x3, y3, TOLERANCE, out);\n cx = x3; cy = y3;\n } else if (cmd === PATH_Q) {\n // Elevated to a cubic rather than given its own flattener.\n const qx = coords[ci]!, qy = coords[ci + 1]!;\n const x3 = coords[ci + 2]!, y3 = coords[ci + 3]!;\n ci += 4;\n flattenCubic(\n cx, cy,\n cx + (2 / 3) * (qx - cx), cy + (2 / 3) * (qy - cy),\n x3 + (2 / 3) * (qx - x3), y3 + (2 / 3) * (qy - y3),\n x3, y3, TOLERANCE, out,\n );\n cx = x3; cy = y3;\n } else if (cmd === PATH_Z) {\n out.push(sx, sy);\n cx = sx; cy = sy;\n }\n }\n // Close it, so a ray leaving through the last edge still finds a crossing.\n if (out.length >= 2 && (out[0] !== out[out.length - 2] || out[1] !== out[out.length - 1])) {\n out.push(out[0]!, out[1]!);\n }\n return out;\n}\n\n/**\n * Where the ray from `center` through `point` last crosses `poly`, or `null`\n * when it never does.\n *\n * The *last* crossing rather than the first: a concave outline can be crossed\n * more than once, and the far side is the boundary an edge should attach to.\n */\nexport function rayHit(\n poly: readonly number[],\n center: { x: number; y: number },\n point: { x: number; y: number },\n): { x: number; y: number } | null {\n const dx = point.x - center.x;\n const dy = point.y - center.y;\n if (dx === 0 && dy === 0) return null;\n let bestT = -Infinity;\n let hit: { x: number; y: number } | null = null;\n for (let i = 0; i + 3 < poly.length; i += 2) {\n const ax = poly[i]!, ay = poly[i + 1]!;\n const bx = poly[i + 2]!, by = poly[i + 3]!;\n const ex = bx - ax;\n const ey = by - ay;\n const denom = dx * ey - dy * ex;\n if (denom === 0) continue;\n // t along the ray, u along the segment.\n const t = ((ax - center.x) * ey - (ay - center.y) * ex) / denom;\n const u = ((ax - center.x) * dy - (ay - center.y) * dx) / denom;\n if (t < 0 || u < 0 || u > 1) continue;\n if (t > bestT) {\n bestT = t;\n hit = { x: center.x + dx * t, y: center.y + dy * t };\n }\n }\n return hit;\n}\n\n/**\n * Every port moved onto `outline`. A port the ray misses — one at the node's\n * dead center, with no direction to cast along — is left where it was.\n */\nexport function portsOnOutline(\n ports: readonly Port[],\n outline: Outline,\n bounds: Bounds,\n): Port[] {\n if (bounds.width <= 0 || bounds.height <= 0) return [...ports];\n const poly = outlinePolyline(outline, bounds);\n const center = { x: bounds.x + bounds.width / 2, y: bounds.y + bounds.height / 2 };\n return ports.map((port) => {\n const hit = rayHit(poly, center, port.point);\n return hit === null ? port : { ...port, point: hit };\n });\n}\n","/**\n * Reading the `DiagramNode` trait off a scene node.\n *\n * Two ways to attach it, both of which this module's default reader answers:\n *\n * - **On the node.** `data.diagram` holds the trait. One node, one answer;\n * what a connect gesture writes when the author drags a new edge.\n * - **By kind.** A consumer declares once which data shapes take part, and\n * every matching node gets the trait without being stamped. This mirrors\n * `createNodeRouting` in the kit — a predicate over `data`, first match\n * wins — and is the shape to reach for when the participants are a class\n * of node rather than a hand-picked set.\n *\n * A reader is a plain function, so a consumer whose data lives somewhere else\n * entirely passes their own and never touches either form.\n */\nimport type { DiagramNode } from './types';\n\n/** The key on a node's `data` the default reader looks under. */\nexport const DIAGRAM_TRAIT_KEY = 'diagram';\n\n/** All a reader looks at. Deliberately not `SceneNode`: naming `TPose` there\n * would put it in a contravariant position for no gain, since nothing here\n * reads a pose. */\nexport interface DiagramNodeLike {\n id: string;\n kind: 'leaf' | 'container';\n data: unknown;\n}\n\n/** Answers \"is this node a diagram participant, and on what terms\" — `null`\n * for a node that takes no part. */\nexport type DiagramNodeReader = (node: DiagramNodeLike) => DiagramNode | null;\n\n/** One class of participant, declared once for every node whose data matches.\n * Mirrors `NodeRoutingEntry`. */\nexport interface DiagramNodeEntry {\n /** Unique within a reader; the same vocabulary as `NodeRoutingEntry.name`. */\n name: string;\n matches: (data: unknown) => boolean;\n /** The trait every matching node carries. A function when it varies with the\n * node's own data — a pipeline stage whose ports come from its rows. */\n trait: DiagramNode | ((data: unknown) => DiagramNode);\n}\n\n/** The trait on the node's own `data.diagram`, or `null`.\n *\n * An edge's trait lives under the same key, so `from` and `to` are what tells\n * the two apart. Without that test an edge reads as a participant declaring\n * no ports, and collects the four defaults on the degenerate pose an edge\n * carries — four grabbable ports in the middle of nowhere. */\nexport const dataKeyReader: DiagramNodeReader = (node) => {\n const data = node.data;\n if (data === null || typeof data !== 'object') return null;\n const trait = (data as Record<string, unknown>)[DIAGRAM_TRAIT_KEY];\n if (trait === null || typeof trait !== 'object') return null;\n if ('from' in trait && 'to' in trait) return null;\n return trait as DiagramNode;\n};\n\n/**\n * A reader over declared kinds. A trait on the node's own data still wins, so\n * a single node can opt out of, or override, whatever its kind says.\n *\n * Throws on a duplicate `name`, for the reason `mergeContributions` does: a\n * class of node silently losing its ports is what this registry exists to make\n * loud.\n */\nexport function createDiagramNodes(entries: readonly DiagramNodeEntry[]): DiagramNodeReader {\n const seen = new Set<string>();\n for (const entry of entries) {\n if (seen.has(entry.name)) {\n throw new Error(`createDiagramNodes: duplicate entry name \"${entry.name}\"`);\n }\n seen.add(entry.name);\n }\n return (node) => {\n const own = dataKeyReader(node);\n if (own !== null) return own;\n for (const entry of entries) {\n if (!entry.matches(node.data)) continue;\n return typeof entry.trait === 'function' ? entry.trait(node.data) : entry.trait;\n }\n return null;\n };\n}\n\n/** The trait `node` carries, through `read` (default: its own `data.diagram`). */\nexport function diagramNodeOf(\n node: DiagramNodeLike,\n read: DiagramNodeReader = dataKeyReader,\n): DiagramNode | null {\n return read(node);\n}\n\n/** True when layout must leave this node where it is. */\nexport function isPinned(node: DiagramNodeLike, read?: DiagramNodeReader): boolean {\n return diagramNodeOf(node, read)?.pinned === true;\n}\n","/**\n * Where a node's ports are, in world coordinates.\n *\n * A port is placed in the node's **unrotated** bounds, then carried through\n * the pose's rotation — the same pivot every other kit reader uses, the AABB\n * center. Bounds come from the pose descriptor rather than from `pose.width`\n * and friends, so a node whose pose is a path, an ellipse or anything else a\n * consumer wired is connectable on the same terms as a rect.\n */\nimport {\n AUTO_POSE_DESCRIPTOR,\n rotatePoint,\n type PoseDescriptor,\n type Vec2,\n} from '@weasel-js/core/math';\nimport { outlinePolyline, rayHit } from './onOutline';\nimport { diagramNodeOf, type DiagramNodeLike, type DiagramNodeReader } from './trait';\nimport type { Port, PortAnchor, PortSpec } from './types';\n\n/** The eight anchors almost everything wants, named the way a compass is. */\nexport const COMPASS = {\n nw: { u: 0, v: 0 },\n n: { u: 0.5, v: 0 },\n ne: { u: 1, v: 0 },\n e: { u: 1, v: 0.5 },\n se: { u: 1, v: 1 },\n s: { u: 0.5, v: 1 },\n sw: { u: 0, v: 1 },\n w: { u: 0, v: 0.5 },\n} as const satisfies Record<string, PortAnchor>;\n\n/**\n * What a node carrying no `ports` gets: the four edge midpoints of its own\n * bounds. Every node has bounds, so every node is connectable without saying\n * anything.\n */\nexport const DEFAULT_PORTS: readonly PortSpec[] = Object.freeze([\n { id: 'n', at: COMPASS.n },\n { id: 'e', at: COMPASS.e },\n { id: 's', at: COMPASS.s },\n { id: 'w', at: COMPASS.w },\n]);\n\n/** How ports are resolved against a node: its bounds, and its trait. */\nexport interface PortsOptions<TPose> {\n /** Reads the AABB a port is placed in, and the node's rotation. Defaults to\n * the kit's `AUTO_POSE_DESCRIPTOR`, which handles rect and path poses. */\n geometry?: PoseDescriptor<TPose>;\n /** How the `DiagramNode` trait is read off a node. */\n read?: DiagramNodeReader;\n}\n\n/**\n * The direction the anchor implies: away from the center of the bounds.\n *\n * `(2u-1, 2v-1)` is the anchor in a box that runs -1..1, which is exactly that\n * direction — an edge midpoint gets the axis-aligned normal, a corner gets the\n * diagonal. It is deliberately not scaled by the node's aspect: this is a\n * heading a router leaves along, not a point on the outline. A port at the\n * dead center has no direction, and says so.\n */\nfunction normalOf(at: PortAnchor): Vec2 | null {\n const x = at.u * 2 - 1;\n const y = at.v * 2 - 1;\n const len = Math.hypot(x, y);\n if (len === 0) return null;\n return { x: x / len, y: y / len };\n}\n\n/**\n * Every port on `node`, resolved against `pose`.\n *\n * Pass the pose the node is **painted** at — `effectivePose(scene, node)` —\n * not `node.pose`. A port that answers from the document pose while the node\n * is mid-drag puts an edge somewhere the user can see the node is not.\n */\nexport function portsOf<TPose>(\n node: DiagramNodeLike,\n pose: TPose,\n opts: PortsOptions<TPose> = {},\n): Port[] {\n const trait = diagramNodeOf(node, opts.read);\n if (trait === null) return [];\n const geometry = opts.geometry ?? (AUTO_POSE_DESCRIPTOR as PoseDescriptor<TPose>);\n const bounds = geometry.getBounds(pose);\n const rotation = geometry.getRotation?.(pose) ?? 0;\n const cx = bounds.x + bounds.width / 2;\n const cy = bounds.y + bounds.height / 2;\n // A port is anchored in the bounds so it survives a resize, but it has to\n // *sit* on the shape: a parallelogram's west anchor is in the gap beside its\n // leaning edge, and an edge ending there ends in empty space. Flattened once\n // per call, not once per port.\n const poly = trait.outline === undefined || bounds.width <= 0 || bounds.height <= 0\n ? null\n : outlinePolyline(trait.outline, bounds);\n\n return (trait.ports ?? DEFAULT_PORTS).map((spec) => {\n const anchored: Vec2 = {\n x: bounds.x + spec.at.u * bounds.width,\n y: bounds.y + spec.at.v * bounds.height,\n };\n const flat = (poly === null ? null : rayHit(poly, { x: cx, y: cy }, anchored)) ?? anchored;\n const normal = spec.normal === undefined ? normalOf(spec.at) : spec.normal;\n if (rotation === 0) {\n return { id: spec.id, nodeId: node.id, point: flat, normal, ...typeOf(spec) };\n }\n return {\n id: spec.id,\n nodeId: node.id,\n point: rotatePoint(flat.x, flat.y, cx, cy, rotation),\n // A direction rotates about the origin, not about the node's center.\n normal: normal === null ? null : rotatePoint(normal.x, normal.y, 0, 0, rotation),\n ...typeOf(spec),\n };\n });\n}\n\n/** One named port, or `undefined` when the node has no such port. */\nexport function portOf<TPose>(\n node: DiagramNodeLike,\n pose: TPose,\n portId: string,\n opts: PortsOptions<TPose> = {},\n): Port | undefined {\n return portsOf(node, pose, opts).find((p) => p.id === portId);\n}\n\n/** Spread rather than assigned, so a port with no type has no `type` key at\n * all — `exactOptionalPropertyTypes` rejects an explicit `undefined`. */\nfunction typeOf(spec: PortSpec): { type?: string } {\n return spec.type === undefined ? {} : { type: spec.type };\n}\n","/**\n * The optional body builder: what a node looks like when it should read as a\n * flowchart box or a visual-programming operator, rather than as whatever\n * scene node it already was.\n *\n * **The body measures a floor; the author sets the rest.** Rows measure to a\n * `{ minWidth, minHeight }` and the node's pose is the max of that and what\n * the author gave it. Adding a port row can grow a node; nothing here ever\n * shrinks one back. Because the pose stays authored data, resize, align,\n * distribute, guides, snapping and undo need no special case, and a node that\n * did not come from the builder just has whatever size it already had.\n *\n * Text measurement is a seam rather than an import: measuring needs a 2D\n * context, which a geometry module has no business owning. `canvasMeasure`\n * adapts the kit's own `measureText` for a caller that has one.\n */\nimport { boxForContent, contentBox, outlinePath, type Bounds, type Outline } from './outline';\nimport { COMPASS } from './ports';\nimport type { DiagramNode, PortSpec } from './types';\n\n/** One line of body content. */\nexport type Row =\n /** Text. `label` is the node's name; `field` is a named value. */\n | { kind: 'label'; text: string; style?: RowTextStyle }\n | { kind: 'field'; label: string; value: string; style?: RowTextStyle }\n /** A row that carries ports on its own left and right edges — the\n * visual-programming shape, where an operator's inputs line up with the\n * rows they feed. */\n | { kind: 'ports'; left?: readonly RowPort[]; right?: readonly RowPort[]; height?: number }\n /** Reserved space a consumer paints into. */\n | { kind: 'slot'; height: number; id?: string };\n\n/** A port declared on a row rather than on the node's perimeter. */\nexport interface RowPort {\n id: string;\n /** Label shown beside it, and what the row measures against. */\n label?: string;\n type?: string;\n}\n\n/** The subset of a text style the body measures against. Deliberately small:\n * a full `ResolvedTextStyle` belongs to whatever paints the row. */\nexport interface RowTextStyle {\n fontSize?: number;\n fontFamily?: string;\n bold?: boolean;\n}\n\n/** Measures one run of text. Returns its advance width and its line height. */\nexport type MeasureRowText = (text: string, style: RowTextStyle) => { width: number; height: number };\n\n/** A body's content: the outline it draws and the rows stacked inside it. */\nexport interface BodySpec {\n outline: Outline;\n rows: readonly Row[];\n /** Space between the outline and its rows. Default 8. */\n padding?: number;\n /** Space between adjacent rows. Default 4. */\n gap?: number;\n}\n\n/** What {@link buildBody} emits: the `AddNodeSpec` fields it fills in. Named\n * structurally rather than imported so a consumer whose scene is typed\n * differently can still spread one. */\nexport interface BodyNodeSpec<TData, TLayer extends string, TPose> {\n kind: 'container' | 'leaf';\n layer: TLayer;\n pose: TPose;\n data: TData;\n id?: string;\n parent?: string;\n /** Set `false` on every leaf the builder emits: the innermost hit wins, so a\n * row that answers a press is a body that cannot be dragged. */\n pickable?: boolean;\n}\n\n/** The floor a body's content puts under its node's size. */\nexport interface BodyFloor {\n minWidth: number;\n minHeight: number;\n}\n\n/** Where one row landed, in the same frame as the bounds it was laid out in.\n * A `ports` row's own ports anchor to this box. */\nexport interface RowBox extends Bounds {\n row: Row;\n index: number;\n}\n\n/** Where one row port's label sits, in the same frame as the row box it was\n * laid out in. Its vertical center is also where the port itself attaches, so\n * a label and the port it names cannot drift apart. */\nexport interface RowPortBox extends Bounds {\n port: RowPort;\n side: 'left' | 'right';\n /** Position within its own side, top to bottom. */\n index: number;\n}\n\nconst DEFAULT_PADDING = 8;\nconst DEFAULT_GAP = 4;\n/** What a row is worth when nothing measures its text. Enough that a body\n * laid out headlessly is not zero-height — a zero-height body renders as an\n * empty page with every unit test still green. */\nconst FALLBACK_LINE = 16;\n\n/** Adapts the kit's `measureText` for a caller holding a 2D context. Pass the\n * same context the renderer measures with, or the floor will not match what\n * is painted. */\nexport function canvasMeasure(\n ctx: { measureText(text: string): { width: number } ; font: string },\n): MeasureRowText {\n return (text, style) => {\n const size = style.fontSize ?? FALLBACK_LINE;\n ctx.font = `${style.bold === true ? 'bold ' : ''}${size}px ${style.fontFamily ?? 'sans-serif'}`;\n return { width: ctx.measureText(text).width, height: Math.ceil(size * 1.2) };\n };\n}\n\n/** What each row is worth on its own, before padding and gaps. */\nfunction measureRow(row: Row, measure: MeasureRowText | undefined): { width: number; height: number } {\n const text = (s: string, style?: RowTextStyle): { width: number; height: number } =>\n measure === undefined\n ? { width: s.length * (((style?.fontSize ?? FALLBACK_LINE) * 0.6)), height: FALLBACK_LINE }\n : measure(s, style ?? {});\n\n switch (row.kind) {\n case 'label':\n return text(row.text, row.style);\n case 'field': {\n // Label and value sit on one line with a gap between them.\n const l = text(row.label, row.style);\n const v = text(row.value, row.style);\n return { width: l.width + DEFAULT_GAP * 2 + v.width, height: Math.max(l.height, v.height) };\n }\n case 'ports': {\n const side = (ports: readonly RowPort[] | undefined): number =>\n (ports ?? []).reduce((w, p) => Math.max(w, p.label === undefined ? 0 : text(p.label).width), 0);\n const rows = Math.max(row.left?.length ?? 0, row.right?.length ?? 0, 1);\n return {\n width: side(row.left) + DEFAULT_GAP * 2 + side(row.right),\n height: row.height ?? rows * FALLBACK_LINE,\n };\n }\n case 'slot':\n return { width: 0, height: row.height };\n }\n}\n\n/**\n * The smallest box `spec`'s rows fit in. A node's pose is maxed against this,\n * never set to it.\n */\nexport function measureBody(spec: BodySpec, measure?: MeasureRowText): BodyFloor {\n const padding = spec.padding ?? DEFAULT_PADDING;\n const gap = spec.gap ?? DEFAULT_GAP;\n let width = 0;\n let height = 0;\n for (const [i, row] of spec.rows.entries()) {\n const m = measureRow(row, measure);\n width = Math.max(width, m.width);\n height += m.height + (i > 0 ? gap : 0);\n }\n // The rows fit the *content* box; the node's own box has to be whatever\n // contains that, or a diamond's label lands outside the diamond.\n const box = boxForContent(spec.outline, {\n width: width + padding * 2,\n height: height + padding * 2,\n });\n return { minWidth: box.width, minHeight: box.height };\n}\n\n/**\n * The authored size, grown to fit the body. Never shrinks: a row removed\n * leaves the node the size the author last saw it at, which is the only\n * behavior that survives a resize the author did on purpose.\n */\nexport function sizeToBody<TPose extends Bounds>(pose: TPose, floor: BodyFloor): TPose {\n const width = Math.max(pose.width, floor.minWidth);\n const height = Math.max(pose.height, floor.minHeight);\n if (width === pose.width && height === pose.height) return pose;\n return { ...pose, width, height };\n}\n\n/** Where each row sits inside `bounds`, top to bottom. Rows keep their\n * measured heights; the leftover goes unclaimed at the bottom rather than\n * being distributed, so a row does not move when a sibling grows. */\nexport function layoutBody(\n spec: BodySpec,\n bounds: Bounds,\n measure?: MeasureRowText,\n): RowBox[] {\n const padding = spec.padding ?? DEFAULT_PADDING;\n const gap = spec.gap ?? DEFAULT_GAP;\n const inner = contentBox(spec.outline, bounds);\n const width = Math.max(inner.width - padding * 2, 0);\n let y = inner.y + padding;\n return spec.rows.map((row, index) => {\n const h = measureRow(row, measure).height;\n const box: RowBox = { row, index, x: inner.x + padding, y, width, height: h };\n y += h + gap;\n return box;\n });\n}\n\n/**\n * Where each of a `ports` row's ports goes inside `box`, on the same terms\n * `layoutBody` gives one box per row.\n *\n * Both sides are cut into the same number of slots — the longer side's count —\n * so the nth input faces the nth output whichever side has more. A label box\n * is as wide as its own text and pinned to its own edge of the row; an\n * unlabeled port gets a zero-width box there, which is still where it attaches.\n */\nexport function layoutRowPorts(\n row: Extract<Row, { kind: 'ports' }>,\n box: Bounds,\n measure?: MeasureRowText,\n): RowPortBox[] {\n const width = (label: string | undefined): number =>\n label === undefined ? 0 : measureRow({ kind: 'label', text: label }, measure).width;\n const slots = Math.max(row.left?.length ?? 0, row.right?.length ?? 0, 1);\n const slotHeight = box.height / slots;\n const out: RowPortBox[] = [];\n const side = (ports: readonly RowPort[] | undefined, which: 'left' | 'right'): void => {\n for (const [index, port] of (ports ?? []).entries()) {\n const w = width(port.label);\n out.push({\n port,\n side: which,\n index,\n x: which === 'left' ? box.x : box.x + box.width - w,\n y: box.y + index * slotHeight,\n width: w,\n height: slotHeight,\n });\n }\n };\n side(row.left, 'left');\n side(row.right, 'right');\n return out;\n}\n\n/**\n * The `DiagramNode` trait a built body implies: perimeter ports for the\n * outline, plus one port per `ports`-row entry, anchored to that row's own\n * left or right edge.\n *\n * Anchors are normalized against `bounds`, so they survive the node being\n * resized — which is the whole reason `PortAnchor` is normalized.\n *\n * **A row port on a side takes that side's compass default with it.** Both sit\n * on the same edge, and a row near the vertical middle puts one exactly on top\n * of `w` or `e` — where the later region wins the hit and the other is\n * grabbable nowhere. A body that declares where its inputs attach has said what\n * that side is for.\n */\nexport function bodyTrait(spec: BodySpec, bounds: Bounds, measure?: MeasureRowText): DiagramNode {\n const outline = spec.outline;\n const compass: PortSpec[] = [\n { id: 'n', at: COMPASS.n },\n { id: 'e', at: COMPASS.e },\n { id: 's', at: COMPASS.s },\n { id: 'w', at: COMPASS.w },\n ];\n if (bounds.height <= 0) return { outline, ports: compass };\n\n const rowPorts: PortSpec[] = [];\n let hasLeft = false;\n let hasRight = false;\n for (const box of layoutBody(spec, bounds, measure)) {\n if (box.row.kind !== 'ports') continue;\n for (const pb of layoutRowPorts(box.row, box, measure)) {\n if (pb.side === 'left') hasLeft = true;\n else hasRight = true;\n const v = (pb.y + pb.height / 2 - bounds.y) / bounds.height;\n rowPorts.push(withType(\n { id: pb.port.id, at: { u: pb.side === 'left' ? 0 : 1, v } },\n pb.port.type,\n ));\n }\n }\n const kept = compass.filter((p) =>\n !(p.id === 'w' && hasLeft) && !(p.id === 'e' && hasRight));\n return { outline, ports: [...kept, ...rowPorts] };\n}\n\nfunction withType(spec: PortSpec, type: string | undefined): PortSpec {\n return type === undefined ? spec : { ...spec, type };\n}\n\n/** The outline path for a built body at `bounds` — what paints it, and what a\n * perimeter-hugging port will eventually be placed on. */\nexport function bodyOutline(spec: BodySpec, bounds: Bounds) {\n return outlinePath(spec.outline, bounds);\n}\n\n/** What a built body's rows are handed to, one call per row.\n *\n * `text` is the row's content already formatted — a `label`'s own text, or a\n * `field`'s `\"label: value\"` — so the common case needs no discrimination.\n * Return `null` for a row the consumer paints itself; `ports` and `slot` rows\n * arrive with `text` empty and are the usual ones to decline. */\nexport type RowNodeData<TData> = (text: string, box: RowBox) => TData | null;\n\n/** Options for {@link buildBody}: the layer and data of each node it emits.\n * Without `measure`, rows are sized from a fallback line height rather than\n * their text. */\nexport interface BuildBodyOptions<TData, TLayer extends string, TPose extends Bounds> {\n layer: TLayer;\n /** The container's id. Edges name it, so pass one for anything an edge or a\n * layout `pin` will refer to. */\n id?: string;\n measure?: MeasureRowText;\n /** The container's own data, given the trait the builder computed and the\n * pose it was computed against. */\n body: (trait: DiagramNode, pose: TPose) => TData;\n /** One row's data, or `null` to leave that row undrawn. */\n row: RowNodeData<TData>;\n /** One row port's label, or `null` to leave it undrawn. Ports with no\n * `label` are never offered. Omit to draw none — a body whose ports are\n * named only for the width they claim needs nothing here. */\n portLabel?: (text: string, box: RowPortBox) => TData | null;\n}\n\n/**\n * The scene nodes a built body is: one container carrying the trait, and one\n * leaf per row that wants drawing.\n *\n * Rows are ordinary scene nodes rather than something this package paints, so\n * the kit's own text painter draws them and text editing, styling and\n * selection work on them unchanged. The walk that places them is\n * `layoutBody` — the same one `bodyTrait` anchors its row ports against, which\n * is why a label and its ports cannot drift apart.\n *\n * The pose is `sizeToBody(at, measureBody(spec))`: the body measures a floor\n * and the authored size is grown to clear it, never shrunk.\n */\nexport function buildBody<TData, TLayer extends string, TPose extends Bounds>(\n spec: BodySpec,\n at: TPose,\n opts: BuildBodyOptions<TData, TLayer, TPose>,\n): { pose: TPose; specs: BodyNodeSpec<TData, TLayer, TPose>[] } {\n const pose = sizeToBody(at, measureBody(spec, opts.measure));\n const specs: BodyNodeSpec<TData, TLayer, TPose>[] = [{\n kind: 'container',\n layer: opts.layer,\n pose,\n data: opts.body(bodyTrait(spec, pose, opts.measure), pose),\n ...(opts.id === undefined ? {} : { id: opts.id }),\n }];\n\n const leaf = (box: Bounds, data: TData): void => {\n specs.push({\n kind: 'leaf',\n layer: opts.layer,\n pose: { ...pose, x: box.x, y: box.y, width: box.width, height: box.height },\n data,\n pickable: false,\n ...(opts.id === undefined ? {} : { parent: opts.id }),\n });\n };\n\n const portLabel = opts.portLabel;\n for (const box of layoutBody(spec, pose, opts.measure)) {\n const data = opts.row(rowText(box.row), box);\n if (data !== null) leaf(box, data);\n if (portLabel === undefined || box.row.kind !== 'ports') continue;\n for (const pb of layoutRowPorts(box.row, box, opts.measure)) {\n if (pb.port.label === undefined) continue;\n const labelData = portLabel(pb.port.label, pb);\n if (labelData !== null) leaf(pb, labelData);\n }\n }\n return { pose, specs };\n}\n\n/** A row's content as one string: empty for a row that carries no text. */\nfunction rowText(row: Row): string {\n if (row.kind === 'label') return row.text;\n if (row.kind === 'field') return `${row.label}: ${row.value}`;\n return '';\n}\n","/**\n * Layout: where the participants go.\n *\n * A layout is a pure function of the graph — no scene, no ops, no history. It\n * hands back the new top-left for every node that **moves**, and a node already\n * standing where the layout wants it is simply absent from the answer. That is\n * what makes re-running a layout free rather than destructive, and it is the\n * property the idempotence test asserts.\n *\n * Three rules keep re-layout non-destructive, and all three live here rather\n * than in each algorithm:\n *\n * - **No RNG anywhere.** Every tiebreak falls back to the graph's own node\n * order, which is the source's order — render order, for a scene.\n * - **Within-rank order is seeded from where the nodes already are**, read\n * off the cross axis, rather than from crossing-minimization. An author who\n * dragged two boxes into an order gets that order back.\n * - **A pin set nothing moves.** Pinned nodes are never in the result, and\n * the rest of the layout is translated to sit around them.\n *\n * `layered` and `tree` are idempotent by construction: the second run reads the\n * order the first run produced and computes the same slots. `force` is an\n * iterative relaxation and makes no such claim — re-running it keeps relaxing.\n */\nimport type { Vec2 } from '@weasel-js/core/math';\nimport type { Graph, GraphNode } from './graph';\nimport type { Bounds } from './outline';\n\n/** Which way the ranks stack. `force` ignores it. */\nexport type LayoutDirection = 'down' | 'up' | 'right' | 'left';\n\n/** Options every layout takes. */\nexport interface LayoutOptions {\n /** Default `'down'`. */\n direction?: LayoutDirection;\n /** Between neighbors within a rank, in world units. Default 48. */\n nodeGap?: number;\n /** Between one rank and the next. Default 96. */\n rankGap?: number;\n /** Ids layout must not move, on top of whatever carries `pinned: true`. */\n pin?: Iterable<string>;\n /** How far a node has to move to be worth moving, in world units. Default\n * `1e-6` — a float-noise floor, not a snapping quantum. Raise it to let a\n * `force` pass that has stopped doing anything useful commit nothing. */\n tolerance?: number;\n}\n\n/** The new top-left for each node that moves. A node that is already there is\n * absent, so an empty result means \"nothing to do\". */\nexport type LayoutResult = ReadonlyMap<string, Vec2>;\n\n/** Every layout in this package has this shape, and so does a consumer's. */\nexport type LayoutFn = (graph: Graph, opts?: LayoutOptions) => LayoutResult;\n\n/** `LayoutOptions.nodeGap`'s default, in world units. */\nexport const DEFAULT_NODE_GAP = 48;\n/** `LayoutOptions.rankGap`'s default, in world units. */\nexport const DEFAULT_RANK_GAP = 96;\nconst DEFAULT_TOLERANCE = 1e-6;\n\n/** Which world axis carries ranks, which carries within-rank order, and\n * whether ranks grow toward positive world coordinates. */\nexport interface LayoutAxes {\n rank: 'x' | 'y';\n cross: 'x' | 'y';\n /** `-1` for `'up'` and `'left'`, where the canonical frame is mirrored. */\n sign: 1 | -1;\n}\n\n/** The axes a direction lays ranks along. Default `'down'`. */\nexport function axesFor(direction: LayoutDirection = 'down'): LayoutAxes {\n switch (direction) {\n case 'up':\n return { rank: 'y', cross: 'x', sign: -1 };\n case 'right':\n return { rank: 'x', cross: 'y', sign: 1 };\n case 'left':\n return { rank: 'x', cross: 'y', sign: -1 };\n default:\n return { rank: 'y', cross: 'x', sign: 1 };\n }\n}\n\n/** A node's extent along one axis. */\nexport function extent(bounds: Bounds, axis: 'x' | 'y'): number {\n return axis === 'x' ? bounds.width : bounds.height;\n}\n\n/** A node's center along one axis — what within-rank order is seeded from. */\nexport function center(bounds: Bounds, axis: 'x' | 'y'): number {\n return axis === 'x' ? bounds.x + bounds.width / 2 : bounds.y + bounds.height / 2;\n}\n\n/** Every id layout must leave alone. */\nexport function pinnedSet(graph: Graph, opts: LayoutOptions = {}): Set<string> {\n const pinned = new Set<string>(opts.pin ?? []);\n for (const node of graph.nodes) {\n if (node.pinned) pinned.add(node.id);\n }\n return pinned;\n}\n\n/**\n * A placement in the canonical `(cross, rank)` frame, before it is turned into\n * world coordinates. `cross` and `rank` are the node's low corner along each.\n */\nexport interface Slot {\n cross: number;\n rank: number;\n}\n\n/**\n * Turn canonical slots into the positions to write.\n *\n * Three steps, in order: map the canonical frame onto the world axes the\n * direction names; translate the whole layout so it lands where the graph\n * already is; drop everything that is pinned or that would not move.\n *\n * The translation is what makes the layout non-destructive, and it is chosen so\n * that a second run lands on the same answer. With a pin, it is whatever keeps\n * the first pinned node exactly where it is. Without one, it is whatever puts\n * the layout's own bounding box where the graph's bounding box already starts —\n * which the first run then makes true, so the second run computes the same\n * translation and writes nothing.\n */\nexport function settle(\n graph: Graph,\n slots: ReadonlyMap<string, Slot>,\n opts: LayoutOptions = {},\n): LayoutResult {\n const axes = axesFor(opts.direction);\n const pinned = pinnedSet(graph, opts);\n const tolerance = opts.tolerance ?? DEFAULT_TOLERANCE;\n\n const placed = new Map<string, Vec2>();\n for (const node of graph.nodes) {\n const slot = slots.get(node.id);\n if (slot === undefined) continue;\n const along = axes.sign === 1 ? slot.rank : -(slot.rank + extent(node.bounds, axes.rank));\n placed.set(\n node.id,\n axes.rank === 'y' ? { x: slot.cross, y: along } : { x: along, y: slot.cross },\n );\n }\n\n return translated(graph, placed, pinned, tolerance);\n}\n\n/**\n * {@link settle}'s second half, for a layout that already works in world\n * coordinates — `force` does, since the integrator moves points around rather\n * than filling slots.\n */\nexport function translated(\n graph: Graph,\n placed: ReadonlyMap<string, Vec2>,\n pinned: ReadonlySet<string>,\n tolerance = DEFAULT_TOLERANCE,\n): LayoutResult {\n const anchor = anchorDelta(graph, placed, pinned);\n const out = new Map<string, Vec2>();\n for (const node of graph.nodes) {\n const at = placed.get(node.id);\n if (at === undefined || pinned.has(node.id)) continue;\n const x = at.x + anchor.x;\n const y = at.y + anchor.y;\n if (Math.abs(x - node.bounds.x) <= tolerance && Math.abs(y - node.bounds.y) <= tolerance) {\n continue;\n }\n out.set(node.id, { x, y });\n }\n return out;\n}\n\nfunction anchorDelta(\n graph: Graph,\n placed: ReadonlyMap<string, Vec2>,\n pinned: ReadonlySet<string>,\n): Vec2 {\n for (const node of graph.nodes) {\n if (!pinned.has(node.id)) continue;\n const at = placed.get(node.id);\n if (at !== undefined) return { x: node.bounds.x - at.x, y: node.bounds.y - at.y };\n }\n let minCurX = Infinity;\n let minCurY = Infinity;\n let minNewX = Infinity;\n let minNewY = Infinity;\n for (const node of graph.nodes) {\n const at = placed.get(node.id);\n if (at === undefined) continue;\n minCurX = Math.min(minCurX, node.bounds.x);\n minCurY = Math.min(minCurY, node.bounds.y);\n minNewX = Math.min(minNewX, at.x);\n minNewY = Math.min(minNewY, at.y);\n }\n if (!Number.isFinite(minCurX)) return { x: 0, y: 0 };\n return { x: minCurX - minNewX, y: minCurY - minNewY };\n}\n\n/**\n * Lay a list of nodes out along the cross axis, in the order given, and hand\n * back each one's low corner plus the total span.\n *\n * Shared by `layered`'s ranks and `tree`'s sibling rows, which pack a row the\n * same way and differ only in what decides the order.\n */\nexport function packAcross(\n nodes: readonly GraphNode[],\n axis: 'x' | 'y',\n gap: number,\n): { at: Map<string, number>; span: number } {\n const at = new Map<string, number>();\n let cursor = 0;\n for (const node of nodes) {\n at.set(node.id, cursor);\n cursor += extent(node.bounds, axis) + gap;\n }\n return { at, span: nodes.length === 0 ? 0 : cursor - gap };\n}\n\n/** Order within a rank: where the nodes already sit on the cross axis, with\n * graph order breaking a tie. Never a comparison that could reverse between\n * two runs on the same input. */\nexport function seededOrder(\n nodes: readonly GraphNode[],\n axis: 'x' | 'y',\n indexOf: (id: string) => number,\n): GraphNode[] {\n return [...nodes].sort((a, b) => {\n const d = center(a.bounds, axis) - center(b.bounds, axis);\n return d !== 0 ? d : indexOf(a.id) - indexOf(b.id);\n });\n}\n\n/** Each node's position in `graph.nodes`, for tiebreaks. */\nexport function graphOrder(graph: Graph): (id: string) => number {\n const index = new Map<string, number>();\n graph.nodes.forEach((node, i) => index.set(node.id, i));\n return (id) => index.get(id) ?? Number.MAX_SAFE_INTEGER;\n}\n","/**\n * `force` — relaxation, for a graph with no direction to read it in.\n *\n * Seeded from where the nodes already are rather than from a fresh random\n * scatter: an author who has arranged half a diagram gets that arrangement\n * relaxed, not replaced. There is no RNG in it at all — two coincident nodes\n * are separated along a golden-angle spiral keyed to their index, which is what\n * a random jiggle is for elsewhere.\n *\n * The integrator is the kit's own `createSimulation`, the same one\n * `useSimulation` runs a frame at a time. Only the forces are local, and they\n * are the naive O(n²) kind — right for the tens-to-hundreds of nodes an\n * edge-per-scene-node diagram is already sized for, wrong for a 10k-node graph,\n * which wants d3-force's Barnes–Hut through `useSimulation` and its own render\n * layer.\n *\n * **This is the one layout that is not idempotent.** A relaxation re-run from\n * its own output keeps relaxing; `direction` means nothing to it. Pins and the\n * `tolerance` option are what keep a second pass from scrambling a settled\n * diagram.\n */\nimport { createSimulation, type SimulationForce, type SimulationNode } from '@weasel-js/core/math';\nimport type { Graph } from './graph';\nimport {\n center,\n pinnedSet,\n translated,\n type LayoutFn,\n type LayoutOptions,\n type LayoutResult,\n} from './layout';\n\n/** Options for {@link force} and {@link forceRelaxation}. `direction` is\n * ignored. */\nexport interface ForceOptions extends LayoutOptions {\n /** Ticks to run. Default 300 — one full cooling schedule. */\n iterations?: number;\n /** Rest length of an edge, in world units. Default 160. */\n linkDistance?: number;\n /** How hard an edge pulls, 0..1. Default 0.35. */\n linkStrength?: number;\n /** Pairwise repulsion. Negative repels; default -3000. */\n charge?: number;\n /** How hard the graph is held around its own centroid. Default 0.02. */\n gravity?: number;\n /** Clear space kept between two boxes, in world units. Default 24. */\n padding?: number;\n}\n\n/** One node as the relaxation sees it: a simulation point centered on the\n * node's box. */\nexport interface ForceBody extends SimulationNode {\n id: string;\n /** Half the node's box, so separation can work on the shape the author sees\n * rather than on a point. */\n hw: number;\n hh: number;\n}\n\nconst DEFAULTS = {\n iterations: 300,\n linkDistance: 160,\n linkStrength: 0.35,\n charge: -3000,\n gravity: 0.02,\n padding: 24,\n} as const;\n\n/** The golden angle. Coincident nodes fan out along it, which spreads any\n * number of them without two landing on the same heading. */\nconst GOLDEN = Math.PI * (3 - Math.sqrt(5));\n/** How far the first coincident node is pushed, in world units. Small enough\n * to be invisible, large enough that the repulsion term is finite. */\nconst NUDGE = 0.5;\n\n/** Pairwise repulsion, applied to every pair once. */\nfunction charge(bodies: readonly ForceBody[], strength: number): SimulationForce<ForceBody> {\n return (alpha) => {\n for (let i = 0; i < bodies.length; i++) {\n const a = bodies[i]!;\n for (let j = i + 1; j < bodies.length; j++) {\n const b = bodies[j]!;\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const d2 = dx * dx + dy * dy;\n if (d2 === 0) continue;\n const w = (strength * alpha) / d2;\n a.vx! += dx * w;\n a.vy! += dy * w;\n b.vx! -= dx * w;\n b.vy! -= dy * w;\n }\n }\n };\n}\n\n/** A spring per edge, pulling both ends toward `distance`. */\nfunction links(\n bodies: ReadonlyMap<string, ForceBody>,\n graph: Graph,\n distance: number,\n strength: number,\n): SimulationForce<ForceBody> {\n return (alpha) => {\n for (const edge of graph.edges) {\n const a = bodies.get(edge.from);\n const b = bodies.get(edge.to);\n if (a === undefined || b === undefined || a === b) continue;\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const d = Math.hypot(dx, dy);\n if (d === 0) continue;\n const pull = ((d - distance) / d) * alpha * strength;\n a.vx! += dx * pull;\n a.vy! += dy * pull;\n b.vx! -= dx * pull;\n b.vy! -= dy * pull;\n }\n };\n}\n\n/**\n * Push overlapping boxes apart along whichever axis they overlap least.\n *\n * Charge alone is not enough: it treats a node as a point, so two wide boxes\n * whose centers are a comfortable distance apart still cover each other. This\n * works on the box, and it is not scaled by alpha — an overlap at the end of\n * the run is exactly as wrong as one at the start.\n */\nfunction separateBoxes(bodies: readonly ForceBody[], padding: number): SimulationForce<ForceBody> {\n return () => {\n for (let i = 0; i < bodies.length; i++) {\n const a = bodies[i]!;\n for (let j = i + 1; j < bodies.length; j++) {\n const b = bodies[j]!;\n const dx = b.x - a.x;\n const dy = b.y - a.y;\n const gapX = a.hw + b.hw + padding - Math.abs(dx);\n const gapY = a.hh + b.hh + padding - Math.abs(dy);\n if (gapX <= 0 || gapY <= 0) continue;\n if (gapX < gapY) {\n const push = (Math.sign(dx) || 1) * gapX * 0.5;\n a.vx! -= push;\n b.vx! += push;\n } else {\n const push = (Math.sign(dy) || 1) * gapY * 0.5;\n a.vy! -= push;\n b.vy! += push;\n }\n }\n }\n };\n}\n\n/** A pull toward the seed centroid, so a component with nothing to hold it\n * does not drift off under pure repulsion. */\nfunction gravity(bodies: readonly ForceBody[], at: { x: number; y: number }, strength: number): SimulationForce<ForceBody> {\n return (alpha) => {\n for (const body of bodies) {\n body.vx! += (at.x - body.x) * strength * alpha;\n body.vy! += (at.y - body.y) * strength * alpha;\n }\n };\n}\n\n/**\n * The bodies and the force list, wound up and ready to tick.\n *\n * Shared by the one-shot `force` below and the live relaxation in `live.ts`,\n * which ticks it a frame at a time. Two copies of a force list drift, and the\n * only thing that would say so is the arrangement they produce.\n */\nexport interface ForceRelaxation {\n bodies: ForceBody[];\n byId: Map<string, ForceBody>;\n /** Ids the caller must not move: declared pins, held as `fx`/`fy`. */\n pinned: ReadonlySet<string>;\n sim: ReturnType<typeof createSimulation<ForceBody>>;\n /** Where a body's node's top-left sits, given the body's center. */\n placed(): Map<string, { x: number; y: number }>;\n}\n\n/** Wind up a relaxation of `graph` without ticking it: bodies seeded from\n * where the nodes are, pins held fixed. Tick `sim` yourself and read the\n * top-lefts from `placed()`. */\nexport function forceRelaxation(graph: Graph, opts: ForceOptions = {}): ForceRelaxation {\n const {\n linkDistance = DEFAULTS.linkDistance,\n linkStrength = DEFAULTS.linkStrength,\n charge: chargeStrength = DEFAULTS.charge,\n gravity: gravityStrength = DEFAULTS.gravity,\n padding = DEFAULTS.padding,\n } = opts;\n\n const pinned = pinnedSet(graph, opts);\n const bodies: ForceBody[] = graph.nodes.map((node) => {\n const body: ForceBody = {\n id: node.id,\n x: center(node.bounds, 'x'),\n y: center(node.bounds, 'y'),\n hw: node.bounds.width / 2,\n hh: node.bounds.height / 2,\n };\n // A pin is the integrator's own `fx`/`fy`, not a filter applied after the\n // fact: a pinned node has to hold its neighbors while they relax, not be\n // put back once they have finished relaxing around where it wasn't.\n if (pinned.has(node.id)) {\n body.fx = body.x;\n body.fy = body.y;\n }\n return body;\n });\n separate(bodies);\n\n const byId = new Map(bodies.map((b) => [b.id, b]));\n const centroid = {\n x: bodies.reduce((sum, b) => sum + b.x, 0) / bodies.length,\n y: bodies.reduce((sum, b) => sum + b.y, 0) / bodies.length,\n };\n\n const sim = createSimulation<ForceBody>({\n nodes: bodies,\n forces: [\n charge(bodies, chargeStrength),\n links(byId, graph, linkDistance, linkStrength),\n gravity(bodies, centroid, gravityStrength),\n separateBoxes(bodies, padding),\n ],\n });\n\n return {\n bodies,\n byId,\n pinned,\n sim,\n placed() {\n const placed = new Map<string, { x: number; y: number }>();\n for (const node of graph.nodes) {\n const body = byId.get(node.id)!;\n placed.set(node.id, {\n x: body.x - node.bounds.width / 2,\n y: body.y - node.bounds.height / 2,\n });\n }\n return placed;\n },\n };\n}\n\n/** The force-directed layout. Unlike the others it is not idempotent: a\n * re-run keeps relaxing, so pins and `tolerance` are what hold a settled\n * diagram still. */\nexport const force = (graph: Graph, opts: ForceOptions = {}): LayoutResult => {\n if (graph.nodes.length === 0) return new Map();\n const relaxation = forceRelaxation(graph, opts);\n relaxation.sim.tick(opts.iterations ?? DEFAULTS.iterations);\n return translated(graph, relaxation.placed(), relaxation.pinned, opts.tolerance);\n};\n\n/** `ForceOptions` only widens `LayoutOptions`, so this is a `LayoutFn` — but\n * declaring it as one would hide the extra options from every caller. */\nforce satisfies LayoutFn;\n\n/** Push coincident bodies apart, deterministically. Two nodes at exactly the\n * same point feel no repulsion from each other and stay stacked forever. A\n * pinned body is counted but never moved — a pin outranks this. */\nfunction separate(bodies: ForceBody[]): void {\n const seen = new Map<string, number>();\n bodies.forEach((body, i) => {\n const key = `${body.x},${body.y}`;\n const nth = seen.get(key) ?? 0;\n seen.set(key, nth + 1);\n if (nth === 0 || body.fx != null || body.fy != null) return;\n const angle = GOLDEN * i;\n const radius = NUDGE * nth;\n body.x += Math.cos(angle) * radius;\n body.y += Math.sin(angle) * radius;\n });\n}\n","/**\n * `layered` — ranks running one way, nodes running across.\n *\n * The flowchart / pipeline layout: an edge points from one rank to the next, so\n * reading down the page is reading the order things happen in. Ranks come from\n * longest-path layering, which puts every node as far along as its deepest\n * predecessor allows.\n *\n * Cycles do not disqualify a graph. A depth-first walk in graph order names the\n * edges that close a cycle, layering ignores those, and they draw as edges\n * running back up the page — which is what a reader expects a loop to look\n * like. Which edges get named depends only on the node order, so it is the same\n * every run.\n *\n * This is not crossing-minimization: within a rank, nodes keep the order they\n * already have on the cross axis. An author who dragged two branches into an\n * order gets that order back, and re-running the layout is free.\n */\nimport type { Graph, GraphNode } from './graph';\nimport {\n DEFAULT_NODE_GAP,\n DEFAULT_RANK_GAP,\n axesFor,\n extent,\n graphOrder,\n packAcross,\n seededOrder,\n settle,\n type LayoutFn,\n type Slot,\n} from './layout';\n\n/** Edge ids that close a cycle, found by a depth-first walk in graph order. */\nexport function backEdges(graph: Graph): Set<string> {\n const back = new Set<string>();\n const done = new Set<string>();\n const onStack = new Set<string>();\n\n const walk = (id: string): void => {\n if (done.has(id)) return;\n onStack.add(id);\n for (const edge of graph.outgoing(id)) {\n if (onStack.has(edge.to)) back.add(edge.id);\n else walk(edge.to);\n }\n onStack.delete(id);\n done.add(id);\n };\n\n for (const node of graph.nodes) walk(node.id);\n return back;\n}\n\n/** Longest-path rank per node: one past its deepest predecessor. */\nexport function ranksOf(graph: Graph, back: ReadonlySet<string>): Map<string, number> {\n const ranks = new Map<string, number>();\n const resolving = new Set<string>();\n\n const rankOf = (id: string): number => {\n const known = ranks.get(id);\n if (known !== undefined) return known;\n // Only reachable if `back` missed an edge; guarding here keeps a bad\n // cycle-breaker from recursing forever rather than reporting a wrong rank.\n if (resolving.has(id)) return 0;\n resolving.add(id);\n let rank = 0;\n for (const edge of graph.incoming(id)) {\n if (back.has(edge.id)) continue;\n rank = Math.max(rank, rankOf(edge.from) + 1);\n }\n resolving.delete(id);\n ranks.set(id, rank);\n return rank;\n };\n\n for (const node of graph.nodes) rankOf(node.id);\n return ranks;\n}\n\n/** The ranked layout: each edge points one rank further along `direction`.\n * Within a rank, nodes keep their current cross-axis order, so a re-run\n * moves nothing. */\nexport const layered: LayoutFn = (graph, opts = {}) => {\n const axes = axesFor(opts.direction);\n const nodeGap = opts.nodeGap ?? DEFAULT_NODE_GAP;\n const rankGap = opts.rankGap ?? DEFAULT_RANK_GAP;\n const order = graphOrder(graph);\n\n const ranks = ranksOf(graph, backEdges(graph));\n const byRank = new Map<number, GraphNode[]>();\n for (const node of graph.nodes) {\n const rank = ranks.get(node.id) ?? 0;\n const list = byRank.get(rank);\n if (list === undefined) byRank.set(rank, [node]);\n else list.push(node);\n }\n\n const rows = [...byRank.keys()].sort((a, b) => a - b);\n const packed = new Map<number, ReturnType<typeof packAcross>>();\n let widest = 0;\n for (const rank of rows) {\n const row = seededOrder(byRank.get(rank)!, axes.cross, order);\n const p = packAcross(row, axes.cross, nodeGap);\n packed.set(rank, p);\n widest = Math.max(widest, p.span);\n }\n\n const slots = new Map<string, Slot>();\n let along = 0;\n for (const rank of rows) {\n const row = byRank.get(rank)!;\n const p = packed.get(rank)!;\n const indent = (widest - p.span) / 2;\n const depth = Math.max(0, ...row.map((n) => extent(n.bounds, axes.rank)));\n for (const node of row) {\n slots.set(node.id, {\n cross: indent + p.at.get(node.id)!,\n // Centered in its rank's band, so a tall node does not push its\n // neighbors' edges off the line they read along.\n rank: along + (depth - extent(node.bounds, axes.rank)) / 2,\n });\n }\n along += depth + rankGap;\n }\n\n return settle(graph, slots, opts);\n};\n","/**\n * `tree` — a parent centered over the block its children occupy.\n *\n * The hierarchy layout: org charts, file trees, decision trees. Depth is the\n * rank axis, so every child sits one band past its parent, and a subtree is\n * packed as a solid block so two siblings' descendants never interleave.\n *\n * A graph that is not a tree still lays out. Roots are the nodes nothing points\n * at, in graph order; a node reachable from two parents belongs to whichever\n * the depth-first walk reaches first; and anything the walk never reaches — a\n * disconnected part, or a pure cycle — becomes a root of its own. So the answer\n * is always a forest, and which forest depends only on the node order.\n *\n * The block packing is deliberately not Reingold–Tilford: it never slides a\n * deep subtree under a shallow neighbor's overhang. That costs horizontal\n * space and buys an invariant an author can rely on — a subtree's extent is a\n * rectangle, and dragging one never lands it inside another.\n */\nimport type { Graph, GraphNode } from './graph';\nimport {\n DEFAULT_NODE_GAP,\n DEFAULT_RANK_GAP,\n axesFor,\n extent,\n graphOrder,\n seededOrder,\n settle,\n type LayoutFn,\n type Slot,\n} from './layout';\n\ninterface Forest {\n roots: GraphNode[];\n children: Map<string, GraphNode[]>;\n depth: Map<string, number>;\n}\n\n/** The forest a depth-first walk in graph order finds. Exported because \"which\n * node ended up whose child\" is the question anyone debugging a tree layout\n * asks first. */\nexport function forestOf(graph: Graph, crossAxis: 'x' | 'y'): Forest {\n const order = graphOrder(graph);\n const children = new Map<string, GraphNode[]>();\n const depth = new Map<string, number>();\n const roots: GraphNode[] = [];\n\n const claim = (node: GraphNode, at: number): void => {\n depth.set(node.id, at);\n const kids: GraphNode[] = [];\n for (const edge of graph.outgoing(node.id)) {\n if (edge.to === node.id || depth.has(edge.to)) continue;\n const child = graph.node(edge.to);\n if (child === undefined) continue;\n // Claimed on sight rather than inside the recursion, so two siblings\n // sharing a descendant cannot both take it.\n depth.set(child.id, at + 1);\n kids.push(child);\n }\n const ordered = seededOrder(kids, crossAxis, order);\n children.set(node.id, ordered);\n for (const child of ordered) claim(child, at + 1);\n };\n\n const rootish = graph.nodes.filter((node) =>\n graph.incoming(node.id).every((edge) => edge.from === node.id));\n for (const node of seededOrder(rootish, crossAxis, order)) {\n if (depth.has(node.id)) continue;\n roots.push(node);\n claim(node, 0);\n }\n // Whatever the walk could not reach: a disconnected part, or a component\n // every node of which is inside a cycle.\n for (const node of graph.nodes) {\n if (depth.has(node.id)) continue;\n roots.push(node);\n claim(node, 0);\n }\n\n return { roots, children, depth };\n}\n\n/** The hierarchy layout: each parent centered over its children's block, one\n * rank per depth. A graph that is not a tree lays out as the forest\n * {@link forestOf} reads from it. */\nexport const tree: LayoutFn = (graph, opts = {}) => {\n const axes = axesFor(opts.direction);\n const nodeGap = opts.nodeGap ?? DEFAULT_NODE_GAP;\n const rankGap = opts.rankGap ?? DEFAULT_RANK_GAP;\n const { roots, children, depth } = forestOf(graph, axes.cross);\n\n const bands = new Map<number, number>();\n for (const node of graph.nodes) {\n const at = depth.get(node.id) ?? 0;\n bands.set(at, Math.max(bands.get(at) ?? 0, extent(node.bounds, axes.rank)));\n }\n const bandStart = new Map<number, number>();\n let along = 0;\n for (const at of [...bands.keys()].sort((a, b) => a - b)) {\n bandStart.set(at, along);\n along += bands.get(at)! + rankGap;\n }\n\n const slots = new Map<string, Slot>();\n\n /** How wide `node`'s whole subtree is on the cross axis: its children's\n * blocks side by side, or the node itself when that is wider. */\n const measured = new Map<string, number>();\n const measure = (node: GraphNode): number => {\n const known = measured.get(node.id);\n if (known !== undefined) return known;\n const kids = children.get(node.id) ?? [];\n let width = 0;\n for (const child of kids) width += measure(child);\n if (kids.length > 0) width += nodeGap * (kids.length - 1);\n const block = Math.max(extent(node.bounds, axes.cross), width);\n measured.set(node.id, block);\n return block;\n };\n\n /** Place `node`'s subtree with its block starting at `from`. */\n const place = (node: GraphNode, from: number): void => {\n const kids = children.get(node.id) ?? [];\n const block = measure(node);\n const width = kids.reduce((sum, k) => sum + measure(k), 0)\n + Math.max(0, kids.length - 1) * nodeGap;\n\n let cursor = from + (block - width) / 2;\n for (const child of kids) {\n place(child, cursor);\n cursor += measure(child) + nodeGap;\n }\n\n const own = extent(node.bounds, axes.cross);\n const at = depth.get(node.id) ?? 0;\n slots.set(node.id, {\n cross: from + (block - own) / 2,\n rank: bandStart.get(at)! + (bands.get(at)! - extent(node.bounds, axes.rank)) / 2,\n });\n };\n\n let cursor = 0;\n for (const root of roots) {\n place(root, cursor);\n cursor += measure(root) + nodeGap;\n }\n\n return settle(graph, slots, opts);\n};\n"]}
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { P as Port, a as PortsOptions, D as DiagramNodeLike, b as DiagramNodeReader, L as LayoutFn, c as LayoutOptions, F as ForceOptions, d as LayoutResult, G as GraphSource, e as Graph } from './layout.entry-C0twMfuH.js';
2
- export { B as BodyFloor, f as BodyNodeSpec, g as BodySpec, h as Bounds, i as BuildBodyOptions, j as BuildGraphOptions, C as COMPASS, k as DEFAULT_NODE_GAP, l as DEFAULT_PORTS, m as DEFAULT_RANK_GAP, n as DIAGRAM_TRAIT_KEY, o as DiagramNode, p as DiagramNodeEntry, q as ForceRelaxation, r as GraphEdge, s as GraphNode, t as GraphNodeLike, u as LayoutAxes, v as LayoutDirection, M as MeasureRowText, O as Outline, w as PortAnchor, x as PortSpec, R as Row, y as RowBox, z as RowNodeData, A as RowPort, E as RowPortBox, H as RowTextStyle, S as Slot, I as axesFor, J as backEdges, K as bodyOutline, N as bodyTrait, Q as boxForContent, T as buildBody, U as buildGraph, V as canvasMeasure, W as contentBox, X as createDiagramNodes, Y as dataKeyReader, Z as diagramNodeOf, _ as force, $ as forceRelaxation, a0 as forestOf, a1 as graphOrder, a2 as isPinned, a3 as layered, a4 as layoutBody, a5 as layoutRowPorts, a6 as measureBody, a7 as outlinePath, a8 as outlinePolyline, a9 as packAcross, aa as pinnedSet, ab as portOf, ac as portsOf, ad as portsOnOutline, ae as ranksOf, af as rayHit, ag as seededOrder, ah as settle, ai as sizeToBody, aj as translated, ak as tree } from './layout.entry-C0twMfuH.js';
1
+ import { P as Port, a as PortsOptions, D as DiagramNodeLike, b as DiagramNodeReader, L as LayoutFn, c as LayoutOptions, F as ForceOptions, d as LayoutResult, G as GraphSource, e as Graph } from './layout.entry-BvR06k9j.js';
2
+ export { B as BodyFloor, f as BodyNodeSpec, g as BodySpec, h as Bounds, i as BuildBodyOptions, j as BuildGraphOptions, C as COMPASS, k as DEFAULT_NODE_GAP, l as DEFAULT_PORTS, m as DEFAULT_RANK_GAP, n as DIAGRAM_TRAIT_KEY, o as DiagramNode, p as DiagramNodeEntry, q as ForceBody, r as ForceRelaxation, s as GraphEdge, t as GraphNode, u as GraphNodeLike, v as LayoutAxes, w as LayoutDirection, M as MeasureRowText, O as Outline, x as PortAnchor, y as PortSpec, R as Row, z as RowBox, A as RowNodeData, E as RowPort, H as RowPortBox, I as RowTextStyle, S as Slot, J as axesFor, K as backEdges, N as bodyOutline, Q as bodyTrait, T as boxForContent, U as buildBody, V as buildGraph, W as canvasMeasure, X as contentBox, Y as createDiagramNodes, Z as dataKeyReader, _ as diagramNodeOf, $ as force, a0 as forceRelaxation, a1 as forestOf, a2 as graphOrder, a3 as isPinned, a4 as layered, a5 as layoutBody, a6 as layoutRowPorts, a7 as measureBody, a8 as outlinePath, a9 as outlinePolyline, aa as packAcross, ab as pinnedSet, ac as portOf, ad as portsOf, ae as portsOnOutline, af as ranksOf, ag as rayHit, ah as seededOrder, ai as settle, aj as sizeToBody, ak as translated, al as tree } from './layout.entry-BvR06k9j.js';
3
3
  import { Vec2, DerivedDep, Path, SceneRegistry, PoseDescriptor, ChromeState, FillStyle, Stroke, CursorSpec, Affordance, InvocationCtx, GestureBinding, Action, Contribution, RenderLayer, EasingFn, NodeId, Scene, NodeShapeEntry } from '@weasel-js/core';
4
+ import '@weasel-js/geom';
4
5
  import '@weasel-js/core/math';
5
6
 
6
7
  /**
@@ -95,6 +96,7 @@ declare function diagramEdgeOf(node: {
95
96
  * that leaves through its own node reads as a bug however short it is.
96
97
  */
97
98
  declare function resolveEnd<TPose>(end: EdgeEnd, dep: DerivedDep<TPose>, toward: Vec2, opts: PortsOptions<TPose>, allPorts: (d: DerivedDep<TPose>) => Port[]): Port | undefined;
99
+ /** Options for {@link edgeDerivePath}. */
98
100
  interface EdgeRouteOptions<TPose> extends PortsOptions<TPose> {
99
101
  /** Routers by key. Defaults to {@link ROUTERS}. */
100
102
  routers?: Readonly<Record<string, Router>>;
@@ -171,6 +173,8 @@ interface PortScratch {
171
173
  /** The port resolved at press time: where it was and which way it faces. */
172
174
  port: Port;
173
175
  }
176
+ /** Options for {@link createPortAffordance}: which ports show, and how they
177
+ * are painted and hit. */
174
178
  interface PortAffordanceOptions<TPose> {
175
179
  /** Also the chrome-caps visibility id. Default {@link PORT_LAYER_ID}. */
176
180
  id?: string;
@@ -252,6 +256,7 @@ interface PendingEdge {
252
256
  * masquerading as a rule.
253
257
  */
254
258
  declare const defaultCanConnect: CanConnect;
259
+ /** Options for {@link createConnectAction}. Only `participants` is required. */
255
260
  interface ConnectActionOptions<TPose> {
256
261
  /** Where the droppable ports come from. The same source the port affordance
257
262
  * reads, so what is grabbable and what is landable cannot disagree. */
@@ -345,6 +350,7 @@ declare function createConnectAction<TPose>(opts: ConnectActionOptions<TPose>):
345
350
  * the two cannot be wired half-way.
346
351
  */
347
352
 
353
+ /** The connect action's options and the port affordance's, in one bag. */
348
354
  interface DiagramContributionOptions<TPose> extends ConnectActionOptions<TPose>, PortAffordanceOptions<TPose> {
349
355
  }
350
356
  /** The bundle: the connect action and the one binding that reaches it. */
@@ -386,6 +392,8 @@ interface DiagramLabel {
386
392
  declare function diagramLabelOf(node: {
387
393
  data: unknown;
388
394
  }): DiagramLabel | null;
395
+ /** Options for {@link labelDerivePose}. `geometry` defaults to the kit's
396
+ * `AUTO_POSE_DESCRIPTOR`. */
389
397
  interface LabelPoseOptions<TPose> {
390
398
  geometry?: PoseDescriptor<TPose>;
391
399
  }
@@ -423,15 +431,28 @@ interface LiveLayoutFrame {
423
431
  result: LayoutResult;
424
432
  done: boolean;
425
433
  }
434
+ /** One frame of a live layout, called once per frame until it reports `done`. */
426
435
  type LiveLayoutProducer<TPose> = (ctx: LiveLayoutCtx<TPose>) => LiveLayoutFrame;
436
+ /** Options for {@link forceProducer}. */
427
437
  interface ForceProducerOptions<TPose> extends ForceOptions {
428
438
  geometry?: PoseDescriptor<TPose>;
429
439
  /** Alpha held while something is pinned, so the graph keeps answering a drag
430
440
  * instead of freezing under it. Default 0.3. */
431
441
  dragAlpha?: number;
442
+ /** The run is at rest once no node moves this far in a tick, in world units.
443
+ * Default 0.1. `0` never rests, leaving the run to the cooling schedule. */
444
+ restDistance?: number;
445
+ /** Consecutive ticks at rest before the run finishes. Default 5. */
446
+ restTicks?: number;
432
447
  }
433
448
  /**
434
- * A relaxation, one tick a frame, done when the simulation settles.
449
+ * A relaxation, one tick a frame, done when the graph stops moving.
450
+ *
451
+ * Motion ends long before alpha cools — a few dozen ticks against three
452
+ * hundred — so a run that waited for alpha would sit visibly still for
453
+ * seconds while still reporting itself running. It finishes on whichever
454
+ * comes first: `restTicks` ticks in a row with no node moving `restDistance`,
455
+ * or the cooling schedule running out. Nothing rests while a node is held.
435
456
  *
436
457
  * The forces are `forceRelaxation`'s — the same ones the one-shot `force`
437
458
  * runs, wound up once here and ticked rather than run to completion.
@@ -444,6 +465,7 @@ interface ForceProducerOptions<TPose> extends ForceOptions {
444
465
  * nodes were, and a pinned node is deliberately somewhere else.
445
466
  */
446
467
  declare function forceProducer<TPose>(graph: Graph, opts?: ForceProducerOptions<TPose>): LiveLayoutProducer<TPose>;
468
+ /** Options for {@link easedProducer}. */
447
469
  interface EasedProducerOptions {
448
470
  layout?: LayoutOptions;
449
471
  /** Frames to arrive in. Default 24. */
@@ -459,6 +481,7 @@ interface EasedProducerOptions {
459
481
  * over.
460
482
  */
461
483
  declare function easedProducer<TPose>(graph: Graph, algorithm: LayoutFn, opts?: EasedProducerOptions): LiveLayoutProducer<TPose>;
484
+ /** Options for {@link useLiveLayout}. Only `scene` and `source` are required. */
462
485
  interface UseLiveLayoutOptions<TPose> {
463
486
  scene: Scene<unknown, string, TPose>;
464
487
  /** Where the graph is read from. The same thunk the port affordance takes. */
@@ -467,7 +490,8 @@ interface UseLiveLayoutOptions<TPose> {
467
490
  * continuously; anything else eases to its answer. Default `'force'`. */
468
491
  algorithm?: string | LayoutFn;
469
492
  layout?: LayoutOptions;
470
- force?: ForceOptions;
493
+ /** The relaxation's forces, and when a live run of it counts as at rest. */
494
+ force?: Omit<ForceProducerOptions<TPose>, 'geometry'>;
471
495
  /** Frames an eased layout takes to arrive. Default 24. */
472
496
  frames?: number;
473
497
  easing?: EasingFn;
@@ -485,6 +509,7 @@ interface UseLiveLayoutOptions<TPose> {
485
509
  requestFrame?: (cb: (t: number) => void) => number;
486
510
  cancelFrame?: (handle: number) => void;
487
511
  }
512
+ /** Controls for a live layout run, from {@link useLiveLayout}. */
488
513
  interface LiveLayout {
489
514
  /** Heat and run. Idempotent while running. */
490
515
  start(): void;
@@ -519,6 +544,7 @@ declare const EASED_LAYOUTS: Readonly<Record<string, LayoutFn>>;
519
544
 
520
545
  /** The layouts this package ships. A consumer's own go in the same shape. */
521
546
  declare const LAYOUTS: Readonly<Record<string, LayoutFn>>;
547
+ /** Options for {@link applyLayout}. */
522
548
  interface ApplyLayoutOptions<TPose> {
523
549
  geometry?: PoseDescriptor<TPose>;
524
550
  /** The undo entry's name. Default `'Layout'`. */
@@ -551,6 +577,7 @@ declare function applyLayout<TPose>(scene: Scene<unknown, string, TPose>, result
551
577
  declare function layoutPoses<TPose>(scene: Scene<unknown, string, TPose>, result: LayoutResult, geometry?: PoseDescriptor<TPose>): Map<string, TPose>;
552
578
  /** The default action id. */
553
579
  declare const LAYOUT_ACTION_ID = "diagram.layout";
580
+ /** Options for {@link createLayoutAction}. Only `source` is required. */
554
581
  interface LayoutActionOptions<TPose> {
555
582
  /** Where the graph is read from. The same thunk the port affordance takes. */
556
583
  source: GraphSource<TPose>;
@@ -642,6 +669,7 @@ declare function portLayer<TPose>(participants: ParticipantSource<TPose>, opts?:
642
669
  * editing, selection and styling work on them without a special case.
643
670
  */
644
671
 
672
+ /** Options for {@link diagramShape} and {@link registerDiagramShape}. */
645
673
  interface DiagramShapeOptions<TPose> {
646
674
  /** Distinguishes one registration from another, and is what the disposer
647
675
  * removes. Default `'diagram:outline'`. */
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { portOf, portsOf, diagramNodeOf, force, tree, layered, forceRelaxation, center, outlinePath } from './chunk-AD7TY6TK.js';
2
- export { COMPASS, DEFAULT_NODE_GAP, DEFAULT_PORTS, DEFAULT_RANK_GAP, DIAGRAM_TRAIT_KEY, axesFor, backEdges, bodyOutline, bodyTrait, boxForContent, buildBody, canvasMeasure, contentBox, createDiagramNodes, dataKeyReader, diagramNodeOf, force, forceRelaxation, forestOf, graphOrder, isPinned, layered, layoutBody, layoutRowPorts, measureBody, outlinePath, outlinePolyline, packAcross, pinnedSet, portOf, portsOf, portsOnOutline, ranksOf, rayHit, seededOrder, settle, sizeToBody, translated, tree } from './chunk-AD7TY6TK.js';
3
- import { AUTO_POSE_DESCRIPTOR, pointAlongPath, translatePoseViaDescriptor, polylineFromPoints, effectivePose, composeAffordanceLayer, usePoseRun, RECT_POSE_DESCRIPTOR, registerNodeShape } from '@weasel-js/core';
1
+ import { portOf, portsOf, diagramNodeOf, force, tree, layered, forceRelaxation, center, outlinePath } from './chunk-4KXQABRM.js';
2
+ export { COMPASS, DEFAULT_NODE_GAP, DEFAULT_PORTS, DEFAULT_RANK_GAP, DIAGRAM_TRAIT_KEY, axesFor, backEdges, bodyOutline, bodyTrait, boxForContent, buildBody, canvasMeasure, contentBox, createDiagramNodes, dataKeyReader, diagramNodeOf, force, forceRelaxation, forestOf, graphOrder, isPinned, layered, layoutBody, layoutRowPorts, measureBody, outlinePath, outlinePolyline, packAcross, pinnedSet, portOf, portsOf, portsOnOutline, ranksOf, rayHit, seededOrder, settle, sizeToBody, translated, tree } from './chunk-4KXQABRM.js';
3
+ import { AUTO_POSE_DESCRIPTOR, pointAlongPath, translatePoseViaDescriptor, polylineFromPoints, effectivePose, composeAffordanceLayer, useLatest, usePoseRun, RECT_POSE_DESCRIPTOR, registerNodeShape } from '@weasel-js/core';
4
4
  import { portCurvePoints } from '@weasel-js/geom';
5
5
  import { AUTO_POSE_DESCRIPTOR as AUTO_POSE_DESCRIPTOR$1 } from '@weasel-js/core/math';
6
6
  import { useRef, useCallback, useEffect, useMemo } from 'react';
@@ -515,10 +515,16 @@ function createLayoutAction(opts) {
515
515
  // src/live.ts
516
516
  var EASE_FRAMES = 24;
517
517
  var easeInOut = (t) => t < 0.5 ? 2 * t * t : 1 - (-2 * t + 2) ** 2 / 2;
518
+ var REST_DISTANCE = 0.1;
519
+ var REST_TICKS = 5;
518
520
  function forceProducer(graph, opts = {}) {
519
521
  const geometry = opts.geometry ?? AUTO_POSE_DESCRIPTOR;
520
522
  const relaxation = forceRelaxation(graph, opts);
521
523
  const dragAlpha = opts.dragAlpha ?? 0.3;
524
+ const restDistance = opts.restDistance ?? REST_DISTANCE;
525
+ const restTicks = opts.restTicks ?? REST_TICKS;
526
+ const was = relaxation.bodies.map((b) => ({ x: b.x, y: b.y }));
527
+ let still = 0;
522
528
  return ({ pinned }) => {
523
529
  for (const node of graph.nodes) {
524
530
  const body = relaxation.byId.get(node.id);
@@ -535,7 +541,16 @@ function forceProducer(graph, opts = {}) {
535
541
  }
536
542
  relaxation.sim.alphaTarget(pinned.size > 0 ? dragAlpha : 0);
537
543
  relaxation.sim.tick();
538
- return { result: relaxation.placed(), done: relaxation.sim.isSettled() };
544
+ let moved = 0;
545
+ relaxation.bodies.forEach((body, i) => {
546
+ const at = was[i];
547
+ moved = Math.max(moved, Math.hypot(body.x - at.x, body.y - at.y));
548
+ at.x = body.x;
549
+ at.y = body.y;
550
+ });
551
+ still = pinned.size === 0 && moved < restDistance ? still + 1 : 0;
552
+ const done = still >= restTicks || relaxation.sim.isSettled();
553
+ return { result: relaxation.placed(), done };
539
554
  };
540
555
  }
541
556
  function easedProducer(graph, algorithm, opts = {}) {
@@ -566,8 +581,7 @@ function shapeOf(graph) {
566
581
  return `${nodes}|${edges}`;
567
582
  }
568
583
  function useLiveLayout(opts) {
569
- const optsRef = useRef(opts);
570
- optsRef.current = opts;
584
+ const optsRef = useLatest(opts);
571
585
  const producer = useRef(null);
572
586
  const producerFrame = useRef(0);
573
587
  const shape = useRef("");
@@ -594,7 +608,7 @@ function useLiveLayout(opts) {
594
608
  ...o.frames === void 0 ? {} : { frames: o.frames },
595
609
  ...o.easing ? { easing: o.easing } : {}
596
610
  });
597
- }, []);
611
+ }, [optsRef]);
598
612
  const step = useCallback((ctx) => {
599
613
  const o = optsRef.current;
600
614
  if (producer.current === null) return { poses: [], done: true };
@@ -610,7 +624,7 @@ function useLiveLayout(opts) {
610
624
  }
611
625
  const poses = layoutPoses(o.scene, placed, o.geometry);
612
626
  return { poses: [...poses], done };
613
- }, []);
627
+ }, [optsRef]);
614
628
  const run = usePoseRun({
615
629
  scene: opts.scene,
616
630
  step,
@@ -631,7 +645,7 @@ function useLiveLayout(opts) {
631
645
  if (shapeOf(graph) === shape.current) return;
632
646
  build();
633
647
  });
634
- }, [opts.scene, opts.reheatOnGraphChange, run, build]);
648
+ }, [opts.scene, opts.reheatOnGraphChange, run, build, optsRef]);
635
649
  return useMemo(() => ({
636
650
  start() {
637
651
  if (run.isRunning()) return;