@reekon-tools/boldr-cad 1.6.0 → 1.8.0

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 (87) hide show
  1. package/README.md +12 -1
  2. package/dist/data/provider.d.ts +2 -1
  3. package/dist/data/sync.js +4 -1
  4. package/dist/data/sync.js.map +1 -1
  5. package/dist/editor/actions.js +26 -2
  6. package/dist/editor/actions.js.map +1 -1
  7. package/dist/editor/advance.d.ts +2 -0
  8. package/dist/editor/advance.js +23 -0
  9. package/dist/editor/advance.js.map +1 -0
  10. package/dist/editor/dimSize.d.ts +13 -0
  11. package/dist/editor/dimSize.js +50 -0
  12. package/dist/editor/dimSize.js.map +1 -0
  13. package/dist/editor/gestures.js +30 -7
  14. package/dist/editor/gestures.js.map +1 -1
  15. package/dist/editor/keypad.d.ts +8 -0
  16. package/dist/editor/keypad.js +15 -1
  17. package/dist/editor/keypad.js.map +1 -1
  18. package/dist/editor/laser.d.ts +9 -0
  19. package/dist/editor/laser.js +38 -12
  20. package/dist/editor/laser.js.map +1 -1
  21. package/dist/editor/linkActions.d.ts +5 -1
  22. package/dist/editor/linkActions.js +27 -5
  23. package/dist/editor/linkActions.js.map +1 -1
  24. package/dist/editor/ports.d.ts +9 -0
  25. package/dist/editor/ports.js +2 -0
  26. package/dist/editor/ports.js.map +1 -1
  27. package/dist/editor/refDim.d.ts +17 -0
  28. package/dist/editor/refDim.js +62 -0
  29. package/dist/editor/refDim.js.map +1 -0
  30. package/dist/index.d.ts +1 -1
  31. package/dist/index.js +1 -1
  32. package/dist/index.js.map +1 -1
  33. package/dist/model/clockwise.d.ts +11 -0
  34. package/dist/model/clockwise.js +123 -0
  35. package/dist/model/clockwise.js.map +1 -0
  36. package/dist/model/settings.d.ts +2 -0
  37. package/dist/model/settings.js +1 -1
  38. package/dist/model/settings.js.map +1 -1
  39. package/dist/model/types.d.ts +5 -0
  40. package/dist/react/BottomBar.js +43 -3
  41. package/dist/react/BottomBar.js.map +1 -1
  42. package/dist/react/PlanCanvas.native.js +15 -9
  43. package/dist/react/PlanCanvas.native.js.map +1 -1
  44. package/dist/react/host.d.ts +6 -0
  45. package/dist/react/host.js +11 -1
  46. package/dist/react/host.js.map +1 -1
  47. package/dist/react/ports.js +2 -1
  48. package/dist/react/ports.js.map +1 -1
  49. package/dist/react/store.d.ts +1 -1
  50. package/dist/react/store.js.map +1 -1
  51. package/dist/render/draw.d.ts +8 -0
  52. package/dist/render/draw.js +164 -92
  53. package/dist/render/draw.js.map +1 -1
  54. package/dist/render/navigate.d.ts +11 -6
  55. package/dist/render/navigate.js +34 -20
  56. package/dist/render/navigate.js.map +1 -1
  57. package/dist/tools/dim.d.ts +15 -0
  58. package/dist/tools/dim.js +171 -45
  59. package/dist/tools/dim.js.map +1 -1
  60. package/dist/tools/line.js +5 -0
  61. package/dist/tools/line.js.map +1 -1
  62. package/package.json +1 -1
  63. package/src/data/provider.ts +2 -2
  64. package/src/data/sync.ts +4 -1
  65. package/src/editor/actions.ts +20 -2
  66. package/src/editor/advance.ts +23 -0
  67. package/src/editor/dimSize.ts +53 -0
  68. package/src/editor/gestures.ts +31 -9
  69. package/src/editor/keypad.ts +17 -1
  70. package/src/editor/laser.ts +38 -10
  71. package/src/editor/linkActions.ts +25 -6
  72. package/src/editor/ports.ts +10 -0
  73. package/src/editor/refDim.ts +61 -0
  74. package/src/index.ts +1 -2
  75. package/src/model/clockwise.ts +121 -0
  76. package/src/model/settings.ts +3 -1
  77. package/src/model/types.ts +5 -0
  78. package/src/react/BottomBar.tsx +46 -2
  79. package/src/react/PlanCanvas.native.tsx +25 -12
  80. package/src/react/host.ts +11 -1
  81. package/src/react/ports.ts +3 -2
  82. package/src/react/store.ts +1 -1
  83. package/src/render/draw.ts +131 -71
  84. package/src/render/navigate.ts +31 -20
  85. package/src/tools/dim.ts +168 -35
  86. package/src/tools/line.ts +4 -0
  87. package/src/ui/domPorts.ts +2 -0
@@ -59,8 +59,8 @@ function hostRequest(spec: KeypadSpec): HostKeypadRequest {
59
59
  };
60
60
  }
61
61
 
62
- /** A slider above the bar (an image's opacity or rotation, the tiles' size): opened, swapped for another, or closed by its button again. */
63
- function toggleImagePop(kind: 'opacity' | 'rotate' | 'tilesize'): void {
62
+ /** A slider above the bar (an image's opacity or rotation, the tiles' or measurement tiles' size): opened, swapped for another, or closed by its button again. */
63
+ function toggleImagePop(kind: 'opacity' | 'rotate' | 'tilesize' | 'dimsize'): void {
64
64
  ui.imgPop = ui.imgPop === kind ? null : kind;
65
65
  ui.menu = false;
66
66
  // (a toast would sit over the slider: it's done with once the slider opens)
@@ -153,6 +153,7 @@ export const reactPorts: EditorPorts = {
153
153
  toggleImageOpacity() { toggleImagePop('opacity'); },
154
154
  toggleImageRotation() { toggleImagePop('rotate'); },
155
155
  toggleTileSize() { toggleImagePop('tilesize'); },
156
+ toggleDimSize() { toggleImagePop('dimsize'); },
156
157
  editRoomName(roomId) { ui.drawer = 'rooms'; ui.renameRoom = roomId; notify(); },
157
158
  setCursor(cursor, where = 'plan') { cursorTargets[where]?.(cursor); },
158
159
  interacting: setInteracting,
@@ -59,7 +59,7 @@ export const ui = sessionState(() => ({
59
59
  * what's open above the bar: the selected image's opacity or turn, or the link tiles' size (sliders), or Open's
60
60
  * question (here, or side by side)
61
61
  */
62
- imgPop: null as null | 'opacity' | 'rotate' | 'tilesize' | 'open',
62
+ imgPop: null as null | 'opacity' | 'rotate' | 'tilesize' | 'dimsize' | 'open',
63
63
  /** the tool each shared place on the rail draws with (the last picked; editor/mode.ts TOOL_GROUPS), and the menu of
64
64
  a group's tools, open beside its place at x, y */
65
65
  picked: { shapes: 'line', marks: 'arrow' } as Record<string, string>,
@@ -11,6 +11,7 @@ import { settings } from '../model/settings';
11
11
  import { curveInfo, frameMemo, lineBetween, roomValid, withLineIndex } from '../model/sketch';
12
12
  import { page, planSK, SK } from '../model/store';
13
13
  import { elev, elevOpen } from '../editor/elevation';
14
+ import { ghostDim } from '../editor/refDim';
14
15
  import { cabPoints } from '../model/faces';
15
16
  import { drawKeyPlan, drawWallBackdrop, drawWallChips, drawWallSelection, type ElevAct } from './elevation';
16
17
  import type { Constraint, Page, Sketch, WallFace, XY } from '../model/types';
@@ -41,7 +42,8 @@ export function rr(c: C2D, x: number, y: number, w: number, h: number, r: number
41
42
  }
42
43
 
43
44
  export interface ChipOpts {
44
- bg: string; fg: string; border?: [string, number?] | null; font?: string; pad?: number; h?: number; minW?: number;
45
+ /** `r`: its corners' radius (5); `dash`: its border dashed so (a grey number nothing keeps yet: editor/refDim.ts) */
46
+ bg: string; fg: string; border?: [string, number?] | null; font?: string; pad?: number; h?: number; minW?: number; r?: number; dash?: number[];
45
47
  kind?: HitChip['kind']; id?: string; rot?: number;
46
48
  /**
47
49
  * 'link': a measurement of the job sets it. The chip is then Figma's linked measurement (2795:77149): a white badge
@@ -80,15 +82,24 @@ export function chipSize(c: C2D, text: string, { font = '600 12px', pad = 7, h =
80
82
  return { w: Math.max(minW, c.measureText(text).width + room), h };
81
83
  }
82
84
 
85
+ /**
86
+ * A measurement tile's size — a dimension's chip: its font, padding, height and corners — times the file's measurement
87
+ * tile size (settings.chipPct, editor/dimSize.ts). At 100%, chip()'s own: 12 px, 7, 22, 5.
88
+ */
89
+ export function dimChip(): Pick<ChipOpts, 'font' | 'pad' | 'h' | 'r'> {
90
+ const k = settings.chipPct / 100;
91
+ return k === 1 ? {} : { font: '600 ' + 12 * k + 'px', pad: 7 * k, h: 22 * k, r: 5 * k };
92
+ }
93
+
83
94
  /** Rounded label on the canvas; registers a hit region when `kind` is given. */
84
95
  export function chip(c: C2D, text: string, cx: number, cy: number, opts: ChipOpts): number {
85
96
  const { bg, fg, border, kind, id, rot = 0, mark } = opts;
86
97
  const { w, h } = chipSize(c, text, opts), x = cx - w / 2, y = cy - h / 2;
87
98
  c.save();
88
99
  if (rot) { c.translate(cx, cy); c.rotate(rot); c.translate(-cx, -cy); }
89
- rr(c, x, y, w, h, 5);
100
+ rr(c, x, y, w, h, opts.r ?? 5);
90
101
  c.fillStyle = bg; c.fill();
91
- if (border) { c.lineWidth = border[1] || 1; c.strokeStyle = border[0]; c.stroke(); }
102
+ if (border) { c.lineWidth = border[1] || 1; c.strokeStyle = border[0]; if (opts.dash) c.setLineDash(opts.dash); c.stroke(); c.setLineDash([]); }
92
103
  c.fillStyle = fg; c.textAlign = 'center'; c.textBaseline = 'middle';
93
104
  if (mark) {
94
105
  const k = h / LINKED.h, inset = LINKED.pad * k, bw = LINKED.badge * k, bx = x + inset, tx = bx + bw + LINKED.gap * k;
@@ -582,76 +593,93 @@ function dimLive(sk: Sketch, id: string, d: Constraint): boolean {
582
593
 
583
594
  /**
584
595
  * Driving/reference dimension chips. (Lengths are added from the bottom bar's + / Length, not on-canvas prompts.) What's
585
- * been entered (blue, or red when it can't be met) always shows; a reference only while it or what it measures is
586
- * selected or hovered.
596
+ * been entered (blue, or red when it can't be met) always shows, and so does a reference kept by hand (Make reference:
597
+ * editor/refDim.ts); a reference the drawing set only while it or what it measures is selected or hovered. Then what the
598
+ * + would make for the selection, as it measures now: the ghost.
587
599
  */
588
600
  function drawDims(c: C2D, T: Xform, sk: Sketch): void {
589
601
  if (!settings.layers.dims) return;
590
602
  for (const id in sk.cons) {
591
603
  const d = sk.cons[id];
592
604
  if (!isDim(d) || d.elev) continue; // the wall view's own dimensions are its chips
593
- const A = dimAnchor(sk, d);
594
- if (!A) continue;
595
- const ref = d.driving === false, val = ref ? measure(sk, d) : d.value!;
596
- const selected = isSel('dim', id) || isSel('cons', id);
597
605
  const bad = ed.highlight.has(id) || ed.ana.bad.has(id);
598
- if (ref && !bad && !dimLive(sk, id, d)) continue;
599
- // a measurement of the job sets it: the link badge before its value (chip()), on the chip's own colour — red once
600
- // the job's measurement is gone
601
- const linked = !!d.measurementRef && !ref && !bad, gone = linked && linkInfoOf(d.measurementRef!)?.exists === false;
602
- let bg = ref ? TH.ref : TH.blue, fg = ref ? TH.reftext : '#fff';
603
- if (bad || gone) { bg = TH.red; fg = '#fff'; }
604
- const border: [string, number] | null = selected ? [TH.yellow, 2.5] : null;
605
- const mark = linked ? 'link' as const : undefined;
606
- const wrap = (s: string) => (ref ? '(' : '') + s + (ref ? ')' : '');
607
- if (d.type === 'angle' && 'vtx' in A) {
608
- const [vx, vy] = S(T, A.vtx.x, A.vtx.y);
609
- // pulled off its corner: its arc out where the label is, the label riding on it; else a little arc at the
610
- // corner, the label out along the bisector
611
- const moved = angleLabel(sk, d), R = moved ? moved.r * T.s : 22;
612
- if (A.u1 && A.u2) {
613
- // arc between the two lines, so the angle reads as belonging to that corner
614
- const t1 = Math.atan2(-A.u1[1], A.u1[0]), t2 = Math.atan2(-A.u2[1], A.u2[0]);
615
- let sweep = t2 - t1;
616
- while (sweep > Math.PI) sweep -= 2 * Math.PI;
617
- while (sweep < -Math.PI) sweep += 2 * Math.PI;
618
- // (blue, as every other dimension is — the user's call, 2026-10-29; purple is the inference guides')
619
- c.save(); c.strokeStyle = bad ? TH.red : ref ? TH.chipline : TH.blue; c.lineWidth = 1.2;
620
- if (ref) c.setLineDash([3, 3]);
621
- c.beginPath(); c.arc(vx, vy, R, t1, t1 + sweep, sweep < 0); c.stroke();
622
- // (pulled out past where a line ends: an extension line along it, out to the arc)
623
- c.lineWidth = 1;
624
- for (const [u, len] of [[A.u1, A.len1], [A.u2, A.len2]] as const) {
625
- const from = (len ?? 0) * T.s;
626
- if (moved && R > from + 2) { c.beginPath(); c.moveTo(vx + u[0] * from, vy - u[1] * from); c.lineTo(vx + u[0] * (R + 4), vy - u[1] * (R + 4)); c.stroke(); }
627
- }
628
- c.restore();
606
+ if (d.driving === false && !d.kept && !bad && !dimLive(sk, id, d)) continue;
607
+ drawDim(c, T, sk, d, id, bad);
608
+ }
609
+ const g = ghostDim();
610
+ if (g) drawDim(c, T, sk, g, null, false);
611
+ }
612
+
613
+ /**
614
+ * One dimension: driving blue, a kept reference solid grey in brackets, red when it can't be met. Faded — the canvas's
615
+ * own colour inside a dashed grey outline, grey text, no brackets — when it shows only while it's selected: the ghost
616
+ * (`id` null) and a reference the drawing set. Its lines are dashed when it holds nothing.
617
+ */
618
+ function drawDim(c: C2D, T: Xform, sk: Sketch, d: Constraint, id: string | null, bad: boolean): void {
619
+ const A = dimAnchor(sk, d);
620
+ if (!A) return;
621
+ const ref = d.driving === false, val = ref ? measure(sk, d) : d.value!;
622
+ const grey = ref || id === null, faded = !bad && (id === null || (ref && !d.kept));
623
+ const selected = id !== null && (isSel('dim', id) || isSel('cons', id));
624
+ // a measurement of the job sets it: the link badge before its value (chip()), on the chip's own colour — red once
625
+ // the job's measurement is gone
626
+ const linked = !!d.measurementRef && !ref && !bad, gone = linked && linkInfoOf(d.measurementRef!)?.exists === false;
627
+ let bg = faded ? TH.bg : ref ? TH.ref : TH.blue, fg = faded ? TH.ink2 : ref ? TH.reftext : '#fff';
628
+ if (bad || gone) { bg = TH.red; fg = '#fff'; }
629
+ const border: [string, number] | null = selected ? [TH.yellow, 2.5] : faded ? [TH.chipline, 1.2] : null;
630
+ // (the ghost is a readout, never a tap target: it sits on what it measures, which a press there is for)
631
+ const opts: ChipOpts = {
632
+ bg, fg, border, ...(id === null ? {} : { kind: 'dim' as const, id }),
633
+ mark: linked ? 'link' : undefined, dash: faded && !selected ? [3, 2] : undefined, ...dimChip(),
634
+ };
635
+ const wrap = (s: string) => (ref && !faded ? '(' + s + ')' : s);
636
+ const lineColor = bad ? TH.red : grey ? TH.chipline : TH.blue;
637
+ if (d.type === 'angle' && 'vtx' in A) {
638
+ const [vx, vy] = S(T, A.vtx.x, A.vtx.y);
639
+ // pulled off its corner: its arc out where the label is, the label riding on it; else a little arc at the
640
+ // corner, the label out along the bisector
641
+ const moved = angleLabel(sk, d), R = moved ? moved.r * T.s : 22;
642
+ if (A.u1 && A.u2) {
643
+ // arc between the two lines, so the angle reads as belonging to that corner
644
+ const t1 = Math.atan2(-A.u1[1], A.u1[0]), t2 = Math.atan2(-A.u2[1], A.u2[0]);
645
+ let sweep = t2 - t1;
646
+ while (sweep > Math.PI) sweep -= 2 * Math.PI;
647
+ while (sweep < -Math.PI) sweep += 2 * Math.PI;
648
+ // (blue, as every other dimension is — the user's call, 2026-10-29; purple is the inference guides')
649
+ c.save(); c.strokeStyle = lineColor; c.lineWidth = 1.2;
650
+ if (grey) c.setLineDash([3, 3]);
651
+ c.beginPath(); c.arc(vx, vy, R, t1, t1 + sweep, sweep < 0); c.stroke();
652
+ // (pulled out past where a line ends: an extension line along it, out to the arc)
653
+ c.lineWidth = 1;
654
+ for (const [u, len] of [[A.u1, A.len1], [A.u2, A.len2]] as const) {
655
+ const from = (len ?? 0) * T.s;
656
+ if (moved && R > from + 2) { c.beginPath(); c.moveTo(vx + u[0] * from, vy - u[1] * from); c.lineTo(vx + u[0] * (R + 4), vy - u[1] * (R + 4)); c.stroke(); }
629
657
  }
630
- const text = wrap(fmtAng(val)), opts: ChipOpts = { bg, fg, border, kind: 'dim', id, mark };
631
- // (left where it was drawn: 50 px out along the bisector, or as far as its corners stay clear of the corner — a
632
- // linked chip is wider)
633
- const sz = chipSize(c, text, opts), out = Math.max(50, Math.hypot(sz.w, sz.h) / 2 + 28);
634
- const [lx, ly] = moved ? [vx + Math.cos(moved.ang) * R, vy - Math.sin(moved.ang) * R] : [vx + A.bis[0] * out, vy - A.bis[1] * out];
635
- chip(c, text, lx, ly, opts);
636
- continue;
637
- }
638
- if (d.type === 'diam' && 'o' in A) {
639
- drawDiameter(c, T, A.o, A.r, d, d.rad ? 'R ' + wrap(fmtLen(val / 2)) : 'Ø ' + wrap(fmtLen(val)), bad ? TH.red : ref ? TH.chipline : TH.blue, { bg, fg, border, kind: 'dim', id, mark }, ref);
640
- continue;
641
- }
642
- if (!('a' in A)) continue;
643
- const [mx, my] = S(T, A.m.x, A.m.y);
644
- const lineColor = bad ? TH.red : ref ? TH.chipline : TH.blue;
645
- if ((d.type === 'dist' || d.type === 'pldist') && A.nx != null && Math.abs((d.off || 0) * T.s) > 10) {
646
- drawDimLeaders(c, T, A.a, A.b, A.nx, A.ny!, d.off!, lineColor, ref);
647
- } else if (d.type === 'pldist' || !d.line) {
648
- // (dashed only when it's a reference: a dashed line means the number holds nothing, wherever it's drawn)
649
- const [ax, ay] = S(T, A.a.x, A.a.y), [bx, by] = S(T, A.b.x, A.b.y);
650
- c.save(); if (ref) c.setLineDash([3, 3]); c.strokeStyle = bad ? TH.red : ref ? TH.chipline : TH.blue; c.lineWidth = 1.2;
651
- c.beginPath(); c.moveTo(ax, ay); c.lineTo(bx, by); c.stroke(); c.restore();
658
+ c.restore();
652
659
  }
653
- chip(c, wrap(fmtLen(val)), mx, my, { bg, fg, border, kind: 'dim', id, mark });
660
+ const text = wrap(fmtAng(val));
661
+ // (left where it was drawn: 50 px out along the bisector, or as far as its corners stay clear of the corner — a
662
+ // linked chip is wider)
663
+ const sz = chipSize(c, text, opts), out = Math.max(50, Math.hypot(sz.w, sz.h) / 2 + 28);
664
+ const [lx, ly] = moved ? [vx + Math.cos(moved.ang) * R, vy - Math.sin(moved.ang) * R] : [vx + A.bis[0] * out, vy - A.bis[1] * out];
665
+ chip(c, text, lx, ly, opts);
666
+ return;
667
+ }
668
+ if (d.type === 'diam' && 'o' in A) {
669
+ drawDiameter(c, T, A.o, A.r, d, d.rad ? 'R ' + wrap(fmtLen(val / 2)) : 'Ø ' + wrap(fmtLen(val)), lineColor, opts, grey);
670
+ return;
671
+ }
672
+ if (!('a' in A)) return;
673
+ const [mx, my] = S(T, A.m.x, A.m.y);
674
+ if ((d.type === 'dist' || d.type === 'pldist') && A.nx != null && Math.abs((d.off || 0) * T.s) > 10) {
675
+ drawDimLeaders(c, T, A.a, A.b, A.nx, A.ny!, d.off!, lineColor, grey);
676
+ } else if (d.type === 'pldist' || !d.line) {
677
+ // (dashed only when it holds nothing: a dashed line means the number holds nothing, wherever it's drawn)
678
+ const [ax, ay] = S(T, A.a.x, A.a.y), [bx, by] = S(T, A.b.x, A.b.y);
679
+ c.save(); if (grey) c.setLineDash([3, 3]); c.strokeStyle = lineColor; c.lineWidth = 1.2;
680
+ c.beginPath(); c.moveTo(ax, ay); c.lineTo(bx, by); c.stroke(); c.restore();
654
681
  }
682
+ chip(c, wrap(fmtLen(val)), mx, my, opts);
655
683
  }
656
684
 
657
685
  /**
@@ -664,14 +692,15 @@ function drawDims(c: C2D, T: Xform, sk: Sketch): void {
664
692
  */
665
693
  function drawOpeningDims(c: C2D, T: Xform, sk: Sketch): void {
666
694
  if (!settings.layers.dims || ed.mode !== 'draft') return;
667
- const ROW = 26 / T.s;
695
+ // (the rows, and how far apart along them, grow with the measurement tiles: editor/dimSize.ts)
696
+ const k = settings.chipPct / 100, ROW = (26 * k) / T.s;
668
697
  for (const id in sk.openings) {
669
698
  const o = sk.openings[id], g = openingFrame(sk, id);
670
699
  if (!g) continue;
671
700
  const l = sk.lines[o.line], L = hyp(sk.points[l.b].x - g.A.x, sk.points[l.b].y - g.A.y);
672
701
  const side = outsideSide(sk, o.line);
673
702
  // automatic rows start 34 px past the wall face (clear of the H/V badges); a dragged dimension keeps its own offset
674
- const k0 = g.t / 2 + 34 / T.s;
703
+ const k0 = g.t / 2 + (34 + 11 * (k - 1)) / T.s;
675
704
  const kRow = (row: number) => side * (k0 + row * ROW);
676
705
  /** screen point at `s` along the wall, `k` (signed, world) off its centerline */
677
706
  const P = (s: number, k: number) => S(T, g.A.x + g.ux * s + g.nx * k, g.A.y + g.uy * s + g.ny * k);
@@ -699,14 +728,14 @@ function drawOpeningDims(c: C2D, T: Xform, sk: Sketch): void {
699
728
  };
700
729
  const label = (s0: number, s1: number, part: string, text: string, k: number, bg: string = TH.blue, fg = '#fff', border: [string, number] | null = null) => {
701
730
  const [mx, my] = P((s0 + s1) / 2, k);
702
- chip(c, text, mx, my, { bg, fg, border: odimSel(part) ? [TH.yellow, 2] : border, kind: 'odim', id });
731
+ chip(c, text, mx, my, { bg, fg, border: odimSel(part) ? [TH.yellow, 2] : border, kind: 'odim', id, ...dimChip() });
703
732
  if (hits && hits.length) hits[hits.length - 1].part = part;
704
733
  };
705
734
  // automatic placement packs dimensions into rows so they don't overlap each other or the width chip;
706
735
  // spans that only touch end to end share a row (a chained string)
707
736
  const rows: [number, number][][] = [o.wOff == null ? [[g.s0, g.s1]] : []];
708
737
  const place = (a: number, b: number) => {
709
- const lo = Math.min(a, b), hi = Math.max(a, b), gap = 64 / T.s;
738
+ const lo = Math.min(a, b), hi = Math.max(a, b), gap = (64 * k) / T.s;
710
739
  const clash = ([x, y]: [number, number]) => (lo < y - 1e-6 && hi > x + 1e-6) || Math.abs((lo + hi) / 2 - (x + y) / 2) < gap;
711
740
  for (let r = 0; ; r++) {
712
741
  rows[r] = rows[r] || [];
@@ -934,9 +963,10 @@ function badgeSpots(T: Xform, sk: Sketch, c: Constraint): [number, number][] {
934
963
  const lid = lineBetween(sk, c.a!, c.b!);
935
964
  if (lid) onLine(lid, 0.22, -1);
936
965
  else {
966
+ // two points no line joins: on the dashed line drawn between them (pointPairLink), halfway
937
967
  const a = P(c.a!), b = P(c.b!);
938
968
  const [x1, y1] = S(T, a.x, a.y), [x2, y2] = S(T, b.x, b.y);
939
- out.push([(x1 + x2) / 2 + 10, (y1 + y2) / 2 - 10]);
969
+ out.push([(x1 + x2) / 2, (y1 + y2) / 2]);
940
970
  }
941
971
  } else if (['par', 'perp', 'col', 'eq', 'angle'].includes(c.type)) {
942
972
  onLine(c.l1, 0.75, -1); onLine(c.l2, 0.75, -1);
@@ -965,16 +995,46 @@ function badgeSpots(T: Xform, sk: Sketch, c: Constraint): [number, number][] {
965
995
  return out;
966
996
  }
967
997
 
998
+ /**
999
+ * Horizontal or Vertical between two points no line joins: the two points it ties, for drawing a dashed line between
1000
+ * them that its badge sits on (the user's call, 2026-11-05: the badge "is floating so u have no idea what it is related
1001
+ * to"). Null for any other constraint.
1002
+ */
1003
+ function pointPairLink(sk: Sketch, k: Constraint): [XY, XY] | null {
1004
+ if ((k.type !== 'h' && k.type !== 'v') || lineBetween(sk, k.a!, k.b!)) return null;
1005
+ const a = sk.points[k.a!], b = sk.points[k.b!];
1006
+ return a && b ? [a, b] : null;
1007
+ }
1008
+
968
1009
  function drawBadges(c: C2D, T: Xform, sk: Sketch): void {
969
1010
  const { W, H } = cvs;
970
1011
  const selIds = new Set(ed.sel.map(s => s.id)), selPts = selPoints(sk);
1012
+ const shown: string[] = [];
971
1013
  for (const id in sk.cons) {
972
1014
  const k = sk.cons[id];
973
- if (isDim(k) || k.elev) continue;
974
- const g = GLYPH[k.type];
975
- if (!g) continue;
1015
+ if (isDim(k) || k.elev || !GLYPH[k.type]) continue;
976
1016
  const related = selIds.has(id) || [k.l, k.l1, k.l2, k.c, k.c1, k.c2].some(x => x && selIds.has(x)) || [k.a, k.b, k.p].some(x => x && selPts.has(x));
977
1017
  if (!settings.showCons && !related && !ed.highlight.has(id)) continue;
1018
+ shown.push(id);
1019
+ }
1020
+ // first the lines between the points a two-point Horizontal or Vertical ties: faint and dashed, yellow with a ring
1021
+ // on each point while it's selected, red when it can't be met — under every badge
1022
+ for (const id of shown) {
1023
+ const ends = pointPairLink(sk, sk.cons[id]);
1024
+ if (!ends) continue;
1025
+ const [x1, y1] = S(T, ends[0].x, ends[0].y), [x2, y2] = S(T, ends[1].x, ends[1].y);
1026
+ if (hyp(x2 - x1, y2 - y1) < 24) continue;
1027
+ const selected = isSel('cons', id), bad = ed.highlight.has(id) || ed.ana.bad.has(id);
1028
+ c.save();
1029
+ c.strokeStyle = bad ? TH.red : selected ? TH.yellow : TH.badgeline; c.lineWidth = selected || bad ? 1.5 : 1;
1030
+ c.setLineDash([4, 4]);
1031
+ c.beginPath(); c.moveTo(x1, y1); c.lineTo(x2, y2); c.stroke();
1032
+ c.setLineDash([]);
1033
+ if (selected) for (const [x, y] of [[x1, y1], [x2, y2]]) { c.beginPath(); c.arc(x, y, 8, 0, Math.PI * 2); c.lineWidth = 2.5; c.stroke(); }
1034
+ c.restore();
1035
+ }
1036
+ for (const id of shown) {
1037
+ const k = sk.cons[id], g = GLYPH[k.type]!;
978
1038
  for (const [x, y] of badgeSpots(T, sk, k)) {
979
1039
  if (x < -20 || y < -20 || x > W + 20 || y > H + 20) continue;
980
1040
  const selected = isSel('cons', id), bad = ed.highlight.has(id) || ed.ana.bad.has(id);
@@ -59,46 +59,57 @@ export interface UiView extends NavView { seq: number }
59
59
  /** What the drawing on screen was drawn at: its view, the latest of the fingers' views it includes, the screen size. */
60
60
  export interface DrawnAt { view: NavView; seq: number; W: number; H: number }
61
61
 
62
- /** The fingers on the screen and what they're doing: navigating or not, where they were last, whether a pen has been seen. */
63
- export interface NavState { fingers: Record<number, { x: number; y: number }>; navigating: boolean; last: Pinch | null; pen: boolean }
62
+ /**
63
+ * The pointers on the screen and what they're doing: the fingers that count (a finger a Pencil landed on doesn't — see
64
+ * navTouch), navigating or not, where they were last, and any Pencil down.
65
+ */
66
+ export interface NavState { fingers: Record<number, { x: number; y: number }>; navigating: boolean; last: Pinch | null; pens: number[] }
64
67
 
65
68
  export const NAV_DOWN = 0, NAV_MOVE = 1, NAV_UP = 2, NAV_CANCEL = 3;
66
69
 
67
70
  /**
68
71
  * One touch event, as the UI thread sees it: the fingers after it, and the view (moved if `moved`). Fingers navigate —
69
- * pan, and zoom about their middle — once two are down, or any one once a pen has been seen or when the drawing is
70
- * view only (editor/gestures.ts decides the same on its side), until the last one lifts. A pen or a mouse never
71
- * navigates. `type` is NAV_DOWN… ; `allIds`, every pointer still down (on a down event: a finger that went without
72
- * a word, a lost touch-up, is dropped so it can't hold a gesture open).
72
+ * pan, and zoom about their middle — once two are down, or a finger lands while a Pencil is down or when the drawing is
73
+ * view only (editor/gestures.ts decides the same on its side), until the last one lifts. A finger already down and not
74
+ * navigating when a Pencil lands is set aside until it lifts. A pen or a mouse never navigates. `type` is NAV_DOWN… ;
75
+ * `kind` is the event's pointer, for a touch that doesn't say what it is itself; `allIds`, every pointer still down (on
76
+ * a down event: a finger that went without a word, a lost touch-up, is dropped so it can't hold a gesture open).
73
77
  */
74
78
  export function navTouch(
75
- st: NavState, type: number, kind: string, changed: { id: number; x: number; y: number }[], allIds: number[] | null,
79
+ st: NavState, type: number, kind: string, changed: { id: number; x: number; y: number; kind?: string }[], allIds: number[] | null,
76
80
  readOnly: boolean, view: UiView, drawn: DrawnAt | null,
77
81
  ): { st: NavState; view: UiView; moved: boolean } {
78
82
  'worklet';
79
- const pen = st.pen || kind === 'pen';
80
- if (kind !== 'touch') return { st: { ...st, pen }, view, moved: false };
83
+ const lost = (id: number) => type === NAV_DOWN && !!allIds && !allIds.includes(id);
81
84
  const fingers: Record<number, { x: number; y: number }> = {};
82
- for (const k in st.fingers) {
83
- const id = Number(k);
84
- if (type !== NAV_DOWN || !allIds || allIds.includes(id)) fingers[id] = st.fingers[id];
85
- }
85
+ for (const k in st.fingers) if (!lost(Number(k))) fingers[Number(k)] = st.fingers[Number(k)];
86
+ let pens = st.pens.filter(id => !lost(id)), landed = false, moved = false;
86
87
  for (const t of changed) {
87
- if (type === NAV_UP || type === NAV_CANCEL) delete fingers[t.id];
88
- else fingers[t.id] = { x: t.x, y: t.y };
88
+ const k = t.kind ?? kind;
89
+ if (type === NAV_UP || type === NAV_CANCEL) {
90
+ delete fingers[t.id];
91
+ pens = pens.filter(id => id !== t.id);
92
+ } else if (type === NAV_DOWN && k === 'pen') {
93
+ if (!pens.includes(t.id)) pens = [...pens, t.id];
94
+ // (fingers down and not navigating are let go of: their moves and lifts are no finger's from here)
95
+ if (!st.navigating) for (const f in fingers) delete fingers[f];
96
+ } else if (type === NAV_DOWN ? k === 'touch' : t.id in fingers) {
97
+ fingers[t.id] = { x: t.x, y: t.y };
98
+ if (type === NAV_DOWN) landed = true; else moved = true;
99
+ }
89
100
  }
90
101
  const pts = Object.keys(fingers).map(k => fingers[Number(k)]);
91
- if (!pts.length) return { st: { fingers, navigating: false, last: null, pen }, view, moved: false };
102
+ if (!pts.length) return { st: { fingers, navigating: false, last: null, pens }, view, moved: false };
92
103
  let navigating = st.navigating, v = view;
93
104
  if (!navigating) {
94
- if (pts.length < 2 && !(type === NAV_DOWN && (pen || readOnly))) return { st: { fingers, navigating: false, last: null, pen }, view, moved: false };
105
+ if (pts.length < 2 && !(landed && (pens.length > 0 || readOnly))) return { st: { fingers, navigating: false, last: null, pens }, view, moved: false };
95
106
  navigating = true;
96
107
  // start from the view the drawing on screen was drawn at, unless the fingers' own is newer
97
108
  if (drawn && v.seq <= drawn.seq) v = { s: drawn.view.s, cx: drawn.view.cx, cy: drawn.view.cy, seq: drawn.seq };
98
109
  }
99
- const now = pinchOf(pts), was = st.last, next = { fingers, navigating, last: now, pen };
100
- // a finger came or went: carry on from here, no jump
101
- if (type !== NAV_MOVE || !now || !was || was.n !== now.n || !drawn) return { st: next, view: v, moved: false };
110
+ const now = pinchOf(pts), was = st.last, next = { fingers, navigating, last: now, pens };
111
+ // a finger came or went: carry on from here, no jump (and a Pencil's move alone moves no view)
112
+ if (type !== NAV_MOVE || !moved || !now || !was || was.n !== now.n || !drawn) return { st: next, view: v, moved: false };
102
113
  const to = navStep(v, was, now, drawn.W, drawn.H);
103
114
  return { st: next, view: { s: to.s, cx: to.cx, cy: to.cy, seq: v.seq + 1 }, moved: true };
104
115
  }