ducjs 3.2.0 → 3.2.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/ducjs_wasm.d.ts +40 -40
- package/dist/ducjs_wasm.js +95 -95
- package/dist/ducjs_wasm_bg.wasm +0 -0
- package/dist/restore/restoreElements.js +5 -1
- package/dist/transform.js +86 -2
- package/dist/types/elements/index.d.ts +2 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/utils/elements/newElement.js +4 -1
- package/package.json +1 -1
package/dist/ducjs_wasm.d.ts
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* Returns the file entry as a JS object, or `undefined` if not found.
|
|
7
|
-
*/
|
|
8
|
-
export function getExternalFile(buf: Uint8Array, file_id: string): any;
|
|
9
|
-
/**
|
|
10
|
-
* Restore a specific checkpoint by its ID from a `.duc` file buffer.
|
|
4
|
+
* Parse a `.duc` file lazily — returns everything EXCEPT external file data blobs.
|
|
11
5
|
*
|
|
12
|
-
*
|
|
6
|
+
* Use `getExternalFile()` or `listExternalFiles()` for on-demand access.
|
|
13
7
|
*/
|
|
14
|
-
export function
|
|
8
|
+
export function parseDucLazy(buf: Uint8Array): any;
|
|
15
9
|
/**
|
|
16
10
|
* List all versions (checkpoints + deltas) from a `.duc` file buffer.
|
|
17
11
|
*
|
|
18
12
|
* Returns a JS array of `VersionEntry` objects (no heavy data blobs).
|
|
19
13
|
*/
|
|
20
14
|
export function listVersions(duc_buf: Uint8Array): any;
|
|
15
|
+
/**
|
|
16
|
+
* Parse a `.duc` file (Uint8Array) into a JS object (ExportedDataState).
|
|
17
|
+
*/
|
|
18
|
+
export function parseDuc(buf: Uint8Array): any;
|
|
21
19
|
/**
|
|
22
20
|
* Read the full VersionGraph from a `.duc` file buffer.
|
|
23
21
|
*
|
|
@@ -26,23 +24,26 @@ export function listVersions(duc_buf: Uint8Array): any;
|
|
|
26
24
|
*/
|
|
27
25
|
export function readVersionGraph(duc_buf: Uint8Array): any;
|
|
28
26
|
/**
|
|
29
|
-
*
|
|
27
|
+
* Apply a changeset to reconstruct document state.
|
|
30
28
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
29
|
+
* `base_state` must be the exact checkpoint data used when the changeset
|
|
30
|
+
* was created. Returns the full document state as `Uint8Array`.
|
|
31
|
+
*
|
|
32
|
+
* Handles all changeset formats transparently:
|
|
33
|
+
* - v3 (bsdiff), v2 (XOR diff), v1 (zlib full snapshot)
|
|
35
34
|
*/
|
|
36
|
-
export function
|
|
35
|
+
export function applyDeltaChangeset(base_state: Uint8Array, changeset: Uint8Array): Uint8Array;
|
|
37
36
|
/**
|
|
38
|
-
*
|
|
37
|
+
* Compute a checkpoint-relative binary diff changeset using bsdiff.
|
|
39
38
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
39
|
+
* `base_state` is the checkpoint's full data blob.
|
|
40
|
+
* `current_state` is the full document state at the new version.
|
|
42
41
|
*
|
|
43
|
-
* Returns
|
|
42
|
+
* Returns an encoded changeset (`Uint8Array`) ready for storage in a
|
|
43
|
+
* `Delta.payload`. bsdiff finds matching blocks even when they shift
|
|
44
|
+
* offsets, which is critical for SQLite databases.
|
|
44
45
|
*/
|
|
45
|
-
export function
|
|
46
|
+
export function createDeltaChangeset(base_state: Uint8Array, current_state: Uint8Array): Uint8Array;
|
|
46
47
|
/**
|
|
47
48
|
* Revert the document to a specific version, removing all newer versions.
|
|
48
49
|
*
|
|
@@ -50,15 +51,11 @@ export function restoreVersion(duc_buf: Uint8Array, version_number: number): any
|
|
|
50
51
|
*/
|
|
51
52
|
export function revertToVersion(duc_buf: Uint8Array, target_version: number): any;
|
|
52
53
|
/**
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* `base_state` must be the exact checkpoint data used when the changeset
|
|
56
|
-
* was created. Returns the full document state as `Uint8Array`.
|
|
54
|
+
* Restore a specific checkpoint by its ID from a `.duc` file buffer.
|
|
57
55
|
*
|
|
58
|
-
*
|
|
59
|
-
* - v3 (bsdiff), v2 (XOR diff), v1 (zlib full snapshot)
|
|
56
|
+
* Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
|
|
60
57
|
*/
|
|
61
|
-
export function
|
|
58
|
+
export function restoreCheckpoint(duc_buf: Uint8Array, checkpoint_id: string): any;
|
|
62
59
|
/**
|
|
63
60
|
* List metadata for all external files (without loading the heavy data blobs).
|
|
64
61
|
*/
|
|
@@ -68,26 +65,29 @@ export function listExternalFiles(buf: Uint8Array): any;
|
|
|
68
65
|
*/
|
|
69
66
|
export function serializeDuc(data: any): Uint8Array;
|
|
70
67
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
* `base_state` is the checkpoint's full data blob.
|
|
74
|
-
* `current_state` is the full document state at the new version.
|
|
68
|
+
* Fetch a single external file from a `.duc` buffer by file ID.
|
|
75
69
|
*
|
|
76
|
-
* Returns
|
|
77
|
-
* `Delta.payload`. bsdiff finds matching blocks even when they shift
|
|
78
|
-
* offsets, which is critical for SQLite databases.
|
|
70
|
+
* Returns the file entry as a JS object, or `undefined` if not found.
|
|
79
71
|
*/
|
|
80
|
-
export function
|
|
72
|
+
export function getExternalFile(buf: Uint8Array, file_id: string): any;
|
|
81
73
|
/**
|
|
82
|
-
*
|
|
74
|
+
* Returns the current version-control schema version defined in Rust.
|
|
75
|
+
*
|
|
76
|
+
* TypeScript should use this as the source of truth instead of hardcoding
|
|
77
|
+
* its own constant. When this value is bumped in Rust, the version control
|
|
78
|
+
* system will automatically handle migration bookkeeping (closing old chains,
|
|
79
|
+
* recording migrations) the next time a checkpoint or delta is created.
|
|
83
80
|
*/
|
|
84
|
-
export function
|
|
81
|
+
export function getCurrentSchemaVersion(): number;
|
|
85
82
|
/**
|
|
86
|
-
*
|
|
83
|
+
* Restore the document state at `version_number` from a `.duc` file buffer.
|
|
87
84
|
*
|
|
88
|
-
*
|
|
85
|
+
* The `.duc` file is a SQLite database — this function opens it and queries
|
|
86
|
+
* the `checkpoints` / `deltas` tables directly for version restoration.
|
|
87
|
+
*
|
|
88
|
+
* Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
|
|
89
89
|
*/
|
|
90
|
-
export function
|
|
90
|
+
export function restoreVersion(duc_buf: Uint8Array, version_number: number): any;
|
|
91
91
|
|
|
92
92
|
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
93
93
|
|
package/dist/ducjs_wasm.js
CHANGED
|
@@ -195,19 +195,16 @@ function takeFromExternrefTable0(idx) {
|
|
|
195
195
|
return value;
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
198
|
-
*
|
|
198
|
+
* Parse a `.duc` file lazily — returns everything EXCEPT external file data blobs.
|
|
199
199
|
*
|
|
200
|
-
*
|
|
200
|
+
* Use `getExternalFile()` or `listExternalFiles()` for on-demand access.
|
|
201
201
|
* @param {Uint8Array} buf
|
|
202
|
-
* @param {string} file_id
|
|
203
202
|
* @returns {any}
|
|
204
203
|
*/
|
|
205
|
-
export function
|
|
204
|
+
export function parseDucLazy(buf) {
|
|
206
205
|
const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
|
|
207
206
|
const len0 = WASM_VECTOR_LEN;
|
|
208
|
-
const
|
|
209
|
-
const len1 = WASM_VECTOR_LEN;
|
|
210
|
-
const ret = wasm.getExternalFile(ptr0, len0, ptr1, len1);
|
|
207
|
+
const ret = wasm.parseDucLazy(ptr0, len0);
|
|
211
208
|
if (ret[2]) {
|
|
212
209
|
throw takeFromExternrefTable0(ret[1]);
|
|
213
210
|
}
|
|
@@ -215,19 +212,16 @@ export function getExternalFile(buf, file_id) {
|
|
|
215
212
|
}
|
|
216
213
|
|
|
217
214
|
/**
|
|
218
|
-
*
|
|
215
|
+
* List all versions (checkpoints + deltas) from a `.duc` file buffer.
|
|
219
216
|
*
|
|
220
|
-
* Returns a JS
|
|
217
|
+
* Returns a JS array of `VersionEntry` objects (no heavy data blobs).
|
|
221
218
|
* @param {Uint8Array} duc_buf
|
|
222
|
-
* @param {string} checkpoint_id
|
|
223
219
|
* @returns {any}
|
|
224
220
|
*/
|
|
225
|
-
export function
|
|
221
|
+
export function listVersions(duc_buf) {
|
|
226
222
|
const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
|
|
227
223
|
const len0 = WASM_VECTOR_LEN;
|
|
228
|
-
const
|
|
229
|
-
const len1 = WASM_VECTOR_LEN;
|
|
230
|
-
const ret = wasm.restoreCheckpoint(ptr0, len0, ptr1, len1);
|
|
224
|
+
const ret = wasm.listVersions(ptr0, len0);
|
|
231
225
|
if (ret[2]) {
|
|
232
226
|
throw takeFromExternrefTable0(ret[1]);
|
|
233
227
|
}
|
|
@@ -235,16 +229,14 @@ export function restoreCheckpoint(duc_buf, checkpoint_id) {
|
|
|
235
229
|
}
|
|
236
230
|
|
|
237
231
|
/**
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
* Returns a JS array of `VersionEntry` objects (no heavy data blobs).
|
|
241
|
-
* @param {Uint8Array} duc_buf
|
|
232
|
+
* Parse a `.duc` file (Uint8Array) into a JS object (ExportedDataState).
|
|
233
|
+
* @param {Uint8Array} buf
|
|
242
234
|
* @returns {any}
|
|
243
235
|
*/
|
|
244
|
-
export function
|
|
245
|
-
const ptr0 = passArray8ToWasm0(
|
|
236
|
+
export function parseDuc(buf) {
|
|
237
|
+
const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
|
|
246
238
|
const len0 = WASM_VECTOR_LEN;
|
|
247
|
-
const ret = wasm.
|
|
239
|
+
const ret = wasm.parseDuc(ptr0, len0);
|
|
248
240
|
if (ret[2]) {
|
|
249
241
|
throw takeFromExternrefTable0(ret[1]);
|
|
250
242
|
}
|
|
@@ -270,37 +262,56 @@ export function readVersionGraph(duc_buf) {
|
|
|
270
262
|
}
|
|
271
263
|
|
|
272
264
|
/**
|
|
273
|
-
*
|
|
265
|
+
* Apply a changeset to reconstruct document state.
|
|
274
266
|
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
267
|
+
* `base_state` must be the exact checkpoint data used when the changeset
|
|
268
|
+
* was created. Returns the full document state as `Uint8Array`.
|
|
269
|
+
*
|
|
270
|
+
* Handles all changeset formats transparently:
|
|
271
|
+
* - v3 (bsdiff), v2 (XOR diff), v1 (zlib full snapshot)
|
|
272
|
+
* @param {Uint8Array} base_state
|
|
273
|
+
* @param {Uint8Array} changeset
|
|
274
|
+
* @returns {Uint8Array}
|
|
280
275
|
*/
|
|
281
|
-
export function
|
|
282
|
-
|
|
276
|
+
export function applyDeltaChangeset(base_state, changeset) {
|
|
277
|
+
const ptr0 = passArray8ToWasm0(base_state, wasm.__wbindgen_malloc);
|
|
278
|
+
const len0 = WASM_VECTOR_LEN;
|
|
279
|
+
const ptr1 = passArray8ToWasm0(changeset, wasm.__wbindgen_malloc);
|
|
280
|
+
const len1 = WASM_VECTOR_LEN;
|
|
281
|
+
const ret = wasm.applyDeltaChangeset(ptr0, len0, ptr1, len1);
|
|
282
|
+
if (ret[3]) {
|
|
283
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
284
|
+
}
|
|
285
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
286
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
287
|
+
return v3;
|
|
283
288
|
}
|
|
284
289
|
|
|
285
290
|
/**
|
|
286
|
-
*
|
|
291
|
+
* Compute a checkpoint-relative binary diff changeset using bsdiff.
|
|
287
292
|
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
293
|
+
* `base_state` is the checkpoint's full data blob.
|
|
294
|
+
* `current_state` is the full document state at the new version.
|
|
290
295
|
*
|
|
291
|
-
* Returns
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
* @
|
|
296
|
+
* Returns an encoded changeset (`Uint8Array`) ready for storage in a
|
|
297
|
+
* `Delta.payload`. bsdiff finds matching blocks even when they shift
|
|
298
|
+
* offsets, which is critical for SQLite databases.
|
|
299
|
+
* @param {Uint8Array} base_state
|
|
300
|
+
* @param {Uint8Array} current_state
|
|
301
|
+
* @returns {Uint8Array}
|
|
295
302
|
*/
|
|
296
|
-
export function
|
|
297
|
-
const ptr0 = passArray8ToWasm0(
|
|
303
|
+
export function createDeltaChangeset(base_state, current_state) {
|
|
304
|
+
const ptr0 = passArray8ToWasm0(base_state, wasm.__wbindgen_malloc);
|
|
298
305
|
const len0 = WASM_VECTOR_LEN;
|
|
299
|
-
const
|
|
300
|
-
|
|
301
|
-
|
|
306
|
+
const ptr1 = passArray8ToWasm0(current_state, wasm.__wbindgen_malloc);
|
|
307
|
+
const len1 = WASM_VECTOR_LEN;
|
|
308
|
+
const ret = wasm.createDeltaChangeset(ptr0, len0, ptr1, len1);
|
|
309
|
+
if (ret[3]) {
|
|
310
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
302
311
|
}
|
|
303
|
-
|
|
312
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
313
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
314
|
+
return v3;
|
|
304
315
|
}
|
|
305
316
|
|
|
306
317
|
/**
|
|
@@ -322,29 +333,23 @@ export function revertToVersion(duc_buf, target_version) {
|
|
|
322
333
|
}
|
|
323
334
|
|
|
324
335
|
/**
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
* `base_state` must be the exact checkpoint data used when the changeset
|
|
328
|
-
* was created. Returns the full document state as `Uint8Array`.
|
|
336
|
+
* Restore a specific checkpoint by its ID from a `.duc` file buffer.
|
|
329
337
|
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
* @param {
|
|
333
|
-
* @
|
|
334
|
-
* @returns {Uint8Array}
|
|
338
|
+
* Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
|
|
339
|
+
* @param {Uint8Array} duc_buf
|
|
340
|
+
* @param {string} checkpoint_id
|
|
341
|
+
* @returns {any}
|
|
335
342
|
*/
|
|
336
|
-
export function
|
|
337
|
-
const ptr0 = passArray8ToWasm0(
|
|
343
|
+
export function restoreCheckpoint(duc_buf, checkpoint_id) {
|
|
344
|
+
const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
|
|
338
345
|
const len0 = WASM_VECTOR_LEN;
|
|
339
|
-
const ptr1 =
|
|
346
|
+
const ptr1 = passStringToWasm0(checkpoint_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
340
347
|
const len1 = WASM_VECTOR_LEN;
|
|
341
|
-
const ret = wasm.
|
|
342
|
-
if (ret[
|
|
343
|
-
throw takeFromExternrefTable0(ret[
|
|
348
|
+
const ret = wasm.restoreCheckpoint(ptr0, len0, ptr1, len1);
|
|
349
|
+
if (ret[2]) {
|
|
350
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
344
351
|
}
|
|
345
|
-
|
|
346
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
347
|
-
return v3;
|
|
352
|
+
return takeFromExternrefTable0(ret[0]);
|
|
348
353
|
}
|
|
349
354
|
|
|
350
355
|
/**
|
|
@@ -378,41 +383,19 @@ export function serializeDuc(data) {
|
|
|
378
383
|
}
|
|
379
384
|
|
|
380
385
|
/**
|
|
381
|
-
*
|
|
382
|
-
*
|
|
383
|
-
* `base_state` is the checkpoint's full data blob.
|
|
384
|
-
* `current_state` is the full document state at the new version.
|
|
386
|
+
* Fetch a single external file from a `.duc` buffer by file ID.
|
|
385
387
|
*
|
|
386
|
-
* Returns
|
|
387
|
-
* `Delta.payload`. bsdiff finds matching blocks even when they shift
|
|
388
|
-
* offsets, which is critical for SQLite databases.
|
|
389
|
-
* @param {Uint8Array} base_state
|
|
390
|
-
* @param {Uint8Array} current_state
|
|
391
|
-
* @returns {Uint8Array}
|
|
392
|
-
*/
|
|
393
|
-
export function createDeltaChangeset(base_state, current_state) {
|
|
394
|
-
const ptr0 = passArray8ToWasm0(base_state, wasm.__wbindgen_malloc);
|
|
395
|
-
const len0 = WASM_VECTOR_LEN;
|
|
396
|
-
const ptr1 = passArray8ToWasm0(current_state, wasm.__wbindgen_malloc);
|
|
397
|
-
const len1 = WASM_VECTOR_LEN;
|
|
398
|
-
const ret = wasm.createDeltaChangeset(ptr0, len0, ptr1, len1);
|
|
399
|
-
if (ret[3]) {
|
|
400
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
401
|
-
}
|
|
402
|
-
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
403
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
404
|
-
return v3;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
/**
|
|
408
|
-
* Parse a `.duc` file (Uint8Array) into a JS object (ExportedDataState).
|
|
388
|
+
* Returns the file entry as a JS object, or `undefined` if not found.
|
|
409
389
|
* @param {Uint8Array} buf
|
|
390
|
+
* @param {string} file_id
|
|
410
391
|
* @returns {any}
|
|
411
392
|
*/
|
|
412
|
-
export function
|
|
393
|
+
export function getExternalFile(buf, file_id) {
|
|
413
394
|
const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
|
|
414
395
|
const len0 = WASM_VECTOR_LEN;
|
|
415
|
-
const
|
|
396
|
+
const ptr1 = passStringToWasm0(file_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
397
|
+
const len1 = WASM_VECTOR_LEN;
|
|
398
|
+
const ret = wasm.getExternalFile(ptr0, len0, ptr1, len1);
|
|
416
399
|
if (ret[2]) {
|
|
417
400
|
throw takeFromExternrefTable0(ret[1]);
|
|
418
401
|
}
|
|
@@ -420,16 +403,33 @@ export function parseDuc(buf) {
|
|
|
420
403
|
}
|
|
421
404
|
|
|
422
405
|
/**
|
|
423
|
-
*
|
|
406
|
+
* Returns the current version-control schema version defined in Rust.
|
|
424
407
|
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
408
|
+
* TypeScript should use this as the source of truth instead of hardcoding
|
|
409
|
+
* its own constant. When this value is bumped in Rust, the version control
|
|
410
|
+
* system will automatically handle migration bookkeeping (closing old chains,
|
|
411
|
+
* recording migrations) the next time a checkpoint or delta is created.
|
|
412
|
+
* @returns {number}
|
|
413
|
+
*/
|
|
414
|
+
export function getCurrentSchemaVersion() {
|
|
415
|
+
return 3000003;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
/**
|
|
419
|
+
* Restore the document state at `version_number` from a `.duc` file buffer.
|
|
420
|
+
*
|
|
421
|
+
* The `.duc` file is a SQLite database — this function opens it and queries
|
|
422
|
+
* the `checkpoints` / `deltas` tables directly for version restoration.
|
|
423
|
+
*
|
|
424
|
+
* Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
|
|
425
|
+
* @param {Uint8Array} duc_buf
|
|
426
|
+
* @param {number} version_number
|
|
427
427
|
* @returns {any}
|
|
428
428
|
*/
|
|
429
|
-
export function
|
|
430
|
-
const ptr0 = passArray8ToWasm0(
|
|
429
|
+
export function restoreVersion(duc_buf, version_number) {
|
|
430
|
+
const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
|
|
431
431
|
const len0 = WASM_VECTOR_LEN;
|
|
432
|
-
const ret = wasm.
|
|
432
|
+
const ret = wasm.restoreVersion(ptr0, len0, version_number);
|
|
433
433
|
if (ret[2]) {
|
|
434
434
|
throw takeFromExternrefTable0(ret[1]);
|
|
435
435
|
}
|
package/dist/ducjs_wasm_bg.wasm
CHANGED
|
Binary file
|
|
@@ -240,7 +240,11 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
|
|
|
240
240
|
? repairBinding(element, endBinding, currentScope, restoredBlocks)
|
|
241
241
|
: null;
|
|
242
242
|
// Create the base restored element
|
|
243
|
+
// Skip sizeFromPoints override for block instance elements: their stored
|
|
244
|
+
// width/height represents the total duplication grid, not single-cell dims.
|
|
245
|
+
const isBlockInstanceElement = !!element.instanceId;
|
|
243
246
|
const sizeFromPoints = !hasBindings &&
|
|
247
|
+
!isBlockInstanceElement &&
|
|
244
248
|
getSizeFromPoints(finalPoints.map(getScopedBezierPointFromDucPoint));
|
|
245
249
|
let restoredElement = restoreElementWithProperties(element, Object.assign({ points: finalPoints, lines, lastCommittedPoint: element.lastCommittedPoint
|
|
246
250
|
? restorePoint(element.lastCommittedPoint, element.scope, currentScope)
|
|
@@ -329,7 +333,7 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
|
|
|
329
333
|
modelType: isValidString(modelElement.modelType) || null,
|
|
330
334
|
code: isValidString(modelElement.code) || null,
|
|
331
335
|
fileIds: modelElement.fileIds || [],
|
|
332
|
-
|
|
336
|
+
thumbnail: modelElement.thumbnail instanceof Uint8Array ? modelElement.thumbnail : null,
|
|
333
337
|
viewerState: (modelElement.viewerState || null),
|
|
334
338
|
}, localState, globalState);
|
|
335
339
|
}
|
package/dist/transform.js
CHANGED
|
@@ -284,14 +284,95 @@ function fixElementFromRust(el) {
|
|
|
284
284
|
return el;
|
|
285
285
|
return Object.assign(Object.assign({}, rest), { isCollapsed: (_c = stackBase.isCollapsed) !== null && _c !== void 0 ? _c : false });
|
|
286
286
|
}
|
|
287
|
+
function normalizeViewer3DStateForRust(vs) {
|
|
288
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
289
|
+
if (!vs || typeof vs !== "object")
|
|
290
|
+
return vs;
|
|
291
|
+
const n = (v, fallback) => typeof v === "number" && Number.isFinite(v) ? v : fallback;
|
|
292
|
+
const b = (v, fallback) => typeof v === "boolean" ? v : fallback;
|
|
293
|
+
const s = (v, fallback) => typeof v === "string" ? v : fallback;
|
|
294
|
+
const arr3 = (v, fallback) => Array.isArray(v) && v.length === 3 && v.every((x) => typeof x === "number")
|
|
295
|
+
? v
|
|
296
|
+
: fallback;
|
|
297
|
+
const arr4 = (v, fallback) => Array.isArray(v) && v.length === 4 && v.every((x) => typeof x === "number")
|
|
298
|
+
? v
|
|
299
|
+
: fallback;
|
|
300
|
+
const cam = (_a = vs.camera) !== null && _a !== void 0 ? _a : {};
|
|
301
|
+
const dsp = (_b = vs.display) !== null && _b !== void 0 ? _b : {};
|
|
302
|
+
const mat = (_c = vs.material) !== null && _c !== void 0 ? _c : {};
|
|
303
|
+
const clip = (_d = vs.clipping) !== null && _d !== void 0 ? _d : {};
|
|
304
|
+
const expl = (_e = vs.explode) !== null && _e !== void 0 ? _e : {};
|
|
305
|
+
const zeb = (_f = vs.zebra) !== null && _f !== void 0 ? _f : {};
|
|
306
|
+
const normalizeClipPlane = (cp) => ({
|
|
307
|
+
enabled: b(cp === null || cp === void 0 ? void 0 : cp.enabled, false),
|
|
308
|
+
value: n(cp === null || cp === void 0 ? void 0 : cp.value, 0),
|
|
309
|
+
normal: (cp === null || cp === void 0 ? void 0 : cp.normal) != null ? arr3(cp.normal, [0, 0, 0]) : null,
|
|
310
|
+
});
|
|
311
|
+
return {
|
|
312
|
+
camera: {
|
|
313
|
+
control: s(cam.control, "orbit"),
|
|
314
|
+
ortho: b(cam.ortho, true),
|
|
315
|
+
up: s(cam.up, "Z"),
|
|
316
|
+
position: arr3(cam.position, [0, 0, 0]),
|
|
317
|
+
quaternion: arr4(cam.quaternion, [0, 0, 0, 1]),
|
|
318
|
+
target: arr3(cam.target, [0, 0, 0]),
|
|
319
|
+
zoom: n(cam.zoom, 1),
|
|
320
|
+
panSpeed: n(cam.panSpeed, 1),
|
|
321
|
+
rotateSpeed: n(cam.rotateSpeed, 1),
|
|
322
|
+
zoomSpeed: n(cam.zoomSpeed, 1),
|
|
323
|
+
holroyd: b(cam.holroyd, false),
|
|
324
|
+
},
|
|
325
|
+
display: {
|
|
326
|
+
wireframe: b(dsp.wireframe, false),
|
|
327
|
+
transparent: b(dsp.transparent, false),
|
|
328
|
+
blackEdges: b(dsp.blackEdges, true),
|
|
329
|
+
grid: (_g = dsp.grid) !== null && _g !== void 0 ? _g : { type: "uniform", value: false },
|
|
330
|
+
axesVisible: b(dsp.axesVisible, false),
|
|
331
|
+
axesAtOrigin: b(dsp.axesAtOrigin, true),
|
|
332
|
+
},
|
|
333
|
+
material: {
|
|
334
|
+
metalness: n(mat.metalness, 0.3),
|
|
335
|
+
roughness: n(mat.roughness, 0.65),
|
|
336
|
+
defaultOpacity: n(mat.defaultOpacity, 0.5),
|
|
337
|
+
edgeColor: n(mat.edgeColor, 0x707070),
|
|
338
|
+
ambientIntensity: n(mat.ambientIntensity, 1.0),
|
|
339
|
+
directIntensity: n(mat.directIntensity, 1.1),
|
|
340
|
+
},
|
|
341
|
+
clipping: {
|
|
342
|
+
x: normalizeClipPlane(clip.x),
|
|
343
|
+
y: normalizeClipPlane(clip.y),
|
|
344
|
+
z: normalizeClipPlane(clip.z),
|
|
345
|
+
intersection: b(clip.intersection, false),
|
|
346
|
+
showPlanes: b(clip.showPlanes, false),
|
|
347
|
+
objectColorCaps: b(clip.objectColorCaps, false),
|
|
348
|
+
},
|
|
349
|
+
explode: {
|
|
350
|
+
active: b(expl.active, false),
|
|
351
|
+
value: n(expl.value, 0),
|
|
352
|
+
},
|
|
353
|
+
zebra: {
|
|
354
|
+
active: b(zeb.active, false),
|
|
355
|
+
stripeCount: toInteger(zeb.stripeCount, 6),
|
|
356
|
+
stripeDirection: n(zeb.stripeDirection, 0),
|
|
357
|
+
colorScheme: s(zeb.colorScheme, "blackwhite"),
|
|
358
|
+
opacity: n(zeb.opacity, 1),
|
|
359
|
+
mappingMode: s(zeb.mappingMode, "reflection"),
|
|
360
|
+
},
|
|
361
|
+
};
|
|
362
|
+
}
|
|
287
363
|
function fixElementToRust(el) {
|
|
288
364
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
289
365
|
if (!el)
|
|
290
366
|
return el;
|
|
291
367
|
fixStylesHatch(el, false);
|
|
292
368
|
fixCustomDataToRust(el);
|
|
293
|
-
if (el.type === "model"
|
|
294
|
-
|
|
369
|
+
if (el.type === "model") {
|
|
370
|
+
if (el.viewerState) {
|
|
371
|
+
el.viewerState = normalizeViewer3DStateForRust(el.viewerState);
|
|
372
|
+
}
|
|
373
|
+
if ((_b = (_a = el.viewerState) === null || _a === void 0 ? void 0 : _a.display) === null || _b === void 0 ? void 0 : _b.grid) {
|
|
374
|
+
el.viewerState = Object.assign(Object.assign({}, el.viewerState), { display: Object.assign(Object.assign({}, el.viewerState.display), { grid: fixViewer3DGridToRust(el.viewerState.display.grid) }) });
|
|
375
|
+
}
|
|
295
376
|
}
|
|
296
377
|
// Convert TypeScript DucLine tuples [start, end] → Rust structs { start, end }
|
|
297
378
|
if (LINEAR_ELEMENT_TYPES.has(el.type) && Array.isArray(el.lines)) {
|
|
@@ -349,6 +430,9 @@ function flattenPrecisionValues(obj) {
|
|
|
349
430
|
return obj.value;
|
|
350
431
|
if (Array.isArray(obj))
|
|
351
432
|
return obj.map(flattenPrecisionValues);
|
|
433
|
+
if (ArrayBuffer.isView(obj) || obj instanceof ArrayBuffer) {
|
|
434
|
+
return obj;
|
|
435
|
+
}
|
|
352
436
|
if (typeof obj === "object") {
|
|
353
437
|
const out = {};
|
|
354
438
|
for (const key in obj) {
|
|
@@ -846,8 +846,8 @@ export type DucModelElement = _DucElementBase & {
|
|
|
846
846
|
modelType: string | null;
|
|
847
847
|
/** Defines the source code of the model using build123d python code */
|
|
848
848
|
code: string | null;
|
|
849
|
-
/** The last known
|
|
850
|
-
|
|
849
|
+
/** The last known image thumbnail of the 3D model for quick rendering on the canvas */
|
|
850
|
+
thumbnail: Uint8Array | null;
|
|
851
851
|
/** Possibly connected external files, such as STEP, STL, DXF, etc. */
|
|
852
852
|
fileIds: ExternalFileId[];
|
|
853
853
|
/** The last known 3D viewer state for the model */
|
package/dist/types/index.d.ts
CHANGED
|
@@ -101,7 +101,7 @@ export type SuggestedPointBinding = [
|
|
|
101
101
|
"start" | "end" | "both",
|
|
102
102
|
NonDeleted<DucBindableElement>
|
|
103
103
|
];
|
|
104
|
-
export type ToolType = "selection" | "rectangle" | "polygon" | "ellipse" | "line" | "freedraw" | "text" | "image" | "eraser" | "hand" | "frame" | "plot" | "embeddable" | "ruler" | "lasso" | "laser" | "table" | "doc" | "pdf";
|
|
104
|
+
export type ToolType = "selection" | "rectangle" | "polygon" | "ellipse" | "line" | "freedraw" | "text" | "image" | "eraser" | "hand" | "frame" | "plot" | "embeddable" | "ruler" | "lasso" | "laser" | "table" | "doc" | "pdf" | "model";
|
|
105
105
|
export type ElementOrToolType = DucElementType | ToolType | "custom";
|
|
106
106
|
/**
|
|
107
107
|
* Defines the global, persistent settings for the drawing. These are fundamental
|
|
@@ -159,7 +159,7 @@ export const newDocElement = (currentScope, opts) => {
|
|
|
159
159
|
} }));
|
|
160
160
|
};
|
|
161
161
|
export const newPdfElement = (currentScope, opts) => (Object.assign(Object.assign({ fileId: null, gridConfig: { columns: 1, gapX: 0, gapY: 0, firstPageAlone: false, scale: 1 } }, _newElementBase("pdf", currentScope, opts)), { type: "pdf" }));
|
|
162
|
-
export const newModelElement = (currentScope, opts) => (Object.assign(Object.assign({ modelType: null, code: null,
|
|
162
|
+
export const newModelElement = (currentScope, opts) => (Object.assign(Object.assign({ modelType: null, code: null, thumbnail: null, fileIds: [], viewerState: null }, _newElementBase("model", currentScope, opts)), { type: 'model' }));
|
|
163
163
|
// Simplified deep clone for the purpose of cloning DucElement.
|
|
164
164
|
//
|
|
165
165
|
// Only clones plain objects and arrays. Doesn't clone Date, RegExp, Map, Set,
|
|
@@ -174,6 +174,9 @@ const _deepCopyElement = (val, depth = 0) => {
|
|
|
174
174
|
if (val == null || typeof val !== "object") {
|
|
175
175
|
return val;
|
|
176
176
|
}
|
|
177
|
+
if (ArrayBuffer.isView(val)) {
|
|
178
|
+
return val.slice(0);
|
|
179
|
+
}
|
|
177
180
|
const objectType = Object.prototype.toString.call(val);
|
|
178
181
|
if (objectType === "[object Object]") {
|
|
179
182
|
const tmp = typeof val.constructor === "function"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ducjs",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "The duc 2D CAD file format is a cornerstone of our advanced design system, conceived to cater to professionals seeking precision and efficiency in their design work.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|