@floless/app 0.135.0 → 0.135.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 +591 -122
- package/dist/schemas/steel.model.v2.schema.json +1 -1
- package/dist/web/aware-update-client.js +137 -25
- package/dist/web/aware.js +269 -28
- package/dist/web/commands-shell.js +35 -4
- package/dist/web/steel-plan-transform.js +74 -15
- package/package.json +1 -1
|
@@ -28,21 +28,70 @@ const refuse = (code, message, plan) => {
|
|
|
28
28
|
throw new PlanTransformError(code, message, plan && plan.viewKind);
|
|
29
29
|
};
|
|
30
30
|
|
|
31
|
+
/**
|
|
32
|
+
* Contract text quoted back into a refusal. `sheet` and the axis labels are schema-unbounded strings an
|
|
33
|
+
* author supplies, and these messages now travel further than the console — the read audit reports them
|
|
34
|
+
* and the request log keeps them (#925) — so a value is identified, never reproduced whole.
|
|
35
|
+
*/
|
|
36
|
+
const MAX_QUOTED_CHARS = 48;
|
|
37
|
+
// Built from a string so no literal control character sits in this source file.
|
|
38
|
+
const CONTROL_CHARS = new RegExp('[\\u0000-\\u001f\\u007f]', 'g');
|
|
39
|
+
// A surrogate that was ALREADY unpaired in the contract, not one this clip broke. Repaired either way:
|
|
40
|
+
// an audit report and a request log are not places to reproduce invalid text.
|
|
41
|
+
// LOOKBEHIND, not a consuming prefix group: `[^\ud800-\udbff][\udc00-\udfff]` eats the character before
|
|
42
|
+
// the low surrogate, so a global replace skips past the next one and `\udc00\udc01` repairs only half.
|
|
43
|
+
const LONE_SURROGATE = new RegExp('[\\ud800-\\udbff](?![\\udc00-\\udfff])|(?<![\\ud800-\\udbff])[\\udc00-\\udfff]', 'g');
|
|
44
|
+
const wellFormed = (text) => typeof text.toWellFormed === 'function'
|
|
45
|
+
? text.toWellFormed() : text.replace(LONE_SURROGATE, '�');
|
|
46
|
+
/**
|
|
47
|
+
* EXPORTED, and the server's diagnosis notes use this one rather than a mirror of it (#925). The audit
|
|
48
|
+
* side of this same change deletes a duplicated reason list on the grounds that two lists which must
|
|
49
|
+
* agree are one list waiting to disagree; two clips which must agree are the same thing, and the
|
|
50
|
+
* server module already imports from here.
|
|
51
|
+
*
|
|
52
|
+
* `max` may be shortened by a caller that has its own budget; a non-positive one yields the empty
|
|
53
|
+
* string rather than looping, so the bound-enforcing helper honours its own contract.
|
|
54
|
+
*/
|
|
55
|
+
export const clipQuoted = (value, max = MAX_QUOTED_CHARS) => {
|
|
56
|
+
const text = wellFormed(typeof value === 'string' && value ? value : '?').replace(CONTROL_CHARS, ' ');
|
|
57
|
+
if (max <= 0) return '';
|
|
58
|
+
if (text.length <= max) return text;
|
|
59
|
+
// Never cut a surrogate pair in half: a lone surrogate is not text, and this string is serialized
|
|
60
|
+
// into an audit report and a request log, not only shown in a console.
|
|
61
|
+
let end = max - 1;
|
|
62
|
+
const code = text.charCodeAt(end - 1);
|
|
63
|
+
if (end > 0 && code >= 0xd800 && code <= 0xdbff) end--;
|
|
64
|
+
return `${text.slice(0, end)}…`;
|
|
65
|
+
};
|
|
66
|
+
const quote = (value) => clipQuoted(value);
|
|
67
|
+
|
|
31
68
|
/**
|
|
32
69
|
* Resolve one labelled model-grid intersection. Labels are evidence, not identity, so a duplicate is
|
|
33
70
|
* ambiguous and refuses instead of quietly selecting the first matching axis.
|
|
34
71
|
*/
|
|
35
|
-
function gridIntersection(grid, ref, plan) {
|
|
36
|
-
if (!grid || typeof grid !== 'object'
|
|
37
|
-
return refuse('grid-unavailable', `sheet "${plan.sheet
|
|
72
|
+
function gridIntersection(grid, ref, plan, field) {
|
|
73
|
+
if (!grid || typeof grid !== 'object') {
|
|
74
|
+
return refuse('grid-unavailable', `sheet "${quote(plan.sheet)}" has no model grid to resolve its registration controls`, plan);
|
|
75
|
+
}
|
|
76
|
+
// A grid that carries axes, spacings and labels but no `origin` used to share the message above, and
|
|
77
|
+
// it sent authors back to the half they had already filled in (#925). `$.grid.origin` is optional in
|
|
78
|
+
// the schema and unmentioned by every other check, so its name has to be in the refusal or nothing
|
|
79
|
+
// says it. Same CODE deliberately: `_PLAN_XF_UNREGISTERED` in steel-editor.html classifies by code.
|
|
80
|
+
if (!finite2(grid.origin)) {
|
|
81
|
+
return refuse(
|
|
82
|
+
'grid-unavailable',
|
|
83
|
+
`sheet "${quote(plan.sheet)}" cannot resolve its registration controls: $.grid.origin is missing or unreadable — it must be two finite world-mm numbers giving where the first x and y grid axes cross`,
|
|
84
|
+
plan,
|
|
85
|
+
);
|
|
38
86
|
}
|
|
39
87
|
if (!ref || typeof ref !== 'object' || typeof ref.axis_x !== 'string' || typeof ref.axis_y !== 'string') {
|
|
40
|
-
return refuse('control-ref-invalid', `sheet "${plan.sheet
|
|
88
|
+
return refuse('control-ref-invalid', `sheet "${quote(plan.sheet)}" has an unreadable ${field}: a registration control needs string axis_x and axis_y labels`, plan);
|
|
41
89
|
}
|
|
42
90
|
|
|
43
91
|
const X = parseSpacings(grid.x), Y = parseSpacings(grid.y);
|
|
44
92
|
if (X.err || Y.err) {
|
|
45
|
-
|
|
93
|
+
const bad = X.err ? '$.grid.x' : '$.grid.y';
|
|
94
|
+
return refuse('grid-spacing-invalid', `sheet "${quote(plan.sheet)}" cannot use ${bad}: ${quote(X.err || Y.err)}`, plan);
|
|
46
95
|
}
|
|
47
96
|
// The SAME resolver the bubbles are drawn from, so a control ref matches the name on the sheet (#740).
|
|
48
97
|
const xs = axisLabelsFor(grid, 'x', 'num', X.offsets.length);
|
|
@@ -55,7 +104,7 @@ function gridIntersection(grid, ref, plan) {
|
|
|
55
104
|
if (xi < 0 || yi < 0) {
|
|
56
105
|
return refuse(
|
|
57
106
|
'control-ref-unresolved',
|
|
58
|
-
`sheet "${plan.sheet
|
|
107
|
+
`sheet "${quote(plan.sheet)}" ${field} names ${quote(ref.axis_x)}/${quote(ref.axis_y)}, which is not exactly one x and one y label on the model grid`,
|
|
59
108
|
plan,
|
|
60
109
|
);
|
|
61
110
|
}
|
|
@@ -71,30 +120,30 @@ function gridIntersection(grid, ref, plan) {
|
|
|
71
120
|
export function planTransform(plan) {
|
|
72
121
|
const kind = plan && plan.viewKind;
|
|
73
122
|
if (kind !== 'plan') {
|
|
74
|
-
const named = typeof kind === 'string' ? kind : 'unknown';
|
|
123
|
+
const named = typeof kind === 'string' && kind ? quote(kind) : 'unknown';
|
|
75
124
|
return refuse(
|
|
76
125
|
'view-kind-unsupported',
|
|
77
|
-
`sheet "${plan && plan.sheet
|
|
126
|
+
`sheet "${quote(plan && plan.sheet)}" is a ${named} view; ${named} views are not supported by the plan transform`,
|
|
78
127
|
plan,
|
|
79
128
|
);
|
|
80
129
|
}
|
|
81
130
|
if (!finite2(plan.datum_at) || !finite2(plan.control2_at) || !plan.control2_ref) {
|
|
82
131
|
return refuse(
|
|
83
132
|
'registration-incomplete',
|
|
84
|
-
`sheet "${plan.sheet
|
|
133
|
+
`sheet "${quote(plan.sheet)}" needs $.datum_at, $.control2_at and $.control2_ref before it can be edited`,
|
|
85
134
|
plan,
|
|
86
135
|
);
|
|
87
136
|
}
|
|
88
137
|
const ptPerFt = Number(plan.pt_per_ft);
|
|
89
138
|
if (!(ptPerFt > 0) || !Number.isFinite(ptPerFt)) {
|
|
90
|
-
return refuse('scale-invalid', `sheet "${plan.sheet
|
|
139
|
+
return refuse('scale-invalid', `sheet "${quote(plan.sheet)}" has no positive $.pt_per_ft, so it has no drawing scale`, plan);
|
|
91
140
|
}
|
|
92
141
|
|
|
93
142
|
// Editor projections expose a display-space `grid` because grid-core draws in pixels. The canonical
|
|
94
143
|
// world grid rides beside it as `modelGrid`; standalone callers and stored-plan fixtures use `grid`.
|
|
95
144
|
const registrationGrid = plan.modelGrid || plan.grid;
|
|
96
|
-
const world0 = plan.datum_ref ? gridIntersection(registrationGrid, plan.datum_ref, plan) : [0, 0];
|
|
97
|
-
const world1 = gridIntersection(registrationGrid, plan.control2_ref, plan);
|
|
145
|
+
const world0 = plan.datum_ref ? gridIntersection(registrationGrid, plan.datum_ref, plan, '$.datum_ref') : [0, 0];
|
|
146
|
+
const world1 = gridIntersection(registrationGrid, plan.control2_ref, plan, '$.control2_ref');
|
|
98
147
|
// The shared plan scale. Its zero/negative fallback is unreachable here — the guard above already
|
|
99
148
|
// refused any sheet whose `pt_per_ft` is not a positive finite number — so this is the same value
|
|
100
149
|
// the inline `FT_MM / ptPerFt` produced, from the one implementation.
|
|
@@ -106,15 +155,25 @@ export function planTransform(plan) {
|
|
|
106
155
|
const worldDelta = [world1[0] - world0[0], world1[1] - world0[1]];
|
|
107
156
|
const localLen = Math.hypot(local1[0], local1[1]);
|
|
108
157
|
const worldLen = Math.hypot(worldDelta[0], worldDelta[1]);
|
|
109
|
-
|
|
110
|
-
|
|
158
|
+
// TWO different defects, and one recovery cannot serve both: the display points can coincide while the
|
|
159
|
+
// refs are fine, or the refs can resolve to one intersection while the display points differ. Naming
|
|
160
|
+
// the wrong pair sends the author to fields that are already correct (#925's own failure mode).
|
|
161
|
+
if (!(localLen > 1e-9)) {
|
|
162
|
+
return refuse('registration-degenerate', `sheet "${quote(plan.sheet)}" has coincident registration controls: $.datum_at and $.control2_at are the same point on the sheet`, plan);
|
|
163
|
+
}
|
|
164
|
+
if (!(worldLen > 1e-9)) {
|
|
165
|
+
// `datum_ref` is ABSENT for the "datum_at is the model origin" case, and naming a field that is
|
|
166
|
+
// not there is the same wrong-half misdirection this refusal exists to avoid.
|
|
167
|
+
const datum = plan.datum_ref ? '$.datum_ref and $.control2_ref resolve to the same grid intersection'
|
|
168
|
+
: '$.control2_ref resolves to the model origin, which is where an absent $.datum_ref already puts the datum';
|
|
169
|
+
return refuse('registration-degenerate', `sheet "${quote(plan.sheet)}" has coincident registration controls: ${datum}`, plan);
|
|
111
170
|
}
|
|
112
171
|
const fitScale = worldLen / localLen;
|
|
113
172
|
const rotation = Math.atan2(worldDelta[1], worldDelta[0]) - Math.atan2(local1[1], local1[0]);
|
|
114
173
|
const c = Math.cos(rotation) * fitScale;
|
|
115
174
|
const s = Math.sin(rotation) * fitScale;
|
|
116
175
|
if (![c, s, fitScale, world0[0], world0[1]].every(Number.isFinite)) {
|
|
117
|
-
return refuse('registration-invalid', `sheet "${plan.sheet
|
|
176
|
+
return refuse('registration-invalid', `sheet "${quote(plan.sheet)}" has a non-finite registration transform`, plan);
|
|
118
177
|
}
|
|
119
178
|
return { datumPx: plan.datum_at, world0, mmPerPx: scale, fitScale, rotation, c, s };
|
|
120
179
|
}
|