glassbrain 0.1.2 → 0.1.4

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.
@@ -17,6 +17,7 @@ import {
17
17
  anchorOf,
18
18
  buildElements,
19
19
  checkEdit,
20
+ chromeStyle,
20
21
  cls,
21
22
  defaultNodeColor,
22
23
  defaultProfile,
@@ -51,7 +52,7 @@ import {
51
52
  unionSides,
52
53
  untheme,
53
54
  validateModel
54
- } from "./chunk-UJCALP4P.js";
55
+ } from "./chunk-VCM766BZ.js";
55
56
  import {
56
57
  DetailPanel,
57
58
  I,
@@ -70,7 +71,7 @@ import {
70
71
  } from "./chunk-ZA47FP7C.js";
71
72
 
72
73
  // src/react/GraphCanvas.tsx
73
- 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";
74
75
 
75
76
  // src/paint.ts
76
77
  var MIN_DOT = 2;
@@ -1475,7 +1476,77 @@ function idPhase(id) {
1475
1476
  }
1476
1477
 
1477
1478
  // src/react/Toolbar.tsx
1478
- 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
1479
1550
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
1480
1551
  var ALL_CONTROLS = ["search", "origins", "layers", "relayout", "zoom"];
1481
1552
  function Hl({ text, re }) {
@@ -1493,11 +1564,12 @@ function Hl({ text, re }) {
1493
1564
  function LayerPicker({ layers, view, setView, disabled }) {
1494
1565
  const t = useStrings();
1495
1566
  const box = useRef(null);
1496
- const [thumb, setThumb] = useState(null);
1567
+ const [thumb, setThumb] = useState2(null);
1568
+ const [edges, setEdges] = useState2({ left: false, right: false });
1497
1569
  const stacked = !!view.planes;
1498
1570
  const on = new Set(view.layers ?? layers.map((l) => l.id));
1499
1571
  const single = stacked ? null : view.layers?.[0] ?? layers[0].id;
1500
- useLayoutEffect(() => {
1572
+ useLayoutEffect2(() => {
1501
1573
  const root = box.current;
1502
1574
  if (!root || single == null) {
1503
1575
  setThumb(null);
@@ -1507,13 +1579,29 @@ function LayerPicker({ layers, view, setView, disabled }) {
1507
1579
  const el = root.querySelector(`button[data-v="${CSS.escape(single)}"]`);
1508
1580
  if (!el) return;
1509
1581
  const r = root.getBoundingClientRect(), e = el.getBoundingClientRect();
1510
- 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 });
1511
1583
  };
1512
1584
  measure();
1513
1585
  const ro = new ResizeObserver(measure);
1514
1586
  ro.observe(root);
1515
1587
  return () => ro.disconnect();
1516
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]);
1517
1605
  const click = (id) => {
1518
1606
  if (!stacked) {
1519
1607
  if (id !== single) setView({ layers: [id] });
@@ -1523,24 +1611,26 @@ function LayerPicker({ layers, view, setView, disabled }) {
1523
1611
  const next = layers.map((l) => l.id).filter((l) => l === id ? !on.has(l) : on.has(l));
1524
1612
  setView({ layers: next });
1525
1613
  };
1526
- return /* @__PURE__ */ jsxs("div", { className: `gb-segm gb-layers${stacked ? " is-multi" : ""}`, ref: box, role: stacked ? "group" : "radiogroup", children: [
1527
- thumb && /* @__PURE__ */ jsx("i", { className: "gb-thumb", style: { transform: `translateX(${thumb.x}px)`, width: thumb.w } }),
1528
- layers.map((l) => {
1529
- const lit = stacked ? on.has(l.id) : l.id === single;
1530
- return /* @__PURE__ */ jsx(
1531
- "button",
1532
- {
1533
- "data-v": l.id,
1534
- disabled,
1535
- className: lit ? "on" : "",
1536
- ...stacked ? { "aria-pressed": lit } : { role: "radio", "aria-checked": lit },
1537
- title: stacked ? t.stackLayer(l.label, lit) : t.viewLayer(l.label),
1538
- onClick: () => click(l.id),
1539
- children: l.label
1540
- },
1541
- l.id
1542
- );
1543
- }),
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
+ ] }),
1544
1634
  /* @__PURE__ */ jsx("span", { className: "gb-sep", "aria-hidden": true }),
1545
1635
  /* @__PURE__ */ jsx(
1546
1636
  "button",
@@ -1556,9 +1646,13 @@ function LayerPicker({ layers, view, setView, disabled }) {
1556
1646
  )
1557
1647
  ] });
1558
1648
  }
1559
- function usePopover() {
1560
- 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);
1561
1653
  const ref = useRef(null);
1654
+ const panelRef = useRef(null);
1655
+ const placement = usePanelPlacement(open, ref, panelRef, prefer);
1562
1656
  useEffect(() => {
1563
1657
  if (!open) return;
1564
1658
  const down = (e) => {
@@ -1574,12 +1668,12 @@ function usePopover() {
1574
1668
  window.removeEventListener("keydown", key);
1575
1669
  };
1576
1670
  }, [open]);
1577
- return { open, setOpen, ref };
1671
+ return { open, setOpen, ref, panelRef, placement };
1578
1672
  }
1579
1673
  function SearchBox(p) {
1580
1674
  const t = useStrings();
1581
- const [focused, setFocused] = useState(false);
1582
- const [active, setActive] = useState(0);
1675
+ const [focused, setFocused] = useState2(false);
1676
+ const [active, setActive] = useState2(0);
1583
1677
  const previewing = useRef(false);
1584
1678
  const results = p.search?.results ?? [];
1585
1679
  const open = focused && !!p.query.trim();
@@ -1698,7 +1792,7 @@ function SearchBox(p) {
1698
1792
  }
1699
1793
  function ViewMenu(p) {
1700
1794
  const t = useStrings();
1701
- const pop = usePopover();
1795
+ const pop = usePopover(MENU_PLACE);
1702
1796
  return /* @__PURE__ */ jsxs("div", { className: "gb-menu", ref: pop.ref, children: [
1703
1797
  /* @__PURE__ */ jsx(
1704
1798
  "button",
@@ -1714,8 +1808,12 @@ function ViewMenu(p) {
1714
1808
  pop.open && /* @__PURE__ */ jsxs(
1715
1809
  "div",
1716
1810
  {
1811
+ ref: pop.panelRef,
1717
1812
  className: "gb-panel",
1718
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" },
1719
1817
  onClick: (e) => {
1720
1818
  if (e.target.closest(".gb-menu-item")) pop.setOpen(false);
1721
1819
  },
@@ -1737,7 +1835,7 @@ function Toolbar(p) {
1737
1835
  const originPick = controls.origins && p.origins.length > 1;
1738
1836
  const multi = controls.layers && p.layers.length > 1;
1739
1837
  const showLayer = (l) => setView(view.planes ? { layers: [...view.layers ?? [], l] } : { layers: [l] });
1740
- return /* @__PURE__ */ jsxs("div", { className: "gb-bar", children: [
1838
+ return /* @__PURE__ */ jsxs("div", { className: `gb-bar${multi ? " has-layers" : ""}`, children: [
1741
1839
  controls.search && /* @__PURE__ */ jsx(
1742
1840
  SearchBox,
1743
1841
  {
@@ -1785,7 +1883,7 @@ function Toolbar(p) {
1785
1883
  var GROUP_CAP = 100;
1786
1884
  function Issues({ issues, onPick }) {
1787
1885
  const t = useStrings();
1788
- const pop = usePopover();
1886
+ const pop = usePopover(ISSUES_PLACE);
1789
1887
  const groups = useMemo(() => {
1790
1888
  const by = /* @__PURE__ */ new Map();
1791
1889
  for (const it of issues) {
@@ -1814,25 +1912,36 @@ function Issues({ issues, onPick }) {
1814
1912
  ]
1815
1913
  }
1816
1914
  ),
1817
- pop.open && /* @__PURE__ */ jsxs("div", { className: "gb-panel gb-panel-up gb-issues", role: "dialog", children: [
1818
- /* @__PURE__ */ jsx("div", { className: "gb-panel-h", children: t.issuesTitle(errors, warns) }),
1819
- groups.map((g) => /* @__PURE__ */ jsxs("details", { open: groups.length === 1, children: [
1820
- /* @__PURE__ */ jsxs("summary", { className: g.error ? "is-err" : "", children: [
1821
- /* @__PURE__ */ jsx("span", { children: g.name }),
1822
- /* @__PURE__ */ jsx("b", { children: g.items.length })
1823
- ] }),
1824
- /* @__PURE__ */ jsxs("ul", { children: [
1825
- g.items.slice(0, GROUP_CAP).map((it, i) => {
1826
- const id = target(it);
1827
- return /* @__PURE__ */ jsx("li", { className: id ? "is-link" : "", onClick: id ? () => {
1828
- onPick(id);
1829
- pop.setOpen(false);
1830
- } : void 0, children: it.message }, i);
1831
- }),
1832
- g.items.length > GROUP_CAP && /* @__PURE__ */ jsx("li", { className: "gb-more", children: t.moreItems(g.items.length - GROUP_CAP) })
1833
- ] })
1834
- ] }, g.name))
1835
- ] })
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
+ )
1836
1945
  ] });
1837
1946
  }
1838
1947
  function ZoomDock(p) {
@@ -1848,6 +1957,254 @@ function ZoomDock(p) {
1848
1957
  ] });
1849
1958
  }
1850
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
+
1851
2208
  // src/react/camera.ts
1852
2209
  var toRect = (v, W, H) => ({
1853
2210
  cx: (W / 2 - v.pan.x) / v.zoom,
@@ -1889,7 +2246,7 @@ function zoomPath(a, b) {
1889
2246
  var easeInOut = (x) => x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
1890
2247
 
1891
2248
  // src/react/EditPanel.tsx
1892
- 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";
1893
2250
  import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
1894
2251
  var PICK_MAX = 8;
1895
2252
  function NodeRef({ id, model, colorOf, sub }) {
@@ -1904,9 +2261,9 @@ function NodeRef({ id, model, colorOf, sub }) {
1904
2261
  }
1905
2262
  function NodePicker({ model, value, onChange, exclude, empty, autoFocus, label, colorOf, id: inputId }) {
1906
2263
  const t = useStrings();
1907
- const [q2, setQ] = useState2("");
1908
- const [open, setOpen] = useState2(false);
1909
- const [active, setActive] = useState2(0);
2264
+ const [q2, setQ] = useState3("");
2265
+ const [open, setOpen] = useState3(false);
2266
+ const [active, setActive] = useState3(0);
1910
2267
  const idx = useMemo2(() => indexModel(model), [model]);
1911
2268
  const hits = useMemo2(
1912
2269
  () => q2.trim() ? searchNodes(model, q2).filter((id) => !exclude?.(id)).slice(0, PICK_MAX) : [],
@@ -2062,7 +2419,7 @@ function EditPanel({ target, model, onSubmit, onCancel, onRetarget, renderEditor
2062
2419
  }
2063
2420
  function useSubmit(onSubmit) {
2064
2421
  const t = useStrings();
2065
- const [error, setError] = useState2(null);
2422
+ const [error, setError] = useState3(null);
2066
2423
  const submit = (op) => {
2067
2424
  const e = onSubmit(op);
2068
2425
  setError(e ? t.error[e] : null);
@@ -2076,14 +2433,14 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
2076
2433
  const { error, setError, submit } = useSubmit(onSubmit);
2077
2434
  const node = target.id ? model.index.get(target.id) : void 0;
2078
2435
  const creating = !node;
2079
- const [id, setId] = useState2("");
2080
- 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);
2081
2438
  const initial = useMemo2(
2082
2439
  () => pretty(node ? { label: node.label, kind: node.kind ?? "", data: node.data ?? {} } : { label: "", kind: "", data: {} }),
2083
2440
  [node]
2084
2441
  );
2085
- const [text, setText] = useState2(initial);
2086
- const [confirming, setConfirming] = useState2(false);
2442
+ const [text, setText] = useState3(initial);
2443
+ const [confirming, setConfirming] = useState3(false);
2087
2444
  const idErr = creating && id ? checkEdit(model, { op: "addNode", id, set: {} }) : null;
2088
2445
  const below = useMemo2(() => {
2089
2446
  if (!node) return null;
@@ -2234,10 +2591,10 @@ function EdgeForm({ source: src, model, onSubmit, onCancel, colorOf }) {
2234
2591
  const t = useStrings();
2235
2592
  const uid = useId();
2236
2593
  const { error, submit } = useSubmit(onSubmit);
2237
- const [source, setSource] = useState2(src ?? null);
2238
- const [target, setTarget] = useState2(null);
2239
- const [kind, setKind] = useState2("");
2240
- 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("");
2241
2598
  const kinds = useMemo2(() => [...new Set(model.edges.map((e) => e.kind).filter(Boolean))].sort(), [model]);
2242
2599
  const save = () => {
2243
2600
  const op = {
@@ -2287,7 +2644,8 @@ function EdgeForm({ source: src, model, onSubmit, onCancel, colorOf }) {
2287
2644
  }
2288
2645
 
2289
2646
  // src/react/Legend.tsx
2290
- import { useCallback, useEffect as useEffect3, 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";
2291
2649
  import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
2292
2650
  function applyLook(profile, look) {
2293
2651
  if (!look || !(look.nodePalette || look.edgePalette || look.nodeSize || look.edgeWidth)) return profile;
@@ -2338,12 +2696,20 @@ function tally(model, profile) {
2338
2696
  var SCALES = [0.5, 1, 2];
2339
2697
  var OPEN_DELAY_MS = 120;
2340
2698
  var CLOSE_GRACE_MS = 200;
2699
+ var LEGEND_PLACE = { side: "top", align: "start" };
2341
2700
  var CHANGE_ORDER = ["added", "changed", "moved", "merged", "removed"];
2342
2701
  function Item(p) {
2343
2702
  const t = useStrings();
2344
2703
  const { k, open, ctl } = p;
2704
+ const item = useRef3(null);
2345
2705
  const btn = useRef3(null);
2706
+ const panel = useRef3(null);
2346
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
+ }, []);
2347
2713
  useEffect3(() => {
2348
2714
  const el = well.current;
2349
2715
  if (!el) return;
@@ -2358,6 +2724,7 @@ function Item(p) {
2358
2724
  return /* @__PURE__ */ jsxs3(
2359
2725
  "span",
2360
2726
  {
2727
+ ref: item,
2361
2728
  className: `gb-lg-item${p.off ? " off" : ""}${open ? " is-open" : ""}`,
2362
2729
  onPointerEnter: (e) => ctl.enter(k, e),
2363
2730
  onPointerLeave: (e) => ctl.leave(k, e),
@@ -2368,7 +2735,7 @@ function Item(p) {
2368
2735
  }
2369
2736
  },
2370
2737
  onBlur: (e) => {
2371
- 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);
2372
2739
  },
2373
2740
  children: [
2374
2741
  /* @__PURE__ */ jsxs3(
@@ -2390,50 +2757,69 @@ function Item(p) {
2390
2757
  ]
2391
2758
  }
2392
2759
  ),
2393
- open && /* @__PURE__ */ jsxs3("div", { className: "gb-lg-pop", role: "dialog", "aria-label": p.title, children: [
2394
- p.onToggle && /* @__PURE__ */ jsx3(
2395
- "button",
2396
- {
2397
- type: "button",
2398
- className: `gb-lg-eye${p.off ? " off" : ""}`,
2399
- "aria-pressed": !p.off,
2400
- "aria-label": p.off ? t.legendShow : t.legendHide,
2401
- title: p.off ? t.legendShow : t.legendHideTip,
2402
- onClick: (e) => {
2403
- p.onToggle();
2404
- finish(e.detail === 0);
2405
- },
2406
- children: /* @__PURE__ */ jsx3(Eye, { off: p.off })
2407
- }
2408
- ),
2409
- /* @__PURE__ */ jsxs3("label", { className: "gb-lg-well", title: `${t.legendColor} \xB7 ${p.color}`, children: [
2410
- /* @__PURE__ */ jsx3("i", { style: { background: p.color } }),
2411
- /* @__PURE__ */ jsx3(
2412
- "input",
2413
- {
2414
- ref: well,
2415
- type: "color",
2416
- value: p.color,
2417
- "aria-label": t.legendColor,
2418
- onClick: () => ctl.picking(true),
2419
- 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);
2420
2775
  }
2421
- )
2422
- ] }),
2423
- p.onScale && /* @__PURE__ */ jsx3("i", { className: "gb-lg-sep" }),
2424
- p.onScale && /* @__PURE__ */ jsx3("span", { className: "gb-lg-segm", role: "group", "aria-label": t.legendSize, children: SCALES.map((s) => /* @__PURE__ */ jsx3(
2425
- "button",
2426
- {
2427
- type: "button",
2428
- className: s === (p.scale ?? 1) ? "on" : "",
2429
- "aria-pressed": s === (p.scale ?? 1),
2430
- title: `${s}\xD7`,
2431
- onClick: () => p.onScale(s),
2432
- 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" }) })
2433
2776
  },
2434
- s
2435
- )) })
2436
- ] })
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)
2437
2823
  ]
2438
2824
  }
2439
2825
  );
@@ -2497,13 +2883,51 @@ function SkeletonEdge({ theme }) {
2497
2883
  /* @__PURE__ */ jsx3("polygon", { points: "1,5.25 29,3 29,9 1,6.75", fill: `url(#${id})` })
2498
2884
  ] });
2499
2885
  }
2886
+ function LegendFrame({ collapsed, children }) {
2887
+ const root = useRef3(null);
2888
+ const size = useRef3(null);
2889
+ useLayoutEffect3(() => {
2890
+ const el = root.current;
2891
+ const before = size.current;
2892
+ const after = el.getBoundingClientRect();
2893
+ size.current = after;
2894
+ if (!before || before.width === after.width && before.height === after.height || window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
2895
+ const body = el.firstElementChild;
2896
+ body.style.width = `${body.getBoundingClientRect().width}px`;
2897
+ const timing = { duration: 220, easing: "cubic-bezier(.3,.7,.2,1)" };
2898
+ const motion = el.animate([
2899
+ { width: `${before.width}px`, height: `${before.height}px`, overflow: "clip" },
2900
+ { width: `${after.width}px`, height: `${after.height}px`, overflow: "clip" }
2901
+ ], timing);
2902
+ const fade = body.animate([{ opacity: 0 }, { opacity: 1 }], timing);
2903
+ motion.onfinish = () => {
2904
+ body.style.width = "";
2905
+ size.current = el.getBoundingClientRect();
2906
+ };
2907
+ return () => {
2908
+ if (motion.playState === "running") size.current = el.getBoundingClientRect();
2909
+ motion.cancel();
2910
+ fade.cancel();
2911
+ body.style.width = "";
2912
+ };
2913
+ }, [collapsed]);
2914
+ useLayoutEffect3(() => {
2915
+ const el = root.current;
2916
+ const ro = new ResizeObserver(() => {
2917
+ if (!el.getAnimations().length) size.current = el.getBoundingClientRect();
2918
+ });
2919
+ ro.observe(el);
2920
+ return () => ro.disconnect();
2921
+ }, []);
2922
+ return /* @__PURE__ */ jsx3("div", { className: "gb-legend", ref: root, children });
2923
+ }
2500
2924
  function Legend(p) {
2501
2925
  const t = useStrings();
2502
2926
  const { look, onLook, theme, profile } = p;
2503
2927
  const count = useMemo3(() => tally(p.model, profile), [p.model, profile]);
2504
- const [open, setOpen] = useState3(null);
2505
- const [focused, setFocused] = useState3(null);
2506
- const [picking, setPicking] = useState3(false);
2928
+ const [open, setOpen] = useState4(null);
2929
+ const [focused, setFocused] = useState4(null);
2930
+ const [picking, setPicking] = useState4(false);
2507
2931
  const quiet = useRef3(null);
2508
2932
  const pointer = useRef3("mouse");
2509
2933
  const over = useRef3(null);
@@ -2521,7 +2945,7 @@ function Legend(p) {
2521
2945
  useEffect3(() => {
2522
2946
  const down = (e) => {
2523
2947
  pointer.current = e.pointerType;
2524
- 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();
2525
2949
  };
2526
2950
  document.addEventListener("pointerdown", down, true);
2527
2951
  return () => document.removeEventListener("pointerdown", down, true);
@@ -2587,105 +3011,105 @@ function Legend(p) {
2587
3011
  const setSkeleton = (c) => onLook({ ...look, skeleton: c });
2588
3012
  const name = (k) => profile.kindLabels[k] ?? k;
2589
3013
  const shown = (c) => themeColor(theme, c);
2590
- if (p.collapsed) {
2591
- return /* @__PURE__ */ jsx3(
2592
- "button",
2593
- {
2594
- type: "button",
2595
- className: "gb-lg-toggle",
2596
- "aria-expanded": false,
2597
- "aria-label": t.legend,
2598
- title: t.legend,
2599
- onClick: () => p.onCollapsed(false),
2600
- children: /* @__PURE__ */ jsx3(Icon, { d: I.legend })
2601
- }
2602
- );
2603
- }
2604
- return /* @__PURE__ */ jsxs3("div", { className: "gb-lg", ref: rootRef, children: [
2605
- p.caption && /* @__PURE__ */ jsx3("div", { className: "gb-lg-cap", children: p.caption }),
2606
- /* @__PURE__ */ jsxs3("div", { className: "gb-lg-row", children: [
2607
- /* @__PURE__ */ jsx3(
2608
- Item,
2609
- {
2610
- ...slot("n:"),
2611
- color: theme.skeleton,
2612
- onPick: setSkeleton,
2613
- title: t.legendPlain,
2614
- mark: /* @__PURE__ */ jsx3(NodeMark, { color: defaultNodeColor(theme, 0.3), ring: theme.canvas }),
2615
- label: t.legendPlainName,
2616
- count: count.plain
2617
- }
2618
- ),
2619
- nodeKinds.map((k) => {
2620
- const off = p.hidden.nodes.includes(k);
2621
- const scale = profile.nodeSize[k] ?? 1;
2622
- return /* @__PURE__ */ jsx3(
3014
+ const content = p.collapsed ? /* @__PURE__ */ jsx3(
3015
+ "button",
3016
+ {
3017
+ type: "button",
3018
+ className: "gb-lg-toggle",
3019
+ "aria-expanded": false,
3020
+ "aria-label": t.legend,
3021
+ title: t.legend,
3022
+ onClick: () => p.onCollapsed(false),
3023
+ children: /* @__PURE__ */ jsx3(Icon, { d: I.legend })
3024
+ }
3025
+ ) : /* @__PURE__ */ jsxs3("div", { className: "gb-lg", ref: rootRef, children: [
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(
2623
3030
  Item,
2624
3031
  {
2625
- ...slot(`n:${k}`),
2626
- color: shown(profile.nodePalette[k]),
2627
- title: name(k),
2628
- off,
2629
- onToggle: () => p.onToggle("nodes", k),
2630
- onPick: (c) => set("nodePalette", k, untheme(theme, c)),
2631
- scale,
2632
- glyph: "dot",
2633
- onScale: (s) => set("nodeSize", k, s),
2634
- mark: /* @__PURE__ */ jsx3(NodeMark, { color: shown(profile.nodePalette[k]), shape: marks.shape(k), ring: theme.canvas, off, scale }),
2635
- label: name(k),
2636
- count: count.nodes[k]
2637
- },
2638
- k
2639
- );
2640
- })
2641
- ] }),
2642
- /* @__PURE__ */ jsxs3("div", { className: "gb-lg-row", children: [
2643
- /* @__PURE__ */ jsx3(
2644
- Item,
2645
- {
2646
- ...slot("e:"),
2647
- color: theme.skeleton,
2648
- onPick: setSkeleton,
2649
- title: t.legendContains,
2650
- mark: /* @__PURE__ */ jsx3(SkeletonEdge, { theme }),
2651
- label: t.legendContainsName
2652
- }
2653
- ),
2654
- edgeKinds.map((k) => {
2655
- const off = p.hidden.edges.includes(k);
2656
- const scale = profile.edgeWidth[k] ?? 1;
2657
- 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(
2658
3066
  Item,
2659
3067
  {
2660
- ...slot(`e:${k}`),
2661
- color: shown(profile.edgePalette[k]),
2662
- title: name(k),
2663
- off,
2664
- onToggle: () => p.onToggle("edges", k),
2665
- onPick: (c) => set("edgePalette", k, untheme(theme, c)),
2666
- scale,
2667
- glyph: "line",
2668
- onScale: (s) => set("edgeWidth", k, s),
2669
- mark: /* @__PURE__ */ jsx3(EdgeMark, { color: shown(profile.edgePalette[k]), stroke: marks.stroke(k), off, scale }),
2670
- label: name(k),
2671
- count: count.edges[k]
2672
- },
2673
- k
2674
- );
2675
- })
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 }) })
2676
3109
  ] }),
2677
- p.delta && /* Change legend: only a legend, not a filter. Marks match the text on the graph: strikethrough = removed, underline = added. */
2678
- /* @__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: [
2679
- /* @__PURE__ */ jsx3("i", { style: { boxShadow: `0 0 0 2px ${DIFF_COLORS[k]}b0, 0 0 0 5px ${DIFF_COLORS[k]}40` } }),
2680
- /* @__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] }),
2681
- /* @__PURE__ */ jsx3("b", { children: p.delta.counts[k] })
2682
- ] }, k)) }),
2683
- /* @__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: () => {
2684
- onLook({});
2685
- p.onShowAll();
2686
- }, children: t.legendReset }) }),
2687
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 }) }) })
2688
3111
  ] });
3112
+ return /* @__PURE__ */ jsx3(LegendFrame, { collapsed: p.collapsed, children: content });
2689
3113
  }
2690
3114
 
2691
3115
  // src/react/DiffOverlay.tsx
@@ -3118,7 +3542,7 @@ function measureDiffGeom(cy, hidden) {
3118
3542
  function Drawer({ children }) {
3119
3543
  const last = useRef4(children);
3120
3544
  if (children) last.current = children;
3121
- const [gone, setGone] = useState4(!children);
3545
+ const [gone, setGone] = useState5(!children);
3122
3546
  const open = !!children;
3123
3547
  useEffect4(() => {
3124
3548
  if (open) {
@@ -3171,7 +3595,7 @@ function GraphCanvas(props) {
3171
3595
  emphasis: hostEmphasis = null,
3172
3596
  legend = true
3173
3597
  } = props;
3174
- const [innerLook, setInnerLook] = useState4(props.defaultLook ?? {});
3598
+ const [innerLook, setInnerLook] = useState5(props.defaultLook ?? {});
3175
3599
  const look = props.look ?? innerLook;
3176
3600
  const setLook = useCallback2((l) => {
3177
3601
  if (!props.look) setInnerLook(l);
@@ -3179,17 +3603,18 @@ function GraphCanvas(props) {
3179
3603
  }, [props.look, props.onLookChange]);
3180
3604
  const lookProfile = useMemo5(() => applyLook(baseProfile, look), [baseProfile, look]);
3181
3605
  const theme = useMemo5(() => look.skeleton ? { ...baseTheme, skeleton: look.skeleton } : baseTheme, [baseTheme, look.skeleton]);
3182
- const [legendEmphasis, setLegendEmphasis] = useState4(null);
3606
+ const rootStyle = useMemo5(() => ({ ...chromeStyle(theme), ...style }), [theme, style]);
3607
+ const [legendEmphasis, setLegendEmphasis] = useState5(null);
3183
3608
  const emphasis = legendEmphasis ?? hostEmphasis;
3184
- const [legendCollapsed, setLegendCollapsed] = useState4(false);
3609
+ const [legendCollapsed, setLegendCollapsed] = useState5(false);
3185
3610
  const stageRef = useRef4(null);
3186
3611
  useEffect4(() => {
3187
3612
  if ((stageRef.current?.clientWidth ?? 1e3) < 640) setLegendCollapsed(true);
3188
3613
  }, []);
3189
- const [liveCy, setLiveCy] = useState4(null);
3614
+ const [liveCy, setLiveCy] = useState5(null);
3190
3615
  const profile = useShapeOf(lookProfile);
3191
3616
  const strings = useMemo5(() => ({ ...EN, ...props.strings, error: { ...EN.error, ...props.strings?.error } }), [props.strings]);
3192
- const [innerView, setInnerView] = useState4({ ...FULL_VIEW, ...props.defaultView });
3617
+ const [innerView, setInnerView] = useState5({ ...FULL_VIEW, ...props.defaultView });
3193
3618
  const rawView = props.view ?? innerView;
3194
3619
  const setView = useCallback2((patch) => {
3195
3620
  const next = { ...props.view ?? innerView, ...patch };
@@ -3197,7 +3622,7 @@ function GraphCanvas(props) {
3197
3622
  props.onViewChange?.(next);
3198
3623
  }, [props.view, props.onViewChange, innerView]);
3199
3624
  const containerRef = useRef4(null);
3200
- const [layoutOwner] = useState4(() => ({}));
3625
+ const [layoutOwner] = useState5(() => ({}));
3201
3626
  const cyRef = useRef4(null);
3202
3627
  const mirrorRef = useRef4(null);
3203
3628
  const mirrorElRef = useRef4(null);
@@ -3207,11 +3632,11 @@ function GraphCanvas(props) {
3207
3632
  const runRef = useRef4(0);
3208
3633
  const platesRef = useRef4([]);
3209
3634
  const dispRef = useRef4({});
3210
- const [renderModel, setRenderModel] = useState4(model);
3635
+ const [renderModel, setRenderModel] = useState5(model);
3211
3636
  const prevModelRef = useRef4(null);
3212
3637
  const prevProfileRef = useRef4(null);
3213
- const [pastRenderModel, setPastRenderModel] = useState4(null);
3214
- const [renderWorld, setRenderWorld] = useState4(profile);
3638
+ const [pastRenderModel, setPastRenderModel] = useState5(null);
3639
+ const [renderWorld, setRenderWorld] = useState5(profile);
3215
3640
  if (renderWorld !== profile) {
3216
3641
  setRenderWorld(profile);
3217
3642
  setRenderModel(model);
@@ -3256,8 +3681,8 @@ function GraphCanvas(props) {
3256
3681
  const playPlanesRef = useRef4(null);
3257
3682
  const sightRef = useRef4("");
3258
3683
  const searchInputRef = useRef4(null);
3259
- const [selected, setSelected] = useState4(null);
3260
- const [editing, setEditing] = useState4(null);
3684
+ const [selected, setSelected] = useState5(null);
3685
+ const [editing, setEditing] = useState5(null);
3261
3686
  const editable = !!onEdit && !diff;
3262
3687
  const onEditRef = useRef4(onEdit);
3263
3688
  onEditRef.current = onEdit;
@@ -3265,13 +3690,13 @@ function GraphCanvas(props) {
3265
3690
  const keepSelRef = useRef4(null);
3266
3691
  const pickRef = useRef4(() => {
3267
3692
  });
3268
- const [prog, setProg] = useState4(null);
3269
- const [plates, setPlates] = useState4([]);
3270
- const [hotLayer, setHotLayer] = useState4(null);
3693
+ const [prog, setProg] = useState5(null);
3694
+ const [plates, setPlates] = useState5([]);
3695
+ const [hotLayer, setHotLayer] = useState5(null);
3271
3696
  const hotLayerRef = useRef4(null);
3272
- const [plateAlpha, setPlateAlpha] = useState4(0);
3697
+ const [plateAlpha, setPlateAlpha] = useState5(0);
3273
3698
  const plateAlphaRef = useRef4(0);
3274
- const [viewport, setViewport] = useState4({ zoom: 1, pan: { x: 0, y: 0 } });
3699
+ const [viewport, setViewport] = useState5({ zoom: 1, pan: { x: 0, y: 0 } });
3275
3700
  const built = useMemo5(
3276
3701
  () => buildElements(renderModel, profile),
3277
3702
  [renderModel, profile]
@@ -3373,7 +3798,7 @@ function GraphCanvas(props) {
3373
3798
  const missedRef = useRef4(false);
3374
3799
  const owedLayoutRef = useRef4(null);
3375
3800
  const flushOwedRef = useRef4(null);
3376
- const [resume, setResume] = useState4(0);
3801
+ const [resume, setResume] = useState5(0);
3377
3802
  const markBusy = useCallback2((v) => {
3378
3803
  if (busyRef.current === v) return;
3379
3804
  busyRef.current = v;
@@ -3461,8 +3886,8 @@ function GraphCanvas(props) {
3461
3886
  markBusy(true);
3462
3887
  setRenderModel(delta.model);
3463
3888
  }, [model, resume]);
3464
- const [diffGeom, setDiffGeom] = useState4(EMPTY_GEOM);
3465
- const [pastGeom, setPastGeom] = useState4(EMPTY_GEOM);
3889
+ const [diffGeom, setDiffGeom] = useState5(EMPTY_GEOM);
3890
+ const [pastGeom, setPastGeom] = useState5(EMPTY_GEOM);
3466
3891
  const visibleNodes = useCallback2((cy) => {
3467
3892
  const { visible } = resolvedRef.current;
3468
3893
  const left = leftRef.current;
@@ -3702,7 +4127,7 @@ function GraphCanvas(props) {
3702
4127
  const ele = cy.$id(id);
3703
4128
  if (ele.empty() || !ele.visible()) continue;
3704
4129
  const painter = painterRef.current;
3705
- const focused = ele.selected() || !!painter?.focused(id);
4130
+ const focused = ele.selected() || ele.hasClass("gb-preview-hop") || !!painter?.focused(id);
3706
4131
  const a = smoothstep(s.o) * ele.effectiveOpacity() * (focused ? 1 : LABEL_ALPHA * (painter?.dimOf(id) ?? 1));
3707
4132
  if (a < 0.02) continue;
3708
4133
  const p = ele.renderedPosition();
@@ -3796,10 +4221,10 @@ function GraphCanvas(props) {
3796
4221
  side: book.get(id)?.next ?? book.get(id)?.side,
3797
4222
  // The selected and the hovered one: name always shown. Search hits only get a bonus (see below): forcing hundreds of hits
3798
4223
  // would pile into a heap, the same problem as a large hovered cluster.
3799
- pinned: n.selected() || id === hovered
4224
+ pinned: n.selected() || id === hovered || n.hasClass("gb-preview")
3800
4225
  });
3801
4226
  const held = book.get(id);
3802
- 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);
3803
4228
  if (b) bias.set(id, b);
3804
4229
  });
3805
4230
  const plan = planLabels(inputs, { viewport: { w, h }, padding: labelSpacingRef.current, bias });
@@ -3873,6 +4298,25 @@ function GraphCanvas(props) {
3873
4298
  applyHover(cy, null);
3874
4299
  }, HOVER_OUT_MS);
3875
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]);
3876
4320
  const armBreath = useCallback2((cy) => {
3877
4321
  if (!readableRef.current || breathTimerRef.current != null) return;
3878
4322
  const tick = () => {
@@ -3980,10 +4424,18 @@ function GraphCanvas(props) {
3980
4424
  layer: d.layer,
3981
4425
  origin: d.origin,
3982
4426
  container: builtRef.current.containers.has(d.id),
3983
- 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)),
3984
4428
  detail: d.detail ?? null
3985
4429
  });
3986
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]);
3987
4439
  const cancelFrames = useCallback2(() => {
3988
4440
  const tw = tweenRef.current;
3989
4441
  if (tw) {
@@ -4571,9 +5023,9 @@ ${lt}`;
4571
5023
  cy.on("render", () => drawLabels(cy));
4572
5024
  let lastW = 0, lastH = 0;
4573
5025
  const refit = () => {
4574
- const el2 = containerRef.current;
4575
- if (!el2) return;
4576
- const w = el2.clientWidth, h = el2.clientHeight;
5026
+ const el = containerRef.current;
5027
+ if (!el) return;
5028
+ const w = el.clientWidth, h = el.clientHeight;
4577
5029
  if (w === 0 || h === 0 || w === lastW && h === lastH) return;
4578
5030
  const first = lastW === 0;
4579
5031
  lastW = w;
@@ -4592,11 +5044,6 @@ ${lt}`;
4592
5044
  };
4593
5045
  ro = new ResizeObserver(refit);
4594
5046
  ro.observe(containerRef.current);
4595
- cy.on("mouseover", "node, edge", (evt) => {
4596
- touchInteraction();
4597
- setHover(cy, evt.target);
4598
- });
4599
- cy.on("mouseout", "node, edge", () => setHover(cy, null));
4600
5047
  cy.on("select", "node", (evt) => {
4601
5048
  ringsRef.current.set(evt.target.id(), performance.now());
4602
5049
  runRing(cy);
@@ -4607,45 +5054,18 @@ ${lt}`;
4607
5054
  });
4608
5055
  cy.on("select unselect", "node", () => scheduleReadability(cy));
4609
5056
  cy.$id(VIRTUAL_ROOT).unselectify();
4610
- cy.on("tap", "node", (evt) => {
4611
- touchInteraction();
4612
- if (evt.target.id() === VIRTUAL_ROOT) setSelected(null);
4613
- else selectEle(evt.target);
4614
- });
4615
- cy.on("tap", (evt) => {
4616
- touchInteraction();
4617
- 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
+ }))
4618
5068
  });
4619
- cy.on("tapstart", () => cancelFly());
4620
- let lastTap = { id: "", t: 0 };
4621
- cy.on("tap", "node", (evt) => {
4622
- const id = evt.target.id();
4623
- const now = Date.now();
4624
- const isDouble = lastTap.id === id && now - lastTap.t < 350;
4625
- lastTap = { id, t: now };
4626
- if (!isDouble || id === VIRTUAL_ROOT) return;
4627
- requestAnimationFrame(() => requestAnimationFrame(() => flyToRef.current(id, true)));
4628
- });
4629
- const el = containerRef.current;
4630
- const onWheel = (e) => {
4631
- e.preventDefault();
4632
- touchInteraction();
4633
- cancelFly();
4634
- if (e.ctrlKey || e.metaKey) {
4635
- const rect = el.getBoundingClientRect();
4636
- cy.zoom({
4637
- level: cy.zoom() * Math.exp(-e.deltaY * 0.01),
4638
- renderedPosition: { x: e.clientX - rect.left, y: e.clientY - rect.top }
4639
- });
4640
- } else cy.panBy({ x: -e.deltaX, y: -e.deltaY });
4641
- };
4642
- el.addEventListener("wheel", onWheel, { passive: false });
4643
- const onLeave = () => setHover(cy, null);
4644
- el.addEventListener("mouseleave", onLeave);
4645
- detach = () => {
4646
- el.removeEventListener("wheel", onWheel);
4647
- el.removeEventListener("mouseleave", onLeave);
4648
- };
4649
5069
  cy.on("viewport", () => {
4650
5070
  if (plateAlphaRef.current > 0 || diffRef.current) setViewport({ zoom: cy.zoom(), pan: { ...cy.pan() } });
4651
5071
  const m = mirrorRef.current;
@@ -4722,12 +5142,12 @@ ${lt}`;
4722
5142
  seatFromLastFrame(m, dispRef.current, (q2) => pastBuilt.parentOf.get(q2));
4723
5143
  mirrorRef.current = m;
4724
5144
  m.$id(VIRTUAL_ROOT).unselectify();
4725
- m.on("tap", "node", (evt) => {
4726
- if (evt.target.id() === VIRTUAL_ROOT) setSelected(null);
4727
- else selectEle(evt.target);
4728
- });
4729
- m.on("tap", (evt) => {
4730
- 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)
4731
5151
  });
4732
5152
  m.on("viewport", () => {
4733
5153
  const cy2 = cyRef.current;
@@ -4737,15 +5157,6 @@ ${lt}`;
4737
5157
  syncingRef.current = false;
4738
5158
  });
4739
5159
  const el = mirrorElRef.current;
4740
- const onWheel = (e) => {
4741
- e.preventDefault();
4742
- if (e.ctrlKey || e.metaKey) {
4743
- const rect = el.getBoundingClientRect();
4744
- m.zoom({ level: m.zoom() * Math.exp(-e.deltaY * 0.01), renderedPosition: { x: e.clientX - rect.left, y: e.clientY - rect.top } });
4745
- } else m.panBy({ x: -e.deltaX, y: -e.deltaY });
4746
- };
4747
- el.addEventListener("wheel", onWheel, { passive: false });
4748
- detach = () => el.removeEventListener("wheel", onWheel);
4749
5160
  ro = new ResizeObserver(() => {
4750
5161
  if (!m.destroyed()) {
4751
5162
  m.resize();
@@ -4996,7 +5407,7 @@ ${lt}`;
4996
5407
  return () => window.removeEventListener("keydown", onKey);
4997
5408
  }, [compact, zoomBy, fit]);
4998
5409
  if (model.nodes.length === 0 && model.errors.length === 0) {
4999
- return /* @__PURE__ */ jsx5(StringsContext.Provider, { value: strings, children: /* @__PURE__ */ jsxs5("div", { className: `gb-root ${className ?? ""}`, style, children: [
5410
+ return /* @__PURE__ */ jsx5(StringsContext.Provider, { value: strings, children: /* @__PURE__ */ jsxs5("div", { className: `gb-root ${className ?? ""}`, style: rootStyle, children: [
5000
5411
  /* @__PURE__ */ jsxs5("div", { className: "gb-empty", children: [
5001
5412
  /* @__PURE__ */ jsx5("div", { children: emptyMessage ?? strings.empty }),
5002
5413
  editable && !editing && /* @__PURE__ */ jsx5("button", { className: "gb-link", onClick: () => startAdd("node"), children: strings.addNode })
@@ -5007,7 +5418,7 @@ ${lt}`;
5007
5418
  const filtering = isFiltering(view);
5008
5419
  const panes = !!diff;
5009
5420
  const platesOn = !panes && plates.length > 0 && plateAlpha > 0.01;
5010
- return /* @__PURE__ */ jsx5(StringsContext.Provider, { value: strings, children: /* @__PURE__ */ jsxs5("div", { className: `gb-root ${className ?? ""}`, style, children: [
5421
+ return /* @__PURE__ */ jsx5(StringsContext.Provider, { value: strings, children: /* @__PURE__ */ jsxs5("div", { className: `gb-root ${className ?? ""}`, style: rootStyle, children: [
5011
5422
  /* @__PURE__ */ jsxs5("div", { className: "gb-stage", ref: stageRef, style: { background: theme.canvas }, children: [
5012
5423
  platesOn && /* @__PURE__ */ jsx5("svg", { className: "gb-planes", style: { opacity: plateAlpha }, children: /* @__PURE__ */ jsx5("g", { transform: `translate(${viewport.pan.x},${viewport.pan.y}) scale(${viewport.zoom})`, children: plates.map((p) => {
5013
5424
  const c = plateColors(theme, p.color);
@@ -5121,7 +5532,7 @@ ${lt}`;
5121
5532
  model.errors.slice(0, 2).map((e) => e.origin).join(", ") + (model.errors.length > 2 ? ", \u2026" : "")
5122
5533
  ) })
5123
5534
  ] }),
5124
- legend && !compact && /* @__PURE__ */ jsx5("div", { className: `gb-legend${legendCollapsed ? " is-collapsed" : ""}`, children: /* @__PURE__ */ jsx5(
5535
+ legend && !compact && /* @__PURE__ */ jsx5(
5125
5536
  Legend,
5126
5537
  {
5127
5538
  model,
@@ -5143,7 +5554,7 @@ ${lt}`;
5143
5554
  onCollapsed: setLegendCollapsed,
5144
5555
  caption: note
5145
5556
  }
5146
- ) })
5557
+ )
5147
5558
  ] }),
5148
5559
  !compact && /* @__PURE__ */ jsx5(
5149
5560
  ZoomDock,
@@ -5219,7 +5630,9 @@ export {
5219
5630
  labelBox,
5220
5631
  planLabels,
5221
5632
  idPhase,
5633
+ placePanel,
5222
5634
  ALL_CONTROLS,
5635
+ touchGestures,
5223
5636
  applyLook,
5224
5637
  DiffOverlay,
5225
5638
  GraphCanvas