ducjs 2.3.0 → 3.0.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 (529) hide show
  1. package/README.md +2 -2
  2. package/dist/enums.d.ts +135 -0
  3. package/dist/enums.js +155 -0
  4. package/dist/index.d.ts +8 -4
  5. package/dist/index.js +8 -4
  6. package/dist/lazy-files.d.ts +44 -0
  7. package/dist/lazy-files.js +129 -0
  8. package/dist/parse.d.ts +21 -55
  9. package/dist/parse.js +58 -1445
  10. package/dist/restore/index.d.ts +0 -1
  11. package/dist/restore/index.js +0 -1
  12. package/dist/restore/restoreDataState.d.ts +6 -10
  13. package/dist/restore/restoreDataState.js +117 -127
  14. package/dist/restore/restoreElements.d.ts +1 -1
  15. package/dist/restore/restoreElements.js +37 -494
  16. package/dist/serialize.d.ts +11 -4
  17. package/dist/serialize.js +58 -2545
  18. package/dist/technical/index.d.ts +0 -1
  19. package/dist/technical/index.js +0 -1
  20. package/dist/technical/scopes.d.ts +1 -1
  21. package/dist/technical/scopes.js +1 -1
  22. package/dist/transform.d.ts +12 -0
  23. package/dist/transform.js +442 -0
  24. package/dist/types/elements/index.d.ts +120 -693
  25. package/dist/types/elements/typeChecks.d.ts +6 -3
  26. package/dist/types/elements/typeChecks.js +9 -8
  27. package/dist/types/geometryTypes.d.ts +1 -1
  28. package/dist/types/index.d.ts +38 -305
  29. package/dist/utils/constants.d.ts +21 -100
  30. package/dist/utils/constants.js +29 -212
  31. package/dist/utils/elements/freedrawElement.d.ts +6 -0
  32. package/dist/utils/elements/freedrawElement.js +28 -11
  33. package/dist/utils/elements/index.d.ts +3 -14
  34. package/dist/utils/elements/index.js +7 -99
  35. package/dist/utils/elements/linearElement.d.ts +2 -2
  36. package/dist/utils/elements/newElement.d.ts +2 -12
  37. package/dist/utils/elements/newElement.js +32 -52
  38. package/dist/utils/elements/textElement.d.ts +3 -3
  39. package/dist/utils/elements/textElement.js +44 -17
  40. package/dist/utils/math/index.d.ts +5 -4
  41. package/dist/utils/math/index.js +3 -3
  42. package/dist/utils/shape.js +2 -2
  43. package/dist/utils/state/index.d.ts +0 -1
  44. package/dist/utils/state/index.js +5 -71
  45. package/dist/utils/traverse.d.ts +8 -0
  46. package/dist/utils/traverse.js +37 -0
  47. package/dist/version-control.d.ts +61 -0
  48. package/dist/version-control.js +84 -0
  49. package/dist/wasm.d.ts +20 -0
  50. package/dist/wasm.js +52 -0
  51. package/package.json +2 -2
  52. package/dist/flatbuffers/duc/alternate-units.d.ts +0 -21
  53. package/dist/flatbuffers/duc/alternate-units.js +0 -66
  54. package/dist/flatbuffers/duc/angular-unit-system.d.ts +0 -17
  55. package/dist/flatbuffers/duc/angular-unit-system.js +0 -50
  56. package/dist/flatbuffers/duc/angular-units-format.d.ts +0 -7
  57. package/dist/flatbuffers/duc/angular-units-format.js +0 -10
  58. package/dist/flatbuffers/duc/axis.d.ts +0 -5
  59. package/dist/flatbuffers/duc/axis.js +0 -8
  60. package/dist/flatbuffers/duc/bezier-mirroring.d.ts +0 -5
  61. package/dist/flatbuffers/duc/bezier-mirroring.js +0 -8
  62. package/dist/flatbuffers/duc/blending.d.ts +0 -9
  63. package/dist/flatbuffers/duc/blending.js +0 -12
  64. package/dist/flatbuffers/duc/block-attachment.d.ts +0 -4
  65. package/dist/flatbuffers/duc/block-attachment.js +0 -7
  66. package/dist/flatbuffers/duc/boolean-operation.d.ts +0 -6
  67. package/dist/flatbuffers/duc/boolean-operation.js +0 -9
  68. package/dist/flatbuffers/duc/bound-element.d.ts +0 -17
  69. package/dist/flatbuffers/duc/bound-element.js +0 -48
  70. package/dist/flatbuffers/duc/checkpoint.d.ts +0 -22
  71. package/dist/flatbuffers/duc/checkpoint.js +0 -75
  72. package/dist/flatbuffers/duc/column-layout.d.ts +0 -22
  73. package/dist/flatbuffers/duc/column-layout.js +0 -72
  74. package/dist/flatbuffers/duc/column-type.d.ts +0 -5
  75. package/dist/flatbuffers/duc/column-type.js +0 -8
  76. package/dist/flatbuffers/duc/custom-hatch-pattern.d.ts +0 -23
  77. package/dist/flatbuffers/duc/custom-hatch-pattern.js +0 -71
  78. package/dist/flatbuffers/duc/datum-bracket-style.d.ts +0 -5
  79. package/dist/flatbuffers/duc/datum-bracket-style.js +0 -8
  80. package/dist/flatbuffers/duc/datum-reference.d.ts +0 -17
  81. package/dist/flatbuffers/duc/datum-reference.js +0 -49
  82. package/dist/flatbuffers/duc/datum-target-type.d.ts +0 -6
  83. package/dist/flatbuffers/duc/datum-target-type.js +0 -9
  84. package/dist/flatbuffers/duc/decimal-separator.d.ts +0 -4
  85. package/dist/flatbuffers/duc/decimal-separator.js +0 -7
  86. package/dist/flatbuffers/duc/delta.d.ts +0 -22
  87. package/dist/flatbuffers/duc/delta.js +0 -75
  88. package/dist/flatbuffers/duc/dictionary-entry.d.ts +0 -17
  89. package/dist/flatbuffers/duc/dictionary-entry.js +0 -49
  90. package/dist/flatbuffers/duc/dimension-baseline-data.d.ts +0 -14
  91. package/dist/flatbuffers/duc/dimension-baseline-data.js +0 -40
  92. package/dist/flatbuffers/duc/dimension-bindings.d.ts +0 -17
  93. package/dist/flatbuffers/duc/dimension-bindings.js +0 -50
  94. package/dist/flatbuffers/duc/dimension-continue-data.d.ts +0 -14
  95. package/dist/flatbuffers/duc/dimension-continue-data.js +0 -40
  96. package/dist/flatbuffers/duc/dimension-definition-points.d.ts +0 -21
  97. package/dist/flatbuffers/duc/dimension-definition-points.js +0 -64
  98. package/dist/flatbuffers/duc/dimension-ext-line-style.d.ts +0 -18
  99. package/dist/flatbuffers/duc/dimension-ext-line-style.js +0 -57
  100. package/dist/flatbuffers/duc/dimension-fit-rule.d.ts +0 -6
  101. package/dist/flatbuffers/duc/dimension-fit-rule.js +0 -9
  102. package/dist/flatbuffers/duc/dimension-fit-style.d.ts +0 -19
  103. package/dist/flatbuffers/duc/dimension-fit-style.js +0 -58
  104. package/dist/flatbuffers/duc/dimension-line-style.d.ts +0 -16
  105. package/dist/flatbuffers/duc/dimension-line-style.js +0 -49
  106. package/dist/flatbuffers/duc/dimension-symbol-style.d.ts +0 -22
  107. package/dist/flatbuffers/duc/dimension-symbol-style.js +0 -72
  108. package/dist/flatbuffers/duc/dimension-text-placement.d.ts +0 -5
  109. package/dist/flatbuffers/duc/dimension-text-placement.js +0 -8
  110. package/dist/flatbuffers/duc/dimension-tolerance-style.d.ts +0 -24
  111. package/dist/flatbuffers/duc/dimension-tolerance-style.js +0 -71
  112. package/dist/flatbuffers/duc/dimension-type.d.ts +0 -15
  113. package/dist/flatbuffers/duc/dimension-type.js +0 -18
  114. package/dist/flatbuffers/duc/dimension-units-format.d.ts +0 -7
  115. package/dist/flatbuffers/duc/dimension-units-format.js +0 -10
  116. package/dist/flatbuffers/duc/dimension-validation-rules.d.ts +0 -25
  117. package/dist/flatbuffers/duc/dimension-validation-rules.js +0 -74
  118. package/dist/flatbuffers/duc/document-grid-align-items.d.ts +0 -5
  119. package/dist/flatbuffers/duc/document-grid-align-items.js +0 -8
  120. package/dist/flatbuffers/duc/document-grid-config.d.ts +0 -22
  121. package/dist/flatbuffers/duc/document-grid-config.js +0 -73
  122. package/dist/flatbuffers/duc/duc-arrow-element.d.ts +0 -16
  123. package/dist/flatbuffers/duc/duc-arrow-element.js +0 -49
  124. package/dist/flatbuffers/duc/duc-block-attribute-definition-entry.d.ts +0 -16
  125. package/dist/flatbuffers/duc/duc-block-attribute-definition-entry.js +0 -44
  126. package/dist/flatbuffers/duc/duc-block-attribute-definition.d.ts +0 -22
  127. package/dist/flatbuffers/duc/duc-block-attribute-definition.js +0 -64
  128. package/dist/flatbuffers/duc/duc-block-collection-entry.d.ts +0 -16
  129. package/dist/flatbuffers/duc/duc-block-collection-entry.js +0 -48
  130. package/dist/flatbuffers/duc/duc-block-collection.d.ts +0 -31
  131. package/dist/flatbuffers/duc/duc-block-collection.js +0 -97
  132. package/dist/flatbuffers/duc/duc-block-duplication-array.d.ts +0 -19
  133. package/dist/flatbuffers/duc/duc-block-duplication-array.js +0 -64
  134. package/dist/flatbuffers/duc/duc-block-instance-element.d.ts +0 -10
  135. package/dist/flatbuffers/duc/duc-block-instance-element.js +0 -28
  136. package/dist/flatbuffers/duc/duc-block-instance.d.ts +0 -32
  137. package/dist/flatbuffers/duc/duc-block-instance.js +0 -100
  138. package/dist/flatbuffers/duc/duc-block-metadata.d.ts +0 -26
  139. package/dist/flatbuffers/duc/duc-block-metadata.js +0 -90
  140. package/dist/flatbuffers/duc/duc-block.d.ts +0 -36
  141. package/dist/flatbuffers/duc/duc-block.js +0 -112
  142. package/dist/flatbuffers/duc/duc-common-style.d.ts +0 -16
  143. package/dist/flatbuffers/duc/duc-common-style.js +0 -44
  144. package/dist/flatbuffers/duc/duc-dimension-element.d.ts +0 -45
  145. package/dist/flatbuffers/duc/duc-dimension-element.js +0 -120
  146. package/dist/flatbuffers/duc/duc-dimension-style.d.ts +0 -28
  147. package/dist/flatbuffers/duc/duc-dimension-style.js +0 -76
  148. package/dist/flatbuffers/duc/duc-doc-element.d.ts +0 -39
  149. package/dist/flatbuffers/duc/duc-doc-element.js +0 -110
  150. package/dist/flatbuffers/duc/duc-doc-style.d.ts +0 -19
  151. package/dist/flatbuffers/duc/duc-doc-style.js +0 -52
  152. package/dist/flatbuffers/duc/duc-element-base.d.ts +0 -100
  153. package/dist/flatbuffers/duc/duc-element-base.js +0 -315
  154. package/dist/flatbuffers/duc/duc-element-styles-base.d.ts +0 -30
  155. package/dist/flatbuffers/duc/duc-element-styles-base.js +0 -103
  156. package/dist/flatbuffers/duc/duc-ellipse-element.d.ts +0 -22
  157. package/dist/flatbuffers/duc/duc-ellipse-element.js +0 -73
  158. package/dist/flatbuffers/duc/duc-embeddable-element.d.ts +0 -14
  159. package/dist/flatbuffers/duc/duc-embeddable-element.js +0 -41
  160. package/dist/flatbuffers/duc/duc-external-file-data.d.ts +0 -27
  161. package/dist/flatbuffers/duc/duc-external-file-data.js +0 -92
  162. package/dist/flatbuffers/duc/duc-external-file-entry.d.ts +0 -16
  163. package/dist/flatbuffers/duc/duc-external-file-entry.js +0 -44
  164. package/dist/flatbuffers/duc/duc-feature-control-frame-element.d.ts +0 -31
  165. package/dist/flatbuffers/duc/duc-feature-control-frame-element.js +0 -89
  166. package/dist/flatbuffers/duc/duc-feature-control-frame-style.d.ts +0 -22
  167. package/dist/flatbuffers/duc/duc-feature-control-frame-style.js +0 -60
  168. package/dist/flatbuffers/duc/duc-frame-element.d.ts +0 -14
  169. package/dist/flatbuffers/duc/duc-frame-element.js +0 -41
  170. package/dist/flatbuffers/duc/duc-free-draw-element.d.ts +0 -52
  171. package/dist/flatbuffers/duc/duc-free-draw-element.js +0 -154
  172. package/dist/flatbuffers/duc/duc-free-draw-ends.d.ts +0 -18
  173. package/dist/flatbuffers/duc/duc-free-draw-ends.js +0 -56
  174. package/dist/flatbuffers/duc/duc-global-state.d.ts +0 -37
  175. package/dist/flatbuffers/duc/duc-global-state.js +0 -121
  176. package/dist/flatbuffers/duc/duc-group.d.ts +0 -16
  177. package/dist/flatbuffers/duc/duc-group.js +0 -44
  178. package/dist/flatbuffers/duc/duc-hatch-style.d.ts +0 -28
  179. package/dist/flatbuffers/duc/duc-hatch-style.js +0 -79
  180. package/dist/flatbuffers/duc/duc-head.d.ts +0 -19
  181. package/dist/flatbuffers/duc/duc-head.js +0 -57
  182. package/dist/flatbuffers/duc/duc-image-element.d.ts +0 -35
  183. package/dist/flatbuffers/duc/duc-image-element.js +0 -91
  184. package/dist/flatbuffers/duc/duc-image-filter.d.ts +0 -15
  185. package/dist/flatbuffers/duc/duc-image-filter.js +0 -48
  186. package/dist/flatbuffers/duc/duc-layer-overrides.d.ts +0 -16
  187. package/dist/flatbuffers/duc/duc-layer-overrides.js +0 -44
  188. package/dist/flatbuffers/duc/duc-layer.d.ts +0 -21
  189. package/dist/flatbuffers/duc/duc-layer.js +0 -59
  190. package/dist/flatbuffers/duc/duc-leader-element.d.ts +0 -22
  191. package/dist/flatbuffers/duc/duc-leader-element.js +0 -60
  192. package/dist/flatbuffers/duc/duc-leader-style.d.ts +0 -27
  193. package/dist/flatbuffers/duc/duc-leader-style.js +0 -79
  194. package/dist/flatbuffers/duc/duc-line-reference.d.ts +0 -15
  195. package/dist/flatbuffers/duc/duc-line-reference.js +0 -43
  196. package/dist/flatbuffers/duc/duc-line.d.ts +0 -15
  197. package/dist/flatbuffers/duc/duc-line.js +0 -43
  198. package/dist/flatbuffers/duc/duc-linear-element-base.d.ts +0 -38
  199. package/dist/flatbuffers/duc/duc-linear-element-base.js +0 -124
  200. package/dist/flatbuffers/duc/duc-linear-element.d.ts +0 -16
  201. package/dist/flatbuffers/duc/duc-linear-element.js +0 -49
  202. package/dist/flatbuffers/duc/duc-local-state.d.ts +0 -68
  203. package/dist/flatbuffers/duc/duc-local-state.js +0 -206
  204. package/dist/flatbuffers/duc/duc-mermaid-element.d.ts +0 -23
  205. package/dist/flatbuffers/duc/duc-mermaid-element.js +0 -65
  206. package/dist/flatbuffers/duc/duc-model-element.d.ts +0 -26
  207. package/dist/flatbuffers/duc/duc-model-element.js +0 -79
  208. package/dist/flatbuffers/duc/duc-parametric-element.d.ts +0 -16
  209. package/dist/flatbuffers/duc/duc-parametric-element.js +0 -44
  210. package/dist/flatbuffers/duc/duc-path.d.ts +0 -26
  211. package/dist/flatbuffers/duc/duc-path.js +0 -69
  212. package/dist/flatbuffers/duc/duc-pdf-element.d.ts +0 -19
  213. package/dist/flatbuffers/duc/duc-pdf-element.js +0 -51
  214. package/dist/flatbuffers/duc/duc-plot-element.d.ts +0 -19
  215. package/dist/flatbuffers/duc/duc-plot-element.js +0 -52
  216. package/dist/flatbuffers/duc/duc-plot-style.d.ts +0 -11
  217. package/dist/flatbuffers/duc/duc-plot-style.js +0 -32
  218. package/dist/flatbuffers/duc/duc-point-binding.d.ts +0 -26
  219. package/dist/flatbuffers/duc/duc-point-binding.js +0 -73
  220. package/dist/flatbuffers/duc/duc-point.d.ts +0 -18
  221. package/dist/flatbuffers/duc/duc-point.js +0 -57
  222. package/dist/flatbuffers/duc/duc-polygon-element.d.ts +0 -16
  223. package/dist/flatbuffers/duc/duc-polygon-element.js +0 -49
  224. package/dist/flatbuffers/duc/duc-rectangle-element.d.ts +0 -14
  225. package/dist/flatbuffers/duc/duc-rectangle-element.js +0 -41
  226. package/dist/flatbuffers/duc/duc-region.d.ts +0 -19
  227. package/dist/flatbuffers/duc/duc-region.js +0 -51
  228. package/dist/flatbuffers/duc/duc-stack-base.d.ts +0 -27
  229. package/dist/flatbuffers/duc/duc-stack-base.js +0 -78
  230. package/dist/flatbuffers/duc/duc-stack-element-base.d.ts +0 -23
  231. package/dist/flatbuffers/duc/duc-stack-element-base.js +0 -65
  232. package/dist/flatbuffers/duc/duc-stack-like-styles.d.ts +0 -16
  233. package/dist/flatbuffers/duc/duc-stack-like-styles.js +0 -48
  234. package/dist/flatbuffers/duc/duc-table-auto-size.d.ts +0 -15
  235. package/dist/flatbuffers/duc/duc-table-auto-size.js +0 -48
  236. package/dist/flatbuffers/duc/duc-table-cell-entry.d.ts +0 -16
  237. package/dist/flatbuffers/duc/duc-table-cell-entry.js +0 -44
  238. package/dist/flatbuffers/duc/duc-table-cell-span.d.ts +0 -15
  239. package/dist/flatbuffers/duc/duc-table-cell-span.js +0 -48
  240. package/dist/flatbuffers/duc/duc-table-cell-style.d.ts +0 -22
  241. package/dist/flatbuffers/duc/duc-table-cell-style.js +0 -59
  242. package/dist/flatbuffers/duc/duc-table-cell.d.ts +0 -27
  243. package/dist/flatbuffers/duc/duc-table-cell.js +0 -72
  244. package/dist/flatbuffers/duc/duc-table-column-entry.d.ts +0 -16
  245. package/dist/flatbuffers/duc/duc-table-column-entry.js +0 -44
  246. package/dist/flatbuffers/duc/duc-table-column.d.ts +0 -18
  247. package/dist/flatbuffers/duc/duc-table-column.js +0 -51
  248. package/dist/flatbuffers/duc/duc-table-element.d.ts +0 -51
  249. package/dist/flatbuffers/duc/duc-table-element.js +0 -167
  250. package/dist/flatbuffers/duc/duc-table-row-entry.d.ts +0 -16
  251. package/dist/flatbuffers/duc/duc-table-row-entry.js +0 -44
  252. package/dist/flatbuffers/duc/duc-table-row.d.ts +0 -18
  253. package/dist/flatbuffers/duc/duc-table-row.js +0 -51
  254. package/dist/flatbuffers/duc/duc-table-style.d.ts +0 -20
  255. package/dist/flatbuffers/duc/duc-table-style.js +0 -57
  256. package/dist/flatbuffers/duc/duc-text-dynamic-dictionary-source.d.ts +0 -14
  257. package/dist/flatbuffers/duc/duc-text-dynamic-dictionary-source.js +0 -40
  258. package/dist/flatbuffers/duc/duc-text-dynamic-element-source.d.ts +0 -17
  259. package/dist/flatbuffers/duc/duc-text-dynamic-element-source.js +0 -49
  260. package/dist/flatbuffers/duc/duc-text-dynamic-part.d.ts +0 -22
  261. package/dist/flatbuffers/duc/duc-text-dynamic-part.js +0 -58
  262. package/dist/flatbuffers/duc/duc-text-dynamic-source-data.d.ts +0 -9
  263. package/dist/flatbuffers/duc/duc-text-dynamic-source-data.js +0 -26
  264. package/dist/flatbuffers/duc/duc-text-dynamic-source.d.ts +0 -19
  265. package/dist/flatbuffers/duc/duc-text-dynamic-source.js +0 -58
  266. package/dist/flatbuffers/duc/duc-text-element.d.ts +0 -33
  267. package/dist/flatbuffers/duc/duc-text-element.js +0 -94
  268. package/dist/flatbuffers/duc/duc-text-style.d.ts +0 -41
  269. package/dist/flatbuffers/duc/duc-text-style.js +0 -120
  270. package/dist/flatbuffers/duc/duc-ucs.d.ts +0 -16
  271. package/dist/flatbuffers/duc/duc-ucs.js +0 -49
  272. package/dist/flatbuffers/duc/duc-view.d.ts +0 -24
  273. package/dist/flatbuffers/duc/duc-view.js +0 -71
  274. package/dist/flatbuffers/duc/duc-viewport-element.d.ts +0 -36
  275. package/dist/flatbuffers/duc/duc-viewport-element.js +0 -102
  276. package/dist/flatbuffers/duc/duc-viewport-style.d.ts +0 -13
  277. package/dist/flatbuffers/duc/duc-viewport-style.js +0 -40
  278. package/dist/flatbuffers/duc/duc-xray-element.d.ts +0 -23
  279. package/dist/flatbuffers/duc/duc-xray-element.js +0 -66
  280. package/dist/flatbuffers/duc/duc-xray-style.d.ts +0 -14
  281. package/dist/flatbuffers/duc/duc-xray-style.js +0 -40
  282. package/dist/flatbuffers/duc/dynamic-snap-settings.d.ts +0 -17
  283. package/dist/flatbuffers/duc/dynamic-snap-settings.js +0 -56
  284. package/dist/flatbuffers/duc/element-background.d.ts +0 -14
  285. package/dist/flatbuffers/duc/element-background.js +0 -41
  286. package/dist/flatbuffers/duc/element-content-base.d.ts +0 -29
  287. package/dist/flatbuffers/duc/element-content-base.js +0 -80
  288. package/dist/flatbuffers/duc/element-content-preference.d.ts +0 -8
  289. package/dist/flatbuffers/duc/element-content-preference.js +0 -11
  290. package/dist/flatbuffers/duc/element-stroke.d.ts +0 -24
  291. package/dist/flatbuffers/duc/element-stroke.js +0 -66
  292. package/dist/flatbuffers/duc/element-wrapper.d.ts +0 -16
  293. package/dist/flatbuffers/duc/element-wrapper.js +0 -49
  294. package/dist/flatbuffers/duc/element.d.ts +0 -51
  295. package/dist/flatbuffers/duc/element.js +0 -110
  296. package/dist/flatbuffers/duc/exported-data-state.d.ts +0 -102
  297. package/dist/flatbuffers/duc/exported-data-state.js +0 -341
  298. package/dist/flatbuffers/duc/fcfbetween-modifier.d.ts +0 -17
  299. package/dist/flatbuffers/duc/fcfbetween-modifier.js +0 -48
  300. package/dist/flatbuffers/duc/fcfdatum-definition.d.ts +0 -16
  301. package/dist/flatbuffers/duc/fcfdatum-definition.js +0 -43
  302. package/dist/flatbuffers/duc/fcfdatum-style.d.ts +0 -14
  303. package/dist/flatbuffers/duc/fcfdatum-style.js +0 -41
  304. package/dist/flatbuffers/duc/fcfframe-modifiers.d.ts +0 -22
  305. package/dist/flatbuffers/duc/fcfframe-modifiers.js +0 -65
  306. package/dist/flatbuffers/duc/fcflayout-style.d.ts +0 -17
  307. package/dist/flatbuffers/duc/fcflayout-style.js +0 -56
  308. package/dist/flatbuffers/duc/fcfprojected-zone-modifier.d.ts +0 -13
  309. package/dist/flatbuffers/duc/fcfprojected-zone-modifier.js +0 -40
  310. package/dist/flatbuffers/duc/fcfsegment-row.d.ts +0 -17
  311. package/dist/flatbuffers/duc/fcfsegment-row.js +0 -55
  312. package/dist/flatbuffers/duc/fcfsymbol-style.d.ts +0 -13
  313. package/dist/flatbuffers/duc/fcfsymbol-style.js +0 -40
  314. package/dist/flatbuffers/duc/feature-control-frame-segment.d.ts +0 -22
  315. package/dist/flatbuffers/duc/feature-control-frame-segment.js +0 -65
  316. package/dist/flatbuffers/duc/feature-modifier.d.ts +0 -18
  317. package/dist/flatbuffers/duc/feature-modifier.js +0 -21
  318. package/dist/flatbuffers/duc/gdt-symbol.d.ts +0 -22
  319. package/dist/flatbuffers/duc/gdt-symbol.js +0 -25
  320. package/dist/flatbuffers/duc/geometric-point.d.ts +0 -10
  321. package/dist/flatbuffers/duc/geometric-point.js +0 -27
  322. package/dist/flatbuffers/duc/grid-display-type.d.ts +0 -6
  323. package/dist/flatbuffers/duc/grid-display-type.js +0 -9
  324. package/dist/flatbuffers/duc/grid-settings.d.ts +0 -54
  325. package/dist/flatbuffers/duc/grid-settings.js +0 -165
  326. package/dist/flatbuffers/duc/grid-style.d.ts +0 -26
  327. package/dist/flatbuffers/duc/grid-style.js +0 -74
  328. package/dist/flatbuffers/duc/grid-type.d.ts +0 -7
  329. package/dist/flatbuffers/duc/grid-type.js +0 -10
  330. package/dist/flatbuffers/duc/handle-type.d.ts +0 -4
  331. package/dist/flatbuffers/duc/handle-type.js +0 -7
  332. package/dist/flatbuffers/duc/hatch-pattern-line.d.ts +0 -35
  333. package/dist/flatbuffers/duc/hatch-pattern-line.js +0 -93
  334. package/dist/flatbuffers/duc/hatch-style.d.ts +0 -5
  335. package/dist/flatbuffers/duc/hatch-style.js +0 -8
  336. package/dist/flatbuffers/duc/identified-common-style.d.ts +0 -16
  337. package/dist/flatbuffers/duc/identified-common-style.js +0 -44
  338. package/dist/flatbuffers/duc/identified-dimension-style.d.ts +0 -16
  339. package/dist/flatbuffers/duc/identified-dimension-style.js +0 -44
  340. package/dist/flatbuffers/duc/identified-doc-style.d.ts +0 -16
  341. package/dist/flatbuffers/duc/identified-doc-style.js +0 -44
  342. package/dist/flatbuffers/duc/identified-fcfstyle.d.ts +0 -16
  343. package/dist/flatbuffers/duc/identified-fcfstyle.js +0 -44
  344. package/dist/flatbuffers/duc/identified-grid-settings.d.ts +0 -16
  345. package/dist/flatbuffers/duc/identified-grid-settings.js +0 -44
  346. package/dist/flatbuffers/duc/identified-hatch-style.d.ts +0 -16
  347. package/dist/flatbuffers/duc/identified-hatch-style.js +0 -44
  348. package/dist/flatbuffers/duc/identified-leader-style.d.ts +0 -16
  349. package/dist/flatbuffers/duc/identified-leader-style.js +0 -44
  350. package/dist/flatbuffers/duc/identified-snap-settings.d.ts +0 -16
  351. package/dist/flatbuffers/duc/identified-snap-settings.js +0 -44
  352. package/dist/flatbuffers/duc/identified-stack-like-style.d.ts +0 -16
  353. package/dist/flatbuffers/duc/identified-stack-like-style.js +0 -44
  354. package/dist/flatbuffers/duc/identified-table-style.d.ts +0 -16
  355. package/dist/flatbuffers/duc/identified-table-style.js +0 -44
  356. package/dist/flatbuffers/duc/identified-text-style.d.ts +0 -16
  357. package/dist/flatbuffers/duc/identified-text-style.js +0 -44
  358. package/dist/flatbuffers/duc/identified-ucs.d.ts +0 -16
  359. package/dist/flatbuffers/duc/identified-ucs.js +0 -44
  360. package/dist/flatbuffers/duc/identified-view.d.ts +0 -16
  361. package/dist/flatbuffers/duc/identified-view.js +0 -44
  362. package/dist/flatbuffers/duc/identified-viewport-style.d.ts +0 -16
  363. package/dist/flatbuffers/duc/identified-viewport-style.js +0 -44
  364. package/dist/flatbuffers/duc/identified-xray-style.d.ts +0 -16
  365. package/dist/flatbuffers/duc/identified-xray-style.js +0 -44
  366. package/dist/flatbuffers/duc/identifier.d.ts +0 -20
  367. package/dist/flatbuffers/duc/identifier.js +0 -57
  368. package/dist/flatbuffers/duc/image-crop.d.ts +0 -23
  369. package/dist/flatbuffers/duc/image-crop.js +0 -80
  370. package/dist/flatbuffers/duc/image-status.d.ts +0 -5
  371. package/dist/flatbuffers/duc/image-status.js +0 -8
  372. package/dist/flatbuffers/duc/isometric-grid-settings.d.ts +0 -15
  373. package/dist/flatbuffers/duc/isometric-grid-settings.js +0 -48
  374. package/dist/flatbuffers/duc/jsonpatch-operation.d.ts +0 -23
  375. package/dist/flatbuffers/duc/jsonpatch-operation.js +0 -64
  376. package/dist/flatbuffers/duc/layer-snap-filters.d.ts +0 -23
  377. package/dist/flatbuffers/duc/layer-snap-filters.js +0 -76
  378. package/dist/flatbuffers/duc/layer-validation-rules.d.ts +0 -17
  379. package/dist/flatbuffers/duc/layer-validation-rules.js +0 -54
  380. package/dist/flatbuffers/duc/leader-block-content.d.ts +0 -25
  381. package/dist/flatbuffers/duc/leader-block-content.js +0 -85
  382. package/dist/flatbuffers/duc/leader-content-data.d.ts +0 -9
  383. package/dist/flatbuffers/duc/leader-content-data.js +0 -26
  384. package/dist/flatbuffers/duc/leader-content-type.d.ts +0 -4
  385. package/dist/flatbuffers/duc/leader-content-type.js +0 -7
  386. package/dist/flatbuffers/duc/leader-content.d.ts +0 -19
  387. package/dist/flatbuffers/duc/leader-content.js +0 -58
  388. package/dist/flatbuffers/duc/leader-text-block-content.d.ts +0 -14
  389. package/dist/flatbuffers/duc/leader-text-block-content.js +0 -40
  390. package/dist/flatbuffers/duc/line-head.d.ts +0 -17
  391. package/dist/flatbuffers/duc/line-head.js +0 -20
  392. package/dist/flatbuffers/duc/line-spacing-type.d.ts +0 -5
  393. package/dist/flatbuffers/duc/line-spacing-type.js +0 -8
  394. package/dist/flatbuffers/duc/line-spacing.d.ts +0 -16
  395. package/dist/flatbuffers/duc/line-spacing.js +0 -49
  396. package/dist/flatbuffers/duc/linear-unit-system.d.ts +0 -24
  397. package/dist/flatbuffers/duc/linear-unit-system.js +0 -75
  398. package/dist/flatbuffers/duc/margins.d.ts +0 -19
  399. package/dist/flatbuffers/duc/margins.js +0 -64
  400. package/dist/flatbuffers/duc/mark-ellipse-center.d.ts +0 -4
  401. package/dist/flatbuffers/duc/mark-ellipse-center.js +0 -7
  402. package/dist/flatbuffers/duc/material-condition.d.ts +0 -5
  403. package/dist/flatbuffers/duc/material-condition.js +0 -8
  404. package/dist/flatbuffers/duc/object-snap-mode.d.ts +0 -22
  405. package/dist/flatbuffers/duc/object-snap-mode.js +0 -25
  406. package/dist/flatbuffers/duc/paragraph-formatting.d.ts +0 -33
  407. package/dist/flatbuffers/duc/paragraph-formatting.js +0 -106
  408. package/dist/flatbuffers/duc/parametric-source-type.d.ts +0 -4
  409. package/dist/flatbuffers/duc/parametric-source-type.js +0 -7
  410. package/dist/flatbuffers/duc/parametric-source.d.ts +0 -20
  411. package/dist/flatbuffers/duc/parametric-source.js +0 -57
  412. package/dist/flatbuffers/duc/plot-layout.d.ts +0 -14
  413. package/dist/flatbuffers/duc/plot-layout.js +0 -41
  414. package/dist/flatbuffers/duc/point-binding-point.d.ts +0 -15
  415. package/dist/flatbuffers/duc/point-binding-point.js +0 -48
  416. package/dist/flatbuffers/duc/polar-grid-settings.d.ts +0 -17
  417. package/dist/flatbuffers/duc/polar-grid-settings.js +0 -56
  418. package/dist/flatbuffers/duc/polar-tracking-settings.d.ts +0 -29
  419. package/dist/flatbuffers/duc/polar-tracking-settings.js +0 -90
  420. package/dist/flatbuffers/duc/primary-units.d.ts +0 -16
  421. package/dist/flatbuffers/duc/primary-units.js +0 -44
  422. package/dist/flatbuffers/duc/pruning-level.d.ts +0 -5
  423. package/dist/flatbuffers/duc/pruning-level.js +0 -8
  424. package/dist/flatbuffers/duc/snap-marker-settings.d.ts +0 -23
  425. package/dist/flatbuffers/duc/snap-marker-settings.js +0 -79
  426. package/dist/flatbuffers/duc/snap-marker-shape.d.ts +0 -6
  427. package/dist/flatbuffers/duc/snap-marker-shape.js +0 -9
  428. package/dist/flatbuffers/duc/snap-marker-style-entry.d.ts +0 -16
  429. package/dist/flatbuffers/duc/snap-marker-style-entry.js +0 -43
  430. package/dist/flatbuffers/duc/snap-marker-style.d.ts +0 -17
  431. package/dist/flatbuffers/duc/snap-marker-style.js +0 -49
  432. package/dist/flatbuffers/duc/snap-mode.d.ts +0 -4
  433. package/dist/flatbuffers/duc/snap-mode.js +0 -7
  434. package/dist/flatbuffers/duc/snap-override-behavior.d.ts +0 -5
  435. package/dist/flatbuffers/duc/snap-override-behavior.js +0 -8
  436. package/dist/flatbuffers/duc/snap-override.d.ts +0 -17
  437. package/dist/flatbuffers/duc/snap-override.js +0 -49
  438. package/dist/flatbuffers/duc/snap-settings.d.ts +0 -75
  439. package/dist/flatbuffers/duc/snap-settings.js +0 -245
  440. package/dist/flatbuffers/duc/stack-format-properties.d.ts +0 -18
  441. package/dist/flatbuffers/duc/stack-format-properties.js +0 -57
  442. package/dist/flatbuffers/duc/stack-format.d.ts +0 -21
  443. package/dist/flatbuffers/duc/stack-format.js +0 -64
  444. package/dist/flatbuffers/duc/stacked-text-align.d.ts +0 -5
  445. package/dist/flatbuffers/duc/stacked-text-align.js +0 -8
  446. package/dist/flatbuffers/duc/standard-overrides.d.ts +0 -63
  447. package/dist/flatbuffers/duc/standard-overrides.js +0 -162
  448. package/dist/flatbuffers/duc/standard-styles.d.ts +0 -77
  449. package/dist/flatbuffers/duc/standard-styles.js +0 -285
  450. package/dist/flatbuffers/duc/standard-units.d.ts +0 -16
  451. package/dist/flatbuffers/duc/standard-units.js +0 -44
  452. package/dist/flatbuffers/duc/standard-validation.d.ts +0 -16
  453. package/dist/flatbuffers/duc/standard-validation.js +0 -44
  454. package/dist/flatbuffers/duc/standard-view-settings.d.ts +0 -35
  455. package/dist/flatbuffers/duc/standard-view-settings.js +0 -124
  456. package/dist/flatbuffers/duc/standard.d.ts +0 -33
  457. package/dist/flatbuffers/duc/standard.js +0 -90
  458. package/dist/flatbuffers/duc/string-value-entry.d.ts +0 -17
  459. package/dist/flatbuffers/duc/string-value-entry.js +0 -49
  460. package/dist/flatbuffers/duc/stroke-cap.d.ts +0 -5
  461. package/dist/flatbuffers/duc/stroke-cap.js +0 -8
  462. package/dist/flatbuffers/duc/stroke-join.d.ts +0 -5
  463. package/dist/flatbuffers/duc/stroke-join.js +0 -8
  464. package/dist/flatbuffers/duc/stroke-placement.d.ts +0 -5
  465. package/dist/flatbuffers/duc/stroke-placement.js +0 -8
  466. package/dist/flatbuffers/duc/stroke-preference.d.ts +0 -6
  467. package/dist/flatbuffers/duc/stroke-preference.js +0 -9
  468. package/dist/flatbuffers/duc/stroke-side-preference.d.ts +0 -8
  469. package/dist/flatbuffers/duc/stroke-side-preference.js +0 -11
  470. package/dist/flatbuffers/duc/stroke-sides.d.ts +0 -24
  471. package/dist/flatbuffers/duc/stroke-sides.js +0 -67
  472. package/dist/flatbuffers/duc/stroke-style.d.ts +0 -37
  473. package/dist/flatbuffers/duc/stroke-style.js +0 -111
  474. package/dist/flatbuffers/duc/stroke-width.d.ts +0 -5
  475. package/dist/flatbuffers/duc/stroke-width.js +0 -8
  476. package/dist/flatbuffers/duc/table-cell-alignment.d.ts +0 -11
  477. package/dist/flatbuffers/duc/table-cell-alignment.js +0 -14
  478. package/dist/flatbuffers/duc/table-flow-direction.d.ts +0 -4
  479. package/dist/flatbuffers/duc/table-flow-direction.js +0 -7
  480. package/dist/flatbuffers/duc/text-align.d.ts +0 -5
  481. package/dist/flatbuffers/duc/text-align.js +0 -8
  482. package/dist/flatbuffers/duc/text-column.d.ts +0 -15
  483. package/dist/flatbuffers/duc/text-column.js +0 -48
  484. package/dist/flatbuffers/duc/text-field-source-property.d.ts +0 -13
  485. package/dist/flatbuffers/duc/text-field-source-property.js +0 -16
  486. package/dist/flatbuffers/duc/text-field-source-type.d.ts +0 -4
  487. package/dist/flatbuffers/duc/text-field-source-type.js +0 -7
  488. package/dist/flatbuffers/duc/text-flow-direction.d.ts +0 -6
  489. package/dist/flatbuffers/duc/text-flow-direction.js +0 -9
  490. package/dist/flatbuffers/duc/tiling-properties.d.ts +0 -21
  491. package/dist/flatbuffers/duc/tiling-properties.js +0 -75
  492. package/dist/flatbuffers/duc/tolerance-clause.d.ts +0 -27
  493. package/dist/flatbuffers/duc/tolerance-clause.js +0 -84
  494. package/dist/flatbuffers/duc/tolerance-display.d.ts +0 -7
  495. package/dist/flatbuffers/duc/tolerance-display.js +0 -10
  496. package/dist/flatbuffers/duc/tolerance-type.d.ts +0 -5
  497. package/dist/flatbuffers/duc/tolerance-type.js +0 -8
  498. package/dist/flatbuffers/duc/tolerance-zone-type.d.ts +0 -7
  499. package/dist/flatbuffers/duc/tolerance-zone-type.js +0 -10
  500. package/dist/flatbuffers/duc/tracking-line-style.d.ts +0 -26
  501. package/dist/flatbuffers/duc/tracking-line-style.js +0 -74
  502. package/dist/flatbuffers/duc/unit-precision.d.ts +0 -19
  503. package/dist/flatbuffers/duc/unit-precision.js +0 -64
  504. package/dist/flatbuffers/duc/unit-system-base.d.ts +0 -20
  505. package/dist/flatbuffers/duc/unit-system-base.js +0 -65
  506. package/dist/flatbuffers/duc/unit-system.d.ts +0 -4
  507. package/dist/flatbuffers/duc/unit-system.js +0 -7
  508. package/dist/flatbuffers/duc/version-base.d.ts +0 -27
  509. package/dist/flatbuffers/duc/version-base.js +0 -80
  510. package/dist/flatbuffers/duc/version-graph-metadata.d.ts +0 -15
  511. package/dist/flatbuffers/duc/version-graph-metadata.js +0 -48
  512. package/dist/flatbuffers/duc/version-graph.d.ts +0 -31
  513. package/dist/flatbuffers/duc/version-graph.js +0 -94
  514. package/dist/flatbuffers/duc/vertical-align.d.ts +0 -5
  515. package/dist/flatbuffers/duc/vertical-align.js +0 -8
  516. package/dist/flatbuffers/duc/viewport-shade-plot.d.ts +0 -6
  517. package/dist/flatbuffers/duc/viewport-shade-plot.js +0 -9
  518. package/dist/flatbuffers/duc/youtube-states.d.ts +0 -8
  519. package/dist/flatbuffers/duc/youtube-states.js +0 -11
  520. package/dist/flatbuffers/duc.d.ts +0 -234
  521. package/dist/flatbuffers/duc.js +0 -236
  522. package/dist/restore/restoreStandards.d.ts +0 -8
  523. package/dist/restore/restoreStandards.js +0 -224
  524. package/dist/technical/standards.d.ts +0 -124
  525. package/dist/technical/standards.js +0 -10
  526. package/dist/utils/elements/viewportElement.d.ts +0 -6
  527. package/dist/utils/elements/viewportElement.js +0 -9
  528. package/dist/utils/state/grid.d.ts +0 -7
  529. package/dist/utils/state/grid.js +0 -25
package/dist/serialize.js CHANGED
@@ -7,2559 +7,72 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- /* eslint-disable @typescript-eslint/consistent-type-definitions */
11
- /* IMPORTANT:
12
- - Single-file serializer for DUC FlatBuffers schema.
13
- - No enum remapping tables: use enums directly from ducjs/flatbuffers/duc.
14
- - No defaults added: only write what's present in TS objects.
15
- - PrecisionValue, Radian, Percentage, ScaleFactor, etc. are branded numbers:
16
- cast to number at the final write site (e.g. pv.value).
17
- - Keep args strongly typed. Never use any for function args.
18
- */
19
- import * as flatbuffers from "flatbuffers";
20
- import * as Duc from "./flatbuffers/duc";
21
- import { zlibSync, strToU8 } from "fflate";
22
10
  import { restore } from "./restore";
23
- import { encodeFunctionString, EXPORT_DATA_TYPES } from "./utils";
24
- /**
25
- * Basic helpers
26
- */
27
- const str = (b, v) => v == null ? undefined : b.createString(v);
28
- function writeString(builder, str) {
29
- if (str === null || str === undefined)
30
- return undefined;
31
- return builder.createString(str);
32
- }
33
- function getPrecisionValue(value, useScopedValues) {
34
- return useScopedValues ? value.scoped : value.value;
35
- }
36
- function writeStringVector(builder, items) {
37
- if (!items || items.length === 0)
38
- return undefined;
39
- const arr = Array.isArray(items) ? items.slice() : Array.from(items);
40
- const offsets = arr.map(item => (item ? builder.createString(item) : 0)).filter((offset) => offset !== 0);
41
- if (offsets.length === 0)
42
- return undefined;
43
- // This helper is used for multiple vector fields; return a builder vector; caller decides which create*Vector to use.
44
- // For current callers that expect createGroupIdsVector specifically, fallback to generic createVector via builder.start/endVector
45
- builder.startVector(4, offsets.length, 4);
46
- for (let i = offsets.length - 1; i >= 0; i--) {
47
- builder.addOffset(offsets[i]);
48
- }
49
- return builder.endVector();
50
- }
51
- /**
52
- * Element style/content serializers
53
- */
54
- function writeTiling(b, t, usv) {
55
- if (!t)
56
- return undefined;
57
- Duc.TilingProperties.startTilingProperties(b);
58
- Duc.TilingProperties.addSizeInPercent(b, t.sizeInPercent);
59
- Duc.TilingProperties.addAngle(b, t.angle);
60
- if (t.spacing !== undefined)
61
- Duc.TilingProperties.addSpacing(b, t.spacing);
62
- if (t.offsetX !== undefined)
63
- Duc.TilingProperties.addOffsetX(b, t.offsetX);
64
- if (t.offsetY !== undefined)
65
- Duc.TilingProperties.addOffsetY(b, t.offsetY);
66
- return Duc.TilingProperties.endTilingProperties(b);
67
- }
68
- function writeHatchPatternLine(b, l, usv) {
69
- const origin = writeDucPoint(b, l.origin, usv);
70
- const offsetVec = Duc.HatchPatternLine.createOffsetVector(b, [getPrecisionValue(l.offset[0], usv), getPrecisionValue(l.offset[1], usv)]);
71
- const dashVec = Duc.HatchPatternLine.createDashPatternVector(b, l.dashPattern.map(Number));
72
- Duc.HatchPatternLine.startHatchPatternLine(b);
73
- Duc.HatchPatternLine.addAngle(b, l.angle);
74
- if (origin)
75
- Duc.HatchPatternLine.addOrigin(b, origin);
76
- Duc.HatchPatternLine.addOffset(b, offsetVec);
77
- if (dashVec)
78
- Duc.HatchPatternLine.addDashPattern(b, dashVec);
79
- return Duc.HatchPatternLine.endHatchPatternLine(b);
80
- }
81
- function writeCustomHatch(b, p, usv) {
82
- if (!p)
83
- return undefined;
84
- const name = str(b, p.name);
85
- const desc = str(b, p.description);
86
- const lines = Duc.CustomHatchPattern.createLinesVector(b, p.lines.map((ln) => writeHatchPatternLine(b, ln, usv)));
87
- Duc.CustomHatchPattern.startCustomHatchPattern(b);
88
- if (name)
89
- Duc.CustomHatchPattern.addName(b, name);
90
- if (desc)
91
- Duc.CustomHatchPattern.addDescription(b, desc);
92
- Duc.CustomHatchPattern.addLines(b, lines);
93
- return Duc.CustomHatchPattern.endCustomHatchPattern(b);
94
- }
95
- function writeHatchStyle(b, h, usv) {
96
- if (!h)
97
- return undefined;
98
- const pattName = str(b, h.pattern.name);
99
- const pattOrigin = writeDucPoint(b, h.pattern.origin, usv);
100
- const custom = writeCustomHatch(b, h.customPattern, usv);
101
- Duc.DucHatchStyle.startDucHatchStyle(b);
102
- if (h.hatchStyle !== undefined)
103
- Duc.DucHatchStyle.addHatchStyle(b, h.hatchStyle);
104
- if (pattName)
105
- Duc.DucHatchStyle.addPatternName(b, pattName);
106
- Duc.DucHatchStyle.addPatternScale(b, h.pattern.scale);
107
- Duc.DucHatchStyle.addPatternAngle(b, h.pattern.angle);
108
- if (pattOrigin)
109
- Duc.DucHatchStyle.addPatternOrigin(b, pattOrigin);
110
- Duc.DucHatchStyle.addPatternDouble(b, h.pattern.double);
111
- if (custom)
112
- Duc.DucHatchStyle.addCustomPattern(b, custom);
113
- return Duc.DucHatchStyle.endDucHatchStyle(b);
114
- }
115
- function writeImageFilter(b, f, usv) {
116
- if (!f)
117
- return undefined;
118
- Duc.DucImageFilter.startDucImageFilter(b);
119
- Duc.DucImageFilter.addBrightness(b, f.brightness);
120
- Duc.DucImageFilter.addContrast(b, f.contrast);
121
- return Duc.DucImageFilter.endDucImageFilter(b);
122
- }
123
- function writeContentBase(b, c, usv) {
124
- if (!c)
125
- return undefined;
126
- const s = str(b, c.src);
127
- const til = writeTiling(b, c.tiling, usv);
128
- const hatch = writeHatchStyle(b, c.hatch, usv);
129
- const filt = writeImageFilter(b, c.imageFilter, usv);
130
- Duc.ElementContentBase.startElementContentBase(b);
131
- if (c.preference !== undefined)
132
- Duc.ElementContentBase.addPreference(b, c.preference);
133
- if (s)
134
- Duc.ElementContentBase.addSrc(b, s);
135
- Duc.ElementContentBase.addVisible(b, c.visible);
136
- Duc.ElementContentBase.addOpacity(b, c.opacity);
137
- if (til)
138
- Duc.ElementContentBase.addTiling(b, til);
139
- if (hatch)
140
- Duc.ElementContentBase.addHatch(b, hatch);
141
- if (filt)
142
- Duc.ElementContentBase.addImageFilter(b, filt);
143
- return Duc.ElementContentBase.endElementContentBase(b);
144
- }
145
- function writeStrokeStyle(b, s, usv) {
146
- var _a;
147
- if (!s)
148
- return undefined;
149
- const dashVec = ((_a = s.dash) === null || _a === void 0 ? void 0 : _a.length) ? Duc.StrokeStyle.createDashVector(b, s.dash) : undefined;
150
- const dashLineOverride = str(b, s.dashLineOverride);
151
- Duc.StrokeStyle.startStrokeStyle(b);
152
- if (s.preference !== undefined)
153
- Duc.StrokeStyle.addPreference(b, s.preference);
154
- if (s.cap != null)
155
- Duc.StrokeStyle.addCap(b, s.cap);
156
- if (s.join != null)
157
- Duc.StrokeStyle.addJoin(b, s.join);
158
- if (dashVec)
159
- Duc.StrokeStyle.addDash(b, dashVec);
160
- if (dashLineOverride)
161
- Duc.StrokeStyle.addDashLineOverride(b, dashLineOverride);
162
- if (s.dashCap != null)
163
- Duc.StrokeStyle.addDashCap(b, s.dashCap);
164
- if (s.miterLimit !== undefined)
165
- Duc.StrokeStyle.addMiterLimit(b, s.miterLimit);
166
- return Duc.StrokeStyle.endStrokeStyle(b);
167
- }
168
- function writeStrokeSides(b, ss, usv) {
169
- var _a;
170
- if (!ss)
171
- return undefined;
172
- const valuesVec = ((_a = ss.values) === null || _a === void 0 ? void 0 : _a.length) ? Duc.StrokeSides.createValuesVector(b, ss.values) : undefined;
173
- Duc.StrokeSides.startStrokeSides(b);
174
- if (ss.preference !== undefined)
175
- Duc.StrokeSides.addPreference(b, ss.preference);
176
- if (valuesVec)
177
- Duc.StrokeSides.addValues(b, valuesVec);
178
- return Duc.StrokeSides.endStrokeSides(b);
179
- }
180
- function writeElementStroke(b, s, usv) {
181
- if (!s)
182
- return undefined;
183
- const c = writeContentBase(b, s.content, usv);
184
- const st = writeStrokeStyle(b, s.style, usv);
185
- const sides = writeStrokeSides(b, s.strokeSides, usv);
186
- Duc.ElementStroke.startElementStroke(b);
187
- if (c)
188
- Duc.ElementStroke.addContent(b, c);
189
- if (s.width) {
190
- Duc.ElementStroke.addWidth(b, getPrecisionValue(s.width, usv));
191
- }
192
- if (st)
193
- Duc.ElementStroke.addStyle(b, st);
194
- if (s.placement)
195
- Duc.ElementStroke.addPlacement(b, s.placement);
196
- if (sides)
197
- Duc.ElementStroke.addStrokeSides(b, sides);
198
- return Duc.ElementStroke.endElementStroke(b);
199
- }
200
- function writeElementBackground(b, bg, usv) {
201
- if (!bg)
202
- return undefined;
203
- const c = writeContentBase(b, bg.content, usv);
204
- Duc.ElementBackground.startElementBackground(b);
205
- if (c)
206
- Duc.ElementBackground.addContent(b, c);
207
- return Duc.ElementBackground.endElementBackground(b);
208
- }
209
- function writeStylesBase(b, s, usv) {
210
- if (!s)
211
- return null;
212
- const bgArrRaw = s.background;
213
- const stArrRaw = s.stroke;
214
- if (bgArrRaw === undefined || stArrRaw === undefined) {
215
- return null;
216
- }
217
- const bgArr = Array.isArray(bgArrRaw)
218
- ? bgArrRaw
219
- : (bgArrRaw ? [bgArrRaw] : []);
220
- const stArr = Array.isArray(stArrRaw)
221
- ? stArrRaw
222
- : (stArrRaw ? [stArrRaw] : []);
223
- const bgOffsets = bgArr
224
- .map((x) => (x ? writeElementBackground(b, x, usv) : undefined))
225
- .filter((o) => o !== undefined);
226
- const stOffsets = stArr
227
- .map((x) => (x ? writeElementStroke(b, x, usv) : undefined))
228
- .filter((o) => o !== undefined);
229
- const bgs = Duc._DucElementStylesBase.createBackgroundVector(b, bgOffsets);
230
- const strokes = Duc._DucElementStylesBase.createStrokeVector(b, stOffsets);
231
- Duc._DucElementStylesBase.start_DucElementStylesBase(b);
232
- if (s.roundness) {
233
- Duc._DucElementStylesBase.addRoundness(b, getPrecisionValue(s.roundness, usv));
234
- }
235
- if (s.blending)
236
- Duc._DucElementStylesBase.addBlending(b, s.blending);
237
- Duc._DucElementStylesBase.addBackground(b, bgs);
238
- Duc._DucElementStylesBase.addStroke(b, strokes);
239
- if (s.opacity) {
240
- Duc._DucElementStylesBase.addOpacity(b, s.opacity);
241
- }
242
- return Duc._DucElementStylesBase.end_DucElementStylesBase(b);
243
- }
244
- /**
245
- * Generic helpers
246
- */
247
- function writeStringEntry(b, k, v) {
248
- const ko = b.createString(k);
249
- const vo = b.createString(v);
250
- Duc.StringValueEntry.startStringValueEntry(b);
251
- Duc.StringValueEntry.addKey(b, ko);
252
- Duc.StringValueEntry.addValue(b, vo);
253
- return Duc.StringValueEntry.endStringValueEntry(b);
254
- }
255
- function writeIdentifier(b, id) {
256
- var _a;
257
- const io = b.createString(id.id);
258
- const no = b.createString(id.name);
259
- const doff = b.createString((_a = id.description) !== null && _a !== void 0 ? _a : "");
260
- Duc.Identifier.startIdentifier(b);
261
- Duc.Identifier.addId(b, io);
262
- Duc.Identifier.addName(b, no);
263
- Duc.Identifier.addDescription(b, doff);
264
- return Duc.Identifier.endIdentifier(b);
265
- }
266
- /**
267
- * Geometry and bindings
268
- */
269
- function writeDucPoint(b, p, usv) {
270
- if (!p)
271
- return undefined;
272
- Duc.DucPoint.startDucPoint(b);
273
- Duc.DucPoint.addX(b, getPrecisionValue(p.x, usv));
274
- Duc.DucPoint.addY(b, getPrecisionValue(p.y, usv));
275
- if (p.mirroring != null)
276
- Duc.DucPoint.addMirroring(b, p.mirroring);
277
- return Duc.DucPoint.endDucPoint(b);
278
- }
279
- function writeGeomPoint(b, p, usv) {
280
- if (!p)
281
- return undefined;
282
- return Duc.GeometricPoint.createGeometricPoint(b, p.x, p.y);
283
- }
284
- function writeHead(b, h, usv) {
285
- if (!h)
286
- return undefined;
287
- const blockId = str(b, h.blockId);
288
- Duc.DucHead.startDucHead(b);
289
- Duc.DucHead.addType(b, h.type);
290
- if (blockId)
291
- Duc.DucHead.addBlockId(b, blockId);
292
- Duc.DucHead.addSize(b, getPrecisionValue(h.size, usv));
293
- return Duc.DucHead.endDucHead(b);
294
- }
295
- function writeBindingPoint(b, p, usv) {
296
- if (!p)
297
- return undefined;
298
- Duc.PointBindingPoint.startPointBindingPoint(b);
299
- Duc.PointBindingPoint.addIndex(b, p.index);
300
- Duc.PointBindingPoint.addOffset(b, p.offset);
301
- return Duc.PointBindingPoint.endPointBindingPoint(b);
302
- }
303
- function writePointBinding(b, pb, usv) {
304
- if (!pb)
305
- return undefined;
306
- const el = str(b, pb.elementId);
307
- const fixed = pb.fixedPoint ? writeGeomPoint(b, pb.fixedPoint, usv) : undefined;
308
- const point = writeBindingPoint(b, pb.point, usv);
309
- const head = writeHead(b, pb.head, usv);
310
- Duc.DucPointBinding.startDucPointBinding(b);
311
- if (el)
312
- Duc.DucPointBinding.addElementId(b, el);
313
- Duc.DucPointBinding.addFocus(b, pb.focus);
314
- Duc.DucPointBinding.addGap(b, getPrecisionValue(pb.gap, usv));
315
- if (fixed)
316
- Duc.DucPointBinding.addFixedPoint(b, fixed);
317
- if (point)
318
- Duc.DucPointBinding.addPoint(b, point);
319
- if (head)
320
- Duc.DucPointBinding.addHead(b, head);
321
- return Duc.DucPointBinding.endDucPointBinding(b);
322
- }
323
- function writeLineRef(b, r, usv) {
324
- Duc.DucLineReference.startDucLineReference(b);
325
- Duc.DucLineReference.addIndex(b, r.index);
326
- if (r.handle) {
327
- const hx = getPrecisionValue(r.handle.x, usv);
328
- const hy = getPrecisionValue(r.handle.y, usv);
329
- const gp = Duc.GeometricPoint.createGeometricPoint(b, hx, hy);
330
- Duc.DucLineReference.addHandle(b, gp);
331
- }
332
- return Duc.DucLineReference.endDucLineReference(b);
333
- }
334
- function writeLine(b, l, usv) {
335
- const s = writeLineRef(b, l[0], usv);
336
- const e = writeLineRef(b, l[1], usv);
337
- Duc.DucLine.startDucLine(b);
338
- Duc.DucLine.addStart(b, s);
339
- Duc.DucLine.addEnd(b, e);
340
- return Duc.DucLine.endDucLine(b);
341
- }
342
- function writePath(b, p, usv) {
343
- const lineIndices = Duc.DucPath.createLineIndicesVector(b, p.lineIndices.map((x) => x));
344
- const bg = p.background ? writeElementBackground(b, p.background, usv) : undefined;
345
- const st = p.stroke ? writeElementStroke(b, p.stroke, usv) : undefined;
346
- Duc.DucPath.startDucPath(b);
347
- Duc.DucPath.addLineIndices(b, lineIndices);
348
- if (bg)
349
- Duc.DucPath.addBackground(b, bg);
350
- if (st)
351
- Duc.DucPath.addStroke(b, st);
352
- return Duc.DucPath.endDucPath(b);
353
- }
354
- /**
355
- * DucElement bases
356
- */
357
- function writeBoundElement(b, be, usv) {
358
- const id = str(b, be.id);
359
- const type = str(b, be.type);
360
- Duc.BoundElement.startBoundElement(b);
361
- Duc.BoundElement.addId(b, id);
362
- Duc.BoundElement.addType(b, type);
363
- return Duc.BoundElement.endBoundElement(b);
364
- }
365
- function writeElementBase(b, e, usv) {
366
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
367
- const id = str(b, e.id);
368
- const styles = writeStylesBase(b, e, usv);
369
- const scope = str(b, e.scope);
370
- const label = str(b, (_a = e.label) !== null && _a !== void 0 ? _a : undefined);
371
- const desc = str(b, (_b = e.description) !== null && _b !== void 0 ? _b : undefined);
372
- const index = str(b, (_c = e.index) !== null && _c !== void 0 ? _c : undefined);
373
- const groupIds = ((_d = e.groupIds) === null || _d === void 0 ? void 0 : _d.length) ? Duc._DucElementBase.createGroupIdsVector(b, e.groupIds.map((g) => b.createString(g))) : undefined;
374
- const blockIds = ((_e = e.blockIds) === null || _e === void 0 ? void 0 : _e.length) ? Duc._DucElementBase.createBlockIdsVector(b, e.blockIds.map((blockId) => b.createString(blockId))) : undefined;
375
- const regionIds = ((_f = e.regionIds) === null || _f === void 0 ? void 0 : _f.length) ? Duc._DucElementBase.createRegionIdsVector(b, e.regionIds.map((r) => b.createString(r))) : undefined;
376
- const instanceId = str(b, (_g = e.instanceId) !== null && _g !== void 0 ? _g : undefined);
377
- const layerId = str(b, (_h = e.layerId) !== null && _h !== void 0 ? _h : undefined);
378
- const frameId = str(b, (_j = e.frameId) !== null && _j !== void 0 ? _j : undefined);
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;
380
- const link = str(b, (_l = e.link) !== null && _l !== void 0 ? _l : undefined);
381
- const custom = e.customData != null ? Duc._DucElementBase.createCustomDataVector(b, zlibSync(strToU8(JSON.stringify(e.customData)))) : undefined;
382
- Duc._DucElementBase.start_DucElementBase(b);
383
- if (id)
384
- Duc._DucElementBase.addId(b, id);
385
- if (styles)
386
- Duc._DucElementBase.addStyles(b, styles);
387
- Duc._DucElementBase.addX(b, getPrecisionValue(e.x, usv));
388
- Duc._DucElementBase.addY(b, getPrecisionValue(e.y, usv));
389
- Duc._DucElementBase.addWidth(b, getPrecisionValue(e.width, usv));
390
- Duc._DucElementBase.addHeight(b, getPrecisionValue(e.height, usv));
391
- Duc._DucElementBase.addAngle(b, e.angle);
392
- if (scope)
393
- Duc._DucElementBase.addScope(b, scope);
394
- if (label)
395
- Duc._DucElementBase.addLabel(b, label);
396
- if (desc)
397
- Duc._DucElementBase.addDescription(b, desc);
398
- Duc._DucElementBase.addIsVisible(b, e.isVisible);
399
- Duc._DucElementBase.addSeed(b, e.seed);
400
- Duc._DucElementBase.addVersion(b, e.version);
401
- Duc._DucElementBase.addVersionNonce(b, e.versionNonce);
402
- Duc._DucElementBase.addUpdated(b, BigInt(e.updated));
403
- if (index)
404
- Duc._DucElementBase.addIndex(b, index);
405
- Duc._DucElementBase.addIsPlot(b, e.isPlot);
406
- Duc._DucElementBase.addIsAnnotative(b, e.isAnnotative);
407
- Duc._DucElementBase.addIsDeleted(b, e.isDeleted);
408
- if (groupIds)
409
- Duc._DucElementBase.addGroupIds(b, groupIds);
410
- if (blockIds)
411
- Duc._DucElementBase.addBlockIds(b, blockIds);
412
- if (regionIds)
413
- Duc._DucElementBase.addRegionIds(b, regionIds);
414
- if (instanceId)
415
- Duc._DucElementBase.addInstanceId(b, instanceId);
416
- if (layerId)
417
- Duc._DucElementBase.addLayerId(b, layerId);
418
- if (frameId)
419
- Duc._DucElementBase.addFrameId(b, frameId);
420
- if (bound)
421
- Duc._DucElementBase.addBoundElements(b, bound);
422
- Duc._DucElementBase.addZIndex(b, e.zIndex);
423
- if (link)
424
- Duc._DucElementBase.addLink(b, link);
425
- Duc._DucElementBase.addLocked(b, e.locked);
426
- if (custom)
427
- Duc._DucElementBase.addCustomData(b, custom);
428
- return Duc._DucElementBase.end_DucElementBase(b);
429
- }
430
- function writeLinearBase(b, e, usv) {
431
- var _a, _b, _c;
432
- const base = writeElementBase(b, e, usv);
433
- // Type-safe guards without using any: default to empty arrays if undefined
434
- const pointsArr = (_a = e.points) !== null && _a !== void 0 ? _a : [];
435
- const linesArr = (_b = e.lines) !== null && _b !== void 0 ? _b : [];
436
- const pathOverridesArr = (_c = e.pathOverrides) !== null && _c !== void 0 ? _c : [];
437
- const points = Duc._DucLinearElementBase.createPointsVector(b, pointsArr.map((p) => writeDucPoint(b, p, usv)).filter((v) => v !== undefined));
438
- const lines = Duc._DucLinearElementBase.createLinesVector(b, linesArr.map((ln) => writeLine(b, ln, usv)));
439
- const pathOverrides = pathOverridesArr.length
440
- ? Duc._DucLinearElementBase.createPathOverridesVector(b, pathOverridesArr.map((p) => writePath(b, p, usv)))
441
- : undefined;
442
- const lastCommitted = writeDucPoint(b, e.lastCommittedPoint, usv);
443
- const startBinding = writePointBinding(b, e.startBinding, usv);
444
- const endBinding = writePointBinding(b, e.endBinding, usv);
445
- Duc._DucLinearElementBase.start_DucLinearElementBase(b);
446
- Duc._DucLinearElementBase.addBase(b, base);
447
- Duc._DucLinearElementBase.addPoints(b, points);
448
- Duc._DucLinearElementBase.addLines(b, lines);
449
- if (pathOverrides)
450
- Duc._DucLinearElementBase.addPathOverrides(b, pathOverrides);
451
- if (lastCommitted)
452
- Duc._DucLinearElementBase.addLastCommittedPoint(b, lastCommitted);
453
- if (startBinding)
454
- Duc._DucLinearElementBase.addStartBinding(b, startBinding);
455
- if (endBinding)
456
- Duc._DucLinearElementBase.addEndBinding(b, endBinding);
457
- return Duc._DucLinearElementBase.end_DucLinearElementBase(b);
458
- }
459
- /**
460
- * Elements
461
- */
462
- function writeRect(b, e, usv) {
463
- const base = writeElementBase(b, e, usv);
464
- Duc.DucRectangleElement.startDucRectangleElement(b);
465
- Duc.DucRectangleElement.addBase(b, base);
466
- return Duc.DucRectangleElement.endDucRectangleElement(b);
467
- }
468
- function writePolygon(b, e, usv) {
469
- const base = writeElementBase(b, e, usv);
470
- Duc.DucPolygonElement.startDucPolygonElement(b);
471
- Duc.DucPolygonElement.addBase(b, base);
472
- Duc.DucPolygonElement.addSides(b, e.sides);
473
- return Duc.DucPolygonElement.endDucPolygonElement(b);
474
- }
475
- function writeEllipse(b, e, usv) {
476
- const base = writeElementBase(b, e, usv);
477
- Duc.DucEllipseElement.startDucEllipseElement(b);
478
- Duc.DucEllipseElement.addBase(b, base);
479
- Duc.DucEllipseElement.addRatio(b, e.ratio);
480
- Duc.DucEllipseElement.addStartAngle(b, e.startAngle);
481
- Duc.DucEllipseElement.addEndAngle(b, e.endAngle);
482
- Duc.DucEllipseElement.addShowAuxCrosshair(b, e.showAuxCrosshair);
483
- return Duc.DucEllipseElement.endDucEllipseElement(b);
484
- }
485
- function writeLinear(b, e, usv) {
486
- const base = writeLinearBase(b, e, usv);
487
- Duc.DucLinearElement.startDucLinearElement(b);
488
- Duc.DucLinearElement.addLinearBase(b, base);
489
- Duc.DucLinearElement.addWipeoutBelow(b, e.wipeoutBelow);
490
- return Duc.DucLinearElement.endDucLinearElement(b);
491
- }
492
- function writeArrow(b, e, usv) {
493
- const base = writeLinearBase(b, e, usv);
494
- Duc.DucArrowElement.startDucArrowElement(b);
495
- Duc.DucArrowElement.addLinearBase(b, base);
496
- Duc.DucArrowElement.addElbowed(b, e.elbowed);
497
- return Duc.DucArrowElement.endDucArrowElement(b);
498
- }
499
- function writeFreeDrawEnds(b, ends, usv) {
500
- if (!ends)
501
- return undefined;
502
- const easing = str(b, encodeFunctionString(ends.easing));
503
- Duc.DucFreeDrawEnds.startDucFreeDrawEnds(b);
504
- Duc.DucFreeDrawEnds.addCap(b, ends.cap);
505
- Duc.DucFreeDrawEnds.addTaper(b, ends.taper);
506
- if (easing)
507
- Duc.DucFreeDrawEnds.addEasing(b, easing);
508
- return Duc.DucFreeDrawEnds.endDucFreeDrawEnds(b);
509
- }
510
- function writeImageCrop(b, c) {
511
- if (!c)
512
- return undefined;
513
- Duc.ImageCrop.startImageCrop(b);
514
- Duc.ImageCrop.addX(b, c.x);
515
- Duc.ImageCrop.addY(b, c.y);
516
- Duc.ImageCrop.addWidth(b, c.width);
517
- Duc.ImageCrop.addHeight(b, c.height);
518
- Duc.ImageCrop.addNaturalWidth(b, c.naturalWidth);
519
- Duc.ImageCrop.addNaturalHeight(b, c.naturalHeight);
520
- return Duc.ImageCrop.endImageCrop(b);
521
- }
522
- function writeImage(b, e, usv) {
523
- const base = writeElementBase(b, e, usv);
524
- const fileId = str(b, e.fileId);
525
- const scaleVec = e.scaleFlip ? Duc.DucImageElement.createScaleVector(b, [e.scaleFlip[0], e.scaleFlip[1]]) : undefined;
526
- const crop = writeImageCrop(b, e.crop);
527
- const filter = writeImageFilter(b, e.filter, usv);
528
- Duc.DucImageElement.startDucImageElement(b);
529
- Duc.DucImageElement.addBase(b, base);
530
- if (fileId)
531
- Duc.DucImageElement.addFileId(b, fileId);
532
- if (e.status)
533
- Duc.DucImageElement.addStatus(b, e.status);
534
- if (scaleVec)
535
- Duc.DucImageElement.addScale(b, scaleVec);
536
- if (crop)
537
- Duc.DucImageElement.addCrop(b, crop);
538
- if (filter)
539
- Duc.DucImageElement.addFilter(b, filter);
540
- return Duc.DucImageElement.endDucImageElement(b);
541
- }
542
- function writeFreeDraw(b, e, usv) {
543
- const base = writeElementBase(b, e, usv);
544
- const pointsVec = e.points && e.points.length
545
- ? Duc.DucFreeDrawElement.createPointsVector(b, e.points.map((p) => writeDucPoint(b, p, usv)).filter((v) => v !== undefined))
546
- : Duc.DucFreeDrawElement.createPointsVector(b, []);
547
- const pressuresVec = e.pressures && e.pressures.length
548
- ? Duc.DucFreeDrawElement.createPressuresVector(b, e.pressures)
549
- : undefined;
550
- const easing = b.createString(encodeFunctionString(e.easing));
551
- const startEnds = writeFreeDrawEnds(b, e.start, usv);
552
- const endEnds = writeFreeDrawEnds(b, e.end, usv);
553
- const lcp = e.lastCommittedPoint ? writeDucPoint(b, e.lastCommittedPoint, usv) : undefined;
554
- const svgPath = e.svgPath ? b.createString(e.svgPath) : undefined;
555
- Duc.DucFreeDrawElement.startDucFreeDrawElement(b);
556
- Duc.DucFreeDrawElement.addBase(b, base);
557
- Duc.DucFreeDrawElement.addPoints(b, pointsVec);
558
- Duc.DucFreeDrawElement.addSize(b, getPrecisionValue(e.size, usv));
559
- Duc.DucFreeDrawElement.addThinning(b, e.thinning);
560
- Duc.DucFreeDrawElement.addSmoothing(b, e.smoothing);
561
- Duc.DucFreeDrawElement.addStreamline(b, e.streamline);
562
- if (easing)
563
- Duc.DucFreeDrawElement.addEasing(b, easing);
564
- if (startEnds)
565
- Duc.DucFreeDrawElement.addStart(b, startEnds);
566
- if (endEnds)
567
- Duc.DucFreeDrawElement.addEnd(b, endEnds);
568
- if (pressuresVec)
569
- Duc.DucFreeDrawElement.addPressures(b, pressuresVec);
570
- Duc.DucFreeDrawElement.addSimulatePressure(b, !!e.simulatePressure);
571
- if (lcp)
572
- Duc.DucFreeDrawElement.addLastCommittedPoint(b, lcp);
573
- if (svgPath)
574
- Duc.DucFreeDrawElement.addSvgPath(b, svgPath);
575
- return Duc.DucFreeDrawElement.endDucFreeDrawElement(b);
576
- }
577
- /**
578
- * Text
579
- */
580
- function writeLineSpacing(b, ls, usv) {
581
- if (!ls)
582
- return undefined;
583
- Duc.LineSpacing.startLineSpacing(b);
584
- if (typeof ls.value === "number") {
585
- Duc.LineSpacing.addValue(b, ls.value);
586
- }
587
- else {
588
- Duc.LineSpacing.addValue(b, getPrecisionValue(ls.value, usv));
589
- }
590
- Duc.LineSpacing.addType(b, ls.type);
591
- return Duc.LineSpacing.endLineSpacing(b);
592
- }
593
- function writeTextStyle(b, s, usv) {
594
- const lineSpacing = writeLineSpacing(b, s.lineSpacing, usv);
595
- const fontFamily = str(b, s.fontFamily.toString());
596
- const bigFont = str(b, s.bigFontFamily);
597
- Duc.DucTextStyle.startDucTextStyle(b);
598
- Duc.DucTextStyle.addIsLtr(b, s.isLtr);
599
- if (fontFamily)
600
- Duc.DucTextStyle.addFontFamily(b, fontFamily);
601
- if (bigFont)
602
- Duc.DucTextStyle.addBigFontFamily(b, bigFont);
603
- if (s.textAlign !== undefined)
604
- Duc.DucTextStyle.addTextAlign(b, s.textAlign);
605
- if (s.verticalAlign !== undefined)
606
- Duc.DucTextStyle.addVerticalAlign(b, s.verticalAlign);
607
- Duc.DucTextStyle.addLineHeight(b, s.lineHeight);
608
- if (lineSpacing)
609
- Duc.DucTextStyle.addLineSpacing(b, lineSpacing);
610
- Duc.DucTextStyle.addObliqueAngle(b, s.obliqueAngle);
611
- Duc.DucTextStyle.addFontSize(b, getPrecisionValue(s.fontSize, usv));
612
- if (s.paperTextHeight !== undefined)
613
- Duc.DucTextStyle.addPaperTextHeight(b, getPrecisionValue(s.paperTextHeight, usv));
614
- Duc.DucTextStyle.addWidthFactor(b, s.widthFactor);
615
- Duc.DucTextStyle.addIsUpsideDown(b, s.isUpsideDown);
616
- Duc.DucTextStyle.addIsBackwards(b, s.isBackwards);
617
- return Duc.DucTextStyle.endDucTextStyle(b);
618
- }
619
- function writePrimaryUnits(b, units, usv) {
620
- if (!units)
621
- return undefined;
622
- // Linear
623
- Duc._UnitSystemBase.start_UnitSystemBase(b);
624
- Duc._UnitSystemBase.addSystem(b, units.linear.system);
625
- Duc._UnitSystemBase.addPrecision(b, units.linear.precision);
626
- Duc._UnitSystemBase.addSuppressLeadingZeros(b, units.linear.suppressLeadingZeros);
627
- Duc._UnitSystemBase.addSuppressTrailingZeros(b, units.linear.suppressTrailingZeros);
628
- const baseLinear = Duc._UnitSystemBase.end_UnitSystemBase(b);
629
- Duc.LinearUnitSystem.startLinearUnitSystem(b);
630
- Duc.LinearUnitSystem.addBase(b, baseLinear);
631
- Duc.LinearUnitSystem.addFormat(b, units.linear.format);
632
- Duc.LinearUnitSystem.addDecimalSeparator(b, units.linear.decimalSeparator);
633
- Duc.LinearUnitSystem.addSuppressZeroFeet(b, units.linear.suppressZeroFeet);
634
- Duc.LinearUnitSystem.addSuppressZeroInches(b, units.linear.suppressZeroInches);
635
- const linear = Duc.LinearUnitSystem.endLinearUnitSystem(b);
636
- // Angular
637
- Duc._UnitSystemBase.start_UnitSystemBase(b);
638
- Duc._UnitSystemBase.addSystem(b, units.angular.system);
639
- Duc._UnitSystemBase.addPrecision(b, units.angular.precision);
640
- Duc._UnitSystemBase.addSuppressLeadingZeros(b, units.angular.suppressLeadingZeros);
641
- Duc._UnitSystemBase.addSuppressTrailingZeros(b, units.angular.suppressTrailingZeros);
642
- const baseAngular = Duc._UnitSystemBase.end_UnitSystemBase(b);
643
- Duc.AngularUnitSystem.startAngularUnitSystem(b);
644
- Duc.AngularUnitSystem.addBase(b, baseAngular);
645
- Duc.AngularUnitSystem.addFormat(b, units.angular.format);
646
- const angular = Duc.AngularUnitSystem.endAngularUnitSystem(b);
647
- Duc.PrimaryUnits.startPrimaryUnits(b);
648
- Duc.PrimaryUnits.addLinear(b, linear);
649
- Duc.PrimaryUnits.addAngular(b, angular);
650
- return Duc.PrimaryUnits.endPrimaryUnits(b);
651
- }
652
- function writeTextDynamicSource(b, s, usv) {
653
- // discriminate by sourceType union ("element" | "dictionary")
654
- if (s.sourceType === Duc.TEXT_FIELD_SOURCE_TYPE.ELEMENT) {
655
- const el = str(b, s.elementId);
656
- const prop = s.property;
657
- Duc.DucTextDynamicElementSource.startDucTextDynamicElementSource(b);
658
- if (el)
659
- Duc.DucTextDynamicElementSource.addElementId(b, el);
660
- Duc.DucTextDynamicElementSource.addProperty(b, prop);
661
- const elem = Duc.DucTextDynamicElementSource.endDucTextDynamicElementSource(b);
662
- Duc.DucTextDynamicSource.startDucTextDynamicSource(b);
663
- Duc.DucTextDynamicSource.addTextSourceType(b, Duc.TEXT_FIELD_SOURCE_TYPE.ELEMENT);
664
- Duc.DucTextDynamicSource.addSourceType(b, Duc.DucTextDynamicSourceData.DucTextDynamicElementSource);
665
- Duc.DucTextDynamicSource.addSource(b, elem);
666
- return Duc.DucTextDynamicSource.endDucTextDynamicSource(b);
667
- }
668
- const key = str(b, s.key);
669
- Duc.DucTextDynamicDictionarySource.startDucTextDynamicDictionarySource(b);
670
- if (key)
671
- Duc.DucTextDynamicDictionarySource.addKey(b, key);
672
- const dict = Duc.DucTextDynamicDictionarySource.endDucTextDynamicDictionarySource(b);
673
- Duc.DucTextDynamicSource.startDucTextDynamicSource(b);
674
- Duc.DucTextDynamicSource.addTextSourceType(b, Duc.TEXT_FIELD_SOURCE_TYPE.DICTIONARY);
675
- Duc.DucTextDynamicSource.addSourceType(b, Duc.DucTextDynamicSourceData.DucTextDynamicDictionarySource);
676
- Duc.DucTextDynamicSource.addSource(b, dict);
677
- return Duc.DucTextDynamicSource.endDucTextDynamicSource(b);
678
- }
679
- function writeTextDynamicPart(b, p, usv) {
680
- const tag = str(b, p.tag);
681
- const src = writeTextDynamicSource(b, p.source, usv);
682
- const fmt = writePrimaryUnits(b, p.formatting, usv);
683
- const cached = str(b, p.cachedValue);
684
- Duc.DucTextDynamicPart.startDucTextDynamicPart(b);
685
- if (tag)
686
- Duc.DucTextDynamicPart.addTag(b, tag);
687
- Duc.DucTextDynamicPart.addSource(b, src);
688
- if (fmt)
689
- Duc.DucTextDynamicPart.addFormatting(b, fmt);
690
- if (cached)
691
- Duc.DucTextDynamicPart.addCachedValue(b, cached);
692
- return Duc.DucTextDynamicPart.endDucTextDynamicPart(b);
693
- }
694
- function writeTextColumn(b, c, usv) {
695
- Duc.TextColumn.startTextColumn(b);
696
- Duc.TextColumn.addWidth(b, getPrecisionValue(c.width, usv));
697
- Duc.TextColumn.addGutter(b, getPrecisionValue(c.gutter, usv));
698
- return Duc.TextColumn.endTextColumn(b);
699
- }
700
- function writeParagraphFormatting(b, p, usv) {
701
- const tabs = Duc.ParagraphFormatting.createTabStopsVector(b, p.tabStops.map((t) => getPrecisionValue(t, usv)));
702
- Duc.ParagraphFormatting.startParagraphFormatting(b);
703
- Duc.ParagraphFormatting.addFirstLineIndent(b, getPrecisionValue(p.firstLineIndent, usv));
704
- Duc.ParagraphFormatting.addHangingIndent(b, getPrecisionValue(p.hangingIndent, usv));
705
- Duc.ParagraphFormatting.addLeftIndent(b, getPrecisionValue(p.leftIndent, usv));
706
- Duc.ParagraphFormatting.addRightIndent(b, getPrecisionValue(p.rightIndent, usv));
707
- Duc.ParagraphFormatting.addSpaceBefore(b, getPrecisionValue(p.spaceBefore, usv));
708
- Duc.ParagraphFormatting.addSpaceAfter(b, getPrecisionValue(p.spaceAfter, usv));
709
- Duc.ParagraphFormatting.addTabStops(b, tabs);
710
- return Duc.ParagraphFormatting.endParagraphFormatting(b);
711
- }
712
- function writeStackFormat(b, s, usv) {
713
- const chars = Duc.StackFormat.createStackCharsVector(b, [...s.stackChars].map((c) => b.createString(c)));
714
- Duc.StackFormatProperties.startStackFormatProperties(b);
715
- Duc.StackFormatProperties.addUpperScale(b, s.properties.upperScale);
716
- Duc.StackFormatProperties.addLowerScale(b, s.properties.lowerScale);
717
- Duc.StackFormatProperties.addAlignment(b, s.properties.alignment);
718
- const props = Duc.StackFormatProperties.endStackFormatProperties(b);
719
- Duc.StackFormat.startStackFormat(b);
720
- Duc.StackFormat.addAutoStack(b, s.autoStack);
721
- Duc.StackFormat.addStackChars(b, chars);
722
- Duc.StackFormat.addProperties(b, props);
723
- return Duc.StackFormat.endStackFormat(b);
724
- }
725
- function writeDocStyle(b, s, usv) {
726
- const text = writeTextStyle(b, s, usv);
727
- const para = writeParagraphFormatting(b, s.paragraph, usv);
728
- const stack = writeStackFormat(b, s.stackFormat, usv);
729
- Duc.DucDocStyle.startDucDocStyle(b);
730
- Duc.DucDocStyle.addTextStyle(b, text);
731
- Duc.DucDocStyle.addParagraph(b, para);
732
- Duc.DucDocStyle.addStackFormat(b, stack);
733
- return Duc.DucDocStyle.endDucDocStyle(b);
734
- }
735
- function writeColumnLayout(b, c, usv) {
736
- const defs = Duc.ColumnLayout.createDefinitionsVector(b, c.definitions.map((d) => writeTextColumn(b, d, usv)));
737
- Duc.ColumnLayout.startColumnLayout(b);
738
- Duc.ColumnLayout.addType(b, c.type);
739
- Duc.ColumnLayout.addDefinitions(b, defs);
740
- Duc.ColumnLayout.addAutoHeight(b, c.autoHeight);
741
- return Duc.ColumnLayout.endColumnLayout(b);
742
- }
743
- function writeDocumentGridConfig(b, config, usv) {
744
- Duc.DocumentGridConfig.startDocumentGridConfig(b);
745
- Duc.DocumentGridConfig.addColumns(b, config.columns);
746
- Duc.DocumentGridConfig.addGapX(b, config.gapX);
747
- Duc.DocumentGridConfig.addGapY(b, config.gapY);
748
- const alignItems = (() => {
749
- if (config.alignItems === 'start')
750
- return Duc.DOCUMENT_GRID_ALIGN_ITEMS.START;
751
- if (config.alignItems === 'center')
752
- return Duc.DOCUMENT_GRID_ALIGN_ITEMS.CENTER;
753
- if (config.alignItems === 'end')
754
- return Duc.DOCUMENT_GRID_ALIGN_ITEMS.END;
755
- return Duc.DOCUMENT_GRID_ALIGN_ITEMS.START;
756
- })();
757
- Duc.DocumentGridConfig.addAlignItems(b, alignItems);
758
- Duc.DocumentGridConfig.addFirstPageAlone(b, config.firstPageAlone);
759
- return Duc.DocumentGridConfig.endDocumentGridConfig(b);
760
- }
761
- function writeText(b, e, usv) {
11
+ import { transformToRust } from "./transform";
12
+ import { ensureWasm, wasmGetCurrentSchemaVersion, wasmSerializeDuc } from "./wasm";
13
+ const getSchemaVersionFromEnv = () => {
762
14
  var _a;
763
- const base = writeElementBase(b, e, usv);
764
- const style = writeTextStyle(b, e, usv);
765
- const text = str(b, e.text);
766
- const dynamic = Duc.DucTextElement.createDynamicVector(b, e.dynamic.map((d) => writeTextDynamicPart(b, d, usv)));
767
- const containerId = str(b, (_a = e.containerId) !== null && _a !== void 0 ? _a : undefined);
768
- const original = str(b, e.originalText);
769
- Duc.DucTextElement.startDucTextElement(b);
770
- Duc.DucTextElement.addBase(b, base);
771
- Duc.DucTextElement.addStyle(b, style);
772
- if (text)
773
- Duc.DucTextElement.addText(b, text);
774
- Duc.DucTextElement.addDynamic(b, dynamic);
775
- Duc.DucTextElement.addAutoResize(b, e.autoResize);
776
- if (containerId)
777
- Duc.DucTextElement.addContainerId(b, containerId);
778
- if (original)
779
- Duc.DucTextElement.addOriginalText(b, original);
780
- return Duc.DucTextElement.endDucTextElement(b);
781
- }
782
- /**
783
- * Blocks
784
- */
785
- function writeBlockAttrDef(b, d, usv) {
786
- const tag = b.createString(d.tag);
787
- const prompt = b.createString(d.prompt);
788
- const defVal = b.createString(d.defaultValue);
789
- Duc.DucBlockAttributeDefinition.startDucBlockAttributeDefinition(b);
790
- Duc.DucBlockAttributeDefinition.addTag(b, tag);
791
- Duc.DucBlockAttributeDefinition.addPrompt(b, prompt);
792
- Duc.DucBlockAttributeDefinition.addDefaultValue(b, defVal);
793
- Duc.DucBlockAttributeDefinition.addIsConstant(b, d.isConstant);
794
- return Duc.DucBlockAttributeDefinition.endDucBlockAttributeDefinition(b);
795
- }
796
- function writeBlockMetadata(b, metadata) {
797
- const source = b.createString(metadata.source);
798
- const localization = metadata.localization ? Duc.DucBlockMetadata.createLocalizationVector(b, zlibSync(strToU8(JSON.stringify(metadata.localization)))) : undefined;
799
- Duc.DucBlockMetadata.startDucBlockMetadata(b);
800
- Duc.DucBlockMetadata.addSource(b, source);
801
- Duc.DucBlockMetadata.addUsageCount(b, metadata.usageCount);
802
- Duc.DucBlockMetadata.addCreatedAt(b, BigInt(metadata.createdAt));
803
- Duc.DucBlockMetadata.addUpdatedAt(b, BigInt(metadata.updatedAt));
804
- if (localization) {
805
- Duc.DucBlockMetadata.addLocalization(b, localization);
806
- }
807
- return Duc.DucBlockMetadata.endDucBlockMetadata(b);
808
- }
809
- function writeBlock(b, bl, usv) {
810
- var _a, _b;
811
- const id = b.createString(bl.id);
812
- const label = b.createString(bl.label);
813
- const desc = b.createString((_a = bl.description) !== null && _a !== void 0 ? _a : "");
814
- const defs = Duc.DucBlock.createAttributeDefinitionsVector(b, Object.entries((_b = bl.attributeDefinitions) !== null && _b !== void 0 ? _b : {}).map(([k, v]) => {
815
- const key = b.createString(k);
816
- const val = writeBlockAttrDef(b, v, usv);
817
- Duc.DucBlockAttributeDefinitionEntry.startDucBlockAttributeDefinitionEntry(b);
818
- Duc.DucBlockAttributeDefinitionEntry.addKey(b, key);
819
- Duc.DucBlockAttributeDefinitionEntry.addValue(b, val);
820
- return Duc.DucBlockAttributeDefinitionEntry.endDucBlockAttributeDefinitionEntry(b);
821
- }));
822
- // Write metadata if present
823
- let metadataOffset;
824
- if (bl.metadata) {
825
- metadataOffset = writeBlockMetadata(b, bl.metadata);
826
- }
827
- // Write thumbnail if present
828
- let thumbnailOffset;
829
- if (bl.thumbnail && bl.thumbnail.length > 0) {
830
- thumbnailOffset = Duc.DucBlock.createThumbnailVector(b, bl.thumbnail);
831
- }
832
- Duc.DucBlock.startDucBlock(b);
833
- Duc.DucBlock.addId(b, id);
834
- Duc.DucBlock.addLabel(b, label);
835
- Duc.DucBlock.addDescription(b, desc);
836
- Duc.DucBlock.addVersion(b, bl.version);
837
- Duc.DucBlock.addAttributeDefinitions(b, defs);
838
- if (metadataOffset) {
839
- Duc.DucBlock.addMetadata(b, metadataOffset);
840
- }
841
- if (thumbnailOffset) {
842
- Duc.DucBlock.addThumbnail(b, thumbnailOffset);
843
- }
844
- return Duc.DucBlock.endDucBlock(b);
845
- }
846
- function writeBlockInstance(b, i, usv) {
847
- var _a, _b;
848
- const id = b.createString(i.id);
849
- const blockId = b.createString(i.blockId);
850
- const overrides = Duc.DucBlockInstance.createElementOverridesVector(b, Object.entries((_a = i.elementOverrides) !== null && _a !== void 0 ? _a : {}).map(([k, v]) => writeStringEntry(b, k, v)));
851
- const attrs = Duc.DucBlockInstance.createAttributeValuesVector(b, Object.entries((_b = i.attributeValues) !== null && _b !== void 0 ? _b : {}).map(([k, v]) => writeStringEntry(b, k, v)));
852
- const dup = i.duplicationArray
853
- ? (() => {
854
- Duc.DucBlockDuplicationArray.startDucBlockDuplicationArray(b);
855
- Duc.DucBlockDuplicationArray.addRows(b, i.duplicationArray.rows);
856
- Duc.DucBlockDuplicationArray.addCols(b, i.duplicationArray.cols);
857
- const rSpacing = typeof i.duplicationArray.rowSpacing === 'number'
858
- ? i.duplicationArray.rowSpacing
859
- : getPrecisionValue(i.duplicationArray.rowSpacing, usv);
860
- const cSpacing = typeof i.duplicationArray.colSpacing === 'number'
861
- ? i.duplicationArray.colSpacing
862
- : getPrecisionValue(i.duplicationArray.colSpacing, usv);
863
- Duc.DucBlockDuplicationArray.addRowSpacing(b, rSpacing);
864
- Duc.DucBlockDuplicationArray.addColSpacing(b, cSpacing);
865
- return Duc.DucBlockDuplicationArray.endDucBlockDuplicationArray(b);
866
- })()
867
- : undefined;
868
- Duc.DucBlockInstance.startDucBlockInstance(b);
869
- Duc.DucBlockInstance.addId(b, id);
870
- Duc.DucBlockInstance.addBlockId(b, blockId);
871
- Duc.DucBlockInstance.addVersion(b, i.version);
872
- if (overrides)
873
- Duc.DucBlockInstance.addElementOverrides(b, overrides);
874
- if (attrs)
875
- Duc.DucBlockInstance.addAttributeValues(b, attrs);
876
- if (dup)
877
- Duc.DucBlockInstance.addDuplicationArray(b, dup);
878
- return Duc.DucBlockInstance.endDucBlockInstance(b);
879
- }
880
- function writeBlockCollection(b, c) {
881
- const id = b.createString(c.id);
882
- const label = b.createString(c.label);
883
- // Serialize children array
884
- const children = c.children.map(child => {
885
- const childId = b.createString(child.id);
886
- Duc.DucBlockCollectionEntry.startDucBlockCollectionEntry(b);
887
- Duc.DucBlockCollectionEntry.addId(b, childId);
888
- Duc.DucBlockCollectionEntry.addIsCollection(b, child.isCollection);
889
- return Duc.DucBlockCollectionEntry.endDucBlockCollectionEntry(b);
15
+ const maybeProcess = globalThis.process;
16
+ return (_a = maybeProcess === null || maybeProcess === void 0 ? void 0 : maybeProcess.env) === null || _a === void 0 ? void 0 : _a.DUC_SCHEMA_VERSION;
17
+ };
18
+ const decodeUserVersionToSemver = (userVersion) => {
19
+ const major = Math.floor(userVersion / 1000000);
20
+ const minor = Math.floor((userVersion % 1000000) / 1000);
21
+ const patch = userVersion % 1000;
22
+ return `${major}.${minor}.${patch}`;
23
+ };
24
+ export const DUC_SCHEMA_VERSION = getSchemaVersionFromEnv();
25
+ /**
26
+ * Serialize an ExportedDataState into `.duc` bytes (Uint8Array).
27
+ *
28
+ * 1. restore() for defaults & migrations
29
+ * 2. Element fixups (re-wrap stack elements)
30
+ * 3. WASM serialize (JS → Rust via serde-wasm-bindgen → SQLite → bytes)
31
+ */
32
+ export function serializeDuc(data, elementsConfig, restoreConfig) {
33
+ return __awaiter(this, void 0, void 0, function* () {
34
+ var _a, _b, _c, _d;
35
+ yield ensureWasm();
36
+ const restored = restore(data, elementsConfig !== null && elementsConfig !== void 0 ? elementsConfig : { syncInvalidIndices: (els) => els }, restoreConfig);
37
+ const shouldDropLegacyVersionGraph = hasLegacyVersionGraphShape(data === null || data === void 0 ? void 0 : data.versionGraph);
38
+ const payloadForRust = Object.assign(Object.assign({ type: (_a = data.type) !== null && _a !== void 0 ? _a : "duc", version: (_c = (_b = data.version) !== null && _b !== void 0 ? _b : DUC_SCHEMA_VERSION) !== null && _c !== void 0 ? _c : decodeUserVersionToSemver(wasmGetCurrentSchemaVersion()), source: (_d = data.source) !== null && _d !== void 0 ? _d : "ducjs" }, restored), { versionGraph: shouldDropLegacyVersionGraph
39
+ ? undefined
40
+ : restored.versionGraph });
41
+ const prepared = transformToRust(payloadForRust);
42
+ return wasmSerializeDuc(prepared);
890
43
  });
891
- const childrenOffset = Duc.DucBlockCollection.createChildrenVector(b, children);
892
- // Serialize metadata if present
893
- let metadataOffset;
894
- if (c.metadata) {
895
- const metadata = c.metadata;
896
- let localizationOffset;
897
- if (metadata.localization) {
898
- // localization is stored as compressed binary JSON data
899
- const localizationBin = zlibSync(strToU8(JSON.stringify(metadata.localization)));
900
- localizationOffset = Duc.DucBlockMetadata.createLocalizationVector(b, localizationBin);
901
- }
902
- const source = b.createString(metadata.source);
903
- Duc.DucBlockMetadata.startDucBlockMetadata(b);
904
- Duc.DucBlockMetadata.addSource(b, source);
905
- Duc.DucBlockMetadata.addUsageCount(b, metadata.usageCount);
906
- // Convert to BigInt as expected by FlatBuffers
907
- Duc.DucBlockMetadata.addCreatedAt(b, BigInt(metadata.createdAt));
908
- Duc.DucBlockMetadata.addUpdatedAt(b, BigInt(metadata.updatedAt));
909
- if (localizationOffset)
910
- Duc.DucBlockMetadata.addLocalization(b, localizationOffset);
911
- metadataOffset = Duc.DucBlockMetadata.endDucBlockMetadata(b);
912
- }
913
- // Serialize thumbnail if present
914
- let thumbnailOffset;
915
- if (c.thumbnail) {
916
- thumbnailOffset = b.createByteVector(c.thumbnail);
917
- }
918
- Duc.DucBlockCollection.startDucBlockCollection(b);
919
- Duc.DucBlockCollection.addId(b, id);
920
- Duc.DucBlockCollection.addLabel(b, label);
921
- Duc.DucBlockCollection.addChildren(b, childrenOffset);
922
- if (metadataOffset)
923
- Duc.DucBlockCollection.addMetadata(b, metadataOffset);
924
- if (thumbnailOffset)
925
- Duc.DucBlockCollection.addThumbnail(b, thumbnailOffset);
926
- return Duc.DucBlockCollection.endDucBlockCollection(b);
927
- }
928
- /**
929
- * Stack containers
930
- */
931
- function writeStackLikeStyles(b, s, usv) {
932
- const color = b.createString(s.labelingColor);
933
- Duc.DucStackLikeStyles.startDucStackLikeStyles(b);
934
- Duc.DucStackLikeStyles.addOpacity(b, s.opacity);
935
- Duc.DucStackLikeStyles.addLabelingColor(b, color);
936
- return Duc.DucStackLikeStyles.endDucStackLikeStyles(b);
937
- }
938
- function writeStackBase(b, s, usv) {
939
- var _a;
940
- const label = b.createString(s.label);
941
- const desc = str(b, (_a = s.description) !== null && _a !== void 0 ? _a : undefined);
942
- const styles = writeStackLikeStyles(b, s, usv);
943
- Duc._DucStackBase.start_DucStackBase(b);
944
- Duc._DucStackBase.addLabel(b, label);
945
- if (desc)
946
- Duc._DucStackBase.addDescription(b, desc);
947
- Duc._DucStackBase.addIsCollapsed(b, s.isCollapsed);
948
- Duc._DucStackBase.addIsPlot(b, s.isPlot);
949
- Duc._DucStackBase.addIsVisible(b, s.isVisible);
950
- Duc._DucStackBase.addLocked(b, s.locked);
951
- Duc._DucStackBase.addStyles(b, styles);
952
- return Duc._DucStackBase.end_DucStackBase(b);
953
- }
954
- function writeStackElementBase(b, s, usv) {
955
- const base = writeElementBase(b, s, usv);
956
- const stackBase = writeStackBase(b, s, usv);
957
- const std = str(b, s.standardOverride);
958
- Duc._DucStackElementBase.start_DucStackElementBase(b);
959
- Duc._DucStackElementBase.addBase(b, base);
960
- Duc._DucStackElementBase.addStackBase(b, stackBase);
961
- Duc._DucStackElementBase.addClip(b, s.clip);
962
- Duc._DucStackElementBase.addLabelVisible(b, s.labelVisible);
963
- if (std)
964
- Duc._DucStackElementBase.addStandardOverride(b, std);
965
- return Duc._DucStackElementBase.end_DucStackElementBase(b);
966
- }
967
- function writeFrame(b, e, usv) {
968
- const base = writeStackElementBase(b, e, usv);
969
- Duc.DucFrameElement.startDucFrameElement(b);
970
- Duc.DucFrameElement.addStackElementBase(b, base);
971
- return Duc.DucFrameElement.endDucFrameElement(b);
972
- }
973
- function writePlotLayout(b, l, usv) {
974
- Duc.Margins.startMargins(b);
975
- Duc.Margins.addTop(b, getPrecisionValue(l.margins.top, usv));
976
- Duc.Margins.addRight(b, getPrecisionValue(l.margins.right, usv));
977
- Duc.Margins.addBottom(b, getPrecisionValue(l.margins.bottom, usv));
978
- Duc.Margins.addLeft(b, getPrecisionValue(l.margins.left, usv));
979
- const margins = Duc.Margins.endMargins(b);
980
- Duc.PlotLayout.startPlotLayout(b);
981
- Duc.PlotLayout.addMargins(b, margins);
982
- return Duc.PlotLayout.endPlotLayout(b);
983
- }
984
- function writePlot(b, e, usv) {
985
- const stackBase = writeStackElementBase(b, e, usv);
986
- const plotStyle = (() => {
987
- Duc.DucPlotStyle.startDucPlotStyle(b);
988
- return Duc.DucPlotStyle.endDucPlotStyle(b);
989
- })();
990
- const layout = writePlotLayout(b, e.layout, usv);
991
- Duc.DucPlotElement.startDucPlotElement(b);
992
- Duc.DucPlotElement.addStackElementBase(b, stackBase);
993
- Duc.DucPlotElement.addStyle(b, plotStyle);
994
- Duc.DucPlotElement.addLayout(b, layout);
995
- return Duc.DucPlotElement.endDucPlotElement(b);
996
- }
997
- /**
998
- * Views / Viewports / XRay
999
- */
1000
- function writeView(b, v, usv) {
1001
- const center = writeDucPoint(b, v.centerPoint, usv);
1002
- const scope = b.createString(v.scope);
1003
- Duc.DucView.startDucView(b);
1004
- Duc.DucView.addScrollX(b, getPrecisionValue(v.scrollX, usv));
1005
- Duc.DucView.addScrollY(b, getPrecisionValue(v.scrollY, usv));
1006
- Duc.DucView.addZoom(b, v.zoom.value);
1007
- Duc.DucView.addTwistAngle(b, v.twistAngle);
1008
- if (center)
1009
- Duc.DucView.addCenterPoint(b, center);
1010
- Duc.DucView.addScope(b, scope);
1011
- return Duc.DucView.endDucView(b);
1012
- }
1013
- function writeViewportStyle(b, s, usv) {
1014
- Duc.DucViewportStyle.startDucViewportStyle(b);
1015
- Duc.DucViewportStyle.addScaleIndicatorVisible(b, s.scaleIndicatorVisible);
1016
- return Duc.DucViewportStyle.endDucViewportStyle(b);
1017
- }
1018
- function writeViewport(b, e, usv) {
1019
- var _a;
1020
- const linear = writeLinearBase(b, e, usv);
1021
- const stackBase = writeStackBase(b, e, usv);
1022
- const style = writeViewportStyle(b, e, usv);
1023
- const view = writeView(b, e.view, usv);
1024
- const frozen = ((_a = e.frozenGroupIds) === null || _a === void 0 ? void 0 : _a.length) ? Duc.DucViewportElement.createFrozenGroupIdsVector(b, e.frozenGroupIds.map((id) => b.createString(id))) : undefined;
1025
- const std = str(b, e.standardOverride);
1026
- Duc.DucViewportElement.startDucViewportElement(b);
1027
- Duc.DucViewportElement.addLinearBase(b, linear);
1028
- Duc.DucViewportElement.addStackBase(b, stackBase);
1029
- Duc.DucViewportElement.addStyle(b, style);
1030
- Duc.DucViewportElement.addView(b, view);
1031
- Duc.DucViewportElement.addScale(b, e.scale);
1032
- if (e.shadePlot !== undefined)
1033
- Duc.DucViewportElement.addShadePlot(b, e.shadePlot);
1034
- if (frozen)
1035
- Duc.DucViewportElement.addFrozenGroupIds(b, frozen);
1036
- if (std)
1037
- Duc.DucViewportElement.addStandardOverride(b, std);
1038
- return Duc.DucViewportElement.endDucViewportElement(b);
1039
- }
1040
- function writeXRayStyle(b, s, usv) {
1041
- const color = b.createString(s.color);
1042
- Duc.DucXRayStyle.startDucXRayStyle(b);
1043
- Duc.DucXRayStyle.addColor(b, color);
1044
- return Duc.DucXRayStyle.endDucXRayStyle(b);
1045
- }
1046
- function writeXRay(b, e, usv) {
1047
- const base = writeElementBase(b, e, usv);
1048
- const style = writeXRayStyle(b, e, usv);
1049
- const origin = writeDucPoint(b, e.origin, usv);
1050
- const direction = writeDucPoint(b, e.direction, usv);
1051
- Duc.DucXRayElement.startDucXRayElement(b);
1052
- Duc.DucXRayElement.addBase(b, base);
1053
- Duc.DucXRayElement.addStyle(b, style);
1054
- if (origin)
1055
- Duc.DucXRayElement.addOrigin(b, origin);
1056
- if (direction)
1057
- Duc.DucXRayElement.addDirection(b, direction);
1058
- Duc.DucXRayElement.addStartFromOrigin(b, e.startFromOrigin);
1059
- return Duc.DucXRayElement.endDucXRayElement(b);
1060
- }
1061
- /**
1062
- * Leader & Dimension & FCF
1063
- */
1064
- function writeLeaderContent(b, c, usv) {
1065
- var _a, _b;
1066
- if (!c)
1067
- return undefined;
1068
- let contentOffset;
1069
- let contentType;
1070
- if (c.type === "text") {
1071
- const text = b.createString(c.text);
1072
- Duc.LeaderTextBlockContent.startLeaderTextBlockContent(b);
1073
- Duc.LeaderTextBlockContent.addText(b, text);
1074
- contentOffset = Duc.LeaderTextBlockContent.endLeaderTextBlockContent(b);
1075
- contentType = Duc.LeaderContentData.LeaderTextBlockContent;
1076
- }
1077
- else {
1078
- const attrs = Duc.LeaderBlockContent.createAttributeValuesVector(b, Object.entries((_a = c.instanceData.attributeValues) !== null && _a !== void 0 ? _a : {}).map(([k, v]) => writeStringEntry(b, k, v)));
1079
- const overrides = Duc.LeaderBlockContent.createElementOverridesVector(b, Object.entries((_b = c.instanceData.elementOverrides) !== null && _b !== void 0 ? _b : {}).map(([k, v]) => writeStringEntry(b, k, v)));
1080
- const blockId = b.createString(c.blockId);
1081
- Duc.LeaderBlockContent.startLeaderBlockContent(b);
1082
- Duc.LeaderBlockContent.addBlockId(b, blockId);
1083
- if (attrs)
1084
- Duc.LeaderBlockContent.addAttributeValues(b, attrs);
1085
- if (overrides)
1086
- Duc.LeaderBlockContent.addElementOverrides(b, overrides);
1087
- contentOffset = Duc.LeaderBlockContent.endLeaderBlockContent(b);
1088
- contentType = Duc.LeaderContentData.LeaderBlockContent;
1089
- }
1090
- Duc.LeaderContent.startLeaderContent(b);
1091
- Duc.LeaderContent.addLeaderContentType(b, Duc.LEADER_CONTENT_TYPE[c.type.toUpperCase()]);
1092
- Duc.LeaderContent.addContentType(b, contentType);
1093
- Duc.LeaderContent.addContent(b, contentOffset);
1094
- return Duc.LeaderContent.endLeaderContent(b);
1095
- }
1096
- function writeLeaderStyle(b, s, usv) {
1097
- const text = writeTextStyle(b, s.textStyle, usv);
1098
- const heads = s.headsOverride ? Duc.DucLeaderStyle.createHeadsOverrideVector(b, s.headsOverride.map((h) => writeHead(b, h, usv))) : undefined;
1099
- Duc.DucLeaderStyle.startDucLeaderStyle(b);
1100
- if (heads)
1101
- Duc.DucLeaderStyle.addHeadsOverride(b, heads);
1102
- if (s.dogleg !== undefined)
1103
- Duc.DucLeaderStyle.addDogleg(b, getPrecisionValue(s.dogleg, usv));
1104
- Duc.DucLeaderStyle.addTextStyle(b, text);
1105
- if (s.textAttachment !== undefined)
1106
- Duc.DucLeaderStyle.addTextAttachment(b, s.textAttachment);
1107
- if (s.blockAttachment !== undefined)
1108
- Duc.DucLeaderStyle.addBlockAttachment(b, s.blockAttachment);
1109
- return Duc.DucLeaderStyle.endDucLeaderStyle(b);
1110
- }
1111
- function writeLeader(b, e, usv) {
1112
- const linear = writeLinearBase(b, e, usv);
1113
- const style = writeLeaderStyle(b, e, usv);
1114
- const content = writeLeaderContent(b, e.leaderContent, usv);
1115
- const anchor = writeGeomPoint(b, e.contentAnchor, usv);
1116
- Duc.DucLeaderElement.startDucLeaderElement(b);
1117
- Duc.DucLeaderElement.addLinearBase(b, linear);
1118
- Duc.DucLeaderElement.addStyle(b, style);
1119
- if (content)
1120
- Duc.DucLeaderElement.addContent(b, content);
1121
- if (anchor)
1122
- Duc.DucLeaderElement.addContentAnchor(b, anchor);
1123
- return Duc.DucLeaderElement.endDucLeaderElement(b);
1124
- }
1125
- function writeDimDefPoints(b, d, usv) {
1126
- const o1 = writeGeomPoint(b, d.origin1, usv);
1127
- const o2 = d.origin2 ? writeGeomPoint(b, d.origin2, usv) : undefined;
1128
- const loc = writeGeomPoint(b, d.location, usv);
1129
- const center = d.center ? writeGeomPoint(b, d.center, usv) : undefined;
1130
- const jog = d.jog ? writeGeomPoint(b, d.jog, usv) : undefined;
1131
- Duc.DimensionDefinitionPoints.startDimensionDefinitionPoints(b);
1132
- if (o1)
1133
- Duc.DimensionDefinitionPoints.addOrigin1(b, o1);
1134
- if (o2)
1135
- Duc.DimensionDefinitionPoints.addOrigin2(b, o2);
1136
- if (loc)
1137
- Duc.DimensionDefinitionPoints.addLocation(b, loc);
1138
- if (center)
1139
- Duc.DimensionDefinitionPoints.addCenter(b, center);
1140
- if (jog)
1141
- Duc.DimensionDefinitionPoints.addJog(b, jog);
1142
- return Duc.DimensionDefinitionPoints.endDimensionDefinitionPoints(b);
1143
- }
1144
- function writeDimBindings(b, d, usv) {
1145
- if (!d)
1146
- return undefined;
1147
- const o1 = d.origin1 ? writePointBinding(b, d.origin1, usv) : undefined;
1148
- const o2 = d.origin2 ? writePointBinding(b, d.origin2, usv) : undefined;
1149
- const c = d.center ? writePointBinding(b, d.center, usv) : undefined;
1150
- Duc.DimensionBindings.startDimensionBindings(b);
1151
- if (o1)
1152
- Duc.DimensionBindings.addOrigin1(b, o1);
1153
- if (o2)
1154
- Duc.DimensionBindings.addOrigin2(b, o2);
1155
- if (c)
1156
- Duc.DimensionBindings.addCenter(b, c);
1157
- return Duc.DimensionBindings.endDimensionBindings(b);
1158
- }
1159
- function writeDimTolStyle(b, t, usv) {
1160
- const textStyle = writeTextStyle(b, t.textStyle, usv);
1161
- Duc.DimensionToleranceStyle.startDimensionToleranceStyle(b);
1162
- Duc.DimensionToleranceStyle.addEnabled(b, t.enabled);
1163
- Duc.DimensionToleranceStyle.addDisplayMethod(b, t.displayMethod);
1164
- Duc.DimensionToleranceStyle.addUpperValue(b, t.upperValue);
1165
- Duc.DimensionToleranceStyle.addLowerValue(b, t.lowerValue);
1166
- Duc.DimensionToleranceStyle.addPrecision(b, t.precision);
1167
- Duc.DimensionToleranceStyle.addTextStyle(b, textStyle);
1168
- return Duc.DimensionToleranceStyle.endDimensionToleranceStyle(b);
1169
- }
1170
- function writeDimLineStyle(b, s, usv) {
1171
- const st = writeElementStroke(b, s.stroke, usv);
1172
- Duc.DimensionLineStyle.startDimensionLineStyle(b);
1173
- if (st)
1174
- Duc.DimensionLineStyle.addStroke(b, st);
1175
- Duc.DimensionLineStyle.addTextGap(b, getPrecisionValue(s.textGap, usv));
1176
- return Duc.DimensionLineStyle.endDimensionLineStyle(b);
1177
- }
1178
- function writeExtLineStyle(b, s, usv) {
1179
- const st = writeElementStroke(b, s.stroke, usv);
1180
- Duc.DimensionExtLineStyle.startDimensionExtLineStyle(b);
1181
- if (st)
1182
- Duc.DimensionExtLineStyle.addStroke(b, st);
1183
- Duc.DimensionExtLineStyle.addOvershoot(b, getPrecisionValue(s.overshoot, usv));
1184
- Duc.DimensionExtLineStyle.addOffset(b, getPrecisionValue(s.offset, usv));
1185
- return Duc.DimensionExtLineStyle.endDimensionExtLineStyle(b);
1186
- }
1187
- function writeDimSymbolStyle(b, s, usv) {
1188
- const heads = s.headsOverride ? Duc.DimensionSymbolStyle.createHeadsOverrideVector(b, s.headsOverride.map((h) => writeHead(b, h, usv))) : undefined;
1189
- Duc.DimensionSymbolStyle.startDimensionSymbolStyle(b);
1190
- if (heads)
1191
- Duc.DimensionSymbolStyle.addHeadsOverride(b, heads);
1192
- Duc.DimensionSymbolStyle.addCenterMarkType(b, s.centerMark.type);
1193
- Duc.DimensionSymbolStyle.addCenterMarkSize(b, getPrecisionValue(s.centerMark.size, usv));
1194
- return Duc.DimensionSymbolStyle.endDimensionSymbolStyle(b);
1195
- }
1196
- function writeDimStyle(b, s, usv) {
1197
- const dim = writeDimLineStyle(b, s.dimLine, usv);
1198
- const ext = writeExtLineStyle(b, s.extLine, usv);
1199
- const text = writeTextStyle(b, s.textStyle, usv);
1200
- const sym = writeDimSymbolStyle(b, s.symbols, usv);
1201
- const tol = writeDimTolStyle(b, s.tolerance, usv);
1202
- const fit = (() => {
1203
- Duc.DimensionFitStyle.startDimensionFitStyle(b);
1204
- Duc.DimensionFitStyle.addRule(b, s.fit.rule);
1205
- Duc.DimensionFitStyle.addTextPlacement(b, s.fit.textPlacement);
1206
- Duc.DimensionFitStyle.addForceTextInside(b, s.fit.forceTextInside);
1207
- return Duc.DimensionFitStyle.endDimensionFitStyle(b);
1208
- })();
1209
- Duc.DucDimensionStyle.startDucDimensionStyle(b);
1210
- Duc.DucDimensionStyle.addDimLine(b, dim);
1211
- Duc.DucDimensionStyle.addExtLine(b, ext);
1212
- Duc.DucDimensionStyle.addTextStyle(b, text);
1213
- Duc.DucDimensionStyle.addSymbols(b, sym);
1214
- Duc.DucDimensionStyle.addTolerance(b, tol);
1215
- Duc.DucDimensionStyle.addFit(b, fit);
1216
- return Duc.DucDimensionStyle.endDucDimensionStyle(b);
1217
- }
1218
- function writeDimension(b, e, usv) {
1219
- const base = writeElementBase(b, e, usv);
1220
- const style = writeDimStyle(b, e, usv);
1221
- const def = writeDimDefPoints(b, e.definitionPoints, usv);
1222
- const bindings = writeDimBindings(b, e.bindings, usv);
1223
- const textOverride = e.textOverride != null ? b.createString(e.textOverride) : undefined;
1224
- const textPos = e.textPosition ? writeGeomPoint(b, e.textPosition, usv) : undefined;
1225
- const tolOverride = e.toleranceOverride ? writeDimTolStyle(b, e.toleranceOverride, usv) : undefined;
1226
- const baseline = e.baselineData
1227
- ? (() => {
1228
- Duc.DimensionBaselineData.startDimensionBaselineData(b);
1229
- Duc.DimensionBaselineData.addBaseDimensionId(b, b.createString(e.baselineData.baseDimensionId));
1230
- return Duc.DimensionBaselineData.endDimensionBaselineData(b);
1231
- })()
1232
- : undefined;
1233
- const cont = e.continueData
1234
- ? (() => {
1235
- Duc.DimensionContinueData.startDimensionContinueData(b);
1236
- Duc.DimensionContinueData.addContinueFromDimensionId(b, b.createString(e.continueData.continueFromDimensionId));
1237
- return Duc.DimensionContinueData.endDimensionContinueData(b);
1238
- })()
1239
- : undefined;
1240
- Duc.DucDimensionElement.startDucDimensionElement(b);
1241
- Duc.DucDimensionElement.addBase(b, base);
1242
- Duc.DucDimensionElement.addStyle(b, style);
1243
- Duc.DucDimensionElement.addDimensionType(b, e.dimensionType);
1244
- Duc.DucDimensionElement.addDefinitionPoints(b, def);
1245
- Duc.DucDimensionElement.addObliqueAngle(b, e.obliqueAngle);
1246
- if (e.ordinateAxis)
1247
- Duc.DucDimensionElement.addOrdinateAxis(b, e.ordinateAxis);
1248
- if (bindings)
1249
- Duc.DucDimensionElement.addBindings(b, bindings);
1250
- if (textOverride)
1251
- Duc.DucDimensionElement.addTextOverride(b, textOverride);
1252
- if (textPos)
1253
- Duc.DucDimensionElement.addTextPosition(b, textPos);
1254
- if (tolOverride)
1255
- Duc.DucDimensionElement.addToleranceOverride(b, tolOverride);
1256
- if (baseline)
1257
- Duc.DucDimensionElement.addBaselineData(b, baseline);
1258
- if (cont)
1259
- Duc.DucDimensionElement.addContinueData(b, cont);
1260
- return Duc.DucDimensionElement.endDucDimensionElement(b);
1261
- }
1262
- function writeDatumRef(b, d, usv) {
1263
- const letters = b.createString(d.letters);
1264
- Duc.DatumReference.startDatumReference(b);
1265
- Duc.DatumReference.addLetters(b, letters);
1266
- if (d.modifier)
1267
- Duc.DatumReference.addModifier(b, d.modifier);
1268
- return Duc.DatumReference.endDatumReference(b);
1269
- }
1270
- function writeToleranceClause(b, t, usv) {
1271
- var _a;
1272
- const value = b.createString(t.value);
1273
- const featureMods = ((_a = t.featureModifiers) === null || _a === void 0 ? void 0 : _a.length)
1274
- ? Duc.ToleranceClause.createFeatureModifiersVector(b, t.featureModifiers.map((f) => f))
1275
- : undefined;
1276
- Duc.ToleranceClause.startToleranceClause(b);
1277
- Duc.ToleranceClause.addValue(b, value);
1278
- if (t.zoneType)
1279
- Duc.ToleranceClause.addZoneType(b, t.zoneType);
1280
- if (featureMods)
1281
- Duc.ToleranceClause.addFeatureModifiers(b, featureMods);
1282
- if (t.materialCondition)
1283
- Duc.ToleranceClause.addMaterialCondition(b, t.materialCondition);
1284
- return Duc.ToleranceClause.endToleranceClause(b);
1285
- }
1286
- function writeFcfSegment(b, s, usv) {
1287
- var _a;
1288
- const tol = writeToleranceClause(b, s.tolerance, usv);
1289
- const datums = ((_a = s.datums) === null || _a === void 0 ? void 0 : _a.length) ? Duc.FeatureControlFrameSegment.createDatumsVector(b, s.datums.filter(Boolean).map((d) => writeDatumRef(b, d, usv))) : undefined;
1290
- Duc.FeatureControlFrameSegment.startFeatureControlFrameSegment(b);
1291
- Duc.FeatureControlFrameSegment.addSymbol(b, s.symbol);
1292
- Duc.FeatureControlFrameSegment.addTolerance(b, tol);
1293
- if (datums)
1294
- Duc.FeatureControlFrameSegment.addDatums(b, datums);
1295
- return Duc.FeatureControlFrameSegment.endFeatureControlFrameSegment(b);
1296
- }
1297
- function writeFcfSegmentRow(b, row, usv) {
1298
- const segs = Duc.FCFSegmentRow.createSegmentsVector(b, row.map((s) => writeFcfSegment(b, s, usv)));
1299
- Duc.FCFSegmentRow.startFCFSegmentRow(b);
1300
- Duc.FCFSegmentRow.addSegments(b, segs);
1301
- return Duc.FCFSegmentRow.endFCFSegmentRow(b);
1302
- }
1303
- function writeFcfBetween(b, v, usv) {
1304
- const s = b.createString(v.start);
1305
- const e = b.createString(v.end);
1306
- Duc.FCFBetweenModifier.startFCFBetweenModifier(b);
1307
- Duc.FCFBetweenModifier.addStart(b, s);
1308
- Duc.FCFBetweenModifier.addEnd(b, e);
1309
- return Duc.FCFBetweenModifier.endFCFBetweenModifier(b);
1310
- }
1311
- function writeProjectedZone(b, v, usv) {
1312
- Duc.FCFProjectedZoneModifier.startFCFProjectedZoneModifier(b);
1313
- Duc.FCFProjectedZoneModifier.addValue(b, getPrecisionValue(v, usv));
1314
- return Duc.FCFProjectedZoneModifier.endFCFProjectedZoneModifier(b);
1315
- }
1316
- function writeFcfFrameModifiers(b, m, usv) {
1317
- if (!m)
1318
- return undefined;
1319
- Duc.FCFFrameModifiers.startFCFFrameModifiers(b);
1320
- if (m.allAround !== undefined)
1321
- Duc.FCFFrameModifiers.addAllAround(b, m.allAround);
1322
- if (m.allOver !== undefined)
1323
- Duc.FCFFrameModifiers.addAllOver(b, m.allOver);
1324
- if (m.continuousFeature !== undefined)
1325
- Duc.FCFFrameModifiers.addContinuousFeature(b, m.continuousFeature);
1326
- if (m.between)
1327
- Duc.FCFFrameModifiers.addBetween(b, writeFcfBetween(b, m.between, usv));
1328
- if (m.projectedToleranceZone)
1329
- Duc.FCFFrameModifiers.addProjectedToleranceZone(b, writeProjectedZone(b, m.projectedToleranceZone, usv));
1330
- return Duc.FCFFrameModifiers.endFCFFrameModifiers(b);
1331
- }
1332
- function writeFcfDatumDefinition(b, d, usv) {
1333
- if (!d)
1334
- return undefined;
1335
- const letter = b.createString(d.letter);
1336
- const binding = d.featureBinding ? writePointBinding(b, d.featureBinding, usv) : undefined;
1337
- Duc.FCFDatumDefinition.startFCFDatumDefinition(b);
1338
- Duc.FCFDatumDefinition.addLetter(b, letter);
1339
- if (binding)
1340
- Duc.FCFDatumDefinition.addFeatureBinding(b, binding);
1341
- return Duc.FCFDatumDefinition.endFCFDatumDefinition(b);
1342
- }
1343
- function writeFcfStyle(b, s, usv) {
1344
- const text = writeTextStyle(b, s.textStyle, usv);
1345
- const layout = (() => {
1346
- Duc.FCFLayoutStyle.startFCFLayoutStyle(b);
1347
- Duc.FCFLayoutStyle.addPadding(b, getPrecisionValue(s.layout.padding, usv));
1348
- Duc.FCFLayoutStyle.addSegmentSpacing(b, getPrecisionValue(s.layout.segmentSpacing, usv));
1349
- Duc.FCFLayoutStyle.addRowSpacing(b, getPrecisionValue(s.layout.rowSpacing, usv));
1350
- return Duc.FCFLayoutStyle.endFCFLayoutStyle(b);
1351
- })();
1352
- const sym = (() => {
1353
- Duc.FCFSymbolStyle.startFCFSymbolStyle(b);
1354
- Duc.FCFSymbolStyle.addScale(b, s.symbols.scale);
1355
- return Duc.FCFSymbolStyle.endFCFSymbolStyle(b);
1356
- })();
1357
- const datum = (() => {
1358
- Duc.FCFDatumStyle.startFCFDatumStyle(b);
1359
- Duc.FCFDatumStyle.addBracketStyle(b, s.datumStyle.bracketStyle);
1360
- return Duc.FCFDatumStyle.endFCFDatumStyle(b);
1361
- })();
1362
- Duc.DucFeatureControlFrameStyle.startDucFeatureControlFrameStyle(b);
1363
- Duc.DucFeatureControlFrameStyle.addTextStyle(b, text);
1364
- Duc.DucFeatureControlFrameStyle.addLayout(b, layout);
1365
- Duc.DucFeatureControlFrameStyle.addSymbols(b, sym);
1366
- Duc.DucFeatureControlFrameStyle.addDatumStyle(b, datum);
1367
- return Duc.DucFeatureControlFrameStyle.endDucFeatureControlFrameStyle(b);
1368
- }
1369
- function writeFcf(b, e, usv) {
1370
- const base = writeElementBase(b, e, usv);
1371
- const style = writeFcfStyle(b, e, usv);
1372
- const rows = Duc.DucFeatureControlFrameElement.createRowsVector(b, e.rows.map((r) => writeFcfSegmentRow(b, r, usv)));
1373
- const mods = writeFcfFrameModifiers(b, e.frameModifiers, usv);
1374
- const leaderId = e.leaderElementId ? b.createString(e.leaderElementId) : undefined;
1375
- const datumDef = writeFcfDatumDefinition(b, e.datumDefinition, usv);
1376
- Duc.DucFeatureControlFrameElement.startDucFeatureControlFrameElement(b);
1377
- Duc.DucFeatureControlFrameElement.addBase(b, base);
1378
- Duc.DucFeatureControlFrameElement.addStyle(b, style);
1379
- Duc.DucFeatureControlFrameElement.addRows(b, rows);
1380
- if (mods)
1381
- Duc.DucFeatureControlFrameElement.addFrameModifiers(b, mods);
1382
- if (leaderId)
1383
- Duc.DucFeatureControlFrameElement.addLeaderElementId(b, leaderId);
1384
- if (datumDef)
1385
- Duc.DucFeatureControlFrameElement.addDatumDefinition(b, datumDef);
1386
- return Duc.DucFeatureControlFrameElement.endDucFeatureControlFrameElement(b);
1387
- }
1388
- /**
1389
- * Doc element
1390
- */
1391
- function writeDoc(b, e, usv) {
1392
- const base = writeElementBase(b, e, usv);
1393
- const style = writeDocStyle(b, e, usv);
1394
- const text = b.createString(e.text);
1395
- const dynamic = Duc.DucDocElement.createDynamicVector(b, e.dynamic.map((d) => writeTextDynamicPart(b, d, usv)));
1396
- const columns = (() => {
1397
- const col = e.columns;
1398
- const defs = Duc.ColumnLayout.createDefinitionsVector(b, col.definitions.map((d) => writeTextColumn(b, d, usv)));
1399
- Duc.ColumnLayout.startColumnLayout(b);
1400
- Duc.ColumnLayout.addType(b, col.type);
1401
- Duc.ColumnLayout.addDefinitions(b, defs);
1402
- Duc.ColumnLayout.addAutoHeight(b, col.autoHeight);
1403
- return Duc.ColumnLayout.endColumnLayout(b);
1404
- })();
1405
- const fileId = e.fileId ? b.createString(e.fileId) : undefined;
1406
- const gridConfig = writeDocumentGridConfig(b, e.gridConfig, usv);
1407
- Duc.DucDocElement.startDucDocElement(b);
1408
- Duc.DucDocElement.addBase(b, base);
1409
- Duc.DucDocElement.addStyle(b, style);
1410
- Duc.DucDocElement.addText(b, text);
1411
- Duc.DucDocElement.addDynamic(b, dynamic);
1412
- Duc.DucDocElement.addFlowDirection(b, e.flowDirection);
1413
- Duc.DucDocElement.addColumns(b, columns);
1414
- Duc.DucDocElement.addAutoResize(b, e.autoResize);
1415
- if (fileId)
1416
- Duc.DucDocElement.addFileId(b, fileId);
1417
- Duc.DucDocElement.addGridConfig(b, gridConfig);
1418
- return Duc.DucDocElement.endDucDocElement(b);
1419
- }
1420
- /**
1421
- * PDF, Mermaid, Embeddable
1422
- */
1423
- function writePdf(b, e, usv) {
1424
- const base = writeElementBase(b, e, usv);
1425
- const fileId = e.fileId ? b.createString(e.fileId) : undefined;
1426
- const gridConfig = writeDocumentGridConfig(b, e.gridConfig, usv);
1427
- Duc.DucPdfElement.startDucPdfElement(b);
1428
- Duc.DucPdfElement.addBase(b, base);
1429
- if (fileId)
1430
- Duc.DucPdfElement.addFileId(b, fileId);
1431
- Duc.DucPdfElement.addGridConfig(b, gridConfig);
1432
- return Duc.DucPdfElement.endDucPdfElement(b);
1433
- }
1434
- function writeMermaid(b, e, usv) {
1435
- const base = writeElementBase(b, e, usv);
1436
- const src = b.createString(e.source);
1437
- const theme = e.theme ? b.createString(e.theme) : undefined;
1438
- const svg = e.svgPath ? b.createString(e.svgPath) : undefined;
1439
- Duc.DucMermaidElement.startDucMermaidElement(b);
1440
- Duc.DucMermaidElement.addBase(b, base);
1441
- Duc.DucMermaidElement.addSource(b, src);
1442
- if (theme)
1443
- Duc.DucMermaidElement.addTheme(b, theme);
1444
- if (svg)
1445
- Duc.DucMermaidElement.addSvgPath(b, svg);
1446
- return Duc.DucMermaidElement.endDucMermaidElement(b);
1447
- }
1448
- function writeModel(b, e, usv) {
1449
- var _a;
1450
- const base = writeElementBase(b, e, usv);
1451
- const src = b.createString(e.source);
1452
- const svg = e.svgPath ? b.createString(e.svgPath) : undefined;
1453
- const fileIds = ((_a = e.fileIds) === null || _a === void 0 ? void 0 : _a.length) ? Duc.DucModelElement.createFileIdsVector(b, e.fileIds.map((id) => b.createString(id))) : undefined;
1454
- Duc.DucModelElement.startDucModelElement(b);
1455
- Duc.DucModelElement.addBase(b, base);
1456
- Duc.DucModelElement.addSource(b, src);
1457
- if (svg)
1458
- Duc.DucModelElement.addSvgPath(b, svg);
1459
- if (fileIds)
1460
- Duc.DucModelElement.addFileIds(b, fileIds);
1461
- return Duc.DucModelElement.endDucModelElement(b);
1462
- }
1463
- function writeEmbeddable(b, e, usv) {
1464
- const base = writeElementBase(b, e, usv);
1465
- Duc.DucEmbeddableElement.startDucEmbeddableElement(b);
1466
- Duc.DucEmbeddableElement.addBase(b, base);
1467
- return Duc.DucEmbeddableElement.endDucEmbeddableElement(b);
1468
- }
1469
- /**
1470
- * Table
1471
- */
1472
- function writeTableCellStyle(b, s, usv) {
1473
- const base = writeStylesBase(b, s, usv);
1474
- const text = writeTextStyle(b, s.textStyle, usv);
1475
- Duc.Margins.startMargins(b);
1476
- Duc.Margins.addTop(b, getPrecisionValue(s.margins.top, usv));
1477
- Duc.Margins.addRight(b, getPrecisionValue(s.margins.right, usv));
1478
- Duc.Margins.addBottom(b, getPrecisionValue(s.margins.bottom, usv));
1479
- Duc.Margins.addLeft(b, getPrecisionValue(s.margins.left, usv));
1480
- const margins = Duc.Margins.endMargins(b);
1481
- Duc.DucTableCellStyle.startDucTableCellStyle(b);
1482
- if (base) {
1483
- Duc.DucTableCellStyle.addBaseStyle(b, base);
1484
- }
1485
- Duc.DucTableCellStyle.addTextStyle(b, text);
1486
- Duc.DucTableCellStyle.addMargins(b, margins);
1487
- Duc.DucTableCellStyle.addAlignment(b, s.alignment);
1488
- return Duc.DucTableCellStyle.endDucTableCellStyle(b);
1489
- }
1490
- function writeTableStyle(b, s, usv) {
1491
- const header = writeTableCellStyle(b, s.headerRowStyle, usv);
1492
- const dataRow = writeTableCellStyle(b, s.dataRowStyle, usv);
1493
- const dataCol = writeTableCellStyle(b, s.dataColumnStyle, usv);
1494
- Duc.DucTableStyle.startDucTableStyle(b);
1495
- Duc.DucTableStyle.addFlowDirection(b, s.flowDirection);
1496
- Duc.DucTableStyle.addHeaderRowStyle(b, header);
1497
- Duc.DucTableStyle.addDataRowStyle(b, dataRow);
1498
- Duc.DucTableStyle.addDataColumnStyle(b, dataCol);
1499
- return Duc.DucTableStyle.endDucTableStyle(b);
1500
- }
1501
- function writeTable(b, e, usv) {
1502
- const base = writeElementBase(b, e, usv);
1503
- const style = writeTableStyle(b, e, usv);
1504
- const colOrder = Duc.DucTableElement.createColumnOrderVector(b, e.columnOrder.map((id) => b.createString(id)));
1505
- const rowOrder = Duc.DucTableElement.createRowOrderVector(b, e.rowOrder.map((id) => b.createString(id)));
1506
- const columns = Duc.DucTableElement.createColumnsVector(b, Object.entries(e.columns).map(([k, v]) => {
1507
- const key = b.createString(k);
1508
- const val = (() => {
1509
- const id = b.createString(v.id);
1510
- Duc.DucTableColumn.startDucTableColumn(b);
1511
- Duc.DucTableColumn.addId(b, id);
1512
- Duc.DucTableColumn.addWidth(b, getPrecisionValue(v.width, usv));
1513
- const styleOverrides = v.styleOverrides ? writeTableCellStyle(b, v.styleOverrides, usv) : undefined;
1514
- if (styleOverrides)
1515
- Duc.DucTableColumn.addStyleOverrides(b, styleOverrides);
1516
- return Duc.DucTableColumn.endDucTableColumn(b);
1517
- })();
1518
- Duc.DucTableColumnEntry.startDucTableColumnEntry(b);
1519
- Duc.DucTableColumnEntry.addKey(b, key);
1520
- Duc.DucTableColumnEntry.addValue(b, val);
1521
- return Duc.DucTableColumnEntry.endDucTableColumnEntry(b);
1522
- }));
1523
- const rows = Duc.DucTableElement.createRowsVector(b, Object.entries(e.rows).map(([k, v]) => {
1524
- const key = b.createString(k);
1525
- const val = (() => {
1526
- const id = b.createString(v.id);
1527
- Duc.DucTableRow.startDucTableRow(b);
1528
- Duc.DucTableRow.addId(b, id);
1529
- Duc.DucTableRow.addHeight(b, getPrecisionValue(v.height, usv));
1530
- const styleOverrides = v.styleOverrides ? writeTableCellStyle(b, v.styleOverrides, usv) : undefined;
1531
- if (styleOverrides)
1532
- Duc.DucTableRow.addStyleOverrides(b, styleOverrides);
1533
- return Duc.DucTableRow.endDucTableRow(b);
1534
- })();
1535
- Duc.DucTableRowEntry.startDucTableRowEntry(b);
1536
- Duc.DucTableRowEntry.addKey(b, key);
1537
- Duc.DucTableRowEntry.addValue(b, val);
1538
- return Duc.DucTableRowEntry.endDucTableRowEntry(b);
1539
- }));
1540
- const cells = Duc.DucTableElement.createCellsVector(b, Object.entries(e.cells).map(([k, v]) => {
1541
- const key = b.createString(k);
1542
- const val = (() => {
1543
- const row = b.createString(v.rowId);
1544
- const col = b.createString(v.columnId);
1545
- const data = b.createString(v.data);
1546
- const span = v.span
1547
- ? (() => {
1548
- Duc.DucTableCellSpan.startDucTableCellSpan(b);
1549
- Duc.DucTableCellSpan.addColumns(b, v.span.columns);
1550
- Duc.DucTableCellSpan.addRows(b, v.span.rows);
1551
- return Duc.DucTableCellSpan.endDucTableCellSpan(b);
1552
- })()
1553
- : undefined;
1554
- const styleOverrides = v.styleOverrides ? writeTableCellStyle(b, v.styleOverrides, usv) : undefined;
1555
- Duc.DucTableCell.startDucTableCell(b);
1556
- Duc.DucTableCell.addRowId(b, row);
1557
- Duc.DucTableCell.addColumnId(b, col);
1558
- Duc.DucTableCell.addData(b, data);
1559
- if (span !== undefined)
1560
- Duc.DucTableCell.addSpan(b, span);
1561
- Duc.DucTableCell.addLocked(b, v.locked);
1562
- if (styleOverrides)
1563
- Duc.DucTableCell.addStyleOverrides(b, styleOverrides);
1564
- return Duc.DucTableCell.endDucTableCell(b);
1565
- })();
1566
- Duc.DucTableCellEntry.startDucTableCellEntry(b);
1567
- Duc.DucTableCellEntry.addKey(b, key);
1568
- Duc.DucTableCellEntry.addValue(b, val);
1569
- return Duc.DucTableCellEntry.endDucTableCellEntry(b);
1570
- }));
1571
- const autoSize = (() => {
1572
- Duc.DucTableAutoSize.startDucTableAutoSize(b);
1573
- Duc.DucTableAutoSize.addColumns(b, e.autoSize.columns);
1574
- Duc.DucTableAutoSize.addRows(b, e.autoSize.rows);
1575
- return Duc.DucTableAutoSize.endDucTableAutoSize(b);
1576
- })();
1577
- Duc.DucTableElement.startDucTableElement(b);
1578
- Duc.DucTableElement.addBase(b, base);
1579
- Duc.DucTableElement.addStyle(b, style);
1580
- Duc.DucTableElement.addColumnOrder(b, colOrder);
1581
- Duc.DucTableElement.addRowOrder(b, rowOrder);
1582
- Duc.DucTableElement.addColumns(b, columns);
1583
- Duc.DucTableElement.addRows(b, rows);
1584
- Duc.DucTableElement.addCells(b, cells);
1585
- Duc.DucTableElement.addHeaderRowCount(b, e.headerRowCount);
1586
- Duc.DucTableElement.addAutoSize(b, autoSize);
1587
- return Duc.DucTableElement.endDucTableElement(b);
1588
- }
1589
- /**
1590
- * Element wrapper
1591
- */
1592
- function writeElementWrapper(b, e, usv) {
1593
- let elem;
1594
- let type;
1595
- switch (e.type) {
1596
- case "rectangle":
1597
- type = Duc.Element.DucRectangleElement;
1598
- elem = writeRect(b, e, usv);
1599
- break;
1600
- case "polygon":
1601
- type = Duc.Element.DucPolygonElement;
1602
- elem = writePolygon(b, e, usv);
1603
- break;
1604
- case "ellipse":
1605
- type = Duc.Element.DucEllipseElement;
1606
- elem = writeEllipse(b, e, usv);
1607
- break;
1608
- case "line":
1609
- type = Duc.Element.DucLinearElement;
1610
- elem = writeLinear(b, e, usv);
1611
- break;
1612
- case "text":
1613
- type = Duc.Element.DucTextElement;
1614
- elem = writeText(b, e, usv);
1615
- break;
1616
- case "arrow":
1617
- type = Duc.Element.DucArrowElement;
1618
- elem = writeArrow(b, e, usv);
1619
- break;
1620
- case "freedraw":
1621
- type = Duc.Element.DucFreeDrawElement;
1622
- elem = writeFreeDraw(b, e, usv);
1623
- break;
1624
- case "image":
1625
- type = Duc.Element.DucImageElement;
1626
- elem = writeImage(b, e, usv);
1627
- break;
1628
- case "table":
1629
- type = Duc.Element.DucTableElement;
1630
- elem = writeTable(b, e, usv);
1631
- break;
1632
- case "frame":
1633
- type = Duc.Element.DucFrameElement;
1634
- elem = writeFrame(b, e, usv);
1635
- break;
1636
- case "plot":
1637
- type = Duc.Element.DucPlotElement;
1638
- elem = writePlot(b, e, usv);
1639
- break;
1640
- case "viewport":
1641
- type = Duc.Element.DucViewportElement;
1642
- elem = writeViewport(b, e, usv);
1643
- break;
1644
- case "xray":
1645
- type = Duc.Element.DucXRayElement;
1646
- elem = writeXRay(b, e, usv);
1647
- break;
1648
- case "leader":
1649
- type = Duc.Element.DucLeaderElement;
1650
- elem = writeLeader(b, e, usv);
1651
- break;
1652
- case "dimension":
1653
- type = Duc.Element.DucDimensionElement;
1654
- elem = writeDimension(b, e, usv);
1655
- break;
1656
- case "featurecontrolframe":
1657
- type = Duc.Element.DucFeatureControlFrameElement;
1658
- elem = writeFcf(b, e, usv);
1659
- break;
1660
- case "doc":
1661
- type = Duc.Element.DucDocElement;
1662
- elem = writeDoc(b, e, usv);
1663
- break;
1664
- case "model":
1665
- type = Duc.Element.DucModelElement;
1666
- elem = writeModel(b, e, usv);
1667
- break;
1668
- case "embeddable":
1669
- type = Duc.Element.DucEmbeddableElement;
1670
- elem = writeEmbeddable(b, e, usv);
1671
- break;
1672
- case "pdf":
1673
- type = Duc.Element.DucPdfElement;
1674
- elem = writePdf(b, e, usv);
1675
- break;
1676
- case "mermaid":
1677
- type = Duc.Element.DucMermaidElement;
1678
- elem = writeMermaid(b, e, usv);
1679
- break;
1680
- default:
1681
- throw new Error(`Unknown element type: ${e.type}`);
1682
- }
1683
- // Safety check to ensure elem is defined
1684
- if (elem === undefined) {
1685
- throw new Error(`Failed to serialize element of type ${e.type}`);
1686
- }
1687
- Duc.ElementWrapper.startElementWrapper(b);
1688
- Duc.ElementWrapper.addElementType(b, type);
1689
- Duc.ElementWrapper.addElement(b, elem);
1690
- return Duc.ElementWrapper.endElementWrapper(b);
1691
- }
1692
- function writeGridStyle(b, s, usv) {
1693
- const color = b.createString(s.color);
1694
- const dash = Duc.GridStyle.createDashPatternVector(b, s.dashPattern);
1695
- Duc.GridStyle.startGridStyle(b);
1696
- Duc.GridStyle.addColor(b, color);
1697
- Duc.GridStyle.addOpacity(b, s.opacity);
1698
- Duc.GridStyle.addDashPattern(b, dash);
1699
- return Duc.GridStyle.endGridStyle(b);
1700
- }
1701
- function writePolarGridSettings(b, p, usv) {
1702
- Duc.PolarGridSettings.startPolarGridSettings(b);
1703
- Duc.PolarGridSettings.addRadialDivisions(b, p.radialDivisions);
1704
- Duc.PolarGridSettings.addRadialSpacing(b, getPrecisionValue(p.radialSpacing, usv));
1705
- Duc.PolarGridSettings.addShowLabels(b, p.showLabels);
1706
- return Duc.PolarGridSettings.endPolarGridSettings(b);
1707
- }
1708
- function writeIsometricGridSettings(b, i, usv) {
1709
- Duc.IsometricGridSettings.startIsometricGridSettings(b);
1710
- Duc.IsometricGridSettings.addLeftAngle(b, i.leftAngle);
1711
- Duc.IsometricGridSettings.addRightAngle(b, i.rightAngle);
1712
- return Duc.IsometricGridSettings.endIsometricGridSettings(b);
1713
- }
1714
- function writeGridSettings(b, g, usv) {
1715
- const origin = Duc.GeometricPoint.createGeometricPoint(b, g.origin.x, g.origin.y);
1716
- const major = writeGridStyle(b, g.majorStyle, usv);
1717
- const minor = writeGridStyle(b, g.minorStyle, usv);
1718
- const polar = g.polarSettings ? writePolarGridSettings(b, g.polarSettings, usv) : undefined;
1719
- const iso = g.isometricSettings ? writeIsometricGridSettings(b, g.isometricSettings, usv) : undefined;
1720
- Duc.GridSettings.startGridSettings(b);
1721
- Duc.GridSettings.addType(b, g.type);
1722
- Duc.GridSettings.addReadonly(b, g.readonly);
1723
- Duc.GridSettings.addDisplayType(b, g.displayType);
1724
- Duc.GridSettings.addIsAdaptive(b, g.isAdaptive);
1725
- Duc.GridSettings.addXSpacing(b, getPrecisionValue(g.xSpacing, usv));
1726
- Duc.GridSettings.addYSpacing(b, getPrecisionValue(g.ySpacing, usv));
1727
- Duc.GridSettings.addSubdivisions(b, g.subdivisions);
1728
- Duc.GridSettings.addOrigin(b, origin);
1729
- Duc.GridSettings.addRotation(b, g.rotation);
1730
- Duc.GridSettings.addFollowUcs(b, g.followUCS);
1731
- Duc.GridSettings.addMajorStyle(b, major);
1732
- Duc.GridSettings.addMinorStyle(b, minor);
1733
- Duc.GridSettings.addShowMinor(b, g.showMinor);
1734
- Duc.GridSettings.addMinZoom(b, g.minZoom);
1735
- Duc.GridSettings.addMaxZoom(b, g.maxZoom);
1736
- Duc.GridSettings.addAutoHide(b, g.autoHide);
1737
- if (polar)
1738
- Duc.GridSettings.addPolarSettings(b, polar);
1739
- if (iso)
1740
- Duc.GridSettings.addIsometricSettings(b, iso);
1741
- Duc.GridSettings.addEnableSnapping(b, g.enableSnapping);
1742
- return Duc.GridSettings.endGridSettings(b);
1743
- }
1744
- function writeSnapMarkerSettings(b, s, usv) {
1745
- const styles = Duc.SnapMarkerSettings.createStylesVector(b, Object.entries(s.styles).map(([k, v]) => {
1746
- Duc.SnapMarkerStyleEntry.startSnapMarkerStyleEntry(b);
1747
- Duc.SnapMarkerStyleEntry.addKey(b, Number(k));
1748
- const color = b.createString(v.color);
1749
- Duc.SnapMarkerStyle.startSnapMarkerStyle(b);
1750
- Duc.SnapMarkerStyle.addShape(b, v.shape);
1751
- Duc.SnapMarkerStyle.addColor(b, color);
1752
- const val = Duc.SnapMarkerStyle.endSnapMarkerStyle(b);
1753
- Duc.SnapMarkerStyleEntry.addValue(b, val);
1754
- return Duc.SnapMarkerStyleEntry.endSnapMarkerStyleEntry(b);
1755
- }));
1756
- Duc.SnapMarkerSettings.startSnapMarkerSettings(b);
1757
- Duc.SnapMarkerSettings.addEnabled(b, s.enabled);
1758
- Duc.SnapMarkerSettings.addSize(b, s.size);
1759
- if (s.duration !== undefined)
1760
- Duc.SnapMarkerSettings.addDuration(b, s.duration);
1761
- Duc.SnapMarkerSettings.addStyles(b, styles);
1762
- return Duc.SnapMarkerSettings.endSnapMarkerSettings(b);
1763
- }
1764
- function writeTrackingLineStyle(b, t, usv) {
1765
- if (!t)
1766
- return undefined;
1767
- const color = b.createString(t.color);
1768
- const dash = t.dashPattern ? Duc.TrackingLineStyle.createDashPatternVector(b, t.dashPattern) : undefined;
1769
- Duc.TrackingLineStyle.startTrackingLineStyle(b);
1770
- Duc.TrackingLineStyle.addColor(b, color);
1771
- Duc.TrackingLineStyle.addOpacity(b, t.opacity);
1772
- if (dash)
1773
- Duc.TrackingLineStyle.addDashPattern(b, dash);
1774
- return Duc.TrackingLineStyle.endTrackingLineStyle(b);
1775
- }
1776
- function writeDynamicSnapSettings(b, d, usv) {
1777
- Duc.DynamicSnapSettings.startDynamicSnapSettings(b);
1778
- Duc.DynamicSnapSettings.addEnabledDuringDrag(b, d.enabledDuringDrag);
1779
- Duc.DynamicSnapSettings.addEnabledDuringRotation(b, d.enabledDuringRotation);
1780
- Duc.DynamicSnapSettings.addEnabledDuringScale(b, d.enabledDuringScale);
1781
- return Duc.DynamicSnapSettings.endDynamicSnapSettings(b);
1782
- }
1783
- function writeSnapOverride(b, o, usv) {
1784
- const key = b.createString(o.key);
1785
- Duc.SnapOverride.startSnapOverride(b);
1786
- Duc.SnapOverride.addKey(b, key);
1787
- Duc.SnapOverride.addBehavior(b, o.behavior);
1788
- return Duc.SnapOverride.endSnapOverride(b);
1789
44
  }
1790
- function writePolarTrackingSettings(b, p, usv) {
1791
- const angles = Duc.PolarTrackingSettings.createAnglesVector(b, p.angles.map(a => a));
1792
- Duc.PolarTrackingSettings.startPolarTrackingSettings(b);
1793
- Duc.PolarTrackingSettings.addEnabled(b, p.enabled);
1794
- Duc.PolarTrackingSettings.addAngles(b, angles);
1795
- if (p.incrementAngle !== undefined)
1796
- Duc.PolarTrackingSettings.addIncrementAngle(b, p.incrementAngle);
1797
- Duc.PolarTrackingSettings.addTrackFromLastPoint(b, p.trackFromLastPoint);
1798
- Duc.PolarTrackingSettings.addShowPolarCoordinates(b, p.showPolarCoordinates);
1799
- return Duc.PolarTrackingSettings.endPolarTrackingSettings(b);
1800
- }
1801
- function writeLayerSnapFilters(b, f, usv) {
1802
- if (!f)
1803
- return undefined;
1804
- const include = f.includeLayers ? Duc.LayerSnapFilters.createIncludeLayersVector(b, f.includeLayers.map(id => b.createString(id))) : undefined;
1805
- const exclude = f.excludeLayers ? Duc.LayerSnapFilters.createExcludeLayersVector(b, f.excludeLayers.map(id => b.createString(id))) : undefined;
1806
- Duc.LayerSnapFilters.startLayerSnapFilters(b);
1807
- if (include)
1808
- Duc.LayerSnapFilters.addIncludeLayers(b, include);
1809
- if (exclude)
1810
- Duc.LayerSnapFilters.addExcludeLayers(b, exclude);
1811
- return Duc.LayerSnapFilters.endLayerSnapFilters(b);
1812
- }
1813
- function writeSnapSettings(b, s, usv) {
1814
- var _a;
1815
- const overridesArray = (_a = s.temporaryOverrides) !== null && _a !== void 0 ? _a : [];
1816
- const overridesVec = overridesArray.length
1817
- ? Duc.SnapSettings.createTemporaryOverridesVector(b, overridesArray.map(o => writeSnapOverride(b, o, usv)))
1818
- : undefined;
1819
- const tracking = writeTrackingLineStyle(b, s.trackingLineStyle, usv);
1820
- const dynamic = writeDynamicSnapSettings(b, s.dynamicSnap, usv);
1821
- // Always build PolarTrackingSettings (constructor ensures required fields); no defaults introduced.
1822
- const polar = writePolarTrackingSettings(b, s.polarTracking, usv);
1823
- const layers = writeLayerSnapFilters(b, s.layerSnapFilters, usv);
1824
- const markers = writeSnapMarkerSettings(b, s.snapMarkers, usv);
1825
- const types = s.elementTypeFilters ? Duc.SnapSettings.createElementTypeFiltersVector(b, s.elementTypeFilters.map(t => {
1826
- // element type enum is Duc.Element (wrapper), but here it's a string union.
1827
- // The schema likely stores raw strings; we store as strings.
1828
- return b.createString(t);
1829
- })) : undefined;
1830
- Duc.SnapSettings.startSnapSettings(b);
1831
- Duc.SnapSettings.addReadonly(b, s.readonly);
1832
- Duc.SnapSettings.addTwistAngle(b, s.twistAngle);
1833
- Duc.SnapSettings.addSnapTolerance(b, s.snapTolerance);
1834
- Duc.SnapSettings.addObjectSnapAperture(b, s.objectSnapAperture);
1835
- Duc.SnapSettings.addIsOrthoModeOn(b, s.isOrthoModeOn);
1836
- if (polar !== undefined)
1837
- Duc.SnapSettings.addPolarTracking(b, polar);
1838
- Duc.SnapSettings.addIsObjectSnapOn(b, s.isObjectSnapOn);
1839
- Duc.SnapSettings.addActiveObjectSnapModes(b, Duc.SnapSettings.createActiveObjectSnapModesVector(b, s.activeObjectSnapModes));
1840
- Duc.SnapSettings.addSnapPriority(b, Duc.SnapSettings.createSnapPriorityVector(b, s.snapPriority));
1841
- Duc.SnapSettings.addShowTrackingLines(b, s.showTrackingLines);
1842
- if (tracking)
1843
- Duc.SnapSettings.addTrackingLineStyle(b, tracking);
1844
- Duc.SnapSettings.addDynamicSnap(b, dynamic);
1845
- if (overridesVec)
1846
- Duc.SnapSettings.addTemporaryOverrides(b, overridesVec);
1847
- if (s.incrementalDistance !== undefined)
1848
- Duc.SnapSettings.addIncrementalDistance(b, s.incrementalDistance);
1849
- if (s.magneticStrength !== undefined)
1850
- Duc.SnapSettings.addMagneticStrength(b, s.magneticStrength);
1851
- if (layers)
1852
- Duc.SnapSettings.addLayerSnapFilters(b, layers);
1853
- if (types)
1854
- Duc.SnapSettings.addElementTypeFilters(b, types);
1855
- Duc.SnapSettings.addSnapMode(b, s.snapMode);
1856
- Duc.SnapSettings.addSnapMarkers(b, markers);
1857
- Duc.SnapSettings.addConstructionSnapEnabled(b, s.constructionSnapEnabled);
1858
- if (s.snapToGridIntersections !== undefined)
1859
- Duc.SnapSettings.addSnapToGridIntersections(b, s.snapToGridIntersections);
1860
- return Duc.SnapSettings.endSnapSettings(b);
1861
- }
1862
- function writeUcs(b, u) {
1863
- const origin = Duc.GeometricPoint.createGeometricPoint(b, u.origin.x, u.origin.y);
1864
- Duc.DucUcs.startDucUcs(b);
1865
- Duc.DucUcs.addOrigin(b, origin);
1866
- Duc.DucUcs.addAngle(b, u.angle);
1867
- return Duc.DucUcs.endDucUcs(b);
1868
- }
1869
- function serializeStandardOverrides(b, o, usv) {
1870
- const activeGrid = o.activeGridSettingsId ? Duc.StandardOverrides.createActiveGridSettingsIdVector(b, o.activeGridSettingsId.map(id => b.createString(id))) : undefined;
1871
- const dashOverride = o.dashLineOverride ? b.createString(o.dashLineOverride) : undefined;
1872
- Duc.StandardOverrides.startStandardOverrides(b);
1873
- if (o.mainScope)
1874
- Duc.StandardOverrides.addMainScope(b, b.createString(o.mainScope));
1875
- if (o.elementsStrokeWidthOverride)
1876
- Duc.StandardOverrides.addElementsStrokeWidthOverride(b, getPrecisionValue(o.elementsStrokeWidthOverride, usv));
1877
- if (o.commonStyleId)
1878
- Duc.StandardOverrides.addCommonStyleId(b, b.createString(o.commonStyleId));
1879
- if (o.stackLikeStyleId)
1880
- Duc.StandardOverrides.addStackLikeStyleId(b, b.createString(o.stackLikeStyleId));
1881
- if (o.textStyleId)
1882
- Duc.StandardOverrides.addTextStyleId(b, b.createString(o.textStyleId));
1883
- if (o.dimensionStyleId)
1884
- Duc.StandardOverrides.addDimensionStyleId(b, b.createString(o.dimensionStyleId));
1885
- if (o.leaderStyleId)
1886
- Duc.StandardOverrides.addLeaderStyleId(b, b.createString(o.leaderStyleId));
1887
- if (o.featureControlFrameStyleId)
1888
- Duc.StandardOverrides.addFeatureControlFrameStyleId(b, b.createString(o.featureControlFrameStyleId));
1889
- if (o.tableStyleId)
1890
- Duc.StandardOverrides.addTableStyleId(b, b.createString(o.tableStyleId));
1891
- if (o.docStyleId)
1892
- Duc.StandardOverrides.addDocStyleId(b, b.createString(o.docStyleId));
1893
- if (o.viewportStyleId)
1894
- Duc.StandardOverrides.addViewportStyleId(b, b.createString(o.viewportStyleId));
1895
- if (o.plotStyleId)
1896
- Duc.StandardOverrides.addPlotStyleId(b, b.createString(o.plotStyleId));
1897
- if (o.hatchStyleId)
1898
- Duc.StandardOverrides.addHatchStyleId(b, b.createString(o.hatchStyleId));
1899
- if (activeGrid)
1900
- Duc.StandardOverrides.addActiveGridSettingsId(b, activeGrid);
1901
- if (o.activeSnapSettingsId)
1902
- Duc.StandardOverrides.addActiveSnapSettingsId(b, b.createString(o.activeSnapSettingsId));
1903
- if (dashOverride)
1904
- Duc.StandardOverrides.addDashLineOverride(b, dashOverride);
1905
- if (o.unitPrecision) {
1906
- Duc.UnitPrecision.startUnitPrecision(b);
1907
- if (o.unitPrecision.linear !== undefined)
1908
- Duc.UnitPrecision.addLinear(b, o.unitPrecision.linear);
1909
- if (o.unitPrecision.angular !== undefined)
1910
- Duc.UnitPrecision.addAngular(b, o.unitPrecision.angular);
1911
- if (o.unitPrecision.area !== undefined)
1912
- Duc.UnitPrecision.addArea(b, o.unitPrecision.area);
1913
- if (o.unitPrecision.volume !== undefined)
1914
- Duc.UnitPrecision.addVolume(b, o.unitPrecision.volume);
1915
- const up = Duc.UnitPrecision.endUnitPrecision(b);
1916
- Duc.StandardOverrides.addUnitPrecision(b, up);
45
+ function hasLegacyVersionGraphShape(versionGraph) {
46
+ if (!versionGraph || typeof versionGraph !== "object") {
47
+ return false;
1917
48
  }
1918
- return Duc.StandardOverrides.endStandardOverrides(b);
1919
- }
1920
- function serializeStandardUnits(b, u, usv) {
1921
- const primary = writePrimaryUnits(b, {
1922
- linear: {
1923
- system: u.primaryUnits.linear.system,
1924
- precision: u.primaryUnits.linear.precision,
1925
- suppressLeadingZeros: u.primaryUnits.linear.suppressLeadingZeros,
1926
- suppressTrailingZeros: u.primaryUnits.linear.suppressTrailingZeros,
1927
- format: u.primaryUnits.linear.format,
1928
- decimalSeparator: u.primaryUnits.linear.decimalSeparator,
1929
- suppressZeroFeet: u.primaryUnits.linear.suppressZeroFeet,
1930
- suppressZeroInches: u.primaryUnits.linear.suppressZeroInches,
1931
- },
1932
- angular: {
1933
- system: u.primaryUnits.angular.system,
1934
- precision: u.primaryUnits.angular.precision,
1935
- suppressLeadingZeros: u.primaryUnits.angular.suppressLeadingZeros,
1936
- suppressTrailingZeros: u.primaryUnits.angular.suppressTrailingZeros,
1937
- format: u.primaryUnits.angular.format,
1938
- },
1939
- }, usv);
1940
- Duc.AlternateUnits.startAlternateUnits(b);
1941
- Duc.AlternateUnits.addIsVisible(b, u.alternateUnits.isVisible);
1942
- Duc.AlternateUnits.addMultiplier(b, u.alternateUnits.multiplier);
1943
- Duc.AlternateUnits.addFormat(b, u.alternateUnits.format);
1944
- // AlternateUnits in schema may not have these fields; only write those that exist
1945
- if ("addSystem" in Duc.AlternateUnits) {
1946
- // @ts-expect-error guarded by runtime check
1947
- Duc.AlternateUnits.addSystem(b, u.alternateUnits.system);
49
+ const metadata = versionGraph.metadata;
50
+ if (!metadata || typeof metadata !== "object") {
51
+ return true;
1948
52
  }
1949
- if ("addPrecision" in Duc.AlternateUnits) {
1950
- // @ts-expect-error guarded by runtime check
1951
- Duc.AlternateUnits.addPrecision(b, u.alternateUnits.precision);
53
+ const hasModernMetadata = typeof metadata.currentVersion === "number" &&
54
+ typeof metadata.currentSchemaVersion === "number" &&
55
+ typeof metadata.chainCount === "number";
56
+ if (!hasModernMetadata) {
57
+ return true;
1952
58
  }
1953
- if ("addSuppressLeadingZeros" in Duc.AlternateUnits) {
1954
- // @ts-expect-error guarded by runtime check
1955
- Duc.AlternateUnits.addSuppressLeadingZeros(b, u.alternateUnits.suppressLeadingZeros);
59
+ if (metadata.currentSchemaVersion < 1 || metadata.chainCount < 1) {
60
+ return true;
1956
61
  }
1957
- if ("addSuppressTrailingZeros" in Duc.AlternateUnits) {
1958
- // @ts-expect-error guarded by runtime check
1959
- Duc.AlternateUnits.addSuppressTrailingZeros(b, u.alternateUnits.suppressTrailingZeros);
62
+ const checkpoints = Array.isArray(versionGraph.checkpoints)
63
+ ? versionGraph.checkpoints
64
+ : [];
65
+ const deltas = Array.isArray(versionGraph.deltas) ? versionGraph.deltas : [];
66
+ const hasLegacyCheckpoint = checkpoints.some((cp) => typeof (cp === null || cp === void 0 ? void 0 : cp.versionNumber) !== "number" ||
67
+ typeof (cp === null || cp === void 0 ? void 0 : cp.schemaVersion) !== "number");
68
+ if (hasLegacyCheckpoint) {
69
+ return true;
1960
70
  }
1961
- const alt = Duc.AlternateUnits.endAlternateUnits(b);
1962
- Duc.StandardUnits.startStandardUnits(b);
1963
- if (primary !== undefined)
1964
- Duc.StandardUnits.addPrimaryUnits(b, primary);
1965
- Duc.StandardUnits.addAlternateUnits(b, alt);
1966
- return Duc.StandardUnits.endStandardUnits(b);
1967
- }
1968
- function writeIdentifiedCommonStyle(b, entry, usv) {
1969
- const idOff = writeIdentifier(b, entry);
1970
- const bg = writeElementBackground(b, entry.background, usv);
1971
- const st = writeElementStroke(b, entry.stroke, usv);
1972
- Duc.DucCommonStyle.startDucCommonStyle(b);
1973
- if (bg)
1974
- Duc.DucCommonStyle.addBackground(b, bg);
1975
- if (st)
1976
- Duc.DucCommonStyle.addStroke(b, st);
1977
- const style = Duc.DucCommonStyle.endDucCommonStyle(b);
1978
- Duc.IdentifiedCommonStyle.startIdentifiedCommonStyle(b);
1979
- Duc.IdentifiedCommonStyle.addId(b, idOff);
1980
- Duc.IdentifiedCommonStyle.addStyle(b, style);
1981
- return Duc.IdentifiedCommonStyle.endIdentifiedCommonStyle(b);
1982
- }
1983
- function writeIdentifiedStackLikeStyle(b, entry, usv) {
1984
- const idOff = writeIdentifier(b, entry);
1985
- const s = (() => {
1986
- Duc.DucStackLikeStyles.startDucStackLikeStyles(b);
1987
- Duc.DucStackLikeStyles.addOpacity(b, entry.opacity);
1988
- Duc.DucStackLikeStyles.addLabelingColor(b, b.createString(entry.labelingColor));
1989
- return Duc.DucStackLikeStyles.endDucStackLikeStyles(b);
1990
- })();
1991
- Duc.IdentifiedStackLikeStyle.startIdentifiedStackLikeStyle(b);
1992
- Duc.IdentifiedStackLikeStyle.addId(b, idOff);
1993
- Duc.IdentifiedStackLikeStyle.addStyle(b, s);
1994
- return Duc.IdentifiedStackLikeStyle.endIdentifiedStackLikeStyle(b);
1995
- }
1996
- function writeIdentifiedTextStyle(b, entry, usv) {
1997
- const idOff = writeIdentifier(b, entry);
1998
- const style = writeTextStyle(b, entry, usv);
1999
- Duc.IdentifiedTextStyle.startIdentifiedTextStyle(b);
2000
- Duc.IdentifiedTextStyle.addId(b, idOff);
2001
- Duc.IdentifiedTextStyle.addStyle(b, style);
2002
- return Duc.IdentifiedTextStyle.endIdentifiedTextStyle(b);
2003
- }
2004
- function writeIdentifiedDimensionStyle(b, entry, usv) {
2005
- const idOff = writeIdentifier(b, entry);
2006
- const style = writeDimStyle(b, entry, usv);
2007
- Duc.IdentifiedDimensionStyle.startIdentifiedDimensionStyle(b);
2008
- Duc.IdentifiedDimensionStyle.addId(b, idOff);
2009
- Duc.IdentifiedDimensionStyle.addStyle(b, style);
2010
- return Duc.IdentifiedDimensionStyle.endIdentifiedDimensionStyle(b);
2011
- }
2012
- function writeIdentifiedLeaderStyle(b, entry, usv) {
2013
- const idOff = writeIdentifier(b, entry);
2014
- const style = writeLeaderStyle(b, entry, usv);
2015
- Duc.IdentifiedLeaderStyle.startIdentifiedLeaderStyle(b);
2016
- Duc.IdentifiedLeaderStyle.addId(b, idOff);
2017
- Duc.IdentifiedLeaderStyle.addStyle(b, style);
2018
- return Duc.IdentifiedLeaderStyle.endIdentifiedLeaderStyle(b);
2019
- }
2020
- function writeIdentifiedFCFStyle(b, entry, usv) {
2021
- const idOff = writeIdentifier(b, entry);
2022
- const style = writeFcfStyle(b, entry, usv);
2023
- Duc.IdentifiedFCFStyle.startIdentifiedFCFStyle(b);
2024
- Duc.IdentifiedFCFStyle.addId(b, idOff);
2025
- Duc.IdentifiedFCFStyle.addStyle(b, style);
2026
- return Duc.IdentifiedFCFStyle.endIdentifiedFCFStyle(b);
2027
- }
2028
- function writeIdentifiedTableStyle(b, entry, usv) {
2029
- const idOff = writeIdentifier(b, entry);
2030
- const style = writeTableStyle(b, entry, usv);
2031
- Duc.IdentifiedTableStyle.startIdentifiedTableStyle(b);
2032
- Duc.IdentifiedTableStyle.addId(b, idOff);
2033
- Duc.IdentifiedTableStyle.addStyle(b, style);
2034
- return Duc.IdentifiedTableStyle.endIdentifiedTableStyle(b);
2035
- }
2036
- function writeIdentifiedDocStyle(b, entry, usv) {
2037
- const idOff = writeIdentifier(b, entry);
2038
- const style = writeDocStyle(b, entry, usv);
2039
- Duc.IdentifiedDocStyle.startIdentifiedDocStyle(b);
2040
- Duc.IdentifiedDocStyle.addId(b, idOff);
2041
- Duc.IdentifiedDocStyle.addStyle(b, style);
2042
- return Duc.IdentifiedDocStyle.endIdentifiedDocStyle(b);
2043
- }
2044
- function writeIdentifiedViewportStyle(b, entry, usv) {
2045
- const idOff = writeIdentifier(b, entry);
2046
- const style = writeViewportStyle(b, entry, usv);
2047
- Duc.IdentifiedViewportStyle.startIdentifiedViewportStyle(b);
2048
- Duc.IdentifiedViewportStyle.addId(b, idOff);
2049
- Duc.IdentifiedViewportStyle.addStyle(b, style);
2050
- return Duc.IdentifiedViewportStyle.endIdentifiedViewportStyle(b);
2051
- }
2052
- function writeIdentifiedHatchStyle(b, entry, usv) {
2053
- const idOff = writeIdentifier(b, entry);
2054
- const style = writeHatchStyle(b, entry, usv);
2055
- Duc.IdentifiedHatchStyle.startIdentifiedHatchStyle(b);
2056
- Duc.IdentifiedHatchStyle.addId(b, idOff);
2057
- if (style)
2058
- Duc.IdentifiedHatchStyle.addStyle(b, style);
2059
- return Duc.IdentifiedHatchStyle.endIdentifiedHatchStyle(b);
2060
- }
2061
- function writeIdentifiedXRayStyle(b, entry, usv) {
2062
- const idOff = writeIdentifier(b, entry);
2063
- const style = writeXRayStyle(b, entry, usv);
2064
- Duc.IdentifiedXRayStyle.startIdentifiedXRayStyle(b);
2065
- Duc.IdentifiedXRayStyle.addId(b, idOff);
2066
- Duc.IdentifiedXRayStyle.addStyle(b, style);
2067
- return Duc.IdentifiedXRayStyle.endIdentifiedXRayStyle(b);
2068
- }
2069
- function serializeStandardStyles(b, s, usv) {
2070
- const commonVec = s.commonStyles.length
2071
- ? Duc.StandardStyles.createCommonStylesVector(b, s.commonStyles.map(cs => writeIdentifiedCommonStyle(b, cs, usv)))
2072
- : undefined;
2073
- const stackLikeVec = s.stackLikeStyles.length
2074
- ? Duc.StandardStyles.createStackLikeStylesVector(b, s.stackLikeStyles.map(st => writeIdentifiedStackLikeStyle(b, st, usv)))
2075
- : undefined;
2076
- const textVec = s.textStyles.length
2077
- ? Duc.StandardStyles.createTextStylesVector(b, s.textStyles.map(ts => writeIdentifiedTextStyle(b, ts, usv)))
2078
- : undefined;
2079
- const dimVec = s.dimensionStyles.length
2080
- ? Duc.StandardStyles.createDimensionStylesVector(b, s.dimensionStyles.map(ds => writeIdentifiedDimensionStyle(b, ds, usv)))
2081
- : undefined;
2082
- const leaderVec = s.leaderStyles.length
2083
- ? Duc.StandardStyles.createLeaderStylesVector(b, s.leaderStyles.map(ls => writeIdentifiedLeaderStyle(b, ls, usv)))
2084
- : undefined;
2085
- const fcfVec = s.featureControlFrameStyles.length
2086
- ? Duc.StandardStyles.createFeatureControlFrameStylesVector(b, s.featureControlFrameStyles.map(fs => writeIdentifiedFCFStyle(b, fs, usv)))
2087
- : undefined;
2088
- const tableVec = s.tableStyles.length
2089
- ? Duc.StandardStyles.createTableStylesVector(b, s.tableStyles.map(ts => writeIdentifiedTableStyle(b, ts, usv)))
2090
- : undefined;
2091
- const docVec = s.docStyles.length
2092
- ? Duc.StandardStyles.createDocStylesVector(b, s.docStyles.map(ds => writeIdentifiedDocStyle(b, ds, usv)))
2093
- : undefined;
2094
- const viewportVec = s.viewportStyles.length
2095
- ? Duc.StandardStyles.createViewportStylesVector(b, s.viewportStyles.map(vs => writeIdentifiedViewportStyle(b, vs, usv)))
2096
- : undefined;
2097
- const hatchVec = s.hatchStyles.length
2098
- ? Duc.StandardStyles.createHatchStylesVector(b, s.hatchStyles.map(hs => writeIdentifiedHatchStyle(b, hs, usv)))
2099
- : undefined;
2100
- const xrayVec = s.xrayStyles.length
2101
- ? Duc.StandardStyles.createXrayStylesVector(b, s.xrayStyles.map(xs => writeIdentifiedXRayStyle(b, xs, usv)))
2102
- : undefined;
2103
- Duc.StandardStyles.startStandardStyles(b);
2104
- if (commonVec)
2105
- Duc.StandardStyles.addCommonStyles(b, commonVec);
2106
- if (stackLikeVec)
2107
- Duc.StandardStyles.addStackLikeStyles(b, stackLikeVec);
2108
- if (textVec)
2109
- Duc.StandardStyles.addTextStyles(b, textVec);
2110
- if (dimVec)
2111
- Duc.StandardStyles.addDimensionStyles(b, dimVec);
2112
- if (leaderVec)
2113
- Duc.StandardStyles.addLeaderStyles(b, leaderVec);
2114
- if (fcfVec)
2115
- Duc.StandardStyles.addFeatureControlFrameStyles(b, fcfVec);
2116
- if (tableVec)
2117
- Duc.StandardStyles.addTableStyles(b, tableVec);
2118
- if (docVec)
2119
- Duc.StandardStyles.addDocStyles(b, docVec);
2120
- if (viewportVec)
2121
- Duc.StandardStyles.addViewportStyles(b, viewportVec);
2122
- if (hatchVec)
2123
- Duc.StandardStyles.addHatchStyles(b, hatchVec);
2124
- if (xrayVec)
2125
- Duc.StandardStyles.addXrayStyles(b, xrayVec);
2126
- return Duc.StandardStyles.endStandardStyles(b);
2127
- }
2128
- function serializeStandardViewSettings(b, v, usv) {
2129
- const viewsVec = v.views && v.views.length
2130
- ? Duc.StandardViewSettings.createViewsVector(b, v.views.map((entry) => {
2131
- const id = writeIdentifier(b, entry);
2132
- const view = writeView(b, entry, usv);
2133
- Duc.IdentifiedView.startIdentifiedView(b);
2134
- Duc.IdentifiedView.addId(b, id);
2135
- Duc.IdentifiedView.addView(b, view);
2136
- return Duc.IdentifiedView.endIdentifiedView(b);
2137
- }))
2138
- : undefined;
2139
- const ucsVec = v.ucs && v.ucs.length
2140
- ? Duc.StandardViewSettings.createUcsVector(b, v.ucs.map((entry) => {
2141
- const id = writeIdentifier(b, entry);
2142
- const ucs = writeUcs(b, entry);
2143
- Duc.IdentifiedUcs.startIdentifiedUcs(b);
2144
- Duc.IdentifiedUcs.addId(b, id);
2145
- Duc.IdentifiedUcs.addUcs(b, ucs);
2146
- return Duc.IdentifiedUcs.endIdentifiedUcs(b);
2147
- }))
2148
- : undefined;
2149
- const gridsVec = v.gridSettings && v.gridSettings.length
2150
- ? Duc.StandardViewSettings.createGridSettingsVector(b, v.gridSettings.map((entry) => {
2151
- const id = writeIdentifier(b, entry);
2152
- const settings = writeGridSettings(b, entry, usv);
2153
- Duc.IdentifiedGridSettings.startIdentifiedGridSettings(b);
2154
- Duc.IdentifiedGridSettings.addId(b, id);
2155
- Duc.IdentifiedGridSettings.addSettings(b, settings);
2156
- return Duc.IdentifiedGridSettings.endIdentifiedGridSettings(b);
2157
- }))
2158
- : undefined;
2159
- const snapsVec = v.snapSettings && v.snapSettings.length
2160
- ? Duc.StandardViewSettings.createSnapSettingsVector(b, v.snapSettings.map((entry) => {
2161
- const id = writeIdentifier(b, entry);
2162
- const settings = writeSnapSettings(b, entry, usv);
2163
- Duc.IdentifiedSnapSettings.startIdentifiedSnapSettings(b);
2164
- Duc.IdentifiedSnapSettings.addId(b, id);
2165
- Duc.IdentifiedSnapSettings.addSettings(b, settings);
2166
- return Duc.IdentifiedSnapSettings.endIdentifiedSnapSettings(b);
2167
- }))
2168
- : undefined;
2169
- Duc.StandardViewSettings.startStandardViewSettings(b);
2170
- if (viewsVec)
2171
- Duc.StandardViewSettings.addViews(b, viewsVec);
2172
- if (ucsVec)
2173
- Duc.StandardViewSettings.addUcs(b, ucsVec);
2174
- if (gridsVec)
2175
- Duc.StandardViewSettings.addGridSettings(b, gridsVec);
2176
- if (snapsVec)
2177
- Duc.StandardViewSettings.addSnapSettings(b, snapsVec);
2178
- return Duc.StandardViewSettings.endStandardViewSettings(b);
2179
- }
2180
- function serializeStandardValidation(b, val, usv) {
2181
- Duc.StandardValidation.startStandardValidation(b);
2182
- if (val.dimensionRules) {
2183
- Duc.DimensionValidationRules.startDimensionValidationRules(b);
2184
- if (val.dimensionRules.minTextHeight !== undefined)
2185
- Duc.DimensionValidationRules.addMinTextHeight(b, getPrecisionValue(val.dimensionRules.minTextHeight, usv));
2186
- if (val.dimensionRules.maxTextHeight !== undefined)
2187
- Duc.DimensionValidationRules.addMaxTextHeight(b, getPrecisionValue(val.dimensionRules.maxTextHeight, usv));
2188
- if (val.dimensionRules.allowedPrecisions) {
2189
- Duc.DimensionValidationRules.addAllowedPrecisions(b, Duc.DimensionValidationRules.createAllowedPrecisionsVector(b, val.dimensionRules.allowedPrecisions));
2190
- }
2191
- const dr = Duc.DimensionValidationRules.endDimensionValidationRules(b);
2192
- Duc.StandardValidation.addDimensionRules(b, dr);
2193
- }
2194
- if (val.layerRules) {
2195
- const prohibited = val.layerRules.prohibitedLayerNames
2196
- ? Duc.LayerValidationRules.createProhibitedLayerNamesVector(b, val.layerRules.prohibitedLayerNames.map(s => b.createString(s)))
2197
- : undefined;
2198
- Duc.LayerValidationRules.startLayerValidationRules(b);
2199
- if (prohibited)
2200
- Duc.LayerValidationRules.addProhibitedLayerNames(b, prohibited);
2201
- const lr = Duc.LayerValidationRules.endLayerValidationRules(b);
2202
- Duc.StandardValidation.addLayerRules(b, lr);
71
+ const hasLegacyDelta = deltas.some((d) => typeof (d === null || d === void 0 ? void 0 : d.versionNumber) !== "number" ||
72
+ typeof (d === null || d === void 0 ? void 0 : d.schemaVersion) !== "number" ||
73
+ typeof (d === null || d === void 0 ? void 0 : d.baseCheckpointId) !== "string");
74
+ if (hasLegacyDelta) {
75
+ return true;
2203
76
  }
2204
- return Duc.StandardValidation.endStandardValidation(b);
2205
- }
2206
- function serializeStandard(b, s, usv) {
2207
- const ident = writeIdentifier(b, s);
2208
- const version = b.createString(s.version);
2209
- const overrides = s.overrides ? serializeStandardOverrides(b, s.overrides, usv) : undefined;
2210
- const styles = s.styles ? serializeStandardStyles(b, s.styles, usv) : undefined;
2211
- const view = s.viewSettings ? serializeStandardViewSettings(b, s.viewSettings, usv) : undefined;
2212
- const units = s.units ? serializeStandardUnits(b, s.units, usv) : undefined;
2213
- const validation = s.validation ? serializeStandardValidation(b, s.validation, usv) : undefined;
2214
- Duc.Standard.startStandard(b);
2215
- Duc.Standard.addIdentifier(b, ident);
2216
- Duc.Standard.addVersion(b, version);
2217
- Duc.Standard.addReadonly(b, s.readonly);
2218
- if (overrides)
2219
- Duc.Standard.addOverrides(b, overrides);
2220
- if (styles)
2221
- Duc.Standard.addStyles(b, styles);
2222
- if (view)
2223
- Duc.Standard.addViewSettings(b, view);
2224
- if (units)
2225
- Duc.Standard.addUnits(b, units);
2226
- if (validation)
2227
- Duc.Standard.addValidation(b, validation);
2228
- return Duc.Standard.endStandard(b);
2229
- }
2230
- /**
2231
- * VersionGraph
2232
- */
2233
- function serializeVersionBase(b, v) {
2234
- const id = b.createString(v.id);
2235
- const parent = v.parentId ? b.createString(v.parentId) : undefined;
2236
- const desc = v.description ? b.createString(v.description) : undefined;
2237
- const user = v.userId ? b.createString(v.userId) : undefined;
2238
- Duc.VersionBase.startVersionBase(b);
2239
- Duc.VersionBase.addId(b, id);
2240
- if (parent)
2241
- Duc.VersionBase.addParentId(b, parent);
2242
- Duc.VersionBase.addTimestamp(b, BigInt(v.timestamp));
2243
- if (desc)
2244
- Duc.VersionBase.addDescription(b, desc);
2245
- Duc.VersionBase.addIsManualSave(b, v.isManualSave);
2246
- if (user)
2247
- Duc.VersionBase.addUserId(b, user);
2248
- return Duc.VersionBase.endVersionBase(b);
2249
- }
2250
- function serializeCheckpoint(b, c) {
2251
- const base = serializeVersionBase(b, c);
2252
- const data = b.createByteVector(c.data);
2253
- Duc.Checkpoint.startCheckpoint(b);
2254
- Duc.Checkpoint.addBase(b, base);
2255
- Duc.Checkpoint.addData(b, data);
2256
- Duc.Checkpoint.addSizeBytes(b, BigInt(c.sizeBytes));
2257
- return Duc.Checkpoint.endCheckpoint(b);
2258
- }
2259
- function writeJsonPatch(b, p) {
2260
- // Compress the JSON patch data
2261
- const patchData = zlibSync(strToU8(JSON.stringify(p)));
2262
- const offset = Duc.Delta.createPatchVector(b, patchData);
2263
- return { offset, sizeBytes: patchData.length };
77
+ return false;
2264
78
  }
2265
- function serializeDelta(b, d) {
2266
- const base = serializeVersionBase(b, d);
2267
- const { offset: patch, sizeBytes } = writeJsonPatch(b, d.patch);
2268
- Duc.Delta.startDelta(b);
2269
- Duc.Delta.addBase(b, base);
2270
- Duc.Delta.addPatch(b, patch);
2271
- Duc.Delta.addSizeBytes(b, BigInt(sizeBytes));
2272
- return Duc.Delta.endDelta(b);
2273
- }
2274
- function serializeDucVersionGraph(b, vg) {
2275
- const userCheckpoint = b.createString(vg.userCheckpointVersionId);
2276
- const latest = b.createString(vg.latestVersionId);
2277
- const checkpoints = Duc.VersionGraph.createCheckpointsVector(b, vg.checkpoints.map(c => serializeCheckpoint(b, c)));
2278
- const deltas = Duc.VersionGraph.createDeltasVector(b, vg.deltas.map(d => serializeDelta(b, d)));
2279
- Duc.VersionGraphMetadata.startVersionGraphMetadata(b);
2280
- Duc.VersionGraphMetadata.addLastPruned(b, BigInt(vg.metadata.lastPruned));
2281
- Duc.VersionGraphMetadata.addTotalSize(b, BigInt(vg.metadata.totalSize));
2282
- const meta = Duc.VersionGraphMetadata.endVersionGraphMetadata(b);
2283
- Duc.VersionGraph.startVersionGraph(b);
2284
- Duc.VersionGraph.addUserCheckpointVersionId(b, userCheckpoint);
2285
- Duc.VersionGraph.addLatestVersionId(b, latest);
2286
- Duc.VersionGraph.addCheckpoints(b, checkpoints);
2287
- Duc.VersionGraph.addDeltas(b, deltas);
2288
- Duc.VersionGraph.addMetadata(b, meta);
2289
- return Duc.VersionGraph.endVersionGraph(b);
2290
- }
2291
- // #endregion
2292
- // #region STATE SERIALIZERS
2293
- function serializeDucGlobalState(builder, state, usv) {
2294
- const nameOffset = writeString(builder, state.name);
2295
- const viewBackgroundColorOffset = writeString(builder, state.viewBackgroundColor);
2296
- const mainScopeOffset = writeString(builder, state.mainScope);
2297
- Duc.DucGlobalState.startDucGlobalState(builder);
2298
- if (nameOffset)
2299
- Duc.DucGlobalState.addName(builder, nameOffset);
2300
- if (viewBackgroundColorOffset)
2301
- Duc.DucGlobalState.addViewBackgroundColor(builder, viewBackgroundColorOffset);
2302
- if (mainScopeOffset)
2303
- Duc.DucGlobalState.addMainScope(builder, mainScopeOffset);
2304
- Duc.DucGlobalState.addDashSpacingScale(builder, state.dashSpacingScale);
2305
- Duc.DucGlobalState.addIsDashSpacingAffectedByViewportScale(builder, state.isDashSpacingAffectedByViewportScale);
2306
- Duc.DucGlobalState.addScopeExponentThreshold(builder, state.scopeExponentThreshold);
2307
- if (state.pruningLevel)
2308
- Duc.DucGlobalState.addPruningLevel(builder, state.pruningLevel);
2309
- Duc.DucGlobalState.addDimensionsAssociativeByDefault(builder, state.dimensionsAssociativeByDefault);
2310
- Duc.DucGlobalState.addUseAnnotativeScaling(builder, state.useAnnotativeScaling);
2311
- Duc.DucGlobalState.addDisplayPrecisionLinear(builder, state.displayPrecision.linear);
2312
- Duc.DucGlobalState.addDisplayPrecisionAngular(builder, state.displayPrecision.angular);
2313
- return Duc.DucGlobalState.endDucGlobalState(builder);
2314
- }
2315
- function serializeDucLocalState(builder, state, usv) {
2316
- const scopeOffset = writeString(builder, state.scope);
2317
- const activeStandardIdOffset = writeString(builder, state.activeStandardId);
2318
- const activeGridSettingsVector = writeStringVector(builder, state.activeGridSettings);
2319
- const activeSnapSettingsOffset = writeString(builder, state.activeSnapSettings);
2320
- const currentItemStrokeOffset = writeElementStroke(builder, state.currentItemStroke, usv);
2321
- const currentItemBackgroundOffset = writeElementBackground(builder, state.currentItemBackground, usv);
2322
- const currentItemFontFamilyOffset = state.currentItemFontFamily && writeString(builder, state.currentItemFontFamily.toString());
2323
- Duc.DucLocalState.startDucLocalState(builder);
2324
- if (scopeOffset)
2325
- Duc.DucLocalState.addScope(builder, scopeOffset);
2326
- if (activeStandardIdOffset)
2327
- Duc.DucLocalState.addActiveStandardId(builder, activeStandardIdOffset);
2328
- if (state.scrollX)
2329
- Duc.DucLocalState.addScrollX(builder, getPrecisionValue(state.scrollX, usv));
2330
- if (state.scrollY)
2331
- Duc.DucLocalState.addScrollY(builder, getPrecisionValue(state.scrollY, usv));
2332
- if (state.zoom)
2333
- Duc.DucLocalState.addZoom(builder, state.zoom.value);
2334
- if (activeGridSettingsVector)
2335
- Duc.DucLocalState.addActiveGridSettings(builder, activeGridSettingsVector);
2336
- if (activeSnapSettingsOffset)
2337
- Duc.DucLocalState.addActiveSnapSettings(builder, activeSnapSettingsOffset);
2338
- Duc.DucLocalState.addIsBindingEnabled(builder, state.isBindingEnabled);
2339
- if (currentItemStrokeOffset)
2340
- Duc.DucLocalState.addCurrentItemStroke(builder, currentItemStrokeOffset);
2341
- if (currentItemBackgroundOffset)
2342
- Duc.DucLocalState.addCurrentItemBackground(builder, currentItemBackgroundOffset);
2343
- Duc.DucLocalState.addCurrentItemOpacity(builder, state.currentItemOpacity);
2344
- if (currentItemFontFamilyOffset)
2345
- Duc.DucLocalState.addCurrentItemFontFamily(builder, currentItemFontFamilyOffset);
2346
- if (state.currentItemFontSize)
2347
- Duc.DucLocalState.addCurrentItemFontSize(builder, getPrecisionValue(state.currentItemFontSize, usv));
2348
- if (state.currentItemTextAlign)
2349
- Duc.DucLocalState.addCurrentItemTextAlign(builder, state.currentItemTextAlign);
2350
- if (state.currentItemRoundness)
2351
- Duc.DucLocalState.addCurrentItemRoundness(builder, getPrecisionValue(state.currentItemRoundness, usv));
2352
- Duc.DucLocalState.addPenMode(builder, state.penMode);
2353
- Duc.DucLocalState.addViewModeEnabled(builder, state.viewModeEnabled);
2354
- Duc.DucLocalState.addObjectsSnapModeEnabled(builder, state.objectsSnapModeEnabled);
2355
- Duc.DucLocalState.addGridModeEnabled(builder, state.gridModeEnabled);
2356
- Duc.DucLocalState.addOutlineModeEnabled(builder, state.outlineModeEnabled);
2357
- Duc.DucLocalState.addManualSaveMode(builder, state.manualSaveMode);
2358
- return Duc.DucLocalState.endDucLocalState(builder);
2359
- }
2360
- function serializeDictionary(builder, dictionary) {
2361
- if (!dictionary)
2362
- return undefined;
2363
- const entries = Object.entries(dictionary).map(([key, value]) => {
2364
- const keyOffset = builder.createString(key);
2365
- const valueOffset = builder.createString(value);
2366
- Duc.DictionaryEntry.startDictionaryEntry(builder);
2367
- Duc.DictionaryEntry.addKey(builder, keyOffset);
2368
- Duc.DictionaryEntry.addValue(builder, valueOffset);
2369
- return Duc.DictionaryEntry.endDictionaryEntry(builder);
2370
- });
2371
- return Duc.ExportedDataState.createDictionaryVector(builder, entries);
2372
- }
2373
- // #endregion
2374
- function serializeDucGroup(builder, g, usv) {
2375
- const id = builder.createString(g.id);
2376
- const stack = writeStackBase(builder, g, usv);
2377
- Duc.DucGroup.startDucGroup(builder);
2378
- Duc.DucGroup.addId(builder, id);
2379
- Duc.DucGroup.addStackBase(builder, stack);
2380
- return Duc.DucGroup.endDucGroup(builder);
2381
- }
2382
- function serializeDucRegion(builder, r, usv) {
2383
- const id = builder.createString(r.id);
2384
- const stack = writeStackBase(builder, r, usv);
2385
- Duc.DucRegion.startDucRegion(builder);
2386
- Duc.DucRegion.addId(builder, id);
2387
- Duc.DucRegion.addStackBase(builder, stack);
2388
- Duc.DucRegion.addBooleanOperation(builder, r.booleanOperation);
2389
- return Duc.DucRegion.endDucRegion(builder);
2390
- }
2391
- function serializeDucLayer(builder, l, usv) {
2392
- const id = builder.createString(l.id);
2393
- const stack = writeStackBase(builder, l, usv);
2394
- const overrides = l.overrides ? (() => {
2395
- const stroke = writeElementStroke(builder, l.overrides.stroke, usv);
2396
- const bg = writeElementBackground(builder, l.overrides.background, usv);
2397
- Duc.DucLayerOverrides.startDucLayerOverrides(builder);
2398
- if (stroke)
2399
- Duc.DucLayerOverrides.addStroke(builder, stroke);
2400
- if (bg)
2401
- Duc.DucLayerOverrides.addBackground(builder, bg);
2402
- return Duc.DucLayerOverrides.endDucLayerOverrides(builder);
2403
- })() : undefined;
2404
- Duc.DucLayer.startDucLayer(builder);
2405
- Duc.DucLayer.addId(builder, id);
2406
- Duc.DucLayer.addStackBase(builder, stack);
2407
- Duc.DucLayer.addReadonly(builder, l.readonly);
2408
- if (overrides)
2409
- Duc.DucLayer.addOverrides(builder, overrides);
2410
- return Duc.DucLayer.endDucLayer(builder);
2411
- }
2412
- /**
2413
- * External files map serializer: returns vector offset or undefined
2414
- */
2415
- function serializeExternalFiles(builder, files, usv) {
2416
- if (!files)
2417
- return undefined;
2418
- const entries = Object.entries(files).map(([key, value]) => {
2419
- const keyOff = builder.createString(key);
2420
- const mt = builder.createString(value.mimeType);
2421
- const idOff = builder.createString(value.id);
2422
- let dataVectorOffset = undefined;
2423
- if (value.data) {
2424
- dataVectorOffset = Duc.DucExternalFileData.createDataVector(builder, value.data);
2425
- }
2426
- Duc.DucExternalFileData.startDucExternalFileData(builder);
2427
- Duc.DucExternalFileData.addMimeType(builder, mt);
2428
- Duc.DucExternalFileData.addId(builder, idOff);
2429
- if (dataVectorOffset)
2430
- Duc.DucExternalFileData.addData(builder, dataVectorOffset);
2431
- Duc.DucExternalFileData.addCreated(builder, BigInt(value.created));
2432
- if (value.lastRetrieved !== undefined)
2433
- Duc.DucExternalFileData.addLastRetrieved(builder, BigInt(value.lastRetrieved));
2434
- const dataOff = Duc.DucExternalFileData.endDucExternalFileData(builder);
2435
- Duc.DucExternalFileEntry.startDucExternalFileEntry(builder);
2436
- Duc.DucExternalFileEntry.addKey(builder, keyOff);
2437
- Duc.DucExternalFileEntry.addValue(builder, dataOff);
2438
- return Duc.DucExternalFileEntry.endDucExternalFileEntry(builder);
2439
- });
2440
- // Build vector of entries
2441
- builder.startVector(4, entries.length, 4);
2442
- for (let i = entries.length - 1; i >= 0; i--)
2443
- builder.addOffset(entries[i]);
2444
- return builder.endVector();
2445
- }
2446
- export const DUC_SCHEMA_VERSION = (typeof process !== "undefined" && process.env && process.env.DUC_SCHEMA_VERSION) ||
2447
- (typeof import.meta !== "undefined" && import.meta.env && import.meta.env.DUC_SCHEMA_VERSION) ||
2448
- "0.0.0";
2449
- export const serializeDuc = (data_1, ...args_1) => __awaiter(void 0, [data_1, ...args_1], void 0, function* (data, useScopedValues = false, passThroughElementIds = [], restoreConfig = {}) {
2450
- const builder = new flatbuffers.Builder(1024);
2451
- const sanitized = restore(data, {
2452
- refreshDimensions: false,
2453
- syncInvalidIndices: (elements) => elements,
2454
- passThroughElementIds
2455
- }, restoreConfig);
2456
- const typeOffset = builder.createString(EXPORT_DATA_TYPES.duc);
2457
- const sourceOffset = builder.createString(typeof window !== "undefined" ? window.location.origin : "unknown");
2458
- const versionOffset = builder.createString(DUC_SCHEMA_VERSION);
2459
- // Serialize elements
2460
- const elementOffsets = sanitized.elements.map((element) => {
2461
- return writeElementWrapper(builder, element, useScopedValues);
2462
- });
2463
- const elementsOffset = Duc.ExportedDataState.createElementsVector(builder, elementOffsets);
2464
- // Serialize localState
2465
- const localStateOffset = serializeDucLocalState(builder, sanitized.localState, useScopedValues);
2466
- // Serialize files
2467
- const externalFilesOffset = serializeExternalFiles(builder, sanitized.files, useScopedValues);
2468
- // Serialize blocks
2469
- const blocksOffset = sanitized.blocks.length > 0
2470
- ? Duc.ExportedDataState.createBlocksVector(builder, sanitized.blocks.map(block => writeBlock(builder, block, useScopedValues)))
2471
- : null;
2472
- // Serialize block instances
2473
- const blockInstancesOffset = sanitized.blockInstances.length > 0
2474
- ? Duc.ExportedDataState.createBlockInstancesVector(builder, sanitized.blockInstances.map(instance => writeBlockInstance(builder, instance, useScopedValues)))
2475
- : null;
2476
- // Serialize block collections
2477
- const blockCollectionsOffset = sanitized.blockCollections.length > 0
2478
- ? Duc.ExportedDataState.createBlockCollectionsVector(builder, sanitized.blockCollections.map(collection => writeBlockCollection(builder, collection)))
2479
- : null;
2480
- // Serialize groups
2481
- const groupsOffset = sanitized.groups.length > 0
2482
- ? Duc.ExportedDataState.createGroupsVector(builder, sanitized.groups.map(group => serializeDucGroup(builder, group, useScopedValues)))
2483
- : null;
2484
- // Serialize regions
2485
- const regionsOffset = (sanitized.regions && sanitized.regions.length > 0)
2486
- ? Duc.ExportedDataState.createRegionsVector(builder, sanitized.regions.map(region => serializeDucRegion(builder, region, useScopedValues)))
2487
- : null;
2488
- // Serialize layers
2489
- const layersOffset = (sanitized.layers && sanitized.layers.length > 0)
2490
- ? Duc.ExportedDataState.createLayersVector(builder, sanitized.layers.map(layer => serializeDucLayer(builder, layer, useScopedValues)))
2491
- : null;
2492
- // Serialize standards
2493
- const standardsOffset = (sanitized.standards && sanitized.standards.length > 0)
2494
- ? Duc.ExportedDataState.createStandardsVector(builder, sanitized.standards.map(standard => serializeStandard(builder, standard, useScopedValues)))
2495
- : null;
2496
- // Serialize dictionary
2497
- const dictionaryOffset = (sanitized.dictionary && Object.keys(sanitized.dictionary).length > 0)
2498
- ? serializeDictionary(builder, sanitized.dictionary)
2499
- : null;
2500
- // Serialize duc_global_state
2501
- const ducGlobalStateOffset = sanitized.globalState
2502
- ? serializeDucGlobalState(builder, sanitized.globalState, useScopedValues)
2503
- : null;
2504
- // Serialize version_graph
2505
- const versionGraphOffset = sanitized.versionGraph
2506
- ? serializeDucVersionGraph(builder, sanitized.versionGraph)
2507
- : null;
2508
- // Serialize thumbnail (as byte vector if present)
2509
- const thumbnailOffset = sanitized.thumbnail
2510
- ? builder.createByteVector(sanitized.thumbnail)
2511
- : null;
2512
- // Serialize id (as string if present)
2513
- const idOffset = sanitized.id
2514
- ? builder.createString(sanitized.id)
2515
- : null;
2516
- Duc.ExportedDataState.startExportedDataState(builder);
2517
- Duc.ExportedDataState.addType(builder, typeOffset);
2518
- Duc.ExportedDataState.addVersion(builder, versionOffset);
2519
- Duc.ExportedDataState.addSource(builder, sourceOffset);
2520
- Duc.ExportedDataState.addElements(builder, elementsOffset);
2521
- Duc.ExportedDataState.addDucLocalState(builder, localStateOffset);
2522
- if (externalFilesOffset) {
2523
- Duc.ExportedDataState.addExternalFiles(builder, externalFilesOffset);
2524
- }
2525
- if (blocksOffset) {
2526
- Duc.ExportedDataState.addBlocks(builder, blocksOffset);
2527
- }
2528
- if (blockInstancesOffset) {
2529
- Duc.ExportedDataState.addBlockInstances(builder, blockInstancesOffset);
2530
- }
2531
- if (blockCollectionsOffset) {
2532
- Duc.ExportedDataState.addBlockCollections(builder, blockCollectionsOffset);
2533
- }
2534
- if (groupsOffset) {
2535
- Duc.ExportedDataState.addGroups(builder, groupsOffset);
2536
- }
2537
- if (regionsOffset) {
2538
- Duc.ExportedDataState.addRegions(builder, regionsOffset);
2539
- }
2540
- if (layersOffset) {
2541
- Duc.ExportedDataState.addLayers(builder, layersOffset);
2542
- }
2543
- if (standardsOffset) {
2544
- Duc.ExportedDataState.addStandards(builder, standardsOffset);
2545
- }
2546
- if (dictionaryOffset) {
2547
- Duc.ExportedDataState.addDictionary(builder, dictionaryOffset);
2548
- }
2549
- if (ducGlobalStateOffset) {
2550
- Duc.ExportedDataState.addDucGlobalState(builder, ducGlobalStateOffset);
2551
- }
2552
- if (versionGraphOffset) {
2553
- Duc.ExportedDataState.addVersionGraph(builder, versionGraphOffset);
2554
- }
2555
- if (thumbnailOffset) {
2556
- Duc.ExportedDataState.addThumbnail(builder, thumbnailOffset);
2557
- }
2558
- if (idOffset) {
2559
- Duc.ExportedDataState.addId(builder, idOffset);
2560
- }
2561
- const exportedDataStateOffset = Duc.ExportedDataState.endExportedDataState(builder);
2562
- builder.finish(exportedDataStateOffset, "DUC_");
2563
- return builder.asUint8Array();
2564
- });
2565
- // #endregion