@vielzeug/wire 0.0.0-stage → 26.11.23

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.
Files changed (69) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -2
  3. package/dist/_format.cjs +2 -0
  4. package/dist/_format.cjs.map +1 -0
  5. package/dist/_format.d.ts +3 -0
  6. package/dist/_format.d.ts.map +1 -0
  7. package/dist/_format.js +8 -0
  8. package/dist/_format.js.map +1 -0
  9. package/dist/_heap.cjs +2 -0
  10. package/dist/_heap.cjs.map +1 -0
  11. package/dist/_heap.d.ts +12 -0
  12. package/dist/_heap.d.ts.map +1 -0
  13. package/dist/_heap.js +37 -0
  14. package/dist/_heap.js.map +1 -0
  15. package/dist/_sides.cjs +2 -0
  16. package/dist/_sides.cjs.map +1 -0
  17. package/dist/_sides.d.ts +20 -0
  18. package/dist/_sides.d.ts.map +1 -0
  19. package/dist/_sides.js +55 -0
  20. package/dist/_sides.js.map +1 -0
  21. package/dist/bezier.cjs +2 -0
  22. package/dist/bezier.cjs.map +1 -0
  23. package/dist/bezier.d.ts +14 -0
  24. package/dist/bezier.d.ts.map +1 -0
  25. package/dist/bezier.js +30 -0
  26. package/dist/bezier.js.map +1 -0
  27. package/dist/errors.cjs +2 -0
  28. package/dist/errors.cjs.map +1 -0
  29. package/dist/errors.d.ts +11 -0
  30. package/dist/errors.d.ts.map +1 -0
  31. package/dist/errors.js +9 -0
  32. package/dist/errors.js.map +1 -0
  33. package/dist/graph.cjs +2 -0
  34. package/dist/graph.cjs.map +1 -0
  35. package/dist/graph.d.ts +21 -0
  36. package/dist/graph.d.ts.map +1 -0
  37. package/dist/graph.js +81 -0
  38. package/dist/graph.js.map +1 -0
  39. package/dist/index.cjs +1 -0
  40. package/dist/index.d.ts +8 -0
  41. package/dist/index.d.ts.map +1 -0
  42. package/dist/index.js +7 -0
  43. package/dist/orthogonal.cjs +2 -0
  44. package/dist/orthogonal.cjs.map +1 -0
  45. package/dist/orthogonal.d.ts +37 -0
  46. package/dist/orthogonal.d.ts.map +1 -0
  47. package/dist/orthogonal.js +122 -0
  48. package/dist/orthogonal.js.map +1 -0
  49. package/dist/path.cjs +2 -0
  50. package/dist/path.cjs.map +1 -0
  51. package/dist/path.d.ts +6 -0
  52. package/dist/path.d.ts.map +1 -0
  53. package/dist/path.js +18 -0
  54. package/dist/path.js.map +1 -0
  55. package/dist/ports.cjs +2 -0
  56. package/dist/ports.cjs.map +1 -0
  57. package/dist/ports.d.ts +9 -0
  58. package/dist/ports.d.ts.map +1 -0
  59. package/dist/ports.js +30 -0
  60. package/dist/ports.js.map +1 -0
  61. package/dist/types.d.ts +31 -0
  62. package/dist/types.d.ts.map +1 -0
  63. package/dist/wire.cjs +2 -0
  64. package/dist/wire.cjs.map +1 -0
  65. package/dist/wire.iife.js +2 -0
  66. package/dist/wire.iife.js.map +1 -0
  67. package/dist/wire.js +353 -0
  68. package/dist/wire.js.map +1 -0
  69. package/package.json +48 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.iife.js","names":["exports","SIDE_VECTOR","Dir","DELTA","SIDE_DIR","OPPOSITE","message","opts","DEFAULT_HANDLE_LENGTH","handleLength","options","fromVector","from","toVector","to","items","i","parent","parentItem","item","top","last","left","right","smallest","swap","index","id","nodeIds","edge","edges","count","outgoing","indegree","ready","order","node","next","remaining","selfLoop","lowLink","discovery","onStack","stack","cycles","time","work","root","frame","children","child","component","member","a","b","DIR_COUNT","rect","padding","obstacles","px","py","xLow","xHigh","yLow","yHigh","point","delta","dir","distance","owners","along","bendPenalty","stub","start","goal","startOwners","goalOwners","startOthers","goalOthers","fromDir","toDir","agreesWithStart","agreesWithGoal","freeSpan","vector","side","fromTip","toTip","routeStart","routeGoal","startDir","forbiddenIncoming","xs","ys","xLines","yLines","columns","rows","nodeCount","y","x","startNode","goalNode","stateCount","gScore","closed","open","startState","goalState","current","incoming","cx","cy","candidates","neighbor","nx","ny","step","bend","nextScore","nextState","nodes","state","points","prev","cur","rounded","value","first","parts","curve","offset"],"sources":["../src/_sides.ts","../src/errors.ts","../src/bezier.ts","../src/_heap.ts","../src/graph.ts","../src/orthogonal.ts","../src/_format.ts","../src/path.ts","../src/ports.ts"],"sourcesContent":["import type { Point, PortSide } from './types.js';\n\n/** Outward unit vector for each port side; shared by the routers. */\nexport const SIDE_VECTOR: Readonly<Record<PortSide, Point>> = {\n bottom: { x: 0, y: 1 },\n left: { x: -1, y: 0 },\n right: { x: 1, y: 0 },\n top: { x: 0, y: -1 },\n};\n\n/** Grid movement directions; `None` (0) marks a start state with no incoming direction. */\nexport const Dir = { Down: 4, Left: 1, None: 0, Right: 2, Up: 3 } as const;\nexport type Dir = (typeof Dir)[keyof typeof Dir];\n/** The four real movement directions, excluding the `None` sentinel. */\nexport type Move = Exclude<Dir, typeof Dir.None>;\n\n/** Unit steps per movement direction, in grid order. */\nexport const DELTA: Readonly<Record<Move, Point>> = {\n [Dir.Left]: { x: -1, y: 0 },\n [Dir.Right]: { x: 1, y: 0 },\n [Dir.Up]: { x: 0, y: -1 },\n [Dir.Down]: { x: 0, y: 1 },\n};\n\n/** Outward direction a port on the given side faces. */\nexport const SIDE_DIR: Readonly<Record<PortSide, Move>> = {\n bottom: Dir.Down,\n left: Dir.Left,\n right: Dir.Right,\n top: Dir.Up,\n};\n\nexport const OPPOSITE: Readonly<Record<Move, Move>> = {\n [Dir.Down]: Dir.Up,\n [Dir.Left]: Dir.Right,\n [Dir.Right]: Dir.Left,\n [Dir.Up]: Dir.Down,\n};\n","/** Base class for all wire errors. Use `instanceof WireError` to catch any wire-originated error. */\nexport class WireError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a graph operation receives an edge that references a node id outside the supplied node set. */\nexport class WireGraphError extends WireError {}\n\n/** Thrown when routing options are invalid, such as a negative `handleLength`, `padding`, `stub`, or `bendPenalty`. */\nexport class WireConfigError extends WireError {}\n","import { SIDE_VECTOR } from './_sides.js';\nimport { WireConfigError } from './errors.js';\nimport type { CubicBezier, PortAnchor } from './types.js';\n\n/** Default control-point distance for `bezierRoute()` when `handleLength` is omitted. */\nconst DEFAULT_HANDLE_LENGTH = 40;\n\n/** Configuration for `bezierRoute()`. */\nexport interface BezierRouteOptions {\n /** Distance each control point extends outward from its port along the port side. Defaults to 40. */\n handleLength?: number;\n}\n\n/**\n * Builds a cubic bezier segment between two ports.\n *\n * Control points extend outward from each port along its side, so the curve leaves\n * and enters ports perpendicular to the node edge.\n */\nexport function bezierRoute(from: PortAnchor, to: PortAnchor, options: BezierRouteOptions = {}): CubicBezier {\n const handleLength = options.handleLength ?? DEFAULT_HANDLE_LENGTH;\n if (!Number.isFinite(handleLength) || handleLength < 0) {\n throw new WireConfigError(\n `Bezier handleLength must be a finite non-negative number, received ${String(handleLength)}.`,\n );\n }\n\n const fromVector = SIDE_VECTOR[from.side];\n const toVector = SIDE_VECTOR[to.side];\n\n return {\n c1: { x: from.x + fromVector.x * handleLength, y: from.y + fromVector.y * handleLength },\n c2: { x: to.x + toVector.x * handleLength, y: to.y + toVector.y * handleLength },\n from: { x: from.x, y: from.y },\n to: { x: to.x, y: to.y },\n };\n}\n","/**\n * Binary min-heap ordered by a numeric key. Ties between equal keys resolve by heap\n * structure, which is fully determined by the push sequence, so extraction is\n * deterministic for identical input.\n */\nexport class MinHeap {\n private readonly items: { key: number; value: number }[] = [];\n\n get size(): number {\n return this.items.length;\n }\n\n push(key: number, value: number): void {\n const items = this.items;\n items.push({ key, value });\n let i = items.length - 1;\n while (i > 0) {\n const parent = (i - 1) >> 1;\n const parentItem = items[parent]!;\n const item = items[i]!;\n if (parentItem.key <= item.key) break;\n items[parent] = item;\n items[i] = parentItem;\n i = parent;\n }\n }\n\n pop(): number {\n const items = this.items;\n const top = items[0]!;\n const last = items.pop()!;\n if (items.length > 0) {\n items[0] = last;\n let i = 0;\n for (;;) {\n const left = i * 2 + 1;\n const right = left + 1;\n let smallest = i;\n if (left < items.length && items[left]!.key < items[smallest]!.key) smallest = left;\n if (right < items.length && items[right]!.key < items[smallest]!.key) smallest = right;\n if (smallest === i) break;\n const item = items[i]!;\n const swap = items[smallest]!;\n items[i] = swap;\n items[smallest] = item;\n i = smallest;\n }\n }\n return top.value;\n }\n}\n","import { MinHeap } from './_heap.js';\nimport { WireGraphError } from './errors.js';\nimport type { Edge } from './types.js';\n\n/** Maps each node id to its input-order index; rejects duplicates so ordering contracts stay well-defined. */\nfunction buildNodeIndex(nodeIds: readonly string[]): Map<string, number> {\n const index = new Map<string, number>();\n for (const id of nodeIds) {\n if (index.has(id)) {\n throw new WireGraphError(`Duplicate node id \"${id}\" in the node list.`);\n }\n index.set(id, index.size);\n }\n return index;\n}\n\nfunction validateEdgeEndpoints(index: ReadonlyMap<string, number>, edges: readonly Edge[]): void {\n for (const edge of edges) {\n if (!index.has(edge.from)) {\n throw new WireGraphError(`Edge from \"${edge.from}\" to \"${edge.to}\" references unknown node id \"${edge.from}\".`);\n }\n if (!index.has(edge.to)) {\n throw new WireGraphError(`Edge from \"${edge.from}\" to \"${edge.to}\" references unknown node id \"${edge.to}\".`);\n }\n }\n}\n\n/**\n * Returns the node ids in topological order using Kahn's algorithm.\n *\n * Ties between ready nodes break by position in `nodeIds`, so the result is fully\n * deterministic for the same inputs. Parallel edges are tolerated; self-loops and\n * larger cycles make ordering impossible and throw `WireGraphError`.\n */\nexport function topologicalOrder(nodeIds: readonly string[], edges: readonly Edge[]): string[] {\n const index = buildNodeIndex(nodeIds);\n validateEdgeEndpoints(index, edges);\n\n const count = nodeIds.length;\n const outgoing: number[][] = Array.from({ length: count }, () => []);\n const indegree = new Array<number>(count).fill(0);\n for (const edge of edges) {\n const from = index.get(edge.from) as number;\n const to = index.get(edge.to) as number;\n outgoing[from]!.push(to);\n indegree[to] = (indegree[to] ?? 0) + 1;\n }\n\n // Ready nodes are always consumed in input order, never an arbitrary FIFO; the heap\n // keyed by input index keeps wide graphs at O(n log n).\n const ready = new MinHeap();\n for (let i = 0; i < count; i += 1) {\n if (indegree[i] === 0) ready.push(i, i);\n }\n\n const order: string[] = [];\n while (ready.size > 0) {\n const node = ready.pop();\n order.push(nodeIds[node] as string);\n for (const next of outgoing[node]!) {\n const remaining = (indegree[next] ?? 0) - 1;\n indegree[next] = remaining;\n if (remaining === 0) ready.push(next, next);\n }\n }\n\n if (order.length !== count) {\n throw new WireGraphError(\n 'Graph contains a cycle; no topological order exists. Use findCyclicGroups() to locate it.',\n );\n }\n return order;\n}\n\n/**\n * Returns the groups of nodes that are mutually reachable (strongly connected\n * components, Tarjan).\n *\n * Each returned group is an SCC with more than one node, or a single node carrying a\n * self-loop — never an exponential enumeration of elementary cycles. A group is a set\n * of nodes, not a path through them: members are sorted by input position, which does\n * not describe any particular cycle. Groups are ordered by the input position of their\n * first member, so results are deterministic.\n */\nexport function findCyclicGroups(nodeIds: readonly string[], edges: readonly Edge[]): string[][] {\n const index = buildNodeIndex(nodeIds);\n validateEdgeEndpoints(index, edges);\n\n const count = nodeIds.length;\n const outgoing: number[][] = Array.from({ length: count }, () => []);\n const selfLoop = new Array<boolean>(count).fill(false);\n for (const edge of edges) {\n const from = index.get(edge.from) as number;\n const to = index.get(edge.to) as number;\n if (from === to) selfLoop[from] = true;\n outgoing[from]!.push(to);\n }\n\n const lowLink = new Array<number>(count).fill(-1);\n const discovery = new Array<number>(count).fill(-1);\n const onStack = new Array<boolean>(count).fill(false);\n const stack: number[] = [];\n const cycles: string[][] = [];\n let time = 0;\n\n const strongConnect = (root: number): void => {\n // Iterative Tarjan: node editors can hold thousands of nodes, and recursion depth\n // must not scale with the longest dependency chain.\n const work: { node: number; child: number }[] = [{ child: 0, node: root }];\n const enter = (node: number): void => {\n discovery[node] = time;\n lowLink[node] = time;\n time += 1;\n stack.push(node);\n onStack[node] = true;\n };\n enter(root);\n\n while (work.length > 0) {\n const frame = work[work.length - 1] as { node: number; child: number };\n const children = outgoing[frame.node]!;\n if (frame.child < children.length) {\n const child = children[frame.child] as number;\n frame.child += 1;\n if (discovery[child] === -1) {\n enter(child);\n work.push({ child: 0, node: child });\n } else if (onStack[child]) {\n lowLink[frame.node] = Math.min(lowLink[frame.node] as number, discovery[child] as number);\n }\n continue;\n }\n\n work.pop();\n const parent = work[work.length - 1];\n if (parent) {\n lowLink[parent.node] = Math.min(lowLink[parent.node] as number, lowLink[frame.node] as number);\n }\n if ((lowLink[frame.node] as number) === (discovery[frame.node] as number)) {\n const component: number[] = [];\n let member = -1;\n do {\n member = stack.pop() as number;\n onStack[member] = false;\n component.push(member);\n } while (member !== frame.node);\n\n const isCyclic = component.length > 1 || (component.length === 1 && selfLoop[component[0] as number]);\n if (isCyclic) {\n component.sort((a, b) => a - b);\n cycles.push(component.map((member) => nodeIds[member] as string));\n }\n }\n }\n };\n\n for (let i = 0; i < count; i += 1) {\n if (discovery[i] === -1) strongConnect(i);\n }\n\n cycles.sort((a, b) => (index.get(a[0] as string) as number) - (index.get(b[0] as string) as number));\n return cycles;\n}\n","import { MinHeap } from './_heap.js';\nimport { DELTA, Dir, type Move, OPPOSITE, SIDE_DIR, SIDE_VECTOR } from './_sides.js';\nimport { WireConfigError } from './errors.js';\nimport type { Point, PortAnchor, PortSide, Rect } from './types.js';\n\n/** Configuration for `orthogonalRoute()`. */\nexport interface OrthogonalRouteOptions {\n /** Cost added per bend, on top of path length. Defaults to 12. */\n bendPenalty?: number;\n /**\n * Rectangles the route must not cross — typically every node's raw bounding box.\n * `padding` supplies the clearance, so do not inflate the rects yourself. The\n * obstacles a port sits inside are exempted for that port's straight exit segment\n * only; the rest of the route still avoids them.\n */\n obstacles?: readonly Rect[];\n /** Distance obstacles are inflated by; routes may travel along the inflated boundary. Defaults to 8. */\n padding?: number;\n /**\n * Distance the route runs straight out of a port before it may bend, and straight\n * into the target port. Defaults to 16; `0` disables the directional stubs (a port\n * inside an obstacle still exits straight to clear it).\n */\n stub?: number;\n}\n\n/** Number of direction slots packed per grid node in a state id (`node * DIR_COUNT + dir`). */\nconst DIR_COUNT = 5;\n\ninterface PaddedRect {\n x0: number;\n x1: number;\n y0: number;\n y1: number;\n}\n\nfunction padRect(rect: Rect, padding: number): PaddedRect {\n return {\n x0: rect.x - padding,\n x1: rect.x + rect.width + padding,\n y0: rect.y - padding,\n y1: rect.y + rect.height + padding,\n };\n}\n\n/** A point exactly on a padded boundary is free: routes are allowed to hug obstacle margins. */\nfunction pointBlocked(px: number, py: number, obstacles: readonly PaddedRect[]): boolean {\n for (const rect of obstacles) {\n if (px > rect.x0 && px < rect.x1 && py > rect.y0 && py < rect.y1) return true;\n }\n return false;\n}\n\n/** Whether the open axis-aligned span from `a` to `b` passes through an obstacle interior. */\nfunction spanBlocked(a: Point, b: Point, obstacles: readonly PaddedRect[]): boolean {\n const xLow = Math.min(a.x, b.x);\n const xHigh = Math.max(a.x, b.x);\n const yLow = Math.min(a.y, b.y);\n const yHigh = Math.max(a.y, b.y);\n for (const rect of obstacles) {\n if (yLow === yHigh) {\n if (yLow > rect.y0 && yLow < rect.y1 && xLow < rect.x1 && rect.x0 < xHigh) return true;\n } else if (xLow === xHigh && xLow > rect.x0 && xLow < rect.x1 && yLow < rect.y1 && rect.y0 < yHigh) {\n return true;\n }\n }\n return false;\n}\n\n/** Obstacles whose padded interior contains `point` — the obstacles that \"own\" the port. */\nfunction ownersOf(point: Point, obstacles: readonly PaddedRect[]): PaddedRect[] {\n return obstacles.filter((rect) => pointBlocked(point.x, point.y, [rect]));\n}\n\n/**\n * Distance from `point` to the padded boundary of `owners`, measured along `dir`.\n * Zero when the point is outside every owner.\n */\nfunction escapeDistance(point: Point, dir: Move, owners: readonly PaddedRect[]): number {\n const delta = DELTA[dir];\n let distance = 0;\n for (const rect of owners) {\n const along =\n delta.x > 0\n ? rect.x1 - point.x\n : delta.x < 0\n ? point.x - rect.x0\n : delta.y > 0\n ? rect.y1 - point.y\n : point.y - rect.y0;\n if (along > distance) distance = along;\n }\n return distance;\n}\n\n/**\n * Routes a Manhattan (axis-aligned) polyline between two ports over a visibility grid\n * built from the obstacle corners, using A* with a per-bend penalty.\n *\n * Pass every node's raw rect as `obstacles`; `padding` supplies the clearance. A port\n * that sits inside an obstacle (its own node, since ports are on node boundaries) is\n * exempted only for the straight exit segment out of that port; the searched route\n * never enters any padded obstacle interior, including its own nodes.\n *\n * Returns the waypoint polyline with `from` first and `to` last, or `null` when every\n * route is blocked (including a blocked exit segment). Cost is path length plus\n * `bendPenalty` per bend, so among equal length routes the one with fewer bends wins.\n * Expansion order is fully deterministic.\n */\nexport function orthogonalRoute(\n from: PortAnchor,\n to: PortAnchor,\n options: OrthogonalRouteOptions = {},\n): Point[] | null {\n const padding = options.padding ?? 8;\n const bendPenalty = options.bendPenalty ?? 12;\n const stub = options.stub ?? 16;\n if (!Number.isFinite(padding) || padding < 0) {\n throw new WireConfigError(`Orthogonal padding must be a finite non-negative number, received ${String(padding)}.`);\n }\n if (!Number.isFinite(bendPenalty) || bendPenalty < 0) {\n throw new WireConfigError(`Bend penalty must be a finite non-negative number, received ${String(bendPenalty)}.`);\n }\n if (!Number.isFinite(stub) || stub < 0) {\n throw new WireConfigError(`Stub must be a finite non-negative number, received ${String(stub)}.`);\n }\n\n const start: Point = { x: from.x, y: from.y };\n const goal: Point = { x: to.x, y: to.y };\n if (start.x === goal.x && start.y === goal.y) return [start];\n\n const obstacles = (options.obstacles ?? []).map((rect) => padRect(rect, padding));\n const startOwners = ownersOf(start, obstacles);\n const goalOwners = ownersOf(goal, obstacles);\n // Obstacles to check against for a segment leaving `owners`: everything except those owners.\n const othersFor = (owners: readonly PaddedRect[]): PaddedRect[] =>\n owners.length === 0 ? obstacles : obstacles.filter((rect) => !owners.includes(rect));\n const startOthers = othersFor(startOwners);\n const goalOthers = othersFor(goalOwners);\n\n // Port stubs: the route leaves the source port straight along its side and enters\n // the target port along that side, so wires never peel off a port sideways. A port\n // inside an obstacle always exits straight far enough to clear the obstacle margin,\n // even when `stub` is smaller than that distance (or zero).\n const fromDir = SIDE_DIR[from.side];\n const toDir = SIDE_DIR[to.side];\n\n // Straight shot: when the direct segment agrees with both port sides and is clear\n // of every obstacle except the endpoints' own owners, it is optimal by construction\n // (also covers facing ports closer than two stubs).\n if (start.x === goal.x || start.y === goal.y) {\n const dir: Move =\n start.x !== goal.x ? (goal.x > start.x ? Dir.Right : Dir.Left) : goal.y > start.y ? Dir.Down : Dir.Up;\n // A port with no forced exit (no stub, no owner to escape) accepts any direction.\n const agreesWithStart = (stub === 0 && startOwners.length === 0) || fromDir === dir;\n const agreesWithGoal = (stub === 0 && goalOwners.length === 0) || OPPOSITE[toDir] === dir;\n const freeSpan = obstacles.filter((rect) => !startOwners.includes(rect) && !goalOwners.includes(rect));\n if (agreesWithStart && agreesWithGoal && !spanBlocked(start, goal, freeSpan)) return [start, goal];\n }\n\n const exitTip = (point: Point, side: PortSide, dir: Move, owners: readonly PaddedRect[]): Point => {\n const vector = SIDE_VECTOR[side];\n const distance = Math.max(stub, escapeDistance(point, dir, owners));\n return { x: point.x + vector.x * distance, y: point.y + vector.y * distance };\n };\n const fromTip = exitTip(start, from.side, fromDir, startOwners);\n const toTip = exitTip(goal, to.side, toDir, goalOwners);\n\n // The exit segment may cross its own owners but no other obstacle; a blocked exit\n // means the port is walled in, so no route exists.\n if (spanBlocked(start, fromTip, startOthers)) return null;\n if (spanBlocked(goal, toTip, goalOthers)) return null;\n\n const routeStart = fromTip;\n const routeGoal = toTip;\n // `stub: 0` disables the directional stubs unless an owner escape forced one.\n const startDir: Dir = stub > 0 || startOwners.length > 0 ? fromDir : Dir.None;\n // The route must not arrive at the goal tip moving along the port's outward\n // direction (that would overshoot the port and double back); any other incoming\n // direction continues smoothly into the final stub segment.\n const forbiddenIncoming: Dir = stub > 0 || goalOwners.length > 0 ? toDir : Dir.None;\n\n // Grid lines: every obstacle edge plus the exit tips' own rows and columns.\n const xs = new Set<number>([routeStart.x, routeGoal.x]);\n const ys = new Set<number>([routeStart.y, routeGoal.y]);\n for (const rect of obstacles) {\n xs.add(rect.x0);\n xs.add(rect.x1);\n ys.add(rect.y0);\n ys.add(rect.y1);\n }\n const xLines = [...xs].sort((a, b) => a - b);\n const yLines = [...ys].sort((a, b) => a - b);\n const columns = xLines.length;\n const rows = yLines.length;\n const nodeCount = columns * rows;\n\n const nodeX = (node: number): number => xLines[node % columns] as number;\n const nodeY = (node: number): number => yLines[Math.floor(node / columns)] as number;\n const nodeAt = (x: number, y: number): number => yLines.indexOf(y) * columns + xLines.indexOf(x);\n\n const startNode = nodeAt(routeStart.x, routeStart.y);\n const goalNode = nodeAt(routeGoal.x, routeGoal.y);\n if (pointBlocked(nodeX(startNode), nodeY(startNode), obstacles)) return null;\n if (pointBlocked(nodeX(goalNode), nodeY(goalNode), obstacles)) return null;\n\n // State = grid node × incoming direction (Dir.None only for the start).\n const stateCount = nodeCount * DIR_COUNT;\n const gScore = new Float64Array(stateCount).fill(Number.POSITIVE_INFINITY);\n const parent = new Int32Array(stateCount).fill(-1);\n const closed = new Uint8Array(stateCount);\n\n const heuristic = (node: number): number => Math.abs(nodeX(node) - routeGoal.x) + Math.abs(nodeY(node) - routeGoal.y);\n const stateId = (node: number, dir: Dir): number => node * DIR_COUNT + dir;\n\n const open = new MinHeap();\n const startState = stateId(startNode, startDir);\n gScore[startState] = 0;\n open.push(heuristic(startNode), startState);\n\n let goalState = -1;\n while (open.size > 0 && goalState === -1) {\n const current = open.pop();\n if (closed[current]) continue;\n closed[current] = 1;\n\n const node = Math.floor(current / DIR_COUNT);\n const incoming = (current % DIR_COUNT) as Dir;\n if (node === goalNode && (forbiddenIncoming === Dir.None || incoming !== forbiddenIncoming)) {\n goalState = current;\n break;\n }\n\n const cx = nodeX(node);\n const cy = nodeY(node);\n const candidates: readonly [Dir, number][] = [\n [Dir.Left, node - 1],\n [Dir.Right, node + 1],\n [Dir.Up, node - columns],\n [Dir.Down, node + columns],\n ];\n for (const [dir, neighbor] of candidates) {\n // Validate grid bounds: Left/Right must stay in the same row, Up/Down in the same column.\n if (dir === Dir.Left && node % columns === 0) continue;\n if (dir === Dir.Right && node % columns === columns - 1) continue;\n if (dir === Dir.Up && node < columns) continue;\n if (dir === Dir.Down && node >= (rows - 1) * columns) continue;\n\n const nx = nodeX(neighbor);\n const ny = nodeY(neighbor);\n if (pointBlocked(nx, ny, obstacles)) continue;\n if (spanBlocked({ x: cx, y: cy }, { x: nx, y: ny }, obstacles)) continue;\n\n const step = Math.abs(nx - cx) + Math.abs(ny - cy);\n const bend = incoming !== Dir.None && incoming !== dir ? bendPenalty : 0;\n const nextScore = (gScore[current] as number) + step + bend;\n const nextState = stateId(neighbor, dir);\n if (nextScore < (gScore[nextState] as number)) {\n gScore[nextState] = nextScore;\n parent[nextState] = current;\n open.push(nextScore + heuristic(neighbor), nextState);\n }\n }\n }\n\n if (goalState === -1) return null;\n\n const nodes: number[] = [];\n for (let state = goalState; state !== -1; state = parent[state] as number) {\n nodes.push(Math.floor(state / DIR_COUNT));\n }\n nodes.reverse();\n\n // Collapse collinear runs so the polyline carries waypoints only at bends.\n const collapsed: Point[] = nodes\n .filter((node, i) => {\n if (i === 0 || i === nodes.length - 1) return true;\n const prev = nodes[i - 1] as number;\n const next = nodes[i + 1] as number;\n const collinear =\n (nodeX(prev) === nodeX(node) && nodeX(node) === nodeX(next)) ||\n (nodeY(prev) === nodeY(node) && nodeY(node) === nodeY(next));\n return !collinear;\n })\n .map((node) => ({ x: nodeX(node), y: nodeY(node) }));\n\n // Re-attach the exact ports outside the stub tips, then drop stub tips that are\n // collinear with their neighbours so a straight-through route keeps two points.\n const points = [start, ...collapsed, goal];\n for (let i = 1; i < points.length - 1; i += 1) {\n const prev = points[i - 1] as Point;\n const cur = points[i] as Point;\n const next = points[i + 1] as Point;\n if ((prev.x === cur.x && cur.x === next.x) || (prev.y === cur.y && cur.y === next.y)) {\n points.splice(i, 1);\n i -= 1;\n }\n }\n return points;\n}\n","/** Formats a number for SVG path output: rounded to micro-precision, no `-0`, no exponent noise. */\nexport function fmt(value: number): string {\n const rounded = Math.round(value * 1e6) / 1e6;\n return Object.is(rounded, -0) ? '0' : String(rounded);\n}\n","import { fmt } from './_format.js';\nimport type { CubicBezier, Point } from './types.js';\n\n/** Formats a polyline as an SVG path `d` string using absolute moveto and lineto commands. */\nexport function polylineToSvgPath(points: readonly Point[]): string {\n const first = points[0];\n if (!first) return '';\n const parts = [`M ${fmt(first.x)} ${fmt(first.y)}`];\n for (let i = 1; i < points.length; i += 1) {\n const point = points[i] as Point;\n parts.push(`L ${fmt(point.x)} ${fmt(point.y)}`);\n }\n return parts.join(' ');\n}\n\n/** Formats a cubic bezier segment as an SVG path `d` string using absolute curveto commands. */\nexport function bezierToSvgPath(curve: CubicBezier): string {\n return `M ${fmt(curve.from.x)} ${fmt(curve.from.y)} C ${fmt(curve.c1.x)} ${fmt(curve.c1.y)}, ${fmt(curve.c2.x)} ${fmt(curve.c2.y)}, ${fmt(curve.to.x)} ${fmt(curve.to.y)}`;\n}\n","import { WireConfigError } from './errors.js';\nimport type { PortAnchor, PortSide, Rect } from './types.js';\n\n/**\n * Places a port on `side` of `rect` and returns its world position with the side it faces.\n *\n * `offset` is the 0..1 fraction along the side (0 is the side's lower coordinate,\n * 0.5 the middle). Screen convention applies: `top` is smaller y.\n */\nexport function portAnchor(rect: Rect, side: PortSide, offset = 0.5): PortAnchor {\n if (!Number.isFinite(offset) || offset < 0 || offset > 1) {\n throw new WireConfigError(`Port offset must be a finite number between 0 and 1, received ${String(offset)}.`);\n }\n switch (side) {\n case 'bottom':\n return { side, x: rect.x + rect.width * offset, y: rect.y + rect.height };\n case 'left':\n return { side, x: rect.x, y: rect.y + rect.height * offset };\n case 'right':\n return { side, x: rect.x + rect.width, y: rect.y + rect.height * offset };\n case 'top':\n return { side, x: rect.x + rect.width * offset, y: rect.y };\n }\n}\n"],"mappings":"A,mFAGA,IAAaC,EAAiD,CAC5D,OAAQ,CAAE,EAAG,EAAG,EAAG,CAAE,EACrB,KAAM,CAAE,EAAG,GAAI,E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,EAC1E,IAAK,MACH,MAAO,CAAE,OAAM,EAAG3E,EAAK,EAAIA,EAAK,MAAQ2E,EAAQ,EAAG3E,EAAK,CAAE,CAC9D,CACF,C"}
package/dist/wire.js ADDED
@@ -0,0 +1,353 @@
1
+ // src/_sides.ts
2
+ var e = {
3
+ bottom: {
4
+ x: 0,
5
+ y: 1
6
+ },
7
+ left: {
8
+ x: -1,
9
+ y: 0
10
+ },
11
+ right: {
12
+ x: 1,
13
+ y: 0
14
+ },
15
+ top: {
16
+ x: 0,
17
+ y: -1
18
+ }
19
+ }, t = {
20
+ Down: 4,
21
+ Left: 1,
22
+ None: 0,
23
+ Right: 2,
24
+ Up: 3
25
+ }, n = {
26
+ [t.Left]: {
27
+ x: -1,
28
+ y: 0
29
+ },
30
+ [t.Right]: {
31
+ x: 1,
32
+ y: 0
33
+ },
34
+ [t.Up]: {
35
+ x: 0,
36
+ y: -1
37
+ },
38
+ [t.Down]: {
39
+ x: 0,
40
+ y: 1
41
+ }
42
+ }, r = {
43
+ bottom: t.Down,
44
+ left: t.Left,
45
+ right: t.Right,
46
+ top: t.Up
47
+ }, i = {
48
+ [t.Down]: t.Up,
49
+ [t.Left]: t.Right,
50
+ [t.Right]: t.Left,
51
+ [t.Up]: t.Down
52
+ }, WireError = class extends Error {
53
+ constructor(e, t) {
54
+ super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
55
+ }
56
+ }, WireGraphError = class extends WireError {}, WireConfigError = class extends WireError {}, a = 40;
57
+ function bezierRoute(t, n, r = {}) {
58
+ let i = r.handleLength ?? a;
59
+ if (!Number.isFinite(i) || i < 0) throw new WireConfigError(`Bezier handleLength must be a finite non-negative number, received ${String(i)}.`);
60
+ let o = e[t.side], s = e[n.side];
61
+ return {
62
+ c1: {
63
+ x: t.x + o.x * i,
64
+ y: t.y + o.y * i
65
+ },
66
+ c2: {
67
+ x: n.x + s.x * i,
68
+ y: n.y + s.y * i
69
+ },
70
+ from: {
71
+ x: t.x,
72
+ y: t.y
73
+ },
74
+ to: {
75
+ x: n.x,
76
+ y: n.y
77
+ }
78
+ };
79
+ }
80
+ // src/_heap.ts
81
+ var MinHeap = class {
82
+ items = [];
83
+ get size() {
84
+ return this.items.length;
85
+ }
86
+ push(e, t) {
87
+ let n = this.items;
88
+ n.push({
89
+ key: e,
90
+ value: t
91
+ });
92
+ let r = n.length - 1;
93
+ for (; r > 0;) {
94
+ let e = r - 1 >> 1, t = n[e], i = n[r];
95
+ if (t.key <= i.key) break;
96
+ n[e] = i, n[r] = t, r = e;
97
+ }
98
+ }
99
+ pop() {
100
+ let e = this.items, t = e[0], n = e.pop();
101
+ if (e.length > 0) {
102
+ e[0] = n;
103
+ let t = 0;
104
+ for (;;) {
105
+ let n = t * 2 + 1, r = n + 1, i = t;
106
+ if (n < e.length && e[n].key < e[i].key && (i = n), r < e.length && e[r].key < e[i].key && (i = r), i === t) break;
107
+ let a = e[t], o = e[i];
108
+ e[t] = o, e[i] = a, t = i;
109
+ }
110
+ }
111
+ return t.value;
112
+ }
113
+ };
114
+ // src/graph.ts
115
+ function buildNodeIndex(e) {
116
+ let t = /* @__PURE__ */ new Map();
117
+ for (let n of e) {
118
+ if (t.has(n)) throw new WireGraphError(`Duplicate node id "${n}" in the node list.`);
119
+ t.set(n, t.size);
120
+ }
121
+ return t;
122
+ }
123
+ function validateEdgeEndpoints(e, t) {
124
+ for (let n of t) {
125
+ if (!e.has(n.from)) throw new WireGraphError(`Edge from "${n.from}" to "${n.to}" references unknown node id "${n.from}".`);
126
+ if (!e.has(n.to)) throw new WireGraphError(`Edge from "${n.from}" to "${n.to}" references unknown node id "${n.to}".`);
127
+ }
128
+ }
129
+ function topologicalOrder(e, t) {
130
+ let n = buildNodeIndex(e);
131
+ validateEdgeEndpoints(n, t);
132
+ let r = e.length, i = Array.from({ length: r }, () => []), a = Array(r).fill(0);
133
+ for (let e of t) {
134
+ let t = n.get(e.from), r = n.get(e.to);
135
+ i[t].push(r), a[r] = (a[r] ?? 0) + 1;
136
+ }
137
+ let o = new MinHeap();
138
+ for (let e = 0; e < r; e += 1) a[e] === 0 && o.push(e, e);
139
+ let s = [];
140
+ for (; o.size > 0;) {
141
+ let t = o.pop();
142
+ s.push(e[t]);
143
+ for (let e of i[t]) {
144
+ let t = (a[e] ?? 0) - 1;
145
+ a[e] = t, t === 0 && o.push(e, e);
146
+ }
147
+ }
148
+ if (s.length !== r) throw new WireGraphError("Graph contains a cycle; no topological order exists. Use findCyclicGroups() to locate it.");
149
+ return s;
150
+ }
151
+ function findCyclicGroups(e, t) {
152
+ let n = buildNodeIndex(e);
153
+ validateEdgeEndpoints(n, t);
154
+ let r = e.length, i = Array.from({ length: r }, () => []), a = Array(r).fill(!1);
155
+ for (let e of t) {
156
+ let t = n.get(e.from), r = n.get(e.to);
157
+ t === r && (a[t] = !0), i[t].push(r);
158
+ }
159
+ let o = Array(r).fill(-1), s = Array(r).fill(-1), c = Array(r).fill(!1), l = [], u = [], d = 0, strongConnect = (t) => {
160
+ let n = [{
161
+ child: 0,
162
+ node: t
163
+ }], enter = (e) => {
164
+ s[e] = d, o[e] = d, d += 1, l.push(e), c[e] = !0;
165
+ };
166
+ for (enter(t); n.length > 0;) {
167
+ let t = n[n.length - 1], r = i[t.node];
168
+ if (t.child < r.length) {
169
+ let e = r[t.child];
170
+ t.child += 1, s[e] === -1 ? (enter(e), n.push({
171
+ child: 0,
172
+ node: e
173
+ })) : c[e] && (o[t.node] = Math.min(o[t.node], s[e]));
174
+ continue;
175
+ }
176
+ n.pop();
177
+ let d = n[n.length - 1];
178
+ if (d && (o[d.node] = Math.min(o[d.node], o[t.node])), o[t.node] === s[t.node]) {
179
+ let n = [], r = -1;
180
+ do
181
+ r = l.pop(), c[r] = !1, n.push(r);
182
+ while (r !== t.node);
183
+ (n.length > 1 || n.length === 1 && a[n[0]]) && (n.sort((e, t) => e - t), u.push(n.map((t) => e[t])));
184
+ }
185
+ }
186
+ };
187
+ for (let e = 0; e < r; e += 1) s[e] === -1 && strongConnect(e);
188
+ return u.sort((e, t) => n.get(e[0]) - n.get(t[0])), u;
189
+ }
190
+ // src/orthogonal.ts
191
+ var o = 5;
192
+ function padRect(e, t) {
193
+ return {
194
+ x0: e.x - t,
195
+ x1: e.x + e.width + t,
196
+ y0: e.y - t,
197
+ y1: e.y + e.height + t
198
+ };
199
+ }
200
+ function pointBlocked(e, t, n) {
201
+ for (let r of n) if (e > r.x0 && e < r.x1 && t > r.y0 && t < r.y1) return !0;
202
+ return !1;
203
+ }
204
+ function spanBlocked(e, t, n) {
205
+ let r = Math.min(e.x, t.x), i = Math.max(e.x, t.x), a = Math.min(e.y, t.y), o = Math.max(e.y, t.y);
206
+ for (let e of n) if (a === o) {
207
+ if (a > e.y0 && a < e.y1 && r < e.x1 && e.x0 < i) return !0;
208
+ } else if (r === i && r > e.x0 && r < e.x1 && a < e.y1 && e.y0 < o) return !0;
209
+ return !1;
210
+ }
211
+ function ownersOf(e, t) {
212
+ return t.filter((t) => pointBlocked(e.x, e.y, [t]));
213
+ }
214
+ function escapeDistance(e, t, r) {
215
+ let i = n[t], a = 0;
216
+ for (let t of r) {
217
+ let n = i.x > 0 ? t.x1 - e.x : i.x < 0 ? e.x - t.x0 : i.y > 0 ? t.y1 - e.y : e.y - t.y0;
218
+ n > a && (a = n);
219
+ }
220
+ return a;
221
+ }
222
+ function orthogonalRoute(n, a, s = {}) {
223
+ let c = s.padding ?? 8, l = s.bendPenalty ?? 12, u = s.stub ?? 16;
224
+ if (!Number.isFinite(c) || c < 0) throw new WireConfigError(`Orthogonal padding must be a finite non-negative number, received ${String(c)}.`);
225
+ if (!Number.isFinite(l) || l < 0) throw new WireConfigError(`Bend penalty must be a finite non-negative number, received ${String(l)}.`);
226
+ if (!Number.isFinite(u) || u < 0) throw new WireConfigError(`Stub must be a finite non-negative number, received ${String(u)}.`);
227
+ let d = {
228
+ x: n.x,
229
+ y: n.y
230
+ }, f = {
231
+ x: a.x,
232
+ y: a.y
233
+ };
234
+ if (d.x === f.x && d.y === f.y) return [d];
235
+ let p = (s.obstacles ?? []).map((e) => padRect(e, c)), m = ownersOf(d, p), h = ownersOf(f, p), othersFor = (e) => e.length === 0 ? p : p.filter((t) => !e.includes(t)), g = othersFor(m), _ = othersFor(h), v = r[n.side], y = r[a.side];
236
+ if (d.x === f.x || d.y === f.y) {
237
+ let e = d.x === f.x ? f.y > d.y ? t.Down : t.Up : f.x > d.x ? t.Right : t.Left, n = u === 0 && m.length === 0 || v === e, r = u === 0 && h.length === 0 || i[y] === e, a = p.filter((e) => !m.includes(e) && !h.includes(e));
238
+ if (n && r && !spanBlocked(d, f, a)) return [d, f];
239
+ }
240
+ let exitTip = (t, n, r, i) => {
241
+ let a = e[n], o = Math.max(u, escapeDistance(t, r, i));
242
+ return {
243
+ x: t.x + a.x * o,
244
+ y: t.y + a.y * o
245
+ };
246
+ }, b = exitTip(d, n.side, v, m), x = exitTip(f, a.side, y, h);
247
+ if (spanBlocked(d, b, g) || spanBlocked(f, x, _)) return null;
248
+ let S = b, C = x, w = u > 0 || m.length > 0 ? v : t.None, T = u > 0 || h.length > 0 ? y : t.None, E = /* @__PURE__ */ new Set([S.x, C.x]), D = /* @__PURE__ */ new Set([S.y, C.y]);
249
+ for (let e of p) E.add(e.x0), E.add(e.x1), D.add(e.y0), D.add(e.y1);
250
+ let O = [...E].sort((e, t) => e - t), k = [...D].sort((e, t) => e - t), A = O.length, j = k.length, M = A * j, nodeX = (e) => O[e % A], nodeY = (e) => k[Math.floor(e / A)], nodeAt = (e, t) => k.indexOf(t) * A + O.indexOf(e), N = nodeAt(S.x, S.y), P = nodeAt(C.x, C.y);
251
+ if (pointBlocked(nodeX(N), nodeY(N), p) || pointBlocked(nodeX(P), nodeY(P), p)) return null;
252
+ let F = M * o, I = new Float64Array(F).fill(Infinity), L = new Int32Array(F).fill(-1), R = new Uint8Array(F), heuristic = (e) => Math.abs(nodeX(e) - C.x) + Math.abs(nodeY(e) - C.y), stateId = (e, t) => e * o + t, z = new MinHeap(), B = stateId(N, w);
253
+ I[B] = 0, z.push(heuristic(N), B);
254
+ let V = -1;
255
+ for (; z.size > 0 && V === -1;) {
256
+ let e = z.pop();
257
+ if (R[e]) continue;
258
+ R[e] = 1;
259
+ let n = Math.floor(e / o), r = e % o;
260
+ if (n === P && (T === t.None || r !== T)) {
261
+ V = e;
262
+ break;
263
+ }
264
+ let i = nodeX(n), a = nodeY(n), s = [
265
+ [t.Left, n - 1],
266
+ [t.Right, n + 1],
267
+ [t.Up, n - A],
268
+ [t.Down, n + A]
269
+ ];
270
+ for (let [o, c] of s) {
271
+ if (o === t.Left && n % A === 0 || o === t.Right && n % A === A - 1 || o === t.Up && n < A || o === t.Down && n >= (j - 1) * A) continue;
272
+ let s = nodeX(c), u = nodeY(c);
273
+ if (pointBlocked(s, u, p) || spanBlocked({
274
+ x: i,
275
+ y: a
276
+ }, {
277
+ x: s,
278
+ y: u
279
+ }, p)) continue;
280
+ let d = Math.abs(s - i) + Math.abs(u - a), f = r !== t.None && r !== o ? l : 0, m = I[e] + d + f, h = stateId(c, o);
281
+ m < I[h] && (I[h] = m, L[h] = e, z.push(m + heuristic(c), h));
282
+ }
283
+ }
284
+ if (V === -1) return null;
285
+ let H = [];
286
+ for (let e = V; e !== -1; e = L[e]) H.push(Math.floor(e / o));
287
+ H.reverse();
288
+ let U = [
289
+ d,
290
+ ...H.filter((e, t) => {
291
+ if (t === 0 || t === H.length - 1) return !0;
292
+ let n = H[t - 1], r = H[t + 1];
293
+ return !(nodeX(n) === nodeX(e) && nodeX(e) === nodeX(r) || nodeY(n) === nodeY(e) && nodeY(e) === nodeY(r));
294
+ }).map((e) => ({
295
+ x: nodeX(e),
296
+ y: nodeY(e)
297
+ })),
298
+ f
299
+ ];
300
+ for (let e = 1; e < U.length - 1; e += 1) {
301
+ let t = U[e - 1], n = U[e], r = U[e + 1];
302
+ (t.x === n.x && n.x === r.x || t.y === n.y && n.y === r.y) && (U.splice(e, 1), --e);
303
+ }
304
+ return U;
305
+ }
306
+ // src/_format.ts
307
+ function fmt(e) {
308
+ let t = Math.round(e * 1e6) / 1e6;
309
+ return Object.is(t, -0) ? "0" : String(t);
310
+ }
311
+ // src/path.ts
312
+ function polylineToSvgPath(e) {
313
+ let t = e[0];
314
+ if (!t) return "";
315
+ let n = [`M ${fmt(t.x)} ${fmt(t.y)}`];
316
+ for (let t = 1; t < e.length; t += 1) {
317
+ let r = e[t];
318
+ n.push(`L ${fmt(r.x)} ${fmt(r.y)}`);
319
+ }
320
+ return n.join(" ");
321
+ }
322
+ function bezierToSvgPath(e) {
323
+ return `M ${fmt(e.from.x)} ${fmt(e.from.y)} C ${fmt(e.c1.x)} ${fmt(e.c1.y)}, ${fmt(e.c2.x)} ${fmt(e.c2.y)}, ${fmt(e.to.x)} ${fmt(e.to.y)}`;
324
+ }
325
+ // src/ports.ts
326
+ function portAnchor(e, t, n = .5) {
327
+ if (!Number.isFinite(n) || n < 0 || n > 1) throw new WireConfigError(`Port offset must be a finite number between 0 and 1, received ${String(n)}.`);
328
+ switch (t) {
329
+ case "bottom": return {
330
+ side: t,
331
+ x: e.x + e.width * n,
332
+ y: e.y + e.height
333
+ };
334
+ case "left": return {
335
+ side: t,
336
+ x: e.x,
337
+ y: e.y + e.height * n
338
+ };
339
+ case "right": return {
340
+ side: t,
341
+ x: e.x + e.width,
342
+ y: e.y + e.height * n
343
+ };
344
+ case "top": return {
345
+ side: t,
346
+ x: e.x + e.width * n,
347
+ y: e.y
348
+ };
349
+ }
350
+ }
351
+ export { WireConfigError, WireError, WireGraphError, bezierRoute, bezierToSvgPath, findCyclicGroups, orthogonalRoute, polylineToSvgPath, portAnchor, topologicalOrder };
352
+
353
+ //# sourceMappingURL=wire.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wire.js","names":["SIDE_VECTOR","Dir","DELTA","SIDE_DIR","OPPOSITE","message","opts","DEFAULT_HANDLE_LENGTH","handleLength","options","fromVector","from","toVector","to","items","i","parent","parentItem","item","top","last","left","right","smallest","swap","index","id","nodeIds","edge","edges","count","outgoing","indegree","ready","order","node","next","remaining","selfLoop","lowLink","discovery","onStack","stack","cycles","time","work","root","frame","children","child","component","member","a","b","DIR_COUNT","rect","padding","obstacles","px","py","xLow","xHigh","yLow","yHigh","point","delta","dir","distance","owners","along","bendPenalty","stub","start","goal","startOwners","goalOwners","startOthers","goalOthers","fromDir","toDir","agreesWithStart","agreesWithGoal","freeSpan","vector","side","fromTip","toTip","routeStart","routeGoal","startDir","forbiddenIncoming","xs","ys","xLines","yLines","columns","rows","nodeCount","y","x","startNode","goalNode","stateCount","gScore","closed","open","startState","goalState","current","incoming","cx","cy","candidates","neighbor","nx","ny","step","bend","nextScore","nextState","nodes","state","points","prev","cur","rounded","value","first","parts","curve","offset"],"sources":["../src/_sides.ts","../src/errors.ts","../src/bezier.ts","../src/_heap.ts","../src/graph.ts","../src/orthogonal.ts","../src/_format.ts","../src/path.ts","../src/ports.ts"],"sourcesContent":["import type { Point, PortSide } from './types.js';\n\n/** Outward unit vector for each port side; shared by the routers. */\nexport const SIDE_VECTOR: Readonly<Record<PortSide, Point>> = {\n bottom: { x: 0, y: 1 },\n left: { x: -1, y: 0 },\n right: { x: 1, y: 0 },\n top: { x: 0, y: -1 },\n};\n\n/** Grid movement directions; `None` (0) marks a start state with no incoming direction. */\nexport const Dir = { Down: 4, Left: 1, None: 0, Right: 2, Up: 3 } as const;\nexport type Dir = (typeof Dir)[keyof typeof Dir];\n/** The four real movement directions, excluding the `None` sentinel. */\nexport type Move = Exclude<Dir, typeof Dir.None>;\n\n/** Unit steps per movement direction, in grid order. */\nexport const DELTA: Readonly<Record<Move, Point>> = {\n [Dir.Left]: { x: -1, y: 0 },\n [Dir.Right]: { x: 1, y: 0 },\n [Dir.Up]: { x: 0, y: -1 },\n [Dir.Down]: { x: 0, y: 1 },\n};\n\n/** Outward direction a port on the given side faces. */\nexport const SIDE_DIR: Readonly<Record<PortSide, Move>> = {\n bottom: Dir.Down,\n left: Dir.Left,\n right: Dir.Right,\n top: Dir.Up,\n};\n\nexport const OPPOSITE: Readonly<Record<Move, Move>> = {\n [Dir.Down]: Dir.Up,\n [Dir.Left]: Dir.Right,\n [Dir.Right]: Dir.Left,\n [Dir.Up]: Dir.Down,\n};\n","/** Base class for all wire errors. Use `instanceof WireError` to catch any wire-originated error. */\nexport class WireError extends Error {\n constructor(message: string, opts?: ErrorOptions) {\n super(message, opts);\n this.name = new.target.name;\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Thrown when a graph operation receives an edge that references a node id outside the supplied node set. */\nexport class WireGraphError extends WireError {}\n\n/** Thrown when routing options are invalid, such as a negative `handleLength`, `padding`, `stub`, or `bendPenalty`. */\nexport class WireConfigError extends WireError {}\n","import { SIDE_VECTOR } from './_sides.js';\nimport { WireConfigError } from './errors.js';\nimport type { CubicBezier, PortAnchor } from './types.js';\n\n/** Default control-point distance for `bezierRoute()` when `handleLength` is omitted. */\nconst DEFAULT_HANDLE_LENGTH = 40;\n\n/** Configuration for `bezierRoute()`. */\nexport interface BezierRouteOptions {\n /** Distance each control point extends outward from its port along the port side. Defaults to 40. */\n handleLength?: number;\n}\n\n/**\n * Builds a cubic bezier segment between two ports.\n *\n * Control points extend outward from each port along its side, so the curve leaves\n * and enters ports perpendicular to the node edge.\n */\nexport function bezierRoute(from: PortAnchor, to: PortAnchor, options: BezierRouteOptions = {}): CubicBezier {\n const handleLength = options.handleLength ?? DEFAULT_HANDLE_LENGTH;\n if (!Number.isFinite(handleLength) || handleLength < 0) {\n throw new WireConfigError(\n `Bezier handleLength must be a finite non-negative number, received ${String(handleLength)}.`,\n );\n }\n\n const fromVector = SIDE_VECTOR[from.side];\n const toVector = SIDE_VECTOR[to.side];\n\n return {\n c1: { x: from.x + fromVector.x * handleLength, y: from.y + fromVector.y * handleLength },\n c2: { x: to.x + toVector.x * handleLength, y: to.y + toVector.y * handleLength },\n from: { x: from.x, y: from.y },\n to: { x: to.x, y: to.y },\n };\n}\n","/**\n * Binary min-heap ordered by a numeric key. Ties between equal keys resolve by heap\n * structure, which is fully determined by the push sequence, so extraction is\n * deterministic for identical input.\n */\nexport class MinHeap {\n private readonly items: { key: number; value: number }[] = [];\n\n get size(): number {\n return this.items.length;\n }\n\n push(key: number, value: number): void {\n const items = this.items;\n items.push({ key, value });\n let i = items.length - 1;\n while (i > 0) {\n const parent = (i - 1) >> 1;\n const parentItem = items[parent]!;\n const item = items[i]!;\n if (parentItem.key <= item.key) break;\n items[parent] = item;\n items[i] = parentItem;\n i = parent;\n }\n }\n\n pop(): number {\n const items = this.items;\n const top = items[0]!;\n const last = items.pop()!;\n if (items.length > 0) {\n items[0] = last;\n let i = 0;\n for (;;) {\n const left = i * 2 + 1;\n const right = left + 1;\n let smallest = i;\n if (left < items.length && items[left]!.key < items[smallest]!.key) smallest = left;\n if (right < items.length && items[right]!.key < items[smallest]!.key) smallest = right;\n if (smallest === i) break;\n const item = items[i]!;\n const swap = items[smallest]!;\n items[i] = swap;\n items[smallest] = item;\n i = smallest;\n }\n }\n return top.value;\n }\n}\n","import { MinHeap } from './_heap.js';\nimport { WireGraphError } from './errors.js';\nimport type { Edge } from './types.js';\n\n/** Maps each node id to its input-order index; rejects duplicates so ordering contracts stay well-defined. */\nfunction buildNodeIndex(nodeIds: readonly string[]): Map<string, number> {\n const index = new Map<string, number>();\n for (const id of nodeIds) {\n if (index.has(id)) {\n throw new WireGraphError(`Duplicate node id \"${id}\" in the node list.`);\n }\n index.set(id, index.size);\n }\n return index;\n}\n\nfunction validateEdgeEndpoints(index: ReadonlyMap<string, number>, edges: readonly Edge[]): void {\n for (const edge of edges) {\n if (!index.has(edge.from)) {\n throw new WireGraphError(`Edge from \"${edge.from}\" to \"${edge.to}\" references unknown node id \"${edge.from}\".`);\n }\n if (!index.has(edge.to)) {\n throw new WireGraphError(`Edge from \"${edge.from}\" to \"${edge.to}\" references unknown node id \"${edge.to}\".`);\n }\n }\n}\n\n/**\n * Returns the node ids in topological order using Kahn's algorithm.\n *\n * Ties between ready nodes break by position in `nodeIds`, so the result is fully\n * deterministic for the same inputs. Parallel edges are tolerated; self-loops and\n * larger cycles make ordering impossible and throw `WireGraphError`.\n */\nexport function topologicalOrder(nodeIds: readonly string[], edges: readonly Edge[]): string[] {\n const index = buildNodeIndex(nodeIds);\n validateEdgeEndpoints(index, edges);\n\n const count = nodeIds.length;\n const outgoing: number[][] = Array.from({ length: count }, () => []);\n const indegree = new Array<number>(count).fill(0);\n for (const edge of edges) {\n const from = index.get(edge.from) as number;\n const to = index.get(edge.to) as number;\n outgoing[from]!.push(to);\n indegree[to] = (indegree[to] ?? 0) + 1;\n }\n\n // Ready nodes are always consumed in input order, never an arbitrary FIFO; the heap\n // keyed by input index keeps wide graphs at O(n log n).\n const ready = new MinHeap();\n for (let i = 0; i < count; i += 1) {\n if (indegree[i] === 0) ready.push(i, i);\n }\n\n const order: string[] = [];\n while (ready.size > 0) {\n const node = ready.pop();\n order.push(nodeIds[node] as string);\n for (const next of outgoing[node]!) {\n const remaining = (indegree[next] ?? 0) - 1;\n indegree[next] = remaining;\n if (remaining === 0) ready.push(next, next);\n }\n }\n\n if (order.length !== count) {\n throw new WireGraphError(\n 'Graph contains a cycle; no topological order exists. Use findCyclicGroups() to locate it.',\n );\n }\n return order;\n}\n\n/**\n * Returns the groups of nodes that are mutually reachable (strongly connected\n * components, Tarjan).\n *\n * Each returned group is an SCC with more than one node, or a single node carrying a\n * self-loop — never an exponential enumeration of elementary cycles. A group is a set\n * of nodes, not a path through them: members are sorted by input position, which does\n * not describe any particular cycle. Groups are ordered by the input position of their\n * first member, so results are deterministic.\n */\nexport function findCyclicGroups(nodeIds: readonly string[], edges: readonly Edge[]): string[][] {\n const index = buildNodeIndex(nodeIds);\n validateEdgeEndpoints(index, edges);\n\n const count = nodeIds.length;\n const outgoing: number[][] = Array.from({ length: count }, () => []);\n const selfLoop = new Array<boolean>(count).fill(false);\n for (const edge of edges) {\n const from = index.get(edge.from) as number;\n const to = index.get(edge.to) as number;\n if (from === to) selfLoop[from] = true;\n outgoing[from]!.push(to);\n }\n\n const lowLink = new Array<number>(count).fill(-1);\n const discovery = new Array<number>(count).fill(-1);\n const onStack = new Array<boolean>(count).fill(false);\n const stack: number[] = [];\n const cycles: string[][] = [];\n let time = 0;\n\n const strongConnect = (root: number): void => {\n // Iterative Tarjan: node editors can hold thousands of nodes, and recursion depth\n // must not scale with the longest dependency chain.\n const work: { node: number; child: number }[] = [{ child: 0, node: root }];\n const enter = (node: number): void => {\n discovery[node] = time;\n lowLink[node] = time;\n time += 1;\n stack.push(node);\n onStack[node] = true;\n };\n enter(root);\n\n while (work.length > 0) {\n const frame = work[work.length - 1] as { node: number; child: number };\n const children = outgoing[frame.node]!;\n if (frame.child < children.length) {\n const child = children[frame.child] as number;\n frame.child += 1;\n if (discovery[child] === -1) {\n enter(child);\n work.push({ child: 0, node: child });\n } else if (onStack[child]) {\n lowLink[frame.node] = Math.min(lowLink[frame.node] as number, discovery[child] as number);\n }\n continue;\n }\n\n work.pop();\n const parent = work[work.length - 1];\n if (parent) {\n lowLink[parent.node] = Math.min(lowLink[parent.node] as number, lowLink[frame.node] as number);\n }\n if ((lowLink[frame.node] as number) === (discovery[frame.node] as number)) {\n const component: number[] = [];\n let member = -1;\n do {\n member = stack.pop() as number;\n onStack[member] = false;\n component.push(member);\n } while (member !== frame.node);\n\n const isCyclic = component.length > 1 || (component.length === 1 && selfLoop[component[0] as number]);\n if (isCyclic) {\n component.sort((a, b) => a - b);\n cycles.push(component.map((member) => nodeIds[member] as string));\n }\n }\n }\n };\n\n for (let i = 0; i < count; i += 1) {\n if (discovery[i] === -1) strongConnect(i);\n }\n\n cycles.sort((a, b) => (index.get(a[0] as string) as number) - (index.get(b[0] as string) as number));\n return cycles;\n}\n","import { MinHeap } from './_heap.js';\nimport { DELTA, Dir, type Move, OPPOSITE, SIDE_DIR, SIDE_VECTOR } from './_sides.js';\nimport { WireConfigError } from './errors.js';\nimport type { Point, PortAnchor, PortSide, Rect } from './types.js';\n\n/** Configuration for `orthogonalRoute()`. */\nexport interface OrthogonalRouteOptions {\n /** Cost added per bend, on top of path length. Defaults to 12. */\n bendPenalty?: number;\n /**\n * Rectangles the route must not cross — typically every node's raw bounding box.\n * `padding` supplies the clearance, so do not inflate the rects yourself. The\n * obstacles a port sits inside are exempted for that port's straight exit segment\n * only; the rest of the route still avoids them.\n */\n obstacles?: readonly Rect[];\n /** Distance obstacles are inflated by; routes may travel along the inflated boundary. Defaults to 8. */\n padding?: number;\n /**\n * Distance the route runs straight out of a port before it may bend, and straight\n * into the target port. Defaults to 16; `0` disables the directional stubs (a port\n * inside an obstacle still exits straight to clear it).\n */\n stub?: number;\n}\n\n/** Number of direction slots packed per grid node in a state id (`node * DIR_COUNT + dir`). */\nconst DIR_COUNT = 5;\n\ninterface PaddedRect {\n x0: number;\n x1: number;\n y0: number;\n y1: number;\n}\n\nfunction padRect(rect: Rect, padding: number): PaddedRect {\n return {\n x0: rect.x - padding,\n x1: rect.x + rect.width + padding,\n y0: rect.y - padding,\n y1: rect.y + rect.height + padding,\n };\n}\n\n/** A point exactly on a padded boundary is free: routes are allowed to hug obstacle margins. */\nfunction pointBlocked(px: number, py: number, obstacles: readonly PaddedRect[]): boolean {\n for (const rect of obstacles) {\n if (px > rect.x0 && px < rect.x1 && py > rect.y0 && py < rect.y1) return true;\n }\n return false;\n}\n\n/** Whether the open axis-aligned span from `a` to `b` passes through an obstacle interior. */\nfunction spanBlocked(a: Point, b: Point, obstacles: readonly PaddedRect[]): boolean {\n const xLow = Math.min(a.x, b.x);\n const xHigh = Math.max(a.x, b.x);\n const yLow = Math.min(a.y, b.y);\n const yHigh = Math.max(a.y, b.y);\n for (const rect of obstacles) {\n if (yLow === yHigh) {\n if (yLow > rect.y0 && yLow < rect.y1 && xLow < rect.x1 && rect.x0 < xHigh) return true;\n } else if (xLow === xHigh && xLow > rect.x0 && xLow < rect.x1 && yLow < rect.y1 && rect.y0 < yHigh) {\n return true;\n }\n }\n return false;\n}\n\n/** Obstacles whose padded interior contains `point` — the obstacles that \"own\" the port. */\nfunction ownersOf(point: Point, obstacles: readonly PaddedRect[]): PaddedRect[] {\n return obstacles.filter((rect) => pointBlocked(point.x, point.y, [rect]));\n}\n\n/**\n * Distance from `point` to the padded boundary of `owners`, measured along `dir`.\n * Zero when the point is outside every owner.\n */\nfunction escapeDistance(point: Point, dir: Move, owners: readonly PaddedRect[]): number {\n const delta = DELTA[dir];\n let distance = 0;\n for (const rect of owners) {\n const along =\n delta.x > 0\n ? rect.x1 - point.x\n : delta.x < 0\n ? point.x - rect.x0\n : delta.y > 0\n ? rect.y1 - point.y\n : point.y - rect.y0;\n if (along > distance) distance = along;\n }\n return distance;\n}\n\n/**\n * Routes a Manhattan (axis-aligned) polyline between two ports over a visibility grid\n * built from the obstacle corners, using A* with a per-bend penalty.\n *\n * Pass every node's raw rect as `obstacles`; `padding` supplies the clearance. A port\n * that sits inside an obstacle (its own node, since ports are on node boundaries) is\n * exempted only for the straight exit segment out of that port; the searched route\n * never enters any padded obstacle interior, including its own nodes.\n *\n * Returns the waypoint polyline with `from` first and `to` last, or `null` when every\n * route is blocked (including a blocked exit segment). Cost is path length plus\n * `bendPenalty` per bend, so among equal length routes the one with fewer bends wins.\n * Expansion order is fully deterministic.\n */\nexport function orthogonalRoute(\n from: PortAnchor,\n to: PortAnchor,\n options: OrthogonalRouteOptions = {},\n): Point[] | null {\n const padding = options.padding ?? 8;\n const bendPenalty = options.bendPenalty ?? 12;\n const stub = options.stub ?? 16;\n if (!Number.isFinite(padding) || padding < 0) {\n throw new WireConfigError(`Orthogonal padding must be a finite non-negative number, received ${String(padding)}.`);\n }\n if (!Number.isFinite(bendPenalty) || bendPenalty < 0) {\n throw new WireConfigError(`Bend penalty must be a finite non-negative number, received ${String(bendPenalty)}.`);\n }\n if (!Number.isFinite(stub) || stub < 0) {\n throw new WireConfigError(`Stub must be a finite non-negative number, received ${String(stub)}.`);\n }\n\n const start: Point = { x: from.x, y: from.y };\n const goal: Point = { x: to.x, y: to.y };\n if (start.x === goal.x && start.y === goal.y) return [start];\n\n const obstacles = (options.obstacles ?? []).map((rect) => padRect(rect, padding));\n const startOwners = ownersOf(start, obstacles);\n const goalOwners = ownersOf(goal, obstacles);\n // Obstacles to check against for a segment leaving `owners`: everything except those owners.\n const othersFor = (owners: readonly PaddedRect[]): PaddedRect[] =>\n owners.length === 0 ? obstacles : obstacles.filter((rect) => !owners.includes(rect));\n const startOthers = othersFor(startOwners);\n const goalOthers = othersFor(goalOwners);\n\n // Port stubs: the route leaves the source port straight along its side and enters\n // the target port along that side, so wires never peel off a port sideways. A port\n // inside an obstacle always exits straight far enough to clear the obstacle margin,\n // even when `stub` is smaller than that distance (or zero).\n const fromDir = SIDE_DIR[from.side];\n const toDir = SIDE_DIR[to.side];\n\n // Straight shot: when the direct segment agrees with both port sides and is clear\n // of every obstacle except the endpoints' own owners, it is optimal by construction\n // (also covers facing ports closer than two stubs).\n if (start.x === goal.x || start.y === goal.y) {\n const dir: Move =\n start.x !== goal.x ? (goal.x > start.x ? Dir.Right : Dir.Left) : goal.y > start.y ? Dir.Down : Dir.Up;\n // A port with no forced exit (no stub, no owner to escape) accepts any direction.\n const agreesWithStart = (stub === 0 && startOwners.length === 0) || fromDir === dir;\n const agreesWithGoal = (stub === 0 && goalOwners.length === 0) || OPPOSITE[toDir] === dir;\n const freeSpan = obstacles.filter((rect) => !startOwners.includes(rect) && !goalOwners.includes(rect));\n if (agreesWithStart && agreesWithGoal && !spanBlocked(start, goal, freeSpan)) return [start, goal];\n }\n\n const exitTip = (point: Point, side: PortSide, dir: Move, owners: readonly PaddedRect[]): Point => {\n const vector = SIDE_VECTOR[side];\n const distance = Math.max(stub, escapeDistance(point, dir, owners));\n return { x: point.x + vector.x * distance, y: point.y + vector.y * distance };\n };\n const fromTip = exitTip(start, from.side, fromDir, startOwners);\n const toTip = exitTip(goal, to.side, toDir, goalOwners);\n\n // The exit segment may cross its own owners but no other obstacle; a blocked exit\n // means the port is walled in, so no route exists.\n if (spanBlocked(start, fromTip, startOthers)) return null;\n if (spanBlocked(goal, toTip, goalOthers)) return null;\n\n const routeStart = fromTip;\n const routeGoal = toTip;\n // `stub: 0` disables the directional stubs unless an owner escape forced one.\n const startDir: Dir = stub > 0 || startOwners.length > 0 ? fromDir : Dir.None;\n // The route must not arrive at the goal tip moving along the port's outward\n // direction (that would overshoot the port and double back); any other incoming\n // direction continues smoothly into the final stub segment.\n const forbiddenIncoming: Dir = stub > 0 || goalOwners.length > 0 ? toDir : Dir.None;\n\n // Grid lines: every obstacle edge plus the exit tips' own rows and columns.\n const xs = new Set<number>([routeStart.x, routeGoal.x]);\n const ys = new Set<number>([routeStart.y, routeGoal.y]);\n for (const rect of obstacles) {\n xs.add(rect.x0);\n xs.add(rect.x1);\n ys.add(rect.y0);\n ys.add(rect.y1);\n }\n const xLines = [...xs].sort((a, b) => a - b);\n const yLines = [...ys].sort((a, b) => a - b);\n const columns = xLines.length;\n const rows = yLines.length;\n const nodeCount = columns * rows;\n\n const nodeX = (node: number): number => xLines[node % columns] as number;\n const nodeY = (node: number): number => yLines[Math.floor(node / columns)] as number;\n const nodeAt = (x: number, y: number): number => yLines.indexOf(y) * columns + xLines.indexOf(x);\n\n const startNode = nodeAt(routeStart.x, routeStart.y);\n const goalNode = nodeAt(routeGoal.x, routeGoal.y);\n if (pointBlocked(nodeX(startNode), nodeY(startNode), obstacles)) return null;\n if (pointBlocked(nodeX(goalNode), nodeY(goalNode), obstacles)) return null;\n\n // State = grid node × incoming direction (Dir.None only for the start).\n const stateCount = nodeCount * DIR_COUNT;\n const gScore = new Float64Array(stateCount).fill(Number.POSITIVE_INFINITY);\n const parent = new Int32Array(stateCount).fill(-1);\n const closed = new Uint8Array(stateCount);\n\n const heuristic = (node: number): number => Math.abs(nodeX(node) - routeGoal.x) + Math.abs(nodeY(node) - routeGoal.y);\n const stateId = (node: number, dir: Dir): number => node * DIR_COUNT + dir;\n\n const open = new MinHeap();\n const startState = stateId(startNode, startDir);\n gScore[startState] = 0;\n open.push(heuristic(startNode), startState);\n\n let goalState = -1;\n while (open.size > 0 && goalState === -1) {\n const current = open.pop();\n if (closed[current]) continue;\n closed[current] = 1;\n\n const node = Math.floor(current / DIR_COUNT);\n const incoming = (current % DIR_COUNT) as Dir;\n if (node === goalNode && (forbiddenIncoming === Dir.None || incoming !== forbiddenIncoming)) {\n goalState = current;\n break;\n }\n\n const cx = nodeX(node);\n const cy = nodeY(node);\n const candidates: readonly [Dir, number][] = [\n [Dir.Left, node - 1],\n [Dir.Right, node + 1],\n [Dir.Up, node - columns],\n [Dir.Down, node + columns],\n ];\n for (const [dir, neighbor] of candidates) {\n // Validate grid bounds: Left/Right must stay in the same row, Up/Down in the same column.\n if (dir === Dir.Left && node % columns === 0) continue;\n if (dir === Dir.Right && node % columns === columns - 1) continue;\n if (dir === Dir.Up && node < columns) continue;\n if (dir === Dir.Down && node >= (rows - 1) * columns) continue;\n\n const nx = nodeX(neighbor);\n const ny = nodeY(neighbor);\n if (pointBlocked(nx, ny, obstacles)) continue;\n if (spanBlocked({ x: cx, y: cy }, { x: nx, y: ny }, obstacles)) continue;\n\n const step = Math.abs(nx - cx) + Math.abs(ny - cy);\n const bend = incoming !== Dir.None && incoming !== dir ? bendPenalty : 0;\n const nextScore = (gScore[current] as number) + step + bend;\n const nextState = stateId(neighbor, dir);\n if (nextScore < (gScore[nextState] as number)) {\n gScore[nextState] = nextScore;\n parent[nextState] = current;\n open.push(nextScore + heuristic(neighbor), nextState);\n }\n }\n }\n\n if (goalState === -1) return null;\n\n const nodes: number[] = [];\n for (let state = goalState; state !== -1; state = parent[state] as number) {\n nodes.push(Math.floor(state / DIR_COUNT));\n }\n nodes.reverse();\n\n // Collapse collinear runs so the polyline carries waypoints only at bends.\n const collapsed: Point[] = nodes\n .filter((node, i) => {\n if (i === 0 || i === nodes.length - 1) return true;\n const prev = nodes[i - 1] as number;\n const next = nodes[i + 1] as number;\n const collinear =\n (nodeX(prev) === nodeX(node) && nodeX(node) === nodeX(next)) ||\n (nodeY(prev) === nodeY(node) && nodeY(node) === nodeY(next));\n return !collinear;\n })\n .map((node) => ({ x: nodeX(node), y: nodeY(node) }));\n\n // Re-attach the exact ports outside the stub tips, then drop stub tips that are\n // collinear with their neighbours so a straight-through route keeps two points.\n const points = [start, ...collapsed, goal];\n for (let i = 1; i < points.length - 1; i += 1) {\n const prev = points[i - 1] as Point;\n const cur = points[i] as Point;\n const next = points[i + 1] as Point;\n if ((prev.x === cur.x && cur.x === next.x) || (prev.y === cur.y && cur.y === next.y)) {\n points.splice(i, 1);\n i -= 1;\n }\n }\n return points;\n}\n","/** Formats a number for SVG path output: rounded to micro-precision, no `-0`, no exponent noise. */\nexport function fmt(value: number): string {\n const rounded = Math.round(value * 1e6) / 1e6;\n return Object.is(rounded, -0) ? '0' : String(rounded);\n}\n","import { fmt } from './_format.js';\nimport type { CubicBezier, Point } from './types.js';\n\n/** Formats a polyline as an SVG path `d` string using absolute moveto and lineto commands. */\nexport function polylineToSvgPath(points: readonly Point[]): string {\n const first = points[0];\n if (!first) return '';\n const parts = [`M ${fmt(first.x)} ${fmt(first.y)}`];\n for (let i = 1; i < points.length; i += 1) {\n const point = points[i] as Point;\n parts.push(`L ${fmt(point.x)} ${fmt(point.y)}`);\n }\n return parts.join(' ');\n}\n\n/** Formats a cubic bezier segment as an SVG path `d` string using absolute curveto commands. */\nexport function bezierToSvgPath(curve: CubicBezier): string {\n return `M ${fmt(curve.from.x)} ${fmt(curve.from.y)} C ${fmt(curve.c1.x)} ${fmt(curve.c1.y)}, ${fmt(curve.c2.x)} ${fmt(curve.c2.y)}, ${fmt(curve.to.x)} ${fmt(curve.to.y)}`;\n}\n","import { WireConfigError } from './errors.js';\nimport type { PortAnchor, PortSide, Rect } from './types.js';\n\n/**\n * Places a port on `side` of `rect` and returns its world position with the side it faces.\n *\n * `offset` is the 0..1 fraction along the side (0 is the side's lower coordinate,\n * 0.5 the middle). Screen convention applies: `top` is smaller y.\n */\nexport function portAnchor(rect: Rect, side: PortSide, offset = 0.5): PortAnchor {\n if (!Number.isFinite(offset) || offset < 0 || offset > 1) {\n throw new WireConfigError(`Port offset must be a finite number between 0 and 1, received ${String(offset)}.`);\n }\n switch (side) {\n case 'bottom':\n return { side, x: rect.x + rect.width * offset, y: rect.y + rect.height };\n case 'left':\n return { side, x: rect.x, y: rect.y + rect.height * offset };\n case 'right':\n return { side, x: rect.x + rect.width, y: rect.y + rect.height * offset };\n case 'top':\n return { side, x: rect.x + rect.width * offset, y: rect.y };\n }\n}\n"],"mappings":";AAGA,IAAaA,IAAiD;CAC5D,QAAQ;EAAE,GAAG;EAAG,GAAG;CAAE;CACrB,MAAM;EAAE,GAAG;EAAI,GAAG;CAAE;CACpB,OAAO;EAAE,GAAG;EAAG,GAAG;CAAE;CACpB,KAAK;EAAE,GAAG;EAAG,GAAG;CAAG;AACrB,GAGaC,IAAM;CAAE,MAAM;CAAG,MAAM;CAAG,MAAM;CAAG,OAAO;CAAG,IAAI;AAAE,GAMnDC,IAAuC;EACjDD,EAAI,OAAO;EAAE,GAAG;EAAI,GAAG;CAAE;EACzBA,EAAI,QAAQ;EAAE,GAAG;EAAG,GAAG;CAAE;EACzBA,EAAI,KAAK;EAAE,GAAG;EAAG,GAAG;CAAG;EACvBA,EAAI,OAAO;EAAE,GAAG;EAAG,GAAG;CAAE;AAC3B,GAGaE,IAA6C;CACxD,QAAQF,EAAI;CACZ,MAAMA,EAAI;CACV,OAAOA,EAAI;CACX,KAAKA,EAAI;AACX,GAEaG,IAAyC;EACnDH,EAAI,OAAOA,EAAI;EACfA,EAAI,OAAOA,EAAI;EACfA,EAAI,QAAQA,EAAI;EAChBA,EAAI,KAAKA,EAAI;AAChB,GCpCa,YAAb,cAA+B,MAAM;CACnC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAMI,GAASC,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;AACF,GAGa,iBAAb,cAAoC,UAAU,CAAC,GA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AC,EAAE,GAAG,IAAIA,EAAM,GAAG,CAAC;AACzK;;ACTA,SAAgB,WAAW,GAAY,GAAgB,IAAS,IAAiB;CAC/E,IAAI,CAAC,OAAO,SAASC,CAAM,KAAKA,IAAS,KAAKA,IAAS,GACrD,MAAM,IAAI,gBAAgB,iEAAiE,OAAOA,CAAM,EAAE,EAAE;CAE9G,QAAQ9C,GAAR;EACE,KAAK,UACH,OAAO;GAAE;GAAM,GAAG7B,EAAK,IAAIA,EAAK,QAAQ2E;GAAQ,GAAG3E,EAAK,IAAIA,EAAK;EAAO;EAC1E,KAAK,QACH,OAAO;GAAE;GAAM,GAAGA,EAAK;GAAG,GAAGA,EAAK,IAAIA,EAAK,SAAS2E;EAAO;EAC7D,KAAK,SACH,OAAO;GAAE;GAAM,GAAG3E,EAAK,IAAIA,EAAK;GAAO,GAAGA,EAAK,IAAIA,EAAK,SAAS2E;EAAO;EAC1E,KAAK,OACH,OAAO;GAAE;GAAM,GAAG3E,EAAK,IAAIA,EAAK,QAAQ2E;GAAQ,GAAG3E,EAAK;EAAE;CAC9D;AACF"}
package/package.json CHANGED
@@ -1,6 +1,50 @@
1
1
  {
2
2
  "name": "@vielzeug/wire",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "26.11.23",
4
+ "description": "Edge routing and graph ordering for node editors",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/helmuthdu/vielzeug",
8
+ "directory": "packages/wire"
9
+ },
10
+ "license": "MIT",
11
+ "type": "module",
12
+ "engines": {
13
+ "node": ">=22"
14
+ },
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "main": "./dist/index.cjs",
19
+ "module": "./dist/index.js",
20
+ "types": "dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "import": "./dist/index.js",
24
+ "require": "./dist/index.cjs",
25
+ "types": "./dist/index.d.ts"
26
+ }
27
+ },
28
+ "sideEffects": false,
29
+ "publishConfig": {
30
+ "access": "public",
31
+ "registry": "https://registry.npmjs.org/"
32
+ },
33
+ "scripts": {
34
+ "build": "vite build && bun run --silent build:bundle && bun run --silent build:types && bun run --silent test:types && bun run --silent verify:exports",
35
+ "build:bundle": "vite build --config vite.bundle.config.ts",
36
+ "build:types": "tsc -p tsconfig.declarations.json",
37
+ "fix": "biome check --write src",
38
+ "lint": "biome ci src",
39
+ "prepublishOnly": "bun run --silent build",
40
+ "test": "vitest",
41
+ "test:types": "tsc -p tsconfig.type-tests.json",
42
+ "verify:exports": "bun verify-exports.mjs"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^26.6.6",
46
+ "typescript": "^6.0.3",
47
+ "vite": "^8.3.6",
48
+ "vitest": "^5.1.0"
49
+ }
50
+ }