ducjs 3.3.0 → 3.4.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.
@@ -1,12 +1,15 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  /**
4
- * Read the full VersionGraph from a `.duc` file buffer.
4
+ * Parse a `.duc` file (Uint8Array) into a JS object (ExportedDataState).
5
+ */
6
+ export function parseDuc(buf: Uint8Array): any;
7
+ /**
8
+ * Restore a specific checkpoint by its ID from a `.duc` file buffer.
5
9
  *
6
- * Returns a JS object matching the `VersionGraph` TypeScript interface,
7
- * or `undefined` if no version graph exists.
10
+ * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
8
11
  */
9
- export function readVersionGraph(duc_buf: Uint8Array): any;
12
+ export function restoreCheckpoint(duc_buf: Uint8Array, checkpoint_id: string): any;
10
13
  /**
11
14
  * Compute a checkpoint-relative binary diff changeset using bsdiff.
12
15
  *
@@ -18,6 +21,12 @@ export function readVersionGraph(duc_buf: Uint8Array): any;
18
21
  * offsets, which is critical for SQLite databases.
19
22
  */
20
23
  export function createDeltaChangeset(base_state: Uint8Array, current_state: Uint8Array): Uint8Array;
24
+ /**
25
+ * Fetch a single external file from a `.duc` buffer by file ID.
26
+ *
27
+ * Returns the file entry as a JS object, or `undefined` if not found.
28
+ */
29
+ export function getExternalFile(buf: Uint8Array, file_id: string): any;
21
30
  /**
22
31
  * Apply a changeset to reconstruct document state.
23
32
  *
@@ -29,44 +38,16 @@ export function createDeltaChangeset(base_state: Uint8Array, current_state: Uint
29
38
  */
30
39
  export function applyDeltaChangeset(base_state: Uint8Array, changeset: Uint8Array): Uint8Array;
31
40
  /**
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.
41
- *
42
- * Returns the file entry as a JS object, or `undefined` if not found.
43
- */
44
- export function getExternalFile(buf: Uint8Array, file_id: string): any;
45
- /**
46
- * Returns the current version-control schema version defined in Rust.
47
- *
48
- * TypeScript should use this as the source of truth instead of hardcoding
49
- * its own constant. When this value is bumped in Rust, the version control
50
- * system will automatically handle migration bookkeeping (closing old chains,
51
- * recording migrations) the next time a checkpoint or delta is created.
52
- */
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 }`.
41
+ * List metadata for all external files (without loading the heavy data blobs).
58
42
  */
59
- export function revertToVersion(duc_buf: Uint8Array, target_version: number): any;
43
+ export function listExternalFiles(buf: Uint8Array): any;
60
44
  /**
61
- * Restore a specific checkpoint by its ID from a `.duc` file buffer.
45
+ * Read the full VersionGraph from a `.duc` file buffer.
62
46
  *
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).
47
+ * Returns a JS object matching the `VersionGraph` TypeScript interface,
48
+ * or `undefined` if no version graph exists.
68
49
  */
69
- export function listExternalFiles(buf: Uint8Array): any;
50
+ export function readVersionGraph(duc_buf: Uint8Array): any;
70
51
  /**
71
52
  * List all versions (checkpoints + deltas) from a `.duc` file buffer.
72
53
  *
@@ -88,6 +69,25 @@ export function parseDucLazy(buf: Uint8Array): any;
88
69
  * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
89
70
  */
90
71
  export function restoreVersion(duc_buf: Uint8Array, version_number: number): any;
72
+ /**
73
+ * Serialize a JS object (ExportedDataState) into `.duc` bytes (Uint8Array).
74
+ */
75
+ export function serializeDuc(data: any): Uint8Array;
76
+ /**
77
+ * Returns the current version-control schema version defined in Rust.
78
+ *
79
+ * TypeScript should use this as the source of truth instead of hardcoding
80
+ * its own constant. When this value is bumped in Rust, the version control
81
+ * system will automatically handle migration bookkeeping (closing old chains,
82
+ * recording migrations) the next time a checkpoint or delta is created.
83
+ */
84
+ export function getCurrentSchemaVersion(): number;
85
+ /**
86
+ * Revert the document to a specific version, removing all newer versions.
87
+ *
88
+ * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
89
+ */
90
+ export function revertToVersion(duc_buf: Uint8Array, target_version: number): any;
91
91
 
92
92
  export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
93
93
 
@@ -195,17 +195,34 @@ function takeFromExternrefTable0(idx) {
195
195
  return value;
196
196
  }
197
197
  /**
198
- * Read the full VersionGraph from a `.duc` file buffer.
198
+ * Parse a `.duc` file (Uint8Array) into a JS object (ExportedDataState).
199
+ * @param {Uint8Array} buf
200
+ * @returns {any}
201
+ */
202
+ export function parseDuc(buf) {
203
+ const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
204
+ const len0 = WASM_VECTOR_LEN;
205
+ const ret = wasm.parseDuc(ptr0, len0);
206
+ if (ret[2]) {
207
+ throw takeFromExternrefTable0(ret[1]);
208
+ }
209
+ return takeFromExternrefTable0(ret[0]);
210
+ }
211
+
212
+ /**
213
+ * Restore a specific checkpoint by its ID from a `.duc` file buffer.
199
214
  *
200
- * Returns a JS object matching the `VersionGraph` TypeScript interface,
201
- * or `undefined` if no version graph exists.
215
+ * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
202
216
  * @param {Uint8Array} duc_buf
217
+ * @param {string} checkpoint_id
203
218
  * @returns {any}
204
219
  */
205
- export function readVersionGraph(duc_buf) {
220
+ export function restoreCheckpoint(duc_buf, checkpoint_id) {
206
221
  const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
207
222
  const len0 = WASM_VECTOR_LEN;
208
- const ret = wasm.readVersionGraph(ptr0, len0);
223
+ const ptr1 = passStringToWasm0(checkpoint_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
224
+ const len1 = WASM_VECTOR_LEN;
225
+ const ret = wasm.restoreCheckpoint(ptr0, len0, ptr1, len1);
209
226
  if (ret[2]) {
210
227
  throw takeFromExternrefTable0(ret[1]);
211
228
  }
@@ -239,6 +256,26 @@ export function createDeltaChangeset(base_state, current_state) {
239
256
  return v3;
240
257
  }
241
258
 
259
+ /**
260
+ * Fetch a single external file from a `.duc` buffer by file ID.
261
+ *
262
+ * Returns the file entry as a JS object, or `undefined` if not found.
263
+ * @param {Uint8Array} buf
264
+ * @param {string} file_id
265
+ * @returns {any}
266
+ */
267
+ export function getExternalFile(buf, file_id) {
268
+ const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
269
+ const len0 = WASM_VECTOR_LEN;
270
+ const ptr1 = passStringToWasm0(file_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
271
+ const len1 = WASM_VECTOR_LEN;
272
+ const ret = wasm.getExternalFile(ptr0, len0, ptr1, len1);
273
+ if (ret[2]) {
274
+ throw takeFromExternrefTable0(ret[1]);
275
+ }
276
+ return takeFromExternrefTable0(ret[0]);
277
+ }
278
+
242
279
  /**
243
280
  * Apply a changeset to reconstruct document state.
244
281
  *
@@ -266,49 +303,14 @@ export function applyDeltaChangeset(base_state, changeset) {
266
303
  }
267
304
 
268
305
  /**
269
- * Parse a `.duc` file (Uint8Array) into a JS object (ExportedDataState).
270
- * @param {Uint8Array} buf
271
- * @returns {any}
272
- */
273
- export function parseDuc(buf) {
274
- const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
275
- const len0 = WASM_VECTOR_LEN;
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);
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.
300
- *
301
- * Returns the file entry as a JS object, or `undefined` if not found.
306
+ * List metadata for all external files (without loading the heavy data blobs).
302
307
  * @param {Uint8Array} buf
303
- * @param {string} file_id
304
308
  * @returns {any}
305
309
  */
306
- export function getExternalFile(buf, file_id) {
310
+ export function listExternalFiles(buf) {
307
311
  const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
308
312
  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);
313
+ const ret = wasm.listExternalFiles(ptr0, len0);
312
314
  if (ret[2]) {
313
315
  throw takeFromExternrefTable0(ret[1]);
314
316
  }
@@ -316,30 +318,17 @@ export function getExternalFile(buf, file_id) {
316
318
  }
317
319
 
318
320
  /**
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;
329
- }
330
-
331
- /**
332
- * Revert the document to a specific version, removing all newer versions.
321
+ * Read the full VersionGraph from a `.duc` file buffer.
333
322
  *
334
- * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
323
+ * Returns a JS object matching the `VersionGraph` TypeScript interface,
324
+ * or `undefined` if no version graph exists.
335
325
  * @param {Uint8Array} duc_buf
336
- * @param {number} target_version
337
326
  * @returns {any}
338
327
  */
339
- export function revertToVersion(duc_buf, target_version) {
328
+ export function readVersionGraph(duc_buf) {
340
329
  const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
341
330
  const len0 = WASM_VECTOR_LEN;
342
- const ret = wasm.revertToVersion(ptr0, len0, target_version);
331
+ const ret = wasm.readVersionGraph(ptr0, len0);
343
332
  if (ret[2]) {
344
333
  throw takeFromExternrefTable0(ret[1]);
345
334
  }
@@ -347,19 +336,16 @@ export function revertToVersion(duc_buf, target_version) {
347
336
  }
348
337
 
349
338
  /**
350
- * Restore a specific checkpoint by its ID from a `.duc` file buffer.
339
+ * List all versions (checkpoints + deltas) from a `.duc` file buffer.
351
340
  *
352
- * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
341
+ * Returns a JS array of `VersionEntry` objects (no heavy data blobs).
353
342
  * @param {Uint8Array} duc_buf
354
- * @param {string} checkpoint_id
355
343
  * @returns {any}
356
344
  */
357
- export function restoreCheckpoint(duc_buf, checkpoint_id) {
345
+ export function listVersions(duc_buf) {
358
346
  const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
359
347
  const len0 = WASM_VECTOR_LEN;
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);
348
+ const ret = wasm.listVersions(ptr0, len0);
363
349
  if (ret[2]) {
364
350
  throw takeFromExternrefTable0(ret[1]);
365
351
  }
@@ -367,14 +353,16 @@ export function restoreCheckpoint(duc_buf, checkpoint_id) {
367
353
  }
368
354
 
369
355
  /**
370
- * List metadata for all external files (without loading the heavy data blobs).
356
+ * Parse a `.duc` file lazily — returns everything EXCEPT external file data blobs.
357
+ *
358
+ * Use `getExternalFile()` or `listExternalFiles()` for on-demand access.
371
359
  * @param {Uint8Array} buf
372
360
  * @returns {any}
373
361
  */
374
- export function listExternalFiles(buf) {
362
+ export function parseDucLazy(buf) {
375
363
  const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
376
364
  const len0 = WASM_VECTOR_LEN;
377
- const ret = wasm.listExternalFiles(ptr0, len0);
365
+ const ret = wasm.parseDucLazy(ptr0, len0);
378
366
  if (ret[2]) {
379
367
  throw takeFromExternrefTable0(ret[1]);
380
368
  }
@@ -382,16 +370,20 @@ export function listExternalFiles(buf) {
382
370
  }
383
371
 
384
372
  /**
385
- * List all versions (checkpoints + deltas) from a `.duc` file buffer.
373
+ * Restore the document state at `version_number` from a `.duc` file buffer.
386
374
  *
387
- * Returns a JS array of `VersionEntry` objects (no heavy data blobs).
375
+ * The `.duc` file is a SQLite database — this function opens it and queries
376
+ * the `checkpoints` / `deltas` tables directly for version restoration.
377
+ *
378
+ * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
388
379
  * @param {Uint8Array} duc_buf
380
+ * @param {number} version_number
389
381
  * @returns {any}
390
382
  */
391
- export function listVersions(duc_buf) {
383
+ export function restoreVersion(duc_buf, version_number) {
392
384
  const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
393
385
  const len0 = WASM_VECTOR_LEN;
394
- const ret = wasm.listVersions(ptr0, len0);
386
+ const ret = wasm.restoreVersion(ptr0, len0, version_number);
395
387
  if (ret[2]) {
396
388
  throw takeFromExternrefTable0(ret[1]);
397
389
  }
@@ -399,37 +391,45 @@ export function listVersions(duc_buf) {
399
391
  }
400
392
 
401
393
  /**
402
- * Parse a `.duc` file lazily — returns everything EXCEPT external file data blobs.
403
- *
404
- * Use `getExternalFile()` or `listExternalFiles()` for on-demand access.
405
- * @param {Uint8Array} buf
406
- * @returns {any}
394
+ * Serialize a JS object (ExportedDataState) into `.duc` bytes (Uint8Array).
395
+ * @param {any} data
396
+ * @returns {Uint8Array}
407
397
  */
408
- export function parseDucLazy(buf) {
409
- const ptr0 = passArray8ToWasm0(buf, wasm.__wbindgen_malloc);
410
- const len0 = WASM_VECTOR_LEN;
411
- const ret = wasm.parseDucLazy(ptr0, len0);
412
- if (ret[2]) {
413
- throw takeFromExternrefTable0(ret[1]);
398
+ export function serializeDuc(data) {
399
+ const ret = wasm.serializeDuc(data);
400
+ if (ret[3]) {
401
+ throw takeFromExternrefTable0(ret[2]);
414
402
  }
415
- return takeFromExternrefTable0(ret[0]);
403
+ var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
404
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
405
+ return v1;
416
406
  }
417
407
 
418
408
  /**
419
- * Restore the document state at `version_number` from a `.duc` file buffer.
409
+ * Returns the current version-control schema version defined in Rust.
420
410
  *
421
- * The `.duc` file is a SQLite database — this function opens it and queries
422
- * the `checkpoints` / `deltas` tables directly for version restoration.
411
+ * TypeScript should use this as the source of truth instead of hardcoding
412
+ * its own constant. When this value is bumped in Rust, the version control
413
+ * system will automatically handle migration bookkeeping (closing old chains,
414
+ * recording migrations) the next time a checkpoint or delta is created.
415
+ * @returns {number}
416
+ */
417
+ export function getCurrentSchemaVersion() {
418
+ return 3000004;
419
+ }
420
+
421
+ /**
422
+ * Revert the document to a specific version, removing all newer versions.
423
423
  *
424
424
  * Returns a JS object `{ versionNumber, schemaVersion, data, fromCheckpoint }`.
425
425
  * @param {Uint8Array} duc_buf
426
- * @param {number} version_number
426
+ * @param {number} target_version
427
427
  * @returns {any}
428
428
  */
429
- export function restoreVersion(duc_buf, version_number) {
429
+ export function revertToVersion(duc_buf, target_version) {
430
430
  const ptr0 = passArray8ToWasm0(duc_buf, wasm.__wbindgen_malloc);
431
431
  const len0 = WASM_VECTOR_LEN;
432
- const ret = wasm.restoreVersion(ptr0, len0, version_number);
432
+ const ret = wasm.revertToVersion(ptr0, len0, target_version);
433
433
  if (ret[2]) {
434
434
  throw takeFromExternrefTable0(ret[1]);
435
435
  }
Binary file
@@ -144,7 +144,7 @@ export declare const isValidTextAlignValue: (value: TextAlign | undefined) => Te
144
144
  export declare const isValidDecimalPlacesValue: (value: number | undefined, fallback: number) => number;
145
145
  export declare const isValidScopeValue: (value: string | undefined, localState?: Readonly<Partial<DucLocalState>> | null, mainScope?: Scope) => Scope;
146
146
  export declare const isValidImageStatusValue: (value: ImageStatus | undefined) => ImageStatus;
147
- export declare const isValidDucHead: (value: DucHead | null | undefined, blocks: RestoredDataState["blocks"], elementScope: Scope, currentScope: Scope) => DucHead | null;
147
+ export declare const isValidDucHead: (value: DucHead | null | undefined, blocks: RestoredDataState["blocks"]) => DucHead | null;
148
148
  export declare const isValidLineHeadValue: (value: LineHead | null | undefined) => LineHead | null;
149
149
  export declare const isValidZoomStepValue: (value: number | undefined) => number;
150
150
  export declare const isValidImageScaleValue: (value: [number, number] | undefined) => [number, number];
@@ -710,18 +710,20 @@ export const isValidImageStatusValue = (value) => {
710
710
  return IMAGE_STATUS.PENDING;
711
711
  return value;
712
712
  };
713
- export const isValidDucHead = (value, blocks, elementScope, currentScope) => {
713
+ export const isValidDucHead = (value, blocks) => {
714
714
  if (value === undefined || value === null)
715
715
  return null;
716
716
  const type = isValidLineHeadValue(value.type);
717
- // blockId can be null - only reject if type is invalid
718
717
  if (type === null)
719
718
  return null;
720
719
  const blockId = isValidBlockId(value.blockId, blocks);
720
+ const size = typeof value.size === "number" && Number.isFinite(value.size) && value.size > 0
721
+ ? value.size
722
+ : 1;
721
723
  return {
722
724
  type,
723
725
  blockId,
724
- size: restorePrecisionValue(value.size, elementScope, currentScope),
726
+ size,
725
727
  };
726
728
  };
727
729
  export const isValidLineHeadValue = (value) => {
@@ -324,6 +324,7 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
324
324
  return restoreElementWithProperties(element, {
325
325
  text: isValidString(docElement.text),
326
326
  fileId: isValidString(docElement.fileId) || null,
327
+ referencedFileIds: docElement.referencedFileIds || [],
327
328
  gridConfig: restoreDocumentGridConfig(docElement.gridConfig),
328
329
  }, localState);
329
330
  }
@@ -746,7 +747,7 @@ const repairBinding = (element, binding, currentScope, restoredBlocks) => {
746
747
  },
747
748
  }
748
749
  : { point: null };
749
- return Object.assign({ elementId: binding.elementId || "", focus: typeof binding.focus === "number" ? binding.focus : 0, gap: restorePrecisionValue(typeof binding.gap === "number" ? Math.max(0, binding.gap) : 0, elementScope, currentScope), head: isValidDucHead(binding.head, restoredBlocks, elementScope, currentScope), fixedPoint: element && isElbowArrow(element)
750
+ return Object.assign({ elementId: binding.elementId || "", focus: typeof binding.focus === "number" ? binding.focus : 0, gap: restorePrecisionValue(typeof binding.gap === "number" ? Math.max(0, binding.gap) : 0, elementScope, currentScope), head: isValidDucHead(binding.head, restoredBlocks), fixedPoint: element && isElbowArrow(element)
750
751
  ? normalizeFixedPoint((_a = binding.fixedPoint) !== null && _a !== void 0 ? _a : { x: 0.5, y: 0.5 })
751
752
  : null }, pointData);
752
753
  };
@@ -830,7 +831,7 @@ const createHeadOnlyBinding = (head, restoredBlocks, currentScope) => {
830
831
  gap: getPrecisionValueFromRaw(0, currentScope, currentScope),
831
832
  fixedPoint: null,
832
833
  point: null,
833
- head: isValidDucHead(head, restoredBlocks, currentScope, currentScope),
834
+ head: isValidDucHead(head, restoredBlocks),
834
835
  };
835
836
  };
836
837
  const validateDeprecatedElementContent = (color, defaultContent) => {
@@ -133,6 +133,37 @@ export type DucGenericElement = DucSelectionElement | DucRectangleElement;
133
133
  */
134
134
  export type DucElement = DucGenericElement | DucTextElement | DucLinearElement | DucFreeDrawElement | DucArrowElement | DucImageElement | DucFrameElement | DucEmbeddableElement | DucTableElement | DucDocElement | DucEllipseElement | DucPolygonElement | DucModelElement | DucPlotElement | DucPdfElement;
135
135
  export type DucElementTypes = DucElement["type"];
136
+ export type DucElementSelectableField = keyof DucElement | keyof Extract<DucElement, {
137
+ type: "model";
138
+ }> | keyof Extract<DucElement, {
139
+ type: "text";
140
+ }> | keyof Extract<DucElement, {
141
+ type: "line";
142
+ }> | keyof Extract<DucElement, {
143
+ type: "arrow";
144
+ }> | keyof Extract<DucElement, {
145
+ type: "freedraw";
146
+ }> | keyof Extract<DucElement, {
147
+ type: "ellipse";
148
+ }> | keyof Extract<DucElement, {
149
+ type: "polygon";
150
+ }> | keyof Extract<DucElement, {
151
+ type: "image";
152
+ }> | keyof Extract<DucElement, {
153
+ type: "frame";
154
+ }> | keyof Extract<DucElement, {
155
+ type: "plot";
156
+ }> | keyof Extract<DucElement, {
157
+ type: "doc";
158
+ }> | keyof Extract<DucElement, {
159
+ type: "pdf";
160
+ }> | keyof Extract<DucElement, {
161
+ type: "table";
162
+ }> | keyof Extract<DucElement, {
163
+ type: "embeddable";
164
+ }>;
165
+ export declare const DUC_ELEMENT_SELECTABLE_FIELDS: readonly ["id", "type", "label", "x", "y", "width", "height", "angle", "opacity", "isDeleted", "isVisible", "groupIds", "frameId", "scope", "layerId", "zIndex", "description", "customData", "roundness", "blending", "background", "stroke", "boundElements", "link", "locked", "regionIds", "blockIds", "instanceId", "index", "updated", "version", "versionNonce", "seed", "modelType", "fileIds", "code", "thumbnail", "viewerState", "text", "autoResize", "containerId", "originalText", "isLtr", "fontFamily", "bigFontFamily", "fontSize", "textAlign", "verticalAlign", "lineHeight", "lineSpacing", "obliqueAngle", "widthFactor", "isUpsideDown", "isBackwards", "points", "fileId", "status", "scaleFlip", "crop", "filter", "elbowed", "wipeoutBelow", "clip", "labelVisible", "layout", "gridConfig", "referencedFileIds", "sides", "ratio", "startAngle", "endAngle", "showAuxCrosshair", "size", "thinning", "smoothing", "streamline", "easing", "start", "end", "pressures", "simulatePressure", "lastCommittedPoint", "lines", "pathOverrides", "startBinding", "endBinding", "svgPath"];
166
+ export declare const DUC_ELEMENT_TYPE_VALUES: readonly ["rectangle", "polygon", "ellipse", "line", "arrow", "freedraw", "text", "image", "frame", "embeddable", "table", "model", "pdf", "doc", "plot"];
136
167
  export type NonDeleted<TElement extends DucElement> = TElement & {
137
168
  isDeleted: boolean;
138
169
  };
@@ -522,7 +553,7 @@ export type DucPointBinding = {
522
553
  export type DucHead = {
523
554
  type: LineHead;
524
555
  blockId: string | null;
525
- size: PrecisionValue;
556
+ size: number;
526
557
  };
527
558
  export interface DucPointPosition {
528
559
  x: PrecisionValue;
@@ -750,6 +781,8 @@ export type DucDocElement = _DucElementBase & {
750
781
  type: "doc";
751
782
  text: string;
752
783
  fileId: ExternalFileId | null;
784
+ /** Files referenced by the Typst source, such as images or data files. */
785
+ referencedFileIds: ExternalFileId[];
753
786
  /** Configuration for rendering the document in a grid layout */
754
787
  gridConfig: DocumentGridConfig;
755
788
  };
@@ -1 +1,107 @@
1
1
  export * from "./typeChecks";
2
+ export const DUC_ELEMENT_SELECTABLE_FIELDS = [
3
+ "id",
4
+ "type",
5
+ "label",
6
+ "x",
7
+ "y",
8
+ "width",
9
+ "height",
10
+ "angle",
11
+ "opacity",
12
+ "isDeleted",
13
+ "isVisible",
14
+ "groupIds",
15
+ "frameId",
16
+ "scope",
17
+ "layerId",
18
+ "zIndex",
19
+ "description",
20
+ "customData",
21
+ "roundness",
22
+ "blending",
23
+ "background",
24
+ "stroke",
25
+ "boundElements",
26
+ "link",
27
+ "locked",
28
+ "regionIds",
29
+ "blockIds",
30
+ "instanceId",
31
+ "index",
32
+ "updated",
33
+ "version",
34
+ "versionNonce",
35
+ "seed",
36
+ "modelType",
37
+ "fileIds",
38
+ "code",
39
+ "thumbnail",
40
+ "viewerState",
41
+ "text",
42
+ "autoResize",
43
+ "containerId",
44
+ "originalText",
45
+ "isLtr",
46
+ "fontFamily",
47
+ "bigFontFamily",
48
+ "fontSize",
49
+ "textAlign",
50
+ "verticalAlign",
51
+ "lineHeight",
52
+ "lineSpacing",
53
+ "obliqueAngle",
54
+ "widthFactor",
55
+ "isUpsideDown",
56
+ "isBackwards",
57
+ "points",
58
+ "fileId",
59
+ "status",
60
+ "scaleFlip",
61
+ "crop",
62
+ "filter",
63
+ "elbowed",
64
+ "wipeoutBelow",
65
+ "clip",
66
+ "labelVisible",
67
+ "layout",
68
+ "gridConfig",
69
+ "referencedFileIds",
70
+ "sides",
71
+ "ratio",
72
+ "startAngle",
73
+ "endAngle",
74
+ "showAuxCrosshair",
75
+ "size",
76
+ "thinning",
77
+ "smoothing",
78
+ "streamline",
79
+ "easing",
80
+ "start",
81
+ "end",
82
+ "pressures",
83
+ "simulatePressure",
84
+ "lastCommittedPoint",
85
+ "lines",
86
+ "pathOverrides",
87
+ "startBinding",
88
+ "endBinding",
89
+ "svgPath",
90
+ ];
91
+ export const DUC_ELEMENT_TYPE_VALUES = [
92
+ "rectangle",
93
+ "polygon",
94
+ "ellipse",
95
+ "line",
96
+ "arrow",
97
+ "freedraw",
98
+ "text",
99
+ "image",
100
+ "frame",
101
+ "embeddable",
102
+ "table",
103
+ "model",
104
+ "pdf",
105
+ "doc",
106
+ "plot",
107
+ ];
@@ -161,13 +161,13 @@ export const newTableElement = (currentScope, opts) => {
161
161
  return (Object.assign(Object.assign({}, _newElementBase("table", currentScope, opts)), { fileId: (_a = opts.fileId) !== null && _a !== void 0 ? _a : null, type: "table" }));
162
162
  };
163
163
  export const newDocElement = (currentScope, opts) => {
164
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
165
- return (Object.assign(Object.assign({}, _newElementBase("doc", currentScope, Object.assign(Object.assign({}, opts), getDocumentElementStyle(opts)))), { type: "doc", text: opts.text || "", fileId: (_a = opts.fileId) !== null && _a !== void 0 ? _a : null, gridConfig: {
166
- columns: (_c = (_b = opts.gridConfig) === null || _b === void 0 ? void 0 : _b.columns) !== null && _c !== void 0 ? _c : 1,
167
- gapX: (_e = (_d = opts.gridConfig) === null || _d === void 0 ? void 0 : _d.gapX) !== null && _e !== void 0 ? _e : 0,
168
- gapY: (_g = (_f = opts.gridConfig) === null || _f === void 0 ? void 0 : _f.gapY) !== null && _g !== void 0 ? _g : 0,
169
- firstPageAlone: (_j = (_h = opts.gridConfig) === null || _h === void 0 ? void 0 : _h.firstPageAlone) !== null && _j !== void 0 ? _j : false,
170
- scale: (_l = (_k = opts.gridConfig) === null || _k === void 0 ? void 0 : _k.scale) !== null && _l !== void 0 ? _l : 1,
164
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
165
+ return (Object.assign(Object.assign({}, _newElementBase("doc", currentScope, Object.assign(Object.assign({}, opts), getDocumentElementStyle(opts)))), { type: "doc", text: opts.text || "", fileId: (_a = opts.fileId) !== null && _a !== void 0 ? _a : null, referencedFileIds: (_b = opts.referencedFileIds) !== null && _b !== void 0 ? _b : [], gridConfig: {
166
+ columns: (_d = (_c = opts.gridConfig) === null || _c === void 0 ? void 0 : _c.columns) !== null && _d !== void 0 ? _d : 1,
167
+ gapX: (_f = (_e = opts.gridConfig) === null || _e === void 0 ? void 0 : _e.gapX) !== null && _f !== void 0 ? _f : 0,
168
+ gapY: (_h = (_g = opts.gridConfig) === null || _g === void 0 ? void 0 : _g.gapY) !== null && _h !== void 0 ? _h : 0,
169
+ firstPageAlone: (_k = (_j = opts.gridConfig) === null || _j === void 0 ? void 0 : _j.firstPageAlone) !== null && _k !== void 0 ? _k : false,
170
+ scale: (_m = (_l = opts.gridConfig) === null || _l === void 0 ? void 0 : _l.scale) !== null && _m !== void 0 ? _m : 1,
171
171
  } }));
172
172
  };
173
173
  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, Object.assign(Object.assign({}, opts), getDocumentElementStyle(opts)))), { type: "pdf" }));
package/dist/wasm.js CHANGED
@@ -10,15 +10,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import init, { applyDeltaChangeset as _applyDeltaChangeset, createDeltaChangeset as _createDeltaChangeset, getCurrentSchemaVersion as _getCurrentSchemaVersion, getExternalFile as _getExternalFile, listExternalFiles as _listExternalFiles, listVersions as _listVersions, parseDuc as _parseDuc, parseDucLazy as _parseDucLazy, readVersionGraph as _readVersionGraph, restoreCheckpoint as _restoreCheckpoint, restoreVersion as _restoreVersion, revertToVersion as _revertToVersion, serializeDuc as _serializeDuc, } from "../dist/ducjs_wasm";
11
11
  let initialized = false;
12
12
  let initPromise = null;
13
+ const DEFAULT_WASM_URL = new URL("../dist/ducjs_wasm_bg.wasm", import.meta.url);
14
+ const isNodeRuntime = () => { var _a; return typeof process !== "undefined" && typeof ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node) === "string"; };
15
+ const loadNodeFsPromises = () => __awaiter(void 0, void 0, void 0, function* () {
16
+ const dynamicImport = new Function("specifier", "return import(specifier)");
17
+ return dynamicImport(["node", "fs/promises"].join(":"));
18
+ });
19
+ const resolveDefaultWasmInput = () => __awaiter(void 0, void 0, void 0, function* () {
20
+ if (!isNodeRuntime()) {
21
+ return DEFAULT_WASM_URL;
22
+ }
23
+ const { readFile } = yield loadNodeFsPromises();
24
+ const bytes = yield readFile(DEFAULT_WASM_URL);
25
+ return new Uint8Array(bytes);
26
+ });
13
27
  export function ensureWasm(wasmUrl) {
14
28
  return __awaiter(this, void 0, void 0, function* () {
15
29
  if (initialized)
16
30
  return;
17
31
  if (!initPromise) {
18
- const arg = wasmUrl !== undefined ? { module_or_path: wasmUrl } : undefined;
19
- initPromise = init(arg).then(() => {
32
+ initPromise = (() => __awaiter(this, void 0, void 0, function* () {
33
+ const moduleOrPath = wasmUrl !== null && wasmUrl !== void 0 ? wasmUrl : yield resolveDefaultWasmInput();
34
+ yield init({ module_or_path: moduleOrPath });
20
35
  initialized = true;
21
- });
36
+ }))();
22
37
  }
23
38
  return initPromise;
24
39
  });
@@ -31,8 +46,12 @@ export function ensureWasm(wasmUrl) {
31
46
  */
32
47
  export function getWasmBinary() {
33
48
  return __awaiter(this, void 0, void 0, function* () {
34
- const url = new URL('../dist/ducjs_wasm_bg.wasm', import.meta.url);
35
- const resp = yield fetch(url);
49
+ if (isNodeRuntime()) {
50
+ const { readFile } = yield loadNodeFsPromises();
51
+ const bytes = yield readFile(DEFAULT_WASM_URL);
52
+ return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
53
+ }
54
+ const resp = yield fetch(DEFAULT_WASM_URL);
36
55
  if (!resp.ok) {
37
56
  throw new Error(`Failed to fetch WASM binary: ${resp.status} ${resp.statusText}`);
38
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ducjs",
3
- "version": "3.3.0",
3
+ "version": "3.4.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",
@@ -8,11 +8,15 @@
8
8
  "types": "dist/index.d.ts",
9
9
  "exports": {
10
10
  ".": {
11
+ "types": "./dist/index.d.ts",
11
12
  "import": "./dist/index.js",
12
- "require": "./dist/index.js",
13
- "types": "./dist/index.d.ts"
13
+ "require": "./dist/index.js"
14
14
  },
15
15
  "./*": {
16
+ "types": [
17
+ "./dist/*.d.ts",
18
+ "./dist/*/index.d.ts"
19
+ ],
16
20
  "import": [
17
21
  "./dist/*.js",
18
22
  "./dist/*/index.js"
@@ -20,10 +24,6 @@
20
24
  "require": [
21
25
  "./dist/*.js",
22
26
  "./dist/*/index.js"
23
- ],
24
- "types": [
25
- "./dist/*.d.ts",
26
- "./dist/*/index.d.ts"
27
27
  ]
28
28
  }
29
29
  },