@moondraft/import 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (323) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +34 -0
  3. package/README.md +36 -2
  4. package/SOURCE.md +169 -0
  5. package/dist/adapter/convert.d.ts +122 -0
  6. package/dist/adapter/convert.js +2302 -0
  7. package/dist/adapter/figma.d.ts +9 -0
  8. package/dist/adapter/figma.js +30 -0
  9. package/dist/adapter/file-components.d.ts +14 -0
  10. package/dist/adapter/file-components.js +262 -0
  11. package/dist/adapter/file-resources.d.ts +29 -0
  12. package/dist/adapter/file-resources.js +562 -0
  13. package/dist/adapter/index.d.ts +6 -0
  14. package/dist/adapter/index.js +9 -0
  15. package/dist/adapter/link.d.ts +45 -0
  16. package/dist/adapter/link.js +688 -0
  17. package/dist/adapter/payload.d.ts +31 -0
  18. package/dist/adapter/payload.js +78 -0
  19. package/dist/adapter/shapes.d.ts +31 -0
  20. package/dist/adapter/shapes.js +75 -0
  21. package/dist/adapter/variables.d.ts +44 -0
  22. package/dist/adapter/variables.js +103 -0
  23. package/dist/figma-file.d.ts +38 -0
  24. package/dist/figma-file.js +97 -0
  25. package/dist/figma-worker.d.ts +11 -0
  26. package/dist/figma-worker.js +12 -0
  27. package/dist/figma.d.ts +26 -0
  28. package/dist/figma.js +96 -0
  29. package/dist/index.d.ts +28 -0
  30. package/dist/index.js +49 -0
  31. package/dist/report.d.ts +15 -0
  32. package/dist/report.js +69 -0
  33. package/dist/svg.d.ts +33 -0
  34. package/dist/svg.js +44 -0
  35. package/dist/syntax.d.ts +8 -0
  36. package/dist/syntax.js +19 -0
  37. package/dist/taco/figma-import/clipboard.d.ts +25 -0
  38. package/dist/taco/figma-import/clipboard.js +87 -0
  39. package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
  40. package/dist/taco/figma-import/clipboardSize.js +107 -0
  41. package/dist/taco/figma-import/container/compression.d.ts +9 -0
  42. package/dist/taco/figma-import/container/compression.js +174 -0
  43. package/dist/taco/figma-import/container/error.d.ts +15 -0
  44. package/dist/taco/figma-import/container/error.js +19 -0
  45. package/dist/taco/figma-import/container/kiwiContainer.d.ts +38 -0
  46. package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
  47. package/dist/taco/figma-import/container/limits.d.ts +22 -0
  48. package/dist/taco/figma-import/container/limits.js +22 -0
  49. package/dist/taco/figma-import/container/zip.d.ts +14 -0
  50. package/dist/taco/figma-import/container/zip.js +154 -0
  51. package/dist/taco/figma-import/figFile.d.ts +34 -0
  52. package/dist/taco/figma-import/figFile.js +91 -0
  53. package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
  54. package/dist/taco/figma-import/figFileDocument.js +100 -0
  55. package/dist/taco/figma-import/import/blobs.d.ts +10 -0
  56. package/dist/taco/figma-import/import/blobs.js +23 -0
  57. package/dist/taco/figma-import/import/carry.d.ts +11 -0
  58. package/dist/taco/figma-import/import/carry.js +33 -0
  59. package/dist/taco/figma-import/import/componentProps.d.ts +84 -0
  60. package/dist/taco/figma-import/import/componentProps.js +313 -0
  61. package/dist/taco/figma-import/import/componentSets.d.ts +83 -0
  62. package/dist/taco/figma-import/import/componentSets.js +647 -0
  63. package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
  64. package/dist/taco/figma-import/import/converters/effects.js +127 -0
  65. package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
  66. package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
  67. package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
  68. package/dist/taco/figma-import/import/converters/frame.js +55 -0
  69. package/dist/taco/figma-import/import/converters/gradient.d.ts +72 -0
  70. package/dist/taco/figma-import/import/converters/gradient.js +106 -0
  71. package/dist/taco/figma-import/import/converters/group.d.ts +21 -0
  72. package/dist/taco/figma-import/import/converters/group.js +39 -0
  73. package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
  74. package/dist/taco/figma-import/import/converters/image.js +83 -0
  75. package/dist/taco/figma-import/import/converters/layout.d.ts +34 -0
  76. package/dist/taco/figma-import/import/converters/layout.js +168 -0
  77. package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
  78. package/dist/taco/figma-import/import/converters/line.js +40 -0
  79. package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
  80. package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
  81. package/dist/taco/figma-import/import/converters/section.d.ts +9 -0
  82. package/dist/taco/figma-import/import/converters/section.js +35 -0
  83. package/dist/taco/figma-import/import/converters/shared.d.ts +68 -0
  84. package/dist/taco/figma-import/import/converters/shared.js +362 -0
  85. package/dist/taco/figma-import/import/converters/text.d.ts +41 -0
  86. package/dist/taco/figma-import/import/converters/text.js +576 -0
  87. package/dist/taco/figma-import/import/converters/vector.d.ts +84 -0
  88. package/dist/taco/figma-import/import/converters/vector.js +468 -0
  89. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +98 -0
  90. package/dist/taco/figma-import/import/converters/vectorNetwork.js +385 -0
  91. package/dist/taco/figma-import/import/fields.d.ts +15 -0
  92. package/dist/taco/figma-import/import/fields.js +29 -0
  93. package/dist/taco/figma-import/import/instances.d.ts +163 -0
  94. package/dist/taco/figma-import/import/instances.js +1323 -0
  95. package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
  96. package/dist/taco/figma-import/import/nestingCycles.js +488 -0
  97. package/dist/taco/figma-import/import/slots.d.ts +56 -0
  98. package/dist/taco/figma-import/import/slots.js +96 -0
  99. package/dist/taco/figma-import/import/styles.d.ts +46 -0
  100. package/dist/taco/figma-import/import/styles.js +42 -0
  101. package/dist/taco/figma-import/import/tree.d.ts +66 -0
  102. package/dist/taco/figma-import/import/tree.js +194 -0
  103. package/dist/taco/figma-import/import/types.d.ts +232 -0
  104. package/dist/taco/figma-import/import/types.js +33 -0
  105. package/dist/taco/figma-import/import/variables.d.ts +136 -0
  106. package/dist/taco/figma-import/import/variables.js +762 -0
  107. package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
  108. package/dist/taco/figma-import/import/variantTrees.js +480 -0
  109. package/dist/taco/figma-import/import/walk.d.ts +159 -0
  110. package/dist/taco/figma-import/import/walk.js +1297 -0
  111. package/dist/taco/figma-import/index.d.ts +22 -0
  112. package/dist/taco/figma-import/index.js +13 -0
  113. package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
  114. package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
  115. package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
  116. package/dist/taco/figma-import/kiwi/error.js +29 -0
  117. package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
  118. package/dist/taco/figma-import/kiwi/limits.js +18 -0
  119. package/dist/taco/figma-import/kiwi/message.d.ts +10 -0
  120. package/dist/taco/figma-import/kiwi/message.js +145 -0
  121. package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
  122. package/dist/taco/figma-import/kiwi/schema.js +206 -0
  123. package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
  124. package/dist/taco/figma-import/kiwi/types.js +18 -0
  125. package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
  126. package/dist/taco/model/agent-hidden-fields.js +29 -0
  127. package/dist/taco/model/asset-users.d.ts +23 -0
  128. package/dist/taco/model/asset-users.js +128 -0
  129. package/dist/taco/model/auto-layout-lines.d.ts +32 -0
  130. package/dist/taco/model/auto-layout-lines.js +70 -0
  131. package/dist/taco/model/codec.d.ts +444 -0
  132. package/dist/taco/model/codec.js +5635 -0
  133. package/dist/taco/model/color.d.ts +11 -0
  134. package/dist/taco/model/color.js +61 -0
  135. package/dist/taco/model/comment-operations.d.ts +102 -0
  136. package/dist/taco/model/comment-operations.js +227 -0
  137. package/dist/taco/model/component-evaluation.d.ts +94 -0
  138. package/dist/taco/model/component-evaluation.js +548 -0
  139. package/dist/taco/model/component-expressions.d.ts +242 -0
  140. package/dist/taco/model/component-expressions.js +1082 -0
  141. package/dist/taco/model/component-properties.d.ts +111 -0
  142. package/dist/taco/model/component-properties.js +339 -0
  143. package/dist/taco/model/component-samples.d.ts +83 -0
  144. package/dist/taco/model/component-samples.js +290 -0
  145. package/dist/taco/model/component-validity.d.ts +85 -0
  146. package/dist/taco/model/component-validity.js +397 -0
  147. package/dist/taco/model/components.d.ts +155 -0
  148. package/dist/taco/model/components.js +505 -0
  149. package/dist/taco/model/connector-ends.d.ts +20 -0
  150. package/dist/taco/model/connector-ends.js +188 -0
  151. package/dist/taco/model/connector-geometry.d.ts +74 -0
  152. package/dist/taco/model/connector-geometry.js +293 -0
  153. package/dist/taco/model/corner-radii.d.ts +26 -0
  154. package/dist/taco/model/corner-radii.js +47 -0
  155. package/dist/taco/model/derivations.d.ts +81 -0
  156. package/dist/taco/model/derivations.js +151 -0
  157. package/dist/taco/model/export-settings.d.ts +53 -0
  158. package/dist/taco/model/export-settings.js +156 -0
  159. package/dist/taco/model/expressions/ast.d.ts +153 -0
  160. package/dist/taco/model/expressions/ast.js +6 -0
  161. package/dist/taco/model/expressions/cache.d.ts +23 -0
  162. package/dist/taco/model/expressions/cache.js +43 -0
  163. package/dist/taco/model/expressions/check.d.ts +72 -0
  164. package/dist/taco/model/expressions/check.js +517 -0
  165. package/dist/taco/model/expressions/completion.d.ts +61 -0
  166. package/dist/taco/model/expressions/completion.js +421 -0
  167. package/dist/taco/model/expressions/evaluate.d.ts +32 -0
  168. package/dist/taco/model/expressions/evaluate.js +519 -0
  169. package/dist/taco/model/expressions/forms.d.ts +84 -0
  170. package/dist/taco/model/expressions/forms.js +200 -0
  171. package/dist/taco/model/expressions/index.d.ts +14 -0
  172. package/dist/taco/model/expressions/index.js +17 -0
  173. package/dist/taco/model/expressions/lexer.d.ts +42 -0
  174. package/dist/taco/model/expressions/lexer.js +213 -0
  175. package/dist/taco/model/expressions/library.d.ts +33 -0
  176. package/dist/taco/model/expressions/library.js +117 -0
  177. package/dist/taco/model/expressions/names.d.ts +43 -0
  178. package/dist/taco/model/expressions/names.js +99 -0
  179. package/dist/taco/model/expressions/parser.d.ts +15 -0
  180. package/dist/taco/model/expressions/parser.js +438 -0
  181. package/dist/taco/model/expressions/rename.d.ts +34 -0
  182. package/dist/taco/model/expressions/rename.js +46 -0
  183. package/dist/taco/model/expressions/source.d.ts +15 -0
  184. package/dist/taco/model/expressions/source.js +161 -0
  185. package/dist/taco/model/expressions/types.d.ts +119 -0
  186. package/dist/taco/model/expressions/types.js +102 -0
  187. package/dist/taco/model/expressions/values.d.ts +97 -0
  188. package/dist/taco/model/expressions/values.js +160 -0
  189. package/dist/taco/model/geometry-limits.d.ts +16 -0
  190. package/dist/taco/model/geometry-limits.js +67 -0
  191. package/dist/taco/model/geometry.d.ts +47 -0
  192. package/dist/taco/model/geometry.js +193 -0
  193. package/dist/taco/model/group-bounds.d.ts +38 -0
  194. package/dist/taco/model/group-bounds.js +144 -0
  195. package/dist/taco/model/id-table.d.ts +37 -0
  196. package/dist/taco/model/id-table.js +80 -0
  197. package/dist/taco/model/index.d.ts +25 -0
  198. package/dist/taco/model/index.js +27 -0
  199. package/dist/taco/model/instance-resolver.d.ts +372 -0
  200. package/dist/taco/model/instance-resolver.js +1748 -0
  201. package/dist/taco/model/layer-syntax.d.ts +340 -0
  202. package/dist/taco/model/layer-syntax.js +3506 -0
  203. package/dist/taco/model/layout/constraints.d.ts +84 -0
  204. package/dist/taco/model/layout/constraints.js +445 -0
  205. package/dist/taco/model/layout/frame-layout.d.ts +46 -0
  206. package/dist/taco/model/layout/frame-layout.js +618 -0
  207. package/dist/taco/model/layout/node-sizing.d.ts +163 -0
  208. package/dist/taco/model/layout/node-sizing.js +486 -0
  209. package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
  210. package/dist/taco/model/legacy-connector-caps.js +70 -0
  211. package/dist/taco/model/linear-call.d.ts +48 -0
  212. package/dist/taco/model/linear-call.js +58 -0
  213. package/dist/taco/model/new-nodes.d.ts +145 -0
  214. package/dist/taco/model/new-nodes.js +277 -0
  215. package/dist/taco/model/node-builder.d.ts +449 -0
  216. package/dist/taco/model/node-builder.js +2294 -0
  217. package/dist/taco/model/node-table-watch.d.ts +36 -0
  218. package/dist/taco/model/node-table-watch.js +63 -0
  219. package/dist/taco/model/node-transform.d.ts +39 -0
  220. package/dist/taco/model/node-transform.js +79 -0
  221. package/dist/taco/model/node-users-index.d.ts +10 -0
  222. package/dist/taco/model/node-users-index.js +82 -0
  223. package/dist/taco/model/operation-references.d.ts +80 -0
  224. package/dist/taco/model/operation-references.js +399 -0
  225. package/dist/taco/model/operations.d.ts +610 -0
  226. package/dist/taco/model/operations.js +2882 -0
  227. package/dist/taco/model/overlay-table.d.ts +71 -0
  228. package/dist/taco/model/overlay-table.js +171 -0
  229. package/dist/taco/model/override-remap.d.ts +69 -0
  230. package/dist/taco/model/override-remap.js +230 -0
  231. package/dist/taco/model/parent-table.d.ts +53 -0
  232. package/dist/taco/model/parent-table.js +193 -0
  233. package/dist/taco/model/problem-collector.d.ts +27 -0
  234. package/dist/taco/model/problem-collector.js +101 -0
  235. package/dist/taco/model/sha256.d.ts +10 -0
  236. package/dist/taco/model/sha256.js +74 -0
  237. package/dist/taco/model/shape-geometry.d.ts +96 -0
  238. package/dist/taco/model/shape-geometry.js +368 -0
  239. package/dist/taco/model/shared-node-table.d.ts +97 -0
  240. package/dist/taco/model/shared-node-table.js +546 -0
  241. package/dist/taco/model/slots.d.ts +113 -0
  242. package/dist/taco/model/slots.js +281 -0
  243. package/dist/taco/model/stroke-settings.d.ts +37 -0
  244. package/dist/taco/model/stroke-settings.js +90 -0
  245. package/dist/taco/model/svg-path-import.d.ts +89 -0
  246. package/dist/taco/model/svg-path-import.js +219 -0
  247. package/dist/taco/model/text-measurement.d.ts +142 -0
  248. package/dist/taco/model/text-measurement.js +846 -0
  249. package/dist/taco/model/text-reads.d.ts +66 -0
  250. package/dist/taco/model/text-reads.js +128 -0
  251. package/dist/taco/model/text-sizer.d.ts +358 -0
  252. package/dist/taco/model/text-sizer.js +996 -0
  253. package/dist/taco/model/theme-users.d.ts +59 -0
  254. package/dist/taco/model/theme-users.js +312 -0
  255. package/dist/taco/model/thumbnail.d.ts +15 -0
  256. package/dist/taco/model/thumbnail.js +34 -0
  257. package/dist/taco/model/types.d.ts +2347 -0
  258. package/dist/taco/model/types.js +366 -0
  259. package/dist/taco/model/unknown-property.d.ts +5 -0
  260. package/dist/taco/model/unknown-property.js +7 -0
  261. package/dist/taco/model/validated-documents.d.ts +22 -0
  262. package/dist/taco/model/validated-documents.js +22 -0
  263. package/dist/taco/model/variable-modes.d.ts +61 -0
  264. package/dist/taco/model/variable-modes.js +438 -0
  265. package/dist/taco/model/variable-references.d.ts +54 -0
  266. package/dist/taco/model/variable-references.js +183 -0
  267. package/dist/taco/model/variables.d.ts +24 -0
  268. package/dist/taco/model/variables.js +151 -0
  269. package/dist/taco/model/vector-network.d.ts +34 -0
  270. package/dist/taco/model/vector-network.js +411 -0
  271. package/dist/taco/svg-import/import-svg.d.ts +36 -0
  272. package/dist/taco/svg-import/import-svg.js +729 -0
  273. package/dist/taco/svg-import/index.d.ts +3 -0
  274. package/dist/taco/svg-import/index.js +3 -0
  275. package/dist/taco/svg-import/limits/limits.d.ts +79 -0
  276. package/dist/taco/svg-import/limits/limits.js +160 -0
  277. package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
  278. package/dist/taco/svg-import/paint/gradients.js +429 -0
  279. package/dist/taco/svg-import/paint/paint.d.ts +32 -0
  280. package/dist/taco/svg-import/paint/paint.js +162 -0
  281. package/dist/taco/svg-import/paths/paths.d.ts +58 -0
  282. package/dist/taco/svg-import/paths/paths.js +205 -0
  283. package/dist/taco/svg-import/public-types.d.ts +279 -0
  284. package/dist/taco/svg-import/public-types.js +56 -0
  285. package/dist/taco/svg-import/report/report.d.ts +44 -0
  286. package/dist/taco/svg-import/report/report.js +79 -0
  287. package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
  288. package/dist/taco/svg-import/reuse/reuse.js +840 -0
  289. package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
  290. package/dist/taco/svg-import/shapes/shapes.js +386 -0
  291. package/dist/taco/svg-import/structure/effects.d.ts +26 -0
  292. package/dist/taco/svg-import/structure/effects.js +618 -0
  293. package/dist/taco/svg-import/structure/image.d.ts +24 -0
  294. package/dist/taco/svg-import/structure/image.js +495 -0
  295. package/dist/taco/svg-import/structure/walk.d.ts +85 -0
  296. package/dist/taco/svg-import/structure/walk.js +544 -0
  297. package/dist/taco/svg-import/style/color.d.ts +40 -0
  298. package/dist/taco/svg-import/style/color.js +275 -0
  299. package/dist/taco/svg-import/style/computed.d.ts +214 -0
  300. package/dist/taco/svg-import/style/computed.js +1534 -0
  301. package/dist/taco/svg-import/style/css.d.ts +127 -0
  302. package/dist/taco/svg-import/style/css.js +541 -0
  303. package/dist/taco/svg-import/style/media.d.ts +25 -0
  304. package/dist/taco/svg-import/style/media.js +307 -0
  305. package/dist/taco/svg-import/style/properties.d.ts +43 -0
  306. package/dist/taco/svg-import/style/properties.js +135 -0
  307. package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
  308. package/dist/taco/svg-import/style/selector-reach.js +169 -0
  309. package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
  310. package/dist/taco/svg-import/style/selector-validity.js +307 -0
  311. package/dist/taco/svg-import/text/text.d.ts +29 -0
  312. package/dist/taco/svg-import/text/text.js +545 -0
  313. package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
  314. package/dist/taco/svg-import/transform/matrix.js +229 -0
  315. package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
  316. package/dist/taco/svg-import/tree/element-data.js +155 -0
  317. package/dist/taco/svg-import/tree/elements.d.ts +36 -0
  318. package/dist/taco/svg-import/tree/elements.js +121 -0
  319. package/dist/taco/svg-import/units/length.d.ts +43 -0
  320. package/dist/taco/svg-import/units/length.js +125 -0
  321. package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
  322. package/dist/taco/svg-import/units/viewbox.js +77 -0
  323. package/package.json +54 -4
@@ -0,0 +1,96 @@
1
+ import { propertyByFigmaId } from "./componentProps.js";
2
+ import { field, guidText, isObject } from "./fields.js";
3
+ import { shownSymbol } from "./instances.js";
4
+ /** The content frame id of a `componentPropAssignments` entry, or `undefined` when it is not a slot value. */
5
+ function slotContentOf(assignment, where) {
6
+ if (!isObject(assignment))
7
+ return undefined;
8
+ const varValue = field(assignment, "varValue", "object", where);
9
+ const value = varValue === undefined ? undefined : field(varValue, "value", "object", `${where}.varValue`);
10
+ const slot = value === undefined ? undefined : field(value, "slotContentIdValue", "object", `${where}.varValue.value`);
11
+ return slot?.["guid"] === undefined ? undefined : guidText(slot["guid"], `${where}.varValue.value.slotContentIdValue`);
12
+ }
13
+ /**
14
+ * The slots an INSTANCE fills: its own `componentPropAssignments`, and those
15
+ * of its `symbolOverrides` entries, which fill the slots of nested instances
16
+ * along the entry's `guidPath`. A path naming the instance's own component
17
+ * fills its own slots.
18
+ */
19
+ export function slotFillsOf(instance) {
20
+ const where = `node ${instance.id}`;
21
+ const fills = [];
22
+ const read = (list, keys, at) => {
23
+ (list ?? []).forEach((assignment, index) => {
24
+ const entryAt = `${at} componentPropAssignments[${String(index)}]`;
25
+ const contentId = slotContentOf(assignment, entryAt);
26
+ if (contentId === undefined || !isObject(assignment) || assignment["defID"] === undefined)
27
+ return;
28
+ fills.push({ keys, defId: guidText(assignment["defID"], entryAt), contentId });
29
+ });
30
+ };
31
+ read(field(instance.change, "componentPropAssignments", "list", where), [], where);
32
+ const symbolData = field(instance.change, "symbolData", "object", where);
33
+ const own = shownSymbol(instance);
34
+ (symbolData === undefined ? [] : field(symbolData, "symbolOverrides", "list", `${where} symbolData`) ?? []).forEach((entry, index) => {
35
+ const at = `${where} symbolOverrides[${String(index)}]`;
36
+ if (!isObject(entry))
37
+ return;
38
+ const path = field(entry, "guidPath", "object", at);
39
+ const keys = (path === undefined ? [] : field(path, "guids", "list", `${at}.guidPath`) ?? []).map((guid) => guidText(guid, `${at}.guidPath`));
40
+ read(field(entry, "componentPropAssignments", "list", at), keys.length === 1 && keys[0] === own ? [] : keys, at);
41
+ });
42
+ return fills;
43
+ }
44
+ /** Whether a Figma node is a frame holding the content an instance puts in a slot. */
45
+ export function isSlotContent(node) {
46
+ return node.change["isSlotContent"] === true;
47
+ }
48
+ /**
49
+ * The slot property a component layer's `componentPropRefs` binds to
50
+ * `SLOT_CONTENT_ID`, for `FrameNode.slot`. A binding on the component's
51
+ * root, on a layer that is not a frame or is a grid, inside another slot
52
+ * frame's default content (`inSlotFrame`), or to a property that was not
53
+ * imported, is reported and left out.
54
+ */
55
+ export function slotBindingOf(figma, layer, isRoot, inSlotFrame, properties, report) {
56
+ const where = `node ${figma.id} componentPropRefs`;
57
+ for (const ref of field(figma.change, "componentPropRefs", "list", `node ${figma.id}`) ?? []) {
58
+ if (!isObject(ref) || ref["componentPropNodeField"] !== "SLOT_CONTENT_ID" || ref["defID"] === undefined || ref["isDeleted"] === true)
59
+ continue;
60
+ const property = propertyByFigmaId(properties, guidText(ref["defID"], where))?.definition;
61
+ if (property?.kind !== "slot")
62
+ report("property-left-out", "a layer bound to a slot property that was not imported keeps its own layers");
63
+ else if (isRoot)
64
+ report("property-left-out", "a slot bound to the component's own frame is left out: only a frame inside a component can be a slot");
65
+ else if (layer.type !== "frame" || layer.layout.kind === "grid")
66
+ report("property-left-out", "a slot bound to a layer that is not a frame, or is a grid, is left out");
67
+ else if (inSlotFrame)
68
+ report("property-left-out", "a slot inside another slot's default content is left out: a slot frame cannot hold another");
69
+ else
70
+ return property.id;
71
+ }
72
+ return undefined;
73
+ }
74
+ /** Whether a slot frame keeps its own size on an axis, so the content does not decide it. */
75
+ function keepsSize(frame, axis) {
76
+ if (frame.resizing?.[axis] === "fill")
77
+ return false;
78
+ return frame.layout.kind === "absolute" || frame.layout[axis === "width" ? "widthSizing" : "heightSizing"] === "fixed";
79
+ }
80
+ /**
81
+ * The reason to report when a slot's content frame is a size the slot
82
+ * frame will not take: the content's size is not imported, so on an axis
83
+ * where the slot frame keeps its size (its own, or an override's), a
84
+ * difference over 1 px shows. An axis whose size layout or constraints
85
+ * decide (`skip`, Fill, Hug) is not checked.
86
+ */
87
+ export function slotSizeMismatch({ slotFrame, content, skip, size: sized }) {
88
+ const size = field(content.change, "size", "object", `node ${content.id}`);
89
+ const width = typeof size?.["x"] === "number" ? size["x"] : undefined;
90
+ const height = typeof size?.["y"] === "number" ? size["y"] : undefined;
91
+ const off = (axis, value) => value !== undefined && !skip[axis] && keepsSize(slotFrame, axis)
92
+ && Math.abs(value - (sized?.[axis] ?? slotFrame.frame[axis])) > 1;
93
+ if (!off("width", width) && !off("height", height))
94
+ return undefined;
95
+ return "a slot's content is another size than its slot frame, which keeps its own size: the content's size is not imported, so the slot shows at the slot frame's size";
96
+ }
@@ -0,0 +1,46 @@
1
+ import { type FigmaObject } from "./fields.ts";
2
+ /** The Figma style types whose lists a layer can take: effect styles and colour styles (Figma's `FILL` style type). */
3
+ export type FigmaStyleType = "EFFECT" | "FILL";
4
+ /**
5
+ * The list a Figma style of `styleType` holds (`effects` for an effect style, `fillPaints` for a colour style) for the
6
+ * style a `styleIdFor…` reference names, or `undefined` when the message does not have that style.
7
+ */
8
+ export type FigmaStyleList = (reference: unknown, styleType: FigmaStyleType) => readonly unknown[] | undefined;
9
+ /**
10
+ * The layer lists a Figma style can back: the field that names the style, the style's type, and the words for report
11
+ * entries. A stroke style is a colour style whose `fillPaints` become the layer's strokes.
12
+ */
13
+ declare const STYLE_BACKED: {
14
+ readonly effects: {
15
+ readonly reference: "styleIdForEffect";
16
+ readonly styleType: "EFFECT";
17
+ readonly style: "effect style";
18
+ readonly what: "effects";
19
+ };
20
+ readonly fillPaints: {
21
+ readonly reference: "styleIdForFill";
22
+ readonly styleType: "FILL";
23
+ readonly style: "fill style";
24
+ readonly what: "fills";
25
+ };
26
+ readonly strokePaints: {
27
+ readonly reference: "styleIdForStrokeFill";
28
+ readonly styleType: "FILL";
29
+ readonly style: "stroke style";
30
+ readonly what: "strokes";
31
+ };
32
+ };
33
+ export type StyleBackedList = keyof typeof STYLE_BACKED;
34
+ /** The `styleIdFor…` fields a layer names its effect, fill and stroke styles with, by the list each style backs. */
35
+ export declare const STYLE_REFERENCE_FIELDS: ReadonlyMap<string, StyleBackedList>;
36
+ /** Figma's style reference for "no style": a guid with both parts 0xffffffff, written when a layer or an override detaches a style. */
37
+ export declare function isDetachedStyle(reference: unknown): boolean;
38
+ /**
39
+ * The `effects`, `fillPaints` or `strokePaints` Figma draws for a layer whose fields are `change`: those of the style
40
+ * the layer names (`styleIdForEffect`, `styleIdForFill`, `styleIdForStrokeFill`), else the layer's own. Figma draws a
41
+ * layer that uses a style by the style's list; the layer's own list is a copy that the file does not keep in step with
42
+ * later edits of the style. A detached style (`isDetachedStyle`) keeps the layer's own list. When `styleList` does not
43
+ * have the style (or is left out), the layer's own list is used and, with `report`, that is reported as approximated.
44
+ */
45
+ export declare function styleBackedList(change: FigmaObject, list: StyleBackedList, styleList: FigmaStyleList | undefined, where: string, report?: (kind: "approximated", reason: string) => void): readonly unknown[] | undefined;
46
+ export {};
@@ -0,0 +1,42 @@
1
+ import { field, isObject } from "./fields.js";
2
+ /**
3
+ * The layer lists a Figma style can back: the field that names the style, the style's type, and the words for report
4
+ * entries. A stroke style is a colour style whose `fillPaints` become the layer's strokes.
5
+ */
6
+ const STYLE_BACKED = {
7
+ effects: { reference: "styleIdForEffect", styleType: "EFFECT", style: "effect style", what: "effects" },
8
+ fillPaints: { reference: "styleIdForFill", styleType: "FILL", style: "fill style", what: "fills" },
9
+ strokePaints: { reference: "styleIdForStrokeFill", styleType: "FILL", style: "stroke style", what: "strokes" },
10
+ };
11
+ /** The `styleIdFor…` fields a layer names its effect, fill and stroke styles with, by the list each style backs. */
12
+ export const STYLE_REFERENCE_FIELDS = new Map(Object.keys(STYLE_BACKED).map((list) => [STYLE_BACKED[list].reference, list]));
13
+ /** Figma's style reference for "no style": a guid with both parts 0xffffffff, written when a layer or an override detaches a style. */
14
+ export function isDetachedStyle(reference) {
15
+ const guid = isObject(reference) ? reference["guid"] : undefined;
16
+ return isObject(guid) && guid["sessionID"] === 0xffffffff && guid["localID"] === 0xffffffff;
17
+ }
18
+ /** The report reason for a layer whose `list` names a style the message does not have. */
19
+ function missingStyleReason(list) {
20
+ const { style, what } = STYLE_BACKED[list];
21
+ return `the Figma ${style} is not in the message; the layer's own copy of its ${what} is used`;
22
+ }
23
+ /**
24
+ * The `effects`, `fillPaints` or `strokePaints` Figma draws for a layer whose fields are `change`: those of the style
25
+ * the layer names (`styleIdForEffect`, `styleIdForFill`, `styleIdForStrokeFill`), else the layer's own. Figma draws a
26
+ * layer that uses a style by the style's list; the layer's own list is a copy that the file does not keep in step with
27
+ * later edits of the style. A detached style (`isDetachedStyle`) keeps the layer's own list. When `styleList` does not
28
+ * have the style (or is left out), the layer's own list is used and, with `report`, that is reported as approximated.
29
+ */
30
+ export function styleBackedList(change, list, styleList, where, report) {
31
+ const own = field(change, list, "list", where);
32
+ const { reference: name, styleType } = STYLE_BACKED[list];
33
+ const reference = change[name];
34
+ if (reference === undefined || isDetachedStyle(reference))
35
+ return own;
36
+ const styled = styleList?.(reference, styleType);
37
+ if (styled === undefined) {
38
+ report?.("approximated", missingStyleReason(list));
39
+ return own;
40
+ }
41
+ return styled;
42
+ }
@@ -0,0 +1,66 @@
1
+ import { type FigmaObject } from "./fields.ts";
2
+ import { type FigmaImportLimits, type FigmaRootSource } from "./types.ts";
3
+ /** One node change placed in the tree that `buildFigmaTree` rebuilds. */
4
+ export interface FigmaTreeNode {
5
+ /** The guid as `sessionID:localID`. */
6
+ readonly id: string;
7
+ readonly type: string;
8
+ readonly name: string;
9
+ readonly change: FigmaObject;
10
+ readonly parentId: string | undefined;
11
+ /** `parentIndex.position`, the fractional-index text that orders siblings. */
12
+ readonly position: string;
13
+ /** Children back to front (see `buildFigmaTree`). */
14
+ readonly children: FigmaTreeNode[];
15
+ }
16
+ export interface FigmaTree {
17
+ readonly nodes: ReadonlyMap<string, FigmaTreeNode>;
18
+ /** Nodes whose parent is not in the message, or that have no parent and are not the `DOCUMENT`. */
19
+ readonly orphans: readonly FigmaTreeNode[];
20
+ }
21
+ /**
22
+ * Rebuilds the tree from the message's flat `nodeChanges` list, which is not
23
+ * in tree order. Refuses a message that is not `NODE_CHANGES`, has more node
24
+ * changes than `limits.nodes`, has a malformed node change, repeats a guid, or
25
+ * has a cycle of parents. Siblings are sorted by `parentIndex.position` with
26
+ * plain code-unit comparison, ties by guid; the first child is at the back, as
27
+ * in fig2sketch (src/figformat/fig2tree.py:49 sorts ascending and gives the
28
+ * list to Sketch, whose first layer is at the back) and in Taco.
29
+ */
30
+ export declare function buildFigmaTree(message: unknown, limits: FigmaImportLimits): FigmaTree;
31
+ export interface FigmaRootGroup {
32
+ /** The page the roots belong to, or `null` for a clipboard selection. */
33
+ readonly page: FigmaTreeNode | null;
34
+ readonly roots: readonly FigmaTreeNode[];
35
+ }
36
+ export interface FigmaRoots {
37
+ readonly groups: readonly FigmaRootGroup[];
38
+ /** Selected guids that name no node in the message. */
39
+ readonly missing: readonly string[];
40
+ /** Pages marked `internalOnly`, which are never imported. */
41
+ readonly internalPages: readonly FigmaTreeNode[];
42
+ }
43
+ /**
44
+ * The root source asked for, else `"clipboard-selection"` when the message has
45
+ * a non-empty `clipboardSelectionRegions`, else `"pages"` (also for a message
46
+ * that is not an object, which `buildFigmaTree` refuses).
47
+ */
48
+ export declare function rootSourceOf(message: unknown, asked: FigmaRootSource | undefined): FigmaRootSource;
49
+ /** Picks the roots, as `FigmaRootSource` describes. */
50
+ export declare function chooseRoots(message: FigmaObject, tree: FigmaTree, asked: FigmaRootSource | undefined): FigmaRoots;
51
+ /** How many nodes sit below `node`, counted without recursion. */
52
+ export declare function countLayersInside(node: FigmaTreeNode): number;
53
+ type Matrix = readonly [number, number, number, number, number, number];
54
+ /** Keyed by node id: the product of that node's transform and its ancestors' (see `withAncestorTransforms`), or null when none has one. */
55
+ export type AncestorTransformCache = Map<string, Matrix | null>;
56
+ /**
57
+ * A copied root with the transforms of its ancestors in the message folded
58
+ * into its own `transform`, which Figma keeps relative to the parent, so a
59
+ * root inside a moved or rotated frame keeps its place and rotation on the
60
+ * page. The walk up stops at a CANVAS or DOCUMENT, or at a parent that is not
61
+ * in the message; an ancestor without a complete transform is skipped. The
62
+ * root is returned unchanged when there is nothing to fold in. Pass the same
63
+ * `cache` for every root of one message.
64
+ */
65
+ export declare function withAncestorTransforms(root: FigmaTreeNode, tree: FigmaTree, cache?: AncestorTransformCache): FigmaTreeNode;
66
+ export {};
@@ -0,0 +1,194 @@
1
+ import { field, guidText, isObject } from "./fields.js";
2
+ import { FigmaImportError } from "./types.js";
3
+ /**
4
+ * Rebuilds the tree from the message's flat `nodeChanges` list, which is not
5
+ * in tree order. Refuses a message that is not `NODE_CHANGES`, has more node
6
+ * changes than `limits.nodes`, has a malformed node change, repeats a guid, or
7
+ * has a cycle of parents. Siblings are sorted by `parentIndex.position` with
8
+ * plain code-unit comparison, ties by guid; the first child is at the back, as
9
+ * in fig2sketch (src/figformat/fig2tree.py:49 sorts ascending and gives the
10
+ * list to Sketch, whose first layer is at the back) and in Taco.
11
+ */
12
+ export function buildFigmaTree(message, limits) {
13
+ if (!isObject(message))
14
+ throw new FigmaImportError("not-node-changes", "the message is not an object");
15
+ const kind = field(message, "type", "string", "message");
16
+ if (kind !== "NODE_CHANGES")
17
+ throw new FigmaImportError("not-node-changes", `the message type is ${JSON.stringify(kind ?? null)}, not "NODE_CHANGES"`);
18
+ const changes = field(message, "nodeChanges", "list", "message");
19
+ if (changes === undefined)
20
+ throw new FigmaImportError("not-node-changes", "the message has no nodeChanges list");
21
+ if (changes.length > limits.nodes) {
22
+ throw new FigmaImportError("too-many-nodes", `the message has ${String(changes.length)} node changes, over the limit of ${String(limits.nodes)}; raise options.limits.nodes to import it`);
23
+ }
24
+ const nodes = new Map();
25
+ changes.forEach((change, index) => {
26
+ const where = `nodeChanges[${String(index)}]`;
27
+ if (!isObject(change))
28
+ throw new FigmaImportError("not-node-changes", `${where} is not an object`);
29
+ const id = guidText(change["guid"], where);
30
+ const type = field(change, "type", "string", where);
31
+ if (type === undefined)
32
+ throw new FigmaImportError("not-node-changes", `${where} (${id}) has no type`);
33
+ const parentIndex = field(change, "parentIndex", "object", where);
34
+ const position = parentIndex === undefined ? "" : field(parentIndex, "position", "string", `${where}.parentIndex`);
35
+ if (position === undefined)
36
+ throw new FigmaImportError("not-node-changes", `${where} (${id}) has a parentIndex without a position`);
37
+ if (nodes.has(id))
38
+ throw new FigmaImportError("duplicate-guid", `guid ${id} is used by more than one node change (again at ${where})`);
39
+ const parentId = parentIndex === undefined ? undefined : guidText(parentIndex["guid"], `${where}.parentIndex`);
40
+ nodes.set(id, { id, type, name: field(change, "name", "string", where) ?? "", change, parentId, position, children: [] });
41
+ });
42
+ checkNoCycles(nodes);
43
+ const orphans = [];
44
+ for (const node of nodes.values()) {
45
+ const parent = node.parentId === undefined ? undefined : nodes.get(node.parentId);
46
+ if (parent !== undefined)
47
+ parent.children.push(node);
48
+ else if (node.type !== "DOCUMENT" || node.parentId !== undefined)
49
+ orphans.push(node);
50
+ }
51
+ for (const node of nodes.values())
52
+ node.children.sort(compareSiblings);
53
+ return { nodes, orphans };
54
+ }
55
+ function compareSiblings(a, b) {
56
+ if (a.position !== b.position)
57
+ return a.position < b.position ? -1 : 1;
58
+ const [aSession, aLocal] = a.id.split(":").map(Number);
59
+ const [bSession, bLocal] = b.id.split(":").map(Number);
60
+ return aSession - bSession || aLocal - bLocal;
61
+ }
62
+ /** Follows every node's parents without recursion; refuses when a node is its own ancestor. */
63
+ function checkNoCycles(nodes) {
64
+ const state = new Map();
65
+ for (const start of nodes.values()) {
66
+ const path = [];
67
+ let current = start;
68
+ while (current !== undefined && !state.has(current.id)) {
69
+ state.set(current.id, "on-path");
70
+ path.push(current.id);
71
+ current = current.parentId === undefined ? undefined : nodes.get(current.parentId);
72
+ }
73
+ if (current !== undefined && state.get(current.id) === "on-path") {
74
+ throw new FigmaImportError("cycle", `node ${current.id} is its own ancestor through parentIndex`);
75
+ }
76
+ for (const id of path)
77
+ state.set(id, "done");
78
+ }
79
+ }
80
+ /**
81
+ * The root source asked for, else `"clipboard-selection"` when the message has
82
+ * a non-empty `clipboardSelectionRegions`, else `"pages"` (also for a message
83
+ * that is not an object, which `buildFigmaTree` refuses).
84
+ */
85
+ export function rootSourceOf(message, asked) {
86
+ if (asked !== undefined)
87
+ return asked;
88
+ if (!isObject(message))
89
+ return "pages";
90
+ const regions = field(message, "clipboardSelectionRegions", "list", "message");
91
+ return regions !== undefined && regions.length > 0 ? "clipboard-selection" : "pages";
92
+ }
93
+ /** Picks the roots, as `FigmaRootSource` describes. */
94
+ export function chooseRoots(message, tree, asked) {
95
+ const regions = field(message, "clipboardSelectionRegions", "list", "message");
96
+ const source = rootSourceOf(message, asked);
97
+ if (source === "clipboard-selection") {
98
+ if (regions === undefined || regions.length === 0)
99
+ throw new FigmaImportError("no-roots", "the message has no clipboardSelectionRegions");
100
+ const roots = new Set();
101
+ const missing = [];
102
+ regions.forEach((region, index) => {
103
+ const where = `clipboardSelectionRegions[${String(index)}]`;
104
+ if (!isObject(region))
105
+ throw new FigmaImportError("not-node-changes", `${where} is not an object`);
106
+ for (const guid of field(region, "nodes", "list", where) ?? []) {
107
+ const id = guidText(guid, `${where}.nodes`);
108
+ const node = tree.nodes.get(id);
109
+ if (node === undefined)
110
+ missing.push(id);
111
+ else
112
+ roots.add(node);
113
+ }
114
+ });
115
+ return { groups: [{ page: null, roots: [...roots] }], missing, internalPages: [] };
116
+ }
117
+ const document = tree.nodes.get("0:0");
118
+ if (document?.type !== "DOCUMENT")
119
+ throw new FigmaImportError("no-roots", "the message has no DOCUMENT node 0:0");
120
+ const pages = document.children.filter((child) => child.type === "CANVAS");
121
+ const internal = (page) => page.change["internalOnly"] === true;
122
+ const groups = pages.filter((page) => !internal(page)).map((page) => ({ page, roots: page.children }));
123
+ return { groups, missing: [], internalPages: pages.filter(internal) };
124
+ }
125
+ /** How many nodes sit below `node`, counted without recursion. */
126
+ export function countLayersInside(node) {
127
+ let count = 0;
128
+ const stack = [...node.children];
129
+ for (let next = stack.pop(); next !== undefined; next = stack.pop()) {
130
+ count += 1;
131
+ stack.push(...next.children);
132
+ }
133
+ return count;
134
+ }
135
+ const MATRIX_KEYS = ["m00", "m01", "m02", "m10", "m11", "m12"];
136
+ function matrixOf(node) {
137
+ const transform = node.change["transform"];
138
+ if (!isObject(transform))
139
+ return null;
140
+ const values = MATRIX_KEYS.map((key) => transform[key]);
141
+ return values.every((value) => typeof value === "number" && Number.isFinite(value)) ? values : null;
142
+ }
143
+ function multiply(p, m) {
144
+ return [
145
+ p[0] * m[0] + p[1] * m[3], p[0] * m[1] + p[1] * m[4], p[0] * m[2] + p[1] * m[5] + p[2],
146
+ p[3] * m[0] + p[4] * m[3], p[3] * m[1] + p[4] * m[4], p[3] * m[2] + p[4] * m[5] + p[5],
147
+ ];
148
+ }
149
+ /** The node's parent when the walk up should go on, else undefined. */
150
+ function foldedParent(node, tree) {
151
+ const parent = node.parentId === undefined ? undefined : tree.nodes.get(node.parentId);
152
+ return parent === undefined || parent.type === "CANVAS" || parent.type === "DOCUMENT" ? undefined : parent;
153
+ }
154
+ /**
155
+ * The product of `node`'s transform and those of its ancestors up to the
156
+ * CANVAS. Each node on the way is computed once and kept in `cache`, so many
157
+ * roots in one deep chain cost one walk of the chain in total.
158
+ */
159
+ function chainMatrix(node, tree, cache) {
160
+ const path = [];
161
+ let current = node;
162
+ while (current !== undefined && !cache.has(current.id)) {
163
+ path.push(current);
164
+ current = foldedParent(current, tree);
165
+ }
166
+ let above = current === undefined ? null : cache.get(current.id);
167
+ for (let i = path.length - 1; i >= 0; i--) {
168
+ const own = matrixOf(path[i]);
169
+ above = own === null ? above : above === null ? own : multiply(above, own);
170
+ cache.set(path[i].id, above);
171
+ }
172
+ return above;
173
+ }
174
+ /**
175
+ * A copied root with the transforms of its ancestors in the message folded
176
+ * into its own `transform`, which Figma keeps relative to the parent, so a
177
+ * root inside a moved or rotated frame keeps its place and rotation on the
178
+ * page. The walk up stops at a CANVAS or DOCUMENT, or at a parent that is not
179
+ * in the message; an ancestor without a complete transform is skipped. The
180
+ * root is returned unchanged when there is nothing to fold in. Pass the same
181
+ * `cache` for every root of one message.
182
+ */
183
+ export function withAncestorTransforms(root, tree, cache = new Map()) {
184
+ const own = matrixOf(root);
185
+ if (own === null)
186
+ return root;
187
+ const parent = foldedParent(root, tree);
188
+ const above = parent === undefined ? null : chainMatrix(parent, tree, cache);
189
+ if (above === null)
190
+ return root;
191
+ const m = multiply(above, own);
192
+ const transform = Object.fromEntries(MATRIX_KEYS.map((key, index) => [key, m[index]]));
193
+ return { ...root, change: { ...root.change, transform } };
194
+ }