ducjs 2.1.0 → 2.2.3

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 (37) 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/duc-block-collection-entry.d.ts +16 -0
  4. package/dist/flatbuffers/duc/duc-block-collection-entry.js +48 -0
  5. package/dist/flatbuffers/duc/duc-block-collection.d.ts +31 -0
  6. package/dist/flatbuffers/duc/duc-block-collection.js +97 -0
  7. package/dist/flatbuffers/duc/duc-block-instance-element.d.ts +0 -20
  8. package/dist/flatbuffers/duc/duc-block-instance-element.js +0 -66
  9. package/dist/flatbuffers/duc/duc-block-instance.d.ts +32 -0
  10. package/dist/flatbuffers/duc/duc-block-instance.js +100 -0
  11. package/dist/flatbuffers/duc/duc-block-metadata.d.ts +26 -0
  12. package/dist/flatbuffers/duc/duc-block-metadata.js +90 -0
  13. package/dist/flatbuffers/duc/duc-block.d.ts +9 -7
  14. package/dist/flatbuffers/duc/duc-block.js +31 -30
  15. package/dist/flatbuffers/duc/duc-element-base.d.ts +14 -2
  16. package/dist/flatbuffers/duc/duc-element-base.js +50 -4
  17. package/dist/flatbuffers/duc/exported-data-state.d.ts +12 -0
  18. package/dist/flatbuffers/duc/exported-data-state.js +45 -1
  19. package/dist/flatbuffers/duc.d.ts +4 -0
  20. package/dist/flatbuffers/duc.js +4 -0
  21. package/dist/parse.js +110 -31
  22. package/dist/restore/restoreDataState.d.ts +23 -1
  23. package/dist/restore/restoreDataState.js +167 -13
  24. package/dist/serialize.js +132 -47
  25. package/dist/types/elements/index.d.ts +91 -20
  26. package/dist/types/elements/typeChecks.d.ts +1 -2
  27. package/dist/types/elements/typeChecks.js +0 -4
  28. package/dist/types/index.d.ts +5 -2
  29. package/dist/utils/bounds.js +1 -1
  30. package/dist/utils/constants.d.ts +12 -2
  31. package/dist/utils/constants.js +19 -3
  32. package/dist/utils/elements/index.js +1 -0
  33. package/dist/utils/elements/newElement.d.ts +1 -7
  34. package/dist/utils/elements/newElement.js +3 -5
  35. package/dist/utils/index.d.ts +1 -0
  36. package/dist/utils/index.js +5 -0
  37. package/package.json +6 -5
@@ -1,6 +1,6 @@
1
1
  import * as flatbuffers from 'flatbuffers';
2
2
  import { DucBlockAttributeDefinitionEntry } from '../duc/duc-block-attribute-definition-entry';
3
- import { ElementWrapper } from '../duc/element-wrapper';
3
+ import { DucBlockMetadata } from '../duc/duc-block-metadata';
4
4
  export declare class DucBlock {
5
5
  bb: flatbuffers.ByteBuffer | null;
6
6
  bb_pos: number;
@@ -14,21 +14,23 @@ export declare class DucBlock {
14
14
  description(): string | null;
15
15
  description(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null;
16
16
  version(): number;
17
- elements(index: number, obj?: ElementWrapper): ElementWrapper | null;
18
- elementsLength(): number;
19
17
  attributeDefinitions(index: number, obj?: DucBlockAttributeDefinitionEntry): DucBlockAttributeDefinitionEntry | null;
20
18
  attributeDefinitionsLength(): number;
19
+ metadata(obj?: DucBlockMetadata): DucBlockMetadata | null;
20
+ thumbnail(index: number): number | null;
21
+ thumbnailLength(): number;
22
+ thumbnailArray(): Uint8Array | null;
21
23
  static startDucBlock(builder: flatbuffers.Builder): void;
22
24
  static addId(builder: flatbuffers.Builder, idOffset: flatbuffers.Offset): void;
23
25
  static addLabel(builder: flatbuffers.Builder, labelOffset: flatbuffers.Offset): void;
24
26
  static addDescription(builder: flatbuffers.Builder, descriptionOffset: flatbuffers.Offset): void;
25
27
  static addVersion(builder: flatbuffers.Builder, version: number): void;
26
- static addElements(builder: flatbuffers.Builder, elementsOffset: flatbuffers.Offset): void;
27
- static createElementsVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset;
28
- static startElementsVector(builder: flatbuffers.Builder, numElems: number): void;
29
28
  static addAttributeDefinitions(builder: flatbuffers.Builder, attributeDefinitionsOffset: flatbuffers.Offset): void;
30
29
  static createAttributeDefinitionsVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset;
31
30
  static startAttributeDefinitionsVector(builder: flatbuffers.Builder, numElems: number): void;
31
+ static addMetadata(builder: flatbuffers.Builder, metadataOffset: flatbuffers.Offset): void;
32
+ static addThumbnail(builder: flatbuffers.Builder, thumbnailOffset: flatbuffers.Offset): void;
33
+ static createThumbnailVector(builder: flatbuffers.Builder, data: number[] | Uint8Array): flatbuffers.Offset;
34
+ static startThumbnailVector(builder: flatbuffers.Builder, numElems: number): void;
32
35
  static endDucBlock(builder: flatbuffers.Builder): flatbuffers.Offset;
33
- static createDucBlock(builder: flatbuffers.Builder, idOffset: flatbuffers.Offset, labelOffset: flatbuffers.Offset, descriptionOffset: flatbuffers.Offset, version: number, elementsOffset: flatbuffers.Offset, attributeDefinitionsOffset: flatbuffers.Offset): flatbuffers.Offset;
34
36
  }
@@ -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
  }
@@ -47,8 +47,14 @@ export declare class _DucElementBase {
47
47
  link(): string | null;
48
48
  link(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null;
49
49
  locked(): boolean;
50
- customData(): string | null;
51
- customData(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null;
50
+ blockIds(index: number): string;
51
+ blockIds(index: number, optionalEncoding: flatbuffers.Encoding): string | Uint8Array;
52
+ blockIdsLength(): number;
53
+ instanceId(): string | null;
54
+ instanceId(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null;
55
+ customData(index: number): number | null;
56
+ customDataLength(): number;
57
+ customDataArray(): Uint8Array | null;
52
58
  static start_DucElementBase(builder: flatbuffers.Builder): void;
53
59
  static addId(builder: flatbuffers.Builder, idOffset: flatbuffers.Offset): void;
54
60
  static addStyles(builder: flatbuffers.Builder, stylesOffset: flatbuffers.Offset): void;
@@ -83,6 +89,12 @@ export declare class _DucElementBase {
83
89
  static addZIndex(builder: flatbuffers.Builder, zIndex: number): void;
84
90
  static addLink(builder: flatbuffers.Builder, linkOffset: flatbuffers.Offset): void;
85
91
  static addLocked(builder: flatbuffers.Builder, locked: boolean): 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;
86
96
  static addCustomData(builder: flatbuffers.Builder, customDataOffset: flatbuffers.Offset): void;
97
+ static createCustomDataVector(builder: flatbuffers.Builder, data: number[] | Uint8Array): flatbuffers.Offset;
98
+ static startCustomDataVector(builder: flatbuffers.Builder, numElems: number): void;
87
99
  static end_DucElementBase(builder: flatbuffers.Builder): flatbuffers.Offset;
88
100
  }
@@ -140,12 +140,32 @@ export class _DucElementBase {
140
140
  const offset = this.bb.__offset(this.bb_pos, 56);
141
141
  return offset ? !!this.bb.readInt8(this.bb_pos + offset) : false;
142
142
  }
143
- customData(optionalEncoding) {
144
- const offset = this.bb.__offset(this.bb_pos, 58);
143
+ blockIds(index, optionalEncoding) {
144
+ const offset = this.bb.__offset(this.bb_pos, 60);
145
+ return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
146
+ }
147
+ blockIdsLength() {
148
+ const offset = this.bb.__offset(this.bb_pos, 60);
149
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
150
+ }
151
+ instanceId(optionalEncoding) {
152
+ const offset = this.bb.__offset(this.bb_pos, 62);
145
153
  return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
146
154
  }
155
+ customData(index) {
156
+ const offset = this.bb.__offset(this.bb_pos, 64);
157
+ return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0;
158
+ }
159
+ customDataLength() {
160
+ const offset = this.bb.__offset(this.bb_pos, 64);
161
+ return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
162
+ }
163
+ customDataArray() {
164
+ const offset = this.bb.__offset(this.bb_pos, 64);
165
+ 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;
166
+ }
147
167
  static start_DucElementBase(builder) {
148
- builder.startObject(28);
168
+ builder.startObject(31);
149
169
  }
150
170
  static addId(builder, idOffset) {
151
171
  builder.addFieldOffset(0, idOffset, 0);
@@ -258,8 +278,34 @@ export class _DucElementBase {
258
278
  static addLocked(builder, locked) {
259
279
  builder.addFieldInt8(26, +locked, +false);
260
280
  }
281
+ static addBlockIds(builder, blockIdsOffset) {
282
+ builder.addFieldOffset(28, blockIdsOffset, 0);
283
+ }
284
+ static createBlockIdsVector(builder, data) {
285
+ builder.startVector(4, data.length, 4);
286
+ for (let i = data.length - 1; i >= 0; i--) {
287
+ builder.addOffset(data[i]);
288
+ }
289
+ return builder.endVector();
290
+ }
291
+ static startBlockIdsVector(builder, numElems) {
292
+ builder.startVector(4, numElems, 4);
293
+ }
294
+ static addInstanceId(builder, instanceIdOffset) {
295
+ builder.addFieldOffset(29, instanceIdOffset, 0);
296
+ }
261
297
  static addCustomData(builder, customDataOffset) {
262
- builder.addFieldOffset(27, customDataOffset, 0);
298
+ builder.addFieldOffset(30, customDataOffset, 0);
299
+ }
300
+ static createCustomDataVector(builder, data) {
301
+ builder.startVector(1, data.length, 1);
302
+ for (let i = data.length - 1; i >= 0; i--) {
303
+ builder.addInt8(data[i]);
304
+ }
305
+ return builder.endVector();
306
+ }
307
+ static startCustomDataVector(builder, numElems) {
308
+ builder.startVector(1, numElems, 1);
263
309
  }
264
310
  static end_DucElementBase(builder) {
265
311
  const offset = builder.endObject();
@@ -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,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, 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";
11
- import { restore } from "./restore";
10
+ import { decompressSync, strFromU8 } from 'fflate';
12
11
  import * as flatbuffers from "flatbuffers";
12
+ import { nanoid } from 'nanoid';
13
+ 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";
14
+ import { restore } from "./restore";
13
15
  // #region HELPERS & LOW-LEVEL CASTS
14
16
  // Helper functions for type casting
15
17
  const toPrecisionValue = (value) => ({
@@ -23,6 +25,29 @@ const toZoom = (value) => ({
23
25
  value: value
24
26
  });
25
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
+ }
26
51
  // #region GEOMETRY & UTILITY PARSERS
27
52
  export function parseGeometricPoint(point) {
28
53
  return {
@@ -164,10 +189,10 @@ export function parseElementBase(base) {
164
189
  stroke: [],
165
190
  opacity: toPercentage(1),
166
191
  };
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) => ({
192
+ 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
193
  id: base.boundElements(i).id(),
169
194
  type: base.boundElements(i).type(),
170
- })) : null, zIndex: base.zIndex(), link: base.link(), locked: base.locked(), customData: base.customData() ? JSON.parse(base.customData()) : undefined }, parsedStyles);
195
+ })) : null, zIndex: base.zIndex(), link: base.link(), locked: base.locked(), customData: parseBinaryToJson(base.customDataArray()) }, parsedStyles);
171
196
  }
172
197
  export function parseLineReference(ref) {
173
198
  return {
@@ -333,24 +358,60 @@ function parseFreeDrawElement(element) {
333
358
  const end = element.end();
334
359
  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
360
  }
336
- function parseBlockInstanceElement(element) {
337
- const duplicationArray = element.duplicationArray();
361
+ function parseBlockInstance(instance) {
362
+ const duplicationArray = instance.duplicationArray();
338
363
  const attributeValues = {};
339
- for (let i = 0; i < element.attributeValuesLength(); i++) {
340
- const entry = element.attributeValues(i);
364
+ for (let i = 0; i < instance.attributeValuesLength(); i++) {
365
+ const entry = instance.attributeValues(i);
341
366
  attributeValues[entry.key()] = entry.value();
342
367
  }
343
368
  const elementOverrides = {};
344
- for (let i = 0; i < element.elementOverridesLength(); i++) {
345
- const entry = element.elementOverrides(i);
369
+ for (let i = 0; i < instance.elementOverridesLength(); i++) {
370
+ const entry = instance.elementOverrides(i);
346
371
  elementOverrides[entry.key()] = entry.value();
347
372
  }
348
- return Object.assign(Object.assign({ type: "blockinstance" }, parseElementBase(element.base())), { blockId: element.blockId(), attributeValues: attributeValues, elementOverrides: elementOverrides, duplicationArray: duplicationArray ? {
373
+ return {
374
+ id: instance.id(),
375
+ blockId: instance.blockId(),
376
+ version: instance.version(),
377
+ attributeValues: attributeValues,
378
+ elementOverrides: elementOverrides,
379
+ duplicationArray: duplicationArray ? {
349
380
  rows: duplicationArray.rows(),
350
381
  cols: duplicationArray.cols(),
351
382
  rowSpacing: toPrecisionValue(duplicationArray.rowSpacing()),
352
383
  colSpacing: toPrecisionValue(duplicationArray.colSpacing()),
353
- } : null });
384
+ } : null,
385
+ };
386
+ }
387
+ // Helper function to parse block metadata from FlatBuffers
388
+ function parseBlockMetadata(metadataFb) {
389
+ if (!metadataFb)
390
+ return undefined;
391
+ // localization is now binary JSON data (Uint8Array)
392
+ const localization = parseBinaryToJson(metadataFb.localizationArray());
393
+ const rawSource = metadataFb.source();
394
+ const source = typeof rawSource === "string" && rawSource.trim().length
395
+ ? rawSource.trim()
396
+ : undefined;
397
+ return Object.assign(Object.assign({}, (source ? { source } : {})), { usageCount: metadataFb.usageCount(), createdAt: Number(metadataFb.createdAt()), updatedAt: Number(metadataFb.updatedAt()), localization });
398
+ }
399
+ function parseBlockCollection(collection) {
400
+ const children = Array.from({ length: collection.childrenLength() }, (_, i) => {
401
+ const child = collection.children(i);
402
+ return {
403
+ id: child.id(),
404
+ isCollection: child.isCollection(),
405
+ };
406
+ });
407
+ const metadata = parseBlockMetadata(collection.metadata());
408
+ return {
409
+ id: collection.id(),
410
+ label: collection.label(),
411
+ children,
412
+ metadata,
413
+ thumbnail: collection.thumbnailArray() || undefined,
414
+ };
354
415
  }
355
416
  function parseFrameElement(element) {
356
417
  return Object.assign({ type: "frame" }, parseStackElementBase(element.stackElementBase()));
@@ -687,9 +748,6 @@ export function parseElementFromBinary(wrapper) {
687
748
  case ElementUnion.DucFreeDrawElement:
688
749
  element = wrapper.element(new DucFreeDrawElementFb());
689
750
  break;
690
- case ElementUnion.DucBlockInstanceElement:
691
- element = wrapper.element(new DucBlockInstanceElementFb());
692
- break;
693
751
  case ElementUnion.DucFrameElement:
694
752
  element = wrapper.element(new DucFrameElementFb());
695
753
  break;
@@ -749,8 +807,6 @@ export function parseElementFromBinary(wrapper) {
749
807
  return parseArrowElement(element);
750
808
  case ElementUnion.DucFreeDrawElement:
751
809
  return parseFreeDrawElement(element);
752
- case ElementUnion.DucBlockInstanceElement:
753
- return parseBlockInstanceElement(element);
754
810
  case ElementUnion.DucFrameElement:
755
811
  return parseFrameElement(element);
756
812
  case ElementUnion.DucPlotElement:
@@ -787,14 +843,18 @@ export function parseBlockFromBinary(block) {
787
843
  isConstant: def.isConstant(),
788
844
  };
789
845
  }
846
+ // Parse metadata if present
847
+ const metadata = parseBlockMetadata(block.metadata());
848
+ // Parse thumbnail if present
849
+ const thumbnail = block.thumbnailArray();
790
850
  return {
791
851
  id: block.id(),
792
852
  label: block.label(),
793
853
  description: block.description() || undefined,
794
854
  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
855
  attributeDefinitions,
856
+ metadata,
857
+ thumbnail: thumbnail || undefined,
798
858
  };
799
859
  }
800
860
  export function parseDictionaryFromBinary(data) {
@@ -1191,15 +1251,7 @@ export function parseVersionGraphFromBinary(graph) {
1191
1251
  description: base.description() || undefined,
1192
1252
  isManualSave: base.isManualSave(),
1193
1253
  userId: base.userId() || undefined,
1194
- patch: Array.from({ length: d.patchLength() }, (_, j) => {
1195
- const p = d.patch(j);
1196
- return {
1197
- op: p.op(),
1198
- path: p.path(),
1199
- from: p.from() || undefined,
1200
- value: p.value() ? JSON.parse(p.value()) : undefined,
1201
- };
1202
- }),
1254
+ patch: parseBinaryToJson(d.patchArray()),
1203
1255
  };
1204
1256
  }),
1205
1257
  metadata: {
@@ -1266,6 +1318,28 @@ export const parseDuc = (blob_1, ...args_1) => __awaiter(void 0, [blob_1, ...arg
1266
1318
  }
1267
1319
  }
1268
1320
  }
1321
+ // Parse block instances
1322
+ const blockInstances = [];
1323
+ for (let i = 0; i < data.blockInstancesLength(); i++) {
1324
+ const blockInstance = data.blockInstances(i);
1325
+ if (blockInstance) {
1326
+ const parsedBlockInstance = parseBlockInstance(blockInstance);
1327
+ if (parsedBlockInstance) {
1328
+ blockInstances.push(parsedBlockInstance);
1329
+ }
1330
+ }
1331
+ }
1332
+ // Parse block collections
1333
+ const blockCollections = [];
1334
+ for (let i = 0; i < data.blockCollectionsLength(); i++) {
1335
+ const blockCollection = data.blockCollections(i);
1336
+ if (blockCollection) {
1337
+ const parsedBlockCollection = parseBlockCollection(blockCollection);
1338
+ if (parsedBlockCollection) {
1339
+ blockCollections.push(parsedBlockCollection);
1340
+ }
1341
+ }
1342
+ }
1269
1343
  // Parse groups
1270
1344
  const groups = [];
1271
1345
  for (let i = 0; i < data.groupsLength(); i++) {
@@ -1317,21 +1391,24 @@ export const parseDuc = (blob_1, ...args_1) => __awaiter(void 0, [blob_1, ...arg
1317
1391
  }
1318
1392
  }
1319
1393
  }
1320
- const sanitized = restore({
1394
+ const exportData = {
1321
1395
  thumbnail,
1322
1396
  dictionary,
1323
1397
  elements: elements,
1324
1398
  localState: parsedLocalState,
1325
1399
  globalState: parsedGlobalState,
1326
1400
  blocks,
1401
+ blockInstances,
1402
+ blockCollections,
1327
1403
  groups,
1328
1404
  regions,
1329
1405
  layers,
1330
1406
  standards,
1331
1407
  files: parsedFiles,
1332
1408
  versionGraph: versionGraph !== null && versionGraph !== void 0 ? versionGraph : undefined,
1333
- id: (_a = data.id()) !== null && _a !== void 0 ? _a : undefined,
1334
- }, {
1409
+ id: (_a = data.id()) !== null && _a !== void 0 ? _a : nanoid(),
1410
+ };
1411
+ const sanitized = restore(exportData, {
1335
1412
  syncInvalidIndices: (elements) => elements,
1336
1413
  repairBindings: true,
1337
1414
  refreshDimensions: false,
@@ -1344,9 +1421,11 @@ export const parseDuc = (blob_1, ...args_1) => __awaiter(void 0, [blob_1, ...arg
1344
1421
  globalState: sanitized.globalState,
1345
1422
  files: sanitized.files,
1346
1423
  blocks: sanitized.blocks,
1424
+ blockInstances: sanitized.blockInstances,
1347
1425
  groups: sanitized.groups,
1348
1426
  regions: sanitized.regions,
1349
1427
  layers: sanitized.layers,
1428
+ blockCollections: sanitized.blockCollections,
1350
1429
  standards: sanitized.standards,
1351
1430
  versionGraph: sanitized.versionGraph,
1352
1431
  id: sanitized.id,