@vibecook/ice 0.1.0 → 0.2.0

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 (115) hide show
  1. package/README.md +37 -2
  2. package/dist/chunk-5SJYHQI4.js +636 -0
  3. package/dist/chunk-5SJYHQI4.js.map +1 -0
  4. package/dist/{chunk-5S7GSXJG.js → chunk-DXU3RZZS.js} +2913 -1180
  5. package/dist/chunk-DXU3RZZS.js.map +1 -0
  6. package/dist/{chunk-FIAXPNNY.js → chunk-IASTQMU5.js} +130 -551
  7. package/dist/chunk-IASTQMU5.js.map +1 -0
  8. package/dist/{chunk-BCJ47SX7.js → chunk-OR5FNVUE.js} +460 -1
  9. package/dist/chunk-OR5FNVUE.js.map +1 -0
  10. package/dist/devtools.js +508 -372
  11. package/dist/devtools.js.map +1 -1
  12. package/dist/dom.js +3 -11
  13. package/dist/ground.js +715 -0
  14. package/dist/ground.js.map +1 -0
  15. package/dist/index.js +70 -2
  16. package/dist/kernel.js +31 -1
  17. package/dist/r3f.js +599 -62
  18. package/dist/r3f.js.map +1 -1
  19. package/dist/react.js +34 -418
  20. package/dist/react.js.map +1 -1
  21. package/dist/types/packages/core/src/catalog/camera-derived.d.ts +41 -3
  22. package/dist/types/packages/core/src/catalog/gesture.d.ts +39 -3
  23. package/dist/types/packages/core/src/catalog/graph.d.ts +7 -6
  24. package/dist/types/packages/core/src/catalog/index.d.ts +1 -0
  25. package/dist/types/packages/core/src/catalog/insert.d.ts +31 -0
  26. package/dist/types/packages/core/src/catalog/pointer.d.ts +11 -0
  27. package/dist/types/packages/core/src/catalog/scene.d.ts +37 -4
  28. package/dist/types/packages/core/src/catalog/selection-presence.d.ts +7 -0
  29. package/dist/types/packages/core/src/catalog/settings-resources.d.ts +21 -0
  30. package/dist/types/packages/core/src/doc/autosave.d.ts +15 -2
  31. package/dist/types/packages/core/src/doc/bootstrap.d.ts +29 -0
  32. package/dist/types/packages/core/src/doc/channels.d.ts +9 -0
  33. package/dist/types/packages/core/src/doc/doc-commit-sink.d.ts +2 -1
  34. package/dist/types/packages/core/src/doc/doc-kit.d.ts +16 -1
  35. package/dist/types/packages/core/src/doc/envelope.d.ts +2 -1
  36. package/dist/types/packages/core/src/doc/migrate.d.ts +8 -6
  37. package/dist/types/packages/core/src/doc/schema-migrate.d.ts +50 -0
  38. package/dist/types/packages/core/src/doc/version-gate.d.ts +3 -0
  39. package/dist/types/packages/core/src/engine/commit-sink.d.ts +24 -2
  40. package/dist/types/packages/core/src/engine/frame-info.d.ts +16 -1
  41. package/dist/types/packages/core/src/facade/create-canvas-engine.d.ts +70 -6
  42. package/dist/types/packages/core/src/guards/guarded-tx.d.ts +4 -2
  43. package/dist/types/packages/core/src/helpers/churn-guard.d.ts +40 -0
  44. package/dist/types/packages/core/src/index.d.ts +13 -7
  45. package/dist/types/packages/core/src/input/queue.d.ts +11 -0
  46. package/dist/types/packages/core/src/nav/nested-canvas.d.ts +47 -11
  47. package/dist/types/packages/core/src/ops/arrange.d.ts +15 -0
  48. package/dist/types/packages/core/src/ops/insert.d.ts +62 -0
  49. package/dist/types/packages/core/src/ops/point-pick.d.ts +11 -7
  50. package/dist/types/packages/core/src/ops/sibling-order.d.ts +70 -0
  51. package/dist/types/packages/core/src/schema/meta.d.ts +1 -0
  52. package/dist/types/packages/core/src/settings/defaults.d.ts +45 -0
  53. package/dist/types/packages/core/src/settings/ground-config.d.ts +55 -0
  54. package/dist/types/packages/core/src/systems/chrome.d.ts +6 -2
  55. package/dist/types/packages/core/src/systems/insert-ghost.d.ts +25 -0
  56. package/dist/types/packages/core/src/systems/l1-pick.d.ts +25 -11
  57. package/dist/types/packages/core/src/systems/l2-recognize.d.ts +10 -4
  58. package/dist/types/packages/core/src/systems/l3-behave.d.ts +6 -4
  59. package/dist/types/packages/core/src/systems/l3-claim.d.ts +7 -3
  60. package/dist/types/packages/core/src/systems/l3-drop.d.ts +3 -1
  61. package/dist/types/packages/core/src/systems/l3-resize.d.ts +3 -1
  62. package/dist/types/packages/core/src/systems/l3-snap.d.ts +25 -7
  63. package/dist/types/packages/core/src/systems/nav-flight.d.ts +95 -0
  64. package/dist/types/packages/core/src/widget/define-widget.d.ts +39 -0
  65. package/dist/types/packages/core/src/widget/mount-store.d.ts +11 -3
  66. package/dist/types/packages/core/src/widget/set-props.d.ts +16 -0
  67. package/dist/types/packages/core/src/widget/spawn.d.ts +21 -1
  68. package/dist/types/packages/devtools/src/attach.d.ts +77 -0
  69. package/dist/types/packages/devtools/src/dock.d.ts +38 -0
  70. package/dist/types/packages/devtools/src/gl-panel.d.ts +69 -0
  71. package/dist/types/packages/devtools/src/index.d.ts +8 -6
  72. package/dist/types/packages/dom/src/index.d.ts +1 -3
  73. package/dist/types/packages/dom/src/measure-wiring.d.ts +2 -2
  74. package/dist/types/packages/dom/src/pointer-adapter.d.ts +21 -1
  75. package/dist/types/packages/dom/src/reflectors/dom-widgets.d.ts +5 -0
  76. package/dist/types/packages/ground/src/index.d.ts +52 -0
  77. package/dist/types/packages/ground/src/layer.d.ts +40 -0
  78. package/dist/types/packages/ground/src/pass.d.ts +41 -0
  79. package/dist/types/packages/ground/src/passes/grid.d.ts +21 -0
  80. package/dist/types/packages/ground/src/passes/guides-collect.d.ts +14 -0
  81. package/dist/types/packages/ground/src/passes/guides.d.ts +3 -0
  82. package/dist/types/packages/ground/src/passes/soup-collect.d.ts +35 -0
  83. package/dist/types/packages/ground/src/passes/soup-mesh.d.ts +8 -0
  84. package/dist/types/packages/ground/src/passes/wires-collect.d.ts +31 -0
  85. package/dist/types/packages/ground/src/passes/wires.d.ts +10 -0
  86. package/dist/types/packages/ground/src/renderer.d.ts +15 -0
  87. package/dist/types/packages/ice/src/ground.d.ts +1 -0
  88. package/dist/types/packages/kernel/src/bezier.d.ts +15 -0
  89. package/dist/types/packages/kernel/src/coords.d.ts +15 -0
  90. package/dist/types/packages/kernel/src/easing.d.ts +11 -0
  91. package/dist/types/packages/kernel/src/index.d.ts +3 -0
  92. package/dist/types/packages/kernel/src/layout.d.ts +118 -0
  93. package/dist/types/packages/kernel/src/nav-flight.d.ts +93 -0
  94. package/dist/types/packages/r3f/src/bridge.d.ts +73 -12
  95. package/dist/types/packages/r3f/src/composite-material.d.ts +9 -0
  96. package/dist/types/packages/r3f/src/compositor-pass.d.ts +22 -0
  97. package/dist/types/packages/r3f/src/gl-root.d.ts +76 -1
  98. package/dist/types/packages/r3f/src/gl-router.d.ts +10 -0
  99. package/dist/types/packages/r3f/src/index.d.ts +3 -2
  100. package/dist/types/packages/r3f/src/island-state.d.ts +44 -0
  101. package/dist/types/packages/r3f/src/preview-capture.d.ts +19 -0
  102. package/dist/types/packages/r3f/src/self-sustain.d.ts +39 -0
  103. package/dist/types/packages/r3f/src/use-island-frame.d.ts +16 -1
  104. package/dist/types/packages/react/src/engine-context.d.ts +8 -0
  105. package/dist/types/packages/react/src/index.d.ts +4 -2
  106. package/dist/types/packages/react/src/infinite-canvas.d.ts +40 -6
  107. package/dist/types/packages/react/src/preview-snapshots.d.ts +17 -0
  108. package/dist/types/packages/react/src/widget-preview.d.ts +14 -0
  109. package/package.json +13 -8
  110. package/dist/chunk-5S7GSXJG.js.map +0 -1
  111. package/dist/chunk-BCJ47SX7.js.map +0 -1
  112. package/dist/chunk-FIAXPNNY.js.map +0 -1
  113. package/dist/types/packages/devtools/src/panel.d.ts +0 -48
  114. package/dist/types/packages/dom/src/reflectors/grid.d.ts +0 -63
  115. package/dist/types/packages/dom/src/reflectors/wires.d.ts +0 -88
@@ -36,6 +36,15 @@ function zoomAtPoint(camera, screenX, screenY, newZoom) {
36
36
  zoom: newZoom
37
37
  };
38
38
  }
39
+ function fitCamera(content, vpW, vpH, opts) {
40
+ const fit = Math.min(vpW / (content.width + opts.pad * 2), vpH / (content.height + opts.pad * 2));
41
+ const zoom = Math.min(opts.maxZoom, Math.max(opts.minZoom, fit));
42
+ return {
43
+ x: content.x + content.width / 2 - vpW / (2 * zoom),
44
+ y: content.y + content.height / 2 - vpH / (2 * zoom),
45
+ zoom
46
+ };
47
+ }
39
48
  function planeCssTransform(camera) {
40
49
  return {
41
50
  tx: -camera.x * camera.zoom,
@@ -488,6 +497,62 @@ function cubicAABB(c) {
488
497
  maxY: Math.max(c.y0, c.y1, c.y2, c.y3)
489
498
  };
490
499
  }
500
+ function flatEnough(c, tolSq) {
501
+ const dx = c.x3 - c.x0;
502
+ const dy = c.y3 - c.y0;
503
+ const chordSq = dx * dx + dy * dy;
504
+ if (chordSq <= 1e-12) {
505
+ const d12 = Math.hypot(c.x1 - c.x0, c.y1 - c.y0);
506
+ const d22 = Math.hypot(c.x2 - c.x0, c.y2 - c.y0);
507
+ return (d12 + d22) * (d12 + d22) <= tolSq;
508
+ }
509
+ const d1 = Math.abs((c.x1 - c.x0) * dy - (c.y1 - c.y0) * dx);
510
+ const d2 = Math.abs((c.x2 - c.x0) * dy - (c.y2 - c.y0) * dx);
511
+ return (d1 + d2) * (d1 + d2) <= tolSq * chordSq;
512
+ }
513
+ function splitCubic(c) {
514
+ const ax = (c.x0 + c.x1) / 2;
515
+ const ay = (c.y0 + c.y1) / 2;
516
+ const bx = (c.x1 + c.x2) / 2;
517
+ const by = (c.y1 + c.y2) / 2;
518
+ const cx = (c.x2 + c.x3) / 2;
519
+ const cy = (c.y2 + c.y3) / 2;
520
+ const abx = (ax + bx) / 2;
521
+ const aby = (ay + by) / 2;
522
+ const bcx = (bx + cx) / 2;
523
+ const bcy = (by + cy) / 2;
524
+ const mx = (abx + bcx) / 2;
525
+ const my = (aby + bcy) / 2;
526
+ return [
527
+ { x0: c.x0, y0: c.y0, x1: ax, y1: ay, x2: abx, y2: aby, x3: mx, y3: my },
528
+ { x0: mx, y0: my, x1: bcx, y1: bcy, x2: cx, y2: cy, x3: c.x3, y3: c.y3 }
529
+ ];
530
+ }
531
+ function tessellateCubic(c, tolerance = 0.25, maxDepth = 16) {
532
+ const pts = [c.x0, c.y0];
533
+ const tolSq = tolerance * tolerance;
534
+ const walk = (cur, depth) => {
535
+ if (depth >= maxDepth || flatEnough(cur, tolSq)) {
536
+ pts.push(cur.x3, cur.y3);
537
+ return;
538
+ }
539
+ const [l, r] = splitCubic(cur);
540
+ walk(l, depth + 1);
541
+ walk(r, depth + 1);
542
+ };
543
+ walk(c, 0);
544
+ const n = pts.length / 2;
545
+ const points = new Float32Array(pts);
546
+ const arcLength = new Float32Array(n);
547
+ let acc = 0;
548
+ for (let i = 1; i < n; i++) {
549
+ const dx = pts[i * 2] - pts[i * 2 - 2];
550
+ const dy = pts[i * 2 + 1] - pts[i * 2 - 1];
551
+ acc += Math.hypot(dx, dy);
552
+ arcLength[i] = acc;
553
+ }
554
+ return { points, arcLength };
555
+ }
491
556
  function distanceToSegment(px, py, ax, ay, bx, by) {
492
557
  const dx = bx - ax;
493
558
  const dy = by - ay;
@@ -513,6 +578,385 @@ function distanceToCubic(px, py, c, samples = 32) {
513
578
  return best;
514
579
  }
515
580
 
581
+ // ../kernel/src/easing.ts
582
+ function sample(u, p1, p2) {
583
+ const v = 1 - u;
584
+ return 3 * v * v * u * p1 + 3 * v * u * u * p2 + u * u * u;
585
+ }
586
+ function cubicBezierEase(x1, y1, x2, y2) {
587
+ const cx1 = Math.min(1, Math.max(0, x1));
588
+ const cx2 = Math.min(1, Math.max(0, x2));
589
+ const sampleDx = (u) => {
590
+ const v = 1 - u;
591
+ return 3 * v * v * cx1 + 6 * v * u * (cx2 - cx1) + 3 * u * u * (1 - cx2);
592
+ };
593
+ return (t) => {
594
+ if (t <= 0) return 0;
595
+ if (t >= 1) return 1;
596
+ let u = t;
597
+ for (let i = 0; i < 8; i++) {
598
+ const err = sample(u, cx1, cx2) - t;
599
+ if (Math.abs(err) < 1e-6) return sample(u, y1, y2);
600
+ const d = sampleDx(u);
601
+ if (d < 1e-6) break;
602
+ u = Math.min(1, Math.max(0, u - err / d));
603
+ }
604
+ let lo = 0;
605
+ let hi = 1;
606
+ u = t;
607
+ while (hi - lo > 1e-6) {
608
+ if (sample(u, cx1, cx2) < t) lo = u;
609
+ else hi = u;
610
+ u = (lo + hi) / 2;
611
+ }
612
+ return sample(u, y1, y2);
613
+ };
614
+ }
615
+
616
+ // ../kernel/src/nav-flight.ts
617
+ function visibleRect(cam, vpW, vpH) {
618
+ return { x: cam.x, y: cam.y, width: vpW / cam.zoom, height: vpH / cam.zoom };
619
+ }
620
+ function portalAffine(arrival, portal) {
621
+ const s = Math.min(portal.width / arrival.width, portal.height / arrival.height);
622
+ return {
623
+ s,
624
+ ox: portal.x + portal.width / 2 - (arrival.x + arrival.width / 2) * s,
625
+ oy: portal.y + portal.height / 2 - (arrival.y + arrival.height / 2) * s
626
+ };
627
+ }
628
+ function invertAffine(a) {
629
+ return { s: 1 / a.s, ox: -a.ox / a.s, oy: -a.oy / a.s };
630
+ }
631
+ function composeAffine(outer, inner) {
632
+ return { s: outer.s * inner.s, ox: outer.ox + inner.ox * outer.s, oy: outer.oy + inner.oy * outer.s };
633
+ }
634
+ function solveFlightStart(A, camPre) {
635
+ return {
636
+ x: A.ox + camPre.x * A.s,
637
+ y: A.oy + camPre.y * A.s,
638
+ zoom: camPre.zoom / A.s
639
+ };
640
+ }
641
+ function flightOctaves(from, to) {
642
+ return Math.abs(Math.log2(to.zoom / from.zoom));
643
+ }
644
+ function capFlightStart(exact, arrival, vpW, vpH, maxOctaves, capFactor) {
645
+ if (flightOctaves(exact, arrival) <= maxOctaves) return { c0: exact, capped: false };
646
+ const zCap = exact.zoom > arrival.zoom ? arrival.zoom * capFactor : arrival.zoom / capFactor;
647
+ return {
648
+ c0: {
649
+ x: exact.x + vpW / 2 * (1 / exact.zoom - 1 / zCap),
650
+ y: exact.y + vpH / 2 * (1 / exact.zoom - 1 / zCap),
651
+ zoom: zCap
652
+ },
653
+ capped: true
654
+ };
655
+ }
656
+ function flightCamera(c0, c1, p, vpW, vpH) {
657
+ const zoom = Math.exp(Math.log(c0.zoom) + (Math.log(c1.zoom) - Math.log(c0.zoom)) * p);
658
+ const inv0 = 1 / c0.zoom;
659
+ const inv1 = 1 / c1.zoom;
660
+ const inv = 1 / zoom;
661
+ const w = Math.abs(inv1 - inv0) < 1e-12 ? p : (inv - inv0) / (inv1 - inv0);
662
+ const cx = c0.x + vpW * inv0 * 0.5 + (c1.x + vpW * inv1 * 0.5 - (c0.x + vpW * inv0 * 0.5)) * w;
663
+ const cy = c0.y + vpH * inv0 * 0.5 + (c1.y + vpH * inv1 * 0.5 - (c0.y + vpH * inv0 * 0.5)) * w;
664
+ return { x: cx - vpW * inv * 0.5, y: cy - vpH * inv * 0.5, zoom };
665
+ }
666
+ function springStep(p, v, omega, dtSec) {
667
+ const u = 1 - p;
668
+ const B = -v + omega * u;
669
+ const decay = Math.exp(-omega * dtSec);
670
+ const u2 = (u + B * dtSec) * decay;
671
+ const du2 = (B - omega * (u + B * dtSec)) * decay;
672
+ return { p: 1 - u2, v: -du2 };
673
+ }
674
+
675
+ // ../kernel/src/layout.ts
676
+ function crowds(a, b, gutter) {
677
+ return a.x < b.x + b.w + gutter && b.x < a.x + a.w + gutter && a.y < b.y + b.h + gutter && b.y < a.y + a.h + gutter;
678
+ }
679
+ function isFree(x, y, size, incumbents, gutter) {
680
+ const r = { x, y, w: size.w, h: size.h };
681
+ for (const i of incumbents) {
682
+ if (crowds(r, i, gutter)) return false;
683
+ }
684
+ return true;
685
+ }
686
+ function insertSlot(incumbents, size, hint, gutter) {
687
+ if (incumbents.length === 0 || isFree(hint.x, hint.y, size, incumbents, gutter)) {
688
+ return { x: hint.x, y: hint.y };
689
+ }
690
+ let best;
691
+ let bestD = Number.POSITIVE_INFINITY;
692
+ for (const i of incumbents) {
693
+ const candidates = [
694
+ { x: i.x + i.w + gutter, y: i.y },
695
+ // right, top-aligned
696
+ { x: i.x, y: i.y + i.h + gutter },
697
+ // below, left-aligned
698
+ { x: i.x - size.w - gutter, y: i.y },
699
+ // left, top-aligned
700
+ { x: i.x, y: i.y - size.h - gutter },
701
+ // above, left-aligned
702
+ { x: i.x + i.w + gutter, y: i.y + i.h - size.h },
703
+ // right, bottom-aligned
704
+ { x: i.x + i.w - size.w, y: i.y + i.h + gutter }
705
+ // below, right-aligned
706
+ ];
707
+ for (const c of candidates) {
708
+ if (!isFree(c.x, c.y, size, incumbents, gutter)) continue;
709
+ const d = (c.x - hint.x) ** 2 + (c.y - hint.y) ** 2;
710
+ if (d < bestD) {
711
+ bestD = d;
712
+ best = c;
713
+ }
714
+ }
715
+ }
716
+ if (best !== void 0) return best;
717
+ let maxRight = Number.NEGATIVE_INFINITY;
718
+ for (const i of incumbents) maxRight = Math.max(maxRight, i.x + i.w);
719
+ return { x: maxRight + gutter, y: hint.y };
720
+ }
721
+ function packLayout(items, opts) {
722
+ if (items.length === 0) return [];
723
+ const gutter = opts.gutter;
724
+ let ox;
725
+ let oy;
726
+ if (opts.origin !== void 0) {
727
+ ox = opts.origin.x;
728
+ oy = opts.origin.y;
729
+ } else {
730
+ ox = Number.POSITIVE_INFINITY;
731
+ oy = Number.POSITIVE_INFINITY;
732
+ for (const it of items) {
733
+ ox = Math.min(ox, it.x);
734
+ oy = Math.min(oy, it.y);
735
+ }
736
+ }
737
+ let maxWidth = opts.maxWidth;
738
+ if (maxWidth === void 0) {
739
+ let area = 0;
740
+ let widest = 0;
741
+ for (const it of items) {
742
+ area += (it.w + gutter) * (it.h + gutter);
743
+ widest = Math.max(widest, it.w);
744
+ }
745
+ maxWidth = Math.max(widest, Math.sqrt(area * 1.6));
746
+ }
747
+ const order = items.map((_, i) => i).sort((a, b) => {
748
+ const ia = items[a];
749
+ const ib = items[b];
750
+ return ia.y - ib.y || ia.x - ib.x || a - b;
751
+ });
752
+ const placed = [...opts.obstacles ?? []];
753
+ const out = new Array(items.length);
754
+ for (const idx of order) {
755
+ const it = items[idx];
756
+ const cands = [{ x: ox, y: oy }];
757
+ for (const r of placed) {
758
+ cands.push({ x: r.x + r.w + gutter, y: r.y });
759
+ cands.push({ x: r.x, y: r.y + r.h + gutter });
760
+ cands.push({ x: ox, y: r.y + r.h + gutter });
761
+ }
762
+ let best;
763
+ for (const inBand of [true, false]) {
764
+ for (const c of cands) {
765
+ if (c.x < ox || c.y < oy) continue;
766
+ if (inBand && c.x + it.w > ox + maxWidth) continue;
767
+ if (!isFree(c.x, c.y, it, placed, gutter)) continue;
768
+ if (best === void 0 || c.y < best.y || c.y === best.y && c.x < best.x) best = c;
769
+ }
770
+ if (best !== void 0) break;
771
+ }
772
+ if (best === void 0) {
773
+ let maxBottom = oy;
774
+ for (const r of placed) maxBottom = Math.max(maxBottom, r.y + r.h);
775
+ best = { x: ox, y: maxBottom + gutter };
776
+ }
777
+ out[idx] = { x: best.x, y: best.y };
778
+ placed.push({ x: best.x, y: best.y, w: it.w, h: it.h });
779
+ }
780
+ return out;
781
+ }
782
+ function layerGraph(nodes, edges, opts) {
783
+ const n = nodes.length;
784
+ if (n === 0) return [];
785
+ const outAdj = Array.from({ length: n }, () => []);
786
+ for (const [u, v] of edges) {
787
+ if (u !== v && u >= 0 && u < n && v >= 0 && v < n) outAdj[u]?.push(v);
788
+ }
789
+ const kept = [];
790
+ const state = new Array(n).fill(0);
791
+ for (let root = 0; root < n; root++) {
792
+ if (state[root] !== 0) continue;
793
+ const stack = [{ u: root, i: 0 }];
794
+ state[root] = 1;
795
+ while (stack.length > 0) {
796
+ const top = stack[stack.length - 1];
797
+ const adj = outAdj[top.u];
798
+ if (top.i < adj.length) {
799
+ const v = adj[top.i];
800
+ top.i += 1;
801
+ if (state[v] === 1) continue;
802
+ kept.push([top.u, v]);
803
+ if (state[v] === 0) {
804
+ state[v] = 1;
805
+ stack.push({ u: v, i: 0 });
806
+ }
807
+ } else {
808
+ state[top.u] = 2;
809
+ stack.pop();
810
+ }
811
+ }
812
+ }
813
+ const keptOut = Array.from({ length: n }, () => []);
814
+ const indeg = new Array(n).fill(0);
815
+ for (const [u, v] of kept) {
816
+ keptOut[u]?.push(v);
817
+ indeg[v] = indeg[v] + 1;
818
+ }
819
+ const rank = new Array(n).fill(0);
820
+ const queue = [];
821
+ for (let i = 0; i < n; i++) if (indeg[i] === 0) queue.push(i);
822
+ for (let qi = 0; qi < queue.length; qi++) {
823
+ const u = queue[qi];
824
+ for (const v of keptOut[u]) {
825
+ rank[v] = Math.max(rank[v], rank[u] + 1);
826
+ indeg[v] = indeg[v] - 1;
827
+ if (indeg[v] === 0) queue.push(v);
828
+ }
829
+ }
830
+ const maxRank = Math.max(...rank);
831
+ const layers = Array.from({ length: maxRank + 1 }, () => []);
832
+ for (let i = 0; i < n; i++) layers[rank[i]]?.push(i);
833
+ const neighbors = Array.from({ length: n }, () => []);
834
+ for (const [u, v] of kept) {
835
+ neighbors[u]?.push(v);
836
+ neighbors[v]?.push(u);
837
+ }
838
+ const slot = new Array(n).fill(0);
839
+ const reSlot = () => {
840
+ for (const layer of layers) {
841
+ layer.forEach((node, s) => {
842
+ slot[node] = s;
843
+ });
844
+ }
845
+ };
846
+ reSlot();
847
+ const crossings = () => {
848
+ let total = 0;
849
+ for (let li = 0; li < maxRank; li++) {
850
+ const pairs = [];
851
+ for (const [u, v] of kept) {
852
+ if (rank[u] === li && rank[v] === li + 1) pairs.push([slot[u], slot[v]]);
853
+ }
854
+ for (let i = 0; i < pairs.length; i++) {
855
+ for (let j = i + 1; j < pairs.length; j++) {
856
+ const a = pairs[i];
857
+ const b = pairs[j];
858
+ if ((a[0] - b[0]) * (a[1] - b[1]) < 0) total += 1;
859
+ }
860
+ }
861
+ }
862
+ return total;
863
+ };
864
+ const snapshot = () => layers.map((l) => [...l]);
865
+ const restore = (saved) => {
866
+ saved.forEach((l, li) => {
867
+ layers[li] = [...l];
868
+ });
869
+ reSlot();
870
+ };
871
+ let best = snapshot();
872
+ let bestX = crossings();
873
+ for (let sweep = 0; sweep < 4 && bestX > 0; sweep++) {
874
+ const forward = sweep % 2 === 0;
875
+ for (let li = forward ? 1 : maxRank - 1; forward ? li <= maxRank : li >= 0; li += forward ? 1 : -1) {
876
+ const layer = layers[li];
877
+ const bary = (node) => {
878
+ const ns = neighbors[node].filter((m) => Math.abs(rank[m] - li) === 1);
879
+ if (ns.length === 0) return slot[node];
880
+ return ns.reduce((sum, m) => sum + slot[m], 0) / ns.length;
881
+ };
882
+ layer.sort((a, b) => bary(a) - bary(b) || a - b);
883
+ reSlot();
884
+ }
885
+ const x = crossings();
886
+ if (x < bestX) {
887
+ bestX = x;
888
+ best = snapshot();
889
+ }
890
+ }
891
+ restore(best);
892
+ let improved = bestX > 0;
893
+ for (let round = 0; round < 4 && improved; round++) {
894
+ improved = false;
895
+ for (const layer of layers) {
896
+ for (let s = 0; s + 1 < layer.length; s++) {
897
+ const a = layer[s];
898
+ const b = layer[s + 1];
899
+ layer[s] = b;
900
+ layer[s + 1] = a;
901
+ reSlot();
902
+ const x = crossings();
903
+ if (x < bestX) {
904
+ bestX = x;
905
+ improved = true;
906
+ } else {
907
+ layer[s] = a;
908
+ layer[s + 1] = b;
909
+ reSlot();
910
+ }
911
+ }
912
+ }
913
+ }
914
+ const colW = layers.map((layer) => {
915
+ let widest = 0;
916
+ for (const node of layer) widest = Math.max(widest, nodes[node].w);
917
+ return widest;
918
+ });
919
+ const colH = layers.map(
920
+ (layer) => layer.reduce((sum, node, i) => sum + nodes[node].h + (i > 0 ? opts.gapY : 0), 0)
921
+ );
922
+ const bands = [];
923
+ if (opts.maxWidth === void 0) {
924
+ bands.push(layers.map((_, li) => li));
925
+ } else {
926
+ let cur = [];
927
+ let width = 0;
928
+ for (let li = 0; li <= maxRank; li++) {
929
+ const grown = (cur.length > 0 ? width + opts.gapX : 0) + colW[li];
930
+ if (cur.length > 0 && grown > opts.maxWidth) {
931
+ bands.push(cur);
932
+ cur = [li];
933
+ width = colW[li];
934
+ } else {
935
+ cur.push(li);
936
+ width = grown;
937
+ }
938
+ }
939
+ if (cur.length > 0) bands.push(cur);
940
+ }
941
+ const out = new Array(n);
942
+ let bandTop = 0;
943
+ for (const band of bands) {
944
+ let tallest = 0;
945
+ for (const li of band) tallest = Math.max(tallest, colH[li]);
946
+ let x = 0;
947
+ for (const li of band) {
948
+ let y = bandTop + (tallest - colH[li]) / 2;
949
+ for (const node of layers[li]) {
950
+ out[node] = { x, y };
951
+ y += nodes[node].h + opts.gapY;
952
+ }
953
+ x += colW[li] + opts.gapX;
954
+ }
955
+ bandTop += tallest + opts.gapY * 2;
956
+ }
957
+ return out;
958
+ }
959
+
516
960
  // ../kernel/src/index.ts
517
961
  var KERNEL_VERSION = "0.0.0";
518
962
 
@@ -525,6 +969,7 @@ export {
525
969
  screenToWorld,
526
970
  worldToScreen,
527
971
  zoomAtPoint,
972
+ fitCamera,
528
973
  planeCssTransform,
529
974
  worldToIsland,
530
975
  islandToWorld,
@@ -543,8 +988,22 @@ export {
543
988
  wireCubic,
544
989
  cubicPoint,
545
990
  cubicAABB,
991
+ tessellateCubic,
546
992
  distanceToSegment,
547
993
  distanceToCubic,
994
+ cubicBezierEase,
995
+ visibleRect,
996
+ portalAffine,
997
+ invertAffine,
998
+ composeAffine,
999
+ solveFlightStart,
1000
+ flightOctaves,
1001
+ capFlightStart,
1002
+ flightCamera,
1003
+ springStep,
1004
+ insertSlot,
1005
+ packLayout,
1006
+ layerGraph,
548
1007
  KERNEL_VERSION
549
1008
  };
550
- //# sourceMappingURL=chunk-BCJ47SX7.js.map
1009
+ //# sourceMappingURL=chunk-OR5FNVUE.js.map