@floless/app 0.160.0 → 0.161.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.
@@ -1102,9 +1102,9 @@ export function isUnknownElev(e) { return !!e && e.unknown === true; }
1102
1102
  * said out loud that the drawings did not settle it.
1103
1103
  *
1104
1104
  * It carries a real `known`, so anything that only asks "is there a number?" builds it, which is the
1105
- * whole point. Anything that asks "is this height EVIDENCE?" has to ask this too — pricing it,
1106
- * scoring it, aligning another member to it, or hanging a connection off it are all decisions that
1107
- * must not be made from a guess.
1105
+ * whole point. Anything that asks "is this height EVIDENCE?" has to ask this too — scoring it,
1106
+ * aligning another member to it, or hanging a connection off it are all decisions that must not be
1107
+ * made from a guess. The bill prices it, but only LABELLED as assumed (owner ruling 2026-10-24, #2735).
1108
1108
  */
1109
1109
  export function isAssumedElev(e) { return !!e && e.assumed === true; }
1110
1110
  /** Either spelling of "nobody has confirmed this height". */
@@ -1212,13 +1212,14 @@ export function columnBelowReachOf(doc) {
1212
1212
  * - 'crossing' — the cut passes through the column (exactly `sheetIncludesElevation`, tolerance included).
1213
1213
  * - 'below' — the column ends under the cut by more than that tolerance and by no more than `reach`.
1214
1214
  * - 'far-below' — it ends further under the cut than `reach`: never drawn by this rule.
1215
- * - 'above' — it starts over the cut.
1215
+ * - 'near-above' — it starts over the cut by no more than `nearAbove` (#2815): a base read a little high.
1216
+ * - 'above' — it starts over the cut by more than that.
1216
1217
  * - 'unknown' — an endpoint elevation or the cut is not a known number. An unknown elevation is an RFI,
1217
1218
  * not a position, so it is never guessed onto a sheet (the §5.3 "nearest sheet" rule).
1218
1219
  *
1219
1220
  * Orientation-agnostic, like `sheetIncludesElevation`: the top is the higher of the two endpoints.
1220
1221
  */
1221
- export function columnCutRelation(fromZ, toZ, cutMm, reach = COLUMN_BELOW_REACH_MM) {
1222
+ export function columnCutRelation(fromZ, toZ, cutMm, reach = COLUMN_BELOW_REACH_MM, nearAbove = COLUMN_NEAR_CUT_MM) {
1222
1223
  const a = knownZ(fromZ), b = knownZ(toZ);
1223
1224
  if (a === null || b === null || !Number.isFinite(cutMm)) return 'unknown';
1224
1225
  if (sheetIncludesElevation(fromZ, toZ, cutMm)) return 'crossing';
@@ -1230,7 +1231,44 @@ export function columnCutRelation(fromZ, toZ, cutMm, reach = COLUMN_BELOW_REACH_
1230
1231
  const gap = Math.round((cutMm - top) * 1e6) / 1e6;
1231
1232
  return gap <= reach ? 'below' : 'far-below';
1232
1233
  }
1233
- return 'above';
1234
+ // The column STARTS over the cut. Within a reading tolerance it is the same floor (#2815); the gap is
1235
+ // rounded like the one above so a base exactly at the tolerance does not flip on arithmetic noise.
1236
+ const gapAbove = Math.round((Math.min(a, b) - cutMm) * 1e6) / 1e6;
1237
+ return gapAbove <= nearAbove ? 'near-above' : 'above';
1238
+ }
1239
+
1240
+ /**
1241
+ * How far ABOVE a plan's cut level a column's base may sit and still be drawn on that plan (#2815). The
1242
+ * mirror of `COLUMN_BELOW_REACH_MM`: that one forgives a top that stops under the floor, this one forgives a
1243
+ * base that was READ a little over it. On a vision-only sheet a base plan's level (BOB +99.350) and the
1244
+ * column bases read off the elevations (24-27 mm higher on ADNOC v4) are two readings of one floor, and a
1245
+ * strict cut emptied the whole base plan.
1246
+ *
1247
+ * NEEDS OWNER. 50 mm (2" imperial): half a millimetre of paper at 1:100, the least a vision read can
1248
+ * resolve, and about twice the 24-27 mm seen. It is a DISPLAY rule only: the column is drawn where it is, no
1249
+ * height is moved or rewritten, and the sheet's notice still says the level is the person's to fix. A column
1250
+ * further off is never guessed onto the sheet; the notice names the nearest ones and the gap and offers to
1251
+ * show them anyway. Keyed on the project's environment for the reason `defaultColumnBelowReach` is. Not in
1252
+ * the frozen `MODEL_V2_TOL`, which is merge/refusal semantics.
1253
+ */
1254
+ export const COLUMN_NEAR_CUT_MM_METRIC = 50;
1255
+ export const COLUMN_NEAR_CUT_MM = 2 * IN_TO_MM;
1256
+ export function defaultColumnNearCut(environment) {
1257
+ return environment === 'UK' ? COLUMN_NEAR_CUT_MM_METRIC : COLUMN_NEAR_CUT_MM;
1258
+ }
1259
+
1260
+ /**
1261
+ * The gap, in mm, between a column's nearest end and a cut level, and which side it is on: 0 when the cut
1262
+ * passes through it. null when an elevation is unknown (an unknown height is a question, not a distance).
1263
+ * What the "no column reaches this level" notice names the nearest columns by.
1264
+ */
1265
+ export function columnCutGap(fromZ, toZ, cutMm) {
1266
+ const a = knownZ(fromZ), b = knownZ(toZ);
1267
+ if (a === null || b === null || !Number.isFinite(cutMm)) return null;
1268
+ const lo = Math.min(a, b), hi = Math.max(a, b);
1269
+ if (cutMm > hi) return { mm: Math.round((cutMm - hi) * 1e6) / 1e6, side: 'below' };
1270
+ if (cutMm < lo) return { mm: Math.round((lo - cutMm) * 1e6) / 1e6, side: 'above' };
1271
+ return { mm: 0, side: 'at' };
1234
1272
  }
1235
1273
 
1236
1274
  /** Apply a similarity transform (from registerSheet) to a local [x,y] → world mm. */
@@ -2427,3 +2465,74 @@ export function clampSwingTheta(thetaReq, barriers, mode, snapRad) {
2427
2465
  const steps = Math.floor(Math.abs(limit) / step);
2428
2466
  return { theta: Math.sign(limit) * steps * step, clamped: true };
2429
2467
  }
2468
+
2469
+ /**
2470
+ * Which labels to hide so none prints on top of another (#2780 item 3).
2471
+ *
2472
+ * A dense frame puts a property label (`Profile: UC356X153`) on nearly every member and the chips land on each
2473
+ * other, so no one of them can be read. This keeps the labels that matter most and hides each label whose box
2474
+ * would overlap one already kept; the hidden ones come back as the view is zoomed or the camera moves in, because
2475
+ * the caller runs this again for every layout.
2476
+ *
2477
+ * Pure and unit-free: boxes are CENTRE (x, y) with width `w` and height `h`, in any one consistent space (screen
2478
+ * px in 3D, drawing units in 2D). `priority` is higher-wins (a selected member beats a long one beats a short
2479
+ * one); equal priorities keep input order, so the result is stable from one frame to the next. Greedy, with a
2480
+ * spatial hash so a model with thousands of labels is not quadratic.
2481
+ *
2482
+ * @param {Array<{ key: string|number, x: number, y: number, w: number, h: number, priority?: number }>} items
2483
+ * @param {number} [gap] extra clearance, in the same units, that two kept boxes must keep between them
2484
+ * @returns {Set<string|number>} the keys to HIDE
2485
+ */
2486
+ export function declutterLabelRects(items, gap = 0) {
2487
+ const hidden = new Set();
2488
+ const order = items
2489
+ .map((item, i) => ({ item, i }))
2490
+ .filter(({ item }) => item && [item.x, item.y, item.w, item.h].every(Number.isFinite))
2491
+ .sort((a, b) => ((b.item.priority || 0) - (a.item.priority || 0)) || (a.i - b.i));
2492
+ if (!order.length) return hidden;
2493
+ // Cells are sized for the TYPICAL label (the median of the larger side), not the widest: one oversized box would otherwise
2494
+ // make every cell as big as itself and every comparison pairwise. An oversized box simply spans more cells, which is
2495
+ // still correct.
2496
+ const sizes = order.map(({ item }) => Math.max(item.w, item.h)).sort((a, b) => a - b);
2497
+ const cell = Math.max(sizes[sizes.length >> 1], 1) + gap; // the MEDIAN: an outlier cannot move it
2498
+ const grid = new Map();
2499
+ const everyKept = [], bigKept = [];
2500
+ const cellKey = (cx, cy) => `${cx},${cy}`;
2501
+ for (const { item } of order) {
2502
+ const x0 = item.x - item.w / 2 - gap / 2, x1 = item.x + item.w / 2 + gap / 2;
2503
+ const y0 = item.y - item.h / 2 - gap / 2, y1 = item.y + item.h / 2 + gap / 2;
2504
+ const cx0 = Math.floor(x0 / cell), cx1 = Math.floor(x1 / cell), cy0 = Math.floor(y0 / cell), cy1 = Math.floor(y1 / cell);
2505
+ const hits = (k) => x0 < k.x1 && x1 > k.x0 && y0 < k.y1 && y1 > k.y0;
2506
+ // A box that would cover more than MAX_CELLS cells (one very long label among many small ones) is OVERSIZED: it is not
2507
+ // put in the hash (its cell count is unbounded), it is checked pairwise against every kept box, and every later box
2508
+ // checks the short oversized list too. Work stays bounded however large one box is.
2509
+ const cells = (cx1 - cx0 + 1) * (cy1 - cy0 + 1);
2510
+ const oversized = !(cells <= MAX_CELLS);
2511
+ let clash = false;
2512
+ if (oversized) {
2513
+ clash = everyKept.some(hits);
2514
+ } else {
2515
+ clash = bigKept.some(hits);
2516
+ for (let cx = cx0; cx <= cx1 && !clash; cx++) {
2517
+ for (let cy = cy0; cy <= cy1 && !clash; cy++) {
2518
+ for (const k of grid.get(cellKey(cx, cy)) || []) {
2519
+ if (hits(k)) { clash = true; break; }
2520
+ }
2521
+ }
2522
+ }
2523
+ }
2524
+ if (clash) { hidden.add(item.key); continue; }
2525
+ const kept = { x0, x1, y0, y1 };
2526
+ everyKept.push(kept);
2527
+ if (oversized) { bigKept.push(kept); continue; }
2528
+ for (let cx = cx0; cx <= cx1; cx++) {
2529
+ for (let cy = cy0; cy <= cy1; cy++) {
2530
+ const id = cellKey(cx, cy);
2531
+ const list = grid.get(id);
2532
+ if (list) list.push(kept); else grid.set(id, [kept]);
2533
+ }
2534
+ }
2535
+ }
2536
+ return hidden;
2537
+ }
2538
+ const MAX_CELLS = 16;
@@ -21,7 +21,7 @@ import { surfaceTextures, applyTriplanar, TILE_MM, DIRECTIONAL } from './steel-m
21
21
  import { canvasToolGuidanceState } from './steel-canvas-guidance.js';
22
22
  import { Brush, Evaluator, SUBTRACTION } from 'three-bvh-csg';
23
23
  import { FT_TO_MM as FT_MM } from './steel-units.js';
24
- import { snapPoint, planPointToWp, memberGeometry, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, projectToPlane, snapGridPoint, projectPointOnSegment2d, projectPointOnSegment3d, selectedFrontmostHit, worldEndpointCommit, SEG_DEGENERACY, segmentHitsRect2d, projectedFootprintHitsRect2d, pickGridLevel, selectedLengthLabelAnchors, sectionKindOf, sectionTopology, memberShapeKind, memberExtrudes, memberSectionTopology, memberMeshAxes, positionSwingDelta, snapToStep, rollCommitNorm, unwrapAngleStep, translateEndpoints, livePositionState, swingBasis, swingEndpoint, swingBarriers, clampSwingTheta, POSITION_SWING_MARGIN_RAD, POSITION_OFFSET_SNAP_MM, POSITION_ROT_SNAP_DEG, POSITION_BASIS_CAPABILITY_VERSION } from './steel-3d-core.js';
24
+ import { snapPoint, planPointToWp, memberGeometry, snapElevation, dim3dGeom, dominantAxis3d, planeBasis, planeFrom3Points, frameFrom3Points, frameFromAngle, worldToLocal, identityFrame, resolvePointEntry, offsetsFor, candidateOnPlane, projectToPlane, snapGridPoint, projectPointOnSegment2d, projectPointOnSegment3d, selectedFrontmostHit, worldEndpointCommit, SEG_DEGENERACY, segmentHitsRect2d, projectedFootprintHitsRect2d, pickGridLevel, selectedLengthLabelAnchors, declutterLabelRects, sectionKindOf, sectionTopology, memberShapeKind, memberExtrudes, memberSectionTopology, memberMeshAxes, positionSwingDelta, snapToStep, rollCommitNorm, unwrapAngleStep, translateEndpoints, livePositionState, swingBasis, swingEndpoint, swingBarriers, clampSwingTheta, POSITION_SWING_MARGIN_RAD, POSITION_OFFSET_SNAP_MM, POSITION_ROT_SNAP_DEG, POSITION_BASIS_CAPABILITY_VERSION } from './steel-3d-core.js';
25
25
  // `gridGeometry`, `gridCandidates3d` and `sheetScaleMm` live behind the host's model read boundary
26
26
  // because their display-scale argument is meaningless on a world-mm model grid.
27
27
  import { visibleGridLevels, gridTransientScopeSignature, reconcileGridTransientState, objectSelectionStatus } from './grid-core.js';
@@ -543,13 +543,19 @@ function steelSelectionHitsAt(pointer, event) {
543
543
  return [{ entity: { kind: 'reference', sourceId: reference.referenceId }, selectable, rawVisible: true }];
544
544
  }
545
545
 
546
+ function steelNativeSelectionHits(ids) {
547
+ const allowed = api?.canSelectIds ? new Set(api.canSelectIds(ids)) : null;
548
+ return ids.map((sourceId) => ({ entity: { kind: 'native', sourceId },
549
+ selectable: allowed ? allowed.has(sourceId) : !api?.canSelectId || api.canSelectId(sourceId), rawVisible: true }));
550
+ }
551
+
546
552
  function steelMarqueeHits(rect) {
547
553
  const x0 = rect.mode === 'enclosed' ? rect.left : rect.right;
548
554
  const x1 = rect.mode === 'enclosed' ? rect.right : rect.left;
549
555
  const native = [...membersInRect(x0, rect.top, x1, rect.bottom, rect.mode === 'enclosed'), ...detailsInRect(x0, rect.top, x1, rect.bottom, rect.mode === 'enclosed')];
550
556
  for (const conn of connsInRect(x0, rect.top, x1, rect.bottom, rect.mode === 'enclosed')) native.push(...connChildIds(conn));
551
557
  return [
552
- ...[...new Set(native)].map((sourceId) => ({ entity: { kind: 'native', sourceId }, selectable: !api?.canSelectId || api.canSelectId(sourceId), rawVisible: true })),
558
+ ...steelNativeSelectionHits([...new Set(native)]),
553
559
  ...gridsInRect(x0, rect.top, x1, rect.bottom, rect.mode === 'enclosed').map((sourceId) => ({ entity: { kind: 'grid', sourceId }, selectable: !api?.canSelectGrid || api.canSelectGrid(), rawVisible: true })),
554
560
  ];
555
561
  }
@@ -801,7 +807,7 @@ function init(canvas, theApi, options = {}) {
801
807
  coordinator: steelSelectionCoordinatorPort(),
802
808
  hitsAt: steelSelectionHitsAt,
803
809
  allHits: () => [
804
- ...[...meshById].filter(([, mesh]) => mesh.visible).map(([sourceId]) => ({ entity: { kind: 'native', sourceId }, selectable: !api?.canSelectId || api.canSelectId(sourceId), rawVisible: true })),
810
+ ...steelNativeSelectionHits(visibleObjectIds()),
805
811
  ...[...structGridLines].filter(([, line]) => line.visible).map(([sourceId]) => ({ entity: { kind: 'grid', sourceId }, selectable: !api?.canSelectGrid || api.canSelectGrid(), rawVisible: true })),
806
812
  ],
807
813
  marqueeHits: steelMarqueeHits,
@@ -887,6 +893,7 @@ let unframedFrames = 0, unframedWarned = false; // a gate that never opens loo
887
893
  // and left selLenLabelHost out, which this closes.
888
894
  function hideLabelHosts() {
889
895
  for (const host of [dimLabelHost, memberLabelHost, propLabelHost, selLenLabelHost]) if (host) host.style.display = 'none';
896
+ if (propLabelNote) propLabelNote.style.display = 'none';
890
897
  }
891
898
  function renderSteelFrame() {
892
899
  if (!camFramed) {
@@ -3542,16 +3549,21 @@ function syncPropLabels() {
3542
3549
  const a = g.line[0], b = g.line[1];
3543
3550
  el._mid = place === 'start' ? a : place === 'end' ? b : [(a[0] + b[0]) / 2, (a[1] + b[1]) / 2, (a[2] + b[2]) / 2];
3544
3551
  el._memberId = m.id;
3552
+ el._sel = !!L.selected;
3553
+ el._len = Math.hypot(b[0] - a[0], b[1] - a[1], b[2] - a[2]);
3545
3554
  el.textContent = L.lines.join('\n');
3555
+ el._w = 0; el._h = 0; // the text changed: measure again the next time it is shown
3546
3556
  el.style.display = 'block';
3547
3557
  }
3548
3558
  }
3549
3559
  // Project each label's anchor → screen px (called from the render loop, like the dim + member labels).
3550
3560
  function positionPropLabels() {
3551
3561
  if (!propLabelHost) return;
3552
- if (!propLabelSpec || (canvasEl && canvasEl.style.display === 'none')) { propLabelHost.style.display = 'none'; return; }
3562
+ if (!propLabelSpec || (canvasEl && canvasEl.style.display === 'none')) { propLabelHost.style.display = 'none'; setPropLabelNote(false); return; }
3553
3563
  propLabelHost.style.display = 'block';
3554
3564
  const rect = canvasEl.getBoundingClientRect();
3565
+ const shown = [];
3566
+ let crowdedCount = 0;
3555
3567
  for (const el of propLabelPool) {
3556
3568
  if (el.style.display === 'none' || !el._mid) continue;
3557
3569
  const mesh = meshById.get(el._memberId);
@@ -3562,7 +3574,49 @@ function positionPropLabels() {
3562
3574
  el.style.left = (rect.left + (v.x * 0.5 + 0.5) * rect.width) + 'px';
3563
3575
  el.style.top = (rect.top + (-v.y * 0.5 + 0.5) * rect.height) + 'px';
3564
3576
  el.style.visibility = 'visible';
3565
- }
3577
+ shown.push(el);
3578
+ }
3579
+ // A dense frame stacks a chip on nearly every member and none of them can be read (#2780): keep the labels that
3580
+ // matter (a selected member, then the longer member) and hide each one that would land on a kept one. Done here, in
3581
+ // screen px, every frame, so orbiting or zooming in brings the hidden ones back as they gain room.
3582
+ if (shown.length > 1) {
3583
+ const items = [];
3584
+ for (const el of shown) {
3585
+ if (!el._w || !el._h) { el._w = el.offsetWidth; el._h = el.offsetHeight; }
3586
+ // A label that was showing a frame ago gets a modest edge over a rival of similar length, so orbiting does not make
3587
+ // two neighbours swap in and out; a selected member still beats everything.
3588
+ items.push({ key: el._memberId, x: parseFloat(el.style.left), y: parseFloat(el.style.top), w: el._w, h: el._h, priority: el._sel ? 1e12 : (el._len || 0) * (el._kept ? 1.25 : 1) });
3589
+ }
3590
+ const crowded = declutterLabelRects(items, 2);
3591
+ for (const el of shown) {
3592
+ el._kept = !crowded.has(el._memberId);
3593
+ if (!el._kept) el.style.visibility = 'hidden';
3594
+ }
3595
+ crowdedCount = crowded.size;
3596
+ }
3597
+ setPropLabelNote(crowdedCount > 0);
3598
+ }
3599
+ let propLabelNote = null;
3600
+ /** The one-line note that says labels were hidden to keep the rest readable (the 2D plan has its own, `#plHint`). */
3601
+ function setPropLabelNote(on) {
3602
+ if (!on) { if (propLabelNote) propLabelNote.style.display = 'none'; return; }
3603
+ if (!propLabelNote) {
3604
+ propLabelNote = document.createElement('div');
3605
+ propLabelNote.id = 'm3dPropLabelNote';
3606
+ propLabelNote.setAttribute('role', 'status');
3607
+ propLabelNote.style.cssText = 'position:fixed;z-index:20;pointer-events:none;background:var(--panel,#0f172a);color:var(--mut,#94a3b8);border:1px solid var(--line,#334155);border-radius:6px;padding:3px 9px;font:11px var(--ui,system-ui)';
3608
+ propLabelNote.textContent = 'Some labels hidden — move closer to see more';
3609
+ document.body.appendChild(propLabelNote);
3610
+ }
3611
+ propLabelNote.style.display = 'block';
3612
+ // Placed from the canvas rect, which positionPropLabels has just read: re-measured only when it moved, so a crowded frame
3613
+ // does not force a layout every frame.
3614
+ const r = canvasEl.getBoundingClientRect();
3615
+ const key = r.left + ',' + r.bottom + ',' + r.width;
3616
+ if (propLabelNote._key === key) return;
3617
+ propLabelNote._key = key;
3618
+ propLabelNote.style.left = (r.left + r.width / 2 - propLabelNote.offsetWidth / 2) + 'px';
3619
+ propLabelNote.style.top = (r.bottom - 64) + 'px';
3566
3620
  }
3567
3621
 
3568
3622
  // ---- On-select member-length labels (⋯ Display → Show member length): the editor owns the TEXT (true 3D
@@ -9034,6 +9088,8 @@ function disposeSteel() {
9034
9088
  dimLabelHost = null; dimLabelPool.length = 0;
9035
9089
  if (memberLabelHost && memberLabelHost.parentNode) memberLabelHost.parentNode.removeChild(memberLabelHost);
9036
9090
  memberLabelHost = null; memberLabelPool.length = 0; labelsOnFlag = false; insertMode = false; insertPending = null; detailPlanePick = null; detailPlaneCandidates = null;
9091
+ if (propLabelNote && propLabelNote.parentNode) propLabelNote.parentNode.removeChild(propLabelNote);
9092
+ propLabelNote = null;
9037
9093
  if (propLabelHost && propLabelHost.parentNode) propLabelHost.parentNode.removeChild(propLabelHost);
9038
9094
  propLabelHost = null; propLabelPool.length = 0; propLabelSpec = null;
9039
9095
  if (selLenLabelHost && selLenLabelHost.parentNode) selLenLabelHost.parentNode.removeChild(selLenLabelHost);