dsh-talk-map 0.1.20 → 0.1.22

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 +74 -34
  2. package/package.json +1 -1
package/client/client.js CHANGED
@@ -448,7 +448,7 @@ var zh = {
448
448
  "digest.empty": "这条对话还没有摘要,先刷新摘要再来看。",
449
449
  "digest.copy": "复制",
450
450
  "digest.close": "关闭",
451
- "global.searchPlaceholder": "搜地图上的卡片(标题/正文)· v0.1.20",
451
+ "global.searchPlaceholder": "搜地图上的卡片(标题/正文)· v0.1.22",
452
452
  "global.searchRun": "搜索",
453
453
  "global.searchTitle": "搜索地图",
454
454
  "font.group": "文字大小",
@@ -599,7 +599,7 @@ var en = {
599
599
  "menu.noGroup": "Remove from group (free card)",
600
600
  "menu.open": "Open conversation",
601
601
  "menu.markUnread": "Mark as unread",
602
- "global.searchPlaceholder": "Search cards on the map · v0.1.20",
602
+ "global.searchPlaceholder": "Search cards on the map · v0.1.22",
603
603
  "global.searchRun": "Search",
604
604
  "global.searchTitle": "Search the map",
605
605
  "font.group": "Text size",
@@ -11740,8 +11740,7 @@ function ContextMenu(props) {
11740
11740
 
11741
11741
  // src/client/edge-route.ts
11742
11742
  var __routeDebug = {};
11743
- var DEFAULTS = { margin: 8, stub: 22, minCorridor: 18 };
11744
- var CROSS_PENALTY = 2e4;
11743
+ var DEFAULTS = { margin: 4, stub: 22, minCorridor: 10 };
11745
11744
  function anchorOf(rect, face) {
11746
11745
  switch (face) {
11747
11746
  case "r":
@@ -11987,7 +11986,7 @@ function routeBetween(ends, from, to, obstacles, options = {}) {
11987
11986
  return Math.max(4, Math.min(stub, half));
11988
11987
  };
11989
11988
  const startStubLength = stubFor(spaceAhead(start2, startNormal));
11990
- const endStubLength = stubFor(spaceAhead(end, { x: -endNormal.x, y: -endNormal.y }));
11989
+ const endStubLength = stubFor(spaceAhead(end, endNormal));
11991
11990
  const startStub = {
11992
11991
  x: start2.x + startNormal.x * startStubLength,
11993
11992
  y: start2.y + startNormal.y * startStubLength
@@ -11998,8 +11997,45 @@ function routeBetween(ends, from, to, obstacles, options = {}) {
11998
11997
  };
11999
11998
  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;
12000
11999
  const overlaps = (a, b) => a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
12001
- const blocked = obstacles.filter((rect) => !sameRect(rect, from) && !sameRect(rect, to)).filter((rect) => !overlaps(rect, from) && !overlaps(rect, to)).map((rect) => expand(rect, margin));
12002
- const fallback = simplify([start2, startStub, { x: endStub.x, y: startStub.y }, endStub, end]);
12000
+ const blocked = obstacles.filter((rect) => !sameRect(rect, from) && !sameRect(rect, to)).map((rect) => expand(rect, margin));
12001
+ __routeDebug.blockedCount = blocked.length;
12002
+ __routeDebug.blockedFirst = blocked.slice(0, 2);
12003
+ const makeFallback = () => {
12004
+ if (blocked.length === 0) return simplify([start2, startStub, { x: endStub.x, y: startStub.y }, endStub, end]);
12005
+ const gap = margin + 8;
12006
+ const left = Math.min(...blocked.map((rect) => rect.x)) - gap;
12007
+ const right = Math.max(...blocked.map((rect) => rect.x + rect.w)) + gap;
12008
+ const top = Math.min(...blocked.map((rect) => rect.y)) - gap;
12009
+ const bottom = Math.max(...blocked.map((rect) => rect.y + rect.h)) + gap;
12010
+ const lanesX = [.../* @__PURE__ */ new Set([left, right, ...xsTrimmed])].sort((a, b) => Math.abs(a - startStub.x) - Math.abs(b - startStub.x));
12011
+ const lanesY = [.../* @__PURE__ */ new Set([top, bottom, ...ysTrimmed])].sort((a, b) => Math.abs(a - startStub.y) - Math.abs(b - startStub.y));
12012
+ const candidates = [];
12013
+ for (const lane of lanesY.slice(0, 8)) {
12014
+ candidates.push([start2, startStub, { x: startStub.x, y: lane }, { x: endStub.x, y: lane }, endStub, end]);
12015
+ }
12016
+ for (const lane of lanesX.slice(0, 8)) {
12017
+ candidates.push([start2, startStub, { x: lane, y: startStub.y }, { x: lane, y: endStub.y }, endStub, end]);
12018
+ }
12019
+ candidates.push([start2, startStub, { x: left, y: startStub.y }, { x: left, y: endStub.y }, endStub, end]);
12020
+ candidates.push([start2, startStub, { x: right, y: startStub.y }, { x: right, y: endStub.y }, endStub, end]);
12021
+ let best2;
12022
+ let bestHits = Infinity;
12023
+ for (const candidate of candidates) {
12024
+ const points = simplify(candidate);
12025
+ let hits = 0;
12026
+ for (let index2 = 1; index2 < points.length; index2 += 1) {
12027
+ const a = points[index2 - 1];
12028
+ const b = points[index2];
12029
+ hits += a.x === b.x ? hitsVertical(blocked, a.x, a.y, b.y) : hitsHorizontal(blocked, a.y, a.x, b.x);
12030
+ }
12031
+ if (hits < bestHits) {
12032
+ bestHits = hits;
12033
+ best2 = points;
12034
+ if (hits === 0) break;
12035
+ }
12036
+ }
12037
+ return best2 ?? simplify([start2, startStub, { x: endStub.x, y: startStub.y }, endStub, end]);
12038
+ };
12003
12039
  __routeDebug.last = { usedFallback: true };
12004
12040
  const pad = 260;
12005
12041
  const window2 = {
@@ -12016,7 +12052,7 @@ function routeBetween(ends, from, to, obstacles, options = {}) {
12016
12052
  const ys = corridors(lanes, "y", minCorridor).filter(withinY);
12017
12053
  const xOuter = outerLines(lanes, "x", margin + 6).filter(withinX);
12018
12054
  const yOuter = outerLines(lanes, "y", margin + 6).filter(withinY);
12019
- const hug = margin + 6;
12055
+ const hug = margin + 8;
12020
12056
  const xHug = lanes.flatMap((rect) => [rect.x - hug, rect.x + rect.w + hug]);
12021
12057
  const yHug = lanes.flatMap((rect) => [rect.y - hug, rect.y + rect.h + hug]);
12022
12058
  const xCands = dedupe([start2.x, end.x, startStub.x, endStub.x, ...xs, ...xOuter, ...xHug]);
@@ -12045,7 +12081,11 @@ function routeBetween(ends, from, to, obstacles, options = {}) {
12045
12081
  };
12046
12082
  const startIndex = { x: xsTrimmed.findIndex((value) => Math.abs(value - startStub.x) < 0.5), y: ysTrimmed.findIndex((value) => Math.abs(value - startStub.y) < 0.5) };
12047
12083
  const endIndex = { x: xsTrimmed.findIndex((value) => Math.abs(value - endStub.x) < 0.5), y: ysTrimmed.findIndex((value) => Math.abs(value - endStub.y) < 0.5) };
12048
- if (startIndex.x < 0 || startIndex.y < 0 || endIndex.x < 0 || endIndex.y < 0) return fallback;
12084
+ if (startIndex.x < 0 || startIndex.y < 0 || endIndex.x < 0 || endIndex.y < 0) {
12085
+ __routeDebug.reason = "no-index";
12086
+ __routeDebug.index = { startIndex, endIndex, xs: xsTrimmed.length, ys: ysTrimmed.length };
12087
+ return makeFallback();
12088
+ }
12049
12089
  const goal = { x: endStub.x, y: endStub.y };
12050
12090
  const startNode = nodeId(startIndex.x, startIndex.y);
12051
12091
  const goalNode = nodeId(endIndex.x, endIndex.y);
@@ -12056,7 +12096,9 @@ function routeBetween(ends, from, to, obstacles, options = {}) {
12056
12096
  best.set(withDir(startNode, "x"), 0);
12057
12097
  heap.push(0, 0, withDir(startNode, "x"));
12058
12098
  const estimate = (point) => Math.abs(point.x - goal.x) + Math.abs(point.y - goal.y);
12099
+ let visited = 0;
12059
12100
  while (heap.size > 0) {
12101
+ visited += 1;
12060
12102
  const popped = heap.pop();
12061
12103
  const state3 = popped.node;
12062
12104
  const [node, dir] = state3.split("|");
@@ -12072,6 +12114,7 @@ function routeBetween(ends, from, to, obstacles, options = {}) {
12072
12114
  }
12073
12115
  path.reverse();
12074
12116
  __routeDebug.last = { usedFallback: false, steps: path.length };
12117
+ __routeDebug.rawPath = path.map((point) => [Math.round(point.x), Math.round(point.y)]);
12075
12118
  return snapToChannels(
12076
12119
  simplify([start2, startStub, ...path.slice(1), endStub, end]),
12077
12120
  obstacles,
@@ -12092,23 +12135,24 @@ function routeBetween(ends, from, to, obstacles, options = {}) {
12092
12135
  if (nx < 0 || ny < 0 || nx >= xsTrimmed.length || ny >= ysTrimmed.length) continue;
12093
12136
  const next = { x: xsTrimmed[nx], y: ysTrimmed[ny] };
12094
12137
  const nextNode = nodeId(nx, ny);
12095
- const insideCost = blocked.filter((rect) => insideStrict(rect, next)).length * CROSS_PENALTY;
12138
+ if (nextNode !== goalNode && blocked.some((rect) => insideStrict(rect, next))) continue;
12096
12139
  const crossing = step2.axis === "x" ? hitsHorizontal(blocked, here.y, here.x, next.x) : hitsVertical(blocked, here.x, here.y, next.y);
12097
- const crossCost = crossing * CROSS_PENALTY;
12140
+ if (crossing > 0) continue;
12098
12141
  const distance2 = Math.abs(next.x - here.x) + Math.abs(next.y - here.y);
12099
12142
  const onCorridor = step2.axis === "x" ? corridorY.has(Math.round(here.y)) : corridorX.has(Math.round(here.x));
12100
12143
  const turn = dir === step2.axis ? 0 : 18;
12101
12144
  const prefer = onCorridor ? 0 : 40;
12102
- const nextCost = cost + distance2 + turn + prefer + crossCost + insideCost;
12145
+ const nextCost = cost + distance2 + turn + prefer;
12103
12146
  const nextState = withDir(nextNode, step2.axis);
12104
12147
  const known = best.get(nextState);
12105
12148
  if (known !== void 0 && known <= nextCost) continue;
12149
+ if (nextNode === goalNode) __routeDebug.goalPushed = nextState;
12106
12150
  best.set(nextState, nextCost);
12107
12151
  cameFrom.set(nextState, state3);
12108
12152
  heap.push(nextCost + estimate(next), nextCost, nextState);
12109
12153
  }
12110
12154
  }
12111
- return fallback;
12155
+ return makeFallback();
12112
12156
  }
12113
12157
  function roundedPath(points, radius = 10) {
12114
12158
  if (points.length === 0) return "";
@@ -12150,28 +12194,23 @@ var boardCache = { at: 0, boxes: [] };
12150
12194
  function boardBoxes() {
12151
12195
  if (typeof document === "undefined") return [];
12152
12196
  const now2 = Date.now();
12153
- if (now2 - boardCache.at < 80) return boardCache.boxes;
12197
+ if (now2 - boardCache.at < 60) return boardCache.boxes;
12154
12198
  const viewport = document.querySelector(".react-flow__viewport");
12155
- const viewportRect = viewport?.getBoundingClientRect();
12156
- let scale = 1;
12157
- if (viewport !== null) {
12158
- const matrix = getComputedStyle(viewport).transform;
12159
- const parsed = /matrix\(([^)]+)\)/.exec(matrix);
12160
- if (parsed !== null) {
12161
- const values = parsed[1].split(",").map(Number);
12162
- scale = values[0] === void 0 || values[0] === 0 ? 1 : values[0];
12163
- }
12164
- }
12199
+ if (viewport === null) return boardCache.boxes;
12165
12200
  const boxes = [];
12166
12201
  for (const element of document.querySelectorAll("[data-talkmap-session]")) {
12167
- const rect = element.getBoundingClientRect();
12168
- if (rect.width < 8 || rect.height < 8) continue;
12169
- boxes.push({
12170
- x: (rect.left - (viewportRect?.left ?? 0)) / scale,
12171
- y: (rect.top - (viewportRect?.top ?? 0)) / scale,
12172
- w: rect.width / scale,
12173
- h: rect.height / scale
12174
- });
12202
+ const node = element;
12203
+ let x = 0;
12204
+ let y = 0;
12205
+ let cursor = node;
12206
+ while (cursor !== null && cursor !== viewport) {
12207
+ x += cursor.offsetLeft;
12208
+ y += cursor.offsetTop;
12209
+ cursor = cursor.offsetParent;
12210
+ }
12211
+ if (cursor === null) continue;
12212
+ if (node.offsetWidth < 8 || node.offsetHeight < 8) continue;
12213
+ boxes.push({ x, y, w: node.offsetWidth, h: node.offsetHeight });
12175
12214
  }
12176
12215
  if (boxes.length > 0) {
12177
12216
  boardCache.at = now2;
@@ -12195,8 +12234,9 @@ function TalkMapEdge(props) {
12195
12234
  return "l";
12196
12235
  };
12197
12236
  const obstacles = data.obstacles;
12198
- const sameCorner = (box, other) => other !== void 0 && Math.abs(box.x - other.x) < 3 && Math.abs(box.y - other.y) < 3;
12199
- const merged = obstacles ?? [].filter((box) => !sameCorner(box, data.fromRect)).filter((box) => !sameCorner(box, data.toRect)).filter((box) => !containsPoint(box, props.sourceX, props.sourceY)).filter((box) => !containsPoint(box, props.targetX, props.targetY));
12237
+ const measuredBoxes = boardBoxes();
12238
+ const sameCorner = (box, other) => other !== void 0 && Math.abs(box.x - other.x) < 6 && Math.abs(box.y - other.y) < 6;
12239
+ const merged = (measuredBoxes.length > 0 ? measuredBoxes : obstacles ?? []).filter((box) => !sameCorner(box, data.fromRect)).filter((box) => !sameCorner(box, data.toRect)).filter((box) => !sameCorner(box, data.fromRect)).filter((box) => !sameCorner(box, data.toRect)).filter((box) => !containsPoint(box, props.sourceX, props.sourceY)).filter((box) => !containsPoint(box, props.targetX, props.targetY));
12200
12240
  const route = merged.length === 0 ? void 0 : routeBetween(
12201
12241
  {
12202
12242
  start: { x: props.sourceX, y: props.sourceY },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-talk-map",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
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",