ducjs 2.1.0 → 2.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.
Files changed (33) hide show
  1. package/dist/flatbuffers/duc/duc-block-collection-entry.d.ts +16 -0
  2. package/dist/flatbuffers/duc/duc-block-collection-entry.js +48 -0
  3. package/dist/flatbuffers/duc/duc-block-collection.d.ts +31 -0
  4. package/dist/flatbuffers/duc/duc-block-collection.js +97 -0
  5. package/dist/flatbuffers/duc/duc-block-instance-element.d.ts +0 -20
  6. package/dist/flatbuffers/duc/duc-block-instance-element.js +0 -66
  7. package/dist/flatbuffers/duc/duc-block-instance.d.ts +32 -0
  8. package/dist/flatbuffers/duc/duc-block-instance.js +100 -0
  9. package/dist/flatbuffers/duc/duc-block-metadata.d.ts +23 -0
  10. package/dist/flatbuffers/duc/duc-block-metadata.js +72 -0
  11. package/dist/flatbuffers/duc/duc-block.d.ts +9 -7
  12. package/dist/flatbuffers/duc/duc-block.js +31 -30
  13. package/dist/flatbuffers/duc/duc-element-base.d.ts +9 -0
  14. package/dist/flatbuffers/duc/duc-element-base.js +29 -1
  15. package/dist/flatbuffers/duc/exported-data-state.d.ts +12 -0
  16. package/dist/flatbuffers/duc/exported-data-state.js +45 -1
  17. package/dist/flatbuffers/duc.d.ts +4 -0
  18. package/dist/flatbuffers/duc.js +4 -0
  19. package/dist/parse.js +95 -20
  20. package/dist/restore/restoreDataState.d.ts +23 -1
  21. package/dist/restore/restoreDataState.js +169 -13
  22. package/dist/serialize.js +124 -30
  23. package/dist/types/elements/index.d.ts +89 -20
  24. package/dist/types/elements/typeChecks.d.ts +1 -2
  25. package/dist/types/elements/typeChecks.js +0 -4
  26. package/dist/types/index.d.ts +3 -1
  27. package/dist/utils/bounds.js +1 -1
  28. package/dist/utils/constants.d.ts +12 -2
  29. package/dist/utils/constants.js +19 -3
  30. package/dist/utils/elements/index.js +1 -0
  31. package/dist/utils/elements/newElement.d.ts +1 -7
  32. package/dist/utils/elements/newElement.js +3 -5
  33. package/package.json +1 -1
@@ -2,7 +2,7 @@
2
2
  /* eslint-disable @typescript-eslint/no-unused-vars, @typescript-eslint/no-explicit-any, @typescript-eslint/no-non-null-assertion */
3
3
  import * as flatbuffers from 'flatbuffers';
4
4
  import { DucBlockAttributeDefinitionEntry } from '../duc/duc-block-attribute-definition-entry';
5
- import { ElementWrapper } from '../duc/element-wrapper';
5
+ import { DucBlockMetadata } from '../duc/duc-block-metadata';
6
6
  export class DucBlock {
7
7
  constructor() {
8
8
  this.bb = null;
@@ -36,24 +36,32 @@ export class DucBlock {
36
36
  const offset = this.bb.__offset(this.bb_pos, 10);
37
37
  return offset ? this.bb.readInt32(this.bb_pos + offset) : 0;
38
38
  }
39
- elements(index, obj) {
39
+ attributeDefinitions(index, obj) {
40
40
  const offset = this.bb.__offset(this.bb_pos, 12);
41
- return offset ? (obj || new ElementWrapper()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
41
+ return offset ? (obj || new DucBlockAttributeDefinitionEntry()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
42
42
  }
43
- elementsLength() {
43
+ attributeDefinitionsLength() {
44
44
  const offset = this.bb.__offset(this.bb_pos, 12);
45
45
  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
46
46
  }
47
- attributeDefinitions(index, obj) {
47
+ metadata(obj) {
48
48
  const offset = this.bb.__offset(this.bb_pos, 14);
49
- return offset ? (obj || new DucBlockAttributeDefinitionEntry()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
49
+ return offset ? (obj || new DucBlockMetadata()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
50
50
  }
51
- attributeDefinitionsLength() {
52
- const offset = this.bb.__offset(this.bb_pos, 14);
51
+ thumbnail(index) {
52
+ const offset = this.bb.__offset(this.bb_pos, 16);
53
+ return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0;
54
+ }
55
+ thumbnailLength() {
56
+ const offset = this.bb.__offset(this.bb_pos, 16);
53
57
  return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
54
58
  }
59
+ thumbnailArray() {
60
+ const offset = this.bb.__offset(this.bb_pos, 16);
61
+ return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
62
+ }
55
63
  static startDucBlock(builder) {
56
- builder.startObject(6);
64
+ builder.startObject(7);
57
65
  }
58
66
  static addId(builder, idOffset) {
59
67
  builder.addFieldOffset(0, idOffset, 0);
@@ -67,45 +75,38 @@ export class DucBlock {
67
75
  static addVersion(builder, version) {
68
76
  builder.addFieldInt32(3, version, 0);
69
77
  }
70
- static addElements(builder, elementsOffset) {
71
- builder.addFieldOffset(4, elementsOffset, 0);
78
+ static addAttributeDefinitions(builder, attributeDefinitionsOffset) {
79
+ builder.addFieldOffset(4, attributeDefinitionsOffset, 0);
72
80
  }
73
- static createElementsVector(builder, data) {
81
+ static createAttributeDefinitionsVector(builder, data) {
74
82
  builder.startVector(4, data.length, 4);
75
83
  for (let i = data.length - 1; i >= 0; i--) {
76
84
  builder.addOffset(data[i]);
77
85
  }
78
86
  return builder.endVector();
79
87
  }
80
- static startElementsVector(builder, numElems) {
88
+ static startAttributeDefinitionsVector(builder, numElems) {
81
89
  builder.startVector(4, numElems, 4);
82
90
  }
83
- static addAttributeDefinitions(builder, attributeDefinitionsOffset) {
84
- builder.addFieldOffset(5, attributeDefinitionsOffset, 0);
91
+ static addMetadata(builder, metadataOffset) {
92
+ builder.addFieldOffset(5, metadataOffset, 0);
85
93
  }
86
- static createAttributeDefinitionsVector(builder, data) {
87
- builder.startVector(4, data.length, 4);
94
+ static addThumbnail(builder, thumbnailOffset) {
95
+ builder.addFieldOffset(6, thumbnailOffset, 0);
96
+ }
97
+ static createThumbnailVector(builder, data) {
98
+ builder.startVector(1, data.length, 1);
88
99
  for (let i = data.length - 1; i >= 0; i--) {
89
- builder.addOffset(data[i]);
100
+ builder.addInt8(data[i]);
90
101
  }
91
102
  return builder.endVector();
92
103
  }
93
- static startAttributeDefinitionsVector(builder, numElems) {
94
- builder.startVector(4, numElems, 4);
104
+ static startThumbnailVector(builder, numElems) {
105
+ builder.startVector(1, numElems, 1);
95
106
  }
96
107
  static endDucBlock(builder) {
97
108
  const offset = builder.endObject();
98
109
  builder.requiredField(offset, 4); // id
99
110
  return offset;
100
111
  }
101
- static createDucBlock(builder, idOffset, labelOffset, descriptionOffset, version, elementsOffset, attributeDefinitionsOffset) {
102
- DucBlock.startDucBlock(builder);
103
- DucBlock.addId(builder, idOffset);
104
- DucBlock.addLabel(builder, labelOffset);
105
- DucBlock.addDescription(builder, descriptionOffset);
106
- DucBlock.addVersion(builder, version);
107
- DucBlock.addElements(builder, elementsOffset);
108
- DucBlock.addAttributeDefinitions(builder, attributeDefinitionsOffset);
109
- return DucBlock.endDucBlock(builder);
110
- }
111
112
  }
@@ -49,6 +49,11 @@ export declare class _DucElementBase {
49
49
  locked(): boolean;
50
50
  customData(): string | null;
51
51
  customData(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null;
52
+ blockIds(index: number): string;
53
+ blockIds(index: number, optionalEncoding: flatbuffers.Encoding): string | Uint8Array;
54
+ blockIdsLength(): number;
55
+ instanceId(): string | null;
56
+ instanceId(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null;
52
57
  static start_DucElementBase(builder: flatbuffers.Builder): void;
53
58
  static addId(builder: flatbuffers.Builder, idOffset: flatbuffers.Offset): void;
54
59
  static addStyles(builder: flatbuffers.Builder, stylesOffset: flatbuffers.Offset): void;
@@ -84,5 +89,9 @@ export declare class _DucElementBase {
84
89
  static addLink(builder: flatbuffers.Builder, linkOffset: flatbuffers.Offset): void;
85
90
  static addLocked(builder: flatbuffers.Builder, locked: boolean): void;
86
91
  static addCustomData(builder: flatbuffers.Builder, customDataOffset: flatbuffers.Offset): void;
92
+ static addBlockIds(builder: flatbuffers.Builder, blockIdsOffset: flatbuffers.Offset): void;
93
+ static createBlockIdsVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset;
94
+ static startBlockIdsVector(builder: flatbuffers.Builder, numElems: number): void;
95
+ static addInstanceId(builder: flatbuffers.Builder, instanceIdOffset: flatbuffers.Offset): void;
87
96
  static end_DucElementBase(builder: flatbuffers.Builder): flatbuffers.Offset;
88
97
  }
@@ -144,8 +144,20 @@ export class _DucElementBase {
144
144
  const offset = this.bb.__offset(this.bb_pos, 58);
145
145
  return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
146
146
  }
147
+ blockIds(index, optionalEncoding) {
148
+ const offset = this.bb.__offset(this.bb_pos, 60);
149
+ return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
150
+ }
151
+ blockIdsLength() {
152
+ const offset = this.bb.__offset(this.bb_pos, 60);
153
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
154
+ }
155
+ instanceId(optionalEncoding) {
156
+ const offset = this.bb.__offset(this.bb_pos, 62);
157
+ return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
158
+ }
147
159
  static start_DucElementBase(builder) {
148
- builder.startObject(28);
160
+ builder.startObject(30);
149
161
  }
150
162
  static addId(builder, idOffset) {
151
163
  builder.addFieldOffset(0, idOffset, 0);
@@ -261,6 +273,22 @@ export class _DucElementBase {
261
273
  static addCustomData(builder, customDataOffset) {
262
274
  builder.addFieldOffset(27, customDataOffset, 0);
263
275
  }
276
+ static addBlockIds(builder, blockIdsOffset) {
277
+ builder.addFieldOffset(28, blockIdsOffset, 0);
278
+ }
279
+ static createBlockIdsVector(builder, data) {
280
+ builder.startVector(4, data.length, 4);
281
+ for (let i = data.length - 1; i >= 0; i--) {
282
+ builder.addOffset(data[i]);
283
+ }
284
+ return builder.endVector();
285
+ }
286
+ static startBlockIdsVector(builder, numElems) {
287
+ builder.startVector(4, numElems, 4);
288
+ }
289
+ static addInstanceId(builder, instanceIdOffset) {
290
+ builder.addFieldOffset(29, instanceIdOffset, 0);
291
+ }
264
292
  static end_DucElementBase(builder) {
265
293
  const offset = builder.endObject();
266
294
  builder.requiredField(offset, 4); // id
@@ -1,6 +1,8 @@
1
1
  import * as flatbuffers from 'flatbuffers';
2
2
  import { DictionaryEntry } from '../duc/dictionary-entry';
3
3
  import { DucBlock } from '../duc/duc-block';
4
+ import { DucBlockCollection } from '../duc/duc-block-collection';
5
+ import { DucBlockInstance } from '../duc/duc-block-instance';
4
6
  import { DucExternalFileEntry } from '../duc/duc-external-file-entry';
5
7
  import { DucGlobalState } from '../duc/duc-global-state';
6
8
  import { DucGroup } from '../duc/duc-group';
@@ -48,6 +50,10 @@ export declare class ExportedDataState {
48
50
  versionGraph(obj?: VersionGraph): VersionGraph | null;
49
51
  id(): string | null;
50
52
  id(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null;
53
+ blockInstances(index: number, obj?: DucBlockInstance): DucBlockInstance | null;
54
+ blockInstancesLength(): number;
55
+ blockCollections(index: number, obj?: DucBlockCollection): DucBlockCollection | null;
56
+ blockCollectionsLength(): number;
51
57
  static startExportedDataState(builder: flatbuffers.Builder): void;
52
58
  static addType(builder: flatbuffers.Builder, typeOffset: flatbuffers.Offset): void;
53
59
  static addVersionLegacy(builder: flatbuffers.Builder, versionLegacy: number): void;
@@ -84,6 +90,12 @@ export declare class ExportedDataState {
84
90
  static startExternalFilesVector(builder: flatbuffers.Builder, numElems: number): void;
85
91
  static addVersionGraph(builder: flatbuffers.Builder, versionGraphOffset: flatbuffers.Offset): void;
86
92
  static addId(builder: flatbuffers.Builder, idOffset: flatbuffers.Offset): void;
93
+ static addBlockInstances(builder: flatbuffers.Builder, blockInstancesOffset: flatbuffers.Offset): void;
94
+ static createBlockInstancesVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset;
95
+ static startBlockInstancesVector(builder: flatbuffers.Builder, numElems: number): void;
96
+ static addBlockCollections(builder: flatbuffers.Builder, blockCollectionsOffset: flatbuffers.Offset): void;
97
+ static createBlockCollectionsVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset;
98
+ static startBlockCollectionsVector(builder: flatbuffers.Builder, numElems: number): void;
87
99
  static endExportedDataState(builder: flatbuffers.Builder): flatbuffers.Offset;
88
100
  static finishExportedDataStateBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void;
89
101
  static finishSizePrefixedExportedDataStateBuffer(builder: flatbuffers.Builder, offset: flatbuffers.Offset): void;
@@ -3,6 +3,8 @@
3
3
  import * as flatbuffers from 'flatbuffers';
4
4
  import { DictionaryEntry } from '../duc/dictionary-entry';
5
5
  import { DucBlock } from '../duc/duc-block';
6
+ import { DucBlockCollection } from '../duc/duc-block-collection';
7
+ import { DucBlockInstance } from '../duc/duc-block-instance';
6
8
  import { DucExternalFileEntry } from '../duc/duc-external-file-entry';
7
9
  import { DucGlobalState } from '../duc/duc-global-state';
8
10
  import { DucGroup } from '../duc/duc-group';
@@ -140,8 +142,24 @@ export class ExportedDataState {
140
142
  const offset = this.bb.__offset(this.bb_pos, 36);
141
143
  return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
142
144
  }
145
+ blockInstances(index, obj) {
146
+ const offset = this.bb.__offset(this.bb_pos, 38);
147
+ return offset ? (obj || new DucBlockInstance()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
148
+ }
149
+ blockInstancesLength() {
150
+ const offset = this.bb.__offset(this.bb_pos, 38);
151
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
152
+ }
153
+ blockCollections(index, obj) {
154
+ const offset = this.bb.__offset(this.bb_pos, 40);
155
+ return offset ? (obj || new DucBlockCollection()).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
156
+ }
157
+ blockCollectionsLength() {
158
+ const offset = this.bb.__offset(this.bb_pos, 40);
159
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
160
+ }
143
161
  static startExportedDataState(builder) {
144
- builder.startObject(17);
162
+ builder.startObject(19);
145
163
  }
146
164
  static addType(builder, typeOffset) {
147
165
  builder.addFieldOffset(0, typeOffset, 0);
@@ -284,6 +302,32 @@ export class ExportedDataState {
284
302
  static addId(builder, idOffset) {
285
303
  builder.addFieldOffset(16, idOffset, 0);
286
304
  }
305
+ static addBlockInstances(builder, blockInstancesOffset) {
306
+ builder.addFieldOffset(17, blockInstancesOffset, 0);
307
+ }
308
+ static createBlockInstancesVector(builder, data) {
309
+ builder.startVector(4, data.length, 4);
310
+ for (let i = data.length - 1; i >= 0; i--) {
311
+ builder.addOffset(data[i]);
312
+ }
313
+ return builder.endVector();
314
+ }
315
+ static startBlockInstancesVector(builder, numElems) {
316
+ builder.startVector(4, numElems, 4);
317
+ }
318
+ static addBlockCollections(builder, blockCollectionsOffset) {
319
+ builder.addFieldOffset(18, blockCollectionsOffset, 0);
320
+ }
321
+ static createBlockCollectionsVector(builder, data) {
322
+ builder.startVector(4, data.length, 4);
323
+ for (let i = data.length - 1; i >= 0; i--) {
324
+ builder.addOffset(data[i]);
325
+ }
326
+ return builder.endVector();
327
+ }
328
+ static startBlockCollectionsVector(builder, numElems) {
329
+ builder.startVector(4, numElems, 4);
330
+ }
287
331
  static endExportedDataState(builder) {
288
332
  const offset = builder.endObject();
289
333
  return offset;
@@ -35,8 +35,12 @@ export { DucArrowElement } from './duc/duc-arrow-element';
35
35
  export { DucBlock } from './duc/duc-block';
36
36
  export { DucBlockAttributeDefinition } from './duc/duc-block-attribute-definition';
37
37
  export { DucBlockAttributeDefinitionEntry } from './duc/duc-block-attribute-definition-entry';
38
+ export { DucBlockCollection } from './duc/duc-block-collection';
39
+ export { DucBlockCollectionEntry } from './duc/duc-block-collection-entry';
38
40
  export { DucBlockDuplicationArray } from './duc/duc-block-duplication-array';
41
+ export { DucBlockInstance } from './duc/duc-block-instance';
39
42
  export { DucBlockInstanceElement } from './duc/duc-block-instance-element';
43
+ export { DucBlockMetadata } from './duc/duc-block-metadata';
40
44
  export { DucCommonStyle } from './duc/duc-common-style';
41
45
  export { DucDimensionElement } from './duc/duc-dimension-element';
42
46
  export { DucDimensionStyle } from './duc/duc-dimension-style';
@@ -37,8 +37,12 @@ export { DucArrowElement } from './duc/duc-arrow-element';
37
37
  export { DucBlock } from './duc/duc-block';
38
38
  export { DucBlockAttributeDefinition } from './duc/duc-block-attribute-definition';
39
39
  export { DucBlockAttributeDefinitionEntry } from './duc/duc-block-attribute-definition-entry';
40
+ export { DucBlockCollection } from './duc/duc-block-collection';
41
+ export { DucBlockCollectionEntry } from './duc/duc-block-collection-entry';
40
42
  export { DucBlockDuplicationArray } from './duc/duc-block-duplication-array';
43
+ export { DucBlockInstance } from './duc/duc-block-instance';
41
44
  export { DucBlockInstanceElement } from './duc/duc-block-instance-element';
45
+ export { DucBlockMetadata } from './duc/duc-block-metadata';
42
46
  export { DucCommonStyle } from './duc/duc-common-style';
43
47
  export { DucDimensionElement } from './duc/duc-dimension-element';
44
48
  export { DucDimensionStyle } from './duc/duc-dimension-style';
package/dist/parse.js CHANGED
@@ -7,9 +7,10 @@ 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, DucBlockInstanceElement as DucBlockInstanceElementFb, 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";
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
11
  import { restore } from "./restore";
12
12
  import * as flatbuffers from "flatbuffers";
13
+ import { nanoid } from 'nanoid';
13
14
  // #region HELPERS & LOW-LEVEL CASTS
14
15
  // Helper functions for type casting
15
16
  const toPrecisionValue = (value) => ({
@@ -164,7 +165,7 @@ export function parseElementBase(base) {
164
165
  stroke: [],
165
166
  opacity: toPercentage(1),
166
167
  };
167
- 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)), layerId: base.layerId(), frameId: base.frameId(), boundElements: base.boundElementsLength() > 0 ? Array.from({ length: base.boundElementsLength() }, (_, i) => ({
168
+ 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) => ({
168
169
  id: base.boundElements(i).id(),
169
170
  type: base.boundElements(i).type(),
170
171
  })) : null, zIndex: base.zIndex(), link: base.link(), locked: base.locked(), customData: base.customData() ? JSON.parse(base.customData()) : undefined }, parsedStyles);
@@ -333,24 +334,72 @@ function parseFreeDrawElement(element) {
333
334
  const end = element.end();
334
335
  return Object.assign(Object.assign({ type: "freedraw" }, parseElementBase(element.base())), { points: Array.from({ length: element.pointsLength() }, (_, i) => parsePoint(element.points(i))), size: toPrecisionValue(element.size()), thinning: toPercentage(element.thinning()), smoothing: toPercentage(element.smoothing()), streamline: toPercentage(element.streamline()), easing: element.easing(), start: start ? { cap: start.cap(), taper: start.taper(), easing: start.easing() } : null, end: end ? { cap: end.cap(), taper: end.taper(), easing: end.easing() } : null, pressures: Array.from(element.pressuresArray() || []), simulatePressure: element.simulatePressure(), lastCommittedPoint: element.lastCommittedPoint() ? parsePoint(element.lastCommittedPoint()) : null, svgPath: element.svgPath() });
335
336
  }
336
- function parseBlockInstanceElement(element) {
337
- const duplicationArray = element.duplicationArray();
337
+ function parseBlockInstance(instance) {
338
+ const duplicationArray = instance.duplicationArray();
338
339
  const attributeValues = {};
339
- for (let i = 0; i < element.attributeValuesLength(); i++) {
340
- const entry = element.attributeValues(i);
340
+ for (let i = 0; i < instance.attributeValuesLength(); i++) {
341
+ const entry = instance.attributeValues(i);
341
342
  attributeValues[entry.key()] = entry.value();
342
343
  }
343
344
  const elementOverrides = {};
344
- for (let i = 0; i < element.elementOverridesLength(); i++) {
345
- const entry = element.elementOverrides(i);
345
+ for (let i = 0; i < instance.elementOverridesLength(); i++) {
346
+ const entry = instance.elementOverrides(i);
346
347
  elementOverrides[entry.key()] = entry.value();
347
348
  }
348
- return Object.assign(Object.assign({ type: "blockinstance" }, parseElementBase(element.base())), { blockId: element.blockId(), attributeValues: attributeValues, elementOverrides: elementOverrides, duplicationArray: duplicationArray ? {
349
+ return {
350
+ id: instance.id(),
351
+ blockId: instance.blockId(),
352
+ version: instance.version(),
353
+ attributeValues: attributeValues,
354
+ elementOverrides: elementOverrides,
355
+ duplicationArray: duplicationArray ? {
349
356
  rows: duplicationArray.rows(),
350
357
  cols: duplicationArray.cols(),
351
358
  rowSpacing: toPrecisionValue(duplicationArray.rowSpacing()),
352
359
  colSpacing: toPrecisionValue(duplicationArray.colSpacing()),
353
- } : null });
360
+ } : null,
361
+ };
362
+ }
363
+ // Helper function to parse block metadata from FlatBuffers
364
+ function parseBlockMetadata(metadataFb) {
365
+ if (!metadataFb)
366
+ 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
+ };
386
+ }
387
+ function parseBlockCollection(collection) {
388
+ const children = Array.from({ length: collection.childrenLength() }, (_, i) => {
389
+ const child = collection.children(i);
390
+ return {
391
+ id: child.id(),
392
+ isCollection: child.isCollection(),
393
+ };
394
+ });
395
+ const metadata = parseBlockMetadata(collection.metadata());
396
+ return {
397
+ id: collection.id(),
398
+ label: collection.label(),
399
+ children,
400
+ metadata,
401
+ thumbnail: collection.thumbnailArray() || undefined,
402
+ };
354
403
  }
355
404
  function parseFrameElement(element) {
356
405
  return Object.assign({ type: "frame" }, parseStackElementBase(element.stackElementBase()));
@@ -687,9 +736,6 @@ export function parseElementFromBinary(wrapper) {
687
736
  case ElementUnion.DucFreeDrawElement:
688
737
  element = wrapper.element(new DucFreeDrawElementFb());
689
738
  break;
690
- case ElementUnion.DucBlockInstanceElement:
691
- element = wrapper.element(new DucBlockInstanceElementFb());
692
- break;
693
739
  case ElementUnion.DucFrameElement:
694
740
  element = wrapper.element(new DucFrameElementFb());
695
741
  break;
@@ -749,8 +795,6 @@ export function parseElementFromBinary(wrapper) {
749
795
  return parseArrowElement(element);
750
796
  case ElementUnion.DucFreeDrawElement:
751
797
  return parseFreeDrawElement(element);
752
- case ElementUnion.DucBlockInstanceElement:
753
- return parseBlockInstanceElement(element);
754
798
  case ElementUnion.DucFrameElement:
755
799
  return parseFrameElement(element);
756
800
  case ElementUnion.DucPlotElement:
@@ -787,14 +831,18 @@ export function parseBlockFromBinary(block) {
787
831
  isConstant: def.isConstant(),
788
832
  };
789
833
  }
834
+ // Parse metadata if present
835
+ const metadata = parseBlockMetadata(block.metadata());
836
+ // Parse thumbnail if present
837
+ const thumbnail = block.thumbnailArray();
790
838
  return {
791
839
  id: block.id(),
792
840
  label: block.label(),
793
841
  description: block.description() || undefined,
794
842
  version: block.version(),
795
- // Filter out any nulls that may arise from malformed entries
796
- elements: Array.from({ length: block.elementsLength() }, (_, i) => parseElementFromBinary(block.elements(i))).filter(Boolean),
797
843
  attributeDefinitions,
844
+ metadata,
845
+ thumbnail: thumbnail || undefined,
798
846
  };
799
847
  }
800
848
  export function parseDictionaryFromBinary(data) {
@@ -1266,6 +1314,28 @@ export const parseDuc = (blob_1, ...args_1) => __awaiter(void 0, [blob_1, ...arg
1266
1314
  }
1267
1315
  }
1268
1316
  }
1317
+ // Parse block instances
1318
+ const blockInstances = [];
1319
+ for (let i = 0; i < data.blockInstancesLength(); i++) {
1320
+ const blockInstance = data.blockInstances(i);
1321
+ if (blockInstance) {
1322
+ const parsedBlockInstance = parseBlockInstance(blockInstance);
1323
+ if (parsedBlockInstance) {
1324
+ blockInstances.push(parsedBlockInstance);
1325
+ }
1326
+ }
1327
+ }
1328
+ // Parse block collections
1329
+ const blockCollections = [];
1330
+ for (let i = 0; i < data.blockCollectionsLength(); i++) {
1331
+ const blockCollection = data.blockCollections(i);
1332
+ if (blockCollection) {
1333
+ const parsedBlockCollection = parseBlockCollection(blockCollection);
1334
+ if (parsedBlockCollection) {
1335
+ blockCollections.push(parsedBlockCollection);
1336
+ }
1337
+ }
1338
+ }
1269
1339
  // Parse groups
1270
1340
  const groups = [];
1271
1341
  for (let i = 0; i < data.groupsLength(); i++) {
@@ -1317,21 +1387,24 @@ export const parseDuc = (blob_1, ...args_1) => __awaiter(void 0, [blob_1, ...arg
1317
1387
  }
1318
1388
  }
1319
1389
  }
1320
- const sanitized = restore({
1390
+ const exportData = {
1321
1391
  thumbnail,
1322
1392
  dictionary,
1323
1393
  elements: elements,
1324
1394
  localState: parsedLocalState,
1325
1395
  globalState: parsedGlobalState,
1326
1396
  blocks,
1397
+ blockInstances,
1398
+ blockCollections,
1327
1399
  groups,
1328
1400
  regions,
1329
1401
  layers,
1330
1402
  standards,
1331
1403
  files: parsedFiles,
1332
1404
  versionGraph: versionGraph !== null && versionGraph !== void 0 ? versionGraph : undefined,
1333
- id: (_a = data.id()) !== null && _a !== void 0 ? _a : undefined,
1334
- }, {
1405
+ id: (_a = data.id()) !== null && _a !== void 0 ? _a : nanoid(),
1406
+ };
1407
+ const sanitized = restore(exportData, {
1335
1408
  syncInvalidIndices: (elements) => elements,
1336
1409
  repairBindings: true,
1337
1410
  refreshDimensions: false,
@@ -1344,9 +1417,11 @@ export const parseDuc = (blob_1, ...args_1) => __awaiter(void 0, [blob_1, ...arg
1344
1417
  globalState: sanitized.globalState,
1345
1418
  files: sanitized.files,
1346
1419
  blocks: sanitized.blocks,
1420
+ blockInstances: sanitized.blockInstances,
1347
1421
  groups: sanitized.groups,
1348
1422
  regions: sanitized.regions,
1349
1423
  layers: sanitized.layers,
1424
+ blockCollections: sanitized.blockCollections,
1350
1425
  standards: sanitized.standards,
1351
1426
  versionGraph: sanitized.versionGraph,
1352
1427
  id: sanitized.id,
@@ -2,7 +2,7 @@ import { BLENDING } from "../flatbuffers/duc";
2
2
  import { Standard } from "../technical/standards";
3
3
  import type { Dictionary, DucExternalFiles, DucGlobalState, ImportedDataState, LibraryItems, PrecisionValue, Scope, VersionGraph } from "../types";
4
4
  import { DucLocalState } from "../types";
5
- import type { _DucStackBase, BezierMirroring, DucBlock, DucElement, DucGroup, DucHead, DucLayer, DucRegion, ElementBackground, ElementContentBase, ElementStroke, ExternalFileId, FillStyle, ImageStatus, LineHead, OrderedDucElement, StrokeCap, StrokeJoin, StrokePreference, StrokeSidePreference, StrokeStyle, TextAlign, VerticalAlign } from "../types/elements";
5
+ import type { _DucStackBase, BezierMirroring, DucBlock, DucBlockCollection, DucBlockInstance, DucElement, DucGroup, DucHead, DucLayer, DucRegion, ElementBackground, ElementContentBase, ElementStroke, ExternalFileId, FillStyle, ImageStatus, LineHead, OrderedDucElement, StrokeCap, StrokeJoin, StrokePreference, StrokeSidePreference, StrokeStyle, TextAlign, VerticalAlign } from "../types/elements";
6
6
  import { Percentage, Radian } from "../types/geometryTypes";
7
7
  import { ValueOf } from "../types/utility-types";
8
8
  import { VERSIONS } from "../utils/constants";
@@ -15,6 +15,8 @@ export type RestoredDataState = {
15
15
  globalState: DucGlobalState;
16
16
  files: DucExternalFiles;
17
17
  blocks: DucBlock[];
18
+ blockInstances: DucBlockInstance[];
19
+ blockCollections: DucBlockCollection[];
18
20
  groups: DucGroup[];
19
21
  regions: DucRegion[];
20
22
  layers: DucLayer[];
@@ -87,6 +89,20 @@ export declare const restoreRegions: (regions: unknown) => RestoredDataState["re
87
89
  * providing the complete block list from Pass 1 as the necessary context.
88
90
  */
89
91
  export declare const restoreBlocks: (blocks: unknown, currentScope: Scope, elementsConfig: ElementsConfig) => RestoredDataState["blocks"];
92
+ /**
93
+ * Restores the blockCollections array.
94
+ */
95
+ export declare const restoreBlockCollections: (collections: unknown) => RestoredDataState["blockCollections"];
96
+ /**
97
+ * Restores the blockInstances array from imported data, ensuring each item
98
+ * conforms to the DucBlockInstance type.
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"];
90
106
  /**
91
107
  * Restores the global state of the document from imported data.
92
108
  * It validates and provides defaults for missing or invalid properties.
@@ -163,6 +179,12 @@ export declare const isValidColor: (value: any, defaultValue?: string) => string
163
179
  * Returns the string if valid, otherwise returns the provided defaultValue or an empty string.
164
180
  */
165
181
  export declare const isValidString: (value: any, defaultValue?: string) => string;
182
+ /**
183
+ * Validates a number value.
184
+ * Returns the number if valid, otherwise returns the provided defaultValue or 0.
185
+ * Optionally parses numeric strings.
186
+ */
187
+ export declare const isValidNumber: (value: any, defaultValue?: number, parseStrings?: boolean) => number;
166
188
  export declare const isValidExternalFileId: (value: any, defaultValue?: ExternalFileId) => ExternalFileId;
167
189
  /**
168
190
  * Validates a value to ensure it is or can be converted to a non-empty Uint8Array.