@floless/app 0.104.0 → 0.104.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53583,7 +53583,7 @@ function appVersion() {
53583
53583
  return resolveVersion({
53584
53584
  isSea: isSea2(),
53585
53585
  sqVersionXml: readSqVersionXml(),
53586
- define: true ? "0.104.0" : void 0,
53586
+ define: true ? "0.104.1" : void 0,
53587
53587
  pkgVersion: readPkgVersion()
53588
53588
  });
53589
53589
  }
@@ -53593,7 +53593,7 @@ function resolveChannel(s) {
53593
53593
  return "dev";
53594
53594
  }
53595
53595
  function appChannel() {
53596
- return resolveChannel({ isSea: isSea2(), define: true ? "0.104.0" : void 0 });
53596
+ return resolveChannel({ isSea: isSea2(), define: true ? "0.104.1" : void 0 });
53597
53597
  }
53598
53598
 
53599
53599
  // workflow-update.ts
@@ -262,6 +262,43 @@ export function snapPoint(dragged, candidates, toScreen, tolPx) {
262
262
  return best ? { snapped: bestPt, candidate: best } : { snapped: dragged, candidate: null };
263
263
  }
264
264
 
265
+ /** An intersection is worth this many px of aim against a line when choosing BETWEEN grid levels. */
266
+ export const GRID_INT_HEADSTART_PX = 3;
267
+ /** Scores this close are "the same pixel" — the levels are stacked, so distance can't choose. */
268
+ export const GRID_LEVEL_TIE_PX = 0.5;
269
+
270
+ /**
271
+ * Choose which grid LEVEL a snap lands on. A structural grid is drawn at every visible Z datum, so the
272
+ * same cursor can be within snapping range of several — and each level is evaluated on its own plane, so
273
+ * the level chosen IS the elevation the point gets.
274
+ *
275
+ * `hits` = one entry per level that produced a snap: { z, d, type } (d = screen px from the cursor,
276
+ * type = the winning candidate type on that level). Returns the winning entry, or null for no hits.
277
+ *
278
+ * Rules, in order:
279
+ * - lowest score wins, where score = d + (an intersection scores as-is, a line pays GRID_INT_HEADSTART_PX).
280
+ * So an intersection wins a near-tie against a line — snapPoint applies that same precedence WITHIN a
281
+ * level — but only by a bounded head start: a line right under the cursor still beats a node several px
282
+ * away on another floor, because landing on the wrong ELEVATION is the worse error.
283
+ * - scores within GRID_LEVEL_TIE_PX are a tie: straight down a Top view every level projects to the SAME
284
+ * pixel, and the elevation you dimension to must never come down to float noise. Nearest `planeZ` wins
285
+ * (the plane the tool is already working on — the member under the cursor, else the scene floor).
286
+ * - ties beyond that keep the earlier entry, so a fixed `hits` order gives a deterministic answer.
287
+ */
288
+ export function pickGridLevel(hits, planeZ) {
289
+ const score = (h) => h.d + (h.type === 'grid-int' ? 0 : GRID_INT_HEADSTART_PX);
290
+ let best = null, bestScore = Infinity;
291
+ for (const h of hits || []) {
292
+ if (!h) continue;
293
+ const s = score(h);
294
+ const beats = !best || (Math.abs(s - bestScore) < GRID_LEVEL_TIE_PX
295
+ ? Math.abs(h.z - planeZ) < Math.abs(best.z - planeZ)
296
+ : s < bestScore);
297
+ if (beats) { best = h; bestScore = s; }
298
+ }
299
+ return best;
300
+ }
301
+
265
302
  // ---- working-plane math (CAD copy/move epic §6) — pure vector helpers, scene-mm space ----
266
303
  const _dot = (a, b) => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
267
304
  const _cross = (a, b) => [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
@@ -17,7 +17,7 @@
17
17
  import * as THREE from 'three';
18
18
  import { OrbitControls } from 'three/addons/OrbitControls.js';
19
19
  import { Brush, Evaluator, SUBTRACTION } from 'three-bvh-csg';
20
- import { snapCandidates, snapPoint, planPointToWp, memberGeometry, elevationLevels, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, vecToPlane, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, snapGridPoint, clipSegmentToPlanes, pointSegmentDistance2d, perspectiveSegmentParameter, gridDepthWins, segmentHitsRect2d, projectedFootprintHitsRect2d } from './steel-3d-core.js';
20
+ import { snapCandidates, snapPoint, planPointToWp, memberGeometry, elevationLevels, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, vecToPlane, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, snapGridPoint, clipSegmentToPlanes, pointSegmentDistance2d, perspectiveSegmentParameter, gridDepthWins, segmentHitsRect2d, projectedFootprintHitsRect2d, pickGridLevel } from './steel-3d-core.js';
21
21
  import { gridGeometry, gridCandidates3d, mmPerPx, visibleGridLevels } from './grid-core.js';
22
22
 
23
23
  let renderer, scene, perspCam, orthoCam, camera, controls, root, api, canvasEl, ro, rafId, grid, raycaster, downXY, lastPick = '(none)';
@@ -891,6 +891,7 @@ function positionSelLenLabels() {
891
891
  // the contract via api.getGrid() (grid-core owns parsing/geometry); allCandidates() feeds the same
892
892
  // grid into snapping, plan-locked.
893
893
  let structGridGroup = null, gridLabelGroup = null;
894
+ let gridLevelsMm = []; // world Zs the grid is DRAWN at (one per visible level) — set by buildStructGrid so grid snapping can never drift from what the user sees
894
895
  const structGridLines = new Map();
895
896
  let selectedGridIds = new Set();
896
897
  const gridTexCache = new Map(); // 'b:LABEL' bubble / 't:LABEL' tag -> CanvasTexture (kept until dispose)
@@ -945,10 +946,11 @@ function clearStructGrid() {
945
946
  for (const o of [...grp.children]) { grp.remove(o); if (o.geometry) o.geometry.dispose(); if (o.material) o.material.dispose(); } // sprite materials are per-sprite; textures stay cached
946
947
  if (parent) parent.remove(grp);
947
948
  }
948
- structGridGroup = gridLabelGroup = null;structGridLines.clear();
949
+ structGridGroup = gridLabelGroup = null;structGridLines.clear();gridLevelsMm = [];
949
950
  }
950
951
  function buildStructGrid() {
951
952
  clearStructGrid();
953
+ dimCandidates3d = null; tfCandidates = null; clipCandidates = null; clipLevels = null; // the grid just changed → EVERY cached snap set built from the OLD one is stale (dim, Move/Copy + Add, clip-box draw). rebuild() already nulls these, but refresh3DGrid() (grid panel edits, and the plan switch setPlan now fires) reaches us without it, which would pair one sheet's grid X/Y with another's elevations.
952
954
  if (!api || !api.getGrid || !scene) return;
953
955
  let g = null, geo = null;
954
956
  try { g = api.getGrid(); if (!g || g.on === false) return; geo = gridGeometry(g, api.ptPerFt()); }
@@ -958,8 +960,12 @@ function buildStructGrid() {
958
960
  const mmX = (px) => px * k, mmY = (px) => -px * k; // display → scene (Y flips)
959
961
  const levels = geo.zs.length ? visibleGridLevels(geo.zs, g.hidden_z) : [{ mm: 0, label: '0' }];
960
962
  if (!levels.length) return; // every authored Z datum is hidden
963
+ gridLevelsMm = levels.map((lv) => lv.mm); // the planes grid snapping evaluates on — same list, same order as what gets drawn below
961
964
  structGridGroup = new THREE.Group();
962
- const addLogical=(id,ends)=>{const pts=[];for(const lv of levels){const z=lv.mm-25;pts.push(V(ends[0][0],ends[0][1],z),V(ends[1][0],ends[1][1],z));}const on=selectedGridIds.has(id);const seg=new THREE.LineSegments(new THREE.BufferGeometry().setFromPoints(pts),new THREE.LineDashedMaterial({color:on?0x3b82f6:0x64748b,dashSize:450,gapSize:220,transparent:true,opacity:on?1:0.85}));seg.computeLineDistances();seg.userData.gridId=id;seg.userData.segments=pts.map(p=>[p.x,p.y,p.z]);structGridLines.set(id,seg);structGridGroup.add(seg);};
965
+ // Drawn at the level's TRUE Z. It used to sit 25 mm under it ("no z-fight/burial"), but the snap
966
+ // targets (gridCandidates3d) are at the true Z — so the reticle floated a fixed 25 mm above the line
967
+ // the user aimed at, which reads as several px of snap error once you zoom in (Pawel 2026-07-18).
968
+ const addLogical=(id,ends)=>{const pts=[];for(const lv of levels){const z=lv.mm;pts.push(V(ends[0][0],ends[0][1],z),V(ends[1][0],ends[1][1],z));}const on=selectedGridIds.has(id);const seg=new THREE.LineSegments(new THREE.BufferGeometry().setFromPoints(pts),new THREE.LineDashedMaterial({color:on?0x3b82f6:0x64748b,dashSize:450,gapSize:220,transparent:true,opacity:on?1:0.85}));seg.computeLineDistances();seg.userData.gridId=id;seg.userData.segments=pts.map(p=>[p.x,p.y,p.z]);structGridLines.set(id,seg);structGridGroup.add(seg);};
963
969
  geo.v.forEach((l,i)=>addLogical('gv:'+i,[[mmX(l.x),mmY(l.lo)],[mmX(l.x),mmY(l.hi)]]));
964
970
  geo.h.forEach((l,i)=>addLogical('gh:'+i,[[mmX(l.lo),mmY(l.y)],[mmX(l.hi),mmY(l.y)]]));
965
971
  (geo.lines||[]).forEach((l,i)=>addLogical('gl:'+(l.id!=null?l.id:i),[[mmX(l.a[0]),mmY(l.a[1])],[mmX(l.b[0]),mmY(l.b[1])]]));
@@ -3204,28 +3210,34 @@ function dimPointAt(e, anchor) {
3204
3210
  const hit = rayToPlane(e.clientX, e.clientY, planeZ); if (!hit) return null;
3205
3211
  if (!dimCandidates3d) dimCandidates3d = allCandidates(null); // member + grid candidates (allCandidates folds in the grid)
3206
3212
  const cands = dimCandidates3d.filter((c) => candAllowed3d(c.type)); // right-click override (one type / free) + the persistent running-snaps from the ⋯ menu
3207
- // Grid geometry is drawn at its OWN Z (often ground, e.g. 0), which can be far from the steel-level planeZ.
3208
- // Evaluate grid candidates against a ray hit on the GRID plane so they align with what's drawn; member
3209
- // candidates keep the member/scene plane. Pick whichever winner is closest to the cursor on screen.
3210
- const gz = gridPlaneZ();
3213
+ // Grid geometry is drawn at its OWN Z levels, which can be far from the steel-level planeZ — and a grid
3214
+ // with several visible datums is drawn at ALL of them (the candidates are plan-only: candidatePoint keeps
3215
+ // the dragged Z, so the plane we evaluate on IS the elevation the snap lands at). So try every drawn level
3216
+ // and keep the one nearest the cursor on screen — dimension to the 2nd-floor grid and you get the 2nd
3217
+ // floor, not the ground copy. Member candidates keep the member/scene plane; closest-on-screen wins overall.
3211
3218
  const isGrid = (c) => c.type === 'grid-int' || c.type === 'grid-line';
3212
- const gridCands = gz != null ? cands.filter(isGrid) : [];
3213
- const memCands = gridCands.length ? cands.filter((c) => !isGrid(c)) : cands;
3219
+ const gridCands = gridLevelsMm.length ? cands.filter(isGrid) : [];
3220
+ // Grid candidates belong to the level loop below and NOWHERE else. Never let them fall through to the
3221
+ // member set: gridCandidates3d gates on g.on alone and ignores hidden_z, so with every Z datum hidden
3222
+ // the grid draws nothing yet still emits candidates — which would snap, invisibly, on the member plane.
3223
+ // What isn't drawn must not snap. (No grid at all → gridCandidates3d returns [] and this filters nothing.)
3224
+ const memCands = cands.filter((c) => !isGrid(c));
3214
3225
  const best = (cset, dragged) => { if (!cset.length || !dragged) return null; const r = snapPoint(dragged, cset, toScreen, SNAP_TOL_PX);
3215
3226
  if (!r.candidate) return null; const a = toScreen(dragged), b = toScreen(r.snapped); return { r, d: Math.hypot(a.x - b.x, a.y - b.y) }; };
3216
3227
  const rMem = best(memCands, [hit[0], hit[1], hit[2]]);
3217
- const hitGrid = gridCands.length ? rayToPlane(e.clientX, e.clientY, gz) : null;
3218
- const rGrid = best(gridCands, hitGrid);
3228
+ // Evaluate the grid on EVERY drawn level (each on its own plane, so the level picked is the elevation the
3229
+ // point gets) and let the pure pickGridLevel rule choose — bounded intersection head start, planeZ breaking
3230
+ // the Top-view tie where the levels stack on one pixel. See its doc comment in steel-3d-core for the why.
3231
+ const gridHits = [];
3232
+ if (gridCands.length) for (const gz of gridLevelsMm) {
3233
+ const r = best(gridCands, rayToPlane(e.clientX, e.clientY, gz)); // null when the view is edge-on to that level → skip it, never a NaN point
3234
+ if (r) gridHits.push({ z: gz, d: r.d, type: r.r.candidate.type, r: r.r });
3235
+ }
3236
+ const gridWin = pickGridLevel(gridHits, planeZ);
3237
+ const rGrid = gridWin ? { r: gridWin.r, d: gridWin.d } : null;
3219
3238
  const win = rGrid && (!rMem || rGrid.d <= rMem.d) ? rGrid : rMem;
3220
3239
  return { p: win ? win.r.snapped : hit, type: win ? win.r.candidate.type : null };
3221
3240
  }
3222
- // The grid's world Z (where its snap targets live), derived from the current grid candidates — or null if no grid.
3223
- function gridPlaneZ() {
3224
- if (!dimCandidates3d) return null;
3225
- const p = dimCandidates3d.find((c) => c.type === 'grid-int'); if (p) return p.p[2];
3226
- const l = dimCandidates3d.find((c) => c.type === 'grid-line'); if (l) return l.a[2];
3227
- return null;
3228
- }
3229
3241
  // The axis to measure on: Alt held during the 2nd pick forces a pure-vertical (Z) measurement,
3230
3242
  // overriding the sticky axis (else a sticky X/Y would collapse the Alt-locked point to zero length).
3231
3243
  // The ONE axis a dimension measures along, resolving the lock set: Alt (held on the 2nd pick) forces vertical Z;
@@ -3815,6 +3827,7 @@ function debug() {
3815
3827
  endpointColors: epGroup ? epGroup.children.map((c) => '#' + c.material.color.getHexString()) : [],
3816
3828
  hoverId, hoverEp, dragEp, refLine: refLineOn,
3817
3829
  snapMarker: marker && marker.visible ? { type: lastSnapType3d, at: [marker.position.x, marker.position.y, marker.position.z] } : null, // test-observability for the snap reticle
3830
+ gridLevels: [...gridLevelsMm], // the drawn grid elevations a grid snap can land on (one plane per visible datum)
3818
3831
 
3819
3832
  inFrustum: (() => { let n = 0, t = 0; for (const m of meshById.values()) { t++; const v = m.getWorldPosition(new THREE.Vector3()).project(camera); if (Math.abs(v.x) <= 1 && Math.abs(v.y) <= 1 && v.z >= -1 && v.z <= 1) n++; } return { n, t }; })(),
3820
3833
  camPos: camera ? [camera.position.x, camera.position.y, camera.position.z] : null,
@@ -6884,6 +6884,7 @@ function setPlan(i){C.active=i;P=C.plans[i];
6884
6884
  if(!P.autofilled){autofillTOS();P.autofilled=true;}
6885
6885
  const ds=new Set([...(P.details||[]).map(d=>d.text),...Object.keys(C.custom_details)]);document.getElementById('detailsBtn').textContent='Details ('+ds.size+')';
6886
6886
  setMode();render();fitToWindow();
6887
+ refresh3DGrid(); // the grid is PER-PLAN, so a plan switch must re-render it in 3D too. The plan <select> is 2D-only, but the Confidence report's Locate buttons switch sheets from 3D — without this the 3D view keeps drawing the OLD sheet's grid while snapping reads the NEW sheet's (found by Codex on the grid-level review)
6887
6888
  const ps=document.getElementById('planSel');if(ps)ps.value=String(i);}
6888
6889
  const planSel=document.getElementById('planSel');
6889
6890
  planSel.innerHTML=C.plans.map((p,i)=>`<option value="${i}">${esc(p.sheet)} · ${esc(p.title)}</option>`).join('');
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.104.0",
3
+ "version": "0.104.1",
4
4
  "type": "module",
5
- "description": "Thin localhost host for floless.app \u2014 serves web/ and shells the aware CLI. No engine, no LLM.",
5
+ "description": "Thin localhost host for floless.app — serves web/ and shells the aware CLI. No engine, no LLM.",
6
6
  "bin": {
7
7
  "floless-app": "bin/floless.mjs"
8
8
  },