@floless/app 0.133.2 → 0.134.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.
- package/dist/floless-server.cjs +5079 -2851
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +93 -6
- package/dist/web/app.css +99 -8
- package/dist/web/app.js +32 -0
- package/dist/web/aware.js +833 -109
- package/dist/web/commands-filter.js +79 -5
- package/dist/web/commands-shell.js +130 -11
- package/dist/web/commands-steel.js +26 -4
- package/dist/web/index.html +30 -15
- package/dist/web/instructor.js +90 -35
- package/dist/web/steel-3d-core.js +329 -3
- package/dist/web/steel-3d-view.js +613 -8
- package/dist/web/steel-editor.html +406 -27
- package/dist/web/steel-filter-core.js +189 -16
- package/dist/web/steel-filter.html +865 -46
- package/dist/web/steel-model-commands.js +23 -2
- package/dist/web/steel-model-v2-commands.js +124 -0
- package/dist/web/workspaces.js +555 -82
- package/package.json +1 -1
package/dist/web/instructor.js
CHANGED
|
@@ -237,7 +237,7 @@
|
|
|
237
237
|
|
|
238
238
|
function focusFor(el) {
|
|
239
239
|
if (!el || el === document.body) return null;
|
|
240
|
-
var target = el.closest('button, [role="button"], [role="treeitem"], a[href], input, select, textarea');
|
|
240
|
+
var target = el.closest('button, summary, [role="button"], [role="treeitem"], a[href], input, select, textarea');
|
|
241
241
|
if (!target) return null;
|
|
242
242
|
|
|
243
243
|
var tip = target.getAttribute('data-tip') || '';
|
|
@@ -247,10 +247,13 @@
|
|
|
247
247
|
// A registered template supplies the facts; the instance key supplies the
|
|
248
248
|
// subject, so one authored entry serves every generated row.
|
|
249
249
|
if (cmd && cmd.meta) {
|
|
250
|
+
// Parameterized command ids keep opaque request/lease keys for exact activation. Narration may
|
|
251
|
+
// provide a separate plain-English subject so `?` never reads implementation ids aloud.
|
|
252
|
+
var narratedInstance = target.getAttribute('data-command-instance-label') || cmd.instance;
|
|
250
253
|
return {
|
|
251
254
|
label: cmd.meta.label || accessibleName(target),
|
|
252
|
-
acts:
|
|
253
|
-
? cmd.meta.actsOn.replace('{instance}',
|
|
255
|
+
acts: narratedInstance && cmd.meta.actsOn
|
|
256
|
+
? cmd.meta.actsOn.replace('{instance}', narratedInstance)
|
|
254
257
|
: cmd.meta.actsOn || null,
|
|
255
258
|
group: cmd.meta.group || groupOf(target),
|
|
256
259
|
key: cmd.meta.key || target.getAttribute('data-key'),
|
|
@@ -463,7 +466,13 @@
|
|
|
463
466
|
|
|
464
467
|
function sheetEntries() {
|
|
465
468
|
if (!window.Commands) return [];
|
|
466
|
-
|
|
469
|
+
var entries = [];
|
|
470
|
+
window.Commands.all().forEach(function (cmd) {
|
|
471
|
+
var instances = visibleCommandInstances(cmd);
|
|
472
|
+
if (instances.length) Array.prototype.push.apply(entries, instances);
|
|
473
|
+
else entries.push(cmd);
|
|
474
|
+
});
|
|
475
|
+
return entries.sort(function (a, b) {
|
|
467
476
|
// What is on screen comes first. Nothing is hidden — the sheet is also how
|
|
468
477
|
// you find out what FloLess can do somewhere else, and its zero-result copy
|
|
469
478
|
// calls a miss "a gap worth reporting", which would be a lie if the
|
|
@@ -480,6 +489,36 @@
|
|
|
480
489
|
});
|
|
481
490
|
}
|
|
482
491
|
|
|
492
|
+
/* A command-sheet row for a runtime-built control must retain the exact instance it describes.
|
|
493
|
+
Otherwise two request rows sharing one template both navigate to whichever carrier happens to
|
|
494
|
+
appear first in the DOM. Read attributes instead of interpolating instance data into a selector:
|
|
495
|
+
request ids and member labels are data, and may legitimately contain selector punctuation. */
|
|
496
|
+
function visibleCommandInstances(cmd) {
|
|
497
|
+
var found = [], seen = {};
|
|
498
|
+
function collect(doc, origin) {
|
|
499
|
+
if (!doc || !doc.querySelectorAll) return;
|
|
500
|
+
Array.prototype.forEach.call(doc.querySelectorAll('[data-command-id]'), function (el) {
|
|
501
|
+
if ((el.closest && el.closest('#command-sheet'))
|
|
502
|
+
|| !(el.offsetParent || (el.getClientRects && el.getClientRects().length))) return;
|
|
503
|
+
var raw = el.getAttribute('data-command-id') || '';
|
|
504
|
+
var parts = window.Commands.split ? window.Commands.split(raw) : null;
|
|
505
|
+
if (!parts || parts.template !== cmd.id || !parts.instance || seen[raw]) return;
|
|
506
|
+
seen[raw] = true;
|
|
507
|
+
found.push(Object.assign({}, cmd, {
|
|
508
|
+
commandId: raw,
|
|
509
|
+
instance: parts.instance,
|
|
510
|
+
instanceLabel: el.getAttribute('data-command-instance-label') || accessibleName(el),
|
|
511
|
+
originSurface: origin,
|
|
512
|
+
}));
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
collect(document, 'shell');
|
|
516
|
+
if (activeReporterWindow && snapshot.child) {
|
|
517
|
+
try { collect(activeReporterWindow.document, snapshot.child.surface || 'shell'); } catch (e) { /* torn down */ }
|
|
518
|
+
}
|
|
519
|
+
return found;
|
|
520
|
+
}
|
|
521
|
+
|
|
483
522
|
/* What a row says BESIDES its label. An entry with nothing to add says
|
|
484
523
|
nothing — silence beats an echo, and a row that reads "Compile — compiles"
|
|
485
524
|
would cost the whole surface its credibility. */
|
|
@@ -489,7 +528,7 @@
|
|
|
489
528
|
serve every generated row. The sheet lists TEMPLATES, so there is no
|
|
490
529
|
instance to fill it with — and shipping the literal braces to a user is
|
|
491
530
|
the kind of leak that costs a documentation surface its credibility. */
|
|
492
|
-
if (cmd.actsOn) facts.push(cmd.actsOn.replace(/\{instance\}/g, 'the one you pick'));
|
|
531
|
+
if (cmd.actsOn) facts.push(cmd.actsOn.replace(/\{instance\}/g, cmd.instanceLabel || cmd.instance || 'the one you pick'));
|
|
493
532
|
if (cmd.risk && cmd.risk.indexOf('destructive') !== -1) facts.push('cannot be undone');
|
|
494
533
|
if (cmd.risk && cmd.risk.indexOf('costs-money') !== -1) facts.push('costs money');
|
|
495
534
|
if (cmd.persistence === 'external') facts.push('reaches outside FloLess');
|
|
@@ -515,7 +554,7 @@
|
|
|
515
554
|
themselves. Risk flags are in, so "destructive" finds what it should. */
|
|
516
555
|
function matches(cmd, q) {
|
|
517
556
|
if (!q) return true;
|
|
518
|
-
var hay = [cmd.label, cmd.actsOn, cmd.group, cmd.key, cmd.why]
|
|
557
|
+
var hay = [cmd.label, cmd.instanceLabel, cmd.actsOn, cmd.group, cmd.key, cmd.why]
|
|
519
558
|
.concat(cmd.steps || [])
|
|
520
559
|
.concat(cmd.risk || [])
|
|
521
560
|
.join(' ').toLowerCase();
|
|
@@ -533,7 +572,7 @@
|
|
|
533
572
|
// the shell
|
|
534
573
|
'In the header', 'In the workflow picker', 'In the project picker',
|
|
535
574
|
'In the project workspace', 'On the workflow canvas',
|
|
536
|
-
'In the Narrative panel', 'In the node Inspect panel', 'In the Instructor strip',
|
|
575
|
+
'In the Narrative panel', 'In the AI answers tab', 'In the node Inspect panel', 'In the Instructor strip',
|
|
537
576
|
'In the ≡ menu', 'In the footer',
|
|
538
577
|
'In the contract editor', 'In the report viewer', 'In the guide',
|
|
539
578
|
'In the agent library', 'In the requests list', 'In the run request dialog', 'In the Routines dialog',
|
|
@@ -554,7 +593,9 @@
|
|
|
554
593
|
'In the Connections dialog', 'In the reference-model dialogs', 'In the connection-import dialog',
|
|
555
594
|
'In the confidence report', 'In the Ask AI dialog', 'In the Favourites dialog',
|
|
556
595
|
// the drawing filter
|
|
557
|
-
'In the Drawing Filter header', 'In
|
|
596
|
+
'In the Drawing Filter header', 'In a Drawing Filter message',
|
|
597
|
+
'In the Drawing Filter panel', 'On the Drawing Filter canvas',
|
|
598
|
+
'In the Drawing Filter layer approval',
|
|
558
599
|
// the vector editor, and its 3D viewer
|
|
559
600
|
'In the Trace header', 'In the Trace panel', 'On the Trace canvas',
|
|
560
601
|
'In the Trace — 3D header', 'On the Trace — 3D view',
|
|
@@ -637,10 +678,10 @@
|
|
|
637
678
|
var row = document.createElement('button');
|
|
638
679
|
row.type = 'button';
|
|
639
680
|
row.className = 'cmd-row';
|
|
640
|
-
row.id = 'cmd-row-' + cmd.id; //
|
|
681
|
+
row.id = 'cmd-row-' + cmd.id + '-' + sheetRows.length; // unique aria-activedescendant target
|
|
641
682
|
row.setAttribute('role', 'option');
|
|
642
683
|
row.setAttribute('aria-selected', 'false');
|
|
643
|
-
row.dataset.commandId = cmd.id;
|
|
684
|
+
row.dataset.commandId = cmd.commandId || cmd.id;
|
|
644
685
|
|
|
645
686
|
var label = document.createElement('span');
|
|
646
687
|
label.className = 'cmd-row-label';
|
|
@@ -713,27 +754,19 @@
|
|
|
713
754
|
row is the ONLY match. The result was focusing a row inside a dialog that
|
|
714
755
|
had just been hidden. Visibility is checked too: a control in a closed
|
|
715
756
|
panel is found by a selector but cannot be focused. */
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
The INSTANCE key is the half that comes from data (a member mark, a level
|
|
722
|
-
elevation like 16'-6"), and it deliberately never appears here: the second
|
|
723
|
-
arm matches on the `id#` PREFIX and lets the attribute selector's own
|
|
724
|
-
quoting cover whatever follows. So an instance containing a quote is a
|
|
725
|
-
problem only where it is WRITTEN INTO markup, never where it is read back.
|
|
726
|
-
Keep it that way — building a selector from a raw instance is the shape
|
|
727
|
-
that would break. */
|
|
728
|
-
var sel = '[data-command-id="' + cmd.id + '"], [data-command-id^="' + cmd.id + '#"]';
|
|
757
|
+
var exactCommandId = cmd.commandId || null;
|
|
758
|
+
function matchesCommand(el) {
|
|
759
|
+
var raw = el.getAttribute('data-command-id') || '';
|
|
760
|
+
return exactCommandId ? raw === exactCommandId : (raw === cmd.id || raw.indexOf(cmd.id + '#') === 0);
|
|
761
|
+
}
|
|
729
762
|
var live = null;
|
|
730
763
|
/* Which document the control was found in — carried so the entry can be stamped
|
|
731
764
|
with where the control LIVES rather than with whatever surface happened to be
|
|
732
765
|
on screen. A shell button stays alive (and focusable) under the child overlay,
|
|
733
766
|
so those two are genuinely different answers. */
|
|
734
767
|
var liveOrigin = 'shell';
|
|
735
|
-
Array.prototype.forEach.call(document.querySelectorAll(
|
|
736
|
-
if (live || (el.closest && el.closest('#command-sheet'))) return;
|
|
768
|
+
Array.prototype.forEach.call(document.querySelectorAll('[data-command-id]'), function (el) {
|
|
769
|
+
if (live || !matchesCommand(el) || (el.closest && el.closest('#command-sheet'))) return;
|
|
737
770
|
if (el.offsetParent || (el.getClientRects && el.getClientRects().length)) live = el;
|
|
738
771
|
});
|
|
739
772
|
|
|
@@ -751,11 +784,11 @@
|
|
|
751
784
|
if (!live && activeReporterWindow && snapshot.child) {
|
|
752
785
|
try {
|
|
753
786
|
var doc = activeReporterWindow.document;
|
|
754
|
-
Array.prototype.forEach.call(doc.querySelectorAll(
|
|
787
|
+
Array.prototype.forEach.call(doc.querySelectorAll('[data-command-id]'), function (el) {
|
|
755
788
|
// Same exclusion as above. No child renders a sheet today, but the rows are
|
|
756
789
|
// the one place a data-command-id describes a LIST ENTRY rather than a control,
|
|
757
790
|
// and half a rule is how that distinction gets lost.
|
|
758
|
-
if (live || (el.closest && el.closest('#command-sheet'))) return;
|
|
791
|
+
if (live || !matchesCommand(el) || (el.closest && el.closest('#command-sheet'))) return;
|
|
759
792
|
if (el.offsetParent || (el.getClientRects && el.getClientRects().length)) {
|
|
760
793
|
live = el;
|
|
761
794
|
liveOrigin = snapshot.child.surface || 'shell';
|
|
@@ -796,14 +829,14 @@
|
|
|
796
829
|
learns what it does and where it lives, which is what they asked for. */
|
|
797
830
|
setFocusEntry({
|
|
798
831
|
label: cmd.label,
|
|
799
|
-
acts: cmd.actsOn ? cmd.actsOn.replace(/\{instance\}/g, 'the one you pick') : null,
|
|
832
|
+
acts: cmd.actsOn ? cmd.actsOn.replace(/\{instance\}/g, cmd.instanceLabel || cmd.instance || 'the one you pick') : null,
|
|
800
833
|
group: cmd.group,
|
|
801
834
|
key: cmd.key,
|
|
802
835
|
tip: cmd.why || '',
|
|
803
836
|
disabled: false,
|
|
804
837
|
disabledReason: null,
|
|
805
838
|
commandId: cmd.id,
|
|
806
|
-
instance: null,
|
|
839
|
+
instance: cmd.instance || null,
|
|
807
840
|
}, cmd.surface || 'shell');
|
|
808
841
|
paint();
|
|
809
842
|
}
|
|
@@ -838,6 +871,7 @@
|
|
|
838
871
|
app using `inert`, so it is latent rather than live, but "the second user of
|
|
839
872
|
inert silently breaks the first" is a bad thing to leave lying around. */
|
|
840
873
|
var inertBefore = null;
|
|
874
|
+
var coveredDialogAriaBefore = null;
|
|
841
875
|
|
|
842
876
|
function setBackgroundInert(on) {
|
|
843
877
|
if (on) {
|
|
@@ -856,15 +890,20 @@
|
|
|
856
890
|
|
|
857
891
|
function openSheet() {
|
|
858
892
|
if (!$sheet || sheetOpen || !enabled) return false;
|
|
859
|
-
/*
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
893
|
+
/* Requests is the one dialog whose runtime-built controls need to be browsable in this sheet.
|
|
894
|
+
It is covered (inert + aria-hidden) while the sheet owns the screen, and app.css gives the
|
|
895
|
+
sheet the explicit upper tier. Every other dialog still refuses stacking: its controls are
|
|
896
|
+
already explained in place and opening above it would obscure an unfinished decision. */
|
|
897
|
+
var shownDialogs = Array.prototype.slice.call(document.querySelectorAll('.modal-backdrop.show'))
|
|
898
|
+
.filter(function (modal) { return modal !== $sheet; });
|
|
899
|
+
if (shownDialogs.some(function (modal) { return modal.id !== 'requests-modal'; })) return false;
|
|
865
900
|
|
|
866
901
|
returnFocusTo = document.activeElement;
|
|
867
902
|
sheetOpen = true;
|
|
903
|
+
coveredDialogAriaBefore = shownDialogs.map(function (modal) {
|
|
904
|
+
return [modal, modal.getAttribute('aria-hidden')];
|
|
905
|
+
});
|
|
906
|
+
shownDialogs.forEach(function (modal) { modal.setAttribute('aria-hidden', 'true'); });
|
|
868
907
|
$sheet.hidden = false;
|
|
869
908
|
$sheet.classList.add('show');
|
|
870
909
|
setBackgroundInert(true);
|
|
@@ -888,7 +927,23 @@
|
|
|
888
927
|
sheetOpen = false;
|
|
889
928
|
$sheet.classList.remove('show');
|
|
890
929
|
$sheet.hidden = true;
|
|
930
|
+
// A pointer-opened row is normally the freshest hover target when this dialog closes.
|
|
931
|
+
// That row is hidden now, so letting the next `?` prefer it over the control we just
|
|
932
|
+
// focused narrates the row's opaque instance key instead of the live control's authored
|
|
933
|
+
// `data-command-instance-label`. Retire only a target owned by this surface: a still-visible
|
|
934
|
+
// control elsewhere remains the user's valid pointer intent after a keyboard close.
|
|
935
|
+
if (lastHovered && lastHovered.closest && lastHovered.closest('#command-sheet')) {
|
|
936
|
+
lastHovered = null;
|
|
937
|
+
lastHoveredAt = 0;
|
|
938
|
+
}
|
|
891
939
|
setBackgroundInert(false);
|
|
940
|
+
if (coveredDialogAriaBefore) {
|
|
941
|
+
coveredDialogAriaBefore.forEach(function (pair) {
|
|
942
|
+
if (pair[1] === null) pair[0].removeAttribute('aria-hidden');
|
|
943
|
+
else pair[0].setAttribute('aria-hidden', pair[1]);
|
|
944
|
+
});
|
|
945
|
+
coveredDialogAriaBefore = null;
|
|
946
|
+
}
|
|
892
947
|
// Focus goes back where it came from. Dropping it on <body> is how a keyboard
|
|
893
948
|
// user gets stranded at the top of the document with no idea what happened.
|
|
894
949
|
if (returnFocusTo && returnFocusTo.focus && document.contains(returnFocusTo)) returnFocusTo.focus();
|
|
@@ -55,9 +55,9 @@ export function canonicalPositionBasis(x, y) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/** One production folding rule shared by scene reading, editor display and basis re-expression. */
|
|
58
|
-
export function effectiveDepthPosition(explicit, role, dzMm, horizMm,
|
|
58
|
+
export function effectiveDepthPosition(explicit, role, dzMm, horizMm, verticalBrace = false) {
|
|
59
59
|
if (explicit === 'top' || explicit === 'middle' || explicit === 'bottom') return explicit;
|
|
60
|
-
if (role === 'column' ||
|
|
60
|
+
if (role === 'column' || verticalBrace) return 'middle'; // param renamed off `isVerticalBrace`, which is now a module-level predicate this would shadow
|
|
61
61
|
return dzMm > horizMm * 0.5774 ? 'middle' : 'top';
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -99,7 +99,7 @@ export function reexpressMemberPlacement(member, refFrom, refTo, target, extents
|
|
|
99
99
|
if (!a0 || !a1) return { ok: false, code: 'position-rebase-degenerate', message: 'A zero-length member has no Profile Position frame.' };
|
|
100
100
|
const dz = Math.abs(refTo[2] - refFrom[2]), horiz = Math.hypot(refTo[0] - refFrom[0], refTo[1] - refFrom[1]);
|
|
101
101
|
const depthFace = effectiveDepthPosition(member.position, member.role === 'column' ? 'column' : 'beam', dz, horiz,
|
|
102
|
-
member
|
|
102
|
+
isVerticalBrace(member)); // one shared predicate — this was a bare `=== 'brace'`, a THIRD spelling of a test the scene reader already normalises (slice 3b.1)
|
|
103
103
|
const widthFace = effectiveWidthPosition(member.positionH);
|
|
104
104
|
let oy0, oz0;
|
|
105
105
|
if (extents && extents.lo && extents.hi) {
|
|
@@ -1542,6 +1542,31 @@ function cross3(a, b) {
|
|
|
1542
1542
|
return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|
1543
1543
|
}
|
|
1544
1544
|
|
|
1545
|
+
/**
|
|
1546
|
+
* The world part frame the Profile Position gizmo (slice 3a) draws its arrows in, for a given authoring
|
|
1547
|
+
* basis. It is the SAME frame the bake and the inspector read (`partFrame`), so a dragged handle moves
|
|
1548
|
+
* the steel exactly where a typed offset would: width = `frame.y`, depth = `frame.z`, member axis =
|
|
1549
|
+
* `frame.x` (basis-independent). The coordinate system's normal `up` is derived from the basis
|
|
1550
|
+
* (`x × y` for a canonical orthonormal basis), never stored — global uses world Z.
|
|
1551
|
+
*
|
|
1552
|
+
* Returns null (the gizmo then shows nothing) for a zero-length member or a basis that is not a usable
|
|
1553
|
+
* frame, so a caller never has to guard `partFrame`'s throw on a degenerate `up`/`upX`.
|
|
1554
|
+
*
|
|
1555
|
+
* @param {number[]} refFrom the authored reference-line start (the gizmo anchor)
|
|
1556
|
+
* @param {number[]} refTo the authored reference-line end
|
|
1557
|
+
* @param {{kind?:string, x?:number[], y?:number[]}} basis a `positionAuthoringBasis()` snapshot
|
|
1558
|
+
* @returns {{x:number[], y:number[], z:number[], degenerate:boolean}|null}
|
|
1559
|
+
*/
|
|
1560
|
+
export function positionGizmoFrame(refFrom, refTo, basis) {
|
|
1561
|
+
let up, upX;
|
|
1562
|
+
if (!basis || basis.kind === 'global') { up = [0, 0, 1]; upX = [1, 0, 0]; }
|
|
1563
|
+
else {
|
|
1564
|
+
if (!finiteVec3(basis.x) || !finiteVec3(basis.y)) return null;
|
|
1565
|
+
up = cross3(basis.x, basis.y); upX = [basis.x[0], basis.x[1], basis.x[2]];
|
|
1566
|
+
}
|
|
1567
|
+
try { return partFrame(refFrom, refTo, up, upX); } catch (_) { return null; }
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1545
1570
|
/**
|
|
1546
1571
|
* `partFrame` with its axes reordered into the MESH's local order — the one place that says which frame
|
|
1547
1572
|
* axis each of a member geometry's local axes becomes. `orientMember` (`web/steel-3d-view.js`) feeds the
|
|
@@ -1626,6 +1651,68 @@ export function positionOffsetVector(frame, ex, depthFace, widthFace, rotDeg, wi
|
|
|
1626
1651
|
];
|
|
1627
1652
|
}
|
|
1628
1653
|
|
|
1654
|
+
// The ¼" / 5° snaps the 3D Profile Position gizmo applies to a dragged offset / roll (Shift = free).
|
|
1655
|
+
export const POSITION_OFFSET_SNAP_MM = 25.4 / 4;
|
|
1656
|
+
export const POSITION_ROT_SNAP_DEG = 5;
|
|
1657
|
+
|
|
1658
|
+
/** Round `value` to the nearest multiple of `step` (the gizmo's ¼"/5° drag snap); `step<=0` = free. */
|
|
1659
|
+
export function snapToStep(value, step) {
|
|
1660
|
+
return step > 0 ? Math.round(value / step) * step : value;
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
/**
|
|
1664
|
+
* The fold applied to a roll (deg) before it is COMMITTED to storage — the SAME `r % 360` (signed) the
|
|
1665
|
+
* Inspect panel commit already uses (`steel-editor.html:6755`/`:7053`). One shared helper so the 3D gizmo's
|
|
1666
|
+
* drag/type commit and the panel can never store two different conventions: a re-expressed base is generically
|
|
1667
|
+
* off-grid, and a cross-seam arc drag accumulates a continuous angle that can run past ±360, so the raw value
|
|
1668
|
+
* must be folded — but signed, because a detailer reads "−5°", not "355°". A non-finite roll reads as 0.
|
|
1669
|
+
*/
|
|
1670
|
+
export function rollCommitNorm(deg) {
|
|
1671
|
+
return (typeof deg === 'number' && isFinite(deg) ? deg : 0) % 360;
|
|
1672
|
+
}
|
|
1673
|
+
|
|
1674
|
+
/**
|
|
1675
|
+
* The shortest-arc increment (rad) from `prevRad` to `curRad`, folded into (−π, π]. Used to CONTINUOUSLY
|
|
1676
|
+
* unwrap the roll arc during a drag: summing these steps tracks the true swept angle, so crossing the ±180°
|
|
1677
|
+
* seam adds a small step instead of the ~2π jump a bare `cur − start` produces (which moved a beam ~360° in one
|
|
1678
|
+
* tick). Both `atan2` outputs live in (−π, π]; this returns their signed shortest difference.
|
|
1679
|
+
*/
|
|
1680
|
+
export function unwrapAngleStep(prevRad, curRad) {
|
|
1681
|
+
let d = curRad - prevRad;
|
|
1682
|
+
while (d > Math.PI) d -= 2 * Math.PI;
|
|
1683
|
+
while (d <= -Math.PI) d += 2 * Math.PI;
|
|
1684
|
+
return d;
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
/**
|
|
1688
|
+
* The world translation the steel undergoes when ONE numeric Profile Position offset changes by
|
|
1689
|
+
* `deltaMm` (the depth offset for `axis:'depth'`, the width offset for `'width'`), holding the other
|
|
1690
|
+
* offset, the named faces and the roll fixed. This is exactly `positionOffsetVector`'s linear response
|
|
1691
|
+
* to that offset — factored out so the 3D gizmo's live preview and the bake CANNOT drift apart. A
|
|
1692
|
+
* hand-copied second copy of this sign/swing convention is precisely the class of silent error the
|
|
1693
|
+
* clash-and-exact-placement rule exists to catch, so the gizmo's preview MUST call this, never re-derive
|
|
1694
|
+
* it. `frame` is a `partFrame` triple; the delta is measured on the section's own (unrotated) axis and
|
|
1695
|
+
* then swung by `rotDeg`, matching §1.3's position-then-rotate order.
|
|
1696
|
+
*
|
|
1697
|
+
* @param {{y:number[], z:number[]}} frame
|
|
1698
|
+
* @param {'depth'|'width'} axis
|
|
1699
|
+
* @param {number} deltaMm
|
|
1700
|
+
* @param {number} rotDeg
|
|
1701
|
+
* @returns {[number, number, number]}
|
|
1702
|
+
*/
|
|
1703
|
+
export function positionSwingDelta(frame, axis, deltaMm, rotDeg) {
|
|
1704
|
+
const th = ((typeof rotDeg === 'number' && isFinite(rotDeg) ? rotDeg : 0) * Math.PI) / 180;
|
|
1705
|
+
const c = Math.cos(th), s = Math.sin(th), d = typeof deltaMm === 'number' && isFinite(deltaMm) ? deltaMm : 0;
|
|
1706
|
+
// width offset (oy) swings to c·y + s·z ; depth offset (oz) swings to −s·y + c·z — the exact partial
|
|
1707
|
+
// derivatives of positionOffsetVector w.r.t. widthOffMm / depthOffMm.
|
|
1708
|
+
const wy = axis === 'depth' ? -s : c, wz = axis === 'depth' ? c : s;
|
|
1709
|
+
return [
|
|
1710
|
+
d * (wy * frame.y[0] + wz * frame.z[0]),
|
|
1711
|
+
d * (wy * frame.y[1] + wz * frame.z[1]),
|
|
1712
|
+
d * (wy * frame.y[2] + wz * frame.z[2]),
|
|
1713
|
+
];
|
|
1714
|
+
}
|
|
1715
|
+
|
|
1629
1716
|
/**
|
|
1630
1717
|
* Reversing a member's two work points must leave the STEEL exactly where it is — and it takes TWO
|
|
1631
1718
|
* transforms, one per branch of `partFrame`. An earlier draft had one rule and it was wrong for a column.
|
|
@@ -1663,3 +1750,242 @@ export function reversePlacement(p, degenerate) {
|
|
|
1663
1750
|
}
|
|
1664
1751
|
return out;
|
|
1665
1752
|
}
|
|
1753
|
+
|
|
1754
|
+
// ---- Reference-line handles: pure geometry (Profile Position gizmo, slice 3b.1) ------------------
|
|
1755
|
+
/*
|
|
1756
|
+
* The shipped gizmo handles (depth / width / roll) move the PROFILE within a fixed reference line. Slice
|
|
1757
|
+
* 3b.1 adds three that move the reference LINE itself — a rigid slide along the member axis and two swings
|
|
1758
|
+
* about the start work point. The math lives HERE, not in steel-3d-view.js, because the view imports
|
|
1759
|
+
* `three` and cannot be unit-tested in node; steel-position-core.test.ts already imports this module.
|
|
1760
|
+
*/
|
|
1761
|
+
|
|
1762
|
+
/**
|
|
1763
|
+
* The quantisation the v2 store applies to a stored world coordinate — the same `round(v * 1e9) / 1e9`
|
|
1764
|
+
* rule `elev()` uses, so a world-point write and an elevation write agree bit-for-bit on the same number.
|
|
1765
|
+
* Exported because the depth-face pin MUST be decided on the QUANTISED endpoints: an unquantised preview
|
|
1766
|
+
* can disagree with what is actually stored, right at the fold threshold.
|
|
1767
|
+
*/
|
|
1768
|
+
export function quantizeMm(v) {
|
|
1769
|
+
return typeof v === 'number' && isFinite(v) ? Math.round(v * 1e9) / 1e9 : NaN;
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
/**
|
|
1773
|
+
* ONE canonical "is this a vertical brace", matching the durable scene reader's normalisation
|
|
1774
|
+
* (`contract-to-scene.ts` `memberIsBrace`, which trims and lowercases). The repo had THREE spellings of
|
|
1775
|
+
* this test, and the scene reader's own comment records that two of them "are not interchangeable"; the
|
|
1776
|
+
* depth-face pin must not add a fourth, so this helper serves the pin AND replaces
|
|
1777
|
+
* `reexpressMemberPlacement`'s bare `=== 'brace'`. The editor's registry path (memberTypeOf /
|
|
1778
|
+
* normMemberTypeKey) stays a third, more permissive answer — recorded here rather than silently widened.
|
|
1779
|
+
*/
|
|
1780
|
+
export function isVerticalBrace(member) {
|
|
1781
|
+
return !!member
|
|
1782
|
+
&& typeof member.memberType === 'string'
|
|
1783
|
+
&& member.memberType.trim().toLowerCase() === 'brace'
|
|
1784
|
+
&& member.brace?.type === 'vertical';
|
|
1785
|
+
}
|
|
1786
|
+
|
|
1787
|
+
/**
|
|
1788
|
+
* The effective depth face before and after a move, and the pin the commit must carry.
|
|
1789
|
+
*
|
|
1790
|
+
* `effectiveDepthPosition` folds an UNSET depth face at `dz > horiz * 0.5774`, so a move that tips a member
|
|
1791
|
+
* past ~30 degrees silently flips which face the profile hangs from and the steel jumps away from where the
|
|
1792
|
+
* user just put it. The fix is to pin the drag-start face explicitly when — and only when — the move would
|
|
1793
|
+
* change it. Deciding that in ONE place, from canonical state and the quantised endpoints, is what stops
|
|
1794
|
+
* the editor's prediction and the model command's verification from ever disagreeing.
|
|
1795
|
+
*
|
|
1796
|
+
* @param {{position?:string, role?:string, memberType?:string, brace?:{type?:string}}} member
|
|
1797
|
+
* @param {{from:number[], to:number[]}} before the stored endpoints
|
|
1798
|
+
* @param {{from:number[], to:number[]}} after the QUANTISED candidate endpoints
|
|
1799
|
+
* @returns {{before:string, after:string, pin:string|undefined}} `pin` is the face to store, or undefined
|
|
1800
|
+
* when the fold does not change. A member with an explicit face never changes, so never pins.
|
|
1801
|
+
*/
|
|
1802
|
+
export function requiredDepthPin(member, before, after) {
|
|
1803
|
+
const role = member && member.role === 'column' ? 'column' : 'beam';
|
|
1804
|
+
const vb = isVerticalBrace(member);
|
|
1805
|
+
const faceOf = (a, b) => effectiveDepthPosition(
|
|
1806
|
+
member ? member.position : undefined, role,
|
|
1807
|
+
Math.abs(b[2] - a[2]), Math.hypot(b[0] - a[0], b[1] - a[1]), vb,
|
|
1808
|
+
);
|
|
1809
|
+
const f0 = faceOf(before.from, before.to);
|
|
1810
|
+
const f1 = faceOf(after.from, after.to);
|
|
1811
|
+
return { before: f0, after: f1, pin: f0 === f1 ? undefined : f0 };
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
/**
|
|
1815
|
+
* A rigid slide of BOTH work points along the member's own axis: the reference line keeps its direction
|
|
1816
|
+
* and its length, and simply moves along itself.
|
|
1817
|
+
*
|
|
1818
|
+
* It is NOT frame-preserving to the bit — the caller quantises each endpoint independently, which perturbs
|
|
1819
|
+
* the direction by ~1e-9 — so a commit must assert that `partFrame`'s BRANCH is stable, never that the
|
|
1820
|
+
* frame is unchanged. Near the degeneracy cone that perturbation can move a member OUT of the seeded
|
|
1821
|
+
* branch as easily as into it, and leaving the cone rebuilds a different section frame than the rigid
|
|
1822
|
+
* preview showed.
|
|
1823
|
+
*
|
|
1824
|
+
* @returns {{from:number[], to:number[]}|null} null on a non-finite input or a zero-length axis.
|
|
1825
|
+
*/
|
|
1826
|
+
export function slideEndpoints(from0, to0, xAxis, deltaMm) {
|
|
1827
|
+
if (!finiteVec3(from0) || !finiteVec3(to0) || !finiteVec3(xAxis)) return null;
|
|
1828
|
+
if (typeof deltaMm !== 'number' || !isFinite(deltaMm)) return null;
|
|
1829
|
+
const l = len3(xAxis);
|
|
1830
|
+
if (!(l > 0)) return null;
|
|
1831
|
+
const d = [(xAxis[0] / l) * deltaMm, (xAxis[1] / l) * deltaMm, (xAxis[2] / l) * deltaMm];
|
|
1832
|
+
return {
|
|
1833
|
+
from: [from0[0] + d[0], from0[1] + d[1], from0[2] + d[2]],
|
|
1834
|
+
to: [to0[0] + d[0], to0[1] + d[1], to0[2] + d[2]],
|
|
1835
|
+
};
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
/**
|
|
1839
|
+
* The right-handed in-plane basis a swing measures its angle in: `e1` is the drag-start radius with the
|
|
1840
|
+
* rotation axis projected out, `e2 = axis x e1`, so `e1 x e2 = axis`. Measuring `atan2(d.e2, d.e1)` in THIS
|
|
1841
|
+
* basis gives the same sign from either side of the screen — which a screen-pixel delta cannot — and it is
|
|
1842
|
+
* the same basis the arc is DRAWN in, so the lobe the user grabs sweeps the way they expect.
|
|
1843
|
+
*
|
|
1844
|
+
* null when the radius is parallel to the axis: there is no swing plane, and the handle must be refused
|
|
1845
|
+
* rather than drawn inert.
|
|
1846
|
+
*/
|
|
1847
|
+
export function swingBasis(from, to0, axis) {
|
|
1848
|
+
if (!finiteVec3(from) || !finiteVec3(to0) || !finiteVec3(axis)) return null;
|
|
1849
|
+
const al = len3(axis);
|
|
1850
|
+
if (!(al > 0)) return null;
|
|
1851
|
+
const A = [axis[0] / al, axis[1] / al, axis[2] / al];
|
|
1852
|
+
const r = [to0[0] - from[0], to0[1] - from[1], to0[2] - from[2]];
|
|
1853
|
+
const rl = len3(r);
|
|
1854
|
+
if (!(rl > 0)) return null;
|
|
1855
|
+
const p = dot3(r, A);
|
|
1856
|
+
const perp = [r[0] - p * A[0], r[1] - p * A[1], r[2] - p * A[2]];
|
|
1857
|
+
const pl = len3(perp);
|
|
1858
|
+
if (!(pl > FRAME_DEGENERATE * rl)) return null;
|
|
1859
|
+
const e1 = [perp[0] / pl, perp[1] / pl, perp[2] / pl];
|
|
1860
|
+
return { e1, e2: cross3(A, e1) };
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
/**
|
|
1864
|
+
* Rodrigues rotation of the FAR work point about `axis` through the anchor:
|
|
1865
|
+
* to(theta) = O + R(A,theta)(E0 - O). Always evaluated from the DRAG-START endpoint and the frozen axis,
|
|
1866
|
+
* never accumulated per tick — a per-tick composition drifts and makes the 5-degree snap chatter.
|
|
1867
|
+
*/
|
|
1868
|
+
export function swingEndpoint(from, to0, axis, theta) {
|
|
1869
|
+
if (!finiteVec3(from) || !finiteVec3(to0) || !finiteVec3(axis)) return null;
|
|
1870
|
+
if (typeof theta !== 'number' || !isFinite(theta)) return null;
|
|
1871
|
+
const al = len3(axis);
|
|
1872
|
+
if (!(al > 0)) return null;
|
|
1873
|
+
const A = [axis[0] / al, axis[1] / al, axis[2] / al];
|
|
1874
|
+
const r = [to0[0] - from[0], to0[1] - from[1], to0[2] - from[2]];
|
|
1875
|
+
const c = Math.cos(theta), s = Math.sin(theta), k = dot3(A, r) * (1 - c);
|
|
1876
|
+
const x = cross3(A, r);
|
|
1877
|
+
return [
|
|
1878
|
+
from[0] + r[0] * c + x[0] * s + A[0] * k,
|
|
1879
|
+
from[1] + r[1] * c + x[1] * s + A[1] * k,
|
|
1880
|
+
from[2] + r[2] * c + x[2] * s + A[2] * k,
|
|
1881
|
+
];
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
/**
|
|
1885
|
+
* The two angles at which an elevation swing would drive the member through plumb — the signed pair
|
|
1886
|
+
* `{negative, positive}`, already backed off by the degeneracy cone and `marginRad`, in radians.
|
|
1887
|
+
*
|
|
1888
|
+
* WHY NOT SAMPLED. `partFrame` calls a frame degenerate at `qSq <= FRAME_DEGENERATE_SQ * dSq`, a half-cone
|
|
1889
|
+
* of 0.0573 degrees — far too thin to find by probing (a 1-degree walk steps over it 17 times).
|
|
1890
|
+
*
|
|
1891
|
+
* WHY IT IS EXACT. With the rotation axis perpendicular to `up` AND to the member radius — which is
|
|
1892
|
+
* precisely `partFrame`'s ordinary branch — the projection of the swept direction onto the plane
|
|
1893
|
+
* perpendicular to `up` stays COLLINEAR with one fixed vector. The whole question then reduces to one
|
|
1894
|
+
* sinusoid, s(theta) = R*cos(theta - phi), whose two roots are phi +/- pi/2. No bisection, no sampling.
|
|
1895
|
+
*
|
|
1896
|
+
* WHY A PAIR. Those roots are ASYMMETRIC about zero whenever phi is nonzero, i.e. for any sloped member —
|
|
1897
|
+
* measured -81 and +99 degrees on the test beam, not +/-90. The drag angle is signed and the pointer can
|
|
1898
|
+
* reverse mid-gesture and cross back through zero, so a single cached barrier would apply the positive
|
|
1899
|
+
* limit to a negative sweep. Cache the pair once per drag; every tick is then an O(1) comparison.
|
|
1900
|
+
*
|
|
1901
|
+
* Returns null when the premise does not hold (the axis is not perpendicular to `up`, or not perpendicular
|
|
1902
|
+
* to the member). The caller must then REFUSE the swing rather than clamp it on a formula that does not
|
|
1903
|
+
* apply — which is exactly why the swing handles are unavailable on a degenerate start frame, where
|
|
1904
|
+
* `yAxis` is seeded from `upX` and need not be perpendicular to `up`.
|
|
1905
|
+
*/
|
|
1906
|
+
export function swingBarriers(from, to0, axis, up, marginRad = 0) {
|
|
1907
|
+
if (!finiteVec3(from) || !finiteVec3(to0) || !finiteVec3(axis) || !finiteVec3(up)) return null;
|
|
1908
|
+
const al = len3(axis), ul = len3(up);
|
|
1909
|
+
if (!(al > 0) || !(ul > 0)) return null;
|
|
1910
|
+
const A = [axis[0] / al, axis[1] / al, axis[2] / al];
|
|
1911
|
+
const u = [up[0] / ul, up[1] / ul, up[2] / ul];
|
|
1912
|
+
const r = [to0[0] - from[0], to0[1] - from[1], to0[2] - from[2]];
|
|
1913
|
+
const rl = len3(r);
|
|
1914
|
+
if (!(rl > 0)) return null;
|
|
1915
|
+
if (Math.abs(dot3(A, u)) > 1e-9) return null; // axis must lie in the plane perp to up
|
|
1916
|
+
if (Math.abs(dot3(r, A)) > FRAME_DEGENERATE * rl) return null; // and be perpendicular to the member
|
|
1917
|
+
const P = (v) => { const d = dot3(v, u); return [v[0] - d * u[0], v[1] - d * u[1], v[2] - d * u[2]]; };
|
|
1918
|
+
const p0 = P(r), p0l = len3(p0);
|
|
1919
|
+
if (!(p0l > 0)) return null; // already plumb — nothing to swing from
|
|
1920
|
+
const w = [p0[0] / p0l, p0[1] / p0l, p0[2] / p0l];
|
|
1921
|
+
const alpha = dot3(P(r), w); // s(0), positive by construction
|
|
1922
|
+
const beta = dot3(P(cross3(A, r)), w);
|
|
1923
|
+
const R = Math.hypot(alpha, beta);
|
|
1924
|
+
if (!(R > 0)) return null;
|
|
1925
|
+
const phi = Math.atan2(beta, alpha);
|
|
1926
|
+
const half = Math.asin(Math.min(1, (FRAME_DEGENERATE * rl) / R)); // cone half-width, in theta
|
|
1927
|
+
return {
|
|
1928
|
+
positive: (phi + Math.PI / 2) - half - marginRad,
|
|
1929
|
+
negative: (phi - Math.PI / 2) + half + marginRad,
|
|
1930
|
+
};
|
|
1931
|
+
}
|
|
1932
|
+
|
|
1933
|
+
/**
|
|
1934
|
+
* Clamp a requested swing angle against the barrier pair, in the mode matching how the value was ENTERED.
|
|
1935
|
+
* Returning one snapped step for all three inputs would silently break Shift-free dragging (continuous by
|
|
1936
|
+
* definition) and typed entry (exact by definition).
|
|
1937
|
+
*
|
|
1938
|
+
* 'snapped' — the last whole snap step still inside the barrier
|
|
1939
|
+
* 'free' — the barrier itself, a smooth stop for a smooth drag
|
|
1940
|
+
* 'typed' — REFUSED (null). Bypassing the snap, which is the shipped typed-entry contract, was never a
|
|
1941
|
+
* licence to bypass geometric validity; the caller keeps its HUD open and says nothing was
|
|
1942
|
+
* committed, rather than silently rewriting the exact value the user asked for.
|
|
1943
|
+
*
|
|
1944
|
+
* Because the barrier already sits short of the cone, a request that merely STOPS INSIDE the cone without
|
|
1945
|
+
* crossing the root is clamped too — that case has no sign change, and a sign-flip-only test would have
|
|
1946
|
+
* accepted a degenerate endpoint.
|
|
1947
|
+
*
|
|
1948
|
+
* @returns {{theta:number, clamped:boolean}|null}
|
|
1949
|
+
*/
|
|
1950
|
+
/**
|
|
1951
|
+
* The extra back-off past the degeneracy cone that a swing barrier carries. ONE constant, because the
|
|
1952
|
+
* drag path and the typed path must agree about what is geometrically legal: if they drift, the symptom
|
|
1953
|
+
* is "the drag let me do it but typing the same number is refused", which reads as a bug in the HUD.
|
|
1954
|
+
*/
|
|
1955
|
+
export const POSITION_SWING_MARGIN_RAD = Math.PI / 180;
|
|
1956
|
+
|
|
1957
|
+
/**
|
|
1958
|
+
* Does this member have at least one snap step of swing travel on BOTH sides of its current heading?
|
|
1959
|
+
*
|
|
1960
|
+
* A member already within the cone-plus-margin of plumb has a barrier pair that does not bracket zero, so
|
|
1961
|
+
* there is no legal swing in one direction at all. Drawing the handle there gives the detailer a grip that
|
|
1962
|
+
* refuses every drag; the honest answer is not to offer it, with a reason they can read.
|
|
1963
|
+
*/
|
|
1964
|
+
export function swingHasTravel(barriers, snapRad) {
|
|
1965
|
+
if (!barriers) return false;
|
|
1966
|
+
const step = typeof snapRad === 'number' && snapRad > 0 ? snapRad : 0;
|
|
1967
|
+
return barriers.positive >= step && barriers.negative <= -step;
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
export function clampSwingTheta(thetaReq, barriers, mode, snapRad) {
|
|
1971
|
+
if (typeof thetaReq !== 'number' || !isFinite(thetaReq)) return null;
|
|
1972
|
+
if (!barriers) return null;
|
|
1973
|
+
const cap = Math.max(-Math.PI, Math.min(Math.PI, thetaReq)); // also bounds a typed/unwrapped sweep
|
|
1974
|
+
const limit = cap >= 0 ? barriers.positive : barriers.negative;
|
|
1975
|
+
if (!(typeof limit === 'number' && isFinite(limit))) return null;
|
|
1976
|
+
// THE BARRIER PAIR NEED NOT BRACKET ZERO. Each barrier is a plumb root backed off by the cone half-width
|
|
1977
|
+
// plus the margin, so on a member that already sits within that back-off of plumb the "negative" barrier
|
|
1978
|
+
// lands on the POSITIVE side (measured: a member 0.2 deg off plumb yields +178.743 / +0.857). Clamping to
|
|
1979
|
+
// it would then hand back a limit signed OPPOSITE to the drag — the member swings the way the hand did
|
|
1980
|
+
// not, by about a degree, with a real write and a real undo entry behind it. There is simply no valid
|
|
1981
|
+
// travel in that direction, so say so rather than substitute a number: every mode refuses, and the caller
|
|
1982
|
+
// reports it. Found by two independent reviewers and reproduced before fixing.
|
|
1983
|
+
if (cap !== 0 && Math.sign(limit) !== Math.sign(cap)) return null;
|
|
1984
|
+
if (cap >= 0 ? cap <= limit : cap >= limit) return { theta: cap, clamped: false };
|
|
1985
|
+
if (mode === 'typed') return null;
|
|
1986
|
+
if (mode === 'free') return { theta: limit, clamped: true };
|
|
1987
|
+
const step = typeof snapRad === 'number' && snapRad > 0 ? snapRad : 0;
|
|
1988
|
+
if (!step) return { theta: limit, clamped: true };
|
|
1989
|
+
const steps = Math.floor(Math.abs(limit) / step);
|
|
1990
|
+
return { theta: Math.sign(limit) * steps * step, clamped: true };
|
|
1991
|
+
}
|