@floless/app 0.143.0 → 0.144.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 (48) hide show
  1. package/dist/floless-server.cjs +177152 -160760
  2. package/dist/schemas/steel.model.v2.schema.json +50 -2
  3. package/dist/schemas/tekla.model.v1.schema.json +66 -0
  4. package/dist/schemas/tekla.model.v2.schema.json +69 -0
  5. package/dist/schemas/tekla.source-package.v1.schema.json +37 -0
  6. package/dist/skills/floless-app-steel-takeoff/SKILL.md +24 -1
  7. package/dist/skills/floless-app-workflows/SKILL.md +8 -2
  8. package/dist/skills/floless-app-workflows/references/workspace-data.md +25 -4
  9. package/dist/templates/floless-workspace-model-report.flo +27 -23
  10. package/dist/templates/revit-model.flo +6 -2
  11. package/dist/templates/tekla-model-report.flo +60 -0
  12. package/dist/templates/tekla-parser.flo +61 -0
  13. package/dist/web/app.css +89 -2
  14. package/dist/web/aware.js +423 -46
  15. package/dist/web/commands-revit.js +4 -0
  16. package/dist/web/commands-shell.js +136 -3
  17. package/dist/web/commands-steel.js +6 -0
  18. package/dist/web/commands-tekla-parser.js +48 -0
  19. package/dist/web/commands.js +1 -1
  20. package/dist/web/grid-core.js +15 -0
  21. package/dist/web/index.html +40 -2
  22. package/dist/web/instructor.js +13 -3
  23. package/dist/web/left-pane.js +160 -10
  24. package/dist/web/model-artifact-loader.js +15 -0
  25. package/dist/web/model-display-units.js +89 -0
  26. package/dist/web/model-editor-revit-adapter.js +21 -4
  27. package/dist/web/model-editor.css +4 -2
  28. package/dist/web/model-measure.js +10 -6
  29. package/dist/web/model-panel-bridge.js +46 -3
  30. package/dist/web/model-pointer-dock.js +21 -1
  31. package/dist/web/model-property-display.js +91 -0
  32. package/dist/web/model-revit-module.js +9 -0
  33. package/dist/web/model-selection-tools.js +11 -0
  34. package/dist/web/model-spatial-panel.js +52 -21
  35. package/dist/web/model-structural-grid-view.js +334 -0
  36. package/dist/web/model-tekla-selection.js +32 -0
  37. package/dist/web/model-viewport-revit-adapter.js +119 -32
  38. package/dist/web/revit-editor.css +11 -1
  39. package/dist/web/revit-editor.html +4 -3
  40. package/dist/web/revit-editor.js +589 -111
  41. package/dist/web/steel-3d-view.js +58 -372
  42. package/dist/web/steel-editor.html +231 -8
  43. package/dist/web/tekla-editor.html +71 -0
  44. package/dist/web/tekla-structural-grid-adapter.js +56 -0
  45. package/dist/web/workspaces.js +872 -97
  46. package/distribution-profile-production.mjs +4 -0
  47. package/distribution-resource-inventory.mjs +4 -2
  48. package/package.json +5 -2
@@ -64,6 +64,22 @@ export const REVIT_POINTER_DOCK_PLAN = frozen({
64
64
  ]),
65
65
  });
66
66
 
67
+ /** Re-label the shared authenticated-mesh controls for another read-only model source. */
68
+ export function readOnlyModelPointerDockPlan(commandPrefix = 'revit', sourceLabel = 'Revit') {
69
+ const map = (item) => frozen({
70
+ ...item,
71
+ command: item.command.replace(/^revit\./, `${commandPrefix}.`),
72
+ carrier: item.carrier.replaceAll('revit.', `${commandPrefix}.`),
73
+ tip: item.tip.replaceAll('Revit', sourceLabel),
74
+ });
75
+ return frozen({
76
+ schema: REVIT_POINTER_DOCK_PLAN.schema,
77
+ selection: frozen(REVIT_POINTER_DOCK_PLAN.selection.map(map)),
78
+ snaps: frozen(REVIT_POINTER_DOCK_PLAN.snaps.map(map)),
79
+ actions: frozen(REVIT_POINTER_DOCK_PLAN.actions.map(map)),
80
+ });
81
+ }
82
+
67
83
  function escapeAttr(value) {
68
84
  return String(value ?? '').replaceAll('&', '&amp;').replaceAll('"', '&quot;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');
69
85
  }
@@ -128,7 +144,11 @@ export function mountModelPointerDock({ selectionHost = null, snapHost = null, a
128
144
  const button = actionsHost?.querySelector('[data-model-action="measure"]');
129
145
  if (button) { button.classList.toggle('on', state.armed === true); button.setAttribute('aria-pressed', String(state.armed === true)); }
130
146
  const status = actionsHost?.querySelector('[data-model-action-status]');
131
- if (status) status.textContent = state.status ?? (state.armed ? (state.hasDraft ? 'Pick point 2' : 'Pick point 1') : (state.count ? `${state.count} placed` : 'Ready'));
147
+ if (status) {
148
+ const text = state.status ?? (state.armed ? (state.hasDraft ? 'Pick point 2' : 'Pick point 1') : (state.count ? `${state.count} placed` : 'Ready'));
149
+ // The pill is width-capped with an ellipsis (model-editor.css); the tooltip carries the same full sentence.
150
+ status.textContent = text; status.dataset.tip = text;
151
+ }
132
152
  const locks = new Set(state.locks ?? []);
133
153
  actionsHost?.querySelectorAll('[data-model-axis]').forEach((axisButton) => {
134
154
  const on = axisButton.dataset.modelAxis === 'f' ? locks.size === 0 : locks.has(axisButton.dataset.modelAxis);
@@ -0,0 +1,91 @@
1
+ import { formatLength, MM } from './display-units.js';
2
+
3
+ /** Property-only decimal policy; Steel's length/elevation formatting is unchanged. */
4
+ export function formatPropertyNumber(value, decimals) {
5
+ const factor = 10 ** decimals;
6
+ const quantum = Math.round(Math.abs(value) * factor);
7
+ const rounded = Math.sign(value) * quantum / factor;
8
+ return String(rounded === 0 ? 0 : rounded);
9
+ }
10
+
11
+ /** Display only: the authenticated source value is never rounded or rewritten. */
12
+ export function formatModelProperty(row, units, { canonicalMillimetres = false } = {}) {
13
+ const value = row?.value;
14
+ if (value == null) return '—';
15
+ if (row.valueEncoding === 'provider-display') return String(value);
16
+ if (row.semantic === 'boolean' && row.valueType === 'boolean' && typeof value === 'boolean') return value ? 'Yes' : 'No';
17
+ // A source string may be a mark, a padded ID, or already formatted by its host. Never parse it.
18
+ if (typeof value !== 'number' || !Number.isFinite(value)) return String(value);
19
+ const unit = row.unit;
20
+ // Current signed parser rows identify lengths explicitly. Older trusted Tekla
21
+ // snapshots only carried a numeric value plus `unit: mm`; that is still a
22
+ // canonical millimetre value, so keep the shared unit switch useful there too.
23
+ if (unit === 'mm' && ((row.semantic === 'length' && row.dimension === 'length') || canonicalMillimetres)) {
24
+ const text = formatLength(value, units);
25
+ return units === MM ? `${text} mm` : text;
26
+ }
27
+ if (row.semantic === 'identifier' || row.semantic === 'integer') return String(value);
28
+ // A source-storage double plus an arbitrary unit label is not a canonical length.
29
+ if (!['angle', 'scalar'].includes(row.semantic)) return unit ? `${value} ${unit}` : String(value);
30
+ const decimals = row.semantic === 'angle' ? 2 : 3;
31
+ const text = Number.isInteger(value) ? String(value) : formatPropertyNumber(value, decimals);
32
+ return unit ? `${text} ${unit}` : text;
33
+ }
34
+
35
+ /** Tekla source names are retained; parser bookkeeping is not an object property. */
36
+ export function teklaPropertyGroups(rows) {
37
+ const properties = [], udas = [], nativeGroups = new Map();
38
+ for (const row of Array.isArray(rows) ? rows : []) {
39
+ const isUda = row.isUda === true || row.groupName === 'User-defined attributes' || row.groupName === 'User-defined attributes (UDA)' || row.groupName === 'UDA';
40
+ if (isUda) { udas.push(row); continue; }
41
+ if (row.semantic && Number.isSafeInteger(row.groupOrdinal)) {
42
+ const key = `${row.groupOrdinal}\0${row.groupName}`;
43
+ const group = nativeGroups.get(key) || { key, name: row.groupName, ordinal: row.groupOrdinal, rows: [], expanded: true };
44
+ group.rows.push(row); nativeGroups.set(key, group); continue;
45
+ }
46
+ if (/^(?:Raw\b|provenance|Reader coverage|Technical details|System)/i.test(row.groupName || '')) continue;
47
+ if (row.groupName === 'Overview' && ['Object kind', 'Subtype'].includes(row.name)) continue;
48
+ if (row.groupName === 'Source identity' && row.name === 'Native type') continue;
49
+ const item = row.name === 'Object ID' ? { ...row, name: 'ID' } : row;
50
+ properties.push(item);
51
+ }
52
+ const ordered = (values) => values.slice().sort((a, b) => (a.propertyOrdinal ?? 0) - (b.propertyOrdinal ?? 0));
53
+ return [
54
+ ...[...nativeGroups.values()].sort((a, b) => a.ordinal - b.ordinal).map((group) => ({ ...group, rows: ordered(group.rows) })),
55
+ ...(properties.length ? [{ key: 'tekla-properties', name: 'Properties', rows: properties, expanded: true }] : []),
56
+ ...(udas.length ? [{ key: 'tekla-udas', name: 'User-defined attributes (UDA)', rows: ordered(udas), expanded: false }] : []),
57
+ ];
58
+ }
59
+
60
+ /** Never recover Name by splitting a composite label: only a supplied property is authoritative. */
61
+ export function teklaObjectFields(entity, rows = []) {
62
+ const source = teklaPropertyGroups(rows).filter((group) => group.key !== 'tekla-udas').flatMap((group) => group.rows);
63
+ const value = (name) => source.find((row) => row.name === name)?.value;
64
+ return { name: value('Name') ?? null, profile: value('Profile') ?? null,
65
+ id: value('ID') ?? entity.objectId ?? (/^element:([0-9]+)$/.exec(entity.id || '')?.[1] ?? null) };
66
+ }
67
+
68
+ export function teklaObjectLabel(entity, rows = []) {
69
+ const fields = teklaObjectFields(entity, rows);
70
+ return [fields.name != null ? `Name: ${fields.name}` : null,
71
+ fields.profile != null ? `Profile: ${fields.profile}` : null,
72
+ fields.id != null ? `ID: ${fields.id}` : null].filter(Boolean).join(' · ') || entity.typeName || 'Tekla object';
73
+ }
74
+
75
+ /** Native kind → optional native subtype; no borrowed Revit classification levels. */
76
+ export function teklaTypeGroups(entities) {
77
+ const groups = new Map();
78
+ for (const entity of entities || []) {
79
+ const label = entity.nativeKind || entity.typeName || 'Type unavailable';
80
+ const group = groups.get(label) || { label, values: [], subtypes: new Map() };
81
+ const subtype = entity.nativeSubtype;
82
+ if (subtype && subtype !== label) {
83
+ const values = group.subtypes.get(subtype) || []; values.push(entity); group.subtypes.set(subtype, values);
84
+ } else group.values.push(entity);
85
+ groups.set(label, group);
86
+ }
87
+ const sorted = (a, b) => a[0].localeCompare(b[0], undefined, { numeric: true });
88
+ return [...groups.entries()].sort(sorted).map(([, group]) => ({ ...group,
89
+ subtypes: [...group.subtypes.entries()].sort(sorted).map(([label, values]) => ({ label, values })),
90
+ }));
91
+ }
@@ -124,6 +124,15 @@ export function revitNoModelCopy(state) {
124
124
  };
125
125
  }
126
126
 
127
+ /** The Tekla editor shares the Revit viewport's empty-state treatment, not its RVT-specific copy. */
128
+ export function teklaNoSnapshotCopy(state) {
129
+ if (!state || revitInitialAuthority(state) || state.source) return null;
130
+ return {
131
+ kind: 'no-source', title: 'No Tekla snapshot to show',
132
+ body: 'There is no read-only snapshot for this project yet. Open the Source tab to see the source status and next step.',
133
+ };
134
+ }
135
+
127
136
  const SVG_NS = 'http://www.w3.org/2000/svg';
128
137
  /**
129
138
  * Render the no-model state into the viewport's status overlay: a muted outline cube, a title and
@@ -23,6 +23,17 @@ function entityToken(hit) {
23
23
  return entity ? JSON.stringify([entity.kind, entity.sourceId]) : null;
24
24
  }
25
25
 
26
+ /** Grid/depth arbitration chooses the first candidate; it must not collapse the overlap cycle behind it. */
27
+ export function orderModelSelectionHits(primary, candidates = []) {
28
+ const ordered = primary ? [primary, ...(Array.isArray(candidates) ? candidates : [])] : (Array.isArray(candidates) ? candidates : []);
29
+ const seen = new Set(); const out = [];
30
+ for (const hit of ordered) {
31
+ const token = entityToken(hit); if (!token || seen.has(token)) continue;
32
+ seen.add(token); out.push(hit);
33
+ }
34
+ return out;
35
+ }
36
+
26
37
  function visibleHits(value) {
27
38
  return (Array.isArray(value) ? value : []).filter((hit) => hit && hit.rawVisible !== false && hit.visible !== false);
28
39
  }
@@ -42,15 +42,18 @@ function button(doc, label, { action, tip, pressed = null, disabled = false } =
42
42
  return control;
43
43
  }
44
44
 
45
- function numberField(doc, label, value, name, step = '1') {
45
+ function numberField(doc, label, value, name, step = '1', presentation = null) {
46
46
  const field = doc.createElement('label'); field.className = 'model-spatial-number-field';
47
47
  const caption = doc.createElement('span'); caption.textContent = label;
48
- const input = doc.createElement('input'); input.type = 'number'; input.step = step; input.value = rounded(value); input.dataset.field = name;
48
+ const input = doc.createElement('input'); input.type = presentation ? 'text' : 'number';
49
+ if (!presentation) input.step = step;
50
+ input.value = presentation ? presentation.format(value) : rounded(value); input.dataset.field = name;
51
+ if (presentation) { input.dataset.displayText = input.value; input.dataset.originalMm = String(value); }
49
52
  input.setAttribute('aria-label', label); field.append(caption, input); return field;
50
53
  }
51
54
 
52
- function vectorFields(doc, host, prefix, values, names = ['X', 'Y', 'Z']) {
53
- values.forEach((value, index) => host.append(numberField(doc, names[index], value, `${prefix}-${index}`)));
55
+ function vectorFields(doc, host, prefix, values, names = ['X', 'Y', 'Z'], presentation = null) {
56
+ values.forEach((value, index) => host.append(numberField(doc, names[index], value, `${prefix}-${index}`, '1', presentation)));
54
57
  }
55
58
 
56
59
  function valuesFrom(host, prefix, label) {
@@ -68,16 +71,35 @@ function actionRow(doc) { const row = doc.createElement('div'); row.className =
68
71
 
69
72
  /**
70
73
  * @param {{tools:any, trigger:HTMLElement, ports?:Record<string,Function>, documentRef?:Document,
71
- * windowRef?:Window, onBeforeOpen?:()=>void, onError?:(error:Error)=>void}} options
74
+ * windowRef?:Window, onBeforeOpen?:()=>void, onError?:(error:Error)=>void,
75
+ * lengthDisplay?:{format:(mm:number)=>string,parse:(text:string)=>number|null,unitLabel:()=>string}} options
72
76
  */
73
77
  export function mountModelSpatialPanel({
74
78
  tools, trigger, ports = {}, documentRef = document, windowRef = window, onError = () => {},
75
- onBeforeOpen = () => {},
79
+ onBeforeOpen = () => {}, lengthDisplay = null,
76
80
  }) {
77
81
  if (!tools?.state || !tools?.subscribe || !tools?.activeFrame) throw new TypeError('Spatial panel requires createModelSpatialTools APIs.');
78
82
  if (!trigger?.addEventListener) throw new TypeError('Spatial panel requires a trigger element.');
83
+ if (lengthDisplay && (typeof lengthDisplay.format !== 'function' || typeof lengthDisplay.parse !== 'function' || typeof lengthDisplay.unitLabel !== 'function')) {
84
+ throw new TypeError('Spatial panel length display requires format, parse, and unitLabel functions.');
85
+ }
79
86
  const panelId = `modelSpatialPanel-${++panelSequence}`;
80
87
  let dialog = null, body = null, status = null, destroyed = false;
88
+ const units = () => lengthDisplay ? String(lengthDisplay.unitLabel()) : 'mm';
89
+ const formattedLength = (mm) => lengthDisplay ? String(lengthDisplay.format(mm)) : rounded(mm);
90
+ const lengthPresentation = lengthDisplay ? { format: formattedLength } : null;
91
+ const readLength = (source, label) => {
92
+ const text = typeof source === 'string' ? source : source?.value;
93
+ if (!lengthDisplay) return finite(text, label);
94
+ // Architectural strings round to sixteenths. An untouched field is the original canonical
95
+ // quantity, so clicking Apply to change another field must not move this one by the rounding gap.
96
+ if (typeof source !== 'string' && source?.dataset?.displayText === text) return Number(source.dataset.originalMm);
97
+ const mm = lengthDisplay.parse(text);
98
+ if (typeof mm !== 'number' || !Number.isFinite(mm)) throw new TypeError(`${label} must be a finite length.`);
99
+ return mm;
100
+ };
101
+ const lengthValuesFrom = (host, prefix, label) => [0, 1, 2].map((index) =>
102
+ readLength(host.querySelector(`[data-field="${prefix}-${index}"]`), `${label} ${'XYZ'[index]}`));
81
103
 
82
104
  trigger.setAttribute('aria-haspopup', 'dialog'); trigger.setAttribute('aria-controls', panelId); trigger.setAttribute('aria-expanded', 'false');
83
105
 
@@ -98,7 +120,7 @@ export function mountModelSpatialPanel({
98
120
  const frameSection = section(documentRef, 'Coordinate frame');
99
121
  const summary = documentRef.createElement('div'); summary.className = 'model-spatial-panel-summary';
100
122
  const active = tools.activeFrame(); const label = documentRef.createElement('strong'); label.textContent = active.label;
101
- const origin = documentRef.createElement('span'); origin.textContent = `Origin ${active.origin.map((value) => rounded(value)).join(', ')} mm`;
123
+ const origin = documentRef.createElement('span'); origin.textContent = `Origin ${active.origin.map(formattedLength).join(', ')} ${units()}`;
102
124
  summary.append(label, origin); frameSection.append(summary);
103
125
 
104
126
  const frameActions = actionRow(documentRef);
@@ -122,15 +144,15 @@ export function mountModelSpatialPanel({
122
144
  const local = state.frames.find((item) => item.id === 'local') || state.frames.find((item) => item.id === 'global');
123
145
  const rotation = eulerDegreesFromFrame(local);
124
146
  const localGrid = documentRef.createElement('div'); localGrid.className = 'model-spatial-panel-grid';
125
- const originLabel = documentRef.createElement('div'); originLabel.className = 'model-spatial-panel-grid-label'; originLabel.textContent = 'Local origin · mm';
126
- localGrid.append(originLabel); vectorFields(documentRef, localGrid, 'local-origin', local.origin);
147
+ const originLabel = documentRef.createElement('div'); originLabel.className = 'model-spatial-panel-grid-label'; originLabel.textContent = `Local origin · ${units()}`;
148
+ localGrid.append(originLabel); vectorFields(documentRef, localGrid, 'local-origin', local.origin, ['X', 'Y', 'Z'], lengthPresentation);
127
149
  const rotationLabel = documentRef.createElement('div'); rotationLabel.className = 'model-spatial-panel-grid-label'; rotationLabel.textContent = 'Rotation · degrees';
128
150
  localGrid.append(rotationLabel); vectorFields(documentRef, localGrid, 'local-rotation', rotation, ['X°', 'Y°', 'Z°']);
129
151
  frameSection.append(localGrid);
130
152
  const localActions = actionRow(documentRef);
131
153
  const apply = button(documentRef, 'Apply local frame', { action: 'frame-local-apply', tip: 'Create or update the local frame from these numeric values' });
132
154
  apply.addEventListener('click', () => run(() => {
133
- const nextOrigin = valuesFrom(frameSection, 'local-origin', 'Local origin');
155
+ const nextOrigin = lengthValuesFrom(frameSection, 'local-origin', 'Local origin');
134
156
  const nextRotation = valuesFrom(frameSection, 'local-rotation', 'Local rotation');
135
157
  tools.setLocalTransform({ origin: nextOrigin, ...axesFromEulerDegrees(...nextRotation) });
136
158
  }, 'Local frame active.'));
@@ -139,11 +161,18 @@ export function mountModelSpatialPanel({
139
161
  if (typeof ports.acceptCoordinates === 'function') {
140
162
  const coordinateSection = section(documentRef, 'Typed coordinates');
141
163
  const coordinateRow = documentRef.createElement('div'); coordinateRow.className = 'model-spatial-coordinate-row';
142
- const input = documentRef.createElement('input'); input.type = 'text'; input.dataset.field = 'typed-coordinates'; input.placeholder = 'X, Y, Z or @dX, dY, dZ'; input.setAttribute('aria-label', 'Absolute or relative coordinates in the active frame');
164
+ const input = documentRef.createElement('input'); input.type = 'text'; input.dataset.field = 'typed-coordinates'; input.placeholder = 'X, Y, Z or @dX, dY, dZ'; input.setAttribute('aria-label', `Absolute or relative coordinates in the active frame (${units()})`);
143
165
  const accept = button(documentRef, 'Accept point', { action: 'coordinate-accept', tip: 'Accept absolute coordinates, or prefix with @ for a relative offset' });
144
166
  accept.addEventListener('click', () => run(() => {
145
167
  const basePoint = typeof ports.coordinateBasePoint === 'function' ? ports.coordinateBasePoint() : undefined;
146
- const point = tools.parseCoordinates(input.value, basePoint);
168
+ let text = input.value;
169
+ if (lengthDisplay) {
170
+ const raw = text.trim(), relative = raw.startsWith('@');
171
+ const parts = (relative ? raw.slice(1) : raw).split(',').map((part) => part.trim());
172
+ if (parts.length !== 3) throw new TypeError('Enter X, Y, Z as three finite lengths.');
173
+ text = `${relative ? '@' : ''}${parts.map((part, axis) => readLength(part, `Coordinate ${'XYZ'[axis]}`)).join(',')}`;
174
+ }
175
+ const point = tools.parseCoordinates(text, basePoint);
147
176
  return ports.acceptCoordinates(point, { relative: input.value.trim().startsWith('@'), frame: tools.activeFrame() });
148
177
  }, 'Coordinate accepted.'));
149
178
  input.addEventListener('keydown', (event) => { if (event.key === 'Enter') { event.preventDefault(); accept.click(); } });
@@ -154,10 +183,10 @@ export function mountModelSpatialPanel({
154
183
  function renderWorkPlane(root, state) {
155
184
  const planeSection = section(documentRef, 'Working plane');
156
185
  const controls = documentRef.createElement('div'); controls.className = 'model-spatial-panel-inline';
157
- const offset = numberField(documentRef, 'Offset · mm', state.workPlane?.offsetMm ?? 0, 'plane-offset'); controls.append(offset);
186
+ const offset = numberField(documentRef, `Offset · ${units()}`, state.workPlane?.offsetMm ?? 0, 'plane-offset', '1', lengthPresentation); controls.append(offset);
158
187
  for (const plane of ['xy', 'xz', 'yz']) {
159
188
  const control = button(documentRef, plane.toUpperCase(), { action: `plane-${plane}`, tip: `Set the principal ${plane.toUpperCase()} working plane`, pressed: state.workPlane?.principal === plane });
160
- control.addEventListener('click', () => run(() => tools.setPrincipalWorkPlane({ plane, offsetMm: finite(offset.querySelector('input').value, 'Working-plane offset') }), `${plane.toUpperCase()} working plane active.`));
189
+ control.addEventListener('click', () => run(() => tools.setPrincipalWorkPlane({ plane, offsetMm: readLength(offset.querySelector('input'), 'Working-plane offset') }), `${plane.toUpperCase()} working plane active.`));
161
190
  controls.append(control);
162
191
  }
163
192
  planeSection.append(controls);
@@ -190,17 +219,17 @@ export function mountModelSpatialPanel({
190
219
  const identity = documentRef.createElement('code'); identity.textContent = clip.id; heading.append(name, identity); card.append(heading);
191
220
  const grid = documentRef.createElement('div'); grid.className = 'model-spatial-panel-grid';
192
221
  if (clip.kind === 'plane') {
193
- const a = documentRef.createElement('div'); a.className = 'model-spatial-panel-grid-label'; a.textContent = 'Origin · mm'; grid.append(a); vectorFields(documentRef, grid, 'clip-origin', clip.origin);
222
+ const a = documentRef.createElement('div'); a.className = 'model-spatial-panel-grid-label'; a.textContent = `Origin · ${units()}`; grid.append(a); vectorFields(documentRef, grid, 'clip-origin', clip.origin, ['X', 'Y', 'Z'], lengthPresentation);
194
223
  const b = documentRef.createElement('div'); b.className = 'model-spatial-panel-grid-label'; b.textContent = 'Normal'; grid.append(b); vectorFields(documentRef, grid, 'clip-normal', clip.normal);
195
224
  } else {
196
- const a = documentRef.createElement('div'); a.className = 'model-spatial-panel-grid-label'; a.textContent = 'Minimum · mm'; grid.append(a); vectorFields(documentRef, grid, 'clip-min', clip.min);
197
- const b = documentRef.createElement('div'); b.className = 'model-spatial-panel-grid-label'; b.textContent = 'Maximum · mm'; grid.append(b); vectorFields(documentRef, grid, 'clip-max', clip.max);
225
+ const a = documentRef.createElement('div'); a.className = 'model-spatial-panel-grid-label'; a.textContent = `Minimum · ${units()}`; grid.append(a); vectorFields(documentRef, grid, 'clip-min', clip.min, ['X', 'Y', 'Z'], lengthPresentation);
226
+ const b = documentRef.createElement('div'); b.className = 'model-spatial-panel-grid-label'; b.textContent = `Maximum · ${units()}`; grid.append(b); vectorFields(documentRef, grid, 'clip-max', clip.max, ['X', 'Y', 'Z'], lengthPresentation);
198
227
  }
199
228
  card.append(grid); const actions = actionRow(documentRef);
200
229
  const update = button(documentRef, 'Update', { action: 'clip-update', tip: `Apply edited values to ${name.textContent}` });
201
230
  update.addEventListener('click', () => run(() => tools.updateClip(clip.id, clip.kind === 'plane'
202
- ? { origin: valuesFrom(card, 'clip-origin', 'Clip origin'), normal: valuesFrom(card, 'clip-normal', 'Clip normal') }
203
- : { min: valuesFrom(card, 'clip-min', 'Clip minimum'), max: valuesFrom(card, 'clip-max', 'Clip maximum') }), 'Clip updated.'));
231
+ ? { origin: lengthValuesFrom(card, 'clip-origin', 'Clip origin'), normal: valuesFrom(card, 'clip-normal', 'Clip normal') }
232
+ : { min: lengthValuesFrom(card, 'clip-min', 'Clip minimum'), max: lengthValuesFrom(card, 'clip-max', 'Clip maximum') }), 'Clip updated.'));
204
233
  const remove = button(documentRef, 'Remove', { action: 'clip-remove', tip: `Remove ${name.textContent}` });
205
234
  remove.addEventListener('click', () => run(() => tools.removeClip(clip.id), 'Clip removed.'));
206
235
  const enabled = button(documentRef, clip.enabled === false ? 'Disabled' : 'Enabled', { action: 'clip-enabled', tip: `Enable or disable ${name.textContent}`, pressed: clip.enabled !== false });
@@ -219,7 +248,7 @@ export function mountModelSpatialPanel({
219
248
  if (!area) { areaSection.append(note(documentRef, 'No work area. Create one from the model or current selection in the toolbar.')); root.append(areaSection); return; }
220
249
  const bounds = documentRef.createElement('div'); bounds.className = 'model-spatial-panel-summary';
221
250
  const label = documentRef.createElement('strong'); label.textContent = area.wholeParts ? 'Whole intersecting parts' : 'Physical section cut';
222
- const value = documentRef.createElement('span'); value.textContent = `${area.min.map(rounded).join(', ')} → ${area.max.map(rounded).join(', ')} mm`; bounds.append(label, value); areaSection.append(bounds);
251
+ const value = documentRef.createElement('span'); value.textContent = `${area.min.map(formattedLength).join(', ')} → ${area.max.map(formattedLength).join(', ')} ${units()}`; bounds.append(label, value); areaSection.append(bounds);
223
252
  const actions = actionRow(documentRef);
224
253
  const whole = button(documentRef, 'Whole parts', { action: 'area-whole', tip: 'Show complete parts intersecting the work area', pressed: area.wholeParts });
225
254
  whole.addEventListener('click', () => run(() => tools.setWorkAreaWhole(true)));
@@ -234,7 +263,9 @@ export function mountModelSpatialPanel({
234
263
  function paint(state = tools.state()) {
235
264
  const active = tools.activeFrame(); trigger.textContent = active.label; trigger.setAttribute('aria-label', `Spatial controls. Active frame: ${active.label}`);
236
265
  if (!body) return;
266
+ const scrollTop = body.scrollTop;
237
267
  body.replaceChildren(); renderFrame(body, state); renderWorkPlane(body, state); renderClips(body, state); renderWorkArea(body, state);
268
+ body.scrollTop = scrollTop;
238
269
  }
239
270
 
240
271
  function position() {
@@ -284,7 +315,7 @@ export function mountModelSpatialPanel({
284
315
  const unsubscribe = tools.subscribe((state) => paint(state));
285
316
 
286
317
  return Object.freeze({
287
- open, close, toggle, isOpen: () => !!dialog,
318
+ open, close, toggle, isOpen: () => !!dialog, refreshDisplay: () => { if (!destroyed) paint(); },
288
319
  destroy() {
289
320
  if (destroyed) return; destroyed = true; close({ restoreFocus: false }); unsubscribe();
290
321
  trigger.removeEventListener('click', triggerClick); documentRef.removeEventListener('pointerdown', outside); windowRef.removeEventListener?.('resize', resize);