@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,193 @@
1
+ /**
2
+ * The table of each node's parent, kept for frozen node records and derived
3
+ * from one edit to the next. Internal: the package exports only
4
+ * `buildParentMap` and `parentMapOf` from here (through `group-bounds`), so
5
+ * no caller can record a table for a record.
6
+ */
7
+ import { isFrozenNodeMap } from "./derivations.js";
8
+ import { entryOf } from "./id-table.js";
9
+ import { ownedChildIds } from "./types.js";
10
+ import { tableValues } from "./shared-node-table.js";
11
+ /** Counts of the work done here, for tests that check what an edit costs. */
12
+ export const parentTableStats = {
13
+ /** Parent tables built by reading every node of a record (`buildParentMap`). */
14
+ wholeBuilds: 0,
15
+ };
16
+ export function buildParentMap(nodes) {
17
+ parentTableStats.wholeBuilds += 1;
18
+ const parents = new Map();
19
+ for (const node of tableValues(nodes)) {
20
+ for (const childId of ownedChildIds(node)) {
21
+ // The first node that owns a child is its parent.
22
+ if (!parents.has(childId))
23
+ parents.set(childId, node.id);
24
+ }
25
+ }
26
+ return parents;
27
+ }
28
+ /**
29
+ * The parents of a node record made from another by writing, inserting or
30
+ * removing a few nodes: the nodes whose parent differs, and the table of the
31
+ * record it was made from for every other node. `null` stands for a node that
32
+ * has no parent there. Reading one parent costs at most one step per table in
33
+ * the chain; listing the table (`size`, iterating) builds the whole table
34
+ * once, from the whole table at the end of the chain and the differences.
35
+ */
36
+ class DerivedParents {
37
+ listed;
38
+ base;
39
+ differences;
40
+ /** How many derived tables lead from this one down to a whole table. */
41
+ depth;
42
+ constructor(base, differences, depth) {
43
+ this.base = base;
44
+ this.differences = differences;
45
+ this.depth = depth;
46
+ }
47
+ get(id) {
48
+ const parent = this.differences.get(id);
49
+ if (parent === undefined)
50
+ return this.base.get(id);
51
+ return parent ?? undefined;
52
+ }
53
+ has(id) {
54
+ return this.get(id) !== undefined;
55
+ }
56
+ get size() {
57
+ return this.whole().size;
58
+ }
59
+ forEach(callback, thisArg) {
60
+ this.whole().forEach((parent, id) => callback.call(thisArg, parent, id, this));
61
+ }
62
+ entries() {
63
+ return this.whole().entries();
64
+ }
65
+ keys() {
66
+ return this.whole().keys();
67
+ }
68
+ values() {
69
+ return this.whole().values();
70
+ }
71
+ [Symbol.iterator]() {
72
+ return this.whole().entries();
73
+ }
74
+ whole() {
75
+ if (this.listed !== undefined)
76
+ return this.listed;
77
+ const chain = [];
78
+ let table = this;
79
+ while (table instanceof DerivedParents) {
80
+ chain.push(table);
81
+ table = table.base;
82
+ }
83
+ const parents = new Map(table);
84
+ for (let index = chain.length - 1; index >= 0; index -= 1) {
85
+ for (const [id, parent] of chain[index].differences) {
86
+ if (parent === null)
87
+ parents.delete(id);
88
+ else
89
+ parents.set(id, parent);
90
+ }
91
+ }
92
+ this.listed = parents;
93
+ return parents;
94
+ }
95
+ }
96
+ /**
97
+ * The most derived tables one lookup reads through. One edit adds a table to
98
+ * the chain, so after this many edits the next table is built whole again:
99
+ * a read costs at most this many steps, and building a table for every node
100
+ * happens once per this many edits instead of once per edit.
101
+ */
102
+ const MAX_DERIVED_PARENTS_DEPTH = 32;
103
+ /** The parent table of each frozen node record that has been asked for or recorded. */
104
+ const frozenParentTables = new WeakMap();
105
+ /**
106
+ * The parent ID of every node in `nodes`, like `buildParentMap`, but kept for
107
+ * a frozen record: a committed document never changes, so the table is built
108
+ * once per document version instead of once per question. Panels ask for a
109
+ * layer's parent many times per selection, and on a page of thousands of
110
+ * layers each fresh table read every layer. A record that is not frozen can
111
+ * still change, so its table is built again each time. A record that an edit
112
+ * made from another (`applyOperations`) has its table recorded with
113
+ * `recordParents`, derived from the table of the record it came from, so a
114
+ * document of many layers does not pay a pass over every layer per edit.
115
+ */
116
+ export function parentMapOf(nodes) {
117
+ let parents = frozenParentTables.get(nodes);
118
+ if (parents !== undefined)
119
+ return parents;
120
+ if (!isFrozenNodeMap(nodes))
121
+ return buildParentMap(nodes);
122
+ parents = buildParentMap(nodes);
123
+ frozenParentTables.set(nodes, parents);
124
+ return parents;
125
+ }
126
+ /**
127
+ * The parent table of `next`, a node record made from `previous` (whose table
128
+ * is `previousParents`) by writing, inserting or removing only the nodes
129
+ * `touched`. Every node whose parent differs between the two is a node in
130
+ * `touched`, a child of one in either record, or one gone from `next`, so
131
+ * only those are read: the work grows with the touched nodes and their
132
+ * children, not with the record. Every few edits the table is built whole
133
+ * instead (`MAX_DERIVED_PARENTS_DEPTH`), so lookups stay short.
134
+ */
135
+ export function derivedParents(previous, previousParents, next, touched) {
136
+ const depth = previousParents instanceof DerivedParents ? previousParents.depth + 1 : 1;
137
+ if (depth > MAX_DERIVED_PARENTS_DEPTH)
138
+ return buildParentMap(next);
139
+ const differences = new Map();
140
+ const touchedIds = [...touched];
141
+ // First every node that may have lost its parent: the touched nodes gone
142
+ // from `next`, and the children the touched containers had.
143
+ for (const id of touchedIds) {
144
+ if (entryOf(next, id) === undefined)
145
+ differences.set(id, null);
146
+ const before = entryOf(previous, id);
147
+ if (before !== undefined) {
148
+ for (const childId of ownedChildIds(before))
149
+ differences.set(childId, null);
150
+ }
151
+ }
152
+ // Then the parent each child of a touched container has in `next`.
153
+ for (const id of touchedIds) {
154
+ const after = entryOf(next, id);
155
+ if (after !== undefined) {
156
+ for (const childId of ownedChildIds(after))
157
+ differences.set(childId, id);
158
+ }
159
+ }
160
+ // A node that kept its parent needs no entry of its own.
161
+ for (const [id, parent] of differences) {
162
+ if ((parent ?? undefined) === previousParents.get(id))
163
+ differences.delete(id);
164
+ }
165
+ return differences.size === 0 ? previousParents : new DerivedParents(previousParents, differences, depth);
166
+ }
167
+ /** The parent table kept for `nodes`, or undefined when none has been built or recorded for it. */
168
+ export function keptParents(nodes) {
169
+ return frozenParentTables.get(nodes);
170
+ }
171
+ /**
172
+ * Keeps `parents` as the parent table of the frozen record `nodes`, for
173
+ * `parentMapOf`. `parents` must be that record's table, such as one
174
+ * `derivedParents` made from the record it came from.
175
+ */
176
+ export function recordParents(nodes, parents) {
177
+ frozenParentTables.set(nodes, parents);
178
+ }
179
+ /** Per node record an edit made, the nodes that edit changed (`recordChangedNodes`). */
180
+ const changedNodesByRecord = new WeakMap();
181
+ /**
182
+ * Keeps the nodes the edit that made the frozen record `nodes` wrote,
183
+ * inserted or removed, for readers that derive something per edit only when
184
+ * asked (`changedSlotOwners`). Called by `applyOperations`, as
185
+ * `recordParents` is.
186
+ */
187
+ export function recordChangedNodes(nodes, changedNodeIds) {
188
+ changedNodesByRecord.set(nodes, changedNodeIds);
189
+ }
190
+ /** The nodes recorded with `recordChangedNodes` for `nodes`, or undefined when no edit recorded any. */
191
+ export function recordedChangedNodes(nodes) {
192
+ return changedNodesByRecord.get(nodes);
193
+ }
@@ -0,0 +1,27 @@
1
+ import { type ModelProblem } from "./codec.ts";
2
+ /**
3
+ * Runs one check of a value. While checks throw, this is `check(value, path)`. While they collect, a
4
+ * problem it finds is recorded and the caller goes on with the next field or item; nothing inside a value
5
+ * that failed is checked further, so one wrong value is one problem.
6
+ */
7
+ export declare function attempt<T>(check: (value: unknown, path: string) => T, value: unknown, path: string): T | undefined;
8
+ /**
9
+ * Runs `check(value)` with each problem it finds at a path of the value itself (`$.opacity`) moved under
10
+ * `base` (`$operation.subtree.nodes.n1.opacity`), both the problems it records and the error it throws, so
11
+ * the problems of two values checked alike stay apart.
12
+ */
13
+ export declare function checkAt(check: (value: unknown) => void, value: unknown, base: string): void;
14
+ /**
15
+ * Whether `check` accepts `value`, recording nothing. A check that compares a value another check reports
16
+ * runs only when this is true, so the wrong value is one problem.
17
+ */
18
+ export declare function passes(check: (value: unknown, path: string) => unknown, value: unknown, path: string): boolean;
19
+ /** Whether a collecting check is running, so checks record problems instead of throwing. */
20
+ export declare function isCollectingProblems(): boolean;
21
+ /** How many problems the running collecting check has found; 0 while checks throw. */
22
+ export declare function collectedProblemCount(): number;
23
+ /**
24
+ * Runs `check` collecting, and returns every problem in the order the checks ran, without a limit. The
25
+ * first is the error the throwing check would throw.
26
+ */
27
+ export declare function collectingProblems(check: () => void): ModelProblem[];
@@ -0,0 +1,101 @@
1
+ import { ModelError } from "./codec.js";
2
+ /*
3
+ * The collecting mode of the model's checks, kept out of the package's exports. While a collecting check
4
+ * runs, each check that `attempt` wraps records its problem and the caller goes on; otherwise `attempt`
5
+ * only calls the check, so the throwing checks stay as they are.
6
+ */
7
+ /** The problems found so far while a collecting check runs, or undefined while the checks throw (the default). */
8
+ let collected;
9
+ /**
10
+ * Runs one check of a value. While checks throw, this is `check(value, path)`. While they collect, a
11
+ * problem it finds is recorded and the caller goes on with the next field or item; nothing inside a value
12
+ * that failed is checked further, so one wrong value is one problem.
13
+ */
14
+ export function attempt(check, value, path) {
15
+ if (collected === undefined)
16
+ return check(value, path);
17
+ try {
18
+ return check(value, path);
19
+ }
20
+ catch (error) {
21
+ if (!(error instanceof ModelError))
22
+ throw error;
23
+ collected.push(...error.problems);
24
+ return undefined;
25
+ }
26
+ }
27
+ /**
28
+ * Runs `check(value)` with each problem it finds at a path of the value itself (`$.opacity`) moved under
29
+ * `base` (`$operation.subtree.nodes.n1.opacity`), both the problems it records and the error it throws, so
30
+ * the problems of two values checked alike stay apart.
31
+ */
32
+ export function checkAt(check, value, base) {
33
+ const rebase = (problem) => /^\$(?=$|[.[])/.test(problem.path) ? { ...problem, path: base + problem.path.slice(1) } : problem;
34
+ const records = collected, start = records?.length ?? 0;
35
+ try {
36
+ check(value);
37
+ }
38
+ catch (error) {
39
+ if (!(error instanceof ModelError))
40
+ throw error;
41
+ const problems = error.problems.map(rebase), [first] = problems;
42
+ throw new ModelError(first.code, first.message, first.path, { problems, cause: error });
43
+ }
44
+ finally {
45
+ if (records !== undefined)
46
+ for (let index = start; index < records.length; index += 1)
47
+ records[index] = rebase(records[index]);
48
+ }
49
+ }
50
+ /**
51
+ * Whether `check` accepts `value`, recording nothing. A check that compares a value another check reports
52
+ * runs only when this is true, so the wrong value is one problem.
53
+ */
54
+ export function passes(check, value, path) {
55
+ const outer = collected;
56
+ collected = undefined;
57
+ try {
58
+ check(value, path);
59
+ return true;
60
+ }
61
+ catch (error) {
62
+ if (error instanceof ModelError)
63
+ return false;
64
+ throw error;
65
+ }
66
+ finally {
67
+ collected = outer;
68
+ }
69
+ }
70
+ /** Whether a collecting check is running, so checks record problems instead of throwing. */
71
+ export function isCollectingProblems() {
72
+ return collected !== undefined;
73
+ }
74
+ /** How many problems the running collecting check has found; 0 while checks throw. */
75
+ export function collectedProblemCount() {
76
+ return collected?.length ?? 0;
77
+ }
78
+ /**
79
+ * Runs `check` collecting, and returns every problem in the order the checks ran, without a limit. The
80
+ * first is the error the throwing check would throw.
81
+ */
82
+ export function collectingProblems(check) {
83
+ const outer = collected;
84
+ const problems = [];
85
+ collected = problems;
86
+ try {
87
+ check();
88
+ }
89
+ catch (error) {
90
+ if (error instanceof ModelError)
91
+ problems.push(...error.problems);
92
+ // Checks that go on after a problem may meet a value of the wrong type where a throwing check would
93
+ // have stopped; what was found stands.
94
+ else if (problems.length === 0)
95
+ throw error;
96
+ }
97
+ finally {
98
+ collected = outer;
99
+ }
100
+ return problems;
101
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * SHA-256 (FIPS 180-4) of binary data or a string's UTF-8 bytes, as 64 lowercase
3
+ * hexadecimal digits. Synchronous, unlike `crypto.subtle.digest`, so a
4
+ * lookup that needs it can stay synchronous.
5
+ */
6
+ /** Computes the SHA-256 digest synchronously.
7
+ * @param input - File bytes or text to encode as UTF-8.
8
+ * @returns A lowercase hexadecimal digest.
9
+ */
10
+ export declare function sha256Hex(input: string | Uint8Array): string;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * SHA-256 (FIPS 180-4) of binary data or a string's UTF-8 bytes, as 64 lowercase
3
+ * hexadecimal digits. Synchronous, unlike `crypto.subtle.digest`, so a
4
+ * lookup that needs it can stay synchronous.
5
+ */
6
+ const ROUND_CONSTANTS = new Uint32Array([
7
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
8
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
9
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
10
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
11
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
12
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
13
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
14
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
15
+ ]);
16
+ const words = new Uint32Array(64);
17
+ const encoder = new TextEncoder();
18
+ /** Computes the SHA-256 digest synchronously.
19
+ * @param input - File bytes or text to encode as UTF-8.
20
+ * @returns A lowercase hexadecimal digest.
21
+ */
22
+ export function sha256Hex(input) {
23
+ const bytes = typeof input === "string" ? encoder.encode(input) : input;
24
+ // The message, a 1 bit, zeros, and the bit length in the last 8 bytes, in 64-byte blocks.
25
+ const complete = bytes.length - bytes.length % 64;
26
+ const remainder = bytes.length - complete;
27
+ const tail = new Uint8Array(remainder < 56 ? 64 : 128);
28
+ tail.set(bytes.subarray(complete));
29
+ tail[remainder] = 0x80;
30
+ const blocks = new DataView(bytes.buffer, bytes.byteOffset, complete);
31
+ const padding = new DataView(tail.buffer);
32
+ const bits = bytes.length * 8;
33
+ padding.setUint32(tail.length - 8, Math.floor(bits / 0x1_0000_0000));
34
+ padding.setUint32(tail.length - 4, bits >>> 0);
35
+ let h0 = 0x6a09e667, h1 = 0xbb67ae85, h2 = 0x3c6ef372, h3 = 0xa54ff53a;
36
+ let h4 = 0x510e527f, h5 = 0x9b05688c, h6 = 0x1f83d9ab, h7 = 0x5be0cd19;
37
+ for (let offset = 0; offset < complete + tail.length; offset += 64) {
38
+ const view = offset < complete ? blocks : padding;
39
+ const at = offset < complete ? offset : offset - complete;
40
+ for (let index = 0; index < 16; index += 1)
41
+ words[index] = view.getUint32(at + index * 4);
42
+ for (let index = 16; index < 64; index += 1) {
43
+ const before = words[index - 15];
44
+ const near = words[index - 2];
45
+ const s0 = ((before >>> 7) | (before << 25)) ^ ((before >>> 18) | (before << 14)) ^ (before >>> 3);
46
+ const s1 = ((near >>> 17) | (near << 15)) ^ ((near >>> 19) | (near << 13)) ^ (near >>> 10);
47
+ words[index] = words[index - 16] + s0 + words[index - 7] + s1;
48
+ }
49
+ let a = h0, b = h1, c = h2, d = h3, e = h4, f = h5, g = h6, h = h7;
50
+ for (let index = 0; index < 64; index += 1) {
51
+ const s1 = ((e >>> 6) | (e << 26)) ^ ((e >>> 11) | (e << 21)) ^ ((e >>> 25) | (e << 7));
52
+ const choose = (e & f) ^ (~e & g);
53
+ const first = (h + s1 + choose + ROUND_CONSTANTS[index] + words[index]) | 0;
54
+ const s0 = ((a >>> 2) | (a << 30)) ^ ((a >>> 13) | (a << 19)) ^ ((a >>> 22) | (a << 10));
55
+ const majority = (a & b) ^ (a & c) ^ (b & c);
56
+ const second = (s0 + majority) | 0;
57
+ h = g;
58
+ g = f;
59
+ f = e;
60
+ e = (d + first) | 0;
61
+ d = c;
62
+ c = b;
63
+ b = a;
64
+ a = (first + second) | 0;
65
+ }
66
+ h0 = (h0 + a) | 0;
67
+ h1 = (h1 + b) | 0;
68
+ h2 = (h2 + c) | 0;
69
+ h3 = (h3 + d) | 0;
70
+ h4 = (h4 + e) | 0;
71
+ h5 = (h5 + f) | 0;
72
+ h6 = (h6 + g) | 0;
73
+ h7 = (h7 + h) | 0;
74
+ }
75
+ let hex = "";
76
+ for (const value of [h0, h1, h2, h3, h4, h5, h6, h7])
77
+ hex += (value >>> 0).toString(16).padStart(8, "0");
78
+ return hex;
79
+ }
@@ -0,0 +1,96 @@
1
+ import { type EllipseArc, type LineNode, type Rect, type VectorNetwork } from "./types.ts";
2
+ /**
3
+ * Pure geometry for the parametric shapes: polygons, stars, ellipse arcs and
4
+ * lines. The renderer compiler, the editor and the tests share these helpers
5
+ * so every consumer agrees on the same vertices.
6
+ */
7
+ export interface ShapePoint {
8
+ readonly x: number;
9
+ readonly y: number;
10
+ }
11
+ /** Figma's defaults for newly drawn shapes. */
12
+ export declare const DEFAULT_POLYGON_POINT_COUNT = 3;
13
+ export declare const DEFAULT_STAR_POINT_COUNT = 5;
14
+ export declare const DEFAULT_STAR_INNER_RADIUS = 0.382;
15
+ export declare function isValidShapePointCount(value: number): boolean;
16
+ /**
17
+ * The corners of a regular polygon in frame-local coordinates, clockwise from
18
+ * the top center. The polygon is stretched so its bounds equal the frame.
19
+ * Corner $k$ of $n$ starts on the unit circle (y points down)
20
+ *
21
+ * $$
22
+ * \theta_k = -\frac{\pi}{2} + \frac{2\pi k}{n}, \qquad
23
+ * (u_k, v_k) = (\cos\theta_k, \sin\theta_k)
24
+ * $$
25
+ *
26
+ * and is then scaled into the frame by its bounding box:
27
+ * $x_k = w \cdot (u_k - u_\text{min}) / (u_\text{max} - u_\text{min})$, and
28
+ * likewise $y_k$ with the height (0 when the span is 0).
29
+ */
30
+ export declare function polygonPoints(pointCount: number, width: number, height: number): ShapePoint[];
31
+ /**
32
+ * The alternating outer and inner points of a star in frame-local
33
+ * coordinates, clockwise from the top outer point. `innerRadius` is the inner
34
+ * point distance as a fraction of the outer radius. The star is stretched so
35
+ * the bounds of all its points equal the frame. Before stretching, point $k$
36
+ * of $2n$ is
37
+ *
38
+ * $$
39
+ * \theta_k = -\frac{\pi}{2} + \frac{\pi k}{n}, \qquad
40
+ * r_k = \begin{cases} 1 & k \text{ even} \\ \rho & k \text{ odd} \end{cases}, \qquad
41
+ * (u_k, v_k) = (r_k\cos\theta_k,\ r_k\sin\theta_k)
42
+ * $$
43
+ *
44
+ * with $\rho$ = `innerRadius`; the stretch is the same as `polygonPoints`.
45
+ */
46
+ export declare function starPoints(pointCount: number, innerRadius: number, width: number, height: number): ShapePoint[];
47
+ /** A closed straight-edged network through the given points, one region. */
48
+ export declare function closedPolygonVectorNetwork(points: readonly ShapePoint[], idPrefix?: string): VectorNetwork;
49
+ export declare function validateEllipseArc(arc: EllipseArc): string | null;
50
+ /**
51
+ * The sweep in degrees, positive clockwise; at most one full turn:
52
+ * $\text{sweep} = \text{endingAngle} - \text{startingAngle}$.
53
+ */
54
+ export declare function ellipseArcSweep(arc: EllipseArc): number;
55
+ /** True when the arc draws the plain whole ellipse. */
56
+ export declare function isWholeEllipseArc(arc: EllipseArc | undefined): boolean;
57
+ /**
58
+ * The network for an ellipse filling a `width` by `height` frame, cut by an
59
+ * optional arc: a whole ellipse, a ring (whole sweep with an inner radius), a
60
+ * pie (partial sweep without one), or a ring sector. A zero sweep draws
61
+ * nothing and returns an empty network. An angle $\phi$ in degrees (0 points
62
+ * right, positive turns clockwise because y points down) lands at
63
+ *
64
+ * $$
65
+ * \left(\frac{w}{2} + \frac{w}{2}\,t\cos\phi,\ \frac{h}{2} + \frac{h}{2}\,t\sin\phi\right)
66
+ * $$
67
+ *
68
+ * where $t = 1$ on the outer edge and $t$ = `innerRadius` on the inner edge.
69
+ */
70
+ export declare function ellipseVectorNetwork(width: number, height: number, arc?: EllipseArc, idPrefix?: string): VectorNetwork;
71
+ /**
72
+ * The start and end points of a line in its parent's coordinates. With frame
73
+ * center $(c_x, c_y)$, width $w$, rotation $\theta$ (degrees converted to
74
+ * radians) and $s = -1$ when `flipX` is set, else $s = 1$:
75
+ *
76
+ * $$
77
+ * \text{start}, \text{end} = (c_x, c_y) \mp \frac{s w}{2}(\cos\theta, \sin\theta)
78
+ * $$
79
+ */
80
+ export declare function lineEndpoints(line: Pick<LineNode, "frame" | "rotation" | "flipX" | "flipY">): {
81
+ readonly start: ShapePoint;
82
+ readonly end: ShapePoint;
83
+ };
84
+ /**
85
+ * The zero-height frame and rotation of a line between two parent-space
86
+ * points. The rotation is in degrees within (-180, 180].
87
+ */
88
+ export declare function lineFrameFromEndpoints(start: ShapePoint, end: ShapePoint): {
89
+ readonly frame: Rect;
90
+ readonly rotation: number;
91
+ };
92
+ /**
93
+ * Moves `point` so the segment from `anchor` keeps its length but turns to
94
+ * the nearest multiple of 45 degrees, as Shift does while drawing a line.
95
+ */
96
+ export declare function constrainLineEndpoint(anchor: ShapePoint, point: ShapePoint): ShapePoint;