@floless/app 0.130.1 → 0.131.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.
- package/dist/floless-server.cjs +71 -222
- package/dist/web/reference-changes.js +224 -0
- package/dist/web/reference-session.js +141 -0
- package/dist/web/steel-3d-view.js +205 -3
- package/dist/web/steel-editor.html +1982 -201
- package/dist/web/steel-split-view.js +169 -0
- package/package.json +1 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the steel editor's canvas view modes (F10a — the 2D/3D split).
|
|
3
|
+
*
|
|
4
|
+
* This module deliberately owns no DOM, no Three.js and no localStorage. steel-editor.html owns the
|
|
5
|
+
* elements, the persistence and the wiring; steel-3d-view.js owns the camera. Everything here is a
|
|
6
|
+
* total function over plain values, so the layout rules that decide what is on screen can be tested
|
|
7
|
+
* off-browser — the same split `steel-view-generation.js` makes for generated views.
|
|
8
|
+
*
|
|
9
|
+
* Design: docs/superpowers/specs/2026-08-15-steel-2d-3d-split-view-design.md
|
|
10
|
+
* Plan: docs/superpowers/plans/2026-08-15-steel-2d-3d-split-view.md
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/** The closed set of canvas modes. `split` shows both panes; the other two show exactly one. */
|
|
14
|
+
export const VIEW_MODES = ['2d', '3d', 'split'];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The narrowest a pane may be, in CSS px.
|
|
18
|
+
*
|
|
19
|
+
* NOT a round number picked for looks. The floating Objects/Views/Favourites panel (#m3dLegend) is
|
|
20
|
+
* `min-width:210px` anchored at `left:12px` inside its pane, so anything under 222px would push that
|
|
21
|
+
* panel out through the pane's own edge. 280 leaves the panel room to breathe and gives the 2D pane
|
|
22
|
+
* (which takes the same floor for symmetry) enough width to be worth looking at.
|
|
23
|
+
*/
|
|
24
|
+
export const MIN_PANE_PX = 280;
|
|
25
|
+
|
|
26
|
+
/** The divider's width in CSS px — mirrors #panelResizer, whose recipe #splitBar reuses. */
|
|
27
|
+
export const DIVIDER_PX = 7;
|
|
28
|
+
|
|
29
|
+
/** The 2D pane's share of the usable width may not leave either side below MIN_PANE_PX; these are the
|
|
30
|
+
* absolute rails, applied even when the stage width is unknown. */
|
|
31
|
+
const RATIO_MIN = 0.15, RATIO_MAX = 0.85, RATIO_DEFAULT = 0.5;
|
|
32
|
+
|
|
33
|
+
const finite = (n) => typeof n === 'number' && Number.isFinite(n);
|
|
34
|
+
|
|
35
|
+
/** Coerce a persisted or caller-supplied mode to a legal one. Anything unrecognised is '2d' — a mode
|
|
36
|
+
* the editor can always render, so a stale localStorage value can never strand it. */
|
|
37
|
+
export function sanitizeMode(mode) {
|
|
38
|
+
return VIEW_MODES.includes(mode) ? mode : '2d';
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Coerce a persisted ratio to the legal band. A non-number is a half, not an error. */
|
|
42
|
+
export function sanitizeRatio(ratio) {
|
|
43
|
+
if (!finite(ratio)) return RATIO_DEFAULT;
|
|
44
|
+
return Math.min(RATIO_MAX, Math.max(RATIO_MIN, ratio));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* The one sentence a refused split says out loud. Kept here rather than in the editor because the
|
|
49
|
+
* refusal is a property of the layout rule, and a test that asserts the rule should be able to assert
|
|
50
|
+
* the words the user actually reads.
|
|
51
|
+
*/
|
|
52
|
+
const TOO_NARROW = 'Not enough room to split — widen the window or collapse the Inspector.';
|
|
53
|
+
|
|
54
|
+
/** Can this stage hold two minimum-width panes and the divider between them? */
|
|
55
|
+
export function canSplit(stageWidthPx) {
|
|
56
|
+
if (!finite(stageWidthPx) || stageWidthPx < MIN_PANE_PX * 2 + DIVIDER_PX) {
|
|
57
|
+
return { ok: false, reason: TOO_NARROW };
|
|
58
|
+
}
|
|
59
|
+
return { ok: true, reason: null };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Clamp the 2D pane's share of the usable width so neither pane falls below MIN_PANE_PX.
|
|
64
|
+
*
|
|
65
|
+
* `ratio` is a fraction of the USABLE width (the stage minus the divider), not of the stage — so the
|
|
66
|
+
* divider never silently eats one pane's minimum as the window shrinks.
|
|
67
|
+
*
|
|
68
|
+
* Always returns a finite ratio, even when `ok` is false: a caller that renders before checking must
|
|
69
|
+
* produce a wrong layout, never a NaN one.
|
|
70
|
+
*/
|
|
71
|
+
export function clampRatio(ratio, stageWidthPx) {
|
|
72
|
+
const safe = sanitizeRatio(ratio);
|
|
73
|
+
const room = canSplit(stageWidthPx);
|
|
74
|
+
if (!room.ok) return { ratio: safe, ok: false, reason: room.reason };
|
|
75
|
+
const usable = stageWidthPx - DIVIDER_PX;
|
|
76
|
+
const min = MIN_PANE_PX / usable;
|
|
77
|
+
return { ratio: Math.min(1 - min, Math.max(min, safe)), ok: true, reason: null };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Resolve the mode the editor may actually enter. A `split` the stage cannot hold becomes '2d' and
|
|
82
|
+
* carries the reason, so the caller can both render something legal and say why it is not what was
|
|
83
|
+
* asked for. This is the reload path: a saved 'split' meeting a window that has since narrowed.
|
|
84
|
+
*/
|
|
85
|
+
export function resolveMode(requested, stageWidthPx) {
|
|
86
|
+
const mode = sanitizeMode(requested);
|
|
87
|
+
if (mode !== 'split') return { mode, reason: null };
|
|
88
|
+
const room = canSplit(stageWidthPx);
|
|
89
|
+
return room.ok ? { mode: 'split', reason: null } : { mode: '2d', reason: room.reason };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** Which canvases are on screen in this mode. */
|
|
93
|
+
export function panesShown(mode) {
|
|
94
|
+
const m = sanitizeMode(mode);
|
|
95
|
+
return { two: m !== '3d', three: m !== '2d' };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Which pane owns the TOOLS. Not which pane is on screen — that is `panesShown`, and the two are
|
|
100
|
+
* different questions the moment a split exists. `view3d` is derived from this one and means "3D is
|
|
101
|
+
* where I am acting"; `view3dShown` is derived from `panesShown` and means "the 3D canvas is visible".
|
|
102
|
+
* Sites that confuse them are enumerated and fixed in the plan's Task 9.
|
|
103
|
+
*
|
|
104
|
+
* In a single mode this is FORCED, and that is load-bearing: with only one canvas up, the pane that
|
|
105
|
+
* owns the tools and the pane on screen are necessarily the same, and letting them disagree would make
|
|
106
|
+
* every `view3d` branch lie.
|
|
107
|
+
*/
|
|
108
|
+
export function resolveActivePane(mode, requested) {
|
|
109
|
+
const m = sanitizeMode(mode);
|
|
110
|
+
if (m === '2d') return '2d';
|
|
111
|
+
if (m === '3d') return '3d';
|
|
112
|
+
return requested === '3d' ? '3d' : '2d';
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Which chrome groups are on screen.
|
|
117
|
+
*
|
|
118
|
+
* THE RULE, in one sentence: a control shows when the pane it addresses is on screen; where two
|
|
119
|
+
* controls do the same job in different panes, only the ACTIVE pane's is shown.
|
|
120
|
+
*
|
|
121
|
+
* The second half is what keeps a dead control off screen. `#dimB` and `#dim3dWrap` both arm a
|
|
122
|
+
* Dimension tool; showing both with one inert is the disabled-not-hidden failure the project's
|
|
123
|
+
* standing UX rule exists to catch.
|
|
124
|
+
*
|
|
125
|
+
* Re-resolves the active pane rather than trusting the caller's, so a caller that forgets cannot hide
|
|
126
|
+
* the 2D Dimension button over a 2D-only canvas.
|
|
127
|
+
*/
|
|
128
|
+
export function chromeVisibility({ mode, activePane } = {}) {
|
|
129
|
+
const m = sanitizeMode(mode);
|
|
130
|
+
const active = resolveActivePane(m, activePane);
|
|
131
|
+
const panes = panesShown(m);
|
|
132
|
+
return {
|
|
133
|
+
zoombar: panes.two, // 2D zoom slider — addresses the plan canvas
|
|
134
|
+
planCombo: panes.two, // plan switcher — chooses what the plan canvas shows
|
|
135
|
+
m3dChrome: panes.three, // #m3dBar, #m3dCube, #m3dAxes, #m3dLegend — painted over the 3D canvas
|
|
136
|
+
dim2d: active === '2d', // #dimB
|
|
137
|
+
dim3d: active === '3d', // #dim3dWrap
|
|
138
|
+
v3d: active === '3d', // body.v3d — gates 3D-only menu rows; follows view3d, unchanged
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* What a mode change has to DO, as data.
|
|
144
|
+
*
|
|
145
|
+
* Named separately from `panesShown` because "is this pane on screen" and "did this pane just arrive"
|
|
146
|
+
* are different questions, and only the second one may spend a camera fit. The rule that matters:
|
|
147
|
+
* a pane is fitted when it BECOMES visible, never when it merely stays visible — re-fitting a 3D view
|
|
148
|
+
* the user had already framed is the most annoying thing a view switch can do.
|
|
149
|
+
*
|
|
150
|
+
* THERE IS NO `fit2d`, and its absence is a decision. The plan originally carried one, paired with
|
|
151
|
+
* `show2d`. Writing the tests killed it: `3d → 2d` reveals the plan pane just as `3d → split` does, so
|
|
152
|
+
* a symmetric `fit2d` would have re-fitted the plan on every return from 3D — silently throwing away a
|
|
153
|
+
* zoom that survives that round trip today. The 2D pane is laid out once by `setPlan` and keeps its
|
|
154
|
+
* viewBox; a narrower pane simply shows less of it, exactly as it does while the divider is dragged.
|
|
155
|
+
* So `show2d` drives a `render()` and nothing else, and Home/Fit stays the user's to press.
|
|
156
|
+
*
|
|
157
|
+
* `hide3d` maps to Steel3DView.hide(), which is real teardown (disarms the dim tool, clip pick, insert
|
|
158
|
+
* mode, work-plane pick, frame manipulator and any Tekla drag-out, hides the label hosts, stops the rAF
|
|
159
|
+
* loop) — so it must fire on split→2d exactly as it does on 3d→2d.
|
|
160
|
+
*/
|
|
161
|
+
export function nextMode(from, to) {
|
|
162
|
+
const a = panesShown(sanitizeMode(from)), b = panesShown(sanitizeMode(to));
|
|
163
|
+
return {
|
|
164
|
+
show3d: !a.three && b.three,
|
|
165
|
+
hide3d: a.three && !b.three,
|
|
166
|
+
fit3d: !a.three && b.three,
|
|
167
|
+
show2d: !a.two && b.two,
|
|
168
|
+
};
|
|
169
|
+
}
|