@floless/app 0.174.1 → 0.175.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 (85) hide show
  1. package/autostart.mjs +117 -10
  2. package/dist/floless-server.cjs +2 -2
  3. package/dist/pdf-engine/floless_pdf/__init__.py +7 -3
  4. package/dist/pdf-engine/floless_pdf/backend_pdfium.py +292 -13
  5. package/dist/pdf-engine/floless_pdf/backend_pymupdf.py +25 -3
  6. package/dist/pdf-engine/floless_pdf/images.py +4 -3
  7. package/dist/pdf-engine/floless_pdf/pages.py +136 -0
  8. package/dist/schemas/steel.model.v2.schema.json +44 -1
  9. package/dist/skills/floless-app-approval/SKILL.md +28 -3
  10. package/dist/skills/floless-app-knowledge/SKILL.md +3 -2
  11. package/dist/skills/floless-app-sketches/SKILL.md +71 -0
  12. package/dist/skills/floless-app-sketches/references/steel-plate.md +15 -0
  13. package/dist/skills/floless-app-steel-model/SKILL.md +11 -1
  14. package/dist/skills/floless-app-steel-model/references/elements.md +90 -23
  15. package/dist/skills/floless-app-steel-takeoff/SKILL.md +11 -6
  16. package/dist/web/agents.js +1 -1
  17. package/dist/web/app.css +120 -15
  18. package/dist/web/app.js +89 -38
  19. package/dist/web/aware-hold.js +10 -0
  20. package/dist/web/aware.js +405 -51
  21. package/dist/web/boot-watchdog.js +249 -0
  22. package/dist/web/card-details.js +88 -0
  23. package/dist/web/chat.css +29 -0
  24. package/dist/web/chat.js +430 -128
  25. package/dist/web/commands-connection-design.js +23 -0
  26. package/dist/web/commands-revit.js +3 -0
  27. package/dist/web/commands-shell.js +226 -10
  28. package/dist/web/commands-steel.js +93 -4
  29. package/dist/web/commands-tekla-parser.js +21 -1
  30. package/dist/web/connection-design-editor.html +71 -0
  31. package/dist/web/connection-design-editor.js +794 -61
  32. package/dist/web/connection-design-handles.js +9 -3
  33. package/dist/web/element-approval.js +74 -0
  34. package/dist/web/element-context.js +76 -6
  35. package/dist/web/element-geometry.js +8 -2
  36. package/dist/web/element-holds.js +68 -5
  37. package/dist/web/element-type-actions.js +22 -3
  38. package/dist/web/element-types.js +12 -5
  39. package/dist/web/element-words.js +15 -11
  40. package/dist/web/grid-place.js +51 -0
  41. package/dist/web/guide.js +2 -0
  42. package/dist/web/index.html +13 -16
  43. package/dist/web/instructor.js +5 -2
  44. package/dist/web/missed-routines.js +6 -1
  45. package/dist/web/model-change-findings.js +100 -30
  46. package/dist/web/model-change-review.js +411 -27
  47. package/dist/web/model-clash-check.css +100 -0
  48. package/dist/web/model-clash-check.js +681 -0
  49. package/dist/web/model-clip-box.js +204 -0
  50. package/dist/web/model-clip-list.js +153 -3
  51. package/dist/web/model-clip-session.js +3 -3
  52. package/dist/web/model-clip-three-overlay.js +135 -25
  53. package/dist/web/model-editor.css +2 -0
  54. package/dist/web/model-elements.js +273 -18
  55. package/dist/web/model-fit-checks.js +354 -0
  56. package/dist/web/model-spatial-panel.js +9 -3
  57. package/dist/web/model-spatial-tools.js +12 -3
  58. package/dist/web/model-tekla-selection.js +74 -0
  59. package/dist/web/model-view-query.js +70 -14
  60. package/dist/web/model-viewport-revit-adapter.js +8 -7
  61. package/dist/web/model-viewport-toolbar.js +8 -4
  62. package/dist/web/pages.js +78 -1
  63. package/dist/web/project-history.js +31 -1
  64. package/dist/web/revit-editor.css +34 -1
  65. package/dist/web/revit-editor.js +174 -55
  66. package/dist/web/run-history.js +8 -0
  67. package/dist/web/sketch-editor.js +141 -2
  68. package/dist/web/sketches.js +192 -6
  69. package/dist/web/start-place.js +46 -0
  70. package/dist/web/steel-3d-core.js +70 -0
  71. package/dist/web/steel-3d-view.js +288 -47
  72. package/dist/web/steel-change-review.css +28 -0
  73. package/dist/web/steel-custom-connection.js +6 -0
  74. package/dist/web/steel-editor.html +532 -33
  75. package/dist/web/steel-filter.html +8 -3
  76. package/dist/web/steel-model-checks.css +76 -0
  77. package/dist/web/steel-model-v2-commands.js +17 -0
  78. package/dist/web/steel-view-generation.js +6 -2
  79. package/dist/web/teams.js +259 -19
  80. package/dist/web/tekla-editor.html +1 -0
  81. package/dist/web/terminal-requests.js +6 -0
  82. package/dist/web/vendor/connection-engine.js +886 -91
  83. package/dist/web/workspaces.js +630 -48
  84. package/package.json +2 -1
  85. package/preferences-file.mjs +27 -0
@@ -0,0 +1,204 @@
1
+ /*
2
+ * Provider-neutral geometry of an ORIENTED clip box, shared by every model viewer.
3
+ *
4
+ * A box clip keeps `min` / `max` — its extents BEFORE rotation, in world millimetres — and an optional
5
+ * `rotationDeg: [rx, ry, rz]`. The box turns about its own centre `c = (min + max) / 2` by
6
+ *
7
+ * R = Rz(rz) · Ry(ry) · Rx(rx) (turn about X first, then Y, then Z — all world axes)
8
+ *
9
+ * so a point p is inside when Rᵀ(p − c) lies within ±h, h = (max − min) / 2. A missing or all-zero
10
+ * rotation is exactly the axis-aligned box every viewer drew before rotation existed, and every function
11
+ * here takes the axis-aligned path for it so an unrotated box stays byte-identical.
12
+ *
13
+ * The rotation gizmo turns the box on GIMBAL axes that match that order: the Z arc about world Z, the Y
14
+ * arc about Rz·Ŷ and the X arc about Rz·Ry·X̂ (the box's own X). With that pairing, dragging one arc
15
+ * changes only its own angle, so the angle the readout shows is the angle the numeric field then holds.
16
+ *
17
+ * AWARE's viewer-3d (aware-aeco/aware cli/src/render/viewer_3d.rs) carries a port of these functions with
18
+ * the same names; `server/model-clip-box.test.ts` and AWARE's own test pin the same fixtures so the two
19
+ * cannot drift silently. No Three.js, Steel, Revit or provider knowledge lives here.
20
+ */
21
+
22
+ /** The rotation gizmo's drag snap — the same 5° the Profile Position gizmo's roll snaps to. */
23
+ export const CLIP_ROTATE_SNAP_DEG = 5;
24
+ export const CLIP_BOX_AXES = Object.freeze(['x', 'y', 'z']);
25
+ const AXIS_INDEX = Object.freeze({ x: 0, y: 1, z: 2 });
26
+ const RAD = Math.PI / 180;
27
+
28
+ const finite3 = (value) => Array.isArray(value) && value.length === 3 && value.every(Number.isFinite);
29
+ const dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
30
+
31
+ /** Fold one angle (degrees) into (−180, 180]. A non-finite angle reads as 0. */
32
+ export function canonicalClipAngle(deg) {
33
+ const value = Number(deg);
34
+ if (!Number.isFinite(value)) return 0;
35
+ let next = value % 360;
36
+ if (next <= -180) next += 360;
37
+ else if (next > 180) next -= 360;
38
+ return Object.is(next, -0) ? 0 : next;
39
+ }
40
+
41
+ /** `[rx, ry, rz]` folded into (−180, 180]; a missing or malformed rotation is `[0, 0, 0]`. */
42
+ export function clipBoxRotation(box) {
43
+ const value = box?.rotationDeg;
44
+ return finite3(value) ? value.map(canonicalClipAngle) : [0, 0, 0];
45
+ }
46
+
47
+ export function clipBoxIsRotated(box) { return clipBoxRotation(box).some((angle) => angle !== 0); }
48
+
49
+ /** Round to the 5° snap unless `free` (Shift held). Folded into (−180, 180]. */
50
+ export function snapClipAngle(deg, free = false) {
51
+ const value = Number(deg);
52
+ if (!Number.isFinite(value)) return 0;
53
+ return canonicalClipAngle(free ? value : Math.round(value / CLIP_ROTATE_SNAP_DEG) * CLIP_ROTATE_SNAP_DEG);
54
+ }
55
+
56
+ /** The box's three own axes in world space (the columns of R), each a unit vector. */
57
+ export function clipBoxAxes(box) {
58
+ const [rx, ry, rz] = clipBoxRotation(box).map((angle) => angle * RAD);
59
+ const cx = Math.cos(rx), sx = Math.sin(rx), cy = Math.cos(ry), sy = Math.sin(ry), cz = Math.cos(rz), sz = Math.sin(rz);
60
+ // R = Rz · Ry · Rx, written out column by column.
61
+ return [
62
+ [cz * cy, sz * cy, -sy],
63
+ [cz * sy * sx - sz * cx, sz * sy * sx + cz * cx, cy * sx],
64
+ [cz * sy * cx + sz * sx, sz * sy * cx - cz * sx, cy * cx],
65
+ ];
66
+ }
67
+
68
+ export function clipBoxCenter(box) { return [0, 1, 2].map((axis) => (box.min[axis] + box.max[axis]) / 2); }
69
+ export function clipBoxHalfSize(box) { return [0, 1, 2].map((axis) => (box.max[axis] - box.min[axis]) / 2); }
70
+
71
+ const assertBox = (box) => {
72
+ if (!box || !finite3(box.min) || !finite3(box.max)) throw new TypeError('A clip box needs finite minimum and maximum points.');
73
+ };
74
+ const at = (center, axes, local) => [0, 1, 2].map((k) => center[k] + axes[0][k] * local[0] + axes[1][k] * local[1] + axes[2][k] * local[2]);
75
+
76
+ /** The point of the box at box-local offset `local` (mm from the centre, along the box's own axes). */
77
+ export function clipBoxPoint(box, local) {
78
+ assertBox(box);
79
+ return at(clipBoxCenter(box), clipBoxAxes(box), local);
80
+ }
81
+
82
+ /** Box-local coordinates of a world point (mm from the centre along the box's own axes). */
83
+ export function clipBoxLocal(box, point) {
84
+ assertBox(box);
85
+ const center = clipBoxCenter(box); const delta = [0, 1, 2].map((k) => point[k] - center[k]);
86
+ return clipBoxAxes(box).map((axis) => dot(delta, axis));
87
+ }
88
+
89
+ /** True when the world point lies inside (or on) the box, tested in its own frame. */
90
+ export function clipBoxContains(box, point, toleranceMm = 1e-7) {
91
+ const local = clipBoxLocal(box, point); const half = clipBoxHalfSize(box);
92
+ return local.every((value, axis) => Math.abs(value) <= half[axis] + toleranceMm);
93
+ }
94
+
95
+ const CORNER_SIGNS = Object.freeze([[-1, -1, -1], [1, -1, -1], [1, 1, -1], [-1, 1, -1], [-1, -1, 1], [1, -1, 1], [1, 1, 1], [-1, 1, 1]]);
96
+ const EDGE_PAIRS = Object.freeze([[0, 1], [1, 2], [2, 3], [3, 0], [4, 5], [5, 6], [6, 7], [7, 4], [0, 4], [1, 5], [2, 6], [3, 7]]);
97
+
98
+ /** The eight corners, in the order the axis-aligned outline always used. */
99
+ export function clipBoxCorners(box) {
100
+ assertBox(box);
101
+ if (!clipBoxIsRotated(box)) {
102
+ const [x0, y0, z0] = box.min; const [x1, y1, z1] = box.max;
103
+ return [[x0, y0, z0], [x1, y0, z0], [x1, y1, z0], [x0, y1, z0], [x0, y0, z1], [x1, y0, z1], [x1, y1, z1], [x0, y1, z1]];
104
+ }
105
+ const center = clipBoxCenter(box); const half = clipBoxHalfSize(box); const axes = clipBoxAxes(box);
106
+ return CORNER_SIGNS.map((signs) => at(center, axes, signs.map((sign, axis) => sign * half[axis])));
107
+ }
108
+
109
+ /** The twelve outline edges as a flat [a0, b0, a1, b1, …] point list (LineSegments order). */
110
+ export function clipBoxEdgePoints(box) {
111
+ const corners = clipBoxCorners(box);
112
+ return EDGE_PAIRS.flatMap(([a, b]) => [corners[a], corners[b]]);
113
+ }
114
+
115
+ /** The outward unit normal of the box face on `axis` ('x' | 'y' | 'z') at `sign` (±1). */
116
+ export function clipBoxFaceNormal(box, axis, sign) {
117
+ const index = AXIS_INDEX[axis]; if (index === undefined || ![-1, 1].includes(sign)) throw new TypeError('A box face needs an axis and a sign.');
118
+ return clipBoxAxes(box)[index].map((value) => value * sign);
119
+ }
120
+
121
+ /** The centre of the box face on `axis` at `sign`. */
122
+ export function clipBoxFaceAnchor(box, axis, sign) {
123
+ assertBox(box);
124
+ const index = AXIS_INDEX[axis]; if (index === undefined || ![-1, 1].includes(sign)) throw new TypeError('A box face needs an axis and a sign.');
125
+ if (!clipBoxIsRotated(box)) {
126
+ const anchor = clipBoxCenter(box); anchor[index] = sign > 0 ? box.max[index] : box.min[index]; return anchor;
127
+ }
128
+ const local = [0, 0, 0]; local[index] = sign * clipBoxHalfSize(box)[index];
129
+ return clipBoxPoint(box, local);
130
+ }
131
+
132
+ /**
133
+ * The six INWARD planes `{ origin, normal, axis, sign }` whose kept sides intersect to the box — the
134
+ * minimum face of each axis first, then its maximum. Six half-spaces, so the kept region stays convex.
135
+ */
136
+ export function clipBoxPlanes(box) {
137
+ assertBox(box);
138
+ return CLIP_BOX_AXES.flatMap((axis) => [-1, 1].map((sign) => Object.freeze({
139
+ axis, sign, origin: clipBoxFaceAnchor(box, axis, sign), normal: clipBoxFaceNormal(box, axis, -sign),
140
+ })));
141
+ }
142
+
143
+ /**
144
+ * Move the face on `axis` at `sign` by `deltaMm` along the box's own +axis (the same convention the
145
+ * axis-aligned drag always used: positive moves toward +axis whichever face is held). The OPPOSITE face
146
+ * stays exactly where it was; the extent never drops below `minimumExtentMm`. Returns a new box with the
147
+ * same rotation (and every other field of the input carried over).
148
+ */
149
+ export function moveClipBoxFace(box, axis, sign, deltaMm, minimumExtentMm = 1) {
150
+ assertBox(box);
151
+ const index = AXIS_INDEX[axis];
152
+ if (index === undefined || ![-1, 1].includes(sign) || !Number.isFinite(deltaMm)) throw new TypeError('A clip box handle needs finite bounds, axis, and sign.');
153
+ const next = { ...box, min: [...box.min], max: [...box.max] };
154
+ if (!clipBoxIsRotated(box)) {
155
+ if (sign > 0) next.max[index] = Math.max(box.max[index] + deltaMm, box.min[index] + minimumExtentMm);
156
+ else next.min[index] = Math.min(box.min[index] + deltaMm, box.max[index] - minimumExtentMm);
157
+ return next;
158
+ }
159
+ const half = clipBoxHalfSize(box)[index];
160
+ let low = -half, high = half;
161
+ if (sign > 0) high = Math.max(half + deltaMm, low + minimumExtentMm);
162
+ else low = Math.min(-half + deltaMm, high - minimumExtentMm);
163
+ const shift = (low + high) / 2; const nextHalf = (high - low) / 2;
164
+ const axisWorld = clipBoxAxes(box)[index];
165
+ const center = clipBoxCenter(box).map((value, k) => value + axisWorld[k] * shift);
166
+ const halves = clipBoxHalfSize(box); halves[index] = nextHalf;
167
+ next.min = center.map((value, k) => value - halves[k]);
168
+ next.max = center.map((value, k) => value + halves[k]);
169
+ return next;
170
+ }
171
+
172
+ /** Return the box with `rotationDeg` replaced (folded; an all-zero rotation drops the field). */
173
+ export function withClipBoxRotation(box, rotationDeg) {
174
+ const next = { ...box };
175
+ const rotation = finite3(rotationDeg) ? rotationDeg.map(canonicalClipAngle) : [0, 0, 0];
176
+ if (rotation.some((angle) => angle !== 0)) next.rotationDeg = rotation; else delete next.rotationDeg;
177
+ return next;
178
+ }
179
+
180
+ /** Set one gimbal angle (degrees, folded). */
181
+ export function rotateClipBox(box, axis, angleDeg) {
182
+ const index = AXIS_INDEX[axis]; if (index === undefined) throw new TypeError('Rotate about x, y or z.');
183
+ const rotation = clipBoxRotation(box); rotation[index] = canonicalClipAngle(angleDeg);
184
+ return withClipBoxRotation(box, rotation);
185
+ }
186
+
187
+ /**
188
+ * The gimbal ring for `axis`: the world axis that arc turns about and the frozen in-plane basis
189
+ * (e1 × e2 = axis) its angle is measured in — `atan2(d·e2, d·e1)`, positive = right-handed about axis.
190
+ * The arc is drawn as the quarter turn from e1 to e2.
191
+ */
192
+ export function clipBoxGimbalRing(box, axis) {
193
+ const [rx, ry, rz] = clipBoxRotation(box);
194
+ const turnZ = clipBoxAxes({ rotationDeg: [0, 0, rz] });
195
+ const turnZY = clipBoxAxes({ rotationDeg: [0, ry, rz] });
196
+ const own = clipBoxAxes({ rotationDeg: [rx, ry, rz] });
197
+ if (axis === 'z') return Object.freeze({ axis: [0, 0, 1], e1: turnZ[0], e2: turnZ[1] });
198
+ if (axis === 'y') return Object.freeze({ axis: turnZ[1], e1: turnZY[2], e2: turnZY[0] });
199
+ if (axis === 'x') return Object.freeze({ axis: own[0], e1: own[1], e2: own[2] });
200
+ throw new TypeError('Rotate about x, y or z.');
201
+ }
202
+
203
+ /** The shortest signed step (degrees) from `previous` to `current`, folded into (−180, 180]. */
204
+ export function clipAngleStep(previousDeg, currentDeg) { return canonicalClipAngle(currentDeg - previousDeg); }
@@ -3,6 +3,8 @@
3
3
  * knowledge; providers render and manipulate the corresponding geometry through their own adapters.
4
4
  */
5
5
 
6
+ import { CLIP_ROTATE_SNAP_DEG, canonicalClipAngle } from './model-clip-box.js';
7
+
6
8
  // Builds a clip-list button. It deliberately sets NO class: `action` is the behavioural hook
7
9
  // (`data-action`, read by the delegated click and dblclick handlers) and is not a style name.
8
10
  // Deriving `model-clip-${action}` doubled the prefix on every one of them, since each action id
@@ -20,11 +22,28 @@ function button(documentRef, { label, action, tip, ariaLabel = null, pressed = n
20
22
  return value;
21
23
  }
22
24
 
23
- /** @param {{session:any, host:HTMLElement, documentRef?:Document, onError?:(message:string)=>void}} options */
24
- export function mountModelClipList({ session, host, documentRef = document, onError = () => {} } = {}) {
25
+ export const CLIP_ROTATION_INVALID_TEXT = 'Type the angle in degrees, for example 15 or -30.';
26
+ const ROTATION_AXES = Object.freeze(['x', 'y', 'z']);
27
+ const rotationOf = (clip) => (Array.isArray(clip?.rotationDeg) && clip.rotationDeg.length === 3 ? clip.rotationDeg.map(canonicalClipAngle) : [0, 0, 0]);
28
+ const angleText = (deg) => String(Math.round(deg * 100) / 100);
29
+
30
+ /**
31
+ * @param {{session:any, host:HTMLElement, documentRef?:Document, onError?:(message:string)=>void, commandPrefix?:string|null}} options
32
+ * `commandPrefix` ('steel' | 'revit' | 'tekla-parser') names the Instructor commands the rotation
33
+ * fields carry (`<prefix>.clip-rotation#x`, `<prefix>.clip-rotation-reset`).
34
+ */
35
+ export function mountModelClipList({ session, host, documentRef = document, onError = () => {}, commandPrefix = null } = {}) {
25
36
  if (!session?.state || !session?.subscribe || !session?.select || !session?.rename) throw new TypeError('Clip list requires a model clip session.');
26
37
  if (!host?.replaceChildren || !host?.addEventListener) throw new TypeError('Clip list requires a host element.');
27
38
  let editingId = null, editingValue = '', destroyed = false;
39
+ /** A typed angle that is not a number yet: kept in the field (never silently reverted) until fixed or Esc. */
40
+ let rotationDraft = null; // { clipId, axis, value }
41
+ // The host may live in another frame's document than the one nodes are created in: focus is that one's.
42
+ const ownerDoc = host.ownerDocument || documentRef;
43
+ // A press that moves focus out of an angle field commits the angle on blur, and the commit repaints.
44
+ // While that press is down the repaint waits, so the click lands on the live control it was aimed at
45
+ // (another angle, Reset rotation, a row's show/select/remove) instead of a node the repaint removed.
46
+ let holdPaint = false, paintHeld = false;
28
47
 
29
48
  const report = (message) => { try { onError(message); } catch (_) { /* reporting cannot break the list */ } };
30
49
  const selectedSingle = () => session.selected().length === 1 ? session.selected()[0] : null;
@@ -74,8 +93,67 @@ export function mountModelClipList({ session, host, documentRef = document, onEr
74
93
  row.append(enabled, label, remove); return row;
75
94
  }
76
95
 
96
+ // The rotation strip: shown only while exactly one BOX is selected — the same box the 3D arcs turn.
97
+ function rotationStrip(state) {
98
+ if (state.selectedIds.length !== 1) return null;
99
+ const clip = state.clips.find((item) => item.id === state.selectedIds[0]);
100
+ if (!clip || clip.kind !== 'box') return null;
101
+ const rotation = rotationOf(clip);
102
+ const strip = documentRef.createElement('div'); strip.className = 'model-clip-rotation'; strip.dataset.clipRotationFor = clip.id;
103
+ const head = documentRef.createElement('div'); head.className = 'model-clip-rotation-head';
104
+ const heading = documentRef.createElement('strong'); heading.textContent = 'Rotation';
105
+ const unit = documentRef.createElement('span'); unit.className = 'model-clip-rotation-unit'; unit.textContent = 'degrees';
106
+ head.append(heading, unit);
107
+ if (rotation.some((angle) => angle !== 0)) {
108
+ const reset = button(documentRef, { label: 'Reset rotation', action: 'clip-rotation-reset', tip: 'Turn the box back square with the model axes' });
109
+ reset.classList.add('model-clip-rotation-reset');
110
+ if (commandPrefix) reset.dataset.commandId = `${commandPrefix}.clip-rotation-reset`;
111
+ head.append(reset);
112
+ }
113
+ const fields = documentRef.createElement('div'); fields.className = 'model-clip-rotation-fields';
114
+ let invalid = false;
115
+ ROTATION_AXES.forEach((axis, index) => {
116
+ const field = documentRef.createElement('label'); field.className = 'model-clip-rotation-field';
117
+ const letter = documentRef.createElement('span'); letter.className = 'model-clip-rotation-axis'; letter.textContent = axis.toUpperCase(); letter.setAttribute('aria-hidden', 'true');
118
+ const input = documentRef.createElement('input'); input.type = 'text'; input.inputMode = 'decimal'; input.className = 'model-clip-rotation-input';
119
+ input.dataset.clipRotationAxis = axis; input.setAttribute('spellcheck', 'false'); input.setAttribute('autocomplete', 'off');
120
+ input.setAttribute('aria-label', `Turn ${clip.label} about ${axis.toUpperCase()}, in degrees`);
121
+ input.dataset.tip = axis === 'z' ? 'Turn about the vertical axis · ↑↓ steps 5°, Shift+↑↓ steps 1°' : `Turn about the box’s own ${axis.toUpperCase()} axis · ↑↓ steps 5°, Shift+↑↓ steps 1°`;
122
+ if (commandPrefix) input.dataset.commandId = `${commandPrefix}.clip-rotation#${axis}`;
123
+ const draft = rotationDraft && rotationDraft.clipId === clip.id && rotationDraft.axis === axis ? rotationDraft : null;
124
+ input.value = draft ? draft.value : angleText(rotation[index]);
125
+ if (draft) { input.setAttribute('aria-invalid', 'true'); invalid = true; }
126
+ const degree = documentRef.createElement('span'); degree.className = 'model-clip-rotation-degree'; degree.textContent = '°'; degree.setAttribute('aria-hidden', 'true');
127
+ field.append(letter, input, degree); fields.append(field);
128
+ });
129
+ strip.append(head, fields);
130
+ if (invalid) {
131
+ const message = documentRef.createElement('div'); message.className = 'model-clip-rotation-error'; message.setAttribute('role', 'alert'); message.textContent = CLIP_ROTATION_INVALID_TEXT;
132
+ strip.append(message);
133
+ }
134
+ return strip;
135
+ }
136
+
137
+ function commitRotation(input, { step = 0 } = {}) {
138
+ const strip = input.closest('[data-clip-rotation-for]'); const id = strip?.dataset.clipRotationFor; const axis = input.dataset.clipRotationAxis;
139
+ const clip = session.clips().find((item) => item.id === id); if (!clip || !axis) return false;
140
+ const index = ROTATION_AXES.indexOf(axis); const rotation = rotationOf(clip);
141
+ const raw = String(input.value ?? '').trim().replace(/°$/, '').trim();
142
+ const typed = raw === '' ? Number.NaN : Number(raw);
143
+ if (!Number.isFinite(typed)) {
144
+ // Not a number: keep what the person typed, say what to type, and change nothing.
145
+ rotationDraft = { clipId: id, axis, value: String(input.value ?? '') }; report(CLIP_ROTATION_INVALID_TEXT); paint(); return false;
146
+ }
147
+ rotationDraft = null;
148
+ const next = [...rotation]; next[index] = canonicalClipAngle(typed + step);
149
+ if (next[index] === rotation[index]) { paint(); return true; } // unchanged (or tabbed through): no empty undo step
150
+ session.update(id, { rotationDeg: next }); return true;
151
+ }
152
+
77
153
  function paint(state = session.state()) {
78
154
  if (destroyed) return;
155
+ if (holdPaint) { paintHeld = true; return; }
156
+ paintHeld = false;
79
157
  const header = documentRef.createElement('div'); header.className = 'model-clip-list-header';
80
158
  const heading = documentRef.createElement('strong'); heading.textContent = 'Clips';
81
159
  const count = documentRef.createElement('span'); count.className = 'model-clip-count'; count.dataset.clipCount = ''; count.textContent = String(state.clips.length);
@@ -100,7 +178,35 @@ export function mountModelClipList({ session, host, documentRef = document, onEr
100
178
  if (!state.clips.length) {
101
179
  const empty = documentRef.createElement('div'); empty.className = 'model-clip-list-empty'; empty.textContent = 'No clips yet. Add a clip plane or box from the toolbar.'; rows.append(empty);
102
180
  } else for (const clip of state.clips) rows.append(clipRow(clip));
103
- host.replaceChildren(header, rows);
181
+ // A repaint replaces every node; keep the caret in the rotation field it was in (a commit repaints).
182
+ const active = ownerDoc.activeElement;
183
+ const focusedAxis = active?.closest?.('[data-clip-rotation-axis]') && host.contains(active) ? active.dataset.clipRotationAxis : null;
184
+ const strip = rotationStrip(state);
185
+ if (!strip) rotationDraft = null;
186
+ host.replaceChildren(header, rows, ...(strip ? [strip] : []));
187
+ if (focusedAxis && strip) {
188
+ const input = strip.querySelector(`[data-clip-rotation-axis="${focusedAxis}"]`);
189
+ input?.focus?.(); input?.select?.();
190
+ }
191
+ }
192
+ function releasePaint() {
193
+ if (!holdPaint) return;
194
+ holdPaint = false;
195
+ if (paintHeld) paint();
196
+ }
197
+ function pointerDown(event) {
198
+ const active = ownerDoc.activeElement;
199
+ if (active?.closest?.('[data-clip-rotation-axis]') && host.contains(active) && event.target !== active) holdPaint = true;
200
+ }
201
+ // The click follows the release in the same task; repaint on the next one, after it has landed.
202
+ function pointerUp() { if (holdPaint) setTimeout(releasePaint, 0); }
203
+ // Where a control sits, so focus moved by Tab can follow it into the repainted strip.
204
+ function controlKey(element) {
205
+ const angle = element?.closest?.('[data-clip-rotation-axis]');
206
+ if (angle) return `[data-clip-rotation-axis="${angle.dataset.clipRotationAxis}"]`;
207
+ const control = element?.closest?.('[data-action]'); if (!control) return null;
208
+ const row = control.closest('[data-clip-id]');
209
+ return row ? `[data-clip-id="${row.dataset.clipId}"] [data-action="${control.dataset.action}"]` : `[data-action="${control.dataset.action}"]`;
104
210
  }
105
211
 
106
212
  function click(event) {
@@ -111,6 +217,10 @@ export function mountModelClipList({ session, host, documentRef = document, onEr
111
217
  else if (control.dataset.action === 'clip-enabled-all') session.toggleAllEnabled();
112
218
  else if (control.dataset.action === 'clip-remove') session.remove(id);
113
219
  else if (control.dataset.action === 'clip-clear') session.clear();
220
+ else if (control.dataset.action === 'clip-rotation-reset') {
221
+ const strip = control.closest('[data-clip-rotation-for]'); rotationDraft = null;
222
+ if (strip) session.update(strip.dataset.clipRotationFor, { rotationDeg: null });
223
+ }
114
224
  }
115
225
  function doubleClick(event) {
116
226
  const label = event.target.closest?.('[data-action="clip-select"]'); const row = label?.closest('[data-clip-id]');
@@ -121,6 +231,19 @@ export function mountModelClipList({ session, host, documentRef = document, onEr
121
231
  }
122
232
  }
123
233
  function keydown(event) {
234
+ const angle = event.target.closest?.('[data-clip-rotation-axis]');
235
+ if (angle) {
236
+ // Every key typed into an angle stays in the field: the viewer's own shortcuts (Delete removes the
237
+ // selected clip, F2 renames) must never fire from here.
238
+ event.stopPropagation();
239
+ if (event.key === 'Enter') { event.preventDefault(); commitRotation(angle); }
240
+ else if (event.key === 'Escape') { event.preventDefault(); rotationDraft = null; angle.dataset.reverting = 'true'; paint(); ownerDoc.activeElement?.blur?.(); }
241
+ else if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
242
+ event.preventDefault();
243
+ commitRotation(angle, { step: (event.key === 'ArrowUp' ? 1 : -1) * (event.shiftKey ? 1 : CLIP_ROTATE_SNAP_DEG) });
244
+ }
245
+ return;
246
+ }
124
247
  const input = event.target.closest?.('[data-clip-rename]');
125
248
  if (input) {
126
249
  if (event.key === 'Enter') { event.preventDefault(); event.stopPropagation(); finishRename(input, true); }
@@ -133,16 +256,42 @@ export function mountModelClipList({ session, host, documentRef = document, onEr
133
256
  }
134
257
  }
135
258
  function focusOut(event) {
259
+ const angle = event.target.closest?.('[data-clip-rotation-axis]');
260
+ if (angle) {
261
+ if (angle.dataset.reverting === 'true' || !angle.isConnected) return;
262
+ const clip = session.clips().find((item) => item.id === angle.closest('[data-clip-rotation-for]')?.dataset.clipRotationFor);
263
+ const shown = clip ? angleText(rotationOf(clip)[ROTATION_AXES.indexOf(angle.dataset.clipRotationAxis)]) : null;
264
+ if (angle.value === shown) return; // blur commits only a change
265
+ // A press elsewhere in the list holds the repaint until its click lands (pointerDown). Focus moved
266
+ // by the keyboard gets no click: the repaint replaces the control it moved to, so follow it there.
267
+ const next = !holdPaint && event.relatedTarget && host.contains(event.relatedTarget) ? controlKey(event.relatedTarget) : null;
268
+ commitRotation(angle);
269
+ if (next) {
270
+ setTimeout(() => {
271
+ const control = destroyed ? null : host.querySelector(next);
272
+ if (control && ownerDoc.activeElement !== control) { control.focus?.(); control.select?.(); }
273
+ }, 0);
274
+ }
275
+ return;
276
+ }
136
277
  const input = event.target.closest?.('[data-clip-rename]');
137
278
  if (input) finishRename(input, true);
138
279
  }
139
280
  function input(event) {
140
281
  const control = event.target.closest?.('[data-clip-rename]');
141
282
  if (control) editingValue = control.value;
283
+ const angle = event.target.closest?.('[data-clip-rotation-axis]');
284
+ if (angle && angle.getAttribute('aria-invalid') === 'true') {
285
+ // Typing again clears the warning; the draft is re-checked on the next commit.
286
+ angle.removeAttribute('aria-invalid'); angle.closest('[data-clip-rotation-for]')?.querySelector('.model-clip-rotation-error')?.remove();
287
+ rotationDraft = null;
288
+ }
142
289
  }
143
290
 
291
+
144
292
  host.classList.add('model-clip-list');
145
293
  host.addEventListener('click', click); host.addEventListener('dblclick', doubleClick); host.addEventListener('keydown', keydown); host.addEventListener('focusout', focusOut); host.addEventListener('input', input);
294
+ host.addEventListener('pointerdown', pointerDown, true); ownerDoc.addEventListener?.('pointerup', pointerUp, true); ownerDoc.addEventListener?.('pointercancel', pointerUp, true);
146
295
  const unsubscribe = session.subscribe((state) => paint(state));
147
296
 
148
297
  return Object.freeze({
@@ -150,6 +299,7 @@ export function mountModelClipList({ session, host, documentRef = document, onEr
150
299
  destroy() {
151
300
  if (destroyed) return; destroyed = true; unsubscribe();
152
301
  host.removeEventListener('click', click); host.removeEventListener('dblclick', doubleClick); host.removeEventListener('keydown', keydown); host.removeEventListener('focusout', focusOut); host.removeEventListener('input', input);
302
+ host.removeEventListener('pointerdown', pointerDown, true); ownerDoc.removeEventListener?.('pointerup', pointerUp, true); ownerDoc.removeEventListener?.('pointercancel', pointerUp, true);
153
303
  host.classList.remove('model-clip-list'); host.replaceChildren();
154
304
  },
155
305
  });
@@ -148,15 +148,15 @@ export function createModelClipSession({
148
148
  return nextId;
149
149
  });
150
150
  },
151
- /** @param {{id?:string|null,label?:string|null,min:number[],max:number[],enabled?:boolean}} value */
151
+ /** @param {{id?:string|null,label?:string|null,min:number[],max:number[],rotationDeg?:number[],enabled?:boolean}} value */
152
152
  addBox(value = /** @type {any} */ ({})) {
153
- const { id = null, label = null, min, max, enabled = true } = value;
153
+ const { id = null, label = null, min, max, rotationDeg = undefined, enabled = true } = value;
154
154
  const suppliedId = String(id ?? '').trim(); const generated = suppliedId ? null : nextIdentity('box');
155
155
  const nextId = suppliedId || generated.id;
156
156
  const suppliedLabel = String(label ?? '').trim(); const nextLabel = suppliedLabel || generated?.label || nextId;
157
157
  if (!labelAvailable(nextLabel)) throw new TypeError('Clip names must be unique and non-empty.');
158
158
  return transact('clip-add', () => {
159
- tools.addClipBox({ id: nextId, label: nextLabel, min, max, enabled });
159
+ tools.addClipBox({ id: nextId, label: nextLabel, min, max, rotationDeg, enabled });
160
160
  selectedIds = new Set([nextId]); rangeAnchorId = nextId;
161
161
  return nextId;
162
162
  });