@floless/app 0.137.4 → 0.138.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 +47618 -26808
- package/dist/internal-workflows/floless-rfi-gmail-send/.floless-owner.json +1 -0
- package/dist/internal-workflows/floless-rfi-gmail-send/floless-rfi-gmail-send.flo +32 -0
- package/dist/schemas/steel.model.v2.schema.json +218 -27
- package/dist/skills/floless-app-knowledge/SKILL.md +5 -2
- package/dist/skills/floless-app-rfi/SKILL.md +410 -0
- package/dist/skills/floless-app-routines/SKILL.md +7 -2
- package/dist/skills/floless-app-routines/references/routines-api.md +14 -5
- package/dist/skills/floless-app-steel-model/SKILL.md +34 -32
- package/dist/skills/floless-app-steel-takeoff/SKILL.md +498 -34
- package/dist/skills/floless-app-steel-takeoff/references/elevation-registration.md +6 -6
- package/dist/skills/floless-app-tweak-contract/SKILL.md +6 -2
- package/dist/templates/floless-workspace-knowledge.flo +20 -4
- package/dist/templates/steel-model.flo +27 -15
- package/dist/web/app.css +559 -131
- package/dist/web/app.js +216 -54
- package/dist/web/aware.js +982 -128
- package/dist/web/checkpoint-standard.js +218 -0
- package/dist/web/commands-filter.js +23 -0
- package/dist/web/commands-shell.js +237 -5
- package/dist/web/commands-steel.js +172 -47
- package/dist/web/connection-review-client.js +2 -2
- package/dist/web/display-units.js +243 -0
- package/dist/web/grid-core.js +470 -56
- package/dist/web/grid-display.js +344 -0
- package/dist/web/index.html +106 -66
- package/dist/web/instructor-reporter.js +5 -0
- package/dist/web/instructor.js +175 -33
- package/dist/web/json-schema-subset.js +145 -25
- package/dist/web/steel-3d-core.js +124 -140
- package/dist/web/steel-3d-view.js +352 -100
- package/dist/web/steel-catalog-picker.js +98 -15
- package/dist/web/steel-detail-refs.js +1 -1
- package/dist/web/steel-editor.html +6458 -915
- package/dist/web/steel-filter.html +404 -57
- package/dist/web/steel-model-adapter.js +1 -1
- package/dist/web/steel-model-commands.js +71 -64
- package/dist/web/steel-model-v2-client-validation.js +10 -3
- package/dist/web/steel-model-v2-commands.js +268 -76
- package/dist/web/steel-model-v2-projection.js +18 -17
- package/dist/web/steel-plan-transform.js +13 -13
- package/dist/web/steel-plan-view-id.js +1 -7
- package/dist/web/steel-read-confidence.js +454 -5
- package/dist/web/steel-units.js +17 -3
- package/dist/web/steel-view-generation.js +21 -7
- package/dist/web/workspaces.js +2178 -497
- package/package.json +4 -1
|
@@ -5,6 +5,77 @@
|
|
|
5
5
|
* confidence, or mutate the contract. Active binding parity is pinned against server/steel-model-read.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
+
import { rawPlanViewId } from './steel-plan-view-id.js';
|
|
9
|
+
|
|
10
|
+
const SHA256_K = Object.freeze([
|
|
11
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
12
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
13
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
14
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
15
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
16
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
17
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
18
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
const rotateRight = (value, bits) => (value >>> bits) | (value << (32 - bits));
|
|
22
|
+
|
|
23
|
+
/** Synchronous SHA-256 for the two tiny lineage tokens projected during a render. */
|
|
24
|
+
function sha256Hex(text) {
|
|
25
|
+
const input = new TextEncoder().encode(text);
|
|
26
|
+
const byteLength = Math.ceil((input.length + 9) / 64) * 64;
|
|
27
|
+
const bytes = new Uint8Array(byteLength);
|
|
28
|
+
bytes.set(input);
|
|
29
|
+
bytes[input.length] = 0x80;
|
|
30
|
+
const view = new DataView(bytes.buffer);
|
|
31
|
+
const bitLength = input.length * 8;
|
|
32
|
+
view.setUint32(byteLength - 8, Math.floor(bitLength / 0x100000000));
|
|
33
|
+
view.setUint32(byteLength - 4, bitLength >>> 0);
|
|
34
|
+
const hash = new Uint32Array([
|
|
35
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a,
|
|
36
|
+
0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19,
|
|
37
|
+
]);
|
|
38
|
+
const words = new Uint32Array(64);
|
|
39
|
+
for (let offset = 0; offset < byteLength; offset += 64) {
|
|
40
|
+
for (let i = 0; i < 16; i++) words[i] = view.getUint32(offset + i * 4);
|
|
41
|
+
for (let i = 16; i < 64; i++) {
|
|
42
|
+
const a = words[i - 15];
|
|
43
|
+
const b = words[i - 2];
|
|
44
|
+
const s0 = rotateRight(a, 7) ^ rotateRight(a, 18) ^ (a >>> 3);
|
|
45
|
+
const s1 = rotateRight(b, 17) ^ rotateRight(b, 19) ^ (b >>> 10);
|
|
46
|
+
words[i] = (words[i - 16] + s0 + words[i - 7] + s1) >>> 0;
|
|
47
|
+
}
|
|
48
|
+
let [a, b, c, d, e, f, g, h] = hash;
|
|
49
|
+
for (let i = 0; i < 64; i++) {
|
|
50
|
+
const s1 = rotateRight(e, 6) ^ rotateRight(e, 11) ^ rotateRight(e, 25);
|
|
51
|
+
const choice = (e & f) ^ (~e & g);
|
|
52
|
+
const t1 = (h + s1 + choice + SHA256_K[i] + words[i]) >>> 0;
|
|
53
|
+
const s0 = rotateRight(a, 2) ^ rotateRight(a, 13) ^ rotateRight(a, 22);
|
|
54
|
+
const majority = (a & b) ^ (a & c) ^ (b & c);
|
|
55
|
+
const t2 = (s0 + majority) >>> 0;
|
|
56
|
+
h = g; g = f; f = e; e = (d + t1) >>> 0; d = c; c = b; b = a; a = (t1 + t2) >>> 0;
|
|
57
|
+
}
|
|
58
|
+
hash[0] = (hash[0] + a) >>> 0; hash[1] = (hash[1] + b) >>> 0;
|
|
59
|
+
hash[2] = (hash[2] + c) >>> 0; hash[3] = (hash[3] + d) >>> 0;
|
|
60
|
+
hash[4] = (hash[4] + e) >>> 0; hash[5] = (hash[5] + f) >>> 0;
|
|
61
|
+
hash[6] = (hash[6] + g) >>> 0; hash[7] = (hash[7] + h) >>> 0;
|
|
62
|
+
}
|
|
63
|
+
return [...hash].map((word) => word.toString(16).padStart(8, '0')).join('');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const endpointLineageId = (observationId, observationEnd) =>
|
|
67
|
+
`sha256:${sha256Hex(`floless:endpoint-lineage:v1\0${JSON.stringify([observationId, observationEnd])}`)}`;
|
|
68
|
+
|
|
69
|
+
const endpointLineageCache = new WeakMap();
|
|
70
|
+
|
|
71
|
+
function expectedEndpointLineageIds(observation, observationId) {
|
|
72
|
+
const cached = endpointLineageCache.get(observation);
|
|
73
|
+
if (cached?.observationId === observationId) return cached.ids;
|
|
74
|
+
const ids = Object.freeze([endpointLineageId(observationId, 0), endpointLineageId(observationId, 1)]);
|
|
75
|
+
endpointLineageCache.set(observation, { observationId, ids });
|
|
76
|
+
return ids;
|
|
77
|
+
}
|
|
78
|
+
|
|
8
79
|
const FIELD_SPECS = Object.freeze([
|
|
9
80
|
Object.freeze({ key: 'role', label: 'Role', kind: 'text' }),
|
|
10
81
|
Object.freeze({ key: 'profile', label: 'Profile', kind: 'text' }),
|
|
@@ -17,6 +88,149 @@ const FIELD_SPECS = Object.freeze([
|
|
|
17
88
|
|
|
18
89
|
const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
19
90
|
const finiteConfidence = (value) => Number.isFinite(value) && value >= 0 && value <= 100;
|
|
91
|
+
const nonEmptyString = (value) => typeof value === 'string' && value.length > 0;
|
|
92
|
+
const codePointLength = (value) => [...value].length;
|
|
93
|
+
const hasOwn = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
94
|
+
const hasOnlyKeys = (value, allowed) => Object.keys(value).every((key) => allowed.has(key));
|
|
95
|
+
const validBox = (value) => Array.isArray(value) && value.length === 4 && value.every(Number.isFinite)
|
|
96
|
+
&& value[2] > value[0] && value[3] > value[1];
|
|
97
|
+
const validProvisionalDrawingTarget = (value) => isObject(value)
|
|
98
|
+
&& Object.keys(value).length === 8
|
|
99
|
+
&& nonEmptyString(value.sourceHash) && codePointLength(value.sourceHash) <= 200
|
|
100
|
+
&& nonEmptyString(value.pageId) && codePointLength(value.pageId) <= 200
|
|
101
|
+
&& nonEmptyString(value.elementId) && codePointLength(value.elementId) <= 200
|
|
102
|
+
&& nonEmptyString(value.sheet) && codePointLength(value.sheet) <= 40
|
|
103
|
+
&& Number.isInteger(value.page) && value.page >= 1
|
|
104
|
+
&& typeof value.ext === 'string' && /^[a-zA-Z0-9]{1,8}$/.test(value.ext)
|
|
105
|
+
&& validBox(value.pageBounds) && validBox(value.region)
|
|
106
|
+
&& value.region[0] >= value.pageBounds[0] && value.region[1] >= value.pageBounds[1]
|
|
107
|
+
&& value.region[2] <= value.pageBounds[2] && value.region[3] <= value.pageBounds[3];
|
|
108
|
+
const validCheckedPage = (value) => isObject(value) && Object.keys(value).length === 3
|
|
109
|
+
&& nonEmptyString(value.sourceHash) && nonEmptyString(value.pageId)
|
|
110
|
+
&& nonEmptyString(value.sheet) && codePointLength(value.sheet) <= 40;
|
|
111
|
+
const HASH_PATTERN = /^sha256:[0-9a-f]{64}$/;
|
|
112
|
+
const MEMBER_OBSERVATION_KEYS = new Set(['id', 'evidence', 'binding']);
|
|
113
|
+
const OBSERVATION_EVIDENCE_KEYS = new Set(['source', 'local', 'provenance', 'observed', 'supersedes']);
|
|
114
|
+
const OBSERVATION_BINDING_KEYS = new Set(['memberIds', 'status', 'verified', 'inherited', 'endpointLineage']);
|
|
115
|
+
const OBSERVED_KEYS = new Set(['role', 'profile', 'mark', 'memberType', 'material', 'fromZ', 'toZ']);
|
|
116
|
+
const UNKNOWN_ELEVATION_KEYS = new Set(['unknown', 'rfiRef', 'why', 'checked']);
|
|
117
|
+
const PROVISIONAL_MEMBER_KEYS = new Set(['id', 'profile', 'provenance', 'material', 'role', 'memberType', 'geometry']);
|
|
118
|
+
const PROVISIONAL_GEOMETRY_KEYS = new Set([
|
|
119
|
+
'kind', 'viewId', 'observationId', 'lineageIds', 'fromDisplay', 'toDisplay',
|
|
120
|
+
'transform', 'why', 'checked', 'drawingTarget',
|
|
121
|
+
]);
|
|
122
|
+
const PLACEMENT_GROUP_KEYS = new Set([
|
|
123
|
+
'kind', 'groupId', 'memberId', 'affectedEnds', 'reasons', 'traces', 'why', 'checked', 'endpointFacts', 'conflicts',
|
|
124
|
+
]);
|
|
125
|
+
const PLACEMENT_TRACE_KEYS = new Set([
|
|
126
|
+
'viewId', 'observationId', 'lineageIds', 'fromDisplay', 'toDisplay', 'endpoints', 'scaleInvalid', 'drawingTarget',
|
|
127
|
+
]);
|
|
128
|
+
const PLACEMENT_ENDPOINT_KEYS = new Set(['observationEnd', 'memberEnd', 'lineageId']);
|
|
129
|
+
const validDisplayPoint = (value) => isObject(value) && Object.keys(value).length === 2
|
|
130
|
+
&& Number.isFinite(value.x) && Number.isFinite(value.y);
|
|
131
|
+
const validProvisionalTransform = (value) => isObject(value) && Object.keys(value).length === 2
|
|
132
|
+
&& value.status === 'unresolved' && Array.isArray(value.reasons) && value.reasons.length === 1
|
|
133
|
+
&& value.reasons[0] === 'view-unregistered-unstarted';
|
|
134
|
+
const validEndpointLineageRow = (value) => isObject(value) && Object.keys(value).length === 4
|
|
135
|
+
&& (value.observationEnd === 0 || value.observationEnd === 1)
|
|
136
|
+
&& nonEmptyString(value.memberId) && (value.memberEnd === 0 || value.memberEnd === 1)
|
|
137
|
+
&& typeof value.lineageId === 'string' && HASH_PATTERN.test(value.lineageId);
|
|
138
|
+
const validObservationBinding = (value) => isObject(value) && hasOnlyKeys(value, OBSERVATION_BINDING_KEYS)
|
|
139
|
+
&& Array.isArray(value.memberIds) && value.memberIds.every(nonEmptyString)
|
|
140
|
+
&& (value.status === 'active' || value.status === 'superseded' || value.status === 'archived')
|
|
141
|
+
&& (!hasOwn(value, 'verified') || typeof value.verified === 'boolean')
|
|
142
|
+
&& (!hasOwn(value, 'inherited') || typeof value.inherited === 'boolean')
|
|
143
|
+
&& (!hasOwn(value, 'endpointLineage') || (Array.isArray(value.endpointLineage)
|
|
144
|
+
&& value.endpointLineage.length <= 32 && value.endpointLineage.every(validEndpointLineageRow)));
|
|
145
|
+
const validObservationSource = (value) => isObject(value) && Object.keys(value).length === 3
|
|
146
|
+
&& nonEmptyString(value.sourceHash) && nonEmptyString(value.sheet) && nonEmptyString(value.elementId);
|
|
147
|
+
const validObservationLocal = (value) => isObject(value) && Object.keys(value).length === 2
|
|
148
|
+
&& Array.isArray(value.wp) && value.wp.length === 2
|
|
149
|
+
&& value.wp.every((point) => Array.isArray(point) && point.length === 2 && point.every(Number.isFinite))
|
|
150
|
+
&& Number.isFinite(value.mm_per_px) && value.mm_per_px > 0;
|
|
151
|
+
const validObservedElevation = (value) => isObject(value) && (
|
|
152
|
+
(Object.keys(value).length === 1 && Number.isFinite(value.known))
|
|
153
|
+
|| (hasOnlyKeys(value, UNKNOWN_ELEVATION_KEYS) && value.unknown === true
|
|
154
|
+
&& (!hasOwn(value, 'rfiRef') || nonEmptyString(value.rfiRef))
|
|
155
|
+
&& (!hasOwn(value, 'why') || (nonEmptyString(value.why) && codePointLength(value.why) <= 600))
|
|
156
|
+
&& (!hasOwn(value, 'checked') || (Array.isArray(value.checked) && value.checked.length <= 20
|
|
157
|
+
&& value.checked.every(validCheckedPage))))
|
|
158
|
+
);
|
|
159
|
+
const validObservedField = (value, elevation = false) => isObject(value) && Object.keys(value).length === 2
|
|
160
|
+
&& finiteConfidence(value.confidence)
|
|
161
|
+
&& (elevation ? validObservedElevation(value.value) : typeof value.value === 'string');
|
|
162
|
+
const validObserved = (value) => isObject(value) && hasOnlyKeys(value, OBSERVED_KEYS)
|
|
163
|
+
&& Object.entries(value).every(([key, field]) => validObservedField(field, key === 'fromZ' || key === 'toZ'));
|
|
164
|
+
const validObservationEvidence = (value) => isObject(value) && hasOnlyKeys(value, OBSERVATION_EVIDENCE_KEYS)
|
|
165
|
+
&& validObservationSource(value.source) && validObservationLocal(value.local)
|
|
166
|
+
&& (value.provenance === 'auto-read' || value.provenance === 'revision-read' || value.provenance === 'manual')
|
|
167
|
+
&& (!hasOwn(value, 'observed') || validObserved(value.observed))
|
|
168
|
+
&& (!hasOwn(value, 'supersedes') || (Array.isArray(value.supersedes) && value.supersedes.every(nonEmptyString)));
|
|
169
|
+
const validMemberObservation = (value) => isObject(value) && Object.keys(value).length === 3
|
|
170
|
+
&& hasOnlyKeys(value, MEMBER_OBSERVATION_KEYS) && nonEmptyString(value.id)
|
|
171
|
+
&& validObservationEvidence(value.evidence) && validObservationBinding(value.binding);
|
|
172
|
+
const validObservationReferences = (observation, entityCount, owningSheet) => {
|
|
173
|
+
if (!validMemberObservation(observation) || observation.evidence.source.sheet !== owningSheet) return false;
|
|
174
|
+
const memberIds = observation.binding.memberIds;
|
|
175
|
+
const boundMembers = new Set(memberIds);
|
|
176
|
+
if (boundMembers.size !== memberIds.length || memberIds.some((id) => entityCount(id) !== 1)) return false;
|
|
177
|
+
if (observation.binding.status === 'active' && memberIds.length === 0) return false;
|
|
178
|
+
if (observation.binding.status === 'archived' && memberIds.length > 0) return false;
|
|
179
|
+
const lineage = observation.binding.endpointLineage;
|
|
180
|
+
if (!lineage?.length) return true;
|
|
181
|
+
const lineageMembers = new Set();
|
|
182
|
+
const lineageKeys = new Set();
|
|
183
|
+
const expectedLineageIds = expectedEndpointLineageIds(observation, observation.id);
|
|
184
|
+
for (const row of lineage) {
|
|
185
|
+
if (entityCount(row.memberId) !== 1 || row.lineageId !== expectedLineageIds[row.observationEnd]) return false;
|
|
186
|
+
const key = JSON.stringify([row.observationEnd, row.memberId, row.memberEnd]);
|
|
187
|
+
if (lineageKeys.has(key)) return false;
|
|
188
|
+
lineageKeys.add(key);
|
|
189
|
+
lineageMembers.add(row.memberId);
|
|
190
|
+
}
|
|
191
|
+
return lineageMembers.size === boundMembers.size
|
|
192
|
+
&& [...lineageMembers].every((memberId) => boundMembers.has(memberId));
|
|
193
|
+
};
|
|
194
|
+
const validPlacementEndpoint = (value) => isObject(value) && hasOnlyKeys(value, PLACEMENT_ENDPOINT_KEYS)
|
|
195
|
+
&& Object.keys(value).length === 3 && (value.observationEnd === 0 || value.observationEnd === 1)
|
|
196
|
+
&& (value.memberEnd === 0 || value.memberEnd === 1) && typeof value.lineageId === 'string' && HASH_PATTERN.test(value.lineageId);
|
|
197
|
+
const validPlacementTrace = (value) => isObject(value) && hasOnlyKeys(value, PLACEMENT_TRACE_KEYS)
|
|
198
|
+
&& Object.keys(value).length === 8 && nonEmptyString(value.viewId) && nonEmptyString(value.observationId)
|
|
199
|
+
&& Array.isArray(value.lineageIds) && value.lineageIds.length === 2 && value.lineageIds.every((id) => typeof id === 'string' && HASH_PATTERN.test(id))
|
|
200
|
+
&& validDisplayPoint(value.fromDisplay) && validDisplayPoint(value.toDisplay)
|
|
201
|
+
&& Array.isArray(value.endpoints) && value.endpoints.length === 2 && value.endpoints.every(validPlacementEndpoint)
|
|
202
|
+
&& typeof value.scaleInvalid === 'boolean' && validProvisionalDrawingTarget(value.drawingTarget);
|
|
203
|
+
const validPlacementGroup = (value) => isObject(value) && hasOnlyKeys(value, PLACEMENT_GROUP_KEYS)
|
|
204
|
+
&& Object.keys(value).length === 10 && value.kind === 'view-frame-group'
|
|
205
|
+
&& nonEmptyString(value.groupId) && nonEmptyString(value.memberId)
|
|
206
|
+
&& Array.isArray(value.affectedEnds) && value.affectedEnds.length >= 1 && value.affectedEnds.every((end) => end === 0 || end === 1)
|
|
207
|
+
&& Array.isArray(value.reasons) && value.reasons.length >= 1 && value.reasons.every((reason) => reason === 'view-scale-invalid' || reason === 'cross-view-conflict')
|
|
208
|
+
&& Array.isArray(value.traces) && value.traces.length >= 1 && value.traces.length <= 32 && value.traces.every(validPlacementTrace)
|
|
209
|
+
&& nonEmptyString(value.why) && codePointLength(value.why) <= 600
|
|
210
|
+
&& Array.isArray(value.checked) && value.checked.length >= 1 && value.checked.length <= 32 && value.checked.every(validCheckedPage)
|
|
211
|
+
&& Array.isArray(value.endpointFacts) && value.endpointFacts.length === 2 && Array.isArray(value.conflicts);
|
|
212
|
+
const validProvisionalGeometry = (value) => validPlacementGroup(value) || (isObject(value) && Object.keys(value).length === 10
|
|
213
|
+
&& hasOnlyKeys(value, PROVISIONAL_GEOMETRY_KEYS)
|
|
214
|
+
&& value.kind === 'view-frame'
|
|
215
|
+
&& nonEmptyString(value.viewId) && codePointLength(value.viewId) <= 200
|
|
216
|
+
&& nonEmptyString(value.observationId) && codePointLength(value.observationId) <= 200
|
|
217
|
+
&& Array.isArray(value.lineageIds) && value.lineageIds.length === 2
|
|
218
|
+
&& value.lineageIds.every((lineageId) => typeof lineageId === 'string' && HASH_PATTERN.test(lineageId))
|
|
219
|
+
&& validDisplayPoint(value.fromDisplay) && validDisplayPoint(value.toDisplay)
|
|
220
|
+
&& validProvisionalTransform(value.transform)
|
|
221
|
+
&& nonEmptyString(value.why) && codePointLength(value.why) <= 600
|
|
222
|
+
&& Array.isArray(value.checked) && value.checked.length >= 1 && value.checked.length <= 20
|
|
223
|
+
&& value.checked.every(validCheckedPage)
|
|
224
|
+
&& validProvisionalDrawingTarget(value.drawingTarget));
|
|
225
|
+
const validOptionalString = (value, key) => !hasOwn(value, key)
|
|
226
|
+
|| (typeof value[key] === 'string' && codePointLength(value[key]) <= 200);
|
|
227
|
+
const validProvisionalMember = (value) => isObject(value) && hasOnlyKeys(value, PROVISIONAL_MEMBER_KEYS)
|
|
228
|
+
&& nonEmptyString(value.id) && codePointLength(value.id) <= 200
|
|
229
|
+
&& typeof value.profile === 'string' && codePointLength(value.profile) <= 200
|
|
230
|
+
&& (value.provenance === 'read' || value.provenance === 'revision-read')
|
|
231
|
+
&& validOptionalString(value, 'material') && validOptionalString(value, 'memberType')
|
|
232
|
+
&& (!hasOwn(value, 'role') || value.role === 'beam' || value.role === 'column')
|
|
233
|
+
&& validProvisionalGeometry(value.geometry);
|
|
20
234
|
const validElevation = (value) => isObject(value) && (
|
|
21
235
|
(Number.isFinite(value.known) && !('unknown' in value))
|
|
22
236
|
|| (value.unknown === true && !('known' in value) && (value.rfiRef === undefined || typeof value.rfiRef === 'string'))
|
|
@@ -25,6 +239,105 @@ const provenanceLabel = (value) => value === 'auto-read' ? 'Auto read'
|
|
|
25
239
|
: value === 'revision-read' ? 'Revision read'
|
|
26
240
|
: value === 'manual' ? 'Manual observation' : 'Recorded observation';
|
|
27
241
|
|
|
242
|
+
function invalidSupersedesObservationIds(observations, observationIdCounts, entityCount, observationSheets, ownerIds) {
|
|
243
|
+
const byId = new Map();
|
|
244
|
+
for (const observation of observations) {
|
|
245
|
+
if (nonEmptyString(observation.id) && observationIdCounts.get(observation.id) === 1) {
|
|
246
|
+
byId.set(observation.id, observation);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const invalid = new Set();
|
|
250
|
+
const edgesById = new Map();
|
|
251
|
+
const predecessors = new Map();
|
|
252
|
+
const reachable = new Set();
|
|
253
|
+
const pending = [...ownerIds];
|
|
254
|
+
for (let index = 0; index < pending.length; index += 1) {
|
|
255
|
+
const id = pending[index];
|
|
256
|
+
if (reachable.has(id)) continue;
|
|
257
|
+
reachable.add(id);
|
|
258
|
+
const observation = byId.get(id);
|
|
259
|
+
if (!observation) {
|
|
260
|
+
invalid.add(id);
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
const evidence = isObject(observation.evidence) ? observation.evidence : null;
|
|
264
|
+
const rawEdges = evidence && Object.prototype.hasOwnProperty.call(evidence, 'supersedes')
|
|
265
|
+
? evidence.supersedes : [];
|
|
266
|
+
if (!Array.isArray(rawEdges)) {
|
|
267
|
+
invalid.add(id);
|
|
268
|
+
edgesById.set(id, []);
|
|
269
|
+
continue;
|
|
270
|
+
}
|
|
271
|
+
const seen = new Set();
|
|
272
|
+
const edges = [];
|
|
273
|
+
for (const target of rawEdges) {
|
|
274
|
+
if (!nonEmptyString(target) || seen.has(target) || target === id
|
|
275
|
+
|| observationIdCounts.get(target) !== 1) {
|
|
276
|
+
invalid.add(id);
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
seen.add(target);
|
|
280
|
+
const targetObservation = byId.get(target);
|
|
281
|
+
if (!targetObservation) {
|
|
282
|
+
invalid.add(id);
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
edges.push(target);
|
|
286
|
+
pending.push(target);
|
|
287
|
+
const parents = predecessors.get(target) ?? [];
|
|
288
|
+
parents.push(id);
|
|
289
|
+
predecessors.set(target, parents);
|
|
290
|
+
}
|
|
291
|
+
edgesById.set(id, edges);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
for (const id of reachable) {
|
|
295
|
+
const observation = byId.get(id);
|
|
296
|
+
if (!observation) continue;
|
|
297
|
+
const valid = validObservationReferences(observation, entityCount, observationSheets.get(observation));
|
|
298
|
+
if (!valid) invalid.add(id);
|
|
299
|
+
for (const target of edgesById.get(id) ?? []) {
|
|
300
|
+
if (byId.get(target)?.binding?.status !== 'superseded') invalid.add(id);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
const WHITE = 0, GREY = 1, BLACK = 2;
|
|
305
|
+
const colour = new Map();
|
|
306
|
+
for (const root of ownerIds) {
|
|
307
|
+
if ((colour.get(root) ?? WHITE) !== WHITE) continue;
|
|
308
|
+
colour.set(root, GREY);
|
|
309
|
+
const stack = [{ id: root, index: 0 }];
|
|
310
|
+
while (stack.length) {
|
|
311
|
+
const top = stack[stack.length - 1];
|
|
312
|
+
const edges = edgesById.get(top.id) ?? [];
|
|
313
|
+
if (top.index >= edges.length) {
|
|
314
|
+
colour.set(top.id, BLACK);
|
|
315
|
+
stack.pop();
|
|
316
|
+
continue;
|
|
317
|
+
}
|
|
318
|
+
const next = edges[top.index++];
|
|
319
|
+
const state = colour.get(next) ?? WHITE;
|
|
320
|
+
if (state === GREY) {
|
|
321
|
+
invalid.add(top.id);
|
|
322
|
+
invalid.add(next);
|
|
323
|
+
} else if (state === WHITE) {
|
|
324
|
+
colour.set(next, GREY);
|
|
325
|
+
stack.push({ id: next, index: 0 });
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
const queue = [...invalid];
|
|
331
|
+
for (let index = 0; index < queue.length; index += 1) {
|
|
332
|
+
for (const predecessor of predecessors.get(queue[index]) ?? []) {
|
|
333
|
+
if (invalid.has(predecessor)) continue;
|
|
334
|
+
invalid.add(predecessor);
|
|
335
|
+
queue.push(predecessor);
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
return invalid;
|
|
339
|
+
}
|
|
340
|
+
|
|
28
341
|
function readField(observed, spec, diagnostics, observationId) {
|
|
29
342
|
if (!Object.prototype.hasOwnProperty.call(observed, spec.key)) return null;
|
|
30
343
|
const record = observed[spec.key];
|
|
@@ -46,14 +359,64 @@ function readField(observed, spec, diagnostics, observationId) {
|
|
|
46
359
|
*/
|
|
47
360
|
export function projectReadConfidence(model) {
|
|
48
361
|
const members = Array.isArray(model?.members) ? model.members : [];
|
|
362
|
+
const plans = Array.isArray(model?.plans) ? model.plans : [];
|
|
363
|
+
const memberIdCounts = new Map();
|
|
364
|
+
for (const member of members) {
|
|
365
|
+
if (isObject(member) && nonEmptyString(member.id)) {
|
|
366
|
+
memberIdCounts.set(member.id, (memberIdCounts.get(member.id) ?? 0) + 1);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
49
369
|
const rows = members.filter((member) => isObject(member) && typeof member.id === 'string').map((member) => ({
|
|
50
370
|
memberId: member.id,
|
|
51
371
|
observations: [],
|
|
52
372
|
}));
|
|
53
373
|
const byMember = new Map(rows.map((row) => [row.memberId, row]));
|
|
374
|
+
const provisionalById = new Map();
|
|
375
|
+
const provisionalRows = Array.isArray(model?.provisional_members) ? model.provisional_members : [];
|
|
376
|
+
const provisionalIdCounts = new Map();
|
|
377
|
+
for (const member of provisionalRows) {
|
|
378
|
+
if (isObject(member) && nonEmptyString(member.id)) {
|
|
379
|
+
provisionalIdCounts.set(member.id, (provisionalIdCounts.get(member.id) ?? 0) + 1);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
for (const member of provisionalRows) {
|
|
383
|
+
if (!validProvisionalMember(member)) continue;
|
|
384
|
+
if (provisionalIdCounts.get(member.id) === 1) provisionalById.set(member.id, member);
|
|
385
|
+
}
|
|
386
|
+
const observationIdCounts = new Map();
|
|
387
|
+
const observationBindingCounts = new Map();
|
|
388
|
+
const viewIdCounts = new Map();
|
|
389
|
+
const observations = [];
|
|
390
|
+
const observationSheets = new Map();
|
|
391
|
+
for (const plan of plans) {
|
|
392
|
+
if (!isObject(plan)) continue;
|
|
393
|
+
const viewId = rawPlanViewId(plan);
|
|
394
|
+
if (viewId) viewIdCounts.set(viewId, (viewIdCounts.get(viewId) ?? 0) + 1);
|
|
395
|
+
for (const observation of Array.isArray(plan.memberObservations) ? plan.memberObservations : []) {
|
|
396
|
+
if (!isObject(observation)) continue;
|
|
397
|
+
observations.push(observation);
|
|
398
|
+
observationSheets.set(observation, typeof plan.sheet === 'string' ? plan.sheet : null);
|
|
399
|
+
if (isObject(observation.binding) && Array.isArray(observation.binding.memberIds)) {
|
|
400
|
+
for (const memberId of observation.binding.memberIds) {
|
|
401
|
+
if (!nonEmptyString(memberId)) continue;
|
|
402
|
+
observationBindingCounts.set(memberId, (observationBindingCounts.get(memberId) ?? 0) + 1);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
if (!nonEmptyString(observation.id)) continue;
|
|
406
|
+
observationIdCounts.set(observation.id, (observationIdCounts.get(observation.id) ?? 0) + 1);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
const entityCount = (id) => (memberIdCounts.get(id) ?? 0) + (provisionalIdCounts.get(id) ?? 0);
|
|
410
|
+
const provisionalOwnerIds = new Set([...provisionalById.values()].flatMap((member) =>
|
|
411
|
+
member.geometry.kind === 'view-frame-group' ? member.geometry.traces.map((trace) => trace.observationId) : [member.geometry.observationId]));
|
|
412
|
+
const invalidSupersedes = provisionalById.size > 0
|
|
413
|
+
? invalidSupersedesObservationIds(
|
|
414
|
+
observations, observationIdCounts, entityCount, observationSheets, provisionalOwnerIds,
|
|
415
|
+
)
|
|
416
|
+
: new Set();
|
|
54
417
|
const diagnostics = [];
|
|
55
418
|
|
|
56
|
-
for (const plan of
|
|
419
|
+
for (const plan of plans) {
|
|
57
420
|
if (!isObject(plan)) continue;
|
|
58
421
|
for (const observation of Array.isArray(plan.memberObservations) ? plan.memberObservations : []) {
|
|
59
422
|
if (!isObject(observation) || !isObject(observation.binding) || observation.binding.status !== 'active') continue;
|
|
@@ -75,11 +438,99 @@ export function projectReadConfidence(model) {
|
|
|
75
438
|
verified: observation.binding.verified === true,
|
|
76
439
|
fields: Object.freeze(fields),
|
|
77
440
|
});
|
|
78
|
-
const
|
|
441
|
+
const bindingMemberIds = Array.isArray(observation.binding.memberIds) ? observation.binding.memberIds : [];
|
|
442
|
+
const memberIds = new Set(bindingMemberIds);
|
|
79
443
|
for (const memberId of memberIds) {
|
|
444
|
+
if (!nonEmptyString(memberId)
|
|
445
|
+
|| (memberIdCounts.get(memberId) ?? 0) + (provisionalIdCounts.get(memberId) ?? 0) !== 1) {
|
|
446
|
+
diagnostics.push(Object.freeze({ code: 'unresolved-member', observationId, memberId }));
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
80
449
|
const row = byMember.get(memberId);
|
|
81
450
|
if (row) row.observations.push(group);
|
|
82
|
-
else
|
|
451
|
+
else {
|
|
452
|
+
const provisional = provisionalById.get(memberId);
|
|
453
|
+
const viewId = rawPlanViewId(plan);
|
|
454
|
+
const provisionalGeometry = provisional?.geometry;
|
|
455
|
+
const grouped = provisionalGeometry?.kind === 'view-frame-group';
|
|
456
|
+
const trace = grouped ? provisionalGeometry.traces.find((candidate) => candidate.observationId === observationId)
|
|
457
|
+
: provisionalGeometry;
|
|
458
|
+
const target = trace?.drawingTarget;
|
|
459
|
+
const checked = provisionalGeometry?.checked;
|
|
460
|
+
const checkedIsValid = Array.isArray(checked) && checked.length >= 1 && checked.length <= (grouped ? 32 : 20)
|
|
461
|
+
&& checked.every(validCheckedPage);
|
|
462
|
+
const targetMatchesEvidence = isObject(target) && isObject(evidence.source)
|
|
463
|
+
&& target.sourceHash === evidence.source.sourceHash && target.elementId === evidence.source.elementId
|
|
464
|
+
&& target.sheet === plan.sheet && target.sheet === evidence.source.sheet
|
|
465
|
+
&& checkedIsValid && checked.some((page) => isObject(page)
|
|
466
|
+
&& page.sourceHash === target.sourceHash && page.pageId === target.pageId && page.sheet === target.sheet);
|
|
467
|
+
const invalidViewScale = !Number.isFinite(plan.mm_per_px) || plan.mm_per_px <= 0;
|
|
468
|
+
const ownerViewIsValid = nonEmptyString(viewId) && viewIdCounts.get(viewId) === 1 && isObject(evidence.local)
|
|
469
|
+
&& (grouped
|
|
470
|
+
? !!trace && trace.viewId === viewId && trace.scaleInvalid === invalidViewScale
|
|
471
|
+
&& (invalidViewScale || evidence.local.mm_per_px === plan.mm_per_px)
|
|
472
|
+
: (plan.viewKind === 'elevation' || plan.viewKind === 'section')
|
|
473
|
+
&& !hasOwn(plan, 'sourceRegistration') && evidence.local.mm_per_px === plan.mm_per_px);
|
|
474
|
+
const rawEndpointRows = Array.isArray(observation.binding.endpointLineage)
|
|
475
|
+
? observation.binding.endpointLineage : [];
|
|
476
|
+
const allEndpointRows = rawEndpointRows.filter(isObject);
|
|
477
|
+
const endpointRows = allEndpointRows.filter((row) => row.memberId === memberId);
|
|
478
|
+
const orderedEndpointRows = endpointRows.slice().sort((a, b) => Number(a.memberEnd) - Number(b.memberEnd));
|
|
479
|
+
const lineageIds = Array.isArray(trace?.lineageIds) ? trace.lineageIds : [];
|
|
480
|
+
const expectedLineageIds = expectedEndpointLineageIds(observation, observationId);
|
|
481
|
+
const lineageMembers = new Set(allEndpointRows.map((row) => row.memberId).filter(nonEmptyString));
|
|
482
|
+
const boundMembers = new Set(bindingMemberIds.filter(nonEmptyString));
|
|
483
|
+
const bindingMembersAreValid = bindingMemberIds.length > 0
|
|
484
|
+
&& boundMembers.size === bindingMemberIds.length
|
|
485
|
+
&& bindingMemberIds.every((id) => nonEmptyString(id)
|
|
486
|
+
&& (memberIdCounts.get(id) ?? 0) + (provisionalIdCounts.get(id) ?? 0) === 1);
|
|
487
|
+
const lineageCoverageMatches = lineageMembers.size === boundMembers.size
|
|
488
|
+
&& [...lineageMembers].every((id) => boundMembers.has(id));
|
|
489
|
+
const lineageKeys = new Set();
|
|
490
|
+
const completeLineageIsValid = rawEndpointRows.length === allEndpointRows.length && allEndpointRows.every((row) => {
|
|
491
|
+
if (!nonEmptyString(row.memberId) || (row.observationEnd !== 0 && row.observationEnd !== 1)
|
|
492
|
+
|| (row.memberEnd !== 0 && row.memberEnd !== 1)
|
|
493
|
+
|| row.lineageId !== expectedLineageIds[row.observationEnd]) return false;
|
|
494
|
+
const key = JSON.stringify([row.observationEnd, row.memberId, row.memberEnd]);
|
|
495
|
+
if (lineageKeys.has(key)) return false;
|
|
496
|
+
lineageKeys.add(key);
|
|
497
|
+
return true;
|
|
498
|
+
});
|
|
499
|
+
const lineageMatches = endpointRows.length === 2
|
|
500
|
+
&& lineageCoverageMatches
|
|
501
|
+
&& completeLineageIsValid
|
|
502
|
+
&& new Set(endpointRows.map((row) => row.memberEnd)).size === 2
|
|
503
|
+
&& endpointRows.every((row) => row.memberEnd === 0 || row.memberEnd === 1)
|
|
504
|
+
&& lineageIds.length === 2
|
|
505
|
+
&& orderedEndpointRows.every((row, index) => row.lineageId === lineageIds[index]
|
|
506
|
+
&& (row.observationEnd === 0 || row.observationEnd === 1)
|
|
507
|
+
&& row.lineageId === expectedLineageIds[row.observationEnd]);
|
|
508
|
+
const workPoints = isObject(evidence.local) && Array.isArray(evidence.local.wp) ? evidence.local.wp : [];
|
|
509
|
+
const displayMatchesEvidence = lineageMatches && orderedEndpointRows.every((row) => {
|
|
510
|
+
const observed = row.observationEnd === 0 || row.observationEnd === 1 ? workPoints[row.observationEnd] : null;
|
|
511
|
+
const display = row.memberEnd === 0 ? trace?.fromDisplay : trace?.toDisplay;
|
|
512
|
+
return Array.isArray(observed) && observed.length === 2 && isObject(display)
|
|
513
|
+
&& Number.isFinite(observed[0]) && Number.isFinite(observed[1])
|
|
514
|
+
&& Number.isFinite(display.x) && Number.isFinite(display.y)
|
|
515
|
+
&& display.x === observed[0] && display.y === observed[1];
|
|
516
|
+
});
|
|
517
|
+
const endpointMappingMatches = !grouped || (Array.isArray(trace?.endpoints)
|
|
518
|
+
&& JSON.stringify(trace.endpoints) === JSON.stringify(endpointRows.slice()
|
|
519
|
+
.sort((a, b) => Number(a.memberEnd) - Number(b.memberEnd))
|
|
520
|
+
.map((row) => ({ observationEnd: row.observationEnd, memberEnd: row.memberEnd, lineageId: row.lineageId }))));
|
|
521
|
+
if (!provisional || !trace || !ownerViewIsValid || observationIdCounts.get(observationId) !== 1
|
|
522
|
+
|| invalidSupersedes.has(observationId)
|
|
523
|
+
|| !validMemberObservation(observation)
|
|
524
|
+
|| !bindingMembersAreValid
|
|
525
|
+
|| observation.binding.inherited === true
|
|
526
|
+
|| bindingMemberIds.filter((candidate) => candidate === memberId).length !== 1
|
|
527
|
+
|| observationBindingCounts.get(memberId) !== (grouped ? provisionalGeometry.traces.length : 1)
|
|
528
|
+
|| trace.observationId !== observationId
|
|
529
|
+
|| trace.viewId !== viewId || !targetMatchesEvidence
|
|
530
|
+
|| !lineageMatches || !displayMatchesEvidence || !endpointMappingMatches) {
|
|
531
|
+
diagnostics.push(Object.freeze({ code: 'unresolved-member', observationId, memberId: String(memberId) }));
|
|
532
|
+
}
|
|
533
|
+
}
|
|
83
534
|
}
|
|
84
535
|
}
|
|
85
536
|
}
|
|
@@ -136,5 +587,3 @@ export function rowIsBelowTarget(row, target) {
|
|
|
136
587
|
return finiteConfidence(target) && (row?.observations || []).some((observation) =>
|
|
137
588
|
(observation.fields || []).some((field) => field.confidence < target));
|
|
138
589
|
}
|
|
139
|
-
|
|
140
|
-
export { FIELD_SPECS };
|
package/dist/web/steel-units.js
CHANGED
|
@@ -14,12 +14,26 @@
|
|
|
14
14
|
* (`FT_TO_MM`/`IN_TO_MM` and `FT_MM`/`IN_MM`), so no existing import had to change and both remain the
|
|
15
15
|
* seams they were. Two names for one binding is not two definitions.
|
|
16
16
|
*
|
|
17
|
-
* NOT everything spelled 304.8 belongs here
|
|
18
|
-
*
|
|
19
|
-
*
|
|
17
|
+
* NOT everything spelled 304.8 belongs here — a `REF_UNIT_RATIOS` table is data, not a conversion.
|
|
18
|
+
* The editor's `V2_PT_PER_FT` used to be the other example: a drawing SCALE that had to spell this
|
|
19
|
+
* number because 304.8 pt/ft was what made the old `304.8 / ptPerFt` come out as 1. It is
|
|
20
|
+
* `V2_GRID_IDENTITY_SCALE = 1` now (UK epic, slice 0), which is why the geometry guard's
|
|
21
|
+
* `NOT_A_UNIT_CONSTANT` list could be emptied.
|
|
20
22
|
*/
|
|
21
23
|
|
|
22
24
|
/** Millimetres per foot. Exact: a foot is 12 inches of 25.4 mm. */
|
|
23
25
|
export const FT_TO_MM = 304.8;
|
|
24
26
|
/** Millimetres per inch. Exact by international definition since 1959. */
|
|
25
27
|
export const IN_TO_MM = 25.4;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Kilograms per metre in one pound per foot. Exact, like its two neighbours: a pound IS
|
|
31
|
+
* 0.45359237 kg and a foot IS 0.3048 m, so this quotient is a definition rather than a measurement.
|
|
32
|
+
*
|
|
33
|
+
* It lives here for the reason the lengths do — a unit conversion written inline is a unit
|
|
34
|
+
* conversion that can be edited alone. It arrived when the contract's `weights` map became kg/m
|
|
35
|
+
* (the UK environment epic, slice 0): the map is canonical metric now, and the imperial BOM
|
|
36
|
+
* columns convert through THIS at the display edge only. A weight crossing that edge without
|
|
37
|
+
* passing through a named constant is exactly the untagged-unit bug the epic exists to prevent.
|
|
38
|
+
*/
|
|
39
|
+
export const LB_PER_FT_TO_KG_PER_M = 0.45359237 / 0.3048;
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* sanitised draft-only saved-view records. steel-editor.html owns the modal/persistence and
|
|
7
7
|
* steel-3d-view.js owns the camera/mesh intersection.
|
|
8
8
|
*/
|
|
9
|
-
import { parseLen, fmtLen, parseSpacings } from './grid-core.js';
|
|
9
|
+
import { parseLen, fmtLen, parseSpacings, LEVEL_SAME_MM } from './grid-core.js';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Display modes a saved view may carry. Must stay a superset of the 3D toolbar's `#m3dMode`
|
|
@@ -70,22 +70,36 @@ export function sourcesFromGrid(geo, mmPerDisplayPx, sheet, grid) {
|
|
|
70
70
|
return { x, y, levels };
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
/**
|
|
74
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Parse the modal's authored depth values into positive world mm.
|
|
75
|
+
*
|
|
76
|
+
* `fmt` RENDERS THE FLOOR IN THE READER'S OWN UNITS and is injected rather than imported, because this
|
|
77
|
+
* module is a leaf with no idea what the project displays. Without it the refusal read "must be at
|
|
78
|
+
* least 0.5 mm" to a US user — a number in a system they are not working in, about a field they
|
|
79
|
+
* authored in feet and inches. The default keeps a bare millimetre string so a caller with no display
|
|
80
|
+
* context (the tests, a script) still gets a sentence rather than `undefined`.
|
|
81
|
+
*/
|
|
82
|
+
export function parseDepths(kind, raw, fmt) {
|
|
83
|
+
const say = typeof fmt === 'function' ? fmt : (mm) => `${mm} mm`;
|
|
75
84
|
const keys = kind === 'level' ? ['above', 'below'] : ['ahead', 'behind'];
|
|
76
85
|
const values = {};
|
|
77
86
|
for (const key of keys) {
|
|
78
87
|
const mm = parseLen(String(raw?.[key] ?? '').trim());
|
|
79
|
-
|
|
88
|
+
// A NUMERIC floor. It used to ask whether the value survived a round trip through `fmtLen`, which
|
|
89
|
+
// is a question about the imperial DISPLAY lattice rather than about the depth: a perfectly good
|
|
90
|
+
// 1 mm depth was refused because it rounded to zero sixteenths of an inch. The floor is the level
|
|
91
|
+
// identity tolerance, which is the repo's one answer to "is this distance nothing".
|
|
92
|
+
if (!positive(mm) || mm < LEVEL_SAME_MM) return { ok: false, error: `${key} must be at least ${say(LEVEL_SAME_MM)}`, values: null };
|
|
80
93
|
values[key] = mm;
|
|
81
94
|
}
|
|
82
95
|
return { ok: true, error: '', values };
|
|
83
96
|
}
|
|
84
97
|
|
|
85
|
-
export function normalizeDepths(kind, raw) {
|
|
86
|
-
const parsed = parseDepths(kind, raw);
|
|
98
|
+
export function normalizeDepths(kind, raw, fmt) {
|
|
99
|
+
const parsed = parseDepths(kind, raw, fmt);
|
|
87
100
|
if (!parsed.ok) return parsed;
|
|
88
|
-
|
|
101
|
+
const say = typeof fmt === 'function' ? fmt : fmtLen;
|
|
102
|
+
return { ...parsed, formatted: Object.fromEntries(Object.entries(parsed.values).map(([key, mm]) => [key, say(mm)])) };
|
|
89
103
|
}
|
|
90
104
|
|
|
91
105
|
/** Shift-range applies the target's next state inclusively and preserves choices outside the range. */
|