@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Helmuth Saatkamp
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # Temporary Holding Version
1
+ # @vielzeug/wire
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > Edge routing and graph ordering for node editors
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ pnpm add @vielzeug/wire
9
+ npm install @vielzeug/wire
10
+ yarn add @vielzeug/wire
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```ts
16
+ import { bezierRoute, bezierToSvgPath, findCyclicGroups, orthogonalRoute, topologicalOrder } from '@vielzeug/wire';
17
+
18
+ const curve = bezierRoute({ side: 'right', x: 100, y: 40 }, { side: 'left', x: 320, y: 120 });
19
+ const d = bezierToSvgPath(curve);
20
+ const points = orthogonalRoute(
21
+ { side: 'right', x: 100, y: 40 },
22
+ { side: 'left', x: 320, y: 120 },
23
+ { obstacles: nodeBounds },
24
+ );
25
+ const order = topologicalOrder(['b', 'a'], [{ from: 'a', to: 'b' }]);
26
+ ```
27
+
28
+ ## Features
29
+
30
+ - `bezierRoute()`: cubic bezier geometry anchored to port sides
31
+ - `orthogonalRoute()`: deterministic A\* Manhattan routing over a padded-obstacle visibility graph with a per-bend penalty and owner-obstacle exemption; `null` when unreachable
32
+ - `portAnchor()`: world position of a port on a node rect, by side and 0..1 offset
33
+ - `bezierToSvgPath()` / `polylineToSvgPath()`: SVG `d` serialization with stable precision
34
+ - `topologicalOrder()`: Kahn ordering with stable input-order tie breaks
35
+ - `findCyclicGroups()`: iterative Tarjan SCC cycle detection (no recursion limits, no exponential enumeration)
36
+ - Typed errors (`WireError`, `WireGraphError`, `WireConfigError`)
37
+ - Zero runtime dependencies, no DOM requirement
38
+
39
+ ## Documentation
40
+
41
+ - [Overview](https://vielzeug.dev/wire/)
42
+ - [Usage Guide](https://vielzeug.dev/wire/usage)
43
+ - [API Reference](https://vielzeug.dev/wire/api)
44
+ - [Examples](https://vielzeug.dev/wire/examples)
45
+ - [Migration Guide](https://vielzeug.dev/wire/migration)
46
+
47
+ ## License
48
+
49
+ MIT © [Helmuth Saatkamp](https://github.com/helmuthdu): part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
@@ -0,0 +1,2 @@
1
+ function fmt(e){let t=Math.round(e*1e6)/1e6;return Object.is(t,-0)?`0`:String(t)}exports.fmt=fmt;
2
+ //# sourceMappingURL=_format.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_format.cjs","names":["rounded","value"],"sources":["../src/_format.ts"],"sourcesContent":["/** 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"],"mappings":"AACA,SAAgB,IAAI,EAAuB,CACzC,IAAMA,EAAU,KAAK,MAAMC,EAAQ,GAAG,EAAI,IAC1C,OAAO,OAAO,GAAGD,EAAS,EAAE,EAAI,IAAM,OAAOA,CAAO,CACtD,C"}
@@ -0,0 +1,3 @@
1
+ /** Formats a number for SVG path output: rounded to micro-precision, no `-0`, no exponent noise. */
2
+ export declare function fmt(value: number): string;
3
+ //# sourceMappingURL=_format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_format.d.ts","sourceRoot":"","sources":["../src/_format.ts"],"names":[],"mappings":"AAAA,oGAAoG;AACpG,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGzC"}
@@ -0,0 +1,8 @@
1
+ // src/_format.ts
2
+ function fmt(e) {
3
+ let t = Math.round(e * 1e6) / 1e6;
4
+ return Object.is(t, -0) ? "0" : String(t);
5
+ }
6
+ export { fmt };
7
+
8
+ //# sourceMappingURL=_format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_format.js","names":["rounded","value"],"sources":["../src/_format.ts"],"sourcesContent":["/** 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"],"mappings":";AACA,SAAgB,IAAI,GAAuB;CACzC,IAAMA,IAAU,KAAK,MAAMC,IAAQ,GAAG,IAAI;CAC1C,OAAO,OAAO,GAAGD,GAAS,EAAE,IAAI,MAAM,OAAOA,CAAO;AACtD"}
package/dist/_heap.cjs ADDED
@@ -0,0 +1,2 @@
1
+ var MinHeap=class{items=[];get size(){return this.items.length}push(e,t){let n=this.items;n.push({key:e,value:t});let r=n.length-1;for(;r>0;){let e=r-1>>1,t=n[e],i=n[r];if(t.key<=i.key)break;n[e]=i,n[r]=t,r=e}}pop(){let e=this.items,t=e[0],n=e.pop();if(e.length>0){e[0]=n;let t=0;for(;;){let n=t*2+1,r=n+1,i=t;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;let a=e[t],o=e[i];e[t]=o,e[i]=a,t=i}}return t.value}};exports.MinHeap=MinHeap;
2
+ //# sourceMappingURL=_heap.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_heap.cjs","names":["items","i","parent","parentItem","item","top","last","left","right","smallest","swap"],"sources":["../src/_heap.ts"],"sourcesContent":["/**\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"],"mappings":"AAKA,IAAa,QAAb,KAAqB,CACnB,MAA2D,CAAC,EAE5D,IAAI,MAAe,CACjB,OAAO,KAAK,MAAM,MACpB,CAEA,KAAK,EAAa,EAAqB,CACrC,IAAMA,EAAQ,KAAK,MACnBA,EAAM,KAAK,CAAE,MAAK,OAAM,CAAC,EACzB,IAAIC,EAAID,EAAM,OAAS,EACvB,KAAOC,EAAI,GAAG,CACZ,IAAMC,EAAUD,EAAI,GAAM,EACpBE,EAAaH,EAAME,GACnBE,EAAOJ,EAAMC,GACnB,GAAIE,EAAW,KAAOC,EAAK,IAAK,MAChC,EAAMF,GAAUE,EAChB,EAAMH,GAAKE,EACX,EAAID,CACN,CACF,CAEA,KAAc,CACZ,IAAMF,EAAQ,KAAK,MACbK,EAAML,EAAM,GACZM,EAAON,EAAM,IAAI,EACvB,GAAIA,EAAM,OAAS,EAAG,CACpB,EAAM,GAAKM,EACX,IAAIL,EAAI,EACR,OAAS,CACP,IAAMM,EAAON,EAAI,EAAI,EACfO,EAAQD,EAAO,EACjBE,EAAWR,EAGf,GAFIM,EAAOP,EAAM,QAAUA,EAAMO,EAAK,CAAE,IAAMP,EAAMS,EAAS,CAAE,MAAK,EAAWF,GAC3EC,EAAQR,EAAM,QAAUA,EAAMQ,EAAM,CAAE,IAAMR,EAAMS,EAAS,CAAE,MAAK,EAAWD,GAC7EC,IAAaR,EAAG,MACpB,IAAMG,EAAOJ,EAAMC,GACbS,EAAOV,EAAMS,GACnB,EAAMR,GAAKS,EACX,EAAMD,GAAYL,EAClB,EAAIK,CACN,CACF,CACA,OAAOJ,EAAI,KACb,CACF,E"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Binary min-heap ordered by a numeric key. Ties between equal keys resolve by heap
3
+ * structure, which is fully determined by the push sequence, so extraction is
4
+ * deterministic for identical input.
5
+ */
6
+ export declare class MinHeap {
7
+ private readonly items;
8
+ get size(): number;
9
+ push(key: number, value: number): void;
10
+ pop(): number;
11
+ }
12
+ //# sourceMappingURL=_heap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_heap.d.ts","sourceRoot":"","sources":["../src/_heap.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAwC;IAE9D,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAetC,GAAG,IAAI,MAAM;CAuBd"}
package/dist/_heap.js ADDED
@@ -0,0 +1,37 @@
1
+ // src/_heap.ts
2
+ var MinHeap = class {
3
+ items = [];
4
+ get size() {
5
+ return this.items.length;
6
+ }
7
+ push(e, t) {
8
+ let n = this.items;
9
+ n.push({
10
+ key: e,
11
+ value: t
12
+ });
13
+ let r = n.length - 1;
14
+ for (; r > 0;) {
15
+ let e = r - 1 >> 1, t = n[e], i = n[r];
16
+ if (t.key <= i.key) break;
17
+ n[e] = i, n[r] = t, r = e;
18
+ }
19
+ }
20
+ pop() {
21
+ let e = this.items, t = e[0], n = e.pop();
22
+ if (e.length > 0) {
23
+ e[0] = n;
24
+ let t = 0;
25
+ for (;;) {
26
+ let n = t * 2 + 1, r = n + 1, i = t;
27
+ 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;
28
+ let a = e[t], o = e[i];
29
+ e[t] = o, e[i] = a, t = i;
30
+ }
31
+ }
32
+ return t.value;
33
+ }
34
+ };
35
+ export { MinHeap };
36
+
37
+ //# sourceMappingURL=_heap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_heap.js","names":["items","i","parent","parentItem","item","top","last","left","right","smallest","swap"],"sources":["../src/_heap.ts"],"sourcesContent":["/**\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"],"mappings":";AAKA,IAAa,UAAb,MAAqB;CACnB,QAA2D,CAAC;CAE5D,IAAI,OAAe;EACjB,OAAO,KAAK,MAAM;CACpB;CAEA,KAAK,GAAa,GAAqB;EACrC,IAAMA,IAAQ,KAAK;EACnB,EAAM,KAAK;GAAE;GAAK;EAAM,CAAC;EACzB,IAAIC,IAAID,EAAM,SAAS;EACvB,OAAOC,IAAI,IAAG;GACZ,IAAMC,IAAUD,IAAI,KAAM,GACpBE,IAAaH,EAAME,IACnBE,IAAOJ,EAAMC;GACnB,IAAIE,EAAW,OAAOC,EAAK,KAAK;GAGhC,AAFA,EAAMF,KAAUE,GAChB,EAAMH,KAAKE,GACX,IAAID;EACN;CACF;CAEA,MAAc;EACZ,IAAMF,IAAQ,KAAK,OACbK,IAAML,EAAM,IACZM,IAAON,EAAM,IAAI;EACvB,IAAIA,EAAM,SAAS,GAAG;GACpB,EAAM,KAAKM;GACX,IAAIL,IAAI;GACR,SAAS;IACP,IAAMM,IAAON,IAAI,IAAI,GACfO,IAAQD,IAAO,GACjBE,IAAWR;IAGf,IAFIM,IAAOP,EAAM,UAAUA,EAAMO,EAAK,CAAE,MAAMP,EAAMS,EAAS,CAAE,QAAK,IAAWF,IAC3EC,IAAQR,EAAM,UAAUA,EAAMQ,EAAM,CAAE,MAAMR,EAAMS,EAAS,CAAE,QAAK,IAAWD,IAC7EC,MAAaR,GAAG;IACpB,IAAMG,IAAOJ,EAAMC,IACbS,IAAOV,EAAMS;IAGnB,AAFA,EAAMR,KAAKS,GACX,EAAMD,KAAYL,GAClB,IAAIK;GACN;EACF;EACA,OAAOJ,EAAI;CACb;AACF"}
@@ -0,0 +1,2 @@
1
+ var e={bottom:{x:0,y:1},left:{x:-1,y:0},right:{x:1,y:0},top:{x:0,y:-1}},t={Down:4,Left:1,None:0,Right:2,Up:3},n={[t.Left]:{x:-1,y:0},[t.Right]:{x:1,y:0},[t.Up]:{x:0,y:-1},[t.Down]:{x:0,y:1}},r={bottom:t.Down,left:t.Left,right:t.Right,top:t.Up},i={[t.Down]:t.Up,[t.Left]:t.Right,[t.Right]:t.Left,[t.Up]:t.Down};exports.DELTA=n,exports.Dir=t,exports.OPPOSITE=i,exports.SIDE_DIR=r,exports.SIDE_VECTOR=e;
2
+ //# sourceMappingURL=_sides.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_sides.cjs","names":["SIDE_VECTOR","Dir","DELTA","SIDE_DIR","OPPOSITE"],"sources":["../src/_sides.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"],"mappings":"AAGA,IAAaA,EAAiD,CAC5D,OAAQ,CAAE,EAAG,EAAG,EAAG,CAAE,EACrB,KAAM,CAAE,EAAG,GAAI,EAAG,CAAE,EACpB,MAAO,CAAE,EAAG,EAAG,EAAG,CAAE,EACpB,IAAK,CAAE,EAAG,EAAG,EAAG,EAAG,CACrB,EAGaC,EAAM,CAAE,KAAM,EAAG,KAAM,EAAG,KAAM,EAAG,MAAO,EAAG,GAAI,CAAE,EAMnDC,EAAuC,EACjDD,EAAI,MAAO,CAAE,EAAG,GAAI,EAAG,CAAE,GACzBA,EAAI,OAAQ,CAAE,EAAG,EAAG,EAAG,CAAE,GACzBA,EAAI,IAAK,CAAE,EAAG,EAAG,EAAG,EAAG,GACvBA,EAAI,MAAO,CAAE,EAAG,EAAG,EAAG,CAAE,CAC3B,EAGaE,EAA6C,CACxD,OAAQF,EAAI,KACZ,KAAMA,EAAI,KACV,MAAOA,EAAI,MACX,IAAKA,EAAI,EACX,EAEaG,EAAyC,EACnDH,EAAI,MAAOA,EAAI,IACfA,EAAI,MAAOA,EAAI,OACfA,EAAI,OAAQA,EAAI,MAChBA,EAAI,IAAKA,EAAI,IAChB,E"}
@@ -0,0 +1,20 @@
1
+ import type { Point, PortSide } from './types.js';
2
+ /** Outward unit vector for each port side; shared by the routers. */
3
+ export declare const SIDE_VECTOR: Readonly<Record<PortSide, Point>>;
4
+ /** Grid movement directions; `None` (0) marks a start state with no incoming direction. */
5
+ export declare const Dir: {
6
+ readonly Down: 4;
7
+ readonly Left: 1;
8
+ readonly None: 0;
9
+ readonly Right: 2;
10
+ readonly Up: 3;
11
+ };
12
+ export type Dir = (typeof Dir)[keyof typeof Dir];
13
+ /** The four real movement directions, excluding the `None` sentinel. */
14
+ export type Move = Exclude<Dir, typeof Dir.None>;
15
+ /** Unit steps per movement direction, in grid order. */
16
+ export declare const DELTA: Readonly<Record<Move, Point>>;
17
+ /** Outward direction a port on the given side faces. */
18
+ export declare const SIDE_DIR: Readonly<Record<PortSide, Move>>;
19
+ export declare const OPPOSITE: Readonly<Record<Move, Move>>;
20
+ //# sourceMappingURL=_sides.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_sides.d.ts","sourceRoot":"","sources":["../src/_sides.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAElD,qEAAqE;AACrE,eAAO,MAAM,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAKzD,CAAC;AAEF,2FAA2F;AAC3F,eAAO,MAAM,GAAG;;;;;;CAA0D,CAAC;AAC3E,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,GAAG,CAAC,CAAC,MAAM,OAAO,GAAG,CAAC,CAAC;AACjD,wEAAwE;AACxE,MAAM,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC;AAEjD,wDAAwD;AACxD,eAAO,MAAM,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAK/C,CAAC;AAEF,wDAAwD;AACxD,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAKrD,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAKjD,CAAC"}
package/dist/_sides.js ADDED
@@ -0,0 +1,55 @@
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
+ };
53
+ export { n as DELTA, t as Dir, i as OPPOSITE, r as SIDE_DIR, e as SIDE_VECTOR };
54
+
55
+ //# sourceMappingURL=_sides.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_sides.js","names":["SIDE_VECTOR","Dir","DELTA","SIDE_DIR","OPPOSITE"],"sources":["../src/_sides.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"],"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"}
@@ -0,0 +1,2 @@
1
+ const e=require("./_sides.cjs"),t=require("./errors.cjs");var n=40;function bezierRoute(r,i,a={}){let o=a.handleLength??n;if(!Number.isFinite(o)||o<0)throw new t.WireConfigError(`Bezier handleLength must be a finite non-negative number, received ${String(o)}.`);let s=e.SIDE_VECTOR[r.side],c=e.SIDE_VECTOR[i.side];return{c1:{x:r.x+s.x*o,y:r.y+s.y*o},c2:{x:i.x+c.x*o,y:i.y+c.y*o},from:{x:r.x,y:r.y},to:{x:i.x,y:i.y}}}exports.bezierRoute=bezierRoute;
2
+ //# sourceMappingURL=bezier.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bezier.cjs","names":["WireConfigError","SIDE_VECTOR","require__sides","require_errors","DEFAULT_HANDLE_LENGTH","handleLength","options","fromVector","from","toVector","to"],"sources":["../src/bezier.ts"],"sourcesContent":["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"],"mappings":"A,0DAKA,IAAMI,EAAwB,GAc9B,SAAgB,YAAY,EAAkB,EAAgB,EAA8B,CAAC,EAAgB,CAC3G,IAAMC,EAAeC,EAAQ,cAAgBF,EAC7C,GAAI,CAAC,OAAO,SAASC,CAAY,GAAKA,EAAe,EACnD,MAAM,IAAIL,EAAAA,gBACR,sEAAsE,OAAOK,CAAY,EAAE,EAC7F,EAGF,IAAME,EAAaN,EAAAA,YAAYO,EAAK,MAC9BC,EAAWR,EAAAA,YAAYS,EAAG,MAEhC,MAAO,CACL,GAAI,CAAE,EAAGF,EAAK,EAAID,EAAW,EAAIF,EAAc,EAAGG,EAAK,EAAID,EAAW,EAAIF,CAAa,EACvF,GAAI,CAAE,EAAGK,EAAG,EAAID,EAAS,EAAIJ,EAAc,EAAGK,EAAG,EAAID,EAAS,EAAIJ,CAAa,EAC/E,KAAM,CAAE,EAAGG,EAAK,EAAG,EAAGA,EAAK,CAAE,EAC7B,GAAI,CAAE,EAAGE,EAAG,EAAG,EAAGA,EAAG,CAAE,CACzB,CACF,C"}
@@ -0,0 +1,14 @@
1
+ import type { CubicBezier, PortAnchor } from './types.js';
2
+ /** Configuration for `bezierRoute()`. */
3
+ export interface BezierRouteOptions {
4
+ /** Distance each control point extends outward from its port along the port side. Defaults to 40. */
5
+ handleLength?: number;
6
+ }
7
+ /**
8
+ * Builds a cubic bezier segment between two ports.
9
+ *
10
+ * Control points extend outward from each port along its side, so the curve leaves
11
+ * and enters ports perpendicular to the node edge.
12
+ */
13
+ export declare function bezierRoute(from: PortAnchor, to: PortAnchor, options?: BezierRouteOptions): CubicBezier;
14
+ //# sourceMappingURL=bezier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bezier.d.ts","sourceRoot":"","sources":["../src/bezier.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAK1D,yCAAyC;AACzC,MAAM,WAAW,kBAAkB;IACjC,qGAAqG;IACrG,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,EAAE,OAAO,GAAE,kBAAuB,GAAG,WAAW,CAiB3G"}
package/dist/bezier.js ADDED
@@ -0,0 +1,30 @@
1
+ import { SIDE_VECTOR as e } from "./_sides.js";
2
+ import { WireConfigError as t } from "./errors.js";
3
+ // src/bezier.ts
4
+ var n = 40;
5
+ function bezierRoute(r, i, a = {}) {
6
+ let o = a.handleLength ?? n;
7
+ if (!Number.isFinite(o) || o < 0) throw new t(`Bezier handleLength must be a finite non-negative number, received ${String(o)}.`);
8
+ let s = e[r.side], c = e[i.side];
9
+ return {
10
+ c1: {
11
+ x: r.x + s.x * o,
12
+ y: r.y + s.y * o
13
+ },
14
+ c2: {
15
+ x: i.x + c.x * o,
16
+ y: i.y + c.y * o
17
+ },
18
+ from: {
19
+ x: r.x,
20
+ y: r.y
21
+ },
22
+ to: {
23
+ x: i.x,
24
+ y: i.y
25
+ }
26
+ };
27
+ }
28
+ export { bezierRoute };
29
+
30
+ //# sourceMappingURL=bezier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bezier.js","names":["DEFAULT_HANDLE_LENGTH","handleLength","options","WireConfigError","fromVector","SIDE_VECTOR","from","toVector","to"],"sources":["../src/bezier.ts"],"sourcesContent":["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"],"mappings":";;;AAKA,IAAMA,IAAwB;AAc9B,SAAgB,YAAY,GAAkB,GAAgB,IAA8B,CAAC,GAAgB;CAC3G,IAAMC,IAAeC,EAAQ,gBAAgBF;CAC7C,IAAI,CAAC,OAAO,SAASC,CAAY,KAAKA,IAAe,GACnD,MAAM,IAAIE,EACR,sEAAsE,OAAOF,CAAY,EAAE,EAC7F;CAGF,IAAMG,IAAaC,EAAYC,EAAK,OAC9BC,IAAWF,EAAYG,EAAG;CAEhC,OAAO;EACL,IAAI;GAAE,GAAGF,EAAK,IAAIF,EAAW,IAAIH;GAAc,GAAGK,EAAK,IAAIF,EAAW,IAAIH;EAAa;EACvF,IAAI;GAAE,GAAGO,EAAG,IAAID,EAAS,IAAIN;GAAc,GAAGO,EAAG,IAAID,EAAS,IAAIN;EAAa;EAC/E,MAAM;GAAE,GAAGK,EAAK;GAAG,GAAGA,EAAK;EAAE;EAC7B,IAAI;GAAE,GAAGE,EAAG;GAAG,GAAGA,EAAG;EAAE;CACzB;AACF"}
@@ -0,0 +1,2 @@
1
+ var WireError=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},WireGraphError=class extends WireError{},WireConfigError=class extends WireError{};exports.WireConfigError=WireConfigError,exports.WireError=WireError,exports.WireGraphError=WireGraphError;
2
+ //# sourceMappingURL=errors.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.cjs","names":["message","opts"],"sources":["../src/errors.ts"],"sourcesContent":["/** 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"],"mappings":"AACA,IAAa,UAAb,cAA+B,KAAM,CACnC,YAAY,EAAiB,EAAqB,CAChD,MAAMA,EAASC,CAAI,EACnB,KAAK,KAAO,WAAW,KACvB,OAAO,eAAe,KAAM,WAAW,SAAS,CAClD,CACF,EAGa,eAAb,cAAoC,SAAU,CAAC,EAGlC,gBAAb,cAAqC,SAAU,CAAC,E"}
@@ -0,0 +1,11 @@
1
+ /** Base class for all wire errors. Use `instanceof WireError` to catch any wire-originated error. */
2
+ export declare class WireError extends Error {
3
+ constructor(message: string, opts?: ErrorOptions);
4
+ }
5
+ /** Thrown when a graph operation receives an edge that references a node id outside the supplied node set. */
6
+ export declare class WireGraphError extends WireError {
7
+ }
8
+ /** Thrown when routing options are invalid, such as a negative `handleLength`, `padding`, `stub`, or `bendPenalty`. */
9
+ export declare class WireConfigError extends WireError {
10
+ }
11
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,YAAY;CAKjD;AAED,8GAA8G;AAC9G,qBAAa,cAAe,SAAQ,SAAS;CAAG;AAEhD,uHAAuH;AACvH,qBAAa,eAAgB,SAAQ,SAAS;CAAG"}
package/dist/errors.js ADDED
@@ -0,0 +1,9 @@
1
+ // src/errors.ts
2
+ var WireError = class extends Error {
3
+ constructor(e, t) {
4
+ super(e, t), this.name = new.target.name, Object.setPrototypeOf(this, new.target.prototype);
5
+ }
6
+ }, WireGraphError = class extends WireError {}, WireConfigError = class extends WireError {};
7
+ export { WireConfigError, WireError, WireGraphError };
8
+
9
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","names":["message","opts"],"sources":["../src/errors.ts"],"sourcesContent":["/** 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"],"mappings":";AACA,IAAa,YAAb,cAA+B,MAAM;CACnC,YAAY,GAAiB,GAAqB;EAGhD,AAFA,MAAMA,GAASC,CAAI,GACnB,KAAK,OAAO,WAAW,MACvB,OAAO,eAAe,MAAM,WAAW,SAAS;CAClD;AACF,GAGa,iBAAb,cAAoC,UAAU,CAAC,GAGlC,kBAAb,cAAqC,UAAU,CAAC"}
package/dist/graph.cjs ADDED
@@ -0,0 +1,2 @@
1
+ const e=require("./_heap.cjs"),t=require("./errors.cjs");function buildNodeIndex(e){let n=new Map;for(let r of e){if(n.has(r))throw new t.WireGraphError(`Duplicate node id "${r}" in the node list.`);n.set(r,n.size)}return n}function validateEdgeEndpoints(e,n){for(let r of n){if(!e.has(r.from))throw new t.WireGraphError(`Edge from "${r.from}" to "${r.to}" references unknown node id "${r.from}".`);if(!e.has(r.to))throw new t.WireGraphError(`Edge from "${r.from}" to "${r.to}" references unknown node id "${r.to}".`)}}function topologicalOrder(n,r){let i=buildNodeIndex(n);validateEdgeEndpoints(i,r);let a=n.length,o=Array.from({length:a},()=>[]),s=Array(a).fill(0);for(let e of r){let t=i.get(e.from),n=i.get(e.to);o[t].push(n),s[n]=(s[n]??0)+1}let c=new e.MinHeap;for(let e=0;e<a;e+=1)s[e]===0&&c.push(e,e);let l=[];for(;c.size>0;){let e=c.pop();l.push(n[e]);for(let t of o[e]){let e=(s[t]??0)-1;s[t]=e,e===0&&c.push(t,t)}}if(l.length!==a)throw new t.WireGraphError(`Graph contains a cycle; no topological order exists. Use findCyclicGroups() to locate it.`);return l}function findCyclicGroups(e,t){let n=buildNodeIndex(e);validateEdgeEndpoints(n,t);let r=e.length,i=Array.from({length:r},()=>[]),a=Array(r).fill(!1);for(let e of t){let t=n.get(e.from),r=n.get(e.to);t===r&&(a[t]=!0),i[t].push(r)}let o=Array(r).fill(-1),s=Array(r).fill(-1),c=Array(r).fill(!1),l=[],u=[],d=0,strongConnect=t=>{let n=[{child:0,node:t}],enter=e=>{s[e]=d,o[e]=d,d+=1,l.push(e),c[e]=!0};for(enter(t);n.length>0;){let t=n[n.length-1],r=i[t.node];if(t.child<r.length){let e=r[t.child];t.child+=1,s[e]===-1?(enter(e),n.push({child:0,node:e})):c[e]&&(o[t.node]=Math.min(o[t.node],s[e]));continue}n.pop();let d=n[n.length-1];if(d&&(o[d.node]=Math.min(o[d.node],o[t.node])),o[t.node]===s[t.node]){let n=[],r=-1;do r=l.pop(),c[r]=!1,n.push(r);while(r!==t.node);(n.length>1||n.length===1&&a[n[0]])&&(n.sort((e,t)=>e-t),u.push(n.map(t=>e[t])))}}};for(let e=0;e<r;e+=1)s[e]===-1&&strongConnect(e);return u.sort((e,t)=>n.get(e[0])-n.get(t[0])),u}exports.findCyclicGroups=findCyclicGroups,exports.topologicalOrder=topologicalOrder;
2
+ //# sourceMappingURL=graph.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.cjs","names":["WireGraphError","MinHeap","require__heap","require_errors","index","id","nodeIds","edge","edges","count","outgoing","indegree","from","to","ready","i","order","node","next","remaining","selfLoop","lowLink","discovery","onStack","stack","cycles","time","work","root","frame","children","child","parent","component","member","a","b"],"sources":["../src/graph.ts"],"sourcesContent":["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"],"mappings":"A,yDAKA,SAAS,eAAe,EAAiD,CACvE,IAAMI,EAAQ,IAAI,IAClB,IAAK,IAAMC,KAAMC,EAAS,CACxB,GAAIF,EAAM,IAAIC,CAAE,EACd,MAAM,IAAIL,EAAAA,eAAe,sBAAsBK,EAAG,oBAAoB,EAExED,EAAM,IAAIC,EAAID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A,CAAK,EACXJ,EAAK,KAAK,CAAE,MAAO,EAAG,KAAMI,CAAM,CAAC,GAC1BR,EAAQQ,KACjB,EAAQF,EAAM,MAAQ,KAAK,IAAIR,EAAQQ,EAAM,MAAiBP,EAAUS,EAAgB,GAE1F,QACF,CAEAJ,EAAK,IAAI,EACT,IAAMK,EAASL,EAAKA,EAAK,OAAS,GAIlC,GAHIK,IACF,EAAQA,EAAO,MAAQ,KAAK,IAAIX,EAAQW,EAAO,MAAiBX,EAAQQ,EAAM,KAAe,GAE1FR,EAAQQ,EAAM,QAAsBP,EAAUO,EAAM,MAAkB,CACzE,IAAMI,EAAsB,CAAC,EACzBC,EAAS,GACb,EACE,GAASV,EAAM,IAAI,EACnB,EAAQU,GAAU,GAClBD,EAAU,KAAKC,CAAM,QACdA,IAAWL,EAAM,OAETI,EAAU,OAAS,GAAMA,EAAU,SAAW,GAAKb,EAASa,EAAU,OAErFA,EAAU,MAAM,EAAG,IAAME,EAAIC,CAAC,EAC9BX,EAAO,KAAKQ,EAAU,IAAK,GAAW3B,EAAQ4B,EAAiB,CAAC,EAEpE,CACF,CACF,EAEA,IAAK,IAAInB,EAAI,EAAGA,EAAIN,EAAO,GAAK,EAC1Ba,EAAUP,KAAO,IAAI,cAAcA,CAAC,EAI1C,OADAU,EAAO,MAAM,EAAG,IAAOrB,EAAM,IAAI+B,EAAE,EAAY,EAAgB/B,EAAM,IAAIgC,EAAE,EAAY,CAAY,EAC5FX,CACT,C"}
@@ -0,0 +1,21 @@
1
+ import type { Edge } from './types.js';
2
+ /**
3
+ * Returns the node ids in topological order using Kahn's algorithm.
4
+ *
5
+ * Ties between ready nodes break by position in `nodeIds`, so the result is fully
6
+ * deterministic for the same inputs. Parallel edges are tolerated; self-loops and
7
+ * larger cycles make ordering impossible and throw `WireGraphError`.
8
+ */
9
+ export declare function topologicalOrder(nodeIds: readonly string[], edges: readonly Edge[]): string[];
10
+ /**
11
+ * Returns the groups of nodes that are mutually reachable (strongly connected
12
+ * components, Tarjan).
13
+ *
14
+ * Each returned group is an SCC with more than one node, or a single node carrying a
15
+ * self-loop — never an exponential enumeration of elementary cycles. A group is a set
16
+ * of nodes, not a path through them: members are sorted by input position, which does
17
+ * not describe any particular cycle. Groups are ordered by the input position of their
18
+ * first member, so results are deterministic.
19
+ */
20
+ export declare function findCyclicGroups(nodeIds: readonly string[], edges: readonly Edge[]): string[][];
21
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../src/graph.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAyBvC;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,MAAM,EAAE,CAsC7F;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,IAAI,EAAE,GAAG,MAAM,EAAE,EAAE,CA8E/F"}
package/dist/graph.js ADDED
@@ -0,0 +1,81 @@
1
+ import { MinHeap as e } from "./_heap.js";
2
+ import { WireGraphError as t } from "./errors.js";
3
+ // src/graph.ts
4
+ function buildNodeIndex(e) {
5
+ let n = /* @__PURE__ */ new Map();
6
+ for (let r of e) {
7
+ if (n.has(r)) throw new t(`Duplicate node id "${r}" in the node list.`);
8
+ n.set(r, n.size);
9
+ }
10
+ return n;
11
+ }
12
+ function validateEdgeEndpoints(e, n) {
13
+ for (let r of n) {
14
+ if (!e.has(r.from)) throw new t(`Edge from "${r.from}" to "${r.to}" references unknown node id "${r.from}".`);
15
+ if (!e.has(r.to)) throw new t(`Edge from "${r.from}" to "${r.to}" references unknown node id "${r.to}".`);
16
+ }
17
+ }
18
+ function topologicalOrder(n, r) {
19
+ let i = buildNodeIndex(n);
20
+ validateEdgeEndpoints(i, r);
21
+ let a = n.length, o = Array.from({ length: a }, () => []), s = Array(a).fill(0);
22
+ for (let e of r) {
23
+ let t = i.get(e.from), n = i.get(e.to);
24
+ o[t].push(n), s[n] = (s[n] ?? 0) + 1;
25
+ }
26
+ let c = new e();
27
+ for (let e = 0; e < a; e += 1) s[e] === 0 && c.push(e, e);
28
+ let l = [];
29
+ for (; c.size > 0;) {
30
+ let e = c.pop();
31
+ l.push(n[e]);
32
+ for (let t of o[e]) {
33
+ let e = (s[t] ?? 0) - 1;
34
+ s[t] = e, e === 0 && c.push(t, t);
35
+ }
36
+ }
37
+ if (l.length !== a) throw new t("Graph contains a cycle; no topological order exists. Use findCyclicGroups() to locate it.");
38
+ return l;
39
+ }
40
+ function findCyclicGroups(e, t) {
41
+ let n = buildNodeIndex(e);
42
+ validateEdgeEndpoints(n, t);
43
+ let r = e.length, i = Array.from({ length: r }, () => []), a = Array(r).fill(!1);
44
+ for (let e of t) {
45
+ let t = n.get(e.from), r = n.get(e.to);
46
+ t === r && (a[t] = !0), i[t].push(r);
47
+ }
48
+ let o = Array(r).fill(-1), s = Array(r).fill(-1), c = Array(r).fill(!1), l = [], u = [], d = 0, strongConnect = (t) => {
49
+ let n = [{
50
+ child: 0,
51
+ node: t
52
+ }], enter = (e) => {
53
+ s[e] = d, o[e] = d, d += 1, l.push(e), c[e] = !0;
54
+ };
55
+ for (enter(t); n.length > 0;) {
56
+ let t = n[n.length - 1], r = i[t.node];
57
+ if (t.child < r.length) {
58
+ let e = r[t.child];
59
+ t.child += 1, s[e] === -1 ? (enter(e), n.push({
60
+ child: 0,
61
+ node: e
62
+ })) : c[e] && (o[t.node] = Math.min(o[t.node], s[e]));
63
+ continue;
64
+ }
65
+ n.pop();
66
+ let d = n[n.length - 1];
67
+ if (d && (o[d.node] = Math.min(o[d.node], o[t.node])), o[t.node] === s[t.node]) {
68
+ let n = [], r = -1;
69
+ do
70
+ r = l.pop(), c[r] = !1, n.push(r);
71
+ while (r !== t.node);
72
+ (n.length > 1 || n.length === 1 && a[n[0]]) && (n.sort((e, t) => e - t), u.push(n.map((t) => e[t])));
73
+ }
74
+ }
75
+ };
76
+ for (let e = 0; e < r; e += 1) s[e] === -1 && strongConnect(e);
77
+ return u.sort((e, t) => n.get(e[0]) - n.get(t[0])), u;
78
+ }
79
+ export { findCyclicGroups, topologicalOrder };
80
+
81
+ //# sourceMappingURL=graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.js","names":["index","id","nodeIds","WireGraphError","edge","edges","count","outgoing","indegree","from","to","ready","MinHeap","i","order","node","next","remaining","selfLoop","lowLink","discovery","onStack","stack","cycles","time","work","root","frame","children","child","parent","component","member","a","b"],"sources":["../src/graph.ts"],"sourcesContent":["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"],"mappings":";;;AAKA,SAAS,eAAe,GAAiD;CACvE,IAAMA,oBAAQ,IAAI,IAAoB;CACtC,KAAK,IAAMC,KAAMC,GAAS;EACxB,IAAIF,EAAM,IAAIC,CAAE,GACd,MAAM,IAAIE,EAAe,sBAAsBF,EAAG,oBAAoB;EAExE,EAAM,IAAIA,GAAID,EAAM,IAAI;CAC1B;CACA,OAAOA;AACT;AAEA,SAAS,sBAAsB,GAAoC,GAA8B;CAC/F,KAAK,IAAMI,KAAQC,GAAO;EACxB,IAAI,CAACL,EAAM,IAAII,EAAK,IAAI,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BP,EAAUS,EAAgB;IAE1F;GACF;GAEA,EAAK,IAAI;GACT,IAAMC,IAASL,EAAKA,EAAK,SAAS;GAIlC,IAHIK,MACF,EAAQA,EAAO,QAAQ,KAAK,IAAIX,EAAQW,EAAO,OAAiBX,EAAQQ,EAAM,KAAe,IAE1FR,EAAQQ,EAAM,UAAsBP,EAAUO,EAAM,OAAkB;IACzE,IAAMI,IAAsB,CAAC,GACzBC,IAAS;IACb;KAGE,AAFA,IAASV,EAAM,IAAI,GACnB,EAAQU,KAAU,IAClBD,EAAU,KAAKC,CAAM;WACdA,MAAWL,EAAM;IAG1B,CADiBI,EAAU,SAAS,KAAMA,EAAU,WAAW,KAAKb,EAASa,EAAU,SAErFA,EAAU,MAAM,GAAG,MAAME,IAAIC,CAAC,GAC9BX,EAAO,KAAKQ,EAAU,KAAK,MAAW7B,EAAQ8B,EAAiB,CAAC;GAEpE;EACF;CACF;CAEA,KAAK,IAAInB,IAAI,GAAGA,IAAIP,GAAO,KAAK,GAC9B,AAAIc,EAAUP,OAAO,MAAI,cAAcA,CAAC;CAI1C,OADAU,EAAO,MAAM,GAAG,MAAOvB,EAAM,IAAIiC,EAAE,EAAY,IAAgBjC,EAAM,IAAIkC,EAAE,EAAY,CAAY,GAC5FX;AACT"}
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./bezier.cjs"),t=require("./errors.cjs"),n=require("./graph.cjs"),r=require("./orthogonal.cjs"),i=require("./path.cjs"),a=require("./ports.cjs");exports.WireConfigError=t.WireConfigError,exports.WireError=t.WireError,exports.WireGraphError=t.WireGraphError,exports.bezierRoute=e.bezierRoute,exports.bezierToSvgPath=i.bezierToSvgPath,exports.findCyclicGroups=n.findCyclicGroups,exports.orthogonalRoute=r.orthogonalRoute,exports.polylineToSvgPath=i.polylineToSvgPath,exports.portAnchor=a.portAnchor,exports.topologicalOrder=n.topologicalOrder;
@@ -0,0 +1,8 @@
1
+ export { type BezierRouteOptions, bezierRoute } from './bezier.js';
2
+ export { WireConfigError, WireError, WireGraphError } from './errors.js';
3
+ export { findCyclicGroups, topologicalOrder } from './graph.js';
4
+ export { type OrthogonalRouteOptions, orthogonalRoute } from './orthogonal.js';
5
+ export { bezierToSvgPath, polylineToSvgPath } from './path.js';
6
+ export { portAnchor } from './ports.js';
7
+ export type { CubicBezier, Edge, Point, PortAnchor, PortSide, Rect } from './types.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,kBAAkB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,KAAK,sBAAsB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC/D,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACxC,YAAY,EAAE,WAAW,EAAE,IAAI,EAAE,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ import { bezierRoute as e } from "./bezier.js";
2
+ import { WireConfigError as t, WireError as n, WireGraphError as r } from "./errors.js";
3
+ import { findCyclicGroups as i, topologicalOrder as a } from "./graph.js";
4
+ import { orthogonalRoute as o } from "./orthogonal.js";
5
+ import { bezierToSvgPath as s, polylineToSvgPath as c } from "./path.js";
6
+ import { portAnchor as l } from "./ports.js";
7
+ export { t as WireConfigError, n as WireError, r as WireGraphError, e as bezierRoute, s as bezierToSvgPath, i as findCyclicGroups, o as orthogonalRoute, c as polylineToSvgPath, l as portAnchor, a as topologicalOrder };
@@ -0,0 +1,2 @@
1
+ const e=require("./_heap.cjs"),t=require("./_sides.cjs"),n=require("./errors.cjs");var r=5;function padRect(e,t){return{x0:e.x-t,x1:e.x+e.width+t,y0:e.y-t,y1:e.y+e.height+t}}function pointBlocked(e,t,n){for(let r of n)if(e>r.x0&&e<r.x1&&t>r.y0&&t<r.y1)return!0;return!1}function spanBlocked(e,t,n){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);for(let e of n)if(a===o){if(a>e.y0&&a<e.y1&&r<e.x1&&e.x0<i)return!0}else if(r===i&&r>e.x0&&r<e.x1&&a<e.y1&&e.y0<o)return!0;return!1}function ownersOf(e,t){return t.filter(t=>pointBlocked(e.x,e.y,[t]))}function escapeDistance(e,n,r){let i=t.DELTA[n],a=0;for(let t of r){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;n>a&&(a=n)}return a}function orthogonalRoute(i,a,o={}){let s=o.padding??8,c=o.bendPenalty??12,l=o.stub??16;if(!Number.isFinite(s)||s<0)throw new n.WireConfigError(`Orthogonal padding must be a finite non-negative number, received ${String(s)}.`);if(!Number.isFinite(c)||c<0)throw new n.WireConfigError(`Bend penalty must be a finite non-negative number, received ${String(c)}.`);if(!Number.isFinite(l)||l<0)throw new n.WireConfigError(`Stub must be a finite non-negative number, received ${String(l)}.`);let u={x:i.x,y:i.y},d={x:a.x,y:a.y};if(u.x===d.x&&u.y===d.y)return[u];let f=(o.obstacles??[]).map(e=>padRect(e,s)),p=ownersOf(u,f),m=ownersOf(d,f),othersFor=e=>e.length===0?f:f.filter(t=>!e.includes(t)),h=othersFor(p),g=othersFor(m),_=t.SIDE_DIR[i.side],v=t.SIDE_DIR[a.side];if(u.x===d.x||u.y===d.y){let e=u.x===d.x?d.y>u.y?t.Dir.Down:t.Dir.Up:d.x>u.x?t.Dir.Right:t.Dir.Left,n=l===0&&p.length===0||_===e,r=l===0&&m.length===0||t.OPPOSITE[v]===e,i=f.filter(e=>!p.includes(e)&&!m.includes(e));if(n&&r&&!spanBlocked(u,d,i))return[u,d]}let exitTip=(e,n,r,i)=>{let a=t.SIDE_VECTOR[n],o=Math.max(l,escapeDistance(e,r,i));return{x:e.x+a.x*o,y:e.y+a.y*o}},y=exitTip(u,i.side,_,p),b=exitTip(d,a.side,v,m);if(spanBlocked(u,y,h)||spanBlocked(d,b,g))return null;let x=y,S=b,C=l>0||p.length>0?_:t.Dir.None,w=l>0||m.length>0?v:t.Dir.None,T=new Set([x.x,S.x]),E=new Set([x.y,S.y]);for(let e of f)T.add(e.x0),T.add(e.x1),E.add(e.y0),E.add(e.y1);let D=[...T].sort((e,t)=>e-t),O=[...E].sort((e,t)=>e-t),k=D.length,A=O.length,j=k*A,nodeX=e=>D[e%k],nodeY=e=>O[Math.floor(e/k)],nodeAt=(e,t)=>O.indexOf(t)*k+D.indexOf(e),M=nodeAt(x.x,x.y),N=nodeAt(S.x,S.y);if(pointBlocked(nodeX(M),nodeY(M),f)||pointBlocked(nodeX(N),nodeY(N),f))return null;let P=j*r,F=new Float64Array(P).fill(1/0),I=new Int32Array(P).fill(-1),L=new Uint8Array(P),heuristic=e=>Math.abs(nodeX(e)-S.x)+Math.abs(nodeY(e)-S.y),stateId=(e,t)=>e*r+t,R=new e.MinHeap,z=stateId(M,C);F[z]=0,R.push(heuristic(M),z);let B=-1;for(;R.size>0&&B===-1;){let e=R.pop();if(L[e])continue;L[e]=1;let n=Math.floor(e/r),i=e%r;if(n===N&&(w===t.Dir.None||i!==w)){B=e;break}let a=nodeX(n),o=nodeY(n),s=[[t.Dir.Left,n-1],[t.Dir.Right,n+1],[t.Dir.Up,n-k],[t.Dir.Down,n+k]];for(let[r,l]of s){if(r===t.Dir.Left&&n%k===0||r===t.Dir.Right&&n%k===k-1||r===t.Dir.Up&&n<k||r===t.Dir.Down&&n>=(A-1)*k)continue;let s=nodeX(l),u=nodeY(l);if(pointBlocked(s,u,f)||spanBlocked({x:a,y:o},{x:s,y:u},f))continue;let d=Math.abs(s-a)+Math.abs(u-o),p=i!==t.Dir.None&&i!==r?c:0,m=F[e]+d+p,h=stateId(l,r);m<F[h]&&(F[h]=m,I[h]=e,R.push(m+heuristic(l),h))}}if(B===-1)return null;let V=[];for(let e=B;e!==-1;e=I[e])V.push(Math.floor(e/r));V.reverse();let H=[u,...V.filter((e,t)=>{if(t===0||t===V.length-1)return!0;let n=V[t-1],r=V[t+1];return!(nodeX(n)===nodeX(e)&&nodeX(e)===nodeX(r)||nodeY(n)===nodeY(e)&&nodeY(e)===nodeY(r))}).map(e=>({x:nodeX(e),y:nodeY(e)})),d];for(let e=1;e<H.length-1;e+=1){let t=H[e-1],n=H[e],r=H[e+1];(t.x===n.x&&n.x===r.x||t.y===n.y&&n.y===r.y)&&(H.splice(e,1),--e)}return H}exports.orthogonalRoute=orthogonalRoute;
2
+ //# sourceMappingURL=orthogonal.cjs.map