@floless/app 0.128.1 → 0.129.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.
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Pure state-to-guidance seam for the steel canvas disclosure.
3
+ *
4
+ * Keeping the force-open decision here makes every armed left-click tool testable without a Three.js
5
+ * scene. `text` is supplied only for tools whose guidance is wholly owned by the 3D renderer; the
6
+ * older move/add/clip/reference branches still compose their richer, live text in steel-3d-view.js.
7
+ */
8
+ export function canvasToolGuidanceState(state = {}) {
9
+ const forceOpen = !!(
10
+ state.teklaDragActive || state.workPlaneMode || state.addActive || state.transformActive ||
11
+ state.referenceMeasureActive || state.gridLinePickActive || state.clipMode || state.dimensionMode ||
12
+ state.insertMode || state.basePickColumn || state.frameMode || state.framePickStep != null || state.geometryMode
13
+ );
14
+
15
+ let text = null;
16
+ if (state.dimensionMode) {
17
+ text = state.dimensionHasStart
18
+ ? 'Click the second dimension point · Esc to step back'
19
+ : 'Click the first dimension point · Esc to cancel';
20
+ } else if (state.insertMode) {
21
+ text = `Click to place ${state.insertName || 'the detail'} on a member face or the working plane · Esc to cancel`;
22
+ } else if (state.basePickColumn) {
23
+ text = `Click a framing level to trim ${state.basePickColumn}’s base · Esc to cancel`;
24
+ } else if (state.framePickStep != null) {
25
+ text = [
26
+ 'Click the local-frame origin · Esc to cancel',
27
+ 'Click the local-X direction point · Esc to cancel',
28
+ 'Click a point on the local frame’s Y side · Esc to cancel',
29
+ ][state.framePickStep] || 'Pick the next local-frame point · Esc to cancel';
30
+ } else if (state.frameMode) {
31
+ text = 'Drag the local-frame origin or rotation ring to refine the axes · Esc to finish';
32
+ } else if (state.geometryMode === 'el') {
33
+ text = 'Click a target member, segment, or grid line to extend/trim the selection · Esc to cancel';
34
+ } else if (state.geometryMode === 'split') {
35
+ text = 'Click a point on the selected member to split it · Esc to cancel';
36
+ }
37
+
38
+ return { forceOpen, text };
39
+ }
@@ -64,12 +64,17 @@
64
64
  #panelResizer::before{content:"";position:absolute;inset:0 3px;border-radius:2px;transition:background-color .12s}
65
65
  #panelResizer:hover::before,#panelResizer.drag::before{background:var(--brand)}
66
66
  #panelResizer:focus-visible{outline:none} #panelResizer:focus-visible::before{background:var(--brand)}
67
- #panelToggle{position:absolute;right:calc(var(--panelw,240px) - 14px);top:50%;transform:translateY(-50%);z-index:12;width:28px;height:42px;padding:0;display:flex;align-items:center;justify-content:center;background:var(--panel);border-color:var(--line);box-shadow:0 4px 14px rgba(0,0,0,.45);font-size:18px;line-height:1}
67
+ #panelToggle{position:absolute;right:calc(var(--panelw,240px) - 14px);top:50%;transform:translateY(-50%);z-index:12;width:28px;height:42px;padding:0;display:flex;align-items:center;justify-content:center;background:var(--panel);border-color:var(--line);box-shadow:0 4px 14px rgba(0,0,0,.45);line-height:1}
68
+ #panelToggle svg,#canvasStatusToggle svg,#m3dLegendCollapse svg,#m3dLegendLauncher svg{width:16px;height:16px;display:block;fill:none;stroke:currentColor;stroke-width:1.8;stroke-linecap:round;stroke-linejoin:round;transition:transform .15s ease}
68
69
  #panelToggle:hover{border-color:var(--brand)}
69
70
  #panelToggle::before,#m3dLegendCollapse::before,#m3dLegendLauncher::before{content:"";position:absolute;inset:-1px -8px}
70
71
  #panelToggle:focus-visible,#m3dLegendCollapse:focus-visible,#m3dLegendLauncher:focus-visible{outline:2px solid var(--brand);outline-offset:2px}
71
72
  body.panel-collapsed #panel,body.panel-collapsed #panelResizer{display:none}
72
- body.panel-collapsed #panelToggle{right:4px}
73
+ #panelStub{display:none;width:48px;flex:none;flex-direction:column;align-items:center;justify-content:flex-start;padding-top:14px;background:var(--panel);border-left:1px solid var(--line);overflow:hidden}
74
+ #panelStub .vertical-label{writing-mode:vertical-rl;transform:rotate(180deg);font-size:10px;color:var(--mut);text-transform:uppercase;letter-spacing:.2em;user-select:none}
75
+ body.panel-collapsed #panelStub{display:flex}
76
+ body.panel-collapsed #panelToggle{right:16px}
77
+ body.panel-collapsed #panelToggle svg{transform:rotate(180deg)}
73
78
  aside h3{margin:0 0 8px;font-size:12px;color:var(--mut);text-transform:uppercase;letter-spacing:.05em}
74
79
  select,input{background:#0f172a;color:var(--text);border:1px solid #475569;border-radius:6px;padding:6px;width:100%;font:13px system-ui}
75
80
  /* The two control classes the generic rule above actively BREAKS, themed globally so anything added
@@ -389,8 +394,23 @@
389
394
  #moreMenu .msnap-sub input:focus{outline:none;border-color:var(--brand)}
390
395
  #moreMenu .msnap-sub .oghint{flex-basis:100%;color:var(--mut);font-size:11px;line-height:1.4;margin-top:2px} /* nudge shown only when the grid is on but no local frame is set yet */
391
396
  /* Pointer-behaviour bars, bottom-right of the canvas (both views): [ Select filter ] [ Snap ]. Both reuse the brand-fill "on" toolbar language. */
392
- #ptrBars{position:absolute;right:12px;bottom:12px;z-index:8;display:flex;align-items:flex-end;gap:8px}
393
- #ptrBars.s3d{right:104px} /* in 3D, sit just LEFT of the bottom-right world-axis triad (#m3dAxes, right 15 + 78 wide) — same bottom edge (the ViewCube is top-right) */
397
+ /* One bottom dock owns both sides of the canvas chrome. The hint may shrink; Select/Snap never do, so
398
+ the two surfaces cannot overlap at narrower widths. In 3D the whole dock stops before the world-axis
399
+ triad, preserving the old 104px clearance without independently-positioned bars. */
400
+ #bottomDock{position:absolute;left:12px;right:12px;bottom:12px;z-index:8;display:flex;align-items:flex-end;gap:8px;min-width:0;pointer-events:none}
401
+ body.v3d #bottomDock{right:104px}
402
+ #bottomDockLeft{display:flex;align-items:center;gap:8px;flex:1;min-width:0;pointer-events:none}
403
+ #ptrBars{position:static;z-index:auto;display:flex;align-items:flex-end;gap:8px;flex:none;pointer-events:auto}
404
+ #canvasStatus{display:none;align-items:center;gap:0;flex:1;min-width:0;pointer-events:auto}
405
+ #canvasStatus.collapsed{flex:0 0 auto}
406
+ #canvasStatusToggle{width:28px;height:28px;flex:none;padding:0;display:flex;align-items:center;justify-content:center;background:var(--panel);border:1px solid var(--line);border-radius:6px 0 0 6px;color:var(--text);box-shadow:0 2px 8px rgba(0,0,0,.45)}
407
+ #canvasStatus.collapsed #canvasStatusToggle{border-radius:6px}
408
+ #canvasStatusToggle.open svg{transform:rotate(180deg)}
409
+ #canvasStatusToggle:hover{background:#475569;border-color:var(--brand)}
410
+ #canvasStatusToggle:focus-visible{outline:2px solid var(--brand);outline-offset:2px}
411
+ #canvasStatusToggle[aria-disabled=true]{cursor:default;opacity:.65}
412
+ #canvasStatusText{display:flex;align-items:center;height:28px;min-width:0;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;background:var(--panel);color:var(--mut);border:1px solid var(--line);border-left:0;border-radius:0 6px 6px 0;padding:0 12px;font:12px system-ui;box-shadow:0 2px 8px rgba(0,0,0,.45)}
413
+ #canvasStatus.collapsed #canvasStatusText{display:none}
394
414
  #snapBar,#selBar{display:flex;align-items:center;gap:2px;padding:3px;background:var(--panel);border:1px solid var(--line);border-radius:8px;box-shadow:0 4px 14px rgba(0,0,0,.45)}
395
415
  #snapBar .lbl,#selBar .lbl{font-size:10px;text-transform:uppercase;letter-spacing:.07em;color:var(--mut);padding:0 4px;user-select:none;align-self:center}
396
416
  /* Select bar: brand-blue "on"; neutral idle (cyan stays reserved for snapping). A flyout class shows partial (blue outline + dot) when only some of its types are on. */
@@ -917,8 +937,9 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
917
937
  lays out [tab strip][active body]; each tab body is its own scroll container (themed by the global * rule). */
918
938
  #m3dLegend{position:absolute;left:12px;bottom:64px;display:none;flex-direction:column;max-height:min(52vh,calc(100% - var(--m3d-legend-clearance,184px)));min-width:210px;max-width:min(340px,92vw);background:var(--panel);border:1px solid var(--line);border-radius:8px;padding:0;z-index:6;box-shadow:0 4px 14px rgba(0,0,0,.45);font-size:12px} /* the measured clearance tracks however many rows the narrow toolbar wraps onto */
919
939
  #m3dLegendCollapse{position:absolute;right:-14px;top:50%;transform:translateY(-50%);z-index:12;width:28px;height:42px;padding:0;display:flex;align-items:center;justify-content:center;border:1px solid var(--line);border-radius:6px;background:var(--panel);color:var(--text);box-shadow:0 4px 14px rgba(0,0,0,.45);font-size:18px;line-height:1}
940
+ #m3dLegendCollapse svg{transform:rotate(180deg)}
920
941
  #m3dLegendCollapse:hover{color:var(--text);background:#475569;border-color:var(--brand)}
921
- #m3dLegendLauncher{position:absolute;left:4px;bottom:12px;z-index:12;width:28px;height:42px;display:none;align-items:center;justify-content:center;padding:0;background:var(--panel);border:1px solid var(--line);border-radius:6px;box-shadow:0 4px 14px rgba(0,0,0,.45);color:var(--text);font-size:18px;line-height:1}
942
+ #m3dLegendLauncher{position:relative;z-index:12;width:28px;height:42px;flex:none;display:none;align-items:center;justify-content:center;padding:0;background:var(--panel);border:1px solid var(--line);border-radius:6px;box-shadow:0 4px 14px rgba(0,0,0,.45);color:var(--text);font-size:18px;line-height:1;pointer-events:auto}
922
943
  #m3dLegendLauncher:hover{color:var(--text);background:#475569;border-color:var(--brand)}
923
944
  /* Tab strip — the .seg-group segmented look, full-width across the panel top; sticky so it never scrolls away. */
924
945
  #m3dPanelHeader{display:flex;flex:none;align-items:stretch;gap:6px;border-bottom:1px solid var(--line);padding:7px 8px 6px}
@@ -1480,10 +1501,10 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
1480
1501
  <span class=tb-sep></span>
1481
1502
  <!-- Section -->
1482
1503
  <div class=m3dwrap>
1483
- <button id=m3dClip data-tip="Clip planes and boxes — section to see inside a connection">Clip ▾</button>
1504
+ <button id=m3dClip data-tip="Clip planes and boxes — section your model to see inside">Clip ▾</button>
1484
1505
  <div id=m3dClipMenu class=m3dmenu role=menu>
1485
1506
  <button data-clip=plane data-tip="Click a model face to cut the view there (Shift+X)">Add clip plane</button>
1486
- <button data-clip=box data-tip="Section a box around the selection (or whole model) (Shift+B)">Add clip box</button>
1507
+ <button data-clip=box data-tip="Click two corners, then a height, to cut away everything outside (Shift+B)">Add clip box</button>
1487
1508
  <hr>
1488
1509
  <button data-clip=clear class=mdanger data-tip="Remove every clip">Clear all clips</button>
1489
1510
  </div>
@@ -1491,7 +1512,7 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
1491
1512
  <div class=m3dwrap>
1492
1513
  <button id=m3dWp data-tip="Working plane — every 3D pick (Move/Copy, next: drawing) lands on it. Set it from a face, 3 points, or a principal plane.">◇ Plane ▾</button>
1493
1514
  <div id=m3dWpMenu class=m3dmenu role=menu>
1494
- <button data-wp=face data-tip="One click on any member face — the plane lands on it">Pick a face…</button>
1515
+ <button data-wp=face data-tip="One click on any face — yours or a reference model's — the plane lands on it">Pick a face…</button>
1495
1516
  <button data-wp=3pt data-tip="Three snapped points: origin, X direction, a point on the Y side">3 points…</button>
1496
1517
  <hr>
1497
1518
  <div class=mlabel>Principal + offset</div>
@@ -1525,14 +1546,13 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
1525
1546
  a tab that can never hold anything is the same dead chrome the header stat spans are hidden for. -->
1526
1547
  <button class=m3dtab role=tab data-tab=refs aria-selected=false style="display:none" data-tip="Reference models — an architect's or engineer's model overlaid to build against. Never part of your steel.">References</button>
1527
1548
  </div>
1528
- <button type=button id=m3dLegendCollapse aria-label="Collapse 3D panel" aria-controls=m3dLegend aria-expanded=true data-tip="Collapse Objects, Views, and Favourites to the bottom-left corner">‹</button>
1549
+ <button type=button id=m3dLegendCollapse aria-label="Collapse 3D panel" aria-controls=m3dLegend aria-expanded=true data-tip="Collapse Objects, Views, and Favourites to the bottom-left corner"><svg viewBox="0 0 16 16" aria-hidden=true><path d="m6 3 5 5-5 5"/></svg></button>
1529
1550
  </div>
1530
1551
  <div id=m3dLegendBody class="m3dbody on" role=tabpanel aria-label=Objects></div>
1531
1552
  <div id=m3dViewsBody class=m3dbody role=tabpanel aria-label=Views></div>
1532
1553
  <div id=m3dFavBody class=m3dbody role=tabpanel aria-label=Favourites></div>
1533
1554
  <div id=m3dRefsBody class=m3dbody role=tabpanel aria-label="Reference models"></div>
1534
1555
  </div>
1535
- <button type=button id=m3dLegendLauncher aria-label="Expand 3D panel" aria-controls=m3dLegend aria-expanded=false data-tip="Expand Objects, Views, and Favourites">›</button>
1536
1556
  <div id=m3dCube data-tip="Click a face for that view · right-drag to orbit"></div>
1537
1557
  <div id=m3dAxes></div>
1538
1558
  <div id=zoombar>
@@ -1542,8 +1562,14 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
1542
1562
  <span id=zPct>100%</span>
1543
1563
  <button id=zFit data-tip="Zoom to fit (Home)">Fit</button>
1544
1564
  </div>
1545
- <!-- Pointer-behaviour bars (bottom-right): Select (what may be picked) + Snap (what you snap to). -->
1546
- <div id=ptrBars>
1565
+ <!-- One bottom dock: the left disclosure shrinks before the right pointer controls, so they cannot collide. -->
1566
+ <div id=bottomDock>
1567
+ <!-- A direct, non-shrinking dock item: if the canvas narrows, this 28px remains allocated instead
1568
+ of overflowing a zero-width status flex child into Select/Snap. -->
1569
+ <button type=button id=m3dLegendLauncher aria-label="Expand 3D panel" aria-controls=m3dLegend aria-expanded=false data-tip="Expand Objects, Views, and Favourites"><svg viewBox="0 0 16 16" aria-hidden=true><path d="m6 3 5 5-5 5"/></svg></button>
1570
+ <div id=bottomDockLeft></div>
1571
+ <!-- Pointer-behaviour bars (bottom-right): Select (what may be picked) + Snap (what you snap to). -->
1572
+ <div id=ptrBars>
1547
1573
  <!-- Selection filter (Tekla "select switches"): a class off can't be picked by click / area-select / Ctrl+A.
1548
1574
  Members + Connections open a type flyout (All on top). Default: everything on, so nothing is filtered. -->
1549
1575
  <div id=selBar role=group aria-label="Selection filter">
@@ -1567,13 +1593,15 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
1567
1593
  <button data-snap=ext data-tip="Extension snap">┈</button>
1568
1594
  <button data-snap3d aria-label="3D snapping" data-tip="3D snapping — on: snap freely to any point in 3D, at any elevation; off: snap only on the current working level.">3D</button>
1569
1595
  </div>
1596
+ </div>
1570
1597
  </div>
1571
1598
  <div id=selFly role=menu aria-label="Selectable types"></div>
1572
1599
  </div>
1573
1600
  <div id=panelResizer role=separator aria-orientation=vertical aria-label="Resize properties panel" tabindex=0 data-tip="Drag to resize · double-click to reset"></div>
1574
1601
  <span id=connectionTruthStatus class=sr-only role=status aria-live=polite aria-atomic=true></span>
1575
1602
  <aside id=panel></aside>
1576
- <button type=button id=panelToggle aria-label="Collapse properties panel" aria-controls=panel aria-expanded=true data-tip="Collapse properties panel">›</button>
1603
+ <div id=panelStub aria-hidden=true><span class=vertical-label>Inspector</span></div>
1604
+ <button type=button id=panelToggle aria-label="Collapse Inspector" aria-controls=panel aria-expanded=true data-tip="Collapse Inspector"><svg viewBox="0 0 16 16" aria-hidden=true><path d="m6 3 5 5-5 5"/></svg></button>
1577
1605
  </main>
1578
1606
  <!-- (The conntypes / profiles / details <datalist>s that used to sit here are gone: every input that
1579
1607
  bound to them moved to the themed dark combobox below (COMBO_SRC / showCombo), which is what a
@@ -4789,7 +4817,7 @@ function renderGridPanel(p){
4789
4817
  document.getElementById('gridRemoveB').onclick=()=>{editGridTopology(()=>{ModelCmd.setPlanGrid(gridHost(),null);});};
4790
4818
  document.getElementById('gridDoneB').onclick=()=>{setGridMode(false);render();};
4791
4819
  }
4792
- function setGeo(){document.body.classList.toggle('geo',!!geoMode);document.body.classList.toggle('geoel',geoMode==='el');} // geoel = Extend/Trim armed; grid lines are a target ONLY then (not in Split), so their crosshair/highlight keys off geoel, not geo
4820
+ function setGeo(){document.body.classList.toggle('geo',!!geoMode);document.body.classList.toggle('geoel',geoMode==='el');if(view3d&&window.Steel3DView&&window.Steel3DView.refreshStatus)window.Steel3DView.refreshStatus();} // geoel = Extend/Trim armed; grid lines are a target ONLY then (not in Split), so their crosshair/highlight keys off geoel, not geo; 3D guidance follows the editor-owned mode immediately
4793
4821
  // --- repeat last command (AutoCAD/Tekla): when NO tool is active, Space/Enter re-invokes the last command ---
4794
4822
  let lastCmd=null;
4795
4823
  function setLastCmd(label,run){lastCmd={label,run};}
@@ -8025,7 +8053,7 @@ reflectOriginGrid();
8025
8053
  const b=document.getElementById('panelToggle');if(!b)return;
8026
8054
  const KEY='steel:propertiesPanelCollapsed:v1';
8027
8055
  let collapsed=false;try{collapsed=localStorage.getItem(KEY)==='1';}catch(_){}
8028
- const reflect=()=>{document.body.classList.toggle('panel-collapsed',collapsed);b.textContent=collapsed?'‹':'›';b.setAttribute('aria-expanded',String(!collapsed));const label=collapsed?'Open properties panel':'Collapse properties panel';b.setAttribute('aria-label',label);b.dataset.tip=label;};
8056
+ const reflect=()=>{document.body.classList.toggle('panel-collapsed',collapsed);b.setAttribute('aria-expanded',String(!collapsed));const label=collapsed?'Expand Inspector':'Collapse Inspector';b.setAttribute('aria-label',label);b.dataset.tip=label;};
8029
8057
  b.onclick=()=>{collapsed=!collapsed;try{localStorage.setItem(KEY,collapsed?'1':'0');}catch(_){}reflect();b.focus();};
8030
8058
  reflect();
8031
8059
  })();
@@ -9535,6 +9563,17 @@ async function deleteFav(f){const idx=steelFavourites.findIndex(x=>x.id===f.id);
9535
9563
  // item is replaced by a sentence saying what unlocks it — the server refuses the verbs there too, with
9536
9564
  // the same words, so a direct API hit and a click get the same answer.
9537
9565
  const refGeom=new Map(); // id -> { objects, dropped } once the geometry route has answered
9566
+ /**
9567
+ * Is a progressive preview session open, and what is it called?
9568
+ *
9569
+ * TWO VARIABLES, because they answer different questions and only one may be trusted as the claim.
9570
+ * `refPreviewBusy` is the mutual-exclusion flag — the 3D layer holds ONE preview group, so a second
9571
+ * overlapping session would draw into the first's placement. `refPreviewFor` is only the label the
9572
+ * References tab prints, and a reference whose name is missing would make it falsy — which is exactly
9573
+ * how a name-as-claim silently stops excluding anything.
9574
+ */
9575
+ let refPreviewBusy=false;
9576
+ let refPreviewFor=null;
9538
9577
  const refLoading=new Set(); // ids with a geometry fetch in flight — the row shows it, and it dedupes
9539
9578
  const refFailed=new Map(); // id -> why its geometry could not be fetched (see loadReferenceGeometry)
9540
9579
  const refEmpty=new Set(); // ids the reader answered for, with nothing drawable in the answer
@@ -9626,6 +9665,158 @@ function pushReferences(){
9626
9665
  if(refSelectedId&&v.selectReference&&(!v.selectedReference||v.selectedReference()!==refSelectedId))v.selectReference(refSelectedId);
9627
9666
  }
9628
9667
 
9668
+ /**
9669
+ * Open a progress channel and draw the model as AWARE tessellates it (aware-aeco/aware#405).
9670
+ *
9671
+ * WHY A SESSION AND NOT JUST A STREAM: the server mints the id, so there is no ordering problem. Were
9672
+ * the client to choose it, we would have to either subscribe before the server knew it existed or POST
9673
+ * before subscribing and lose the early batches. Here the session is real the moment the POST below
9674
+ * returns, so we subscribe to something that exists and only then start the import.
9675
+ *
9676
+ * EVERYTHING HERE IS OPTIONAL. A server too old to know the route, a blocked EventSource, a filtered
9677
+ * read (which never produces segments) — every one of them returns null or simply never calls back,
9678
+ * and the import proceeds exactly as it did before this existed. It must never be able to fail one.
9679
+ *
9680
+ * Returns `{progressId, close}`; `close()` is idempotent and MUST be called on every exit, because it
9681
+ * is what removes the preview from the scene.
9682
+ */
9683
+ async function refPreviewOpen(placement,displayName){
9684
+ const V=window.Steel3DView;
9685
+ if(!V||!V.appendReferencePreview)return null;
9686
+ // ONE PREVIEW AT A TIME, and the second caller simply goes without.
9687
+ //
9688
+ // The 3D layer holds a SINGLE preview group with one placement matrix, so two overlapping sessions
9689
+ // would append into each other: the second reference's objects drawn at the first's placement, and
9690
+ // whichever finished first calling `clearReferencePreview()` on both. Overlap is reachable — an
9691
+ // insert can start while a cold-cache `loadReferenceGeometry` is still streaming. Refusing the second
9692
+ // is honest and costs it only the preview; its import is untouched and it draws normally at the end.
9693
+ // (Codex review; the alternative — a per-session group — buys nothing a user can perceive, since two
9694
+ // previews at once is not a state worth rendering.)
9695
+ if(refPreviewBusy)return null;
9696
+ // CLAIMED SYNCHRONOUSLY, before the first `await`. Claiming after the POST would leave the guard above
9697
+ // useless: two callers would both read false, both suspend on the fetch, and both proceed — precisely
9698
+ // the overlap the guard exists to prevent.
9699
+ // The CLAIM is taken now; the LABEL is not. `refPreviewFor` drives a sentence asserting that grey
9700
+ // geometry is on the canvas, and at this instant none is — the first batch is seconds away, and on a
9701
+ // FILTERED import none ever arrives, because `wantsSegments` refuses to segment those at all. Setting
9702
+ // it here would point that sentence at an empty canvas for the whole import. It is set on the first
9703
+ // batch instead, where the claim becomes true. (Code + UX review.)
9704
+ refPreviewBusy=true;refPreviewFor=null;
9705
+ const label=displayName||null;
9706
+ const giveUp=()=>{refPreviewBusy=false;refPreviewFor=null;return null;};
9707
+ let sessionId=null;
9708
+ try{
9709
+ const res=await fetch(refApi('/progress'),{method:'POST',headers:{'content-type':'application/json'}});
9710
+ const d=await res.json().catch(()=>({}));
9711
+ if(!res.ok||!d.ok||!d.sessionId)return giveUp();
9712
+ sessionId=d.sessionId;
9713
+ }catch(e){return giveUp();} // an unreachable/older server gets today's behaviour
9714
+ let es=null,done=false,painted=0;
9715
+ // THE NOTE IS BORROWED, NOT OWNED, so it is put back. `#riProgNote` carries authored copy ("You can
9716
+ // close this — FloLess will keep importing this model.") that nothing else ever rewrites; without a
9717
+ // restore, the first preview replaces that affordance for the rest of the page's life, and a preview
9718
+ // run from `loadReferenceGeometry` — which has no modal open — leaves a stale count behind that the
9719
+ // NEXT import shows, about a different model. (Silent-failure review.)
9720
+ const noteEl=document.getElementById('riProgNote');
9721
+ const noteWas=noteEl?noteEl.textContent:null;
9722
+ const close=()=>{
9723
+ if(done)return;done=true;
9724
+ try{es&&es.close();}catch(e){}
9725
+ // CLEARED BEFORE the authoritative geometry is built by `pushReferences`, never after, so peak GPU
9726
+ // is the larger of preview and real rather than their sum.
9727
+ try{V.clearReferencePreview&&V.clearReferencePreview();}catch(e){console.error('[reference] preview dispose failed',e);}
9728
+ // Put the borrowed note back exactly as it was, so the next import starts from the authored copy.
9729
+ if(noteEl&&noteWas!==null)noteEl.textContent=noteWas;
9730
+ refPreviewBusy=false;refPreviewFor=null;
9731
+ // The panel is showing preview copy that is no longer true; repaint it. Guarded because `close()`
9732
+ // also runs on paths where the tab was never the references one.
9733
+ try{if(legendTab==='refs')renderRefsTab();}catch(e){}
9734
+ };
9735
+ try{
9736
+ es=new EventSource(refApi('/progress/'+encodeURIComponent(sessionId)));
9737
+ es.onmessage=(ev)=>{
9738
+ if(done)return;
9739
+ let m=null;try{m=JSON.parse(ev.data);}catch(e){return;}
9740
+ if(!m)return;
9741
+ if(m.type==='stopped'){
9742
+ // TERMINAL. The server says so for a crossed cap, a suppressed channel, an overflow or the import
9743
+ // answering. The geometry stays on screen until `close()`, which the caller runs the moment it has
9744
+ // the real thing; only the STREAM ends here.
9745
+ //
9746
+ // AND THE LINE MUST BE CORRECTED, which this branch previously did not do. It closed the stream and
9747
+ // returned, leaving "…the rest are still being prepared" frozen on screen — a sentence that becomes
9748
+ // FALSE the instant the channel stops, because the rest of the preview is never coming even though
9749
+ // the import genuinely is still running. The comment here used to describe that exact failure as
9750
+ // the thing to avoid while the code committed it. (UX review.)
9751
+ try{es.close();}catch(e){}
9752
+ // ONLY WHEN DELIVERY STOPPED EARLY, which is what the reason distinguishes. A normal finish also
9753
+ // ends this channel — the pump is aborted the moment the read returns — and rewriting the line
9754
+ // then would flash "the live preview stopped there, but the import is still running" on EVERY
9755
+ // successful import, a second before the modal closes. True for that second and useless: the
9756
+ // sentence exists for the case where the preview stops and the wait genuinely continues.
9757
+ // INVERTED, so a reason nobody listed here is SAFE rather than silent. The first cut named the
9758
+ // three early stops explicitly — and omitted `error`, which is what a failed segment transfer
9759
+ // emits and so the likeliest early stop of all, plus `expired`. Those fell through to "say
9760
+ // nothing", freezing "…the rest are still being prepared" on screen for the remaining minutes of
9761
+ // the read: exactly the false sentence this branch was rewritten to prevent, reintroduced by an
9762
+ // allowlist. Only the two reasons that mean THE READ ITSELF ended stay quiet; anything else is an
9763
+ // early stop until proven otherwise. (Silent-failure review.)
9764
+ if(m.reason!=='aborted'&&m.reason!=='done')refPreviewStopped(painted);
9765
+ return;
9766
+ }
9767
+ if(m.type!=='batch'||!Array.isArray(m.objects))return;
9768
+ try{
9769
+ V.appendReferencePreview(m.objects,placement||null);
9770
+ // Once, on the first batch — a model at real site coordinates would otherwise preview entirely
9771
+ // off-screen, which for this feature is indistinguishable from it not working.
9772
+ V.frameReferencePreview&&V.frameReferencePreview();
9773
+ const first=painted===0;
9774
+ painted=m.painted||painted;
9775
+ refPreviewNote(painted);
9776
+ // The label goes up with the FIRST batch — the moment its sentence becomes true — and the panel is
9777
+ // repainted once, then never again per batch, which would be pure churn.
9778
+ if(first){refPreviewFor=label;if(legendTab==='refs')renderRefsTab();}
9779
+ }catch(e){console.error('[reference] preview batch failed',e);}
9780
+ };
9781
+ // An EventSource error is ordinary here (the server ends the stream when the import answers) and
9782
+ // must stay silent: the import owns the outcome and is about to report it.
9783
+ es.onerror=()=>{};
9784
+ }catch(e){return {progressId:sessionId,close};}
9785
+ return {progressId:sessionId,close};
9786
+ }
9787
+
9788
+ /**
9789
+ * Say what the preview is showing, in the modal's own progress line.
9790
+ *
9791
+ * A count rather than a bar: the total is not known until the walk ends (that is the whole reason this
9792
+ * feature exists), so a percentage would be invented. "Showing 1,300 objects so far" is true.
9793
+ */
9794
+ function refPreviewNote(painted){
9795
+ const el=document.getElementById('riProgNote');
9796
+ if(!el||!painted)return;
9797
+ el.textContent='Showing '+painted.toLocaleString('en-US')+' object'+(painted===1?'':'s')+' so far — the rest are still being prepared.';
9798
+ }
9799
+
9800
+ /**
9801
+ * The preview stream has ended while the import continues — say so, precisely.
9802
+ *
9803
+ * THE SENTENCE MUST STOP PROMISING. "…the rest are still being prepared" is true only while batches
9804
+ * are still coming; once the channel is done it describes something that will never happen, on a modal
9805
+ * that is otherwise scrupulous about claiming only what it can back up. The import is genuinely still
9806
+ * running, so the copy has to separate the two: the PREVIEW stopped, the IMPORT did not.
9807
+ *
9808
+ * Two cases, because they are different facts. Some geometry arrived and then delivery ended (the cap,
9809
+ * a suppressed channel, an overflow) — name what is on screen and that it stops there. Or none ever
9810
+ * arrived, in which case saying "showing 0 objects" would be worse than saying nothing about a count.
9811
+ */
9812
+ function refPreviewStopped(painted){
9813
+ const el=document.getElementById('riProgNote');
9814
+ if(!el)return;
9815
+ el.textContent=painted>0
9816
+ ? 'Showing '+painted.toLocaleString('en-US')+' object'+(painted===1?'':'s')+' — the live preview stopped there, but the import is still running.'
9817
+ : "A live preview isn't available for this import — it's still converting in the background.";
9818
+ }
9819
+
9629
9820
  /**
9630
9821
  * Fetch one reference's geometry.
9631
9822
  *
@@ -9640,11 +9831,17 @@ function pushReferences(){
9640
9831
  async function loadReferenceGeometry(id,opts){
9641
9832
  if(refGeom.has(id)||refLoading.has(id))return;
9642
9833
  refLoading.add(id);if(legendTab==='refs')renderRefsTab();
9834
+ // THE COLD-CACHE PATH IS WHERE THIS MATTERS MOST. The geometry cache is reserved-internal, so every
9835
+ // imported or duplicated project arrives with nothing cached and rebuilds here — someone opening a
9836
+ // shared project waits the whole read before a single triangle appears. The preview uses the stored
9837
+ // placement so it lands where the finished reference will.
9838
+ const pv=await refPreviewOpen((refById(id)||{}).placement||null,(refById(id)||{}).name||null).catch(()=>null);
9643
9839
  try{
9644
9840
  // INSIDE the suffix, not appended after. `refApi` already adds `?project=` and picks its own
9645
9841
  // separator from whether the suffix carries a `?` — appending afterwards produced a second `?`
9646
9842
  // and a 400, which is exactly what the browser pass caught.
9647
- const res=await fetch(refApi('/'+encodeURIComponent(id)+'/geometry'+((opts&&opts.rebuild)?'?rebuild=1':'')));
9843
+ const q=[(opts&&opts.rebuild)?'rebuild=1':'',pv?'progressId='+encodeURIComponent(pv.progressId):''].filter(Boolean).join('&');
9844
+ const res=await fetch(refApi('/'+encodeURIComponent(id)+'/geometry'+(q?'?'+q:'')));
9648
9845
  const d=await res.json().catch(()=>({}));
9649
9846
  // A LATE RESPONSE FOR A REMOVED REFERENCE IS DROPPED. These bodies can be hundreds of megabytes, and
9650
9847
  // repopulating `refGeom` under an id the contract no longer holds leaks all of it while making the
@@ -9686,7 +9883,11 @@ async function loadReferenceGeometry(id,opts){
9686
9883
  // here destroys an in-progress edit: a member selected, a value half-typed and not yet blurred, and any
9687
9884
  // reference finishing its fetch removes the focused input and restores the old value. `loadAllReferences`
9688
9885
  // fires one of these per uncached reference at boot, so it is not a rare race. (Both halves: Codex.)
9689
- finally{refLoading.delete(id);pushReferences();if(legendTab==='refs')renderRefsTab();if(refSelectedObjIdx!==null)panel();}
9886
+ // `pv.close()` FIRST, so the preview is gone before `pushReferences()` builds the authoritative
9887
+ // meshes — the two must never be in the scene together, and disposing first is what keeps peak GPU
9888
+ // at the larger of them rather than their sum. It runs on every exit, including the arms above that
9889
+ // return early for a removed reference.
9890
+ finally{if(pv)pv.close();refLoading.delete(id);pushReferences();if(legendTab==='refs')renderRefsTab();if(refSelectedObjIdx!==null)panel();}
9690
9891
  }
9691
9892
  /** Pull every reference's geometry once the 3D view is up. Sequential: one AWARE run at a time anyway. */
9692
9893
  async function loadAllReferences(){for(const r of refList())await loadReferenceGeometry(r.id);}
@@ -9974,7 +10175,14 @@ function renderRefsTab(){const host=document.getElementById('m3dRefsBody');if(!h
9974
10175
 
9975
10176
  const all=refList();
9976
10177
  if(!all.length){const e=Object.assign(document.createElement('div'),{className:'refempty'});
9977
- e.textContent='No reference models yet — add somebody else’s IFC to see it beside your steel and snap to it. It never enters your BOM, an export, or the lock.';
10178
+ // A PREVIEW ON THE CANVAS MAKES THE PERMANENT COPY READ AS A CONTRADICTION. "No reference models yet"
10179
+ // is literally true while an import is still running — nothing is committed, which is the whole point
10180
+ // of the preview being kept out of `refGeom` and `xrefById` — but a user looking at a grey building on
10181
+ // screen is being told it is not there. Both facts are said instead: it is a preview, and it becomes a
10182
+ // row when the import finishes. (UX review.)
10183
+ e.textContent=refPreviewFor
10184
+ ? 'Reading “'+refPreviewFor+'” — the grey model on the canvas is a live preview. It will appear here as a reference once the import finishes.'
10185
+ : 'No reference models yet — add somebody else’s IFC to see it beside your steel and snap to it. It never enters your BOM, an export, or the lock.';
9978
10186
  host.appendChild(e);return;}
9979
10187
  for(const r of all){host.appendChild(buildRefRow(r));if(r.id===refSelectedId)host.appendChild(buildRefDetail(r));}
9980
10188
  // …and put the caret back where it was. Done here rather than in buildRefMeasureCard because focus only
@@ -11577,6 +11785,10 @@ function adoptReferenceWrite(etag){if(!etag)return;const prev=serverEtag;serverE
11577
11785
  const riOriginShift=takeOrigin&&riProbeCentre?riProbeCentre.map((v,i)=>riNative[i]-v):null;
11578
11786
  riStage('prog');ri$('riTitle').textContent='Converting into 3D viewer geometry';ri$('riProgNote').style.display='block';ri$('riCancel').textContent='Continue in background';riProg('Converting “'+riName+'” into 3D viewer geometry…','AWARE is tessellating objects and preparing the viewer file. Whole-building models can take several minutes; FloLess will add the reference when that completes.');
11579
11787
  let mid=null;
11788
+ // OPENED BEFORE THE POST, which is the whole ordering requirement: batches announced early would
11789
+ // otherwise be published to a session nobody had attached to yet. Null whenever a preview is not
11790
+ // available — an older server, a blocked EventSource, or a filtered read, which never segments.
11791
+ const riPreview=await refPreviewOpen(takeOrigin&&riOriginShift?{origin:riOriginShift}:null,riName).catch(()=>null);
11580
11792
  try{
11581
11793
  mid=newMutationId();riMutationId=mid;claimMutation(mid);
11582
11794
  const res=await fetch(refApi(''),{method:'POST',signal,headers:{'content-type':'application/json','x-floless-mutation-id':mid},
@@ -11588,7 +11800,10 @@ function adoptReferenceWrite(etag){if(!etag)return;const prev=serverEtag;serverE
11588
11800
  // part of what the user decided in this modal, so it belongs inside the point of no return
11589
11801
  // rather than in a PUT afterwards. `undefined` here means the whole file — never an empty list,
11590
11802
  // which the reader would read as "select nothing".
11591
- body:JSON.stringify({sha:riSha,name:riName,...(riFilterBody?{filter:riFilterBody}:{}),...(takeOrigin&&riOriginShift?{placement:{origin:riOriginShift}}:{})})});
11803
+ // `progressId` binds this import to the channel opened above. The server refuses a session
11804
+ // belonging to another app or project, and ignores an absent one — so an older server, or a
11805
+ // request without it, is simply the behaviour that shipped before this feature.
11806
+ body:JSON.stringify({sha:riSha,name:riName,...(riPreview?{progressId:riPreview.progressId}:{}),...(riFilterBody?{filter:riFilterBody}:{}),...(takeOrigin&&riOriginShift?{placement:{origin:riOriginShift}}:{})})});
11592
11807
  d=await res.json().catch(()=>({}));
11593
11808
  if(mine!==riRun){
11594
11809
  // Cancelled while this was in flight. The server refuses to commit for a client that has gone
@@ -11631,7 +11846,13 @@ function adoptReferenceWrite(etag){if(!etag)return;const prev=serverEtag;serverE
11631
11846
  if(mine!==riRun||(e&&e.name==='AbortError')){if(mid)releaseMutation(mid);if(riMutationId===mid)riMutationId=null;return;}
11632
11847
  if(riBackgrounded)toast('Reference import failed — the model could not be added.');
11633
11848
  riClearSoft();riStage('drop');riErr('Could not add that reference.');console.error('[reference] insert failed',e);return;}
11634
- finally{if(mine===riRun){riBusy=false;riAbort=null;riBackgrounded=false;ri$('riCancel').textContent='Cancel';}if(riMutationId===mid)riMutationId=null;}
11849
+ finally{
11850
+ // EVERY EXIT — committed, refused, cancelled, thrown. The preview is standing in for a model
11851
+ // that has now either arrived or been refused, so leaving it on screen would show geometry
11852
+ // beside the real thing, or geometry for an import that was rejected. This runs BEFORE
11853
+ // `pushReferences()` below builds the authoritative meshes, so the two never coexist.
11854
+ if(riPreview)riPreview.close();
11855
+ if(mine===riRun){riBusy=false;riAbort=null;riBackgrounded=false;ri$('riCancel').textContent='Cancel';}if(riMutationId===mid)riMutationId=null;}
11635
11856
  // ── PAST THE POINT OF NO RETURN. Everything above is the transaction; everything below is showing
11636
11857
  // it. They were one try, and a throw in the presentation half ran riErr() on a modal riClose() had
11637
11858
  // already hidden — so the user saw NOTHING while the reference was committed and on disk, and the