@floless/app 0.91.0 → 0.92.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.91.0" : void 0,
53109
+ define: true ? "0.92.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.91.0" : void 0 });
53119
+ return resolveChannel({ isSea: isSea2(), define: true ? "0.92.0" : void 0 });
53120
53120
  }
53121
53121
 
53122
53122
  // workflow-update.ts
@@ -243,6 +243,61 @@ export function frameFromAngle(origin, angleRad) {
243
243
  return { origin: [origin[0], origin[1], origin[2]], xAxis: [c, s, 0], yAxis: [-s, c, 0], normal: [0, 0, 1] };
244
244
  }
245
245
 
246
+ /**
247
+ * Typed coordinate entry (UCS Stage 3) — the ONE pure seam Move/Copy + Add both route through. Given a
248
+ * parsed component triple + a `provided` mask (which slots the user actually typed), a mode, the anchor in
249
+ * WORLD, and the entry `frame`, return a finite world `{ point, vector }` (or `{ error }`). `vector` is the
250
+ * RELATIVE world offset (destination − anchor); array/linear repeat repeats THAT vector, so an absolute
251
+ * target is never re-applied N times. Every value is finite-checked here — the single guard against
252
+ * NaN/Infinity reaching the contract.
253
+ * ABS: local L = comps, each unprovided slot ← the anchor's local coord on that axis → point =
254
+ * localToWorld(L); vector = point − anchorWorld.
255
+ * REL: local Δ = comps, each unprovided slot ← 0 → vector = localVectorToWorld(Δ); point = anchor + vector.
256
+ */
257
+ export function resolvePointEntry({ mode, comps, provided, anchorWorld, frame }) {
258
+ if (!Array.isArray(comps) || !Array.isArray(anchorWorld) || !frame) return { error: 'bad-input' };
259
+ const pv = provided || [true, true, true];
260
+ if (!pv.some(Boolean)) return { error: 'empty' }; // a bare "," supplies no coordinate — reject
261
+ const c = [Number(comps[0]), Number(comps[1]), Number(comps[2])]; // NO `|| 0` — that would turn NaN into 0 and slip past the finite guard
262
+ for (let i = 0; i < 3; i++) { if (pv[i] && !Number.isFinite(c[i])) return { error: 'non-finite' }; if (!pv[i]) c[i] = 0; } // validate only the PROVIDED slots (unprovided are held/zeroed below); reject NaN/Infinity
263
+ if (!anchorWorld.every(Number.isFinite)) return { error: 'non-finite' };
264
+ const aLocal = worldToLocal(anchorWorld, frame);
265
+ let point, vector;
266
+ if (mode === 'abs') {
267
+ const L = [pv[0] ? c[0] : aLocal[0], pv[1] ? c[1] : aLocal[1], pv[2] ? c[2] : aLocal[2]];
268
+ point = localToWorld(L, frame);
269
+ vector = [point[0] - anchorWorld[0], point[1] - anchorWorld[1], point[2] - anchorWorld[2]];
270
+ } else {
271
+ const D = [pv[0] ? c[0] : 0, pv[1] ? c[1] : 0, pv[2] ? c[2] : 0];
272
+ vector = localVectorToWorld(D, frame);
273
+ point = [anchorWorld[0] + vector[0], anchorWorld[1] + vector[1], anchorWorld[2] + vector[2]];
274
+ }
275
+ if (!point.every(Number.isFinite) || !vector.every(Number.isFinite)) return { error: 'non-finite' };
276
+ return { point, vector };
277
+ }
278
+
279
+ /**
280
+ * The Move/Copy offset list for a commit vector `v` (scene mm) — extracted pure so the 3D view's
281
+ * `tfOffsetsFor` is a thin caller and the linear/grid multiplication is unit-tested directly. (The editor's
282
+ * 2D `linearOffsets`/`arrayOffsets` are the same shape but not yet wired through this — a future cleanup.)
283
+ * `st` = { array, tool:'move'|'copy', count, countA, countB }. Counts INCLUDE the original; the array grid
284
+ * skips (0,0) so an n×m grid adds n*m−1 copies. `vA` (direction A, or null) supplied for a staged array.
285
+ */
286
+ export function offsetsFor(v, st, vA) {
287
+ const z = (a) => a && a.length > 2 ? a[2] : 0; // 2D vectors omit Z → treat as 0
288
+ const lin = (vec, n) => { const o = []; for (let k = 1; k <= n; k++) o.push([vec[0] * k, vec[1] * k, z(vec) * k]); return o; };
289
+ if (st.array) {
290
+ if (!vA) return lin(v, Math.max(0, st.countA - 1));
291
+ const o = [];
292
+ for (let i = 0; i < st.countA; i++) for (let j = 0; j < st.countB; j++) {
293
+ if (!i && !j) continue;
294
+ o.push([vA[0] * i + v[0] * j, vA[1] * i + v[1] * j, z(vA) * i + z(v) * j]);
295
+ }
296
+ return o;
297
+ }
298
+ return st.tool === 'copy' ? lin(v, st.count) : [v];
299
+ }
300
+
246
301
  /**
247
302
  * 3D dimension geometry (pure). a,b are scene mm [x,y,z]. axis ∈ free|x|y|z.
248
303
  * free → the straight segment a→b (valueMm = full 3D distance); x|y|z →
@@ -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 } from './steel-3d-core.js';
20
+ import { snapCandidates, snapPoint, planPointToWp, memberGeometry, elevationLevels, snapElevation, dim3dGeom, planeBasis, planeFrom3Points, vecToPlane, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor } 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)';
@@ -155,7 +155,12 @@ function init(canvas, theApi) {
155
155
  readout.style.cssText = 'position:fixed;display:none;pointer-events:none;z-index:60;background:var(--panel,#0f172a);color:var(--text,#f8fafc);border:1px solid var(--line,#1e293b);border-radius:4px;padding:3px 7px;font:12px system-ui;white-space:nowrap;box-shadow:0 2px 8px rgba(0,0,0,.5)';
156
156
  readout._dist = document.createElement('span');
157
157
  readout._type = document.createElement('span'); readout._type.style.color = 'var(--mut,#94a3b8)';
158
- readout.append(readout._dist, readout._type);
158
+ // UCS Stage 2 — live local-coordinate row (X′/Y′/Z′): a block row that wraps below the length line;
159
+ // persistent label+value nodes updated per hover frame (textContent, never innerHTML). Hidden until fed.
160
+ readout._coord = document.createElement('div'); readout._coord.className = 'ro-coord'; readout._coord.style.display = 'none';
161
+ readout._coordL = []; readout._coordV = [];
162
+ for (let i = 0; i < 3; i++) { const lbl = document.createElement('span'); lbl.className = 'ro-lbl'; const val = document.createElement('b'); readout._coord.append(lbl, val); readout._coordL.push(lbl); readout._coordV.push(val); }
163
+ readout.append(readout._dist, readout._type, readout._coord);
159
164
  document.body.appendChild(readout);
160
165
  // 3D dimension tool: a group of placed-dim lines (over the steel) + a live preview line + an HTML
161
166
  // overlay host for the midpoint labels (positioned each frame so they face the camera as screen text).
@@ -1032,6 +1037,7 @@ function repivotToCursor() {
1032
1037
  let rebuildSeq = 0;
1033
1038
  async function rebuild(fit = false) {
1034
1039
  if (!api) return;
1040
+ invalidatePointEntry('rebuild'); // synchronous, BEFORE the first await — the scene is changing; drop any open typed entry + stale base (never on stale async completion)
1035
1041
  if (fit) fitPending = true; // entering 3D re-fits; an edit-triggered rebuild keeps the camera put
1036
1042
  const seq = ++rebuildSeq;
1037
1043
  const sc = await api.fetchScene(); // editor POSTs the current contract to /scene
@@ -2263,6 +2269,52 @@ function effectiveWP() {
2263
2269
  if (frame3d) return { origin: [...frame3d.origin], normal: [...frame3d.normal], xAxis: [...frame3d.xAxis], kind: 'frame' };
2264
2270
  return { origin: [0, 0, api ? api.defaultTosMm() : 0], normal: [0, 0, 1], xAxis: [1, 0, 0] };
2265
2271
  }
2272
+ // ---- Typed coordinate entry (UCS Stage 3) — the ONE authoritative point-entry frame + a generation-stamped
2273
+ // lifecycle. `pointEntryFrame()` is what the tools actually follow: a ◇ Plane shadows the local frame, and
2274
+ // the GLOBAL fallback is a TRUE identity (origin [0,0,0], not effectiveWP's active-TOS origin) so global
2275
+ // ABS/readout are true global. `kind` drives the ′-prime (shown when kind !== 'global'). ----
2276
+ function pointEntryFrame() {
2277
+ if (workPlane) { const b = planeBasis(workPlane.normal, workPlane.xAxis); return { kind: 'plane', frame: { origin: [...workPlane.origin], xAxis: b.u || [1, 0, 0], yAxis: b.v || [0, 1, 0], normal: [...workPlane.normal] } }; }
2278
+ if (frame3d) return { kind: 'local', frame: frame3d }; // full basis already; token deep-clones it
2279
+ return { kind: 'global', frame: RO_IDENT }; // identity([0,0,0]) — reused, no per-call alloc
2280
+ }
2281
+ // A monotonic generation: any mutation that could change the entry frame, anchor, or scene bumps it, so a
2282
+ // token whose gen still matches at commit is proven un-drifted (frame/anchor snapshot stays valid).
2283
+ let pointEntryGen = 0;
2284
+ let pointEntryTok = null; // { consumer:'movecopy'|'add', gen, frame, kind, anchorWorld, aimWorld|null, addPhase } | null
2285
+ // Open: capture the frame/anchor/aim snapshot for one operation. Returns the initial HUD UI state, or null-ok.
2286
+ function pointEntryBegin(consumer) {
2287
+ const pef = pointEntryFrame();
2288
+ let anchorWorld, aimWorld = null, addPhase = null, locked = false, mode = 'rel';
2289
+ if (consumer === 'movecopy') {
2290
+ if (!cmActive() || !tfDraft || addActive()) return { ok: false };
2291
+ anchorWorld = [...tfDraft.base];
2292
+ aimWorld = tfLast ? [...tfLast] : null;
2293
+ } else { // add
2294
+ if (!addActive()) return { ok: false };
2295
+ if (drDraft) { anchorWorld = [...drDraft]; addPhase = 'second'; }
2296
+ else { anchorWorld = [...effectiveWP().origin]; addPhase = 'start'; locked = true; mode = 'abs'; } // 1st point has no anchor to offset from → ABS-only
2297
+ }
2298
+ pointEntryTok = { consumer, gen: pointEntryGen, frame: cloneFrame(pef.frame), kind: pef.kind, anchorWorld, aimWorld, addPhase };
2299
+ return { ok: true, mode, locked, kind: pef.kind, primed: pef.kind !== 'global' };
2300
+ }
2301
+ function pointEntryEnd() { pointEntryTok = null; } // editor closed the HUD (not a commit) → drop the token, no gen bump
2302
+ function pointEntryCommit() { pointEntryTok = null; pointEntryGen++; } // a successful commit: clear token + bump gen BEFORE the geometry callback (silent — no drift toast on the reentrant rebuild)
2303
+ // Any mutation that could change the entry frame/anchor/scene. hard = the scene/tool changed → also drop the
2304
+ // base/start so a stale anchor can't revalidate; soft (frame/workplane drift) keeps the world base.
2305
+ function invalidatePointEntry(reason) {
2306
+ const hadLive = !!pointEntryTok, hadStaged = !!(tfDraft && tfDraft.vA);
2307
+ pointEntryGen++; pointEntryTok = null;
2308
+ tfLast = null; tfLastClient = null; // drop the captured aim so a reopened {dist} demands a fresh hover under the new frame (Codex R5 #1)
2309
+ const hard = reason === 'rebuild' || reason === 'undo' || reason === 'view' || reason === 'hide';
2310
+ if (hard) { cmClear3d(); drClear3d(); }
2311
+ else if (tfDraft && tfDraft.vA) { tfDraft.vA = null; tfPreviewClear(); } // soft drift: drop staged direction A, keep the base (geometry didn't move)
2312
+ if (hadLive && api && api.closeCmHud) api.closeCmHud(); // close an open typed-entry HUD
2313
+ if (reason === 'drift' && (hadLive || hadStaged) && api && api.toast) api.toast('Frame changed — re-enter the value');
2314
+ }
2315
+ // A pointer base/start pick invalidates any open typed-entry token (silent — no toast): the anchor changed,
2316
+ // so a stale HUD from a prior phase/operation must not commit against the new draft.
2317
+ function notePointerPick() { if (pointEntryTok && api && api.closeCmHud) api.closeCmHud(); pointEntryTok = null; pointEntryGen++; }
2266
2318
  // What the tools ACTUALLY follow — a set ◇ Plane shadows the local frame, so the chip never claims Local
2267
2319
  // while a plane overrides it. Editor's Axes chip reads this in 3D. A horizontal frame reports its in-plane
2268
2320
  // angle; a tilted frame reports its tilt (normal off-vertical) — a single angle can't describe a 3D orientation.
@@ -2276,7 +2328,7 @@ function frameInfo() {
2276
2328
  }
2277
2329
  return { mode: 'global' };
2278
2330
  }
2279
- function fireFrameChange() { renderFrameGizmo(); if (api && api.onFrame3dChange) api.onFrame3dChange(frameInfo()); }
2331
+ function fireFrameChange() { invalidatePointEntry('drift'); renderFrameGizmo(); if (api && api.onFrame3dChange) api.onFrame3dChange(frameInfo()); } // a frame change re-bases typed entry → invalidate any open HUD (drift)
2280
2332
  // Set a HORIZONTAL frame at origin (numeric entry + gizmo materialize). origin defaults its Z to the active level.
2281
2333
  function setFrame3d(originMm, angleDeg) {
2282
2334
  const z = (originMm && originMm.length > 2) ? originMm[2] : frameZ();
@@ -2451,6 +2503,8 @@ function renderFramePickPreview(e) {
2451
2503
  if (!overlayScene || !framePickPts) return;
2452
2504
  const r = dimPointAt(e), cur = r ? r.p : null;
2453
2505
  if (r) showMarker(r.p, r.type); else if (marker) marker.visible = false; // snap reticle on EVERY step, including the origin pick
2506
+ if (cur) roShowCoordOnly(cur, e.clientX, e.clientY); // live coords of the cursor at every frame-set click (origin/X/Y)
2507
+ else if (readout) readout.style.display = 'none'; // cursor resolved to nothing (edge-on/miss) → don't freeze the last coord
2454
2508
  if (!cur || !framePickPts.length) return; // origin step: just the reticle, no rubber-band yet
2455
2509
  const g = new THREE.Group();
2456
2510
  const line = (a, b, col, op) => { const l = new THREE.Line(new THREE.BufferGeometry().setFromPoints([new THREE.Vector3(...a), new THREE.Vector3(...b)]), new THREE.LineBasicMaterial({ color: col, transparent: true, opacity: op == null ? 0.95 : op })); l.material.depthTest = false; l.renderOrder = 998; return l; };
@@ -2512,9 +2566,9 @@ function setWorkPlanePrincipal(kind, offsetMm) {
2512
2566
  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];
2513
2567
  if (!def) return;
2514
2568
  workPlane = { origin: def.normal.map((c) => c * off), normal: def.normal, xAxis: def.xAxis, kind };
2515
- wpMode = null; wpDraft = null; renderWorkPlane(); reflectWpBar();
2569
+ wpMode = null; wpDraft = null; invalidatePointEntry('drift'); renderWorkPlane(); reflectWpBar();
2516
2570
  }
2517
- function clearWorkPlane() { workPlane = null; wpMode = null; wpDraft = null; renderWorkPlane(); reflectWpBar(); }
2571
+ function clearWorkPlane() { workPlane = null; wpMode = null; wpDraft = null; invalidatePointEntry('drift'); renderWorkPlane(); reflectWpBar(); }
2518
2572
  function toggleWorkPlaneVisible(on) { wpVisible = on === undefined ? !wpVisible : !!on; renderWorkPlane(); }
2519
2573
  function workPlaneInfo() { return { set: !!workPlane, mode: wpMode, visible: wpVisible, plane: workPlane ? { origin: [...workPlane.origin], normal: [...workPlane.normal], xAxis: [...workPlane.xAxis] } : null }; }
2520
2574
  // face pick: the clip tool's raycast, minus the camera-side flip — the plane lands ON the face.
@@ -2579,15 +2633,8 @@ function tfConstrain(p, e) {
2579
2633
  if (ax === 'v') return [b[0] + c.dv * v[0], b[1] + c.dv * v[1], b[2] + c.dv * v[2]];
2580
2634
  return p;
2581
2635
  }
2582
- // mirror of the editor's offset builders (mm side): counts INCLUDE the original, grid skips (0,0)
2583
- function tfOffsetsFor(v, st) {
2584
- const lin = (vec, n) => { const o = []; for (let k = 1; k <= n; k++) o.push([vec[0] * k, vec[1] * k, vec[2] * k]); return o; };
2585
- if (st.array) {
2586
- if (!tfDraft.vA) return lin(v, Math.max(0, st.countA - 1));
2587
- const o = []; for (let i = 0; i < st.countA; i++) for (let j = 0; j < st.countB; j++) { if (!i && !j) continue; o.push([tfDraft.vA[0] * i + v[0] * j, tfDraft.vA[1] * i + v[1] * j, tfDraft.vA[2] * i + v[2] * j]); } return o;
2588
- }
2589
- return st.tool === 'copy' ? lin(v, st.count) : [v];
2590
- }
2636
+ // the offset list is the pure core `offsetsFor` (unit-tested for linear/grid) — counts INCLUDE the original, grid skips (0,0)
2637
+ function tfOffsetsFor(v, st) { return offsetsFor(v, st, tfDraft ? tfDraft.vA : null); }
2591
2638
  function tfGhostBuild(offs) {
2592
2639
  tfDisposeGhost(); // dispose the previous rebuild's own geometries (the >600 boxes) before dropping it
2593
2640
  tfGhost = new THREE.Group();
@@ -2610,7 +2657,7 @@ function tfGhostBuild(offs) {
2610
2657
  }
2611
2658
  function tfPreview(e) {
2612
2659
  const st = cmActive(); if (!st || !tfDraft) return;
2613
- const r = wpPointAt(e); if (!r) return;
2660
+ 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
2614
2661
  const p = tfConstrain(r.p, e);
2615
2662
  tfLast = p; tfLastClient = [e.clientX, e.clientY];
2616
2663
  if (r.snap && tfAxis === 'free' && !e.shiftKey) showMarker(p, r.type); else marker.visible = false;
@@ -2628,6 +2675,7 @@ function tfPreview(e) {
2628
2675
  readout._dist.textContent = api.fmtLen ? api.fmtLen(L) : (L / FT_MM).toFixed(2) + ' ft';
2629
2676
  readout._type.textContent = r.snap ? ' · ' + (r.type || 'snap') : (st.tool === 'copy' && !st.array && st.count > 1 ? ' ×' + st.count : '');
2630
2677
  readout.style.left = (e.clientX + 14) + 'px'; readout.style.top = (e.clientY + 14) + 'px'; readout.style.display = 'block';
2678
+ roCoords(p); // local coords of the destination point
2631
2679
  }
2632
2680
  function tfClick(e) {
2633
2681
  const st = cmActive(); if (!st) return false;
@@ -2639,7 +2687,7 @@ function tfClick(e) {
2639
2687
  const r = wpPointAt(e); if (!r) return true;
2640
2688
  const p = tfConstrain(r.p, e);
2641
2689
  tfLastClient = [e.clientX, e.clientY];
2642
- if (!tfDraft) { tfDraft = { base: p, vA: null }; tfCandidates = null; tfLast = p; return true; }
2690
+ if (!tfDraft) { notePointerPick(); tfDraft = { base: p, vA: null }; tfCandidates = null; tfLast = p; return true; } // base pick bumps the gen so a stale typed token can't survive
2643
2691
  const v = [p[0] - tfDraft.base[0], p[1] - tfDraft.base[1], p[2] - tfDraft.base[2]];
2644
2692
  if (Math.hypot(v[0], v[1], v[2]) < 5) return true; // ~zero pick (5 mm) — ignore, like the 2D 0.5 px guard
2645
2693
  if (st.array && !tfDraft.vA) { tfDraft.vA = v; return true; }
@@ -2649,23 +2697,54 @@ function tfClick(e) {
2649
2697
  tfDraft = null; tfPreviewClear();
2650
2698
  return true;
2651
2699
  }
2652
- // HUD hand-off: the editor parses (inches), we turn it into a plane-space vector and run the same flow.
2653
- function cmHudApply(pv) {
2654
- const st = cmActive(); if (!st || !tfDraft) return { err: 'Pick a base point first' };
2655
- const wp = effectiveWP(), { u, v: vv } = planeBasis(wp.normal, wp.xAxis);
2700
+ // HUD hand-off (Move/Copy): the editor parses (inches) + the pill mode (`abs`); we resolve through the pure
2701
+ // resolvePointEntry against the token's frame snapshot. The token gen must still match (no drift) or the HUD
2702
+ // is stale. ABS resolves an absolute local coord (offset = dest − base); REL a delta; both feed the same
2703
+ // `offsetsFor` so a Copy array repeats the RELATIVE vector, never re-stacks an absolute target.
2704
+ function cmHudApply(pv, abs) {
2705
+ const t = pointEntryTok, st = cmActive();
2706
+ if (!t || t.consumer !== 'movecopy' || t.gen !== pointEntryGen || !st || !tfDraft || addActive()) return { err: 'Pick the base point again' };
2656
2707
  let v;
2657
- if (pv.comp) { const IN = 25.4, du = pv.comp[0] * IN, dv = pv.comp[1] * IN, dn = (pv.comp[2] || 0) * IN;
2658
- v = [du * u[0] + dv * vv[0] + dn * wp.normal[0], du * u[1] + dv * vv[1] + dn * wp.normal[1], du * u[2] + dv * vv[2] + dn * wp.normal[2]]; }
2659
- else { if (!tfLast) return { err: 'Move the mouse to aim, or type dx,dy' };
2660
- const dir = [tfLast[0] - tfDraft.base[0], tfLast[1] - tfDraft.base[1], tfLast[2] - tfDraft.base[2]];
2661
- const L = Math.hypot(dir[0], dir[1], dir[2]); if (L < 1e-6) return { err: 'Move the mouse to aim, or type dx,dy' };
2662
- const d = pv.dist * 25.4; v = [dir[0] / L * d, dir[1] / L * d, dir[2] / L * d]; }
2708
+ if (pv.comp) {
2709
+ const r = resolvePointEntry({ mode: abs ? 'abs' : 'rel', comps: pv.comp.map((c) => c * 25.4), provided: pv.provided, anchorWorld: t.anchorWorld, frame: t.frame });
2710
+ if (r.error) return { err: r.error === 'empty' ? 'Type a coordinate (X, Y)' : 'Enter a valid value' };
2711
+ v = r.vector;
2712
+ } else { // {dist} along the captured aim — REL / Move-Copy only
2713
+ if (abs) return { err: 'Type X′,Y′ for an absolute point' }; // a bare length is meaningless as an absolute coordinate
2714
+ if (!t.aimWorld) return { err: 'Move the mouse to aim, or type dx,dy' };
2715
+ const dir = [t.aimWorld[0] - t.anchorWorld[0], t.aimWorld[1] - t.anchorWorld[1], t.aimWorld[2] - t.anchorWorld[2]];
2716
+ const L = Math.hypot(dir[0], dir[1], dir[2]);
2717
+ if (!(L > 1e-6) || !Number.isFinite(pv.dist)) return { err: 'Move the mouse to aim, or type dx,dy' };
2718
+ const d = pv.dist * 25.4; v = [dir[0] / L * d, dir[1] / L * d, dir[2] / L * d];
2719
+ }
2720
+ if (!v.every(Number.isFinite)) return { err: 'Enter a valid value' };
2663
2721
  if (Math.hypot(v[0], v[1], v[2]) < 5) return { err: 'Zero distance — type a non-zero value' };
2664
- if (st.array && !tfDraft.vA) { tfDraft.vA = v; tfPreviewClear(); return { ok: true, staged: true }; }
2722
+ if (st.array && !tfDraft.vA) { tfDraft.vA = v; tfPreviewClear(); return { ok: true, staged: true }; } // stage direction A — same operation, does NOT bump gen
2665
2723
  const offs = tfOffsetsFor(v, st);
2666
2724
  if (!offs.length) { tfDraft = null; tfPreviewClear(); return { err: st.array ? 'A 1 × 1 array places no copies — raise a count' : 'Nothing to place' }; }
2667
- api.onTransform3d(offs);
2725
+ if (!offs.every((o) => o.every(Number.isFinite))) { tfDraft = null; tfPreviewClear(); return { err: 'Value out of range' }; } // a big count × a big vector can overflow to Infinity — never send it to the contract
2726
+ pointEntryCommit(); // clear token + bump gen BEFORE the geometry callback so the reentrant rebuild can't false-toast
2668
2727
  tfDraft = null; tfPreviewClear();
2728
+ api.onTransform3d(offs);
2729
+ return { ok: true };
2730
+ }
2731
+ // HUD hand-off (Add-member): 1st point (no drDraft) = ABS-only → set the draw start; 2nd point = resolve
2732
+ // against the start and commit. A bare length ({dist}) is rejected — Add has no aim direction to run it along.
2733
+ function drHudApply(pv, abs) {
2734
+ const t = pointEntryTok;
2735
+ if (!t || t.consumer !== 'add' || t.gen !== pointEntryGen || !addActive()) return { err: 'Arm Add again' };
2736
+ if (pv.dist != null) return { err: 'Type coordinates (X, Y) or a delta (dx, dy)' };
2737
+ const r = resolvePointEntry({ mode: abs ? 'abs' : 'rel', comps: pv.comp.map((c) => c * 25.4), provided: pv.provided, anchorWorld: t.anchorWorld, frame: t.frame });
2738
+ if (r.error) return { err: r.error === 'empty' ? 'Type a coordinate (X, Y)' : 'Enter a valid value' };
2739
+ const p = r.point;
2740
+ if (t.addPhase === 'start') { // set the start; the tool stays armed for the 2nd point
2741
+ pointEntryCommit(); drDraft = p; tfCandidates = null;
2742
+ if (readout) readout.style.display = 'none';
2743
+ return { ok: true };
2744
+ }
2745
+ if (!drDraft || Math.hypot(p[0] - drDraft[0], p[1] - drDraft[1], p[2] - drDraft[2]) < 0.5) return { err: 'Zero length — type a non-zero value' }; // sub-mm epsilon (typed; NOT the 50 mm pointer double-click guard)
2746
+ pointEntryCommit();
2747
+ commitDrawPoint(p);
2669
2748
  return { ok: true };
2670
2749
  }
2671
2750
 
@@ -2680,25 +2759,32 @@ function drShiftLock(p, e) { // Shift = ortho
2680
2759
  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);
2681
2760
  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]];
2682
2761
  }
2762
+ // The shared "commit the 2nd draw point" transition — used by both the pointer (drClick) and typed entry
2763
+ // (drHudApply). Clears local draw state BEFORE the geometry callback so the reentrant rebuild is safe.
2764
+ function commitDrawPoint(p2) {
2765
+ const start = drDraft;
2766
+ drDraft = null; tfCandidates = null; // the new member is a snap target for the NEXT one — invalidate the shared snap cache
2767
+ if (drRubber) drRubber.visible = false; if (readout) readout.style.display = 'none'; // stays armed for the next member
2768
+ if (start && api && api.onAddMember3d) api.onAddMember3d(start, p2);
2769
+ }
2683
2770
  function drClick(e) {
2684
2771
  const r = wpPointAt(e); if (!r) return;
2685
- if (!drDraft) { drDraft = r.p; return; }
2772
+ if (!drDraft) { notePointerPick(); drDraft = r.p; return; } // start pick bumps the gen so an open first-point typed token can't survive
2686
2773
  const p = drShiftLock(r.p, e);
2687
- if (Math.hypot(p[0] - drDraft[0], p[1] - drDraft[1], p[2] - drDraft[2]) < 50) return; // ~<2in — ignore a doubled click
2688
- if (api && api.onAddMember3d) api.onAddMember3d(drDraft, p);
2689
- drDraft = null; tfCandidates = null; // the new member is a snap target for the NEXT one — invalidate the shared snap cache
2690
- if (drRubber) drRubber.visible = false; readout.style.display = 'none'; // stays armed for the next member
2774
+ 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)
2775
+ commitDrawPoint(p);
2691
2776
  }
2692
2777
  function drPreview(e) {
2693
- const r = wpPointAt(e); if (!r) return;
2778
+ 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
2694
2779
  if (r.snap) showMarker(r.p, r.type); else marker.visible = false;
2695
- if (!drDraft) { readout.style.display = 'none'; return; }
2780
+ if (!drDraft) { roShowCoordOnly(r.p, e.clientX, e.clientY); return; } // before the start pick: show the start point's local coords
2696
2781
  const p = drShiftLock(r.p, e);
2697
2782
  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); }
2698
2783
  drRubber.geometry.setFromPoints([new THREE.Vector3(...drDraft), new THREE.Vector3(...p)]); drRubber.visible = true;
2699
2784
  const L = Math.hypot(p[0] - drDraft[0], p[1] - drDraft[1], p[2] - drDraft[2]);
2700
2785
  readout._dist.textContent = api.fmtLen ? api.fmtLen(L) : (L / FT_MM).toFixed(2) + ' ft'; readout._type.textContent = r.snap ? ' · ' + (r.type || 'snap') : '';
2701
2786
  readout.style.left = (e.clientX + 14) + 'px'; readout.style.top = (e.clientY + 14) + 'px'; readout.style.display = 'block';
2787
+ roCoords(p); // local coords of the member end point
2702
2788
  }
2703
2789
  // world units per screen pixel at the target plane — drives screen-CONSTANT marker/dot sizes, for
2704
2790
  // BOTH perspective (distance) and ortho (frustum height / zoom), so dots stay small when zoomed in.
@@ -2792,16 +2878,17 @@ function gridPlaneZ() {
2792
2878
  function dimEffectiveAxis(alt) { return alt && dimDraft3d ? 'z' : dimAxis3d; }
2793
2879
 
2794
2880
  function onDown(e) {
2881
+ if (readout) { readout.style.display = 'none'; if (readout._coord) readout._coord.style.display = 'none'; } // UCS Stage 2: hide the whole readout chip so a drag never shows a lingering coordinate (or an empty coord-only shell); the drag/next hover re-shows it
2795
2882
  if (e.button === 2) { rightDownXY = [e.clientX, e.clientY]; rightMoved = false; } // arm the click-vs-drag test for the snap menu
2796
2883
  if (e.button !== 0) return; // RIGHT/MIDDLE → OrbitControls (orbit/pan)
2797
- if (wpMode === 'face') { e.stopPropagation(); const r = wpFacePick(e.clientX, e.clientY); if (r) { workPlane = r; wpMode = null; canvasEl.style.cursor = 'default'; renderWorkPlane(); reflectWpBar(); if (api && api.toast) api.toast('Working plane set on the face'); } return; } // armed: one face click sets the plane
2884
+ if (wpMode === 'face') { e.stopPropagation(); const r = wpFacePick(e.clientX, e.clientY); if (r) { workPlane = r; wpMode = null; invalidatePointEntry('drift'); canvasEl.style.cursor = 'default'; renderWorkPlane(); reflectWpBar(); if (api && api.toast) api.toast('Working plane set on the face'); } return; } // armed: one face click sets the plane
2798
2885
  if (wpMode === '3pt') { e.stopPropagation();
2799
2886
  const r = dimPointAt(e); if (!r) return;
2800
2887
  wpDraft = wpDraft || []; wpDraft.push(r.p);
2801
2888
  showMarker(r.p, r.type);
2802
2889
  if (wpDraft.length === 3) { const wp = planeFrom3Points(wpDraft[0], wpDraft[1], wpDraft[2]);
2803
2890
  wpDraft = null; wpMode = null; marker.visible = false; canvasEl.style.cursor = 'default';
2804
- if (wp) { wp.kind = 'p3'; workPlane = wp; renderWorkPlane(); if (api && api.toast) api.toast('Working plane set from 3 points'); }
2891
+ if (wp) { wp.kind = 'p3'; workPlane = wp; invalidatePointEntry('drift'); renderWorkPlane(); if (api && api.toast) api.toast('Working plane set from 3 points'); }
2805
2892
  else if (api && api.toast) api.toast('Points are collinear — plane not set');
2806
2893
  reflectWpBar(); }
2807
2894
  return; }
@@ -3126,6 +3213,32 @@ function closestOnSeg3(p, a, b) {
3126
3213
  }
3127
3214
 
3128
3215
  // ---- hover: cursor + readout chip (no drag in progress) ----
3216
+ // UCS Stage 2 — live local-coordinate readout. Show a resolved world point in the ACTIVE local frame
3217
+ // as X′/Y′/Z′ (measured from the local origin along its axes), or as plain global X/Y/Z at identity
3218
+ // (worldToLocal on identityFrame is a no-op), as a second row of the cursor readout chip. Fed once per
3219
+ // resolver step from the hover RAF (never double-subscribed); the row is cleared on pointerdown so a
3220
+ // drag never shows a lingering coordinate.
3221
+ const RO_IDENT = identityFrame(); // reused every global-mode hover so we don't alloc a frame per RAF
3222
+ const RO_AX = ['X', 'Y', 'Z'];
3223
+ function roFmt(mm) { if (Math.abs(mm) < 0.5) mm = 0; return api && api.fmtLen ? api.fmtLen(mm) : (mm / FT_MM).toFixed(2) + ' ft'; } // snap sub-1/16" float noise to 0 so a plane point never reads "-0""
3224
+ function roCoords(worldPt) {
3225
+ if (!readout || !readout._coord || !worldPt) return;
3226
+ const pef = pointEntryFrame(); // ◇ Plane shadows the local frame; global = TRUE identity([0,0,0])
3227
+ const isLocal = pef.kind !== 'global';
3228
+ const local = worldToLocal(worldPt, pef.frame); // identity → the point's global coords
3229
+ const prime = isLocal ? '′' : ''; // U+2032 prime marks a local axis; plain X/Y/Z at global
3230
+ for (let i = 0; i < 3; i++) { readout._coordL[i].textContent = RO_AX[i] + prime + ' '; readout._coordV[i].textContent = roFmt(local[i]); }
3231
+ readout._coord.classList.toggle('ro-local', isLocal); // cyan the row for a local frame OR a ◇ Plane (reuses #csStat.local's accent)
3232
+ readout._coord.style.display = '';
3233
+ }
3234
+ // A single-point pick with no length yet (base point, first Add/Move/Copy/Dim click, frame 3-click set):
3235
+ // show the chip with the coord row as its only content (clear the length line first).
3236
+ function roShowCoordOnly(worldPt, x, y) {
3237
+ if (!readout) return;
3238
+ readout._dist.textContent = ''; readout._type.textContent = '';
3239
+ roCoords(worldPt);
3240
+ readout.style.left = (x + 14) + 'px'; readout.style.top = (y + 14) + 'px'; readout.style.display = 'block';
3241
+ }
3129
3242
  function onHoverMove(e) {
3130
3243
  lastHoverXY = [e.clientX, e.clientY];
3131
3244
  dimLastAlt = e.altKey; // remembered so the rAF body can rebuild a synthetic event
@@ -3142,6 +3255,7 @@ function onHoverMove(e) {
3142
3255
  readout._dist.textContent = api.fmtLen ? api.fmtLen(p.z) : (p.z / 304.8).toFixed(2) + ' ft';
3143
3256
  readout._type.textContent = p.snapped ? ' · ' + (p.label || 'level') : ' ↕';
3144
3257
  readout.style.left = (lastHoverXY[0] + 14) + 'px'; readout.style.top = (lastHoverXY[1] + 14) + 'px'; readout.style.display = 'block';
3258
+ roCoords([p.x, p.y, p.z]);
3145
3259
  } else { marker.visible = false; readout.style.display = 'none'; canvasEl.style.cursor = 'crosshair'; }
3146
3260
  return;
3147
3261
  }
@@ -3158,7 +3272,8 @@ function onHoverMove(e) {
3158
3272
  canvasEl.style.cursor = 'crosshair';
3159
3273
  if (tfDraft) tfPreview({ clientX: lastHoverXY[0], clientY: lastHoverXY[1], altKey: dimLastAlt, shiftKey: tfLastShift });
3160
3274
  else { const r = wpPointAt({ clientX: lastHoverXY[0], clientY: lastHoverXY[1], altKey: dimLastAlt });
3161
- if (r && r.snap) showMarker(r.p, r.type); else marker.visible = false; }
3275
+ if (r && r.snap) showMarker(r.p, r.type); else marker.visible = false;
3276
+ 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
3162
3277
  updateStatusChip(); return; }
3163
3278
  if (clipMode) { canvasEl.style.cursor = 'crosshair'; if (clipMode === 'box') clipBoxPreviewAt(lastHoverXY[0], lastHoverXY[1]); return; } // armed clip pick: crosshair (+ live box preview while drawing)
3164
3279
  if (dimMode3d) { // dim tool: snap marker + live preview line + readout (no member hover)
@@ -3173,7 +3288,10 @@ function onHoverMove(e) {
3173
3288
  readout._dist.textContent = api.fmtLen ? api.fmtLen(g.valueMm) : (g.valueMm / 304.8).toFixed(2) + ' ft';
3174
3289
  readout._type.textContent = r.type ? ' · ' + r.type : (dimLastAlt ? ' ↕' : '');
3175
3290
  readout.style.left = (lastHoverXY[0] + 14) + 'px'; readout.style.top = (lastHoverXY[1] + 14) + 'px'; readout.style.display = 'block';
3176
- } else { dimPreviewLine.visible = false; if (!dimDraft3d) readout.style.display = 'none'; }
3291
+ roCoords(r.p); // local coords of the second dim point
3292
+ } else { dimPreviewLine.visible = false;
3293
+ if (r && !dimDraft3d) roShowCoordOnly(r.p, lastHoverXY[0], lastHoverXY[1]); // first dim point: coords-only chip
3294
+ 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
3177
3295
  return;
3178
3296
  }
3179
3297
  if (framePicking()) { // 3-click UCS set in progress: live rubber-band X/Y + Z-flip arrow, snap marker at the cursor
@@ -3232,6 +3350,7 @@ function updateStatusChip() {
3232
3350
 
3233
3351
  function show() { if (controls) controls.enabled = true; if (canvasEl) { canvasEl.style.display = 'block'; resize(); } if (!rafId) loop(); updateStatusChip(); refreshDims(); refreshOverlayDims(); renderFrameGizmo(); } // resume the render loop (reset orbit in case a gesture was stranded by a mid-drag hide)
3234
3352
  function hide() {
3353
+ invalidatePointEntry('hide'); // leaving 3D → drop any open typed entry + stale base/start
3235
3354
  if (dimMode3d) toggleDimTool(); // disarm the dim tool + sync its toolbar (no stale draft/armed state on return)
3236
3355
  if (clipMode) setClipMode(null); // disarm the clip-plane pick too (no stale armed state on return)
3237
3356
  if (insertMode) setInsertMode(false); // disarm a pending detail placement — else the first click on return would place it
@@ -3363,7 +3482,9 @@ window.Steel3DView = {
3363
3482
  workAreaSetAll, workAreaFromSelection, workAreaToggle, workAreaSetWhole, clearWorkArea, workAreaState,
3364
3483
  armWorkPlanePick, setWorkPlanePrincipal, clearWorkPlane, toggleWorkPlaneVisible, workPlaneInfo,
3365
3484
  armFrame3d, disarmFrame3d, repickFrame3d, setFrame3d, setFrameBasis, setFrameAngle, setFrameOrigin, clearFrame3d, frameInfo, frameArmed: () => frameMode, framePicking, framePickStep, frameHandlesScreen, // 3D local drawing frame (UCS stage 1)
3485
+ 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)
3366
3486
  cmEscape, cmHasBase, cmClear3d, setCmAxis, cmLastClient, cmHudApply,
3487
+ drHudApply, pointEntryBegin, pointEntryEnd, drHasStart: () => !!drDraft, // UCS stage 3: shared typed point-entry HUD (Move/Copy + Add)
3367
3488
  drClear3d, drEscape: () => { if (drDraft) { drDraft = null; drClear3d(); return true; } return false; },
3368
3489
  toggleDimTool, setDimAxis, dimAxis, setDims3dVisible, dims3dVisible, refreshDims,
3369
3490
  setSnapOnly: setSnapOnly3d, snapOnly: () => snapOnly3d, dimToolOn: () => dimMode3d, rightDragged: () => rightMoved, // Tekla-style snap override (right-click menu lives in steel-editor.html)
@@ -148,6 +148,11 @@
148
148
  #csStat.local{border:1px solid #22d3ee;background:rgba(34,211,238,.10);border-radius:4px;padding:1px 6px;cursor:pointer} /* lift the chip out of the muted row when a local frame/plane is active (reuses the dim/accent cyan — no new colour); clickable → reset to global */
149
149
  #snapStat{cursor:pointer;border:1px solid #22d3ee;background:rgba(34,211,238,.10);border-radius:4px;padding:1px 6px} /* snap-override chip — same cyan treatment as #csStat.local; the cyan IS the snap-marker colour it restricts */
150
150
  #snapStat:hover b{color:#fff}
151
+ /* UCS stage 2 — live local-coordinate row inside the 3D cursor readout chip (steel-3d-view.js builds the element). */
152
+ .ro-coord{font-variant-numeric:tabular-nums;color:var(--mut,#94a3b8);white-space:nowrap;font-size:12px}
153
+ .ro-coord .ro-lbl{margin-left:9px} .ro-coord .ro-lbl:first-child{margin-left:0}
154
+ .ro-coord b{color:var(--text,#f8fafc);font-weight:400}
155
+ .ro-coord.ro-local,.ro-coord.ro-local b{color:#22d3ee} /* whole row goes cyan when a local frame is set — reuses #csStat.local's accent, no new colour */
151
156
  #snapMenu{position:fixed;left:0;top:0;z-index:45;min-width:186px} /* right-click snap menu — reuses the .m3dmenu skin, opened at the cursor */
152
157
  #snapMenu .sg{display:inline-block;width:17px;color:#22d3ee} /* leading glyph = the marker the cursor will show */
153
158
  #snapMenu button.dim{opacity:.55} /* a running-snap turned off in the ⋯ menu — still forceable here (AutoCAD-style) */
@@ -307,6 +312,15 @@ text.mlentx{fill:#e2e8f0;text-anchor:middle;dominant-baseline:central;font-famil
307
312
  #cmHud input{width:110px;height:24px;background:var(--bg);color:var(--text);border:1px solid var(--line);border-radius:5px;padding:0 7px;font:12px system-ui}
308
313
  #cmHud input:focus{outline:none;border-color:var(--brand)}
309
314
  #cmHud.err input{border-color:#fca5a5}
315
+ #cmHudPill{display:inline-flex;align-items:center;gap:2px;padding:2px;height:20px;border-radius:4px;background:#0f172a;border:1px solid var(--line)}
316
+ #cmHud:not(.v3d) #cmHudPill{display:none} /* 2D Move/Copy is relative-only — no ABS pill (out of scope) */
317
+ .cmHudSeg{border:none;border-radius:3px;padding:2px 7px;font:inherit;font-size:10px;font-weight:600;letter-spacing:.03em;color:#94a3b8;background:transparent;cursor:pointer;transition:background .1s ease,color .1s ease}
318
+ .cmHudSeg:hover{background:rgba(148,163,184,.08);color:#cbd5e1}
319
+ .cmHudSeg.on{background:rgba(34,211,238,.16);box-shadow:inset 0 0 0 1px rgba(34,211,238,.55);color:#22d3ee;font-weight:700}
320
+ .cmHudSeg.on:hover{background:rgba(34,211,238,.22)}
321
+ .cmHudSeg:focus-visible{outline:2px solid var(--brand);outline-offset:1px}
322
+ #cmHudPill.locked .cmHudSeg[data-mode="rel"]{display:none} /* Add first point: no anchor → ABS only, REL hidden (not disabled) */
323
+ #cmHudPill.locked .cmHudSeg[data-mode="abs"]{cursor:default}
310
324
  #lvModal .lvrow{display:flex;align-items:center;gap:10px;padding:8px 10px;border:1px solid transparent;border-radius:7px;cursor:pointer}
311
325
  #lvModal .lvrow:hover{background:var(--line)}
312
326
  #lvModal .lvrow.pick{background:var(--line);border-color:var(--brand)}
@@ -1184,7 +1198,7 @@ function parseLen(str){if(str==null)return null;
1184
1198
  if(s!==''){const m=s.match(/^([0-9]+(?:\.[0-9]+)?)?\s*([0-9]+)\/([0-9]+)$|^([0-9]+(?:\.[0-9]+)?)$/);
1185
1199
  if(!m)return null;
1186
1200
  if(m[4]!=null)inch=parseFloat(m[4]);else{if(m[1]!=null)inch+=parseFloat(m[1]);inch+=parseInt(m[2],10)/parseInt(m[3],10);}}
1187
- const t=ft*12+inch;return neg?-t:t;}
1201
+ const t=ft*12+inch;return Number.isFinite(t)?(neg?-t:t):null;} // fail closed on 1/0 (Infinity) or decimal overflow (1e999) so a bad value never reaches geometry
1188
1202
  function fmtFtIn(v){if(v==null||isNaN(v))return '';const neg=v<0;let sx=Math.round(Math.abs(v)*16);
1189
1203
  let ft=Math.floor(sx/192);sx-=ft*192;let inch=Math.floor(sx/16);let fr=sx-inch*16;
1190
1204
  let num=fr,den=16;while(num>0&&num%2===0){num/=2;den/=2;}const fs=num>0?(' '+num+'/'+den):'';
@@ -1357,10 +1371,15 @@ function linearOffsets(v,n){const o=[];for(let k=1;k<=n;k++)o.push([v[0]*k,v[1]*
1357
1371
  // Rectangular array: counts INCLUDE the original position; (0,0) is skipped so the grid adds n*m-1 copies.
1358
1372
  function arrayOffsets(vA,nA,vB,nB){const o=[];for(let i=0;i<nA;i++)for(let j=0;j<nB;j++){if(!i&&!j)continue;
1359
1373
  o.push([vA[0]*i+vB[0]*j,vA[1]*i+vB[1]*j,(vA[2]||0)*i+(vB[2]||0)*j]);}return o;}
1360
- // HUD input → {dist} (inches, along the live direction) or {comp:[dx,dy,dz] inches}. null = unparseable.
1374
+ // HUD input → {dist} (inches, along the live direction) or {comp:[x,y,z] inches, provided:[b,b,b]}. The
1375
+ // `provided` mask records which slots the user actually typed (","+Y → [false,true,false]) so ABS can hold
1376
+ // the anchor's coord on an omitted axis while REL/2D treat it as 0. null = unparseable.
1361
1377
  function parseVec(s){s=String(s==null?'':s).trim();if(!s)return null;
1362
- if(s.includes(',')){const p=s.split(',').map(t=>t.trim()===''?0:parseLen(t));if(p.some(x=>x==null)||p.length>3)return null;
1363
- return {comp:[p[0]||0,p[1]||0,p[2]||0]};}
1378
+ if(s.includes(',')){const toks=s.split(',');if(toks.length>3)return null;
1379
+ const comp=[0,0,0],provided=[false,false,false];
1380
+ for(let i=0;i<toks.length;i++){const t=toks[i].trim();if(t==='')continue;const v=parseLen(t);if(v==null)return null;comp[i]=v;provided[i]=true;}
1381
+ if(!provided.some(Boolean))return null; // a bare "," supplies no coordinate
1382
+ return {comp,provided};}
1364
1383
  const d=parseLen(s);return d==null?null:{dist:d};}
1365
1384
  // To-level TOS mapping (spec §4.5): default-follow ends land on the target level automatically;
1366
1385
  // explicit overrides shift by Δ so relative offsets survive. Columns keep their height (bos shifts by Δ).
@@ -3559,37 +3578,66 @@ function cmApplyOffsets(offs){const sel=sel2d();if(!sel.length){toast('Selection
3559
3578
  function cmCommit(v){cmApplyOffsets(cmOffsetsFor(v));}
3560
3579
  // --- numeric HUD (spec §3.3): type after the base pick → exact distance or dx,dy[,dz] (dz inches).
3561
3580
  // Live parse echo while typing; unparseable Enter flags the chip red (inline, not just a toast). ---
3562
- let cmHudEl=null;
3581
+ let cmHudEl=null,cmHudAbs=false,cmHudLock=false,cmHudConsumer='movecopy',cmHudPrimed=false; // UCS stage 3 typed-entry HUD state (per open)
3563
3582
  function cmHudIsOpen(){return !!(cmHudEl&&cmHudEl.style.display!=='none');}
3564
- function cmHudClose(){if(cmHudEl){cmHudEl.style.display='none';cmHudEl.classList.remove('err');const i=cmHudEl.querySelector('input');if(i)i.value='';}try{stage.focus({preventScroll:true});}catch(_){}}
3583
+ function cmHudClose(){if(cmHudEl){cmHudEl.style.display='none';cmHudEl.classList.remove('err');const i=cmHudEl.querySelector('input');if(i)i.value='';}
3584
+ if(view3d&&window.Steel3DView&&window.Steel3DView.pointEntryEnd)window.Steel3DView.pointEntryEnd(); // drop the view's captured token (a close is not a commit)
3585
+ try{stage.focus({preventScroll:true});}catch(_){}}
3586
+ function cmHudSetAbs(abs){if(cmHudLock)abs=true;cmHudAbs=!!abs;cmHudSyncPill();cmHudPlaceholder();if(cmHudEl)cmHudEcho();} // REL/ABS pill toggle — re-runs the same live parse/echo
3587
+ function cmHudSyncPill(){if(!cmHudEl)return;const pill=cmHudEl.querySelector('#cmHudPill');if(!pill)return;
3588
+ pill.classList.toggle('locked',cmHudLock); // Add 1st point → ABS only, REL hidden (not disabled)
3589
+ pill.querySelectorAll('.cmHudSeg').forEach(s=>{const on=((s.dataset.mode==='abs')===cmHudAbs);s.setAttribute('aria-checked',on?'true':'false');s.tabIndex=on?0:-1;s.classList.toggle('on',on);}); // roving tabindex: only the selected radio is Tab-reachable
3590
+ const abs=pill.querySelector('.cmHudSeg[data-mode="abs"]');if(abs)abs.setAttribute('data-tip',cmHudLock?'First point has no anchor to offset from — absolute only':'Absolute — X′,Y′,Z′ in the local frame (X,Y,Z if none)');}
3591
+ function cmHudPlaceholder(){if(!cmHudEl)return;const inp=cmHudEl.querySelector('input');if(!inp)return;
3592
+ inp.placeholder=cmHudAbs?(cmHudPrimed?"X′,Y′ · or X′,Y′,Z′":"X,Y · or X,Y,Z"):(cmHudConsumer==='add'?"dx,dy · or dx,dy,dz":"12'-6 · or dx,dy");}
3565
3593
  function cmHudEcho(){const inp=cmHudEl.querySelector('input'),lbl=cmHudEl.querySelector('#cmHudLbl');
3566
- const pv=parseVec(inp.value),n=(cmTool==='copy'&&!cmArrayMode&&cmCount>1)?(' ×'+cmCount):'';
3567
- lbl.textContent=(pv?(pv.dist!=null?('= '+fmtFtIn(pv.dist)):('= '+pv.comp.map(fmtFtIn).join(', ')))+n:n.trim());
3594
+ const pv=parseVec(inp.value),n=(cmTool==='copy'&&!cmArrayMode&&cmCount>1)?(' ×'+cmCount):'';let txt='';
3595
+ if(pv){if(pv.dist!=null){txt='= '+fmtFtIn(pv.dist);}
3596
+ else{const ax=!view3d?['','','']:(cmHudAbs?(cmHudPrimed?['X′','Y′','Z′']:['X','Y','Z']):['Δx','Δy','Δz']); // 3D echo carries the ′ prime + axis so the space is never ambiguous; 2D stays plain (unchanged)
3597
+ txt='= '+pv.comp.map((c,i)=>pv.provided[i]?((ax[i]?ax[i]+' ':'')+fmtFtIn(c)):null).filter(Boolean).join(', ');}}
3598
+ lbl.textContent=(txt?txt+n:n.trim());
3568
3599
  cmHudEl.classList.remove('err');}
3569
- function cmHudShow(seed){if(!cmDraft&&!(view3d&&window.Steel3DView&&window.Steel3DView.cmHasBase&&window.Steel3DView.cmHasBase()))return;
3600
+ function cmHudShow(seed){
3601
+ if(view3d&&window.Steel3DView&&window.Steel3DView.pointEntryBegin){ // 3D: capture the view's frame/anchor/aim token for this operation
3602
+ const consumer=cmTool?'movecopy':(mode==='add'?'add':null);if(!consumer)return;
3603
+ const b=window.Steel3DView.pointEntryBegin(consumer);if(!b||!b.ok)return;
3604
+ cmHudConsumer=consumer;cmHudLock=!!b.locked;cmHudAbs=!!(b.mode==='abs'||b.locked);cmHudPrimed=!!b.primed;
3605
+ }else{if(!cmDraft)return;cmHudConsumer='movecopy';cmHudLock=false;cmHudAbs=false;cmHudPrimed=false;} // 2D: Move/Copy relative-only (no ABS pill)
3570
3606
  if(!cmHudEl){cmHudEl=document.createElement('div');cmHudEl.id='cmHud';
3571
- const inp=document.createElement('input');inp.placeholder="12'-6 · or dx,dy";inp.autocomplete='off';inp.spellcheck=false;
3607
+ const pill=document.createElement('div');pill.id='cmHudPill';pill.setAttribute('role','radiogroup');pill.setAttribute('aria-label','Coordinate mode');
3608
+ const mkSeg=(v,label)=>{const bt=document.createElement('button');bt.type='button';bt.className='cmHudSeg';bt.dataset.mode=v;bt.textContent=label;bt.setAttribute('role','radio');
3609
+ bt.addEventListener('click',()=>{cmHudSetAbs(v==='abs');const inp=cmHudEl.querySelector('input');if(inp)inp.focus();});
3610
+ bt.addEventListener('keydown',ev=>{
3611
+ if(ev.key==='ArrowLeft'||ev.key==='ArrowRight'){ev.stopPropagation();ev.preventDefault();if(!cmHudLock){cmHudSetAbs(!cmHudAbs);const on=pill.querySelector('.cmHudSeg.on');if(on)on.focus();}}
3612
+ else if(ev.key==='Escape'){ev.stopPropagation();ev.preventDefault();cmHudClose();} // Escape closes the HUD even when a pill segment holds focus (not just the input)
3613
+ else if(ev.key==='Enter'){ev.stopPropagation();ev.preventDefault();cmHudCommit(cmHudEl.querySelector('input').value);}}); // Enter from the pill commits too, like the input
3614
+ return bt;};
3615
+ pill.append(mkSeg('rel','REL'),mkSeg('abs','ABS'));
3616
+ const inp=document.createElement('input');inp.autocomplete='off';inp.spellcheck=false;
3572
3617
  const lbl=document.createElement('span');lbl.id='cmHudLbl';
3573
- cmHudEl.append(inp,lbl);document.body.appendChild(cmHudEl);
3618
+ cmHudEl.append(pill,inp,lbl);document.body.appendChild(cmHudEl);
3574
3619
  inp.addEventListener('input',cmHudEcho);
3575
3620
  inp.addEventListener('keydown',ev=>{ev.stopPropagation();
3576
3621
  if(ev.key==='Enter'){ev.preventDefault();cmHudCommit(inp.value);}
3577
3622
  else if(ev.key==='Escape'){ev.preventDefault();cmHudClose();}});}
3623
+ cmHudEl.classList.toggle('v3d',!!view3d);
3624
+ cmHudSyncPill();cmHudPlaceholder();
3578
3625
  const scr3=view3d&&window.Steel3DView&&window.Steel3DView.cmLastClient?window.Steel3DView.cmLastClient():null;
3579
3626
  const scr=scr3||(cmLastEvt?[cmLastEvt.clientX,cmLastEvt.clientY]:[innerWidth/2,innerHeight/2]);
3580
- cmHudEl.style.left=Math.min(scr[0]+16,innerWidth-200)+'px';cmHudEl.style.top=Math.min(scr[1]+16,innerHeight-46)+'px';
3627
+ cmHudEl.style.left=Math.min(scr[0]+16,innerWidth-240)+'px';cmHudEl.style.top=Math.min(scr[1]+16,innerHeight-46)+'px';
3581
3628
  cmHudEl.style.display='flex';cmHudEl.classList.remove('err');
3582
3629
  const inp=cmHudEl.querySelector('input');inp.value=seed||'';cmHudEcho();inp.focus();
3583
3630
  try{inp.setSelectionRange(inp.value.length,inp.value.length);}catch(_){}}
3584
3631
  function cmHudCommit(str){const pv=parseVec(str);
3585
3632
  if(!pv){cmHudEl.classList.add('err');toast('Enter a length (12\'-6) or components (dx,dy)');return;}
3586
- if(view3d&&window.Steel3DView&&window.Steel3DView.cmHudApply){ // 3D: the view maps the value into the working-plane basis and commits via onTransform3d
3587
- const res=window.Steel3DView.cmHudApply(pv);
3588
- if(res&&res.err){cmHudEl.classList.add('err');toast(res.err);return;}
3589
- if(res&&res.staged){cmHudClose();panel();return;} // array direction A staged
3590
- cmHudClose();return;}
3633
+ if(view3d&&window.Steel3DView){ // 3D: the view resolves via the pure resolver + its token, commits via onTransform3d/onAddMember3d
3634
+ const fn=cmHudConsumer==='add'?window.Steel3DView.drHudApply:window.Steel3DView.cmHudApply;
3635
+ if(fn){const res=fn(pv,cmHudAbs);
3636
+ if(res&&res.err){cmHudEl.classList.add('err');toast(res.err);return;}
3637
+ if(res&&res.staged){cmHudClose();panel();return;} // array direction A staged
3638
+ cmHudClose();return;}}
3591
3639
  let v;
3592
- if(pv.comp){const u=P.frame?P.frame.u:[1,0],vv=[u[1],-u[0]]; // typed components live in the local frame; +Y = up the plan
3640
+ if(pv.comp){const u=P.frame?P.frame.u:[1,0],vv=[u[1],-u[0]]; // 2D typed components live in P.frame; +Y = up the plan
3593
3641
  const dxp=pv.comp[0]*FT/12,dyp=pv.comp[1]*FT/12;
3594
3642
  v=[dxp*u[0]+dyp*vv[0],dxp*u[1]+dyp*vv[1],pv.comp[2]||0];}
3595
3643
  else{if(!cmLastPtr){cmHudEl.classList.add('err');toast('Move the mouse to aim, or type dx,dy');return;}
@@ -3932,7 +3980,7 @@ svg.addEventListener('dblclick',e=>{ // dbl-click a grid bubble → rename tha
3932
3980
  gridRenameBubble(gb.dataset.gl!=null?'l':(gb.dataset.gv!=null?'v':'h'),+(gb.dataset.gl!=null?gb.dataset.gl:(gb.dataset.gv!=null?gb.dataset.gv:gb.dataset.gh)),gb.querySelector('circle'));}});
3933
3981
  function setMode(){document.body.classList.toggle('add',mode==='add');document.getElementById('mAdd').classList.toggle('on',mode==='add');
3934
3982
  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)
3935
- if(mode!=='add'){drawDraft=null;drawPrevClear();}} // leaving Add-member drops any in-progress start point + its preview
3983
+ 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)
3936
3984
  document.getElementById('mAdd').onclick=()=>{if(dimMode){dimMode=false;setDimMode();}if(csaxisMode){csaxisMode=false;setCsMode();}if(cmTool)disarmCm();
3937
3985
  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
3938
3986
  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
@@ -4029,7 +4077,7 @@ addEventListener('keydown',e=>{
4029
4077
  if(e.key==='Enter'&&dimMode&&dimChainPrev){e.preventDefault();dimChainPrev=null;dimPrevClear();render();return;} // Enter ends a running chain
4030
4078
  if(e.key==='Escape'&&dimMode){if(dimChainPrev){dimChainPrev=null;dimPrevClear();}else if(dimDraft){dimDraft=null;dimPrevClear();}else{dimMode=false;setDimMode();}render();return;} // Esc: end the chain → drop the in-progress dim → exit the tool
4031
4079
  if(e.key==='Escape'&&selDimIds.size){if(dimSplitMode){dimSplitMode=false;snapClear();render();}else{selDimIds.clear();render();}return;} // Esc on a selected dim: end split mode → else deselect
4032
- if(e.key==='Escape'&&view3d&&mode==='add'&&window.Steel3DView&&window.Steel3DView.drEscape&&window.Steel3DView.drEscape()){return;} // 3D draw: 1st Esc drops the in-progress start pick, 2nd exits add mode (falls through below)
4080
+ if(e.key==='Escape'&&view3d&&mode==='add'){if(cmHudIsOpen()){cmHudClose();return;}if(window.Steel3DView&&window.Steel3DView.drEscape&&window.Steel3DView.drEscape())return;} // 3D draw: Esc closes an open typed-entry HUD first, then drops the in-progress start pick, then exits add mode (falls through below)
4033
4081
  if(e.key==='Escape'&&!view3d&&mode==='add'&&drawDraft){drawDraft=null;drawPrevClear();render();return;} // 2D Add-member: 1st Esc drops the in-progress start point (2nd falls through below → exits the tool), like the Dimension tool
4034
4082
  if(e.key==='Escape'){if(geoMode){geoMode=null;setGeo();render();return;}if(mode==='add'){mode='sel';setMode();}picking=false;pickKind='profile';pickEnd=null;selIds.clear();selGridIds.clear();render();return;}
4035
4083
  if((e.key==='Delete'||e.key==='Backspace')&&view3d&&window.Steel3DView.selectedClips&&window.Steel3DView.selectedClips().length&&!selIds.size&&!sel3dDimIds.size&&!selDimIds.size&&!inForm){e.preventDefault();window.Steel3DView.deleteSelectedClips();return;} // 3D: Del removes the selected clip plane(s)/box(es) — only when nothing else is selected (clip selection is exclusive)
@@ -4058,7 +4106,8 @@ addEventListener('keydown',e=>{
4058
4106
  if(view3d&&window.Steel3DView&&window.Steel3DView.setCmAxis)window.Steel3DView.setCmAxis(ak);
4059
4107
  else{cmAxis=ak==='f'?'free':ak;cmRefreshPrev();}return;}
4060
4108
  const hasBase=cmDraft||(view3d&&window.Steel3DView&&window.Steel3DView.cmHasBase&&window.Steel3DView.cmHasBase());
4061
- if(hasBase&&/^[0-9.\-']$/.test(e.key)){e.preventDefault();cmHudShow(e.key);return;}}
4109
+ 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
4110
+ 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)
4062
4111
  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)
4063
4112
  if(ck==='m'){e.preventDefault();armCm('move',false);return;}
4064
4113
  if(ck==='c'){e.preventDefault();armCm('copy',false);return;}}
@@ -4248,6 +4297,8 @@ const view3dApi={
4248
4297
  disarmTransform:()=>{if(cmTool){disarmCm();render();}}, // the 3D dim tool arming kicks Move/Copy off the left-click
4249
4298
  // 3D draw-on-plane (spec §7): the editor's add-member mode + profile drive it; two plane picks (scene mm) come back here.
4250
4299
  addModeActive:()=>mode==='add',
4300
+ closeCmHud:()=>{if(cmHudIsOpen())cmHudClose();}, // the view closes an open typed-entry HUD on frame drift / rebuild (invalidatePointEntry)
4301
+
4251
4302
  disarmAdd:()=>{if(mode==='add'){mode='sel';setMode();render();}},
4252
4303
  onAddMember3d:(aMm,bMm)=>{const k=304.8/((P&&P.pt_per_ft>0)?P.pt_per_ft:1),r6=n=>Math.round(n*1e6)/1e6; // mm → wp px (Y FLIPPED) + elevation inches
4253
4304
  const wpA=[r6(aMm[0]/k),r6(-aMm[1]/k)],wpB=[r6(bMm[0]/k),r6(-bMm[1]/k)];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.91.0",
3
+ "version": "0.92.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": {