dsh-timeback 0.7.0 → 0.7.1

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.
package/client.js CHANGED
@@ -23,7 +23,7 @@ window.__ModuleLoader__.load({
23
23
  const REFRESH_MS = 3000
24
24
  const MAX_ROWS = 240
25
25
  /** Bump together with package.json so a stale browser bundle is obvious. */
26
- const BUILD = '0.7.0+sticky'
26
+ const BUILD = '0.7.1+sticky'
27
27
  /** Set by apply(): opens another Session in the main column. */
28
28
  let openSessionBridge = null
29
29
  /** Set by apply(): opens the Timeback tab in the right sidebar. */
@@ -100,7 +100,27 @@ window.__ModuleLoader__.load({
100
100
  'board.subtitle': '全局 Markdown 记录板 · 回溯时一起恢复',
101
101
  'board.newSticky': '新建便签',
102
102
  'board.stickyHint': '便签可拖动;画笔可在方格纸背景或便签上绘制,橡皮擦除笔画。',
103
+ 'board.resizeNote': '拖动缩放便签',
104
+ 'board.drawOnSticky': '便签可画',
105
+ 'board.drawOnStickyOn': '便签可画:开',
106
+ 'board.drawOnStickyOff': '便签可画:关',
107
+ 'board.drawOnStickyHint': '开启后画笔/图形可直接画在便签上;关闭则只画在方格纸背景。',
108
+ 'board.center': '自动调整',
109
+ 'board.reader': '阅读 md',
110
+ 'board.close': '关闭',
103
111
  'board.toolSelect': '拖动',
112
+ 'board.shapeRect': '矩形',
113
+ 'board.shapeEllipse': '圆形',
114
+ 'board.shapeLine': '直线',
115
+ 'board.shapeArrow': '箭头',
116
+ 'board.shapeTriangle': '三角形',
117
+ 'board.toolLink': '路径',
118
+ 'board.commonShapes': '常用图形',
119
+ 'board.brushSize': '粗细',
120
+ 'board.anchorsHint': '路径工具:从便签四角的吸附点拖到另一张便签,形成图结构;点路径可删除。',
121
+ 'board.clearEdges': '清路径',
122
+ 'board.edgeDeleteConfirm': '删除这条路径?',
123
+ 'board.panHint': '拖动工具下按住空白方格纸可平移画布',
104
124
  'board.toolPen': '画笔',
105
125
  'board.toolEraser': '橡皮',
106
126
  'board.clearBg': '清背景笔迹',
@@ -110,6 +130,16 @@ window.__ModuleLoader__.load({
110
130
  'board.mdBelow': '记录板内容(Markdown)',
111
131
  'board.canvasVersion': '便签板 v{version}',
112
132
  'board.color': '颜色',
133
+ 'board.colorTitle': '选择颜色',
134
+ 'board.commonColors': '常用颜色',
135
+ 'board.recentColors': '近期使用',
136
+ 'board.customColor': '自定义颜色',
137
+ 'board.rgb': 'RGB',
138
+ 'board.eyedropper': '屏幕取色',
139
+ 'board.eyedropperHint': '从屏幕任意位置吸取颜色(需要 Chrome/Edge 等支持 EyeDropper 的浏览器)',
140
+ 'board.eyedropperUnsupported': '当前浏览器不支持屏幕取色,请使用「自定义颜色」里的系统取色器或手动输入 HEX。',
141
+ 'board.eyedropperInsecure': '屏幕取色需要 https 或 localhost 环境;当前页面不是安全上下文。',
142
+ 'board.eyedropperFailed': '取色被取消或失败:{error}',
113
143
  'board.new': '新建记录',
114
144
  'board.edit': '编辑',
115
145
  'board.delete': '删除',
@@ -288,7 +318,27 @@ window.__ModuleLoader__.load({
288
318
  'board.subtitle': 'Global Markdown notes · rewinds restore them too',
289
319
  'board.newSticky': 'New sticky',
290
320
  'board.stickyHint': 'Sticky notes are draggable; draw on the grid or on a note, erase strokes with the eraser.',
321
+ 'board.resizeNote': 'Drag to resize the sticky',
322
+ 'board.drawOnSticky': 'Draw on stickies',
323
+ 'board.drawOnStickyOn': 'Sticky drawing: on',
324
+ 'board.drawOnStickyOff': 'Sticky drawing: off',
325
+ 'board.drawOnStickyHint': 'When on, pen/shape tools draw directly on sticky notes; when off they only draw on the grid.',
326
+ 'board.center': 'Auto fit',
327
+ 'board.reader': 'Read md',
328
+ 'board.close': 'Close',
291
329
  'board.toolSelect': 'Move',
330
+ 'board.shapeRect': 'Rectangle',
331
+ 'board.shapeEllipse': 'Ellipse',
332
+ 'board.shapeLine': 'Line',
333
+ 'board.shapeArrow': 'Arrow',
334
+ 'board.shapeTriangle': 'Triangle',
335
+ 'board.toolLink': 'Link',
336
+ 'board.commonShapes': 'Shapes',
337
+ 'board.brushSize': 'Size',
338
+ 'board.anchorsHint': 'Link tool: drag from a sticky anchor to another sticky to build a graph; click a link to delete it.',
339
+ 'board.clearEdges': 'Clear links',
340
+ 'board.edgeDeleteConfirm': 'Delete this link?',
341
+ 'board.panHint': 'With the Move tool, drag on empty grid to pan the canvas',
292
342
  'board.toolPen': 'Pen',
293
343
  'board.toolEraser': 'Eraser',
294
344
  'board.clearBg': 'Clear drawings',
@@ -298,6 +348,16 @@ window.__ModuleLoader__.load({
298
348
  'board.mdBelow': 'Board contents (Markdown)',
299
349
  'board.canvasVersion': 'Board v{version}',
300
350
  'board.color': 'Colour',
351
+ 'board.colorTitle': 'Pick a colour',
352
+ 'board.commonColors': 'Common colours',
353
+ 'board.recentColors': 'Recent',
354
+ 'board.customColor': 'Custom colour',
355
+ 'board.rgb': 'RGB',
356
+ 'board.eyedropper': 'Pick from screen',
357
+ 'board.eyedropperHint': 'Sample any colour from the screen (Chrome/Edge and other EyeDropper-capable browsers)',
358
+ 'board.eyedropperUnsupported': 'This browser does not support screen sampling; use the system picker under Custom colour or type a HEX value.',
359
+ 'board.eyedropperInsecure': 'Screen sampling needs https or localhost; this page is not a secure context.',
360
+ 'board.eyedropperFailed': 'Colour picking was cancelled or failed: {error}',
301
361
  'board.new': 'New note',
302
362
  'board.edit': 'Edit',
303
363
  'board.delete': 'Delete',
@@ -519,14 +579,43 @@ window.__ModuleLoader__.load({
519
579
  .tb-board-testid{display:none}
520
580
  .tb-board-toolbar{display:flex;align-items:center;gap:6px;flex-wrap:wrap;padding:6px 12px;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.08))}
521
581
  .tb-tool{appearance:none;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:transparent;color:var(--dsw-alias-label-secondary,#9aa0a6);border-radius:6px;padding:3px 8px;font-size:11.5px;cursor:pointer;line-height:1.4}
582
+ .tb-shape-wrap{position:relative;display:inline-flex}
583
+ .tb-shape-menu{position:absolute;top:calc(100% + 4px);left:0;z-index:40;display:flex;flex-direction:column;gap:2px;min-width:148px;padding:4px;border-radius:8px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:var(--dsw-alias-bg-layer-2,rgba(24,28,36,.98));box-shadow:0 10px 24px rgba(0,0,0,.35)}
584
+ .tb-shape-menu button{appearance:none;border:0;background:transparent;color:var(--dsw-alias-label-primary,#e6e6e6);text-align:left;padding:5px 8px;border-radius:5px;font-size:11.5px;cursor:pointer;white-space:nowrap}
585
+ .tb-shape-menu button:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(255,255,255,.1))}
586
+ .tb-size-range{width:82px;accent-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
522
587
  .tb-tool.on{color:var(--dsw-alias-label-primary,#e6e6e6);border-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.08))}
588
+ .tb-color-wrap{position:relative;display:inline-flex}
589
+ .tb-color-btn{width:26px;height:22px;border-radius:6px;border:2px solid var(--dsw-alias-border-l2,rgba(255,255,255,.3));cursor:pointer;padding:0;box-shadow:inset 0 0 0 1px rgba(0,0,0,.25)}
590
+ .tb-color-panel{position:absolute;top:calc(100% + 4px);left:0;z-index:45;width:248px;padding:8px;border-radius:9px;border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));background:var(--dsw-alias-bg-layer-2,rgba(24,28,36,.99));box-shadow:0 12px 30px rgba(0,0,0,.4);display:flex;flex-direction:column;gap:7px}
591
+ .tb-color-row{display:flex;align-items:center;gap:5px;flex-wrap:wrap}
592
+ .tb-color-label{font-size:10.5px;color:var(--dsw-alias-label-secondary,#9aa0a6);min-width:56px}
593
+ .tb-color-grid{display:grid;grid-template-columns:repeat(8,1fr);gap:4px}
594
+ .tb-color-grid button{width:100%;aspect-ratio:1;border-radius:4px;border:1px solid rgba(255,255,255,.22);cursor:pointer;padding:0}
595
+ .tb-rgb-row{display:flex;align-items:center;gap:4px;font-size:10.5px;color:var(--dsw-alias-label-secondary,#9aa0a6)}
596
+ .tb-rgb-row input[type=range]{flex:1;min-width:40px;accent-color:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
597
+ .tb-hex-row{display:flex;align-items:center;gap:5px}
598
+ .tb-hex-row input[type=text]{flex:1;min-width:0;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.05));color:var(--dsw-alias-label-primary,#e6e6e6);border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.16));border-radius:5px;padding:3px 6px;font-size:11px;font-family:ui-monospace,monospace}
523
599
  .tb-swatch{width:18px;height:18px;border-radius:50%;border:2px solid transparent;cursor:pointer;padding:0}
524
600
  .tb-swatch.on{border-color:var(--dsw-alias-label-primary,#e6e6e6);box-shadow:0 0 0 2px rgba(0,0,0,.3)}
525
- .tb-board-canvas{position:relative;flex:1;min-height:240px;overflow:auto;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));background-color:var(--dsw-alias-bg-base,#16181d);background-image:linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px);background-size:22px 22px,22px 22px,110px 110px,110px 110px;cursor:crosshair}
526
- .tb-board-canvas.select{cursor:default}
527
- .tb-board-stage{position:relative;width:1800px;height:1200px}
601
+ .tb-board-canvas{position:relative;touch-action:none;flex:1;min-height:240px;overflow:auto;border-bottom:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));background:var(--dsw-alias-bg-base,#16181d);cursor:crosshair}
602
+ .tb-board-canvas.select{cursor:grab}
603
+ .tb-board-canvas.draw,.tb-board-canvas.draw .tb-sticky{cursor:crosshair}
604
+ .tb-board-canvas.link,.tb-board-canvas.link .tb-sticky{cursor:crosshair}
605
+ .tb-anchor{position:absolute;width:9px;height:9px;border-radius:50%;background:var(--dsw-alias-bg-base,#16181d);border:2px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);z-index:7;display:none;box-sizing:border-box;transform:translate(-50%,-50%)}
606
+ .tb-board-stage.show-anchors .tb-anchor{display:block}
607
+ .tb-anchor:hover{background:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6)}
608
+ .tb-board-edges{position:absolute;left:0;top:0;pointer-events:none;overflow:visible;z-index:1}
609
+ .tb-board-edge-path{fill:none;stroke-width:2;opacity:.7;pointer-events:stroke}
610
+ .tb-board-edge-path:hover{opacity:1;stroke-width:3}
611
+ .tb-board-edge-dot{fill:var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);stroke:none}
612
+ .tb-board-edge-preview{fill:none;stroke-dasharray:6 5;stroke-width:2;opacity:.7}
613
+ .tb-board-canvas.draw .tb-sticky-resize{cursor:nwse-resize}
614
+ .tb-board-canvas.select:active{cursor:grabbing}
615
+ .tb-board-world{position:relative;flex:none}
616
+ .tb-board-stage{position:absolute;left:0;top:0;transform-origin:0 0;background-color:var(--dsw-alias-bg-base,#16181d);background-image:linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.07)) 1px,transparent 1px),linear-gradient(to right,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px),linear-gradient(to bottom,var(--dsw-alias-border-l2,rgba(255,255,255,.12)) 1px,transparent 1px);background-size:22px 22px,22px 22px,110px 110px,110px 110px}
528
617
  .tb-board-bgdraw{position:absolute;left:0;top:0;pointer-events:none;overflow:visible}
529
- .tb-sticky{position:absolute;width:232px;height:176px;box-sizing:border-box;border-radius:5px;padding:8px 9px;display:flex;flex-direction:column;gap:5px;color:#2a2418;box-shadow:0 6px 16px rgba(0,0,0,.28);border:1px solid rgba(0,0,0,.18);overflow:hidden;cursor:grab;user-select:none}
618
+ .tb-sticky{position:absolute;width:232px;height:176px;min-width:160px;min-height:120px;box-sizing:border-box;border-radius:5px;padding:8px 9px;display:flex;flex-direction:column;gap:5px;color:#2a2418;box-shadow:0 6px 16px rgba(0,0,0,.28);border:1px solid rgba(0,0,0,.18);overflow:hidden;cursor:grab;user-select:none}
530
619
  .tb-sticky:active{cursor:grabbing}
531
620
  .tb-sticky.selected{outline:2px solid var(--dsw-alias-brand-primary-new-colorprimary-new-color,#4176e6);outline-offset:1px}
532
621
  .tb-sticky.link{border-style:dashed;cursor:pointer}
@@ -535,11 +624,17 @@ window.__ModuleLoader__.load({
535
624
  .tb-sticky-actions{display:flex;gap:3px;opacity:.65}
536
625
  .tb-sticky-actions button{appearance:none;border:0;background:rgba(0,0,0,.08);border-radius:4px;font-size:10px;line-height:16px;padding:0 4px;cursor:pointer;color:#2a2418}
537
626
  .tb-sticky-actions button:hover{background:rgba(0,0,0,.16)}
538
- .tb-sticky-body{flex:1;min-height:0;overflow:hidden;font-size:11px;line-height:1.45;color:#3a3326;word-break:break-word;position:relative;z-index:2}
627
+ .tb-sticky-body{flex:1;min-height:0;overflow:hidden;font-size:11px;line-height:1.45;color:#3a3326;word-break:break-word;position:relative;z-index:2;pointer-events:none}
539
628
  .tb-sticky-body.md{display:-webkit-box;-webkit-line-clamp:5;-webkit-box-orient:vertical}
540
629
  .tb-sticky-linkline{display:flex;align-items:center;gap:6px;font-size:12px;font-weight:600;color:#1c4d8f;text-decoration:underline;cursor:pointer;background:rgba(255,255,255,.35);border-radius:5px;padding:6px 8px}
541
630
  .tb-sticky-src{font-size:9.5px;font-weight:600;opacity:.6;white-space:nowrap}
542
- .tb-sticky-draw{position:absolute;inset:0;pointer-events:none;z-index:1}
631
+ .tb-sticky-draw{position:absolute;inset:0;pointer-events:none;z-index:3}
632
+ .tb-sticky-head{position:relative;z-index:4}
633
+ .tb-sticky-resize{position:absolute;right:0;bottom:0;width:16px;height:16px;cursor:nwse-resize;z-index:6;opacity:.55}
634
+ .tb-sticky-resize:after{content:"";position:absolute;right:3px;bottom:3px;width:8px;height:8px;border-right:2px solid rgba(0,0,0,.45);border-bottom:2px solid rgba(0,0,0,.45)}
635
+ .tb-sticky:hover .tb-sticky-resize{opacity:.9}
636
+ .tb-sticky-linkline,.tb-sticky-actions{position:relative;z-index:4}
637
+ .tb-board-bgdraw rect,.tb-board-bgdraw ellipse,.tb-board-bgdraw polygon,.tb-board-bgdraw line,.tb-sticky-draw rect,.tb-sticky-draw ellipse,.tb-sticky-draw polygon,.tb-sticky-draw line,.tb-board-bgdraw polyline,.tb-sticky-draw polyline{vector-effect:non-scaling-stroke}
543
638
  .tb-board-md-pane{flex:0 0 36%;min-height:140px;overflow:auto;padding:8px 12px 20px;display:flex;flex-direction:column;gap:8px;background:var(--dsw-alias-bg-base,#16181d)}
544
639
  .tb-board-md-head{font-size:11px;color:var(--dsw-alias-label-secondary,#9aa0a6);position:sticky;top:0;background:var(--dsw-alias-bg-base,#16181d);padding:2px 0;z-index:1}
545
640
  .tb-board-md-item{border:1px solid var(--dsw-alias-border-l2,rgba(255,255,255,.12));border-radius:8px;padding:8px 10px;display:flex;flex-direction:column;gap:5px;background:var(--dsw-alias-bg-layer-1,rgba(255,255,255,.03))}
@@ -2756,13 +2851,32 @@ window.__ModuleLoader__.load({
2756
2851
 
2757
2852
  const BOARD_NOTE_W = 232
2758
2853
  const BOARD_NOTE_H = 176
2759
- const BOARD_STAGE_W = 1800
2760
- const BOARD_STAGE_H = 1200
2854
+ const BOARD_STAGE_W = 4000
2855
+ const BOARD_STAGE_H = 3000
2761
2856
  const BOARD_COLORS = ['#e6b84c', '#ff8f7a', '#7ad3ff', '#8be28b', '#d9a8ff', '#ffffff']
2762
- const BOARD_INKS = ['#e6b84c', '#ff7a7a', '#7ad3ff', '#8be28b', '#ffffff']
2857
+ const BOARD_INKS = [
2858
+ '#e6b84c', '#ff7a7a', '#7ad3ff', '#8be28b', '#d9a8ff', '#ffffff',
2859
+ '#ff9f43', '#ff6b81', '#54a0ff', '#00d2d3', '#10ac84', '#f368e0',
2860
+ '#576574', '#222f3e', '#feca57', '#48dbfb',
2861
+ ]
2862
+
2863
+ /** #rrggbb -> [r,g,b]. */
2864
+ function hexToRgb(value) {
2865
+ const match = /^#?([0-9a-f]{6})$/i.exec(String(value || '').trim())
2866
+ if (!match) return [255, 255, 255]
2867
+ const number = parseInt(match[1], 16)
2868
+ return [(number >> 16) & 255, (number >> 8) & 255, number & 255]
2869
+ }
2870
+
2871
+ /** [r,g,b] -> #rrggbb. */
2872
+ function rgbToHex(rgb) {
2873
+ return `#${rgb.map((value) => Math.min(255, Math.max(0, Math.round(Number(value) || 0))).toString(16).padStart(2, '0')).join('')}`
2874
+ }
2875
+
2876
+ const BOARD_ANCHORS = ['top', 'right', 'bottom', 'left']
2763
2877
 
2764
2878
  function emptyBoardCanvas() {
2765
- return { notes: {}, background: [], drawings: {} }
2879
+ return { notes: {}, background: [], drawings: {}, edges: [] }
2766
2880
  }
2767
2881
 
2768
2882
  /** Deep-copy the sticky canvas so React sees new references. */
@@ -2781,21 +2895,147 @@ window.__ModuleLoader__.load({
2781
2895
  drawings: Object.fromEntries(
2782
2896
  Object.entries(canvas.drawings && typeof canvas.drawings === 'object' ? canvas.drawings : {}).map(([id, strokes]) => [id, copyStrokes(strokes)]),
2783
2897
  ),
2898
+ edges: (Array.isArray(canvas.edges) ? canvas.edges : []).map((edge) => ({
2899
+ ...edge,
2900
+ from: { ...(edge.from ?? {}) },
2901
+ to: { ...(edge.to ?? {}) },
2902
+ })),
2903
+ }
2904
+ }
2905
+
2906
+ /** World coordinates of one sticky anchor point. */
2907
+ function boardAnchorPoint(layout, anchor) {
2908
+ const x = Number(layout?.x) || 0
2909
+ const y = Number(layout?.y) || 0
2910
+ const width = Math.min(640, Math.max(160, Number(layout?.width) || BOARD_NOTE_W))
2911
+ const height = Math.min(560, Math.max(120, Number(layout?.height) || BOARD_NOTE_H))
2912
+ if (anchor === 'top') return [x + width / 2, y]
2913
+ if (anchor === 'right') return [x + width, y + height / 2]
2914
+ if (anchor === 'bottom') return [x + width / 2, y + height]
2915
+ return [x, y + height / 2]
2916
+ }
2917
+
2918
+ /** Nearest anchor id to a world point. */
2919
+ function nearestBoardAnchor(layout, point) {
2920
+ let best = BOARD_ANCHORS[0]
2921
+ let bestDistance = Infinity
2922
+ for (const anchor of BOARD_ANCHORS) {
2923
+ const [x, y] = boardAnchorPoint(layout, anchor)
2924
+ const distance = Math.hypot(x - point[0], y - point[1])
2925
+ if (distance < bestDistance) {
2926
+ bestDistance = distance
2927
+ best = anchor
2928
+ }
2929
+ }
2930
+ return best
2931
+ }
2932
+
2933
+ /** Cubic path between two anchor points (same path in both directions). */
2934
+ function boardEdgePath(from, to) {
2935
+ let [x1, y1] = from
2936
+ let [x2, y2] = to
2937
+ if (x1 > x2 || (x1 === x2 && y1 > y2)) {
2938
+ ;[x1, x2] = [x2, x1]
2939
+ ;[y1, y2] = [y2, y1]
2784
2940
  }
2941
+ const dx = Math.max(24, Math.abs(x2 - x1) * 0.4)
2942
+ const dy = Math.max(20, Math.abs(y2 - y1) * 0.25)
2943
+ return `M ${x1} ${y1} C ${x1 + dx} ${y1 + (y2 >= y1 ? dy : -dy)}, ${x2 - dx} ${y2 + (y1 >= y2 ? dy : -dy)}, ${x2} ${y2}`
2785
2944
  }
2786
2945
 
2787
- /** SVG polylines for one stroke layer. */
2788
- function boardPolylines(strokes, keyPrefix) {
2789
- return (strokes ?? []).map((stroke, index) =>
2790
- h('polyline', {
2791
- key: `${keyPrefix}-${index}`,
2792
- points: stroke.points.map((point) => `${point[0]},${point[1]}`).join(' '),
2946
+ /** Arrowhead polygon points for one arrow stroke. */
2947
+ function boardArrowHead(first, last, size) {
2948
+ const dx = last[0] - first[0]
2949
+ const dy = last[1] - first[1]
2950
+ const length = Math.hypot(dx, dy)
2951
+ if (length < 1) return ''
2952
+ const ux = dx / length
2953
+ const uy = dy / length
2954
+ const px = -uy
2955
+ const py = ux
2956
+ const head = Math.min(18, Math.max(8, size * 4))
2957
+ const width = head * 0.55
2958
+ const p1 = `${last[0] - ux * head + px * width},${last[1] - uy * head + py * width}`
2959
+ const p2 = `${last[0] - ux * head - px * width},${last[1] - uy * head - py * width}`
2960
+ return `${last[0]},${last[1]} ${p1} ${p2}`
2961
+ }
2962
+
2963
+ /** Render pen strokes and common shapes for one stroke layer. */
2964
+ function boardStrokeElements(strokes, keyPrefix) {
2965
+ return (strokes ?? []).map((stroke, index) => {
2966
+ const key = `${keyPrefix}-${index}`
2967
+ const points = stroke.points ?? []
2968
+ const kind = stroke.kind || 'pen'
2969
+ const color = stroke.color
2970
+ const width = stroke.width
2971
+ if (kind === 'pen' || points.length < 2) {
2972
+ return h('polyline', {
2973
+ key,
2974
+ points: points.map((point) => `${point[0]},${point[1]}`).join(' '),
2975
+ fill: 'none',
2976
+ stroke: color,
2977
+ strokeWidth: width,
2978
+ strokeLinecap: 'round',
2979
+ strokeLinejoin: 'round',
2980
+ })
2981
+ }
2982
+ const a = points[0]
2983
+ const b = points[1]
2984
+ const x = Math.min(a[0], b[0])
2985
+ const y = Math.min(a[1], b[1])
2986
+ const w = Math.abs(b[0] - a[0])
2987
+ const hgt = Math.abs(b[1] - a[1])
2988
+ if (kind === 'rect') {
2989
+ return h('rect', { key, x, y, width: w, height: hgt, rx: 2, fill: 'none', stroke: color, strokeWidth: width })
2990
+ }
2991
+ if (kind === 'ellipse') {
2992
+ return h('ellipse', { key, cx: x + w / 2, cy: y + hgt / 2, rx: w / 2, ry: hgt / 2, fill: 'none', stroke: color, strokeWidth: width })
2993
+ }
2994
+ if (kind === 'line') {
2995
+ return h('line', { key, x1: a[0], y1: a[1], x2: b[0], y2: b[1], stroke: color, strokeWidth: width, strokeLinecap: 'round' })
2996
+ }
2997
+ if (kind === 'triangle') {
2998
+ return h('polygon', {
2999
+ key,
3000
+ points: `${(a[0] + b[0]) / 2},${y} ${x},${y + hgt} ${x + w},${y + hgt}`,
3001
+ fill: 'none',
3002
+ stroke: color,
3003
+ strokeWidth: width,
3004
+ strokeLinejoin: 'round',
3005
+ })
3006
+ }
3007
+ if (kind === 'arrow') {
3008
+ return h(
3009
+ 'g',
3010
+ { key },
3011
+ h('line', { x1: a[0], y1: a[1], x2: b[0], y2: b[1], stroke: color, strokeWidth: width, strokeLinecap: 'round' }),
3012
+ h('polygon', { points: boardArrowHead(a, b, width), fill: color, stroke: 'none' }),
3013
+ )
3014
+ }
3015
+ return h('polyline', {
3016
+ key,
3017
+ points: points.map((point) => `${point[0]},${point[1]}`).join(' '),
2793
3018
  fill: 'none',
2794
- stroke: stroke.color,
2795
- strokeWidth: stroke.width,
3019
+ stroke: color,
3020
+ strokeWidth: width,
2796
3021
  strokeLinecap: 'round',
2797
- strokeLinejoin: 'round',
2798
- }),
3022
+ })
3023
+ })
3024
+ }
3025
+
3026
+ /** Whether an eraser click hits one stroke. */
3027
+ function boardStrokeHit(stroke, point) {
3028
+ const points = stroke.points ?? []
3029
+ if ((stroke.kind || 'pen') === 'pen') {
3030
+ return points.some(([x, y]) => Math.hypot(x - point[0], y - point[1]) < 12)
3031
+ }
3032
+ if (points.length < 2) return false
3033
+ const [a, b] = points
3034
+ return (
3035
+ point[0] >= Math.min(a[0], b[0]) - 10 &&
3036
+ point[0] <= Math.max(a[0], b[0]) + 10 &&
3037
+ point[1] >= Math.min(a[1], b[1]) - 10 &&
3038
+ point[1] <= Math.max(a[1], b[1]) + 10
2799
3039
  )
2800
3040
  }
2801
3041
 
@@ -2805,11 +3045,21 @@ window.__ModuleLoader__.load({
2805
3045
  return {
2806
3046
  x: 24 + (index % columns) * (BOARD_NOTE_W + 20),
2807
3047
  y: 24 + Math.floor(index / columns) * (BOARD_NOTE_H + 20),
3048
+ width: BOARD_NOTE_W,
3049
+ height: BOARD_NOTE_H,
2808
3050
  z: index,
2809
3051
  color: BOARD_COLORS[index % BOARD_COLORS.length],
2810
3052
  }
2811
3053
  }
2812
3054
 
3055
+ const BOARD_SHAPES = [
3056
+ ['rect', '▭', 'board.shapeRect'],
3057
+ ['ellipse', '◯', 'board.shapeEllipse'],
3058
+ ['line', '╱', 'board.shapeLine'],
3059
+ ['arrow', '→', 'board.shapeArrow'],
3060
+ ['triangle', '△', 'board.shapeTriangle'],
3061
+ ]
3062
+
2813
3063
  function BoardPanel(props) {
2814
3064
  const t = typeof props?.t === 'function' ? props.t : (key) => key
2815
3065
  const [state, setState] = React.useState({ loading: true, board: null, error: null })
@@ -2836,13 +3086,57 @@ window.__ModuleLoader__.load({
2836
3086
  const [tool, setTool] = React.useState('select')
2837
3087
  const toolRef = React.useRef(tool)
2838
3088
  toolRef.current = tool
2839
- const [ink, setInk] = React.useState(BOARD_INKS[0])
3089
+ const [ink, setInk] = React.useState(() => {
3090
+ try {
3091
+ const stored = window.localStorage.getItem('dsh-timeback:board-ink-color') || ''
3092
+ return /^#[0-9a-f]{6}$/i.test(stored) ? stored.toLowerCase() : BOARD_INKS[0]
3093
+ } catch {
3094
+ return BOARD_INKS[0]
3095
+ }
3096
+ })
2840
3097
  const inkRef = React.useRef(ink)
2841
3098
  inkRef.current = ink
3099
+ const [inkWidth, setInkWidth] = React.useState(() => {
3100
+ try {
3101
+ const raw = Number(window.localStorage.getItem('dsh-timeback:board-ink-width'))
3102
+ return Number.isFinite(raw) && raw >= 1 && raw <= 8 ? Math.round(raw) : 2
3103
+ } catch {
3104
+ return 2
3105
+ }
3106
+ })
3107
+ const inkWidthRef = React.useRef(inkWidth)
3108
+ inkWidthRef.current = inkWidth
3109
+ const [shapeMenu, setShapeMenu] = React.useState(false)
3110
+ const [colorOpen, setColorOpen] = React.useState(false)
3111
+ const [colorHint, setColorHint] = React.useState('')
3112
+ const [recentColors, setRecentColors] = React.useState(() => {
3113
+ try {
3114
+ const raw = JSON.parse(window.localStorage.getItem('dsh-timeback:board-recent-colors') || '[]')
3115
+ return Array.isArray(raw) ? raw.filter((value) => /^#[0-9a-f]{6}$/i.test(String(value))).slice(0, 8) : []
3116
+ } catch {
3117
+ return []
3118
+ }
3119
+ })
2842
3120
  const [selected, setSelected] = React.useState('')
2843
3121
  const selectedRef = React.useRef(selected)
2844
3122
  selectedRef.current = selected
3123
+ const [readerId, setReaderId] = React.useState('')
3124
+ const [linkPreview, setLinkPreview] = React.useState(null)
3125
+ const [zoom, setZoom] = React.useState(1)
3126
+ const zoomRef = React.useRef(zoom)
3127
+ zoomRef.current = zoom
3128
+ const [drawOnSticky, setDrawOnSticky] = React.useState(() => {
3129
+ try {
3130
+ return window.localStorage.getItem('dsh-timeback:board-draw-on-sticky') !== '0'
3131
+ } catch {
3132
+ return true
3133
+ }
3134
+ })
3135
+ const drawOnStickyRef = React.useRef(drawOnSticky)
3136
+ drawOnStickyRef.current = drawOnSticky
3137
+ const centeredRef = React.useRef(false)
2845
3138
  const stageRef = React.useRef(null)
3139
+ const viewportRef = React.useRef(null)
2846
3140
  const saveTimerRef = React.useRef(null)
2847
3141
  const gestureRef = React.useRef(null)
2848
3142
 
@@ -2874,6 +3168,67 @@ window.__ModuleLoader__.load({
2874
3168
  if (saveTimerRef.current) clearTimeout(saveTimerRef.current)
2875
3169
  }, [])
2876
3170
 
3171
+ /** Fit every note/stroke into view: pick a zoom and scroll offset. */
3172
+ const autoFit = () => {
3173
+ const viewport = viewportRef.current
3174
+ if (!viewport) return
3175
+ const notes = (state.board?.entries ?? []).map((entry, index) => layoutFor(entry, index))
3176
+ let minX = Infinity
3177
+ let minY = Infinity
3178
+ let maxX = -Infinity
3179
+ let maxY = -Infinity
3180
+ const include = (x, y) => {
3181
+ if (Number.isFinite(x) && Number.isFinite(y)) {
3182
+ minX = Math.min(minX, x)
3183
+ minY = Math.min(minY, y)
3184
+ maxX = Math.max(maxX, x)
3185
+ maxY = Math.max(maxY, y)
3186
+ }
3187
+ }
3188
+ for (const layout of notes) {
3189
+ const size = noteSize(layout)
3190
+ include(Number(layout.x) || 0, Number(layout.y) || 0)
3191
+ include((Number(layout.x) || 0) + size.width, (Number(layout.y) || 0) + size.height)
3192
+ }
3193
+ const addStrokes = (strokes) => {
3194
+ for (const stroke of strokes ?? []) for (const point of stroke.points ?? []) include(point[0], point[1])
3195
+ }
3196
+ addStrokes(canvasRef.current.background)
3197
+ for (const strokes of Object.values(canvasRef.current.drawings ?? {})) addStrokes(strokes)
3198
+ if (!Number.isFinite(minX)) {
3199
+ minX = BOARD_STAGE_W / 2 - 300
3200
+ maxX = BOARD_STAGE_W / 2 + 300
3201
+ minY = BOARD_STAGE_H / 2 - 200
3202
+ maxY = BOARD_STAGE_H / 2 + 200
3203
+ }
3204
+ const spanX = Math.max(120, maxX - minX)
3205
+ const spanY = Math.max(120, maxY - minY)
3206
+ const nextZoom = Math.min(1.6, Math.max(0.2, Math.min((viewport.clientWidth - 40) / spanX, (viewport.clientHeight - 40) / spanY)))
3207
+ setZoom(nextZoom)
3208
+ zoomRef.current = nextZoom
3209
+ const centerX = (minX + maxX) / 2
3210
+ const centerY = (minY + maxY) / 2
3211
+ window.requestAnimationFrame(() => {
3212
+ const currentViewport = viewportRef.current
3213
+ if (!currentViewport) return
3214
+ currentViewport.scrollLeft = Math.max(0, centerX * nextZoom - currentViewport.clientWidth / 2)
3215
+ currentViewport.scrollTop = Math.max(0, centerY * nextZoom - currentViewport.clientHeight / 2)
3216
+ })
3217
+ }
3218
+
3219
+ React.useEffect(() => {
3220
+ if (!state.board || centeredRef.current) return
3221
+ centeredRef.current = true
3222
+ const frame = window.requestAnimationFrame(() => autoFit())
3223
+ return () => window.cancelAnimationFrame(frame)
3224
+ }, [state.board])
3225
+
3226
+ /** Read one Markdown note in a large overlay. */
3227
+ const openReader = (id) => {
3228
+ setSelected(id)
3229
+ setReaderId(id)
3230
+ }
3231
+
2877
3232
  /** Persist the canvas shortly after the last change (drag/draw). */
2878
3233
  const saveCanvasSoon = (next) => {
2879
3234
  canvasRef.current = next
@@ -2939,6 +3294,57 @@ window.__ModuleLoader__.load({
2939
3294
  const sortedEntries = [...entries].sort((left, right) => (right.updatedAt ?? 0) - (left.updatedAt ?? 0))
2940
3295
  const boardVersion = state.board?.version ?? 0
2941
3296
  const layoutFor = (entry, index) => canvas.notes[entry.id] ?? autoBoardLayout(index)
3297
+ const noteSize = (layout) => ({
3298
+ width: Math.min(640, Math.max(160, Number(layout?.width) || BOARD_NOTE_W)),
3299
+ height: Math.min(560, Math.max(120, Number(layout?.height) || BOARD_NOTE_H)),
3300
+ })
3301
+ /** Viewport client point -> unscaled stage coordinates. */
3302
+ const stagePoint = (event) => {
3303
+ const stage = stageRef.current
3304
+ if (!stage) return [event.clientX, event.clientY]
3305
+ const rect = stage.getBoundingClientRect()
3306
+ const scale = zoomRef.current || 1
3307
+ return [(event.clientX - rect.left) / scale, (event.clientY - rect.top) / scale]
3308
+ }
3309
+ /** Viewport rect of a sticky, as unscaled stage-relative offsets. */
3310
+ const noteOffsets = (element) => {
3311
+ const stage = stageRef.current
3312
+ if (!stage) return { left: 0, top: 0 }
3313
+ const stageRect = stage.getBoundingClientRect()
3314
+ const rect = element.getBoundingClientRect()
3315
+ const scale = zoomRef.current || 1
3316
+ return { left: (rect.left - stageRect.left) / scale, top: (rect.top - stageRect.top) / scale }
3317
+ }
3318
+ const offsetsFromRect = (rect) => {
3319
+ const stage = stageRef.current
3320
+ if (!stage) return { left: 0, top: 0 }
3321
+ const stageRect = stage.getBoundingClientRect()
3322
+ const scale = zoomRef.current || 1
3323
+ return { left: (rect.left - stageRect.left) / scale, top: (rect.top - stageRect.top) / scale }
3324
+ }
3325
+ const zoomScale = () => zoomRef.current || 1
3326
+
3327
+ /** Which layer (background or one sticky) is under the pointer. */
3328
+ const layerAt = (event) => {
3329
+ let element = event.target
3330
+ try {
3331
+ if (typeof document !== 'undefined' && typeof document.elementFromPoint === 'function') {
3332
+ element = document.elementFromPoint(event.clientX, event.clientY) || element
3333
+ }
3334
+ } catch {
3335
+ // elementFromPoint is a convenience; event.target is the fallback.
3336
+ }
3337
+ const noteElement = element?.closest?.('.tb-sticky')
3338
+ if (noteElement) {
3339
+ return {
3340
+ layer: 'note',
3341
+ noteId: noteElement.getAttribute('data-note-id') || '',
3342
+ rect: noteElement.getBoundingClientRect(),
3343
+ }
3344
+ }
3345
+ const stage = stageRef.current
3346
+ return stage ? { layer: 'background', noteId: '', rect: stage.getBoundingClientRect() } : null
3347
+ }
2942
3348
  const startCreate = () => setDraft({ id: '', title: '', body: '', preview: false, busy: false, error: null })
2943
3349
  const startEdit = (entry) => setDraft({ id: entry.id, title: entry.title, body: entry.body, preview: false, busy: false, error: null })
2944
3350
  const closeDraft = () => {
@@ -3003,28 +3409,243 @@ window.__ModuleLoader__.load({
3003
3409
  /* sticky canvas: drag notes and draw strokes */
3004
3410
  /* -------------------------------------------------------------- */
3005
3411
 
3412
+ /** Ctrl/Shift snapping: shapes stay square/circular, lines/arrows snap to 45°. */
3413
+ const snapShapeEnd = (gesture, world) => {
3414
+ const [sx, sy] = gesture.startWorld
3415
+ const dx = world[0] - sx
3416
+ const dy = world[1] - sy
3417
+ const ctrl = gesture.ctrl
3418
+ if (!ctrl) return world
3419
+ if (gesture.kind === 'line' || gesture.kind === 'arrow') {
3420
+ const length = Math.hypot(dx, dy)
3421
+ if (length < 1) return world
3422
+ const step = Math.PI / 4
3423
+ const angle = Math.round(Math.atan2(dy, dx) / step) * step
3424
+ return [Math.round(sx + Math.cos(angle) * length), Math.round(sy + Math.sin(angle) * length)]
3425
+ }
3426
+ const size = Math.max(Math.abs(dx), Math.abs(dy))
3427
+ return [sx + (dx < 0 ? -size : size), sy + (dy < 0 ? -size : size)]
3428
+ }
3429
+
3430
+ /**
3431
+ * Build the shape preview on BOTH layers: the background copy always, plus
3432
+ * one copy on every sticky the shape touched (so the sticky shows the
3433
+ * clipped part even when the pointer ends outside it).
3434
+ */
3435
+ const buildShapeCanvas = (gesture) => {
3436
+ const next = cloneBoardCanvas(gesture.baseCanvas)
3437
+ const start = gesture.startWorld
3438
+ const end = snapShapeEnd(gesture, gesture.endWorld)
3439
+ next.background.push({
3440
+ kind: gesture.kind,
3441
+ color: gesture.color,
3442
+ width: gesture.width,
3443
+ points: [start, end],
3444
+ })
3445
+ for (const [noteId, offset] of gesture.targets) {
3446
+ const local = [
3447
+ [start[0] - offset.left, start[1] - offset.top],
3448
+ [end[0] - offset.left, end[1] - offset.top],
3449
+ ]
3450
+ const list = [...(next.drawings[noteId] ?? [])]
3451
+ list.push({ kind: gesture.kind, color: gesture.color, width: gesture.width, points: local })
3452
+ next.drawings[noteId] = list
3453
+ }
3454
+ return next
3455
+ }
3456
+
3006
3457
  const setGesture = (gesture) => {
3007
3458
  gestureRef.current = gesture
3008
3459
  const move = (event) => {
3009
3460
  const current = gestureRef.current
3010
3461
  if (!current) return
3462
+ if (current.type === 'link') {
3463
+ const localPoint = stagePoint(event)
3464
+ const under = layerAt(event)
3465
+ let targetNoteId = ''
3466
+ let targetAnchor = ''
3467
+ if (under?.layer === 'note' && under.noteId && under.noteId !== current.fromNoteId) {
3468
+ const layout = canvasRef.current.notes[under.noteId] ?? autoBoardLayout(0)
3469
+ targetNoteId = under.noteId
3470
+ targetAnchor = nearestBoardAnchor(layout, localPoint)
3471
+ }
3472
+ setLinkPreview((previous) =>
3473
+ previous
3474
+ ? { ...previous, pointer: localPoint, targetNoteId, targetAnchor }
3475
+ : previous,
3476
+ )
3477
+ return
3478
+ }
3479
+ if (current.type === 'shape') {
3480
+ const under = layerAt(event)
3481
+ if (under?.layer === 'note' && drawOnStickyRef.current && under.noteId && !current.targets.has(under.noteId)) {
3482
+ current.targets.set(under.noteId, offsetsFromRect(under.rect))
3483
+ }
3484
+ current.endWorld = stagePoint(event)
3485
+ current.ctrl = event.ctrlKey || event.metaKey || event.shiftKey
3486
+ const next = buildShapeCanvas(current)
3487
+ canvasRef.current = next
3488
+ setCanvas(next)
3489
+ return
3490
+ }
3491
+ if (current.type === 'pan') {
3492
+ const viewport = viewportRef.current
3493
+ if (viewport) {
3494
+ viewport.scrollLeft = current.scrollLeft - (event.clientX - current.startX)
3495
+ viewport.scrollTop = current.scrollTop - (event.clientY - current.startY)
3496
+ }
3497
+ return
3498
+ }
3499
+ if (current.type === 'resize') {
3500
+ const scale = zoomScale()
3501
+ const width = Math.min(640, Math.max(160, Math.round(current.startW + (event.clientX - current.startX) / scale)))
3502
+ const height = Math.min(560, Math.max(120, Math.round(current.startH + (event.clientY - current.startY) / scale)))
3503
+ const next = cloneBoardCanvas(canvasRef.current)
3504
+ const layout = next.notes[current.noteId] ?? autoBoardLayout(0)
3505
+ layout.width = width
3506
+ layout.height = height
3507
+ next.notes[current.noteId] = layout
3508
+ canvasRef.current = next
3509
+ setCanvas(next)
3510
+ return
3511
+ }
3011
3512
  if (current.type === 'drag') {
3012
3513
  const next = cloneBoardCanvas(canvasRef.current)
3013
3514
  const layout = { ...(next.notes[current.noteId] ?? autoBoardLayout(0)) }
3014
- layout.x = Math.max(0, Math.min(BOARD_STAGE_W - BOARD_NOTE_W, current.originX + event.clientX - current.startX))
3015
- layout.y = Math.max(0, Math.min(BOARD_STAGE_H - BOARD_NOTE_H, current.originY + event.clientY - current.startY))
3515
+ const size = noteSize(layout)
3516
+ const scale = zoomScale()
3517
+ layout.x = Math.max(0, Math.min(BOARD_STAGE_W - size.width, current.originX + (event.clientX - current.startX) / scale))
3518
+ layout.y = Math.max(0, Math.min(BOARD_STAGE_H - size.height, current.originY + (event.clientY - current.startY) / scale))
3016
3519
  next.notes[current.noteId] = layout
3017
3520
  canvasRef.current = next
3018
3521
  setCanvas(next)
3019
3522
  return
3020
3523
  }
3021
- const point = [Math.round(event.clientX - current.rect.left), Math.round(event.clientY - current.rect.top)]
3524
+ const scale = zoomScale()
3525
+ const point = [Math.round((event.clientX - current.rect.left) / scale), Math.round((event.clientY - current.rect.top) / scale)]
3022
3526
  if (current.type === 'draw') {
3023
3527
  const stroke = current.stroke
3024
- const last = stroke.points[stroke.points.length - 1]
3025
- if (last && Math.abs(last[0] - point[0]) + Math.abs(last[1] - point[1]) < 2) return
3026
- if (stroke.points.length >= 800) return
3027
- stroke.points.push(point)
3528
+ if (!current.shape) {
3529
+ const under = layerAt(event)
3530
+ const changed =
3531
+ under &&
3532
+ (under.layer !== current.layer || (under.layer === 'note' && under.noteId !== current.noteId)) &&
3533
+ !(under.layer === 'note' && !drawOnStickyRef.current)
3534
+ if (changed) {
3535
+ const previous = current.lastWorld ?? [event.clientX, event.clientY]
3536
+ const crossScale = zoomScale()
3537
+ const local = [
3538
+ Math.round((previous[0] - under.rect.left) / crossScale),
3539
+ Math.round((previous[1] - under.rect.top) / crossScale),
3540
+ ]
3541
+ const localCurrent = [
3542
+ Math.round((event.clientX - under.rect.left) / crossScale),
3543
+ Math.round((event.clientY - under.rect.top) / crossScale),
3544
+ ]
3545
+ const next = cloneBoardCanvas(canvasRef.current)
3546
+ // Extend the old stroke to the crossing point so the sticky edge
3547
+ // is not left with a gap (the sticky's own SVG clips it).
3548
+ const oldLocal = [
3549
+ Math.round((event.clientX - current.rect.left) / crossScale),
3550
+ Math.round((event.clientY - current.rect.top) / crossScale),
3551
+ ]
3552
+ const oldLast = stroke.points[stroke.points.length - 1]
3553
+ if (!oldLast || oldLast[0] !== oldLocal[0] || oldLast[1] !== oldLocal[1]) stroke.points.push(oldLocal)
3554
+ if (current.layer === 'background') {
3555
+ next.background = [...next.background]
3556
+ next.background[current.strokeIndex] = { ...stroke, points: stroke.points.map((item) => [...item]) }
3557
+ } else {
3558
+ const list = [...(next.drawings[current.noteId] ?? [])]
3559
+ list[current.strokeIndex] = { ...stroke, points: stroke.points.map((item) => [...item]) }
3560
+ next.drawings[current.noteId] = list
3561
+ }
3562
+ const nextStroke = {
3563
+ kind: 'pen',
3564
+ color: stroke.color,
3565
+ width: stroke.width,
3566
+ points: local[0] === localCurrent[0] && local[1] === localCurrent[1] ? [local] : [local, localCurrent],
3567
+ }
3568
+ let nextIndex
3569
+ if (under.layer === 'background') {
3570
+ nextIndex = next.background.length
3571
+ next.background.push(nextStroke)
3572
+ } else {
3573
+ const list = [...(next.drawings[under.noteId] ?? [])]
3574
+ nextIndex = list.length
3575
+ list.push(nextStroke)
3576
+ next.drawings[under.noteId] = list
3577
+ }
3578
+ current.layer = under.layer
3579
+ current.noteId = under.noteId
3580
+ current.rect = under.rect
3581
+ current.stroke = nextStroke
3582
+ current.strokeIndex = nextIndex
3583
+ current.lastWorld = [event.clientX, event.clientY]
3584
+ canvasRef.current = next
3585
+ setCanvas(next)
3586
+ return
3587
+ }
3588
+ }
3589
+ if (current.shape) {
3590
+ const underShape = layerAt(event)
3591
+ const shapeChanged =
3592
+ underShape &&
3593
+ (underShape.layer !== current.layer || (underShape.layer === 'note' && underShape.noteId !== current.noteId)) &&
3594
+ !(underShape.layer === 'note' && !drawOnStickyRef.current)
3595
+ if (shapeChanged) {
3596
+ const startWorld = current.startWorld ?? [event.clientX, event.clientY]
3597
+ const next = cloneBoardCanvas(canvasRef.current)
3598
+ if (current.layer === 'background') {
3599
+ next.background = next.background.filter((_, index) => index !== current.strokeIndex)
3600
+ } else {
3601
+ const list = (next.drawings[current.noteId] ?? []).filter((_, index) => index !== current.strokeIndex)
3602
+ if (list.length > 0) next.drawings[current.noteId] = list
3603
+ else delete next.drawings[current.noteId]
3604
+ }
3605
+ current.layer = underShape.layer
3606
+ current.noteId = underShape.noteId
3607
+ current.rect = underShape.rect
3608
+ stroke.points = [
3609
+ [startWorld[0] - underShape.rect.left, startWorld[1] - underShape.rect.top],
3610
+ [event.clientX - underShape.rect.left, event.clientY - underShape.rect.top],
3611
+ ]
3612
+ let nextIndex
3613
+ if (underShape.layer === 'background') {
3614
+ nextIndex = next.background.length
3615
+ next.background.push(stroke)
3616
+ } else {
3617
+ const list = [...(next.drawings[underShape.noteId] ?? [])]
3618
+ nextIndex = list.length
3619
+ list.push(stroke)
3620
+ next.drawings[underShape.noteId] = list
3621
+ }
3622
+ current.strokeIndex = nextIndex
3623
+ canvasRef.current = next
3624
+ setCanvas(next)
3625
+ return
3626
+ }
3627
+ const startPoint = stroke.points[0]
3628
+ const ctrl = event.ctrlKey || event.metaKey || event.shiftKey
3629
+ const dx = point[0] - startPoint[0]
3630
+ const dy = point[1] - startPoint[1]
3631
+ if (ctrl && (current.stroke.kind === 'line' || current.stroke.kind === 'arrow')) {
3632
+ // Ctrl/Shift snaps lines and arrows to the nearest cardinal direction.
3633
+ stroke.points[1] = Math.abs(dx) >= Math.abs(dy)
3634
+ ? [point[0], startPoint[1]]
3635
+ : [startPoint[0], point[1]]
3636
+ } else if (ctrl) {
3637
+ const size = Math.max(Math.abs(dx), Math.abs(dy))
3638
+ stroke.points[1] = [startPoint[0] + (dx < 0 ? -size : size), startPoint[1] + (dy < 0 ? -size : size)]
3639
+ } else {
3640
+ stroke.points[1] = point
3641
+ }
3642
+ } else {
3643
+ const last = stroke.points[stroke.points.length - 1]
3644
+ if (last && Math.abs(last[0] - point[0]) + Math.abs(last[1] - point[1]) < 2) return
3645
+ if (stroke.points.length >= 800) return
3646
+ stroke.points.push(point)
3647
+ current.lastWorld = [event.clientX, event.clientY]
3648
+ }
3028
3649
  const next = cloneBoardCanvas(canvasRef.current)
3029
3650
  if (current.layer === 'background') {
3030
3651
  next.background = [...next.background]
@@ -3040,14 +3661,30 @@ window.__ModuleLoader__.load({
3040
3661
  eraseAt(current, point)
3041
3662
  }
3042
3663
  }
3043
- const finish = () => {
3664
+ const finish = (event) => {
3044
3665
  window.removeEventListener('pointermove', move)
3045
3666
  window.removeEventListener('pointerup', finish)
3046
3667
  window.removeEventListener('pointercancel', finish)
3047
3668
  const current = gestureRef.current
3048
3669
  gestureRef.current = null
3049
- if (current && current.type !== 'erase') saveCanvasSoon(cloneBoardCanvas(canvasRef.current))
3050
- else if (current) saveCanvasSoon(cloneBoardCanvas(canvasRef.current))
3670
+ if (current && current.type === 'link') {
3671
+ setLinkPreview(null)
3672
+ const under = event ? layerAt(event) : null
3673
+ if (!under || under.layer !== 'note' || !under.noteId || under.noteId === current.fromNoteId) return
3674
+ const localPoint = stagePoint(event)
3675
+ const layout = canvasRef.current.notes[under.noteId] ?? autoBoardLayout(0)
3676
+ const anchor = nearestBoardAnchor(layout, localPoint)
3677
+ const next = cloneBoardCanvas(canvasRef.current)
3678
+ next.edges.push({
3679
+ id: `eg-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 7)}`,
3680
+ from: { noteId: current.fromNoteId, anchor: current.fromAnchor },
3681
+ to: { noteId: under.noteId, anchor },
3682
+ color: inkRef.current,
3683
+ })
3684
+ saveCanvasSoon(next)
3685
+ return
3686
+ }
3687
+ if (current && current.type !== 'pan') saveCanvasSoon(cloneBoardCanvas(canvasRef.current))
3051
3688
  }
3052
3689
  window.addEventListener('pointermove', move)
3053
3690
  window.addEventListener('pointerup', finish)
@@ -3057,7 +3694,7 @@ window.__ModuleLoader__.load({
3057
3694
  const eraseAt = (gesture, point) => {
3058
3695
  const next = cloneBoardCanvas(canvasRef.current)
3059
3696
  const list = gesture.layer === 'background' ? [...next.background] : [...(next.drawings[gesture.noteId] ?? [])]
3060
- const kept = list.filter((stroke) => !stroke.points.some(([x, y]) => Math.hypot(x - point[0], y - point[1]) < 12))
3697
+ const kept = list.filter((stroke) => !boardStrokeHit(stroke, point))
3061
3698
  if (kept.length === list.length) return
3062
3699
  if (gesture.layer === 'background') next.background = kept
3063
3700
  else if (kept.length > 0) next.drawings[gesture.noteId] = kept
@@ -3068,14 +3705,50 @@ window.__ModuleLoader__.load({
3068
3705
 
3069
3706
  const beginPointer = (event) => {
3070
3707
  if (event.button !== 0) return
3071
- if (event.target?.closest?.('button')) return
3708
+ if (event.target?.closest?.('button') || event.target?.closest?.('.tb-sticky-linkline') || event.target?.closest?.('.tb-sticky-actions')) return
3072
3709
  const stage = stageRef.current
3073
3710
  if (!stage) return
3074
3711
  const noteElement = event.target?.closest?.('.tb-sticky')
3075
3712
  const noteId = noteElement?.getAttribute?.('data-note-id') || ''
3713
+ if (toolRef.current === 'link') {
3714
+ event.preventDefault()
3715
+ if (!noteId) return
3716
+ const localPoint = stagePoint(event)
3717
+ const layout = canvasRef.current.notes[noteId] ?? autoBoardLayout(0)
3718
+ const anchorElement = event.target?.closest?.('.tb-anchor')
3719
+ const anchor = anchorElement?.getAttribute?.('data-anchor') || nearestBoardAnchor(layout, localPoint)
3720
+ setLinkPreview({ fromNoteId: noteId, fromAnchor: anchor, pointer: localPoint, targetNoteId: '', targetAnchor: '' })
3721
+ setGesture({ type: 'link', fromNoteId: noteId, fromAnchor: anchor })
3722
+ return
3723
+ }
3724
+ if (noteId && event.target?.closest?.('.tb-sticky-resize')) {
3725
+ event.preventDefault()
3726
+ event.stopPropagation()
3727
+ setSelected(noteId)
3728
+ const layout = canvasRef.current.notes[noteId] ?? autoBoardLayout(0)
3729
+ const size = noteSize(layout)
3730
+ setGesture({
3731
+ type: 'resize',
3732
+ noteId,
3733
+ startX: event.clientX,
3734
+ startY: event.clientY,
3735
+ startW: size.width,
3736
+ startH: size.height,
3737
+ })
3738
+ return
3739
+ }
3076
3740
  if (toolRef.current === 'select') {
3077
3741
  if (!noteId) {
3742
+ event.preventDefault()
3078
3743
  setSelected('')
3744
+ const viewport = viewportRef.current
3745
+ setGesture({
3746
+ type: 'pan',
3747
+ startX: event.clientX,
3748
+ startY: event.clientY,
3749
+ scrollLeft: viewport?.scrollLeft ?? 0,
3750
+ scrollTop: viewport?.scrollTop ?? 0,
3751
+ })
3079
3752
  return
3080
3753
  }
3081
3754
  event.preventDefault()
@@ -3091,9 +3764,17 @@ window.__ModuleLoader__.load({
3091
3764
  })
3092
3765
  return
3093
3766
  }
3767
+ if (noteId && !drawOnStickyRef.current) {
3768
+ // Drawing on sticky notes is switched off: keep the note selected but
3769
+ // do not start a stroke there.
3770
+ event.preventDefault()
3771
+ setSelected(noteId)
3772
+ return
3773
+ }
3094
3774
  event.preventDefault()
3095
3775
  const rect = (noteElement ?? stage).getBoundingClientRect()
3096
- const point = [Math.round(event.clientX - rect.left), Math.round(event.clientY - rect.top)]
3776
+ const scale = zoomScale()
3777
+ const point = [Math.round((event.clientX - rect.left) / scale), Math.round((event.clientY - rect.top) / scale)]
3097
3778
  const layer = noteId ? 'note' : 'background'
3098
3779
  if (toolRef.current === 'eraser') {
3099
3780
  const gesture = { type: 'erase', layer, noteId, rect }
@@ -3101,7 +3782,30 @@ window.__ModuleLoader__.load({
3101
3782
  setGesture(gesture)
3102
3783
  return
3103
3784
  }
3104
- const stroke = { color: inkRef.current, width: 2, points: [point] }
3785
+ const shape = ['rect', 'ellipse', 'line', 'arrow', 'triangle'].includes(toolRef.current)
3786
+ if (shape) {
3787
+ const baseCanvas = cloneBoardCanvas(canvasRef.current)
3788
+ const targets = new Map()
3789
+ if (noteId && noteElement) targets.set(noteId, noteOffsets(noteElement))
3790
+ const startWorld = stagePoint(event)
3791
+ const gesture = {
3792
+ type: 'shape',
3793
+ kind: toolRef.current,
3794
+ color: inkRef.current,
3795
+ width: inkWidthRef.current,
3796
+ baseCanvas,
3797
+ startWorld,
3798
+ endWorld: [...startWorld],
3799
+ targets,
3800
+ ctrl: event.ctrlKey || event.metaKey || event.shiftKey,
3801
+ }
3802
+ const preview = buildShapeCanvas(gesture)
3803
+ canvasRef.current = preview
3804
+ setCanvas(preview)
3805
+ setGesture(gesture)
3806
+ return
3807
+ }
3808
+ const stroke = { kind: 'pen', color: inkRef.current, width: inkWidthRef.current, points: [point] }
3105
3809
  const next = cloneBoardCanvas(canvasRef.current)
3106
3810
  let strokeIndex
3107
3811
  if (layer === 'background') {
@@ -3115,7 +3819,75 @@ window.__ModuleLoader__.load({
3115
3819
  }
3116
3820
  canvasRef.current = next
3117
3821
  setCanvas(next)
3118
- setGesture({ type: 'draw', layer, noteId, rect, stroke, strokeIndex })
3822
+ setGesture({
3823
+ type: 'draw',
3824
+ shape,
3825
+ layer,
3826
+ noteId,
3827
+ rect,
3828
+ stroke,
3829
+ strokeIndex,
3830
+ startWorld: [event.clientX, event.clientY],
3831
+ lastWorld: [event.clientX, event.clientY],
3832
+ })
3833
+ }
3834
+
3835
+ const toggleDrawOnSticky = () => {
3836
+ setDrawOnSticky((value) => {
3837
+ const next = !value
3838
+ try {
3839
+ window.localStorage.setItem('dsh-timeback:board-draw-on-sticky', next ? '1' : '0')
3840
+ } catch {
3841
+ // Storage can be disabled.
3842
+ }
3843
+ return next
3844
+ })
3845
+ }
3846
+
3847
+ /** Change the drawing colour (recent colours are recorded only once used). */
3848
+ const applyInk = (value, options = {}) => {
3849
+ const normalized = /^#[0-9a-f]{6}$/i.test(String(value || '')) ? String(value).toLowerCase() : '#e6b84c'
3850
+ setInk(normalized)
3851
+ inkRef.current = normalized
3852
+ try {
3853
+ window.localStorage.setItem('dsh-timeback:board-ink-color', normalized)
3854
+ } catch {
3855
+ // Storage can be disabled.
3856
+ }
3857
+ if (options.close === true) setColorOpen(false)
3858
+ }
3859
+
3860
+ /** Remember a colour in the recent list after a real stroke used it. */
3861
+ const rememberInk = (value) => {
3862
+ const normalized = /^#[0-9a-f]{6}$/i.test(String(value || '')) ? String(value).toLowerCase() : ''
3863
+ if (normalized === '') return
3864
+ setRecentColors((previous) => {
3865
+ const next = [normalized, ...previous.filter((item) => item !== normalized)].slice(0, 8)
3866
+ try {
3867
+ window.localStorage.setItem('dsh-timeback:board-recent-colors', JSON.stringify(next))
3868
+ } catch {
3869
+ // Storage can be disabled.
3870
+ }
3871
+ return next
3872
+ })
3873
+ }
3874
+
3875
+ const pickScreenColor = async () => {
3876
+ setColorHint('')
3877
+ if (typeof window === 'undefined' || typeof window.EyeDropper !== 'function') {
3878
+ setColorHint(t('board.eyedropperUnsupported'))
3879
+ return
3880
+ }
3881
+ if (window.isSecureContext === false) {
3882
+ setColorHint(t('board.eyedropperInsecure'))
3883
+ return
3884
+ }
3885
+ try {
3886
+ const result = await new window.EyeDropper().open()
3887
+ if (result?.sRGBHex) applyInk(result.sRGBHex, { close: true })
3888
+ } catch (error) {
3889
+ setColorHint(format(t('board.eyedropperFailed'), { error: error?.message || 'cancelled' }))
3890
+ }
3119
3891
  }
3120
3892
 
3121
3893
  const clearBackground = () => {
@@ -3135,10 +3907,68 @@ window.__ModuleLoader__.load({
3135
3907
  /* -------------------------------------------------------------- */
3136
3908
 
3137
3909
  const drawingLayer = (strokes, prefix) =>
3138
- h('svg', { className: prefix === 'bg' ? 'tb-board-bgdraw' : 'tb-sticky-draw', width: prefix === 'bg' ? BOARD_STAGE_W : '100%', height: prefix === 'bg' ? BOARD_STAGE_H : '100%' }, ...boardPolylines(strokes, prefix))
3910
+ h('svg', { className: prefix === 'bg' ? 'tb-board-bgdraw' : 'tb-sticky-draw', width: prefix === 'bg' ? BOARD_STAGE_W : '100%', height: prefix === 'bg' ? BOARD_STAGE_H : '100%' }, ...boardStrokeElements(strokes, prefix))
3911
+
3912
+ const layoutById = new Map()
3913
+ entries.forEach((entry, index) => layoutById.set(entry.id, layoutFor(entry, index)))
3914
+
3915
+ const edgeLayer = () => {
3916
+ const nodes = []
3917
+ for (const edge of canvas.edges ?? []) {
3918
+ const fromLayout = layoutById.get(edge.from?.noteId)
3919
+ const toLayout = layoutById.get(edge.to?.noteId)
3920
+ if (!fromLayout || !toLayout) continue
3921
+ const from = boardAnchorPoint(fromLayout, edge.from.anchor)
3922
+ const to = boardAnchorPoint(toLayout, edge.to.anchor)
3923
+ nodes.push(
3924
+ h(
3925
+ 'g',
3926
+ {
3927
+ key: edge.id,
3928
+ className: 'tb-board-edge',
3929
+ onPointerDown: (event) => {
3930
+ if (toolRef.current !== 'link') return
3931
+ event.stopPropagation()
3932
+ event.preventDefault()
3933
+ let confirmed = true
3934
+ try {
3935
+ confirmed = typeof window.confirm === 'function' ? window.confirm(t('board.edgeDeleteConfirm')) : true
3936
+ } catch {
3937
+ confirmed = true
3938
+ }
3939
+ if (!confirmed) return
3940
+ const next = cloneBoardCanvas(canvasRef.current)
3941
+ next.edges = next.edges.filter((candidate) => candidate.id !== edge.id)
3942
+ saveCanvasSoon(next)
3943
+ },
3944
+ },
3945
+ h('path', { className: 'tb-board-edge-path', d: boardEdgePath(from, to), stroke: edge.color || '#7aa2ff' }),
3946
+ h('circle', { className: 'tb-board-edge-dot', cx: from[0], cy: from[1], r: 3 }),
3947
+ h('circle', { className: 'tb-board-edge-dot', cx: to[0], cy: to[1], r: 3 }),
3948
+ ),
3949
+ )
3950
+ }
3951
+ if (linkPreview) {
3952
+ const fromLayout = layoutById.get(linkPreview.fromNoteId)
3953
+ if (fromLayout) {
3954
+ const from = boardAnchorPoint(fromLayout, linkPreview.fromAnchor)
3955
+ let to = linkPreview.pointer
3956
+ if (linkPreview.targetNoteId) {
3957
+ const targetLayout = layoutById.get(linkPreview.targetNoteId)
3958
+ if (targetLayout) to = boardAnchorPoint(targetLayout, linkPreview.targetAnchor)
3959
+ }
3960
+ nodes.push(
3961
+ h('g', { key: 'link-preview', className: 'tb-board-edge-preview-group' },
3962
+ h('path', { className: 'tb-board-edge-preview', d: boardEdgePath(from, to), stroke: ink })),
3963
+ )
3964
+ }
3965
+ }
3966
+ return h('svg', { className: 'tb-board-edges', width: BOARD_STAGE_W, height: BOARD_STAGE_H }, ...nodes)
3967
+ }
3139
3968
 
3140
3969
  const stickyFor = (entry, index) => {
3141
3970
  const layout = layoutFor(entry, index)
3971
+ const size = noteSize(layout)
3142
3972
  const agent = entry.source === 'agent'
3143
3973
  return h(
3144
3974
  'article',
@@ -3149,6 +3979,8 @@ window.__ModuleLoader__.load({
3149
3979
  style: {
3150
3980
  left: Number(layout.x) || 0,
3151
3981
  top: Number(layout.y) || 0,
3982
+ width: size.width,
3983
+ height: size.height,
3152
3984
  zIndex: 100 + (Number(layout.z) || 0),
3153
3985
  background: layout.color || BOARD_COLORS[index % BOARD_COLORS.length],
3154
3986
  },
@@ -3181,7 +4013,7 @@ window.__ModuleLoader__.load({
3181
4013
  tabIndex: 0,
3182
4014
  onClick: (event) => {
3183
4015
  event.stopPropagation()
3184
- focusEntry(entry.id)
4016
+ openReader(entry.id)
3185
4017
  },
3186
4018
  },
3187
4019
  `🔗 ${t('board.openMd')}`,
@@ -3190,6 +4022,23 @@ window.__ModuleLoader__.load({
3190
4022
  )
3191
4023
  : h('div', { className: 'tb-sticky-body md' }, stripMarkdown(entry.body) || t('board.empty')),
3192
4024
  drawingLayer(canvas.drawings[entry.id] ?? [], `d-${entry.id}`),
4025
+ ...BOARD_ANCHORS.map((anchor) =>
4026
+ h('div', {
4027
+ key: anchor,
4028
+ className: `tb-anchor tb-anchor-${anchor}`,
4029
+ 'data-note-id': entry.id,
4030
+ 'data-anchor': anchor,
4031
+ style:
4032
+ anchor === 'top'
4033
+ ? { left: '50%', top: 0 }
4034
+ : anchor === 'right'
4035
+ ? { left: '100%', top: '50%' }
4036
+ : anchor === 'bottom'
4037
+ ? { left: '50%', top: '100%' }
4038
+ : { left: 0, top: '50%' },
4039
+ }),
4040
+ ),
4041
+ h('div', { className: 'tb-sticky-resize', title: t('board.resizeNote'), role: 'separator' }),
3193
4042
  )
3194
4043
  }
3195
4044
 
@@ -3199,19 +4048,190 @@ window.__ModuleLoader__.load({
3199
4048
  h('button', { type: 'button', className: `tb-tool${tool === 'select' ? ' on' : ''}`, onClick: () => setTool('select') }, t('board.toolSelect')),
3200
4049
  h('button', { type: 'button', className: `tb-tool${tool === 'pen' ? ' on' : ''}`, onClick: () => setTool('pen') }, `✏️ ${t('board.toolPen')}`),
3201
4050
  h('button', { type: 'button', className: `tb-tool${tool === 'eraser' ? ' on' : ''}`, onClick: () => setTool('eraser') }, `🧽 ${t('board.toolEraser')}`),
3202
- h('span', { className: 'tb-board-meta' }, t('board.color')),
3203
- ...BOARD_INKS.map((value) =>
4051
+ h('button', { type: 'button', className: `tb-tool${tool === 'link' ? ' on' : ''}`, title: t('board.anchorsHint'), onClick: () => setTool('link') }, `🔗 ${t('board.toolLink')}`),
4052
+ h(
4053
+ 'div',
4054
+ { className: 'tb-shape-wrap' },
4055
+ h(
4056
+ 'button',
4057
+ {
4058
+ type: 'button',
4059
+ className: `tb-tool${BOARD_SHAPES.some(([value]) => value === tool) ? ' on' : ''}`,
4060
+ title: t('board.commonShapes'),
4061
+ onClick: () => setShapeMenu((value) => !value),
4062
+ },
4063
+ `${t('board.commonShapes')} ${BOARD_SHAPES.find(([value]) => value === tool)?.[1] ?? '▭'}`,
4064
+ ),
4065
+ shapeMenu
4066
+ ? h(
4067
+ 'div',
4068
+ { className: 'tb-shape-menu', role: 'menu' },
4069
+ ...BOARD_SHAPES.map(([value, glyph, key]) =>
4070
+ h(
4071
+ 'button',
4072
+ {
4073
+ key: value,
4074
+ type: 'button',
4075
+ role: 'menuitem',
4076
+ onClick: () => {
4077
+ setTool(value)
4078
+ setShapeMenu(false)
4079
+ },
4080
+ },
4081
+ `${glyph} ${t(key)}`,
4082
+ ),
4083
+ ),
4084
+ )
4085
+ : null,
4086
+ ),
4087
+ h('span', { className: 'tb-board-meta' }, t('board.brushSize')),
4088
+ h('input', {
4089
+ type: 'range',
4090
+ className: 'tb-size-range',
4091
+ min: 1,
4092
+ max: 8,
4093
+ step: 1,
4094
+ value: inkWidth,
4095
+ 'aria-label': t('board.brushSize'),
4096
+ onChange: (event) => {
4097
+ const next = Math.min(8, Math.max(1, Number(event.target.value) || 2))
4098
+ setInkWidth(next)
4099
+ try {
4100
+ window.localStorage.setItem('dsh-timeback:board-ink-width', String(next))
4101
+ } catch {
4102
+ // Storage can be disabled.
4103
+ }
4104
+ },
4105
+ }),
4106
+ h('span', { className: 'tb-board-meta' }, String(inkWidth)),
4107
+ h(
4108
+ 'div',
4109
+ { className: 'tb-color-wrap' },
3204
4110
  h('button', {
3205
- key: value,
3206
4111
  type: 'button',
3207
- className: `tb-swatch${ink === value ? ' on' : ''}`,
3208
- style: { background: value },
3209
- title: value,
3210
- onClick: () => setInk(value),
4112
+ className: 'tb-color-btn',
4113
+ style: { background: ink },
4114
+ title: `${t('board.color')} ${ink}`,
4115
+ 'aria-label': t('board.colorTitle'),
4116
+ onClick: () => setColorOpen((value) => !value),
3211
4117
  }),
4118
+ colorOpen
4119
+ ? (() => {
4120
+ const rgb = hexToRgb(ink)
4121
+ return h(
4122
+ 'div',
4123
+ { className: 'tb-color-panel', role: 'dialog' },
4124
+ h('div', { className: 'tb-board-meta' }, t('board.colorTitle')),
4125
+ h(
4126
+ 'div',
4127
+ { className: 'tb-color-row' },
4128
+ h('span', { className: 'tb-color-label' }, t('board.customColor')),
4129
+ h('input', {
4130
+ type: 'color',
4131
+ value: ink,
4132
+ 'aria-label': t('board.customColor'),
4133
+ onChange: (event) => applyInk(event.target.value),
4134
+ }),
4135
+ h(
4136
+ 'button',
4137
+ {
4138
+ type: 'button',
4139
+ className: 'tb-tool',
4140
+ title: t('board.eyedropperHint'),
4141
+ onClick: pickScreenColor,
4142
+ },
4143
+ `🎯 ${t('board.eyedropper')}`,
4144
+ ),
4145
+ ),
4146
+ colorHint ? h('div', { className: 'tb-feedback warn', style: { padding: '5px 7px', fontSize: '10.5px' } }, colorHint) : null,
4147
+ h(
4148
+ 'div',
4149
+ { className: 'tb-hex-row' },
4150
+ h('span', { className: 'tb-color-label' }, 'HEX'),
4151
+ h('input', {
4152
+ type: 'text',
4153
+ value: ink,
4154
+ spellCheck: false,
4155
+ onChange: (event) => {
4156
+ const value = event.target.value.trim()
4157
+ if (/^#[0-9a-f]{6}$/i.test(value)) applyInk(value)
4158
+ },
4159
+ }),
4160
+ ),
4161
+ h('div', { className: 'tb-color-label' }, t('board.rgb')),
4162
+ ...['R', 'G', 'B'].map((channel, index) =>
4163
+ h(
4164
+ 'div',
4165
+ { key: channel, className: 'tb-rgb-row' },
4166
+ h('span', { className: 'tb-color-label' }, channel),
4167
+ h('input', {
4168
+ type: 'range',
4169
+ min: 0,
4170
+ max: 255,
4171
+ step: 1,
4172
+ value: rgb[index],
4173
+ 'aria-label': `${t('board.rgb')} ${channel}`,
4174
+ onChange: (event) => {
4175
+ const next = [...rgb]
4176
+ next[index] = Number(event.target.value)
4177
+ applyInk(rgbToHex(next))
4178
+ },
4179
+ }),
4180
+ h('span', null, String(rgb[index])),
4181
+ ),
4182
+ ),
4183
+ h('div', { className: 'tb-color-label' }, t('board.commonColors')),
4184
+ h(
4185
+ 'div',
4186
+ { className: 'tb-color-grid' },
4187
+ ...BOARD_INKS.map((value) =>
4188
+ h('button', {
4189
+ key: value,
4190
+ type: 'button',
4191
+ title: value,
4192
+ style: { background: value },
4193
+ onClick: () => applyInk(value, { close: true }),
4194
+ }),
4195
+ ),
4196
+ ),
4197
+ recentColors.length > 0
4198
+ ? h(
4199
+ 'div',
4200
+ null,
4201
+ h('div', { className: 'tb-color-label' }, t('board.recentColors')),
4202
+ h(
4203
+ 'div',
4204
+ { className: 'tb-color-grid' },
4205
+ ...recentColors.map((value) =>
4206
+ h('button', {
4207
+ key: `recent-${value}`,
4208
+ type: 'button',
4209
+ title: value,
4210
+ style: { background: value },
4211
+ onClick: () => applyInk(value, { close: true }),
4212
+ }),
4213
+ ),
4214
+ ),
4215
+ )
4216
+ : null,
4217
+ )
4218
+ })()
4219
+ : null,
4220
+ ),
4221
+ h(
4222
+ 'button',
4223
+ {
4224
+ type: 'button',
4225
+ className: `tb-tool${drawOnSticky ? ' on' : ''}`,
4226
+ title: t('board.drawOnStickyHint'),
4227
+ onClick: toggleDrawOnSticky,
4228
+ },
4229
+ drawOnSticky ? t('board.drawOnStickyOn') : t('board.drawOnStickyOff'),
3212
4230
  ),
3213
4231
  h('span', { style: { flex: 1 } }),
4232
+ h('button', { type: 'button', className: 'tb-btn', onClick: autoFit }, t('board.center')),
3214
4233
  h('button', { type: 'button', className: 'tb-btn', disabled: canvas.background.length === 0, onClick: clearBackground }, t('board.clearBg')),
4234
+ h('button', { type: 'button', className: 'tb-btn', disabled: (canvas.edges ?? []).length === 0, onClick: () => { const next = cloneBoardCanvas(canvasRef.current); next.edges = []; saveCanvasSoon(next) } }, t('board.clearEdges')),
3215
4235
  h('button', { type: 'button', className: 'tb-btn', disabled: !selected || !(canvas.drawings[selected]?.length > 0), onClick: clearSelectedDrawing }, t('board.clearNote')),
3216
4236
  )
3217
4237
 
@@ -3230,16 +4250,25 @@ window.__ModuleLoader__.load({
3230
4250
  h('button', { type: 'button', className: 'tb-btn primary', onClick: startCreate }, `+ ${t('board.newSticky')}`),
3231
4251
  ),
3232
4252
  toolbar,
3233
- h('div', { className: 'tb-board-hint-wrap' }, h('span', { className: 'tb-ws-hint' }, t('board.stickyHint'))),
4253
+ h('div', { className: 'tb-board-hint-wrap' }, h('span', { className: 'tb-ws-hint' }, `${t('board.stickyHint')} · ${t('board.panHint')}`)),
3234
4254
  state.error ? h('div', { className: 'tb-feedback err' }, format(t('board.error'), { error: state.error })) : null,
3235
4255
  h(
3236
4256
  'div',
3237
- { className: `tb-board-canvas${tool === 'select' ? ' select' : ''}`, onPointerDown: beginPointer },
4257
+ { className: `tb-board-canvas${tool === 'select' ? ' select' : tool === 'link' ? ' link' : ' draw'}`, ref: viewportRef, onPointerDown: beginPointer },
3238
4258
  h(
3239
4259
  'div',
3240
- { className: 'tb-board-stage', ref: stageRef, style: { width: BOARD_STAGE_W, height: BOARD_STAGE_H } },
3241
- drawingLayer(canvas.background, 'bg'),
3242
- ...entries.map((entry, index) => stickyFor(entry, index)),
4260
+ { className: 'tb-board-world', style: { width: BOARD_STAGE_W * zoom, height: BOARD_STAGE_H * zoom } },
4261
+ h(
4262
+ 'div',
4263
+ {
4264
+ className: `tb-board-stage${tool === 'link' || linkPreview ? ' show-anchors' : ''}`,
4265
+ ref: stageRef,
4266
+ style: { width: BOARD_STAGE_W, height: BOARD_STAGE_H, transform: `scale(${zoom})` },
4267
+ },
4268
+ drawingLayer(canvas.background, 'bg'),
4269
+ edgeLayer(),
4270
+ ...entries.map((entry, index) => stickyFor(entry, index)),
4271
+ ),
3243
4272
  ),
3244
4273
  state.loading && !state.board ? h('p', { className: 'tb-board-md-empty' }, t('panel.loading')) : null,
3245
4274
  !state.loading && entries.length === 0 ? h('p', { className: 'tb-board-md-empty' }, t('board.empty')) : null,
@@ -3263,7 +4292,7 @@ window.__ModuleLoader__.load({
3263
4292
  h(
3264
4293
  'div',
3265
4294
  { className: 'tb-board-actions' },
3266
- h('button', { type: 'button', className: 'tb-btn', onClick: () => focusEntry(entry.id) }, t('board.openMd')),
4295
+ h('button', { type: 'button', className: 'tb-btn', onClick: () => openReader(entry.id) }, t('board.reader')),
3267
4296
  h('button', { type: 'button', className: 'tb-btn', onClick: () => startEdit(entry) }, t('board.edit')),
3268
4297
  h('button', { type: 'button', className: 'tb-btn danger', disabled: busy !== '', onClick: () => removeEntry(entry.id) }, busy === entry.id ? '…' : t('board.delete')),
3269
4298
  ),
@@ -3272,6 +4301,39 @@ window.__ModuleLoader__.load({
3272
4301
  ),
3273
4302
  ),
3274
4303
  ),
4304
+ (() => {
4305
+ const readerEntry = entries.find((entry) => entry.id === readerId)
4306
+ if (!readerEntry) return null
4307
+ return h(
4308
+ 'div',
4309
+ { className: 'tb-overlay center', onClick: () => setReaderId('') },
4310
+ h(
4311
+ 'div',
4312
+ {
4313
+ className: 'tb-board-dialog',
4314
+ role: 'dialog',
4315
+ 'aria-modal': true,
4316
+ style: { width: 'min(780px, 94vw)', height: '72vh' },
4317
+ onClick: (event) => event.stopPropagation(),
4318
+ },
4319
+ h(
4320
+ 'div',
4321
+ { className: 'tb-detail-head' },
4322
+ h('span', { className: 'tb-detail-title' }, `📄 ${readerEntry.title || '未命名便签'}`),
4323
+ h('span', { className: 'tb-chip' }, readerEntry.source === 'agent' ? t('board.sourceAgent') : t('board.sourceUser')),
4324
+ h('span', { style: { flex: 1 } }),
4325
+ h('button', { type: 'button', className: 'tb-btn', onClick: () => { setReaderId(''); startEdit(readerEntry) } }, t('board.edit')),
4326
+ h(
4327
+ 'button',
4328
+ { type: 'button', className: 'tb-btn danger', disabled: busy !== '', onClick: () => { setReaderId(''); removeEntry(readerEntry.id) } },
4329
+ t('board.delete'),
4330
+ ),
4331
+ h('button', { type: 'button', className: 'tb-btn primary', onClick: () => setReaderId('') }, t('board.close')),
4332
+ ),
4333
+ h('div', { className: 'tb-md', style: { flex: 1, overflow: 'auto' } }, ...renderMarkdown(readerEntry.body || '', `reader-${readerEntry.id}`)),
4334
+ ),
4335
+ )
4336
+ })(),
3275
4337
  draft
3276
4338
  ? h(
3277
4339
  'div',
@@ -3336,6 +4398,7 @@ window.__ModuleLoader__.load({
3336
4398
  window.__TIMEBACK_TEST__.edgePanVector = edgePanVector
3337
4399
  window.__TIMEBACK_TEST__.renderMarkdown = renderMarkdown
3338
4400
  window.__TIMEBACK_TEST__.stripMarkdown = stripMarkdown
4401
+ window.__TIMEBACK_TEST__.boardEdgePath = boardEdgePath
3339
4402
  }
3340
4403
 
3341
4404
  return {