ducjs 3.2.0 → 3.2.2
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 +45 -45
- package/dist/ducjs_wasm.js +116 -116
- package/dist/ducjs_wasm_bg.wasm +0 -0
- package/dist/restore/restoreDataState.d.ts +1 -1
- package/dist/restore/restoreDataState.js +25 -6
- 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,30 +1,47 @@
|
|
|
1
1
|
/* tslint:disable */
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Read the full VersionGraph from a `.duc` file buffer.
|
|
5
5
|
*
|
|
6
|
-
* Returns
|
|
6
|
+
* Returns a JS object matching the `VersionGraph` TypeScript interface,
|
|
7
|
+
* or `undefined` if no version graph exists.
|
|
7
8
|
*/
|
|
8
|
-
export function
|
|
9
|
+
export function readVersionGraph(duc_buf: Uint8Array): any;
|
|
9
10
|
/**
|
|
10
|
-
*
|
|
11
|
+
* Compute a checkpoint-relative binary diff changeset using bsdiff.
|
|
11
12
|
*
|
|
12
|
-
*
|
|
13
|
+
* `base_state` is the checkpoint's full data blob.
|
|
14
|
+
* `current_state` is the full document state at the new version.
|
|
15
|
+
*
|
|
16
|
+
* Returns an encoded changeset (`Uint8Array`) ready for storage in a
|
|
17
|
+
* `Delta.payload`. bsdiff finds matching blocks even when they shift
|
|
18
|
+
* offsets, which is critical for SQLite databases.
|
|
13
19
|
*/
|
|
14
|
-
export function
|
|
20
|
+
export function createDeltaChangeset(base_state: Uint8Array, current_state: Uint8Array): Uint8Array;
|
|
15
21
|
/**
|
|
16
|
-
*
|
|
22
|
+
* Apply a changeset to reconstruct document state.
|
|
17
23
|
*
|
|
18
|
-
*
|
|
24
|
+
* `base_state` must be the exact checkpoint data used when the changeset
|
|
25
|
+
* was created. Returns the full document state as `Uint8Array`.
|
|
26
|
+
*
|
|
27
|
+
* Handles all changeset formats transparently:
|
|
28
|
+
* - v3 (bsdiff), v2 (XOR diff), v1 (zlib full snapshot)
|
|
19
29
|
*/
|
|
20
|
-
export function
|
|
30
|
+
export function applyDeltaChangeset(base_state: Uint8Array, changeset: Uint8Array): Uint8Array;
|
|
21
31
|
/**
|
|
22
|
-
*
|
|
32
|
+
* Parse a `.duc` file (Uint8Array) into a JS object (ExportedDataState).
|
|
33
|
+
*/
|
|
34
|
+
export function parseDuc(buf: Uint8Array): any;
|
|
35
|
+
/**
|
|
36
|
+
* Serialize a JS object (ExportedDataState) into `.duc` bytes (Uint8Array).
|
|
37
|
+
*/
|
|
38
|
+
export function serializeDuc(data: any): Uint8Array;
|
|
39
|
+
/**
|
|
40
|
+
* Fetch a single external file from a `.duc` buffer by file ID.
|
|
23
41
|
*
|
|
24
|
-
* Returns a JS object
|
|
25
|
-
* or `undefined` if no version graph exists.
|
|
42
|
+
* Returns the file entry as a JS object, or `undefined` if not found.
|
|
26
43
|
*/
|
|
27
|
-
export function
|
|
44
|
+
export function getExternalFile(buf: Uint8Array, file_id: string): any;
|
|
28
45
|
/**
|
|
29
46
|
* Returns the current version-control schema version defined in Rust.
|
|
30
47
|
*
|
|
@@ -34,15 +51,6 @@ export function readVersionGraph(duc_buf: Uint8Array): any;
|
|
|
34
51
|
* recording migrations) the next time a checkpoint or delta is created.
|
|
35
52
|
*/
|
|
36
53
|
export function getCurrentSchemaVersion(): number;
|
|
37
|
-
/**
|
|
38
|
-
* Restore the document state at `version_number` from a `.duc` file buffer.
|
|
39
|
-
*
|
|
40
|
-
* The `.duc` file is a SQLite database — this function opens it and queries
|
|
41
|
-
* the `checkpoints` / `deltas` tables directly for version restoration.
|
|
42
|
-
*
|
|
43
|
-
* Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
|
|
44
|
-
*/
|
|
45
|
-
export function restoreVersion(duc_buf: Uint8Array, version_number: number): any;
|
|
46
54
|
/**
|
|
47
55
|
* Revert the document to a specific version, removing all newer versions.
|
|
48
56
|
*
|
|
@@ -50,44 +58,36 @@ export function restoreVersion(duc_buf: Uint8Array, version_number: number): any
|
|
|
50
58
|
*/
|
|
51
59
|
export function revertToVersion(duc_buf: Uint8Array, target_version: number): any;
|
|
52
60
|
/**
|
|
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`.
|
|
61
|
+
* Restore a specific checkpoint by its ID from a `.duc` file buffer.
|
|
57
62
|
*
|
|
58
|
-
*
|
|
59
|
-
* - v3 (bsdiff), v2 (XOR diff), v1 (zlib full snapshot)
|
|
63
|
+
* Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
|
|
60
64
|
*/
|
|
61
|
-
export function
|
|
65
|
+
export function restoreCheckpoint(duc_buf: Uint8Array, checkpoint_id: string): any;
|
|
62
66
|
/**
|
|
63
67
|
* List metadata for all external files (without loading the heavy data blobs).
|
|
64
68
|
*/
|
|
65
69
|
export function listExternalFiles(buf: Uint8Array): any;
|
|
66
70
|
/**
|
|
67
|
-
*
|
|
68
|
-
*/
|
|
69
|
-
export function serializeDuc(data: any): Uint8Array;
|
|
70
|
-
/**
|
|
71
|
-
* Compute a checkpoint-relative binary diff changeset using bsdiff.
|
|
72
|
-
*
|
|
73
|
-
* `base_state` is the checkpoint's full data blob.
|
|
74
|
-
* `current_state` is the full document state at the new version.
|
|
71
|
+
* List all versions (checkpoints + deltas) from a `.duc` file buffer.
|
|
75
72
|
*
|
|
76
|
-
* Returns
|
|
77
|
-
* `Delta.payload`. bsdiff finds matching blocks even when they shift
|
|
78
|
-
* offsets, which is critical for SQLite databases.
|
|
79
|
-
*/
|
|
80
|
-
export function createDeltaChangeset(base_state: Uint8Array, current_state: Uint8Array): Uint8Array;
|
|
81
|
-
/**
|
|
82
|
-
* Parse a `.duc` file (Uint8Array) into a JS object (ExportedDataState).
|
|
73
|
+
* Returns a JS array of `VersionEntry` objects (no heavy data blobs).
|
|
83
74
|
*/
|
|
84
|
-
export function
|
|
75
|
+
export function listVersions(duc_buf: Uint8Array): any;
|
|
85
76
|
/**
|
|
86
77
|
* Parse a `.duc` file lazily — returns everything EXCEPT external file data blobs.
|
|
87
78
|
*
|
|
88
79
|
* Use `getExternalFile()` or `listExternalFiles()` for on-demand access.
|
|
89
80
|
*/
|
|
90
81
|
export function parseDucLazy(buf: Uint8Array): any;
|
|
82
|
+
/**
|
|
83
|
+
* Restore the document state at `version_number` from a `.duc` file buffer.
|
|
84
|
+
*
|
|
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
|
+
*/
|
|
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,17 @@ function takeFromExternrefTable0(idx) {
|
|
|
195
195
|
return value;
|
|
196
196
|
}
|
|
197
197
|
/**
|
|
198
|
-
*
|
|
198
|
+
* Read the full VersionGraph from a `.duc` file buffer.
|
|
199
199
|
*
|
|
200
|
-
* Returns
|
|
201
|
-
*
|
|
202
|
-
* @param {
|
|
200
|
+
* Returns a JS object matching the `VersionGraph` TypeScript interface,
|
|
201
|
+
* or `undefined` if no version graph exists.
|
|
202
|
+
* @param {Uint8Array} duc_buf
|
|
203
203
|
* @returns {any}
|
|
204
204
|
*/
|
|
205
|
-
export function
|
|
206
|
-
const ptr0 = passArray8ToWasm0(
|
|
205
|
+
export function readVersionGraph(duc_buf) {
|
|
206
|
+
const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
|
|
207
207
|
const len0 = WASM_VECTOR_LEN;
|
|
208
|
-
const
|
|
209
|
-
const len1 = WASM_VECTOR_LEN;
|
|
210
|
-
const ret = wasm.getExternalFile(ptr0, len0, ptr1, len1);
|
|
208
|
+
const ret = wasm.readVersionGraph(ptr0, len0);
|
|
211
209
|
if (ret[2]) {
|
|
212
210
|
throw takeFromExternrefTable0(ret[1]);
|
|
213
211
|
}
|
|
@@ -215,36 +213,67 @@ export function getExternalFile(buf, file_id) {
|
|
|
215
213
|
}
|
|
216
214
|
|
|
217
215
|
/**
|
|
218
|
-
*
|
|
216
|
+
* Compute a checkpoint-relative binary diff changeset using bsdiff.
|
|
219
217
|
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
218
|
+
* `base_state` is the checkpoint's full data blob.
|
|
219
|
+
* `current_state` is the full document state at the new version.
|
|
220
|
+
*
|
|
221
|
+
* Returns an encoded changeset (`Uint8Array`) ready for storage in a
|
|
222
|
+
* `Delta.payload`. bsdiff finds matching blocks even when they shift
|
|
223
|
+
* offsets, which is critical for SQLite databases.
|
|
224
|
+
* @param {Uint8Array} base_state
|
|
225
|
+
* @param {Uint8Array} current_state
|
|
226
|
+
* @returns {Uint8Array}
|
|
224
227
|
*/
|
|
225
|
-
export function
|
|
226
|
-
const ptr0 = passArray8ToWasm0(
|
|
228
|
+
export function createDeltaChangeset(base_state, current_state) {
|
|
229
|
+
const ptr0 = passArray8ToWasm0(base_state, wasm.__wbindgen_malloc);
|
|
227
230
|
const len0 = WASM_VECTOR_LEN;
|
|
228
|
-
const ptr1 =
|
|
231
|
+
const ptr1 = passArray8ToWasm0(current_state, wasm.__wbindgen_malloc);
|
|
229
232
|
const len1 = WASM_VECTOR_LEN;
|
|
230
|
-
const ret = wasm.
|
|
231
|
-
if (ret[
|
|
232
|
-
throw takeFromExternrefTable0(ret[
|
|
233
|
+
const ret = wasm.createDeltaChangeset(ptr0, len0, ptr1, len1);
|
|
234
|
+
if (ret[3]) {
|
|
235
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
233
236
|
}
|
|
234
|
-
|
|
237
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
238
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
239
|
+
return v3;
|
|
235
240
|
}
|
|
236
241
|
|
|
237
242
|
/**
|
|
238
|
-
*
|
|
243
|
+
* Apply a changeset to reconstruct document state.
|
|
239
244
|
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
245
|
+
* `base_state` must be the exact checkpoint data used when the changeset
|
|
246
|
+
* was created. Returns the full document state as `Uint8Array`.
|
|
247
|
+
*
|
|
248
|
+
* Handles all changeset formats transparently:
|
|
249
|
+
* - v3 (bsdiff), v2 (XOR diff), v1 (zlib full snapshot)
|
|
250
|
+
* @param {Uint8Array} base_state
|
|
251
|
+
* @param {Uint8Array} changeset
|
|
252
|
+
* @returns {Uint8Array}
|
|
253
|
+
*/
|
|
254
|
+
export function applyDeltaChangeset(base_state, changeset) {
|
|
255
|
+
const ptr0 = passArray8ToWasm0(base_state, wasm.__wbindgen_malloc);
|
|
256
|
+
const len0 = WASM_VECTOR_LEN;
|
|
257
|
+
const ptr1 = passArray8ToWasm0(changeset, wasm.__wbindgen_malloc);
|
|
258
|
+
const len1 = WASM_VECTOR_LEN;
|
|
259
|
+
const ret = wasm.applyDeltaChangeset(ptr0, len0, ptr1, len1);
|
|
260
|
+
if (ret[3]) {
|
|
261
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
262
|
+
}
|
|
263
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
264
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
265
|
+
return v3;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Parse a `.duc` file (Uint8Array) into a JS object (ExportedDataState).
|
|
270
|
+
* @param {Uint8Array} buf
|
|
242
271
|
* @returns {any}
|
|
243
272
|
*/
|
|
244
|
-
export function
|
|
245
|
-
const ptr0 = passArray8ToWasm0(
|
|
273
|
+
export function parseDuc(buf) {
|
|
274
|
+
const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
|
|
246
275
|
const len0 = WASM_VECTOR_LEN;
|
|
247
|
-
const ret = wasm.
|
|
276
|
+
const ret = wasm.parseDuc(ptr0, len0);
|
|
248
277
|
if (ret[2]) {
|
|
249
278
|
throw takeFromExternrefTable0(ret[1]);
|
|
250
279
|
}
|
|
@@ -252,17 +281,34 @@ export function listVersions(duc_buf) {
|
|
|
252
281
|
}
|
|
253
282
|
|
|
254
283
|
/**
|
|
255
|
-
*
|
|
284
|
+
* Serialize a JS object (ExportedDataState) into `.duc` bytes (Uint8Array).
|
|
285
|
+
* @param {any} data
|
|
286
|
+
* @returns {Uint8Array}
|
|
287
|
+
*/
|
|
288
|
+
export function serializeDuc(data) {
|
|
289
|
+
const ret = wasm.serializeDuc(data);
|
|
290
|
+
if (ret[3]) {
|
|
291
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
292
|
+
}
|
|
293
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
294
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
295
|
+
return v1;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Fetch a single external file from a `.duc` buffer by file ID.
|
|
256
300
|
*
|
|
257
|
-
* Returns a JS object
|
|
258
|
-
*
|
|
259
|
-
* @param {
|
|
301
|
+
* Returns the file entry as a JS object, or `undefined` if not found.
|
|
302
|
+
* @param {Uint8Array} buf
|
|
303
|
+
* @param {string} file_id
|
|
260
304
|
* @returns {any}
|
|
261
305
|
*/
|
|
262
|
-
export function
|
|
263
|
-
const ptr0 = passArray8ToWasm0(
|
|
306
|
+
export function getExternalFile(buf, file_id) {
|
|
307
|
+
const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
|
|
264
308
|
const len0 = WASM_VECTOR_LEN;
|
|
265
|
-
const
|
|
309
|
+
const ptr1 = passStringToWasm0(file_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
310
|
+
const len1 = WASM_VECTOR_LEN;
|
|
311
|
+
const ret = wasm.getExternalFile(ptr0, len0, ptr1, len1);
|
|
266
312
|
if (ret[2]) {
|
|
267
313
|
throw takeFromExternrefTable0(ret[1]);
|
|
268
314
|
}
|
|
@@ -279,24 +325,21 @@ export function readVersionGraph(duc_buf) {
|
|
|
279
325
|
* @returns {number}
|
|
280
326
|
*/
|
|
281
327
|
export function getCurrentSchemaVersion() {
|
|
282
|
-
return
|
|
328
|
+
return 3000003;
|
|
283
329
|
}
|
|
284
330
|
|
|
285
331
|
/**
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
* The `.duc` file is a SQLite database — this function opens it and queries
|
|
289
|
-
* the `checkpoints` / `deltas` tables directly for version restoration.
|
|
332
|
+
* Revert the document to a specific version, removing all newer versions.
|
|
290
333
|
*
|
|
291
334
|
* Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
|
|
292
335
|
* @param {Uint8Array} duc_buf
|
|
293
|
-
* @param {number}
|
|
336
|
+
* @param {number} target_version
|
|
294
337
|
* @returns {any}
|
|
295
338
|
*/
|
|
296
|
-
export function
|
|
339
|
+
export function revertToVersion(duc_buf, target_version) {
|
|
297
340
|
const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
|
|
298
341
|
const len0 = WASM_VECTOR_LEN;
|
|
299
|
-
const ret = wasm.
|
|
342
|
+
const ret = wasm.revertToVersion(ptr0, len0, target_version);
|
|
300
343
|
if (ret[2]) {
|
|
301
344
|
throw takeFromExternrefTable0(ret[1]);
|
|
302
345
|
}
|
|
@@ -304,49 +347,25 @@ export function restoreVersion(duc_buf, version_number) {
|
|
|
304
347
|
}
|
|
305
348
|
|
|
306
349
|
/**
|
|
307
|
-
*
|
|
350
|
+
* Restore a specific checkpoint by its ID from a `.duc` file buffer.
|
|
308
351
|
*
|
|
309
352
|
* Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
|
|
310
353
|
* @param {Uint8Array} duc_buf
|
|
311
|
-
* @param {
|
|
354
|
+
* @param {string} checkpoint_id
|
|
312
355
|
* @returns {any}
|
|
313
356
|
*/
|
|
314
|
-
export function
|
|
357
|
+
export function restoreCheckpoint(duc_buf, checkpoint_id) {
|
|
315
358
|
const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
|
|
316
359
|
const len0 = WASM_VECTOR_LEN;
|
|
317
|
-
const
|
|
360
|
+
const ptr1 = passStringToWasm0(checkpoint_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
361
|
+
const len1 = WASM_VECTOR_LEN;
|
|
362
|
+
const ret = wasm.restoreCheckpoint(ptr0, len0, ptr1, len1);
|
|
318
363
|
if (ret[2]) {
|
|
319
364
|
throw takeFromExternrefTable0(ret[1]);
|
|
320
365
|
}
|
|
321
366
|
return takeFromExternrefTable0(ret[0]);
|
|
322
367
|
}
|
|
323
368
|
|
|
324
|
-
/**
|
|
325
|
-
* Apply a changeset to reconstruct document state.
|
|
326
|
-
*
|
|
327
|
-
* `base_state` must be the exact checkpoint data used when the changeset
|
|
328
|
-
* was created. Returns the full document state as `Uint8Array`.
|
|
329
|
-
*
|
|
330
|
-
* Handles all changeset formats transparently:
|
|
331
|
-
* - v3 (bsdiff), v2 (XOR diff), v1 (zlib full snapshot)
|
|
332
|
-
* @param {Uint8Array} base_state
|
|
333
|
-
* @param {Uint8Array} changeset
|
|
334
|
-
* @returns {Uint8Array}
|
|
335
|
-
*/
|
|
336
|
-
export function applyDeltaChangeset(base_state, changeset) {
|
|
337
|
-
const ptr0 = passArray8ToWasm0(base_state, wasm.__wbindgen_malloc);
|
|
338
|
-
const len0 = WASM_VECTOR_LEN;
|
|
339
|
-
const ptr1 = passArray8ToWasm0(changeset, wasm.__wbindgen_malloc);
|
|
340
|
-
const len1 = WASM_VECTOR_LEN;
|
|
341
|
-
const ret = wasm.applyDeltaChangeset(ptr0, len0, ptr1, len1);
|
|
342
|
-
if (ret[3]) {
|
|
343
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
344
|
-
}
|
|
345
|
-
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
346
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
347
|
-
return v3;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
369
|
/**
|
|
351
370
|
* List metadata for all external files (without loading the heavy data blobs).
|
|
352
371
|
* @param {Uint8Array} buf
|
|
@@ -363,56 +382,33 @@ export function listExternalFiles(buf) {
|
|
|
363
382
|
}
|
|
364
383
|
|
|
365
384
|
/**
|
|
366
|
-
*
|
|
367
|
-
* @param {any} data
|
|
368
|
-
* @returns {Uint8Array}
|
|
369
|
-
*/
|
|
370
|
-
export function serializeDuc(data) {
|
|
371
|
-
const ret = wasm.serializeDuc(data);
|
|
372
|
-
if (ret[3]) {
|
|
373
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
374
|
-
}
|
|
375
|
-
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
376
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
377
|
-
return v1;
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Compute a checkpoint-relative binary diff changeset using bsdiff.
|
|
382
|
-
*
|
|
383
|
-
* `base_state` is the checkpoint's full data blob.
|
|
384
|
-
* `current_state` is the full document state at the new version.
|
|
385
|
+
* List all versions (checkpoints + deltas) from a `.duc` file buffer.
|
|
385
386
|
*
|
|
386
|
-
* Returns
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* @param {Uint8Array} base_state
|
|
390
|
-
* @param {Uint8Array} current_state
|
|
391
|
-
* @returns {Uint8Array}
|
|
387
|
+
* Returns a JS array of `VersionEntry` objects (no heavy data blobs).
|
|
388
|
+
* @param {Uint8Array} duc_buf
|
|
389
|
+
* @returns {any}
|
|
392
390
|
*/
|
|
393
|
-
export function
|
|
394
|
-
const ptr0 = passArray8ToWasm0(
|
|
391
|
+
export function listVersions(duc_buf) {
|
|
392
|
+
const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
|
|
395
393
|
const len0 = WASM_VECTOR_LEN;
|
|
396
|
-
const
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
if (ret[3]) {
|
|
400
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
394
|
+
const ret = wasm.listVersions(ptr0, len0);
|
|
395
|
+
if (ret[2]) {
|
|
396
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
401
397
|
}
|
|
402
|
-
|
|
403
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
404
|
-
return v3;
|
|
398
|
+
return takeFromExternrefTable0(ret[0]);
|
|
405
399
|
}
|
|
406
400
|
|
|
407
401
|
/**
|
|
408
|
-
* Parse a `.duc` file
|
|
402
|
+
* Parse a `.duc` file lazily — returns everything EXCEPT external file data blobs.
|
|
403
|
+
*
|
|
404
|
+
* Use `getExternalFile()` or `listExternalFiles()` for on-demand access.
|
|
409
405
|
* @param {Uint8Array} buf
|
|
410
406
|
* @returns {any}
|
|
411
407
|
*/
|
|
412
|
-
export function
|
|
408
|
+
export function parseDucLazy(buf) {
|
|
413
409
|
const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
|
|
414
410
|
const len0 = WASM_VECTOR_LEN;
|
|
415
|
-
const ret = wasm.
|
|
411
|
+
const ret = wasm.parseDucLazy(ptr0, len0);
|
|
416
412
|
if (ret[2]) {
|
|
417
413
|
throw takeFromExternrefTable0(ret[1]);
|
|
418
414
|
}
|
|
@@ -420,16 +416,20 @@ export function parseDuc(buf) {
|
|
|
420
416
|
}
|
|
421
417
|
|
|
422
418
|
/**
|
|
423
|
-
*
|
|
419
|
+
* Restore the document state at `version_number` from a `.duc` file buffer.
|
|
424
420
|
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
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
|
|
@@ -47,7 +47,7 @@ export type RestoreConfig = {
|
|
|
47
47
|
forceScope?: Scope;
|
|
48
48
|
};
|
|
49
49
|
export declare const restore: (data: ImportedDataState | null, elementsConfig: ElementsConfig, restoreConfig?: RestoreConfig) => RestoredDataState;
|
|
50
|
-
export declare const restoreFiles: (importedFiles: unknown) => DucExternalFiles;
|
|
50
|
+
export declare const restoreFiles: (importedFiles: unknown, restoredFilesData?: ExternalFilesData) => DucExternalFiles;
|
|
51
51
|
/**
|
|
52
52
|
* Restore external file data blobs from the split `filesData` field.
|
|
53
53
|
* Also extracts data from legacy inline `revisions[].data` when present.
|
|
@@ -20,6 +20,8 @@ export const restore = (data, elementsConfig, restoreConfig = {}) => {
|
|
|
20
20
|
const restoredBlockInstances = restoreBlockInstances(data === null || data === void 0 ? void 0 : data.blockInstances, restoredLocalState.scope);
|
|
21
21
|
const restoredElements = restoreElements(data === null || data === void 0 ? void 0 : data.elements, restoredLocalState.scope, restoredBlocks, restoredElementsConfig);
|
|
22
22
|
const restoredVersionGraph = restoreVersionGraph(data === null || data === void 0 ? void 0 : data.versionGraph);
|
|
23
|
+
const restoredFilesData = restoreFilesData(data === null || data === void 0 ? void 0 : data.filesData, data === null || data === void 0 ? void 0 : data.files);
|
|
24
|
+
const restoredFiles = restoreFiles(data === null || data === void 0 ? void 0 : data.files, restoredFilesData);
|
|
23
25
|
// Generate a new ID if none exists or if it's empty
|
|
24
26
|
const parsedId = data === null || data === void 0 ? void 0 : data.id;
|
|
25
27
|
const restoredId = (parsedId && parsedId.trim().length > 0) ? parsedId : nanoid();
|
|
@@ -36,12 +38,28 @@ export const restore = (data, elementsConfig, restoreConfig = {}) => {
|
|
|
36
38
|
versionGraph: restoredVersionGraph,
|
|
37
39
|
localState: restoredLocalState,
|
|
38
40
|
globalState: restoredGlobalState,
|
|
39
|
-
files:
|
|
40
|
-
filesData:
|
|
41
|
+
files: restoredFiles,
|
|
42
|
+
filesData: restoredFilesData,
|
|
41
43
|
id: restoredId,
|
|
42
44
|
};
|
|
43
45
|
};
|
|
44
|
-
|
|
46
|
+
const getRestoredRevisionSizeBytes = (rawSizeBytes, revisionId, restoredFilesData) => {
|
|
47
|
+
var _a, _b, _c;
|
|
48
|
+
const explicitSizeBytes = isFiniteNumber(rawSizeBytes)
|
|
49
|
+
? rawSizeBytes
|
|
50
|
+
: undefined;
|
|
51
|
+
if (typeof explicitSizeBytes === "number" && explicitSizeBytes > 0) {
|
|
52
|
+
return explicitSizeBytes;
|
|
53
|
+
}
|
|
54
|
+
return (_c = (_b = (_a = restoredFilesData[revisionId]) === null || _a === void 0 ? void 0 : _a.byteLength) !== null && _b !== void 0 ? _b : explicitSizeBytes) !== null && _c !== void 0 ? _c : 0;
|
|
55
|
+
};
|
|
56
|
+
const getRestoredSourceName = (fileData) => {
|
|
57
|
+
return isValidString(fileData.sourceName)
|
|
58
|
+
|| isValidString(fileData.fileName)
|
|
59
|
+
|| isValidString(fileData.name)
|
|
60
|
+
|| undefined;
|
|
61
|
+
};
|
|
62
|
+
export const restoreFiles = (importedFiles, restoredFilesData = {}) => {
|
|
45
63
|
if (!importedFiles || typeof importedFiles !== "object") {
|
|
46
64
|
return {};
|
|
47
65
|
}
|
|
@@ -74,9 +92,9 @@ export const restoreFiles = (importedFiles) => {
|
|
|
74
92
|
continue;
|
|
75
93
|
restoredRevisions[revKey] = {
|
|
76
94
|
id: revId,
|
|
77
|
-
sizeBytes:
|
|
95
|
+
sizeBytes: getRestoredRevisionSizeBytes(r.sizeBytes, revId, restoredFilesData),
|
|
78
96
|
checksum: isValidString(r.checksum) || undefined,
|
|
79
|
-
sourceName:
|
|
97
|
+
sourceName: getRestoredSourceName(r),
|
|
80
98
|
mimeType,
|
|
81
99
|
message: isValidString(r.message) || undefined,
|
|
82
100
|
created: isFiniteNumber(r.created) ? r.created : Date.now(),
|
|
@@ -113,7 +131,8 @@ export const restoreFiles = (importedFiles) => {
|
|
|
113
131
|
revisions: {
|
|
114
132
|
[revId]: {
|
|
115
133
|
id: revId,
|
|
116
|
-
sizeBytes:
|
|
134
|
+
sizeBytes: getRestoredRevisionSizeBytes(legacyData.sizeBytes, revId, restoredFilesData),
|
|
135
|
+
sourceName: getRestoredSourceName(legacyData),
|
|
117
136
|
mimeType,
|
|
118
137
|
created,
|
|
119
138
|
lastRetrieved: isFiniteNumber(legacyData.lastRetrieved)
|
|
@@ -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, false),
|
|
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.2",
|
|
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",
|