dsh-talk-map 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/client/client.js +478 -410
  2. package/package.json +1 -1
package/client/client.js CHANGED
@@ -10844,275 +10844,6 @@ function pickFaces(from, to, obstacles, options) {
10844
10844
  return { fromHandle: fromSide, toHandle: toSide };
10845
10845
  }
10846
10846
 
10847
- // src/client/edge-route.ts
10848
- var DEFAULTS = { margin: 10, stub: 14, minCorridor: 28 };
10849
- function anchorOf(rect, face) {
10850
- switch (face) {
10851
- case "r":
10852
- return { x: rect.x + rect.w, y: rect.y + rect.h / 2 };
10853
- case "l":
10854
- return { x: rect.x, y: rect.y + rect.h / 2 };
10855
- case "t":
10856
- return { x: rect.x + rect.w / 2, y: rect.y };
10857
- default:
10858
- return { x: rect.x + rect.w / 2, y: rect.y + rect.h };
10859
- }
10860
- }
10861
- function normalOf(face) {
10862
- switch (face) {
10863
- case "r":
10864
- return { x: 1, y: 0 };
10865
- case "l":
10866
- return { x: -1, y: 0 };
10867
- case "t":
10868
- return { x: 0, y: -1 };
10869
- default:
10870
- return { x: 0, y: 1 };
10871
- }
10872
- }
10873
- function expand(rect, by) {
10874
- return { x: rect.x - by, y: rect.y - by, w: rect.w + by * 2, h: rect.h + by * 2 };
10875
- }
10876
- function insideStrict(rect, point) {
10877
- return point.x > rect.x && point.x < rect.x + rect.w && point.y > rect.y && point.y < rect.y + rect.h;
10878
- }
10879
- function hitsHorizontal(rects, y, x1, x2) {
10880
- const lo = Math.min(x1, x2);
10881
- const hi = Math.max(x1, x2);
10882
- for (const rect of rects) {
10883
- if (y <= rect.y || y >= rect.y + rect.h) continue;
10884
- if (hi <= rect.x || lo >= rect.x + rect.w) continue;
10885
- return true;
10886
- }
10887
- return false;
10888
- }
10889
- function hitsVertical(rects, x, y1, y2) {
10890
- const lo = Math.min(y1, y2);
10891
- const hi = Math.max(y1, y2);
10892
- for (const rect of rects) {
10893
- if (x <= rect.x || x >= rect.x + rect.w) continue;
10894
- if (hi <= rect.y || lo >= rect.y + rect.h) continue;
10895
- return true;
10896
- }
10897
- return false;
10898
- }
10899
- function bands(rects, axis) {
10900
- const spans = rects.map((rect) => axis === "x" ? { start: rect.x, end: rect.x + rect.w } : { start: rect.y, end: rect.y + rect.h }).sort((a, b) => a.start - b.start);
10901
- const out = [];
10902
- for (const span of spans) {
10903
- const last = out[out.length - 1];
10904
- if (last !== void 0 && span.start <= last.end) {
10905
- last.end = Math.max(last.end, span.end);
10906
- } else {
10907
- out.push({ ...span });
10908
- }
10909
- }
10910
- return out;
10911
- }
10912
- function corridors(rects, axis, minCorridor) {
10913
- const merged = bands(rects, axis);
10914
- const out = [];
10915
- for (let index2 = 1; index2 < merged.length; index2 += 1) {
10916
- const gap = merged[index2].start - merged[index2 - 1].end;
10917
- if (gap >= minCorridor) out.push((merged[index2 - 1].end + merged[index2].start) / 2);
10918
- }
10919
- return out;
10920
- }
10921
- function outerLines(rects, axis, clearance) {
10922
- const merged = bands(rects, axis);
10923
- const out = [];
10924
- for (const band of merged) {
10925
- out.push(band.start - clearance, band.end + clearance);
10926
- }
10927
- return out;
10928
- }
10929
- var Heap = class {
10930
- items = [];
10931
- push(cost, key, node) {
10932
- this.items.push({ cost, key, node });
10933
- let index2 = this.items.length - 1;
10934
- while (index2 > 0) {
10935
- const parent = index2 - 1 >> 1;
10936
- if (this.items[parent].cost <= this.items[index2].cost) break;
10937
- const tmp = this.items[parent];
10938
- this.items[parent] = this.items[index2];
10939
- this.items[index2] = tmp;
10940
- index2 = parent;
10941
- }
10942
- }
10943
- pop() {
10944
- if (this.items.length === 0) return void 0;
10945
- const top = this.items[0];
10946
- const last = this.items.pop();
10947
- if (this.items.length > 0) {
10948
- this.items[0] = last;
10949
- let index2 = 0;
10950
- for (; ; ) {
10951
- const left = index2 * 2 + 1;
10952
- const right = left + 1;
10953
- let smallest = index2;
10954
- if (left < this.items.length && this.items[left].cost < this.items[smallest].cost) smallest = left;
10955
- if (right < this.items.length && this.items[right].cost < this.items[smallest].cost) smallest = right;
10956
- if (smallest === index2) break;
10957
- const tmp = this.items[smallest];
10958
- this.items[smallest] = this.items[index2];
10959
- this.items[index2] = tmp;
10960
- index2 = smallest;
10961
- }
10962
- }
10963
- return { key: top.key, node: top.node };
10964
- }
10965
- get size() {
10966
- return this.items.length;
10967
- }
10968
- };
10969
- function dedupe(values, epsilon = 0.5) {
10970
- const sorted = [...values].sort((a, b) => a - b);
10971
- const out = [];
10972
- for (const value of sorted) {
10973
- if (out.length === 0 || Math.abs(value - out[out.length - 1]) > epsilon) out.push(value);
10974
- }
10975
- return out;
10976
- }
10977
- function simplify(points) {
10978
- const out = [];
10979
- for (const point of points) {
10980
- const last = out[out.length - 1];
10981
- if (last !== void 0 && Math.abs(last.x - point.x) < 0.5 && Math.abs(last.y - point.y) < 0.5) continue;
10982
- out.push(point);
10983
- }
10984
- for (let index2 = 1; index2 < out.length - 1; ) {
10985
- const a = out[index2 - 1];
10986
- const b = out[index2];
10987
- const c = out[index2 + 1];
10988
- const collinear = Math.abs(a.x - b.x) < 0.5 && Math.abs(b.x - c.x) < 0.5 || Math.abs(a.y - b.y) < 0.5 && Math.abs(b.y - c.y) < 0.5;
10989
- if (collinear) out.splice(index2, 1);
10990
- else index2 += 1;
10991
- }
10992
- return out;
10993
- }
10994
- function routeEdge(from, to, fromFace, toFace, obstacles, options = {}) {
10995
- const margin = options.margin ?? DEFAULTS.margin;
10996
- const stub = options.stub ?? DEFAULTS.stub;
10997
- const minCorridor = options.minCorridor ?? DEFAULTS.minCorridor;
10998
- const start2 = anchorOf(from, fromFace);
10999
- const end = anchorOf(to, toFace);
11000
- const startNormal = normalOf(fromFace);
11001
- const endNormal = normalOf(toFace);
11002
- const startStub = { x: start2.x + startNormal.x * stub, y: start2.y + startNormal.y * stub };
11003
- const endStub = { x: end.x + endNormal.x * stub, y: end.y + endNormal.y * stub };
11004
- const blocked = obstacles.filter((rect) => rect !== from && rect !== to).map((rect) => expand(rect, margin));
11005
- const fallback = simplify([start2, startStub, { x: endStub.x, y: startStub.y }, endStub, end]);
11006
- const xs = corridors(obstacles, "x", minCorridor);
11007
- const ys = corridors(obstacles, "y", minCorridor);
11008
- const xOuter = outerLines(obstacles, "x", margin + 6);
11009
- const yOuter = outerLines(obstacles, "y", margin + 6);
11010
- const xCands = dedupe([start2.x, end.x, startStub.x, endStub.x, ...xs, ...xOuter]);
11011
- const yCands = dedupe([start2.y, end.y, startStub.y, endStub.y, ...ys, ...yOuter]);
11012
- if (xCands.length > 60 || yCands.length > 60) return fallback;
11013
- const corridorX = new Set(xs.map((value) => Math.round(value)));
11014
- const corridorY = new Set(ys.map((value) => Math.round(value)));
11015
- const nodeId = (ix, iy) => `${ix},${iy}`;
11016
- const pointAt = (id2) => {
11017
- const [ix, iy] = id2.split(",").map(Number);
11018
- return { x: xCands[ix], y: yCands[iy] };
11019
- };
11020
- const startIndex = { x: xCands.findIndex((value) => Math.abs(value - startStub.x) < 0.5), y: yCands.findIndex((value) => Math.abs(value - startStub.y) < 0.5) };
11021
- const endIndex = { x: xCands.findIndex((value) => Math.abs(value - endStub.x) < 0.5), y: yCands.findIndex((value) => Math.abs(value - endStub.y) < 0.5) };
11022
- if (startIndex.x < 0 || startIndex.y < 0 || endIndex.x < 0 || endIndex.y < 0) return fallback;
11023
- const goal = { x: endStub.x, y: endStub.y };
11024
- const startNode = nodeId(startIndex.x, startIndex.y);
11025
- const goalNode = nodeId(endIndex.x, endIndex.y);
11026
- const best = /* @__PURE__ */ new Map();
11027
- const cameFrom = /* @__PURE__ */ new Map();
11028
- const heap = new Heap();
11029
- const withDir = (node, dir) => `${node}|${dir}`;
11030
- best.set(withDir(startNode, "x"), 0);
11031
- heap.push(0, 0, withDir(startNode, "x"));
11032
- const estimate = (point) => Math.abs(point.x - goal.x) + Math.abs(point.y - goal.y);
11033
- while (heap.size > 0) {
11034
- const popped = heap.pop();
11035
- const state3 = popped.node;
11036
- const [node, dir] = state3.split("|");
11037
- const cost = best.get(state3);
11038
- if (cost === void 0) continue;
11039
- if (node === goalNode) {
11040
- const path = [];
11041
- let cursor = state3;
11042
- while (cursor !== void 0) {
11043
- const [cell] = cursor.split("|");
11044
- path.push(pointAt(cell));
11045
- cursor = cameFrom.get(cursor);
11046
- }
11047
- path.reverse();
11048
- return simplify([start2, startStub, ...path.slice(1), endStub, end]);
11049
- }
11050
- const [ix, iy] = node.split(",").map(Number);
11051
- const here = pointAt(node);
11052
- const steps = [
11053
- { dx: 1, dy: 0, axis: "x" },
11054
- { dx: -1, dy: 0, axis: "x" },
11055
- { dx: 0, dy: 1, axis: "y" },
11056
- { dx: 0, dy: -1, axis: "y" }
11057
- ];
11058
- for (const step2 of steps) {
11059
- const nx = ix + step2.dx;
11060
- const ny = iy + step2.dy;
11061
- if (nx < 0 || ny < 0 || nx >= xCands.length || ny >= yCands.length) continue;
11062
- const next = { x: xCands[nx], y: yCands[ny] };
11063
- const nextNode = nodeId(nx, ny);
11064
- if (nextNode !== goalNode && blocked.some((rect) => insideStrict(rect, next))) continue;
11065
- const clear = step2.axis === "x" ? !hitsHorizontal(blocked, here.y, here.x, next.x) : !hitsVertical(blocked, here.x, here.y, next.y);
11066
- if (!clear) continue;
11067
- const distance2 = Math.abs(next.x - here.x) + Math.abs(next.y - here.y);
11068
- const onCorridor = step2.axis === "x" ? corridorY.has(Math.round(here.y)) : corridorX.has(Math.round(here.x));
11069
- const turn = dir === step2.axis ? 0 : 18;
11070
- const prefer = onCorridor ? 0 : 6;
11071
- const nextCost = cost + distance2 + turn + prefer;
11072
- const nextState = withDir(nextNode, step2.axis);
11073
- const known = best.get(nextState);
11074
- if (known !== void 0 && known <= nextCost) continue;
11075
- best.set(nextState, nextCost);
11076
- cameFrom.set(nextState, state3);
11077
- heap.push(nextCost + estimate(next), nextCost, nextState);
11078
- }
11079
- }
11080
- return fallback;
11081
- }
11082
- function roundedPath(points, radius = 10) {
11083
- if (points.length === 0) return "";
11084
- if (points.length === 1) return `M ${round(points[0].x)} ${round(points[0].y)}`;
11085
- const parts = [`M ${round(points[0].x)} ${round(points[0].y)}`];
11086
- for (let index2 = 1; index2 < points.length - 1; index2 += 1) {
11087
- const prev = points[index2 - 1];
11088
- const here = points[index2];
11089
- const next = points[index2 + 1];
11090
- const inLength = Math.hypot(here.x - prev.x, here.y - prev.y);
11091
- const outLength = Math.hypot(next.x - here.x, next.y - here.y);
11092
- const corner = Math.min(radius, inLength / 2, outLength / 2);
11093
- if (corner < 0.5) {
11094
- parts.push(`L ${round(here.x)} ${round(here.y)}`);
11095
- continue;
11096
- }
11097
- const enter = {
11098
- x: here.x + (prev.x - here.x) / (inLength || 1) * corner,
11099
- y: here.y + (prev.y - here.y) / (inLength || 1) * corner
11100
- };
11101
- const leave = {
11102
- x: here.x + (next.x - here.x) / (outLength || 1) * corner,
11103
- y: here.y + (next.y - here.y) / (outLength || 1) * corner
11104
- };
11105
- parts.push(`L ${round(enter.x)} ${round(enter.y)}`);
11106
- parts.push(`Q ${round(here.x)} ${round(here.y)} ${round(leave.x)} ${round(leave.y)}`);
11107
- }
11108
- const last = points[points.length - 1];
11109
- parts.push(`L ${round(last.x)} ${round(last.y)}`);
11110
- return parts.join(" ");
11111
- }
11112
- function round(value) {
11113
- return Math.round(value * 100) / 100;
11114
- }
11115
-
11116
10847
  // src/client/push-log.ts
11117
10848
  var KEY = "dsh.talk-map.push-log.v1";
11118
10849
  function pairKey(fromCardId, toCardId) {
@@ -11878,133 +11609,466 @@ var PATHS = {
11878
11609
  function MenuIcon(props) {
11879
11610
  return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("svg", { className: talk_map_default["menuIcon"], viewBox: "0 0 24 24", width: "14", height: "14", "aria-hidden": "true", children: PATHS[props.name] });
11880
11611
  }
11881
-
11882
- // src/client/ContextMenu.tsx
11883
- var import_jsx_runtime7 = require("react/jsx-runtime");
11884
- function ContextMenu(props) {
11885
- const { menu } = props;
11886
- const [query, setQuery] = (0, import_react5.useState)("");
11887
- const [busy, setBusy] = (0, import_react5.useState)(false);
11888
- const [error, setError] = (0, import_react5.useState)(void 0);
11889
- const inputRef = (0, import_react5.useRef)(null);
11890
- const submitPrompt = async () => {
11891
- const prompt = menu.prompt;
11892
- if (prompt === void 0 || busy || query.trim() === "") return;
11893
- setBusy(true);
11894
- setError(void 0);
11895
- try {
11896
- await prompt.onSubmit(query.trim());
11897
- } catch (submitError) {
11898
- setError(String(submitError));
11899
- setBusy(false);
11612
+
11613
+ // src/client/ContextMenu.tsx
11614
+ var import_jsx_runtime7 = require("react/jsx-runtime");
11615
+ function ContextMenu(props) {
11616
+ const { menu } = props;
11617
+ const [query, setQuery] = (0, import_react5.useState)("");
11618
+ const [busy, setBusy] = (0, import_react5.useState)(false);
11619
+ const [error, setError] = (0, import_react5.useState)(void 0);
11620
+ const inputRef = (0, import_react5.useRef)(null);
11621
+ const submitPrompt = async () => {
11622
+ const prompt = menu.prompt;
11623
+ if (prompt === void 0 || busy || query.trim() === "") return;
11624
+ setBusy(true);
11625
+ setError(void 0);
11626
+ try {
11627
+ await prompt.onSubmit(query.trim());
11628
+ } catch (submitError) {
11629
+ setError(String(submitError));
11630
+ setBusy(false);
11631
+ }
11632
+ };
11633
+ (0, import_react5.useEffect)(() => {
11634
+ const release = mapUi.claimEscape("context-menu");
11635
+ const onKeyDown = (event) => {
11636
+ if (event.key === "Escape") {
11637
+ event.stopPropagation();
11638
+ props.onClose();
11639
+ }
11640
+ };
11641
+ window.addEventListener("keydown", onKeyDown);
11642
+ return () => {
11643
+ window.removeEventListener("keydown", onKeyDown);
11644
+ release();
11645
+ };
11646
+ }, []);
11647
+ (0, import_react5.useEffect)(() => {
11648
+ if (menu.searchable === true || menu.prompt !== void 0) inputRef.current?.focus();
11649
+ }, [menu.searchable, menu.prompt]);
11650
+ const normalized = query.trim().toLowerCase();
11651
+ const visible = normalized === "" ? menu.items : menu.items.filter((item) => item.label.toLowerCase().includes(normalized));
11652
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
11653
+ "div",
11654
+ {
11655
+ className: talk_map_default["menu"],
11656
+ style: { left: menu.left, top: menu.top },
11657
+ role: "menu",
11658
+ onClick: (event) => {
11659
+ event.stopPropagation();
11660
+ },
11661
+ onPointerDown: (event) => {
11662
+ event.stopPropagation();
11663
+ },
11664
+ onContextMenu: (event) => {
11665
+ event.preventDefault();
11666
+ },
11667
+ children: [
11668
+ menu.title !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: talk_map_default["menuTitle"], children: menu.title }) : null,
11669
+ menu.prompt !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
11670
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
11671
+ "input",
11672
+ {
11673
+ ref: inputRef,
11674
+ className: talk_map_default["menuSearch"],
11675
+ placeholder: menu.prompt.placeholder,
11676
+ value: query,
11677
+ onChange: (event) => {
11678
+ setQuery(event.target.value);
11679
+ },
11680
+ onKeyDown: (event) => {
11681
+ if (event.key === "Enter") {
11682
+ event.preventDefault();
11683
+ void submitPrompt();
11684
+ }
11685
+ }
11686
+ }
11687
+ ),
11688
+ menu.prompt.preview !== void 0 && query.trim() !== "" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: talk_map_default["menuPreview"], children: menu.prompt.preview(query.trim()) }) : null,
11689
+ error !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: talk_map_default["menuError"], children: error }) : null,
11690
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
11691
+ "button",
11692
+ {
11693
+ type: "button",
11694
+ className: talk_map_default["menuItem"],
11695
+ disabled: busy || query.trim() === "",
11696
+ onClick: () => {
11697
+ void submitPrompt();
11698
+ },
11699
+ children: busy ? t("menu.working") : menu.prompt.submitLabel
11700
+ }
11701
+ )
11702
+ ] }) : null,
11703
+ menu.searchable === true ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
11704
+ "input",
11705
+ {
11706
+ ref: inputRef,
11707
+ className: talk_map_default["menuSearch"],
11708
+ placeholder: t("menu.search"),
11709
+ value: query,
11710
+ onChange: (event) => {
11711
+ setQuery(event.target.value);
11712
+ }
11713
+ }
11714
+ ) : null,
11715
+ menu.prompt !== void 0 ? null : visible.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: talk_map_default["menuEmpty"], children: t("menu.empty") }) : visible.map((item) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
11716
+ "button",
11717
+ {
11718
+ type: "button",
11719
+ role: "menuitem",
11720
+ className: `${talk_map_default["menuItem"]}${item.danger === true ? ` ${talk_map_default["menuItemDanger"] ?? ""}` : ""}`,
11721
+ disabled: item.disabled === true,
11722
+ onClick: () => {
11723
+ item.onPick();
11724
+ },
11725
+ children: [
11726
+ item.icon !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MenuIcon, { name: item.icon }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: talk_map_default["menuIcon"] }),
11727
+ item.label,
11728
+ item.hint !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: talk_map_default["menuHint"], children: [
11729
+ " ",
11730
+ item.hint
11731
+ ] }) : null
11732
+ ]
11733
+ },
11734
+ item.key
11735
+ ))
11736
+ ]
11737
+ }
11738
+ );
11739
+ }
11740
+
11741
+ // src/client/edge-route.ts
11742
+ var DEFAULTS = { margin: 14, stub: 14, minCorridor: 28 };
11743
+ function anchorOf(rect, face) {
11744
+ switch (face) {
11745
+ case "r":
11746
+ return { x: rect.x + rect.w, y: rect.y + rect.h / 2 };
11747
+ case "l":
11748
+ return { x: rect.x, y: rect.y + rect.h / 2 };
11749
+ case "t":
11750
+ return { x: rect.x + rect.w / 2, y: rect.y };
11751
+ default:
11752
+ return { x: rect.x + rect.w / 2, y: rect.y + rect.h };
11753
+ }
11754
+ }
11755
+ function normalOf(face) {
11756
+ switch (face) {
11757
+ case "r":
11758
+ return { x: 1, y: 0 };
11759
+ case "l":
11760
+ return { x: -1, y: 0 };
11761
+ case "t":
11762
+ return { x: 0, y: -1 };
11763
+ default:
11764
+ return { x: 0, y: 1 };
11765
+ }
11766
+ }
11767
+ function expand(rect, by) {
11768
+ return { x: rect.x - by, y: rect.y - by, w: rect.w + by * 2, h: rect.h + by * 2 };
11769
+ }
11770
+ function insideStrict(rect, point) {
11771
+ return point.x > rect.x && point.x < rect.x + rect.w && point.y > rect.y && point.y < rect.y + rect.h;
11772
+ }
11773
+ function hitsHorizontal(rects, y, x1, x2) {
11774
+ const lo = Math.min(x1, x2);
11775
+ const hi = Math.max(x1, x2);
11776
+ for (const rect of rects) {
11777
+ if (y <= rect.y || y >= rect.y + rect.h) continue;
11778
+ if (hi <= rect.x || lo >= rect.x + rect.w) continue;
11779
+ return true;
11780
+ }
11781
+ return false;
11782
+ }
11783
+ function hitsVertical(rects, x, y1, y2) {
11784
+ const lo = Math.min(y1, y2);
11785
+ const hi = Math.max(y1, y2);
11786
+ for (const rect of rects) {
11787
+ if (x <= rect.x || x >= rect.x + rect.w) continue;
11788
+ if (hi <= rect.y || lo >= rect.y + rect.h) continue;
11789
+ return true;
11790
+ }
11791
+ return false;
11792
+ }
11793
+ function bands(rects, axis) {
11794
+ const spans = rects.map((rect) => axis === "x" ? { start: rect.x, end: rect.x + rect.w } : { start: rect.y, end: rect.y + rect.h }).sort((a, b) => a.start - b.start);
11795
+ const out = [];
11796
+ for (const span of spans) {
11797
+ const last = out[out.length - 1];
11798
+ if (last !== void 0 && span.start <= last.end) {
11799
+ last.end = Math.max(last.end, span.end);
11800
+ } else {
11801
+ out.push({ ...span });
11802
+ }
11803
+ }
11804
+ return out;
11805
+ }
11806
+ function corridors(rects, axis, minCorridor) {
11807
+ const merged = bands(rects, axis);
11808
+ const out = [];
11809
+ for (let index2 = 1; index2 < merged.length; index2 += 1) {
11810
+ const gap = merged[index2].start - merged[index2 - 1].end;
11811
+ if (gap >= minCorridor) out.push((merged[index2 - 1].end + merged[index2].start) / 2);
11812
+ }
11813
+ return out;
11814
+ }
11815
+ function outerLines(rects, axis, clearance) {
11816
+ const merged = bands(rects, axis);
11817
+ const out = [];
11818
+ for (const band of merged) {
11819
+ out.push(band.start - clearance, band.end + clearance);
11820
+ }
11821
+ return out;
11822
+ }
11823
+ var Heap = class {
11824
+ items = [];
11825
+ push(cost, key, node) {
11826
+ this.items.push({ cost, key, node });
11827
+ let index2 = this.items.length - 1;
11828
+ while (index2 > 0) {
11829
+ const parent = index2 - 1 >> 1;
11830
+ if (this.items[parent].cost <= this.items[index2].cost) break;
11831
+ const tmp = this.items[parent];
11832
+ this.items[parent] = this.items[index2];
11833
+ this.items[index2] = tmp;
11834
+ index2 = parent;
11835
+ }
11836
+ }
11837
+ pop() {
11838
+ if (this.items.length === 0) return void 0;
11839
+ const top = this.items[0];
11840
+ const last = this.items.pop();
11841
+ if (this.items.length > 0) {
11842
+ this.items[0] = last;
11843
+ let index2 = 0;
11844
+ for (; ; ) {
11845
+ const left = index2 * 2 + 1;
11846
+ const right = left + 1;
11847
+ let smallest = index2;
11848
+ if (left < this.items.length && this.items[left].cost < this.items[smallest].cost) smallest = left;
11849
+ if (right < this.items.length && this.items[right].cost < this.items[smallest].cost) smallest = right;
11850
+ if (smallest === index2) break;
11851
+ const tmp = this.items[smallest];
11852
+ this.items[smallest] = this.items[index2];
11853
+ this.items[index2] = tmp;
11854
+ index2 = smallest;
11855
+ }
11856
+ }
11857
+ return { key: top.key, node: top.node };
11858
+ }
11859
+ get size() {
11860
+ return this.items.length;
11861
+ }
11862
+ };
11863
+ function dedupe(values, epsilon = 0.5) {
11864
+ const sorted = [...values].sort((a, b) => a - b);
11865
+ const out = [];
11866
+ for (const value of sorted) {
11867
+ if (out.length === 0 || Math.abs(value - out[out.length - 1]) > epsilon) out.push(value);
11868
+ }
11869
+ return out;
11870
+ }
11871
+ function simplify(points) {
11872
+ const out = [];
11873
+ for (const point of points) {
11874
+ const last = out[out.length - 1];
11875
+ if (last !== void 0 && Math.abs(last.x - point.x) < 0.5 && Math.abs(last.y - point.y) < 0.5) continue;
11876
+ out.push(point);
11877
+ }
11878
+ for (let index2 = 1; index2 < out.length - 1; ) {
11879
+ const a = out[index2 - 1];
11880
+ const b = out[index2];
11881
+ const c = out[index2 + 1];
11882
+ const collinear = Math.abs(a.x - b.x) < 0.5 && Math.abs(b.x - c.x) < 0.5 || Math.abs(a.y - b.y) < 0.5 && Math.abs(b.y - c.y) < 0.5;
11883
+ if (collinear) out.splice(index2, 1);
11884
+ else index2 += 1;
11885
+ }
11886
+ return out;
11887
+ }
11888
+ function routeEdge(from, to, fromFace, toFace, obstacles, options = {}) {
11889
+ return routeBetween(
11890
+ { start: anchorOf(from, fromFace), startFace: fromFace, end: anchorOf(to, toFace), endFace: toFace },
11891
+ from,
11892
+ to,
11893
+ obstacles,
11894
+ options
11895
+ );
11896
+ }
11897
+ function snapToChannels(points, obstacles, margin) {
11898
+ if (points.length < 3) return points;
11899
+ const out = points.map((point) => ({ ...point }));
11900
+ const rowBands = bands(obstacles, "y");
11901
+ const colBands = bands(obstacles, "x");
11902
+ const channelFor = (value, bandsList) => {
11903
+ for (let index2 = 1; index2 < bandsList.length; index2 += 1) {
11904
+ const lo = bandsList[index2 - 1].end;
11905
+ const hi = bandsList[index2].start;
11906
+ if (hi - lo < margin * 2 + 8) continue;
11907
+ if (value > lo && value < hi) return (lo + hi) / 2;
11900
11908
  }
11909
+ return void 0;
11901
11910
  };
11902
- (0, import_react5.useEffect)(() => {
11903
- const release = mapUi.claimEscape("context-menu");
11904
- const onKeyDown = (event) => {
11905
- if (event.key === "Escape") {
11906
- event.stopPropagation();
11907
- props.onClose();
11911
+ const last = out.length - 1;
11912
+ const horizontalSegment = (index2) => Math.abs(out[index2 - 1].y - out[index2].y) < 0.6;
11913
+ const fromStubHorizontal = horizontalSegment(1);
11914
+ const toStubHorizontal = horizontalSegment(last);
11915
+ for (let index2 = 1; index2 < last; index2 += 1) {
11916
+ const a = out[index2 - 1];
11917
+ const b = out[index2];
11918
+ const horizontalRun = Math.abs(a.y - b.y) < 0.6;
11919
+ if (index2 === 1 && horizontalRun === fromStubHorizontal) continue;
11920
+ if (index2 === last - 1 && horizontalRun === toStubHorizontal) continue;
11921
+ if (horizontalRun) {
11922
+ const centre = channelFor(a.y, rowBands);
11923
+ if (centre !== void 0 && Math.abs(centre - a.y) > 0.6) {
11924
+ a.y = centre;
11925
+ b.y = centre;
11926
+ }
11927
+ } else {
11928
+ const centre = channelFor(a.x, colBands);
11929
+ if (centre !== void 0 && Math.abs(centre - a.x) > 0.6) {
11930
+ a.x = centre;
11931
+ b.x = centre;
11932
+ }
11933
+ }
11934
+ }
11935
+ return simplify(out);
11936
+ }
11937
+ function routeBetween(ends, from, to, obstacles, options = {}) {
11938
+ const margin = options.margin ?? DEFAULTS.margin;
11939
+ const stub = options.stub ?? DEFAULTS.stub;
11940
+ const minCorridor = options.minCorridor ?? DEFAULTS.minCorridor;
11941
+ const start2 = ends.start;
11942
+ const end = ends.end;
11943
+ const startNormal = normalOf(ends.startFace);
11944
+ const endNormal = normalOf(ends.endFace);
11945
+ const startStub = { x: start2.x + startNormal.x * stub, y: start2.y + startNormal.y * stub };
11946
+ const endStub = { x: end.x + endNormal.x * stub, y: end.y + endNormal.y * stub };
11947
+ const sameRect = (a, b) => Math.abs(a.x - b.x) < 0.5 && Math.abs(a.y - b.y) < 0.5 && Math.abs(a.w - b.w) < 0.5 && Math.abs(a.h - b.h) < 0.5;
11948
+ const blocked = obstacles.filter((rect) => !sameRect(rect, from) && !sameRect(rect, to)).map((rect) => expand(rect, margin));
11949
+ const fallback = simplify([start2, startStub, { x: endStub.x, y: startStub.y }, endStub, end]);
11950
+ const pad = 260;
11951
+ const window2 = {
11952
+ x1: Math.min(start2.x, end.x) - pad,
11953
+ x2: Math.max(start2.x, end.x) + pad,
11954
+ y1: Math.min(start2.y, end.y) - pad,
11955
+ y2: Math.max(start2.y, end.y) + pad
11956
+ };
11957
+ const near = obstacles.filter((rect) => rect.x + rect.w >= window2.x1 && rect.x <= window2.x2 && rect.y + rect.h >= window2.y1 && rect.y <= window2.y2);
11958
+ const withinX = (value) => value >= window2.x1 && value <= window2.x2;
11959
+ const withinY = (value) => value >= window2.y1 && value <= window2.y2;
11960
+ const xs = corridors(near, "x", minCorridor).filter(withinX);
11961
+ const ys = corridors(near, "y", minCorridor).filter(withinY);
11962
+ const xOuter = outerLines(near, "x", margin + 6).filter(withinX);
11963
+ const yOuter = outerLines(near, "y", margin + 6).filter(withinY);
11964
+ const xCands = dedupe([start2.x, end.x, startStub.x, endStub.x, ...xs, ...xOuter]);
11965
+ const yCands = dedupe([start2.y, end.y, startStub.y, endStub.y, ...ys, ...yOuter]);
11966
+ if (xCands.length > 96 || yCands.length > 96) return fallback;
11967
+ const corridorX = new Set(xs.map((value) => Math.round(value)));
11968
+ const corridorY = new Set(ys.map((value) => Math.round(value)));
11969
+ const nodeId = (ix, iy) => `${ix},${iy}`;
11970
+ const pointAt = (id2) => {
11971
+ const [ix, iy] = id2.split(",").map(Number);
11972
+ return { x: xCands[ix], y: yCands[iy] };
11973
+ };
11974
+ const startIndex = { x: xCands.findIndex((value) => Math.abs(value - startStub.x) < 0.5), y: yCands.findIndex((value) => Math.abs(value - startStub.y) < 0.5) };
11975
+ const endIndex = { x: xCands.findIndex((value) => Math.abs(value - endStub.x) < 0.5), y: yCands.findIndex((value) => Math.abs(value - endStub.y) < 0.5) };
11976
+ if (startIndex.x < 0 || startIndex.y < 0 || endIndex.x < 0 || endIndex.y < 0) return fallback;
11977
+ const goal = { x: endStub.x, y: endStub.y };
11978
+ const startNode = nodeId(startIndex.x, startIndex.y);
11979
+ const goalNode = nodeId(endIndex.x, endIndex.y);
11980
+ const best = /* @__PURE__ */ new Map();
11981
+ const cameFrom = /* @__PURE__ */ new Map();
11982
+ const heap = new Heap();
11983
+ const withDir = (node, dir) => `${node}|${dir}`;
11984
+ best.set(withDir(startNode, "x"), 0);
11985
+ heap.push(0, 0, withDir(startNode, "x"));
11986
+ const estimate = (point) => Math.abs(point.x - goal.x) + Math.abs(point.y - goal.y);
11987
+ while (heap.size > 0) {
11988
+ const popped = heap.pop();
11989
+ const state3 = popped.node;
11990
+ const [node, dir] = state3.split("|");
11991
+ const cost = best.get(state3);
11992
+ if (cost === void 0) continue;
11993
+ if (node === goalNode) {
11994
+ const path = [];
11995
+ let cursor = state3;
11996
+ while (cursor !== void 0) {
11997
+ const [cell] = cursor.split("|");
11998
+ path.push(pointAt(cell));
11999
+ cursor = cameFrom.get(cursor);
11908
12000
  }
12001
+ path.reverse();
12002
+ return snapToChannels(
12003
+ simplify([start2, startStub, ...path.slice(1), endStub, end]),
12004
+ obstacles,
12005
+ margin
12006
+ );
12007
+ }
12008
+ const [ix, iy] = node.split(",").map(Number);
12009
+ const here = pointAt(node);
12010
+ const steps = [
12011
+ { dx: 1, dy: 0, axis: "x" },
12012
+ { dx: -1, dy: 0, axis: "x" },
12013
+ { dx: 0, dy: 1, axis: "y" },
12014
+ { dx: 0, dy: -1, axis: "y" }
12015
+ ];
12016
+ for (const step2 of steps) {
12017
+ const nx = ix + step2.dx;
12018
+ const ny = iy + step2.dy;
12019
+ if (nx < 0 || ny < 0 || nx >= xCands.length || ny >= yCands.length) continue;
12020
+ const next = { x: xCands[nx], y: yCands[ny] };
12021
+ const nextNode = nodeId(nx, ny);
12022
+ if (nextNode !== goalNode && blocked.some((rect) => insideStrict(rect, next))) continue;
12023
+ const clear = step2.axis === "x" ? !hitsHorizontal(blocked, here.y, here.x, next.x) : !hitsVertical(blocked, here.x, here.y, next.y);
12024
+ if (!clear) continue;
12025
+ const distance2 = Math.abs(next.x - here.x) + Math.abs(next.y - here.y);
12026
+ const onCorridor = step2.axis === "x" ? corridorY.has(Math.round(here.y)) : corridorX.has(Math.round(here.x));
12027
+ const turn = dir === step2.axis ? 0 : 18;
12028
+ const prefer = onCorridor ? 0 : 40;
12029
+ const nextCost = cost + distance2 + turn + prefer;
12030
+ const nextState = withDir(nextNode, step2.axis);
12031
+ const known = best.get(nextState);
12032
+ if (known !== void 0 && known <= nextCost) continue;
12033
+ best.set(nextState, nextCost);
12034
+ cameFrom.set(nextState, state3);
12035
+ heap.push(nextCost + estimate(next), nextCost, nextState);
12036
+ }
12037
+ }
12038
+ return fallback;
12039
+ }
12040
+ function roundedPath(points, radius = 10) {
12041
+ if (points.length === 0) return "";
12042
+ if (points.length === 1) return `M ${round(points[0].x)} ${round(points[0].y)}`;
12043
+ const parts = [`M ${round(points[0].x)} ${round(points[0].y)}`];
12044
+ for (let index2 = 1; index2 < points.length - 1; index2 += 1) {
12045
+ const prev = points[index2 - 1];
12046
+ const here = points[index2];
12047
+ const next = points[index2 + 1];
12048
+ const inLength = Math.hypot(here.x - prev.x, here.y - prev.y);
12049
+ const outLength = Math.hypot(next.x - here.x, next.y - here.y);
12050
+ const corner = Math.min(radius, inLength / 2, outLength / 2);
12051
+ if (corner < 0.5) {
12052
+ parts.push(`L ${round(here.x)} ${round(here.y)}`);
12053
+ continue;
12054
+ }
12055
+ const enter = {
12056
+ x: here.x + (prev.x - here.x) / (inLength || 1) * corner,
12057
+ y: here.y + (prev.y - here.y) / (inLength || 1) * corner
11909
12058
  };
11910
- window.addEventListener("keydown", onKeyDown);
11911
- return () => {
11912
- window.removeEventListener("keydown", onKeyDown);
11913
- release();
12059
+ const leave = {
12060
+ x: here.x + (next.x - here.x) / (outLength || 1) * corner,
12061
+ y: here.y + (next.y - here.y) / (outLength || 1) * corner
11914
12062
  };
11915
- }, []);
11916
- (0, import_react5.useEffect)(() => {
11917
- if (menu.searchable === true || menu.prompt !== void 0) inputRef.current?.focus();
11918
- }, [menu.searchable, menu.prompt]);
11919
- const normalized = query.trim().toLowerCase();
11920
- const visible = normalized === "" ? menu.items : menu.items.filter((item) => item.label.toLowerCase().includes(normalized));
11921
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
11922
- "div",
11923
- {
11924
- className: talk_map_default["menu"],
11925
- style: { left: menu.left, top: menu.top },
11926
- role: "menu",
11927
- onClick: (event) => {
11928
- event.stopPropagation();
11929
- },
11930
- onPointerDown: (event) => {
11931
- event.stopPropagation();
11932
- },
11933
- onContextMenu: (event) => {
11934
- event.preventDefault();
11935
- },
11936
- children: [
11937
- menu.title !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: talk_map_default["menuTitle"], children: menu.title }) : null,
11938
- menu.prompt !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(import_jsx_runtime7.Fragment, { children: [
11939
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
11940
- "input",
11941
- {
11942
- ref: inputRef,
11943
- className: talk_map_default["menuSearch"],
11944
- placeholder: menu.prompt.placeholder,
11945
- value: query,
11946
- onChange: (event) => {
11947
- setQuery(event.target.value);
11948
- },
11949
- onKeyDown: (event) => {
11950
- if (event.key === "Enter") {
11951
- event.preventDefault();
11952
- void submitPrompt();
11953
- }
11954
- }
11955
- }
11956
- ),
11957
- menu.prompt.preview !== void 0 && query.trim() !== "" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: talk_map_default["menuPreview"], children: menu.prompt.preview(query.trim()) }) : null,
11958
- error !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: talk_map_default["menuError"], children: error }) : null,
11959
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
11960
- "button",
11961
- {
11962
- type: "button",
11963
- className: talk_map_default["menuItem"],
11964
- disabled: busy || query.trim() === "",
11965
- onClick: () => {
11966
- void submitPrompt();
11967
- },
11968
- children: busy ? t("menu.working") : menu.prompt.submitLabel
11969
- }
11970
- )
11971
- ] }) : null,
11972
- menu.searchable === true ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
11973
- "input",
11974
- {
11975
- ref: inputRef,
11976
- className: talk_map_default["menuSearch"],
11977
- placeholder: t("menu.search"),
11978
- value: query,
11979
- onChange: (event) => {
11980
- setQuery(event.target.value);
11981
- }
11982
- }
11983
- ) : null,
11984
- menu.prompt !== void 0 ? null : visible.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: talk_map_default["menuEmpty"], children: t("menu.empty") }) : visible.map((item) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
11985
- "button",
11986
- {
11987
- type: "button",
11988
- role: "menuitem",
11989
- className: `${talk_map_default["menuItem"]}${item.danger === true ? ` ${talk_map_default["menuItemDanger"] ?? ""}` : ""}`,
11990
- disabled: item.disabled === true,
11991
- onClick: () => {
11992
- item.onPick();
11993
- },
11994
- children: [
11995
- item.icon !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MenuIcon, { name: item.icon }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: talk_map_default["menuIcon"] }),
11996
- item.label,
11997
- item.hint !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: talk_map_default["menuHint"], children: [
11998
- " ",
11999
- item.hint
12000
- ] }) : null
12001
- ]
12002
- },
12003
- item.key
12004
- ))
12005
- ]
12006
- }
12007
- );
12063
+ parts.push(`L ${round(enter.x)} ${round(enter.y)}`);
12064
+ parts.push(`Q ${round(here.x)} ${round(here.y)} ${round(leave.x)} ${round(leave.y)}`);
12065
+ }
12066
+ const last = points[points.length - 1];
12067
+ parts.push(`L ${round(last.x)} ${round(last.y)}`);
12068
+ return parts.join(" ");
12069
+ }
12070
+ function round(value) {
12071
+ return Math.round(value * 100) / 100;
12008
12072
  }
12009
12073
 
12010
12074
  // src/client/TalkMapEdge.tsx
@@ -12013,7 +12077,26 @@ function TalkMapEdge(props) {
12013
12077
  const data = props.data ?? {};
12014
12078
  const synced = data.sync === "synced";
12015
12079
  const hidden = synced && data.structural !== true;
12016
- const route = data.route;
12080
+ const faceOf = (position) => {
12081
+ const name2 = String(position ?? "left");
12082
+ if (name2 === "right") return "r";
12083
+ if (name2 === "top") return "t";
12084
+ if (name2 === "bottom") return "b";
12085
+ return "l";
12086
+ };
12087
+ const obstacles = data.obstacles;
12088
+ const route = obstacles === void 0 ? void 0 : routeBetween(
12089
+ {
12090
+ start: { x: props.sourceX, y: props.sourceY },
12091
+ startFace: faceOf(props.sourcePosition),
12092
+ end: { x: props.targetX, y: props.targetY },
12093
+ endFace: faceOf(props.targetPosition)
12094
+ },
12095
+ // Endpoint bodies for the corridor maths; the router skips them by value.
12096
+ { x: props.sourceX, y: props.sourceY, w: 0, h: 0 },
12097
+ { x: props.targetX, y: props.targetY, w: 0, h: 0 },
12098
+ obstacles
12099
+ );
12017
12100
  const routed = route !== void 0 && route.length > 1;
12018
12101
  const [smoothPath] = getSmoothStepPath({
12019
12102
  sourceX: props.sourceX,
@@ -13829,22 +13912,7 @@ function CanvasInner(props) {
13829
13912
  if (card === void 0) return void 0;
13830
13913
  return sessions.byId[card.sessionId]?.updatedAt;
13831
13914
  };
13832
- const routeFor = (fromCardId, toCardId) => {
13833
- const fromCard = canvasState.cards[fromCardId];
13834
- const toCard = canvasState.cards[toCardId];
13835
- if (fromCard === void 0 || toCard === void 0) return [];
13836
- const faces = sideHandles(fromCardId, toCardId);
13837
- const fromRect = { x: fromCard.x, y: fromCard.y, w: CARD_W, h: CARD_H };
13838
- const toRect = { x: toCard.x, y: toCard.y, w: CARD_W, h: CARD_H };
13839
- const others = Object.entries(canvasState.cards).filter(([id2]) => id2 !== fromCardId && id2 !== toCardId).filter(([id2]) => !foldedSet.has(id2)).map(([, card]) => ({ x: card.x, y: card.y, w: CARD_W, h: CARD_H }));
13840
- return routeEdge(
13841
- fromRect,
13842
- toRect,
13843
- faces.fromHandle,
13844
- faces.toHandle,
13845
- [fromRect, toRect, ...others]
13846
- );
13847
- };
13915
+ const obstaclesFor = (fromCardId, toCardId) => Object.entries(canvasState.cards).filter(([id2]) => id2 !== fromCardId && id2 !== toCardId).filter(([id2]) => !foldedSet.has(id2)).map(([, card]) => ({ x: card.x, y: card.y, w: CARD_W, h: CARD_H }));
13848
13916
  const routingObstacles = () => Object.entries(canvasState.cards).map(([id2, card]) => ({
13849
13917
  id: id2,
13850
13918
  x: card.x,
@@ -13898,7 +13966,7 @@ function CanvasInner(props) {
13898
13966
  fromCardId: edge.fromCardId,
13899
13967
  toCardId: edge.toCardId,
13900
13968
  sync,
13901
- route: routeFor(edge.fromCardId, edge.toCardId)
13969
+ obstacles: obstaclesFor(edge.fromCardId, edge.toCardId)
13902
13970
  },
13903
13971
  // Every line carries its direction now: 「推送摘要」 always travels
13904
13972
  // source → target, so a link edge gets a lighter arrow instead of none.
@@ -13953,7 +14021,7 @@ function CanvasInner(props) {
13953
14021
  toCardId: cardId,
13954
14022
  sync: lineageSync,
13955
14023
  structural: true,
13956
- route: routeFor(parentCardId, cardId)
14024
+ obstacles: obstaclesFor(parentCardId, cardId)
13957
14025
  },
13958
14026
  // No inline stroke: inline style beats everything the renderer draws.
13959
14027
  style: { opacity: 0.85 }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-talk-map",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Visual conversation map for DeepSeek Harness: an infinite whiteboard where every session is a card — drag to arrange, double-click to start a chat in place, draw an edge to fork a new session with injected context. Built for ADHD-friendly spatial memory. · DSH 可视化对话地图:会话即卡片,双击即聊,连线分叉带上下文的新对话。",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",