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.
- package/dist/flatbuffers/duc/delta.d.ts +6 -4
- package/dist/flatbuffers/duc/delta.js +22 -11
- package/dist/flatbuffers/duc/duc-block-collection-entry.d.ts +16 -0
- package/dist/flatbuffers/duc/duc-block-collection-entry.js +48 -0
- package/dist/flatbuffers/duc/duc-block-collection.d.ts +31 -0
- package/dist/flatbuffers/duc/duc-block-collection.js +97 -0
- package/dist/flatbuffers/duc/duc-block-instance-element.d.ts +0 -20
- package/dist/flatbuffers/duc/duc-block-instance-element.js +0 -66
- package/dist/flatbuffers/duc/duc-block-instance.d.ts +32 -0
- package/dist/flatbuffers/duc/duc-block-instance.js +100 -0
- package/dist/flatbuffers/duc/duc-block-metadata.d.ts +26 -0
- package/dist/flatbuffers/duc/duc-block-metadata.js +90 -0
- package/dist/flatbuffers/duc/duc-block.d.ts +9 -7
- package/dist/flatbuffers/duc/duc-block.js +31 -30
- package/dist/flatbuffers/duc/duc-element-base.d.ts +14 -2
- package/dist/flatbuffers/duc/duc-element-base.js +50 -4
- package/dist/flatbuffers/duc/exported-data-state.d.ts +12 -0
- package/dist/flatbuffers/duc/exported-data-state.js +45 -1
- package/dist/flatbuffers/duc.d.ts +4 -0
- package/dist/flatbuffers/duc.js +4 -0
- package/dist/parse.js +110 -31
- package/dist/restore/restoreDataState.d.ts +23 -1
- package/dist/restore/restoreDataState.js +167 -13
- package/dist/serialize.js +132 -47
- package/dist/types/elements/index.d.ts +91 -20
- package/dist/types/elements/typeChecks.d.ts +1 -2
- package/dist/types/elements/typeChecks.js +0 -4
- package/dist/types/index.d.ts +5 -2
- package/dist/utils/bounds.js +1 -1
- package/dist/utils/constants.d.ts +12 -2
- package/dist/utils/constants.js +19 -3
- package/dist/utils/elements/index.js +1 -0
- package/dist/utils/elements/newElement.d.ts +1 -7
- package/dist/utils/elements/newElement.js +3 -5
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +5 -0
- package/package.json +6 -5
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export * from "./typeChecks";
|
|
2
|
+
import { DucView, PrecisionValue, Scope } from "..";
|
|
2
3
|
import { BEZIER_MIRRORING, BLENDING, BLOCK_ATTACHMENT, BOOLEAN_OPERATION, COLUMN_TYPE, DATUM_BRACKET_STYLE, DATUM_TARGET_TYPE, DIMENSION_FIT_RULE, DIMENSION_TEXT_PLACEMENT, DIMENSION_TYPE, ELEMENT_CONTENT_PREFERENCE, FEATURE_MODIFIER, GDT_SYMBOL, HATCH_STYLE, IMAGE_STATUS, LINE_HEAD, LINE_SPACING_TYPE, MARK_ELLIPSE_CENTER, MATERIAL_CONDITION, PARAMETRIC_SOURCE_TYPE, STACKED_TEXT_ALIGN, STROKE_CAP, STROKE_JOIN, STROKE_PLACEMENT, STROKE_PREFERENCE, STROKE_SIDE_PREFERENCE, TABLE_CELL_ALIGNMENT, TABLE_FLOW_DIRECTION, TEXT_ALIGN, TEXT_FIELD_SOURCE_PROPERTY, TEXT_FIELD_SOURCE_TYPE, TEXT_FLOW_DIRECTION, TOLERANCE_DISPLAY, TOLERANCE_TYPE, TOLERANCE_ZONE_TYPE, VERTICAL_ALIGN, VIEWPORT_SHADE_PLOT } from "../../flatbuffers/duc";
|
|
3
4
|
import { Standard, StandardUnits } from "../../technical/standards";
|
|
4
|
-
import {
|
|
5
|
+
import { FONT_FAMILY, FREEDRAW_EASINGS } from "../../utils/constants";
|
|
5
6
|
import { Axis, GeometricPoint, Percentage, Radian, ScaleFactor } from "../geometryTypes";
|
|
6
7
|
import { MakeBrand, MarkNonNullable, MarkOptional, Merge, ValueOf } from "../utility-types";
|
|
7
|
-
import { FONT_FAMILY, FREEDRAW_EASINGS } from "../../utils/constants";
|
|
8
8
|
/**
|
|
9
9
|
* Base styles that all elements share
|
|
10
10
|
*/
|
|
@@ -56,17 +56,27 @@ export type _DucElementBase = Readonly<_DucElementStylesBase & {
|
|
|
56
56
|
isAnnotative: boolean;
|
|
57
57
|
/** Whether the element is deleted */
|
|
58
58
|
isDeleted: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* List of regions the element belongs.
|
|
61
|
+
* Used to define boolean operations between elements.
|
|
62
|
+
* Ordered from deepest to shallowest.
|
|
63
|
+
*/
|
|
64
|
+
regionIds: readonly RegionId[];
|
|
59
65
|
/**
|
|
60
66
|
* List of groups the element belongs to.
|
|
61
67
|
* Ordered from deepest to shallowest.
|
|
62
68
|
*/
|
|
63
69
|
groupIds: readonly GroupId[];
|
|
64
70
|
/**
|
|
65
|
-
* List of
|
|
66
|
-
*
|
|
67
|
-
* Ordered from deepest to shallowest.
|
|
71
|
+
* List of blocks this element helps *define*.
|
|
72
|
+
* If this is populated, `instanceId` should be null.
|
|
68
73
|
*/
|
|
69
|
-
|
|
74
|
+
blockIds: readonly BlockId[];
|
|
75
|
+
/**
|
|
76
|
+
* The ID of the `DucBlockInstance` this element belongs to.
|
|
77
|
+
* If not null, `blockIds` is empty (the relationship to the Block is via the Instance).
|
|
78
|
+
*/
|
|
79
|
+
instanceId: InstanceId | null;
|
|
70
80
|
/** The layer the element belongs to */
|
|
71
81
|
layerId: string | null;
|
|
72
82
|
/** The frame the element belongs to */
|
|
@@ -96,6 +106,8 @@ export type FillStyle = ValueOf<typeof ELEMENT_CONTENT_PREFERENCE>;
|
|
|
96
106
|
export type StrokePlacement = ValueOf<typeof STROKE_PLACEMENT>;
|
|
97
107
|
export type Blending = ValueOf<typeof BLENDING>;
|
|
98
108
|
export type GroupId = string;
|
|
109
|
+
export type BlockId = string;
|
|
110
|
+
export type InstanceId = string;
|
|
99
111
|
export type LayerId = string;
|
|
100
112
|
export type RegionId = string;
|
|
101
113
|
export type PointerType = "mouse" | "pen" | "touch";
|
|
@@ -122,7 +134,7 @@ export type DucGenericElement = DucSelectionElement | DucRectangleElement;
|
|
|
122
134
|
* no computed data. The list of all DucElements should be shareable
|
|
123
135
|
* between peers and contain no state local to the peer.
|
|
124
136
|
*/
|
|
125
|
-
export type DucElement = DucGenericElement | DucTextElement | DucLinearElement | DucFreeDrawElement | DucArrowElement | DucImageElement | DucFrameElement | DucEmbeddableElement | DucTableElement | DucDocElement | DucEllipseElement |
|
|
137
|
+
export type DucElement = DucGenericElement | DucTextElement | DucLinearElement | DucFreeDrawElement | DucArrowElement | DucImageElement | DucFrameElement | DucEmbeddableElement | DucTableElement | DucDocElement | DucEllipseElement | DucPolygonElement | DucParametricElement | DucFeatureControlFrameElement | DucLeaderElement | DucDimensionElement | DucViewportElement | DucPlotElement | DucXRayElement | DucPdfElement | DucMermaidElement;
|
|
126
138
|
export type DucElementTypes = DucElement["type"];
|
|
127
139
|
export type NonDeleted<TElement extends DucElement> = TElement & {
|
|
128
140
|
isDeleted: boolean;
|
|
@@ -134,12 +146,12 @@ export type DucBinderElement = DucLinearElement | DucDimensionElement | DucFeatu
|
|
|
134
146
|
export type DucBindableElement = DucRectangleElement | DucPolygonElement | DucEllipseElement | DucTextElement | DucImageElement | DucEmbeddableElement | DucFrameElement | DucTableElement | DucDocElement | DucFeatureControlFrameElement | DucLinearElement | DucPdfElement | DucMermaidElement;
|
|
135
147
|
export type DucTextContainer = DucRectangleElement | DucPolygonElement | DucEllipseElement | DucArrowElement;
|
|
136
148
|
export type DucFlowchartNodeElement = DucRectangleElement | DucPolygonElement | DucEllipseElement;
|
|
137
|
-
export type RectangularElement = DucRectangleElement | DucPolygonElement | DucFrameLikeElement | DucEmbeddableElement | DucImageElement | DucTextElement | DucSelectionElement | DucDocElement | DucTableElement | DucFeatureControlFrameElement | DucViewportElement | DucPlotElement | DucPdfElement
|
|
149
|
+
export type RectangularElement = DucRectangleElement | DucPolygonElement | DucFrameLikeElement | DucEmbeddableElement | DucImageElement | DucTextElement | DucSelectionElement | DucDocElement | DucTableElement | DucFeatureControlFrameElement | DucViewportElement | DucPlotElement | DucPdfElement;
|
|
138
150
|
export type DucStackLikeElement = DucPlotElement | DucViewportElement | DucFrameElement;
|
|
139
151
|
export type DucLinearLikeElement = DucLinearElement | DucViewportElement | DucArrowElement;
|
|
140
152
|
export type DucFrameLikeElement = DucPlotElement | DucFrameElement;
|
|
141
153
|
export type DucIframeLikeElement = DucEmbeddableElement | DucTableElement | DucDocElement;
|
|
142
|
-
export type ElementConstructorOpts = MarkOptional<Omit<DucGenericElement, "id" | "type" | "isDeleted" | "updated">, "width" | "height" | "angle" | "groupIds" | "frameId" | "index" | "boundElements" | "seed" | "version" | "versionNonce" | "link" | "background" | "stroke" | "roundness" | "locked" | "opacity" | "customData" | "isVisible" | "description" | "scope" | "blending" | "isPlot" | "isAnnotative" | "regionIds" | "layerId">;
|
|
154
|
+
export type ElementConstructorOpts = MarkOptional<Omit<DucGenericElement, "id" | "type" | "isDeleted" | "updated">, "width" | "height" | "angle" | "groupIds" | "blockIds" | "instanceId" | "frameId" | "index" | "boundElements" | "seed" | "version" | "versionNonce" | "link" | "background" | "stroke" | "roundness" | "locked" | "opacity" | "customData" | "isVisible" | "description" | "scope" | "blending" | "isPlot" | "isAnnotative" | "regionIds" | "layerId">;
|
|
143
155
|
export type ElementUpdate<TElement extends DucElement> = Omit<Partial<TElement>, "id" | "version" | "versionNonce" | "updated">;
|
|
144
156
|
export type DucElementType = DucElement["type"];
|
|
145
157
|
export type DucCommonStyle = {
|
|
@@ -246,7 +258,7 @@ export type StrokeStyle = {
|
|
|
246
258
|
/**
|
|
247
259
|
* Override the dash line into a custom shape
|
|
248
260
|
*/
|
|
249
|
-
dashLineOverride?:
|
|
261
|
+
dashLineOverride?: InstanceId;
|
|
250
262
|
/**
|
|
251
263
|
* The cap of the dash
|
|
252
264
|
* @default butt
|
|
@@ -734,25 +746,71 @@ export type DucBlockAttributeDefinition = {
|
|
|
734
746
|
/** If true, the attribute's value is fixed and cannot be changed after insertion. */
|
|
735
747
|
isConstant: boolean;
|
|
736
748
|
};
|
|
749
|
+
/**
|
|
750
|
+
* Indicates the source drawing of a block.
|
|
751
|
+
*/
|
|
752
|
+
export type BlockSource = string;
|
|
753
|
+
export interface BlockLocalizationEntry {
|
|
754
|
+
title: string;
|
|
755
|
+
description?: string;
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* A mapping of locale codes to their corresponding localized block metadata.
|
|
759
|
+
* The keys represent locales in a BCP-47 standard language tag format (e.g., "en-US", "fr-FR").
|
|
760
|
+
*/
|
|
761
|
+
export type BlockLocalizationMap = Record<string, BlockLocalizationEntry>;
|
|
762
|
+
export interface DucBlockMetadata {
|
|
763
|
+
/** Drawing id this block originates from */
|
|
764
|
+
source?: BlockSource;
|
|
765
|
+
/** Total number of times the block was instantiated */
|
|
766
|
+
usageCount: number;
|
|
767
|
+
/** Creation timestamp */
|
|
768
|
+
createdAt: number;
|
|
769
|
+
/** Last update timestamp */
|
|
770
|
+
updatedAt: number;
|
|
771
|
+
/** Localization metadata */
|
|
772
|
+
localization?: BlockLocalizationMap;
|
|
773
|
+
}
|
|
774
|
+
/**
|
|
775
|
+
* Defines the "Blueprint" for a reusable component.
|
|
776
|
+
*
|
|
777
|
+
* **Element Relationship Logic:**
|
|
778
|
+
* The connection between this Block Definition and `_DucElementBase` depends on the state:
|
|
779
|
+
*
|
|
780
|
+
* 1. **Definition State (Source):**
|
|
781
|
+
* - Elements that define the geometry of this block have this `id` inside their `element.blockIds`.
|
|
782
|
+
* - Their `element.instanceId` is `null`.
|
|
783
|
+
*
|
|
784
|
+
* 2. **Instance State (Usage):**
|
|
785
|
+
* - When instantiated via `DucBlockInstance`, the rendered elements have `element.instanceId` set (not null).
|
|
786
|
+
* - Crucially, these instance elements have **empty** `element.blockIds`.
|
|
787
|
+
* - The relationship is resolved indirectly: `Element.instanceId` -> `DucBlockInstance.blockId` -> `DucBlock.id`.
|
|
788
|
+
*/
|
|
737
789
|
export type DucBlock = {
|
|
738
|
-
id:
|
|
790
|
+
id: BlockId;
|
|
739
791
|
label: string;
|
|
740
792
|
description?: string;
|
|
741
793
|
version: number;
|
|
742
|
-
/** An array of all elements that constitute the block's geometry and annotations. */
|
|
743
|
-
elements: readonly DucElement[];
|
|
744
794
|
/**
|
|
745
795
|
* A record of attribute definitions for this block, keyed by their tag.
|
|
746
796
|
* This defines the "slots" for data that each instance can fill.
|
|
747
797
|
*/
|
|
748
798
|
attributeDefinitions: Readonly<Record<string, DucBlockAttributeDefinition>>;
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
799
|
+
/** Block metadata including source, usage count, timestamps, and localization */
|
|
800
|
+
metadata?: DucBlockMetadata;
|
|
801
|
+
/** Cached thumbnail image for the block (webp format) */
|
|
802
|
+
thumbnail?: Uint8Array;
|
|
803
|
+
};
|
|
804
|
+
export type DucBlockInstance = {
|
|
805
|
+
id: InstanceId;
|
|
806
|
+
/** The reference to the DucBlock definition this instance is based on */
|
|
752
807
|
blockId: string;
|
|
808
|
+
/** The version that should match the blockId's version, incremented on each change */
|
|
809
|
+
version: number;
|
|
753
810
|
/**
|
|
754
811
|
* Keys are the element ids of the block instance
|
|
755
812
|
* Values are the element overrides
|
|
813
|
+
* <string, string> <=> <elementId, path to field on the element (via JSON RFC6902 style path)>
|
|
756
814
|
*/
|
|
757
815
|
elementOverrides?: Record<string, string>;
|
|
758
816
|
/**
|
|
@@ -762,6 +820,19 @@ export type DucBlockInstanceElement = _DucElementBase & {
|
|
|
762
820
|
attributeValues?: Readonly<Record<string, string>>;
|
|
763
821
|
duplicationArray: DucBlockDuplicationArray | null;
|
|
764
822
|
};
|
|
823
|
+
export type DucBlockCollection = {
|
|
824
|
+
id: string;
|
|
825
|
+
label: string;
|
|
826
|
+
/**
|
|
827
|
+
* True if pointing to another collection, False if pointing to a block.
|
|
828
|
+
*/
|
|
829
|
+
children: Array<{
|
|
830
|
+
isCollection: boolean;
|
|
831
|
+
id: string;
|
|
832
|
+
}>;
|
|
833
|
+
metadata?: DucBlockMetadata;
|
|
834
|
+
thumbnail?: Uint8Array;
|
|
835
|
+
};
|
|
765
836
|
export type _DucStackBase = DucStackLikeStyles & {
|
|
766
837
|
label: string;
|
|
767
838
|
description: string | null;
|
|
@@ -935,14 +1006,14 @@ export type LeaderContent = {
|
|
|
935
1006
|
} | {
|
|
936
1007
|
type: "block";
|
|
937
1008
|
/** The ID of the DucBlock definition to use as content. */
|
|
938
|
-
blockId:
|
|
1009
|
+
blockId: InstanceId;
|
|
939
1010
|
/**
|
|
940
1011
|
* The attribute values and element overrides for this specific block instance.
|
|
941
|
-
* This is a subset of the properties from
|
|
1012
|
+
* This is a subset of the properties from DucBlockInstance.
|
|
942
1013
|
*/
|
|
943
1014
|
instanceData: {
|
|
944
|
-
attributeValues?:
|
|
945
|
-
elementOverrides?:
|
|
1015
|
+
attributeValues?: DucBlockInstance["attributeValues"];
|
|
1016
|
+
elementOverrides?: DucBlockInstance["elementOverrides"];
|
|
946
1017
|
};
|
|
947
1018
|
};
|
|
948
1019
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ElementOrToolType } from "..";
|
|
2
2
|
import type { MarkNonNullable } from "../utility-types";
|
|
3
3
|
import { Bounds, LineSegment, TuplePoint } from "../geometryTypes";
|
|
4
|
-
import type { DucArrowElement, DucBindableElement, DucElbowArrowElement, DucElement, DucElementType, DucEmbeddableElement, DucFlowchartNodeElement, DucFrameElement, DucFrameLikeElement, DucFreeDrawElement, DucImageElement, DucLinearElement, DucPlotElement, DucTableElement, DucPointBinding, DucTextContainer, DucTextElement, DucTextElementWithContainer, FixedPointBinding, InitializedDucImageElement, DucNonSelectionElement, DucEllipseElement, DucPolygonElement,
|
|
4
|
+
import type { DucArrowElement, DucBindableElement, DucElbowArrowElement, DucElement, DucElementType, DucEmbeddableElement, DucFlowchartNodeElement, DucFrameElement, DucFrameLikeElement, DucFreeDrawElement, DucImageElement, DucLinearElement, DucPlotElement, DucTableElement, DucPointBinding, DucTextContainer, DucTextElement, DucTextElementWithContainer, FixedPointBinding, InitializedDucImageElement, DucNonSelectionElement, DucEllipseElement, DucPolygonElement, NonDeleted, DucIframeLikeElement } from "./";
|
|
5
5
|
export declare const isInitializedImageElement: (element: DucElement | null) => element is InitializedDucImageElement;
|
|
6
6
|
export declare const isImageElement: (element: DucElement | null) => element is DucImageElement;
|
|
7
7
|
export declare const isEmbeddableElement: (element: DucElement | null | undefined) => element is DucEmbeddableElement;
|
|
@@ -25,7 +25,6 @@ export declare const isBindingElement: (element?: DucElement | null, includeLock
|
|
|
25
25
|
export declare const isBindingElementType: (elementType: ElementOrToolType) => boolean;
|
|
26
26
|
export declare const isBindableElement: (element: DucElement | null | undefined, includeLocked?: boolean) => element is DucBindableElement;
|
|
27
27
|
export declare const isRectanguloidElement: (element?: DucElement | null) => element is DucBindableElement;
|
|
28
|
-
export declare const isBlockInstanceElement: (element?: DucElement | null) => element is DucBlockInstanceElement;
|
|
29
28
|
export declare const isRectangularElement: (element?: DucElement | null) => element is DucBindableElement;
|
|
30
29
|
export declare const isTextBindableContainer: (element: DucElement | null, includeLocked?: boolean) => element is DucTextContainer;
|
|
31
30
|
export declare const isDucElement: (element: any) => element is DucElement;
|
|
@@ -93,9 +93,6 @@ export const isRectanguloidElement = (element) => {
|
|
|
93
93
|
element.type === "table" ||
|
|
94
94
|
(element.type === "text" && !element.containerId)));
|
|
95
95
|
};
|
|
96
|
-
export const isBlockInstanceElement = (element) => {
|
|
97
|
-
return element != null && element.type === "blockinstance";
|
|
98
|
-
};
|
|
99
96
|
// TODO: Remove this when proper distance calculation is introduced
|
|
100
97
|
// @see binding.ts:distanceToBindableElement()
|
|
101
98
|
export const isRectangularElement = (element) => {
|
|
@@ -135,7 +132,6 @@ export const isDucElement = (element) => {
|
|
|
135
132
|
case "dimension":
|
|
136
133
|
case "leader":
|
|
137
134
|
case "doc":
|
|
138
|
-
case "blockinstance":
|
|
139
135
|
case "selection":
|
|
140
136
|
case "parametric":
|
|
141
137
|
case "featurecontrolframe":
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ export * from "./typeChecks";
|
|
|
5
5
|
import { OBJECT_SNAP_MODE, PRUNING_LEVEL } from "../flatbuffers/duc";
|
|
6
6
|
import { SupportedMeasures } from "../technical/scopes";
|
|
7
7
|
import { Standard } from "../technical/standards";
|
|
8
|
-
import { DucBindableElement, DucBlock, DucElement, DucElementType, DucGroup, DucIframeLikeElement, DucLayer, DucLinearElement, DucPoint, DucRegion, DucTextElement, ElementBackground, ElementStroke, ExternalFileId, FontFamilyValues, LineHead, NonDeleted, TextAlign } from "./elements";
|
|
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
|
|
@@ -24,6 +24,8 @@ export interface ExportedDataState {
|
|
|
24
24
|
/** Project-wide settings that are saved with the document and shared by all users */
|
|
25
25
|
globalState: DucGlobalState;
|
|
26
26
|
blocks: readonly DucBlock[];
|
|
27
|
+
blockInstances: readonly DucBlockInstance[];
|
|
28
|
+
blockCollections: readonly DucBlockCollection[];
|
|
27
29
|
groups: readonly DucGroup[];
|
|
28
30
|
regions: readonly DucRegion[];
|
|
29
31
|
layers: readonly DucLayer[];
|
|
@@ -35,6 +37,7 @@ export interface ExportedDataState {
|
|
|
35
37
|
id: string | undefined;
|
|
36
38
|
}
|
|
37
39
|
export type ExportedDataStateContent = Omit<ExportedDataState, "type" | "version" | "source">;
|
|
40
|
+
export type BaseExportedDataState = MarkOptional<ExportedDataStateContent, "elements" | "localState" | "versionGraph">;
|
|
38
41
|
/**
|
|
39
42
|
* A version of the data state where all fields are optional.
|
|
40
43
|
* This is useful for importing data where some fields might be missing.
|
package/dist/utils/bounds.js
CHANGED
|
@@ -294,7 +294,7 @@ export const calculatePointsBoundsWithCenter = (points) => {
|
|
|
294
294
|
};
|
|
295
295
|
export const getElementPointsCoords = (element, points) => {
|
|
296
296
|
var _a, _b, _c;
|
|
297
|
-
if (points.length === 0) {
|
|
297
|
+
if (!points || !Array.isArray(points) || points.length === 0) {
|
|
298
298
|
return [
|
|
299
299
|
element.x.scoped,
|
|
300
300
|
element.y.scoped,
|
|
@@ -49,6 +49,15 @@ export declare const MIME_TYPES: {
|
|
|
49
49
|
readonly binary: "application/octet-stream";
|
|
50
50
|
readonly pdf: "application/pdf";
|
|
51
51
|
readonly zip: "application/zip";
|
|
52
|
+
readonly xls: "application/vnd.ms-excel";
|
|
53
|
+
readonly xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
54
|
+
readonly doc: "application/msword";
|
|
55
|
+
readonly docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
56
|
+
readonly csv: "text/csv";
|
|
57
|
+
readonly markdown: "text/markdown";
|
|
58
|
+
readonly step: "model/step";
|
|
59
|
+
readonly stp: "application/step";
|
|
60
|
+
readonly stl: "model/stl";
|
|
52
61
|
};
|
|
53
62
|
export declare const EXPORT_IMAGE_TYPES: {
|
|
54
63
|
readonly png: "png";
|
|
@@ -58,10 +67,11 @@ export declare const EXPORT_IMAGE_TYPES: {
|
|
|
58
67
|
export declare const EXPORT_DATA_TYPES: {
|
|
59
68
|
readonly duc: "duc";
|
|
60
69
|
readonly json: "json";
|
|
61
|
-
readonly
|
|
70
|
+
readonly ducClipboard: "duc/clipboard";
|
|
62
71
|
readonly excalidrawLibrary: "excalidrawlib";
|
|
63
|
-
readonly
|
|
72
|
+
readonly ducClipboardWithAPI: "duc-api/clipboard";
|
|
64
73
|
};
|
|
74
|
+
export declare const SUPPORTED_DATA_TYPES: ("image/svg+xml" | "image/png" | "image/jpeg" | "image/gif" | "image/webp" | "image/bmp" | "image/x-icon" | "image/avif" | "image/jfif" | "application/json" | "application/vnd.duc-cad" | "application/vnd.duc-config" | "application/pdf" | "application/vnd.ms-excel" | "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" | "application/msword" | "application/vnd.openxmlformats-officedocument.wordprocessingml.document" | "text/csv" | "text/markdown" | "model/step" | "application/step" | "model/stl")[];
|
|
65
75
|
export declare const VERSIONS: {
|
|
66
76
|
readonly excalidraw: 2;
|
|
67
77
|
readonly excalidrawLibrary: 2;
|
package/dist/utils/constants.js
CHANGED
|
@@ -37,7 +37,7 @@ export const MIME_TYPES = Object.assign({ json: "application/json",
|
|
|
37
37
|
// excalidraw data
|
|
38
38
|
duc: "application/vnd.duc-cad", ducfig: "application/vnd.duc-config", excalidrawlib: "application/vnd.excalidrawlib+json",
|
|
39
39
|
// image-encoded excalidraw data
|
|
40
|
-
"excalidraw.svg": "image/svg+xml", "excalidraw.png": "image/png", binary: "application/octet-stream", pdf: "application/pdf", zip: "application/zip" }, IMAGE_MIME_TYPES);
|
|
40
|
+
"excalidraw.svg": "image/svg+xml", "excalidraw.png": "image/png", binary: "application/octet-stream", pdf: "application/pdf", zip: "application/zip", xls: "application/vnd.ms-excel", xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", doc: "application/msword", docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", csv: "text/csv", markdown: "text/markdown", step: "model/step", stp: "application/step", stl: "model/stl" }, IMAGE_MIME_TYPES);
|
|
41
41
|
export const EXPORT_IMAGE_TYPES = {
|
|
42
42
|
png: "png",
|
|
43
43
|
svg: "svg",
|
|
@@ -46,10 +46,26 @@ export const EXPORT_IMAGE_TYPES = {
|
|
|
46
46
|
export const EXPORT_DATA_TYPES = {
|
|
47
47
|
duc: "duc",
|
|
48
48
|
json: "json",
|
|
49
|
-
|
|
49
|
+
ducClipboard: "duc/clipboard",
|
|
50
50
|
excalidrawLibrary: "excalidrawlib",
|
|
51
|
-
|
|
51
|
+
ducClipboardWithAPI: "duc-api/clipboard",
|
|
52
52
|
};
|
|
53
|
+
export const SUPPORTED_DATA_TYPES = [
|
|
54
|
+
MIME_TYPES.duc,
|
|
55
|
+
MIME_TYPES.ducfig,
|
|
56
|
+
MIME_TYPES.pdf,
|
|
57
|
+
MIME_TYPES.xls,
|
|
58
|
+
MIME_TYPES.xlsx,
|
|
59
|
+
MIME_TYPES.doc,
|
|
60
|
+
MIME_TYPES.docx,
|
|
61
|
+
MIME_TYPES.json,
|
|
62
|
+
MIME_TYPES.csv,
|
|
63
|
+
MIME_TYPES.markdown,
|
|
64
|
+
MIME_TYPES.step,
|
|
65
|
+
MIME_TYPES.stp,
|
|
66
|
+
MIME_TYPES.stl,
|
|
67
|
+
...Object.values(IMAGE_MIME_TYPES),
|
|
68
|
+
];
|
|
53
69
|
export const VERSIONS = {
|
|
54
70
|
excalidraw: 2,
|
|
55
71
|
excalidrawLibrary: 2,
|
|
@@ -162,6 +162,7 @@ export const getBaseElementProps = (element) => {
|
|
|
162
162
|
isAnnotative: element.isAnnotative,
|
|
163
163
|
layerId: element.layerId,
|
|
164
164
|
regionIds: element.regionIds,
|
|
165
|
+
blockIds: element.blockIds,
|
|
165
166
|
roundness: element.roundness,
|
|
166
167
|
blending: element.blending,
|
|
167
168
|
background: element.background,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Scope } from "../../types";
|
|
2
|
-
import { DucArrowElement,
|
|
2
|
+
import { DucArrowElement, DucDimensionElement, DucDocElement, DucElement, DucEllipseElement, DucEmbeddableElement, DucFeatureControlFrameElement, DucFrameElement, DucFreeDrawElement, DucGenericElement, DucImageElement, DucLeaderElement, DucLinearElement, DucMermaidElement, DucParametricElement, DucPdfElement, DucPlotElement, DucPolygonElement, DucTableElement, DucTextElement, DucViewportElement, DucXRayElement, ElementConstructorOpts, ElementUpdate, NonDeleted } from "../../types/elements";
|
|
3
3
|
import { Mutable } from "../../types/utility-types";
|
|
4
4
|
export declare const newElementWith: <TElement extends DucElement>(element: TElement, updates: ElementUpdate<TElement>,
|
|
5
5
|
/** pass `true` to always regenerate */
|
|
@@ -46,12 +46,6 @@ export declare const newXRayElement: (currentScope: Scope, opts: ElementConstruc
|
|
|
46
46
|
export declare const newLeaderElement: (currentScope: Scope, opts: Partial<DucLeaderElement> & ElementConstructorOpts) => NonDeleted<DucLeaderElement>;
|
|
47
47
|
export declare const newDimensionElement: (currentScope: Scope, opts: ElementConstructorOpts) => NonDeleted<DucDimensionElement>;
|
|
48
48
|
export declare const newFeatureControlFrameElement: (currentScope: Scope, opts: ElementConstructorOpts) => NonDeleted<DucFeatureControlFrameElement>;
|
|
49
|
-
export declare const newBlockInstanceElement: (currentScope: Scope, opts: {
|
|
50
|
-
blockId: DucBlockInstanceElement["blockId"];
|
|
51
|
-
elementOverrides?: DucBlockInstanceElement["elementOverrides"];
|
|
52
|
-
attributeValues?: DucBlockInstanceElement["attributeValues"];
|
|
53
|
-
duplicationArray?: DucBlockInstanceElement["duplicationArray"];
|
|
54
|
-
} & ElementConstructorOpts) => NonDeleted<DucBlockInstanceElement>;
|
|
55
49
|
export declare const newParametricElement: (currentScope: Scope, opts: ElementConstructorOpts) => NonDeleted<DucParametricElement>;
|
|
56
50
|
/**
|
|
57
51
|
* Clones DucElement data structure. Does not regenerate id, nonce, or
|
|
@@ -39,7 +39,7 @@ force = false) => {
|
|
|
39
39
|
};
|
|
40
40
|
const _newElementBase = (type, currentScope, _a) => {
|
|
41
41
|
var _b, _c;
|
|
42
|
-
var { x, y, scope = currentScope, zIndex, index = DEFAULT_ELEMENT_PROPS.index, label, isVisible = DEFAULT_ELEMENT_PROPS.isVisible, isPlot = DEFAULT_ELEMENT_PROPS.isPlot, isAnnotative = DEFAULT_ELEMENT_PROPS.isAnnotative, stroke = [DEFAULT_ELEMENT_PROPS.stroke], background = [DEFAULT_ELEMENT_PROPS.background], opacity = DEFAULT_ELEMENT_PROPS.opacity, width = DEFAULT_ELEMENT_PROPS.width, height = DEFAULT_ELEMENT_PROPS.height, angle = DEFAULT_ELEMENT_PROPS.angle, groupIds = DEFAULT_ELEMENT_PROPS.groupIds, regionIds = [], frameId = DEFAULT_ELEMENT_PROPS.frameId, layerId = null, roundness = DEFAULT_ELEMENT_PROPS.roundness, boundElements = DEFAULT_ELEMENT_PROPS.boundElements, link = DEFAULT_ELEMENT_PROPS.link, locked = DEFAULT_ELEMENT_PROPS.locked, description = null } = _a, rest = __rest(_a, ["x", "y", "scope", "zIndex", "index", "label", "isVisible", "isPlot", "isAnnotative", "stroke", "background", "opacity", "width", "height", "angle", "groupIds", "regionIds", "frameId", "layerId", "roundness", "boundElements", "link", "locked", "description"]);
|
|
42
|
+
var { x, y, scope = currentScope, zIndex, index = DEFAULT_ELEMENT_PROPS.index, label, isVisible = DEFAULT_ELEMENT_PROPS.isVisible, isPlot = DEFAULT_ELEMENT_PROPS.isPlot, isAnnotative = DEFAULT_ELEMENT_PROPS.isAnnotative, stroke = [DEFAULT_ELEMENT_PROPS.stroke], background = [DEFAULT_ELEMENT_PROPS.background], opacity = DEFAULT_ELEMENT_PROPS.opacity, width = DEFAULT_ELEMENT_PROPS.width, height = DEFAULT_ELEMENT_PROPS.height, angle = DEFAULT_ELEMENT_PROPS.angle, groupIds = DEFAULT_ELEMENT_PROPS.groupIds, blockIds = [], instanceId = null, regionIds = [], frameId = DEFAULT_ELEMENT_PROPS.frameId, layerId = null, roundness = DEFAULT_ELEMENT_PROPS.roundness, boundElements = DEFAULT_ELEMENT_PROPS.boundElements, link = DEFAULT_ELEMENT_PROPS.link, locked = DEFAULT_ELEMENT_PROPS.locked, description = null } = _a, rest = __rest(_a, ["x", "y", "scope", "zIndex", "index", "label", "isVisible", "isPlot", "isAnnotative", "stroke", "background", "opacity", "width", "height", "angle", "groupIds", "blockIds", "instanceId", "regionIds", "frameId", "layerId", "roundness", "boundElements", "link", "locked", "description"]);
|
|
43
43
|
// assign type to guard against excess properties
|
|
44
44
|
const element = {
|
|
45
45
|
id: rest.id || randomId(),
|
|
@@ -55,6 +55,8 @@ const _newElementBase = (type, currentScope, _a) => {
|
|
|
55
55
|
background,
|
|
56
56
|
opacity,
|
|
57
57
|
groupIds,
|
|
58
|
+
blockIds,
|
|
59
|
+
instanceId,
|
|
58
60
|
frameId,
|
|
59
61
|
roundness,
|
|
60
62
|
label,
|
|
@@ -177,10 +179,6 @@ export const newFeatureControlFrameElement = (currentScope, opts) => {
|
|
|
177
179
|
bracketStyle: DATUM_BRACKET_STYLE.SQUARE
|
|
178
180
|
} }, _newElementBase("featurecontrolframe", currentScope, opts)), { type: "featurecontrolframe" });
|
|
179
181
|
};
|
|
180
|
-
export const newBlockInstanceElement = (currentScope, opts) => {
|
|
181
|
-
var _a, _b, _c;
|
|
182
|
-
return (Object.assign(Object.assign({}, _newElementBase("blockinstance", currentScope, opts)), { type: "blockinstance", blockId: opts.blockId, elementOverrides: (_a = opts.elementOverrides) !== null && _a !== void 0 ? _a : {}, attributeValues: (_b = opts.attributeValues) !== null && _b !== void 0 ? _b : {}, duplicationArray: (_c = opts.duplicationArray) !== null && _c !== void 0 ? _c : null }));
|
|
183
|
-
};
|
|
184
182
|
export const newParametricElement = (currentScope, opts) => (Object.assign(Object.assign({ source: { type: PARAMETRIC_SOURCE_TYPE.CODE, code: "" } }, _newElementBase("parametric", currentScope, opts)), { type: 'parametric' }));
|
|
185
183
|
// Simplified deep clone for the purpose of cloning DucElement.
|
|
186
184
|
//
|
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.
|
|
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",
|