@floless/app 0.134.2 → 0.134.3

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.
@@ -7,7 +7,7 @@ description: >-
7
7
  two-phase Drawing Filter process: first prepare and save the deterministic Filter, then read only the
8
8
  selected evidence into model-global members, registered plan views, observations, and revision history.
9
9
  metadata:
10
- version: 0.28.0
10
+ version: 0.28.2
11
11
  ---
12
12
 
13
13
  # Steel Takeoff — read drawings into `steel.model/v2`
@@ -544,7 +544,8 @@ Each observation is model-globally unique and split into immutable `evidence` an
544
544
  "provenance": "auto-read",
545
545
  "observed": {
546
546
  "profile": { "value": "W16X26", "confidence": 91 },
547
- "fromZ": { "value": { "known": 5029.2 }, "confidence": 82 }
547
+ "fromZ": { "value": { "known": 5029.2 }, "confidence": 82 },
548
+ "toZ": { "value": { "known": 5029.2 }, "confidence": 82 }
548
549
  }
549
550
  },
550
551
  "binding": {
@@ -585,6 +586,15 @@ face stays face-short in both `evidence.local.wp` and the literal candidate's co
585
586
  endpoint. Bind each physical observation endpoint explicitly through `binding.endpointLineage`; use the
586
587
  following exact algorithm and never guess or reuse the other end's identity:
587
588
 
589
+ For every lineaged plan endpoint of a support-centerline-eligible beam or brace, record the endpoint's
590
+ source-backed world-millimetre elevation in the matching `evidence.observed.fromZ` or `toZ`. Both linked
591
+ ends need their own evidence. A plan's `elevation_in` is only the horizontal cut plane: never copy it or
592
+ infer an endpoint elevation from it. Columns are support targets and are not required to carry framing-
593
+ plan bottom/top evidence under this rule. If the drawings cannot establish an eligible endpoint's
594
+ elevation, record the RFI/refusal and do not submit unverifiable new-member geometry. The deterministic
595
+ completion audit blocks that candidate and the member-end review names the missing endpoint elevation;
596
+ do not erase lineage or invent a value to get past the diagnostic.
597
+
588
598
  1. JCS-encode the two-item JSON array `[observationId, observationEnd]`, preserving the array order.
589
599
  2. Form the byte preimage exactly as `UTF8("floless:endpoint-lineage:v1") || 0x00 ||
590
600
  UTF8(JCS([observationId, observationEnd]))`, where `UTF8` means UTF-8 encoding and `||` means byte
@@ -605,6 +615,19 @@ On a revision, keep every existing member endpoint literal to the reader's compo
605
615
  members are eligible for server automatic alignment; the server routes any proposed change to an
606
616
  existing endpoint to review. This boundary protects approved or manually edited geometry.
607
617
 
618
+ If missing `endpointLineage` is repaired after publication, a plain contract PUT does not run
619
+ `support-centerline/v1` and must not move the existing member. Its `revalidation` response describes
620
+ connection revalidation only; empty `kept`, `repointed`, `removed`, `flagged`, and `deferred` arrays do
621
+ not mean the new lineage was ignored. After the binding-only repair succeeds, tell the user to open
622
+ the **3D** model and choose **More actions → Model checks → Check member ends short of supports** for
623
+ a whole-model recovery scan. A scan launched from a 2D drawing is intentionally limited to that active
624
+ view and is suitable only for view-local inspection; it cannot replace the required 3D recovery scan,
625
+ because separate 2D scans do not combine cross-view evidence or expose disagreements between views.
626
+ The scan recomputes the server-owned candidates from the stored drawing evidence; the user reviews and
627
+ applies the exact ends that may move. A fresh revision-read is not required solely to trigger this
628
+ review. Use a fresh revision-read when the immutable observation evidence itself must change; never
629
+ rewrite that evidence through a generic contract PUT.
630
+
608
631
  ## Confidence and verification
609
632
 
610
633
  Score confidence per observed field, not once per member. Loop until the request's `target_confidence`
package/dist/web/app.css CHANGED
@@ -5250,6 +5250,16 @@ table.hist tr.current td { background:var(--accent-soft); }
5250
5250
  .rev-changed[hidden] { display:none; }
5251
5251
  .rev-changed b { color:var(--text); font-weight:600; }
5252
5252
 
5253
+ /* The destructive staged-read exit shares the ordinary modal button recipe; spacing alone separates
5254
+ it from Close/Apply so those reversible actions remain one right-aligned group. The confirmation is
5255
+ a shared dark modal, raised above the review it can open from. */
5256
+ .revreview-discard { margin-right:auto; }
5257
+ #revdiscard-modal { z-index:110; }
5258
+ .revision-discard-error { margin:12px 0 0; padding:9px 11px; border:1px solid var(--err);
5259
+ border-radius:7px; background:var(--surface-2); color:var(--err); font-size:12px; line-height:1.45; }
5260
+ .revision-discard-error[hidden] { display:none; }
5261
+ .revision-discard[aria-busy="true"] .modal-sub { opacity:.78; }
5262
+
5253
5263
  .rev-group { margin:0 0 16px; }
5254
5264
  .rev-group:last-child { margin-bottom:0; }
5255
5265
  .rev-group-head { display:flex; align-items:center; justify-content:space-between; gap:12px; margin:0 0 7px; }
@@ -5317,7 +5327,11 @@ table.hist tr.current td { background:var(--accent-soft); }
5317
5327
  .ws-revision-card.state-unavailable .wrc-warn-ico { color:var(--warn); flex:none; }
5318
5328
  .ws-revision-card.state-staged, .ws-revision-card.state-filter-ready, .ws-revision-card.state-filter-saved { border-left:3px solid var(--accent); }
5319
5329
  .ws-revision-card.state-staged .wrc-dot, .ws-revision-card.state-filter-ready .wrc-dot, .ws-revision-card.state-filter-saved .wrc-dot { background:var(--accent); }
5330
+ .ws-revision-card.state-stale { border-left-color:var(--warn); }
5331
+ .ws-revision-card.state-stale .wrc-dot { background:var(--warn); }
5320
5332
  .ws-revision-card .wrc-actions { display:flex; gap:6px; flex:none; }
5333
+ .ws-revision-card .wrc-actions .wrc-discard { color:var(--err); }
5334
+ .ws-revision-card .wrc-actions .wrc-discard:hover { color:var(--err); border-color:var(--err); background:rgba(248,113,113,.1); }
5321
5335
  .hist .gate-badge.ai-read { background:var(--accent-soft); border-color:var(--accent-dim); color:var(--accent-bright); }
5322
5336
 
5323
5337
  /* History rollback and Knowledge remove confirmation share this themed anchored popover. */
package/dist/web/app.js CHANGED
@@ -387,6 +387,10 @@ function renderDagTopology(p) {
387
387
  }
388
388
 
389
389
  function drawDagWires(svg, connections) {
390
+ // A queued animation frame can outlive the prompt it was scheduled for. Once the shell switches to a
391
+ // non-DAG prompt, that old SVG is detached and the new prompt has no `connections`; both are normal
392
+ // lifecycle states, not drawing errors.
393
+ if (!svg.isConnected || !Array.isArray(connections)) return;
390
394
  svg.innerHTML = '';
391
395
  connections.forEach((c, idx) => {
392
396
  const fromEl = dagCardMap[c.from];
@@ -653,6 +653,28 @@
653
653
  guidance: 'on-demand',
654
654
  });
655
655
 
656
+ def('shell.revision-discard-open', {
657
+ label: 'Discard drawing read',
658
+ actsOn: 'Opens a confirmation before removing this staged drawing-read review',
659
+ group: 'In the project workspace',
660
+ persistence: 'none',
661
+ interaction: 'dialog',
662
+ risk: [],
663
+ guidance: 'on-demand',
664
+ why: 'Close keeps the review. Discard is a separate confirmed action because the drawing read would have to be run again.',
665
+ });
666
+
667
+ def('shell.revision-discard-review-open', {
668
+ label: 'Discard this drawing read',
669
+ actsOn: 'Opens the discard confirmation from the staged proposal currently being reviewed',
670
+ group: 'In the revision review',
671
+ persistence: 'none',
672
+ interaction: 'dialog',
673
+ risk: [],
674
+ guidance: 'on-demand',
675
+ why: 'Close keeps the review. This separate action asks for confirmation before removing it.',
676
+ });
677
+
656
678
  def('shell.revision-failure-dismiss', {
657
679
  label: 'Dismiss failed drawing read',
658
680
  actsOn: 'Removes this failed drawing-read request from the project workspace',
@@ -1047,6 +1069,17 @@
1047
1069
  guidance: 'on-demand',
1048
1070
  });
1049
1071
 
1072
+ def('shell.revision-discard-confirm', {
1073
+ label: 'Discard drawing read',
1074
+ actsOn: 'Permanently removes this staged drawing-read review without changing the model or History',
1075
+ group: 'In the FloLess dialogs',
1076
+ persistence: 'working',
1077
+ interaction: 'instant',
1078
+ risk: ['destructive'],
1079
+ guidance: 'on-demand',
1080
+ why: 'The staged review is removed and must be recreated by attaching and reading the drawing set again.',
1081
+ });
1082
+
1050
1083
  def('shell.approval-confirm', {
1051
1084
  label: 'Approve the changes',
1052
1085
  actsOn: 'Signs off every change you have just reviewed',
@@ -289,13 +289,23 @@
289
289
 
290
290
  def('steel.pick-profile', {
291
291
  label: 'Pick a profile',
292
- actsOn: 'Takes the profile from the member you click',
292
+ actsOn: 'Takes the designation from a profile label on the active drawing',
293
293
  group: 'In the Inspect panel',
294
294
  persistence: 'working',
295
295
  interaction: 'mode',
296
296
  risk: [],
297
297
  guidance: 'active-command',
298
- steps: ['Click the member to take the profile from'],
298
+ steps: ['Choose a highlighted profile label by click, Enter, or Space'],
299
+ });
300
+
301
+ def('steel.apply-profile-label', {
302
+ label: 'Apply profile {instance}',
303
+ actsOn: 'Replaces the selected member’s profile with {instance}',
304
+ group: 'On the drawing canvas',
305
+ persistence: 'working',
306
+ interaction: 'instant',
307
+ risk: [],
308
+ guidance: 'on-demand',
299
309
  });
300
310
 
301
311
  def('steel.pick-detail', {
@@ -1067,7 +1077,7 @@
1067
1077
 
1068
1078
  def('steel.member-end-select-all', {
1069
1079
  label: 'Select all reviewed ends',
1070
- actsOn: 'Includes every actionable endpoint in the pending centerline extension',
1080
+ actsOn: 'Includes every endpoint whose support centerline is already chosen in the pending extension',
1071
1081
  group: 'In the Inspect panel',
1072
1082
  persistence: 'none',
1073
1083
  interaction: 'instant',
@@ -1586,7 +1596,7 @@
1586
1596
 
1587
1597
  def('steel.view-create', {
1588
1598
  label: 'Create views',
1589
- actsOn: 'Saves a view for every ticked grid line or level',
1599
+ actsOn: 'Saves a view for each ticked grid line or level whose cut intersects the model',
1590
1600
  group: 'In the Generate views dialog',
1591
1601
  persistence: 'working',
1592
1602
  interaction: 'instant',
@@ -1761,6 +1771,7 @@
1761
1771
  guidance: 'on-demand',
1762
1772
  why: 'How sure the automatic read of the drawing has to be before an element stops being flagged for review.',
1763
1773
  });
1774
+ def('steel.confidence-report', { label: 'Open confidence report', actsOn: 'Opens the recorded drawing-confidence review', group: 'In the steel editor header', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand', why: 'Shows current field-level read evidence without changing the model.' });
1764
1775
 
1765
1776
  /* Ask AI */
1766
1777
 
@@ -1893,7 +1904,7 @@
1893
1904
  def('steel.default-tos', { label: 'Default TOS', actsOn: 'Sets the project top-of-steel elevation for this sheet', group: 'In the Inspect panel', persistence: 'working', interaction: 'instant', risk: [], guidance: 'on-demand', why: 'Ends following the default move with it; explicit end elevations stay where they are.' });
1894
1905
  def('steel.ends-reset-default', { label: 'Reset all ends to default', actsOn: 'Makes every member end on this sheet follow the default TOS', group: 'In the Inspect panel', persistence: 'working', interaction: 'instant', risk: [], guidance: 'on-demand', why: 'This replaces explicit end elevations too. Undo restores them.' });
1895
1906
  def('steel.end-tos-default', { label: 'Use default TOS', actsOn: 'Turns default-following on or off for {instance}', group: 'In the Inspect panel', persistence: 'working', interaction: 'instant', risk: [], guidance: 'on-demand' });
1896
- def('steel.end-tos', { label: 'Top of steel', actsOn: 'Sets the top-of-steel elevation for {instance}', group: 'In the Inspect panel', persistence: 'working', interaction: 'instant', risk: [], guidance: 'on-demand', why: 'The field is locked while that end follows the project default.' });
1907
+ def('steel.end-tos', { label: 'Endpoint elevation', actsOn: 'Sets the explicit elevation for {instance}', group: 'In the Inspect panel', persistence: 'working', interaction: 'instant', risk: [], guidance: 'on-demand' });
1897
1908
  def('steel.end-elevation', { label: 'End elevation', actsOn: 'Sets the elevation for {instance}', group: 'In the Inspect panel', persistence: 'working', interaction: 'instant', risk: [], guidance: 'on-demand' });
1898
1909
  def('steel.end-note', { label: 'Connection note', actsOn: 'Sets the connection note for {instance}', group: 'In the Inspect panel', persistence: 'working', interaction: 'instant', risk: [], guidance: 'on-demand' });
1899
1910
  def('steel.end-detail', { label: 'Connection detail', actsOn: 'Sets the detail callout for {instance}', group: 'In the Inspect panel', persistence: 'working', interaction: 'instant', risk: [], guidance: 'on-demand' });
@@ -1950,6 +1961,7 @@
1950
1961
  def('steel.rfi-profile', { label: 'Resolve profile', actsOn: 'Sets the profile for unresolved member {instance}', group: 'In the RFI dialog', persistence: 'working', interaction: 'instant', risk: [], guidance: 'on-demand' });
1951
1962
  def('steel.locate-member', { label: 'Locate member', actsOn: 'Closes the report and selects {instance}', group: 'In the steel editor dialogs', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand' });
1952
1963
  def('steel.confidence-filter', { label: 'Confidence filter', actsOn: 'Filters the confidence report by {instance}', group: 'In the confidence report', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand' });
1964
+ def('steel.confidence-fields', { label: 'Review confidence fields', actsOn: 'Shows or hides every recorded drawing field for {instance}', group: 'In the confidence report', persistence: 'none', interaction: 'instant', risk: [], guidance: 'on-demand', why: 'Keeps the original value, percentage, and source visible without changing the model.' });
1953
1965
 
1954
1966
  /* ── Profile Position, in the Inspect panel ─────────────────────────── */
1955
1967
 
@@ -217,7 +217,7 @@
217
217
  <button data-command-id="shell.attach-revision" type="button" id="ws-attach-revision" class="btn-mini" data-tip="Attach a revised drawing set (PDF or image) — your terminal AI reads it into a new version">⤒ Attach revised drawings…</button>
218
218
  <input data-command-id="shell.attach-revision" type="file" id="ws-revision-file" accept=".pdf,image/*" multiple hidden>
219
219
  </div>
220
- <div class="ws-revision-card" id="ws-revision-card" hidden></div>
220
+ <div class="ws-revision-card" id="ws-revision-card" role="status" aria-live="polite" aria-atomic="true" hidden></div>
221
221
  <!-- Two lazily-srced iframes so switching steps never reloads the editor's 3D state.
222
222
  Same-origin like #contract-editor-frame (they call /api/contract directly). -->
223
223
  <iframe id="ws-frame-model" class="ws-frame" title="Project model editor" hidden></iframe>
@@ -726,7 +726,7 @@
726
726
  notion of grouped rows, per-bucket bulk actions, or re-rendering in place when the
727
727
  model moves underneath the review. Same backdrop, same .modal chrome — no new look.
728
728
  The counts line sits OUTSIDE .revreview-body so it stays pinned while the list scrolls. -->
729
- <div class="modal-backdrop" id="revreview-modal" role="dialog" aria-modal="true" aria-labelledby="revreview-title">
729
+ <div class="modal-backdrop" id="revreview-modal" role="dialog" aria-modal="true" aria-labelledby="revreview-title" aria-describedby="revreview-sub revreview-changed">
730
730
  <div class="modal revreview">
731
731
  <div class="modal-title" id="revreview-title">Review this read</div>
732
732
  <div class="modal-sub" id="revreview-sub"></div>
@@ -734,12 +734,28 @@
734
734
  <div class="rev-counts" id="revreview-counts"></div>
735
735
  <div class="revreview-body" id="revreview-body"></div>
736
736
  <div class="modal-actions">
737
- <button data-command-id="shell.dialog-cancel#the revision review" id="revreview-cancel">Cancel</button>
737
+ <button id="revreview-discard" data-command-id="shell.revision-discard-review-open" class="danger revreview-discard" hidden>Discard this read…</button>
738
+ <button data-command-id="shell.dialog-cancel#the revision review" id="revreview-cancel">Close</button>
738
739
  <button data-command-id="shell.revision-confirm" id="revreview-confirm" class="primary">Apply selected</button>
739
740
  </div>
740
741
  </div>
741
742
  </div>
742
743
 
744
+ <!-- Explicit staged-read discard confirmation. This is separate from the review's generic Close:
745
+ closing is always reversible; only the named danger action below deletes the staged generation. -->
746
+ <div class="modal-backdrop" id="revdiscard-modal" role="dialog" aria-modal="true"
747
+ aria-labelledby="revdiscard-title" aria-describedby="revdiscard-sub revdiscard-error">
748
+ <div class="modal revision-discard">
749
+ <div class="modal-title" id="revdiscard-title">Discard this drawing read?</div>
750
+ <div class="modal-sub" id="revdiscard-sub"></div>
751
+ <div class="revision-discard-error" id="revdiscard-error" role="alert" aria-live="assertive" hidden></div>
752
+ <div class="modal-actions">
753
+ <button id="revdiscard-cancel" data-command-id="shell.dialog-cancel#discarding the drawing read">Keep review</button>
754
+ <button id="revdiscard-confirm" data-command-id="shell.revision-discard-confirm" class="danger">Discard read</button>
755
+ </div>
756
+ </div>
757
+ </div>
758
+
743
759
  <!-- Approval is a mandatory review, never a one-click mutation. The server supplies every group
744
760
  and all plain-English copy; this surface only records an explicit decision for each group. -->
745
761
  <div class="modal-backdrop" id="approval-review-modal" role="dialog" aria-modal="true" aria-labelledby="approval-review-title" aria-describedby="approval-review-sub">
@@ -254,7 +254,9 @@
254
254
  // provide a separate plain-English subject so `?` never reads implementation ids aloud.
255
255
  var narratedInstance = target.getAttribute('data-command-instance-label') || cmd.instance;
256
256
  return {
257
- label: cmd.meta.label || accessibleName(target),
257
+ label: cmd.meta.label
258
+ ? cmd.meta.label.replace(/\{instance\}/g, narratedInstance || 'the one you pick')
259
+ : accessibleName(target),
258
260
  acts: narratedInstance && cmd.meta.actsOn
259
261
  ? cmd.meta.actsOn.replace('{instance}', narratedInstance)
260
262
  : cmd.meta.actsOn || null,
@@ -507,10 +509,12 @@
507
509
  var parts = window.Commands.split ? window.Commands.split(raw) : null;
508
510
  if (!parts || parts.template !== cmd.id || !parts.instance || seen[raw]) return;
509
511
  seen[raw] = true;
512
+ var instanceLabel = el.getAttribute('data-command-instance-label') || accessibleName(el);
510
513
  found.push(Object.assign({}, cmd, {
511
514
  commandId: raw,
512
515
  instance: parts.instance,
513
- instanceLabel: el.getAttribute('data-command-instance-label') || accessibleName(el),
516
+ instanceLabel: instanceLabel,
517
+ label: cmd.label ? cmd.label.replace(/\{instance\}/g, parts.instance) : instanceLabel,
514
518
  originSurface: origin,
515
519
  }));
516
520
  });
@@ -578,14 +582,14 @@
578
582
  'In the Narrative panel', 'In the AI answers tab', 'In the node Inspect panel', 'In the Instructor strip',
579
583
  'In the ≡ menu', 'In the footer',
580
584
  'In the contract editor', 'In the report viewer', 'In the guide',
581
- 'In the agent library', 'In the requests list', 'In the run request dialog', 'In the Routines dialog',
585
+ 'In the agent library', 'In the requests list', 'In the revision review', 'In the run request dialog', 'In the Routines dialog',
582
586
  'In the Report an issue dialog', 'In the Build an agent dialog', 'In the Bake dialog',
583
587
  'In the FloLess dialogs',
584
588
  /* the steel editor — read top-left down, then the menus, then the dialogs.
585
589
  The ⋯ menu is six groups rather than one because it is six accordion
586
590
  sections on screen: a single 'In the ⋯ menu' would have been about thirty
587
591
  rows under one heading, which is a scroll rather than a list. */
588
- 'In the steel editor header', 'On the steel canvas', 'In the Copy panel', 'In the Copy array panel', 'On the 2D zoom bar',
592
+ 'In the steel editor header', 'On the steel canvas', 'On the drawing canvas', 'In the Copy panel', 'In the Copy array panel', 'On the 2D zoom bar',
589
593
  'In the 3D toolbar', 'In the 3D side panel', 'On the snap bar',
590
594
  'In the grid panel', 'In the Inspect panel',
591
595
  'In the Properties popup', 'In the snap override menu', 'In the dimension value popup', 'In the selection filter',
@@ -27,6 +27,8 @@
27
27
  * exactly as the drawing prints it is also what lets a detailer match it against the sheet.
28
28
  */
29
29
 
30
+ import { normalizeCatalogText } from './steel-catalog-picker.js';
31
+
30
32
  const finite = (n) => Number.isFinite(typeof n === 'number' ? n : Number(n));
31
33
  /** A drawable position. The renderer coerces, so numeric strings are accepted — but not a NaN, which
32
34
  * would put an un-clickable rect at an undefined coordinate. */
@@ -102,6 +104,122 @@ export function planDetailRefs(plan) {
102
104
  return out;
103
105
  }
104
106
 
107
+ /**
108
+ * Every drawable profile label on the plan: `{text, disp}`, in source order, NOT deduplicated.
109
+ *
110
+ * These are `plan.labels[]` — the PDF-extracted `{text, disp}` strings the profile-pick overlay draws
111
+ * as clickable hot-zones ("click a profile label in the drawing to apply it"). Same shape rule as
112
+ * `planDetailRefs`: an entry needs BOTH a printable string AND a drawable point, because the hot-zone
113
+ * is sized from the text and positioned at `disp` — an empty string sizes a zero box and a missing/NaN
114
+ * `disp` puts a rect at an undefined coordinate. Dropping the malformed ones here keeps that validation
115
+ * (and its tests) out of the page closure, where #887 hid: the overlay drew a positioned box for every
116
+ * label but never the text inside it, so every hot-zone rendered empty and unlabelled.
117
+ */
118
+ export function planProfileLabels(plan) {
119
+ if (!plan || typeof plan !== 'object' || !Array.isArray(plan.labels)) return [];
120
+ const out = [];
121
+ for (const entry of plan.labels) {
122
+ if (!entry || typeof entry !== 'object') continue;
123
+ const name = text(entry.text);
124
+ if (!name || !point(entry.disp)) continue;
125
+ out.push({ text: name, disp: [Number(entry.disp[0]), Number(entry.disp[1])] });
126
+ }
127
+ return out;
128
+ }
129
+
130
+ const profileSheetIndex = new WeakMap();
131
+ const canonicalProfile = (value) => normalizeCatalogText(value);
132
+ // Drawing labels may legitimately name custom, built-up, foreign, or unresolved sections that are
133
+ // absent from the installed catalogue. Keep those pickable (the editor marks them RFI), while rejecting
134
+ // ordinary annotations. Catalogue membership is authoritative; outside it, accept only known structural
135
+ // section families plus the two explicit unresolved/custom conventions FloLess already authors.
136
+ const STRUCTURAL_PROFILE = /^(?:2L|HSS|PIPE|HP|MC|WT|MT|ST|W|M|S|C|L|IPE|IPN|HEA|HEB|HEM|HE|HL|HD|UB|UC|UKB|UKC|PFC|CHS|RHS|SHS|EA|UA)\d/;
137
+ const CUSTOM_PROFILE = /^(?:MF\d+|BG\d+-CUSTOM)$/;
138
+ const DRAWING_ANNOTATION = /^(?:NOTE|NOTES|GRID|LEVEL|ELEV|ELEVATION|DETAIL|SHEET)\d/;
139
+ const profileToken = (value) => {
140
+ const name = canonicalProfile(value);
141
+ return name.length >= 2 && name.length <= 64 && /[A-Z]/.test(name) && /\d/.test(name)
142
+ && /^[A-Z0-9][A-Z0-9X./+'"#-]*$/.test(name)
143
+ ? name : '';
144
+ };
145
+ const profileDesignation = (value, catalogue) => {
146
+ const name = profileToken(value);
147
+ return name && !DRAWING_ANNOTATION.test(name)
148
+ && (catalogue.has(name) || STRUCTURAL_PROFILE.test(name) || CUSTOM_PROFILE.test(name)) ? name : '';
149
+ };
150
+ const sheetKey = (value) => String(value == null ? '' : value).trim().replace(/\s+/g, ' ').toUpperCase();
151
+ const bbox = (value) => Array.isArray(value) && value.length >= 4 && value.slice(0, 4).every(finite)
152
+ && Number(value[2]) >= Number(value[0]) && Number(value[3]) >= Number(value[1]);
153
+ const intersects = (a, b) => !b || (a[2] >= b[0] && a[0] <= b[2] && a[3] >= b[1] && a[1] <= b[3]);
154
+
155
+ function indexedFilterLabels(sheet) {
156
+ const cached = profileSheetIndex.get(sheet);
157
+ if (cached) return cached;
158
+ const out = [];
159
+ for (const entry of Array.isArray(sheet?.elements) ? sheet.elements : []) {
160
+ if (!entry || entry.kind !== 'text' || !bbox(entry.bbox)) continue;
161
+ const name = profileToken(entry.text);
162
+ if (!name) continue;
163
+ const box = entry.bbox.slice(0, 4).map(Number);
164
+ out.push({ text: name, disp: [(box[0] + box[2]) / 2, (box[1] + box[3]) / 2], bbox: box });
165
+ }
166
+ profileSheetIndex.set(sheet, out);
167
+ return out;
168
+ }
169
+
170
+ /**
171
+ * The bounded data source for the profile-pick overlay.
172
+ *
173
+ * Authored plan labels win. Only when there are none does the caller receive a Filter-text fallback,
174
+ * and that fallback is available only for one exact, case-folded sheet match. The Filter sheet's raw
175
+ * text is indexed once by object identity; designation-shape validation, viewport intersection and the
176
+ * DOM cap keep a 40k-element drawing from becoming a 40k-node overlay without hiding unresolved profiles.
177
+ */
178
+ export function planProfileLabelOverlay(plan, filter, options = {}) {
179
+ const max = Number.isSafeInteger(options.max) && options.max > 0 ? options.max : 500;
180
+ const viewport = bbox(options.viewport) ? options.viewport.slice(0, 4).map(Number) : null;
181
+ const catalogue = new Set((Array.isArray(options.profiles) ? options.profiles : []).map(canonicalProfile).filter(Boolean));
182
+ const explicit = [];
183
+ const seen = new Set();
184
+ for (const entry of Array.isArray(plan?.labels) ? plan.labels : []) {
185
+ if (!entry || !point(entry.disp)) continue;
186
+ const name = profileDesignation(entry.text, catalogue);
187
+ if (!name) continue;
188
+ const x = Number(entry.disp[0]), y = Number(entry.disp[1]), key = `${name}\0${x}\0${y}`;
189
+ if (seen.has(key)) continue;
190
+ seen.add(key);
191
+ explicit.push({ text: name, disp: [x, y], bbox: [x, y, x, y] });
192
+ }
193
+ let source = 'plan', candidates = explicit, diagnostic = null;
194
+ if (!explicit.length) {
195
+ const wanted = sheetKey(plan?.sheet);
196
+ const matches = (Array.isArray(filter?.sheets) ? filter.sheets : []).filter((sheet) => sheetKey(sheet?.sheet) === wanted);
197
+ if (matches.length !== 1) {
198
+ const action = ' Save the matching sheet in Drawing Filter, or choose a profile with Browse.';
199
+ diagnostic = matches.length
200
+ ? `Profile picking is unavailable because more than one Filter sheet matches ${text(plan?.sheet) || 'this plan'}.${action}`
201
+ : `Profile picking is unavailable because no Filter sheet matches ${text(plan?.sheet) || 'this plan'}.${action}`;
202
+ return { labels: [], source: 'none', hidden: 0, message: null, diagnostic };
203
+ }
204
+ source = 'filter';
205
+ const fallbackSeen = new Set();
206
+ candidates = indexedFilterLabels(matches[0]).filter((entry) => {
207
+ if (!profileDesignation(entry.text, catalogue)) return false;
208
+ const key = `${entry.text}\0${entry.bbox.join('\0')}`;
209
+ if (fallbackSeen.has(key)) return false;
210
+ fallbackSeen.add(key);
211
+ return true;
212
+ });
213
+ }
214
+ const visible = candidates.filter((entry) => intersects(entry.bbox, viewport));
215
+ const labels = visible.slice(0, max);
216
+ const hidden = visible.length - labels.length;
217
+ return {
218
+ labels, source, hidden, diagnostic,
219
+ message: hidden > 0 ? 'Zoom in to reveal the remaining profile labels' : null,
220
+ };
221
+ }
222
+
105
223
  /**
106
224
  * Callout kinds that are NOT details for scoring purposes.
107
225
  *