ducjs 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/README.md +1 -1
  2. package/dist/flatbuffers/duc/duc-feature-control-frame-style.d.ts +0 -3
  3. package/dist/flatbuffers/duc/duc-feature-control-frame-style.js +0 -8
  4. package/dist/flatbuffers/duc/duc-leader-style.d.ts +0 -3
  5. package/dist/flatbuffers/duc/duc-leader-style.js +0 -8
  6. package/dist/flatbuffers/duc/duc-plot-style.d.ts +1 -4
  7. package/dist/flatbuffers/duc/duc-plot-style.js +1 -10
  8. package/dist/flatbuffers/duc/duc-table-style.d.ts +0 -3
  9. package/dist/flatbuffers/duc/duc-table-style.js +0 -8
  10. package/dist/flatbuffers/duc/duc-text-style.d.ts +0 -3
  11. package/dist/flatbuffers/duc/duc-text-style.js +0 -8
  12. package/dist/flatbuffers/duc/duc-viewport-style.d.ts +1 -4
  13. package/dist/flatbuffers/duc/duc-viewport-style.js +1 -10
  14. package/dist/flatbuffers/duc/duc-xray-style.d.ts +1 -4
  15. package/dist/flatbuffers/duc/duc-xray-style.js +1 -10
  16. package/dist/flatbuffers/duc/exported-data-state.d.ts +3 -0
  17. package/dist/flatbuffers/duc/exported-data-state.js +8 -1
  18. package/dist/index.d.ts +0 -1
  19. package/dist/index.js +0 -1
  20. package/dist/parse.d.ts +2 -2
  21. package/dist/parse.js +55 -18
  22. package/dist/restore/restoreDataState.d.ts +6 -2
  23. package/dist/restore/restoreDataState.js +20 -13
  24. package/dist/restore/restoreElements.js +16 -9
  25. package/dist/serialize.d.ts +2 -1
  26. package/dist/serialize.js +12 -25
  27. package/dist/types/elements/index.d.ts +7 -7
  28. package/dist/types/elements/typeChecks.d.ts +2 -1
  29. package/dist/types/elements/typeChecks.js +4 -1
  30. package/dist/types/index.d.ts +4 -1
  31. package/dist/types/index.js +1 -0
  32. package/dist/types/typeChecks.d.ts +5 -0
  33. package/dist/types/typeChecks.js +10 -0
  34. package/dist/utils/constants.d.ts +2 -0
  35. package/dist/utils/constants.js +1 -3
  36. package/dist/utils/elements/frameElement.d.ts +1 -0
  37. package/dist/utils/elements/frameElement.js +13 -1
  38. package/dist/utils/elements/index.js +11 -15
  39. package/dist/utils/elements/newElement.d.ts +1 -1
  40. package/dist/utils/elements/newElement.js +23 -23
  41. package/dist/utils/elements/textElement.js +3 -1
  42. package/dist/utils/functionCodec.js +2 -2
  43. package/dist/utils/index.d.ts +1 -0
  44. package/dist/utils/index.js +1 -0
  45. package/dist/utils/traverse.d.ts +22 -0
  46. package/dist/utils/traverse.js +87 -0
  47. package/package.json +4 -2
  48. package/dist/legacy/index.d.ts +0 -1
  49. package/dist/legacy/index.js +0 -1
  50. package/dist/legacy/v1/duc/app-state.d.ts +0 -124
  51. package/dist/legacy/v1/duc/app-state.js +0 -388
  52. package/dist/legacy/v1/duc/binary-file-data.d.ts +0 -27
  53. package/dist/legacy/v1/duc/binary-file-data.js +0 -90
  54. package/dist/legacy/v1/duc/binary-files-entry.d.ts +0 -16
  55. package/dist/legacy/v1/duc/binary-files-entry.js +0 -43
  56. package/dist/legacy/v1/duc/binary-files.d.ts +0 -17
  57. package/dist/legacy/v1/duc/binary-files.js +0 -55
  58. package/dist/legacy/v1/duc/binding-point.d.ts +0 -15
  59. package/dist/legacy/v1/duc/binding-point.js +0 -48
  60. package/dist/legacy/v1/duc/bound-element.d.ts +0 -17
  61. package/dist/legacy/v1/duc/bound-element.js +0 -48
  62. package/dist/legacy/v1/duc/duc-block-attribute-details.d.ts +0 -22
  63. package/dist/legacy/v1/duc/duc-block-attribute-details.js +0 -57
  64. package/dist/legacy/v1/duc/duc-block-attribute.d.ts +0 -16
  65. package/dist/legacy/v1/duc/duc-block-attribute.js +0 -43
  66. package/dist/legacy/v1/duc/duc-block-instance-element-override.d.ts +0 -17
  67. package/dist/legacy/v1/duc/duc-block-instance-element-override.js +0 -48
  68. package/dist/legacy/v1/duc/duc-block.d.ts +0 -34
  69. package/dist/legacy/v1/duc/duc-block.js +0 -110
  70. package/dist/legacy/v1/duc/duc-element.d.ts +0 -273
  71. package/dist/legacy/v1/duc/duc-element.js +0 -865
  72. package/dist/legacy/v1/duc/duc-group.d.ts +0 -40
  73. package/dist/legacy/v1/duc/duc-group.js +0 -114
  74. package/dist/legacy/v1/duc/duc-line-reference.d.ts +0 -15
  75. package/dist/legacy/v1/duc/duc-line-reference.js +0 -43
  76. package/dist/legacy/v1/duc/duc-line.d.ts +0 -15
  77. package/dist/legacy/v1/duc/duc-line.js +0 -43
  78. package/dist/legacy/v1/duc/duc-path.d.ts +0 -26
  79. package/dist/legacy/v1/duc/duc-path.js +0 -69
  80. package/dist/legacy/v1/duc/duc-table-cell.d.ts +0 -22
  81. package/dist/legacy/v1/duc/duc-table-cell.js +0 -57
  82. package/dist/legacy/v1/duc/duc-table-column.d.ts +0 -18
  83. package/dist/legacy/v1/duc/duc-table-column.js +0 -50
  84. package/dist/legacy/v1/duc/duc-table-row.d.ts +0 -18
  85. package/dist/legacy/v1/duc/duc-table-row.js +0 -50
  86. package/dist/legacy/v1/duc/duc-table-style-props.d.ts +0 -39
  87. package/dist/legacy/v1/duc/duc-table-style-props.js +0 -114
  88. package/dist/legacy/v1/duc/duc-table-style.d.ts +0 -14
  89. package/dist/legacy/v1/duc/duc-table-style.js +0 -41
  90. package/dist/legacy/v1/duc/element-background.d.ts +0 -14
  91. package/dist/legacy/v1/duc/element-background.js +0 -41
  92. package/dist/legacy/v1/duc/element-content-base.d.ts +0 -22
  93. package/dist/legacy/v1/duc/element-content-base.js +0 -64
  94. package/dist/legacy/v1/duc/element-stroke.d.ts +0 -23
  95. package/dist/legacy/v1/duc/element-stroke.js +0 -66
  96. package/dist/legacy/v1/duc/exported-data-state.d.ts +0 -51
  97. package/dist/legacy/v1/duc/exported-data-state.js +0 -155
  98. package/dist/legacy/v1/duc/image-crop.d.ts +0 -23
  99. package/dist/legacy/v1/duc/image-crop.js +0 -80
  100. package/dist/legacy/v1/duc/linear-element-editor.d.ts +0 -44
  101. package/dist/legacy/v1/duc/linear-element-editor.js +0 -119
  102. package/dist/legacy/v1/duc/point-binding.d.ts +0 -25
  103. package/dist/legacy/v1/duc/point-binding.js +0 -72
  104. package/dist/legacy/v1/duc/point.d.ts +0 -20
  105. package/dist/legacy/v1/duc/point.js +0 -63
  106. package/dist/legacy/v1/duc/pointer-down-state.d.ts +0 -32
  107. package/dist/legacy/v1/duc/pointer-down-state.js +0 -90
  108. package/dist/legacy/v1/duc/renderer-state.d.ts +0 -17
  109. package/dist/legacy/v1/duc/renderer-state.js +0 -54
  110. package/dist/legacy/v1/duc/segment-midpoint-state.d.ts +0 -18
  111. package/dist/legacy/v1/duc/segment-midpoint-state.js +0 -57
  112. package/dist/legacy/v1/duc/simple-point.d.ts +0 -15
  113. package/dist/legacy/v1/duc/simple-point.js +0 -48
  114. package/dist/legacy/v1/duc/stroke-sides.d.ts +0 -23
  115. package/dist/legacy/v1/duc/stroke-sides.js +0 -66
  116. package/dist/legacy/v1/duc/stroke-style.d.ts +0 -31
  117. package/dist/legacy/v1/duc/stroke-style.js +0 -102
  118. package/dist/legacy/v1/duc/tiling-properties.d.ts +0 -21
  119. package/dist/legacy/v1/duc/tiling-properties.js +0 -75
  120. package/dist/legacy/v1/duc.d.ts +0 -35
  121. package/dist/legacy/v1/duc.js +0 -37
  122. package/dist/legacy/v1/index.d.ts +0 -1
  123. package/dist/legacy/v1/index.js +0 -1
  124. package/dist/legacy/v1/parse/index.d.ts +0 -67
  125. package/dist/legacy/v1/parse/index.js +0 -101
  126. package/dist/legacy/v1/parse/parseAppStateFromBinary.d.ts +0 -3
  127. package/dist/legacy/v1/parse/parseAppStateFromBinary.js +0 -139
  128. package/dist/legacy/v1/parse/parseBinaryFilesFromBinary.d.ts +0 -4
  129. package/dist/legacy/v1/parse/parseBinaryFilesFromBinary.js +0 -32
  130. package/dist/legacy/v1/parse/parseBlockFromBinary.d.ts +0 -3
  131. package/dist/legacy/v1/parse/parseBlockFromBinary.js +0 -70
  132. package/dist/legacy/v1/parse/parseElementFromBinary.d.ts +0 -8
  133. package/dist/legacy/v1/parse/parseElementFromBinary.js +0 -387
  134. package/dist/legacy/v1/parse/parseGroupFromBinary.d.ts +0 -4
  135. package/dist/legacy/v1/parse/parseGroupFromBinary.js +0 -36
  136. package/dist/legacy/v1/parse/parseRendererStateFromBinary.d.ts +0 -4
  137. package/dist/legacy/v1/parse/parseRendererStateFromBinary.js +0 -15
  138. package/dist/legacy/v1/serialize/index.d.ts +0 -5
  139. package/dist/legacy/v1/serialize/index.js +0 -81
  140. package/dist/legacy/v1/serialize/serializationUtils.d.ts +0 -17
  141. package/dist/legacy/v1/serialize/serializationUtils.js +0 -27
  142. package/dist/legacy/v1/serialize/serializeAppStateFromDuc.d.ts +0 -4
  143. package/dist/legacy/v1/serialize/serializeAppStateFromDuc.js +0 -145
  144. package/dist/legacy/v1/serialize/serializeBinaryFilesFromDuc.d.ts +0 -4
  145. package/dist/legacy/v1/serialize/serializeBinaryFilesFromDuc.js +0 -46
  146. package/dist/legacy/v1/serialize/serializeBlockFromDuc.d.ts +0 -3
  147. package/dist/legacy/v1/serialize/serializeBlockFromDuc.js +0 -60
  148. package/dist/legacy/v1/serialize/serializeElementFromDuc.d.ts +0 -8
  149. package/dist/legacy/v1/serialize/serializeElementFromDuc.js +0 -435
  150. package/dist/legacy/v1/serialize/serializeGroupFromDuc.d.ts +0 -3
  151. package/dist/legacy/v1/serialize/serializeGroupFromDuc.js +0 -37
  152. package/dist/legacy/v1/serialize/serializeRendererStateFromDuc.d.ts +0 -4
  153. package/dist/legacy/v1/serialize/serializeRendererStateFromDuc.js +0 -7
  154. package/dist/legacy/v1/types/elements/index.d.ts +0 -480
  155. package/dist/legacy/v1/types/elements/index.js +0 -1
  156. package/dist/legacy/v1/types/elements/typeChecks.d.ts +0 -40
  157. package/dist/legacy/v1/types/elements/typeChecks.js +0 -179
  158. package/dist/legacy/v1/types/geometryTypes.d.ts +0 -78
  159. package/dist/legacy/v1/types/geometryTypes.js +0 -1
  160. package/dist/legacy/v1/types/index.d.ts +0 -496
  161. package/dist/legacy/v1/types/index.js +0 -1
  162. package/dist/legacy/v1/types/utility-types.d.ts +0 -31
  163. package/dist/legacy/v1/types/utility-types.js +0 -1
  164. package/dist/legacy/v1/utils/bounds.d.ts +0 -76
  165. package/dist/legacy/v1/utils/bounds.js +0 -415
  166. package/dist/legacy/v1/utils/constants.d.ts +0 -370
  167. package/dist/legacy/v1/utils/constants.js +0 -571
  168. package/dist/legacy/v1/utils/elements/index.d.ts +0 -26
  169. package/dist/legacy/v1/utils/elements/index.js +0 -108
  170. package/dist/legacy/v1/utils/elements/linearElement.d.ts +0 -133
  171. package/dist/legacy/v1/utils/elements/linearElement.js +0 -544
  172. package/dist/legacy/v1/utils/elements/textElement.d.ts +0 -89
  173. package/dist/legacy/v1/utils/elements/textElement.js +0 -563
  174. package/dist/legacy/v1/utils/index.d.ts +0 -26
  175. package/dist/legacy/v1/utils/index.js +0 -40
  176. package/dist/legacy/v1/utils/math/algebra/ga.d.ts +0 -63
  177. package/dist/legacy/v1/utils/math/algebra/ga.js +0 -268
  178. package/dist/legacy/v1/utils/math/algebra/gadirections.d.ts +0 -9
  179. package/dist/legacy/v1/utils/math/algebra/gadirections.js +0 -18
  180. package/dist/legacy/v1/utils/math/algebra/galines.d.ts +0 -23
  181. package/dist/legacy/v1/utils/math/algebra/galines.js +0 -32
  182. package/dist/legacy/v1/utils/math/algebra/gapoints.d.ts +0 -8
  183. package/dist/legacy/v1/utils/math/algebra/gapoints.js +0 -30
  184. package/dist/legacy/v1/utils/math/algebra/gatransforms.d.ts +0 -10
  185. package/dist/legacy/v1/utils/math/algebra/gatransforms.js +0 -23
  186. package/dist/legacy/v1/utils/math/bbox.d.ts +0 -10
  187. package/dist/legacy/v1/utils/math/bbox.js +0 -42
  188. package/dist/legacy/v1/utils/math/geometry.d.ts +0 -102
  189. package/dist/legacy/v1/utils/math/geometry.js +0 -790
  190. package/dist/legacy/v1/utils/math/index.d.ts +0 -309
  191. package/dist/legacy/v1/utils/math/index.js +0 -1140
  192. package/dist/legacy/v1/utils/math/random.d.ts +0 -4
  193. package/dist/legacy/v1/utils/math/random.js +0 -25
  194. package/dist/legacy/v1/utils/measurements.d.ts +0 -33
  195. package/dist/legacy/v1/utils/measurements.js +0 -65
  196. package/dist/legacy/v1/utils/normalize.d.ts +0 -14
  197. package/dist/legacy/v1/utils/normalize.js +0 -49
  198. package/dist/legacy/v1/utils/restore.d.ts +0 -197
  199. package/dist/legacy/v1/utils/restore.js +0 -1255
  200. package/dist/legacy/v1/utils/scopes.d.ts +0 -260
  201. package/dist/legacy/v1/utils/scopes.js +0 -661
  202. package/dist/legacy/v1/utils/standards.d.ts +0 -12
  203. package/dist/legacy/v1/utils/standards.js +0 -10
  204. package/dist/legacy/v1/utils/state/index.d.ts +0 -2
  205. package/dist/legacy/v1/utils/state/index.js +0 -68
  206. package/dist/legacy/v1/utils/url.d.ts +0 -8
  207. package/dist/legacy/v1/utils/url.js +0 -33
@@ -20,6 +20,7 @@ export type RestoredDataState = {
20
20
  layers: DucLayer[];
21
21
  standards: Standard[];
22
22
  versionGraph: VersionGraph | undefined;
23
+ id: string;
23
24
  };
24
25
  export interface ExportedLibraryData {
25
26
  type: string;
@@ -41,7 +42,10 @@ export type ElementsConfig = {
41
42
  */
42
43
  passThroughElementIds?: string[];
43
44
  };
44
- export declare const restore: (data: ImportedDataState | null, elementsConfig: ElementsConfig) => RestoredDataState;
45
+ export type RestoreConfig = {
46
+ forceScope?: Scope;
47
+ };
48
+ export declare const restore: (data: ImportedDataState | null, elementsConfig: ElementsConfig, restoreConfig?: RestoreConfig) => RestoredDataState;
45
49
  export declare const restoreFiles: (importedFiles: unknown) => DucExternalFiles;
46
50
  export declare const restoreDictionary: (importedDictionary: unknown) => Dictionary;
47
51
  /**
@@ -100,7 +104,7 @@ export declare const restoreGlobalState: (importedState?: Partial<DucGlobalState
100
104
  * @param restoredGlobalState - The complete and valid global state for the document.
101
105
  * @returns A complete and valid DucLocalState object.
102
106
  */
103
- export declare const restoreLocalState: (importedState: Partial<DucLocalState> | undefined, restoredGlobalState: RestoredDataState["globalState"], restoredStandards: RestoredDataState["standards"]) => DucLocalState;
107
+ export declare const restoreLocalState: (importedState: Partial<DucLocalState> | undefined, restoredGlobalState: RestoredDataState["globalState"], restoredStandards: RestoredDataState["standards"], forceScope?: Scope) => DucLocalState;
104
108
  export declare const restoreVersionGraph: (importedGraph: any) => RestoredDataState["versionGraph"];
105
109
  /**
106
110
  * Restores common properties for elements leveraging _DucStackBase.
@@ -1,4 +1,5 @@
1
1
  import { BEZIER_MIRRORING, BLENDING, BOOLEAN_OPERATION, ELEMENT_CONTENT_PREFERENCE, IMAGE_STATUS, LINE_HEAD, PRUNING_LEVEL, STROKE_CAP, STROKE_JOIN, STROKE_PLACEMENT, STROKE_PREFERENCE, STROKE_SIDE_PREFERENCE, TEXT_ALIGN, VERTICAL_ALIGN, } from "../flatbuffers/duc";
2
+ import { nanoid } from "nanoid";
2
3
  import { restoreElements } from "./restoreElements";
3
4
  import { isStandardIdPresent, restoreStandards, } from "./restoreStandards";
4
5
  import { getPrecisionScope } from "../technical/measurements";
@@ -8,11 +9,11 @@ import { base64ToUint8Array, getDefaultGlobalState, getDefaultLocalState, getZoo
8
9
  import { DEFAULT_ELEMENT_PROPS, DEFAULT_POLYGON_SIDES, DEFAULT_TEXT_ALIGN, DEFAULT_VERTICAL_ALIGN, DEFAULT_ZOOM_STEP, MAX_ZOOM_STEP, MIN_ZOOM_STEP, } from "../utils/constants";
9
10
  import { getDefaultStackProperties } from "../utils/elements";
10
11
  import tinycolor from "tinycolor2";
11
- export const restore = (data, elementsConfig) => {
12
+ export const restore = (data, elementsConfig, restoreConfig = {}) => {
12
13
  const restoredStandards = restoreStandards(data === null || data === void 0 ? void 0 : data.standards);
13
14
  const restoredDictionary = restoreDictionary(data === null || data === void 0 ? void 0 : data.dictionary);
14
15
  const restoredGlobalState = restoreGlobalState(data === null || data === void 0 ? void 0 : data.globalState);
15
- const restoredLocalState = restoreLocalState(data === null || data === void 0 ? void 0 : data.localState, restoredGlobalState, restoredStandards);
16
+ const restoredLocalState = restoreLocalState(data === null || data === void 0 ? void 0 : data.localState, restoredGlobalState, restoredStandards, restoreConfig.forceScope);
16
17
  const restoredElementsConfig = Object.assign(Object.assign({}, elementsConfig), { localState: restoredLocalState });
17
18
  const restoredBlocks = restoreBlocks(data === null || data === void 0 ? void 0 : data.blocks, restoredLocalState.scope, restoredElementsConfig);
18
19
  const restoredRegions = restoreRegions(data === null || data === void 0 ? void 0 : data.regions);
@@ -20,6 +21,9 @@ export const restore = (data, elementsConfig) => {
20
21
  const restoredLayers = restoreLayers(data === null || data === void 0 ? void 0 : data.layers, restoredLocalState.scope);
21
22
  const restoredElements = restoreElements(data === null || data === void 0 ? void 0 : data.elements, restoredLocalState.scope, restoredBlocks, restoredElementsConfig);
22
23
  const restoredVersionGraph = restoreVersionGraph(data === null || data === void 0 ? void 0 : data.versionGraph);
24
+ // Generate a new ID if none exists or if it's empty
25
+ const parsedId = data === null || data === void 0 ? void 0 : data.id;
26
+ const restoredId = (parsedId && parsedId.trim().length > 0) ? parsedId : nanoid();
23
27
  return {
24
28
  dictionary: restoredDictionary,
25
29
  thumbnail: isValidUint8Array(data === null || data === void 0 ? void 0 : data.thumbnail),
@@ -33,6 +37,7 @@ export const restore = (data, elementsConfig) => {
33
37
  localState: restoredLocalState,
34
38
  globalState: restoredGlobalState,
35
39
  files: restoreFiles(data === null || data === void 0 ? void 0 : data.files),
40
+ id: restoredId,
36
41
  };
37
42
  };
38
43
  export const restoreFiles = (importedFiles) => {
@@ -211,13 +216,13 @@ export const restoreBlocks = (blocks, currentScope, elementsConfig) => {
211
216
  * @returns A complete and valid DucGlobalState object.
212
217
  */
213
218
  export const restoreGlobalState = (importedState = {}) => {
214
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
219
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
215
220
  const defaults = getDefaultGlobalState();
216
- const linearPrecision = isValidFinitePositiveByteValue(importedState.coordDecimalPlaces, defaults.displayPrecision.linear);
217
- return Object.assign(Object.assign({}, defaults), { name: (_a = importedState.name) !== null && _a !== void 0 ? _a : defaults.name, viewBackgroundColor: (_b = importedState.viewBackgroundColor) !== null && _b !== void 0 ? _b : defaults.viewBackgroundColor, mainScope: (_c = isValidAppStateScopeValue(importedState.mainScope)) !== null && _c !== void 0 ? _c : defaults.mainScope, scopeExponentThreshold: isValidAppStateScopeExponentThresholdValue(importedState.scopeExponentThreshold, defaults.scopeExponentThreshold), dashSpacingScale: (_d = importedState.dashSpacingScale) !== null && _d !== void 0 ? _d : defaults.dashSpacingScale, isDashSpacingAffectedByViewportScale: (_e = importedState.isDashSpacingAffectedByViewportScale) !== null && _e !== void 0 ? _e : defaults.isDashSpacingAffectedByViewportScale, dimensionsAssociativeByDefault: (_f = importedState.dimensionsAssociativeByDefault) !== null && _f !== void 0 ? _f : defaults.dimensionsAssociativeByDefault, useAnnotativeScaling: (_g = importedState.useAnnotativeScaling) !== null && _g !== void 0 ? _g : defaults.useAnnotativeScaling, displayPrecision: {
221
+ const linearPrecision = isValidFinitePositiveByteValue((_a = importedState === null || importedState === void 0 ? void 0 : importedState.displayPrecision) === null || _a === void 0 ? void 0 : _a.linear, defaults.displayPrecision.linear);
222
+ return Object.assign(Object.assign({}, defaults), { name: (_b = importedState === null || importedState === void 0 ? void 0 : importedState.name) !== null && _b !== void 0 ? _b : defaults.name, viewBackgroundColor: (_c = importedState === null || importedState === void 0 ? void 0 : importedState.viewBackgroundColor) !== null && _c !== void 0 ? _c : defaults.viewBackgroundColor, mainScope: (_d = isValidAppStateScopeValue(importedState === null || importedState === void 0 ? void 0 : importedState.mainScope)) !== null && _d !== void 0 ? _d : defaults.mainScope, scopeExponentThreshold: isValidAppStateScopeExponentThresholdValue(importedState === null || importedState === void 0 ? void 0 : importedState.scopeExponentThreshold, defaults.scopeExponentThreshold), dashSpacingScale: (_e = importedState === null || importedState === void 0 ? void 0 : importedState.dashSpacingScale) !== null && _e !== void 0 ? _e : defaults.dashSpacingScale, isDashSpacingAffectedByViewportScale: (_f = importedState === null || importedState === void 0 ? void 0 : importedState.isDashSpacingAffectedByViewportScale) !== null && _f !== void 0 ? _f : defaults.isDashSpacingAffectedByViewportScale, dimensionsAssociativeByDefault: (_g = importedState === null || importedState === void 0 ? void 0 : importedState.dimensionsAssociativeByDefault) !== null && _g !== void 0 ? _g : defaults.dimensionsAssociativeByDefault, useAnnotativeScaling: (_h = importedState === null || importedState === void 0 ? void 0 : importedState.useAnnotativeScaling) !== null && _h !== void 0 ? _h : defaults.useAnnotativeScaling, displayPrecision: {
218
223
  linear: linearPrecision,
219
- angular: (_j = (_h = importedState.displayPrecision) === null || _h === void 0 ? void 0 : _h.angular) !== null && _j !== void 0 ? _j : defaults.displayPrecision.angular,
220
- }, pruningLevel: importedState.pruningLevel &&
224
+ angular: (_k = (_j = importedState === null || importedState === void 0 ? void 0 : importedState.displayPrecision) === null || _j === void 0 ? void 0 : _j.angular) !== null && _k !== void 0 ? _k : defaults.displayPrecision.angular,
225
+ }, pruningLevel: (importedState === null || importedState === void 0 ? void 0 : importedState.pruningLevel) &&
221
226
  Object.values(PRUNING_LEVEL).includes(importedState.pruningLevel)
222
227
  ? importedState.pruningLevel
223
228
  : PRUNING_LEVEL.BALANCED });
@@ -231,16 +236,18 @@ export const restoreGlobalState = (importedState = {}) => {
231
236
  * @param restoredGlobalState - The complete and valid global state for the document.
232
237
  * @returns A complete and valid DucLocalState object.
233
238
  */
234
- export const restoreLocalState = (importedState = {}, restoredGlobalState, restoredStandards) => {
239
+ export const restoreLocalState = (importedState = {}, restoredGlobalState, restoredStandards, forceScope) => {
235
240
  var _a, _b, _c, _d, _e, _f, _g, _h;
236
241
  const defaults = getDefaultLocalState();
237
- const zoom = getZoom((_b = (_a = importedState.zoom) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : defaults.zoom.value, restoredGlobalState.mainScope, restoredGlobalState.scopeExponentThreshold);
238
- const scope = isValidPrecisionScopeValue(zoom.value, restoredGlobalState.mainScope, restoredGlobalState.scopeExponentThreshold);
239
- return Object.assign(Object.assign(Object.assign({}, defaults), importedState), { scope, activeStandardId: isValidStandardId(importedState.activeStandardId, restoredStandards, defaults.activeStandardId), isBindingEnabled: isValidBoolean(importedState.isBindingEnabled, defaults.isBindingEnabled), penMode: isValidBoolean(importedState.penMode, defaults.penMode), scrollX: importedState.scrollX
242
+ const zoom = getZoom((_b = (_a = importedState === null || importedState === void 0 ? void 0 : importedState.zoom) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : defaults.zoom.value, restoredGlobalState.mainScope, restoredGlobalState.scopeExponentThreshold);
243
+ const scope = forceScope
244
+ ? isValidScopeValue(forceScope)
245
+ : isValidPrecisionScopeValue(zoom.value, restoredGlobalState.mainScope, restoredGlobalState.scopeExponentThreshold);
246
+ return Object.assign(Object.assign(Object.assign({}, defaults), importedState), { scope, activeStandardId: isValidStandardId(importedState === null || importedState === void 0 ? void 0 : importedState.activeStandardId, restoredStandards, defaults.activeStandardId), isBindingEnabled: isValidBoolean(importedState === null || importedState === void 0 ? void 0 : importedState.isBindingEnabled, defaults.isBindingEnabled), penMode: isValidBoolean(importedState === null || importedState === void 0 ? void 0 : importedState.penMode, defaults.penMode), scrollX: (importedState === null || importedState === void 0 ? void 0 : importedState.scrollX)
240
247
  ? restorePrecisionValue(importedState.scrollX, NEUTRAL_SCOPE, scope)
241
- : getPrecisionValueFromRaw(defaults.scrollX.value, NEUTRAL_SCOPE, scope), scrollY: importedState.scrollY
248
+ : getPrecisionValueFromRaw(defaults.scrollX.value, NEUTRAL_SCOPE, scope), scrollY: (importedState === null || importedState === void 0 ? void 0 : importedState.scrollY)
242
249
  ? restorePrecisionValue(importedState.scrollY, NEUTRAL_SCOPE, scope)
243
- : getPrecisionValueFromRaw(defaults.scrollY.value, NEUTRAL_SCOPE, scope), zoom, activeGridSettings: (_c = importedState.activeGridSettings) !== null && _c !== void 0 ? _c : defaults.activeGridSettings, activeSnapSettings: (_d = importedState.activeSnapSettings) !== null && _d !== void 0 ? _d : defaults.activeSnapSettings, currentItemStroke: (_e = validateStroke(importedState.currentItemStroke, scope, scope)) !== null && _e !== void 0 ? _e : defaults.currentItemStroke, currentItemBackground: (_f = validateBackground(importedState.currentItemBackground)) !== null && _f !== void 0 ? _f : defaults.currentItemBackground, currentItemOpacity: isValidPercentageValue(importedState.currentItemOpacity, defaults.currentItemOpacity), currentItemStartLineHead: (_g = isValidLineHeadValue(importedState.currentItemStartLineHead)) !== null && _g !== void 0 ? _g : defaults.currentItemStartLineHead, currentItemEndLineHead: (_h = isValidLineHeadValue(importedState.currentItemEndLineHead)) !== null && _h !== void 0 ? _h : defaults.currentItemEndLineHead });
250
+ : getPrecisionValueFromRaw(defaults.scrollY.value, NEUTRAL_SCOPE, scope), zoom, activeGridSettings: (_c = importedState === null || importedState === void 0 ? void 0 : importedState.activeGridSettings) !== null && _c !== void 0 ? _c : defaults.activeGridSettings, activeSnapSettings: (_d = importedState === null || importedState === void 0 ? void 0 : importedState.activeSnapSettings) !== null && _d !== void 0 ? _d : defaults.activeSnapSettings, currentItemStroke: (_e = validateStroke(importedState === null || importedState === void 0 ? void 0 : importedState.currentItemStroke, scope, scope)) !== null && _e !== void 0 ? _e : defaults.currentItemStroke, currentItemBackground: (_f = validateBackground(importedState === null || importedState === void 0 ? void 0 : importedState.currentItemBackground)) !== null && _f !== void 0 ? _f : defaults.currentItemBackground, currentItemOpacity: isValidPercentageValue(importedState === null || importedState === void 0 ? void 0 : importedState.currentItemOpacity, defaults.currentItemOpacity), currentItemStartLineHead: (_g = isValidLineHeadValue(importedState === null || importedState === void 0 ? void 0 : importedState.currentItemStartLineHead)) !== null && _g !== void 0 ? _g : defaults.currentItemStartLineHead, currentItemEndLineHead: (_h = isValidLineHeadValue(importedState === null || importedState === void 0 ? void 0 : importedState.currentItemEndLineHead)) !== null && _h !== void 0 ? _h : defaults.currentItemEndLineHead });
244
251
  };
245
252
  export const restoreVersionGraph = (importedGraph) => {
246
253
  if (!importedGraph || typeof importedGraph !== "object") {
@@ -1258,17 +1258,24 @@ const restoreFcfDatumDefinition = (def, elementScope, currentScope, restoredBloc
1258
1258
  const restoreTextStyle = (style, currentScope) => {
1259
1259
  var _a, _b, _c;
1260
1260
  const defaultLineHeight = 1.15;
1261
- return Object.assign(Object.assign(Object.assign({}, ((style === null || style === void 0 ? void 0 : style.background)
1262
- ? { background: style.background.map(validateBackground) }
1263
- : { background: [DEFAULT_ELEMENT_PROPS.background] })), ((style === null || style === void 0 ? void 0 : style.stroke)
1264
- ? {
1265
- stroke: style.stroke.map((s) => validateStroke(s, NEUTRAL_SCOPE, currentScope)),
1266
- }
1267
- : { stroke: [DEFAULT_ELEMENT_PROPS.stroke] })), { roundness: restorePrecisionValue(style === null || style === void 0 ? void 0 : style.roundness, NEUTRAL_SCOPE, currentScope, DEFAULT_ELEMENT_PROPS.roundness.value), opacity: isValidPercentageValue(style === null || style === void 0 ? void 0 : style.opacity, DEFAULT_ELEMENT_PROPS.opacity), blending: isValidBlendingValue(style === null || style === void 0 ? void 0 : style.blending),
1261
+ return {
1268
1262
  // Text-specific styles
1269
- isLtr: isValidBoolean(style === null || style === void 0 ? void 0 : style.isLtr, true), fontFamily: getFontFamilyByName(style === null || style === void 0 ? void 0 : style.fontFamily), bigFontFamily: isValidString(style === null || style === void 0 ? void 0 : style.bigFontFamily, "sans-serif"), textAlign: isValidTextAlignValue(style === null || style === void 0 ? void 0 : style.textAlign), verticalAlign: isValidVerticalAlignValue(style === null || style === void 0 ? void 0 : style.verticalAlign), lineHeight: (_a = style === null || style === void 0 ? void 0 : style.lineHeight) !== null && _a !== void 0 ? _a : defaultLineHeight, lineSpacing: restoreLineSpacing(style === null || style === void 0 ? void 0 : style.lineSpacing, (_b = style === null || style === void 0 ? void 0 : style.lineHeight) !== null && _b !== void 0 ? _b : defaultLineHeight.valueOf(), currentScope), obliqueAngle: isValidRadianValue(style === null || style === void 0 ? void 0 : style.obliqueAngle, 0), fontSize: restorePrecisionValue(style === null || style === void 0 ? void 0 : style.fontSize, NEUTRAL_SCOPE, currentScope, DEFAULT_FONT_SIZE), paperTextHeight: (style === null || style === void 0 ? void 0 : style.paperTextHeight)
1263
+ isLtr: isValidBoolean(style === null || style === void 0 ? void 0 : style.isLtr, true),
1264
+ fontFamily: getFontFamilyByName(style === null || style === void 0 ? void 0 : style.fontFamily),
1265
+ bigFontFamily: isValidString(style === null || style === void 0 ? void 0 : style.bigFontFamily, "sans-serif"),
1266
+ textAlign: isValidTextAlignValue(style === null || style === void 0 ? void 0 : style.textAlign),
1267
+ verticalAlign: isValidVerticalAlignValue(style === null || style === void 0 ? void 0 : style.verticalAlign),
1268
+ lineHeight: (_a = style === null || style === void 0 ? void 0 : style.lineHeight) !== null && _a !== void 0 ? _a : defaultLineHeight,
1269
+ lineSpacing: restoreLineSpacing(style === null || style === void 0 ? void 0 : style.lineSpacing, (_b = style === null || style === void 0 ? void 0 : style.lineHeight) !== null && _b !== void 0 ? _b : defaultLineHeight.valueOf(), currentScope),
1270
+ obliqueAngle: isValidRadianValue(style === null || style === void 0 ? void 0 : style.obliqueAngle, 0),
1271
+ fontSize: restorePrecisionValue(style === null || style === void 0 ? void 0 : style.fontSize, NEUTRAL_SCOPE, currentScope, DEFAULT_FONT_SIZE),
1272
+ paperTextHeight: (style === null || style === void 0 ? void 0 : style.paperTextHeight)
1270
1273
  ? restorePrecisionValue(style.paperTextHeight, NEUTRAL_SCOPE, currentScope)
1271
- : undefined, widthFactor: (_c = style === null || style === void 0 ? void 0 : style.widthFactor) !== null && _c !== void 0 ? _c : 1, isUpsideDown: isValidBoolean(style === null || style === void 0 ? void 0 : style.isUpsideDown, false), isBackwards: isValidBoolean(style === null || style === void 0 ? void 0 : style.isBackwards, false) });
1274
+ : undefined,
1275
+ widthFactor: (_c = style === null || style === void 0 ? void 0 : style.widthFactor) !== null && _c !== void 0 ? _c : 1,
1276
+ isUpsideDown: isValidBoolean(style === null || style === void 0 ? void 0 : style.isUpsideDown, false),
1277
+ isBackwards: isValidBoolean(style === null || style === void 0 ? void 0 : style.isBackwards, false),
1278
+ };
1272
1279
  };
1273
1280
  const restoreHeadsOverride = (heads, restoredBlocks, elementScope, currentScope) => {
1274
1281
  if (!Array.isArray(heads) || heads.length !== 2)
@@ -1,3 +1,4 @@
1
1
  import { ImportedDataState } from "./types";
2
+ import { RestoreConfig } from "./restore";
2
3
  export declare const DUC_SCHEMA_VERSION: any;
3
- export declare const serializeDuc: (data: ImportedDataState, useScopedValues?: boolean, passThroughElementIds?: string[]) => Promise<Uint8Array>;
4
+ export declare const serializeDuc: (data: ImportedDataState, useScopedValues?: boolean, passThroughElementIds?: string[], restoreConfig?: RestoreConfig) => Promise<Uint8Array>;
package/dist/serialize.js CHANGED
@@ -16,8 +16,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
16
16
  cast to number at the final write site (e.g. pv.value).
17
17
  - Keep args strongly typed. Never use any for function args.
18
18
  */
19
- import * as Duc from "./flatbuffers/duc";
20
19
  import * as flatbuffers from "flatbuffers";
20
+ import * as Duc from "./flatbuffers/duc";
21
21
  import { restore } from "./restore";
22
22
  import { encodeFunctionString, EXPORT_DATA_TYPES } from "./utils";
23
23
  /**
@@ -584,13 +584,10 @@ function writeLineSpacing(b, ls, usv) {
584
584
  return Duc.LineSpacing.endLineSpacing(b);
585
585
  }
586
586
  function writeTextStyle(b, s, usv) {
587
- const base = writeStylesBase(b, s, usv);
588
587
  const lineSpacing = writeLineSpacing(b, s.lineSpacing, usv);
589
588
  const fontFamily = str(b, s.fontFamily.toString());
590
589
  const bigFont = str(b, s.bigFontFamily);
591
590
  Duc.DucTextStyle.startDucTextStyle(b);
592
- if (base)
593
- Duc.DucTextStyle.addBaseStyle(b, base);
594
591
  Duc.DucTextStyle.addIsLtr(b, s.isLtr);
595
592
  if (fontFamily)
596
593
  Duc.DucTextStyle.addFontFamily(b, fontFamily);
@@ -879,11 +876,8 @@ function writePlotLayout(b, l, usv) {
879
876
  }
880
877
  function writePlot(b, e, usv) {
881
878
  const stackBase = writeStackElementBase(b, e, usv);
882
- const baseStyle = writeStylesBase(b, e, usv);
883
879
  const plotStyle = (() => {
884
880
  Duc.DucPlotStyle.startDucPlotStyle(b);
885
- if (baseStyle)
886
- Duc.DucPlotStyle.addBaseStyle(b, baseStyle);
887
881
  return Duc.DucPlotStyle.endDucPlotStyle(b);
888
882
  })();
889
883
  const layout = writePlotLayout(b, e.layout, usv);
@@ -910,10 +904,7 @@ function writeView(b, v, usv) {
910
904
  return Duc.DucView.endDucView(b);
911
905
  }
912
906
  function writeViewportStyle(b, s, usv) {
913
- const base = writeStylesBase(b, s, usv);
914
907
  Duc.DucViewportStyle.startDucViewportStyle(b);
915
- if (base)
916
- Duc.DucViewportStyle.addBaseStyle(b, base);
917
908
  Duc.DucViewportStyle.addScaleIndicatorVisible(b, s.scaleIndicatorVisible);
918
909
  return Duc.DucViewportStyle.endDucViewportStyle(b);
919
910
  }
@@ -940,11 +931,8 @@ function writeViewport(b, e, usv) {
940
931
  return Duc.DucViewportElement.endDucViewportElement(b);
941
932
  }
942
933
  function writeXRayStyle(b, s, usv) {
943
- const base = writeStylesBase(b, s, usv);
944
934
  const color = b.createString(s.color);
945
935
  Duc.DucXRayStyle.startDucXRayStyle(b);
946
- if (base)
947
- Duc.DucXRayStyle.addBaseStyle(b, base);
948
936
  Duc.DucXRayStyle.addColor(b, color);
949
937
  return Duc.DucXRayStyle.endDucXRayStyle(b);
950
938
  }
@@ -999,12 +987,9 @@ function writeLeaderContent(b, c, usv) {
999
987
  return Duc.LeaderContent.endLeaderContent(b);
1000
988
  }
1001
989
  function writeLeaderStyle(b, s, usv) {
1002
- const base = writeStylesBase(b, s, usv);
1003
990
  const text = writeTextStyle(b, s.textStyle, usv);
1004
991
  const heads = s.headsOverride ? Duc.DucLeaderStyle.createHeadsOverrideVector(b, s.headsOverride.map((h) => writeHead(b, h, usv))) : undefined;
1005
992
  Duc.DucLeaderStyle.startDucLeaderStyle(b);
1006
- if (base)
1007
- Duc.DucLeaderStyle.addBaseStyle(b, base);
1008
993
  if (heads)
1009
994
  Duc.DucLeaderStyle.addHeadsOverride(b, heads);
1010
995
  if (s.dogleg !== undefined)
@@ -1249,7 +1234,6 @@ function writeFcfDatumDefinition(b, d, usv) {
1249
1234
  return Duc.FCFDatumDefinition.endFCFDatumDefinition(b);
1250
1235
  }
1251
1236
  function writeFcfStyle(b, s, usv) {
1252
- const base = writeStylesBase(b, s, usv);
1253
1237
  const text = writeTextStyle(b, s.textStyle, usv);
1254
1238
  const layout = (() => {
1255
1239
  Duc.FCFLayoutStyle.startFCFLayoutStyle(b);
@@ -1269,8 +1253,6 @@ function writeFcfStyle(b, s, usv) {
1269
1253
  return Duc.FCFDatumStyle.endFCFDatumStyle(b);
1270
1254
  })();
1271
1255
  Duc.DucFeatureControlFrameStyle.startDucFeatureControlFrameStyle(b);
1272
- if (base)
1273
- Duc.DucFeatureControlFrameStyle.addBaseStyle(b, base);
1274
1256
  Duc.DucFeatureControlFrameStyle.addTextStyle(b, text);
1275
1257
  Duc.DucFeatureControlFrameStyle.addLayout(b, layout);
1276
1258
  Duc.DucFeatureControlFrameStyle.addSymbols(b, sym);
@@ -1386,21 +1368,19 @@ function writeTableCellStyle(b, s, usv) {
1386
1368
  Duc.Margins.addLeft(b, getPrecisionValue(s.margins.left, usv));
1387
1369
  const margins = Duc.Margins.endMargins(b);
1388
1370
  Duc.DucTableCellStyle.startDucTableCellStyle(b);
1389
- if (base)
1371
+ if (base) {
1390
1372
  Duc.DucTableCellStyle.addBaseStyle(b, base);
1373
+ }
1391
1374
  Duc.DucTableCellStyle.addTextStyle(b, text);
1392
1375
  Duc.DucTableCellStyle.addMargins(b, margins);
1393
1376
  Duc.DucTableCellStyle.addAlignment(b, s.alignment);
1394
1377
  return Duc.DucTableCellStyle.endDucTableCellStyle(b);
1395
1378
  }
1396
1379
  function writeTableStyle(b, s, usv) {
1397
- const base = writeStylesBase(b, s, usv);
1398
1380
  const header = writeTableCellStyle(b, s.headerRowStyle, usv);
1399
1381
  const dataRow = writeTableCellStyle(b, s.dataRowStyle, usv);
1400
1382
  const dataCol = writeTableCellStyle(b, s.dataColumnStyle, usv);
1401
1383
  Duc.DucTableStyle.startDucTableStyle(b);
1402
- if (base)
1403
- Duc.DucTableStyle.addBaseStyle(b, base);
1404
1384
  Duc.DucTableStyle.addFlowDirection(b, s.flowDirection);
1405
1385
  Duc.DucTableStyle.addHeaderRowStyle(b, header);
1406
1386
  Duc.DucTableStyle.addDataRowStyle(b, dataRow);
@@ -2369,13 +2349,13 @@ function serializeExternalFiles(builder, files, usv) {
2369
2349
  export const DUC_SCHEMA_VERSION = (typeof process !== "undefined" && process.env && process.env.DUC_SCHEMA_VERSION) ||
2370
2350
  (typeof import.meta !== "undefined" && import.meta.env && import.meta.env.DUC_SCHEMA_VERSION) ||
2371
2351
  "0.0.0";
2372
- export const serializeDuc = (data_1, ...args_1) => __awaiter(void 0, [data_1, ...args_1], void 0, function* (data, useScopedValues = false, passThroughElementIds = []) {
2352
+ export const serializeDuc = (data_1, ...args_1) => __awaiter(void 0, [data_1, ...args_1], void 0, function* (data, useScopedValues = false, passThroughElementIds = [], restoreConfig = {}) {
2373
2353
  const builder = new flatbuffers.Builder(1024);
2374
2354
  const sanitized = restore(data, {
2375
2355
  refreshDimensions: false,
2376
2356
  syncInvalidIndices: (elements) => elements,
2377
2357
  passThroughElementIds
2378
- });
2358
+ }, restoreConfig);
2379
2359
  const typeOffset = builder.createString(EXPORT_DATA_TYPES.duc);
2380
2360
  const sourceOffset = builder.createString(typeof window !== "undefined" ? window.location.origin : "unknown");
2381
2361
  const versionOffset = builder.createString(DUC_SCHEMA_VERSION);
@@ -2422,6 +2402,10 @@ export const serializeDuc = (data_1, ...args_1) => __awaiter(void 0, [data_1, ..
2422
2402
  const thumbnailOffset = sanitized.thumbnail
2423
2403
  ? builder.createByteVector(sanitized.thumbnail)
2424
2404
  : null;
2405
+ // Serialize id (as string if present)
2406
+ const idOffset = sanitized.id
2407
+ ? builder.createString(sanitized.id)
2408
+ : null;
2425
2409
  Duc.ExportedDataState.startExportedDataState(builder);
2426
2410
  Duc.ExportedDataState.addType(builder, typeOffset);
2427
2411
  Duc.ExportedDataState.addVersion(builder, versionOffset);
@@ -2458,6 +2442,9 @@ export const serializeDuc = (data_1, ...args_1) => __awaiter(void 0, [data_1, ..
2458
2442
  if (thumbnailOffset) {
2459
2443
  Duc.ExportedDataState.addThumbnail(builder, thumbnailOffset);
2460
2444
  }
2445
+ if (idOffset) {
2446
+ Duc.ExportedDataState.addId(builder, idOffset);
2447
+ }
2461
2448
  const exportedDataStateOffset = Duc.ExportedDataState.endExportedDataState(builder);
2462
2449
  builder.finish(exportedDataStateOffset, "DUC_");
2463
2450
  return builder.asUint8Array();
@@ -341,7 +341,7 @@ export type DucTableCellStyle = _DucElementStylesBase & {
341
341
  * It sets the defaults for rows, columns, and cells, which can be
342
342
  * individually overridden.
343
343
  */
344
- export type DucTableStyle = _DucElementStylesBase & {
344
+ export type DucTableStyle = {
345
345
  /** The direction in which new rows are added */
346
346
  flowDirection: TableFlowDirection;
347
347
  /** Default style for the header row(s) */
@@ -453,7 +453,7 @@ export type TextAlign = ValueOf<typeof TEXT_ALIGN>;
453
453
  export type VerticalAlign = ValueOf<typeof VERTICAL_ALIGN>;
454
454
  export type LineSpacingType = ValueOf<typeof LINE_SPACING_TYPE>;
455
455
  export type TextFieldSourceProperty = ValueOf<typeof TEXT_FIELD_SOURCE_PROPERTY>;
456
- export type DucTextStyle = _DucElementStylesBase & {
456
+ export type DucTextStyle = {
457
457
  /**
458
458
  * Whether the text is left-to-right or right-to-left
459
459
  * @default true
@@ -845,7 +845,7 @@ export type ViewportShadePlot = ValueOf<typeof VIEWPORT_SHADE_PLOT>;
845
845
  * This is the style for the viewport element
846
846
  * Grid settings, UCS, Snapping and more can be overridden through the overrideStandard property from the _DucStackElementBase
847
847
  */
848
- export type DucViewportStyle = _DucElementStylesBase & {
848
+ export type DucViewportStyle = {
849
849
  scaleIndicatorVisible: boolean;
850
850
  };
851
851
  export type DucViewportElement = _DucLinearElementBase & _DucStackBase & DucViewportStyle & {
@@ -873,7 +873,7 @@ export type PlotLayout = {
873
873
  left: PrecisionValue;
874
874
  };
875
875
  };
876
- export type DucPlotStyle = _DucElementStylesBase & {};
876
+ export type DucPlotStyle = {};
877
877
  /**
878
878
  * A DucPlotElement represents a finite layout or "paper space" within the infinite canvas.
879
879
  * It serves as a container for viewports and other annotations, defining the final
@@ -885,7 +885,7 @@ export type DucPlotElement = _DucStackElementBase & DucPlotStyle & {
885
885
  /** The layout definition for this plot, including paper size and margins. */
886
886
  layout: PlotLayout;
887
887
  };
888
- export type DucXRayStyle = _DucElementStylesBase & {
888
+ export type DucXRayStyle = {
889
889
  /**
890
890
  * The color of the x-ray
891
891
  */
@@ -906,7 +906,7 @@ export type BlockAttachment = ValueOf<typeof BLOCK_ATTACHMENT>;
906
906
  /**
907
907
  * Defines the visual appearance and behavior of a leader.
908
908
  */
909
- export type DucLeaderStyle = _DucElementStylesBase & {
909
+ export type DucLeaderStyle = {
910
910
  /**
911
911
  * Override the heads of the leader
912
912
  * The tuple represents [startHead, endHead]
@@ -1161,7 +1161,7 @@ export type FeatureControlFrameSegment = {
1161
1161
  * Defines the visual appearance of a Feature Control Frame.
1162
1162
  * This can be stored in a style library and reused.
1163
1163
  */
1164
- export type DucFeatureControlFrameStyle = _DucElementStylesBase & {
1164
+ export type DucFeatureControlFrameStyle = {
1165
1165
  /** The base text style for numbers and letters within the frame */
1166
1166
  textStyle: DucTextStyle;
1167
1167
  /** Layout and spacing properties */
@@ -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, DucTableElement, DucPointBinding, DucTextContainer, DucTextElement, DucTextElementWithContainer, FixedPointBinding, InitializedDucImageElement, DucNonSelectionElement, DucEllipseElement, DucPolygonElement, DucBlockInstanceElement, NonDeleted, DucIframeLikeElement } from "./";
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, DucBlockInstanceElement, 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;
@@ -9,6 +9,7 @@ export declare const isTableElement: (element: DucElement | null) => element is
9
9
  export declare const isIframeLikeElement: (element: DucElement | null) => element is DucIframeLikeElement;
10
10
  export declare const isTextElement: (element: DucElement | null) => element is DucTextElement;
11
11
  export declare const isFrameElement: (element: DucElement | null) => element is DucFrameElement;
12
+ export declare const isPlotElement: (element: DucElement | null) => element is DucPlotElement;
12
13
  export declare const isFrameLikeElement: (element: DucElement | null) => element is DucFrameLikeElement;
13
14
  export declare const isFreeDrawElement: (element?: DucElement | null) => element is DucFreeDrawElement;
14
15
  export declare const isEllipseElement: (element?: DucElement | null) => element is DucEllipseElement;
@@ -22,9 +22,12 @@ export const isTextElement = (element) => {
22
22
  export const isFrameElement = (element) => {
23
23
  return element != null && element.type === "frame";
24
24
  };
25
+ export const isPlotElement = (element) => {
26
+ return element != null && element.type === "plot";
27
+ };
25
28
  export const isFrameLikeElement = (element) => {
26
29
  return (element != null &&
27
- (element.type === "frame"));
30
+ (element.type === "frame" || element.type === "plot"));
28
31
  };
29
32
  export const isFreeDrawElement = (element) => {
30
33
  return element != null && isFreeDrawElementType(element.type);
@@ -1,6 +1,7 @@
1
1
  export * from "./elements";
2
2
  export * from "./geometryTypes";
3
3
  export * from "./utility-types";
4
+ export * from "./typeChecks";
4
5
  import { OBJECT_SNAP_MODE, PRUNING_LEVEL } from "../flatbuffers/duc";
5
6
  import { SupportedMeasures } from "../technical/scopes";
6
7
  import { Standard } from "../technical/standards";
@@ -30,6 +31,8 @@ export interface ExportedDataState {
30
31
  files: DucExternalFiles | undefined;
31
32
  /** In case it is needed to embed the version control into the file format */
32
33
  versionGraph: VersionGraph | undefined;
34
+ /** Actual file id */
35
+ id: string | undefined;
33
36
  }
34
37
  export type ExportedDataStateContent = Omit<ExportedDataState, "type" | "version" | "source">;
35
38
  /**
@@ -106,7 +109,7 @@ export type SuggestedPointBinding = [
106
109
  "start" | "end" | "both",
107
110
  NonDeleted<DucBindableElement>
108
111
  ];
109
- export type ToolType = "selection" | "rectangle" | "polygon" | "ellipse" | "line" | "freedraw" | "text" | "image" | "eraser" | "hand" | "frame" | "embeddable" | "ruler" | "lasso" | "laser" | "table";
112
+ export type ToolType = "selection" | "rectangle" | "polygon" | "ellipse" | "line" | "freedraw" | "text" | "image" | "eraser" | "hand" | "frame" | "plot" | "embeddable" | "ruler" | "lasso" | "laser" | "table";
110
113
  export type ElementOrToolType = DucElementType | ToolType | "custom";
111
114
  /**
112
115
  * Defines the global, persistent settings for the drawing. These are fundamental
@@ -1,3 +1,4 @@
1
1
  export * from "./elements";
2
2
  export * from "./geometryTypes";
3
3
  export * from "./utility-types";
4
+ export * from "./typeChecks";
@@ -0,0 +1,5 @@
1
+ import { PrecisionValue } from ".";
2
+ /**
3
+ * Type guard to check if an object is a PrecisionValue
4
+ */
5
+ export declare const isPrecisionValue: (obj: any) => obj is PrecisionValue;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Type guard to check if an object is a PrecisionValue
3
+ */
4
+ export const isPrecisionValue = (obj) => {
5
+ return obj !== null &&
6
+ typeof obj === 'object' &&
7
+ typeof obj.value === 'number' &&
8
+ typeof obj.scoped === 'number' &&
9
+ Object.keys(obj).length === 2;
10
+ };
@@ -47,6 +47,8 @@ export declare const MIME_TYPES: {
47
47
  readonly "excalidraw.svg": "image/svg+xml";
48
48
  readonly "excalidraw.png": "image/png";
49
49
  readonly binary: "application/octet-stream";
50
+ readonly pdf: "application/pdf";
51
+ readonly zip: "application/zip";
50
52
  };
51
53
  export declare const EXPORT_IMAGE_TYPES: {
52
54
  readonly png: "png";
@@ -37,9 +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",
41
- // binary
42
- binary: "application/octet-stream" }, IMAGE_MIME_TYPES);
40
+ "excalidraw.svg": "image/svg+xml", "excalidraw.png": "image/png", binary: "application/octet-stream", pdf: "application/pdf", zip: "application/zip" }, IMAGE_MIME_TYPES);
43
41
  export const EXPORT_IMAGE_TYPES = {
44
42
  png: "png",
45
43
  svg: "svg",
@@ -1,4 +1,5 @@
1
1
  import { DucElement, DucElementsIncludingDeleted, DucFrameLikeElement, ElementsMap } from "../../types/elements";
2
2
  export declare const getContainingFrame: (element: DucElement, elementsMap: ElementsMap) => DucFrameLikeElement | null;
3
3
  export declare const getFrameLikeElements: (allElements: DucElementsIncludingDeleted) => DucFrameLikeElement[];
4
+ export declare const canFrameLikeContainElement: (frame: DucFrameLikeElement, element: DucElement) => boolean;
4
5
  export declare const getFrameLikeTitle: (element: DucFrameLikeElement) => string;
@@ -1,4 +1,4 @@
1
- import { isFrameLikeElement } from "../../types/elements/typeChecks";
1
+ import { isFrameElement, isFrameLikeElement, isPlotElement } from "../../types/elements/typeChecks";
2
2
  export const getContainingFrame = (element, elementsMap) => {
3
3
  if (!element.frameId) {
4
4
  return null;
@@ -9,6 +9,18 @@ export const getContainingFrame = (element, elementsMap) => {
9
9
  export const getFrameLikeElements = (allElements) => {
10
10
  return allElements.filter((element) => isFrameLikeElement(element));
11
11
  };
12
+ export const canFrameLikeContainElement = (frame, element) => {
13
+ if (frame.id === element.id) {
14
+ return false;
15
+ }
16
+ if (isPlotElement(element)) {
17
+ return false;
18
+ }
19
+ if (isFrameElement(element)) {
20
+ return frame.type === "plot";
21
+ }
22
+ return true;
23
+ };
12
24
  export const getFrameLikeTitle = (element) => {
13
25
  return element.label === null
14
26
  ? "Frame"
@@ -15,13 +15,6 @@ import { getPrecisionValueFromRaw } from "../../technical/scopes";
15
15
  */
16
16
  export function getDefaultTextStyle(currentScope) {
17
17
  return {
18
- roundness: DEFAULT_ELEMENT_PROPS.roundness,
19
- blending: undefined,
20
- strokeColor: undefined,
21
- backgroundColor: undefined,
22
- background: [DEFAULT_ELEMENT_PROPS.background],
23
- stroke: [DEFAULT_ELEMENT_PROPS.stroke],
24
- opacity: DEFAULT_ELEMENT_PROPS.opacity,
25
18
  isLtr: true,
26
19
  fontFamily: DEFAULT_FONT_FAMILY,
27
20
  bigFontFamily: "sans-serif",
@@ -83,7 +76,12 @@ export const getDefaultTableData = (currentScope) => {
83
76
  // A practical starting column width
84
77
  const defaultColumnWidth = getPrecisionValueFromRaw(140, currentScope, currentScope);
85
78
  // Base/default styling for cells
86
- const baseCellStyle = Object.assign(Object.assign({}, DEFAULT_ELEMENT_PROPS), { background: [DEFAULT_ELEMENT_PROPS.background], stroke: [DEFAULT_ELEMENT_PROPS.stroke], textStyle: {
79
+ const baseCellStyle = {
80
+ stroke: [DEFAULT_ELEMENT_PROPS.stroke],
81
+ background: [DEFAULT_ELEMENT_PROPS.background],
82
+ roundness: DEFAULT_ELEMENT_PROPS.roundness,
83
+ opacity: DEFAULT_ELEMENT_PROPS.opacity,
84
+ textStyle: {
87
85
  isLtr: true,
88
86
  fontFamily: FONT_FAMILY.Virgil,
89
87
  bigFontFamily: "sans-serif",
@@ -97,18 +95,16 @@ export const getDefaultTableData = (currentScope) => {
97
95
  widthFactor: 1,
98
96
  isUpsideDown: false,
99
97
  isBackwards: false,
100
- roundness: DEFAULT_ELEMENT_PROPS.roundness,
101
- background: [DEFAULT_ELEMENT_PROPS.background],
102
- stroke: [DEFAULT_ELEMENT_PROPS.stroke],
103
- opacity: DEFAULT_ELEMENT_PROPS.opacity,
104
- }, margins: {
98
+ },
99
+ margins: {
105
100
  top: vMargin,
106
101
  right: hMargin,
107
102
  bottom: vMargin,
108
103
  left: hMargin,
109
- },
104
+ },
110
105
  // Left + middle is a great general-purpose default for tables
111
- alignment: TABLE_CELL_ALIGNMENT.MIDDLE_LEFT });
106
+ alignment: TABLE_CELL_ALIGNMENT.MIDDLE_LEFT,
107
+ };
112
108
  // Create default columns
113
109
  const columns = Object.fromEntries(columnIds.map((id) => [id, { id, width: defaultColumnWidth }]));
114
110
  // Create default rows (taller header row)
@@ -1,5 +1,5 @@
1
1
  import { Scope } from "../../types";
2
- import { DucArrowElement, DucDimensionElement, DucDocElement, DucElement, DucEllipseElement, DucEmbeddableElement, DucFeatureControlFrameElement, DucFrameElement, DucFreeDrawElement, DucGenericElement, DucImageElement, DucLeaderElement, DucLinearElement, DucMermaidElement, DucParametricElement, DucPdfElement, DucPlotElement, DucPolygonElement, DucTableElement, DucTextElement, DucViewportElement, DucXRayElement, DucBlockInstanceElement, ElementConstructorOpts, ElementUpdate, NonDeleted } from "../../types/elements";
2
+ import { DucArrowElement, DucBlockInstanceElement, 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 */