@floless/app 0.130.1 → 0.131.1

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.
@@ -147,6 +147,8 @@ let dimDraft3d = null; // { a:[x,y,z] } once the first point is place
147
147
  let dimLastAlt = false; // last-seen Alt state (the hover rAF rebuilds a synthetic event)
148
148
  let hoverTeklaMod = false; // last-seen Ctrl+Shift state — arms the drag-out-to-Tekla cursor hint
149
149
  let pointerOverCanvas = false; // is the cursor actually on the 3D canvas right now (lastHoverXY outlives the pointer leaving)
150
+ let inputActive = true; // does this view own the keyboard? The editor sets it false when the 2D pane
151
+ // is the active one in a split — see setInputActive.
150
152
  let dims3dGroup = null; // THREE.Group of placed-dim lines (+ the live preview line)
151
153
  let dimPreviewLine = null; // reused preview line (point 1 → cursor)
152
154
  let dimLabelHost = null; // fixed-position container for label overlays
@@ -268,7 +270,7 @@ function init(canvas, theApi) {
268
270
  * THE FOUR MODEL-GLUED LABEL HOSTS SIT UNDER THE 3D CHROME, and the numbers below are the whole rule.
269
271
  *
270
272
  * Each is `position:fixed` on `<body>` and projected per frame, so it is painted in the ROOT stacking
271
- * context (`#stagewrap` and `<main>` are `position:relative; z-index:auto`, which creates none) — it
273
+ * context (`#pane3d`, `#stagewrap` and `<main>` are `position:relative; z-index:auto`, which creates none) — it
272
274
  * competes directly with the panels. They shipped at 56/57, above every panel, and a chip landing over
273
275
  * the expanded Objects panel drew ON TOP of it: unreadable itself, and hiding a control the user was
274
276
  * reading. Reported against the 3D property labels, but it was never theirs — the mark/id, dimension
@@ -1254,6 +1256,151 @@ function clearReferencePreview() {
1254
1256
  }
1255
1257
  }
1256
1258
 
1259
+ // ── GHOSTS: where an object USED to be (#734, design §6.4) ──
1260
+ //
1261
+ // A `removed` row in the change list names an object that is in the previous version of a reference and
1262
+ // not in the new one. These are its shapes, re-read from that previous file, drawn where it stood.
1263
+ //
1264
+ // A SIBLING OF `xrefGroup`, NEVER A CHILD, for exactly the reason the preview above is one — and here the
1265
+ // requirement is sharper, because "never snappable and never counted in bounds" is a promise this feature
1266
+ // makes explicitly. Every reference-interaction entry point reads that group or `xrefById` directly:
1267
+ // `pickReferenceAt` raycasts `xrefGroup.children`, `referenceCandidates` and `referenceBounds` walk
1268
+ // `xrefById`, and `visibleWorldBox` — what Fit, Home, the ViewCube and the work-area box all measure —
1269
+ // unions `sceneBox` with `xrefGroup.children` and nothing else. Parented outside both, a ghost cannot be
1270
+ // picked, cannot be snapped to and cannot drag the Fit box out to a building that is no longer there. A
1271
+ // rule someone has to remember would not survive; this is structural.
1272
+ //
1273
+ // ONE MATERIAL, in the `removed` chip's own ink, so the shape on the canvas and the badge in the list are
1274
+ // visibly the same fact. Transparent and `depthWrite:false` behind the model, like every other borrowed
1275
+ // geometry here — a deletion must never occlude the steel you are checking it against.
1276
+
1277
+ /**
1278
+ * `--err` AS THE DARK THEME DRAWS IT (#fca5a5) — the same value the change list's `removed` chip takes,
1279
+ * so the shape on the canvas and the badge in the list read as one fact.
1280
+ *
1281
+ * A COPY, AND IT DOES NOT FOLLOW `[data-theme=light]`, which is correct rather than an oversight twice
1282
+ * over: WebGL cannot read a CSS custom property, and this canvas is dark in BOTH themes anyway —
1283
+ * `scene.background` is a fixed 0x020817 and `#stage3d` is in the light theme's re-anchor list, which
1284
+ * restates the dark tokens for exactly this subtree. On light, the chip moves to `--err`'s light stop
1285
+ * and the ghost stays where the canvas it sits on stayed.
1286
+ */
1287
+ const XREF_GHOST_COLOR = 0xfca5a5;
1288
+ const XREF_GHOST_OPACITY = 0.3;
1289
+ let xrefGhostGroup = null; // the ghosts' meshes, or null when none are drawn
1290
+ let xrefGhostMat = null; // its ONE material — ghosts are uniform, so one is enough
1291
+ let xrefGhostRef = null; // which reference these belong to, so a stale set cannot outlive it
1292
+ const xrefGhostById = new Map(); // globalId -> mesh, so one ghost can be framed
1293
+
1294
+ /**
1295
+ * Draw ghosts for one reference, appending to whatever is already there.
1296
+ *
1297
+ * APPENDS rather than rebuilds, because they arrive lazily — the panel asks only for the removed rows a
1298
+ * user has actually scrolled to, so a revision with 3,000 deletions never tessellates 3,000 objects.
1299
+ * A different `refId` clears first: ghosts belong to one reference's history, and two sets overlaid would
1300
+ * be two buildings' deletions with nothing on screen saying which is which.
1301
+ *
1302
+ * `placement` is the reference's own, applied to the group exactly as the real one's is, so a ghost sits
1303
+ * where the object stood rather than at the world origin.
1304
+ */
1305
+ function setReferenceGhosts(refId, objects, placement) {
1306
+ // THE OWNERSHIP CHECK COMES FIRST, before the empty-list guard. The other order leaves the PREVIOUS
1307
+ // reference's ghosts standing — under the previous reference's placement matrix — whenever a
1308
+ // different reference asks with nothing to draw. Not reachable from today's single caller, which
1309
+ // guards on `objects.length` itself, and that is exactly what makes it worth closing: this branch is
1310
+ // the same latent seam mismatch review already caught once on this change. (Review.)
1311
+ if (xrefGhostRef !== null && xrefGhostRef !== refId) clearReferenceGhosts();
1312
+ if (!scene || !Array.isArray(objects) || !objects.length) return { drawn: 0, skipped: 0 };
1313
+ if (!xrefGhostGroup) {
1314
+ xrefGhostGroup = new THREE.Group();
1315
+ xrefGhostGroup.renderOrder = -1;
1316
+ xrefGhostGroup.applyMatrix4(xrefMatrix(placement));
1317
+ scene.add(xrefGhostGroup);
1318
+ xrefGhostMat = newXrefMaterial(XREF_GHOST_COLOR, XREF_GHOST_OPACITY);
1319
+ xrefGhostMat.opacity = XREF_GHOST_OPACITY;
1320
+ xrefGhostRef = refId;
1321
+ }
1322
+ // COUNTED PER CALL, NOT CUMULATIVELY, and both halves are returned. `xrefGhostById.size` is a running
1323
+ // total, so a caller reading it could not tell "I drew nothing" from "I drew nothing NEW" — and the
1324
+ // two skips below are silent by construction: an object whose tessellation came back empty, and one
1325
+ // with no `globalId` (which gets a mesh but can never be framed, because framing is by id). The
1326
+ // caller reconciles this against what it asked for, so a shortfall is stated rather than looking
1327
+ // like a smaller deletion. (Review.)
1328
+ let drawn = 0, skipped = 0;
1329
+ for (const o of objects) {
1330
+ if (!o || !Array.isArray(o.positions) || !o.positions.length) { skipped++; continue; }
1331
+ const gid = (o && typeof o.globalId === 'string' && o.globalId) ? o.globalId : null;
1332
+ if (!gid) { skipped++; continue; } // unframeable and uncountable — drawing it would be a shape nothing can reach
1333
+ // ALREADY DRAWN IS NOT DRAWN AGAIN. The panel can legitimately ask for a row twice — scroll away and
1334
+ // back — and a second mesh at the same coordinates doubles the fill and leaves the first unreachable.
1335
+ if (xrefGhostById.has(gid)) continue;
1336
+ const g = new THREE.BufferGeometry();
1337
+ g.setAttribute('position', new THREE.Float32BufferAttribute(o.positions, 3));
1338
+ if (Array.isArray(o.indices) && o.indices.length) g.setIndex(o.indices);
1339
+ g.computeVertexNormals();
1340
+ const mesh = new THREE.Mesh(g, xrefGhostMat);
1341
+ // NOT PICKABLE EVEN IF SOMETHING EVER RAYCASTS THE WHOLE SCENE. The parenting above is what makes
1342
+ // this true today; this is the belt to that pair of braces, and it costs one field.
1343
+ mesh.raycast = () => {};
1344
+ mesh.userData.ghost = true;
1345
+ mesh.userData.globalId = gid;
1346
+ xrefGhostById.set(gid, mesh);
1347
+ xrefGhostGroup.add(mesh);
1348
+ drawn++;
1349
+ }
1350
+ return { drawn, skipped };
1351
+ }
1352
+
1353
+ /**
1354
+ * What the ghosts are ACTUALLY painted in, read off the material the renderer will use.
1355
+ *
1356
+ * The same reason `referenceProbe` exists: a screenshot cannot distinguish the authored colour from a
1357
+ * plausible one, and 30% alpha over a dark canvas makes every pale ink look alike. The rendered value is
1358
+ * the only thing entitled to answer "is this drawn in the `removed` chip's ink". `parent` is here because
1359
+ * the whole promise of this layer — never snappable, never in the Fit box — rests on WHERE the group is
1360
+ * parented, and that is otherwise unobservable from outside.
1361
+ */
1362
+ function referenceGhostPaint() {
1363
+ if (!xrefGhostGroup || !xrefGhostMat) return null;
1364
+ return {
1365
+ color: `#${xrefGhostMat.color.getHexString()}`,
1366
+ opacity: xrefGhostMat.opacity,
1367
+ meshes: xrefGhostGroup.children.length,
1368
+ /** 'scene' is correct; 'xref' would mean the ghosts had become snappable, pickable and framed. */
1369
+ parent: xrefGhostGroup.parent === scene ? 'scene' : xrefGhostGroup.parent === xrefGroup ? 'xref' : 'other',
1370
+ };
1371
+ }
1372
+
1373
+ /** Frame one ghost — what a click on a `removed` row asks for, since there is nothing to select. */
1374
+ function frameReferenceGhost(globalId) {
1375
+ const mesh = xrefGhostById.get(globalId);
1376
+ if (!mesh) return false;
1377
+ const box = new THREE.Box3().setFromObject(mesh);
1378
+ if (box.isEmpty()) return false;
1379
+ fitCamera(box);
1380
+ return true;
1381
+ }
1382
+
1383
+ /**
1384
+ * Remove every ghost and free what they hold. Idempotent — every terminal path in the panel calls it.
1385
+ *
1386
+ * The RESET IS IN `finally` for the reason the preview's is: a half-disposed group that stays referenced
1387
+ * is worse than a leak, because the next `setReferenceGhosts` would see a live group, skip its init, and
1388
+ * append a new reference's deletions into the old one's placement matrix.
1389
+ */
1390
+ function clearReferenceGhosts() {
1391
+ if (!xrefGhostGroup) { xrefGhostById.clear(); xrefGhostRef = null; return; }
1392
+ try {
1393
+ xrefGhostGroup.traverse((o) => { o.geometry?.dispose?.(); });
1394
+ scene?.remove(xrefGhostGroup);
1395
+ xrefGhostMat?.dispose?.();
1396
+ } finally {
1397
+ xrefGhostGroup = null;
1398
+ xrefGhostMat = null;
1399
+ xrefGhostRef = null;
1400
+ xrefGhostById.clear();
1401
+ }
1402
+ }
1403
+
1257
1404
  /** Unique world points for snapping, quantised so a tessellated corner is one target and not thirty. */
1258
1405
  function xrefSnapPoints(objects) {
1259
1406
  const seen = new Set(); const out = [];
@@ -1688,6 +1835,19 @@ function setReferencePlacement(id, placement) {
1688
1835
  entry.group.position.set(0, 0, 0); entry.group.quaternion.identity(); entry.group.scale.set(1, 1, 1);
1689
1836
  entry.group.applyMatrix4(xrefMatrix(placement));
1690
1837
  entry.group.updateMatrixWorld(true);
1838
+ // THE GHOSTS MOVE WITH THE REFERENCE THEY BELONG TO. Their group takes the same matrix at creation
1839
+ // and would otherwise keep it forever — so Scale, "move it next to your model", or the heuristic's
1840
+ // fix button would leave red shapes standing at coordinates the removed objects never occupied,
1841
+ // which is precisely the "geometry asserting something nothing says" the ghost layer's own header
1842
+ // argues against. Newly REACHABLE because the change list is deliberately non-modal: the panel
1843
+ // floats over a live canvas, so a placement can change while ghosts are on screen. Batches that
1844
+ // arrive afterwards then land in the corrected matrix too, so one layer cannot hold two placements.
1845
+ if (xrefGhostGroup && xrefGhostRef === id) {
1846
+ xrefGhostGroup.matrix.identity();
1847
+ xrefGhostGroup.position.set(0, 0, 0); xrefGhostGroup.quaternion.identity(); xrefGhostGroup.scale.set(1, 1, 1);
1848
+ xrefGhostGroup.applyMatrix4(xrefMatrix(placement));
1849
+ xrefGhostGroup.updateMatrixWorld(true);
1850
+ }
1691
1851
  invalidateClipFloor(); // this reference just MOVED, so any floor measured from where it used to be is now wrong
1692
1852
  if (refMeasure3d && refMeasure3d.refId === id) {
1693
1853
  // The cache holds points BAKED through the old matrix, so every one of them now points at where
@@ -1977,6 +2137,28 @@ function frameReference(id) {
1977
2137
  return true;
1978
2138
  }
1979
2139
 
2140
+ /**
2141
+ * Frame ONE object inside a reference (#734, the change list's row click).
2142
+ *
2143
+ * `selectReferenceObject` lights an object; it does not move the camera, which is right for Ctrl+click —
2144
+ * you are already looking at the thing you clicked. It is wrong for a row in a list: "56 changed" is a
2145
+ * list of objects the user has NOT found yet, and highlighting one somewhere off-screen answers nothing.
2146
+ *
2147
+ * SEPARATE FROM THE SELECTION rather than folded into it, so the canvas gesture keeps its behaviour
2148
+ * exactly: two callers, two questions, and the panel is the only one that asks the camera to move.
2149
+ * Returns false when the index does not name a mesh — the same refusal, for the same reason, as
2150
+ * `selectReferenceObject`: quietly framing something else is worse than not moving.
2151
+ */
2152
+ function frameReferenceObject(refId, index) {
2153
+ const entry = xrefById.get(refId);
2154
+ const mesh = entry && Number.isInteger(index) && index >= 0 ? entry.group.children[index] : null;
2155
+ if (!mesh || !mesh.isMesh) return false;
2156
+ const box = new THREE.Box3().setFromObject(mesh);
2157
+ if (box.isEmpty()) return false;
2158
+ fitCamera(box);
2159
+ return true;
2160
+ }
2161
+
1980
2162
  /**
1981
2163
  * The reference snap candidates for a drag, in the shape `snapPoint` consumes.
1982
2164
  *
@@ -3605,7 +3787,11 @@ function panView(dx, dy) { // dx/dy in "steps" along the camera's screen right/u
3605
3787
  const ARROWS = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, 1], ArrowDown: [0, -1] };
3606
3788
  const VIEW_KEYS = { t: 'top', f: 'front', r: 'right', b: 'back', l: 'left' }; // single-key ortho views, mirrors the ViewCube + AWARE viewer-3d
3607
3789
  function onKey(e) {
3608
- if (!renderer || !canvasEl || canvasEl.style.display === 'none') return; // only when 3D is active
3790
+ // NOT "is the canvas visible" — that predicate was written when 2D and 3D were mutually exclusive,
3791
+ // where visible and active were the same fact. In a split both canvases are on screen at once, and a
3792
+ // visibility test would let an arrow key orbit the model while the user is dimensioning the plan, and
3793
+ // let Escape in the 2D pane cancel an in-flight clip-handle drag in here. The editor owns the answer.
3794
+ if (!renderer || !canvasEl || canvasEl.style.display === 'none' || !inputActive) return;
3609
3795
  const ae = document.activeElement; if (ae && /^(INPUT|SELECT|TEXTAREA)$/.test(ae.tagName)) return;
3610
3796
  // Esc mid-drag-out → nothing is sent, even if the pointer is then released over Tekla: ending the
3611
3797
  // gesture here leaves the release with no drag to complete. (A native HTML5 drag never delivered
@@ -6369,6 +6555,9 @@ function hide() {
6369
6555
  endTeklaDrag(); // and a live drag-out to Tekla — a stranded one would leave its badge on screen and swallow every later pointer move
6370
6556
  if (canvasEl) canvasEl.style.display = 'none'; if (hoverChipShell) hoverChipShell.style.display = 'none'; else if (hoverChip) hoverChip.style.display = 'none'; if (rafId) { cancelAnimationFrame(rafId); rafId = null; }
6371
6557
  }
6558
+ // The editor's active-pane state, pushed in. Defaults true so every existing caller — and vector-3d.html,
6559
+ // which has no split and never calls this — keeps today's behaviour with no change.
6560
+ function setInputActive(on) { inputActive = on !== false; }
6372
6561
  function isReady() { return built; }
6373
6562
 
6374
6563
  function dispose() {
@@ -6420,6 +6609,9 @@ function dispose() {
6420
6609
  // The reference layer owns real GPU buffers — a whole tessellated building's worth. Leaving them
6421
6610
  // attached to a torn-down scene is the kind of leak that only shows up after the fifth 2D↔3D switch.
6422
6611
  if (xrefGroup) { disposeReferenceMaterials(); xrefGroup.traverse((o) => { o.geometry?.dispose?.(); }); if (scene) scene.remove(xrefGroup); }
6612
+ // The ghost layer owns real buffers too, and it is a SIBLING of that group rather than a child — which
6613
+ // is the whole point of it, and also the reason the sweep above cannot reach it.
6614
+ clearReferenceGhosts();
6423
6615
  xrefGroup = null; xrefById.clear(); xrefSelected = null;
6424
6616
  xrefSubSelected = null; xrefSubMesh = null; xrefSubMats = null;
6425
6617
  clearStructGrid();
@@ -6563,7 +6755,7 @@ function gridSegmentsScreen() {
6563
6755
  }
6564
6756
  function gridBubblesScreen(){if(!gridLabelGroup)return [];const rect=canvasEl.getBoundingClientRect();return gridLabelGroup.children.filter(s=>s.visible&&s.userData.gridId).map(s=>{const p=s.getWorldPosition(new THREE.Vector3()).project(camera);return {id:s.userData.gridId,x:rect.left+(p.x*.5+.5)*rect.width,y:rect.top+(-p.y*.5+.5)*rect.height};});}
6565
6757
  window.Steel3DView = {
6566
- init, show, hide, rebuild, setSelection, setGridSelection, isReady, dispose,
6758
+ init, show, hide, setInputActive, rebuild, setSelection, setGridSelection, isReady, dispose,
6567
6759
  setProjection, projection, setDisplayMode, mode: () => displayMode, frameAll, frameSelection, applyView,
6568
6760
  setRefLine, refLine: () => refLineOn,
6569
6761
  setInsertMode, insertMode: insertModeOn, // arm/query the detail-placement pick (Slice 4)
@@ -6584,6 +6776,16 @@ window.Steel3DView = {
6584
6776
  // Stage A: drilling into ONE object inside a reference. `selectReferenceObject` is what Ctrl+click and
6585
6777
  // (later) an object-tree row both call, so the two routes cannot drift into different selections.
6586
6778
  selectReferenceObject, selectedReferenceObject,
6779
+ // …and framing one, which the change list's rows need and Ctrl+click deliberately does not do.
6780
+ frameReferenceObject,
6781
+ // The GHOST layer (#734): where removed objects used to be. A third sibling group, outside `xrefById`
6782
+ // and outside `xrefGroup`, which is what makes "never snappable, never in the Fit box" structural.
6783
+ // `referenceGhostCount` and `referenceGhostIds` are test probes — a function having been called is not
6784
+ // evidence that anything was drawn, and the E2E has to be able to assert both halves of that promise.
6785
+ setReferenceGhosts, clearReferenceGhosts, frameReferenceGhost,
6786
+ referenceGhostCount: () => xrefGhostById.size,
6787
+ referenceGhostIds: () => [...xrefGhostById.keys()],
6788
+ referenceGhostPaint,
6587
6789
  // Stage D: the two-point measure. `armRefMeasure3d(id)` arms it, `armRefMeasure3d(null)` disarms;
6588
6790
  // `clearRefMeasure3d()` drops the kept segment. The three probes below are what the E2E asserts against,
6589
6791
  // because "a function was called" is not evidence that anything was drawn.