@floless/app 0.131.0 → 0.132.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 +2558 -1885
- package/dist/schemas/steel.model.v2.schema.json +3 -1
- package/dist/web/app.css +359 -0
- package/dist/web/app.js +22 -0
- package/dist/web/aware.js +62 -10
- package/dist/web/commands-filter.js +157 -0
- package/dist/web/commands-shell.js +1316 -0
- package/dist/web/commands-steel.js +1829 -0
- package/dist/web/commands-vector.js +154 -0
- package/dist/web/commands-vector3d.js +96 -0
- package/dist/web/commands.js +316 -0
- package/dist/web/grid-core.js +124 -23
- package/dist/web/index.html +269 -164
- package/dist/web/instructor-reporter.js +201 -0
- package/dist/web/instructor.js +1119 -0
- package/dist/web/reference-changes.js +55 -0
- package/dist/web/reference-geometry-worker.js +194 -0
- package/dist/web/steel-3d-core.js +454 -107
- package/dist/web/steel-3d-view.js +790 -165
- package/dist/web/steel-canvas-guidance.js +7 -4
- package/dist/web/steel-editor.html +2347 -1810
- package/dist/web/steel-filter-core.js +13 -5
- package/dist/web/steel-filter.html +36 -22
- package/dist/web/steel-model-adapter.js +17 -22
- package/dist/web/steel-model-commands.js +23 -10
- package/dist/web/steel-model-v2-client-validation.js +20 -3
- package/dist/web/steel-model-v2-commands.js +91 -3
- package/dist/web/steel-model-v2-projection.js +4 -5
- package/dist/web/steel-plan-transform.js +4 -8
- package/dist/web/steel-split-view.js +52 -0
- package/dist/web/vector-3d.html +19 -7
- package/dist/web/vector-editor.html +21 -8
- package/dist/web/workspaces.js +9 -24
- package/package.json +9 -1
|
@@ -218,7 +218,62 @@ export function filterDiffers(selected) {
|
|
|
218
218
|
return norm(selected.base) !== norm(selected.revised);
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
/**
|
|
222
|
+
* The version chain as ROWS a history list can draw — newest first, numbered by position.
|
|
223
|
+
*
|
|
224
|
+
* NUMBERED BY POSITION IN THE CHAIN, NOT BY RENDER ORDER. The chain is oldest-first and everything else
|
|
225
|
+
* in this feature numbers it that way ("version 3" in the change panel's header is `versions.length`),
|
|
226
|
+
* so reversing for display must not renumber — a row that reads "version 1" at the bottom of one panel
|
|
227
|
+
* and "version 3" at the top of another is the same row described two ways.
|
|
228
|
+
*
|
|
229
|
+
* THREE DIFFERENT PASTS, THREE DIFFERENT WORDS, and collapsing any pair states something the chain does
|
|
230
|
+
* not say:
|
|
231
|
+
* • `adopted` — its date is when versioning was RECORDED, not when the file was loaded; nothing
|
|
232
|
+
* durable records the latter, which is the whole reason `sha256` had to join the
|
|
233
|
+
* schema. Saying "imported" would fabricate history in the one field a user reads to
|
|
234
|
+
* answer "which of these did I load first?".
|
|
235
|
+
* • restored — a rollback appends a COPY of an earlier row under a fresh id, so the same file
|
|
236
|
+
* appears twice. Rendered as an ordinary import it reads as "why did I load this
|
|
237
|
+
* twice?".
|
|
238
|
+
* • imported — an actual upload.
|
|
239
|
+
*
|
|
240
|
+
* A restored row is recognised by its FILE matching an earlier row's, which is exactly what `rollbackTo`
|
|
241
|
+
* produces and is the only handle available: nothing on the schema flags a restore, deliberately — the
|
|
242
|
+
* row IS a genuine load and carries no `adopted`.
|
|
243
|
+
*/
|
|
244
|
+
export function versionRows(versions) {
|
|
245
|
+
// NUMBERED FROM THE RAW ARRAY, NOT THE FILTERED ONE. Dropping a null entry and then numbering by
|
|
246
|
+
// position would renumber every row after it, while the change panel's own "version N" counts
|
|
247
|
+
// `versions.length` unfiltered — so a malformed chain would make one row read as two different
|
|
248
|
+
// numbers in two panels, which is the exact thing this function's contract forbids.
|
|
249
|
+
const raw = Array.isArray(versions) ? versions : [];
|
|
250
|
+
const all = raw.map((v, rawIdx) => ({ v, rawIdx })).filter((x) => x.v);
|
|
251
|
+
const last = all.length - 1;
|
|
252
|
+
return all.map(({ v, rawIdx }, i) => {
|
|
253
|
+
const priorSame = all.findIndex((o) => o.v.file && o.v.file === v.file);
|
|
254
|
+
const restored = !v.adopted && priorSame >= 0 && priorSame < i;
|
|
255
|
+
return {
|
|
256
|
+
id: v.id || null,
|
|
257
|
+
// WHETHER ANYTHING CAN BE DONE TO THIS ROW. Both actions address a version by id, so a row without
|
|
258
|
+
// one can only produce a click that does nothing — and a control whose sole outcome is nothing is
|
|
259
|
+
// worse than no control, which is the rule the ⋯ menu already applies to itself.
|
|
260
|
+
actionable: !!v.id,
|
|
261
|
+
n: rawIdx + 1,
|
|
262
|
+
name: v.name || v.file || 'this version',
|
|
263
|
+
importedAt: v.importedAt || null,
|
|
264
|
+
current: i === last,
|
|
265
|
+
dateWord: v.adopted ? 'recorded' : restored ? 'restored' : 'imported',
|
|
266
|
+
// …AND THE NOTE'S NUMBER IS A RAW INDEX TOO. `priorSame` indexes the filtered list, so quoting it
|
|
267
|
+
// directly would name a different row than `n` counts once a null has been dropped.
|
|
268
|
+
note: v.adopted ? 'first seen before versioning'
|
|
269
|
+
: restored ? 'restored from version ' + (all[priorSame].rawIdx + 1)
|
|
270
|
+
: null,
|
|
271
|
+
};
|
|
272
|
+
}).reverse();
|
|
273
|
+
}
|
|
274
|
+
|
|
221
275
|
export default {
|
|
222
276
|
RC_CAP, STATUS, STAT_ORDER, REFUSAL_ACTIONS,
|
|
223
277
|
summaryStats, movedPhrase, groupNeedsAttention, needsAttention, capWindow, refusalCopy, filterDiffers,
|
|
278
|
+
versionRows,
|
|
224
279
|
};
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
const TYPE = 'application/vnd.floless.reference-geometry-v7';
|
|
2
|
+
const HEADER = 192;
|
|
3
|
+
const MAX_FILE = 145 * 1024 * 1024;
|
|
4
|
+
const MAX_META = 8 * 1024 * 1024;
|
|
5
|
+
const MAX_POSITIONS = 96 * 1024 * 1024;
|
|
6
|
+
const MAX_INDICES = 32 * 1024 * 1024;
|
|
7
|
+
const MAX_FRAGMENT_VERTICES = 60_000;
|
|
8
|
+
const MAX_FRAGMENT_INDICES = 96_000;
|
|
9
|
+
const CRC_TABLE = new Uint32Array(256);
|
|
10
|
+
for (let n = 0; n < 256; n++) {
|
|
11
|
+
let value = n;
|
|
12
|
+
for (let bit = 0; bit < 8; bit++) value = (value >>> 1) ^ ((value & 1) ? 0xedb88320 : 0);
|
|
13
|
+
CRC_TABLE[n] = value >>> 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function crc32(bytes) {
|
|
17
|
+
let crc = 0xffffffff;
|
|
18
|
+
for (let i = 0; i < bytes.length; i++) crc = (crc >>> 8) ^ CRC_TABLE[(crc ^ bytes[i]) & 0xff];
|
|
19
|
+
return (crc ^ 0xffffffff) >>> 0;
|
|
20
|
+
}
|
|
21
|
+
function u64(view, offset) {
|
|
22
|
+
const value = Number(view.getBigUint64(offset, true));
|
|
23
|
+
if (!Number.isSafeInteger(value)) throw new Error('reference binary offset is not safe');
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
function section(view, offsetAt, lengthAt, crcAt, label, max) {
|
|
27
|
+
const offset = u64(view, offsetAt), length = u64(view, lengthAt);
|
|
28
|
+
if (offset % 8 || length < 0 || length > max || offset < HEADER || offset + length > u64(view, 16)) throw new Error(`invalid ${label} section`);
|
|
29
|
+
return { label, offset, length, crc: view.getUint32(crcAt, true), bytes: new Uint8Array(length) };
|
|
30
|
+
}
|
|
31
|
+
function overlapCopy(target, chunk, chunkAt) {
|
|
32
|
+
const from = Math.max(target.offset, chunkAt), to = Math.min(target.offset + target.length, chunkAt + chunk.length);
|
|
33
|
+
if (to > from) target.bytes.set(chunk.subarray(from - chunkAt, to - chunkAt), from - target.offset);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Read only the three required sections; padding and manifest bytes are discarded as they stream by. */
|
|
37
|
+
async function readSections(response) {
|
|
38
|
+
if (!response.body) throw new Error('reference response has no stream');
|
|
39
|
+
const reader = response.body.getReader(), header = new Uint8Array(HEADER);
|
|
40
|
+
let received = 0, headerFilled = 0, targets = null, total = null;
|
|
41
|
+
for (;;) {
|
|
42
|
+
const { value, done } = await reader.read();
|
|
43
|
+
if (done) break;
|
|
44
|
+
const chunk = value instanceof Uint8Array ? value : new Uint8Array(value), chunkAt = received;
|
|
45
|
+
received += chunk.length;
|
|
46
|
+
if (received > MAX_FILE) throw new Error('reference binary exceeds its file limit');
|
|
47
|
+
if (headerFilled < HEADER) {
|
|
48
|
+
const from = Math.max(0, headerFilled - chunkAt), take = Math.min(chunk.length - from, HEADER - headerFilled);
|
|
49
|
+
if (take > 0) { header.set(chunk.subarray(from, from + take), headerFilled); headerFilled += take; }
|
|
50
|
+
if (headerFilled === HEADER) {
|
|
51
|
+
const view = new DataView(header.buffer), magic = new TextDecoder().decode(header.subarray(0, 8));
|
|
52
|
+
if (magic !== 'FLREFV7\0' || view.getUint32(8, true) !== 7 || view.getUint32(12, true) !== HEADER) throw new Error('unsupported reference geometry binary');
|
|
53
|
+
total = u64(view, 16);
|
|
54
|
+
if (total < HEADER || total > MAX_FILE) throw new Error('reference binary length is invalid');
|
|
55
|
+
targets = [
|
|
56
|
+
section(view, 48, 56, 72, 'metadata', MAX_META),
|
|
57
|
+
section(view, 80, 88, 96, 'positions', MAX_POSITIONS),
|
|
58
|
+
section(view, 128, 136, 144, 'indices', MAX_INDICES),
|
|
59
|
+
];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (targets) for (const target of targets) overlapCopy(target, chunk, chunkAt);
|
|
63
|
+
}
|
|
64
|
+
if (headerFilled !== HEADER || total === null || received !== total) throw new Error('reference binary length mismatch');
|
|
65
|
+
for (const target of targets) if (crc32(target.bytes) !== target.crc) {
|
|
66
|
+
const error = new Error(`${target.label} checksum mismatch`);
|
|
67
|
+
// The full declared body arrived, so this is a bad cache rather than a broken transfer. The editor
|
|
68
|
+
// may safely rebuild it once; a short response never receives this marker and remains a network error.
|
|
69
|
+
error.referenceBinaryCorrupt = true;
|
|
70
|
+
throw error;
|
|
71
|
+
}
|
|
72
|
+
return { header, metadata: targets[0].bytes, positions: targets[1].bytes.buffer, indices: targets[2].bytes.buffer, binaryBytes: total };
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function gunzip(bytes) {
|
|
76
|
+
const stream = new Blob([bytes]).stream().pipeThrough(new DecompressionStream('gzip'));
|
|
77
|
+
const out = await new Response(stream).arrayBuffer();
|
|
78
|
+
if (out.byteLength > MAX_META) throw new Error('reference metadata expands past its limit');
|
|
79
|
+
return new Uint8Array(out);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function sourceNormals(positions, indices) {
|
|
83
|
+
const normals = new Float32Array(positions.length);
|
|
84
|
+
for (let at = 0; at + 2 < indices.length; at += 3) {
|
|
85
|
+
const ia = indices[at] * 3, ib = indices[at + 1] * 3, ic = indices[at + 2] * 3;
|
|
86
|
+
const abx = positions[ib] - positions[ia], aby = positions[ib + 1] - positions[ia + 1], abz = positions[ib + 2] - positions[ia + 2];
|
|
87
|
+
const acx = positions[ic] - positions[ia], acy = positions[ic + 1] - positions[ia + 1], acz = positions[ic + 2] - positions[ia + 2];
|
|
88
|
+
const nx = aby * acz - abz * acy, ny = abz * acx - abx * acz, nz = abx * acy - aby * acx;
|
|
89
|
+
for (const base of [ia, ib, ic]) { normals[base] += nx; normals[base + 1] += ny; normals[base + 2] += nz; }
|
|
90
|
+
}
|
|
91
|
+
for (let i = 0; i < normals.length; i += 3) {
|
|
92
|
+
const length = Math.hypot(normals[i], normals[i + 1], normals[i + 2]) || 1;
|
|
93
|
+
normals[i] /= length; normals[i + 1] /= length; normals[i + 2] /= length;
|
|
94
|
+
}
|
|
95
|
+
return normals;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Reindex each colour run into bounded fragments so shared vertices cannot leak a later run's colour. */
|
|
99
|
+
function renderFragments(positions, indices, runs, transfers) {
|
|
100
|
+
const normals = sourceNormals(positions, indices), out = [];
|
|
101
|
+
for (const run of runs) {
|
|
102
|
+
const rgba = Array.isArray(run.rgba) ? run.rgba : [0.58, 0.64, 0.72, 1];
|
|
103
|
+
const start = Math.max(0, run.start | 0), end = Math.min(indices.length, start + Math.max(0, run.count | 0));
|
|
104
|
+
let map = new Map(), p = [], n = [], ix = [];
|
|
105
|
+
const flush = () => {
|
|
106
|
+
if (!ix.length) return;
|
|
107
|
+
const fp = Float32Array.from(p), fn = Float32Array.from(n), fi = Uint16Array.from(ix);
|
|
108
|
+
const fc = new Uint8Array((fp.length / 3) * 4);
|
|
109
|
+
const q = rgba.map((v) => Math.max(0, Math.min(255, Math.round(Number(v) * 255))));
|
|
110
|
+
for (let i = 0; i < fc.length; i += 4) { fc[i] = q[0]; fc[i + 1] = q[1]; fc[i + 2] = q[2]; fc[i + 3] = q[3]; }
|
|
111
|
+
const fragment = { positions: fp, normals: fn, indices: fi, vertexColors: fc, authoredTransparent: Number(rgba[3]) < 0.999 };
|
|
112
|
+
out.push(fragment); transfers.push(fp.buffer, fn.buffer, fi.buffer, fc.buffer);
|
|
113
|
+
map = new Map(); p = []; n = []; ix = [];
|
|
114
|
+
};
|
|
115
|
+
for (let at = start; at + 2 < end; at += 3) {
|
|
116
|
+
let needed = 0;
|
|
117
|
+
for (let k = 0; k < 3; k++) if (!map.has(indices[at + k])) needed++;
|
|
118
|
+
if (ix.length && (ix.length + 3 > MAX_FRAGMENT_INDICES || map.size + needed > MAX_FRAGMENT_VERTICES)) flush();
|
|
119
|
+
for (let k = 0; k < 3; k++) {
|
|
120
|
+
const source = indices[at + k]; let local = map.get(source);
|
|
121
|
+
if (local === undefined) {
|
|
122
|
+
local = map.size; map.set(source, local); const base = source * 3;
|
|
123
|
+
p.push(positions[base], positions[base + 1], positions[base + 2]);
|
|
124
|
+
n.push(normals[base], normals[base + 1], normals[base + 2]);
|
|
125
|
+
}
|
|
126
|
+
ix.push(local);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
flush();
|
|
130
|
+
}
|
|
131
|
+
return out;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async function decodeBinary(parts) {
|
|
135
|
+
const view = new DataView(parts.header.buffer);
|
|
136
|
+
const expanded = await gunzip(parts.metadata);
|
|
137
|
+
if (expanded.byteLength !== u64(view, 64) || crc32(expanded) !== view.getUint32(76, true)) throw new Error('expanded metadata checksum mismatch');
|
|
138
|
+
const metadata = JSON.parse(new TextDecoder().decode(expanded));
|
|
139
|
+
let spanMm = 0, maxLocal = 0;
|
|
140
|
+
const transfers = [parts.positions, parts.indices];
|
|
141
|
+
const objects = metadata.objects.map((object) => {
|
|
142
|
+
const { positionStart, positionCount, indexStart, indexCount, ...rest } = object;
|
|
143
|
+
const positions = new Float32Array(parts.positions, positionStart * 4, positionCount);
|
|
144
|
+
const indices = new Uint32Array(parts.indices, indexStart * 4, indexCount);
|
|
145
|
+
// The reader historically permits triangle-soup objects with positions but no explicit index.
|
|
146
|
+
// Preserve that contract in v7: the former main-thread renderer synthesized these indices too.
|
|
147
|
+
const drawableIndices = indices.length ? indices : Uint32Array.from({ length: positionCount / 3 }, (_, i) => i);
|
|
148
|
+
if (!indices.length) transfers.push(drawableIndices.buffer);
|
|
149
|
+
const runs = Array.isArray(rest.colors) && rest.colors.length ? rest.colors : [{ start: 0, count: drawableIndices.length, rgba: [0.58, 0.64, 0.72, 1] }];
|
|
150
|
+
const fragments = renderFragments(positions, drawableIndices, runs, transfers);
|
|
151
|
+
for (let i = 0; i < positions.length; i++) { spanMm = Math.max(spanMm, Math.abs(positions[i])); maxLocal = Math.max(maxLocal, Math.abs(positions[i])); }
|
|
152
|
+
return { ...rest, positions, indices, renderFragments: fragments, geometryAnchor: metadata.anchor };
|
|
153
|
+
});
|
|
154
|
+
return {
|
|
155
|
+
ok: true, objects, dropped: metadata.dropped || 0, colorsAvailable: metadata.colorsAvailable ?? null,
|
|
156
|
+
colorsDropped: metadata.colorsDropped || 0, propertySetsAvailable: metadata.propertySetsAvailable ?? null,
|
|
157
|
+
spanMm: spanMm * 2, binaryBytes: parts.binaryBytes,
|
|
158
|
+
maxRebaseErrorMm: Number.isFinite(metadata.maxRebaseErrorMm) ? metadata.maxRebaseErrorMm : maxLocal * 2 ** -23,
|
|
159
|
+
maxSafeScale: Number.isFinite(metadata.maxSafeScale) ? metadata.maxSafeScale : (maxLocal ? 0.5 / (maxLocal * 2 ** -23) : 1e12),
|
|
160
|
+
transfer: transfers,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const controllers = new Map();
|
|
165
|
+
self.onmessage = async (event) => {
|
|
166
|
+
const message = event.data || {};
|
|
167
|
+
if (message.type === 'abort') { controllers.get(message.id)?.abort(); return; }
|
|
168
|
+
if (message.type !== 'load') return;
|
|
169
|
+
const controller = new AbortController(); controllers.set(message.id, controller);
|
|
170
|
+
let decoding = false;
|
|
171
|
+
try {
|
|
172
|
+
const response = await fetch(message.url, { signal: controller.signal });
|
|
173
|
+
const contentType = (response.headers.get('content-type') || '').split(';')[0].trim().toLowerCase();
|
|
174
|
+
if (!response.ok || contentType !== TYPE) {
|
|
175
|
+
const data = await response.json().catch(() => ({
|
|
176
|
+
error: response.ok
|
|
177
|
+
? `reference geometry had content type “${contentType || 'missing'}”, expected “${TYPE}”`
|
|
178
|
+
: `the server answered ${response.status} without a readable error`,
|
|
179
|
+
}));
|
|
180
|
+
self.postMessage({ id: message.id, ok: false, status: response.status, data }); return;
|
|
181
|
+
}
|
|
182
|
+
const sections = await readSections(response);
|
|
183
|
+
decoding = true; // only complete, CRC-checked bytes can now be diagnosed as a corrupt binary
|
|
184
|
+
const decoded = await decodeBinary(sections);
|
|
185
|
+
const transfer = decoded.transfer; delete decoded.transfer;
|
|
186
|
+
self.postMessage({ id: message.id, ok: true, data: decoded }, transfer);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
const corrupt = decoding || error?.referenceBinaryCorrupt === true;
|
|
189
|
+
self.postMessage({ id: message.id, ok: false, status: corrupt ? 422 : 0, data: {
|
|
190
|
+
...(corrupt ? { code: 'reference-binary-corrupt' } : {}),
|
|
191
|
+
error: error?.message || 'could not decode reference geometry',
|
|
192
|
+
} });
|
|
193
|
+
} finally { controllers.delete(message.id); }
|
|
194
|
+
};
|