@floless/app 0.131.0 → 0.132.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.
Files changed (34) hide show
  1. package/dist/floless-server.cjs +2558 -1885
  2. package/dist/schemas/steel.model.v2.schema.json +3 -1
  3. package/dist/web/app.css +359 -0
  4. package/dist/web/app.js +22 -0
  5. package/dist/web/aware.js +62 -10
  6. package/dist/web/commands-filter.js +157 -0
  7. package/dist/web/commands-shell.js +1316 -0
  8. package/dist/web/commands-steel.js +1829 -0
  9. package/dist/web/commands-vector.js +154 -0
  10. package/dist/web/commands-vector3d.js +96 -0
  11. package/dist/web/commands.js +316 -0
  12. package/dist/web/grid-core.js +124 -23
  13. package/dist/web/index.html +269 -164
  14. package/dist/web/instructor-reporter.js +201 -0
  15. package/dist/web/instructor.js +1119 -0
  16. package/dist/web/reference-changes.js +55 -0
  17. package/dist/web/reference-geometry-worker.js +194 -0
  18. package/dist/web/steel-3d-core.js +454 -107
  19. package/dist/web/steel-3d-view.js +790 -165
  20. package/dist/web/steel-canvas-guidance.js +7 -4
  21. package/dist/web/steel-editor.html +2347 -1810
  22. package/dist/web/steel-filter-core.js +13 -5
  23. package/dist/web/steel-filter.html +36 -22
  24. package/dist/web/steel-model-adapter.js +17 -22
  25. package/dist/web/steel-model-commands.js +23 -10
  26. package/dist/web/steel-model-v2-client-validation.js +20 -3
  27. package/dist/web/steel-model-v2-commands.js +91 -3
  28. package/dist/web/steel-model-v2-projection.js +4 -5
  29. package/dist/web/steel-plan-transform.js +4 -8
  30. package/dist/web/steel-split-view.js +52 -0
  31. package/dist/web/vector-3d.html +19 -7
  32. package/dist/web/vector-editor.html +21 -8
  33. package/dist/web/workspaces.js +9 -24
  34. package/package.json +9 -1
@@ -178,7 +178,7 @@ export const gridLevelKey = (mm) => typeof mm === 'number' && Number.isFinite(mm
178
178
 
179
179
  /**
180
180
  * Keep only hidden elevations that still exist in the authored level list, returning the authored
181
- * canonical mm values. Sparse hidden state means legacy/new levels are visible by default.
181
+ * canonical mm values. Sparse hidden state means newly authored levels are visible by default.
182
182
  */
183
183
  export function normalizeHiddenLevels(hiddenZ = [], levels = []) {
184
184
  const authored = new Map();
@@ -268,7 +268,7 @@ export function normalizeLevelLabels(parsed, labelsZ = []) {
268
268
  /**
269
269
  * Carry labels from one canonical level list to another by elevation, never by display position.
270
270
  * The editor sorts Z values before showing them, so using array indexes here would silently swap
271
- * labels loaded from an unsorted legacy contract. Labels for removed elevations join the retained
271
+ * labels loaded from an unsorted input. Labels for removed elevations join the retained
272
272
  * extras and remain available until the user explicitly removes them.
273
273
  */
274
274
  export function reconcileLevelLabels(previousParsed, normalizedLabels = [], nextParsed) {
@@ -317,6 +317,109 @@ export function labelsFor(override, style, n) {
317
317
  return auto.map((a, i) => own[i] != null ? own[i] : a);
318
318
  }
319
319
 
320
+ /** The schema's cap on `axes[].label`. A name is display text, and 40 characters is where it stops. */
321
+ export const GRID_LABEL_MAX = 40;
322
+
323
+ /**
324
+ * The labels one direction will actually CARRY for an authored override string — `labelsFor` clamped to
325
+ * the schema cap.
326
+ *
327
+ * The clamp has to happen before anything else looks at the tokens, which is the whole reason this is a
328
+ * function rather than a step inside the writer. Two names that differ only past character 40 are
329
+ * distinct as typed and identical as stored, so a duplicate check run on the raw tokens passes and the
330
+ * commit then writes two axes with one name. The feedback line, the duplicate guard and the write all
331
+ * read this, so they cannot disagree about what "the labels" are.
332
+ */
333
+ export function gridLabelTokens(override, style, n) {
334
+ return labelsFor(override, style, n).map((l) => truncateText(l, GRID_LABEL_MAX));
335
+ }
336
+
337
+ /** The `labels_x` / `labels_y` key that carries one direction's authored override string. */
338
+ const overrideKey = (dir) => dir === 'x' ? 'labels_x' : 'labels_y';
339
+
340
+ /** The dir-x (or dir-y) rows of a steel.model/v2 grid, in authored order. Empty for a grid with no axes. */
341
+ const axisRows = (g, dir) => (g && Array.isArray(g.axes)) ? g.axes.filter((a) => a && a.dir === dir) : [];
342
+
343
+ /**
344
+ * The n labels ONE grid direction actually carries — the single rule every reader must use.
345
+ *
346
+ * A steel.model/v2 axis names itself twice: in `grid.axes[].label` and positionally in the
347
+ * `labels_x`/`labels_y` override string. Per-axis wins (the schema calls it the editable display text)
348
+ * and the string is the per-SLOT fallback, so an axis with no label of its own still reads its slot,
349
+ * and `labelsFor`'s auto sequence continues past both.
350
+ *
351
+ * This exists because the two halves used to be read differently: `gridGeometry` drew bubbles from the
352
+ * override string alone while `gridIntersection` preferred the per-axis label, so a plan could print
353
+ * `X1` and refuse a registration control named `X1` (#740). A blank or whitespace-only `label` falls
354
+ * back rather than winning, which is what `contract-to-scene.ts` already did for the 3D scene.
355
+ *
356
+ * A grid whose axis count disagrees with its parsed spacings is not describable — the rows no longer
357
+ * pair with the offsets — so the whole direction falls back to the string. `checkModelReferences`
358
+ * (`grid-axis-count`) refuses such a document upstream; this is the local fail-safe, and it is also the
359
+ * shape of every pre-v2 / inferred grid, which carries no `axes` at all.
360
+ */
361
+ export function axisLabelsFor(g, dir, style, n) {
362
+ const fallback = labelsFor(g && g[overrideKey(dir)], style, n);
363
+ const rows = axisRows(g, dir);
364
+ if (rows.length !== n) return fallback;
365
+ // `fallback[i]` is never blank for i < n (labelsFor fills every slot from autoLabels), so a blank
366
+ // per-axis label always resolves to a real name here.
367
+ return rows.map((a, i) => String(a.label ?? '').trim() || fallback[i]);
368
+ }
369
+
370
+ /**
371
+ * The grid patch that renames one direction to `labels`, written so BOTH halves agree.
372
+ *
373
+ * Writing only `labels_x`/`labels_y` is what made a rename silently do nothing once per-axis labels
374
+ * win: the axis kept its old name and the new string was never consulted. So every writer goes through
375
+ * here, which sets each axis's own `label` AND keeps the override string as the readable authored text.
376
+ *
377
+ * `labels` is the full resolved list for the direction, in authored axis order. Pass null to clear the
378
+ * direction back to auto — the override string is emptied and every per-axis label removed, which is
379
+ * the only way "no explicit label" survives a round trip (a whitespace-joined string cannot express a
380
+ * hole at slot 0).
381
+ *
382
+ * Each label is clamped to `GRID_LABEL_MAX` — the last line of defence, since `gridLabelTokens` has
383
+ * already clamped anything derived from an override string. The override string was never capped, so before the per-axis half moved with
384
+ * it a 41-character bubble name was simply stored; now it would fail canonical validation and the whole
385
+ * rename would come back as "would leave steel.model/v2 invalid". Clamping HERE keeps both halves equal:
386
+ * capping only the axis row would re-open the divergence this function exists to close.
387
+ */
388
+ export function gridLabelPatch(g, dir, labels) {
389
+ const key = overrideKey(dir);
390
+ const clamped = labels ? labels.map((l) => truncateText(l, GRID_LABEL_MAX)) : null;
391
+ const patch = { [key]: clamped ? clamped.join(' ') : '' };
392
+ if (!(g && Array.isArray(g.axes))) return patch;
393
+ let slot = 0;
394
+ patch.axes = g.axes.map((a) => {
395
+ if (!a || a.dir !== dir) return a;
396
+ const label = clamped ? clamped[slot++] : null;
397
+ if (label == null) { const { label: _drop, ...rest } = a; return rest; }
398
+ return { ...a, label };
399
+ });
400
+ return patch;
401
+ }
402
+
403
+ /**
404
+ * The text the label field for one direction should SHOW — the resolved labels once any axis carries
405
+ * its own name, else the raw override string so an untouched grid still shows blank (and its "auto:
406
+ * 1 2 3…" placeholder) rather than a materialised sequence.
407
+ *
408
+ * NULL means the direction cannot be REPRESENTED in a whitespace-separated field, because one of its
409
+ * names contains whitespace. `gridAxis.label` is an arbitrary string in the schema, so `GRID 1` is a
410
+ * legal name that only the contract can author (both label editors refuse spaces); the field would
411
+ * render it as `GRID 1 GRID 2` and re-tokenise a subsequent edit into two different names, silently
412
+ * renaming both axes and rewriting the registration refs that pointed at them. A caller that offers
413
+ * editing must handle null by not offering it — `axisLabelsFor` is still the way to READ those names,
414
+ * and writing them stays lossless because the per-axis labels outrank the string on the way back in.
415
+ */
416
+ export function axisLabelText(g, dir, style, n) {
417
+ const rows = axisRows(g, dir);
418
+ if (!rows.some((a) => String(a.label ?? '').trim())) return String((g && g[overrideKey(dir)]) || '');
419
+ const labels = axisLabelsFor(g, dir, style, n);
420
+ return labels.some((l) => /\s/.test(l)) ? null : labels.join(' ');
421
+ }
422
+
320
423
  /** A fresh default grid (display-space origin px). 4×4 30' bays, ground level only. */
321
424
  export function defaultGrid(origin) {
322
425
  return { on: true, origin: (origin || [0, 0]).slice(0, 2), x: "0'-0\", 3*30'-0\"", y: "0'-0\", 3*30'-0\"", z: "0'-0\"", labels_x: '', labels_y: '', labels_z: [], ext: 5 * FT_MM };
@@ -353,15 +456,14 @@ export function gridLines(g) {
353
456
  * errX/errY/errZ carry per-axis parse errors; warningsZ reports duplicate/orphan level labels;
354
457
  * lines of a failed axis are [].
355
458
  *
356
- * `opts.yUp` — WHICH GRID THIS IS, and it is the only structural difference between the two (unit 5, P7d).
357
- * Default false is v1: the grid lives in one sheet's DISPLAY space, so Y grows DOWN the page and the
358
- * spacings run UP it (`oy - off`). True is `steel.model/v2`'s ONE model grid, already in world mm with Y
359
- * up, so the spacings run along +Y and `ptPerFt` should be FT_MM (k = 1, the identity). Passing a v2 grid
459
+ * `opts.yUp` selects coordinate space. Default false is a projected sheet grid, where Y grows DOWN the
460
+ * page and spacings run UP it (`oy - off`). True is the native model grid, already in world mm with Y
461
+ * up, so the spacings run along +Y and `ptPerFt` should be FT_MM (k = 1, the identity). Passing a native grid
360
462
  * without this does not throw — it draws the whole grid mirrored about the origin's Y, plausibly, which is
361
463
  * the silent-wrong-space failure this epic exists to prevent.
362
464
  *
363
- * It also selects which per-line EXTENT vocabulary is read: v1's index-keyed `ends_x`/`ends_y` in display
364
- * px, or v2's single `ends` map keyed by stable AXIS ID in world mm — see the block at the end.
465
+ * It also selects which per-line extent vocabulary is read: projected index-keyed `ends_x`/`ends_y` in
466
+ * display px, or the native `ends` map keyed by stable axis id in world mm.
365
467
  */
366
468
  export function gridGeometry(g, ptPerFt, opts = {}) {
367
469
  const yUp = !!opts.yUp;
@@ -370,10 +472,11 @@ export function gridGeometry(g, ptPerFt, opts = {}) {
370
472
  const X = parseSpacings(g && g.x), Y = parseSpacings(g && g.y);
371
473
  const ok = sane(g);
372
474
  const ox = ok ? g.origin[0] : 0, oy = ok ? g.origin[1] : 0;
373
- const lx = labelsFor(g && g.labels_x, 'num', X.offsets.length);
374
- const ly = labelsFor(g && g.labels_y, 'alpha', Y.offsets.length);
475
+ // Bubbles print what a registration control resolves against — one rule, `axisLabelsFor` (#740).
476
+ const lx = axisLabelsFor(g, 'x', 'num', X.offsets.length);
477
+ const ly = axisLabelsFor(g, 'y', 'alpha', Y.offsets.length);
375
478
  const v = X.offsets.map((off, i) => ({ x: ox + px(off), label: lx[i] }));
376
- const h = Y.offsets.map((off, i) => ({ y: yUp ? oy + px(off) : oy - px(off), label: ly[i] })); // v1: up the sheet = -Y (scene +Y). v2: world mm, already Y-up.
479
+ const h = Y.offsets.map((off, i) => ({ y: yUp ? oy + px(off) : oy - px(off), label: ly[i] })); // projected sheet: up = -Y; native model: world mm, already Y-up
377
480
  // Z levels are absolute, sorted/deduped, and retain their authored label source index.
378
481
  const resolvedZ = parseLevels(g && g.z, g && g.labels_z);
379
482
  const levelsZ = resolvedZ.err ? [] : resolvedZ.levels;
@@ -393,17 +496,16 @@ export function gridGeometry(g, ptPerFt, opts = {}) {
393
496
  y0: Math.min((ys.length ? Math.min(...ys) : oy), ly0) - ext,
394
497
  y1: Math.max((ys.length ? Math.max(...ys) : oy), ly1) + ext,
395
498
  };
396
- // per-line extent overrides. v1 keys them by INDEX (g.ends_x / g.ends_y: { "<index>": [lo|null, hi|null] }
397
- // in display px along the line — a real sheet has partial lines like a 5.1 covering one wing). v2
398
- // replaced BOTH with one `ends` map keyed by stable AXIS ID in world mm, precisely because index keys
499
+ // Per-line extent overrides. The projected facade keys them by index (`ends_x` / `ends_y`) in display
500
+ // px along the line; native storage uses one `ends` map keyed by stable axis id because index keys
399
501
  // meant "an insert or re-space changed what a reference meant" ($defs.modelGrid). null / absent = the
400
502
  // auto full span. Every consumer (2D render, snapping, 3D) reads l.lo / l.hi.
401
503
  //
402
504
  // Reading the v2 map is not optional politeness: a line the model says covers one wing, drawn full
403
505
  // span, is a WRONG drawing rather than an absent one.
404
506
  const axisIds = (dir) => (yUp && g && Array.isArray(g.axes)) ? g.axes.filter((a) => a && a.dir === dir).map((a) => a.id) : [];
405
- const override = (dir, i, legacy) => {
406
- if (!yUp) return (g && g[legacy] && g[legacy][i]) || [];
507
+ const override = (dir, i, positionalKey) => {
508
+ if (!yUp) return (g && g[positionalKey] && g[positionalKey][i]) || [];
407
509
  const id = axisIds(dir)[i];
408
510
  return (id != null && g && g.ends && g.ends[id]) || [];
409
511
  };
@@ -711,26 +813,25 @@ export function inferGrid(members, ptPerFt) {
711
813
  * `formatSpacings` / `fmtLen` are the notation, and the v2 schema keeps it — "Authoring notation is
712
814
  * unchanged (relative X/Y spacing strings, absolute Z levels; web/grid-core.js is the parser source of
713
815
  * truth), but every coordinate here is world mm" (`$defs.modelGrid`). Only the coordinate half is new,
714
- * so this shares the clustering rule and the 1/2" spacing snap with its v1 sibling rather than restating
715
- * them differently.
816
+ * so this shares the clustering rule and the 1/2" spacing snap with the projected helper.
716
817
  *
717
818
  * THE THREE DIFFERENCES, all consequences of the display→world change:
718
819
  *
719
820
  * 1. NO `ptPerFt`. v2 work points are already mm, so the 150 mm tolerance is applied directly instead
720
821
  * of being divided back into pixels. It is an ADJACENCY tolerance, not a cluster width — the walk
721
822
  * compares each column to the LAST one admitted, so a run of columns 100 mm apart chains into a
722
- * single line of unbounded span. Inherited verbatim (v1's `150/k` px test is the same predicate
823
+ * single line of unbounded span. The projected `150/k` px test is the same predicate
723
824
  * after the scale cancels), and named here because "150 mm tolerance" alone reads as a width.
724
- * 2. THE Y AXIS IS NOT REVERSED. v1 reads display space, where Y grows DOWN — hence its bottom-most
825
+ * 2. THE Y AXIS IS NOT REVERSED. Projected display space grows Y down — hence its bottom-most
725
826
  * origin (`cy[cy.length-1]`) and its `.reverse()`. World +Y already runs up the plan, so the origin
726
- * is the LOWEST Y and the offsets come out ascending on their own. Keeping v1's reversal here would
827
+ * is the LOWEST Y and the offsets come out ascending on their own. Keeping that reversal here would
727
828
  * produce a grid mirrored about its own origin, which parses cleanly and is silently upside-down.
728
829
  * 3. `origin` IS RETURNED IN MM, matching `$defs.modelGrid.origin` — "The [1,A] corner in WORLD MM
729
- * (v1's was display space)". v1 returns px there, and the two are not interchangeable.
830
+ * while the projected facade returns display px. The two are not interchangeable.
730
831
  *
731
832
  * A column with an UNKNOWN elevation still counts. Its `z` is an RFI; its plan position is not, and
732
833
  * dropping it would move the [1,A] corner because an unanswered question sits on the grid line.
733
- * Returns null when the model has no columns — the caller falls back to `defaultGrid`, as in v1.
834
+ * Returns null when the model has no columns; the caller falls back to `defaultGrid`.
734
835
  *
735
836
  * ORIGIN + OFFSETS DO NOT EXACTLY RECONSTRUCT THE CLUSTER CENTRES, and that is inherited rather than
736
837
  * new: the offsets are snapped to the 1/2" authoring quantum while the origin is the raw centre, so a