glassbrain 0.1.3 → 0.2.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -52,7 +52,7 @@ import {
52
52
  unionSides,
53
53
  untheme,
54
54
  validateModel
55
- } from "./chunk-W357BGA7.js";
55
+ } from "./chunk-VCM766BZ.js";
56
56
  import {
57
57
  DetailPanel,
58
58
  I,
@@ -71,7 +71,7 @@ import {
71
71
  } from "./chunk-ZA47FP7C.js";
72
72
 
73
73
  // src/react/GraphCanvas.tsx
74
- import { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo5, useRef as useRef4, useState as useState4 } from "react";
74
+ import { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo5, useRef as useRef4, useState as useState5 } from "react";
75
75
 
76
76
  // src/paint.ts
77
77
  var MIN_DOT = 2;
@@ -1476,7 +1476,77 @@ function idPhase(id) {
1476
1476
  }
1477
1477
 
1478
1478
  // src/react/Toolbar.tsx
1479
- import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
1479
+ import { useEffect, useLayoutEffect as useLayoutEffect2, useMemo, useRef, useState as useState2 } from "react";
1480
+
1481
+ // src/react/placement.ts
1482
+ import { useLayoutEffect, useState } from "react";
1483
+ var GAP2 = 6;
1484
+ var MARGIN = 8;
1485
+ function placePanel(anchor, panel, boundary, prefer) {
1486
+ const combos = [
1487
+ prefer,
1488
+ { side: prefer.side, align: prefer.align === "start" ? "end" : "start" },
1489
+ { side: prefer.side === "bottom" ? "top" : "bottom", align: prefer.align },
1490
+ { side: prefer.side === "bottom" ? "top" : "bottom", align: prefer.align === "start" ? "end" : "start" }
1491
+ ];
1492
+ const at = (c) => ({
1493
+ left: c.align === "start" ? anchor.left : anchor.right - panel.width,
1494
+ top: c.side === "bottom" ? anchor.bottom + GAP2 : anchor.top - GAP2 - panel.height
1495
+ });
1496
+ const fits = (c) => {
1497
+ const p2 = at(c);
1498
+ return p2.left >= boundary.left + MARGIN && p2.left + panel.width <= boundary.right - MARGIN && p2.top >= boundary.top + MARGIN && p2.top + panel.height <= boundary.bottom - MARGIN;
1499
+ };
1500
+ const chosen = combos.find(fits) ?? prefer;
1501
+ const p = at(chosen);
1502
+ const minLeft = boundary.left + MARGIN;
1503
+ const maxLeft = Math.max(minLeft, boundary.right - MARGIN - panel.width);
1504
+ const minTop = boundary.top + MARGIN;
1505
+ const maxTop = Math.max(minTop, boundary.bottom - MARGIN - panel.height);
1506
+ return {
1507
+ ...chosen,
1508
+ left: Math.min(Math.max(p.left, minLeft), maxLeft),
1509
+ top: Math.min(Math.max(p.top, minTop), maxTop)
1510
+ };
1511
+ }
1512
+ function usePanelPlacement(open, anchorRef, panelRef, prefer, boundaryRef) {
1513
+ const [placement, setPlacement] = useState(null);
1514
+ useLayoutEffect(() => {
1515
+ if (!open) {
1516
+ setPlacement(null);
1517
+ return;
1518
+ }
1519
+ const anchor = anchorRef.current, panel = panelRef.current;
1520
+ if (!anchor || !panel) return;
1521
+ const boundary = boundaryRef?.current ?? anchor.closest(".gb-stage") ?? document.documentElement;
1522
+ const update = () => {
1523
+ const next = placePanel(
1524
+ anchor.getBoundingClientRect(),
1525
+ { width: panel.offsetWidth, height: panel.offsetHeight },
1526
+ boundary.getBoundingClientRect(),
1527
+ prefer
1528
+ );
1529
+ const parent = panel.offsetParent;
1530
+ const rect = parent?.getBoundingClientRect();
1531
+ next.left -= (rect?.left ?? 0) + (parent?.clientLeft ?? 0) - (parent?.scrollLeft ?? 0);
1532
+ next.top -= (rect?.top ?? 0) + (parent?.clientTop ?? 0) - (parent?.scrollTop ?? 0);
1533
+ setPlacement((old) => old && old.left === next.left && old.top === next.top && old.side === next.side && old.align === next.align ? old : next);
1534
+ };
1535
+ update();
1536
+ const ro = new ResizeObserver(update);
1537
+ for (const el of [anchor, panel, boundary]) ro.observe(el);
1538
+ window.addEventListener("resize", update);
1539
+ window.addEventListener("scroll", update, true);
1540
+ return () => {
1541
+ ro.disconnect();
1542
+ window.removeEventListener("resize", update);
1543
+ window.removeEventListener("scroll", update, true);
1544
+ };
1545
+ }, [open, anchorRef, panelRef, boundaryRef, prefer.side, prefer.align]);
1546
+ return placement;
1547
+ }
1548
+
1549
+ // src/react/Toolbar.tsx
1480
1550
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
1481
1551
  var ALL_CONTROLS = ["search", "origins", "layers", "relayout", "zoom"];
1482
1552
  function Hl({ text, re }) {
@@ -1494,11 +1564,12 @@ function Hl({ text, re }) {
1494
1564
  function LayerPicker({ layers, view, setView, disabled }) {
1495
1565
  const t = useStrings();
1496
1566
  const box = useRef(null);
1497
- const [thumb, setThumb] = useState(null);
1567
+ const [thumb, setThumb] = useState2(null);
1568
+ const [edges, setEdges] = useState2({ left: false, right: false });
1498
1569
  const stacked = !!view.planes;
1499
1570
  const on = new Set(view.layers ?? layers.map((l) => l.id));
1500
1571
  const single = stacked ? null : view.layers?.[0] ?? layers[0].id;
1501
- useLayoutEffect(() => {
1572
+ useLayoutEffect2(() => {
1502
1573
  const root = box.current;
1503
1574
  if (!root || single == null) {
1504
1575
  setThumb(null);
@@ -1508,13 +1579,29 @@ function LayerPicker({ layers, view, setView, disabled }) {
1508
1579
  const el = root.querySelector(`button[data-v="${CSS.escape(single)}"]`);
1509
1580
  if (!el) return;
1510
1581
  const r = root.getBoundingClientRect(), e = el.getBoundingClientRect();
1511
- setThumb({ x: e.left - r.left - root.clientLeft, w: e.width });
1582
+ setThumb({ x: e.left - r.left - root.clientLeft + root.scrollLeft, w: e.width });
1512
1583
  };
1513
1584
  measure();
1514
1585
  const ro = new ResizeObserver(measure);
1515
1586
  ro.observe(root);
1516
1587
  return () => ro.disconnect();
1517
1588
  }, [single, layers.length]);
1589
+ useLayoutEffect2(() => {
1590
+ const root = box.current;
1591
+ if (!root) return;
1592
+ const update = () => {
1593
+ const max = root.scrollWidth - root.clientWidth;
1594
+ setEdges({ left: root.scrollLeft > 1, right: root.scrollLeft < max - 1 });
1595
+ };
1596
+ update();
1597
+ const ro = new ResizeObserver(update);
1598
+ ro.observe(root);
1599
+ root.addEventListener("scroll", update, { passive: true });
1600
+ return () => {
1601
+ ro.disconnect();
1602
+ root.removeEventListener("scroll", update);
1603
+ };
1604
+ }, [layers.length]);
1518
1605
  const click = (id) => {
1519
1606
  if (!stacked) {
1520
1607
  if (id !== single) setView({ layers: [id] });
@@ -1524,24 +1611,26 @@ function LayerPicker({ layers, view, setView, disabled }) {
1524
1611
  const next = layers.map((l) => l.id).filter((l) => l === id ? !on.has(l) : on.has(l));
1525
1612
  setView({ layers: next });
1526
1613
  };
1527
- return /* @__PURE__ */ jsxs("div", { className: `gb-segm gb-layers${stacked ? " is-multi" : ""}`, ref: box, role: stacked ? "group" : "radiogroup", children: [
1528
- thumb && /* @__PURE__ */ jsx("i", { className: "gb-thumb", style: { transform: `translateX(${thumb.x}px)`, width: thumb.w } }),
1529
- layers.map((l) => {
1530
- const lit = stacked ? on.has(l.id) : l.id === single;
1531
- return /* @__PURE__ */ jsx(
1532
- "button",
1533
- {
1534
- "data-v": l.id,
1535
- disabled,
1536
- className: lit ? "on" : "",
1537
- ...stacked ? { "aria-pressed": lit } : { role: "radio", "aria-checked": lit },
1538
- title: stacked ? t.stackLayer(l.label, lit) : t.viewLayer(l.label),
1539
- onClick: () => click(l.id),
1540
- children: l.label
1541
- },
1542
- l.id
1543
- );
1544
- }),
1614
+ return /* @__PURE__ */ jsxs("div", { className: `gb-segm gb-layers${stacked ? " is-multi" : ""}`, role: stacked ? "group" : "radiogroup", children: [
1615
+ /* @__PURE__ */ jsxs("div", { className: `gb-layer-track${edges.left ? " can-left" : ""}${edges.right ? " can-right" : ""}`, ref: box, children: [
1616
+ thumb && /* @__PURE__ */ jsx("i", { className: "gb-thumb", style: { transform: `translateX(${thumb.x}px)`, width: thumb.w } }),
1617
+ layers.map((l) => {
1618
+ const lit = stacked ? on.has(l.id) : l.id === single;
1619
+ return /* @__PURE__ */ jsx(
1620
+ "button",
1621
+ {
1622
+ "data-v": l.id,
1623
+ disabled,
1624
+ className: lit ? "on" : "",
1625
+ ...stacked ? { "aria-pressed": lit } : { role: "radio", "aria-checked": lit },
1626
+ title: stacked ? t.stackLayer(l.label, lit) : t.viewLayer(l.label),
1627
+ onClick: () => click(l.id),
1628
+ children: l.label
1629
+ },
1630
+ l.id
1631
+ );
1632
+ })
1633
+ ] }),
1545
1634
  /* @__PURE__ */ jsx("span", { className: "gb-sep", "aria-hidden": true }),
1546
1635
  /* @__PURE__ */ jsx(
1547
1636
  "button",
@@ -1557,9 +1646,13 @@ function LayerPicker({ layers, view, setView, disabled }) {
1557
1646
  )
1558
1647
  ] });
1559
1648
  }
1560
- function usePopover() {
1561
- const [open, setOpen] = useState(false);
1649
+ var MENU_PLACE = { side: "bottom", align: "start" };
1650
+ var ISSUES_PLACE = { side: "top", align: "end" };
1651
+ function usePopover(prefer) {
1652
+ const [open, setOpen] = useState2(false);
1562
1653
  const ref = useRef(null);
1654
+ const panelRef = useRef(null);
1655
+ const placement = usePanelPlacement(open, ref, panelRef, prefer);
1563
1656
  useEffect(() => {
1564
1657
  if (!open) return;
1565
1658
  const down = (e) => {
@@ -1575,12 +1668,12 @@ function usePopover() {
1575
1668
  window.removeEventListener("keydown", key);
1576
1669
  };
1577
1670
  }, [open]);
1578
- return { open, setOpen, ref };
1671
+ return { open, setOpen, ref, panelRef, placement };
1579
1672
  }
1580
1673
  function SearchBox(p) {
1581
1674
  const t = useStrings();
1582
- const [focused, setFocused] = useState(false);
1583
- const [active, setActive] = useState(0);
1675
+ const [focused, setFocused] = useState2(false);
1676
+ const [active, setActive] = useState2(0);
1584
1677
  const previewing = useRef(false);
1585
1678
  const results = p.search?.results ?? [];
1586
1679
  const open = focused && !!p.query.trim();
@@ -1699,7 +1792,7 @@ function SearchBox(p) {
1699
1792
  }
1700
1793
  function ViewMenu(p) {
1701
1794
  const t = useStrings();
1702
- const pop = usePopover();
1795
+ const pop = usePopover(MENU_PLACE);
1703
1796
  return /* @__PURE__ */ jsxs("div", { className: "gb-menu", ref: pop.ref, children: [
1704
1797
  /* @__PURE__ */ jsx(
1705
1798
  "button",
@@ -1715,8 +1808,12 @@ function ViewMenu(p) {
1715
1808
  pop.open && /* @__PURE__ */ jsxs(
1716
1809
  "div",
1717
1810
  {
1811
+ ref: pop.panelRef,
1718
1812
  className: "gb-panel",
1719
1813
  role: "dialog",
1814
+ "data-x": pop.placement?.align,
1815
+ "data-y": pop.placement?.side,
1816
+ style: pop.placement ? { left: pop.placement.left, top: pop.placement.top, right: "auto", bottom: "auto" } : { visibility: "hidden" },
1720
1817
  onClick: (e) => {
1721
1818
  if (e.target.closest(".gb-menu-item")) pop.setOpen(false);
1722
1819
  },
@@ -1738,7 +1835,7 @@ function Toolbar(p) {
1738
1835
  const originPick = controls.origins && p.origins.length > 1;
1739
1836
  const multi = controls.layers && p.layers.length > 1;
1740
1837
  const showLayer = (l) => setView(view.planes ? { layers: [...view.layers ?? [], l] } : { layers: [l] });
1741
- return /* @__PURE__ */ jsxs("div", { className: "gb-bar", children: [
1838
+ return /* @__PURE__ */ jsxs("div", { className: `gb-bar${multi ? " has-layers" : ""}`, children: [
1742
1839
  controls.search && /* @__PURE__ */ jsx(
1743
1840
  SearchBox,
1744
1841
  {
@@ -1786,7 +1883,7 @@ function Toolbar(p) {
1786
1883
  var GROUP_CAP = 100;
1787
1884
  function Issues({ issues, onPick }) {
1788
1885
  const t = useStrings();
1789
- const pop = usePopover();
1886
+ const pop = usePopover(ISSUES_PLACE);
1790
1887
  const groups = useMemo(() => {
1791
1888
  const by = /* @__PURE__ */ new Map();
1792
1889
  for (const it of issues) {
@@ -1815,25 +1912,36 @@ function Issues({ issues, onPick }) {
1815
1912
  ]
1816
1913
  }
1817
1914
  ),
1818
- pop.open && /* @__PURE__ */ jsxs("div", { className: "gb-panel gb-panel-up gb-issues", role: "dialog", children: [
1819
- /* @__PURE__ */ jsx("div", { className: "gb-panel-h", children: t.issuesTitle(errors, warns) }),
1820
- groups.map((g) => /* @__PURE__ */ jsxs("details", { open: groups.length === 1, children: [
1821
- /* @__PURE__ */ jsxs("summary", { className: g.error ? "is-err" : "", children: [
1822
- /* @__PURE__ */ jsx("span", { children: g.name }),
1823
- /* @__PURE__ */ jsx("b", { children: g.items.length })
1824
- ] }),
1825
- /* @__PURE__ */ jsxs("ul", { children: [
1826
- g.items.slice(0, GROUP_CAP).map((it, i) => {
1827
- const id = target(it);
1828
- return /* @__PURE__ */ jsx("li", { className: id ? "is-link" : "", onClick: id ? () => {
1829
- onPick(id);
1830
- pop.setOpen(false);
1831
- } : void 0, children: it.message }, i);
1832
- }),
1833
- g.items.length > GROUP_CAP && /* @__PURE__ */ jsx("li", { className: "gb-more", children: t.moreItems(g.items.length - GROUP_CAP) })
1834
- ] })
1835
- ] }, g.name))
1836
- ] })
1915
+ pop.open && /* @__PURE__ */ jsxs(
1916
+ "div",
1917
+ {
1918
+ ref: pop.panelRef,
1919
+ className: "gb-panel gb-issues",
1920
+ role: "dialog",
1921
+ "data-x": pop.placement?.align,
1922
+ "data-y": pop.placement?.side,
1923
+ style: pop.placement ? { left: pop.placement.left, top: pop.placement.top, right: "auto", bottom: "auto" } : { visibility: "hidden" },
1924
+ children: [
1925
+ /* @__PURE__ */ jsx("div", { className: "gb-panel-h", children: t.issuesTitle(errors, warns) }),
1926
+ groups.map((g) => /* @__PURE__ */ jsxs("details", { open: groups.length === 1, children: [
1927
+ /* @__PURE__ */ jsxs("summary", { className: g.error ? "is-err" : "", children: [
1928
+ /* @__PURE__ */ jsx("span", { children: g.name }),
1929
+ /* @__PURE__ */ jsx("b", { children: g.items.length })
1930
+ ] }),
1931
+ /* @__PURE__ */ jsxs("ul", { children: [
1932
+ g.items.slice(0, GROUP_CAP).map((it, i) => {
1933
+ const id = target(it);
1934
+ return /* @__PURE__ */ jsx("li", { className: id ? "is-link" : "", onClick: id ? () => {
1935
+ onPick(id);
1936
+ pop.setOpen(false);
1937
+ } : void 0, children: it.message }, i);
1938
+ }),
1939
+ g.items.length > GROUP_CAP && /* @__PURE__ */ jsx("li", { className: "gb-more", children: t.moreItems(g.items.length - GROUP_CAP) })
1940
+ ] })
1941
+ ] }, g.name))
1942
+ ]
1943
+ }
1944
+ )
1837
1945
  ] });
1838
1946
  }
1839
1947
  function ZoomDock(p) {
@@ -1849,6 +1957,254 @@ function ZoomDock(p) {
1849
1957
  ] });
1850
1958
  }
1851
1959
 
1960
+ // src/react/touch.ts
1961
+ var TAP_MS = 350;
1962
+ var DOUBLE_MS = 350;
1963
+ var SLOP = 8;
1964
+ var distance = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
1965
+ var middle = (a, b) => ({ x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 });
1966
+ function touchGestures(actions) {
1967
+ const fingers = /* @__PURE__ */ new Map();
1968
+ let navigation = false, moved = false;
1969
+ let start = null;
1970
+ let startedAt = 0;
1971
+ let target = null;
1972
+ let previewId = null;
1973
+ let lastTap = null;
1974
+ let pinch = null;
1975
+ const anchor = () => {
1976
+ const entries = [...fingers];
1977
+ pinch = entries.length < 2 ? null : {
1978
+ ids: entries.slice(0, 2).map(([id]) => id),
1979
+ center: middle(entries[0][1], entries[1][1]),
1980
+ distance: distance(entries[0][1], entries[1][1]),
1981
+ view: actions.viewport()
1982
+ };
1983
+ };
1984
+ const reset = () => {
1985
+ fingers.clear();
1986
+ pinch = null;
1987
+ start = null;
1988
+ target = null;
1989
+ navigation = moved = false;
1990
+ };
1991
+ return {
1992
+ down(id, point) {
1993
+ actions.interact();
1994
+ fingers.set(id, point);
1995
+ if (fingers.size > 1 || navigation) {
1996
+ navigation = true;
1997
+ lastTap = null;
1998
+ actions.preview(null);
1999
+ anchor();
2000
+ return;
2001
+ }
2002
+ start = point;
2003
+ startedAt = Date.now();
2004
+ moved = false;
2005
+ target = actions.hit(point);
2006
+ previewId = target?.id ?? null;
2007
+ actions.preview(target?.value ?? null);
2008
+ },
2009
+ move(id, point) {
2010
+ if (!fingers.has(id)) return;
2011
+ actions.interact();
2012
+ fingers.set(id, point);
2013
+ if (navigation) {
2014
+ if (!pinch) return;
2015
+ const a = fingers.get(pinch.ids[0]), b = fingers.get(pinch.ids[1]);
2016
+ if (!a || !b) return;
2017
+ const center = middle(a, b), limits = actions.limits();
2018
+ const zoom = Math.max(limits.min, Math.min(
2019
+ limits.max,
2020
+ pinch.view.zoom * distance(a, b) / Math.max(1, pinch.distance)
2021
+ ));
2022
+ const ratio = zoom / pinch.view.zoom;
2023
+ actions.move({ zoom, pan: {
2024
+ x: center.x - (pinch.center.x - pinch.view.pan.x) * ratio,
2025
+ y: center.y - (pinch.center.y - pinch.view.pan.y) * ratio
2026
+ } });
2027
+ return;
2028
+ }
2029
+ if (start && distance(start, point) > SLOP) {
2030
+ moved = true;
2031
+ lastTap = null;
2032
+ }
2033
+ if (moved) {
2034
+ const next = actions.hit(point);
2035
+ if ((next?.id ?? null) !== previewId) {
2036
+ previewId = next?.id ?? null;
2037
+ actions.preview(next?.value ?? null);
2038
+ }
2039
+ }
2040
+ },
2041
+ up(id, point) {
2042
+ if (!fingers.has(id)) return;
2043
+ fingers.delete(id);
2044
+ if (!navigation && !moved && start && Date.now() - startedAt < TAP_MS && distance(start, point) <= SLOP) {
2045
+ const hit = actions.hit(point);
2046
+ if ((hit?.id ?? null) === (target?.id ?? null)) {
2047
+ actions.preview(hit?.value ?? null);
2048
+ if (!hit) {
2049
+ actions.select(null);
2050
+ lastTap = null;
2051
+ } else if (hit.node) {
2052
+ const now = Date.now();
2053
+ if (lastTap?.id === hit.id && now - lastTap.time < DOUBLE_MS && distance(lastTap.point, point) <= SLOP * 3) {
2054
+ actions.select(hit.value);
2055
+ lastTap = null;
2056
+ } else lastTap = { id: hit.id, point, time: now };
2057
+ } else lastTap = null;
2058
+ } else lastTap = null;
2059
+ } else lastTap = null;
2060
+ if (fingers.size === 0) reset();
2061
+ else anchor();
2062
+ },
2063
+ cancel() {
2064
+ reset();
2065
+ lastTap = null;
2066
+ actions.preview(null);
2067
+ },
2068
+ dispose() {
2069
+ reset();
2070
+ lastTap = null;
2071
+ }
2072
+ };
2073
+ }
2074
+
2075
+ // src/react/input.ts
2076
+ function installGraphInput(cy, el, actions) {
2077
+ const interact = () => {
2078
+ actions.interact();
2079
+ actions.cancelFly();
2080
+ };
2081
+ let hasTouchPreview = false;
2082
+ const previewTouch = (target) => {
2083
+ hasTouchPreview = target != null;
2084
+ actions.preview(target);
2085
+ };
2086
+ const touch = touchGestures({
2087
+ interact,
2088
+ hit(p) {
2089
+ const z = cy.zoom(), pan = cy.pan();
2090
+ const hit = cy.renderer().findNearestElements((p.x - pan.x) / z, (p.y - pan.y) / z, true, true)[0];
2091
+ return !hit || hit.id() === VIRTUAL_ROOT ? null : { id: hit.id(), node: hit.isNode(), value: hit };
2092
+ },
2093
+ preview: previewTouch,
2094
+ select: actions.selectTouch,
2095
+ viewport: () => ({ zoom: cy.zoom(), pan: { ...cy.pan() } }),
2096
+ move: (view) => cy.viewport(view),
2097
+ limits: () => ({ min: cy.minZoom(), max: cy.maxZoom() })
2098
+ });
2099
+ const bindings = [];
2100
+ const onCy = (events, handler) => {
2101
+ cy.on(events, handler);
2102
+ bindings.push(() => cy.off(events, handler));
2103
+ };
2104
+ let lastTap = { id: "", time: 0 };
2105
+ onCy("tap", (e) => {
2106
+ actions.interact();
2107
+ if (e.target === cy) actions.select(null);
2108
+ else if (e.target.isNode()) {
2109
+ const id = e.target.id(), time = Date.now();
2110
+ actions.select(id === VIRTUAL_ROOT ? null : e.target);
2111
+ if (id !== VIRTUAL_ROOT && lastTap.id === id && time - lastTap.time < 350) actions.focus?.(id);
2112
+ lastTap = { id, time };
2113
+ }
2114
+ });
2115
+ onCy("tapstart", actions.cancelFly);
2116
+ if (actions.hover) {
2117
+ onCy("mouseover", (e) => {
2118
+ if (e.target !== cy) {
2119
+ actions.interact();
2120
+ actions.hover(e.target);
2121
+ }
2122
+ });
2123
+ onCy("mouseout", (e) => {
2124
+ if (e.target !== cy) actions.hover(null);
2125
+ });
2126
+ }
2127
+ const on = (name, fn, capture = false) => {
2128
+ el.addEventListener(name, fn, { capture, passive: false });
2129
+ bindings.push(() => el.removeEventListener(name, fn, capture));
2130
+ };
2131
+ on("wheel", (e) => {
2132
+ e.preventDefault();
2133
+ interact();
2134
+ if (e.ctrlKey || e.metaKey) {
2135
+ const rect = el.getBoundingClientRect();
2136
+ cy.zoom({
2137
+ level: cy.zoom() * Math.exp(-e.deltaY * 0.01),
2138
+ renderedPosition: { x: e.clientX - rect.left, y: e.clientY - rect.top }
2139
+ });
2140
+ } else cy.panBy({ x: -e.deltaX, y: -e.deltaY });
2141
+ });
2142
+ on("mouseleave", () => actions.hover?.(null));
2143
+ const captured = /* @__PURE__ */ new Set();
2144
+ const point = (e) => {
2145
+ const rect = el.getBoundingClientRect();
2146
+ return { x: e.clientX - rect.left, y: e.clientY - rect.top };
2147
+ };
2148
+ const stop = (e) => {
2149
+ if (e.cancelable) e.preventDefault();
2150
+ e.stopImmediatePropagation();
2151
+ };
2152
+ on("pointerdown", (e) => {
2153
+ if (e.pointerType !== "touch") {
2154
+ if (hasTouchPreview) previewTouch(null);
2155
+ return;
2156
+ }
2157
+ stop(e);
2158
+ lastTap = { id: "", time: 0 };
2159
+ captured.add(e.pointerId);
2160
+ el.setPointerCapture(e.pointerId);
2161
+ touch.down(e.pointerId, point(e));
2162
+ }, true);
2163
+ on("pointermove", (e) => {
2164
+ if (e.pointerType !== "touch" && hasTouchPreview) previewTouch(null);
2165
+ if (!captured.has(e.pointerId)) return;
2166
+ stop(e);
2167
+ touch.move(e.pointerId, point(e));
2168
+ }, true);
2169
+ on("pointerup", (e) => {
2170
+ if (!captured.delete(e.pointerId)) return;
2171
+ stop(e);
2172
+ touch.up(e.pointerId, point(e));
2173
+ if (el.hasPointerCapture(e.pointerId)) el.releasePointerCapture(e.pointerId);
2174
+ }, true);
2175
+ const cancel = () => {
2176
+ touch.cancel();
2177
+ const ids = [...captured];
2178
+ captured.clear();
2179
+ for (const id of ids) if (el.hasPointerCapture(id)) el.releasePointerCapture(id);
2180
+ };
2181
+ on("pointercancel", (e) => {
2182
+ if (captured.has(e.pointerId)) {
2183
+ stop(e);
2184
+ cancel();
2185
+ }
2186
+ }, true);
2187
+ on("lostpointercapture", (e) => {
2188
+ if (captured.has(e.pointerId)) cancel();
2189
+ }, true);
2190
+ for (const name of ["touchstart", "touchmove", "touchend", "touchcancel"]) on(name, stop, true);
2191
+ on("contextmenu", (e) => {
2192
+ if (captured.size || e.pointerType === "touch") stop(e);
2193
+ }, true);
2194
+ const previousTouchAction = el.style.touchAction;
2195
+ el.style.touchAction = "none";
2196
+ const win = el.ownerDocument.defaultView;
2197
+ win?.addEventListener("blur", cancel);
2198
+ return () => {
2199
+ touch.dispose();
2200
+ bindings.forEach((off) => off());
2201
+ win?.removeEventListener("blur", cancel);
2202
+ for (const id of captured) if (el.hasPointerCapture(id)) el.releasePointerCapture(id);
2203
+ captured.clear();
2204
+ el.style.touchAction = previousTouchAction;
2205
+ };
2206
+ }
2207
+
1852
2208
  // src/react/camera.ts
1853
2209
  var toRect = (v, W, H) => ({
1854
2210
  cx: (W / 2 - v.pan.x) / v.zoom,
@@ -1890,7 +2246,7 @@ function zoomPath(a, b) {
1890
2246
  var easeInOut = (x) => x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
1891
2247
 
1892
2248
  // src/react/EditPanel.tsx
1893
- import { useEffect as useEffect2, useId, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
2249
+ import { useEffect as useEffect2, useId, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
1894
2250
  import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
1895
2251
  var PICK_MAX = 8;
1896
2252
  function NodeRef({ id, model, colorOf, sub }) {
@@ -1905,9 +2261,9 @@ function NodeRef({ id, model, colorOf, sub }) {
1905
2261
  }
1906
2262
  function NodePicker({ model, value, onChange, exclude, empty, autoFocus, label, colorOf, id: inputId }) {
1907
2263
  const t = useStrings();
1908
- const [q2, setQ] = useState2("");
1909
- const [open, setOpen] = useState2(false);
1910
- const [active, setActive] = useState2(0);
2264
+ const [q2, setQ] = useState3("");
2265
+ const [open, setOpen] = useState3(false);
2266
+ const [active, setActive] = useState3(0);
1911
2267
  const idx = useMemo2(() => indexModel(model), [model]);
1912
2268
  const hits = useMemo2(
1913
2269
  () => q2.trim() ? searchNodes(model, q2).filter((id) => !exclude?.(id)).slice(0, PICK_MAX) : [],
@@ -2063,7 +2419,7 @@ function EditPanel({ target, model, onSubmit, onCancel, onRetarget, renderEditor
2063
2419
  }
2064
2420
  function useSubmit(onSubmit) {
2065
2421
  const t = useStrings();
2066
- const [error, setError] = useState2(null);
2422
+ const [error, setError] = useState3(null);
2067
2423
  const submit = (op) => {
2068
2424
  const e = onSubmit(op);
2069
2425
  setError(e ? t.error[e] : null);
@@ -2077,14 +2433,14 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
2077
2433
  const { error, setError, submit } = useSubmit(onSubmit);
2078
2434
  const node = target.id ? model.index.get(target.id) : void 0;
2079
2435
  const creating = !node;
2080
- const [id, setId] = useState2("");
2081
- const [parent, setParent] = useState2(node ? node.parent ?? null : target.parent ?? null);
2436
+ const [id, setId] = useState3("");
2437
+ const [parent, setParent] = useState3(node ? node.parent ?? null : target.parent ?? null);
2082
2438
  const initial = useMemo2(
2083
2439
  () => pretty(node ? { label: node.label, kind: node.kind ?? "", data: node.data ?? {} } : { label: "", kind: "", data: {} }),
2084
2440
  [node]
2085
2441
  );
2086
- const [text, setText] = useState2(initial);
2087
- const [confirming, setConfirming] = useState2(false);
2442
+ const [text, setText] = useState3(initial);
2443
+ const [confirming, setConfirming] = useState3(false);
2088
2444
  const idErr = creating && id ? checkEdit(model, { op: "addNode", id, set: {} }) : null;
2089
2445
  const below = useMemo2(() => {
2090
2446
  if (!node) return null;
@@ -2235,10 +2591,10 @@ function EdgeForm({ source: src, model, onSubmit, onCancel, colorOf }) {
2235
2591
  const t = useStrings();
2236
2592
  const uid = useId();
2237
2593
  const { error, submit } = useSubmit(onSubmit);
2238
- const [source, setSource] = useState2(src ?? null);
2239
- const [target, setTarget] = useState2(null);
2240
- const [kind, setKind] = useState2("");
2241
- const [label, setLabel] = useState2("");
2594
+ const [source, setSource] = useState3(src ?? null);
2595
+ const [target, setTarget] = useState3(null);
2596
+ const [kind, setKind] = useState3("");
2597
+ const [label, setLabel] = useState3("");
2242
2598
  const kinds = useMemo2(() => [...new Set(model.edges.map((e) => e.kind).filter(Boolean))].sort(), [model]);
2243
2599
  const save = () => {
2244
2600
  const op = {
@@ -2288,7 +2644,8 @@ function EdgeForm({ source: src, model, onSubmit, onCancel, colorOf }) {
2288
2644
  }
2289
2645
 
2290
2646
  // src/react/Legend.tsx
2291
- import { useCallback, useEffect as useEffect3, useLayoutEffect as useLayoutEffect2, useMemo as useMemo3, useRef as useRef3, useState as useState3 } from "react";
2647
+ import { useCallback, useEffect as useEffect3, useLayoutEffect as useLayoutEffect3, useMemo as useMemo3, useRef as useRef3, useState as useState4 } from "react";
2648
+ import { createPortal } from "react-dom";
2292
2649
  import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
2293
2650
  function applyLook(profile, look) {
2294
2651
  if (!look || !(look.nodePalette || look.edgePalette || look.nodeSize || look.edgeWidth)) return profile;
@@ -2339,12 +2696,20 @@ function tally(model, profile) {
2339
2696
  var SCALES = [0.5, 1, 2];
2340
2697
  var OPEN_DELAY_MS = 120;
2341
2698
  var CLOSE_GRACE_MS = 200;
2699
+ var LEGEND_PLACE = { side: "top", align: "start" };
2342
2700
  var CHANGE_ORDER = ["added", "changed", "moved", "merged", "removed"];
2343
2701
  function Item(p) {
2344
2702
  const t = useStrings();
2345
2703
  const { k, open, ctl } = p;
2704
+ const item = useRef3(null);
2346
2705
  const btn = useRef3(null);
2706
+ const panel = useRef3(null);
2347
2707
  const well = useRef3(null);
2708
+ const [portalRoot, setPortalRoot] = useState4(null);
2709
+ const placement = usePanelPlacement(open, item, panel, LEGEND_PLACE);
2710
+ useLayoutEffect3(() => {
2711
+ setPortalRoot(item.current?.closest(".gb-root") ?? document.body);
2712
+ }, []);
2348
2713
  useEffect3(() => {
2349
2714
  const el = well.current;
2350
2715
  if (!el) return;
@@ -2359,6 +2724,7 @@ function Item(p) {
2359
2724
  return /* @__PURE__ */ jsxs3(
2360
2725
  "span",
2361
2726
  {
2727
+ ref: item,
2362
2728
  className: `gb-lg-item${p.off ? " off" : ""}${open ? " is-open" : ""}`,
2363
2729
  onPointerEnter: (e) => ctl.enter(k, e),
2364
2730
  onPointerLeave: (e) => ctl.leave(k, e),
@@ -2369,7 +2735,7 @@ function Item(p) {
2369
2735
  }
2370
2736
  },
2371
2737
  onBlur: (e) => {
2372
- if (!e.currentTarget.contains(e.relatedTarget)) ctl.focus(k, false, false);
2738
+ if (!e.currentTarget.contains(e.relatedTarget) && !e.relatedTarget?.closest?.(".gb-lg-pop")) ctl.focus(k, false, false);
2373
2739
  },
2374
2740
  children: [
2375
2741
  /* @__PURE__ */ jsxs3(
@@ -2391,50 +2757,69 @@ function Item(p) {
2391
2757
  ]
2392
2758
  }
2393
2759
  ),
2394
- open && /* @__PURE__ */ jsxs3("div", { className: "gb-lg-pop", role: "dialog", "aria-label": p.title, children: [
2395
- p.onToggle && /* @__PURE__ */ jsx3(
2396
- "button",
2397
- {
2398
- type: "button",
2399
- className: `gb-lg-eye${p.off ? " off" : ""}`,
2400
- "aria-pressed": !p.off,
2401
- "aria-label": p.off ? t.legendShow : t.legendHide,
2402
- title: p.off ? t.legendShow : t.legendHideTip,
2403
- onClick: (e) => {
2404
- p.onToggle();
2405
- finish(e.detail === 0);
2406
- },
2407
- children: /* @__PURE__ */ jsx3(Eye, { off: p.off })
2408
- }
2409
- ),
2410
- /* @__PURE__ */ jsxs3("label", { className: "gb-lg-well", title: `${t.legendColor} \xB7 ${p.color}`, children: [
2411
- /* @__PURE__ */ jsx3("i", { style: { background: p.color } }),
2412
- /* @__PURE__ */ jsx3(
2413
- "input",
2414
- {
2415
- ref: well,
2416
- type: "color",
2417
- value: p.color,
2418
- "aria-label": t.legendColor,
2419
- onClick: () => ctl.picking(true),
2420
- onChange: (e) => p.onPick(e.target.value)
2760
+ open && portalRoot && createPortal(/* @__PURE__ */ jsxs3(
2761
+ "div",
2762
+ {
2763
+ ref: panel,
2764
+ className: "gb-lg-pop",
2765
+ role: "dialog",
2766
+ "aria-label": p.title,
2767
+ "data-side": placement?.side,
2768
+ style: placement ? { position: "absolute", left: placement.left, top: placement.top, right: "auto", bottom: "auto" } : { position: "absolute", visibility: "hidden" },
2769
+ onPointerEnter: (e) => ctl.enter(k, e),
2770
+ onPointerLeave: (e) => ctl.leave(k, e),
2771
+ onKeyDown: (e) => {
2772
+ if (e.key === "Escape") {
2773
+ e.stopPropagation();
2774
+ finish(true);
2421
2775
  }
2422
- )
2423
- ] }),
2424
- p.onScale && /* @__PURE__ */ jsx3("i", { className: "gb-lg-sep" }),
2425
- p.onScale && /* @__PURE__ */ jsx3("span", { className: "gb-lg-segm", role: "group", "aria-label": t.legendSize, children: SCALES.map((s) => /* @__PURE__ */ jsx3(
2426
- "button",
2427
- {
2428
- type: "button",
2429
- className: s === (p.scale ?? 1) ? "on" : "",
2430
- "aria-pressed": s === (p.scale ?? 1),
2431
- title: `${s}\xD7`,
2432
- onClick: () => p.onScale(s),
2433
- children: /* @__PURE__ */ jsx3("svg", { viewBox: "0 0 16 10", width: 16, height: 10, children: p.glyph === "line" ? /* @__PURE__ */ jsx3("line", { x1: 2, y1: 5, x2: 14, y2: 5, stroke: "currentColor", strokeWidth: s * 1.6, strokeLinecap: "round" }) : /* @__PURE__ */ jsx3("circle", { cx: 8, cy: 5, r: 1.6 + s * 1.4, fill: "currentColor" }) })
2434
2776
  },
2435
- s
2436
- )) })
2437
- ] })
2777
+ children: [
2778
+ p.onToggle && /* @__PURE__ */ jsx3(
2779
+ "button",
2780
+ {
2781
+ type: "button",
2782
+ className: `gb-lg-eye${p.off ? " off" : ""}`,
2783
+ "aria-pressed": !p.off,
2784
+ "aria-label": p.off ? t.legendShow : t.legendHide,
2785
+ title: p.off ? t.legendShow : t.legendHideTip,
2786
+ onClick: (e) => {
2787
+ p.onToggle();
2788
+ finish(e.detail === 0);
2789
+ },
2790
+ children: /* @__PURE__ */ jsx3(Eye, { off: p.off })
2791
+ }
2792
+ ),
2793
+ /* @__PURE__ */ jsxs3("label", { className: "gb-lg-well", title: `${t.legendColor} \xB7 ${p.color}`, children: [
2794
+ /* @__PURE__ */ jsx3("i", { style: { background: p.color } }),
2795
+ /* @__PURE__ */ jsx3(
2796
+ "input",
2797
+ {
2798
+ ref: well,
2799
+ type: "color",
2800
+ value: p.color,
2801
+ "aria-label": t.legendColor,
2802
+ onClick: () => ctl.picking(true),
2803
+ onChange: (e) => p.onPick(e.target.value)
2804
+ }
2805
+ )
2806
+ ] }),
2807
+ p.onScale && /* @__PURE__ */ jsx3("i", { className: "gb-lg-sep" }),
2808
+ p.onScale && /* @__PURE__ */ jsx3("span", { className: "gb-lg-segm", role: "group", "aria-label": t.legendSize, children: SCALES.map((s) => /* @__PURE__ */ jsx3(
2809
+ "button",
2810
+ {
2811
+ type: "button",
2812
+ className: s === (p.scale ?? 1) ? "on" : "",
2813
+ "aria-pressed": s === (p.scale ?? 1),
2814
+ title: `${s}\xD7`,
2815
+ onClick: () => p.onScale(s),
2816
+ children: /* @__PURE__ */ jsx3("svg", { viewBox: "0 0 16 10", width: 16, height: 10, children: p.glyph === "line" ? /* @__PURE__ */ jsx3("line", { x1: 2, y1: 5, x2: 14, y2: 5, stroke: "currentColor", strokeWidth: s * 1.6, strokeLinecap: "round" }) : /* @__PURE__ */ jsx3("circle", { cx: 8, cy: 5, r: 1.6 + s * 1.4, fill: "currentColor" }) })
2817
+ },
2818
+ s
2819
+ )) })
2820
+ ]
2821
+ }
2822
+ ), portalRoot)
2438
2823
  ]
2439
2824
  }
2440
2825
  );
@@ -2501,7 +2886,7 @@ function SkeletonEdge({ theme }) {
2501
2886
  function LegendFrame({ collapsed, children }) {
2502
2887
  const root = useRef3(null);
2503
2888
  const size = useRef3(null);
2504
- useLayoutEffect2(() => {
2889
+ useLayoutEffect3(() => {
2505
2890
  const el = root.current;
2506
2891
  const before = size.current;
2507
2892
  const after = el.getBoundingClientRect();
@@ -2526,7 +2911,7 @@ function LegendFrame({ collapsed, children }) {
2526
2911
  body.style.width = "";
2527
2912
  };
2528
2913
  }, [collapsed]);
2529
- useLayoutEffect2(() => {
2914
+ useLayoutEffect3(() => {
2530
2915
  const el = root.current;
2531
2916
  const ro = new ResizeObserver(() => {
2532
2917
  if (!el.getAnimations().length) size.current = el.getBoundingClientRect();
@@ -2540,9 +2925,9 @@ function Legend(p) {
2540
2925
  const t = useStrings();
2541
2926
  const { look, onLook, theme, profile } = p;
2542
2927
  const count = useMemo3(() => tally(p.model, profile), [p.model, profile]);
2543
- const [open, setOpen] = useState3(null);
2544
- const [focused, setFocused] = useState3(null);
2545
- const [picking, setPicking] = useState3(false);
2928
+ const [open, setOpen] = useState4(null);
2929
+ const [focused, setFocused] = useState4(null);
2930
+ const [picking, setPicking] = useState4(false);
2546
2931
  const quiet = useRef3(null);
2547
2932
  const pointer = useRef3("mouse");
2548
2933
  const over = useRef3(null);
@@ -2560,7 +2945,7 @@ function Legend(p) {
2560
2945
  useEffect3(() => {
2561
2946
  const down = (e) => {
2562
2947
  pointer.current = e.pointerType;
2563
- if (openRef.current && !rootRef.current?.querySelector(".gb-lg-item.is-open")?.contains(e.target)) close();
2948
+ if (openRef.current && !rootRef.current?.querySelector(".gb-lg-item.is-open")?.contains(e.target) && !e.target?.closest?.(".gb-lg-pop")) close();
2564
2949
  };
2565
2950
  document.addEventListener("pointerdown", down, true);
2566
2951
  return () => document.removeEventListener("pointerdown", down, true);
@@ -2638,88 +3023,90 @@ function Legend(p) {
2638
3023
  children: /* @__PURE__ */ jsx3(Icon, { d: I.legend })
2639
3024
  }
2640
3025
  ) : /* @__PURE__ */ jsxs3("div", { className: "gb-lg", ref: rootRef, children: [
2641
- p.caption && /* @__PURE__ */ jsx3("div", { className: "gb-lg-cap", children: p.caption }),
2642
- /* @__PURE__ */ jsxs3("div", { className: "gb-lg-row", children: [
2643
- /* @__PURE__ */ jsx3(
2644
- Item,
2645
- {
2646
- ...slot("n:"),
2647
- color: theme.skeleton,
2648
- onPick: setSkeleton,
2649
- title: t.legendPlain,
2650
- mark: /* @__PURE__ */ jsx3(NodeMark, { color: defaultNodeColor(theme, 0.3), ring: theme.canvas }),
2651
- label: t.legendPlainName,
2652
- count: count.plain
2653
- }
2654
- ),
2655
- nodeKinds.map((k) => {
2656
- const off = p.hidden.nodes.includes(k);
2657
- const scale = profile.nodeSize[k] ?? 1;
2658
- return /* @__PURE__ */ jsx3(
3026
+ /* @__PURE__ */ jsxs3("div", { className: "gb-lg-body", children: [
3027
+ p.caption && /* @__PURE__ */ jsx3("div", { className: "gb-lg-cap", children: p.caption }),
3028
+ /* @__PURE__ */ jsxs3("div", { className: "gb-lg-row", children: [
3029
+ /* @__PURE__ */ jsx3(
2659
3030
  Item,
2660
3031
  {
2661
- ...slot(`n:${k}`),
2662
- color: shown(profile.nodePalette[k]),
2663
- title: name(k),
2664
- off,
2665
- onToggle: () => p.onToggle("nodes", k),
2666
- onPick: (c) => set("nodePalette", k, untheme(theme, c)),
2667
- scale,
2668
- glyph: "dot",
2669
- onScale: (s) => set("nodeSize", k, s),
2670
- mark: /* @__PURE__ */ jsx3(NodeMark, { color: shown(profile.nodePalette[k]), shape: marks.shape(k), ring: theme.canvas, off, scale }),
2671
- label: name(k),
2672
- count: count.nodes[k]
2673
- },
2674
- k
2675
- );
2676
- })
2677
- ] }),
2678
- /* @__PURE__ */ jsxs3("div", { className: "gb-lg-row", children: [
2679
- /* @__PURE__ */ jsx3(
2680
- Item,
2681
- {
2682
- ...slot("e:"),
2683
- color: theme.skeleton,
2684
- onPick: setSkeleton,
2685
- title: t.legendContains,
2686
- mark: /* @__PURE__ */ jsx3(SkeletonEdge, { theme }),
2687
- label: t.legendContainsName
2688
- }
2689
- ),
2690
- edgeKinds.map((k) => {
2691
- const off = p.hidden.edges.includes(k);
2692
- const scale = profile.edgeWidth[k] ?? 1;
2693
- return /* @__PURE__ */ jsx3(
3032
+ ...slot("n:"),
3033
+ color: theme.skeleton,
3034
+ onPick: setSkeleton,
3035
+ title: t.legendPlain,
3036
+ mark: /* @__PURE__ */ jsx3(NodeMark, { color: defaultNodeColor(theme, 0.3), ring: theme.canvas }),
3037
+ label: t.legendPlainName,
3038
+ count: count.plain
3039
+ }
3040
+ ),
3041
+ nodeKinds.map((k) => {
3042
+ const off = p.hidden.nodes.includes(k);
3043
+ const scale = profile.nodeSize[k] ?? 1;
3044
+ return /* @__PURE__ */ jsx3(
3045
+ Item,
3046
+ {
3047
+ ...slot(`n:${k}`),
3048
+ color: shown(profile.nodePalette[k]),
3049
+ title: name(k),
3050
+ off,
3051
+ onToggle: () => p.onToggle("nodes", k),
3052
+ onPick: (c) => set("nodePalette", k, untheme(theme, c)),
3053
+ scale,
3054
+ glyph: "dot",
3055
+ onScale: (s) => set("nodeSize", k, s),
3056
+ mark: /* @__PURE__ */ jsx3(NodeMark, { color: shown(profile.nodePalette[k]), shape: marks.shape(k), ring: theme.canvas, off, scale }),
3057
+ label: name(k),
3058
+ count: count.nodes[k]
3059
+ },
3060
+ k
3061
+ );
3062
+ })
3063
+ ] }),
3064
+ /* @__PURE__ */ jsxs3("div", { className: "gb-lg-row", children: [
3065
+ /* @__PURE__ */ jsx3(
2694
3066
  Item,
2695
3067
  {
2696
- ...slot(`e:${k}`),
2697
- color: shown(profile.edgePalette[k]),
2698
- title: name(k),
2699
- off,
2700
- onToggle: () => p.onToggle("edges", k),
2701
- onPick: (c) => set("edgePalette", k, untheme(theme, c)),
2702
- scale,
2703
- glyph: "line",
2704
- onScale: (s) => set("edgeWidth", k, s),
2705
- mark: /* @__PURE__ */ jsx3(EdgeMark, { color: shown(profile.edgePalette[k]), stroke: marks.stroke(k), off, scale }),
2706
- label: name(k),
2707
- count: count.edges[k]
2708
- },
2709
- k
2710
- );
2711
- })
3068
+ ...slot("e:"),
3069
+ color: theme.skeleton,
3070
+ onPick: setSkeleton,
3071
+ title: t.legendContains,
3072
+ mark: /* @__PURE__ */ jsx3(SkeletonEdge, { theme }),
3073
+ label: t.legendContainsName
3074
+ }
3075
+ ),
3076
+ edgeKinds.map((k) => {
3077
+ const off = p.hidden.edges.includes(k);
3078
+ const scale = profile.edgeWidth[k] ?? 1;
3079
+ return /* @__PURE__ */ jsx3(
3080
+ Item,
3081
+ {
3082
+ ...slot(`e:${k}`),
3083
+ color: shown(profile.edgePalette[k]),
3084
+ title: name(k),
3085
+ off,
3086
+ onToggle: () => p.onToggle("edges", k),
3087
+ onPick: (c) => set("edgePalette", k, untheme(theme, c)),
3088
+ scale,
3089
+ glyph: "line",
3090
+ onScale: (s) => set("edgeWidth", k, s),
3091
+ mark: /* @__PURE__ */ jsx3(EdgeMark, { color: shown(profile.edgePalette[k]), stroke: marks.stroke(k), off, scale }),
3092
+ label: name(k),
3093
+ count: count.edges[k]
3094
+ },
3095
+ k
3096
+ );
3097
+ })
3098
+ ] }),
3099
+ p.delta && /* Change legend: only a legend, not a filter. Marks match the text on the graph: strikethrough = removed, underline = added. */
3100
+ /* @__PURE__ */ jsx3("div", { className: "gb-lg-row gb-lg-diff", children: CHANGE_ORDER.filter((k) => p.delta.counts[k] > 0).map((k) => /* @__PURE__ */ jsxs3("span", { className: `gb-lg-chg${PAST_KINDS.has(k) ? " past" : ""}`, children: [
3101
+ /* @__PURE__ */ jsx3("i", { style: { boxShadow: `0 0 0 2px ${DIFF_COLORS[k]}b0, 0 0 0 5px ${DIFF_COLORS[k]}40` } }),
3102
+ /* @__PURE__ */ jsx3("span", { style: k === "added" ? { textDecoration: `underline 2px ${DIFF_COLORS[k]}`, textUnderlineOffset: 3 } : PAST_KINDS.has(k) ? { textDecoration: `line-through 2px ${DIFF_COLORS[k]}` } : void 0, children: t.change[k] }),
3103
+ /* @__PURE__ */ jsx3("b", { children: p.delta.counts[k] })
3104
+ ] }, k)) }),
3105
+ /* @__PURE__ */ jsx3("div", { className: "gb-lg-foot", children: isEmptyLook(look) && !p.hidden.nodes.length && !p.hidden.edges.length ? /* @__PURE__ */ jsx3("span", { children: t.legendHint }) : /* @__PURE__ */ jsx3("button", { type: "button", onClick: () => {
3106
+ onLook({});
3107
+ p.onShowAll();
3108
+ }, children: t.legendReset }) })
2712
3109
  ] }),
2713
- p.delta && /* Change legend: only a legend, not a filter. Marks match the text on the graph: strikethrough = removed, underline = added. */
2714
- /* @__PURE__ */ jsx3("div", { className: "gb-lg-row gb-lg-diff", children: CHANGE_ORDER.filter((k) => p.delta.counts[k] > 0).map((k) => /* @__PURE__ */ jsxs3("span", { className: `gb-lg-chg${PAST_KINDS.has(k) ? " past" : ""}`, children: [
2715
- /* @__PURE__ */ jsx3("i", { style: { boxShadow: `0 0 0 2px ${DIFF_COLORS[k]}b0, 0 0 0 5px ${DIFF_COLORS[k]}40` } }),
2716
- /* @__PURE__ */ jsx3("span", { style: k === "added" ? { textDecoration: `underline 2px ${DIFF_COLORS[k]}`, textUnderlineOffset: 3 } : PAST_KINDS.has(k) ? { textDecoration: `line-through 2px ${DIFF_COLORS[k]}` } : void 0, children: t.change[k] }),
2717
- /* @__PURE__ */ jsx3("b", { children: p.delta.counts[k] })
2718
- ] }, k)) }),
2719
- /* @__PURE__ */ jsx3("div", { className: "gb-lg-foot", children: isEmptyLook(look) && !p.hidden.nodes.length && !p.hidden.edges.length ? /* @__PURE__ */ jsx3("span", { children: t.legendHint }) : /* @__PURE__ */ jsx3("button", { type: "button", onClick: () => {
2720
- onLook({});
2721
- p.onShowAll();
2722
- }, children: t.legendReset }) }),
2723
3110
  /* @__PURE__ */ jsx3("span", { className: "gb-lg-act", children: /* @__PURE__ */ jsx3("button", { type: "button", className: "gb-lg-btn", onClick: () => p.onCollapsed(true), "aria-expanded": true, "aria-label": t.legend, title: t.legend, children: /* @__PURE__ */ jsx3(Icon, { d: I.collapse, size: 13 }) }) })
2724
3111
  ] });
2725
3112
  return /* @__PURE__ */ jsx3(LegendFrame, { collapsed: p.collapsed, children: content });
@@ -3155,7 +3542,7 @@ function measureDiffGeom(cy, hidden) {
3155
3542
  function Drawer({ children }) {
3156
3543
  const last = useRef4(children);
3157
3544
  if (children) last.current = children;
3158
- const [gone, setGone] = useState4(!children);
3545
+ const [gone, setGone] = useState5(!children);
3159
3546
  const open = !!children;
3160
3547
  useEffect4(() => {
3161
3548
  if (open) {
@@ -3208,7 +3595,7 @@ function GraphCanvas(props) {
3208
3595
  emphasis: hostEmphasis = null,
3209
3596
  legend = true
3210
3597
  } = props;
3211
- const [innerLook, setInnerLook] = useState4(props.defaultLook ?? {});
3598
+ const [innerLook, setInnerLook] = useState5(props.defaultLook ?? {});
3212
3599
  const look = props.look ?? innerLook;
3213
3600
  const setLook = useCallback2((l) => {
3214
3601
  if (!props.look) setInnerLook(l);
@@ -3217,17 +3604,17 @@ function GraphCanvas(props) {
3217
3604
  const lookProfile = useMemo5(() => applyLook(baseProfile, look), [baseProfile, look]);
3218
3605
  const theme = useMemo5(() => look.skeleton ? { ...baseTheme, skeleton: look.skeleton } : baseTheme, [baseTheme, look.skeleton]);
3219
3606
  const rootStyle = useMemo5(() => ({ ...chromeStyle(theme), ...style }), [theme, style]);
3220
- const [legendEmphasis, setLegendEmphasis] = useState4(null);
3607
+ const [legendEmphasis, setLegendEmphasis] = useState5(null);
3221
3608
  const emphasis = legendEmphasis ?? hostEmphasis;
3222
- const [legendCollapsed, setLegendCollapsed] = useState4(false);
3609
+ const [legendCollapsed, setLegendCollapsed] = useState5(false);
3223
3610
  const stageRef = useRef4(null);
3224
3611
  useEffect4(() => {
3225
3612
  if ((stageRef.current?.clientWidth ?? 1e3) < 640) setLegendCollapsed(true);
3226
3613
  }, []);
3227
- const [liveCy, setLiveCy] = useState4(null);
3614
+ const [liveCy, setLiveCy] = useState5(null);
3228
3615
  const profile = useShapeOf(lookProfile);
3229
3616
  const strings = useMemo5(() => ({ ...EN, ...props.strings, error: { ...EN.error, ...props.strings?.error } }), [props.strings]);
3230
- const [innerView, setInnerView] = useState4({ ...FULL_VIEW, ...props.defaultView });
3617
+ const [innerView, setInnerView] = useState5({ ...FULL_VIEW, ...props.defaultView });
3231
3618
  const rawView = props.view ?? innerView;
3232
3619
  const setView = useCallback2((patch) => {
3233
3620
  const next = { ...props.view ?? innerView, ...patch };
@@ -3235,7 +3622,7 @@ function GraphCanvas(props) {
3235
3622
  props.onViewChange?.(next);
3236
3623
  }, [props.view, props.onViewChange, innerView]);
3237
3624
  const containerRef = useRef4(null);
3238
- const [layoutOwner] = useState4(() => ({}));
3625
+ const [layoutOwner] = useState5(() => ({}));
3239
3626
  const cyRef = useRef4(null);
3240
3627
  const mirrorRef = useRef4(null);
3241
3628
  const mirrorElRef = useRef4(null);
@@ -3245,11 +3632,11 @@ function GraphCanvas(props) {
3245
3632
  const runRef = useRef4(0);
3246
3633
  const platesRef = useRef4([]);
3247
3634
  const dispRef = useRef4({});
3248
- const [renderModel, setRenderModel] = useState4(model);
3635
+ const [renderModel, setRenderModel] = useState5(model);
3249
3636
  const prevModelRef = useRef4(null);
3250
3637
  const prevProfileRef = useRef4(null);
3251
- const [pastRenderModel, setPastRenderModel] = useState4(null);
3252
- const [renderWorld, setRenderWorld] = useState4(profile);
3638
+ const [pastRenderModel, setPastRenderModel] = useState5(null);
3639
+ const [renderWorld, setRenderWorld] = useState5(profile);
3253
3640
  if (renderWorld !== profile) {
3254
3641
  setRenderWorld(profile);
3255
3642
  setRenderModel(model);
@@ -3294,8 +3681,8 @@ function GraphCanvas(props) {
3294
3681
  const playPlanesRef = useRef4(null);
3295
3682
  const sightRef = useRef4("");
3296
3683
  const searchInputRef = useRef4(null);
3297
- const [selected, setSelected] = useState4(null);
3298
- const [editing, setEditing] = useState4(null);
3684
+ const [selected, setSelected] = useState5(null);
3685
+ const [editing, setEditing] = useState5(null);
3299
3686
  const editable = !!onEdit && !diff;
3300
3687
  const onEditRef = useRef4(onEdit);
3301
3688
  onEditRef.current = onEdit;
@@ -3303,13 +3690,13 @@ function GraphCanvas(props) {
3303
3690
  const keepSelRef = useRef4(null);
3304
3691
  const pickRef = useRef4(() => {
3305
3692
  });
3306
- const [prog, setProg] = useState4(null);
3307
- const [plates, setPlates] = useState4([]);
3308
- const [hotLayer, setHotLayer] = useState4(null);
3693
+ const [prog, setProg] = useState5(null);
3694
+ const [plates, setPlates] = useState5([]);
3695
+ const [hotLayer, setHotLayer] = useState5(null);
3309
3696
  const hotLayerRef = useRef4(null);
3310
- const [plateAlpha, setPlateAlpha] = useState4(0);
3697
+ const [plateAlpha, setPlateAlpha] = useState5(0);
3311
3698
  const plateAlphaRef = useRef4(0);
3312
- const [viewport, setViewport] = useState4({ zoom: 1, pan: { x: 0, y: 0 } });
3699
+ const [viewport, setViewport] = useState5({ zoom: 1, pan: { x: 0, y: 0 } });
3313
3700
  const built = useMemo5(
3314
3701
  () => buildElements(renderModel, profile),
3315
3702
  [renderModel, profile]
@@ -3411,7 +3798,7 @@ function GraphCanvas(props) {
3411
3798
  const missedRef = useRef4(false);
3412
3799
  const owedLayoutRef = useRef4(null);
3413
3800
  const flushOwedRef = useRef4(null);
3414
- const [resume, setResume] = useState4(0);
3801
+ const [resume, setResume] = useState5(0);
3415
3802
  const markBusy = useCallback2((v) => {
3416
3803
  if (busyRef.current === v) return;
3417
3804
  busyRef.current = v;
@@ -3499,8 +3886,8 @@ function GraphCanvas(props) {
3499
3886
  markBusy(true);
3500
3887
  setRenderModel(delta.model);
3501
3888
  }, [model, resume]);
3502
- const [diffGeom, setDiffGeom] = useState4(EMPTY_GEOM);
3503
- const [pastGeom, setPastGeom] = useState4(EMPTY_GEOM);
3889
+ const [diffGeom, setDiffGeom] = useState5(EMPTY_GEOM);
3890
+ const [pastGeom, setPastGeom] = useState5(EMPTY_GEOM);
3504
3891
  const visibleNodes = useCallback2((cy) => {
3505
3892
  const { visible } = resolvedRef.current;
3506
3893
  const left = leftRef.current;
@@ -3740,7 +4127,7 @@ function GraphCanvas(props) {
3740
4127
  const ele = cy.$id(id);
3741
4128
  if (ele.empty() || !ele.visible()) continue;
3742
4129
  const painter = painterRef.current;
3743
- const focused = ele.selected() || !!painter?.focused(id);
4130
+ const focused = ele.selected() || ele.hasClass("gb-preview-hop") || !!painter?.focused(id);
3744
4131
  const a = smoothstep(s.o) * ele.effectiveOpacity() * (focused ? 1 : LABEL_ALPHA * (painter?.dimOf(id) ?? 1));
3745
4132
  if (a < 0.02) continue;
3746
4133
  const p = ele.renderedPosition();
@@ -3834,10 +4221,10 @@ function GraphCanvas(props) {
3834
4221
  side: book.get(id)?.next ?? book.get(id)?.side,
3835
4222
  // The selected and the hovered one: name always shown. Search hits only get a bonus (see below): forcing hundreds of hits
3836
4223
  // would pile into a heap, the same problem as a large hovered cluster.
3837
- pinned: n.selected() || id === hovered
4224
+ pinned: n.selected() || id === hovered || n.hasClass("gb-preview")
3838
4225
  });
3839
4226
  const held = book.get(id);
3840
- const b = (held && (held.t === 1 || held.next) ? LABEL_HOLD : 0) + (painterRef.current?.focused(id) ? HOVER_BOOST : 0) + (changed?.has(id) ? CHANGE_BOOST : 0) + (breathing ? BREATH_AMPLITUDE * Math.sin(breathPhaseRef.current * 0.6 + idPhase(id)) : 0);
4227
+ const b = (held && (held.t === 1 || held.next) ? LABEL_HOLD : 0) + (painterRef.current?.focused(id) || n.hasClass("gb-preview-hop") ? HOVER_BOOST : 0) + (changed?.has(id) ? CHANGE_BOOST : 0) + (breathing ? BREATH_AMPLITUDE * Math.sin(breathPhaseRef.current * 0.6 + idPhase(id)) : 0);
3841
4228
  if (b) bias.set(id, b);
3842
4229
  });
3843
4230
  const plan = planLabels(inputs, { viewport: { w, h }, padding: labelSpacingRef.current, bias });
@@ -3911,6 +4298,25 @@ function GraphCanvas(props) {
3911
4298
  applyHover(cy, null);
3912
4299
  }, HOVER_OUT_MS);
3913
4300
  }, [labelsFrozen, applyHover]);
4301
+ const previewTouch = useCallback2((cy, target) => {
4302
+ if (hoverOutRef.current != null) {
4303
+ clearTimeout(hoverOutRef.current);
4304
+ hoverOutRef.current = null;
4305
+ }
4306
+ if (labelsFrozen()) target = null;
4307
+ cy.batch(() => {
4308
+ cy.$(".gb-preview, .gb-preview-hop").removeClass("gb-preview gb-preview-hop");
4309
+ if (diffRef.current || !readableRef.current) {
4310
+ target?.addClass("gb-preview");
4311
+ if (target) (target.isNode() ? target.closedNeighborhood() : target.connectedNodes()).addClass("gb-preview-hop");
4312
+ }
4313
+ });
4314
+ if (!diffRef.current && readableRef.current) applyHover(cy, target);
4315
+ else {
4316
+ replanLabels(cy);
4317
+ drawLabels(cy);
4318
+ }
4319
+ }, [labelsFrozen, applyHover, replanLabels, drawLabels]);
3914
4320
  const armBreath = useCallback2((cy) => {
3915
4321
  if (!readableRef.current || breathTimerRef.current != null) return;
3916
4322
  const tick = () => {
@@ -4018,10 +4424,18 @@ function GraphCanvas(props) {
4018
4424
  layer: d.layer,
4019
4425
  origin: d.origin,
4020
4426
  container: builtRef.current.containers.has(d.id),
4021
- flags: el.classes().filter((c) => !["gb-node", "flat", "container", "gb-hit", d.kind].includes(c)),
4427
+ flags: el.classes().filter((c) => !["gb-node", "flat", "container", "gb-hit", "gb-preview", "gb-preview-hop", d.kind].includes(c)),
4022
4428
  detail: d.detail ?? null
4023
4429
  });
4024
4430
  }, []);
4431
+ const selectTouch = useCallback2((target) => {
4432
+ for (const cy of [cyRef.current, mirrorRef.current]) {
4433
+ if (cy && !cy.destroyed()) cy.$(":selected").unselect();
4434
+ }
4435
+ target?.select();
4436
+ if (target) selectEle(target);
4437
+ else setSelected(null);
4438
+ }, [selectEle]);
4025
4439
  const cancelFrames = useCallback2(() => {
4026
4440
  const tw = tweenRef.current;
4027
4441
  if (tw) {
@@ -4609,9 +5023,9 @@ ${lt}`;
4609
5023
  cy.on("render", () => drawLabels(cy));
4610
5024
  let lastW = 0, lastH = 0;
4611
5025
  const refit = () => {
4612
- const el2 = containerRef.current;
4613
- if (!el2) return;
4614
- const w = el2.clientWidth, h = el2.clientHeight;
5026
+ const el = containerRef.current;
5027
+ if (!el) return;
5028
+ const w = el.clientWidth, h = el.clientHeight;
4615
5029
  if (w === 0 || h === 0 || w === lastW && h === lastH) return;
4616
5030
  const first = lastW === 0;
4617
5031
  lastW = w;
@@ -4630,11 +5044,6 @@ ${lt}`;
4630
5044
  };
4631
5045
  ro = new ResizeObserver(refit);
4632
5046
  ro.observe(containerRef.current);
4633
- cy.on("mouseover", "node, edge", (evt) => {
4634
- touchInteraction();
4635
- setHover(cy, evt.target);
4636
- });
4637
- cy.on("mouseout", "node, edge", () => setHover(cy, null));
4638
5047
  cy.on("select", "node", (evt) => {
4639
5048
  ringsRef.current.set(evt.target.id(), performance.now());
4640
5049
  runRing(cy);
@@ -4645,45 +5054,18 @@ ${lt}`;
4645
5054
  });
4646
5055
  cy.on("select unselect", "node", () => scheduleReadability(cy));
4647
5056
  cy.$id(VIRTUAL_ROOT).unselectify();
4648
- cy.on("tap", "node", (evt) => {
4649
- touchInteraction();
4650
- if (evt.target.id() === VIRTUAL_ROOT) setSelected(null);
4651
- else selectEle(evt.target);
4652
- });
4653
- cy.on("tap", (evt) => {
4654
- touchInteraction();
4655
- if (evt.target === cy) setSelected(null);
5057
+ detach = installGraphInput(cy, containerRef.current, {
5058
+ interact: touchInteraction,
5059
+ cancelFly,
5060
+ selectTouch,
5061
+ select: (target) => target ? selectEle(target) : setSelected(null),
5062
+ hover: (target) => setHover(cy, target),
5063
+ preview: (target) => previewTouch(cy, target),
5064
+ // The first click opens the inspector: let its new width settle before framing.
5065
+ focus: (id) => requestAnimationFrame(() => requestAnimationFrame(() => {
5066
+ if (!cy.destroyed()) flyToRef.current(id, true);
5067
+ }))
4656
5068
  });
4657
- cy.on("tapstart", () => cancelFly());
4658
- let lastTap = { id: "", t: 0 };
4659
- cy.on("tap", "node", (evt) => {
4660
- const id = evt.target.id();
4661
- const now = Date.now();
4662
- const isDouble = lastTap.id === id && now - lastTap.t < 350;
4663
- lastTap = { id, t: now };
4664
- if (!isDouble || id === VIRTUAL_ROOT) return;
4665
- requestAnimationFrame(() => requestAnimationFrame(() => flyToRef.current(id, true)));
4666
- });
4667
- const el = containerRef.current;
4668
- const onWheel = (e) => {
4669
- e.preventDefault();
4670
- touchInteraction();
4671
- cancelFly();
4672
- if (e.ctrlKey || e.metaKey) {
4673
- const rect = el.getBoundingClientRect();
4674
- cy.zoom({
4675
- level: cy.zoom() * Math.exp(-e.deltaY * 0.01),
4676
- renderedPosition: { x: e.clientX - rect.left, y: e.clientY - rect.top }
4677
- });
4678
- } else cy.panBy({ x: -e.deltaX, y: -e.deltaY });
4679
- };
4680
- el.addEventListener("wheel", onWheel, { passive: false });
4681
- const onLeave = () => setHover(cy, null);
4682
- el.addEventListener("mouseleave", onLeave);
4683
- detach = () => {
4684
- el.removeEventListener("wheel", onWheel);
4685
- el.removeEventListener("mouseleave", onLeave);
4686
- };
4687
5069
  cy.on("viewport", () => {
4688
5070
  if (plateAlphaRef.current > 0 || diffRef.current) setViewport({ zoom: cy.zoom(), pan: { ...cy.pan() } });
4689
5071
  const m = mirrorRef.current;
@@ -4760,12 +5142,12 @@ ${lt}`;
4760
5142
  seatFromLastFrame(m, dispRef.current, (q2) => pastBuilt.parentOf.get(q2));
4761
5143
  mirrorRef.current = m;
4762
5144
  m.$id(VIRTUAL_ROOT).unselectify();
4763
- m.on("tap", "node", (evt) => {
4764
- if (evt.target.id() === VIRTUAL_ROOT) setSelected(null);
4765
- else selectEle(evt.target);
4766
- });
4767
- m.on("tap", (evt) => {
4768
- if (evt.target === m) setSelected(null);
5145
+ detach = installGraphInput(m, mirrorElRef.current, {
5146
+ interact: touchInteraction,
5147
+ cancelFly,
5148
+ selectTouch,
5149
+ select: (target) => target ? selectEle(target) : setSelected(null),
5150
+ preview: (target) => previewTouch(m, target)
4769
5151
  });
4770
5152
  m.on("viewport", () => {
4771
5153
  const cy2 = cyRef.current;
@@ -4775,15 +5157,6 @@ ${lt}`;
4775
5157
  syncingRef.current = false;
4776
5158
  });
4777
5159
  const el = mirrorElRef.current;
4778
- const onWheel = (e) => {
4779
- e.preventDefault();
4780
- if (e.ctrlKey || e.metaKey) {
4781
- const rect = el.getBoundingClientRect();
4782
- m.zoom({ level: m.zoom() * Math.exp(-e.deltaY * 0.01), renderedPosition: { x: e.clientX - rect.left, y: e.clientY - rect.top } });
4783
- } else m.panBy({ x: -e.deltaX, y: -e.deltaY });
4784
- };
4785
- el.addEventListener("wheel", onWheel, { passive: false });
4786
- detach = () => el.removeEventListener("wheel", onWheel);
4787
5160
  ro = new ResizeObserver(() => {
4788
5161
  if (!m.destroyed()) {
4789
5162
  m.resize();
@@ -5257,7 +5630,9 @@ export {
5257
5630
  labelBox,
5258
5631
  planLabels,
5259
5632
  idPhase,
5633
+ placePanel,
5260
5634
  ALL_CONTROLS,
5635
+ touchGestures,
5261
5636
  applyLook,
5262
5637
  DiffOverlay,
5263
5638
  GraphCanvas