@floless/app 0.95.1 → 0.96.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.
@@ -53106,7 +53106,7 @@ function appVersion() {
53106
53106
  return resolveVersion({
53107
53107
  isSea: isSea2(),
53108
53108
  sqVersionXml: readSqVersionXml(),
53109
- define: true ? "0.95.1" : void 0,
53109
+ define: true ? "0.96.0" : void 0,
53110
53110
  pkgVersion: readPkgVersion()
53111
53111
  });
53112
53112
  }
@@ -53116,7 +53116,7 @@ function resolveChannel(s) {
53116
53116
  return "dev";
53117
53117
  }
53118
53118
  function appChannel() {
53119
- return resolveChannel({ isSea: isSea2(), define: true ? "0.95.1" : void 0 });
53119
+ return resolveChannel({ isSea: isSea2(), define: true ? "0.96.0" : void 0 });
53120
53120
  }
53121
53121
 
53122
53122
  // workflow-update.ts
@@ -125,7 +125,7 @@ function closestOnSeg(p, a, b) {
125
125
 
126
126
  /** The 3D point a candidate proposes for the dragged point. */
127
127
  function candidatePoint(c, dragged) {
128
- if (c.type === 'vertex' || c.type === 'intersection' || c.type === 'midpoint' || c.type === 'level' || c.type === 'origin') return c.p; // fixed points
128
+ if (c.type === 'vertex' || c.type === 'intersection' || c.type === 'midpoint' || c.type === 'level' || c.type === 'origin' || c.type === 'origin-grid') return c.p; // fixed points (origin-grid = a quantized lattice node, UCS Stage 6)
129
129
  if (c.type === 'vertical-axis') return [c.p[0], c.p[1], dragged[2]]; // lock plan X/Y to the axis, keep dragged Z
130
130
  if (c.type === 'grid-int') return [c.p[0], c.p[1], dragged[2]]; // grid steers PLAN only — never yanks the elevation
131
131
  if (c.type === 'grid-line') { const q = closestOnSeg(dragged, c.a, c.b); return [q[0], q[1], dragged[2]]; }
@@ -261,6 +261,24 @@ export function frameFromAngle(origin, angleRad) {
261
261
  return { origin: [origin[0], origin[1], origin[2]], xAxis: [c, s, 0], yAxis: [-s, c, 0], normal: [0, 0, 1] };
262
262
  }
263
263
 
264
+ /**
265
+ * UCS Stage 6 — origin-relative snap: quantize a WORLD point to the nearest node of a lattice of spacing
266
+ * `incMm` measured FROM the frame origin ALONG its rotated local axes (worldToLocal → round each local coord
267
+ * to the increment → localToWorld). Returns a world point (3 finite mm), or null when it can't produce a
268
+ * finite node — no frame (null), `incMm` not a positive finite number, a non-array point, or a non-finite
269
+ * result (the single fail-closed guard so a garbage increment/point never reaches geometry). Opt-in: the caller
270
+ * competes
271
+ * this ONE node against real geometry in snapPoint, where the 'origin-grid' type has the lowest precedence, so
272
+ * a real vertex/intersection always wins — the grid only catches a free click, never drowns geometry snap.
273
+ */
274
+ export function snapGridPoint(p, frame, incMm) {
275
+ if (!frame || !Array.isArray(p) || !Number.isFinite(incMm) || !(incMm > 0)) return null;
276
+ const l = worldToLocal(p, frame);
277
+ const q = [Math.round(l[0] / incMm) * incMm, Math.round(l[1] / incMm) * incMm, Math.round(l[2] / incMm) * incMm];
278
+ const w = localToWorld(q, frame);
279
+ return (Number.isFinite(w[0]) && Number.isFinite(w[1]) && Number.isFinite(w[2])) ? w : null;
280
+ }
281
+
264
282
  /**
265
283
  * Typed coordinate entry (UCS Stage 3) — the ONE pure seam Move/Copy + Add both route through. Given a
266
284
  * parsed component triple + a `provided` mask (which slots the user actually typed), a mode, the anchor in
@@ -359,6 +377,21 @@ export function sanitizeDims3d(arr) {
359
377
  * valueMm = that component's length. Returns the drawn endpoints, the midpoint (where the label
360
378
  * sits), and the measured length in mm.
361
379
  */
380
+ /**
381
+ * The axis key in `axesMap` whose direction the span a→b is most aligned with (largest |dot|). Pure.
382
+ * `axesMap` = { key: [x,y,z] world unit vector, ... } (a subset of the locked axes). Used to resolve a
383
+ * multi-axis dimension lock (X+Z) to the ONE axis the measured span runs most along. null iff the map is empty.
384
+ */
385
+ export function dominantAxis3d(a, b, axesMap) {
386
+ const d = [b[0] - a[0], b[1] - a[1], b[2] - a[2]];
387
+ let best = null, bestScore = -1;
388
+ for (const k in axesMap) {
389
+ const v = axesMap[k], s = Math.abs(d[0] * v[0] + d[1] * v[1] + d[2] * v[2]);
390
+ if (s > bestScore) { bestScore = s; best = k; }
391
+ }
392
+ return best;
393
+ }
394
+
362
395
  export function dim3dGeom(a, b, axis, axisDir) {
363
396
  const p1 = [a[0], a[1], a[2]];
364
397
  const u = (axis === 'x' || axis === 'y') ? unitOrNull(axisDir) : null; // z/free never project onto axisDir
@@ -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, planeBasis, planeFrom3Points, vecToPlane, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane } 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 } from './steel-3d-core.js';
21
21
  import { gridGeometry, gridCandidates3d, mmPerPx } 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)';
@@ -99,7 +99,7 @@ function candOnActiveWP(c, dragged, wp) {
99
99
  return candidateOnPlane(c, dragged, wp.origin, wp.normal, WP_SNAP_TOL_MM);
100
100
  }
101
101
  let rightDownXY = null, rightMoved = false; // right button: dragged (= orbit/pan, no menu) vs clicked (= snap menu)
102
- let dimAxis3d = 'free'; // sticky axis: free | x | y | z
102
+ const dimLock = new Set(); // locked MEASURE axes (subset of x|y|z); empty = Free/aligned. Toggle+combine like Move/Copy's tfLock (measures along the resolved/dominant axis; the 2nd point still free-snaps).
103
103
  let dims3dVisibleFlag = true; // show/hide placed dims
104
104
  let dimDraft3d = null; // { a:[x,y,z] } once the first point is placed (awaiting the 2nd)
105
105
  let dimLastAlt = false; // last-seen Alt state (the hover rAF rebuilds a synthetic event)
@@ -1607,10 +1607,10 @@ function onKey(e) {
1607
1607
  if (k === 'd' && !e.ctrlKey && !e.metaKey && !e.altKey && !midGesture) { e.preventDefault(); toggleDimTool(); return; } // D arms/disarms the dimension tool
1608
1608
  if (dimMode3d && !midGesture) {
1609
1609
  if (k === 'escape') { e.preventDefault(); if (snapOnly3d) setSnapOnly3d(null); else if (dimDraft3d) { dimDraft3d = null; dimPreviewLine.visible = false; readout.style.display = 'none'; } else toggleDimTool(); return; } // Esc steps back: drop the snap override → cancel the in-progress dim → exit the tool (mirrors the 2D two-step)
1610
- if (k === 'f' || k === 'x' || k === 'y' || k === 'z') { e.preventDefault(); setDimAxis(k === 'f' ? 'free' : k); reflectDimAxisBar(); return; } // sticky axis: Free / X / Y / Z
1610
+ if (k === 'f' || k === 'x' || k === 'y' || k === 'z') { e.preventDefault(); setDimAxis(k); return; } // toggle+combine the measure-axis lock: Free / X / Y / Z (setDimAxis refreshes the bar + chip)
1611
1611
  }
1612
1612
  // Named-view shortcuts mirror the ViewCube faces (parity with AWARE viewer-3d): T/F/R/B/L snap to an ortho view.
1613
- if (VIEW_KEYS[k] && !cmActive() && !wpMode && !e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey) { e.preventDefault(); applyView(VIEW_KEYS[k]); return; } // while Move/Copy or a set-plane pick is armed, F belongs to the axis force — not the Front view (review finding)
1613
+ if (VIEW_KEYS[k] && !cmActive() && (k !== 'f' || !addActive()) && !wpMode && !e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey) { e.preventDefault(); applyView(VIEW_KEYS[k]); return; } // while Move/Copy or a set-plane pick is armed, no view key fires (unchanged); while Add is armed only F is claimed (axis-lock clear) — T/R/B/L still switch views (review finding)
1614
1614
  const a = ARROWS[e.key]; if (!a) return;
1615
1615
  const [hx, hy] = a;
1616
1616
  if (e.ctrlKey || e.metaKey) { e.preventDefault(); rotateView(-hx * Math.PI / 12, hy * Math.PI / 12); } // 15°
@@ -1627,8 +1627,28 @@ function toggleDimTool() {
1627
1627
  }
1628
1628
  // snap override setter — notifies the host page so its header chip stays in sync with every clear path
1629
1629
  function setSnapOnly3d(k) { snapOnly3d = k || null; if (api && api.onSnapOnlyChanged) api.onSnapOnlyChanged(); }
1630
- function setDimAxis(a) { if (['free', 'x', 'y', 'z'].includes(a)) dimAxis3d = a; }
1631
- function dimAxis() { return dimAxis3d; }
1630
+ // X/Y/Z each TOGGLE the measure axis in the lock set (press again to release; combine 2–3 → the dim measures along
1631
+ // whichever locked axis the span runs most along); F/free clears → aligned. Refreshes the bar + chip so a key press
1632
+ // then a click without moving measures what's shown.
1633
+ function setDimAxis(a) {
1634
+ if (a === 'free' || a === 'f') dimLock.clear();
1635
+ else if (a === 'x' || a === 'y' || a === 'z') { if (dimLock.has(a)) dimLock.delete(a); else dimLock.add(a); }
1636
+ reflectDimAxisBar(); updateStatusChip();
1637
+ if (dimMode3d) dimHoverPreview(dimLastAlt); // refresh the preview line SYNCHRONOUSLY so a key/button then an immediate click measures what's shown (mirrors setCmAxis; no RAF lag)
1638
+ }
1639
+ function dimAxis() { return [...dimLock]; } // the locked measure axes (empty = free/aligned)
1640
+ // The frame-aware label for a measure axis: X/Y/Z global, X′/Y′/Elev under a local frame, World X/World Y/Elev under
1641
+ // a ◇ Plane (the single source the buttons AND the chip use, so they never disagree — ui-ux review).
1642
+ function dimAxisLabel(a) {
1643
+ const framed = !!frame3d && !workPlane, planed = !!workPlane;
1644
+ if (a === 'x') return planed ? 'World X' : framed ? 'X′' : 'X';
1645
+ if (a === 'y') return planed ? 'World Y' : framed ? 'Y′' : 'Y';
1646
+ if (a === 'z') return (framed || planed) ? 'Elev' : 'Z';
1647
+ return '';
1648
+ }
1649
+ // "measuring" (NOT "locked") — a dimension only changes the MEASURED direction; the 2nd point still free-snaps
1650
+ // (unlike Move/Copy, whose pick is truly axis-constrained). Frame-aware via dimAxisLabel.
1651
+ function dimLockChipTxt() { const _l = ['x', 'y', 'z'].filter((a) => dimLock.has(a)); return _l.length ? ' · measuring ' + _l.map(dimAxisLabel).join(', ') : ''; }
1632
1652
  function setDims3dVisible(on) { dims3dVisibleFlag = !!on; refreshDims(); }
1633
1653
  function dims3dVisible() { return dims3dVisibleFlag; }
1634
1654
  function reflectDimBar() {
@@ -1643,20 +1663,17 @@ function reflectDimBar() {
1643
1663
  // · a ◇ Plane set (shadows the frame) → World X / World Y / Elev + a tip: dims IGNORE the plane (they go global)
1644
1664
  function reflectDimAxisBar() {
1645
1665
  const framed = !!frame3d && !workPlane, planed = !!workPlane;
1646
- const LBL = {
1647
- x: planed ? 'World X' : framed ? 'X′' : 'X',
1648
- y: planed ? 'World Y' : framed ? 'Y′' : 'Y',
1649
- z: (framed || planed) ? 'Elev' : 'Z',
1650
- };
1651
1666
  const TIP = {
1652
- x: planed ? 'Dims measure WORLD X, not the ◇ Plane (X)' : framed ? 'Measure along the local frame X′ (X)' : 'Lock measurement to X (X)',
1653
- y: planed ? 'Dims measure WORLD Y, not the ◇ Plane (Y)' : framed ? 'Measure along the local frame Y′ (Y)' : 'Lock measurement to Y (Y)',
1654
- z: (framed || planed) ? 'World Z — stays vertical even with a tilted frame (Z); Alt = quick vertical' : 'Lock to Z / vertical (Z); Alt = quick vertical',
1667
+ x: planed ? 'Dims measure WORLD X, not the ◇ Plane — combine with Y/Z (X)' : framed ? 'Measure along the local frame X′ — combine with Y/Z (X)' : 'Measure along X — combine with Y/Z (X)',
1668
+ y: planed ? 'Dims measure WORLD Y, not the ◇ Plane — combine with X/Z (Y)' : framed ? 'Measure along the local frame Y′ — combine with X/Z (Y)' : 'Measure along Y — combine with X/Z (Y)',
1669
+ z: (framed || planed) ? 'World Z — stays vertical even with a tilted frame; combine with X/Y (Z); Alt = quick vertical' : 'Measure along Z / vertical — combine with X/Y (Z); Alt = quick vertical',
1655
1670
  };
1656
1671
  document.querySelectorAll('#m3dDimAxis button').forEach((x) => {
1657
1672
  const a = x.dataset.d3axis;
1658
- x.classList.toggle('on', a === dimAxis3d);
1659
- if (a && LBL[a]) { x.textContent = LBL[a]; x.dataset.tip = TIP[a]; } // free button untouched (no LBL entry)
1673
+ const on = a === 'free' ? dimLock.size === 0 : dimLock.has(a);
1674
+ x.classList.toggle('on', on); // Free lit when nothing is locked; X/Y/Z lit per the lock set (multiple can be on)
1675
+ x.setAttribute('aria-pressed', String(on)); // multi-select toggle group → aria-pressed is the correct state (ui-ux review)
1676
+ if (a && dimAxisLabel(a)) { x.textContent = dimAxisLabel(a); x.dataset.tip = TIP[a]; } // frame-aware label (shared with the chip); free button untouched
1660
1677
  });
1661
1678
  }
1662
1679
  // "Zoom to detail": double-click a part → zoom to a tight region around the click point so a connection
@@ -2709,20 +2726,40 @@ function setCmAxis(a, shiftHeld) {
2709
2726
  // Refresh the ghost/readout NOW so a key press then a click WITHOUT moving commits what's shown. The
2710
2727
  // editor's axis-key handler fires only with Alt UP, so use altKey:false (NOT the stale hover mirror
2711
2728
  // dimLastAlt, which lags a modifier released without a pointer move); Shift comes live from the key event.
2712
- if (tfDraft && lastHoverXY) tfPreview({ clientX: lastHoverXY[0], clientY: lastHoverXY[1], altKey: false, shiftKey: !!shiftHeld });
2729
+ const ev = lastHoverXY ? { clientX: lastHoverXY[0], clientY: lastHoverXY[1], altKey: false, shiftKey: !!shiftHeld } : null;
2730
+ if (ev && tfDraft) tfPreview(ev); // Move/Copy ghost
2731
+ else if (ev && addActive() && drDraft) drPreview(ev); // Add-member rubber band — refresh so a key-then-click commits what's shown
2713
2732
  updateStatusChip();
2714
2733
  }
2715
2734
  function cmClear3d() { tfDraft = null; tfCandidates = null; tfLock.clear(); tfPreviewClear(); if (canvasEl) canvasEl.style.cursor = 'default'; } // callable BEFORE init() (editor boot) — every touched handle is guarded
2716
2735
  function cmEscape() { if (!tfDraft) return false; if (tfDraft.vA) { tfDraft.vA = null; tfPreviewClear(); return true; } tfDraft = null; tfPreviewClear(); return true; }
2717
2736
  function tfDisposeGhost() { if (!tfGhost) return; if (scene) scene.remove(tfGhost); for (const c of tfGhost.children) { if (c.userData._ownGeom && c.geometry) c.geometry.dispose(); } tfGhost = null; } // clones share the source geometry/material; only the >600 fallback BoxGeometry is per-ghost → dispose those (flagged _ownGeom) so the preview can't leak
2718
2737
  function tfPreviewClear() { tfDisposeGhost(); if (tfRubber) tfRubber.visible = false; if (tfRubberA) tfRubberA.visible = false; if (marker) marker.visible = false; if (readout) readout.style.display = 'none'; }
2738
+ // UCS Stage 6 — origin-relative snap (opt-in, OFF by default). ONE candidate: the cursor quantized to the
2739
+ // nearest node of a lattice measured FROM the local-frame origin ALONG its rotated axes (snapGridPoint).
2740
+ // Injected per-hover here because allCandidates is cached + cursorless — a lattice node depends on the cursor.
2741
+ // It competes in snapPoint at the lowest precedence (type 'origin-grid' → PRECEDENCE default), so a real
2742
+ // vertex/intersection always wins; the grid only catches a FREE click and never drowns geometry snap.
2743
+ // Requires an UNSHADOWED local frame (a UCS origin to measure from): a set ◇ Plane shadows frame3d for every
2744
+ // drawing tool (chip reads "Plane"), so the grid — a frame3d-axes feature — is dormant under a plane too, the
2745
+ // same way Stage-5 dims ignore a shadowed frame. A transient snap override (one-type or 'none') or the host
2746
+ // toggle being off also suppresses it. NOT gated by candOnActiveWP: that level constraint is measured against
2747
+ // effectiveWP (which can differ in Z from the frame origin), whereas the grid deliberately measures from
2748
+ // frame3d.origin — the "3D snapping" toggle governs GEOMETRY snapping, not this explicit opt-in grid.
2749
+ function gridSnapCand(p) {
2750
+ if (!frame3d || workPlane || snapOnly3d || !api || !api.originGrid) return [];
2751
+ const g = api.originGrid(); if (!g || !g.on) return [];
2752
+ const node = snapGridPoint(p, frame3d, g.incMm);
2753
+ return node ? [{ type: 'origin-grid', p: node, fromId: 'ucs-grid' }] : [];
2754
+ }
2755
+
2719
2756
  // snapped pick projected onto the working plane (Tekla: snaps win, then land on the plane)
2720
2757
  function wpPointAt(e) {
2721
2758
  const wp = effectiveWP();
2722
2759
  const hit = rayToWP(e.clientX, e.clientY, wp); if (!hit) return null;
2723
2760
  if (!e.altKey) {
2724
2761
  if (!tfCandidates) tfCandidates = allCandidates(null); // members + grid, so Move/Copy + draw-on-plane snap to the grid too
2725
- const cands = tfCandidates.filter((c) => candAllowed3d(c.type) && candOnActiveWP(c, hit, wp)); // running-snaps / override, then (3D toggle off) the working-plane constraint
2762
+ const cands = tfCandidates.filter((c) => candAllowed3d(c.type) && candOnActiveWP(c, hit, wp)).concat(gridSnapCand(hit)); // running-snaps / override, then (3D toggle off) the working-plane constraint; opt-in origin grid rides on top (its own precedence)
2726
2763
  const r = snapPoint(hit, cands, toScreen, SNAP_TOL_PX);
2727
2764
  if (r.candidate) return { p: r.snapped, snap: true, type: r.candidate.type }; // land on the TRUE 3D snap (member end / grid) when the SNAP-bar 3D toggle is ON — free to the whole model, same as global (Pawel D5); OFF constrains to the working plane above; a free (non-snapped) click still rides the plane below
2728
2765
  }
@@ -2736,8 +2773,9 @@ function frameBasis() { const wp = effectiveWP(), b = planeBasis(wp.normal, wp.x
2736
2773
  // offset when the cursor nears the horizon (the axis grazes the view). Edge-on axis (its screen projection
2737
2774
  // collapses because you're looking down it): a ~vertical axis falls back to screen-Y → Z (Top view); any
2738
2775
  // other axis → no move. A ~vertical axis then snaps t to the framing levels. X/Y/Z + Alt normal-lock alike.
2739
- function cmAxisLock(e, axisVec) {
2740
- const base = tfDraft.base, n = _unit3(axisVec), bs = toScreen(base), rect = canvasEl.getBoundingClientRect();
2776
+ function cmAxisLock(e, axisVec, base, opts) {
2777
+ base = base || tfDraft.base; // Move/Copy passes tfDraft.base; Add passes drDraft (shared line-lock)
2778
+ const n = _unit3(axisVec), bs = toScreen(base), rect = canvasEl.getBoundingClientRect();
2741
2779
  const sc = pxToWorldAt(120, base) || 1; // a world length that spans ~120 px at the base
2742
2780
  const q = toScreen([base[0] + n[0] * sc, base[1] + n[1] * sc, base[2] + n[2] * sc]);
2743
2781
  const sdx = q.x - bs.x, sdy = q.y - bs.y, slen = Math.hypot(sdx, sdy); // the axis's screen vector for `sc` world units
@@ -2752,7 +2790,7 @@ function cmAxisLock(e, axisVec) {
2752
2790
  if (!Number.isFinite(t)) t = 0; // never commit a NaN offset
2753
2791
  let p = [base[0] + n[0] * t, base[1] + n[1] * t, base[2] + n[2] * t];
2754
2792
  let snap = false, type = null;
2755
- if (Math.abs(n[2]) > 0.999) { // ~vertical axis → snap the elevation to a framing level (WORLD-space: in Top view all levels share one screen point)
2793
+ if (Math.abs(n[2]) > 0.999 && !(opts && opts.noSnap)) { // ~vertical axis → snap the elevation to a framing level (WORLD-space: in Top view all levels share one screen point); Add+Alt passes noSnap so "no snap" holds even under a lock
2756
2794
  const tol = pxToWorldAt(SNAP_TOL_PX, base);
2757
2795
  let best = null, bestD = tol;
2758
2796
  for (const z of elevationLevels(members(), api.ptPerFt(), api.defaultTosMm(), null)) { const d = Math.abs(p[2] - z); if (d <= bestD) { bestD = d; best = z; } }
@@ -2763,8 +2801,9 @@ function cmAxisLock(e, axisVec) {
2763
2801
  // Among `axes` (basis keys), the ONE the cursor is dragging toward: the axis whose SCREEN direction best
2764
2802
  // matches the cursor's screen move from the base (|cos|). Lets a 2-axis lock (X+Z) snap the move to X or Z
2765
2803
  // (whichever you lean toward), and Shift pick the dominant in-plane axis — one straight axis, never diagonal.
2766
- function dominantAmong(e, axes) {
2767
- const base = tfDraft.base, bs = toScreen(base), rect = canvasEl.getBoundingClientRect();
2804
+ function dominantAmong(e, axes, base) {
2805
+ base = base || tfDraft.base;
2806
+ const bs = toScreen(base), rect = canvasEl.getBoundingClientRect();
2768
2807
  const cx = (e.clientX - rect.left) - bs.x, cy = (e.clientY - rect.top) - bs.y, cl = Math.hypot(cx, cy) || 1;
2769
2808
  const bv = frameBasis(), sc = pxToWorldAt(120, base) || 1; // world length spanning ~120 px → a well-conditioned axis screen vector
2770
2809
  let best = axes[0], bestScore = -1;
@@ -2778,21 +2817,24 @@ function dominantAmong(e, axes) {
2778
2817
  }
2779
2818
  // The single axis the move is line-locked to ('u'|'v'|'n'), or null = free. Precedence: Alt (normal) >
2780
2819
  // Shift (dominant in-plane) > the sticky lock set (the lone locked axis, or the dominant of two).
2781
- function cmEffAxis(e) {
2782
- if (!tfDraft) return null;
2783
- if (e && e.altKey) return 'n';
2784
- if (e && e.shiftKey) return dominantAmong(e, ['u', 'v']);
2820
+ function cmEffAxis(e, base, opts) {
2821
+ base = base || (tfDraft && tfDraft.base);
2822
+ if (!base) return null;
2823
+ if (e && e.altKey && !(opts && opts.noAlt)) return 'n'; // Alt = normal-lock (Move/Copy); Add passes noAlt so its Alt stays "no snap"
2824
+ if (e && e.shiftKey) return dominantAmong(e, ['u', 'v'], base);
2785
2825
  if (!tfLock.size) return null; // no lock → free
2786
- return tfLock.size === 1 ? [...tfLock][0] : dominantAmong(e, [...tfLock]); // 1 = that axis; 2 or 3 = whichever locked axis the cursor drags toward
2787
- }
2788
- // Resolve the Move/Copy destination: a line-lock along the effective axis (ray-to-axis), else the free
2789
- // working-plane pick (with snapping). null = no valid pick (cursor off the plane, edge-on).
2790
- function cmDestPoint(e) {
2791
- const ax = cmEffAxis(e);
2792
- if (ax) return cmAxisLock(e, frameBasis()[ax]);
2826
+ return tfLock.size === 1 ? [...tfLock][0] : dominantAmong(e, [...tfLock], base); // 1 = that axis; 2 or 3 = whichever locked axis the cursor drags toward
2827
+ }
2828
+ // Resolve a 2nd-point destination from a base: a line-lock along the effective axis (screen-space drag), else the
2829
+ // free working-plane pick (with snapping). null = no valid pick (cursor off the plane, edge-on). Shared by Move/Copy
2830
+ // (base = tfDraft.base) and Add-member (base = drDraft) — the SAME lock (tfLock), the tools being mutually exclusive.
2831
+ function cmDestPointFrom(e, base) {
2832
+ const ax = cmEffAxis(e, base);
2833
+ if (ax) return cmAxisLock(e, frameBasis()[ax], base);
2793
2834
  const r = wpPointAt(e); if (!r) return null;
2794
2835
  return { p: r.p, snap: r.snap, type: r.type };
2795
2836
  }
2837
+ function cmDestPoint(e) { return cmDestPointFrom(e, tfDraft && tfDraft.base); } // Move/Copy destination; base may be null before the base pick (cmEffAxis then returns null → free) — do NOT deref tfDraft eagerly
2796
2838
  // the offset list is the pure core `offsetsFor` (unit-tested for linear/grid) — counts INCLUDE the original, grid skips (0,0)
2797
2839
  function tfOffsetsFor(v, st) { return offsetsFor(v, st, tfDraft ? tfDraft.vA : null); }
2798
2840
  function tfGhostBuild(offs) {
@@ -2913,12 +2955,7 @@ function drHudApply(pv, abs) {
2913
2955
  let drDraft = null; // first pick, scene mm
2914
2956
  let drRubber = null;
2915
2957
  const addActive = () => !!(api && api.addModeActive && api.addModeActive());
2916
- function drClear3d() { drDraft = null; if (drRubber) drRubber.visible = false; if (marker) marker.visible = false; if (readout) readout.style.display = 'none'; } // callable pre-init (all handles guarded)
2917
- function drShiftLock(p, e) { // Shift = ortho along the plane's local axes (same basis as Move/Copy)
2918
- if (!e || !e.shiftKey || !drDraft) return p;
2919
- const wp = effectiveWP(), { u, v } = planeBasis(wp.normal, wp.xAxis), d = [p[0] - drDraft[0], p[1] - drDraft[1], p[2] - drDraft[2]], c = vecToPlane(d, u, v, wp.normal);
2920
- return Math.abs(c.du) >= Math.abs(c.dv) ? [drDraft[0] + c.du * u[0], drDraft[1] + c.du * u[1], drDraft[2] + c.du * u[2]] : [drDraft[0] + c.dv * v[0], drDraft[1] + c.dv * v[1], drDraft[2] + c.dv * v[2]];
2921
- }
2958
+ function drClear3d() { drDraft = null; tfLock.clear(); if (drRubber) drRubber.visible = false; if (marker) marker.visible = false; if (readout) readout.style.display = 'none'; } // callable pre-init (all handles guarded); clears the shared axis lock on Add disarm (mirrors cmClear3d)
2922
2959
  // The shared "commit the 2nd draw point" transition — used by both the pointer (drClick) and typed entry
2923
2960
  // (drHudApply). Clears local draw state BEFORE the geometry callback so the reentrant rebuild is safe.
2924
2961
  function commitDrawPoint(p2) {
@@ -2928,17 +2965,26 @@ function commitDrawPoint(p2) {
2928
2965
  if (start && api && api.onAddMember3d) api.onAddMember3d(start, p2);
2929
2966
  }
2930
2967
  function drClick(e) {
2931
- const r = wpPointAt(e); if (!r) return;
2932
- if (!drDraft) { notePointerPick(); drDraft = r.p; return; } // start pick bumps the gen so an open first-point typed token can't survive
2933
- const p = drShiftLock(r.p, e);
2968
+ if (!drDraft) { const r0 = wpPointAt(e); if (!r0) return; notePointerPick(); drDraft = r0.p; return; } // start pick = free (bumps the gen so an open first-point typed token can't survive)
2969
+ const r = drDestPoint(e); if (!r) return; // 2nd pick: X/Y/Z line-lock (or Alt normal) if locked, else free snap
2970
+ const p = r.p;
2934
2971
  if (Math.hypot(p[0] - drDraft[0], p[1] - drDraft[1], p[2] - drDraft[2]) < 50) return; // ~<2in — ignore a doubled click (pointer only; typed uses a sub-mm epsilon)
2935
2972
  commitDrawPoint(p);
2936
2973
  }
2974
+ // Add-member 2nd-point resolver — the SAME axis-lock as Move/Copy (base = drDraft): drawing a member strictly along
2975
+ // local X/Y/Z (the 'z' key locks the normal), toggle+combine + Shift(dominant in-plane), with level-snap; else a
2976
+ // free working-plane snap. Add's Alt stays "no snap" (noAlt), NOT normal-lock — a member you draw off-geometry.
2977
+ function drDestPoint(e) {
2978
+ const ax = cmEffAxis(e, drDraft, { noAlt: true });
2979
+ if (ax) return cmAxisLock(e, frameBasis()[ax], drDraft, { noSnap: !!(e && e.altKey) }); // Add's Alt = no snap even under a lock (skip the vertical level-snap)
2980
+ const r = wpPointAt(e); if (!r) return null; // Alt held here → wpPointAt returns the raw plane hit (no snap), preserved
2981
+ return { p: r.p, snap: r.snap, type: r.type };
2982
+ }
2937
2983
  function drPreview(e) {
2938
- const r = wpPointAt(e); if (!r) { if (readout) readout.style.display = 'none'; return; } // cursor off the plane (edge-on) → clear the chip, don't freeze the last readout
2984
+ if (!drDraft) { const r0 = wpPointAt(e); if (!r0) { if (readout) readout.style.display = 'none'; return; } if (r0.snap) showMarker(r0.p, r0.type); else marker.visible = false; roShowCoordOnly(r0.p, e.clientX, e.clientY); return; } // before the start pick: free snap + local coords
2985
+ const r = drDestPoint(e); if (!r) { if (readout) readout.style.display = 'none'; return; } // cursor off the plane (edge-on) → clear the chip, don't freeze the last readout
2939
2986
  if (r.snap) showMarker(r.p, r.type); else marker.visible = false;
2940
- if (!drDraft) { roShowCoordOnly(r.p, e.clientX, e.clientY); return; } // before the start pick: show the start point's local coords
2941
- const p = drShiftLock(r.p, e);
2987
+ const p = r.p;
2942
2988
  if (!drRubber) { drRubber = new THREE.Line(new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(), new THREE.Vector3()]), new THREE.LineBasicMaterial({ color: 0x22d3ee })); drRubber.material.depthTest = false; drRubber.renderOrder = 997; scene.add(drRubber); }
2943
2989
  drRubber.geometry.setFromPoints([new THREE.Vector3(...drDraft), new THREE.Vector3(...p)]); drRubber.visible = true;
2944
2990
  const L = Math.hypot(p[0] - drDraft[0], p[1] - drDraft[1], p[2] - drDraft[2]);
@@ -2977,6 +3023,7 @@ function makeReticleTexture(kind) {
2977
3023
  else if (kind === 'vbar') dual(() => { g.beginPath(); g.moveTo(cx, cy - r); g.lineTo(cx, cy + r); g.stroke(); }, 8, 14);
2978
3024
  else if (kind === 'square') dual(() => { g.beginPath(); g.rect(cx - r, cy - r, 2 * r, 2 * r); g.stroke(); }, 7, 13); // vertex/endpoint = square (CAD convention; matches the 2D endpoint marker)
2979
3025
  else if (kind === 'hourglass') dual(() => { g.beginPath(); g.moveTo(cx - r, cy - r); g.lineTo(cx + r, cy - r); g.lineTo(cx - r, cy + r); g.lineTo(cx + r, cy + r); g.closePath(); g.stroke(); }, 6, 12); // on-line ("nearest") = hourglass/clepsydra, matches the 2D marker
3026
+ else if (kind === 'plus') dual(() => { g.beginPath(); g.moveTo(cx - r, cy); g.lineTo(cx + r, cy); g.moveTo(cx, cy - r); g.lineTo(cx, cy + r); g.stroke(); }, 7, 13); // origin-grid node = upright plus (distinct from the × intersection glyph)
2980
3027
  else { g.fillStyle = HALO; g.beginPath(); g.arc(cx, cy, 11, 0, Math.PI * 2); g.fill(); g.fillStyle = CY; g.beginPath(); g.arc(cx, cy, 8, 0, Math.PI * 2); g.fill(); } // dot (fallback)
2981
3028
  const tex = new THREE.CanvasTexture(c); if (THREE.SRGBColorSpace) tex.colorSpace = THREE.SRGBColorSpace; tex.needsUpdate = true;
2982
3029
  return tex;
@@ -2986,6 +3033,7 @@ function reticleFor(type) {
2986
3033
  const k = (type === 'intersection' || type === 'grid-int') ? 'x' : type === 'midpoint' ? 'tri'
2987
3034
  : (type === 'centerline' || type === 'grid-line') ? 'hourglass' // snap ONTO a line = "nearest"
2988
3035
  : type === 'level' ? 'bar' // elevation level = horizontal bar
3036
+ : type === 'origin-grid' ? 'plus' // origin-relative grid node (UCS Stage 6)
2989
3037
  : type === 'vertical-axis' ? 'vbar' : type === 'vertex' ? 'square' : 'dot';
2990
3038
  return reticleTex[k] || (reticleTex[k] = makeReticleTexture(k));
2991
3039
  }
@@ -3036,7 +3084,19 @@ function gridPlaneZ() {
3036
3084
  }
3037
3085
  // The axis to measure on: Alt held during the 2nd pick forces a pure-vertical (Z) measurement,
3038
3086
  // overriding the sticky axis (else a sticky X/Y would collapse the Alt-locked point to zero length).
3039
- function dimEffectiveAxis(alt) { return alt && dimDraft3d ? 'z' : dimAxis3d; }
3087
+ // The ONE axis a dimension measures along, resolving the lock set: Alt (held on the 2nd pick) forces vertical Z;
3088
+ // empty lock → 'free' (aligned a→b); one locked axis → that; 2–3 locked → the axis the span a→b runs most along
3089
+ // (dominantAxis3d, by |component along the frame axis|). The 2nd point itself still free-snaps; only the measured
3090
+ // direction is constrained. Frame-aware: the resolved axis feeds dimAxisDir/dim3dGeom exactly as before.
3091
+ function dimEffAxis(alt, a, b) {
3092
+ if (alt && dimDraft3d) return 'z';
3093
+ if (!dimLock.size) return 'free';
3094
+ if (dimLock.size === 1) return [...dimLock][0];
3095
+ if (!a || !b) return [...dimLock][0]; // no span yet (1st-point preview) → the first locked axis
3096
+ const map = {};
3097
+ for (const k of dimLock) map[k] = dimAxisDir(k) || (k === 'x' ? [1, 0, 0] : k === 'y' ? [0, 1, 0] : [0, 0, 1]); // dominance uses the SAME axis the measurement will (dimAxisDir: frame X/Y or world; z always world elevation) — never pick one axis and measure another (review finding)
3098
+ return dominantAxis3d(a, b, map);
3099
+ }
3040
3100
  // UCS Stage 5: the world direction a frame-aware x|y dim measures along — the LOCAL frame's X/Y, captured at
3041
3101
  // placement so the dim survives frame changes/reset/reload. null when: no local frame; a ◇ Plane shadows the frame
3042
3102
  // (dims go global under a plane — never a SHADOWED frame3d, matching the chip/gizmo); or axis is z/free (world).
@@ -3078,7 +3138,7 @@ function onDown(e) {
3078
3138
  const r = dimPointAt(e, dimDraft3d && dimDraft3d.a); if (!r) return;
3079
3139
  if (!dimDraft3d) { dimDraft3d = { a: r.p }; dimCandidates3d = null; }
3080
3140
  else {
3081
- const a = dimDraft3d.a, b = r.p, axis = dimEffectiveAxis(e.altKey), axisDir = dimAxisDir(axis);
3141
+ const a = dimDraft3d.a, b = r.p, axis = dimEffAxis(e.altKey, a, b), axisDir = dimAxisDir(axis);
3082
3142
  const g = dim3dGeom(a, b, axis, axisDir);
3083
3143
  dimDraft3d = null; dimPreviewLine.visible = false; marker.visible = false; readout.style.display = 'none'; dimCandidates3d = null;
3084
3144
  if (g.valueMm > 1 && api && api.onAddDim3d) api.onAddDim3d({ id: api.newDim3dId(), a, b, axis, ...(axisDir ? { axisDir } : {}) });
@@ -3412,6 +3472,26 @@ function roShowCoordOnly(worldPt, x, y) {
3412
3472
  roCoords(worldPt);
3413
3473
  readout.style.left = (x + 14) + 'px'; readout.style.top = (y + 14) + 'px'; readout.style.display = 'block';
3414
3474
  }
3475
+ // Live dim preview (snap marker + preview line + readout) from lastHoverXY — SYNCHRONOUS, so setDimAxis can refresh it
3476
+ // immediately on a key/button (not one animation frame later); `alt` is the live modifier (dim measures Z on Alt).
3477
+ function dimHoverPreview(alt) {
3478
+ if (!dimPreviewLine || !canvasEl || !lastHoverXY) return;
3479
+ const r = dimPointAt({ clientX: lastHoverXY[0], clientY: lastHoverXY[1], altKey: alt }, dimDraft3d && dimDraft3d.a);
3480
+ const snapped = !!(r && r.type);
3481
+ if (snapped) showMarker(r.p, r.type); else marker.visible = false; // reticle only on a real snap (free point rides the preview line)
3482
+ canvasEl.style.cursor = snapped ? 'none' : 'crosshair'; // at a snap the reticle IS the cursor (Tekla) — hide the native crosshair
3483
+ if (dimDraft3d && r) {
3484
+ const ax = dimEffAxis(alt, dimDraft3d.a, r.p);
3485
+ const g = dim3dGeom(dimDraft3d.a, r.p, ax, dimAxisDir(ax)); // live preview matches what the commit will store
3486
+ dimPreviewLine.geometry.setFromPoints([new THREE.Vector3(...g.p1), new THREE.Vector3(...g.p2)]); dimPreviewLine.visible = true;
3487
+ readout._dist.textContent = api.fmtLen ? api.fmtLen(g.valueMm) : (g.valueMm / 304.8).toFixed(2) + ' ft';
3488
+ readout._type.textContent = (r.type ? ' · ' + r.type : (alt ? ' ↕' : '')) + dimLockChipTxt(); // show the measure-axis lock (· measuring X′) alongside the snap type
3489
+ readout.style.left = (lastHoverXY[0] + 14) + 'px'; readout.style.top = (lastHoverXY[1] + 14) + 'px'; readout.style.display = 'block';
3490
+ roCoords(r.p); // local coords of the second dim point
3491
+ } else { dimPreviewLine.visible = false;
3492
+ if (r && !dimDraft3d) roShowCoordOnly(r.p, lastHoverXY[0], lastHoverXY[1]); // first dim point: coords-only chip
3493
+ else if (readout) readout.style.display = 'none'; } // no point (or a draft with the cursor off-plane) → clear the chip
3494
+ }
3415
3495
  function onHoverMove(e) {
3416
3496
  lastHoverXY = [e.clientX, e.clientY];
3417
3497
  dimLastAlt = e.altKey; // remembered so the rAF body can rebuild a synthetic event
@@ -3449,25 +3529,7 @@ function onHoverMove(e) {
3449
3529
  if (r) roShowCoordOnly(r.p, lastHoverXY[0], lastHoverXY[1]); else if (readout) readout.style.display = 'none'; } // local coords of the base point before it's picked
3450
3530
  updateStatusChip(); return; }
3451
3531
  if (clipMode) { canvasEl.style.cursor = 'crosshair'; if (clipMode === 'box') clipBoxPreviewAt(lastHoverXY[0], lastHoverXY[1]); return; } // armed clip pick: crosshair (+ live box preview while drawing)
3452
- if (dimMode3d) { // dim tool: snap marker + live preview line + readout (no member hover)
3453
- const ev = { clientX: lastHoverXY[0], clientY: lastHoverXY[1], altKey: dimLastAlt };
3454
- const r = dimPointAt(ev, dimDraft3d && dimDraft3d.a);
3455
- const snapped = !!(r && r.type);
3456
- if (snapped) showMarker(r.p, r.type); else marker.visible = false; // reticle only on a real snap (free point rides the preview line) — parity with 2D snapClear
3457
- canvasEl.style.cursor = snapped ? 'none' : 'crosshair'; // at a snap the reticle IS the cursor (Tekla) — hide the native crosshair so it doesn't double up on the marker
3458
- if (dimDraft3d && r) {
3459
- const ax = dimEffectiveAxis(dimLastAlt);
3460
- const g = dim3dGeom(dimDraft3d.a, r.p, ax, dimAxisDir(ax)); // live preview matches what the commit will store
3461
- dimPreviewLine.geometry.setFromPoints([new THREE.Vector3(...g.p1), new THREE.Vector3(...g.p2)]); dimPreviewLine.visible = true;
3462
- readout._dist.textContent = api.fmtLen ? api.fmtLen(g.valueMm) : (g.valueMm / 304.8).toFixed(2) + ' ft';
3463
- readout._type.textContent = r.type ? ' · ' + r.type : (dimLastAlt ? ' ↕' : '');
3464
- readout.style.left = (lastHoverXY[0] + 14) + 'px'; readout.style.top = (lastHoverXY[1] + 14) + 'px'; readout.style.display = 'block';
3465
- roCoords(r.p); // local coords of the second dim point
3466
- } else { dimPreviewLine.visible = false;
3467
- if (r && !dimDraft3d) roShowCoordOnly(r.p, lastHoverXY[0], lastHoverXY[1]); // first dim point: coords-only chip
3468
- else if (readout) readout.style.display = 'none'; } // no point (or a draft with the cursor off-plane) → clear the chip, don't freeze the last readout
3469
- return;
3470
- }
3532
+ if (dimMode3d) { dimHoverPreview(dimLastAlt); return; } // dim tool: snap marker + live preview line + readout (extracted so setDimAxis can refresh it synchronously)
3471
3533
  if (framePicking()) { // 3-click UCS set in progress: live rubber-band X/Y + Z-flip arrow, snap marker at the cursor
3472
3534
  canvasEl.style.cursor = 'crosshair';
3473
3535
  renderFramePickPreview({ clientX: lastHoverXY[0], clientY: lastHoverXY[1], altKey: dimLastAlt });
@@ -3498,6 +3560,8 @@ function onHoverMove(e) {
3498
3560
  if (top !== hoverId) { setHover(top); updateStatusChip(); }
3499
3561
  });
3500
3562
  }
3563
+ // The shared axis-lock chip suffix (' · X, Y locked') from tfLock — used by both the Move/Copy and Add-member chips.
3564
+ function lockChipTxt() { const _lk = ['u', 'v', 'n'].filter((a) => tfLock.has(a)); return _lk.length ? ' · ' + _lk.map((a) => (a === 'u' ? 'X' : a === 'v' ? 'Y' : 'Z')).join(', ') + ' locked' : ''; }
3501
3565
  function updateStatusChip() {
3502
3566
  if (!hoverChip || !canvasEl) return;
3503
3567
  const rect = canvasEl.getBoundingClientRect();
@@ -3505,8 +3569,8 @@ function updateStatusChip() {
3505
3569
  const showId = hoverId || (selIds.size === 1 ? [...selIds][0] : null);
3506
3570
  if (wpMode === 'face') txt = 'Click a member face — the working plane lands on it · Esc to cancel';
3507
3571
  else if (wpMode === '3pt') txt = ['Click the plane origin (snapped) · Esc to cancel', 'Click the local-X direction point · Esc to cancel', 'Click a point on the plane’s Y side · Esc to cancel'][(wpDraft || []).length] || '';
3508
- else if (addActive()) txt = drDraft ? 'Click the member end · Shift straight · Esc drops the start' : 'Draw a member on the working plane — click the start point · Esc exits';
3509
- else if (cmActive()) { const st = cmActive(), _lk = ['u', 'v', 'n'].filter((a) => tfLock.has(a)), lock = _lk.length ? ' · ' + _lk.map((a) => (a === 'u' ? 'X' : a === 'v' ? 'Y' : 'Z')).join(', ') + ' locked' : '';
3572
+ else if (addActive()) txt = drDraft ? 'Click the member end · X/Y/Z lock to the local axes, Shift straight · Esc drops the start' + lockChipTxt() : 'Draw a member on the working plane — click the start point · Esc exits';
3573
+ else if (cmActive()) { const st = cmActive(), lock = lockChipTxt();
3510
3574
  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')
3511
3575
  : (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; }
3512
3576
  else if (clipMode === 'plane') txt = 'Click a face to set a clip plane · Esc to cancel';
@@ -3669,7 +3733,7 @@ window.Steel3DView = {
3669
3733
  coordReadout: () => { if (!readout || !readout._coord || readout.style.display === 'none' || readout._coord.style.display === 'none') return null; return { local: readout._coord.classList.contains('ro-local'), values: readout._coordV.map((v) => v.textContent), labels: readout._coordL.map((l) => l.textContent.trim()), text: readout._coord.textContent }; }, // UCS stage 2 test probe: the live local-coordinate row (null when hidden)
3670
3734
  cmEscape, cmHasBase, cmClear3d, setCmAxis, cmLastClient, cmHudApply,
3671
3735
  drHudApply, pointEntryBegin, pointEntryEnd, drHasStart: () => !!drDraft, // UCS stage 3: shared typed point-entry HUD (Move/Copy + Add)
3672
- drClear3d, drEscape: () => { if (drDraft) { drDraft = null; drClear3d(); return true; } return false; },
3736
+ drClear3d, drEscape: () => { if (drDraft) { drDraft = null; if (drRubber) drRubber.visible = false; if (marker) marker.visible = false; if (readout) readout.style.display = 'none'; return true; } return false; }, // Esc drops the START only — KEEP the axis lock (tfLock) so the next member reuses it (matches the chip + Move/Copy step-back); full disarm (drClear3d) clears the lock
3673
3737
  toggleDimTool, setDimAxis, dimAxis, setDims3dVisible, dims3dVisible, refreshDims,
3674
3738
  setSnapOnly: setSnapOnly3d, snapOnly: () => snapOnly3d, dimToolOn: () => dimMode3d, rightDragged: () => rightMoved, // Tekla-style snap override (right-click menu lives in steel-editor.html)
3675
3739
  refreshOverlayDims,
@@ -3678,6 +3742,10 @@ window.Steel3DView = {
3678
3742
  dims3dCount: () => (api && api.getDims3d ? (api.getDims3d() || []).length : 0),
3679
3743
  dims3dRecords: () => (api && api.getDims3d ? (api.getDims3d() || []).map((d) => ({ id: d.id, axis: d.axis, axisDir: d.axisDir || null, valueMm: dim3dGeom(d.a, d.b, d.axis, d.axisDir).valueMm })) : []), // test probe: lightweight per-dim {axis, axisDir, rendered length} for E2E assertions (frame-aware capture + read==write)
3680
3744
  dimAxisBarLabels: () => Array.from(document.querySelectorAll('#m3dDimAxis button')).map((b) => b.textContent), // test probe: the visible axis-control labels (3-state disclosure)
3745
+ dimLockSet: () => [...dimLock], // test probe: the dimension's locked measure axes (x|y|z)
3746
+ axisLockSet: () => [...tfLock], // test probe: the shared Move/Copy + Add line-lock set (u|v|n)
3747
+ addDraftPt: () => (drDraft ? [...drDraft] : null), // test probe: the Add-member first pick (scene mm), or null
3748
+ addDestAt: (x, y) => { if (!drDraft) return null; const r = drDestPoint({ clientX: x, clientY: y, shiftKey: false, altKey: false }); return r ? { p: r.p, snap: r.snap } : null; }, // test probe: the resolved 2nd draw point at a cursor (respects the axis lock) — read-only, no commit
3681
3749
  selDims3dCount: () => (api && api.selDim3d ? (api.selDim3d() || []).length : 0), // test helper: how many 3D dims are selected
3682
3750
  dim3dLabelOf: (i) => { const el = dimLabelPool[i]; if (!el || el.style.display === 'none') return null; const r = el.getBoundingClientRect(); return { x: r.left + r.width / 2, y: r.top + r.height / 2, text: el.textContent }; },
3683
3751
  debug, probe, screenOf, centerOf, worldOf, snapCandidatesScreen, clipHandlesScreen,
@@ -206,6 +206,14 @@
206
206
  .m3dmenu button.wtog.on{color:var(--text)} /* the slider carries the on-state — don't also brand the label text */
207
207
  #moreMenu button.msnap .sg{display:inline-block;width:17px;color:#22d3ee;opacity:.5;flex:none;transition:opacity .15s}
208
208
  #moreMenu button.msnap.on .sg{opacity:1}
209
+ /* UCS Stage 6 — origin-grid: a plain .msnap toggle (3D-only), then a Step sub-row revealed only when it's on. */
210
+ body:not(.v3d) #snapSect [data-s3donly]{display:none} body.v3d #snapSect [data-s3donly]{display:flex} /* body:not(.v3d) adds the specificity to beat the base #moreMenu button.msnap{display:flex} rule (else the 3D-only row leaks into the 2D menu) */
211
+ #moreMenu .msnap-sub{display:none;align-items:center;flex-wrap:wrap;gap:4px 8px;padding:2px 12px 6px 26px} /* indent to sit under the toggle's label; revealed via .on (and only in 3D) */
212
+ body.v3d #moreMenu .msnap-sub.on{display:flex}
213
+ #moreMenu .msnap-sub .msub-lbl{color:var(--mut);font-size:11px;flex:none}
214
+ #moreMenu .msnap-sub input{width:92px;height:24px;background:var(--bg);color:var(--text);border:1px solid var(--line);border-radius:5px;padding:0 7px;font:12px system-ui;box-sizing:border-box}
215
+ #moreMenu .msnap-sub input:focus{outline:none;border-color:var(--brand)}
216
+ #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 */
209
217
  /* Pointer-behaviour bars, bottom-right of the canvas (both views): [ Select filter ] [ Snap ]. Both reuse the brand-fill "on" toolbar language. */
210
218
  #ptrBars{position:absolute;right:12px;bottom:12px;z-index:8;display:flex;align-items:flex-end;gap:8px}
211
219
  #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) */
@@ -251,7 +259,7 @@
251
259
  /* The "3D" snap-MODE toggle is the inverse: 3D-only. A short text label (not an osnap glyph) → smaller/bolder; a hair-line divider before it marks it as a mode, not a peer snap type. */
252
260
  #snapBar [data-snap3d]{display:none;font-size:11px;font-weight:700;letter-spacing:.02em;margin-left:4px;border-left:1px solid var(--line);border-radius:0 5px 5px 0;padding-left:4px;box-sizing:border-box;width:32px}
253
261
  body.v3d #snapBar [data-snap3d]{display:grid}
254
- #snapSect [data-snap3d]{display:none}
262
+ body:not(.v3d) #snapSect [data-snap3d]{display:none} /* specificity to beat button.msnap{display:flex} — same 2D-leak fix as [data-s3donly] above */
255
263
  body.v3d #snapSect [data-snap3d]{display:flex}
256
264
  #moreMenu .mhint{color:var(--mut);font-size:11px;line-height:1.4;padding:4px 12px 6px;max-width:230px;white-space:normal}
257
265
  #rfiStat{cursor:pointer;text-decoration:underline dotted} #rfiStat:hover b{color:#fff}
@@ -731,7 +739,7 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
731
739
  <!-- 3D Dimension cluster — relocated here from the 3D toolbar so Dimension has ONE home; shown only in 3D (applyViewState). Same ids so steel-3d-view.js reflectDimBar() still drives it. -->
732
740
  <span id=dim3dWrap style="display:none;align-items:center;gap:8px">
733
741
  <button id=m3dDim data-tip="Measure in 3D — click two snapped points (D); the axis buttons follow the active coordinate frame (X′/Y′/Elev local, World X/Y under a ◇ Plane); Alt = vertical; right-click = restrict snap">⊢ Dimension</button>
734
- <div class=seg-group id=m3dDimAxis style="display:none"><button data-d3axis=free class=on data-tip="Free 3D measurement (F)">Free</button><button data-d3axis=x data-tip="Lock measurement to X (X)">X</button><button data-d3axis=y data-tip="Lock measurement to Y (Y)">Y</button><button data-d3axis=z data-tip="Lock to Z / vertical (Z); Alt = quick vertical">Z</button></div>
742
+ <div class=seg-group id=m3dDimAxis role=group aria-label="Dimension measure axis (X/Y/Z combine)" style="display:none"><button data-d3axis=free class=on aria-pressed=true data-tip="Free 3D measurement — clears the axis lock (F)">Free</button><button data-d3axis=x data-tip="Lock measurement to X (X)">X</button><button data-d3axis=y data-tip="Lock measurement to Y (Y)">Y</button><button data-d3axis=z data-tip="Lock to Z / vertical (Z); Alt = quick vertical">Z</button></div>
735
743
  <button id=m3dDimShow data-tip="Show or hide placed 3D dimensions" style="display:none">Hide dims</button>
736
744
  </span>
737
745
  <div class=cmwrap>
@@ -765,6 +773,8 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
765
773
  <button class="msnap" data-snap=par role=menuitemcheckbox aria-checked=false data-tip="Parallel — when you draw roughly parallel to a nearby line, snap the direction to exactly parallel."><span class=mck aria-hidden=true></span><span class=sg aria-hidden=true>∥</span>Parallel</button>
766
774
  <button class="msnap" data-snap=ext role=menuitemcheckbox aria-checked=false data-tip="Snap along the invisible extension of a member/line past its endpoint, with a dashed guide line"><span class=mck aria-hidden=true></span><span class=sg aria-hidden=true>┈</span>Extension</button>
767
775
  <button class="msnap on" data-snap3d role=menuitemcheckbox aria-checked=true data-tip="On: snap freely to any point in 3D, at any elevation. Off: snap only on the current working level. (3D view only.)"><span class=mck aria-hidden=true></span><span class=sg aria-hidden=true>◈</span>3D snapping</button>
776
+ <button class=msnap data-ogrid data-s3donly role=menuitemcheckbox aria-checked=false data-tip="On: also snap to a lattice measured from your local-axes origin, spaced by the Step, along the rotated axes — on top of geometry snapping (real geometry always wins). Does nothing until you set a local frame (3D). 3D view only."><span class=mck aria-hidden=true></span><span class=sg aria-hidden=true>▦</span>Origin grid</button>
777
+ <div class=msnap-sub data-ogrid-sub><span class=msub-lbl>Step</span><input id=ogridInc type=text inputmode=decimal autocomplete=off spellcheck=false aria-label="Origin grid step" data-tip="Distance between snap points along the local axes (feet-inches, e.g. 12&quot; or 1'-0&quot;)."><span id=ogridHint class=oghint hidden>Set local axes (3D) below to activate.</span></div>
768
778
  <div class=mhint>Right-click the canvas any time to force one snap type for a single pick.</div>
769
779
  </div>
770
780
  <button class=msec-hdr data-sec=display aria-expanded=false data-tip="Show/hide plan layers, and edit grid lines">Display<span class=chev aria-hidden=true>▸</span></button>
@@ -2962,6 +2972,14 @@ function saveSnapPrefs(){try{localStorage.setItem(SNAP_PREF_KEY,JSON.stringify(s
2962
2972
  const SNAP3D_KEY='steel:snap3dFree:v1';
2963
2973
  let snap3dFree=(()=>{try{return localStorage.getItem(SNAP3D_KEY)!=='0';}catch(_){return true;}})(); // default ON; only an explicit '0' is OFF (unset OR a corrupted value falls back to the ON default)
2964
2974
  function saveSnap3d(){try{localStorage.setItem(SNAP3D_KEY,snap3dFree?'1':'0');}catch(_){}}
2975
+ // UCS Stage 6 — origin-relative snap (opt-in, OFF by default). A lattice measured from the local-frame
2976
+ // origin along its rotated axes; the 3D view reads it live (api.originGrid) and competes ONE quantized node
2977
+ // against real geometry at the lowest precedence (never drowns geometry snap). Increment stored in INCHES
2978
+ // (parseLen/fmtFtIn units); it only does anything once a local frame is set (Set local axes, 3D).
2979
+ const OGRID_ON_KEY='steel:originGrid:v1', OGRID_INC_KEY='steel:originGridInc:v1', OGRID_INC_DEFAULT=12; // 12" default step — a clean, visible grid; user-configurable
2980
+ let originGridOn=(()=>{try{return localStorage.getItem(OGRID_ON_KEY)==='1';}catch(_){return false;}})(); // default OFF (opt-in): only an explicit '1' turns it on
2981
+ let originGridInc=(()=>{try{const v=Number(localStorage.getItem(OGRID_INC_KEY));return (Number.isFinite(v)&&v>0)?v:OGRID_INC_DEFAULT;}catch(_){return OGRID_INC_DEFAULT;}})(); // inches; STRICT Number() (not parseFloat) so "6garbage" → NaN → default, not a partial 6
2982
+ function saveOriginGrid(){try{localStorage.setItem(OGRID_ON_KEY,originGridOn?'1':'0');localStorage.setItem(OGRID_INC_KEY,String(originGridInc));}catch(_){}}
2965
2983
  // ── Selection filter (Tekla "select switches"): which object CLASSES — and which member types /
2966
2984
  // connection kinds — may enter a selection. One persisted source of truth, consulted at every pick
2967
2985
  // sink (2D click/marquee/Ctrl+A, 3D pick/box). Default: everything ON, so nothing is filtered out
@@ -3827,6 +3845,7 @@ function axisGlyphSvg(o,dir,preview){
3827
3845
  +tag(lx,'#ef4444','X')+tag(ly,'#22c55e','Y')+`</g>`;}
3828
3846
  // header chip + the More-menu "Reset to global" enabled state — reflect the current frame.
3829
3847
  function updCS(){const s=document.getElementById('csStat');const r=document.getElementById('csResetB');
3848
+ if(typeof syncOgridHint==='function')syncOgridHint(); // keep the origin-grid "set a frame" nudge in sync when the frame is set/cleared
3830
3849
  if(view3d&&window.Steel3DView&&window.Steel3DView.frameInfo){ // 3D → the local drawing frame (◇ Plane shadows it)
3831
3850
  const fi=window.Steel3DView.frameInfo(),local=fi.mode==='local',plane=fi.mode==='plane';
3832
3851
  const desc=plane?'Plane':(local?((fi.horizontal?Math.round(fi.angleDeg)+'°':'tilted')+' local (3D)'):'Global'); // a tilt can't be one number → the word "tilted" (numeric tilt lives in the panel/tooltip)
@@ -4185,7 +4204,7 @@ addEventListener('keydown',e=>{
4185
4204
  if(hadReg)toast('Regular grid lines come from the grid spacing — remove them in “Grid lines…”. Only free grid lines are deletable here.');
4186
4205
  return;}
4187
4206
  if(!inForm&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&e.key.toLowerCase()==='d'&&!view3d){e.preventDefault();dimMode=!dimMode;setDimMode();render();setLastCmd('Dimension',()=>{if(!dimMode){dimMode=true;setDimMode();render();}});return;} // D — toggle the Dimension tool
4188
- if(!inForm&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&e.key.toLowerCase()==='a'&&!view3d){e.preventDefault();document.getElementById('mAdd').click();return;} // A — toggle the Add-member tool (mirrors D=Dimension; plain 'a', Ctrl+A is still select-all). The mAdd click owns the arm/disarm-conflicts + setLastCmd logic.
4207
+ if(!inForm&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&e.key.toLowerCase()==='a'){e.preventDefault();document.getElementById('mAdd').click();return;} // A — toggle the Add-member tool in 2D AND 3D (mirrors D=Dimension; plain 'a', Ctrl+A is still select-all). The mAdd click owns the arm/disarm-conflicts + setLastCmd logic.
4189
4208
  if(dimMode&&!inForm&&!e.ctrlKey&&!e.metaKey&&!e.altKey){const dk=e.key.toLowerCase();
4190
4209
  if(dk==='x'||dk==='y'||dk==='f'){e.preventDefault();dimSetAxis(dk==='f'?'free':dk);dimDraft&&svg.querySelector('#dimPrevG')&&dimRefreshPrev();return;}
4191
4210
  if(dk==='c'){e.preventDefault();toggleDimChain();return;}} // C — toggle chained (continuous) dimensioning
@@ -4195,7 +4214,9 @@ addEventListener('keydown',e=>{
4195
4214
  else{const wa=ak==='f'?'free':ak;cmAxis=(wa!=='free'&&cmAxis===wa)?'free':wa;cmRefreshPrev();}return;} // same axis key again toggles the lock off (F always frees)
4196
4215
  const hasBase=cmDraft||(view3d&&window.Steel3DView&&window.Steel3DView.cmHasBase&&window.Steel3DView.cmHasBase());
4197
4216
  if(hasBase&&/^[0-9.\-',]$/.test(e.key)){e.preventDefault();cmHudShow(e.key);return;}} // comma included so a leading-comma entry (,Y) can open the HUD
4198
- if(view3d&&mode==='add'&&!inForm&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&/^[0-9.\-',]$/.test(e.key)){e.preventDefault();cmHudShow(e.key);return;} // 3D Add-member: typing opens the shared point-entry HUD (own branch, OUTSIDE the Move/Copy guard)
4217
+ if(view3d&&mode==='add'&&!inForm&&!e.ctrlKey&&!e.metaKey&&!e.altKey){const ak=e.key.toLowerCase();
4218
+ if(ak==='x'||ak==='y'||ak==='z'||ak==='f'){e.preventDefault();if(window.Steel3DView&&window.Steel3DView.setCmAxis)window.Steel3DView.setCmAxis(ak,e.shiftKey);return;} // 3D Add-member: X/Y/Z/F line-lock the draw to a local axis (same shared lock as Move/Copy; 'z'=normal, Alt stays no-snap)
4219
+ if(/^[0-9.\-',]$/.test(e.key)){e.preventDefault();cmHudShow(e.key);return;}} // typing opens the shared point-entry HUD (own branch, OUTSIDE the Move/Copy guard)
4199
4220
  if(!inForm&&!e.ctrlKey&&!e.metaKey&&!e.altKey&&!dimMode){const ck=e.key.toLowerCase(); // M / C — arm Move / Copy (2D and 3D; dim-armed keys win above)
4200
4221
  if(ck==='m'){e.preventDefault();armCm('move',false);return;}
4201
4222
  if(ck==='c'){e.preventDefault();armCm('copy',false);return;}}
@@ -4255,6 +4276,25 @@ function reflectSnap3d(){for(const b of snap3dBtns){b.classList.toggle('on',snap
4255
4276
  function toggleSnap3d(){snap3dFree=!snap3dFree;saveSnap3d();reflectSnap3d();}
4256
4277
  for(const b of snap3dBtns)b.onclick=e=>{e.stopPropagation();toggleSnap3d();};
4257
4278
  reflectSnap3d();
4279
+ // UCS Stage 6 — origin-grid toggle + step (increment) field. Persists locally; the 3D view reads it live
4280
+ // (api.originGrid) per hover. Step is stored/parsed in inches (parseLen/fmtFtIn); a bad/empty entry reverts
4281
+ // to the last good value. No marker to clear — the next canvas hover re-evaluates against the new setting.
4282
+ const ogridBtn=document.getElementById('snapSect')?.querySelector('[data-ogrid]'), ogridSub=document.querySelector('[data-ogrid-sub]'), ogridInc=document.getElementById('ogridInc');
4283
+ function syncOgridHint(){const h=document.getElementById('ogridHint');if(!h)return;let local=false;try{local=!!(view3d&&window.Steel3DView&&window.Steel3DView.frameInfo&&window.Steel3DView.frameInfo().mode==='local');}catch(_){}h.hidden=!(originGridOn&&!local);} // nudge appears only when the grid is on but no local frame exists yet; self-heals via updCS on frame set/clear
4284
+ function reflectOriginGrid(){
4285
+ if(ogridBtn){ogridBtn.classList.toggle('on',originGridOn);ogridBtn.setAttribute('aria-checked',String(originGridOn));}
4286
+ if(ogridSub)ogridSub.classList.toggle('on',originGridOn); // reveal the Step sub-row only while on (mirrors #csF3dFields.on)
4287
+ if(ogridInc&&document.activeElement!==ogridInc)ogridInc.value=fmtFtIn(originGridInc); // don't clobber what the user is typing
4288
+ syncOgridHint();
4289
+ }
4290
+ function commitOriginGridInc(){const v=parseLen(ogridInc.value);if(v!=null&&v>0)originGridInc=v;saveOriginGrid();ogridInc.value=fmtFtIn(originGridInc);syncOgridHint();} // reject <=0 / unparseable, then ALWAYS echo the canonical last-good step back into the field (a garbage/blank/Escape entry visibly snaps to the previous value)
4291
+ if(ogridBtn)ogridBtn.onclick=e=>{e.stopPropagation();originGridOn=!originGridOn;saveOriginGrid();reflectOriginGrid();};
4292
+ if(ogridInc){
4293
+ ogridInc.addEventListener('keydown',e=>{e.stopPropagation();if(e.key==='Enter'){e.preventDefault();commitOriginGridInc();ogridInc.blur();}else if(e.key==='Escape'){e.preventDefault();ogridInc.value=fmtFtIn(originGridInc);ogridInc.blur();}}); // stopPropagation keeps editor shortcuts out while typing; Enter commits; Escape restores the last-good display (the ensuing blur re-commits that same value, a no-op)
4294
+ ogridInc.addEventListener('change',commitOriginGridInc); // blur/commit
4295
+ ogridInc.addEventListener('click',e=>e.stopPropagation()); // clicking the field must not close the ⋯ menu
4296
+ }
4297
+ reflectOriginGrid();
4258
4298
  // Property-panel width: draggable handle on its left edge (persisted, clamped so it can't swallow the canvas).
4259
4299
  (function(){
4260
4300
  const rz=document.getElementById('panelResizer'); if(!rz)return;
@@ -4369,6 +4409,7 @@ const view3dApi={
4369
4409
  membersByPlan:()=>((C&&Array.isArray(C.plans))?C.plans:[]).map(p=>({members:p.members||[],ptPerFt:(p.pt_per_ft>0?p.pt_per_ft:1),defaultTosMm:(p.default_tos!=null?p.default_tos:0)*25.4})), // every sheet's members WITH its OWN px→ft scale AND its OWN default T.O.S — 3D snapping targets the whole model (any elevation), each plan resolved exactly like the server bake (contract-to-scene: per-plan pt_per_ft + `default_tos ?? 0`) so candidates land on the rendered steel. Guards a not-yet-loaded contract (C.plans absent) so a hover can't throw out of the pointer handler.
4370
4410
  snapEnabled:()=>snapEnabled, // the persistent running-snaps (⋯ menu → Snapping) — 3D honours the same on/off set
4371
4411
  snap3dFree:()=>snap3dFree, // SNAP-bar "3D snapping" mode — ON: free 3D snap; OFF: 3D placement snap constrained to the working plane
4412
+ originGrid:()=>({on:originGridOn,incMm:originGridInc*25.4}), // UCS Stage 6 origin-relative snap — read live per hover; incMm from the inches step. Off ⇒ view skips it; requires a local frame to have any effect
4372
4413
  canSelectId:(id)=>selIdOK(id), // Select-filter predicate for the 3D view (e.g. don't draw a whole-connection envelope for a fully-filtered connection)
4373
4414
  ptPerFt:()=>(P&&P.pt_per_ft>0?P.pt_per_ft:1),
4374
4415
  defaultTosMm:()=>(defaultTOS!=null?defaultTOS*25.4:0), // editor stores default T.O.S in inches
@@ -5488,7 +5529,7 @@ function wire3DBar(){if(bar3dWired||!window.Steel3DView)return;bar3dWired=true;
5488
5529
  document.getElementById('m3dRef').onchange=e=>window.Steel3DView.setRefLine(e.target.checked); // View ▾ menu checkbox
5489
5530
  const d3=window.Steel3DView;
5490
5531
  document.getElementById('m3dDim').onclick=()=>{d3.toggleDimTool();setLastCmd('Dimension',()=>{const b=document.getElementById('m3dDim');if(b&&!b.classList.contains('on'))d3.toggleDimTool();});}; // toggleDimTool()'s reflectDimBar() owns the button .on class + axis/show visibility (single source, no duplicate DOM toggles)
5491
- document.querySelectorAll('#m3dDimAxis button').forEach(b=>b.onclick=()=>{d3.setDimAxis(b.dataset.d3axis);seg3dActive('#m3dDimAxis','data-d3axis',b.dataset.d3axis);});
5532
+ document.querySelectorAll('#m3dDimAxis button').forEach(b=>b.onclick=()=>d3.setDimAxis(b.dataset.d3axis)); // toggle+combine the measure-axis lock; setDimAxis owns the multi-state button refresh (reflectDimAxisBar), not single-active seg3dActive
5492
5533
  document.getElementById('m3dDimShow').onclick=()=>{const on=!d3.dims3dVisible();d3.setDims3dVisible(on);document.getElementById('m3dDimShow').textContent=on?'Hide dims':'Show dims';};
5493
5534
  // Clip: the ⬡ Clip button opens a small menu (Add clip plane / box / Clear). While the plane-pick is armed the
5494
5535
  // button becomes a cancel target (handled by onClipModeChange). Outside-click closes the menu (capture mousedown).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.95.1",
3
+ "version": "0.96.0",
4
4
  "type": "module",
5
5
  "description": "Thin localhost host for floless.app — serves web/ and shells the aware CLI. No engine, no LLM.",
6
6
  "bin": {