@floless/app 0.143.0 → 0.145.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 (52) hide show
  1. package/dist/floless-server.cjs +177602 -161132
  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/chat.css +17 -2
  16. package/dist/web/chat.js +2 -1
  17. package/dist/web/commands-revit.js +4 -0
  18. package/dist/web/commands-shell.js +136 -3
  19. package/dist/web/commands-steel.js +6 -0
  20. package/dist/web/commands-tekla-parser.js +48 -0
  21. package/dist/web/commands.js +1 -1
  22. package/dist/web/grid-core.js +15 -0
  23. package/dist/web/index.html +43 -5
  24. package/dist/web/instructor.js +13 -3
  25. package/dist/web/left-pane.js +160 -10
  26. package/dist/web/model-artifact-loader.js +15 -0
  27. package/dist/web/model-display-units.js +89 -0
  28. package/dist/web/model-editor-revit-adapter.js +21 -4
  29. package/dist/web/model-editor.css +4 -2
  30. package/dist/web/model-measure.js +83 -22
  31. package/dist/web/model-panel-bridge.js +46 -3
  32. package/dist/web/model-pointer-dock.js +26 -1
  33. package/dist/web/model-property-display.js +91 -0
  34. package/dist/web/model-revit-module.js +9 -0
  35. package/dist/web/model-selection-tools.js +11 -0
  36. package/dist/web/model-snap-contract.js +14 -0
  37. package/dist/web/model-snapping.js +564 -139
  38. package/dist/web/model-spatial-panel.js +52 -21
  39. package/dist/web/model-structural-grid-view.js +334 -0
  40. package/dist/web/model-tekla-selection.js +32 -0
  41. package/dist/web/model-viewport-revit-adapter.js +179 -32
  42. package/dist/web/revit-editor.css +11 -1
  43. package/dist/web/revit-editor.html +4 -3
  44. package/dist/web/revit-editor.js +589 -111
  45. package/dist/web/steel-3d-view.js +58 -372
  46. package/dist/web/steel-editor.html +231 -8
  47. package/dist/web/tekla-editor.html +71 -0
  48. package/dist/web/tekla-structural-grid-adapter.js +56 -0
  49. package/dist/web/workspaces.js +872 -97
  50. package/distribution-profile-production.mjs +4 -0
  51. package/distribution-resource-inventory.mjs +4 -2
  52. package/package.json +5 -2
@@ -10,6 +10,17 @@ const SNAP_GLYPH = Object.freeze({
10
10
  });
11
11
  const SNAP_LABEL = Object.freeze({ 'mesh-vertex': 'Mesh vertex', 'mesh-edge-midpoint': 'Mesh edge midpoint',
12
12
  'mesh-edge-nearest': 'Nearest on mesh edge', surface: 'Mesh surface' });
13
+ /**
14
+ * What the Dimension tool says when the snap index could not check the region under the pointer
15
+ * (#1747). `status` is appended to the step prompt in the dock and `readout` replaces the frame label
16
+ * next to the reticle; the dock's longer explanation is the refusal's own message, so the words live in
17
+ * one place (web/model-snapping.js). Only `crowded` is cured by zooming in; `pending` by waiting.
18
+ */
19
+ const SNAP_LIMIT_COPY = Object.freeze({
20
+ crowded: Object.freeze({ status: 'zoom in to snap', readout: 'zoom in to snap' }),
21
+ pending: Object.freeze({ status: 'checking snaps…', readout: 'checking snaps…' }),
22
+ element: Object.freeze({ status: 'no snap on this element', readout: 'no snap on this element' }),
23
+ });
13
24
 
14
25
  const point3 = (value) => Array.isArray(value) && value.length === 3 && value.every(Number.isFinite);
15
26
  const unit = (value) => { const length = Math.hypot(...value); return length > 1e-9 ? value.map((item) => item / length) : null; };
@@ -156,17 +167,20 @@ function constrainedPoint(anchor, target, lockSet, frame, verticalOnly) {
156
167
  * Session-only, provider-neutral point → point → placement dimension tool.
157
168
  * @param {{surface:any,host:any,viewport:any,snapIndex?:()=>any,onState?:(state:any)=>void,
158
169
  * onChange?:(value:any,reason:string)=>void,onEditRequest?:((dimension:any,index:number)=>void)|null,
159
- * initialDimensions?:any[],initialPresentation?:any}} options
170
+ * initialDimensions?:any[],initialPresentation?:any,formatDistance?:((mm:number)=>string)|null}} options
160
171
  */
161
172
  export function mountModelMeasureTool({
162
173
  surface, host, viewport, snapIndex = () => null, onState = () => {}, onChange = () => {},
163
- onEditRequest = null, initialDimensions = [], initialPresentation = null,
174
+ onEditRequest = null, initialDimensions = [], initialPresentation = null, formatDistance = null,
164
175
  }) {
165
176
  if (!surface || !host || !viewport) throw new Error('Model measurement needs a surface, overlay host, and viewport.');
166
177
  const svg = document.createElementNS(SVG_NS, 'svg'); svg.classList.add('model-dim-overlay'); svg.setAttribute('aria-hidden', 'true'); host.append(svg);
167
178
  const session = createModelMeasureSession({ initialDimensions, initialPresentation, onChange });
168
179
  let armed, first, second, placementOffset, selectedIndex, onePickKind, visible, presentation, dimensions, lockSet;
169
- let hover = null, onePickMenu = null;
180
+ let hover = null, onePickMenu = null, snapLimit = null, snapLimitTip = null;
181
+ // The pointer the tool last acquired at, so a zoom (which moves no pointer) re-checks the same spot.
182
+ let lastPointer = null, retryTimer = null, lastIndex = null;
183
+ const clearHover = () => { hover = null; snapLimit = null; snapLimitTip = null; };
170
184
  const syncSession = () => {
171
185
  const value = session.state(); ({ armed, first, second, placementOffset, selectedIndex, onePickKind, visible, presentation } = value);
172
186
  dimensions = session.dimensions(); lockSet = new Set(value.locks); return value;
@@ -208,7 +222,7 @@ export function mountModelMeasureTool({
208
222
  const distance = viewport.distanceMm?.(dimension.a, dimension.b) ?? Math.hypot(...dimension.b.map((value, axis) => value - dimension.a[axis]));
209
223
  const style = { ...presentation, ...(dimension.presentation ?? {}) };
210
224
  const converted = distanceInUnits(distance, style.units);
211
- label.textContent = `${converted.toLocaleString(undefined, { minimumFractionDigits: style.precision, maximumFractionDigits: style.precision })} ${style.units}`;
225
+ label.textContent = formatDistance ? formatDistance(distance) : `${converted.toLocaleString(undefined, { minimumFractionDigits: style.precision, maximumFractionDigits: style.precision })} ${style.units}`;
212
226
  group.append(label); svg.append(group);
213
227
  };
214
228
  const drawGuide = (guide) => {
@@ -227,7 +241,8 @@ export function mountModelMeasureTool({
227
241
  svgNode('line', { x1: x, y1: y - 13, x2: x, y2: y + 13 }));
228
242
  const glyph = svgNode('text', { x, y: y + 4 }); glyph.textContent = SNAP_GLYPH[acquisition.kind] ?? '•'; group.append(glyph);
229
243
  const readout = svgNode('text', { x: x + 15, y: y - 12, class: 'model-snap-readout' });
230
- readout.textContent = `${acquisition.kind} · ${resolveFrame(viewport).label}`; group.append(readout); svg.append(group);
244
+ const limit = acquisition.kind === 'surface' ? SNAP_LIMIT_COPY[acquisition.snapLimit] : null;
245
+ readout.textContent = `${acquisition.kind} · ${limit ? limit.readout : resolveFrame(viewport).label}`; group.append(readout); svg.append(group);
231
246
  };
232
247
  const render = () => {
233
248
  svg.replaceChildren();
@@ -237,17 +252,53 @@ export function mountModelMeasureTool({
237
252
  if (first && second) drawDimension({ a: first.point, b: second.point, offsetPx: placementOffset }, true);
238
253
  if (armed && hover) drawReticle(hover);
239
254
  };
240
- const surfaceAcquisition = (event, point) => point && snapModes.surface !== false ? Object.freeze({
255
+ const surfaceAcquisition = (event, point, limit = null) => point && snapModes.surface !== false ? Object.freeze({
241
256
  id: 'surface-under-pointer', kind: 'surface', point: Object.freeze([...point]),
242
- screen: viewport.projectPoint(point), distance: 0, entityId: null,
257
+ screen: viewport.projectPoint(point), distance: 0, entityId: null, snapLimit: limit,
243
258
  }) : null;
244
259
  const acquire = (event) => {
245
- const surfacePoint = viewport.pickSurface(event.clientX, event.clientY); if (!surfacePoint) return null;
260
+ // Over empty space there is nothing to snap and nothing new to report, so the last notice stays:
261
+ // that is also the path the pointer takes to the dock, where the notice's explanation is hovered.
262
+ // Only "still reading" goes: the spot it was about has been left.
263
+ const surfacePoint = viewport.pickSurface(event.clientX, event.clientY);
264
+ if (!surfacePoint) {
265
+ // The spot a "still reading" retry would finish has been left: cancel it and forget the spot.
266
+ if (retryTimer !== null) { clearTimeout(retryTimer); retryTimer = null; }
267
+ lastPointer = null;
268
+ if (snapLimit === 'pending') { snapLimit = null; snapLimitTip = null; }
269
+ return null;
270
+ }
271
+ // Remember the last spot over the model: a zoom re-checks it, and a "still reading" retry finishes it.
272
+ lastPointer = { clientX: event.clientX, clientY: event.clientY, altKey: event.altKey === true };
273
+ snapLimit = null; snapLimitTip = null;
246
274
  if (event.altKey) return surfaceAcquisition(event, surfacePoint);
247
275
  const enabled = onePickKind ? Object.fromEntries(Object.keys(snapModes).map((kind) => [kind, kind === onePickKind])) : snapModes;
248
- return closestModelSnap(snapIndex(), { x: event.clientX, y: event.clientY }, viewport.projectPoint, enabled, 12, surfacePoint, 256)
249
- ?? (enabled.surface !== false ? surfaceAcquisition(event, surfacePoint) : null);
276
+ const index = snapIndex();
277
+ const snapped = closestModelSnap(index, { x: event.clientX, y: event.clientY }, viewport.projectPoint, enabled, 12, surfacePoint,
278
+ undefined, viewport.pointerRayOrigin?.(event.clientX, event.clientY) ?? null, viewport.snapVisibility?.() ?? null);
279
+ // A refused region is not "nothing nearby": the dock and the reticle say which, and why.
280
+ const looked = ['mesh-vertex', 'mesh-edge-midpoint', 'mesh-edge-nearest'].some((kind) => enabled[kind] !== false);
281
+ const refusal = snapped || !looked ? null : index?.pointerRefusal?.() ?? null;
282
+ if (refusal && SNAP_LIMIT_COPY[refusal.reason]) {
283
+ snapLimit = refusal.reason;
284
+ // The click outcome depends on this tool's own surface setting, so it is said here, not by the index.
285
+ const clickNow = refusal.reason === 'element' ? 'Here, a click places the point on the surface under the pointer.'
286
+ : 'Until then, a click places the point on the surface under the pointer.';
287
+ snapLimitTip = [refusal.message, enabled.surface !== false ? clickNow : null]
288
+ .filter(Boolean).join(' ') || null;
289
+ }
290
+ // Still being indexed: finish it without waiting for the pointer to move again.
291
+ if (snapLimit === 'pending') scheduleRetry();
292
+ return snapped ?? (enabled.surface !== false ? surfaceAcquisition(event, surfacePoint, snapLimit) : null);
293
+ };
294
+ // Re-acquire at the last pointer when the view changed or the region was still being indexed.
295
+ const reacquire = () => {
296
+ retryTimer = null; if (destroyed) return;
297
+ if (!armed || second || !lastPointer) { render(); return; }
298
+ hover = adjusted(acquire(lastPointer), lastPointer); render(); notify();
250
299
  };
300
+ let destroyed = false;
301
+ const scheduleRetry = () => { if (retryTimer === null && !destroyed) retryTimer = setTimeout(reacquire, 0); };
251
302
  const adjusted = (acquisition, event) => {
252
303
  if (!first || !acquisition) return acquisition;
253
304
  const frame = resolveFrame(viewport); const point = constrainedPoint(first.point, acquisition.point, lockSet, frame, event.altKey);
@@ -255,9 +306,15 @@ export function mountModelMeasureTool({
255
306
  };
256
307
  const notify = () => {
257
308
  const index = snapIndex(); const step = !armed ? 0 : first === null ? 1 : second === null ? 2 : 3;
258
- const status = index?.available === false ? index.refusal?.message : (step === 1 ? 'Pick point 1' : step === 2 ? 'Pick point 2' : step === 3 ? 'Place dimension'
259
- : selectedIndex !== null ? 'Dimension selected · Enter to edit · Delete to remove' : (dimensions.length ? `${dimensions.length} placed` : 'Ready'));
260
- onState({ armed, hasDraft: !!first, step, count: dimensions.length, selectedIndex, status, visible,
309
+ if (index !== lastIndex) { lastIndex = index; snapLimit = null; snapLimitTip = null; } // a new model generation
310
+ const limit = step === 1 || step === 2 ? SNAP_LIMIT_COPY[snapLimit] ?? null : null;
311
+ const prompt = step === 1 ? 'Pick point 1' : step === 2 ? 'Pick point 2' : step === 3 ? 'Place dimension'
312
+ : selectedIndex !== null ? 'Dimension selected · Enter to edit · Delete to remove' : (dimensions.length ? `${dimensions.length} placed` : 'Ready');
313
+ // A snap refusal is about picking points, so it is shown only while the tool is armed. Disarmed, the
314
+ // status returns to the session (Ready / N placed / selected) — a sentence-long refusal left behind there
315
+ // kept the dock's actions bar wide enough to strand it on its own upper row (#1738).
316
+ const status = armed && index?.available === false ? index.refusal?.message : limit ? `${prompt} · ${limit.status}` : prompt;
317
+ onState({ armed, hasDraft: !!first, step, count: dimensions.length, selectedIndex, status, statusTip: limit ? snapLimitTip : null, visible,
261
318
  presentation: { ...presentation }, snapModes: { ...snapModes }, locks: [...lockSet],
262
319
  activeFrame: resolveFrame(viewport).label, acquired: hover?.kind ?? null, onePickKind });
263
320
  };
@@ -288,7 +345,7 @@ export function mountModelMeasureTool({
288
345
  }
289
346
  event.preventDefault(); event.stopImmediatePropagation();
290
347
  if (second) {
291
- session.commitPlacement({ frameId: resolveFrame(viewport).id }); syncSession(); hover = null;
348
+ session.commitPlacement({ frameId: resolveFrame(viewport).id }); syncSession(); clearHover();
292
349
  } else {
293
350
  const acquisition = adjusted(acquire(event), event); if (!acquisition) { notify(); return; }
294
351
  session.pickPoint(acquisition); syncSession(); if (second) hover = acquisition;
@@ -314,8 +371,8 @@ export function mountModelMeasureTool({
314
371
  }
315
372
  dialog.append(group);
316
373
  };
317
- choice('Units', ['mm', 'cm', 'm', 'in', 'ft'], dimension.presentation.units, (units) => api.update(index, { presentation: { units } }));
318
- choice('Precision', [0, 1, 2, 3, 4], dimension.presentation.precision, (precision) => api.update(index, { presentation: { precision } }));
374
+ if (!formatDistance) choice('Units', ['mm', 'cm', 'm', 'in', 'ft'], dimension.presentation.units, (units) => api.update(index, { presentation: { units } }));
375
+ if (!formatDistance) choice('Precision', [0, 1, 2, 3, 4], dimension.presentation.precision, (precision) => api.update(index, { presentation: { precision } }));
319
376
  choice('Label', ['above', 'center', 'below'], dimension.presentation.labelPlacement, (labelPlacement) => api.update(index, { presentation: { labelPlacement } }));
320
377
  const actions = document.createElement('div'); actions.className = 'model-dimension-editor-actions';
321
378
  const remove = document.createElement('button'); remove.type = 'button'; remove.textContent = 'Delete'; remove.dataset.tip = 'Delete selected dimension';
@@ -333,7 +390,7 @@ export function mountModelMeasureTool({
333
390
  if (enabled === false) continue;
334
391
  const button = document.createElement('button'); button.type = 'button'; button.setAttribute('role', 'menuitem');
335
392
  button.dataset.snapOnePick = kind; button.textContent = `${SNAP_GLYPH[kind] ?? '•'} ${SNAP_LABEL[kind] ?? kind}`;
336
- button.addEventListener('click', () => { session.restrictNextPick(kind); syncSession(); closeOnePickMenu(); notify(); }); menu.append(button);
393
+ button.addEventListener('click', () => { session.restrictNextPick(kind); syncSession(); snapLimit = null; snapLimitTip = null; closeOnePickMenu(); notify(); }); menu.append(button);
337
394
  }
338
395
  document.body.append(menu); onePickMenu = menu; menu.querySelector('button')?.focus();
339
396
  };
@@ -358,20 +415,23 @@ export function mountModelMeasureTool({
358
415
  if (onePickMenu) closeOnePickMenu();
359
416
  // The rung that disarms the tool takes the button's way out: the cursor and the canvas input go with it.
360
417
  else if (session.cancelStep() === 'tool') { api.setArmed(false); return; }
361
- else { syncSession(); hover = null; }
418
+ else { syncSession(); clearHover(); }
362
419
  render(); notify();
363
420
  };
364
421
  let api;
365
422
  const releaseInput = viewport.registerInputTool?.({ pointerMove: onMove, click: onClick, contextMenu: onContextMenu, keyDown: onKey,
366
423
  cancel() { if (armed) api?.setArmed(false); } }, { id: 'model-measure', priority: 50, exclusiveGroup: 'model-command' });
367
424
  if (typeof releaseInput !== 'function') throw new Error('Model measurement requires the shared CAD input arbiter.');
368
- const unsubscribe = viewport.onCameraChange?.(render) ?? (() => {});
425
+ // A zoom or orbit moves the view under a still pointer: re-check that spot, so a notice such as "zoom
426
+ // in to snap" does not outlive the zoom that answered it.
427
+ // Coalesced: an orbit notifies many times per frame; the spot is re-checked once after them.
428
+ const unsubscribe = viewport.onCameraChange?.(() => { if (armed && !second && lastPointer) scheduleRetry(); render(); }) ?? (() => {});
369
429
  api = {
370
- setArmed(value) { if (value) releaseInput.activate?.(); else releaseInput.deactivate?.(); session.setArmed(value); syncSession(); surface.classList.toggle('measure-armed', armed); if (!armed) { hover = null; closeOnePickMenu(); } render(); notify(); },
430
+ setArmed(value) { if (value) releaseInput.activate?.(); else releaseInput.deactivate?.(); session.setArmed(value); syncSession(); surface.classList.toggle('measure-armed', armed); if (!armed) { clearHover(); lastPointer = null; closeOnePickMenu(); } render(); notify(); },
371
431
  toggle() { api.setArmed(!armed); },
372
432
  setSnapMode(kind, value) { if (kind in snapModes) { snapModes = { ...snapModes, [kind]: value === true }; render(); notify(); } },
373
433
  setAxisLock(kind) { if (['f', 'x', 'y', 'z'].includes(kind)) setLock(kind); },
374
- clear() { session.clear(); syncSession(); hover = null; render(); notify(); },
434
+ clear() { session.clear(); syncSession(); clearHover(); render(); notify(); },
375
435
  setVisible(value) { const result = session.setVisible(value); syncSession(); render(); notify(); return result; },
376
436
  setPresentation(value) { const result = session.setPresentation(value); syncSession(); render(); notify(); return result; },
377
437
  update(index, patch) {
@@ -384,7 +444,8 @@ export function mountModelMeasureTool({
384
444
  selectedIndex, visible, presentation: { ...presentation }, snapModes: { ...snapModes }, locks: [...lockSet], activeFrame: resolveFrame(viewport).label, onePickKind }; },
385
445
  dimensions() { return session.dimensions(); },
386
446
  serialize() { return session.serialize(); },
387
- destroy() { closeOnePickMenu(); closeEditor(); unsubscribe(); releaseInput(); session.dispose(); svg.remove(); },
447
+ refresh() { render(); },
448
+ destroy() { destroyed = true; if (retryTimer !== null) clearTimeout(retryTimer); retryTimer = null; closeOnePickMenu(); closeEditor(); unsubscribe(); releaseInput(); session.dispose(); svg.remove(); },
388
449
  };
389
450
  notify(); return api;
390
451
  }
@@ -49,13 +49,15 @@ export function serializeModelPanelNodes(host, path = 'root') {
49
49
  nodes.push({ label: trigger.querySelector('.row-label')?.textContent || trigger.textContent || '',
50
50
  count: trigger.querySelector('.explorer-count')?.textContent || null, children,
51
51
  tip: trigger.dataset.tip || null,
52
+ ...(trigger.dataset.selectable === 'true' ? { selectable: true } : {}),
52
53
  lazy: !children.length && Number(trigger.querySelector('.explorer-count')?.textContent || 0) > 0,
53
54
  expanded: trigger.getAttribute('aria-expanded') === 'true', groupId: `${path}.${index}` });
54
55
  }
55
56
  continue;
56
57
  }
57
- if (child.classList.contains('explorer-row')) nodes.push({ label: child.querySelector('.row-label')?.textContent || child.textContent || '',
58
+ if (child.classList.contains('explorer-row')) nodes.push({ label: child.querySelector('.row-label')?.textContent ?? child.textContent ?? '',
58
59
  count: child.querySelector('.explorer-count')?.textContent || null, entityId: child.dataset.entityId || null,
60
+ ...(child.classList.contains('model-object-row') ? { objectFields: Object.fromEntries(['name', 'profile', 'id'].map((key) => [key, child.querySelector(`[data-object-field="${key}"]`)?.textContent ?? null])) } : {}),
59
61
  tip: child.dataset.tip || null });
60
62
  }
61
63
  return nodes;
@@ -80,6 +82,24 @@ export function expandModelPanelGroup(tabs, byId, groupId) {
80
82
  return true;
81
83
  }
82
84
 
85
+ /** Select an already-populated selectable group without changing its disclosure state. */
86
+ export function selectModelPanelGroup(tabs, byId, groupId) {
87
+ const parts = String(groupId || '').split('.'), key = parts.shift();
88
+ const tab = tabs.find((item) => item.key === key); if (!tab || !parts.length) return false;
89
+ let host = byId(tab.bodyId), trigger = null;
90
+ for (const raw of parts) {
91
+ if (!/^\d+$/.test(raw)) return false;
92
+ const branch = [...(host?.children || [])][Number(raw)];
93
+ if (!branch?.classList.contains('revit-tree-branch')) return false;
94
+ trigger = branch.querySelector(':scope > .explorer-row');
95
+ host = branch.querySelector(':scope > .revit-tree-children');
96
+ if (!trigger || !host) return false;
97
+ }
98
+ if (trigger?.dataset.selectable !== 'true') return false;
99
+ trigger.dispatchEvent(new trigger.ownerDocument.defaultView.Event('model-group-select'));
100
+ return true;
101
+ }
102
+
83
103
  // The main window's panel frame is an about:blank iframe, so it shares this origin and an editor may move its
84
104
  // own elements into it. It gets the editor's stylesheets and follows the editor's <html> attributes (the
85
105
  // theme), so what moves renders as it did at home. Returns the function that stops following.
@@ -151,7 +171,9 @@ export function createPanelHost({ win = window, root, bodies, install = (_doc) =
151
171
 
152
172
  export function createModelPanelBridge({ win = window, origin = location.origin, snapshot, selectedId, selectedIds = () => {
153
173
  const id = selectedId(); return typeof id === 'string' ? [id] : [];
154
- }, selectedSubjects = () => null, select, expand, panel = (_tab, _person, _follow) => false, chatLinksChanged = null }) {
174
+ }, select, expand, selectGroup = (_groupId) => false, search = (_tab, _query) => false,
175
+ selectionState = () => ({}), panel = (_tab, _person, _follow) => false,
176
+ gridVisibility = (_action) => false, selectedSubjects = () => null, chatLinksChanged = null }) {
155
177
  let requested = false;
156
178
  let generation = null;
157
179
  let revision = 0;
@@ -172,7 +194,7 @@ export function createModelPanelBridge({ win = window, origin = location.origin,
172
194
  // `subjects` is the selection as model objects a chat message may be about (#1653): {source, revision, total,
173
195
  // items: [{kind, id, label}]}, or null. Raw selected ids stay beside it for the tree's own rows.
174
196
  const publishSelection = (selectionOrigin = 'tree') => lifecycle === 'ready' && send({ type: 'selection', selectedId: selectedId(), selectedIds: selectedIds(),
175
- subjects: selectedSubjects(), selectionOrigin });
197
+ subjects: selectedSubjects(), selectionOrigin, ...selectionState() });
176
198
  const actionResult = (requestId, ok, message = '') => send({ type: 'action-result', requestId, ok, message });
177
199
 
178
200
  const receive = (event) => {
@@ -209,6 +231,27 @@ export function createModelPanelBridge({ win = window, origin = location.origin,
209
231
  actionResult(data.requestId, ok, ok ? '' : 'That model group has changed. Try opening it again.');
210
232
  return;
211
233
  }
234
+ if (data.action === 'select-group' && typeof data.groupId === 'string') {
235
+ let ok = false;
236
+ try { ok = data.datasetKey === datasetKey && !!selectGroup(data.groupId); if (ok) { publishSnapshot(); publishSelection('tree'); } }
237
+ catch (error) { try { win.console?.error?.('[model-panel] group selection failed', error); } catch { /* reporting must still continue */ } ok = false; }
238
+ actionResult(data.requestId, ok, ok ? '' : 'That model group has changed. Try selecting it again.');
239
+ return;
240
+ }
241
+ if (data.action === 'search' && typeof data.tab === 'string' && typeof data.query === 'string' && data.query.length <= 200) {
242
+ let ok = false;
243
+ try { ok = data.datasetKey === datasetKey && !!search(data.tab, data.query); if (ok) publishSnapshot(); }
244
+ catch (error) { try { win.console?.error?.('[model-panel] search action failed', error); } catch { /* reporting must still continue */ } ok = false; }
245
+ actionResult(data.requestId, ok, ok ? '' : 'Object search could not be updated. Reopen the model and try again.');
246
+ return;
247
+ }
248
+ if (data.action === 'grid-visibility' && (data.levelKey === null || typeof data.levelKey === 'string') && typeof data.visible === 'boolean') {
249
+ let ok = false;
250
+ try { ok = data.datasetKey === datasetKey && !!gridVisibility({ levelKey: data.levelKey, visible: data.visible }); if (ok) publishSnapshot(); }
251
+ catch (error) { try { win.console?.error?.('[model-panel] grid visibility action failed', error); } catch { /* reporting must still continue */ } ok = false; }
252
+ actionResult(data.requestId, ok, ok ? '' : 'Grid visibility could not be updated. Try again.');
253
+ return;
254
+ }
212
255
  // The main window shows one of the snapshot's panelTabs (tab: its key) or has left them (tab: null). `person` is
213
256
  // true when a person chose it (a click on the tab), not the main window restoring or following the editor's reveal.
214
257
  // `follow` is the Follow selection switch, for a panel tab that declared `follows` (it re-arrives when the switch flips).
@@ -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,16 @@ 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
+ // This runs on every pointer move while measuring. Touch the live region only when the words
149
+ // change, so assistive technology is not re-told the same status on each move. The pill is
150
+ // width-capped with an ellipsis (model-editor.css), so it always carries a themed tooltip: the
151
+ // provider's longer explanation when it has one (a snap notice), else the same full sentence.
152
+ const text = state.status ?? (state.armed ? (state.hasDraft ? 'Pick point 2' : 'Pick point 1') : (state.count ? `${state.count} placed` : 'Ready'));
153
+ if (status.textContent !== text) status.textContent = text;
154
+ const tip = typeof state.statusTip === 'string' && state.statusTip ? state.statusTip : text;
155
+ if (status.getAttribute('data-tip') !== tip) status.setAttribute('data-tip', tip);
156
+ }
132
157
  const locks = new Set(state.locks ?? []);
133
158
  actionsHost?.querySelectorAll('[data-model-axis]').forEach((axisButton) => {
134
159
  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
  }
@@ -19,6 +19,20 @@ export const MODEL_SNAP_LIMITS_V1 = Object.freeze({
19
19
  directionMinLength: 1e-9, nearParallelCrossLength: 1e-8,
20
20
  extensionSourceLengths: 10, extensionMaximumMm: 100000,
21
21
  });
22
+ /**
23
+ * How mesh snap acquisition decides what it has checked (#1747). Topology is indexed per element, on
24
+ * demand, for the pointer's sightline region only: a capsule along the pick ray, from its origin to
25
+ * `behindHitReach` radii past the surface under the pointer, whose radius is `neighbourhoodMargin`
26
+ * times the world length of the acquisition radius at that surface. Every visible element whose
27
+ * envelope meets that region is indexed COMPLETELY or the query is refused with `over-budget` — a
28
+ * partial set is never returned. `over-budget` therefore means "this pointer position's region could
29
+ * not be checked completely within the fixed budget" (or not yet, within one move's share of it),
30
+ * never "snapping is off for the model". `queryEvaluationCap` bounds the candidates one pointer event
31
+ * may evaluate; more than that inside the region is refused the same way, not truncated.
32
+ */
33
+ export const MODEL_SNAP_INDEX_POLICY_V1 = Object.freeze({
34
+ coverage: 'pointer-sightline', neighbourhoodMargin: 2, behindHitReach: 8, queryEvaluationCap: 4096,
35
+ });
22
36
 
23
37
  const MAX_COORD = 1e12, MAX_CSS = 1e7, MAX_GENERATION = 0xffffffff;
24
38
  const own = (v, k) => Object.prototype.hasOwnProperty.call(v, k);