dsh-talk-map 0.1.9 → 0.1.11

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 +91 -17
  2. package/package.json +1 -1
package/client/client.js CHANGED
@@ -11739,7 +11739,8 @@ function ContextMenu(props) {
11739
11739
  }
11740
11740
 
11741
11741
  // src/client/edge-route.ts
11742
- var DEFAULTS = { margin: 14, stub: 22, minCorridor: 28 };
11742
+ var __routeDebug = {};
11743
+ var DEFAULTS = { margin: 8, stub: 22, minCorridor: 18 };
11743
11744
  function anchorOf(rect, face) {
11744
11745
  switch (face) {
11745
11746
  case "r":
@@ -11962,11 +11963,41 @@ function routeBetween(ends, from, to, obstacles, options = {}) {
11962
11963
  const end = ends.end;
11963
11964
  const startNormal = normalOf(ends.startFace);
11964
11965
  const endNormal = normalOf(ends.endFace);
11965
- const startStub = { x: start2.x + startNormal.x * stub, y: start2.y + startNormal.y * stub };
11966
- const endStub = { x: end.x + endNormal.x * stub, y: end.y + endNormal.y * stub };
11966
+ const spaceAhead = (point, normal) => {
11967
+ let best2 = 240;
11968
+ for (const raw of obstacles) {
11969
+ const rect = expand(raw, margin);
11970
+ if (normal.x !== 0) {
11971
+ if (point.y <= rect.y || point.y >= rect.y + rect.h) continue;
11972
+ if (normal.x > 0 && rect.x >= point.x) best2 = Math.min(best2, rect.x - point.x);
11973
+ if (normal.x < 0 && rect.x + rect.w <= point.x) best2 = Math.min(best2, point.x - (rect.x + rect.w));
11974
+ } else {
11975
+ if (point.x <= rect.x || point.x >= rect.x + rect.w) continue;
11976
+ if (normal.y > 0 && rect.y >= point.y) best2 = Math.min(best2, rect.y - point.y);
11977
+ if (normal.y < 0 && rect.y + rect.h <= point.y) best2 = Math.min(best2, point.y - (rect.y + rect.h));
11978
+ }
11979
+ }
11980
+ return best2;
11981
+ };
11982
+ const stubFor = (space) => {
11983
+ const half = Math.max(0, (space - margin * 2) / 2);
11984
+ return Math.max(4, Math.min(stub, half));
11985
+ };
11986
+ const startStubLength = stubFor(spaceAhead(start2, startNormal));
11987
+ const endStubLength = stubFor(spaceAhead(end, { x: -endNormal.x, y: -endNormal.y }));
11988
+ const startStub = {
11989
+ x: start2.x + startNormal.x * startStubLength,
11990
+ y: start2.y + startNormal.y * startStubLength
11991
+ };
11992
+ const endStub = {
11993
+ x: end.x + endNormal.x * endStubLength,
11994
+ y: end.y + endNormal.y * endStubLength
11995
+ };
11967
11996
  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;
11968
- const blocked = obstacles.filter((rect) => !sameRect(rect, from) && !sameRect(rect, to)).map((rect) => expand(rect, margin));
11997
+ 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;
11998
+ const blocked = obstacles.filter((rect) => !sameRect(rect, from) && !sameRect(rect, to)).filter((rect) => !overlaps(rect, from) && !overlaps(rect, to)).map((rect) => expand(rect, margin));
11969
11999
  const fallback = simplify([start2, startStub, { x: endStub.x, y: startStub.y }, endStub, end]);
12000
+ __routeDebug.last = { usedFallback: true };
11970
12001
  const pad = 260;
11971
12002
  const window2 = {
11972
12003
  x1: Math.min(start2.x, end.x) - pad,
@@ -11981,18 +12012,35 @@ function routeBetween(ends, from, to, obstacles, options = {}) {
11981
12012
  const ys = corridors(near, "y", minCorridor).filter(withinY);
11982
12013
  const xOuter = outerLines(near, "x", margin + 6).filter(withinX);
11983
12014
  const yOuter = outerLines(near, "y", margin + 6).filter(withinY);
11984
- const xCands = dedupe([start2.x, end.x, startStub.x, endStub.x, ...xs, ...xOuter]);
11985
- const yCands = dedupe([start2.y, end.y, startStub.y, endStub.y, ...ys, ...yOuter]);
11986
- if (xCands.length > 96 || yCands.length > 96) return fallback;
12015
+ const hug = margin + 6;
12016
+ const xHug = near.flatMap((rect) => [rect.x - hug, rect.x + rect.w + hug]);
12017
+ const yHug = near.flatMap((rect) => [rect.y - hug, rect.y + rect.h + hug]);
12018
+ const xCands = dedupe([start2.x, end.x, startStub.x, endStub.x, ...xs, ...xOuter, ...xHug]);
12019
+ const yCands = dedupe([start2.y, end.y, startStub.y, endStub.y, ...ys, ...yOuter, ...yHug]);
12020
+ const trim = (values, mustKeep, limit) => {
12021
+ if (values.length <= limit) return values;
12022
+ const keep = new Set(mustKeep);
12023
+ const rest = values.filter((value) => !keep.has(value));
12024
+ const slots = Math.max(1, limit - keep.size);
12025
+ const stride = Math.max(1, Math.floor(rest.length / slots));
12026
+ for (let index2 = 0; index2 < rest.length && keep.size < limit; index2 += stride) {
12027
+ keep.add(rest[index2]);
12028
+ }
12029
+ return values.filter((value) => keep.has(value));
12030
+ };
12031
+ const MAX_LINES = 72;
12032
+ const xsTrimmed = xCands.length > MAX_LINES ? trim(xCands, [start2.x, end.x, startStub.x, endStub.x], MAX_LINES) : xCands;
12033
+ const ysTrimmed = yCands.length > MAX_LINES ? trim(yCands, [start2.y, end.y, startStub.y, endStub.y], MAX_LINES) : yCands;
12034
+ __routeDebug.candidates = { x: xsTrimmed.length, y: ysTrimmed.length, near: near.length };
11987
12035
  const corridorX = new Set(xs.map((value) => Math.round(value)));
11988
12036
  const corridorY = new Set(ys.map((value) => Math.round(value)));
11989
12037
  const nodeId = (ix, iy) => `${ix},${iy}`;
11990
12038
  const pointAt = (id2) => {
11991
12039
  const [ix, iy] = id2.split(",").map(Number);
11992
- return { x: xCands[ix], y: yCands[iy] };
12040
+ return { x: xsTrimmed[ix], y: ysTrimmed[iy] };
11993
12041
  };
11994
- const startIndex = { x: xCands.findIndex((value) => Math.abs(value - startStub.x) < 0.5), y: yCands.findIndex((value) => Math.abs(value - startStub.y) < 0.5) };
11995
- const endIndex = { x: xCands.findIndex((value) => Math.abs(value - endStub.x) < 0.5), y: yCands.findIndex((value) => Math.abs(value - endStub.y) < 0.5) };
12042
+ const startIndex = { x: xsTrimmed.findIndex((value) => Math.abs(value - startStub.x) < 0.5), y: ysTrimmed.findIndex((value) => Math.abs(value - startStub.y) < 0.5) };
12043
+ const endIndex = { x: xsTrimmed.findIndex((value) => Math.abs(value - endStub.x) < 0.5), y: ysTrimmed.findIndex((value) => Math.abs(value - endStub.y) < 0.5) };
11996
12044
  if (startIndex.x < 0 || startIndex.y < 0 || endIndex.x < 0 || endIndex.y < 0) return fallback;
11997
12045
  const goal = { x: endStub.x, y: endStub.y };
11998
12046
  const startNode = nodeId(startIndex.x, startIndex.y);
@@ -12019,6 +12067,7 @@ function routeBetween(ends, from, to, obstacles, options = {}) {
12019
12067
  cursor = cameFrom.get(cursor);
12020
12068
  }
12021
12069
  path.reverse();
12070
+ __routeDebug.last = { usedFallback: false, steps: path.length };
12022
12071
  return snapToChannels(
12023
12072
  simplify([start2, startStub, ...path.slice(1), endStub, end]),
12024
12073
  obstacles,
@@ -12036,8 +12085,8 @@ function routeBetween(ends, from, to, obstacles, options = {}) {
12036
12085
  for (const step2 of steps) {
12037
12086
  const nx = ix + step2.dx;
12038
12087
  const ny = iy + step2.dy;
12039
- if (nx < 0 || ny < 0 || nx >= xCands.length || ny >= yCands.length) continue;
12040
- const next = { x: xCands[nx], y: yCands[ny] };
12088
+ if (nx < 0 || ny < 0 || nx >= xsTrimmed.length || ny >= ysTrimmed.length) continue;
12089
+ const next = { x: xsTrimmed[nx], y: ysTrimmed[ny] };
12041
12090
  const nextNode = nodeId(nx, ny);
12042
12091
  if (nextNode !== goalNode && blocked.some((rect) => insideStrict(rect, next))) continue;
12043
12092
  const clear = step2.axis === "x" ? !hitsHorizontal(blocked, here.y, here.x, next.x) : !hitsVertical(blocked, here.x, here.y, next.y);
@@ -12112,12 +12161,27 @@ function TalkMapEdge(props) {
12112
12161
  end: { x: props.targetX, y: props.targetY },
12113
12162
  endFace: faceOf(props.targetPosition)
12114
12163
  },
12115
- // Endpoint bodies for the corridor maths; the router skips them by value.
12116
- { x: props.sourceX, y: props.sourceY, w: 0, h: 0 },
12117
- { x: props.targetX, y: props.targetY, w: 0, h: 0 },
12164
+ // The endpoints' real boxes: the router excludes them from the obstacle
12165
+ // set by geometry. A degenerate 0×0 box never matches, so the endpoints
12166
+ // used to block their own handles and every line fell back to a straight L.
12167
+ data.fromRect ?? { x: props.sourceX, y: props.sourceY, w: 0, h: 0 },
12168
+ data.toRect ?? { x: props.targetX, y: props.targetY, w: 0, h: 0 },
12118
12169
  obstacles
12119
12170
  );
12120
12171
  const routed = route !== void 0 && route.length > 1;
12172
+ if (typeof window !== "undefined") {
12173
+ const w = window;
12174
+ w.__edgeDebug = w.__edgeDebug ?? [];
12175
+ w.__edgeDebug.push({
12176
+ id: props.id,
12177
+ obstacles: obstacles?.length ?? null,
12178
+ fromRect: data.fromRect ?? null,
12179
+ toRect: data.toRect ?? null,
12180
+ src: { x: props.sourceX, y: props.sourceY, pos: String(props.sourcePosition) },
12181
+ dst: { x: props.targetX, y: props.targetY, pos: String(props.targetPosition) },
12182
+ points: route ?? null
12183
+ });
12184
+ }
12121
12185
  const [smoothPath] = getSmoothStepPath({
12122
12186
  sourceX: props.sourceX,
12123
12187
  sourceY: props.sourceY,
@@ -13933,6 +13997,12 @@ function CanvasInner(props) {
13933
13997
  return sessions.byId[card.sessionId]?.updatedAt;
13934
13998
  };
13935
13999
  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 }));
14000
+ const boxOf = (cardId) => {
14001
+ const card = canvasState.cards[cardId];
14002
+ if (card === void 0) return void 0;
14003
+ const slot = cardLayout[cardId];
14004
+ return { x: slot?.x ?? card.x, y: slot?.y ?? card.y, w: CARD_W, h: CARD_H };
14005
+ };
13936
14006
  const routingObstacles = () => Object.entries(canvasState.cards).map(([id2, card]) => ({
13937
14007
  id: id2,
13938
14008
  x: card.x,
@@ -13986,7 +14056,9 @@ function CanvasInner(props) {
13986
14056
  fromCardId: edge.fromCardId,
13987
14057
  toCardId: edge.toCardId,
13988
14058
  sync,
13989
- obstacles: obstaclesFor(edge.fromCardId, edge.toCardId)
14059
+ obstacles: obstaclesFor(edge.fromCardId, edge.toCardId),
14060
+ ...boxOf(edge.fromCardId) !== void 0 ? { fromRect: boxOf(edge.fromCardId) } : {},
14061
+ ...boxOf(edge.toCardId) !== void 0 ? { toRect: boxOf(edge.toCardId) } : {}
13990
14062
  },
13991
14063
  // Every line carries its direction now: 「推送摘要」 always travels
13992
14064
  // source → target, so a link edge gets a lighter arrow instead of none.
@@ -14041,7 +14113,9 @@ function CanvasInner(props) {
14041
14113
  toCardId: cardId,
14042
14114
  sync: lineageSync,
14043
14115
  structural: true,
14044
- obstacles: obstaclesFor(parentCardId, cardId)
14116
+ obstacles: obstaclesFor(parentCardId, cardId),
14117
+ ...boxOf(parentCardId) !== void 0 ? { fromRect: boxOf(parentCardId) } : {},
14118
+ ...boxOf(cardId) !== void 0 ? { toRect: boxOf(cardId) } : {}
14045
14119
  },
14046
14120
  // No inline stroke: inline style beats everything the renderer draws.
14047
14121
  style: { opacity: 0.85 }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-talk-map",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
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",