@reekon-tools/boldr-cad 1.5.0 → 1.7.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.
- package/README.md +12 -1
- package/dist/app/state.d.ts +3 -3
- package/dist/data/provider.d.ts +2 -1
- package/dist/data/sync.js +4 -1
- package/dist/data/sync.js.map +1 -1
- package/dist/editor/actions.js +122 -19
- package/dist/editor/actions.js.map +1 -1
- package/dist/editor/advance.d.ts +2 -0
- package/dist/editor/advance.js +23 -0
- package/dist/editor/advance.js.map +1 -0
- package/dist/editor/dimSize.d.ts +13 -0
- package/dist/editor/dimSize.js +50 -0
- package/dist/editor/dimSize.js.map +1 -0
- package/dist/editor/gestures.js +30 -7
- package/dist/editor/gestures.js.map +1 -1
- package/dist/editor/keypad.d.ts +8 -0
- package/dist/editor/keypad.js +15 -1
- package/dist/editor/keypad.js.map +1 -1
- package/dist/editor/keys.js +2 -1
- package/dist/editor/keys.js.map +1 -1
- package/dist/editor/laser.d.ts +13 -2
- package/dist/editor/laser.js +42 -14
- package/dist/editor/laser.js.map +1 -1
- package/dist/editor/linkActions.d.ts +29 -11
- package/dist/editor/linkActions.js +76 -29
- package/dist/editor/linkActions.js.map +1 -1
- package/dist/editor/links.d.ts +13 -0
- package/dist/editor/links.js +7 -1
- package/dist/editor/links.js.map +1 -1
- package/dist/editor/mode.d.ts +2 -1
- package/dist/editor/mode.js +7 -5
- package/dist/editor/mode.js.map +1 -1
- package/dist/editor/ports.d.ts +9 -0
- package/dist/editor/ports.js +2 -0
- package/dist/editor/ports.js.map +1 -1
- package/dist/editor/selection.js +1 -1
- package/dist/editor/selection.js.map +1 -1
- package/dist/editor/tooltips.js +1 -0
- package/dist/editor/tooltips.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/model/clockwise.d.ts +11 -0
- package/dist/model/clockwise.js +123 -0
- package/dist/model/clockwise.js.map +1 -0
- package/dist/model/constraints.js +2 -0
- package/dist/model/constraints.js.map +1 -1
- package/dist/model/geom.d.ts +2 -0
- package/dist/model/geom.js +11 -0
- package/dist/model/geom.js.map +1 -1
- package/dist/model/links.d.ts +6 -1
- package/dist/model/links.js +6 -1
- package/dist/model/links.js.map +1 -1
- package/dist/model/scale.js +3 -0
- package/dist/model/scale.js.map +1 -1
- package/dist/model/settings.d.ts +2 -0
- package/dist/model/settings.js +1 -1
- package/dist/model/settings.js.map +1 -1
- package/dist/model/sketch.d.ts +5 -1
- package/dist/model/sketch.js +19 -18
- package/dist/model/sketch.js.map +1 -1
- package/dist/model/trim.d.ts +54 -0
- package/dist/model/trim.js +219 -0
- package/dist/model/trim.js.map +1 -0
- package/dist/model/types.d.ts +24 -2
- package/dist/react/BottomBar.js +94 -25
- package/dist/react/BottomBar.js.map +1 -1
- package/dist/react/CadEditor.js +18 -9
- package/dist/react/CadEditor.js.map +1 -1
- package/dist/react/Drawer.js +3 -2
- package/dist/react/Drawer.js.map +1 -1
- package/dist/react/PlanCanvas.native.js +15 -9
- package/dist/react/PlanCanvas.native.js.map +1 -1
- package/dist/react/PlanCanvas.web.js +17 -5
- package/dist/react/PlanCanvas.web.js.map +1 -1
- package/dist/react/ShapeMenu.js +3 -2
- package/dist/react/ShapeMenu.js.map +1 -1
- package/dist/react/ToolTip.js +3 -2
- package/dist/react/ToolTip.js.map +1 -1
- package/dist/react/TopBar.js +4 -3
- package/dist/react/TopBar.js.map +1 -1
- package/dist/react/editorBox.d.ts +8 -0
- package/dist/react/editorBox.js +10 -0
- package/dist/react/editorBox.js.map +1 -0
- package/dist/react/host.d.ts +7 -1
- package/dist/react/host.js +12 -2
- package/dist/react/host.js.map +1 -1
- package/dist/react/pageLock.native.d.ts +2 -0
- package/dist/react/pageLock.native.js +2 -0
- package/dist/react/pageLock.native.js.map +1 -1
- package/dist/react/pageLock.web.d.ts +6 -0
- package/dist/react/pageLock.web.js +12 -3
- package/dist/react/pageLock.web.js.map +1 -1
- package/dist/react/ports.js +10 -4
- package/dist/react/ports.js.map +1 -1
- package/dist/react/saving.d.ts +7 -1
- package/dist/react/saving.js +10 -2
- package/dist/react/saving.js.map +1 -1
- package/dist/react/store.d.ts +5 -2
- package/dist/react/store.js +4 -1
- package/dist/react/store.js.map +1 -1
- package/dist/render/draw.d.ts +7 -0
- package/dist/render/draw.js +41 -15
- package/dist/render/draw.js.map +1 -1
- package/dist/render/linkTile.js +2 -2
- package/dist/render/linkTile.js.map +1 -1
- package/dist/render/navigate.d.ts +11 -6
- package/dist/render/navigate.js +34 -20
- package/dist/render/navigate.js.map +1 -1
- package/dist/render/snap.d.ts +5 -0
- package/dist/render/snap.js +84 -14
- package/dist/render/snap.js.map +1 -1
- package/dist/render/view.js +7 -2
- package/dist/render/view.js.map +1 -1
- package/dist/solver/equations.js +30 -16
- package/dist/solver/equations.js.map +1 -1
- package/dist/tools/dim.d.ts +6 -0
- package/dist/tools/dim.js +28 -4
- package/dist/tools/dim.js.map +1 -1
- package/dist/tools/modify.d.ts +32 -4
- package/dist/tools/modify.js +247 -97
- package/dist/tools/modify.js.map +1 -1
- package/dist/tools/registry.d.ts +2 -0
- package/dist/tools/registry.js +8 -0
- package/dist/tools/registry.js.map +1 -1
- package/dist/tools/select.d.ts +11 -8
- package/dist/tools/select.js +51 -19
- package/dist/tools/select.js.map +1 -1
- package/package.json +1 -1
- package/src/app/state.ts +3 -3
- package/src/data/provider.ts +2 -2
- package/src/data/sync.ts +4 -1
- package/src/editor/actions.ts +98 -16
- package/src/editor/advance.ts +23 -0
- package/src/editor/dimSize.ts +53 -0
- package/src/editor/gestures.ts +31 -9
- package/src/editor/keypad.ts +17 -1
- package/src/editor/keys.ts +2 -1
- package/src/editor/laser.ts +45 -14
- package/src/editor/linkActions.ts +87 -26
- package/src/editor/links.ts +17 -1
- package/src/editor/mode.ts +7 -5
- package/src/editor/ports.ts +10 -0
- package/src/editor/selection.ts +1 -1
- package/src/editor/tooltips.ts +1 -0
- package/src/index.ts +2 -2
- package/src/model/clockwise.ts +121 -0
- package/src/model/constraints.ts +1 -0
- package/src/model/geom.ts +10 -0
- package/src/model/links.ts +6 -1
- package/src/model/scale.ts +2 -0
- package/src/model/settings.ts +3 -1
- package/src/model/sketch.ts +14 -7
- package/src/model/trim.ts +188 -0
- package/src/model/types.ts +19 -2
- package/src/react/BottomBar.tsx +109 -25
- package/src/react/CadEditor.tsx +19 -9
- package/src/react/Drawer.tsx +3 -2
- package/src/react/PlanCanvas.native.tsx +25 -12
- package/src/react/PlanCanvas.web.tsx +17 -5
- package/src/react/ShapeMenu.tsx +3 -2
- package/src/react/ToolTip.tsx +3 -2
- package/src/react/TopBar.tsx +4 -3
- package/src/react/editorBox.ts +20 -0
- package/src/react/host.ts +12 -2
- package/src/react/pageLock.native.ts +2 -0
- package/src/react/pageLock.web.ts +12 -3
- package/src/react/ports.ts +10 -4
- package/src/react/saving.ts +10 -2
- package/src/react/store.ts +5 -2
- package/src/render/draw.ts +38 -16
- package/src/render/linkTile.ts +2 -2
- package/src/render/navigate.ts +31 -20
- package/src/render/snap.ts +80 -15
- package/src/render/view.ts +6 -2
- package/src/solver/equations.ts +30 -16
- package/src/tools/dim.ts +28 -4
- package/src/tools/modify.ts +205 -69
- package/src/tools/registry.ts +8 -0
- package/src/tools/select.ts +47 -20
- package/src/ui/domPorts.ts +2 -0
- package/dist/react/LaserTray.d.ts +0 -4
- package/dist/react/LaserTray.js +0 -26
- package/dist/react/LaserTray.js.map +0 -1
- package/src/react/LaserTray.tsx +0 -42
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { circleCircle, distSeg, hyp, lineCircleT, normAng, projT, segInter } from './geom';
|
|
2
|
+
import { arcAngles } from './planGeom';
|
|
3
|
+
import type { Sketch, XY } from './types';
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
Trim's geometry (the tool and the cutting: tools/modify.ts). An item — a line (a wall, a guide), an arc or a circle — is
|
|
7
|
+
cut wherever something crosses it, and wherever a point something else is attached at lies on it: another line's or
|
|
8
|
+
arc's end resting on it (a T, an arc drawn into a corner), a point held on it. A tap takes away the piece between the
|
|
9
|
+
cuts either side of it. Nothing here edits the sketch.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export type TrimKind = 'line' | 'arc' | 'circle';
|
|
13
|
+
export interface TrimItem { kind: TrimKind; id: string }
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A cut along an item: where (`at` — a line's 0..1 from A to B; an arc's angle round from its start, 0 to its sweep; a
|
|
17
|
+
* circle's angle, 0 to 2π; counter-clockwise) and what makes it: a point already there (`pt` — the trimmed end is that
|
|
18
|
+
* point, so what meets there stays joined), or a crossing (`line` / `curve` — a new point, held on what it crosses).
|
|
19
|
+
*/
|
|
20
|
+
export interface Cut { at: number; x: number; y: number; pt?: string; line?: string; curve?: string }
|
|
21
|
+
|
|
22
|
+
/** The piece of an item between two cuts. Null: the item's own end — a circle has none, so either null is all of it. */
|
|
23
|
+
export interface TrimPiece { item: TrimItem; lo: Cut | null; hi: Cut | null }
|
|
24
|
+
|
|
25
|
+
/** A curve's circle, and the part of it that's there: from t0, counter-clockwise, `sweep` round (a circle's: all of it). */
|
|
26
|
+
interface Round { o: XY; r: number; t0: number; sweep: number }
|
|
27
|
+
|
|
28
|
+
function roundOf(sk: Sketch, it: TrimItem): Round | null {
|
|
29
|
+
if (it.kind === 'circle') {
|
|
30
|
+
const ci = sk.circles[it.id], o = ci && sk.points[ci.c];
|
|
31
|
+
return o ? { o, r: ci.r, t0: 0, sweep: 2 * Math.PI } : null;
|
|
32
|
+
}
|
|
33
|
+
const a = it.kind === 'arc' ? sk.arcs[it.id] : undefined;
|
|
34
|
+
if (!a || !sk.points[a.c] || !sk.points[a.a] || !sk.points[a.b]) return null;
|
|
35
|
+
const g = arcAngles(sk, a);
|
|
36
|
+
return { o: g.o, r: g.r, t0: g.t0, sweep: g.full ? 2 * Math.PI : normAng(g.t1 - g.t0) };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** How far round from a round's start the direction to `p` is (radians, counter-clockwise). */
|
|
40
|
+
const roundAt = (R: Round, p: XY): number => normAng(Math.atan2(p.y - R.o.y, p.x - R.o.x) - R.t0);
|
|
41
|
+
|
|
42
|
+
/** How far `p` is from an item, as drawn (a wall: from its faces in); Infinity off its ends, or if it's gone. */
|
|
43
|
+
export function distTo(sk: Sketch, it: TrimItem, p: XY): number {
|
|
44
|
+
if (it.kind === 'line') {
|
|
45
|
+
const l = sk.lines[it.id], A = l && sk.points[l.a], B = l && sk.points[l.b];
|
|
46
|
+
if (!A || !B) return Infinity;
|
|
47
|
+
return Math.max(0, distSeg(p, A, B) - (l.kind === 'wall' ? l.thick / 2 : 0));
|
|
48
|
+
}
|
|
49
|
+
const R = roundOf(sk, it), o = it.kind === 'circle' ? sk.circles[it.id] : sk.arcs[it.id];
|
|
50
|
+
if (!R || !o || (it.kind === 'arc' && roundAt(R, p) > R.sweep)) return Infinity;
|
|
51
|
+
return Math.max(0, Math.abs(hyp(p.x - R.o.x, p.y - R.o.y) - R.r) - (o.kind === 'wall' ? (o.thick || 4.5) / 2 : 0));
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The point on an item (on its centreline, within its ends) nearest `p`: where on it a tap beside it is. */
|
|
55
|
+
export function nearestOn(sk: Sketch, it: TrimItem, p: XY): XY {
|
|
56
|
+
if (it.kind === 'line') {
|
|
57
|
+
const l = sk.lines[it.id], A = sk.points[l.a], B = sk.points[l.b], t = Math.max(0, Math.min(1, projT(A, B, p)));
|
|
58
|
+
return { x: A.x + (B.x - A.x) * t, y: A.y + (B.y - A.y) * t };
|
|
59
|
+
}
|
|
60
|
+
const R = roundOf(sk, it);
|
|
61
|
+
if (!R) return p;
|
|
62
|
+
const d = hyp(p.x - R.o.x, p.y - R.o.y) || 1;
|
|
63
|
+
return { x: R.o.x + ((p.x - R.o.x) / d) * R.r, y: R.o.y + ((p.y - R.o.y) / d) * R.r };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The line, arc or circle nearest `p`, within `tol`: what a trim there is of. Not a wall face's own edges (the plan's)
|
|
68
|
+
* or a cabinet's: those are whole things, not pieces to cut away.
|
|
69
|
+
*/
|
|
70
|
+
export function trimItemAt(sk: Sketch, p: XY, tol: number): TrimItem | null {
|
|
71
|
+
const best = { it: null as TrimItem | null, d: tol };
|
|
72
|
+
const consider = (it: TrimItem) => { const d = distTo(sk, it, p); if (d <= best.d) { best.it = it; best.d = d; } };
|
|
73
|
+
for (const id in sk.lines) if (!sk.lines[id].anchor && !sk.lines[id].cab) consider({ kind: 'line', id });
|
|
74
|
+
for (const id in sk.arcs) consider({ kind: 'arc', id });
|
|
75
|
+
for (const id in sk.circles) consider({ kind: 'circle', id });
|
|
76
|
+
return best.it;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Every cut along an item, in order. `tol` (inches): a point this near it is on it; a cut this near its own end isn't
|
|
81
|
+
* one; cuts this near each other are one (a point there wins over a crossing).
|
|
82
|
+
*/
|
|
83
|
+
export function cutsOn(sk: Sketch, it: TrimItem, tol: number): Cut[] {
|
|
84
|
+
const pt = (id: string): XY | undefined => sk.points[id];
|
|
85
|
+
let A: XY | undefined, B: XY | undefined, len = 0, R: Round | null = null;
|
|
86
|
+
if (it.kind === 'line') {
|
|
87
|
+
const l = sk.lines[it.id];
|
|
88
|
+
A = l && pt(l.a); B = l && pt(l.b);
|
|
89
|
+
if (!A || !B) return [];
|
|
90
|
+
len = hyp(B.x - A.x, B.y - A.y);
|
|
91
|
+
if (len < 1e-9) return [];
|
|
92
|
+
} else {
|
|
93
|
+
R = roundOf(sk, it);
|
|
94
|
+
if (!R || R.r < 1e-9) return [];
|
|
95
|
+
}
|
|
96
|
+
const raw: Cut[] = [];
|
|
97
|
+
/** Where `p` is along the item, if it's inside it (clear of the item's own ends). */
|
|
98
|
+
const along = (p: XY): number | null => {
|
|
99
|
+
if (A && B) { const t = projT(A, B, p); return t * len > tol && (1 - t) * len > tol ? t : null; }
|
|
100
|
+
const s = roundAt(R!, p);
|
|
101
|
+
return it.kind === 'circle' || (s < R!.sweep && s * R!.r > tol && (R!.sweep - s) * R!.r > tol) ? s : null;
|
|
102
|
+
};
|
|
103
|
+
const add = (p: XY, by: Omit<Cut, 'at' | 'x' | 'y'>) => { const at = along(p); if (at != null) raw.push({ at, x: p.x, y: p.y, ...by }); };
|
|
104
|
+
|
|
105
|
+
// what crosses it: lines…
|
|
106
|
+
for (const id in sk.lines) {
|
|
107
|
+
if (it.kind === 'line' && id === it.id) continue;
|
|
108
|
+
const l = sk.lines[id], C = pt(l.a), D = pt(l.b);
|
|
109
|
+
if (!C || !D) continue;
|
|
110
|
+
if (A && B) { const r = segInter(A, B, C, D); if (r) add(r, { line: id }); }
|
|
111
|
+
else for (const t of lineCircleT(C, D, R!.o, R!.r)) add({ x: C.x + (D.x - C.x) * t, y: C.y + (D.y - C.y) * t }, { line: id });
|
|
112
|
+
}
|
|
113
|
+
// …and arcs and circles (an arc only where it's drawn)
|
|
114
|
+
const curves: TrimItem[] = [...Object.keys(sk.circles).map(id => ({ kind: 'circle' as const, id })), ...Object.keys(sk.arcs).map(id => ({ kind: 'arc' as const, id }))];
|
|
115
|
+
for (const cv of curves) {
|
|
116
|
+
if (cv.kind === it.kind && cv.id === it.id) continue;
|
|
117
|
+
const Q = roundOf(sk, cv);
|
|
118
|
+
if (!Q) continue;
|
|
119
|
+
const hits = A && B ? lineCircleT(A, B, Q.o, Q.r).map(t => ({ x: A!.x + (B!.x - A!.x) * t, y: A!.y + (B!.y - A!.y) * t })) : circleCircle(R!.o, R!.r, Q.o, Q.r);
|
|
120
|
+
for (const p of hits) if (cv.kind === 'circle' || roundAt(Q, p) <= Q.sweep + 1e-9) add(p, { curve: cv.id });
|
|
121
|
+
}
|
|
122
|
+
// the points on it that something else is attached at: other lines' and arcs' ends, points held on it
|
|
123
|
+
const held = new Set<string>();
|
|
124
|
+
for (const id in sk.lines) if (!(it.kind === 'line' && id === it.id)) { held.add(sk.lines[id].a); held.add(sk.lines[id].b); }
|
|
125
|
+
for (const id in sk.arcs) if (!(it.kind === 'arc' && id === it.id)) { held.add(sk.arcs[id].a); held.add(sk.arcs[id].b); }
|
|
126
|
+
for (const c of Object.values(sk.cons)) if (c.p && ((c.type === 'online' && !c.face && c.l === it.id) || (c.type === 'oncircle' && c.c === it.id))) held.add(c.p);
|
|
127
|
+
for (const id of held) {
|
|
128
|
+
const P = pt(id);
|
|
129
|
+
if (!P) continue;
|
|
130
|
+
const off = A && B ? distSeg(P, A, B) : Math.abs(hyp(P.x - R!.o.x, P.y - R!.o.y) - R!.r);
|
|
131
|
+
if (off <= tol) add(P, { pt: id });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
raw.sort((a, b) => a.at - b.at);
|
|
135
|
+
const scale = A && B ? len : R!.r, out: Cut[] = [];
|
|
136
|
+
for (const c of raw) {
|
|
137
|
+
const last = out[out.length - 1];
|
|
138
|
+
if (last && (c.at - last.at) * scale <= tol) { if (c.pt && !last.pt) out[out.length - 1] = c; continue; }
|
|
139
|
+
out.push(c);
|
|
140
|
+
}
|
|
141
|
+
// (round a circle, the last cut and the first can be one place)
|
|
142
|
+
if (it.kind === 'circle' && out.length > 1 && (2 * Math.PI - out[out.length - 1].at + out[0].at) * scale <= tol) {
|
|
143
|
+
const last = out.pop()!;
|
|
144
|
+
if (last.pt && !out[0].pt) out[0] = last;
|
|
145
|
+
}
|
|
146
|
+
return out;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** The piece of an item around `p` (on it): between the cuts either side of it. */
|
|
150
|
+
export function pieceAt(sk: Sketch, it: TrimItem, p: XY, tol: number): TrimPiece {
|
|
151
|
+
const cuts = cutsOn(sk, it, tol);
|
|
152
|
+
let at: number;
|
|
153
|
+
if (it.kind === 'line') { const l = sk.lines[it.id]; at = projT(sk.points[l.a], sk.points[l.b], p); }
|
|
154
|
+
else { const R = roundOf(sk, it); at = R ? roundAt(R, p) : 0; }
|
|
155
|
+
if (it.kind === 'circle') {
|
|
156
|
+
// round a circle, the cut before it (from the last, if none is) and the one after (the first, if none is)
|
|
157
|
+
if (cuts.length < 2) return { item: it, lo: null, hi: null };
|
|
158
|
+
let lo = cuts[cuts.length - 1], hi = cuts[0];
|
|
159
|
+
for (const c of cuts) if (c.at <= at) lo = c;
|
|
160
|
+
for (const c of cuts) if (c.at > at) { hi = c; break; }
|
|
161
|
+
return { item: it, lo, hi };
|
|
162
|
+
}
|
|
163
|
+
let lo: Cut | null = null, hi: Cut | null = null;
|
|
164
|
+
for (const c of cuts) { if (c.at <= at) lo = c; else if (!hi) hi = c; }
|
|
165
|
+
return { item: it, lo, hi };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** A piece as it's drawn: a segment, or a circle's arc from t0 counter-clockwise to t1 (radians). */
|
|
169
|
+
export type PieceShape = { a: XY; b: XY } | { o: XY; r: number; t0: number; t1: number };
|
|
170
|
+
|
|
171
|
+
export function pieceShape(sk: Sketch, pc: TrimPiece): PieceShape | null {
|
|
172
|
+
const it = pc.item;
|
|
173
|
+
if (it.kind === 'line') {
|
|
174
|
+
const l = sk.lines[it.id], A = l && sk.points[l.a], B = l && sk.points[l.b];
|
|
175
|
+
return A && B ? { a: pc.lo ?? A, b: pc.hi ?? B } : null;
|
|
176
|
+
}
|
|
177
|
+
const R = roundOf(sk, it);
|
|
178
|
+
if (!R) return null;
|
|
179
|
+
if (it.kind === 'circle') {
|
|
180
|
+
if (!pc.lo || !pc.hi) return { o: R.o, r: R.r, t0: 0, t1: 2 * Math.PI };
|
|
181
|
+
return { o: R.o, r: R.r, t0: pc.lo.at, t1: pc.hi.at > pc.lo.at ? pc.hi.at : pc.hi.at + 2 * Math.PI };
|
|
182
|
+
}
|
|
183
|
+
return { o: R.o, r: R.r, t0: R.t0 + (pc.lo?.at ?? 0), t1: R.t0 + (pc.hi?.at ?? R.sweep) };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** One key per piece: a stroke takes each piece once, however many times it crosses it. */
|
|
187
|
+
export const pieceKey = (pc: TrimPiece): string =>
|
|
188
|
+
pc.item.kind + ':' + pc.item.id + ':' + (pc.lo ? pc.lo.at.toFixed(9) : 's') + ':' + (pc.hi ? pc.hi.at.toFixed(9) : 'e');
|
package/src/model/types.ts
CHANGED
|
@@ -45,12 +45,14 @@ export interface Constraint {
|
|
|
45
45
|
/**
|
|
46
46
|
* dist, a wall's length: measured along this face of it — +1 the face to the left of its line's A → B, −1 the right
|
|
47
47
|
* — corner to corner, as a tape measure along it reads. diam, a curved wall's: across its outer face (+1) or its
|
|
48
|
-
* inner face (−1).
|
|
48
|
+
* inner face (−1). online, a point on a straight wall: on this face of it, half its thickness off the centreline.
|
|
49
|
+
* Unset, its centreline.
|
|
49
50
|
*/
|
|
50
51
|
face?: 1 | -1;
|
|
51
52
|
/**
|
|
52
53
|
* pldist between two walls (`l`, and `l2`, the wall `p` is on): which face of each it's measured from — +1 the face
|
|
53
|
-
* toward the other, −1 the far one, 0 the centreline; unset, both centrelines.
|
|
54
|
+
* toward the other, −1 the far one, 0 the centreline; unset, both centrelines. eq: each line's length along this face
|
|
55
|
+
* of it, corner to corner, as `face` is for a wall's length (+1 the left of its A → B, −1 the right, 0 as drawn).
|
|
54
56
|
*/
|
|
55
57
|
faces?: [number, number];
|
|
56
58
|
value?: number;
|
|
@@ -209,6 +211,8 @@ export interface LinkInfo {
|
|
|
209
211
|
/** whether it can be opened from the drawing, and its measurement changed from it (unset: yes) */
|
|
210
212
|
canOpen?: boolean;
|
|
211
213
|
canEdit?: boolean;
|
|
214
|
+
/** whether it can be shown in a pane beside the drawing, when the host has one (CadLinks.openBeside; unset: yes) */
|
|
215
|
+
canOpenBeside?: boolean;
|
|
212
216
|
}
|
|
213
217
|
export interface Note {
|
|
214
218
|
id: string;
|
|
@@ -299,6 +303,12 @@ export interface Sketch {
|
|
|
299
303
|
unscaled?: boolean;
|
|
300
304
|
/** what the first length scaled the sketch by (its view zoomed by the inverse, so nothing moved): undone, it zooms back */
|
|
301
305
|
scaledBy?: number;
|
|
306
|
+
/**
|
|
307
|
+
* The size the page's tiles were first placed at, inches on the drawing: what the Tile size slider calls 100%. It
|
|
308
|
+
* scales with the page when the first length gives it its scale, as the tiles do, so the percent holds. Unset on a
|
|
309
|
+
* page from before it (its tiles' size now is 100%, kept once the slider's used).
|
|
310
|
+
*/
|
|
311
|
+
tileRef?: number;
|
|
302
312
|
}
|
|
303
313
|
|
|
304
314
|
/** Photo or plan traced under the drawing. (x, y) is its top-left corner in world inches. */
|
|
@@ -316,6 +326,13 @@ export interface Underlay {
|
|
|
316
326
|
rot?: number;
|
|
317
327
|
/** locked images can't be moved, resized or turned (they still show, and can be unlocked) */
|
|
318
328
|
locked?: boolean;
|
|
329
|
+
/**
|
|
330
|
+
* Cropped by its side handles (the user's call, 2026-11-03: they crop, never stretch): what's trimmed off each side of
|
|
331
|
+
* the picture, as a share of it (0 to 1 — l and r across it, t and b down it, as it's seen before it's turned). x, y,
|
|
332
|
+
* w, h are the part that shows; the picture is drawn whole past them and clipped, so a side dragged back out brings
|
|
333
|
+
* it back. Unset: all of it shows.
|
|
334
|
+
*/
|
|
335
|
+
crop?: { l: number; t: number; r: number; b: number };
|
|
319
336
|
/**
|
|
320
337
|
* A photo of the job's, expanded from its tile (the user's call, 2026-10-26: "it expands the image to full size + shows
|
|
321
338
|
* a link icon in the corner", as Skia's annotation does): its picture is the one the host shows it as (LinkInfo.thumbUrl;
|
package/src/react/BottomBar.tsx
CHANGED
|
@@ -2,10 +2,10 @@ import { memo, useCallback, useEffect, useMemo, useRef, useState, type Component
|
|
|
2
2
|
import { Animated, ScrollView, Text, View } from 'react-native';
|
|
3
3
|
import { ed } from '../app/state';
|
|
4
4
|
import { applyCtxAction, barItems, deleteSelection, iconAlone, plusAction, plusLabel, plusVisible } from '../editor/actions';
|
|
5
|
-
import { addLinks, LINK_PLUS_LABEL, linkPlusVisible, linkSizeVisible, pageLinkSize,
|
|
5
|
+
import { addLinks, LINK_PLUS_LABEL, linkPlusVisible, linkSizeVisible, openLinkTarget, opensWithChoice, pageLinkSize, pageTilePct, pctToStep, selectedOpenTarget, setTilePct, SIZE_STEPS, stepToPct } from '../editor/linkActions';
|
|
6
6
|
import { afterEdit } from '../app/edit';
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { DIM_STEPS, dimPctToStep, dimSizeDone, dimSizeVisible, setDimPct, stepToDimPct } from '../editor/dimSize';
|
|
8
|
+
import { settings } from '../model/settings';
|
|
9
9
|
import { bar3d, run3d } from '../editor/view3d';
|
|
10
10
|
import { is3d } from '../editor/view3dState';
|
|
11
11
|
import { OPACITY_MIN, OPACITY_STEP, ROTATE_MAX, ROTATE_STEP, setUnderlayOpacity, setUnderlayRotation } from '../editor/project';
|
|
@@ -35,7 +35,7 @@ export function BottomBar({ phone }: { phone: boolean }) {
|
|
|
35
35
|
// what's in the bar and what it's for, and the selected image's opacity and turn (its sliders)
|
|
36
36
|
useEditorKey(() => {
|
|
37
37
|
const u = ed.sel.length === 1 && ed.sel[0].type === 'underlay' ? imageById(ed.sel[0].id) : undefined;
|
|
38
|
-
return [buttonsKey(), barFor(), plusVisible(), ed.sel.length, u ? u.opacity ?? 0.6 : '', u ? (u.rot ?? 0) + (u.locked ? 'L' : '') : '', linkPlusVisible(), ui.linkFab, linkSizeVisible(), pageLinkSize() ?? ''].join('|');
|
|
38
|
+
return [buttonsKey(), barFor(), plusVisible(), ed.sel.length, u ? u.opacity ?? 0.6 : '', u ? (u.rot ?? 0) + (u.locked ? 'L' : '') : '', linkPlusVisible(), ui.linkFab, linkSizeVisible(), pageLinkSize() ?? '', dimSizeVisible(), settings.chipPct].join('|');
|
|
39
39
|
});
|
|
40
40
|
// (on a phone only buttons show: a bar that would hold just a label isn't shown at all. The 3D tab measures and
|
|
41
41
|
// deletes nothing: what's tapped there shows its sizes, and what can be done with it from there)
|
|
@@ -56,6 +56,8 @@ export function BottomBar({ phone }: { phone: boolean }) {
|
|
|
56
56
|
<View style={[s.bottom, phone ? s.phoneRow : s.centered]} onLayout={e => setRow(e.nativeEvent.layout.width)}>
|
|
57
57
|
<ImagePopover />
|
|
58
58
|
<LinkSizePopover />
|
|
59
|
+
<DimSizePopover />
|
|
60
|
+
<OpenPopover />
|
|
59
61
|
{/* a phone's bar sits between two springs that start as wide as the trash takes and share what's left
|
|
60
62
|
equally, so it's centred; only the left one gives way (first, before the bar), so a long bar slides left
|
|
61
63
|
to clear the trash. (A minimum width on the right one alone did that in a browser, but a device's layout
|
|
@@ -196,8 +198,14 @@ const BarButtons = memo(function BarButtons({ phone, onWidth }: { k: string; pho
|
|
|
196
198
|
return (
|
|
197
199
|
<Tap key={it.act + i} onLayout={e => onWidth(i, e.nativeEvent.layout.width)} accessibilityRole="button" accessibilityLabel={it.label}
|
|
198
200
|
accessibilityState={it.on != null || it.locked != null ? { selected: !!(it.on || it.locked) } : undefined}
|
|
199
|
-
onPress={e => {
|
|
200
|
-
|
|
201
|
+
onPress={e => {
|
|
202
|
+
if (is3d() && run3d(it.act)) return;
|
|
203
|
+
// (Open asks how — here, or beside the drawing — where the host can show it there and no pane's open yet)
|
|
204
|
+
const t = isOpen(it.act) ? selectedOpenTarget() : null;
|
|
205
|
+
if (t && opensWithChoice(t)) { ui.imgPop = ui.imgPop === 'open' ? null : 'open'; notify(); return; }
|
|
206
|
+
applyCtxAction(it.act, e.currentTarget);
|
|
207
|
+
}}
|
|
208
|
+
style={st => [s.cb, iconAlone(it) && s.lead, it.on || (it.act === 'imgOpacity' && ui.imgPop === 'opacity') || (it.act === 'imgRotate' && ui.imgPop === 'rotate') || (it.act === 'linkSize' && ui.imgPop === 'tilesize') || (it.act === 'dimSize' && ui.imgPop === 'dimsize') || (isOpen(it.act) && ui.imgPop === 'open') ? { backgroundColor: 'rgba(255,255,255,0.14)' } : null,
|
|
201
209
|
it.on ? { backgroundColor: '#fff' } : hovered(st) && { backgroundColor: 'rgba(255,255,255,0.08)' }]}>
|
|
202
210
|
<Icon name={it.ic} color={fg} />
|
|
203
211
|
{/* (the bar's lead — Lock, or Open — and Lock wherever it is: its icon alone, its name said, not shown) */}
|
|
@@ -209,6 +217,41 @@ const BarButtons = memo(function BarButtons({ phone, onWidth }: { k: string; pho
|
|
|
209
217
|
);
|
|
210
218
|
});
|
|
211
219
|
|
|
220
|
+
/** The bar's Open: a tile's or expanded photo's, or a linked dimension's. */
|
|
221
|
+
const isOpen = (act: string): boolean => act === 'linkOpen' || act === 'dimLinkOpen';
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Open's question, just above the bar (the user's call, 2026-10-30): Open, the host's own way as before, or Open side
|
|
225
|
+
* by side, in a pane beside the drawing. Asked only where the host can show it there and no pane is open yet
|
|
226
|
+
* (opensWithChoice); a press on the drawing closes it, as it does the bar's sliders.
|
|
227
|
+
*/
|
|
228
|
+
function OpenPopover() {
|
|
229
|
+
const t = ui.imgPop === 'open' ? selectedOpenTarget() : null, open = !!t && opensWithChoice(t);
|
|
230
|
+
const pop = usePopup(open, { y: 8 }, 'bottom center');
|
|
231
|
+
if (!pop.present) return null;
|
|
232
|
+
const go = (how: 'here' | 'beside') => {
|
|
233
|
+
const target = selectedOpenTarget();
|
|
234
|
+
ui.imgPop = null;
|
|
235
|
+
notify();
|
|
236
|
+
if (target) openLinkTarget(target, how);
|
|
237
|
+
};
|
|
238
|
+
return (
|
|
239
|
+
<View style={s.popWrap} pointerEvents="box-none">
|
|
240
|
+
<Animated.View style={[s.pop, s.choices, pop.style]} pointerEvents={open ? 'auto' : 'none'} testID={open ? 'openPop' : undefined}>
|
|
241
|
+
<Tap feel="dim" accessibilityRole="button" accessibilityLabel="Open" testID="openHere" onPress={() => go('here')}
|
|
242
|
+
style={st => [s.choice, hovered(st) && s.choiceHover]}>
|
|
243
|
+
<Text style={s.choiceText}>Open</Text>
|
|
244
|
+
</Tap>
|
|
245
|
+
<View style={s.sep} />
|
|
246
|
+
<Tap feel="dim" accessibilityRole="button" accessibilityLabel="Open side by side" testID="openBeside" onPress={() => go('beside')}
|
|
247
|
+
style={st => [s.choice, hovered(st) && s.choiceHover]}>
|
|
248
|
+
<Text style={s.choiceText}>Open side by side</Text>
|
|
249
|
+
</Tap>
|
|
250
|
+
</Animated.View>
|
|
251
|
+
</View>
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
|
|
212
255
|
/** Degrees, as the rotation slider shows them: whole, or to the half degree. */
|
|
213
256
|
const fmtDeg = (v: number): string => (Math.round(v * 2) / 2).toString().replace('-', '−') + '°';
|
|
214
257
|
|
|
@@ -270,36 +313,32 @@ function ImagePopover() {
|
|
|
270
313
|
);
|
|
271
314
|
}
|
|
272
315
|
|
|
273
|
-
/** A tile size from the slider, as it's kept: to the quarter inch. */
|
|
274
|
-
const tileSize = (step: number): number => Math.round(stepToSize(step) * 4) / 4;
|
|
275
|
-
|
|
276
316
|
/**
|
|
277
317
|
* The tiles' size, just above the bar (Size in it opens and closes it): one size for every tile on the page, on the drawing
|
|
278
|
-
* (they zoom with the plan and print at it)
|
|
279
|
-
*
|
|
318
|
+
* (they zoom with the plan and print at it), said in percent of the size they came in at — never feet or metres (the
|
|
319
|
+
* user's call, 2026-11-03: see editor/linkActions.ts). Kept quick on a device, as ImagePopover is: the thumb and the
|
|
320
|
+
* number follow the finger from here, the tiles are sized at most once a frame, and the rest of the editor hears of it
|
|
321
|
+
* as it's let go.
|
|
280
322
|
*/
|
|
281
323
|
function LinkSizePopover() {
|
|
282
324
|
const [live, setLive] = useState<number | null>(null);
|
|
283
|
-
// the number's width as it was laid out, held while a drag goes on (the track ends at it: as long as the number is,
|
|
284
|
-
// no longer — but never narrower mid-drag, which would move the track under the finger)
|
|
285
|
-
const [numW, setNumW] = useState(0);
|
|
286
325
|
const pending = useRef<{ v: number; frame: number } | null>(null);
|
|
287
326
|
// (opened from the bar's Size, as an image's sliders are; a press on the drawing closes it)
|
|
288
|
-
const
|
|
327
|
+
const pct = ui.imgPop === 'tilesize' && linkSizeVisible() ? pageTilePct() : null, open = pct != null;
|
|
289
328
|
// (as it goes it keeps showing the size it had)
|
|
290
|
-
const last = useRef(
|
|
291
|
-
if (
|
|
329
|
+
const last = useRef(pct ?? 100), pop = usePopup(open, { y: 8 }, 'bottom center');
|
|
330
|
+
if (pct != null) last.current = pct;
|
|
292
331
|
if (!pop.present) return null;
|
|
293
|
-
const value = live ??
|
|
332
|
+
const value = live ?? pctToStep(last.current);
|
|
294
333
|
const change = (v: number) => {
|
|
295
334
|
setLive(v);
|
|
296
335
|
const p = pending.current;
|
|
297
336
|
if (p) { p.v = v; return; }
|
|
298
|
-
pending.current = { v, frame: requestAnimationFrame(() => { const q = pending.current; pending.current = null; if (q)
|
|
337
|
+
pending.current = { v, frame: requestAnimationFrame(() => { const q = pending.current; pending.current = null; if (q) setTilePct(stepToPct(q.v)); }) };
|
|
299
338
|
};
|
|
300
339
|
const end = () => {
|
|
301
340
|
const p = pending.current;
|
|
302
|
-
if (p) { cancelAnimationFrame(p.frame); pending.current = null;
|
|
341
|
+
if (p) { cancelAnimationFrame(p.frame); pending.current = null; setTilePct(stepToPct(p.v)); }
|
|
303
342
|
setLive(null);
|
|
304
343
|
afterEdit();
|
|
305
344
|
notify();
|
|
@@ -309,11 +348,52 @@ function LinkSizePopover() {
|
|
|
309
348
|
<Animated.View style={[s.pop, pop.style]} pointerEvents={open ? 'auto' : 'none'} testID={open ? 'tileSizePop' : undefined}>
|
|
310
349
|
<Text style={s.popLabel}>Tile size</Text>
|
|
311
350
|
<View style={{ flex: 1 }}>
|
|
312
|
-
<Slider label="Tile size" testID="tileSizeSlider" value={value} min={0} max={SIZE_STEPS} step={1} format={v =>
|
|
351
|
+
<Slider label="Tile size" testID="tileSizeSlider" value={value} min={0} max={SIZE_STEPS} step={1} format={v => stepToPct(v) + '%'}
|
|
313
352
|
onStart={pushHistory} onChange={change} onEnd={end} />
|
|
314
353
|
</View>
|
|
315
|
-
|
|
316
|
-
|
|
354
|
+
{/* (a fixed width, as the image sliders' numbers: the track stays one length whatever the number — "70%" or "1000%" — the user's call, 2026-11-03) */}
|
|
355
|
+
<Text style={s.popValue}>{(live != null ? stepToPct(live) : last.current) + '%'}</Text>
|
|
356
|
+
</Animated.View>
|
|
357
|
+
</View>
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* The measurement tiles' size slider (editor/dimSize.ts): the bar's Size with a dimension picked, as LinkSizePopover is
|
|
363
|
+
* for the tiles — one size for every measurement tile in the file, in percent of the size they're drawn at (50% to
|
|
364
|
+
* 300%), catching at 100%. Kept quick the same way: the thumb and the number follow the finger, the drawing is redrawn
|
|
365
|
+
* at most once a frame, and the change is marked (to save) as it's let go. Not an undo step, as the file's other
|
|
366
|
+
* settings aren't.
|
|
367
|
+
*/
|
|
368
|
+
function DimSizePopover() {
|
|
369
|
+
const [live, setLive] = useState<number | null>(null);
|
|
370
|
+
const pending = useRef<{ v: number; frame: number } | null>(null);
|
|
371
|
+
const open = ui.imgPop === 'dimsize' && dimSizeVisible();
|
|
372
|
+
const pop = usePopup(open, { y: 8 }, 'bottom center');
|
|
373
|
+
if (!pop.present) return null;
|
|
374
|
+
const value = live ?? dimPctToStep(settings.chipPct);
|
|
375
|
+
const change = (v: number) => {
|
|
376
|
+
setLive(v);
|
|
377
|
+
const p = pending.current;
|
|
378
|
+
if (p) { p.v = v; return; }
|
|
379
|
+
pending.current = { v, frame: requestAnimationFrame(() => { const q = pending.current; pending.current = null; if (q) setDimPct(stepToDimPct(q.v)); }) };
|
|
380
|
+
};
|
|
381
|
+
const end = () => {
|
|
382
|
+
const p = pending.current;
|
|
383
|
+
if (p) { cancelAnimationFrame(p.frame); pending.current = null; setDimPct(stepToDimPct(p.v)); }
|
|
384
|
+
setLive(null);
|
|
385
|
+
dimSizeDone();
|
|
386
|
+
notify();
|
|
387
|
+
};
|
|
388
|
+
return (
|
|
389
|
+
<View style={s.popWrap} pointerEvents="box-none">
|
|
390
|
+
<Animated.View style={[s.pop, pop.style]} pointerEvents={open ? 'auto' : 'none'} testID={open ? 'dimSizePop' : undefined}>
|
|
391
|
+
<Text style={s.popLabel}>Measurement size</Text>
|
|
392
|
+
<View style={{ flex: 1 }}>
|
|
393
|
+
<Slider label="Measurement size" testID="dimSizeSlider" value={value} min={0} max={DIM_STEPS} step={1} format={v => stepToDimPct(v) + '%'}
|
|
394
|
+
onChange={change} onEnd={end} />
|
|
395
|
+
</View>
|
|
396
|
+
<Text style={s.popValue}>{(live != null ? stepToDimPct(live) : settings.chipPct) + '%'}</Text>
|
|
317
397
|
</Animated.View>
|
|
318
398
|
</View>
|
|
319
399
|
);
|
|
@@ -364,13 +444,17 @@ const s = createSheet({
|
|
|
364
444
|
pop: { width: 400, maxWidth: '100%', flexDirection: 'row', alignItems: 'center', gap: 10, backgroundColor: C.g2, borderRadius: 999, paddingHorizontal: 16, paddingVertical: 4, ...shadow },
|
|
365
445
|
popLabel: { fontFamily: FONT, fontSize: 12.5, fontWeight: '600', color: C.lg2 },
|
|
366
446
|
popValue: { fontFamily: FONT, fontSize: 12.5, fontWeight: '600', color: '#fff', width: 48, textAlign: 'right' },
|
|
367
|
-
// (a length: as long as it is, the track running up to it)
|
|
368
|
-
sizeValue: { width: 'auto', minWidth: 0 },
|
|
369
447
|
// back to upright: a pill at the end of the rotation slider, concentric with it — the same 4 above, below and beside
|
|
370
448
|
// it, and the slider's radius (22, half its 44) less that 4 for its own
|
|
371
449
|
popReset: { paddingRight: 4 },
|
|
372
450
|
reset: { height: 36, paddingHorizontal: 16, borderRadius: 18, backgroundColor: C.g3, justifyContent: 'center' },
|
|
373
451
|
resetText: { fontFamily: FONT, fontSize: 12.5, fontWeight: '600', color: '#fff' },
|
|
452
|
+
// Open's question: its two answers as the bar's own buttons are (white on the bar's grey, a divider between),
|
|
453
|
+
// concentric with it (4 in all round)
|
|
454
|
+
choices: { width: 'auto', paddingHorizontal: 4, gap: 2 },
|
|
455
|
+
choice: { height: 40, paddingHorizontal: 16, borderRadius: 20, justifyContent: 'center' },
|
|
456
|
+
choiceHover: { backgroundColor: 'rgba(255,255,255,0.08)' },
|
|
457
|
+
choiceText: { fontFamily: FONT, fontSize: 14, fontWeight: '600', color: '#fff' },
|
|
374
458
|
// (6 in from the bar's end, top and bottom: concentric with it)
|
|
375
459
|
add: { width: ADD, height: ADD, borderRadius: ADD / 2, backgroundColor: C.yellow, alignItems: 'center', justifyContent: 'center', marginLeft: ADD_GAP },
|
|
376
460
|
// BOLDR's delete FAB (the annotation editors' DeleteFab): a 60 pt solid red circle 12 from the right and 14 from the
|
package/src/react/CadEditor.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useRef, useState, type ReactNode } from 'react';
|
|
1
|
+
import { useEffect, useMemo, useRef, useState, type ReactNode } from 'react';
|
|
2
2
|
import { useColorScheme, useWindowDimensions, View } from 'react-native';
|
|
3
3
|
import { analyze } from '../app/edit';
|
|
4
4
|
import { ed } from '../app/state';
|
|
@@ -19,7 +19,6 @@ import { confirmCancel, confirmOpen } from '../editor/confirm';
|
|
|
19
19
|
import { Drawer } from './Drawer';
|
|
20
20
|
import { Duck } from './Duck';
|
|
21
21
|
import { elevOpen } from '../editor/elevation';
|
|
22
|
-
import { LaserTray } from './LaserTray';
|
|
23
22
|
import { MarkupPanel } from './MarkupPanel';
|
|
24
23
|
import { Menu, NoteInput } from './Popovers';
|
|
25
24
|
import { KeypadSheet } from './KeypadSheet';
|
|
@@ -29,7 +28,7 @@ import { Empty3D } from './Empty3D';
|
|
|
29
28
|
import { is3d } from '../editor/view3dState';
|
|
30
29
|
import { reactPorts, setFileSaver } from './ports';
|
|
31
30
|
import { editorHost } from './host';
|
|
32
|
-
import { checkChanges, startManualSave, stopManualSave, type CadSaveState } from './saving';
|
|
31
|
+
import { announceSaveState, checkChanges, startManualSave, stopManualSave, type CadSaveState } from './saving';
|
|
33
32
|
import { PAGE_LOCK_ROOT, usePageLock } from './pageLock';
|
|
34
33
|
import { setSkiaFonts } from '../skia/fonts';
|
|
35
34
|
import type { SkiaFonts } from '../skia/SkiaDrawCtx';
|
|
@@ -47,6 +46,7 @@ import { setLinksHost, type CadLinks } from '../editor/links';
|
|
|
47
46
|
import { ShapeMenu } from './ShapeMenu';
|
|
48
47
|
import { PHONE_MAX } from './theme';
|
|
49
48
|
import { createSheet } from './corners';
|
|
49
|
+
import { EditorBoxContext, type EditorBox } from './editorBox';
|
|
50
50
|
|
|
51
51
|
export interface CadEditorProps {
|
|
52
52
|
/** Back to the host (otherwise the back button opens the project's pages) */
|
|
@@ -154,6 +154,8 @@ export function CadEditor({ onBack, headerRight, pickImage = pickImageInBrowser,
|
|
|
154
154
|
clearTimeout(closing.current);
|
|
155
155
|
setPorts(reactPorts);
|
|
156
156
|
editorHost.open = true;
|
|
157
|
+
// saving manually: the state it opens in, now it's mounted (not as it rendered: see startManualSave)
|
|
158
|
+
announceSaveState();
|
|
157
159
|
return () => {
|
|
158
160
|
// saving as they draw: the last edits and the preview go now. Saving manually: unsaved edits are dropped.
|
|
159
161
|
if (!manualSave) {
|
|
@@ -172,17 +174,21 @@ export function CadEditor({ onBack, headerRight, pickImage = pickImageInBrowser,
|
|
|
172
174
|
// the canvases read their colors when they draw: set them before this render's children draw
|
|
173
175
|
setCanvasTheme(theme);
|
|
174
176
|
useEffect(() => { requestDraw(); }, [theme]);
|
|
175
|
-
|
|
177
|
+
// the chrome is laid out in the editor's own area, not the window: the host can put it in a pane (editorBox.ts)
|
|
178
|
+
const win = useWindowDimensions(), [laid, setLaid] = useState<EditorBox | null>(null);
|
|
179
|
+
const box = useMemo(() => laid ?? { width: win.width, height: win.height }, [laid, win.width, win.height]);
|
|
180
|
+
const phone = box.width < PHONE_MAX, wide = box.width >= 900;
|
|
176
181
|
// (asked about once the drawing's loaded: what it links to)
|
|
177
182
|
useEffect(() => {
|
|
178
183
|
setLinksHost(links ?? null);
|
|
179
184
|
return () => setLinksHost(null);
|
|
180
185
|
}, [links]);
|
|
181
|
-
// (a phone asks with the host's keypad, when it has one)
|
|
186
|
+
// (a phone asks with the host's keypad, when it has one: the device is a phone, whatever the editor's area)
|
|
187
|
+
const phoneDevice = win.width < PHONE_MAX;
|
|
182
188
|
useEffect(() => {
|
|
183
|
-
setHostKeypad(
|
|
189
|
+
setHostKeypad(phoneDevice && keypad ? keypad : null);
|
|
184
190
|
return () => setHostKeypad(null);
|
|
185
|
-
}, [
|
|
191
|
+
}, [phoneDevice, keypad]);
|
|
186
192
|
// (a modeless keypad leaves the drawing live: no backdrop. On a tablet or a computer the drawing stays in reach
|
|
187
193
|
// around a sheet too — it pans and zooms, and a tap on it (or the chrome over it) closes the sheet: see
|
|
188
194
|
// editor/gestures.ts sheetUp. A phone's sheet covers most of it: there a backdrop closes it.)
|
|
@@ -198,7 +204,11 @@ export function CadEditor({ onBack, headerRight, pickImage = pickImageInBrowser,
|
|
|
198
204
|
return () => clearTimeout(t);
|
|
199
205
|
}, [threeD, kept3d]);
|
|
200
206
|
return (
|
|
201
|
-
<
|
|
207
|
+
<EditorBoxContext.Provider value={box}>
|
|
208
|
+
<View nativeID={PAGE_LOCK_ROOT} style={[s.root, { backgroundColor: CANVAS_THEMES[theme].bg }]} onLayout={e => {
|
|
209
|
+
const { width, height } = e.nativeEvent.layout;
|
|
210
|
+
setLaid(b => (b && Math.abs(b.width - width) < 0.5 && Math.abs(b.height - height) < 0.5 ? b : { width, height }));
|
|
211
|
+
}}>
|
|
202
212
|
<PlanCanvas />
|
|
203
213
|
{/* the 3D tab: over the plan, which stays as it was underneath */}
|
|
204
214
|
{(threeD || kept3d) && <View3D theme={theme} active={threeD} />}
|
|
@@ -212,7 +222,6 @@ export function CadEditor({ onBack, headerRight, pickImage = pickImageInBrowser,
|
|
|
212
222
|
{/* (none in 3D: it's a view, its camera moved with the fingers) */}
|
|
213
223
|
{!readOnly && !threeD && <Rail phone={phone} onAddImage={() => { pickImage().then(img => { if (img) placeUnderlay(img.dataUrl, img.w, img.h); }); }} />}
|
|
214
224
|
{!readOnly && <BottomBar phone={phone} />}
|
|
215
|
-
{!threeD && <LaserTray phone={phone} />}
|
|
216
225
|
{!threeD && <MarkupPanel phone={phone} />}
|
|
217
226
|
</Duck>
|
|
218
227
|
{!readOnly && !elevOpen() && !threeD && <ShapeMenu />}
|
|
@@ -226,6 +235,7 @@ export function CadEditor({ onBack, headerRight, pickImage = pickImageInBrowser,
|
|
|
226
235
|
<ConflictSheet wide={wide} open={!!ui.conflict && !ui.keypad} />
|
|
227
236
|
<ConfirmSheet wide={wide} />
|
|
228
237
|
</View>
|
|
238
|
+
</EditorBoxContext.Provider>
|
|
229
239
|
);
|
|
230
240
|
}
|
|
231
241
|
|
package/src/react/Drawer.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useMemo, useRef, useState, type ComponentRef } from 'react';
|
|
2
2
|
import {
|
|
3
|
-
Animated, Easing, Keyboard, PanResponder, Platform, Pressable, ScrollView, StyleSheet, Text, TextInput,
|
|
3
|
+
Animated, Easing, Keyboard, PanResponder, Platform, Pressable, ScrollView, StyleSheet, Text, TextInput, View,
|
|
4
4
|
} from 'react-native';
|
|
5
5
|
import {
|
|
6
6
|
addPage, deletePage, deletePending, duplicatePage, focusSpace, renamePage, renameSpace, spaceSchedule, switchPage,
|
|
@@ -18,6 +18,7 @@ import { C, FONT } from './theme';
|
|
|
18
18
|
import { EASE, Segmented, Tap } from './motion';
|
|
19
19
|
import { NATIVE } from './easing';
|
|
20
20
|
import { createSheet } from './corners';
|
|
21
|
+
import { useEditorBox } from './editorBox';
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* The Pages frame's sizes, scaled to the panel: Figma draws it 515 wide, the panel's content is about 370 (K). Its
|
|
@@ -44,7 +45,7 @@ const CLOSE_DRAG = 80, CLOSE_FLICK = 0.5;
|
|
|
44
45
|
* down or a tap outside). Either way it slides back out when closed.
|
|
45
46
|
*/
|
|
46
47
|
export function Drawer({ phone = false }: { phone?: boolean }) {
|
|
47
|
-
const version = useEditorVersion(), { width, height } =
|
|
48
|
+
const version = useEditorVersion(), { width, height } = useEditorBox(), w = Math.min(400, width);
|
|
48
49
|
const open = !!ui.drawer;
|
|
49
50
|
// what it showed last stays while it slides away
|
|
50
51
|
const last = useRef<DrawerTab>('pages');
|