ducjs 3.2.1 → 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.
@@ -1,21 +1,5 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
- /**
4
- * Parse a `.duc` file lazily — returns everything EXCEPT external file data blobs.
5
- *
6
- * Use `getExternalFile()` or `listExternalFiles()` for on-demand access.
7
- */
8
- export function parseDucLazy(buf: Uint8Array): any;
9
- /**
10
- * List all versions (checkpoints + deltas) from a `.duc` file buffer.
11
- *
12
- * Returns a JS array of `VersionEntry` objects (no heavy data blobs).
13
- */
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;
19
3
  /**
20
4
  * Read the full VersionGraph from a `.duc` file buffer.
21
5
  *
@@ -23,16 +7,6 @@ export function parseDuc(buf: Uint8Array): any;
23
7
  * or `undefined` if no version graph exists.
24
8
  */
25
9
  export function readVersionGraph(duc_buf: Uint8Array): any;
26
- /**
27
- * Apply a changeset to reconstruct document state.
28
- *
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)
34
- */
35
- export function applyDeltaChangeset(base_state: Uint8Array, changeset: Uint8Array): Uint8Array;
36
10
  /**
37
11
  * Compute a checkpoint-relative binary diff changeset using bsdiff.
38
12
  *
@@ -45,21 +19,19 @@ export function applyDeltaChangeset(base_state: Uint8Array, changeset: Uint8Arra
45
19
  */
46
20
  export function createDeltaChangeset(base_state: Uint8Array, current_state: Uint8Array): Uint8Array;
47
21
  /**
48
- * Revert the document to a specific version, removing all newer versions.
22
+ * Apply a changeset to reconstruct document state.
49
23
  *
50
- * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
51
- */
52
- export function revertToVersion(duc_buf: Uint8Array, target_version: number): any;
53
- /**
54
- * Restore a specific checkpoint by its ID from a `.duc` file buffer.
24
+ * `base_state` must be the exact checkpoint data used when the changeset
25
+ * was created. Returns the full document state as `Uint8Array`.
55
26
  *
56
- * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
27
+ * Handles all changeset formats transparently:
28
+ * - v3 (bsdiff), v2 (XOR diff), v1 (zlib full snapshot)
57
29
  */
58
- export function restoreCheckpoint(duc_buf: Uint8Array, checkpoint_id: string): any;
30
+ export function applyDeltaChangeset(base_state: Uint8Array, changeset: Uint8Array): Uint8Array;
59
31
  /**
60
- * List metadata for all external files (without loading the heavy data blobs).
32
+ * Parse a `.duc` file (Uint8Array) into a JS object (ExportedDataState).
61
33
  */
62
- export function listExternalFiles(buf: Uint8Array): any;
34
+ export function parseDuc(buf: Uint8Array): any;
63
35
  /**
64
36
  * Serialize a JS object (ExportedDataState) into `.duc` bytes (Uint8Array).
65
37
  */
@@ -79,6 +51,34 @@ export function getExternalFile(buf: Uint8Array, file_id: string): any;
79
51
  * recording migrations) the next time a checkpoint or delta is created.
80
52
  */
81
53
  export function getCurrentSchemaVersion(): number;
54
+ /**
55
+ * Revert the document to a specific version, removing all newer versions.
56
+ *
57
+ * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
58
+ */
59
+ export function revertToVersion(duc_buf: Uint8Array, target_version: number): any;
60
+ /**
61
+ * Restore a specific checkpoint by its ID from a `.duc` file buffer.
62
+ *
63
+ * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
64
+ */
65
+ export function restoreCheckpoint(duc_buf: Uint8Array, checkpoint_id: string): any;
66
+ /**
67
+ * List metadata for all external files (without loading the heavy data blobs).
68
+ */
69
+ export function listExternalFiles(buf: Uint8Array): any;
70
+ /**
71
+ * List all versions (checkpoints + deltas) from a `.duc` file buffer.
72
+ *
73
+ * Returns a JS array of `VersionEntry` objects (no heavy data blobs).
74
+ */
75
+ export function listVersions(duc_buf: Uint8Array): any;
76
+ /**
77
+ * Parse a `.duc` file lazily — returns everything EXCEPT external file data blobs.
78
+ *
79
+ * Use `getExternalFile()` or `listExternalFiles()` for on-demand access.
80
+ */
81
+ export function parseDucLazy(buf: Uint8Array): any;
82
82
  /**
83
83
  * Restore the document state at `version_number` from a `.duc` file buffer.
84
84
  *
@@ -195,48 +195,17 @@ function takeFromExternrefTable0(idx) {
195
195
  return value;
196
196
  }
197
197
  /**
198
- * Parse a `.duc` file lazily — returns everything EXCEPT external file data blobs.
199
- *
200
- * Use `getExternalFile()` or `listExternalFiles()` for on-demand access.
201
- * @param {Uint8Array} buf
202
- * @returns {any}
203
- */
204
- export function parseDucLazy(buf) {
205
- const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
206
- const len0 = WASM_VECTOR_LEN;
207
- const ret = wasm.parseDucLazy(ptr0, len0);
208
- if (ret[2]) {
209
- throw takeFromExternrefTable0(ret[1]);
210
- }
211
- return takeFromExternrefTable0(ret[0]);
212
- }
213
-
214
- /**
215
- * List all versions (checkpoints + deltas) from a `.duc` file buffer.
198
+ * Read the full VersionGraph from a `.duc` file buffer.
216
199
  *
217
- * Returns a JS array of `VersionEntry` objects (no heavy data blobs).
200
+ * Returns a JS object matching the `VersionGraph` TypeScript interface,
201
+ * or `undefined` if no version graph exists.
218
202
  * @param {Uint8Array} duc_buf
219
203
  * @returns {any}
220
204
  */
221
- export function listVersions(duc_buf) {
205
+ export function readVersionGraph(duc_buf) {
222
206
  const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
223
207
  const len0 = WASM_VECTOR_LEN;
224
- const ret = wasm.listVersions(ptr0, len0);
225
- if (ret[2]) {
226
- throw takeFromExternrefTable0(ret[1]);
227
- }
228
- return takeFromExternrefTable0(ret[0]);
229
- }
230
-
231
- /**
232
- * Parse a `.duc` file (Uint8Array) into a JS object (ExportedDataState).
233
- * @param {Uint8Array} buf
234
- * @returns {any}
235
- */
236
- export function parseDuc(buf) {
237
- const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
238
- const len0 = WASM_VECTOR_LEN;
239
- const ret = wasm.parseDuc(ptr0, len0);
208
+ const ret = wasm.readVersionGraph(ptr0, len0);
240
209
  if (ret[2]) {
241
210
  throw takeFromExternrefTable0(ret[1]);
242
211
  }
@@ -244,21 +213,30 @@ export function parseDuc(buf) {
244
213
  }
245
214
 
246
215
  /**
247
- * Read the full VersionGraph from a `.duc` file buffer.
216
+ * Compute a checkpoint-relative binary diff changeset using bsdiff.
248
217
  *
249
- * Returns a JS object matching the `VersionGraph` TypeScript interface,
250
- * or `undefined` if no version graph exists.
251
- * @param {Uint8Array} duc_buf
252
- * @returns {any}
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}
253
227
  */
254
- export function readVersionGraph(duc_buf) {
255
- const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
228
+ export function createDeltaChangeset(base_state, current_state) {
229
+ const ptr0 = passArray8ToWasm0(base_state, wasm.__wbindgen_malloc);
256
230
  const len0 = WASM_VECTOR_LEN;
257
- const ret = wasm.readVersionGraph(ptr0, len0);
258
- if (ret[2]) {
259
- throw takeFromExternrefTable0(ret[1]);
231
+ const ptr1 = passArray8ToWasm0(current_state, wasm.__wbindgen_malloc);
232
+ const len1 = WASM_VECTOR_LEN;
233
+ const ret = wasm.createDeltaChangeset(ptr0, len0, ptr1, len1);
234
+ if (ret[3]) {
235
+ throw takeFromExternrefTable0(ret[2]);
260
236
  }
261
- return takeFromExternrefTable0(ret[0]);
237
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
238
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
239
+ return v3;
262
240
  }
263
241
 
264
242
  /**
@@ -288,30 +266,66 @@ export function applyDeltaChangeset(base_state, changeset) {
288
266
  }
289
267
 
290
268
  /**
291
- * Compute a checkpoint-relative binary diff changeset using bsdiff.
292
- *
293
- * `base_state` is the checkpoint's full data blob.
294
- * `current_state` is the full document state at the new version.
295
- *
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}
269
+ * Parse a `.duc` file (Uint8Array) into a JS object (ExportedDataState).
270
+ * @param {Uint8Array} buf
271
+ * @returns {any}
302
272
  */
303
- export function createDeltaChangeset(base_state, current_state) {
304
- const ptr0 = passArray8ToWasm0(base_state, wasm.__wbindgen_malloc);
273
+ export function parseDuc(buf) {
274
+ const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
305
275
  const len0 = WASM_VECTOR_LEN;
306
- const ptr1 = passArray8ToWasm0(current_state, wasm.__wbindgen_malloc);
307
- const len1 = WASM_VECTOR_LEN;
308
- const ret = wasm.createDeltaChangeset(ptr0, len0, ptr1, len1);
276
+ const ret = wasm.parseDuc(ptr0, len0);
277
+ if (ret[2]) {
278
+ throw takeFromExternrefTable0(ret[1]);
279
+ }
280
+ return takeFromExternrefTable0(ret[0]);
281
+ }
282
+
283
+ /**
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);
309
290
  if (ret[3]) {
310
291
  throw takeFromExternrefTable0(ret[2]);
311
292
  }
312
- var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
293
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
313
294
  wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
314
- return v3;
295
+ return v1;
296
+ }
297
+
298
+ /**
299
+ * Fetch a single external file from a `.duc` buffer by file ID.
300
+ *
301
+ * Returns the file entry as a JS object, or `undefined` if not found.
302
+ * @param {Uint8Array} buf
303
+ * @param {string} file_id
304
+ * @returns {any}
305
+ */
306
+ export function getExternalFile(buf, file_id) {
307
+ const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
308
+ const len0 = WASM_VECTOR_LEN;
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);
312
+ if (ret[2]) {
313
+ throw takeFromExternrefTable0(ret[1]);
314
+ }
315
+ return takeFromExternrefTable0(ret[0]);
316
+ }
317
+
318
+ /**
319
+ * Returns the current version-control schema version defined in Rust.
320
+ *
321
+ * TypeScript should use this as the source of truth instead of hardcoding
322
+ * its own constant. When this value is bumped in Rust, the version control
323
+ * system will automatically handle migration bookkeeping (closing old chains,
324
+ * recording migrations) the next time a checkpoint or delta is created.
325
+ * @returns {number}
326
+ */
327
+ export function getCurrentSchemaVersion() {
328
+ return 3000003;
315
329
  }
316
330
 
317
331
  /**
@@ -368,53 +382,39 @@ export function listExternalFiles(buf) {
368
382
  }
369
383
 
370
384
  /**
371
- * Serialize a JS object (ExportedDataState) into `.duc` bytes (Uint8Array).
372
- * @param {any} data
373
- * @returns {Uint8Array}
385
+ * List all versions (checkpoints + deltas) from a `.duc` file buffer.
386
+ *
387
+ * Returns a JS array of `VersionEntry` objects (no heavy data blobs).
388
+ * @param {Uint8Array} duc_buf
389
+ * @returns {any}
374
390
  */
375
- export function serializeDuc(data) {
376
- const ret = wasm.serializeDuc(data);
377
- if (ret[3]) {
378
- throw takeFromExternrefTable0(ret[2]);
391
+ export function listVersions(duc_buf) {
392
+ const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
393
+ const len0 = WASM_VECTOR_LEN;
394
+ const ret = wasm.listVersions(ptr0, len0);
395
+ if (ret[2]) {
396
+ throw takeFromExternrefTable0(ret[1]);
379
397
  }
380
- var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
381
- wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
382
- return v1;
398
+ return takeFromExternrefTable0(ret[0]);
383
399
  }
384
400
 
385
401
  /**
386
- * Fetch a single external file from a `.duc` buffer by file ID.
402
+ * Parse a `.duc` file lazily returns everything EXCEPT external file data blobs.
387
403
  *
388
- * Returns the file entry as a JS object, or `undefined` if not found.
404
+ * Use `getExternalFile()` or `listExternalFiles()` for on-demand access.
389
405
  * @param {Uint8Array} buf
390
- * @param {string} file_id
391
406
  * @returns {any}
392
407
  */
393
- export function getExternalFile(buf, file_id) {
408
+ export function parseDucLazy(buf) {
394
409
  const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
395
410
  const len0 = WASM_VECTOR_LEN;
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);
411
+ const ret = wasm.parseDucLazy(ptr0, len0);
399
412
  if (ret[2]) {
400
413
  throw takeFromExternrefTable0(ret[1]);
401
414
  }
402
415
  return takeFromExternrefTable0(ret[0]);
403
416
  }
404
417
 
405
- /**
406
- * Returns the current version-control schema version defined in Rust.
407
- *
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
418
  /**
419
419
  * Restore the document state at `version_number` from a `.duc` file buffer.
420
420
  *
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: restoreFiles(data === null || data === void 0 ? void 0 : data.files),
40
- filesData: restoreFilesData(data === null || data === void 0 ? void 0 : data.filesData, data === null || data === void 0 ? void 0 : data.files),
41
+ files: restoredFiles,
42
+ filesData: restoredFilesData,
41
43
  id: restoredId,
42
44
  };
43
45
  };
44
- export const restoreFiles = (importedFiles) => {
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: isFiniteNumber(r.sizeBytes) ? r.sizeBytes : 0,
95
+ sizeBytes: getRestoredRevisionSizeBytes(r.sizeBytes, revId, restoredFilesData),
78
96
  checksum: isValidString(r.checksum) || undefined,
79
- sourceName: isValidString(r.sourceName) || undefined,
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: 0,
134
+ sizeBytes: getRestoredRevisionSizeBytes(legacyData.sizeBytes, revId, restoredFilesData),
135
+ sourceName: getRestoredSourceName(legacyData),
117
136
  mimeType,
118
137
  created,
119
138
  lastRetrieved: isFiniteNumber(legacyData.lastRetrieved)
package/dist/transform.js CHANGED
@@ -328,7 +328,7 @@ function normalizeViewer3DStateForRust(vs) {
328
328
  blackEdges: b(dsp.blackEdges, true),
329
329
  grid: (_g = dsp.grid) !== null && _g !== void 0 ? _g : { type: "uniform", value: false },
330
330
  axesVisible: b(dsp.axesVisible, false),
331
- axesAtOrigin: b(dsp.axesAtOrigin, true),
331
+ axesAtOrigin: b(dsp.axesAtOrigin, false),
332
332
  },
333
333
  material: {
334
334
  metalness: n(mat.metalness, 0.3),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ducjs",
3
- "version": "3.2.1",
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",