@moondraft/import 0.0.0-stage → 0.2.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 (337) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +34 -0
  3. package/README.md +36 -2
  4. package/SOURCE.md +394 -0
  5. package/dist/adapter/convert.d.ts +144 -0
  6. package/dist/adapter/convert.js +2811 -0
  7. package/dist/adapter/figma-descriptions.d.ts +7 -0
  8. package/dist/adapter/figma-descriptions.js +34 -0
  9. package/dist/adapter/figma-grids.d.ts +12 -0
  10. package/dist/adapter/figma-grids.js +175 -0
  11. package/dist/adapter/figma-handoff.d.ts +12 -0
  12. package/dist/adapter/figma-handoff.js +167 -0
  13. package/dist/adapter/figma-hyperlinks.d.ts +13 -0
  14. package/dist/adapter/figma-hyperlinks.js +77 -0
  15. package/dist/adapter/figma.d.ts +12 -0
  16. package/dist/adapter/figma.js +40 -0
  17. package/dist/adapter/file-components.d.ts +20 -0
  18. package/dist/adapter/file-components.js +352 -0
  19. package/dist/adapter/file-resources.d.ts +29 -0
  20. package/dist/adapter/file-resources.js +851 -0
  21. package/dist/adapter/image-crop.d.ts +18 -0
  22. package/dist/adapter/image-crop.js +30 -0
  23. package/dist/adapter/index.d.ts +6 -0
  24. package/dist/adapter/index.js +9 -0
  25. package/dist/adapter/link.d.ts +49 -0
  26. package/dist/adapter/link.js +892 -0
  27. package/dist/adapter/payload.d.ts +31 -0
  28. package/dist/adapter/payload.js +78 -0
  29. package/dist/adapter/shapes.d.ts +31 -0
  30. package/dist/adapter/shapes.js +75 -0
  31. package/dist/adapter/variables.d.ts +45 -0
  32. package/dist/adapter/variables.js +106 -0
  33. package/dist/figma-file.d.ts +38 -0
  34. package/dist/figma-file.js +97 -0
  35. package/dist/figma-worker.d.ts +11 -0
  36. package/dist/figma-worker.js +12 -0
  37. package/dist/figma.d.ts +26 -0
  38. package/dist/figma.js +230 -0
  39. package/dist/index.d.ts +29 -0
  40. package/dist/index.js +50 -0
  41. package/dist/report.d.ts +42 -0
  42. package/dist/report.js +142 -0
  43. package/dist/serialize.d.ts +7 -0
  44. package/dist/serialize.js +79 -0
  45. package/dist/svg.d.ts +33 -0
  46. package/dist/svg.js +44 -0
  47. package/dist/syntax.d.ts +8 -0
  48. package/dist/syntax.js +19 -0
  49. package/dist/taco/figma-import/clipboard.d.ts +25 -0
  50. package/dist/taco/figma-import/clipboard.js +87 -0
  51. package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
  52. package/dist/taco/figma-import/clipboardSize.js +107 -0
  53. package/dist/taco/figma-import/container/compression.d.ts +9 -0
  54. package/dist/taco/figma-import/container/compression.js +174 -0
  55. package/dist/taco/figma-import/container/error.d.ts +15 -0
  56. package/dist/taco/figma-import/container/error.js +19 -0
  57. package/dist/taco/figma-import/container/kiwiContainer.d.ts +41 -0
  58. package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
  59. package/dist/taco/figma-import/container/limits.d.ts +22 -0
  60. package/dist/taco/figma-import/container/limits.js +22 -0
  61. package/dist/taco/figma-import/container/zip.d.ts +14 -0
  62. package/dist/taco/figma-import/container/zip.js +154 -0
  63. package/dist/taco/figma-import/figFile.d.ts +34 -0
  64. package/dist/taco/figma-import/figFile.js +91 -0
  65. package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
  66. package/dist/taco/figma-import/figFileDocument.js +100 -0
  67. package/dist/taco/figma-import/import/blobs.d.ts +10 -0
  68. package/dist/taco/figma-import/import/blobs.js +23 -0
  69. package/dist/taco/figma-import/import/carry.d.ts +24 -0
  70. package/dist/taco/figma-import/import/carry.js +66 -0
  71. package/dist/taco/figma-import/import/componentProps.d.ts +90 -0
  72. package/dist/taco/figma-import/import/componentProps.js +329 -0
  73. package/dist/taco/figma-import/import/componentSets.d.ts +85 -0
  74. package/dist/taco/figma-import/import/componentSets.js +647 -0
  75. package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
  76. package/dist/taco/figma-import/import/converters/effects.js +127 -0
  77. package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
  78. package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
  79. package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
  80. package/dist/taco/figma-import/import/converters/exportSettings.js +49 -0
  81. package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
  82. package/dist/taco/figma-import/import/converters/frame.js +63 -0
  83. package/dist/taco/figma-import/import/converters/gradient.d.ts +74 -0
  84. package/dist/taco/figma-import/import/converters/gradient.js +108 -0
  85. package/dist/taco/figma-import/import/converters/group.d.ts +19 -0
  86. package/dist/taco/figma-import/import/converters/group.js +30 -0
  87. package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
  88. package/dist/taco/figma-import/import/converters/image.js +94 -0
  89. package/dist/taco/figma-import/import/converters/layout.d.ts +33 -0
  90. package/dist/taco/figma-import/import/converters/layout.js +187 -0
  91. package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
  92. package/dist/taco/figma-import/import/converters/line.js +40 -0
  93. package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
  94. package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
  95. package/dist/taco/figma-import/import/converters/section.d.ts +8 -0
  96. package/dist/taco/figma-import/import/converters/section.js +29 -0
  97. package/dist/taco/figma-import/import/converters/shared.d.ts +71 -0
  98. package/dist/taco/figma-import/import/converters/shared.js +372 -0
  99. package/dist/taco/figma-import/import/converters/text.d.ts +54 -0
  100. package/dist/taco/figma-import/import/converters/text.js +707 -0
  101. package/dist/taco/figma-import/import/converters/vector.d.ts +105 -0
  102. package/dist/taco/figma-import/import/converters/vector.js +609 -0
  103. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +114 -0
  104. package/dist/taco/figma-import/import/converters/vectorNetwork.js +503 -0
  105. package/dist/taco/figma-import/import/fields.d.ts +15 -0
  106. package/dist/taco/figma-import/import/fields.js +29 -0
  107. package/dist/taco/figma-import/import/instances.d.ts +184 -0
  108. package/dist/taco/figma-import/import/instances.js +1530 -0
  109. package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
  110. package/dist/taco/figma-import/import/nestingCycles.js +488 -0
  111. package/dist/taco/figma-import/import/slots.d.ts +56 -0
  112. package/dist/taco/figma-import/import/slots.js +96 -0
  113. package/dist/taco/figma-import/import/styles.d.ts +48 -0
  114. package/dist/taco/figma-import/import/styles.js +48 -0
  115. package/dist/taco/figma-import/import/tree.d.ts +66 -0
  116. package/dist/taco/figma-import/import/tree.js +194 -0
  117. package/dist/taco/figma-import/import/types.d.ts +232 -0
  118. package/dist/taco/figma-import/import/types.js +33 -0
  119. package/dist/taco/figma-import/import/variables.d.ts +137 -0
  120. package/dist/taco/figma-import/import/variables.js +769 -0
  121. package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
  122. package/dist/taco/figma-import/import/variantTrees.js +520 -0
  123. package/dist/taco/figma-import/import/walk.d.ts +207 -0
  124. package/dist/taco/figma-import/import/walk.js +1464 -0
  125. package/dist/taco/figma-import/index.d.ts +22 -0
  126. package/dist/taco/figma-import/index.js +13 -0
  127. package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
  128. package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
  129. package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
  130. package/dist/taco/figma-import/kiwi/error.js +29 -0
  131. package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
  132. package/dist/taco/figma-import/kiwi/limits.js +18 -0
  133. package/dist/taco/figma-import/kiwi/message.d.ts +12 -0
  134. package/dist/taco/figma-import/kiwi/message.js +147 -0
  135. package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
  136. package/dist/taco/figma-import/kiwi/schema.js +206 -0
  137. package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
  138. package/dist/taco/figma-import/kiwi/types.js +18 -0
  139. package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
  140. package/dist/taco/model/agent-hidden-fields.js +29 -0
  141. package/dist/taco/model/asset-users.d.ts +23 -0
  142. package/dist/taco/model/asset-users.js +128 -0
  143. package/dist/taco/model/auto-layout-lines.d.ts +32 -0
  144. package/dist/taco/model/auto-layout-lines.js +70 -0
  145. package/dist/taco/model/codec.d.ts +444 -0
  146. package/dist/taco/model/codec.js +5665 -0
  147. package/dist/taco/model/color.d.ts +11 -0
  148. package/dist/taco/model/color.js +61 -0
  149. package/dist/taco/model/comment-operations.d.ts +102 -0
  150. package/dist/taco/model/comment-operations.js +227 -0
  151. package/dist/taco/model/component-evaluation.d.ts +96 -0
  152. package/dist/taco/model/component-evaluation.js +555 -0
  153. package/dist/taco/model/component-expressions.d.ts +242 -0
  154. package/dist/taco/model/component-expressions.js +1082 -0
  155. package/dist/taco/model/component-properties.d.ts +111 -0
  156. package/dist/taco/model/component-properties.js +339 -0
  157. package/dist/taco/model/component-samples.d.ts +83 -0
  158. package/dist/taco/model/component-samples.js +290 -0
  159. package/dist/taco/model/component-validity.d.ts +85 -0
  160. package/dist/taco/model/component-validity.js +397 -0
  161. package/dist/taco/model/components.d.ts +155 -0
  162. package/dist/taco/model/components.js +505 -0
  163. package/dist/taco/model/connector-ends.d.ts +20 -0
  164. package/dist/taco/model/connector-ends.js +188 -0
  165. package/dist/taco/model/connector-geometry.d.ts +74 -0
  166. package/dist/taco/model/connector-geometry.js +293 -0
  167. package/dist/taco/model/corner-radii.d.ts +26 -0
  168. package/dist/taco/model/corner-radii.js +47 -0
  169. package/dist/taco/model/derivations.d.ts +81 -0
  170. package/dist/taco/model/derivations.js +151 -0
  171. package/dist/taco/model/export-settings.d.ts +53 -0
  172. package/dist/taco/model/export-settings.js +156 -0
  173. package/dist/taco/model/expressions/ast.d.ts +153 -0
  174. package/dist/taco/model/expressions/ast.js +6 -0
  175. package/dist/taco/model/expressions/cache.d.ts +23 -0
  176. package/dist/taco/model/expressions/cache.js +43 -0
  177. package/dist/taco/model/expressions/check.d.ts +72 -0
  178. package/dist/taco/model/expressions/check.js +517 -0
  179. package/dist/taco/model/expressions/completion.d.ts +61 -0
  180. package/dist/taco/model/expressions/completion.js +421 -0
  181. package/dist/taco/model/expressions/evaluate.d.ts +32 -0
  182. package/dist/taco/model/expressions/evaluate.js +519 -0
  183. package/dist/taco/model/expressions/forms.d.ts +84 -0
  184. package/dist/taco/model/expressions/forms.js +200 -0
  185. package/dist/taco/model/expressions/index.d.ts +14 -0
  186. package/dist/taco/model/expressions/index.js +17 -0
  187. package/dist/taco/model/expressions/lexer.d.ts +42 -0
  188. package/dist/taco/model/expressions/lexer.js +213 -0
  189. package/dist/taco/model/expressions/library.d.ts +33 -0
  190. package/dist/taco/model/expressions/library.js +117 -0
  191. package/dist/taco/model/expressions/names.d.ts +43 -0
  192. package/dist/taco/model/expressions/names.js +99 -0
  193. package/dist/taco/model/expressions/parser.d.ts +15 -0
  194. package/dist/taco/model/expressions/parser.js +438 -0
  195. package/dist/taco/model/expressions/rename.d.ts +34 -0
  196. package/dist/taco/model/expressions/rename.js +46 -0
  197. package/dist/taco/model/expressions/source.d.ts +15 -0
  198. package/dist/taco/model/expressions/source.js +161 -0
  199. package/dist/taco/model/expressions/types.d.ts +119 -0
  200. package/dist/taco/model/expressions/types.js +102 -0
  201. package/dist/taco/model/expressions/values.d.ts +97 -0
  202. package/dist/taco/model/expressions/values.js +160 -0
  203. package/dist/taco/model/geometry-limits.d.ts +16 -0
  204. package/dist/taco/model/geometry-limits.js +67 -0
  205. package/dist/taco/model/geometry.d.ts +47 -0
  206. package/dist/taco/model/geometry.js +193 -0
  207. package/dist/taco/model/group-bounds.d.ts +38 -0
  208. package/dist/taco/model/group-bounds.js +144 -0
  209. package/dist/taco/model/id-table.d.ts +37 -0
  210. package/dist/taco/model/id-table.js +80 -0
  211. package/dist/taco/model/index.d.ts +25 -0
  212. package/dist/taco/model/index.js +27 -0
  213. package/dist/taco/model/instance-resolver.d.ts +376 -0
  214. package/dist/taco/model/instance-resolver.js +1778 -0
  215. package/dist/taco/model/layer-syntax.d.ts +340 -0
  216. package/dist/taco/model/layer-syntax.js +3506 -0
  217. package/dist/taco/model/layout/constraints.d.ts +84 -0
  218. package/dist/taco/model/layout/constraints.js +445 -0
  219. package/dist/taco/model/layout/frame-layout.d.ts +46 -0
  220. package/dist/taco/model/layout/frame-layout.js +618 -0
  221. package/dist/taco/model/layout/node-sizing.d.ts +163 -0
  222. package/dist/taco/model/layout/node-sizing.js +486 -0
  223. package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
  224. package/dist/taco/model/legacy-connector-caps.js +70 -0
  225. package/dist/taco/model/linear-call.d.ts +48 -0
  226. package/dist/taco/model/linear-call.js +58 -0
  227. package/dist/taco/model/new-nodes.d.ts +145 -0
  228. package/dist/taco/model/new-nodes.js +277 -0
  229. package/dist/taco/model/node-builder.d.ts +449 -0
  230. package/dist/taco/model/node-builder.js +2294 -0
  231. package/dist/taco/model/node-table-watch.d.ts +36 -0
  232. package/dist/taco/model/node-table-watch.js +63 -0
  233. package/dist/taco/model/node-transform.d.ts +39 -0
  234. package/dist/taco/model/node-transform.js +79 -0
  235. package/dist/taco/model/node-users-index.d.ts +10 -0
  236. package/dist/taco/model/node-users-index.js +82 -0
  237. package/dist/taco/model/operation-references.d.ts +80 -0
  238. package/dist/taco/model/operation-references.js +399 -0
  239. package/dist/taco/model/operations.d.ts +610 -0
  240. package/dist/taco/model/operations.js +2882 -0
  241. package/dist/taco/model/overlay-table.d.ts +71 -0
  242. package/dist/taco/model/overlay-table.js +171 -0
  243. package/dist/taco/model/override-remap.d.ts +69 -0
  244. package/dist/taco/model/override-remap.js +230 -0
  245. package/dist/taco/model/parent-table.d.ts +53 -0
  246. package/dist/taco/model/parent-table.js +193 -0
  247. package/dist/taco/model/problem-collector.d.ts +27 -0
  248. package/dist/taco/model/problem-collector.js +101 -0
  249. package/dist/taco/model/sha256.d.ts +10 -0
  250. package/dist/taco/model/sha256.js +79 -0
  251. package/dist/taco/model/shape-geometry.d.ts +96 -0
  252. package/dist/taco/model/shape-geometry.js +368 -0
  253. package/dist/taco/model/shared-node-table.d.ts +97 -0
  254. package/dist/taco/model/shared-node-table.js +546 -0
  255. package/dist/taco/model/slots.d.ts +113 -0
  256. package/dist/taco/model/slots.js +281 -0
  257. package/dist/taco/model/stroke-settings.d.ts +37 -0
  258. package/dist/taco/model/stroke-settings.js +90 -0
  259. package/dist/taco/model/svg-path-import.d.ts +89 -0
  260. package/dist/taco/model/svg-path-import.js +219 -0
  261. package/dist/taco/model/text-measurement.d.ts +142 -0
  262. package/dist/taco/model/text-measurement.js +846 -0
  263. package/dist/taco/model/text-reads.d.ts +66 -0
  264. package/dist/taco/model/text-reads.js +128 -0
  265. package/dist/taco/model/text-sizer.d.ts +358 -0
  266. package/dist/taco/model/text-sizer.js +996 -0
  267. package/dist/taco/model/theme-users.d.ts +59 -0
  268. package/dist/taco/model/theme-users.js +312 -0
  269. package/dist/taco/model/thumbnail.d.ts +15 -0
  270. package/dist/taco/model/thumbnail.js +34 -0
  271. package/dist/taco/model/types.d.ts +2369 -0
  272. package/dist/taco/model/types.js +366 -0
  273. package/dist/taco/model/unknown-property.d.ts +5 -0
  274. package/dist/taco/model/unknown-property.js +7 -0
  275. package/dist/taco/model/validated-documents.d.ts +22 -0
  276. package/dist/taco/model/validated-documents.js +22 -0
  277. package/dist/taco/model/variable-modes.d.ts +61 -0
  278. package/dist/taco/model/variable-modes.js +438 -0
  279. package/dist/taco/model/variable-references.d.ts +54 -0
  280. package/dist/taco/model/variable-references.js +183 -0
  281. package/dist/taco/model/variables.d.ts +24 -0
  282. package/dist/taco/model/variables.js +151 -0
  283. package/dist/taco/model/vector-network.d.ts +34 -0
  284. package/dist/taco/model/vector-network.js +411 -0
  285. package/dist/taco/svg-import/import-svg.d.ts +36 -0
  286. package/dist/taco/svg-import/import-svg.js +729 -0
  287. package/dist/taco/svg-import/index.d.ts +3 -0
  288. package/dist/taco/svg-import/index.js +3 -0
  289. package/dist/taco/svg-import/limits/limits.d.ts +79 -0
  290. package/dist/taco/svg-import/limits/limits.js +160 -0
  291. package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
  292. package/dist/taco/svg-import/paint/gradients.js +429 -0
  293. package/dist/taco/svg-import/paint/paint.d.ts +32 -0
  294. package/dist/taco/svg-import/paint/paint.js +162 -0
  295. package/dist/taco/svg-import/paths/paths.d.ts +58 -0
  296. package/dist/taco/svg-import/paths/paths.js +205 -0
  297. package/dist/taco/svg-import/public-types.d.ts +279 -0
  298. package/dist/taco/svg-import/public-types.js +56 -0
  299. package/dist/taco/svg-import/report/report.d.ts +44 -0
  300. package/dist/taco/svg-import/report/report.js +79 -0
  301. package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
  302. package/dist/taco/svg-import/reuse/reuse.js +840 -0
  303. package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
  304. package/dist/taco/svg-import/shapes/shapes.js +386 -0
  305. package/dist/taco/svg-import/structure/effects.d.ts +26 -0
  306. package/dist/taco/svg-import/structure/effects.js +618 -0
  307. package/dist/taco/svg-import/structure/image.d.ts +24 -0
  308. package/dist/taco/svg-import/structure/image.js +495 -0
  309. package/dist/taco/svg-import/structure/walk.d.ts +85 -0
  310. package/dist/taco/svg-import/structure/walk.js +544 -0
  311. package/dist/taco/svg-import/style/color.d.ts +40 -0
  312. package/dist/taco/svg-import/style/color.js +275 -0
  313. package/dist/taco/svg-import/style/computed.d.ts +214 -0
  314. package/dist/taco/svg-import/style/computed.js +1534 -0
  315. package/dist/taco/svg-import/style/css.d.ts +127 -0
  316. package/dist/taco/svg-import/style/css.js +541 -0
  317. package/dist/taco/svg-import/style/media.d.ts +25 -0
  318. package/dist/taco/svg-import/style/media.js +307 -0
  319. package/dist/taco/svg-import/style/properties.d.ts +43 -0
  320. package/dist/taco/svg-import/style/properties.js +135 -0
  321. package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
  322. package/dist/taco/svg-import/style/selector-reach.js +169 -0
  323. package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
  324. package/dist/taco/svg-import/style/selector-validity.js +307 -0
  325. package/dist/taco/svg-import/text/text.d.ts +29 -0
  326. package/dist/taco/svg-import/text/text.js +545 -0
  327. package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
  328. package/dist/taco/svg-import/transform/matrix.js +229 -0
  329. package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
  330. package/dist/taco/svg-import/tree/element-data.js +155 -0
  331. package/dist/taco/svg-import/tree/elements.d.ts +36 -0
  332. package/dist/taco/svg-import/tree/elements.js +121 -0
  333. package/dist/taco/svg-import/units/length.d.ts +43 -0
  334. package/dist/taco/svg-import/units/length.js +125 -0
  335. package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
  336. package/dist/taco/svg-import/units/viewbox.js +77 -0
  337. package/package.json +55 -4
@@ -0,0 +1,67 @@
1
+ /** The float32 ceiling used by render-core's Skia adapter (`kMaximumSkScalar`). */
2
+ export const MAX_RENDER_SCALAR = (2 - 2 ** -23) * 2 ** 127;
3
+ /**
4
+ * Maximum magnitude of authored geometry. Leave room for products (text size
5
+ * times line height, transformed paths), rotated bounds, strokes and effects.
6
+ */
7
+ export const MAX_GEOMETRY = Math.sqrt(MAX_RENDER_SCALAR) / 1024;
8
+ const geometryFields = new Set([
9
+ "x", "y", "dx", "dy", "width", "height", "minWidth", "maxWidth", "minHeight", "maxHeight",
10
+ "rotation", "angle", "startingAngle", "endingAngle", "xAxisRotation",
11
+ "radius", "radiusX", "radiusY", "cornerRadius", "topLeft", "topRight", "bottomLeft", "bottomRight",
12
+ "strokeWidth", "gap", "wrapGap", "columnGap", "rowGap", "top", "right", "bottom", "left",
13
+ "paddingTop", "paddingRight", "paddingBottom", "paddingLeft", "fontSize", "lineHeight",
14
+ "letterSpacing", "spacingBefore", "spacingAfter", "firstLine", "paragraphSpacing", "paragraphIndent", "spaceAbove", "spaceBelow", "indent",
15
+ "blur", "spread", "layerBlur", "backgroundBlur",
16
+ ]);
17
+ const geometryArrays = new Set(["transform", "dash", "fontVariations"]);
18
+ const geometryTables = new Set(["$geometryTable", "nodes", "pages", "assets", "components", "nodeStyles", "textStyles", "codeStyles", "conflicts"]);
19
+ const opaqueFields = new Set(["metadata", "properties", "propertyValues", "variableCollections", "expressions"]);
20
+ /**
21
+ * Bounds geometry in document/operation JSON without changing the input or
22
+ * unrelated values. Unchanged branches keep their identity. Schema validation
23
+ * still rejects non-finite numbers and invalid signs before this is called.
24
+ * Group sizes are derived from their children and may exceed the authored
25
+ * limit. Clamping them would invalidate the fit and move rotated groups on
26
+ * every subsequent refit.
27
+ */
28
+ export function clampGeometry(value) {
29
+ return visit(value, "");
30
+ }
31
+ function visit(value, field) {
32
+ if (typeof value === "number") {
33
+ if (!geometryFields.has(field) && !geometryArrays.has(field) && field !== "$groupSize")
34
+ return value;
35
+ if (!Number.isFinite(value))
36
+ throw new RangeError(`Geometry ${field} must be finite.`);
37
+ const limit = field === "$groupSize" ? MAX_RENDER_SCALAR / 1024 : MAX_GEOMETRY;
38
+ return Math.max(-limit, Math.min(limit, value));
39
+ }
40
+ if (value === null || typeof value !== "object" || opaqueFields.has(field))
41
+ return value;
42
+ if (Array.isArray(value)) {
43
+ let result;
44
+ value.forEach((entry, index) => {
45
+ const next = visit(entry, field);
46
+ if (next !== entry)
47
+ (result ??= [...value])[index] = next;
48
+ });
49
+ return result ?? value;
50
+ }
51
+ let result;
52
+ for (const [key, entry] of Object.entries(value)) {
53
+ // IDs in these tables are data, even when an ID is "metadata" or "transform".
54
+ const instanceOverrides = key === "overrides" && value.type === "instance";
55
+ const groupFrame = key === "frame" && value.type === "group";
56
+ const entryField = groupFrame ? "$groupFrame"
57
+ : field === "$groupFrame" && (key === "width" || key === "height") ? "$groupSize"
58
+ : instanceOverrides ? "$geometryTable"
59
+ : geometryTables.has(field) ? "" : geometryArrays.has(field) ? field : key;
60
+ const next = visit(entry, entryField);
61
+ if (next !== entry) {
62
+ result ??= { ...value };
63
+ Object.defineProperty(result, key, { value: next, enumerable: true, configurable: true, writable: true });
64
+ }
65
+ }
66
+ return result ?? value;
67
+ }
@@ -0,0 +1,47 @@
1
+ import { type DesignDocument, type PageId, type Rect, type SceneNode, type TransformMatrix, type VectorNetwork } from "./types.ts";
2
+ export declare const IDENTITY_TRANSFORM: TransformMatrix;
3
+ export declare function assertValidPathData(pathData: string): void;
4
+ /** Returns `true` when every subpath closes back to its starting point. */
5
+ export declare function isClosedPathData(pathData: string): boolean;
6
+ /** Returns tight fill bounds after applying an SVG-compatible affine transform. */
7
+ export declare function getPathBounds(pathData: string, transform?: TransformMatrix): Rect | null;
8
+ /**
9
+ * Returns tight network-edge bounds after applying an affine transform.
10
+ * Untransformed bounds of a frozen network are cached; the returned rectangle
11
+ * is then shared and frozen.
12
+ */
13
+ export declare function getVectorNetworkBounds(vectorNetwork: VectorNetwork, transform?: TransformMatrix): Rect | null;
14
+ /** Returns the parent-space axis-aligned bounds of a rotated frame. */
15
+ export declare function getRotatedRectBounds(frame: Rect, rotation: number): Rect;
16
+ /**
17
+ * Changes a frame's size while keeping one of its local points fixed in the
18
+ * parent coordinate system. The default anchor is the local top-left corner.
19
+ * `anchor` is a fraction of the size, so $(\alpha, \beta) = (0.5, 0.5)$ is
20
+ * the center. With $R_\theta$ the rotation by `rotation` degrees (clockwise
21
+ * in y-down space), the anchor sits at this offset from the frame's `x`, `y`:
22
+ *
23
+ * $$
24
+ * \mathbf{o}(w, h) = \begin{bmatrix} w/2 \\ h/2 \end{bmatrix} +
25
+ * R_\theta \begin{bmatrix} (\alpha - \tfrac12)\,w \\ (\beta - \tfrac12)\,h \end{bmatrix},
26
+ * \qquad
27
+ * R_\theta = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix}
28
+ * $$
29
+ *
30
+ * and the new position is
31
+ * $(x', y') = (x, y) + \mathbf{o}(w_\text{old}, h_\text{old}) - \mathbf{o}(w_\text{new}, h_\text{new})$.
32
+ */
33
+ export declare function resizeRotatedRect(frame: Rect, rotation: number, size: {
34
+ readonly width: number;
35
+ readonly height: number;
36
+ }, anchor?: {
37
+ readonly x: number;
38
+ readonly y: number;
39
+ }): Rect;
40
+ /** Returns layout bounds in the coordinate system of the node's parent. */
41
+ export declare function getNodeBounds(node: SceneNode): Rect;
42
+ /**
43
+ * A page root's frame is the page's visible extent: the area the editor fits
44
+ * on screen and the renderer sizes its scene to. Page roots never clip, so
45
+ * top-level nodes may lie outside it.
46
+ */
47
+ export declare function pageRootFrame(document: DesignDocument, pageId: PageId): Rect | undefined;
@@ -0,0 +1,193 @@
1
+ import { SVGPathData } from "svg-pathdata";
2
+ import { isContainerNode, } from "./types.js";
3
+ import { vectorNetworkToStrokePathData } from "./vector-network.js";
4
+ import { entryOf } from "./id-table.js";
5
+ export const IDENTITY_TRANSFORM = [1, 0, 0, 1, 0, 0];
6
+ export function assertValidPathData(pathData) {
7
+ void new SVGPathData(pathData);
8
+ }
9
+ /** Returns `true` when every subpath closes back to its starting point. */
10
+ export function isClosedPathData(pathData) {
11
+ const commands = new SVGPathData(pathData).commands;
12
+ let hasSubpath = false;
13
+ let subpathOpen = false;
14
+ for (const command of commands) {
15
+ if (command.type === SVGPathData.MOVE_TO) {
16
+ if (subpathOpen)
17
+ return false;
18
+ hasSubpath = true;
19
+ subpathOpen = true;
20
+ }
21
+ else if (command.type === SVGPathData.CLOSE_PATH) {
22
+ subpathOpen = false;
23
+ }
24
+ else if (hasSubpath && !subpathOpen) {
25
+ subpathOpen = true;
26
+ }
27
+ }
28
+ return hasSubpath && !subpathOpen;
29
+ }
30
+ function finiteBounds(minX, minY, maxX, maxY) {
31
+ if (![minX, minY, maxX, maxY].every(Number.isFinite))
32
+ return null;
33
+ return {
34
+ x: minX,
35
+ y: minY,
36
+ width: Math.max(0, maxX - minX),
37
+ height: Math.max(0, maxY - minY),
38
+ };
39
+ }
40
+ /** Returns tight fill bounds after applying an SVG-compatible affine transform. */
41
+ export function getPathBounds(pathData, transform = IDENTITY_TRANSFORM) {
42
+ const bounds = new SVGPathData(pathData)
43
+ .normalizeHVZ()
44
+ .matrix(...transform)
45
+ .getBounds();
46
+ return finiteBounds(bounds.minX, bounds.minY, bounds.maxX, bounds.maxY);
47
+ }
48
+ /**
49
+ * Untransformed bounds of frozen vector networks. A frozen network never
50
+ * changes (this package freezes values all the way down), so its bounds can
51
+ * be kept for as long as the network itself is alive. Measuring means
52
+ * writing the network as SVG path text and parsing it again, which costs
53
+ * about 0.1 ms per icon; the editor asks for every path's bounds on each
54
+ * pan and zoom step.
55
+ */
56
+ const frozenVectorNetworkBounds = new WeakMap();
57
+ /**
58
+ * Transformed bounds of frozen vector networks, by transform. The same path
59
+ * is measured at the same place again whenever the instances that show it are
60
+ * laid out, so a few transforms per network are kept. Callers get a copy, as
61
+ * they did when every call measured.
62
+ */
63
+ const frozenTransformedBounds = new WeakMap();
64
+ const MAX_TRANSFORMS_PER_NETWORK = 16;
65
+ function isIdentityTransform(transform) {
66
+ return transform === IDENTITY_TRANSFORM || (transform[0] === 1 && transform[1] === 0 && transform[2] === 0 &&
67
+ transform[3] === 1 && transform[4] === 0 && transform[5] === 0);
68
+ }
69
+ function measureVectorNetworkBounds(vectorNetwork, transform) {
70
+ const pathData = vectorNetworkToStrokePathData(vectorNetwork);
71
+ return pathData.length === 0 ? null : getPathBounds(pathData, transform);
72
+ }
73
+ /**
74
+ * Returns tight network-edge bounds after applying an affine transform.
75
+ * Untransformed bounds of a frozen network are cached; the returned rectangle
76
+ * is then shared and frozen.
77
+ */
78
+ export function getVectorNetworkBounds(vectorNetwork, transform = IDENTITY_TRANSFORM) {
79
+ if (!Object.isFrozen(vectorNetwork))
80
+ return measureVectorNetworkBounds(vectorNetwork, transform);
81
+ if (!isIdentityTransform(transform)) {
82
+ let byTransform = frozenTransformedBounds.get(vectorNetwork);
83
+ if (byTransform === undefined) {
84
+ byTransform = new Map();
85
+ frozenTransformedBounds.set(vectorNetwork, byTransform);
86
+ }
87
+ const key = transform.map((value) => Object.is(value, -0) ? "-0" : String(value)).join(",");
88
+ const known = byTransform.get(key);
89
+ if (known !== undefined)
90
+ return known === null ? null : { ...known };
91
+ const measured = measureVectorNetworkBounds(vectorNetwork, transform);
92
+ if (byTransform.size >= MAX_TRANSFORMS_PER_NETWORK)
93
+ byTransform.clear();
94
+ byTransform.set(key, measured === null ? null : Object.freeze({ ...measured }));
95
+ return measured;
96
+ }
97
+ const cached = frozenVectorNetworkBounds.get(vectorNetwork);
98
+ if (cached !== undefined)
99
+ return cached;
100
+ const bounds = measureVectorNetworkBounds(vectorNetwork, IDENTITY_TRANSFORM);
101
+ const frozenBounds = bounds === null ? null : Object.freeze(bounds);
102
+ frozenVectorNetworkBounds.set(vectorNetwork, frozenBounds);
103
+ return frozenBounds;
104
+ }
105
+ /** Returns the parent-space axis-aligned bounds of a rotated frame. */
106
+ export function getRotatedRectBounds(frame, rotation) {
107
+ // A zero-height frame (a line) still turns with its rotation.
108
+ if (rotation % 360 === 0 || (frame.width === 0 && frame.height === 0)) {
109
+ return frame;
110
+ }
111
+ const angle = rotation * Math.PI / 180;
112
+ const cosine = Math.cos(angle);
113
+ const sine = Math.sin(angle);
114
+ const centerX = frame.x + frame.width / 2;
115
+ const centerY = frame.y + frame.height / 2;
116
+ const halfWidth = frame.width / 2;
117
+ const halfHeight = frame.height / 2;
118
+ const corners = [
119
+ [-halfWidth, -halfHeight],
120
+ [halfWidth, -halfHeight],
121
+ [halfWidth, halfHeight],
122
+ [-halfWidth, halfHeight],
123
+ ];
124
+ const xCoordinates = corners.map(([x, y]) => centerX + cosine * x - sine * y);
125
+ const yCoordinates = corners.map(([x, y]) => centerY + sine * x + cosine * y);
126
+ const left = Math.min(...xCoordinates);
127
+ const top = Math.min(...yCoordinates);
128
+ const right = Math.max(...xCoordinates);
129
+ const bottom = Math.max(...yCoordinates);
130
+ return { x: left, y: top, width: right - left, height: bottom - top };
131
+ }
132
+ /**
133
+ * Changes a frame's size while keeping one of its local points fixed in the
134
+ * parent coordinate system. The default anchor is the local top-left corner.
135
+ * `anchor` is a fraction of the size, so $(\alpha, \beta) = (0.5, 0.5)$ is
136
+ * the center. With $R_\theta$ the rotation by `rotation` degrees (clockwise
137
+ * in y-down space), the anchor sits at this offset from the frame's `x`, `y`:
138
+ *
139
+ * $$
140
+ * \mathbf{o}(w, h) = \begin{bmatrix} w/2 \\ h/2 \end{bmatrix} +
141
+ * R_\theta \begin{bmatrix} (\alpha - \tfrac12)\,w \\ (\beta - \tfrac12)\,h \end{bmatrix},
142
+ * \qquad
143
+ * R_\theta = \begin{bmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{bmatrix}
144
+ * $$
145
+ *
146
+ * and the new position is
147
+ * $(x', y') = (x, y) + \mathbf{o}(w_\text{old}, h_\text{old}) - \mathbf{o}(w_\text{new}, h_\text{new})$.
148
+ */
149
+ export function resizeRotatedRect(frame, rotation, size, anchor = { x: 0, y: 0 }) {
150
+ const angle = rotation * Math.PI / 180;
151
+ const cosine = Math.cos(angle);
152
+ const sine = Math.sin(angle);
153
+ const anchorOffset = (width, height) => {
154
+ const centerX = width / 2;
155
+ const centerY = height / 2;
156
+ const relativeX = anchor.x * width - centerX;
157
+ const relativeY = anchor.y * height - centerY;
158
+ return {
159
+ x: centerX + cosine * relativeX - sine * relativeY,
160
+ y: centerY + sine * relativeX + cosine * relativeY,
161
+ };
162
+ };
163
+ const previousOffset = anchorOffset(frame.width, frame.height);
164
+ const nextOffset = anchorOffset(size.width, size.height);
165
+ return {
166
+ x: frame.x + previousOffset.x - nextOffset.x,
167
+ y: frame.y + previousOffset.y - nextOffset.y,
168
+ width: size.width,
169
+ height: size.height,
170
+ };
171
+ }
172
+ /** Returns layout bounds in the coordinate system of the node's parent. */
173
+ export function getNodeBounds(node) {
174
+ if (node.type !== "shape" || node.shape !== "path") {
175
+ return getRotatedRectBounds(node.frame, node.rotation);
176
+ }
177
+ return getVectorNetworkBounds(node.vectorNetwork, node.transform) ?? {
178
+ x: node.transform[4],
179
+ y: node.transform[5],
180
+ width: 0,
181
+ height: 0,
182
+ };
183
+ }
184
+ /**
185
+ * A page root's frame is the page's visible extent: the area the editor fits
186
+ * on screen and the renderer sizes its scene to. Page roots never clip, so
187
+ * top-level nodes may lie outside it.
188
+ */
189
+ export function pageRootFrame(document, pageId) {
190
+ const page = entryOf(document.pages, pageId);
191
+ const root = page === undefined ? undefined : entryOf(document.nodes, page.rootId);
192
+ return root === undefined || !isContainerNode(root) ? undefined : root.frame;
193
+ }
@@ -0,0 +1,38 @@
1
+ import { type GroupNode, type NodeId, type Rect, type SceneNode } from "./types.ts";
2
+ export { buildParentMap, parentMapOf } from "./parent-table.ts";
3
+ /**
4
+ * A group has no size of its own: its frame is always the union of its
5
+ * children's bounds. Children are stored relative to the group's frame, so a
6
+ * refit also moves the children by the same amount the frame moves, which
7
+ * keeps every child in place on the page.
8
+ *
9
+ * Differences below this tolerance are floating-point noise from scaling and
10
+ * rotation, not a stale group size.
11
+ */
12
+ export declare const GROUP_BOUNDS_TOLERANCE = 0.000001;
13
+ type NodeRecord = Readonly<Record<string, SceneNode>>;
14
+ /**
15
+ * Returns the union of a group's children bounds in the group's own
16
+ * coordinate system, or `null` for a group without children. Rotated children
17
+ * contribute their rotated bounding box and nested groups contribute their
18
+ * own (already fitted) frame.
19
+ */
20
+ export declare function getGroupChildrenBounds(nodes: NodeRecord, group: GroupNode): Rect | null;
21
+ export interface FittedGroup {
22
+ readonly group: GroupNode;
23
+ /** Children whose local position changed because the group origin moved. */
24
+ readonly children: readonly SceneNode[];
25
+ }
26
+ /**
27
+ * Fits a group's frame to its children without moving anything on the page.
28
+ * Returns `null` when the frame already matches. An empty group keeps its
29
+ * position and collapses to zero size.
30
+ */
31
+ export declare function fitGroupToChildren(nodes: NodeRecord, group: GroupNode): FittedGroup | null;
32
+ export declare function nodeDepth(parents: Pick<ReadonlyMap<NodeId, NodeId>, "get">, nodeId: NodeId): number;
33
+ /**
34
+ * Fits every group in a node record, deepest groups first so a parent group
35
+ * sees its nested groups' final frames. Used when a document is loaded, which
36
+ * repairs files saved with a stale group size.
37
+ */
38
+ export declare function fitAllGroups(nodes: NodeRecord): NodeRecord;
@@ -0,0 +1,144 @@
1
+ import { getNodeBounds } from "./geometry.js";
2
+ import { isContainerNode, } from "./types.js";
3
+ import { entryOf, putEntry } from "./id-table.js";
4
+ import { buildParentMap } from "./parent-table.js";
5
+ import { tableValues } from "./shared-node-table.js";
6
+ // Kept in the parent-table module, which the package does not export whole.
7
+ export { buildParentMap, parentMapOf } from "./parent-table.js";
8
+ /**
9
+ * A group has no size of its own: its frame is always the union of its
10
+ * children's bounds. Children are stored relative to the group's frame, so a
11
+ * refit also moves the children by the same amount the frame moves, which
12
+ * keeps every child in place on the page.
13
+ *
14
+ * Differences below this tolerance are floating-point noise from scaling and
15
+ * rotation, not a stale group size.
16
+ */
17
+ export const GROUP_BOUNDS_TOLERANCE = 1e-6;
18
+ /**
19
+ * Returns the union of a group's children bounds in the group's own
20
+ * coordinate system, or `null` for a group without children. Rotated children
21
+ * contribute their rotated bounding box and nested groups contribute their
22
+ * own (already fitted) frame.
23
+ */
24
+ export function getGroupChildrenBounds(nodes, group) {
25
+ let left = Number.POSITIVE_INFINITY;
26
+ let top = Number.POSITIVE_INFINITY;
27
+ let right = Number.NEGATIVE_INFINITY;
28
+ let bottom = Number.NEGATIVE_INFINITY;
29
+ for (const childId of group.children) {
30
+ const child = entryOf(nodes, childId);
31
+ if (child === undefined) {
32
+ throw new Error(`Group ${group.id} lists a missing child ${childId}.`);
33
+ }
34
+ const bounds = getNodeBounds(child);
35
+ left = Math.min(left, bounds.x);
36
+ top = Math.min(top, bounds.y);
37
+ right = Math.max(right, bounds.x + bounds.width);
38
+ bottom = Math.max(bottom, bounds.y + bounds.height);
39
+ }
40
+ if (![left, top, right, bottom].every(Number.isFinite))
41
+ return null;
42
+ return { x: left, y: top, width: right - left, height: bottom - top };
43
+ }
44
+ /** Maps a local vector through the group's flip and then its rotation. */
45
+ function orientVector(group, x, y) {
46
+ const angle = group.rotation * Math.PI / 180;
47
+ const cosine = Math.cos(angle);
48
+ const sine = Math.sin(angle);
49
+ const flippedX = group.flipX === true ? -x : x;
50
+ const flippedY = group.flipY === true ? -y : y;
51
+ return {
52
+ x: cosine * flippedX - sine * flippedY,
53
+ y: sine * flippedX + cosine * flippedY,
54
+ };
55
+ }
56
+ function shiftedChild(child, deltaX, deltaY) {
57
+ if (child.type === "shape" && child.shape === "path") {
58
+ const [a, b, c, d, e, f] = child.transform;
59
+ return { ...child, transform: [a, b, c, d, e + deltaX, f + deltaY] };
60
+ }
61
+ return {
62
+ ...child,
63
+ frame: { ...child.frame, x: child.frame.x + deltaX, y: child.frame.y + deltaY },
64
+ };
65
+ }
66
+ /**
67
+ * Fits a group's frame to its children without moving anything on the page.
68
+ * Returns `null` when the frame already matches. An empty group keeps its
69
+ * position and collapses to zero size.
70
+ */
71
+ export function fitGroupToChildren(nodes, group) {
72
+ const union = getGroupChildrenBounds(nodes, group) ?? {
73
+ x: 0,
74
+ y: 0,
75
+ width: 0,
76
+ height: 0,
77
+ };
78
+ const { frame } = group;
79
+ const moved = Math.abs(union.x) > GROUP_BOUNDS_TOLERANCE
80
+ || Math.abs(union.y) > GROUP_BOUNDS_TOLERANCE;
81
+ const resized = Math.abs(union.width - frame.width) > GROUP_BOUNDS_TOLERANCE
82
+ || Math.abs(union.height - frame.height) > GROUP_BOUNDS_TOLERANCE;
83
+ if (!moved && !resized)
84
+ return null;
85
+ // The group paints as translate(frame) * center * rotate * flip * -center.
86
+ // Keep the point that was at local `union.x, union.y` fixed on the page
87
+ // while it becomes the new local origin.
88
+ const oldCenterX = frame.width / 2;
89
+ const oldCenterY = frame.height / 2;
90
+ const newCenterX = union.width / 2;
91
+ const newCenterY = union.height / 2;
92
+ const offset = orientVector(group, newCenterX + union.x - oldCenterX, newCenterY + union.y - oldCenterY);
93
+ const fittedGroup = {
94
+ ...group,
95
+ frame: {
96
+ x: frame.x + oldCenterX - newCenterX + offset.x,
97
+ y: frame.y + oldCenterY - newCenterY + offset.y,
98
+ width: union.width,
99
+ height: union.height,
100
+ },
101
+ };
102
+ const children = moved
103
+ ? group.children.map((childId) => shiftedChild(entryOf(nodes, childId), -union.x, -union.y))
104
+ : [];
105
+ return { group: fittedGroup, children };
106
+ }
107
+ export function nodeDepth(parents, nodeId) {
108
+ let depth = 0;
109
+ let current = parents.get(nodeId);
110
+ while (current !== undefined) {
111
+ depth += 1;
112
+ current = parents.get(current);
113
+ }
114
+ return depth;
115
+ }
116
+ /**
117
+ * Fits every group in a node record, deepest groups first so a parent group
118
+ * sees its nested groups' final frames. Used when a document is loaded, which
119
+ * repairs files saved with a stale group size.
120
+ */
121
+ export function fitAllGroups(nodes) {
122
+ const groups = tableValues(nodes).filter((node) => node.type === "group");
123
+ if (groups.length === 0)
124
+ return nodes;
125
+ const parents = buildParentMap(nodes);
126
+ const ordered = groups
127
+ .map((group) => ({ id: group.id, depth: nodeDepth(parents, group.id) }))
128
+ .sort((left, right) => right.depth - left.depth);
129
+ let working = null;
130
+ for (const { id } of ordered) {
131
+ const current = working ?? nodes;
132
+ const group = entryOf(current, id);
133
+ if (group?.type !== "group")
134
+ continue;
135
+ const fitted = fitGroupToChildren(current, group);
136
+ if (fitted === null)
137
+ continue;
138
+ working ??= { ...nodes };
139
+ putEntry(working, id, fitted.group);
140
+ for (const child of fitted.children)
141
+ putEntry(working, child.id, child);
142
+ }
143
+ return working ?? nodes;
144
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Reading and writing tables that are plain objects keyed by an ID from a document
3
+ * (`DesignDocument.nodes`, `pages`, `assets`, `components`, a subtree's `nodes`, branch
4
+ * names, and the like). A document file may use any text as an ID, also the name of a
5
+ * member every plain object has: `__proto__`, `constructor`, `toString`,
6
+ * `hasOwnProperty`. With the usual `table[id]` such an ID goes wrong both ways:
7
+ *
8
+ * - reading finds the inherited member when the table has no such entry, so a missing
9
+ * node named `constructor` looks present;
10
+ * - `table["__proto__"] = value` adds no entry: it replaces the object's prototype.
11
+ *
12
+ * (An object literal with a computed key, a spread, `Object.fromEntries` and
13
+ * `JSON.parse` all add a real entry for any key, and `Object.keys`, `Object.entries`
14
+ * and `JSON.stringify` list only real entries; those need no care.)
15
+ *
16
+ * The tables stay plain objects, so the saved form and the shape other code sees do
17
+ * not change.
18
+ */
19
+ /** The entry of `table` for `id`, or `undefined` when the table has none. Never an inherited member. */
20
+ export declare function entryOf<Value>(table: Readonly<Record<string, Value>> | undefined, id: string): Value | undefined;
21
+ /** Whether `table` has an entry for `id`. */
22
+ export declare function hasEntry(table: Readonly<Record<string, unknown>> | undefined, id: string): boolean;
23
+ /**
24
+ * Whether `table` has any entry. Kept for a frozen table: listing the keys of
25
+ * a table of thousands of entries, as `for…in` and `Object.keys` do, is not
26
+ * paid on every read.
27
+ */
28
+ export declare function hasAnyEntry(table: Readonly<Record<string, unknown>> | undefined): boolean;
29
+ /** Sets the entry of `table` for `id`, for any `id`. */
30
+ export declare function putEntry<Value>(table: Record<string, Value>, id: string, value: Value): void;
31
+ /**
32
+ * A new plain object with every entry of `table`, in the same order: what
33
+ * `{ ...table }` makes. A copy made one entry at a time takes about two thirds
34
+ * of the time of a spread for a table of thousands of entries in V8, and a
35
+ * drag preview copies the node table on every step.
36
+ */
37
+ export declare function copyTable<Value>(table: Readonly<Record<string, Value>>): Record<string, Value>;
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Reading and writing tables that are plain objects keyed by an ID from a document
3
+ * (`DesignDocument.nodes`, `pages`, `assets`, `components`, a subtree's `nodes`, branch
4
+ * names, and the like). A document file may use any text as an ID, also the name of a
5
+ * member every plain object has: `__proto__`, `constructor`, `toString`,
6
+ * `hasOwnProperty`. With the usual `table[id]` such an ID goes wrong both ways:
7
+ *
8
+ * - reading finds the inherited member when the table has no such entry, so a missing
9
+ * node named `constructor` looks present;
10
+ * - `table["__proto__"] = value` adds no entry: it replaces the object's prototype.
11
+ *
12
+ * (An object literal with a computed key, a spread, `Object.fromEntries` and
13
+ * `JSON.parse` all add a real entry for any key, and `Object.keys`, `Object.entries`
14
+ * and `JSON.stringify` list only real entries; those need no care.)
15
+ *
16
+ * The tables stay plain objects, so the saved form and the shape other code sees do
17
+ * not change.
18
+ */
19
+ /** The entry of `table` for `id`, or `undefined` when the table has none. Never an inherited member. */
20
+ export function entryOf(table, id) {
21
+ if (table === undefined)
22
+ return undefined;
23
+ const value = table[id];
24
+ // An inherited member is a function, or (for `__proto__`) the object every plain
25
+ // object inherits from. A table of document data holds neither, so only then is a
26
+ // second look needed to tell an entry from a member.
27
+ return typeof value === "function" || value === Object.prototype
28
+ ? (Object.hasOwn(table, id) ? value : undefined)
29
+ : value;
30
+ }
31
+ /** Whether `table` has an entry for `id`. */
32
+ export function hasEntry(table, id) {
33
+ return table !== undefined && Object.hasOwn(table, id);
34
+ }
35
+ /** Per frozen table, whether it has any entry: a frozen table never changes. */
36
+ const nonEmptyTables = new WeakMap();
37
+ /**
38
+ * Whether `table` has any entry. Kept for a frozen table: listing the keys of
39
+ * a table of thousands of entries, as `for…in` and `Object.keys` do, is not
40
+ * paid on every read.
41
+ */
42
+ export function hasAnyEntry(table) {
43
+ if (table === undefined)
44
+ return false;
45
+ const known = nonEmptyTables.get(table);
46
+ if (known !== undefined)
47
+ return known;
48
+ let found = false;
49
+ for (const _ in table) {
50
+ found = true;
51
+ break;
52
+ }
53
+ if (Object.isFrozen(table))
54
+ nonEmptyTables.set(table, found);
55
+ return found;
56
+ }
57
+ /** Sets the entry of `table` for `id`, for any `id`. */
58
+ export function putEntry(table, id, value) {
59
+ if (id === "__proto__") {
60
+ Object.defineProperty(table, id, { value, enumerable: true, configurable: true, writable: true });
61
+ }
62
+ else {
63
+ table[id] = value;
64
+ }
65
+ }
66
+ /**
67
+ * A new plain object with every entry of `table`, in the same order: what
68
+ * `{ ...table }` makes. A copy made one entry at a time takes about two thirds
69
+ * of the time of a spread for a table of thousands of entries in V8, and a
70
+ * drag preview copies the node table on every step.
71
+ */
72
+ export function copyTable(table) {
73
+ const copy = {};
74
+ const ids = Object.keys(table);
75
+ for (let index = 0; index < ids.length; index += 1) {
76
+ const id = ids[index];
77
+ putEntry(copy, id, table[id]);
78
+ }
79
+ return copy;
80
+ }
@@ -0,0 +1,25 @@
1
+ export { assertSceneNode, checkSceneNode, deserializeDocument, ModelError } from "./codec.ts";
2
+ export { paragraphsFromCharacters } from "./component-evaluation.ts";
3
+ export { componentExpressionEnvironment, componentValueEnvironment, computableFieldType, storedFieldValue, variableExpressionType, variablesByExpressionName } from "./component-expressions.ts";
4
+ export { computableFieldsOf, variablePropertiesOfField } from "./component-properties.ts";
5
+ export { plainInstanceSample } from "./component-samples.ts";
6
+ export { isValidVariantCombination } from "./component-validity.ts";
7
+ export { componentNestingGraph, findComponentCycle, layerPathKey, parseLayerPath } from "./components.ts";
8
+ export { checkExpressionSource, evaluateExpression, EXPRESSION_NAME_MAX_LENGTH, EXPRESSION_SOURCE_LIMIT, EXPRESSION_TYPES, expressionNameProblem, type ExpressionValue, expressionValuesEqual, expressionValueSource, formatExpressionName, formatExpressionString, normalizeExpressionName, parseExpression, writeValueTable } from "./expressions/index.ts";
9
+ export { getNodeBounds, getPathBounds, getVectorNetworkBounds } from "./geometry.ts";
10
+ export { buildParentMap, fitAllGroups, fitGroupToChildren } from "./group-bounds.ts";
11
+ export { entryOf } from "./id-table.ts";
12
+ export { PROPERTIES_DROPPED_BY_FIELD, resolveInstance, TEXT_STYLE_PROPERTIES } from "./instance-resolver.ts";
13
+ export { type LayerSyntaxVariables, planLayerEdit } from "./layer-syntax.ts";
14
+ export { constrainChildren } from "./layout/constraints.ts";
15
+ export { layoutFrameTree } from "./layout/frame-layout.ts";
16
+ export { multiplyTransforms, nodeLocalTransform, transformIsInvertible } from "./node-transform.ts";
17
+ export { applyOperations, type DocumentOperation } from "./operations.ts";
18
+ export { isWholeEllipseArc } from "./shape-geometry.ts";
19
+ export { miterAngleFromLimit } from "./stroke-settings.ts";
20
+ export { pathNodeFromSvgPath } from "./svg-path-import.ts";
21
+ export { paragraphSpaceAbove, resolveTextStyle, splitCssFontFamilies } from "./text-measurement.ts";
22
+ export { type AssetId, BLEND_MODES, type BlendMode, codeStyleId, type CodeStyleId, type ComponentDefinition, componentId, type ComponentId, type ComponentPropertyDefinition, componentPropertyId, type ComponentPropertyId, type ComponentPropertyValue, type ComponentPropertyValues, type ComputableField, CURRENT_DOCUMENT_SCHEMA_VERSION, type DashCap, DEFAULT_STROKE_MITER_ANGLE, type DesignDocument, documentId, type DocumentId, type DocumentTheme, type EllipseArc, type EllipseNode, type FontAsset, type FramedNodeBase, type FrameNode, type GradientStop, type GroupNode, type HorizontalConstraint, type ImageAsset, type ImagePaintFit, type InstanceNode, type InstanceSlots, type LayerOverride, type LayerSizingOverride, type LayoutPadding, type LayoutSizing, type LinearGradientPaint, type LineNode, type NodeBase, type NodeExpressions, nodeId, type NodeId, type NodeResizing, ownedChildIds, type Page, pageId, type PageId, type Paint, type PathNode, type RadialGradientPaint, type Rect, type RectangleNode, type ResizeConstraints, type SceneNode, type Shadow, type ShadowKind, type StackAutoLayout, type Stroke, type StrokeJoin, type StrokePosition, type StrokeSides, type TextNode, type TextParagraph, type TextRun, type TextStyle, textStyleId, type TextStyleId, type TextStyleOverrides, type TransformMatrix, type VariableCollection, type VariableDefinition, type VariableId, type VariableModeId, type VariableModes, type VariableProperty, type VariableType, type VariableValue, type VectorCubicSegment, type VectorEllipticalArcSegment, vectorHandleId, type VectorHandleId, type VectorNetwork, type VectorRegion, vectorRegionId, type VectorRegionLoop, type VectorSegment, vectorSegmentId, type VectorSegmentReference, type VectorVertex, vectorVertexId, type VerticalConstraint, type VisualStyle } from "./types.ts";
23
+ export { applyVariableBindings } from "./variable-modes.ts";
24
+ export { listVariablesForProperty, nodeSupportsVariableProperty, VARIABLE_PROPERTY_TYPES } from "./variables.ts";
25
+ export { vectorRegionToSvgPathData } from "./vector-network.ts";