@floless/app 0.104.0 → 0.104.2

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.
@@ -53583,7 +53583,7 @@ function appVersion() {
53583
53583
  return resolveVersion({
53584
53584
  isSea: isSea2(),
53585
53585
  sqVersionXml: readSqVersionXml(),
53586
- define: true ? "0.104.0" : void 0,
53586
+ define: true ? "0.104.2" : void 0,
53587
53587
  pkgVersion: readPkgVersion()
53588
53588
  });
53589
53589
  }
@@ -53593,7 +53593,7 @@ function resolveChannel(s) {
53593
53593
  return "dev";
53594
53594
  }
53595
53595
  function appChannel() {
53596
- return resolveChannel({ isSea: isSea2(), define: true ? "0.104.0" : void 0 });
53596
+ return resolveChannel({ isSea: isSea2(), define: true ? "0.104.2" : void 0 });
53597
53597
  }
53598
53598
 
53599
53599
  // workflow-update.ts
@@ -262,6 +262,43 @@ export function snapPoint(dragged, candidates, toScreen, tolPx) {
262
262
  return best ? { snapped: bestPt, candidate: best } : { snapped: dragged, candidate: null };
263
263
  }
264
264
 
265
+ /** An intersection is worth this many px of aim against a line when choosing BETWEEN grid levels. */
266
+ export const GRID_INT_HEADSTART_PX = 3;
267
+ /** Scores this close are "the same pixel" — the levels are stacked, so distance can't choose. */
268
+ export const GRID_LEVEL_TIE_PX = 0.5;
269
+
270
+ /**
271
+ * Choose which grid LEVEL a snap lands on. A structural grid is drawn at every visible Z datum, so the
272
+ * same cursor can be within snapping range of several — and each level is evaluated on its own plane, so
273
+ * the level chosen IS the elevation the point gets.
274
+ *
275
+ * `hits` = one entry per level that produced a snap: { z, d, type } (d = screen px from the cursor,
276
+ * type = the winning candidate type on that level). Returns the winning entry, or null for no hits.
277
+ *
278
+ * Rules, in order:
279
+ * - lowest score wins, where score = d + (an intersection scores as-is, a line pays GRID_INT_HEADSTART_PX).
280
+ * So an intersection wins a near-tie against a line — snapPoint applies that same precedence WITHIN a
281
+ * level — but only by a bounded head start: a line right under the cursor still beats a node several px
282
+ * away on another floor, because landing on the wrong ELEVATION is the worse error.
283
+ * - scores within GRID_LEVEL_TIE_PX are a tie: straight down a Top view every level projects to the SAME
284
+ * pixel, and the elevation you dimension to must never come down to float noise. Nearest `planeZ` wins
285
+ * (the plane the tool is already working on — the member under the cursor, else the scene floor).
286
+ * - ties beyond that keep the earlier entry, so a fixed `hits` order gives a deterministic answer.
287
+ */
288
+ export function pickGridLevel(hits, planeZ) {
289
+ const score = (h) => h.d + (h.type === 'grid-int' ? 0 : GRID_INT_HEADSTART_PX);
290
+ let best = null, bestScore = Infinity;
291
+ for (const h of hits || []) {
292
+ if (!h) continue;
293
+ const s = score(h);
294
+ const beats = !best || (Math.abs(s - bestScore) < GRID_LEVEL_TIE_PX
295
+ ? Math.abs(h.z - planeZ) < Math.abs(best.z - planeZ)
296
+ : s < bestScore);
297
+ if (beats) { best = h; bestScore = s; }
298
+ }
299
+ return best;
300
+ }
301
+
265
302
  // ---- working-plane math (CAD copy/move epic §6) — pure vector helpers, scene-mm space ----
266
303
  const _dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
267
304
  const _cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
@@ -17,7 +17,7 @@
17
17
  import * as THREE from 'three';
18
18
  import { OrbitControls } from 'three/addons/OrbitControls.js';
19
19
  import { Brush, Evaluator, SUBTRACTION } from 'three-bvh-csg';
20
- import { snapCandidates, snapPoint, planPointToWp, memberGeometry, elevationLevels, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, vecToPlane, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, snapGridPoint, clipSegmentToPlanes, pointSegmentDistance2d, perspectiveSegmentParameter, gridDepthWins, segmentHitsRect2d, projectedFootprintHitsRect2d } from './steel-3d-core.js';
20
+ import { snapCandidates, snapPoint, planPointToWp, memberGeometry, elevationLevels, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, vecToPlane, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, snapGridPoint, clipSegmentToPlanes, pointSegmentDistance2d, perspectiveSegmentParameter, gridDepthWins, segmentHitsRect2d, projectedFootprintHitsRect2d, pickGridLevel } from './steel-3d-core.js';
21
21
  import { gridGeometry, gridCandidates3d, mmPerPx, visibleGridLevels } from './grid-core.js';
22
22
 
23
23
  let renderer, scene, perspCam, orthoCam, camera, controls, root, api, canvasEl, ro, rafId, grid, raycaster, downXY, lastPick = '(none)';
@@ -68,6 +68,10 @@ const EP_END = 0xf472b6; // end endpoint (end 2) — magenta
68
68
 
69
69
  // ---- 3D dimension tool ----
70
70
  let dimMode3d = false; // tool armed
71
+ // The grid panel's "Add single line" pick, armed while the 3D view is showing. Same two-click gesture as the
72
+ // dimension tool (and as the 2D pick it mirrors): null = disarmed, {a:null} = waiting for the first point,
73
+ // {a:[x,y,z]} = waiting for the second. The editor owns the arming — it drives BOTH views off one flag.
74
+ let gridLinePick3d = null;
71
75
  let snapOnly3d = null; // Tekla-style snap override for the dim tool: a snapCandidates type ('vertex'|'intersection'|'midpoint'|'centerline'|'vertical-axis'), 'none' = free, null = all (set from the right-click menu in steel-editor.html)
72
76
  // map a 3D candidate type → the 2D running-snap key (⋯ menu → Snapping). Types with no key (level, vertical-axis) are 3D-only aids, always allowed.
73
77
  const SNAP3D_PREF = { vertex: 'end', intersection: 'int', midpoint: 'mid', centerline: 'line', 'grid-line': 'line', 'grid-int': 'int' };
@@ -678,6 +682,7 @@ function setRefLine(on) { refLineOn = !!on; buildRefLines(); }
678
682
  // placement click raycasts a member face (anchor) or the ground plane and hands the point + basis +
679
683
  // anchor id back to the editor, which creates + selects the detail and records the create request.
680
684
  function setInsertMode(on, pending) {
685
+ if (on) dropGridLinePick3d();
681
686
  insertMode = !!on;
682
687
  insertPending = insertMode ? (pending || insertPending) : null;
683
688
  if (insertMode) { if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); setClipMode(null); disarmFrame3d(); }
@@ -691,6 +696,7 @@ function insertModeOn() { return insertMode; }
691
696
  // snaps the base to a real framing level. A one-shot left-click hands the picked base elevation to the editor
692
697
  // via api.onBasePick. Mirrors setInsertMode.
693
698
  function setBasePickMode(colId) {
699
+ if (colId) dropGridLinePick3d();
694
700
  basePickCol = colId || null;
695
701
  basePickLevels = null;
696
702
  if (basePickCol) {
@@ -891,6 +897,7 @@ function positionSelLenLabels() {
891
897
  // the contract via api.getGrid() (grid-core owns parsing/geometry); allCandidates() feeds the same
892
898
  // grid into snapping, plan-locked.
893
899
  let structGridGroup = null, gridLabelGroup = null;
900
+ let gridLevelsMm = []; // world Zs the grid is DRAWN at (one per visible level) — set by buildStructGrid so grid snapping can never drift from what the user sees
894
901
  const structGridLines = new Map();
895
902
  let selectedGridIds = new Set();
896
903
  const gridTexCache = new Map(); // 'b:LABEL' bubble / 't:LABEL' tag -> CanvasTexture (kept until dispose)
@@ -945,10 +952,11 @@ function clearStructGrid() {
945
952
  for (const o of [...grp.children]) { grp.remove(o); if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); } // sprite materials are per-sprite; textures stay cached
946
953
  if (parent) parent.remove(grp);
947
954
  }
948
- structGridGroup = gridLabelGroup = null;structGridLines.clear();
955
+ structGridGroup = gridLabelGroup = null;structGridLines.clear();gridLevelsMm = [];
949
956
  }
950
957
  function buildStructGrid() {
951
958
  clearStructGrid();
959
+ dimCandidates3d = null; tfCandidates = null; clipCandidates = null; clipLevels = null; // the grid just changed → EVERY cached snap set built from the OLD one is stale (dim, Move/Copy + Add, clip-box draw). rebuild() already nulls these, but refresh3DGrid() (grid panel edits, and the plan switch setPlan now fires) reaches us without it, which would pair one sheet's grid X/Y with another's elevations.
952
960
  if (!api || !api.getGrid || !scene) return;
953
961
  let g = null, geo = null;
954
962
  try { g = api.getGrid(); if (!g || g.on === false) return; geo = gridGeometry(g, api.ptPerFt()); }
@@ -958,8 +966,12 @@ function buildStructGrid() {
958
966
  const mmX = (px) => px * k, mmY = (px) => -px * k; // display → scene (Y flips)
959
967
  const levels = geo.zs.length ? visibleGridLevels(geo.zs, g.hidden_z) : [{ mm: 0, label: '0' }];
960
968
  if (!levels.length) return; // every authored Z datum is hidden
969
+ gridLevelsMm = levels.map((lv) => lv.mm); // the planes grid snapping evaluates on — same list, same order as what gets drawn below
961
970
  structGridGroup = new THREE.Group();
962
- const addLogical=(id,ends)=>{const pts=[];for(const lv of levels){const z=lv.mm-25;pts.push(V(ends[0][0],ends[0][1],z),V(ends[1][0],ends[1][1],z));}const on=selectedGridIds.has(id);const seg=new THREE.LineSegments(new THREE.BufferGeometry().setFromPoints(pts),new THREE.LineDashedMaterial({color:on?0x3b82f6:0x64748b,dashSize:450,gapSize:220,transparent:true,opacity:on?1:0.85}));seg.computeLineDistances();seg.userData.gridId=id;seg.userData.segments=pts.map(p=>[p.x,p.y,p.z]);structGridLines.set(id,seg);structGridGroup.add(seg);};
971
+ // Drawn at the level's TRUE Z. It used to sit 25 mm under it ("no z-fight/burial"), but the snap
972
+ // targets (gridCandidates3d) are at the true Z — so the reticle floated a fixed 25 mm above the line
973
+ // the user aimed at, which reads as several px of snap error once you zoom in (Pawel 2026-07-18).
974
+ const addLogical=(id,ends)=>{const pts=[];for(const lv of levels){const z=lv.mm;pts.push(V(ends[0][0],ends[0][1],z),V(ends[1][0],ends[1][1],z));}const on=selectedGridIds.has(id);const seg=new THREE.LineSegments(new THREE.BufferGeometry().setFromPoints(pts),new THREE.LineDashedMaterial({color:on?0x3b82f6:0x64748b,dashSize:450,gapSize:220,transparent:true,opacity:on?1:0.85}));seg.computeLineDistances();seg.userData.gridId=id;seg.userData.segments=pts.map(p=>[p.x,p.y,p.z]);structGridLines.set(id,seg);structGridGroup.add(seg);};
963
975
  geo.v.forEach((l,i)=>addLogical('gv:'+i,[[mmX(l.x),mmY(l.lo)],[mmX(l.x),mmY(l.hi)]]));
964
976
  geo.h.forEach((l,i)=>addLogical('gh:'+i,[[mmX(l.lo),mmY(l.y)],[mmX(l.hi),mmY(l.y)]]));
965
977
  (geo.lines||[]).forEach((l,i)=>addLogical('gl:'+(l.id!=null?l.id:i),[[mmX(l.a[0]),mmY(l.a[1])],[mmX(l.b[0]),mmY(l.b[1])]]));
@@ -1238,6 +1250,7 @@ function rebuildClipPlanes(c) { // recompute a clip's .planes from its ed
1238
1250
  c.planes = c.kind === 'box' ? boxToPlanes(c.box) : [new THREE.Plane().setFromNormalAndCoplanarPoint(c.n, c.point)];
1239
1251
  }
1240
1252
  function setClipMode(m) { // arm/disarm a clip pick: 'plane' (click a face) | 'box' (draw 2 corners) | null
1253
+ if (m) dropGridLinePick3d();
1241
1254
  if (m && dimMode3d) toggleDimTool();
1242
1255
  if (m) { if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); cmClear3d(); drClear3d(); disarmFrame3d(); } // clip shares the left-click — disarm Move/Copy + Add + the local frame so their picks don't steal it (onDown routes them first)
1243
1256
  clipMode = (m === 'plane' || m === 'box') ? m : null;
@@ -1696,6 +1709,10 @@ function onKey(e) {
1696
1709
  if (wasEp) rebuildEndpoints(); // restore the dragged endpoint dot to its original spot
1697
1710
  return;
1698
1711
  }
1712
+ // No Escape branch for gridLinePick3d on purpose: the EDITOR owns Esc for this tool. Its window keydown is bound at
1713
+ // parse time, ours inside init(), so the editor's always runs first and cancels the pick while leaving grid mode open.
1714
+ // Cancelling here first would make its handler fall through to setGridMode(false) and close the panel too — one Esc
1715
+ // doing two things.
1699
1716
  if (wpMode && e.key === 'Escape') { e.preventDefault(); if (wpMode === '3pt' && wpDraft && wpDraft.length) { wpDraft.pop(); updateStatusChip(); } else { wpMode = null; wpDraft = null; marker.visible = false; canvasEl.style.cursor = 'default'; reflectWpBar(); updateStatusChip(); } return; } // Esc steps a 3pt pick back, else disarms the set-plane mode
1700
1717
  if (insertMode && e.key === 'Escape') { e.preventDefault(); setInsertMode(false); if (api && api.toast) api.toast('Insert cancelled'); return; } // Esc disarms the detail-placement pick
1701
1718
  if (basePickCol && e.key === 'Escape') { e.preventDefault(); setBasePickMode(null); if (api && api.toast) api.toast('Trim cancelled'); return; } // Esc disarms the Mode B column-base pick
@@ -1722,12 +1739,34 @@ function onKey(e) {
1722
1739
  }
1723
1740
  // ---- 3D dimension tool controls (driven from the toolbar + the keyboard) ----
1724
1741
  function toggleDimTool() {
1742
+ if (!dimMode3d) dropGridLinePick3d(); // arming the dim tool takes the left-click — cancel an armed grid-line pick through the editor first
1725
1743
  dimMode3d = !dimMode3d;
1726
1744
  if (!dimMode3d) { dimDraft3d = null; dimCandidates3d = null; dimPreviewLine.visible = false; marker.visible = false; readout.style.display = 'none'; canvasEl.style.cursor = 'default'; setSnapOnly3d(null); } // disarming ends the operation → the snap override reverts to all snaps
1727
1745
  else { if (clipMode) setClipMode(null); if (wpMode) armWorkPlanePick(wpMode); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); drClear3d(); disarmFrame3d(); controls.enabled = true; canvasEl.style.cursor = 'crosshair'; } // arming the dim tool disarms the clip pick, a set-plane pick, Move/Copy, Add-member AND the local frame (all share the left-click + Esc)
1728
1746
  reflectDimBar();
1729
1747
  return dimMode3d;
1730
1748
  }
1749
+ // Arm/disarm the grid panel's "Add single line" pick for the 3D view. The early-out keeps re-arming a no-op:
1750
+ // every path that arms this pick starts from a fresh {a:null}, so a redundant arm can never wipe a half-finished one.
1751
+ function armGridLinePick3d(on) {
1752
+ on = !!on;
1753
+ if (on === !!gridLinePick3d) return on;
1754
+ // Disarm the conflicting tools BEFORE raising our own flag — each call below takes the DISARM direction, where their
1755
+ // own dropGridLinePick3d() guard is skipped, so this cannot cancel the very pick being armed.
1756
+ // basePickCol and insertMode matter as much as the rest: onDown routes both AHEAD of this pick, so leaving either
1757
+ // armed would make every click place a detail / do the base pick while the hint still reads "Pick the first point"
1758
+ // — the exact dead-control failure this change exists to fix.
1759
+ if (on) { if (dimMode3d) toggleDimTool(); if (clipMode) setClipMode(null); setInsertMode(false); setBasePickMode(null); if (wpMode) armWorkPlanePick(wpMode); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); drClear3d(); disarmFrame3d(); }
1760
+ gridLinePick3d = on ? { a: null } : null;
1761
+ if (!gridLinePick3d) { if (dimPreviewLine) dimPreviewLine.visible = false; if (marker) marker.visible = false; if (readout) readout.style.display = 'none'; if (canvasEl) canvasEl.style.cursor = 'default'; }
1762
+ else { if (controls) controls.enabled = true; if (canvasEl) canvasEl.style.cursor = 'crosshair'; }
1763
+ updateStatusChip();
1764
+ return on;
1765
+ }
1766
+ // The reverse of the exclusivity above: another 3D tool taking the left-click must cancel an armed grid-line pick
1767
+ // THROUGH the editor, so the panel hint and the button's armed state can't be left claiming a pick that no longer owns
1768
+ // the canvas. Falls back to a local disarm if the host wired no callback, so the pick can never survive the handover.
1769
+ function dropGridLinePick3d() { if (!gridLinePick3d) return; if (api && api.onGridLinePickCancel) api.onGridLinePickCancel(); else armGridLinePick3d(false); }
1731
1770
  // snap override setter — notifies the host page so its header chip stays in sync with every clear path
1732
1771
  function setSnapOnly3d(k) { snapOnly3d = k || null; if (api && api.onSnapOnlyChanged) api.onSnapOnlyChanged(); }
1733
1772
  // X/Y/Z each TOGGLE the measure axis in the lock set (press again to release; combine 2–3 → the dim measures along
@@ -2583,6 +2622,7 @@ function setFrameOrigin(originMm) {
2583
2622
  function clearFrame3d() { const had = !!frame3d || frameMode; cancelFramePick(); frame3d = null; frameMode = false; if (had) fireFrameChange(); }
2584
2623
  function armFrame3d(on) { // arm/disarm the tool; arming disarms conflicting tools
2585
2624
  frameMode = on == null ? !frameMode : !!on;
2625
+ if (frameMode) dropGridLinePick3d();
2586
2626
  if (frameMode) {
2587
2627
  if (dimMode3d) toggleDimTool(); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); cmClear3d(); drClear3d(); if (wpMode) { wpMode = null; wpDraft = null; reflectWpBar(); } setClipMode(null); setInsertMode(false); // arming the frame disarms EVERY other left-click 3D tool (incl. clip + insert)
2588
2628
  framePickPts = frame3d ? null : []; // no frame yet → start the 3-click pick; an existing frame → straight to drag-refine (re-pick from the panel)
@@ -2815,7 +2855,7 @@ function renderWorkPlane() {
2815
2855
  function reflectWpBar() { const b = document.getElementById('m3dWp'); if (b) { b.classList.toggle('on', !!wpMode || !!workPlane);
2816
2856
  const kind = workPlane && workPlane.kind ? { face: 'Face', p3: '3pt', xy: 'XY', xz: 'XZ', yz: 'YZ' }[workPlane.kind] || '' : '';
2817
2857
  b.textContent = wpMode ? '◇ Plane ✕' : (kind ? '◇ Plane: ' + kind + ' ▾' : '◇ Plane ▾'); } reflectDimAxisBar(); } // the label reads the active plane without opening the menu (ux review); relabel the dim-axis bar (a set/cleared plane flips X/Y between World and local)
2818
- function armWorkPlanePick(mode) { if (wpMode === mode) { wpMode = null; wpDraft = null; } else { wpMode = mode; wpDraft = null; if (dimMode3d) toggleDimTool(); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); cmClear3d(); drClear3d(); disarmFrame3d(); } marker.visible = false; canvasEl.style.cursor = wpMode ? 'crosshair' : 'default'; reflectWpBar(); } // a set-plane pick shares the left-click — disarm Move/Copy + Add + the local frame (their onDown routes run first)
2858
+ function armWorkPlanePick(mode) { if (wpMode === mode) { wpMode = null; wpDraft = null; } else { wpMode = mode; wpDraft = null; dropGridLinePick3d(); if (dimMode3d) toggleDimTool(); if (api && api.disarmTransform) api.disarmTransform(); if (api && api.disarmAdd) api.disarmAdd(); cmClear3d(); drClear3d(); disarmFrame3d(); } marker.visible = false; canvasEl.style.cursor = wpMode ? 'crosshair' : 'default'; reflectWpBar(); } // a set-plane pick shares the left-click — disarm Move/Copy + Add + the local frame (their onDown routes run first)
2819
2859
  function setWorkPlanePrincipal(kind, offsetMm) {
2820
2860
  const off = offsetMm || 0;
2821
2861
  const def = { xy: { normal: [0, 0, 1], xAxis: [1, 0, 0] }, xz: { normal: [0, 1, 0], xAxis: [1, 0, 0] }, yz: { normal: [1, 0, 0], xAxis: [0, 1, 0] } }[kind];
@@ -3204,27 +3244,53 @@ function dimPointAt(e, anchor) {
3204
3244
  const hit = rayToPlane(e.clientX, e.clientY, planeZ); if (!hit) return null;
3205
3245
  if (!dimCandidates3d) dimCandidates3d = allCandidates(null); // member + grid candidates (allCandidates folds in the grid)
3206
3246
  const cands = dimCandidates3d.filter((c) => candAllowed3d(c.type)); // right-click override (one type / free) + the persistent running-snaps from the ⋯ menu
3207
- // Grid geometry is drawn at its OWN Z (often ground, e.g. 0), which can be far from the steel-level planeZ.
3208
- // Evaluate grid candidates against a ray hit on the GRID plane so they align with what's drawn; member
3209
- // candidates keep the member/scene plane. Pick whichever winner is closest to the cursor on screen.
3210
- const gz = gridPlaneZ();
3247
+ // Grid geometry is drawn at its OWN Z levels, which can be far from the steel-level planeZ — and a grid
3248
+ // with several visible datums is drawn at ALL of them (the candidates are plan-only: candidatePoint keeps
3249
+ // the dragged Z, so the plane we evaluate on IS the elevation the snap lands at). So try every drawn level
3250
+ // and keep the one nearest the cursor on screen — dimension to the 2nd-floor grid and you get the 2nd
3251
+ // floor, not the ground copy. Member candidates keep the member/scene plane; closest-on-screen wins overall.
3211
3252
  const isGrid = (c) => c.type === 'grid-int' || c.type === 'grid-line';
3212
- const gridCands = gz != null ? cands.filter(isGrid) : [];
3213
- const memCands = gridCands.length ? cands.filter((c) => !isGrid(c)) : cands;
3253
+ const gridCands = gridLevelsMm.length ? cands.filter(isGrid) : [];
3254
+ // Grid candidates belong to the level loop below and NOWHERE else. Never let them fall through to the
3255
+ // member set: gridCandidates3d gates on g.on alone and ignores hidden_z, so with every Z datum hidden
3256
+ // the grid draws nothing yet still emits candidates — which would snap, invisibly, on the member plane.
3257
+ // What isn't drawn must not snap. (No grid at all → gridCandidates3d returns [] and this filters nothing.)
3258
+ const memCands = cands.filter((c) => !isGrid(c));
3214
3259
  const best = (cset, dragged) => { if (!cset.length || !dragged) return null; const r = snapPoint(dragged, cset, toScreen, SNAP_TOL_PX);
3215
3260
  if (!r.candidate) return null; const a = toScreen(dragged), b = toScreen(r.snapped); return { r, d: Math.hypot(a.x - b.x, a.y - b.y) }; };
3216
3261
  const rMem = best(memCands, [hit[0], hit[1], hit[2]]);
3217
- const hitGrid = gridCands.length ? rayToPlane(e.clientX, e.clientY, gz) : null;
3218
- const rGrid = best(gridCands, hitGrid);
3262
+ // Evaluate the grid on EVERY drawn level (each on its own plane, so the level picked is the elevation the
3263
+ // point gets) and let the pure pickGridLevel rule choose — bounded intersection head start, planeZ breaking
3264
+ // the Top-view tie where the levels stack on one pixel. See its doc comment in steel-3d-core for the why.
3265
+ const gridHits = [];
3266
+ if (gridCands.length) for (const gz of gridLevelsMm) {
3267
+ const r = best(gridCands, rayToPlane(e.clientX, e.clientY, gz)); // null when the view is edge-on to that level → skip it, never a NaN point
3268
+ if (r) gridHits.push({ z: gz, d: r.d, type: r.r.candidate.type, r: r.r });
3269
+ }
3270
+ const gridWin = pickGridLevel(gridHits, planeZ);
3271
+ const rGrid = gridWin ? { r: gridWin.r, d: gridWin.d } : null;
3219
3272
  const win = rGrid && (!rMem || rGrid.d <= rMem.d) ? rGrid : rMem;
3220
3273
  return { p: win ? win.r.snapped : hit, type: win ? win.r.candidate.type : null };
3221
3274
  }
3222
- // The grid's world Z (where its snap targets live), derived from the current grid candidates — or null if no grid.
3223
- function gridPlaneZ() {
3224
- if (!dimCandidates3d) return null;
3225
- const p = dimCandidates3d.find((c) => c.type === 'grid-int'); if (p) return p.p[2];
3226
- const l = dimCandidates3d.find((c) => c.type === 'grid-line'); if (l) return l.a[2];
3227
- return null;
3275
+ // The point under the cursor for the grid-line pick. Reuses the dimension tool's snapped pick (member + grid
3276
+ // candidates, running-snaps applied) with NO anchor, so Alt never forces the dim tool's vertical branch — a grid
3277
+ // line is a plan entity and only its X/Y survive the commit.
3278
+ function gridLinePickPoint3d(e) { return dimPointAt({ clientX: e.clientX, clientY: e.clientY, altKey: false }, null); }
3279
+ // Rubber-band + readout while placing a grid line: plan length and bearing, matching what the 2D pick shows.
3280
+ function gridLineHoverPreview3d() {
3281
+ if (!lastHoverXY || !canvasEl || !dimPreviewLine) return;
3282
+ const r = gridLinePickPoint3d({ clientX: lastHoverXY[0], clientY: lastHoverXY[1] });
3283
+ const snapped = !!(r && r.type);
3284
+ if (snapped) showMarker(r.p, r.type); else marker.visible = false; // reticle only on a real snap — same rule as the dim tool
3285
+ canvasEl.style.cursor = snapped ? 'none' : 'crosshair';
3286
+ if (gridLinePick3d.a && r) {
3287
+ dimPreviewLine.geometry.setFromPoints([new THREE.Vector3(...gridLinePick3d.a), new THREE.Vector3(...r.p)]);
3288
+ dimPreviewLine.visible = true;
3289
+ const dx = r.p[0] - gridLinePick3d.a[0], dy = r.p[1] - gridLinePick3d.a[1], len = Math.hypot(dx, dy); // PLAN length (X/Y only) — the Z the pick landed on is discarded on commit
3290
+ readout._dist.textContent = api.fmtLen ? api.fmtLen(len) : (len / 304.8).toFixed(2) + ' ft';
3291
+ readout._type.textContent = ' · angle ' + Math.round(Math.atan2(-dy, dx) * 180 / Math.PI) + '°' + (r.type ? ' · ' + r.type : ''); // NEGATE dy: scene Y runs opposite plan-display Y (buildStructGrid: mmY = -px*k), so a raw atan2 would report the bearing mirrored against the 2D tool for the very same line. The k>0 scale cancels out of the ratio.
3292
+ readout.style.left = (lastHoverXY[0] + 14) + 'px'; readout.style.top = (lastHoverXY[1] + 14) + 'px'; readout.style.display = 'block';
3293
+ } else { dimPreviewLine.visible = false; if (r) roShowCoordOnly(r.p, lastHoverXY[0], lastHoverXY[1]); else readout.style.display = 'none'; }
3228
3294
  }
3229
3295
  // The axis to measure on: Alt held during the 2nd pick forces a pure-vertical (Z) measurement,
3230
3296
  // overriding the sticky axis (else a sticky X/Y would collapse the Alt-locked point to zero length).
@@ -3272,11 +3338,20 @@ function onDown(e) {
3272
3338
  if (clipMode === 'box') { e.stopPropagation(); onClipBoxClick(e); return; } // armed: 2-corner clip-box draw on the floor plane
3273
3339
  if (framePicking()) { e.stopPropagation(); controls.enabled = true; framePickClick(e); return; } // 3-click UCS set: this click collects the origin / X point / Y point
3274
3340
  if (frameMode) { let fh = null; try { fh = pickFrameHandle(e.clientX, e.clientY); } catch { fh = null; } if (fh) { e.stopPropagation(); controls.enabled = false; startFrameDrag(fh, e); return; } } // grab the local-frame origin/ring (armed) → drag it; an empty click falls through (orbit)
3275
- if (frame3d && !frameMode && !geoMode() && !cmActive() && !addActive() && !dimMode3d && !clipMode && !wpMode && !basePickCol && !insertMode && !selectedClipIds.size) { // passive gizmo, no tool armed → clicking its origin/ring re-selects the local frame for editing (NOT reached by box-select or select-all, which only touch members)
3341
+ if (frame3d && !frameMode && !geoMode() && !cmActive() && !addActive() && !dimMode3d && !clipMode && !wpMode && !basePickCol && !insertMode && !gridLinePick3d && !selectedClipIds.size) { // passive gizmo, no tool armed → clicking its origin/ring re-selects the local frame for editing (NOT reached by box-select or select-all, which only touch members). gridLinePick3d belongs in this list like every other armed tool: the handle captures within ~16 px, so without it the frame ORIGIN — a snap target the grid pick advertises — could never be used as a grid endpoint; the click would re-arm the frame and cancel the pick instead.
3276
3342
  let fh = null; try { fh = pickFrameHandle(e.clientX, e.clientY, true); } catch { fh = null; }
3277
3343
  if (fh) { e.stopPropagation(); controls.enabled = false; armFrame3d(true); startFrameDrag(fh, e); return; } // re-arm the tool + grab the clicked handle so a click-drag manipulates immediately
3278
3344
  }
3279
- if (selectedClipIds.size) { let ch = null; try { ch = pickClipHandle(e.clientX, e.clientY); } catch { ch = null; } if (ch) { e.stopPropagation(); controls.enabled = false; downXY = [e.clientX, e.clientY]; startClipDrag(ch, e); return; } } // grab a clip handle (plane dot / box face) → drag it
3345
+ if (selectedClipIds.size && !gridLinePick3d) { let ch = null; try { ch = pickClipHandle(e.clientX, e.clientY); } catch { ch = null; } if (ch) { e.stopPropagation(); controls.enabled = false; downXY = [e.clientX, e.clientY]; startClipDrag(ch, e); return; } } // grab a clip handle (plane dot / box face) → drag it. Not while the grid pick is armed: a handle drag would start under an armed two-click tool, leaving the button + hint claiming a pick and the shared preview line stranded (onUp clears the marker/readout but not dimPreviewLine).
3346
+ if (gridLinePick3d) { // grid panel "Add single line": pick A, then B → the editor commits it (mirrors the 2D pick)
3347
+ e.stopPropagation(); controls.enabled = true;
3348
+ const r = gridLinePickPoint3d(e); if (!r) return;
3349
+ if (!gridLinePick3d.a) { gridLinePick3d.a = r.p; updateStatusChip(); if (api && api.onGridLinePickStep) api.onGridLinePickStep(); return; } // step BOTH readouts to "second point" — the canvas chip and the panel hint
3350
+ const a = gridLinePick3d.a;
3351
+ if (dimPreviewLine) dimPreviewLine.visible = false; if (marker) marker.visible = false; if (readout) readout.style.display = 'none';
3352
+ if (api && api.onAddGridLine3d) api.onAddGridLine3d(a, r.p); // the editor converts world mm → plan display px, commits + disarms; a rejected (too-short) line leaves the pick armed so the 2nd point can be retried, exactly as in 2D
3353
+ return;
3354
+ }
3280
3355
  if (dimMode3d) { // 2-click dimension placement (not a drag): pick A, then B → place
3281
3356
  e.stopPropagation(); controls.enabled = true;
3282
3357
  const r = dimPointAt(e, dimDraft3d && dimDraft3d.a); if (!r) return;
@@ -3648,6 +3723,7 @@ function onHoverMove(e) {
3648
3723
  hoverRAF = requestAnimationFrame(() => {
3649
3724
  hoverRAF = 0;
3650
3725
  if (!lastHoverXY || pending || dragging || boxSel) return;
3726
+ if (gridLinePick3d) { gridLineHoverPreview3d(); return; } // armed grid-line pick owns the hover (rubber-band + snap reticle)
3651
3727
  if (basePickCol) { // Mode B armed: reticle on the column axis + a live elevation readout
3652
3728
  const p = basePickPoint(lastHoverXY[0], lastHoverXY[1]);
3653
3729
  if (p) {
@@ -3721,6 +3797,7 @@ function updateStatusChip() {
3721
3797
  else if (cmActive()) { const st = cmActive(), lock = lockChipTxt();
3722
3798
  txt = (!tfDraft ? ((st.tool === 'move' ? 'Move' : (st.array ? 'Copy array' : 'Copy')) + ' — click the base point on the working plane · type after the pick for an exact value')
3723
3799
  : (st.array && !tfDraft.vA ? 'Click the direction-A point — or type its spacing' : st.array ? 'Click the direction-B point — the grid previews live' : 'Click the destination — X/Y lock to the plane axes · Esc cancels')) + lock; }
3800
+ else if (gridLinePick3d) txt = gridLinePick3d.a ? 'Click the second point of the grid line · Esc to cancel' : 'Click the first point of the grid line · Esc to cancel'; // must sit above the showId/default branches, else an armed two-click tool shows the hovered member or the drag-move hint the user can't act on
3724
3801
  else if (clipMode === 'plane') txt = 'Click a face to set a clip plane · Esc to cancel';
3725
3802
  else if (clipMode === 'box') txt = !clipBoxDraft ? 'Click the first floor corner of the clip box · Esc to cancel' : !clipBoxDraft.b ? 'Click the opposite floor corner · Esc to cancel' : 'Move up/down to set the height, then click · Esc to step back';
3726
3803
  else if (showId) { const m = memberById(showId); txt = m ? `${m.id} · ${m.profile || '—'}` : ''; }
@@ -3815,6 +3892,7 @@ function debug() {
3815
3892
  endpointColors: epGroup ? epGroup.children.map((c) => '#' + c.material.color.getHexString()) : [],
3816
3893
  hoverId, hoverEp, dragEp, refLine: refLineOn,
3817
3894
  snapMarker: marker && marker.visible ? { type: lastSnapType3d, at: [marker.position.x, marker.position.y, marker.position.z] } : null, // test-observability for the snap reticle
3895
+ gridLevels: [...gridLevelsMm], // the drawn grid elevations a grid snap can land on (one plane per visible datum)
3818
3896
 
3819
3897
  inFrustum: (() => { let n = 0, t = 0; for (const m of meshById.values()) { t++; const v = m.getWorldPosition(new THREE.Vector3()).project(camera); if (Math.abs(v.x) <= 1 && Math.abs(v.y) <= 1 && v.z >= -1 && v.z <= 1) n++; } return { n, t }; })(),
3820
3898
  camPos: camera ? [camera.position.x, camera.position.y, camera.position.z] : null,
@@ -3874,6 +3952,7 @@ window.Steel3DView = {
3874
3952
  selLenLabelTexts: () => selLenLabelPool.filter((el) => el.style.display !== 'none' && el.style.visibility !== 'hidden').map((el) => el.textContent), // visible on-select length chips — for tests
3875
3953
  epScreen: (id) => { const m = memberById(id); if (!m || !canvasEl) return null; const g = memberGeometry(m, api.ptPerFt(), api.defaultTosMm()); const rect = canvasEl.getBoundingClientRect(); const proj = (p) => { const v = new THREE.Vector3(p[0], p[1], p[2]).project(camera); return { x: rect.left + (v.x * 0.5 + 0.5) * rect.width, y: rect.top + (-v.y * 0.5 + 0.5) * rect.height }; }; return { a: proj(g.line[0]), b: proj(g.line[1]) }; }, // project a member's endpoints to viewport px — test probe for endpoint-drag tests
3876
3954
  refreshGrid: buildStructGrid, // grid edited in the panel → re-render without a full rebuild
3955
+ armGridLinePick3d, gridLinePick3dState: () => (gridLinePick3d ? { armed: true, hasFirst: !!gridLinePick3d.a, a: gridLinePick3d.a || null } : { armed: false, hasFirst: false, a: null }), // grid panel "Add single line" in 3D (+ test probe)
3877
3956
  gridInfo: () => ({ lines: structGridLines.size, labels: gridLabelGroup ? gridLabelGroup.children.length : 0,labelTexts:gridLabelGroup?[...new Set(gridLabelGroup.children.map(s=>s.userData.label).filter(Boolean))]:[],selected:[...selectedGridIds],ids:[...structGridLines.keys()] }), // test helper
3878
3957
  wpProbe: () => { // test helper: the "Show plane" reference surface — asserts no grid, bbox-sized surface, light-blue colour. `extent` is the projected u/v footprint the surface was actually sized to (work-area/tilted-plane aware), null for the fallback square. Surface w == extent.uSpan + 2*extent.margin.
3879
3958
  if (!wpGroup) return { group: false, extent: wpExtent };
@@ -2127,11 +2127,25 @@ function sanitizePlanGrid(pl){if(!pl||pl.grid==null)return;const g=pl.grid;
2127
2127
  function gridLineId(){return 'gl'+Date.now().toString(36)+Math.floor(Math.random()*1000).toString(36);}
2128
2128
  function gridNextLineLabel(){const n=(P&&P.grid&&Array.isArray(P.grid.lines))?P.grid.lines.length+1:1;return 'L'+n;}
2129
2129
  function gridEnsureForLine(a){const gc=GC();if(P.grid)return;P.grid={on:true,origin:a.slice(),x:'',y:'',z:"0'-0\"",labels_x:'',labels_y:'',labels_z:[],ext:gc?5*gc.FT_MM:1524,lines:[]};}
2130
- function gridAddFreeLine(a,b,label){const gc=GC();if(Math.hypot(b[0]-a[0],b[1]-a[1])<6/zoom){toast('Line is too short to create a grid line');return false;}
2130
+ // The 3D pick's minimum line length, in display px — a fixed floor, since 3D has no 2D `zoom` to scale by. 6 px is
2131
+ // what the 2D tool enforces at 1:1; in real terms that is 6*mmPerPx (~2" at a typical 1/4"=1' sheet scale).
2132
+ const GRID_LINE_MIN_DISP=6;
2133
+ // minDisp = the shortest acceptable line, in DISPLAY px. 2D defaults to 6/zoom so the floor is a constant ~6 px on
2134
+ // screen whatever the pan/zoom. A 3D caller must pass its own: `zoom` is the 2D viewport's live scale and is
2135
+ // meaningless while the user is in 3D, so inheriting it would make an identical 3D pick commit or get rejected
2136
+ // depending on a hidden viewport (fitted at zoom≈0.2 it would silently refuse lines under ~2.5 ft).
2137
+ function gridAddFreeLine(a,b,label,minDisp){const gc=GC();if(Math.hypot(b[0]-a[0],b[1]-a[1])<(minDisp>0?minDisp:6/zoom)){toast('Line is too short to create a grid line');return false;}
2131
2138
  gridEnsureForLine(a);if(!Array.isArray(P.grid.lines))P.grid.lines=[];
2132
2139
  P.grid.lines.push({id:gridLineId(),label:label||gridNextLineLabel(),a:a.slice(),b:b.slice()});return true;}
2133
- function gridSetPickClass(){document.body.classList.toggle('gridpick',!!gridPick||!!gridLinePick);}
2140
+ function gridSetPickClass(){document.body.classList.toggle('gridpick',!!gridPick||!!gridLinePick);
2141
+ // ONE choke point for the 3D side: every path that arms or tears down the pick (start, cancel, setGridMode,
2142
+ // Move/Copy arm, plan switch, view switch) already calls this, so the 3D pick can never outlive the 2D flag.
2143
+ // Panel repaints do NOT come through here — they don't need to; the 3D view owns the live draft once armed.
2144
+ if(window.Steel3DView&&window.Steel3DView.armGridLinePick3d)window.Steel3DView.armGridLinePick3d(!!gridLinePick&&view3d);}
2134
2145
  function gridStartLinePick(){gridPick=false;gridLinePick={a:null};gridSetPickClass();panel();}
2146
+ // Has the first point been placed? In 3D the live draft lives in the 3D view (its point is scene mm, deliberately
2147
+ // NOT stored in gridLinePick.a, which the 2D handler reads as display px). One helper so the panel hint is honest in both views.
2148
+ const gridPickHasFirst=()=>view3d?!!(window.Steel3DView&&window.Steel3DView.gridLinePick3dState&&window.Steel3DView.gridLinePick3dState().hasFirst):!!(gridLinePick&&gridLinePick.a);
2135
2149
  function gridCancelLinePick(){if(gridLinePick&&gridLinePick.line)gridLinePick.line.remove();gridLinePick=null;gridSetPickClass();snapClear();gridReadoutHide();panel();}
2136
2150
  function planColumnCount(){let n=0;for(const m of ((P&&P.members)||[]))if(m.role==='column')n++;return n;}
2137
2151
  // The active plan's steel-filter elements (per-sheet linework the reader captured) — the source the
@@ -2222,7 +2236,7 @@ function renderGridPanel(p){
2222
2236
  p.innerHTML=`<span class=badge>Grid lines</span>
2223
2237
  <div class=hint style="margin-top:8px">No grid yet. Grid lines are a plan reference — they don't constrain members.</div>
2224
2238
  <div class=gbtns><button id=gridLineB class="${gridLinePick?'on':''}" data-tip="Add an individual grid line at any angle with two clicks. Undoable.">Add single line</button><button id=gridReadB ${hasEls?'':'disabled'} data-tip="${hasEls?'Detect the printed grid lines and bubbles in this sheet’s linework. Undoable.':'Needs this sheet’s filter linework — re-read the drawing with the steel filter step to capture it.'}">From drawing</button><button id=gridAutoB ${nCols<2?'disabled':''} data-tip="${nCols<2?'Needs at least two columns in the model to infer spacing.':'Infer spacings and origin from the column layout. Undoable.'}">Auto from columns</button><button id=gridBlankB data-tip="Start from a 4×4 grid of 30' bays and edit the spacings. Undoable.">Start blank</button></div>
2225
- ${gridLinePick?'<div class=hint style="margin-top:6px">'+(gridLinePick.a?'Pick the second point for the grid line — snaps to linework (<b>Alt</b> off). <b>Esc</b> cancels.':'Pick the first point for the grid line — snaps to linework (<b>Alt</b> off). <b>Esc</b> cancels.')+'</div>':''}
2239
+ ${gridLinePick?'<div class=hint style="margin-top:6px">'+(gridPickHasFirst()?'Pick the second point for the grid line':'Pick the first point for the grid line')+(view3d?' — snaps to the model and the grid.':' — snaps to linework (<b>Alt</b> off).')+' <b>Esc</b> cancels.</div>':''}
2226
2240
  <div class=hint style="margin-top:10px">Spacing uses <b>n*d</b> to repeat (e.g. <b>3*25'</b> = three 25' bays). Tokens: <b>25'-6"</b>, <b>6"</b>, <b>7.5m</b>, bare mm.</div>`;
2227
2241
  document.getElementById('gridLineB').onclick=gridStartLinePick;
2228
2242
  const rb=document.getElementById('gridReadB');if(rb)rb.onclick=()=>gridReadFromDrawing(null);
@@ -2261,7 +2275,7 @@ function renderGridPanel(p){
2261
2275
  <div class=sect style="margin-top:10px">Single lines <span style="color:var(--mut);font-weight:400;text-transform:none">· any angle</span></div>
2262
2276
  <div class=gfb>${(g.lines&&g.lines.length)?(g.lines.length+' individual line'+(g.lines.length===1?'':'s')+' · drag endpoints to adjust'):'No individual lines yet.'}</div>
2263
2277
  <div class=gbtns><button id=gridLineB class="${gridLinePick?'on':''}" data-tip="Add an individual grid line at any angle with two clicks. Undoable.">Add single line</button>${(g.lines&&g.lines.length)?'<button id=gridClearLinesB class=ghostw data-tip="Remove every individual grid line. The X/Y grid and levels stay. Undoable.">Clear single lines</button>':''}</div>
2264
- ${gridLinePick?'<div class=hint style="margin-top:6px">'+(gridLinePick.a?'Pick the second point for the grid line — snaps to linework (<b>Alt</b> off). <b>Esc</b> cancels.':'Pick the first point for the grid line — snaps to linework (<b>Alt</b> off). <b>Esc</b> cancels.')+'</div>':''}
2278
+ ${gridLinePick?'<div class=hint style="margin-top:6px">'+(gridPickHasFirst()?'Pick the second point for the grid line':'Pick the first point for the grid line')+(view3d?' — snaps to the model and the grid.':' — snaps to linework (<b>Alt</b> off).')+' <b>Esc</b> cancels.</div>':''}
2265
2279
  <div class=sect style="margin-top:10px">Extension</div>
2266
2280
  <input id=gExt class=gin style="width:110px" value="${esc(gc.fmtLen(isFinite(g.ext)?g.ext:1524))}" autocomplete=off spellcheck=false>
2267
2281
  <div class=hint style="margin-top:3px">How far every line runs past the outermost, in plan. Drag a bubble <b>along</b> its line to override just that one.</div>
@@ -4587,6 +4601,7 @@ function setMode(){document.body.classList.toggle('add',mode==='add');document.g
4587
4601
  picking=false;pickKind='profile';pickEnd=null; // a pick armed in one mode must never bleed into the other (an inspector ⌖ pick would otherwise show the Add panel's button pre-armed)
4588
4602
  if(mode!=='add'){drawDraft=null;drawPrevClear();cmHudClose();if(view3d&&window.Steel3DView&&window.Steel3DView.drClear3d)window.Steel3DView.drClear3d();}} // leaving Add-member drops the in-progress start + preview, closes any open typed-entry HUD, and clears the 3D draw start (else a stale Add token could revalidate on re-arm — Codex)
4589
4603
  document.getElementById('mAdd').onclick=()=>{if(dimMode){dimMode=false;setDimMode();}if(csaxisMode){csaxisMode=false;setCsMode();}if(cmTool)disarmCm();if(qdPick){qdPick=null;setQdPickCls();}
4604
+ if(gridMode||gridPick||gridLinePick){if(gridLinePick&&gridLinePick.line)gridLinePick.line.remove();gridMode=false;gridPick=false;gridLinePick=null;gridSetPickClass();} // arming Add leaves the grid panel — same mutual exclusion Move/Copy already enforces. In 3D addActive() consumes the click AHEAD of the grid pick, so without this the Add gesture would run while the grid button + hint still claimed an armed pick (the A shortcut routes through this same handler)
4590
4605
  if(view3d&&window.Steel3DView){const dm=document.getElementById('m3dDim');if(dm&&dm.classList.contains('on'))window.Steel3DView.toggleDimTool();if(window.Steel3DView.disarmFrame3d)window.Steel3DView.disarmFrame3d();} // the 3D dim tool + the local frame share the left-click — disarm both when entering add mode
4591
4606
  selDimIds.clear();dimStyleMode=false;mode=(mode==='add'?'sel':'add');if(mode==='add')selIds.clear();else if(window.Steel3DView&&window.Steel3DView.drClear3d)window.Steel3DView.drClear3d();snapOnlyClear2d();setMode();render();setLastCmd('Add member',()=>{if(mode!=='add'){if(dimMode){dimMode=false;setDimMode();}mode='add';selIds.clear();setMode();render();}});}; // entering add/sel disarms the Dimension + set-axes tools + the Dimension style pane + drops any dim selection + reverts a snap override; leaving add clears the 3D draw draft
4592
4607
  document.getElementById('dimB').onclick=()=>{if(csaxisMode){csaxisMode=false;setCsMode();}if(qdPick){qdPick=null;setQdPickCls();}dimMode=!dimMode;setDimMode();render();setLastCmd('Dimension',()=>{if(!dimMode){dimMode=true;setDimMode();render();}});};
@@ -4678,7 +4693,7 @@ addEventListener('keydown',e=>{
4678
4693
  if(ck==='b'){e.preventDefault();window.Steel3DView.setClipMode('box');setLastCmd('Clip box',()=>window.Steel3DView.setClipMode('box'));return;}}
4679
4694
  if(!view3d&&!inForm&&(((e.key==='z'||e.key==='Z')&&e.altKey)||(e.key===' '&&e.shiftKey))){e.preventDefault();zoomToSelection();return;} // 2D zoom-to-selected (Tekla Shift+Space / Alt+Z); 3D handles its own (steel-3d-view onKey)
4680
4695
  if((e.key===' '||e.key==='Enter')&&!inForm&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&!e.shiftKey){if(!anyToolActive()&&lastCmd){e.preventDefault();repeatLast();}return;} // idle Space/Enter → repeat the last command (AutoCAD/Tekla)
4681
- if(e.key==='Escape'&&gridLinePick){gridCancelLinePick();return;} // Esc disarms add-single-line (grid mode stays)
4696
+ if(e.key==='Escape'&&gridLinePick){e.stopImmediatePropagation();gridCancelLinePick();return;} // Esc disarms add-single-line (grid mode stays). stopImmediatePropagation because the 3D view binds its OWN window keydown: this Esc is fully consumed here, and without it the same press would ALSO run the 3D handler — which, seeing the pick already cancelled, falls through and clears an active isolation. One Esc, one action.
4682
4697
  if(e.key==='Escape'&&gridPick){gridPick=false;gridSetPickClass();snapClear();panel();return;} // Esc disarms pick-origin (grid mode stays)
4683
4698
  if(e.key==='Escape'&&gridMode&&!inForm){setGridMode(false);render();return;} // Esc exits the grid panel (a focused field handles its own Esc = revert)
4684
4699
  if(e.key==='Escape'&&dimStyleMode&&!inForm){setDimStyleMode(false);render();return;} // …likewise the Dimension style pane
@@ -4951,6 +4966,14 @@ const view3dApi={
4951
4966
  getDimOverlays:()=>C.dim_overlays||{}, // the legend DIMENSIONS toggles {bolt_pitch,edge_clearance,cope_size} — the 3D view derives + filters overlays from this
4952
4967
  // dims3d is model-global: mutate + persist directly. NOT via edit() — a plan-scoped undo snapshot would corrupt dims3d across plans (undo on plan A could wipe dims added on plan B), and edit()'s sync3D would needlessly re-extrude every member mesh for a pure annotation. boot() guarantees C.dims3d is an array.
4953
4968
  onAddDim3d:(dim)=>{C.dims3d.push(dim);scheduleSave();refreshDims3d();},
4969
+ // "Add single line" committed from the 3D view. The picked points are scene mm; grid lines are stored in the
4970
+ // plan's display space, so invert exactly what buildStructGrid does to draw them (mmX=px*k, mmY=-px*k → Y flips).
4971
+ // Z is dropped on purpose: a grid line is a plan entity, drawn in 3D at every grid level.
4972
+ onAddGridLine3d:(a,b)=>{const gc=GC();if(!gc||!P){panel();return;} // no grid module / no active plan → repaint so the hint can't outlive a pick that cannot commit
4973
+ const k=gc.mmPerPx(P.pt_per_ft>0?P.pt_per_ft:1),toDisp=p=>[p[0]/k,-p[1]/k],pv=snapshot();
4974
+ if(gridAddFreeLine(toDisp(a),toDisp(b),null,GRID_LINE_MIN_DISP)){pushUndo(pv);gridCancelLinePick();render();refresh3DGrid();}else panel();}, // rejected (too short) → keep the pick armed and let the user retry the 2nd point, same as 2D
4975
+ onGridLinePickStep:()=>panel(), // first point placed in 3D → repaint the panel hint ("Pick the second point")
4976
+ onGridLinePickCancel:()=>gridCancelLinePick(), // Esc in the 3D view cancels the pick (grid mode stays)
4954
4977
  onSnapOnlyChanged:()=>updSnapStat(), // keep the header snap-override chip honest for every 3D-side clear (tool disarm etc.)
4955
4978
  onDeleteDim3d:(id)=>{C.dims3d=(C.dims3d||[]).filter(x=>x.id!==id);sel3dDimIds.delete(id);scheduleSave();refreshDims3d();},
4956
4979
  onSelectDim3d:(id,mods)=>{ // Ctrl/Shift multi-select (same as parts); selecting a dim is exclusive with member/2D-dim/clip selection
@@ -6884,6 +6907,7 @@ function setPlan(i){C.active=i;P=C.plans[i];
6884
6907
  if(!P.autofilled){autofillTOS();P.autofilled=true;}
6885
6908
  const ds=new Set([...(P.details||[]).map(d=>d.text),...Object.keys(C.custom_details)]);document.getElementById('detailsBtn').textContent='Details ('+ds.size+')';
6886
6909
  setMode();render();fitToWindow();
6910
+ refresh3DGrid(); // the grid is PER-PLAN, so a plan switch must re-render it in 3D too. The plan <select> is 2D-only, but the Confidence report's Locate buttons switch sheets from 3D — without this the 3D view keeps drawing the OLD sheet's grid while snapping reads the NEW sheet's (found by Codex on the grid-level review)
6887
6911
  const ps=document.getElementById('planSel');if(ps)ps.value=String(i);}
6888
6912
  const planSel=document.getElementById('planSel');
6889
6913
  planSel.innerHTML=C.plans.map((p,i)=>`<option value="${i}">${esc(p.sheet)} · ${esc(p.title)}</option>`).join('');
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.104.0",
3
+ "version": "0.104.2",
4
4
  "type": "module",
5
- "description": "Thin localhost host for floless.app \u2014 serves web/ and shells the aware CLI. No engine, no LLM.",
5
+ "description": "Thin localhost host for floless.app — serves web/ and shells the aware CLI. No engine, no LLM.",
6
6
  "bin": {
7
7
  "floless-app": "bin/floless.mjs"
8
8
  },