ducjs 2.2.2 → 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.
- package/dist/flatbuffers/duc/delta.d.ts +6 -4
- package/dist/flatbuffers/duc/delta.js +22 -11
- package/dist/flatbuffers/duc/duc-block-metadata.d.ts +5 -2
- package/dist/flatbuffers/duc/duc-block-metadata.js +23 -5
- package/dist/flatbuffers/duc/duc-element-base.d.ts +6 -3
- package/dist/flatbuffers/duc/duc-element-base.js +26 -8
- package/dist/parse.js +35 -31
- package/dist/restore/restoreDataState.js +5 -7
- package/dist/serialize.js +12 -21
- package/dist/types/elements/index.d.ts +6 -4
- package/dist/types/index.d.ts +2 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +5 -0
- package/package.json +6 -5
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as flatbuffers from 'flatbuffers';
|
|
2
|
-
import { JSONPatchOperation } from '../duc/jsonpatch-operation';
|
|
3
2
|
import { VersionBase } from '../duc/version-base';
|
|
4
3
|
export declare class Delta {
|
|
5
4
|
bb: flatbuffers.ByteBuffer | null;
|
|
@@ -8,13 +7,16 @@ export declare class Delta {
|
|
|
8
7
|
static getRootAsDelta(bb: flatbuffers.ByteBuffer, obj?: Delta): Delta;
|
|
9
8
|
static getSizePrefixedRootAsDelta(bb: flatbuffers.ByteBuffer, obj?: Delta): Delta;
|
|
10
9
|
base(obj?: VersionBase): VersionBase | null;
|
|
11
|
-
|
|
10
|
+
sizeBytes(): bigint;
|
|
11
|
+
patch(index: number): number | null;
|
|
12
12
|
patchLength(): number;
|
|
13
|
+
patchArray(): Uint8Array | null;
|
|
13
14
|
static startDelta(builder: flatbuffers.Builder): void;
|
|
14
15
|
static addBase(builder: flatbuffers.Builder, baseOffset: flatbuffers.Offset): void;
|
|
16
|
+
static addSizeBytes(builder: flatbuffers.Builder, sizeBytes: bigint): void;
|
|
15
17
|
static addPatch(builder: flatbuffers.Builder, patchOffset: flatbuffers.Offset): void;
|
|
16
|
-
static createPatchVector(builder: flatbuffers.Builder, data:
|
|
18
|
+
static createPatchVector(builder: flatbuffers.Builder, data: number[] | Uint8Array): flatbuffers.Offset;
|
|
17
19
|
static startPatchVector(builder: flatbuffers.Builder, numElems: number): void;
|
|
18
20
|
static endDelta(builder: flatbuffers.Builder): flatbuffers.Offset;
|
|
19
|
-
static createDelta(builder: flatbuffers.Builder, baseOffset: flatbuffers.Offset, patchOffset: flatbuffers.Offset): flatbuffers.Offset;
|
|
21
|
+
static createDelta(builder: flatbuffers.Builder, baseOffset: flatbuffers.Offset, sizeBytes: bigint, patchOffset: flatbuffers.Offset): flatbuffers.Offset;
|
|
20
22
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// automatically generated by the FlatBuffers compiler, do not modify
|
|
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
|
-
import { JSONPatchOperation } from '../duc/jsonpatch-operation';
|
|
5
4
|
import { VersionBase } from '../duc/version-base';
|
|
6
5
|
export class Delta {
|
|
7
6
|
constructor() {
|
|
@@ -24,40 +23,52 @@ export class Delta {
|
|
|
24
23
|
const offset = this.bb.__offset(this.bb_pos, 4);
|
|
25
24
|
return offset ? (obj || new VersionBase()).__init(this.bb.__indirect(this.bb_pos + offset), this.bb) : null;
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
const offset = this.bb.__offset(this.bb_pos,
|
|
29
|
-
return offset ?
|
|
26
|
+
sizeBytes() {
|
|
27
|
+
const offset = this.bb.__offset(this.bb_pos, 8);
|
|
28
|
+
return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0');
|
|
29
|
+
}
|
|
30
|
+
patch(index) {
|
|
31
|
+
const offset = this.bb.__offset(this.bb_pos, 10);
|
|
32
|
+
return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0;
|
|
30
33
|
}
|
|
31
34
|
patchLength() {
|
|
32
|
-
const offset = this.bb.__offset(this.bb_pos,
|
|
35
|
+
const offset = this.bb.__offset(this.bb_pos, 10);
|
|
33
36
|
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
|
34
37
|
}
|
|
38
|
+
patchArray() {
|
|
39
|
+
const offset = this.bb.__offset(this.bb_pos, 10);
|
|
40
|
+
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;
|
|
41
|
+
}
|
|
35
42
|
static startDelta(builder) {
|
|
36
|
-
builder.startObject(
|
|
43
|
+
builder.startObject(4);
|
|
37
44
|
}
|
|
38
45
|
static addBase(builder, baseOffset) {
|
|
39
46
|
builder.addFieldOffset(0, baseOffset, 0);
|
|
40
47
|
}
|
|
48
|
+
static addSizeBytes(builder, sizeBytes) {
|
|
49
|
+
builder.addFieldInt64(2, sizeBytes, BigInt('0'));
|
|
50
|
+
}
|
|
41
51
|
static addPatch(builder, patchOffset) {
|
|
42
|
-
builder.addFieldOffset(
|
|
52
|
+
builder.addFieldOffset(3, patchOffset, 0);
|
|
43
53
|
}
|
|
44
54
|
static createPatchVector(builder, data) {
|
|
45
|
-
builder.startVector(
|
|
55
|
+
builder.startVector(1, data.length, 1);
|
|
46
56
|
for (let i = data.length - 1; i >= 0; i--) {
|
|
47
|
-
builder.
|
|
57
|
+
builder.addInt8(data[i]);
|
|
48
58
|
}
|
|
49
59
|
return builder.endVector();
|
|
50
60
|
}
|
|
51
61
|
static startPatchVector(builder, numElems) {
|
|
52
|
-
builder.startVector(
|
|
62
|
+
builder.startVector(1, numElems, 1);
|
|
53
63
|
}
|
|
54
64
|
static endDelta(builder) {
|
|
55
65
|
const offset = builder.endObject();
|
|
56
66
|
return offset;
|
|
57
67
|
}
|
|
58
|
-
static createDelta(builder, baseOffset, patchOffset) {
|
|
68
|
+
static createDelta(builder, baseOffset, sizeBytes, patchOffset) {
|
|
59
69
|
Delta.startDelta(builder);
|
|
60
70
|
Delta.addBase(builder, baseOffset);
|
|
71
|
+
Delta.addSizeBytes(builder, sizeBytes);
|
|
61
72
|
Delta.addPatch(builder, patchOffset);
|
|
62
73
|
return Delta.endDelta(builder);
|
|
63
74
|
}
|
|
@@ -10,14 +10,17 @@ export declare class DucBlockMetadata {
|
|
|
10
10
|
usageCount(): number;
|
|
11
11
|
createdAt(): bigint;
|
|
12
12
|
updatedAt(): bigint;
|
|
13
|
-
localization():
|
|
14
|
-
|
|
13
|
+
localization(index: number): number | null;
|
|
14
|
+
localizationLength(): number;
|
|
15
|
+
localizationArray(): Uint8Array | null;
|
|
15
16
|
static startDucBlockMetadata(builder: flatbuffers.Builder): void;
|
|
16
17
|
static addSource(builder: flatbuffers.Builder, sourceOffset: flatbuffers.Offset): void;
|
|
17
18
|
static addUsageCount(builder: flatbuffers.Builder, usageCount: number): void;
|
|
18
19
|
static addCreatedAt(builder: flatbuffers.Builder, createdAt: bigint): void;
|
|
19
20
|
static addUpdatedAt(builder: flatbuffers.Builder, updatedAt: bigint): void;
|
|
20
21
|
static addLocalization(builder: flatbuffers.Builder, localizationOffset: flatbuffers.Offset): void;
|
|
22
|
+
static createLocalizationVector(builder: flatbuffers.Builder, data: number[] | Uint8Array): flatbuffers.Offset;
|
|
23
|
+
static startLocalizationVector(builder: flatbuffers.Builder, numElems: number): void;
|
|
21
24
|
static endDucBlockMetadata(builder: flatbuffers.Builder): flatbuffers.Offset;
|
|
22
25
|
static createDucBlockMetadata(builder: flatbuffers.Builder, sourceOffset: flatbuffers.Offset, usageCount: number, createdAt: bigint, updatedAt: bigint, localizationOffset: flatbuffers.Offset): flatbuffers.Offset;
|
|
23
26
|
}
|
|
@@ -34,12 +34,20 @@ export class DucBlockMetadata {
|
|
|
34
34
|
const offset = this.bb.__offset(this.bb_pos, 10);
|
|
35
35
|
return offset ? this.bb.readInt64(this.bb_pos + offset) : BigInt('0');
|
|
36
36
|
}
|
|
37
|
-
localization(
|
|
38
|
-
const offset = this.bb.__offset(this.bb_pos,
|
|
39
|
-
return offset ? this.bb.
|
|
37
|
+
localization(index) {
|
|
38
|
+
const offset = this.bb.__offset(this.bb_pos, 14);
|
|
39
|
+
return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0;
|
|
40
|
+
}
|
|
41
|
+
localizationLength() {
|
|
42
|
+
const offset = this.bb.__offset(this.bb_pos, 14);
|
|
43
|
+
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
|
44
|
+
}
|
|
45
|
+
localizationArray() {
|
|
46
|
+
const offset = this.bb.__offset(this.bb_pos, 14);
|
|
47
|
+
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;
|
|
40
48
|
}
|
|
41
49
|
static startDucBlockMetadata(builder) {
|
|
42
|
-
builder.startObject(
|
|
50
|
+
builder.startObject(6);
|
|
43
51
|
}
|
|
44
52
|
static addSource(builder, sourceOffset) {
|
|
45
53
|
builder.addFieldOffset(0, sourceOffset, 0);
|
|
@@ -54,7 +62,17 @@ export class DucBlockMetadata {
|
|
|
54
62
|
builder.addFieldInt64(3, updatedAt, BigInt('0'));
|
|
55
63
|
}
|
|
56
64
|
static addLocalization(builder, localizationOffset) {
|
|
57
|
-
builder.addFieldOffset(
|
|
65
|
+
builder.addFieldOffset(5, localizationOffset, 0);
|
|
66
|
+
}
|
|
67
|
+
static createLocalizationVector(builder, data) {
|
|
68
|
+
builder.startVector(1, data.length, 1);
|
|
69
|
+
for (let i = data.length - 1; i >= 0; i--) {
|
|
70
|
+
builder.addInt8(data[i]);
|
|
71
|
+
}
|
|
72
|
+
return builder.endVector();
|
|
73
|
+
}
|
|
74
|
+
static startLocalizationVector(builder, numElems) {
|
|
75
|
+
builder.startVector(1, numElems, 1);
|
|
58
76
|
}
|
|
59
77
|
static endDucBlockMetadata(builder) {
|
|
60
78
|
const offset = builder.endObject();
|
|
@@ -47,13 +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;
|
|
52
50
|
blockIds(index: number): string;
|
|
53
51
|
blockIds(index: number, optionalEncoding: flatbuffers.Encoding): string | Uint8Array;
|
|
54
52
|
blockIdsLength(): number;
|
|
55
53
|
instanceId(): string | null;
|
|
56
54
|
instanceId(optionalEncoding: flatbuffers.Encoding): string | Uint8Array | null;
|
|
55
|
+
customData(index: number): number | null;
|
|
56
|
+
customDataLength(): number;
|
|
57
|
+
customDataArray(): Uint8Array | null;
|
|
57
58
|
static start_DucElementBase(builder: flatbuffers.Builder): void;
|
|
58
59
|
static addId(builder: flatbuffers.Builder, idOffset: flatbuffers.Offset): void;
|
|
59
60
|
static addStyles(builder: flatbuffers.Builder, stylesOffset: flatbuffers.Offset): void;
|
|
@@ -88,10 +89,12 @@ export declare class _DucElementBase {
|
|
|
88
89
|
static addZIndex(builder: flatbuffers.Builder, zIndex: number): void;
|
|
89
90
|
static addLink(builder: flatbuffers.Builder, linkOffset: flatbuffers.Offset): void;
|
|
90
91
|
static addLocked(builder: flatbuffers.Builder, locked: boolean): void;
|
|
91
|
-
static addCustomData(builder: flatbuffers.Builder, customDataOffset: flatbuffers.Offset): void;
|
|
92
92
|
static addBlockIds(builder: flatbuffers.Builder, blockIdsOffset: flatbuffers.Offset): void;
|
|
93
93
|
static createBlockIdsVector(builder: flatbuffers.Builder, data: flatbuffers.Offset[]): flatbuffers.Offset;
|
|
94
94
|
static startBlockIdsVector(builder: flatbuffers.Builder, numElems: number): void;
|
|
95
95
|
static addInstanceId(builder: flatbuffers.Builder, instanceIdOffset: flatbuffers.Offset): void;
|
|
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;
|
|
96
99
|
static end_DucElementBase(builder: flatbuffers.Builder): flatbuffers.Offset;
|
|
97
100
|
}
|
|
@@ -140,10 +140,6 @@ 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);
|
|
145
|
-
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
|
146
|
-
}
|
|
147
143
|
blockIds(index, optionalEncoding) {
|
|
148
144
|
const offset = this.bb.__offset(this.bb_pos, 60);
|
|
149
145
|
return offset ? this.bb.__string(this.bb.__vector(this.bb_pos + offset) + index * 4, optionalEncoding) : null;
|
|
@@ -156,8 +152,20 @@ export class _DucElementBase {
|
|
|
156
152
|
const offset = this.bb.__offset(this.bb_pos, 62);
|
|
157
153
|
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
|
158
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
|
+
}
|
|
159
167
|
static start_DucElementBase(builder) {
|
|
160
|
-
builder.startObject(
|
|
168
|
+
builder.startObject(31);
|
|
161
169
|
}
|
|
162
170
|
static addId(builder, idOffset) {
|
|
163
171
|
builder.addFieldOffset(0, idOffset, 0);
|
|
@@ -270,9 +278,6 @@ export class _DucElementBase {
|
|
|
270
278
|
static addLocked(builder, locked) {
|
|
271
279
|
builder.addFieldInt8(26, +locked, +false);
|
|
272
280
|
}
|
|
273
|
-
static addCustomData(builder, customDataOffset) {
|
|
274
|
-
builder.addFieldOffset(27, customDataOffset, 0);
|
|
275
|
-
}
|
|
276
281
|
static addBlockIds(builder, blockIdsOffset) {
|
|
277
282
|
builder.addFieldOffset(28, blockIdsOffset, 0);
|
|
278
283
|
}
|
|
@@ -289,6 +294,19 @@ export class _DucElementBase {
|
|
|
289
294
|
static addInstanceId(builder, instanceIdOffset) {
|
|
290
295
|
builder.addFieldOffset(29, instanceIdOffset, 0);
|
|
291
296
|
}
|
|
297
|
+
static addCustomData(builder, customDataOffset) {
|
|
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);
|
|
309
|
+
}
|
|
292
310
|
static end_DucElementBase(builder) {
|
|
293
311
|
const offset = builder.endObject();
|
|
294
312
|
builder.requiredField(offset, 4); // id
|
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 {
|
|
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 { 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";
|
|
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 {
|
|
@@ -168,7 +192,7 @@ export function parseElementBase(base) {
|
|
|
168
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) => ({
|
|
169
193
|
id: base.boundElements(i).id(),
|
|
170
194
|
type: base.boundElements(i).type(),
|
|
171
|
-
})) : null, zIndex: base.zIndex(), link: base.link(), locked: base.locked(), customData:
|
|
195
|
+
})) : null, zIndex: base.zIndex(), link: base.link(), locked: base.locked(), customData: parseBinaryToJson(base.customDataArray()) }, parsedStyles);
|
|
172
196
|
}
|
|
173
197
|
export function parseLineReference(ref) {
|
|
174
198
|
return {
|
|
@@ -364,25 +388,13 @@ function parseBlockInstance(instance) {
|
|
|
364
388
|
function parseBlockMetadata(metadataFb) {
|
|
365
389
|
if (!metadataFb)
|
|
366
390
|
return undefined;
|
|
367
|
-
// localization is
|
|
368
|
-
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
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
|
-
};
|
|
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 });
|
|
386
398
|
}
|
|
387
399
|
function parseBlockCollection(collection) {
|
|
388
400
|
const children = Array.from({ length: collection.childrenLength() }, (_, i) => {
|
|
@@ -1239,15 +1251,7 @@ export function parseVersionGraphFromBinary(graph) {
|
|
|
1239
1251
|
description: base.description() || undefined,
|
|
1240
1252
|
isManualSave: base.isManualSave(),
|
|
1241
1253
|
userId: base.userId() || undefined,
|
|
1242
|
-
patch:
|
|
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
|
-
}),
|
|
1254
|
+
patch: parseBinaryToJson(d.patchArray()),
|
|
1251
1255
|
};
|
|
1252
1256
|
}),
|
|
1253
1257
|
metadata: {
|
|
@@ -331,13 +331,11 @@ const restoreBlockMetadata = (metadata) => {
|
|
|
331
331
|
localization = undefined;
|
|
332
332
|
}
|
|
333
333
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
localization,
|
|
340
|
-
};
|
|
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 });
|
|
341
339
|
};
|
|
342
340
|
/**
|
|
343
341
|
* Restores instances from block instances data (alias for restoreBlockInstances)
|
package/dist/serialize.js
CHANGED
|
@@ -18,6 +18,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
18
18
|
*/
|
|
19
19
|
import * as flatbuffers from "flatbuffers";
|
|
20
20
|
import * as Duc from "./flatbuffers/duc";
|
|
21
|
+
import { zlibSync, strToU8 } from "fflate";
|
|
21
22
|
import { restore } from "./restore";
|
|
22
23
|
import { encodeFunctionString, EXPORT_DATA_TYPES } from "./utils";
|
|
23
24
|
/**
|
|
@@ -377,7 +378,7 @@ function writeElementBase(b, e, usv) {
|
|
|
377
378
|
const frameId = str(b, (_j = e.frameId) !== null && _j !== void 0 ? _j : undefined);
|
|
378
379
|
const bound = ((_k = e.boundElements) === null || _k === void 0 ? void 0 : _k.length) ? Duc._DucElementBase.createBoundElementsVector(b, e.boundElements.map((x) => writeBoundElement(b, x, usv))) : undefined;
|
|
379
380
|
const link = str(b, (_l = e.link) !== null && _l !== void 0 ? _l : undefined);
|
|
380
|
-
const custom = e.customData != null ?
|
|
381
|
+
const custom = e.customData != null ? Duc._DucElementBase.createCustomDataVector(b, zlibSync(strToU8(JSON.stringify(e.customData)))) : undefined;
|
|
381
382
|
Duc._DucElementBase.start_DucElementBase(b);
|
|
382
383
|
if (id)
|
|
383
384
|
Duc._DucElementBase.addId(b, id);
|
|
@@ -776,7 +777,7 @@ function writeBlockAttrDef(b, d, usv) {
|
|
|
776
777
|
}
|
|
777
778
|
function writeBlockMetadata(b, metadata) {
|
|
778
779
|
const source = b.createString(metadata.source);
|
|
779
|
-
const localization = metadata.localization ?
|
|
780
|
+
const localization = metadata.localization ? Duc.DucBlockMetadata.createLocalizationVector(b, zlibSync(strToU8(JSON.stringify(metadata.localization)))) : undefined;
|
|
780
781
|
Duc.DucBlockMetadata.startDucBlockMetadata(b);
|
|
781
782
|
Duc.DucBlockMetadata.addSource(b, source);
|
|
782
783
|
Duc.DucBlockMetadata.addUsageCount(b, metadata.usageCount);
|
|
@@ -870,9 +871,9 @@ function writeBlockCollection(b, c) {
|
|
|
870
871
|
const metadata = c.metadata;
|
|
871
872
|
let localizationOffset;
|
|
872
873
|
if (metadata.localization) {
|
|
873
|
-
// localization is stored as
|
|
874
|
-
const
|
|
875
|
-
localizationOffset =
|
|
874
|
+
// localization is stored as compressed binary JSON data
|
|
875
|
+
const localizationBin = zlibSync(strToU8(JSON.stringify(metadata.localization)));
|
|
876
|
+
localizationOffset = Duc.DucBlockMetadata.createLocalizationVector(b, localizationBin);
|
|
876
877
|
}
|
|
877
878
|
const source = b.createString(metadata.source);
|
|
878
879
|
Duc.DucBlockMetadata.startDucBlockMetadata(b);
|
|
@@ -2228,28 +2229,18 @@ function serializeCheckpoint(b, c) {
|
|
|
2228
2229
|
return Duc.Checkpoint.endCheckpoint(b);
|
|
2229
2230
|
}
|
|
2230
2231
|
function writeJsonPatch(b, p) {
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
const valueStr = op.value !== undefined ? b.createString(JSON.stringify(op.value)) : undefined;
|
|
2236
|
-
Duc.JSONPatchOperation.startJSONPatchOperation(b);
|
|
2237
|
-
Duc.JSONPatchOperation.addOp(b, opStr);
|
|
2238
|
-
Duc.JSONPatchOperation.addPath(b, pathStr);
|
|
2239
|
-
if (fromStr)
|
|
2240
|
-
Duc.JSONPatchOperation.addFrom(b, fromStr);
|
|
2241
|
-
if (valueStr)
|
|
2242
|
-
Duc.JSONPatchOperation.addValue(b, valueStr);
|
|
2243
|
-
return Duc.JSONPatchOperation.endJSONPatchOperation(b);
|
|
2244
|
-
});
|
|
2245
|
-
return Duc.Delta.createPatchVector(b, ops);
|
|
2232
|
+
// Compress the JSON patch data
|
|
2233
|
+
const patchData = zlibSync(strToU8(JSON.stringify(p)));
|
|
2234
|
+
const offset = Duc.Delta.createPatchVector(b, patchData);
|
|
2235
|
+
return { offset, sizeBytes: patchData.length };
|
|
2246
2236
|
}
|
|
2247
2237
|
function serializeDelta(b, d) {
|
|
2248
2238
|
const base = serializeVersionBase(b, d);
|
|
2249
|
-
const patch = writeJsonPatch(b, d.patch);
|
|
2239
|
+
const { offset: patch, sizeBytes } = writeJsonPatch(b, d.patch);
|
|
2250
2240
|
Duc.Delta.startDelta(b);
|
|
2251
2241
|
Duc.Delta.addBase(b, base);
|
|
2252
2242
|
Duc.Delta.addPatch(b, patch);
|
|
2243
|
+
Duc.Delta.addSizeBytes(b, BigInt(sizeBytes));
|
|
2253
2244
|
return Duc.Delta.endDelta(b);
|
|
2254
2245
|
}
|
|
2255
2246
|
function serializeDucVersionGraph(b, vg) {
|
|
@@ -746,8 +746,10 @@ export type DucBlockAttributeDefinition = {
|
|
|
746
746
|
/** If true, the attribute's value is fixed and cannot be changed after insertion. */
|
|
747
747
|
isConstant: boolean;
|
|
748
748
|
};
|
|
749
|
-
/**
|
|
750
|
-
|
|
749
|
+
/**
|
|
750
|
+
* Indicates the source drawing of a block.
|
|
751
|
+
*/
|
|
752
|
+
export type BlockSource = string;
|
|
751
753
|
export interface BlockLocalizationEntry {
|
|
752
754
|
title: string;
|
|
753
755
|
description?: string;
|
|
@@ -758,8 +760,8 @@ export interface BlockLocalizationEntry {
|
|
|
758
760
|
*/
|
|
759
761
|
export type BlockLocalizationMap = Record<string, BlockLocalizationEntry>;
|
|
760
762
|
export interface DucBlockMetadata {
|
|
761
|
-
/**
|
|
762
|
-
source
|
|
763
|
+
/** Drawing id this block originates from */
|
|
764
|
+
source?: BlockSource;
|
|
763
765
|
/** Total number of times the block was instantiated */
|
|
764
766
|
usageCount: number;
|
|
765
767
|
/** Creation timestamp */
|
package/dist/types/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { SupportedMeasures } from "../technical/scopes";
|
|
|
7
7
|
import { Standard } from "../technical/standards";
|
|
8
8
|
import { DucBindableElement, DucBlock, DucBlockCollection, DucBlockInstance, DucElement, DucElementType, DucGroup, DucIframeLikeElement, DucLayer, DucLinearElement, DucPoint, DucRegion, DucTextElement, ElementBackground, ElementStroke, ExternalFileId, FontFamilyValues, LineHead, NonDeleted, TextAlign } from "./elements";
|
|
9
9
|
import { GeometricPoint, Percentage, Radian, ScaleFactor } from "./geometryTypes";
|
|
10
|
-
import { MakeBrand, MaybePromise, ValueOf } from "./utility-types";
|
|
10
|
+
import { MakeBrand, MarkOptional, MaybePromise, ValueOf } from "./utility-types";
|
|
11
11
|
import type { GRID_DISPLAY_TYPE, GRID_TYPE, SNAP_MARKER_SHAPE, SNAP_MODE, SNAP_OVERRIDE_BEHAVIOR } from "../utils/constants";
|
|
12
12
|
/**
|
|
13
13
|
* Root data structure for the stored data state
|
|
@@ -37,6 +37,7 @@ export interface ExportedDataState {
|
|
|
37
37
|
id: string | undefined;
|
|
38
38
|
}
|
|
39
39
|
export type ExportedDataStateContent = Omit<ExportedDataState, "type" | "version" | "source">;
|
|
40
|
+
export type BaseExportedDataState = MarkOptional<ExportedDataStateContent, "elements" | "localState" | "versionGraph">;
|
|
40
41
|
/**
|
|
41
42
|
* A version of the data state where all fields are optional.
|
|
42
43
|
* This is useful for importing data where some fields might be missing.
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare const isFiniteNumber: (value: any) => value is number;
|
|
|
24
24
|
export declare const arrayToMap: <T extends {
|
|
25
25
|
id: string;
|
|
26
26
|
} | string>(items: readonly T[] | Map<string, T>) => Map<any, any>;
|
|
27
|
+
export declare function omitKeys<T extends Record<string, unknown>, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>;
|
|
27
28
|
/**
|
|
28
29
|
* Checks whether first directional character is RTL. Meaning whether it starts
|
|
29
30
|
* with RTL characters, or indeterminate (numbers etc.) characters followed by
|
package/dist/utils/index.js
CHANGED
|
@@ -41,6 +41,11 @@ export const arrayToMap = (items) => {
|
|
|
41
41
|
return acc;
|
|
42
42
|
}, new Map());
|
|
43
43
|
};
|
|
44
|
+
export function omitKeys(obj, keys) {
|
|
45
|
+
const result = Object.assign({}, obj);
|
|
46
|
+
keys.forEach(key => delete result[key]);
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
44
49
|
const RS_LTR_CHARS = "A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF" +
|
|
45
50
|
"\u2C00-\uFB1C\uFDFE-\uFE6F\uFEFD-\uFFFF";
|
|
46
51
|
const RS_RTL_CHARS = "\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ducjs",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.3",
|
|
4
4
|
"description": "The duc 2D CAD file format is a cornerstone of our advanced design system, conceived to cater to professionals seeking precision and efficiency in their design work.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -43,12 +43,13 @@
|
|
|
43
43
|
"undici-types": "^6.21.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"flatbuffers": "^24.12.23",
|
|
47
|
-
"nanoid": "5.1.5",
|
|
48
|
-
"tinycolor2": "1.6.0",
|
|
49
46
|
"@braintree/sanitize-url": "6.0.2",
|
|
50
47
|
"browser-fs-access": "0.35.0",
|
|
51
|
-
"
|
|
48
|
+
"fflate": "^0.8.2",
|
|
49
|
+
"flatbuffers": "^24.12.23",
|
|
50
|
+
"nanoid": "5.1.5",
|
|
51
|
+
"perfect-freehand": "1.2.2",
|
|
52
|
+
"tinycolor2": "1.6.0"
|
|
52
53
|
},
|
|
53
54
|
"files": [
|
|
54
55
|
"dist",
|