@floless/app 0.116.0 → 0.117.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.
@@ -0,0 +1,170 @@
1
+ /*
2
+ * The steel.model/v2 read boundary for the legacy-shaped editor canvas.
3
+ *
4
+ * Stored geometry stays model-global and in world mm. This module builds a detached plan-shaped view in
5
+ * display pixels, records why each member is present on that sheet, and patches member rows by stable id.
6
+ * It never mutates the model. The activation switch lives in steel-editor.html; importing this module is
7
+ * therefore inert.
8
+ */
9
+
10
+ import { sheetIncludesElevation } from './steel-3d-core.js';
11
+ import { worldToSheetPx } from './steel-plan-transform.js';
12
+
13
+ const IN_MM = 25.4;
14
+ export const V2_PROJECTION_LINK = Symbol.for('floless.steelModelV2ProjectionLink');
15
+
16
+ const clone = (v) => v == null ? v : (typeof structuredClone === 'function'
17
+ ? structuredClone(v)
18
+ : JSON.parse(JSON.stringify(v)));
19
+ const knownIn = (z) => z && Number.isFinite(z.known) ? z.known / IN_MM : null;
20
+
21
+ function link(value, data) {
22
+ if (value && typeof value === 'object') {
23
+ Object.defineProperty(value, V2_PROJECTION_LINK, { value: data, enumerable: false, configurable: true });
24
+ }
25
+ return value;
26
+ }
27
+
28
+ function observationIds(plan) {
29
+ const ids = new Set();
30
+ for (const obs of plan.memberObservations || []) {
31
+ if (obs?.binding?.status !== 'active') continue;
32
+ for (const id of obs.binding.memberIds || []) ids.add(id);
33
+ }
34
+ return ids;
35
+ }
36
+
37
+ /** The three-source membersOnSheet rule, kept byte-for-byte equivalent to the server projection. */
38
+ export function memberPresence(model, plan, member) {
39
+ const observed = observationIds(plan).has(member.id);
40
+ const explicit = (plan.memberRefs || []).includes(member.id);
41
+ const cutMm = Number.isFinite(plan.elevation_in) ? plan.elevation_in * IN_MM : null;
42
+ const crossing = cutMm !== null && member.role === 'column'
43
+ && sheetIncludesElevation(member.from?.z, member.to?.z, cutMm);
44
+ return { observed, explicit, crossing, visible: observed || explicit || crossing };
45
+ }
46
+
47
+ export function memberSheets(model, memberId) {
48
+ const member = (model.members || []).find((m) => m?.id === memberId);
49
+ if (!member) return [];
50
+ return (model.plans || []).filter((p) => memberPresence(model, p, member).visible).map((p) => p.sheet);
51
+ }
52
+
53
+ function projectGrid(modelGrid, plan) {
54
+ if (!modelGrid) return null;
55
+ const out = clone(modelGrid);
56
+ const wp = (xy) => worldToSheetPx({ x: xy[0], y: xy[1], z: { unknown: true } }, {
57
+ ...plan, modelGrid,
58
+ });
59
+ if (Array.isArray(modelGrid.origin)) out.origin = wp(modelGrid.origin);
60
+ if (Array.isArray(modelGrid.lines)) {
61
+ out.lines = modelGrid.lines.map((line) => ({
62
+ ...clone(line),
63
+ a: wp(line.a),
64
+ b: wp(line.b),
65
+ }));
66
+ }
67
+ return out;
68
+ }
69
+
70
+ /** One canonical member mapped into exactly the v1 vocabulary the canvas already consumes. */
71
+ export function projectMember(member, plan, session = null) {
72
+ const a = worldToSheetPx(member.from, plan);
73
+ const b = worldToSheetPx(member.to, plan);
74
+ const meta = {
75
+ id: member.id,
76
+ profile: member.profile,
77
+ role: member.role || 'beam',
78
+ provenance: member.provenance,
79
+ };
80
+ for (const key of ['material', 'memberType', 'position', 'rot', 'section', 'bf', 'rfi', 'mf', 'verified', 'source', 'brace']) {
81
+ if (member[key] !== undefined) meta[key] = clone(member[key]);
82
+ }
83
+ const endMeta = Array.isArray(member.ends) ? member.ends : [{}, {}];
84
+ const ends = [0, 1].map((i) => ({
85
+ ...clone(endMeta[i] || {}),
86
+ tos: knownIn(i === 0 ? member.from.z : member.to.z),
87
+ tosDef: false,
88
+ }));
89
+ const projected = {
90
+ ...meta,
91
+ wp: [a, b],
92
+ ends,
93
+ col: {
94
+ bos: knownIn(member.from.z),
95
+ tos: knownIn(member.to.z),
96
+ tosDef: false,
97
+ note: endMeta[1]?.note || '',
98
+ detail: endMeta[1]?.detail || '',
99
+ conn: endMeta[1]?.conn,
100
+ connVerified: endMeta[1]?.connVerified,
101
+ },
102
+ };
103
+ const base = { session, kind: 'member', memberId: member.id, sheet: plan.sheet };
104
+ link(projected, base);
105
+ link(projected.ends[0], { ...base, kind: 'end', end: 0 });
106
+ link(projected.ends[1], { ...base, kind: 'end', end: 1 });
107
+ link(projected.col, { ...base, kind: 'column' });
108
+ if (projected.brace) link(projected.brace, { ...base, kind: 'brace' });
109
+ return projected;
110
+ }
111
+
112
+ /** @param {any} model @param {string} sheet @param {{session?: any}} options */
113
+ export function createV2Projection(model, sheet, options = {}) {
114
+ const { session = null } = options;
115
+ const plan = (model.plans || []).find((p) => p?.sheet === sheet);
116
+ if (!plan) throw new Error(`steel.model/v2 has no plan "${sheet}"`);
117
+ const projection = {
118
+ ...clone(plan),
119
+ modelGrid: clone(model.grid || null),
120
+ };
121
+ for (const key of ['segments', 'labels', 'details', 'callouts', 'tos_callouts', 'dims']) {
122
+ if (!Array.isArray(projection[key])) projection[key] = [];
123
+ }
124
+ projection.default_tos = Number.isFinite(plan.elevation_in) ? plan.elevation_in : 0;
125
+ projection.grid = projectGrid(model.grid || null, projection);
126
+ const visible = (model.members || []).filter((m) => memberPresence(model, plan, m).visible);
127
+ projection.members = visible.map((m) => projectMember(m, projection, session));
128
+ link(projection, { session, kind: 'plan', sheet });
129
+ if (projection.grid) {
130
+ link(projection.grid, { session, kind: 'grid', sheet });
131
+ for (const line of projection.grid.lines || []) link(line, {
132
+ session, kind: 'grid-line', sheet, gridLineId: line.id,
133
+ });
134
+ }
135
+
136
+ let rebuildCount = 1;
137
+ let patchCount = 0;
138
+ const controller = {
139
+ model,
140
+ sheet,
141
+ plan: projection,
142
+ get rebuildCount() { return rebuildCount; },
143
+ get patchCount() { return patchCount; },
144
+ patchMembers(ids) {
145
+ const wanted = ids instanceof Set ? ids : new Set(ids || []);
146
+ const canonical = new Map((model.members || []).map((m) => [m.id, m]));
147
+ for (let i = 0; i < projection.members.length; i += 1) {
148
+ const id = projection.members[i]?.id;
149
+ if (!wanted.has(id)) continue;
150
+ const member = canonical.get(id);
151
+ if (member) projection.members[i] = projectMember(member, projection, session);
152
+ }
153
+ patchCount += wanted.size;
154
+ return projection;
155
+ },
156
+ rebuild() {
157
+ const fresh = createV2Projection(model, sheet, { session });
158
+ for (const key of Object.keys(projection)) delete projection[key];
159
+ Object.assign(projection, fresh.plan);
160
+ link(projection, { session, kind: 'plan', sheet });
161
+ rebuildCount += 1;
162
+ return projection;
163
+ },
164
+ };
165
+ return controller;
166
+ }
167
+
168
+ export function projectionLink(value) {
169
+ return value && typeof value === 'object' ? value[V2_PROJECTION_LINK] || null : null;
170
+ }
@@ -0,0 +1,151 @@
1
+ /*
2
+ * steel-plan-transform.js — the reversible steel.model/v2 plan-view coordinate boundary.
3
+ *
4
+ * Canonical member work points are world mm with Y up. The editor draws one sheet in display px with
5
+ * Y down. A plan's two authored controls bind those spaces; the model grid resolves each labelled
6
+ * control to a world point. Nothing here infers a view kind or substitutes missing registration data.
7
+ */
8
+
9
+ import { parseSpacings, labelsFor } from './grid-core.js';
10
+
11
+ const FT_MM = 304.8;
12
+ const ROUND = 1e9;
13
+ const clean = (n) => {
14
+ const q = Math.round(n * ROUND) / ROUND;
15
+ return Object.is(q, -0) ? 0 : q;
16
+ };
17
+ const finite2 = (p) => Array.isArray(p) && p.length === 2 && p.every(Number.isFinite);
18
+
19
+ export class PlanTransformError extends Error {
20
+ constructor(code, message, viewKind = null) {
21
+ super(message);
22
+ this.name = 'PlanTransformError';
23
+ this.code = code;
24
+ this.viewKind = viewKind;
25
+ }
26
+ }
27
+
28
+ const refuse = (code, message, plan) => {
29
+ throw new PlanTransformError(code, message, plan && plan.viewKind);
30
+ };
31
+
32
+ /**
33
+ * Resolve one labelled model-grid intersection. Labels are evidence, not identity, so a duplicate is
34
+ * ambiguous and refuses instead of quietly selecting the first matching axis.
35
+ */
36
+ function gridIntersection(grid, ref, plan) {
37
+ if (!grid || typeof grid !== 'object' || !finite2(grid.origin)) {
38
+ return refuse('grid-unavailable', `sheet "${plan.sheet || '?'}" has no model grid to resolve its registration controls`, plan);
39
+ }
40
+ if (!ref || typeof ref !== 'object' || typeof ref.axis_x !== 'string' || typeof ref.axis_y !== 'string') {
41
+ return refuse('control-ref-invalid', `sheet "${plan.sheet || '?'}" has an unreadable registration control`, plan);
42
+ }
43
+
44
+ const X = parseSpacings(grid.x), Y = parseSpacings(grid.y);
45
+ if (X.err || Y.err) {
46
+ return refuse('grid-spacing-invalid', `sheet "${plan.sheet || '?'}" cannot use an invalid model-grid spacing string`, plan);
47
+ }
48
+ const axes = Array.isArray(grid.axes) ? grid.axes : [];
49
+ const axisLabels = (dir, fallback, n) => {
50
+ const rows = axes.filter((a) => a && a.dir === dir);
51
+ return rows.length === n ? rows.map((a, i) => String(a.label || fallback[i] || '')) : fallback;
52
+ };
53
+ const xs = axisLabels('x', labelsFor(grid.labels_x, 'num', X.offsets.length), X.offsets.length);
54
+ const ys = axisLabels('y', labelsFor(grid.labels_y, 'alpha', Y.offsets.length), Y.offsets.length);
55
+ const uniqueIndex = (labels, wanted) => {
56
+ const hits = labels.map((label, i) => label === wanted ? i : -1).filter((i) => i >= 0);
57
+ return hits.length === 1 ? hits[0] : -1;
58
+ };
59
+ const xi = uniqueIndex(xs, ref.axis_x), yi = uniqueIndex(ys, ref.axis_y);
60
+ if (xi < 0 || yi < 0) {
61
+ return refuse(
62
+ 'control-ref-unresolved',
63
+ `sheet "${plan.sheet || '?'}" registration control ${ref.axis_x}/${ref.axis_y} does not resolve uniquely on the model grid`,
64
+ plan,
65
+ );
66
+ }
67
+ return [grid.origin[0] + X.offsets[xi], grid.origin[1] + Y.offsets[yi]];
68
+ }
69
+
70
+ /**
71
+ * Build the px↔world similarity for one plan-shaped editor projection.
72
+ *
73
+ * `plan.grid` is the model grid exposed through the projection (canonical ModelPlan intentionally has
74
+ * no grid property). `datum_ref` may be absent only for the explicit "datum_at is world origin" case.
75
+ */
76
+ export function planTransform(plan) {
77
+ const kind = plan && plan.viewKind;
78
+ if (kind !== 'plan') {
79
+ const named = typeof kind === 'string' ? kind : 'unknown';
80
+ return refuse(
81
+ 'view-kind-unsupported',
82
+ `sheet "${plan && plan.sheet || '?'}" is a ${named} view; ${named} views are not supported by the plan transform`,
83
+ plan,
84
+ );
85
+ }
86
+ if (!finite2(plan.datum_at) || !finite2(plan.control2_at) || !plan.control2_ref) {
87
+ return refuse(
88
+ 'registration-incomplete',
89
+ `sheet "${plan.sheet || '?'}" needs two resolved registration controls before it can be edited`,
90
+ plan,
91
+ );
92
+ }
93
+ const ptPerFt = Number(plan.pt_per_ft);
94
+ if (!(ptPerFt > 0) || !Number.isFinite(ptPerFt)) {
95
+ return refuse('scale-invalid', `sheet "${plan.sheet || '?'}" has no positive drawing scale`, plan);
96
+ }
97
+
98
+ // Editor projections expose a display-space `grid` because grid-core draws in pixels. The canonical
99
+ // world grid rides beside it as `modelGrid`; standalone callers and stored-plan fixtures use `grid`.
100
+ const registrationGrid = plan.modelGrid || plan.grid;
101
+ const world0 = plan.datum_ref ? gridIntersection(registrationGrid, plan.datum_ref, plan) : [0, 0];
102
+ const world1 = gridIntersection(registrationGrid, plan.control2_ref, plan);
103
+ const mmPerPx = FT_MM / ptPerFt;
104
+ const local1 = [
105
+ (plan.control2_at[0] - plan.datum_at[0]) * mmPerPx,
106
+ (plan.datum_at[1] - plan.control2_at[1]) * mmPerPx,
107
+ ];
108
+ const worldDelta = [world1[0] - world0[0], world1[1] - world0[1]];
109
+ const localLen = Math.hypot(local1[0], local1[1]);
110
+ const worldLen = Math.hypot(worldDelta[0], worldDelta[1]);
111
+ if (!(localLen > 1e-9) || !(worldLen > 1e-9)) {
112
+ return refuse('registration-degenerate', `sheet "${plan.sheet || '?'}" has coincident registration controls`, plan);
113
+ }
114
+ const fitScale = worldLen / localLen;
115
+ const rotation = Math.atan2(worldDelta[1], worldDelta[0]) - Math.atan2(local1[1], local1[0]);
116
+ const c = Math.cos(rotation) * fitScale;
117
+ const s = Math.sin(rotation) * fitScale;
118
+ if (![c, s, fitScale, world0[0], world0[1]].every(Number.isFinite)) {
119
+ return refuse('registration-invalid', `sheet "${plan.sheet || '?'}" has a non-finite registration transform`, plan);
120
+ }
121
+ return { datumPx: plan.datum_at, world0, mmPerPx, fitScale, rotation, c, s };
122
+ }
123
+
124
+ /** Canonical world-mm work point → this plan's display px. */
125
+ export function worldToSheetPx(workPoint, plan) {
126
+ if (!workPoint || !Number.isFinite(workPoint.x) || !Number.isFinite(workPoint.y)) {
127
+ return refuse('work-point-invalid', 'a work point needs finite world x/y coordinates', plan);
128
+ }
129
+ const t = planTransform(plan);
130
+ const wx = workPoint.x - t.world0[0], wy = workPoint.y - t.world0[1];
131
+ const det = t.c * t.c + t.s * t.s;
132
+ const localX = (t.c * wx + t.s * wy) / det;
133
+ const localY = (-t.s * wx + t.c * wy) / det;
134
+ return [
135
+ clean(t.datumPx[0] + localX / t.mmPerPx),
136
+ clean(t.datumPx[1] - localY / t.mmPerPx),
137
+ ];
138
+ }
139
+
140
+ /** This plan's display px → canonical world-mm work point, retaining the endpoint's elevation union. */
141
+ export function sheetPxToWorld(point, plan, keepZ) {
142
+ if (!finite2(point)) return refuse('sheet-point-invalid', 'a sheet point needs two finite pixel coordinates', plan);
143
+ const t = planTransform(plan);
144
+ const localX = (point[0] - t.datumPx[0]) * t.mmPerPx;
145
+ const localY = (t.datumPx[1] - point[1]) * t.mmPerPx;
146
+ return {
147
+ x: clean(t.world0[0] + localX * t.c - localY * t.s),
148
+ y: clean(t.world0[1] + localX * t.s + localY * t.c),
149
+ z: keepZ,
150
+ };
151
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floless/app",
3
- "version": "0.116.0",
3
+ "version": "0.117.1",
4
4
  "type": "module",
5
5
  "description": "Thin localhost host for floless.app — serves web/ and shells the aware CLI. No engine, no LLM.",
6
6
  "bin": {
@@ -27,6 +27,7 @@
27
27
  "verify:skills": "node build/verify-shipped-skills.mjs",
28
28
  "verify:skill-versions": "node build/verify-skill-versions.mjs",
29
29
  "verify:flo": "node build/verify-flo-descriptions.mjs",
30
+ "verify:flo-naming": "node build/verify-flo-naming.mjs",
30
31
  "verify:no-title": "node build/verify-no-title.mjs",
31
32
  "verify:display-sync": "node build/verify-display-sync.mjs",
32
33
  "verify:view-modes": "node build/verify-view-modes.mjs",