ducjs 2.2.2 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/flatbuffers/duc/delta.d.ts +6 -4
  2. package/dist/flatbuffers/duc/delta.js +22 -11
  3. package/dist/flatbuffers/duc/document-grid-align-items.d.ts +5 -0
  4. package/dist/flatbuffers/duc/document-grid-align-items.js +8 -0
  5. package/dist/flatbuffers/duc/document-grid-config.d.ts +22 -0
  6. package/dist/flatbuffers/duc/document-grid-config.js +73 -0
  7. package/dist/flatbuffers/duc/duc-block-metadata.d.ts +5 -2
  8. package/dist/flatbuffers/duc/duc-block-metadata.js +23 -5
  9. package/dist/flatbuffers/duc/duc-doc-element.d.ts +6 -0
  10. package/dist/flatbuffers/duc/duc-doc-element.js +16 -1
  11. package/dist/flatbuffers/duc/duc-element-base.d.ts +6 -3
  12. package/dist/flatbuffers/duc/duc-element-base.js +26 -8
  13. package/dist/flatbuffers/duc/duc-model-element.d.ts +26 -0
  14. package/dist/flatbuffers/duc/duc-model-element.js +79 -0
  15. package/dist/flatbuffers/duc/duc-pdf-element.d.ts +3 -1
  16. package/dist/flatbuffers/duc/duc-pdf-element.js +9 -7
  17. package/dist/flatbuffers/duc/element.d.ts +5 -3
  18. package/dist/flatbuffers/duc/element.js +4 -0
  19. package/dist/flatbuffers/duc.d.ts +3 -0
  20. package/dist/flatbuffers/duc.js +3 -0
  21. package/dist/parse.d.ts +3 -2
  22. package/dist/parse.js +75 -44
  23. package/dist/restore/restoreDataState.d.ts +1 -6
  24. package/dist/restore/restoreDataState.js +9 -18
  25. package/dist/restore/restoreElements.js +39 -25
  26. package/dist/serialize.js +67 -48
  27. package/dist/types/elements/index.d.ts +34 -31
  28. package/dist/types/elements/typeChecks.js +1 -1
  29. package/dist/types/index.d.ts +5 -4
  30. package/dist/types/index.js +1 -1
  31. package/dist/utils/elements/newElement.d.ts +2 -2
  32. package/dist/utils/elements/newElement.js +4 -4
  33. package/dist/utils/index.d.ts +1 -0
  34. package/dist/utils/index.js +5 -0
  35. package/package.json +6 -5
@@ -13,6 +13,7 @@ import { DucImageElement } from '../duc/duc-image-element';
13
13
  import { DucLeaderElement } from '../duc/duc-leader-element';
14
14
  import { DucLinearElement } from '../duc/duc-linear-element';
15
15
  import { DucMermaidElement } from '../duc/duc-mermaid-element';
16
+ import { DucModelElement } from '../duc/duc-model-element';
16
17
  import { DucParametricElement } from '../duc/duc-parametric-element';
17
18
  import { DucPdfElement } from '../duc/duc-pdf-element';
18
19
  import { DucPlotElement } from '../duc/duc-plot-element';
@@ -47,6 +48,7 @@ export var Element;
47
48
  Element[Element["DucFeatureControlFrameElement"] = 20] = "DucFeatureControlFrameElement";
48
49
  Element[Element["DucDocElement"] = 21] = "DucDocElement";
49
50
  Element[Element["DucParametricElement"] = 22] = "DucParametricElement";
51
+ Element[Element["DucModelElement"] = 23] = "DucModelElement";
50
52
  })(Element || (Element = {}));
51
53
  export function unionToElement(type, accessor) {
52
54
  switch (Element[type]) {
@@ -73,6 +75,7 @@ export function unionToElement(type, accessor) {
73
75
  case 'DucFeatureControlFrameElement': return accessor(new DucFeatureControlFrameElement());
74
76
  case 'DucDocElement': return accessor(new DucDocElement());
75
77
  case 'DucParametricElement': return accessor(new DucParametricElement());
78
+ case 'DucModelElement': return accessor(new DucModelElement());
76
79
  default: return null;
77
80
  }
78
81
  }
@@ -101,6 +104,7 @@ export function unionListToElement(type, accessor, index) {
101
104
  case 'DucFeatureControlFrameElement': return accessor(index, new DucFeatureControlFrameElement());
102
105
  case 'DucDocElement': return accessor(index, new DucDocElement());
103
106
  case 'DucParametricElement': return accessor(index, new DucParametricElement());
107
+ case 'DucModelElement': return accessor(index, new DucModelElement());
104
108
  default: return null;
105
109
  }
106
110
  }
@@ -18,6 +18,7 @@ export { DIMENSION_FIT_RULE } from './duc/dimension-fit-rule';
18
18
  export { DIMENSION_TEXT_PLACEMENT } from './duc/dimension-text-placement';
19
19
  export { DIMENSION_TYPE } from './duc/dimension-type';
20
20
  export { DIMENSION_UNITS_FORMAT } from './duc/dimension-units-format';
21
+ export { DOCUMENT_GRID_ALIGN_ITEMS } from './duc/document-grid-align-items';
21
22
  export { DatumReference } from './duc/datum-reference';
22
23
  export { Delta } from './duc/delta';
23
24
  export { DictionaryEntry } from './duc/dictionary-entry';
@@ -31,6 +32,7 @@ export { DimensionLineStyle } from './duc/dimension-line-style';
31
32
  export { DimensionSymbolStyle } from './duc/dimension-symbol-style';
32
33
  export { DimensionToleranceStyle } from './duc/dimension-tolerance-style';
33
34
  export { DimensionValidationRules } from './duc/dimension-validation-rules';
35
+ export { DocumentGridConfig } from './duc/document-grid-config';
34
36
  export { DucArrowElement } from './duc/duc-arrow-element';
35
37
  export { DucBlock } from './duc/duc-block';
36
38
  export { DucBlockAttributeDefinition } from './duc/duc-block-attribute-definition';
@@ -70,6 +72,7 @@ export { DucLineReference } from './duc/duc-line-reference';
70
72
  export { DucLinearElement } from './duc/duc-linear-element';
71
73
  export { DucLocalState } from './duc/duc-local-state';
72
74
  export { DucMermaidElement } from './duc/duc-mermaid-element';
75
+ export { DucModelElement } from './duc/duc-model-element';
73
76
  export { DucParametricElement } from './duc/duc-parametric-element';
74
77
  export { DucPath } from './duc/duc-path';
75
78
  export { DucPdfElement } from './duc/duc-pdf-element';
@@ -20,6 +20,7 @@ export { DIMENSION_FIT_RULE } from './duc/dimension-fit-rule';
20
20
  export { DIMENSION_TEXT_PLACEMENT } from './duc/dimension-text-placement';
21
21
  export { DIMENSION_TYPE } from './duc/dimension-type';
22
22
  export { DIMENSION_UNITS_FORMAT } from './duc/dimension-units-format';
23
+ export { DOCUMENT_GRID_ALIGN_ITEMS } from './duc/document-grid-align-items';
23
24
  export { DatumReference } from './duc/datum-reference';
24
25
  export { Delta } from './duc/delta';
25
26
  export { DictionaryEntry } from './duc/dictionary-entry';
@@ -33,6 +34,7 @@ export { DimensionLineStyle } from './duc/dimension-line-style';
33
34
  export { DimensionSymbolStyle } from './duc/dimension-symbol-style';
34
35
  export { DimensionToleranceStyle } from './duc/dimension-tolerance-style';
35
36
  export { DimensionValidationRules } from './duc/dimension-validation-rules';
37
+ export { DocumentGridConfig } from './duc/document-grid-config';
36
38
  export { DucArrowElement } from './duc/duc-arrow-element';
37
39
  export { DucBlock } from './duc/duc-block';
38
40
  export { DucBlockAttributeDefinition } from './duc/duc-block-attribute-definition';
@@ -72,6 +74,7 @@ export { DucLineReference } from './duc/duc-line-reference';
72
74
  export { DucLinearElement } from './duc/duc-linear-element';
73
75
  export { DucLocalState } from './duc/duc-local-state';
74
76
  export { DucMermaidElement } from './duc/duc-mermaid-element';
77
+ export { DucModelElement } from './duc/duc-model-element';
75
78
  export { DucParametricElement } from './duc/duc-parametric-element';
76
79
  export { DucPath } from './duc/duc-path';
77
80
  export { DucPdfElement } from './duc/duc-pdf-element';
package/dist/parse.d.ts CHANGED
@@ -1,11 +1,12 @@
1
1
  import { FileSystemHandle } from 'browser-fs-access';
2
- import { CustomHatchPattern as CustomHatchPatternFb, DimensionToleranceStyle as DimensionToleranceStyleFb, DucBlock as DucBlockFb, DucDimensionStyle as DucDimensionStyleFb, DucDocStyle as DucDocStyleFb, DucExternalFileEntry, DucFeatureControlFrameStyle as DucFeatureControlFrameStyleFb, DucGlobalState as DucGlobalStateFb, DucGroup as DucGroupFb, DucHatchStyle as DucHatchStyleFb, DucHead as DucHeadFb, DucImageFilter as DucImageFilterFb, DucLayer as DucLayerFb, DucLeaderStyle as DucLeaderStyleFb, DucLine as DucLineFb, DucLineReference as DucLineReferenceFb, DucLocalState as DucLocalStateFb, DucPath as DucPathFb, DucPlotStyle as DucPlotStyleFb, DucPointBinding as DucPointBindingFb, DucPoint as DucPointFb, DucRegion as DucRegionFb, DucStackLikeStyles as DucStackLikeStylesFb, DucTableCellStyle as DucTableCellStyleFb, DucTableStyle as DucTableStyleFb, DucTextStyle as DucTextStyleFb, DucViewportStyle as DucViewportStyleFb, DucXRayStyle as DucXRayStyleFb, ElementBackground as ElementBackgroundFb, ElementContentBase as ElementContentBaseFb, ElementStroke as ElementStrokeFb, ElementWrapper, ExportedDataState as ExportedDataStateFb, GeometricPoint as GeometricPointFb, HatchPatternLine as HatchPatternLineFb, Margins as MarginsFb, PrimaryUnits as PrimaryUnitsFb, Standard as StandardFb, StrokeSides as StrokeSidesFb, StrokeStyle as StrokeStyleFb, TilingProperties as TilingPropertiesFb, VersionGraph as VersionGraphFb, _DucElementBase as _DucElementBaseFb, _DucElementStylesBase as _DucElementStylesBaseFb, _DucLinearElementBase as _DucLinearElementBaseFb, _DucStackBase as _DucStackBaseFb, _DucStackElementBase as _DucStackElementBaseFb } from "./flatbuffers/duc";
2
+ import { CustomHatchPattern as CustomHatchPatternFb, DimensionToleranceStyle as DimensionToleranceStyleFb, DucBlock as DucBlockFb, DucDimensionStyle as DucDimensionStyleFb, DucDocStyle as DucDocStyleFb, DucExternalFileEntry, DucFeatureControlFrameStyle as DucFeatureControlFrameStyleFb, DucGlobalState as DucGlobalStateFb, DucGroup as DucGroupFb, DucHatchStyle as DucHatchStyleFb, DucHead as DucHeadFb, DucImageFilter as DucImageFilterFb, DucLayer as DucLayerFb, DucLeaderStyle as DucLeaderStyleFb, DucLine as DucLineFb, DucLineReference as DucLineReferenceFb, DucLocalState as DucLocalStateFb, DucPath as DucPathFb, DucPlotStyle as DucPlotStyleFb, DucPointBinding as DucPointBindingFb, DucPoint as DucPointFb, DucRegion as DucRegionFb, DucStackLikeStyles as DucStackLikeStylesFb, DucTableCellStyle as DucTableCellStyleFb, DucTableStyle as DucTableStyleFb, DucTextStyle as DucTextStyleFb, DucViewportStyle as DucViewportStyleFb, DucXRayStyle as DucXRayStyleFb, DocumentGridConfig as DocumentGridConfigFb, ElementBackground as ElementBackgroundFb, ElementContentBase as ElementContentBaseFb, ElementStroke as ElementStrokeFb, ElementWrapper, ExportedDataState as ExportedDataStateFb, GeometricPoint as GeometricPointFb, HatchPatternLine as HatchPatternLineFb, Margins as MarginsFb, PrimaryUnits as PrimaryUnitsFb, Standard as StandardFb, StrokeSides as StrokeSidesFb, StrokeStyle as StrokeStyleFb, TilingProperties as TilingPropertiesFb, VersionGraph as VersionGraphFb, _DucElementBase as _DucElementBaseFb, _DucElementStylesBase as _DucElementStylesBaseFb, _DucLinearElementBase as _DucLinearElementBaseFb, _DucStackBase as _DucStackBaseFb, _DucStackElementBase as _DucStackElementBaseFb } from "./flatbuffers/duc";
3
3
  import { RestoreConfig, RestoredDataState } from "./restore";
4
4
  import { Standard, StandardUnits } from "./technical";
5
- import { CustomHatchPattern, Dictionary, DucBlock, DucDimensionStyle, DucDocStyle, DucElement, DucExternalFiles, DucFeatureControlFrameStyle, DucGlobalState, DucGroup, DucHatchStyle, DucHead, DucImageFilter, DucLayer, DucLeaderStyle, DucLine, DucLineReference, DucLocalState, DucPath, DucPlotStyle, DucPoint, DucPointBinding, DucRegion, DucStackLikeStyles, DucTableCellStyle, DucTableStyle, DucTextStyle, DucViewportStyle, DucXRayStyle, ElementBackground, ElementContentBase, ElementStroke, GeometricPoint, HatchPatternLine, PlotLayout, StrokeSides, StrokeStyle, TilingProperties, VersionGraph, _DucElementBase, _DucElementStylesBase, _DucLinearElementBase, _DucStackBase, _DucStackElementBase } from "./types";
5
+ import { CustomHatchPattern, Dictionary, DocumentGridConfig, DucBlock, DucDimensionStyle, DucDocStyle, DucElement, DucExternalFiles, DucFeatureControlFrameStyle, DucGlobalState, DucGroup, DucHatchStyle, DucHead, DucImageFilter, DucLayer, DucLeaderStyle, DucLine, DucLineReference, DucLocalState, DucPath, DucPlotStyle, DucPoint, DucPointBinding, DucRegion, DucStackLikeStyles, DucTableCellStyle, DucTableStyle, DucTextStyle, DucViewportStyle, DucXRayStyle, ElementBackground, ElementContentBase, ElementStroke, GeometricPoint, HatchPatternLine, PlotLayout, StrokeSides, StrokeStyle, TilingProperties, VersionGraph, _DucElementBase, _DucElementStylesBase, _DucLinearElementBase, _DucStackBase, _DucStackElementBase } from "./types";
6
6
  export declare function parseGeometricPoint(point: GeometricPointFb): GeometricPoint;
7
7
  export declare function parsePoint(point: DucPointFb): DucPoint;
8
8
  export declare function parseMargins(margins: MarginsFb): PlotLayout["margins"];
9
+ export declare function parseDocumentGridConfig(gridConfig: DocumentGridConfigFb): DocumentGridConfig;
9
10
  export declare function parseHead(head: DucHeadFb): DucHead;
10
11
  export declare function parseHatchPatternLine(line: HatchPatternLineFb): HatchPatternLine;
11
12
  export declare function parseCustomHatchPattern(pattern: CustomHatchPatternFb): CustomHatchPattern;
package/dist/parse.js CHANGED
@@ -7,10 +7,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import { DucArrowElement as DucArrowElementFb, DucDimensionElement as DucDimensionElementFb, DucDocElement as DucDocElementFb, DucEllipseElement as DucEllipseElementFb, DucEmbeddableElement as DucEmbeddableElementFb, DucFeatureControlFrameElement as DucFeatureControlFrameElementFb, DucFrameElement as DucFrameElementFb, DucFreeDrawElement as DucFreeDrawElementFb, DucImageElement as DucImageElementFb, DucLeaderElement as DucLeaderElementFb, DucLinearElement as DucLinearElementFb, DucMermaidElement as DucMermaidElementFb, DucParametricElement as DucParametricElementFb, DucPdfElement as DucPdfElementFb, DucPlotElement as DucPlotElementFb, DucPolygonElement as DucPolygonElementFb, DucRectangleElement as DucRectangleElementFb, DucTableElement as DucTableElementFb, DucTextDynamicDictionarySource as DucTextDynamicDictionarySourceFb, DucTextDynamicElementSource as DucTextDynamicElementSourceFb, DucTextElement as DucTextElementFb, DucViewportElement as DucViewportElementFb, DucXRayElement as DucXRayElementFb, Element as ElementUnion, ExportedDataState, LEADER_CONTENT_TYPE as LEADER_CONTENT_TYPE_ENUM, LeaderBlockContent as LeaderBlockContentFb, LeaderTextBlockContent as LeaderTextBlockContentFb, TEXT_FIELD_SOURCE_TYPE } from "./flatbuffers/duc";
11
- import { restore } from "./restore";
10
+ import { decompressSync, strFromU8 } from 'fflate';
12
11
  import * as flatbuffers from "flatbuffers";
13
12
  import { nanoid } from 'nanoid';
13
+ import { DOCUMENT_GRID_ALIGN_ITEMS, DucArrowElement as DucArrowElementFb, DucDimensionElement as DucDimensionElementFb, DucDocElement as DucDocElementFb, DucEllipseElement as DucEllipseElementFb, DucEmbeddableElement as DucEmbeddableElementFb, DucFeatureControlFrameElement as DucFeatureControlFrameElementFb, DucFrameElement as DucFrameElementFb, DucFreeDrawElement as DucFreeDrawElementFb, DucImageElement as DucImageElementFb, DucLeaderElement as DucLeaderElementFb, DucLinearElement as DucLinearElementFb, DucMermaidElement as DucMermaidElementFb, DucModelElement as DucModelElementFb, DucPdfElement as DucPdfElementFb, DucPlotElement as DucPlotElementFb, DucPolygonElement as DucPolygonElementFb, DucRectangleElement as DucRectangleElementFb, DucTableElement as DucTableElementFb, DucTextDynamicDictionarySource as DucTextDynamicDictionarySourceFb, DucTextDynamicElementSource as DucTextDynamicElementSourceFb, DucTextElement as DucTextElementFb, DucViewportElement as DucViewportElementFb, DucXRayElement as DucXRayElementFb, Element as ElementUnion, ExportedDataState, LEADER_CONTENT_TYPE as LEADER_CONTENT_TYPE_ENUM, LeaderBlockContent as LeaderBlockContentFb, LeaderTextBlockContent as LeaderTextBlockContentFb, TEXT_FIELD_SOURCE_TYPE } from "./flatbuffers/duc";
14
+ import { restore } from "./restore";
14
15
  // #region HELPERS & LOW-LEVEL CASTS
15
16
  // Helper functions for type casting
16
17
  const toPrecisionValue = (value) => ({
@@ -24,6 +25,29 @@ const toZoom = (value) => ({
24
25
  value: value
25
26
  });
26
27
  // #endregion
28
+ // Helper function to parse binary JSON data (Uint8Array) to object
29
+ // The data is zlib-compressed JSON (new format) or plain JSON string (legacy format)
30
+ function parseBinaryToJson(binaryData) {
31
+ if (!binaryData || binaryData.length === 0)
32
+ return undefined;
33
+ // Try new format: zlib-compressed binary JSON
34
+ try {
35
+ const decompressed = decompressSync(binaryData);
36
+ const text = strFromU8(decompressed);
37
+ return JSON.parse(text);
38
+ }
39
+ catch (e) {
40
+ // Fall back to legacy format: plain JSON string (for old file compatibility)
41
+ try {
42
+ const text = new TextDecoder().decode(binaryData);
43
+ return JSON.parse(text);
44
+ }
45
+ catch (e2) {
46
+ console.warn('Failed to parse binary JSON (tried both compressed and legacy formats):', e2);
47
+ return undefined;
48
+ }
49
+ }
50
+ }
27
51
  // #region GEOMETRY & UTILITY PARSERS
28
52
  export function parseGeometricPoint(point) {
29
53
  return {
@@ -46,6 +70,24 @@ export function parseMargins(margins) {
46
70
  left: toPrecisionValue(margins.left()),
47
71
  };
48
72
  }
73
+ export function parseDocumentGridConfig(gridConfig) {
74
+ return {
75
+ columns: gridConfig.columns(),
76
+ gapX: gridConfig.gapX(),
77
+ gapY: gridConfig.gapY(),
78
+ alignItems: (() => {
79
+ const align = gridConfig.alignItems();
80
+ if (align === DOCUMENT_GRID_ALIGN_ITEMS.START)
81
+ return 'start';
82
+ if (align === DOCUMENT_GRID_ALIGN_ITEMS.CENTER)
83
+ return 'center';
84
+ if (align === DOCUMENT_GRID_ALIGN_ITEMS.END)
85
+ return 'end';
86
+ return 'start';
87
+ })(),
88
+ firstPageAlone: gridConfig.firstPageAlone(),
89
+ };
90
+ }
49
91
  export function parseHead(head) {
50
92
  return {
51
93
  type: head.type(),
@@ -168,7 +210,7 @@ export function parseElementBase(base) {
168
210
  return Object.assign({ id: base.id(), x: toPrecisionValue(base.x()), y: toPrecisionValue(base.y()), width: toPrecisionValue(base.width()), height: toPrecisionValue(base.height()), angle: toRadian(base.angle()), scope: base.scope(), label: base.label(), description: base.description(), isVisible: base.isVisible(), seed: base.seed(), version: base.version(), versionNonce: base.versionNonce(), updated: Number(base.updated()), index: base.index(), isPlot: base.isPlot(), isAnnotative: base.isAnnotative(), isDeleted: base.isDeleted(), groupIds: Array.from({ length: base.groupIdsLength() }, (_, i) => base.groupIds(i)), regionIds: Array.from({ length: base.regionIdsLength() }, (_, i) => base.regionIds(i)), blockIds: Array.from({ length: base.blockIdsLength() }, (_, i) => base.blockIds(i)), instanceId: base.instanceId(), layerId: base.layerId(), frameId: base.frameId(), boundElements: base.boundElementsLength() > 0 ? Array.from({ length: base.boundElementsLength() }, (_, i) => ({
169
211
  id: base.boundElements(i).id(),
170
212
  type: base.boundElements(i).type(),
171
- })) : null, zIndex: base.zIndex(), link: base.link(), locked: base.locked(), customData: base.customData() ? JSON.parse(base.customData()) : undefined }, parsedStyles);
213
+ })) : null, zIndex: base.zIndex(), link: base.link(), locked: base.locked(), customData: parseBinaryToJson(base.customDataArray()) }, parsedStyles);
172
214
  }
173
215
  export function parseLineReference(ref) {
174
216
  return {
@@ -233,7 +275,14 @@ function parseEmbeddableElement(element) {
233
275
  return Object.assign({ type: "embeddable" }, parseElementBase(element.base()));
234
276
  }
235
277
  function parsePdfElement(element) {
236
- return Object.assign(Object.assign({ type: "pdf" }, parseElementBase(element.base())), { fileId: element.fileId() });
278
+ const gridConfig = element.gridConfig();
279
+ return Object.assign(Object.assign({ type: "pdf" }, parseElementBase(element.base())), { fileId: element.fileId(), gridConfig: gridConfig ? parseDocumentGridConfig(gridConfig) : {
280
+ columns: 1,
281
+ gapX: 0,
282
+ gapY: 0,
283
+ alignItems: 'start',
284
+ firstPageAlone: false,
285
+ } });
237
286
  }
238
287
  function parseMermaidElement(element) {
239
288
  return Object.assign(Object.assign({ type: "mermaid" }, parseElementBase(element.base())), { source: element.source(), theme: element.theme() || undefined, svgPath: element.svgPath() });
@@ -364,25 +413,13 @@ function parseBlockInstance(instance) {
364
413
  function parseBlockMetadata(metadataFb) {
365
414
  if (!metadataFb)
366
415
  return undefined;
367
- // localization is a JSON string containing the localization data
368
- let localization;
369
- const localizationStr = metadataFb.localization();
370
- if (localizationStr) {
371
- try {
372
- localization = JSON.parse(localizationStr);
373
- }
374
- catch (e) {
375
- // If parsing fails, leave localization undefined
376
- console.warn('Failed to parse localization JSON:', e);
377
- }
378
- }
379
- return {
380
- source: metadataFb.source(),
381
- usageCount: metadataFb.usageCount(),
382
- createdAt: Number(metadataFb.createdAt()),
383
- updatedAt: Number(metadataFb.updatedAt()),
384
- localization,
385
- };
416
+ // localization is now binary JSON data (Uint8Array)
417
+ const localization = parseBinaryToJson(metadataFb.localizationArray());
418
+ const rawSource = metadataFb.source();
419
+ const source = typeof rawSource === "string" && rawSource.trim().length
420
+ ? rawSource.trim()
421
+ : undefined;
422
+ return Object.assign(Object.assign({}, (source ? { source } : {})), { usageCount: metadataFb.usageCount(), createdAt: Number(metadataFb.createdAt()), updatedAt: Number(metadataFb.updatedAt()), localization });
386
423
  }
387
424
  function parseBlockCollection(collection) {
388
425
  const children = Array.from({ length: collection.childrenLength() }, (_, i) => {
@@ -533,6 +570,7 @@ function parseDocElement(element) {
533
570
  });
534
571
  }
535
572
  const columns = element.columns();
573
+ const gridConfig = element.gridConfig();
536
574
  return Object.assign(Object.assign(Object.assign({ type: "doc" }, parseElementBase(element.base())), parseDocStyle(element.style())), { text: element.text(), dynamic: dynamicParts, flowDirection: element.flowDirection(), columns: {
537
575
  type: columns.type(),
538
576
  definitions: Array.from({ length: columns.definitionsLength() }, (_, i) => {
@@ -543,16 +581,17 @@ function parseDocElement(element) {
543
581
  };
544
582
  }),
545
583
  autoHeight: columns.autoHeight(),
546
- }, autoResize: element.autoResize() });
547
- }
548
- function parseParametricElement(element) {
549
- const source = element.source();
550
- return Object.assign(Object.assign({ type: "parametric" }, parseElementBase(element.base())), { source: {
551
- type: source.type(),
552
- code: source.code(),
553
- fileId: source.fileId(),
584
+ }, autoResize: element.autoResize(), fileId: element.fileId(), gridConfig: gridConfig ? parseDocumentGridConfig(gridConfig) : {
585
+ columns: 1,
586
+ gapX: 0,
587
+ gapY: 0,
588
+ alignItems: 'start',
589
+ firstPageAlone: false,
554
590
  } });
555
591
  }
592
+ function parseModelElement(element) {
593
+ return Object.assign(Object.assign({ type: "model" }, parseElementBase(element.base())), { source: element.source(), svgPath: element.svgPath(), fileIds: Array.from({ length: element.fileIdsLength() }, (_, i) => element.fileIds(i)) });
594
+ }
556
595
  // #endregion
557
596
  // #region STYLE PARSERS (ELEMENT-LEVEL)
558
597
  export function parseTextStyle(style) {
@@ -760,8 +799,8 @@ export function parseElementFromBinary(wrapper) {
760
799
  case ElementUnion.DucDocElement:
761
800
  element = wrapper.element(new DucDocElementFb());
762
801
  break;
763
- case ElementUnion.DucParametricElement:
764
- element = wrapper.element(new DucParametricElementFb());
802
+ case ElementUnion.DucModelElement:
803
+ element = wrapper.element(new DucModelElementFb());
765
804
  break;
766
805
  default:
767
806
  return null;
@@ -811,8 +850,8 @@ export function parseElementFromBinary(wrapper) {
811
850
  return parseFeatureControlFrameElement(element);
812
851
  case ElementUnion.DucDocElement:
813
852
  return parseDocElement(element);
814
- case ElementUnion.DucParametricElement:
815
- return parseParametricElement(element);
853
+ case ElementUnion.DucModelElement:
854
+ return parseModelElement(element);
816
855
  default:
817
856
  return null;
818
857
  }
@@ -1239,15 +1278,7 @@ export function parseVersionGraphFromBinary(graph) {
1239
1278
  description: base.description() || undefined,
1240
1279
  isManualSave: base.isManualSave(),
1241
1280
  userId: base.userId() || undefined,
1242
- patch: Array.from({ length: d.patchLength() }, (_, j) => {
1243
- const p = d.patch(j);
1244
- return {
1245
- op: p.op(),
1246
- path: p.path(),
1247
- from: p.from() || undefined,
1248
- value: p.value() ? JSON.parse(p.value()) : undefined,
1249
- };
1250
- }),
1281
+ patch: parseBinaryToJson(d.patchArray()),
1251
1282
  };
1252
1283
  }),
1253
1284
  metadata: {
@@ -97,12 +97,7 @@ export declare const restoreBlockCollections: (collections: unknown) => Restored
97
97
  * Restores the blockInstances array from imported data, ensuring each item
98
98
  * conforms to the DucBlockInstance type.
99
99
  */
100
- export declare const restoreBlockInstances: (blockInstances: unknown) => RestoredDataState["blockInstances"];
101
- /**
102
- * Restores instances from block instances data (alias for restoreBlockInstances)
103
- * This method provides a consistent naming convention for instance restoration.
104
- */
105
- export declare const restoreInstances: (instances: unknown) => RestoredDataState["blockInstances"];
100
+ export declare const restoreBlockInstances: (blockInstances: unknown, currentScope: Scope) => RestoredDataState["blockInstances"];
106
101
  /**
107
102
  * Restores the global state of the document from imported data.
108
103
  * It validates and provides defaults for missing or invalid properties.
@@ -20,7 +20,7 @@ export const restore = (data, elementsConfig, restoreConfig = {}) => {
20
20
  const restoredRegions = restoreRegions(data === null || data === void 0 ? void 0 : data.regions);
21
21
  const restoredGroups = restoreGroups(data === null || data === void 0 ? void 0 : data.groups);
22
22
  const restoredLayers = restoreLayers(data === null || data === void 0 ? void 0 : data.layers, restoredLocalState.scope);
23
- const restoredBlockInstances = restoreBlockInstances(data === null || data === void 0 ? void 0 : data.blockInstances);
23
+ const restoredBlockInstances = restoreBlockInstances(data === null || data === void 0 ? void 0 : data.blockInstances, restoredLocalState.scope);
24
24
  const restoredElements = restoreElements(data === null || data === void 0 ? void 0 : data.elements, restoredLocalState.scope, restoredBlocks, restoredElementsConfig);
25
25
  const restoredVersionGraph = restoreVersionGraph(data === null || data === void 0 ? void 0 : data.versionGraph);
26
26
  // Generate a new ID if none exists or if it's empty
@@ -247,7 +247,7 @@ export const restoreBlockCollections = (collections) => {
247
247
  * Restores the blockInstances array from imported data, ensuring each item
248
248
  * conforms to the DucBlockInstance type.
249
249
  */
250
- export const restoreBlockInstances = (blockInstances) => {
250
+ export const restoreBlockInstances = (blockInstances, currentScope) => {
251
251
  if (!Array.isArray(blockInstances)) {
252
252
  return [];
253
253
  }
@@ -301,8 +301,8 @@ export const restoreBlockInstances = (blockInstances) => {
301
301
  ? {
302
302
  rows: typeof dupArray.rows === "number" ? dupArray.rows : 1,
303
303
  cols: typeof dupArray.cols === "number" ? dupArray.cols : 1,
304
- rowSpacing: typeof dupArray.rowSpacing === "number" ? dupArray.rowSpacing : 0,
305
- colSpacing: typeof dupArray.colSpacing === "number" ? dupArray.colSpacing : 0,
304
+ rowSpacing: restorePrecisionValue(dupArray.rowSpacing, NEUTRAL_SCOPE, currentScope),
305
+ colSpacing: restorePrecisionValue(dupArray.colSpacing, NEUTRAL_SCOPE, currentScope),
306
306
  }
307
307
  : null,
308
308
  };
@@ -331,20 +331,11 @@ const restoreBlockMetadata = (metadata) => {
331
331
  localization = undefined;
332
332
  }
333
333
  }
334
- return {
335
- source: typeof metadataObj.source === "string" ? metadataObj.source : "",
336
- usageCount: typeof metadataObj.usageCount === "number" ? metadataObj.usageCount : 0,
337
- createdAt: typeof metadataObj.createdAt === "number" ? metadataObj.createdAt : Date.now(),
338
- updatedAt: typeof metadataObj.updatedAt === "number" ? metadataObj.updatedAt : Date.now(),
339
- localization,
340
- };
341
- };
342
- /**
343
- * Restores instances from block instances data (alias for restoreBlockInstances)
344
- * This method provides a consistent naming convention for instance restoration.
345
- */
346
- export const restoreInstances = (instances) => {
347
- return restoreBlockInstances(instances);
334
+ const rawSource = metadataObj.source;
335
+ const source = typeof rawSource === "string" && rawSource.trim().length
336
+ ? rawSource.trim()
337
+ : undefined;
338
+ return Object.assign(Object.assign({}, (source ? { source } : {})), { usageCount: typeof metadataObj.usageCount === "number" ? metadataObj.usageCount : 0, createdAt: typeof metadataObj.createdAt === "number" ? metadataObj.createdAt : Date.now(), updatedAt: typeof metadataObj.updatedAt === "number" ? metadataObj.updatedAt : Date.now(), localization });
348
339
  };
349
340
  /**
350
341
  * Restores the global state of the document from imported data.
@@ -3,7 +3,7 @@ isValidColor, isValidDucHead, isValidEnumValue, isValidFunction, isValidImageSca
3
3
  import { getPrecisionValueFromRaw, getPrecisionValueFromScoped, getScaledZoomValueForScope, getScopedBezierPointFromDucPoint, getScopedZoomValue, NEUTRAL_SCOPE, ScaleFactors, } from "../technical/scopes";
4
4
  import { isElbowArrow, isLinearElement, isTextElement, } from "../types";
5
5
  import { arrayToMap, bumpVersion, DEFAULT_ELEMENT_PROPS, DEFAULT_ELLIPSE_ELEMENT, DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE, DEFAULT_FREEDRAW_ELEMENT, detectLineHeight, FONT_FAMILY, getContainerElement, getDefaultLocalState, getDefaultTableData, getNormalizedDimensions, getNormalizedPoints, getNormalizedZoom, getSizeFromPoints, getUpdatedTimestamp, isFiniteNumber, isInvisiblySmallElement, LINE_CONFIRM_THRESHOLD, mergeOverlappingPoints, migratePoints, normalizeFixedPoint, normalizeLink, randomId, refreshTextDimensions, validateClosedPath, } from "../utils";
6
- import { AXIS, BLOCK_ATTACHMENT, COLUMN_TYPE, DATUM_BRACKET_STYLE, DIMENSION_FIT_RULE, DIMENSION_TEXT_PLACEMENT, DIMENSION_TYPE, GDT_SYMBOL, LEADER_CONTENT_TYPE, LINE_SPACING_TYPE, MARK_ELLIPSE_CENTER, MATERIAL_CONDITION, PARAMETRIC_SOURCE_TYPE, STACKED_TEXT_ALIGN, TABLE_CELL_ALIGNMENT, TABLE_FLOW_DIRECTION, TEXT_FLOW_DIRECTION, TOLERANCE_DISPLAY, TOLERANCE_ZONE_TYPE, VERTICAL_ALIGN, VIEWPORT_SHADE_PLOT, } from "../flatbuffers/duc";
6
+ import { AXIS, BLOCK_ATTACHMENT, COLUMN_TYPE, DATUM_BRACKET_STYLE, DIMENSION_FIT_RULE, DIMENSION_TEXT_PLACEMENT, DIMENSION_TYPE, GDT_SYMBOL, LEADER_CONTENT_TYPE, LINE_SPACING_TYPE, MARK_ELLIPSE_CENTER, MATERIAL_CONDITION, STACKED_TEXT_ALIGN, TABLE_CELL_ALIGNMENT, TABLE_FLOW_DIRECTION, TEXT_FLOW_DIRECTION, TOLERANCE_DISPLAY, TOLERANCE_ZONE_TYPE, VERTICAL_ALIGN, VIEWPORT_SHADE_PLOT, } from "../flatbuffers/duc";
7
7
  import tinycolor from "tinycolor2";
8
8
  const restoreElementWithProperties = (element, extra, localState, globalState) => {
9
9
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
@@ -80,7 +80,7 @@ const restoreElementWithProperties = (element, extra, localState, globalState) =
80
80
  return Object.assign(Object.assign(Object.assign(Object.assign({}, _element), base), normalized), { type: _element.type });
81
81
  };
82
82
  const restoreElement = (element, currentScope, restoredBlocks, localState, globalState) => {
83
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
83
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
84
84
  // Migration: convert deprecated 'diamond' to 'polygon' with 4 sides
85
85
  if (element.type === "diamond") {
86
86
  const migrated = Object.assign(Object.assign({}, element), { type: "polygon", sides: 4 });
@@ -343,7 +343,10 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
343
343
  }
344
344
  // Other elements
345
345
  case "pdf":
346
- return restoreElementWithProperties(element, { fileId: isValidString(element.fileId) || null }, localState);
346
+ return restoreElementWithProperties(element, {
347
+ fileId: isValidString(element.fileId) || null,
348
+ gridConfig: restoreDocumentGridConfig(element.gridConfig),
349
+ }, localState);
347
350
  case "mermaid":
348
351
  return restoreElementWithProperties(element, {
349
352
  source: isValidString(element.source),
@@ -381,7 +384,7 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
381
384
  const docElement = element;
382
385
  return restoreElementWithProperties(element, Object.assign(Object.assign({}, restoreDocStyleProperties(docElement, currentScope)), { text: isValidString(docElement.text), dynamic: restoreTextDynamicParts(docElement.dynamic), flowDirection: (Object.values(TEXT_FLOW_DIRECTION)).includes(docElement.flowDirection)
383
386
  ? docElement.flowDirection
384
- : TEXT_FLOW_DIRECTION.TOP_TO_BOTTOM, columns: restoreTextColumns(docElement.columns, currentScope), autoResize: isValidBooleanValue(docElement.autoResize, true) }), localState);
387
+ : TEXT_FLOW_DIRECTION.TOP_TO_BOTTOM, columns: restoreTextColumns(docElement.columns, currentScope), autoResize: isValidBooleanValue(docElement.autoResize, true), fileId: isValidString(docElement.fileId) || null, gridConfig: restoreDocumentGridConfig(docElement.gridConfig) }), localState);
385
388
  }
386
389
  case "xray": {
387
390
  const xrayElement = element;
@@ -393,22 +396,13 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
393
396
  color: isValidColor(xrayElement.color, "#FF00FF"),
394
397
  }, localState, globalState);
395
398
  }
396
- case "parametric": {
397
- const parametricElement = element;
398
- let source;
399
- if (((_s = parametricElement.source) === null || _s === void 0 ? void 0 : _s.type) === PARAMETRIC_SOURCE_TYPE.FILE) {
400
- source = {
401
- type: PARAMETRIC_SOURCE_TYPE.FILE,
402
- fileId: isValidString((_t = parametricElement.source) === null || _t === void 0 ? void 0 : _t.fileId),
403
- };
404
- }
405
- else {
406
- source = {
407
- type: PARAMETRIC_SOURCE_TYPE.CODE,
408
- code: isValidString((_u = parametricElement.source) === null || _u === void 0 ? void 0 : _u.code),
409
- };
410
- }
411
- return restoreElementWithProperties(parametricElement, { source }, localState, globalState);
399
+ case "model": {
400
+ const modelElement = element;
401
+ return restoreElementWithProperties(modelElement, {
402
+ source: isValidString(modelElement.source),
403
+ fileIds: modelElement.fileIds || [],
404
+ svgPath: modelElement.svgPath || null,
405
+ }, localState, globalState);
412
406
  }
413
407
  case "featurecontrolframe": {
414
408
  const fcfElement = element;
@@ -417,15 +411,15 @@ const restoreElement = (element, currentScope, restoredBlocks, localState, globa
417
411
  // Restore style properties
418
412
  textStyle: restoreTextStyle(fcfElement.textStyle, currentScope),
419
413
  layout: {
420
- padding: restorePrecisionValue((_v = fcfElement.layout) === null || _v === void 0 ? void 0 : _v.padding, elementScope, currentScope, 2),
421
- segmentSpacing: restorePrecisionValue((_w = fcfElement.layout) === null || _w === void 0 ? void 0 : _w.segmentSpacing, elementScope, currentScope, 2),
422
- rowSpacing: restorePrecisionValue((_x = fcfElement.layout) === null || _x === void 0 ? void 0 : _x.rowSpacing, elementScope, currentScope, 2),
414
+ padding: restorePrecisionValue((_s = fcfElement.layout) === null || _s === void 0 ? void 0 : _s.padding, elementScope, currentScope, 2),
415
+ segmentSpacing: restorePrecisionValue((_t = fcfElement.layout) === null || _t === void 0 ? void 0 : _t.segmentSpacing, elementScope, currentScope, 2),
416
+ rowSpacing: restorePrecisionValue((_u = fcfElement.layout) === null || _u === void 0 ? void 0 : _u.rowSpacing, elementScope, currentScope, 2),
423
417
  },
424
418
  symbols: {
425
- scale: (_z = (_y = fcfElement.symbols) === null || _y === void 0 ? void 0 : _y.scale) !== null && _z !== void 0 ? _z : 1,
419
+ scale: (_w = (_v = fcfElement.symbols) === null || _v === void 0 ? void 0 : _v.scale) !== null && _w !== void 0 ? _w : 1,
426
420
  },
427
421
  datumStyle: {
428
- bracketStyle: isValidEnumValue((_0 = fcfElement.datumStyle) === null || _0 === void 0 ? void 0 : _0.bracketStyle, DATUM_BRACKET_STYLE, DATUM_BRACKET_STYLE.SQUARE),
422
+ bracketStyle: isValidEnumValue((_x = fcfElement.datumStyle) === null || _x === void 0 ? void 0 : _x.bracketStyle, DATUM_BRACKET_STYLE, DATUM_BRACKET_STYLE.SQUARE),
429
423
  },
430
424
  // Restore data properties
431
425
  rows: restoreFcfRows(fcfElement.rows),
@@ -973,6 +967,26 @@ const restoreTextColumns = (columns, currentScope) => {
973
967
  autoHeight: isValidBooleanValue(columns.autoHeight, true),
974
968
  };
975
969
  };
970
+ const restoreDocumentGridConfig = (gridConfig) => {
971
+ if (!gridConfig || typeof gridConfig !== "object") {
972
+ return {
973
+ columns: 1,
974
+ gapX: 0,
975
+ gapY: 0,
976
+ alignItems: "start",
977
+ firstPageAlone: false,
978
+ };
979
+ }
980
+ return {
981
+ columns: typeof gridConfig.columns === "number" ? gridConfig.columns : 1,
982
+ gapX: typeof gridConfig.gapX === "number" ? gridConfig.gapX : 0,
983
+ gapY: typeof gridConfig.gapY === "number" ? gridConfig.gapY : 0,
984
+ alignItems: (typeof gridConfig.alignItems === "string" && ["start", "center", "end"].includes(gridConfig.alignItems))
985
+ ? gridConfig.alignItems
986
+ : "start",
987
+ firstPageAlone: typeof gridConfig.firstPageAlone === "boolean" ? gridConfig.firstPageAlone : false,
988
+ };
989
+ };
976
990
  const getFontFamilyByName = (fontFamilyName) => {
977
991
  if (Object.keys(FONT_FAMILY).includes(fontFamilyName)) {
978
992
  return FONT_FAMILY[fontFamilyName];