@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
@@ -13,6 +13,9 @@
13
13
  const split = document.getElementById('left-pane-split');
14
14
  const status = document.getElementById('left-pane-status');
15
15
  const modelTabs = document.getElementById('left-model-tabs');
16
+ const modelSearch = document.getElementById('left-model-search');
17
+ const modelSearchInput = document.getElementById('left-model-search-input');
18
+ const modelSearchClear = document.getElementById('left-model-search-clear');
16
19
  const modelIndexLabel = document.getElementById('left-model-index-label');
17
20
  const followSelection = document.getElementById('left-model-follow-selection');
18
21
  const modelContent = document.getElementById('left-model-content');
@@ -25,7 +28,7 @@
25
28
  // controls leave with it. No src: the frame's first about:blank document is this origin and stays put.
26
29
  const panelSlot = document.getElementById('left-model-panel-slot');
27
30
  let panelFrame = document.getElementById('left-model-panel');
28
- if (!frame || !pane || !stack || !split || !status || !modelTabs || !modelIndexLabel || !followSelection || !modelContent || !collapsedHost || !empty || !modelContext
31
+ if (!frame || !pane || !stack || !split || !status || !modelTabs || !modelSearch || !modelSearchInput || !modelSearchClear || !modelIndexLabel || !followSelection || !modelContent || !collapsedHost || !empty || !modelContext
29
32
  || !modelIndexHeader || !panelSlot || !panelFrame) return;
30
33
 
31
34
  const sections = {
@@ -73,6 +76,8 @@
73
76
  let panelShown = null; // the panel tab the editor was last told it is showing (null: none)
74
77
  let chosenByPerson = false; // true only while a click on a tab renders: the editor is told a person chose it
75
78
  let displacedTab = null; // a chosen tab the snapshot stopped offering (a 3D-only tab while in 2D); it comes back with it
79
+ let searchTimer = null;
80
+ let lastSearchAnnouncement = '';
76
81
 
77
82
  const panelTabsOf = (snapshot) => (Array.isArray(snapshot?.panelTabs) ? snapshot.panelTabs : [])
78
83
  .filter((tab) => typeof tab?.key === 'string' && typeof tab?.label === 'string');
@@ -101,6 +106,25 @@
101
106
  if (state.followSelection) revealSelectedEntity();
102
107
  if (followsTab(state.tab)) { panelShown = null; renderModel(); } // the editor draws the following, so it is told again
103
108
  });
109
+ const searchContext = (query) => ({ generation: state.generation, datasetKey: state.datasetKey, tab: state.tab, query: String(query).slice(0, 200) });
110
+ const requestSearch = (context) => {
111
+ if (context.generation !== state.generation || context.datasetKey !== state.datasetKey || context.tab !== state.tab
112
+ || isPanelTab(context.tab) || !context.datasetKey) return false;
113
+ const requestId = sendAction({ action: 'search', tab: context.tab, query: context.query, datasetKey: context.datasetKey });
114
+ if (requestId) pendingActions.set(requestId, { kind: 'search', tab: context.tab });
115
+ return !!requestId;
116
+ };
117
+ const clearSearch = () => {
118
+ clearTimeout(searchTimer); modelSearchInput.value = ''; modelSearchClear.hidden = true;
119
+ requestSearch(searchContext('')); modelSearchInput.focus();
120
+ };
121
+ modelSearchInput.addEventListener('input', () => {
122
+ modelSearchClear.hidden = !modelSearchInput.value;
123
+ const context = searchContext(modelSearchInput.value);
124
+ clearTimeout(searchTimer); searchTimer = setTimeout(() => requestSearch(context), 120);
125
+ });
126
+ modelSearchInput.addEventListener('keydown', (event) => { if (event.key === 'Escape' && modelSearchInput.value) { event.preventDefault(); clearSearch(); } });
127
+ modelSearchClear.addEventListener('click', clearSearch);
104
128
 
105
129
  function available(key) { return key === 'narrative' || state.modelAvailable; }
106
130
  function shown(key) { return available(key) && (state.visible[key] || sessionVisible[key]); }
@@ -441,8 +465,66 @@
441
465
 
442
466
  function renderNodes(nodes, host) {
443
467
  const scrollTop = host.scrollTop;
468
+ let objectRowIndex = 0;
444
469
  host.replaceChildren();
445
470
  if (!Array.isArray(nodes) || !nodes.length) { const empty = document.createElement('div'); empty.className = 'left-model-empty'; empty.textContent = 'No objects in this index.'; host.append(empty); return; }
471
+ const renderGridVisibility = (control) => {
472
+ const levels = Array.isArray(control?.levels) ? control.levels.filter((level) => level && typeof level.key === 'string'
473
+ && Number.isFinite(level.mm) && typeof level.visible === 'boolean').sort((left, right) => left.mm - right.mm) : [];
474
+ if (!levels.length) return null;
475
+ const fieldset = document.createElement('fieldset'); fieldset.className = 'left-grid-visibility';
476
+ fieldset.setAttribute('aria-label', 'Grid visibility');
477
+ const legend = document.createElement('legend'); legend.textContent = 'Grid visibility'; fieldset.append(legend);
478
+ const rows = [];
479
+ const option = ({ key, primary, secondary = '', checked, master = false }) => {
480
+ const row = document.createElement('label'); row.className = `left-grid-level${master ? ' left-grid-level-all' : ''}`;
481
+ const input = document.createElement('input'); input.type = 'checkbox'; input.checked = checked;
482
+ input.dataset.gridLevelKey = key; input.dataset.commandId = `shell.grid-elevation#${commandInstance(key)}`;
483
+ const name = document.createElement('span'); name.className = 'left-grid-level-name'; name.textContent = primary;
484
+ row.append(input, name);
485
+ if (secondary) { const value = document.createElement('span'); value.className = 'left-grid-level-value'; value.textContent = secondary; row.append(value); }
486
+ fieldset.append(row); rows.push({ input, level: key === '*' ? null : levels.find((level) => level.key === key) });
487
+ return input;
488
+ };
489
+ const visibleCount = levels.filter((level) => level.visible).length;
490
+ const master = option({ key: '*', primary: 'All elevations', secondary: `${visibleCount} of ${levels.length}`, checked: visibleCount === levels.length, master: true });
491
+ master.indeterminate = visibleCount > 0 && visibleCount < levels.length;
492
+ master.setAttribute('aria-checked', master.indeterminate ? 'mixed' : String(master.checked));
493
+ for (const level of levels) {
494
+ const primary = String(level.authored || level.label || 'Grid plane').trim() || 'Grid plane';
495
+ const display = String(level.display || `${Math.round(level.mm)} mm`).trim();
496
+ const comparable = (value) => value.toLocaleLowerCase().replace(/[^\p{L}\p{N}]+/gu, '');
497
+ option({ key: level.key, primary, secondary: comparable(display) === comparable(primary) ? '' : display, checked: level.visible });
498
+ }
499
+ const note = document.createElement('p'); note.className = 'left-grid-visibility-status'; fieldset.append(note);
500
+ const repaint = (announce = false) => {
501
+ const individual = rows.filter((item) => item.level); const shown = individual.filter((item) => item.input.checked);
502
+ master.checked = shown.length === individual.length; master.indeterminate = shown.length > 0 && shown.length < individual.length;
503
+ master.setAttribute('aria-checked', master.indeterminate ? 'mixed' : String(master.checked));
504
+ master.dataset.commandInstanceLabel = `all elevations — ${master.indeterminate ? 'mixed' : master.checked ? 'shown' : 'hidden'}`;
505
+ for (const item of individual) {
506
+ const authored = String(item.level.authored || item.level.label || item.level.display || 'grid plane').trim();
507
+ item.input.dataset.commandInstanceLabel = `${authored} — ${item.input.checked ? 'shown' : 'hidden'}`;
508
+ }
509
+ const count = master.closest('label')?.querySelector('.left-grid-level-value'); if (count) count.textContent = `${shown.length} of ${individual.length}`;
510
+ note.textContent = shown.length ? `Bubbles at lowest shown elevation: ${String(shown[0].level.authored || shown[0].level.label || shown[0].level.display).trim()}.`
511
+ : 'Grid hidden at all elevations. Check an elevation to show it.';
512
+ if (announce) status.textContent = note.textContent;
513
+ const active = document.activeElement;
514
+ if (rows.some((item) => item.input === active)) window.Instructor?.refreshCarrier?.(active);
515
+ };
516
+ const sendVisibility = (levelKey, visible, input) => {
517
+ const requestId = sendAction({ action: 'grid-visibility', levelKey, visible, datasetKey: state.datasetKey });
518
+ if (requestId) pendingActions.set(requestId, { kind: 'grid-visibility', commandId: input.dataset.commandId });
519
+ };
520
+ master.addEventListener('change', () => {
521
+ for (const item of rows) if (item.level) item.input.checked = master.checked;
522
+ repaint(true); sendVisibility(null, master.checked, master);
523
+ });
524
+ for (const item of rows) if (item.level) item.input.addEventListener('change', () => { repaint(true); sendVisibility(item.level.key, item.input.checked, item.input); });
525
+ repaint();
526
+ return fieldset;
527
+ };
446
528
  const append = (items, parent) => {
447
529
  for (const node of items) {
448
530
  if (!node || typeof node.label !== 'string') continue;
@@ -455,17 +537,48 @@
455
537
  ? `shell.model-item#${commandInstance(instance)}`
456
538
  : `shell.model-group#${commandInstance(instance)}`;
457
539
  row.dataset.commandInstanceLabel = node.label;
458
- const accessibleLabel = node.count == null ? node.label : `${node.label}, ${node.count}`;
459
- row.setAttribute('aria-label', accessibleLabel);
460
540
  if (typeof node.tip === 'string' && node.tip) row.dataset.tip = node.tip;
461
- const label = document.createElement('span'); label.className = 'row-label'; label.textContent = node.label; row.append(label);
541
+ const label = document.createElement('span'); label.className = 'row-label'; label.textContent = node.label;
542
+ if (node.entityId && node.objectFields && ['name', 'profile', 'id'].every((key) => node.objectFields[key] == null || typeof node.objectFields[key] === 'string')) {
543
+ row.classList.add('model-object-row');
544
+ const summary = document.createElement('span'); summary.className = 'model-object-summary';
545
+ const fieldId = `left-model-object-${++objectRowIndex}`;
546
+ label.classList.add('model-object-name'); label.id = `${fieldId}-name`;
547
+ if (node.objectFields.name != null) { label.dataset.objectField = 'name'; label.textContent = node.objectFields.name; }
548
+ summary.append(label); row.setAttribute('aria-labelledby', label.id);
549
+ const details = document.createElement('span'); details.className = 'model-object-details'; details.id = `${fieldId}-details`;
550
+ for (const [key, caption] of [['profile', 'Profile'], ['id', 'ID']]) {
551
+ if (node.objectFields[key] == null) continue;
552
+ const field = document.createElement('span'); field.className = 'model-object-field';
553
+ const fieldLabel = document.createElement('span'); fieldLabel.className = 'model-object-field-label'; fieldLabel.textContent = `${caption}: `;
554
+ const value = document.createElement('span'); value.dataset.objectField = key; value.textContent = node.objectFields[key];
555
+ field.append(fieldLabel, value); details.append(field);
556
+ }
557
+ if (details.children.length) { summary.append(details); row.setAttribute('aria-describedby', details.id); }
558
+ row.append(summary);
559
+ } else {
560
+ row.setAttribute('aria-label', node.count == null ? node.label : `${node.label}, ${node.count}`);
561
+ row.append(label);
562
+ }
462
563
  if (node.count != null) { const count = document.createElement('span'); count.className = 'explorer-count'; count.textContent = String(node.count); row.append(count); }
463
564
  if (node.entityId) {
464
565
  row.dataset.entityId = node.entityId;
465
566
  row.classList.toggle('selected', selectedIdsOf(state.snapshot).includes(node.entityId));
466
567
  if (node.entityId === state.snapshot?.selectedId) row.setAttribute('aria-current', 'true');
467
- row.addEventListener('click', (event) => selectRow(node.entityId, event));
468
- const item = document.createElement('div'); item.setAttribute('role', 'listitem'); item.append(row);
568
+ const gridControl = state.snapshot?.gridVisibility?.entityId === node.entityId ? renderGridVisibility(state.snapshot.gridVisibility) : null;
569
+ const item = document.createElement('div'); item.setAttribute('role', 'listitem');
570
+ if (gridControl) {
571
+ item.className = 'left-model-branch left-grid-object';
572
+ const disclosureKey = `${state.datasetKey}:${state.tab}:grid-visibility:${node.entityId}`;
573
+ const searching = !!state.snapshot?.searches?.[state.tab]?.query;
574
+ const expanded = searching || (groupDisclosure.has(disclosureKey) ? groupDisclosure.get(disclosureKey) : true);
575
+ row.setAttribute('aria-expanded', String(expanded)); gridControl.hidden = !expanded;
576
+ row.addEventListener('click', (event) => {
577
+ const open = row.getAttribute('aria-expanded') !== 'true'; row.setAttribute('aria-expanded', String(open)); gridControl.hidden = !open;
578
+ groupDisclosure.set(disclosureKey, open); selectRow(node.entityId, event);
579
+ });
580
+ item.append(row, gridControl);
581
+ } else { row.addEventListener('click', (event) => selectRow(node.entityId, event)); item.append(row); }
469
582
  parent.append(item); continue;
470
583
  }
471
584
  if (Array.isArray(node.children)) {
@@ -487,6 +600,7 @@
487
600
  if (node.lazy && !node.children.length) { requestLazyChildren(); return; }
488
601
  const open = row.getAttribute('aria-expanded') !== 'true'; row.setAttribute('aria-expanded', String(open)); children.hidden = !open;
489
602
  groupDisclosure.set(disclosureKey, open);
603
+ if (node.selectable === true) sendAction({ action: 'select-group', groupId: node.groupId, datasetKey: state.datasetKey });
490
604
  });
491
605
  branch.append(row, children); parent.append(branch);
492
606
  if (expanded && node.lazy && !node.children.length) requestLazyChildren();
@@ -509,10 +623,14 @@
509
623
  }
510
624
  const selectedId = selectedIds[0];
511
625
  pendingRevealId = selectedId;
512
- if (state.tab !== 'model') { state.tab = 'model'; renderModel(); }
626
+ const followTab = state.snapshot.tabs.find((tab) => tab.key === 'model')?.key || state.snapshot.tabs[0]?.key;
627
+ if (followTab && state.tab !== followTab) { state.tab = followTab; renderModel(); }
513
628
  const row = [...modelContent.querySelectorAll('[data-entity-id]')]
514
629
  .find((candidate) => candidate.dataset.entityId === selectedId);
515
- if (!row) return false;
630
+ if (!row) {
631
+ if (state.snapshot?.searches?.[state.tab]?.query) status.textContent = 'The selected object is hidden by search. Clear the search to reveal it.';
632
+ return false;
633
+ }
516
634
  let children = row.closest('.left-model-children');
517
635
  while (children) {
518
636
  children.hidden = false;
@@ -525,6 +643,8 @@
525
643
  }
526
644
  children = branch?.parentElement?.closest('.left-model-children') || null;
527
645
  }
646
+ const gridControl = row.parentElement?.querySelector(':scope > .left-grid-visibility');
647
+ if (gridControl) { row.setAttribute('aria-expanded', 'true'); gridControl.hidden = false; }
528
648
  const sequence = ++revealSequence;
529
649
  const generation = state.generation;
530
650
  const revision = state.revision;
@@ -581,6 +701,7 @@
581
701
  if (!button.dataset.leftPaneBound) {
582
702
  button.dataset.leftPaneBound = 'true';
583
703
  button.addEventListener('click', () => {
704
+ clearTimeout(searchTimer); searchTimer = null;
584
705
  state.tab = button.dataset.modelTabKey; displacedTab = null; save();
585
706
  chosenByPerson = true; try { renderModel(); } finally { chosenByPerson = false; }
586
707
  button.focus();
@@ -601,7 +722,7 @@
601
722
  if (focusedKey) buttons.find((button) => button.dataset.modelTabKey === focusedKey)?.focus({ preventScroll: true });
602
723
  // A PANEL tab: the editor draws it in the frame; this side only shows the slot and says which tab.
603
724
  const panel = isPanelTab(state.tab) ? state.tab : null;
604
- modelIndexHeader.hidden = !!panel && !followsTab(panel); modelContent.hidden = !!panel; panelSlot.hidden = !panel;
725
+ modelSearch.hidden = !!panel; modelIndexHeader.hidden = !!panel && !followsTab(panel); modelContent.hidden = !!panel; panelSlot.hidden = !panel;
605
726
  if (panel) {
606
727
  if (followsTab(panel)) modelIndexLabel.textContent = tabs.find((tab) => tab.key === panel).label;
607
728
  panelSlot.setAttribute('aria-labelledby', `left-model-tab-${panel}`);
@@ -613,12 +734,27 @@
613
734
  if (requestId) { panelShown = panel; pendingActions.set(requestId, { kind: 'panel', key: panel }); }
614
735
  }
615
736
  if (panel) return;
737
+ const activeSearch = snapshot.searches?.[state.tab] || {};
738
+ const nextQuery = typeof activeSearch.query === 'string' ? activeSearch.query : '';
739
+ if (document.activeElement !== modelSearchInput) modelSearchInput.value = nextQuery;
740
+ modelSearchInput.setAttribute('aria-label', `Search objects in ${tabs.find((tab) => tab.key === state.tab)?.label || 'model'}`);
741
+ modelSearchClear.hidden = !modelSearchInput.value;
616
742
  modelContent.setAttribute('aria-labelledby', `left-model-tab-${state.tab}`);
617
743
  const focusedCommand = modelContent.contains(document.activeElement)
618
744
  ? document.activeElement?.closest?.('[data-command-id]')?.getAttribute('data-command-id') : null;
619
745
  const body = Array.isArray(snapshot.bodies?.[state.tab]) ? snapshot.bodies[state.tab] : [];
620
746
  const headingIndex = body.findIndex((node) => node?.kind === 'label');
621
- modelIndexLabel.textContent = headingIndex >= 0 ? body[headingIndex].label : `Browse by ${tabs.find((tab) => tab.key === state.tab)?.label?.toLowerCase() || 'model'}`;
747
+ const indexLabel = headingIndex >= 0 ? body[headingIndex].label : `Browse by ${tabs.find((tab) => tab.key === state.tab)?.label?.toLowerCase() || 'model'}`;
748
+ modelIndexLabel.textContent = Number.isFinite(activeSearch.shown) && Number.isFinite(activeSearch.total) && nextQuery
749
+ ? `${indexLabel} · ${activeSearch.shown} of ${activeSearch.total}` : indexLabel;
750
+ const announcementKey = nextQuery && Number.isFinite(activeSearch.shown) && Number.isFinite(activeSearch.total)
751
+ ? `${state.datasetKey}:${state.tab}:${nextQuery}:${activeSearch.shown}:${activeSearch.total}` : '';
752
+ if (announcementKey && announcementKey !== lastSearchAnnouncement) {
753
+ status.textContent = activeSearch.shown > 0
754
+ ? `${activeSearch.shown} of ${activeSearch.total} objects.`
755
+ : `No objects match “${nextQuery}”.`;
756
+ lastSearchAnnouncement = announcementKey;
757
+ } else if (!announcementKey) lastSearchAnnouncement = '';
622
758
  renderNodes(headingIndex >= 0 ? body.filter((_node, index) => index !== headingIndex) : body, modelContent);
623
759
  if (focusedCommand) [...modelContent.querySelectorAll('[data-command-id]')]
624
760
  .find((item) => item.getAttribute('data-command-id') === focusedCommand)?.focus({ preventScroll: true });
@@ -686,6 +822,16 @@
686
822
  if (currentChildren) currentChildren.hidden = false;
687
823
  }
688
824
  }
825
+ if (pending?.kind === 'grid-visibility' && !data.ok) {
826
+ const refreshRollback = document.activeElement?.dataset?.commandId === pending.commandId;
827
+ renderModel();
828
+ if (refreshRollback) {
829
+ const restored = [...modelContent.querySelectorAll('[data-command-id]')]
830
+ .find((row) => row.dataset.commandId === pending.commandId);
831
+ if (restored) { restored.focus(); window.Instructor?.refreshCarrier?.(restored); }
832
+ else window.Instructor?.clear?.();
833
+ }
834
+ }
689
835
  if (!data.ok) status.textContent = data.message || 'That model action is no longer available.';
690
836
  // The frame stays empty, so say so where the tab would be — for the tab still shown, not an earlier one.
691
837
  if (pending?.kind === 'panel' && !data.ok && pending.key === panelShown) {
@@ -715,6 +861,10 @@
715
861
  state.snapshot.selectedId = typeof data.selectedId === 'string' ? data.selectedId : null;
716
862
  state.snapshot.selectedIds = Array.isArray(data.selectedIds) ? data.selectedIds.filter((id) => typeof id === 'string') : (state.snapshot.selectedId ? [state.snapshot.selectedId] : []);
717
863
  state.snapshot.selectionOrigin = data.selectionOrigin || 'tree';
864
+ if (Array.isArray(data.geometrySelectionIds)) {
865
+ state.snapshot.focusEntityId = typeof data.focusEntityId === 'string' ? data.focusEntityId : null;
866
+ state.snapshot.geometrySelectionIds = data.geometrySelectionIds.filter((id) => typeof id === 'string');
867
+ }
718
868
  state.snapshot.subjects = data.subjects && typeof data.subjects === 'object' ? data.subjects : null;
719
869
  }
720
870
  announceSelection();
@@ -56,6 +56,21 @@ export async function readModelJsonArtifact({ url, receipt, rowKey, expectedItem
56
56
  return { document, rows, bytes: bytes.byteLength };
57
57
  }
58
58
 
59
+ /** Fetch and authenticate a signed JSON document whose receipt counts something other than a top-level row array. */
60
+ export async function readModelJsonDocument({ url, receipt, fetchImpl = fetch, cryptoImpl = crypto, signal = undefined }) {
61
+ preflightModelJsonReceipt(receipt);
62
+ const response = await fetchImpl(url, { credentials: 'same-origin', signal });
63
+ if (!response.ok) throw new Error(`Model artifact request failed (${response.status}).`);
64
+ const bytes = await readBoundedBytes(response, receipt, MODEL_VIEWER_MAX_JSON_BYTES);
65
+ if (bytes.byteLength !== receipt.bytes) throw new Error('The model artifact byte length does not match its signed receipt.');
66
+ const digest = hex(new Uint8Array(await cryptoImpl.subtle.digest('SHA-256', bytes)));
67
+ if (digest !== receipt.digest) throw new Error('The model artifact digest does not match its signed receipt.');
68
+ let document;
69
+ try { document = JSON.parse(new TextDecoder().decode(bytes)); } catch { throw new Error('The authenticated model artifact is not valid JSON.'); }
70
+ if (!document || typeof document !== 'object' || Array.isArray(document)) throw new Error('The authenticated model artifact is not a JSON object.');
71
+ return { document, bytes: bytes.byteLength };
72
+ }
73
+
59
74
  /** Fetch and authenticate one signed binary model artifact without exceeding its bounded receipt. */
60
75
  export async function readModelBinaryArtifact({ url, receipt, maxBytes, fetchImpl = fetch, cryptoImpl = crypto, signal = undefined }) {
61
76
  if (!receipt || !Number.isSafeInteger(receipt.bytes) || receipt.bytes < 0 || receipt.bytes > maxBytes || !SHA256.test(receipt.digest)) throw new Error('The model artifact has no safe signed byte receipt.');
@@ -0,0 +1,89 @@
1
+ import { DEFAULT_DISPLAY_UNITS, formatLength, FT_IN, MM } from './display-units.js';
2
+
3
+ const valid = (value) => value === FT_IN || value === MM;
4
+
5
+ /** The parser viewers share Steel's project preference and its single length formatter. */
6
+ export function mountModelDisplayUnits({ host, doc, projectId, commandPrefix, request, onChange, onError,
7
+ wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms)) }) {
8
+ let units = null, saving = false, destroyed = false, generation = 0, readGeneration = 0, connectionGeneration = 0, connected = true, stale = false;
9
+ const controls = [];
10
+ host.setAttribute('role', 'group'); host.setAttribute('aria-label', 'Display units');
11
+ const label = doc.createElement('span'); label.textContent = 'Units'; host.append(label);
12
+ const status = doc.createElement('span'); status.className = 'model-units-status'; status.setAttribute('role', 'status');
13
+ const retry = doc.createElement('button'); retry.type = 'button'; retry.className = 'model-units-retry'; retry.textContent = 'Retry'; retry.dataset.commandId = `${commandPrefix}.display-units-retry`; retry.setAttribute('aria-label', 'Retry loading project display units');
14
+ retry.addEventListener('click', () => load());
15
+ const paint = () => {
16
+ for (const [value, button] of controls) {
17
+ button.disabled = units === null || saving;
18
+ button.setAttribute('aria-pressed', String(value === units));
19
+ button.dataset.tip = units === null ? 'Loading this project’s display units…'
20
+ : saving ? 'Saving this project’s display units…' : `Display lengths in ${value === MM ? 'millimetres' : 'feet and inches'}`;
21
+ }
22
+ status.hidden = connected && !stale;
23
+ status.textContent = stale ? (units === null ? 'Units unavailable (ft-in)' : 'Units may be stale') : connected ? '' : 'Offline';
24
+ status.dataset.tip = units === null ? 'Project units could not be confirmed. Feet and inches are shown until Retry succeeds.' : 'The last confirmed units are shown. Retry to read the current project setting.';
25
+ status.setAttribute('aria-label', status.hidden ? '' : units === null ? 'Project display units unavailable; showing feet and inches' : 'Display units may be out of date');
26
+ retry.hidden = !stale; retry.disabled = saving;
27
+ const instructorState = doc.defaultView?.__revitInstructorState;
28
+ if (instructorState && typeof instructorState === 'object') {
29
+ doc.defaultView.__revitInstructorState = {
30
+ ...instructorState,
31
+ hiddenCommands: retry.hidden ? [retry.dataset.commandId] : [],
32
+ };
33
+ }
34
+ doc.defaultView?.__instructor?.notifyChanged?.();
35
+ };
36
+ const confirm = (value) => { if (!valid(value) || destroyed) return; const changed = units !== value; units = value; paint(); if (changed) onChange(units); };
37
+ const adopt = (value) => { if (!valid(value) || destroyed) return; generation += 1; confirm(value); };
38
+ const url = `/api/projects/${encodeURIComponent(projectId)}/display-units`;
39
+ const choose = async (value) => {
40
+ if (saving || units === null || units === value || destroyed) return;
41
+ const started = generation;
42
+ saving = true; paint();
43
+ try {
44
+ const body = await request(url, { method: 'PUT', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ displayUnits: value }) });
45
+ if (!valid(body.displayUnits)) throw new Error('Unknown confirmed display units');
46
+ if (generation === started) { stale = false; confirm(body.displayUnits); }
47
+ else await load(); // A live event arrived during the write; ask the server which value won.
48
+ } catch { if (!destroyed) { await load(); onError('Could not confirm the unit change. Showing the last confirmed units.'); } }
49
+ finally { saving = false; if (!destroyed) paint(); }
50
+ };
51
+ for (const value of [FT_IN, MM]) {
52
+ const button = doc.createElement('button'); button.type = 'button'; button.textContent = value;
53
+ button.dataset.unitChoice = value;
54
+ button.dataset.commandId = `${commandPrefix}.display-units#${value}`;
55
+ button.setAttribute('aria-label', `Display units: ${value}`);
56
+ button.addEventListener('click', () => choose(value)); controls.push([value, button]); host.append(button);
57
+ }
58
+ host.append(status, retry);
59
+ paint();
60
+ async function load() {
61
+ const requestGeneration = ++readGeneration;
62
+ for (const backoff of [100, 250, 500]) {
63
+ await wait(backoff);
64
+ if (destroyed || requestGeneration !== readGeneration) return false;
65
+ const started = generation;
66
+ try {
67
+ const body = await request(url); if (!valid(body.displayUnits)) throw new Error('Unknown display units');
68
+ if (destroyed || requestGeneration !== readGeneration) return false;
69
+ // Every event is an observation epoch, even when the displayed units did not change.
70
+ // Retry until the GET completed without an intervening cross-tab observation.
71
+ if (generation !== started) continue;
72
+ stale = false; confirm(body.displayUnits); return true;
73
+ } catch { /* Retry the same bounded reconciliation pass. */ }
74
+ }
75
+ if (!destroyed && requestGeneration === readGeneration) {
76
+ stale = true; paint(); onError(units === null ? 'Could not read this project’s display units. Showing feet and inches.' : 'Project units could not be refreshed. Showing the last confirmed units.');
77
+ }
78
+ return false;
79
+ }
80
+ return {
81
+ load,
82
+ connectionLost() { connectionGeneration++; connected = false; paint(); },
83
+ async reconnect() { const attempt = ++connectionGeneration; const confirmed = await load(); if (!destroyed && attempt === connectionGeneration) { connected = confirmed; paint(); } },
84
+ adopt,
85
+ units: () => units ?? DEFAULT_DISPLAY_UNITS,
86
+ length(mm) { const value = units ?? DEFAULT_DISPLAY_UNITS; return formatLength(mm, value) + (value === MM ? ' mm' : ''); },
87
+ destroy() { destroyed = true; host.replaceChildren(); },
88
+ };
89
+ }
@@ -89,16 +89,31 @@ const CONTROLS = Object.freeze({
89
89
  });
90
90
 
91
91
  export function revitRenderPlan(entries = revitCapabilityEntries()) {
92
+ return readOnlyModelRenderPlan({ entries, commandPrefix: 'revit', sourceLabel: 'Revit' });
93
+ }
94
+
95
+ const mappedText = (value, commandPrefix, sourceLabel) => typeof value === 'string'
96
+ ? value.replaceAll('revit.', `${commandPrefix}.`).replaceAll('Revit', sourceLabel)
97
+ : value;
98
+
99
+ /** Reuse the authenticated read-only model chrome without leaking Revit product language. */
100
+ export function readOnlyModelRenderPlan({
101
+ entries = revitCapabilityEntries(), commandPrefix = 'revit', sourceLabel = 'Revit',
102
+ } = {}) {
92
103
  const resolved = resolveToolbar(capabilityMap(entries));
93
104
  const clusters = toolbarClusters(resolved).map((cluster) => ({
94
105
  ...cluster,
95
106
  controls: cluster.controls.map((control) => {
96
107
  const descriptor = CONTROLS[control.id];
97
108
  if (!descriptor) throw new Error(`revitRenderPlan: no descriptor for "${control.id}"`);
98
- const withCommand = { ...descriptor, semantic: control.id, cmd: descriptor.cmd ?? REVIT_COMMAND_BINDING_V1[control.id] };
99
- if (!control.items) return withCommand;
100
- const live = new Set(control.items);
101
- return { ...withCommand, items: descriptor.items.filter((item) => !item.cap || live.has(item.cap)) };
109
+ const withCommand = Object.fromEntries(Object.entries({
110
+ ...descriptor, semantic: control.id, cmd: descriptor.cmd ?? REVIT_COMMAND_BINDING_V1[control.id],
111
+ }).map(([key, value]) => [key, mappedText(value, commandPrefix, sourceLabel)]));
112
+ if (!descriptor.items) return withCommand;
113
+ const live = control.items ? new Set(control.items) : null;
114
+ return { ...withCommand, items: descriptor.items.filter((item) => !item.cap || !live || live.has(item.cap)).map((item) => (
115
+ Object.fromEntries(Object.entries(item).map(([key, value]) => [key, mappedText(value, commandPrefix, sourceLabel)]))
116
+ )) };
102
117
  }),
103
118
  }));
104
119
  const plan = { schema: 'floless.model-toolbar-plan/v1', clusters };
@@ -139,3 +154,5 @@ export function createRevitEditorAdapter({ viewport, host = {} }) {
139
154
  const capabilities = capabilityMap(revitCapabilityEntries());
140
155
  return createModelEditorFacade({ provider: provider(viewport), capabilities, host });
141
156
  }
157
+
158
+ export const createReadOnlyModelEditorAdapter = createRevitEditorAdapter;
@@ -117,7 +117,7 @@
117
117
  .model-view-cube-host canvas:focus-visible,#m3dCube canvas:focus-visible{outline:2px solid var(--brand,var(--accent,#60a5fa));outline-offset:3px;border-radius:8px}
118
118
  .model-view-cube-status{position:absolute;width:1px;height:1px;overflow:hidden;clip-path:inset(50%);white-space:nowrap}
119
119
 
120
- .model-clip-list{border-top:1px solid var(--line);margin-top:8px;padding-top:4px}.model-clip-list-header{height:30px;display:flex;align-items:center;gap:7px;padding:0 5px;color:var(--text)}.model-clip-list-header strong{font-size:11px;text-transform:uppercase;letter-spacing:.08em}.model-clip-count{min-width:18px;height:18px;display:grid;place-items:center;border-radius:9px;background:var(--btn);color:var(--muted);font-size:10px}.model-clip-enable-all{width:24px;min-width:24px;min-height:24px;padding:0;border:0;background:transparent;color:var(--muted);box-shadow:none}.model-clip-enable-all[data-state="on"]{color:var(--brand,#60a5fa)}.model-clip-enable-all[data-state="mixed"]{color:#64748b}.model-clip-clear{margin-left:auto}.model-clip-list-rows{display:grid;gap:2px}.model-clip-row{min-height:30px;display:grid;grid-template-columns:24px minmax(0,1fr) 24px;align-items:center;gap:4px;border-radius:5px;padding:2px 3px}.model-clip-row:hover,.model-clip-row.is-selected{background:var(--accent-soft)}.model-clip-row.is-selected{outline:1px solid color-mix(in srgb,var(--brand,#3b82f6) 58%,transparent)}.model-clip-row button{min-width:0;min-height:24px;padding:2px 5px;border:0;background:transparent;color:var(--muted);box-shadow:none}.model-clip-row button:hover{background:var(--btn-hover);color:var(--text)}.model-clip-enable{width:22px;border:1px solid var(--line)!important;color:var(--brand,#60a5fa)!important}.model-clip-enable[aria-pressed="false"]{color:transparent!important}.model-clip-label{text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--text)!important}.model-clip-remove{font-size:16px;line-height:1}.model-clip-rename{width:100%;min-width:0;height:25px;border:1px solid var(--brand,#3b82f6);border-radius:4px;background:var(--bg,#020817);color:var(--text);padding:2px 6px;font:inherit;outline:none}.model-clip-list-empty{padding:10px 7px 12px;color:var(--muted);font-size:11px;line-height:1.45}.model-clip-drag-readout{position:fixed;z-index:60;pointer-events:none;padding:5px 9px;border:1px solid var(--line);border-radius:5px;background:var(--panel);color:var(--text);box-shadow:0 3px 10px rgba(0,0,0,.45);font:11px var(--mono,monospace)}
120
+ .model-clip-list{border-top:1px solid var(--line);margin-top:8px;padding-top:4px}.model-clip-list-header{height:30px;display:flex;align-items:center;gap:7px;padding:0 5px;color:var(--text)}.model-clip-list-header strong{font-size:11px;text-transform:uppercase;letter-spacing:.08em}.model-clip-count{min-width:18px;height:18px;display:grid;place-items:center;border-radius:9px;background:var(--btn);color:var(--muted);font-size:10px}.model-clip-enable-all{width:24px;min-width:24px;min-height:24px;padding:0;border:0;background:transparent;color:var(--muted);box-shadow:none}.model-clip-enable-all[data-state="on"]{color:var(--brand,#60a5fa)}.model-clip-enable-all[data-state="mixed"]{color:#64748b}.model-clip-clear{margin-left:auto}.model-clip-list-rows{display:grid;align-content:start;gap:2px}.model-clip-row{min-height:30px;display:grid;grid-template-columns:24px minmax(0,1fr) 24px;align-items:center;gap:4px;border-radius:5px;padding:2px 3px}.model-clip-row:hover,.model-clip-row.is-selected{background:var(--accent-soft)}.model-clip-row.is-selected{outline:1px solid color-mix(in srgb,var(--brand,#3b82f6) 58%,transparent)}.model-clip-row button{min-width:0;min-height:24px;padding:2px 5px;border:0;background:transparent;color:var(--muted);box-shadow:none}.model-clip-row button:hover{background:var(--btn-hover);color:var(--text)}.model-clip-enable{width:22px;border:1px solid var(--line)!important;color:var(--brand,#60a5fa)!important}.model-clip-enable[aria-pressed="false"]{color:transparent!important}.model-clip-label{text-align:left;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--text)!important}.model-clip-remove{font-size:16px;line-height:1}.model-clip-rename{width:100%;min-width:0;height:25px;border:1px solid var(--brand,#3b82f6);border-radius:4px;background:var(--bg,#020817);color:var(--text);padding:2px 6px;font:inherit;outline:none}.model-clip-list-empty{padding:10px 7px 12px;color:var(--muted);font-size:11px;line-height:1.45}.model-clip-drag-readout{position:fixed;z-index:60;pointer-events:none;padding:5px 9px;border:1px solid var(--line);border-radius:5px;background:var(--panel);color:var(--text);box-shadow:0 3px 10px rgba(0,0,0,.45);font:11px var(--mono,monospace)}
121
121
 
122
122
  /* Inspector seam, stub and grip are shared with master Steel. */
123
123
  .model-inspector-resizer{flex:none;width:11px;cursor:col-resize;background:transparent;position:relative;z-index:6;touch-action:none;align-self:stretch}
@@ -162,7 +162,9 @@ body:has(.model-inspector-resizer.drag) .model-inspector-panel,body:has(.model-i
162
162
  .model-module-actions{gap:5px}
163
163
  .model-module-actions button{min-height:28px;padding:3px 9px;font-size:11px}
164
164
  .model-module-actions button.on{background:var(--brand,var(--accent,#60a5fa));border-color:var(--brand,var(--accent,#60a5fa));color:#0f172a}
165
- .model-dock-status{min-width:52px;padding:0 5px;color:var(--mut,var(--muted));font-size:10px;text-align:center;white-space:nowrap}
165
+ /* One line, width-capped: a sentence-long status (a snap refusal) must never widen the actions bar enough to
166
+ wrap the dock (#1738). The full text is in the pill's data-tip and its role=status announcement. */
167
+ .model-dock-status{min-width:52px;max-width:320px;padding:0 5px;color:var(--mut,var(--muted));font-size:10px;text-align:center;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
166
168
 
167
169
  /* Shared model-space dimension and acquisition overlay. Providers supply points; this presentation,
168
170
  including witness lines, ticks, reticle and acquired-target readout, is identical in every module. */