dsh-talk-map 0.1.48 → 0.1.50

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 +151 -102
  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": "b48 · 搜地图上的卡片(标题/正文)",
451
+ "global.searchPlaceholder": "b50 · 搜地图上的卡片(标题/正文)",
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": "b48 · Search cards on the map",
602
+ "global.searchPlaceholder": "b50 · Search cards on the map",
603
603
  "global.searchRun": "Search",
604
604
  "global.searchTitle": "Search the map",
605
605
  "font.group": "Text size",
@@ -11720,18 +11720,6 @@ function ContextMenu(props) {
11720
11720
  // src/client/edge-route.ts
11721
11721
  var __routeDebug = {};
11722
11722
  var DEFAULTS = { margin: 4, stub: 22, minCorridor: 10 };
11723
- function anchorOf(rect, face) {
11724
- switch (face) {
11725
- case "r":
11726
- return { x: rect.x + rect.w, y: rect.y + rect.h / 2 };
11727
- case "l":
11728
- return { x: rect.x, y: rect.y + rect.h / 2 };
11729
- case "t":
11730
- return { x: rect.x + rect.w / 2, y: rect.y };
11731
- default:
11732
- return { x: rect.x + rect.w / 2, y: rect.y + rect.h };
11733
- }
11734
- }
11735
11723
  function normalOf(face) {
11736
11724
  switch (face) {
11737
11725
  case "r":
@@ -11867,15 +11855,6 @@ function simplify(points) {
11867
11855
  }
11868
11856
  return out;
11869
11857
  }
11870
- function routeEdge(from, to, fromFace, toFace, obstacles, options = {}) {
11871
- return routeBetween(
11872
- { start: anchorOf(from, fromFace), startFace: fromFace, end: anchorOf(to, toFace), endFace: toFace },
11873
- from,
11874
- to,
11875
- obstacles,
11876
- options
11877
- );
11878
- }
11879
11858
  function snapToChannels(points, obstacles, margin) {
11880
11859
  if (points.length < 3) return points;
11881
11860
  const rects = obstacles;
@@ -13130,94 +13109,164 @@ function StackDrawer(props) {
13130
13109
  }
13131
13110
  return hits2;
13132
13111
  };
13133
- const FACES = ["t", "r", "b", "l"];
13134
- const anchorOn = (rect, face) => face === "t" ? { x: rect.x + rect.w / 2, y: rect.y } : face === "b" ? { x: rect.x + rect.w / 2, y: rect.y + rect.h } : face === "l" ? { x: rect.x, y: rect.y + rect.h / 2 } : { x: rect.x + rect.w, y: rect.y + rect.h / 2 };
13135
- const normalOf2 = (face) => face === "t" ? { x: 0, y: -1 } : face === "b" ? { x: 0, y: 1 } : face === "l" ? { x: -1, y: 0 } : { x: 1, y: 0 };
13136
- const bandCentres = (values, size) => {
13137
- const unique = [...new Set(values.map((value) => Math.round(value)))].sort((a, b) => a - b);
13138
- const lanes = [];
13139
- for (let index2 = 1; index2 < unique.length; index2 += 1) {
13140
- const left = unique[index2 - 1];
13141
- const right = unique[index2];
13142
- if (right - left > size + 2) lanes.push((left + size + right) / 2);
13143
- else lanes.push((left + size / 2 + right + size / 2) / 2);
13112
+ const sideOf = (rect, other) => {
13113
+ const dx = other.x + other.w / 2 - (rect.x + rect.w / 2);
13114
+ const dy = other.y + other.h / 2 - (rect.y + rect.h / 2);
13115
+ if (Math.abs(dx) >= Math.abs(dy)) return dx >= 0 ? "r" : "l";
13116
+ return dy >= 0 ? "b" : "t";
13117
+ };
13118
+ const anchorOf = (rect, side) => side === "t" ? { x: rect.x + rect.w / 2, y: rect.y } : side === "b" ? { x: rect.x + rect.w / 2, y: rect.y + rect.h } : side === "l" ? { x: rect.x, y: rect.y + rect.h / 2 } : { x: rect.x + rect.w, y: rect.y + rect.h / 2 };
13119
+ const normalOf2 = (side) => side === "t" ? { x: 0, y: -1 } : side === "b" ? { x: 0, y: 1 } : side === "l" ? { x: -1, y: 0 } : { x: 1, y: 0 };
13120
+ const fromSide = sideOf(fromRect, toRect);
13121
+ const toSide = sideOf(toRect, fromRect);
13122
+ const startPoint = anchorOf(fromRect, fromSide);
13123
+ const endPoint = anchorOf(toRect, toSide);
13124
+ const startNormal = normalOf2(fromSide);
13125
+ const endNormal = normalOf2(toSide);
13126
+ const span = Math.hypot(endPoint.x - startPoint.x, endPoint.y - startPoint.y);
13127
+ const badness = (sample) => {
13128
+ let bad = 0;
13129
+ for (let step2 = 0; step2 <= 40; step2 += 1) {
13130
+ const point = sample(step2 / 40);
13131
+ if (point.x < 6 || point.y < 6 || point.x > boundsWidth - 6 || point.y > boundsHeight - 6) bad += 1;
13132
+ for (const card of cardsInDrawer) {
13133
+ if (point.x <= card.x + 2 || point.x >= card.x + card.w - 2) continue;
13134
+ if (point.y <= card.y + 2 || point.y >= card.y + card.h - 2) continue;
13135
+ const own = card.id === link2.from || card.id === link2.to;
13136
+ const nearStart = Math.hypot(point.x - startPoint.x, point.y - startPoint.y) < 18;
13137
+ const nearEnd = Math.hypot(point.x - endPoint.x, point.y - endPoint.y) < 18;
13138
+ if (own && (nearStart || nearEnd)) continue;
13139
+ bad += 1;
13140
+ }
13144
13141
  }
13145
- const first = unique[0];
13146
- const last = unique[unique.length - 1];
13147
- if (first !== void 0) lanes.unshift(first - 14);
13148
- if (last !== void 0) lanes.push(last + size + 14);
13149
- return lanes;
13142
+ return bad;
13150
13143
  };
13151
- const lanesY = bandCentres(cardsInDrawer.map((card) => card.y), 104);
13152
- const lanesX = bandCentres(cardsInDrawer.map((card) => card.x), 224);
13153
- const lengthOf = (candidate) => {
13154
- let total = 0;
13155
- for (let index2 = 1; index2 < candidate.length; index2 += 1) {
13156
- total += Math.abs(candidate[index2].x - candidate[index2 - 1].x) + Math.abs(candidate[index2].y - candidate[index2 - 1].y);
13144
+ let bestD;
13145
+ let bestCost = Number.POSITIVE_INFINITY;
13146
+ let arrival = { x: endPoint.x - startPoint.x, y: endPoint.y - startPoint.y };
13147
+ const tryCurve = (control1, control2) => {
13148
+ const u1 = (t2) => (1 - t2) * (1 - t2) * (1 - t2);
13149
+ const u2 = (t2) => 3 * (1 - t2) * (1 - t2) * t2;
13150
+ const u3 = (t2) => 3 * (1 - t2) * t2 * t2;
13151
+ const u4 = (t2) => t2 * t2 * t2;
13152
+ const sample = (t2) => ({
13153
+ x: u1(t2) * startPoint.x + u2(t2) * control1.x + u3(t2) * control2.x + u4(t2) * endPoint.x,
13154
+ y: u1(t2) * startPoint.y + u2(t2) * control1.y + u3(t2) * control2.y + u4(t2) * endPoint.y
13155
+ });
13156
+ const cost = badness(sample);
13157
+ if (cost < bestCost) {
13158
+ bestCost = cost;
13159
+ bestD = "M " + startPoint.x + " " + startPoint.y + " C " + control1.x + " " + control1.y + ", " + control2.x + " " + control2.y + ", " + endPoint.x + " " + endPoint.y;
13160
+ arrival = { x: endPoint.x - control2.x, y: endPoint.y - control2.y };
13157
13161
  }
13158
- return total;
13159
13162
  };
13160
- const candidates = [];
13161
- for (const fromFace of FACES) {
13162
- for (const toFace of FACES) {
13163
- candidates.push(routeEdge(fromRect, toRect, fromFace, toFace, [fromRect, toRect, ...obstacles], { stub: 10 }));
13164
- const start2 = anchorOn(fromRect, fromFace);
13165
- const end = anchorOn(toRect, toFace);
13166
- const startNormal = normalOf2(fromFace);
13167
- const endNormal = normalOf2(toFace);
13168
- const startStub = { x: start2.x + startNormal.x * 10, y: start2.y + startNormal.y * 10 };
13169
- const endStub = { x: end.x + endNormal.x * 10, y: end.y + endNormal.y * 10 };
13170
- for (const lane of lanesY) {
13171
- candidates.push([start2, startStub, { x: startStub.x, y: lane }, { x: endStub.x, y: lane }, endStub, end]);
13172
- candidates.push([
13173
- start2,
13174
- startStub,
13175
- { x: startStub.x, y: lane },
13176
- { x: endStub.x, y: lane },
13177
- { x: endStub.x, y: endStub.y },
13178
- endStub,
13179
- end
13180
- ]);
13163
+ for (const bow of [0.15, 0.3, 0.5, 0.75, 1.1]) {
13164
+ const reach = Math.max(18, span * bow);
13165
+ const c1 = { x: startPoint.x + startNormal.x * reach, y: startPoint.y + startNormal.y * reach };
13166
+ const c2 = { x: endPoint.x + endNormal.x * reach, y: endPoint.y + endNormal.y * reach };
13167
+ tryCurve(c1, c2);
13168
+ if (bestCost === 0) break;
13169
+ }
13170
+ if (bestCost > 0) {
13171
+ const pad = 10;
13172
+ const pairTop = Math.min(fromRect.y, toRect.y);
13173
+ const pairBottom = Math.max(fromRect.y + fromRect.h, toRect.y + toRect.h);
13174
+ const pairLeft = Math.min(fromRect.x, toRect.x);
13175
+ const pairRight = Math.max(fromRect.x + fromRect.w, toRect.x + toRect.w);
13176
+ const midX = (startPoint.x + endPoint.x) / 2;
13177
+ const midY = (startPoint.y + endPoint.y) / 2;
13178
+ const waypoints = [
13179
+ { x: midX, y: Math.max(pad, pairTop - 16) },
13180
+ { x: midX, y: Math.min(boundsHeight - pad, pairBottom + 16) },
13181
+ { x: Math.max(pad, pairLeft - 16), y: midY },
13182
+ { x: Math.min(boundsWidth - pad, pairRight + 16), y: midY }
13183
+ ];
13184
+ for (const waypoint of waypoints) {
13185
+ tryCurve(waypoint, waypoint);
13186
+ if (bestCost === 0) break;
13187
+ }
13188
+ }
13189
+ if (bestCost > 0) {
13190
+ const bands2 = (edges) => {
13191
+ const sorted = [...edges].sort((a, b) => a.start - b.start);
13192
+ const lanes = [];
13193
+ let reach = Number.NEGATIVE_INFINITY;
13194
+ for (const edge of sorted) {
13195
+ if (edge.start > reach && Number.isFinite(reach)) lanes.push((reach + edge.start) / 2);
13196
+ reach = Math.max(reach, edge.end);
13197
+ }
13198
+ if (sorted.length > 0) {
13199
+ lanes.unshift(Math.max(8, sorted[0].start - 14));
13200
+ lanes.push(reach + 14);
13201
+ }
13202
+ return lanes;
13203
+ };
13204
+ const samplePolyline = (points) => (t2) => {
13205
+ let total = 0;
13206
+ for (let index2 = 1; index2 < points.length; index2 += 1) {
13207
+ total += Math.abs(points[index2].x - points[index2 - 1].x) + Math.abs(points[index2].y - points[index2 - 1].y);
13181
13208
  }
13182
- for (const lane of lanesX) {
13183
- candidates.push([start2, startStub, { x: lane, y: startStub.y }, { x: lane, y: endStub.y }, endStub, end]);
13184
- candidates.push([
13185
- start2,
13186
- startStub,
13187
- { x: lane, y: startStub.y },
13188
- { x: lane, y: endStub.y },
13189
- { x: endStub.x, y: endStub.y },
13190
- endStub,
13191
- end
13192
- ]);
13209
+ let walked = 0;
13210
+ const target = t2 * total;
13211
+ for (let index2 = 1; index2 < points.length; index2 += 1) {
13212
+ const a = points[index2 - 1];
13213
+ const b = points[index2];
13214
+ const length = Math.abs(b.x - a.x) + Math.abs(b.y - a.y);
13215
+ if (walked + length >= target || index2 === points.length - 1) {
13216
+ const ratio = length === 0 ? 0 : Math.min(1, (target - walked) / length);
13217
+ return { x: a.x + (b.x - a.x) * ratio, y: a.y + (b.y - a.y) * ratio };
13218
+ }
13219
+ walked += length;
13193
13220
  }
13221
+ return points[points.length - 1];
13222
+ };
13223
+ const midY = (startPoint.y + endPoint.y) / 2;
13224
+ const midX = (startPoint.x + endPoint.x) / 2;
13225
+ const lanesY = bands2(cardsInDrawer.map((card) => ({ start: card.y, end: card.y + card.h }))).sort((a, b) => Math.abs(a - midY) - Math.abs(b - midY));
13226
+ const lanesX = bands2(cardsInDrawer.map((card) => ({ start: card.x, end: card.x + card.w }))).sort((a, b) => Math.abs(a - midX) - Math.abs(b - midX));
13227
+ const startStub = { x: startPoint.x + startNormal.x * 12, y: startPoint.y + startNormal.y * 12 };
13228
+ const endStub = { x: endPoint.x + endNormal.x * 12, y: endPoint.y + endNormal.y * 12 };
13229
+ const shapes = [];
13230
+ for (const lane of lanesY) {
13231
+ shapes.push([
13232
+ startPoint,
13233
+ startStub,
13234
+ { x: startStub.x, y: lane },
13235
+ { x: endStub.x, y: lane },
13236
+ endStub,
13237
+ endPoint
13238
+ ]);
13194
13239
  }
13195
- }
13196
- let bestPoints = candidates[0] ?? routeEdge(
13197
- fromRect,
13198
- toRect,
13199
- faces.fromHandle,
13200
- faces.toHandle,
13201
- [fromRect, toRect, ...obstacles],
13202
- { stub: 10 }
13203
- );
13204
- let bestDirty = dirty(bestPoints);
13205
- let bestLength = lengthOf(bestPoints);
13206
- for (const candidate of candidates) {
13207
- const cost = dirty(candidate);
13208
- const length = lengthOf(candidate);
13209
- if (cost < bestDirty || cost === bestDirty && length < bestLength) {
13210
- bestDirty = cost;
13211
- bestLength = length;
13212
- bestPoints = candidate;
13213
- if (cost === 0 && length <= 220) break;
13240
+ for (const lane of lanesX) {
13241
+ shapes.push([
13242
+ startPoint,
13243
+ startStub,
13244
+ { x: lane, y: startStub.y },
13245
+ { x: lane, y: endStub.y },
13246
+ endStub,
13247
+ endPoint
13248
+ ]);
13249
+ }
13250
+ for (const shape of shapes) {
13251
+ const cost = badness(samplePolyline(shape));
13252
+ if (cost < bestCost) {
13253
+ bestCost = cost;
13254
+ bestD = roundedPath(shape, 10);
13255
+ arrival = { x: endPoint.x - endStub.x, y: endPoint.y - endStub.y };
13256
+ if (cost === 0) break;
13257
+ }
13214
13258
  }
13215
13259
  }
13216
- const points = bestPoints;
13217
- const tip = points[points.length - 1];
13218
- const prev = points[points.length - 2];
13219
- const angle = Math.abs(tip.x - prev.x) >= Math.abs(tip.y - prev.y) ? tip.x >= prev.x ? 0 : 180 : tip.y >= prev.y ? 90 : -90;
13220
- next.push({ d: roundedPath(points, 8), ax: tip.x, ay: tip.y, angle, from: link2.from, to: link2.to });
13260
+ const angle = Math.abs(arrival.x) < 0.5 && Math.abs(arrival.y) < 0.5 ? toSide === "l" ? 180 : toSide === "r" ? 0 : toSide === "t" ? -90 : 90 : Math.abs(arrival.x) >= Math.abs(arrival.y) ? arrival.x >= 0 ? 0 : 180 : arrival.y >= 0 ? 90 : -90;
13261
+ const arrowAngle = angle;
13262
+ next.push({
13263
+ d: bestD ?? "M " + startPoint.x + " " + startPoint.y + " L " + endPoint.x + " " + endPoint.y,
13264
+ ax: endPoint.x,
13265
+ ay: endPoint.y,
13266
+ angle: arrowAngle,
13267
+ from: link2.from,
13268
+ to: link2.to
13269
+ });
13221
13270
  }
13222
13271
  setWires((current) => {
13223
13272
  if (current.length === next.length && current.every((wire, index2) => wire.d === next[index2]?.d)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-talk-map",
3
- "version": "0.1.48",
3
+ "version": "0.1.50",
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",