@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,9 @@
1
+ import type { FigmaImportResult } from '../taco/figma-import/index.ts';
2
+ import type { TacoDocument } from './convert.ts';
3
+ /**
4
+ * Wraps reader output as a Taco document for conversion.
5
+ * @param result - Pages, components, assets and styles from the Figma reader.
6
+ * @param name - Display name for the clipboard's page. Saved files keep their page names.
7
+ * @returns The source document with roots grouped by page.
8
+ */
9
+ export declare function figmaDocument(result: FigmaImportResult, name?: string): TacoDocument;
@@ -0,0 +1,30 @@
1
+ const base64 = (bytes) => { let s = ''; for (let i = 0; i < bytes.length; i += 0x8000)
2
+ s += String.fromCharCode(...bytes.subarray(i, i + 0x8000)); return btoa(s); };
3
+ /**
4
+ * Wraps reader output as a Taco document for conversion.
5
+ * @param result - Pages, components, assets and styles from the Figma reader.
6
+ * @param name - Display name for the clipboard's page. Saved files keep their page names.
7
+ * @returns The source document with roots grouped by page.
8
+ */
9
+ export function figmaDocument(result, name) {
10
+ const nodes = {};
11
+ for (const n of result.nodes)
12
+ nodes[n.id] = n;
13
+ const groups = result.rootSource === 'pages'
14
+ ? result.pages.map((p, i) => ({ name: p.name.trim() || `Page ${i + 1}`, roots: p.roots, variableModes: p.variableModes }))
15
+ : [{ name: name ?? 'Pasted', roots: result.roots.map((r) => r.id), variableModes: undefined }];
16
+ const pageOrder = [], pages = {};
17
+ groups.forEach((group, i) => {
18
+ const rootId = `@page-${i}`;
19
+ nodes[rootId] = { id: rootId, type: 'frame', name: group.name, frame: { x: 0, y: 0, width: 0, height: 0 }, children: [...group.roots], variableModes: group.variableModes };
20
+ pageOrder.push(`page-${i}`);
21
+ pages[`page-${i}`] = { name: group.name, rootId };
22
+ });
23
+ const components = {};
24
+ for (const c of result.components)
25
+ components[c.id] = c;
26
+ const assets = {};
27
+ for (const i of Object.values(result.assets))
28
+ assets[i.id] = { id: i.id, kind: 'image', mimeType: i.mimeType, ...(i.width !== undefined ? { width: i.width } : {}), ...(i.height !== undefined ? { height: i.height } : {}), source: { kind: 'data', data: base64(i.bytes) } };
29
+ return { pageOrder, pages, nodes, components, assets, componentPlacements: result.componentPlacements, theme: { variableCollections: result.variableCollections, textStyles: result.textStyles ?? {} } };
30
+ }
@@ -0,0 +1,14 @@
1
+ import type { DocumentJSON } from '@moondraft/editor/schema';
2
+ import type { ImportReportEntry } from '@moondraft/editor/core';
3
+ import type { readFileMessage } from '../taco/figma-import/import/walk.ts';
4
+ /** Reader output with the original set members and resource identities.
5
+ * @internal
6
+ */
7
+ export type FileMessage = ReturnType<typeof readFileMessage>;
8
+ /** Installs local property IDs, their bindings, instance assignments and slot content.
9
+ * @param result - Original Figma component declarations and placements.
10
+ * @param doc - Linked document, with source IDs for the original nodes.
11
+ * @param report - Receives occurrences the native document cannot represent.
12
+ * @returns Authored Figma fields keyed by the surviving instance and native override path.
13
+ */
14
+ export declare function fileComponents(result: FileMessage, doc: DocumentJSON, report: ImportReportEntry[]): Map<string, Map<string, Readonly<Record<string, unknown>>>>;
@@ -0,0 +1,262 @@
1
+ import { guidText } from '../taco/figma-import/import/fields.js';
2
+ import { formatExpressionName, parseLayerPath } from '../taco/model/index.js';
3
+ /** Installs local property IDs, their bindings, instance assignments and slot content.
4
+ * @param result - Original Figma component declarations and placements.
5
+ * @param doc - Linked document, with source IDs for the original nodes.
6
+ * @param report - Receives occurrences the native document cannot represent.
7
+ * @returns Authored Figma fields keyed by the surviving instance and native override path.
8
+ */
9
+ export function fileComponents(result, doc, report) {
10
+ const models = doc.models;
11
+ const byId = new Map(models.map(m => [m.id, m]));
12
+ const mains = new Map(), bySource = new Map();
13
+ const source = new Map(result.nodes.map(n => [n.id, n]));
14
+ const componentOfRoot = new Map(result.components.map(c => [c.rootId, c.id]));
15
+ for (const m of models) {
16
+ if (m.component === m.id)
17
+ mains.set(componentOfRoot.get(m.sourceId), m);
18
+ if (m.fileInstance) {
19
+ m.sourceId = m.fileInstance;
20
+ delete m.fileInstance;
21
+ }
22
+ if (m.sourceId)
23
+ bySource.set(m.sourceId, m);
24
+ }
25
+ const definitions = new Map();
26
+ const nameOf = (name) => name.replace(/#\d+(?::\d+)*$/, '').trim() || 'Property';
27
+ function declare(owner, properties, isSet) {
28
+ const refs = new Map(), names = new Set();
29
+ for (const p of properties) {
30
+ if (refs.has(p.id) || p.kind === 'slot')
31
+ continue;
32
+ const base = nameOf(p.name);
33
+ let name = base;
34
+ for (let i = 2; names.has(name); i++)
35
+ name = base + ' ' + i;
36
+ if (name !== base)
37
+ report.push({ kind: 'approximated', what: `property renamed from ${base} to ${name}`, count: 1, ids: [owner.id] });
38
+ names.add(name);
39
+ const id = 'p' + (refs.size + 1);
40
+ const def = { id, name, kind: p.kind, default: p.defaultValue };
41
+ if (p.kind === 'variant') {
42
+ def.options = p.options;
43
+ }
44
+ else if (p.kind === 'instance') {
45
+ def.kind = 'swap';
46
+ def.default = mains.get(p.defaultValue).id;
47
+ if (p.preferred)
48
+ def.preferred = p.preferred.flatMap((key) => mains.get(key)?.id ?? []);
49
+ }
50
+ refs.set(p.id, def);
51
+ }
52
+ const props = [...refs.values()];
53
+ if (isSet)
54
+ owner.variantSet = { props };
55
+ else if (props.length)
56
+ owner.props = props;
57
+ if (props.length)
58
+ owner.propSeq = props.length;
59
+ return refs;
60
+ }
61
+ const components = new Map(result.components.map(c => [c.id, c]));
62
+ for (const [guid, { plan, properties }] of result.sources.variants) {
63
+ const members = plan.variants;
64
+ let set = bySource.get(result.layerIds[guid]);
65
+ if (!set) {
66
+ set = { id: 'set-' + guid, kind: 'frame', name: plan.set.name, parent: '@components', w: 0, h: 0 };
67
+ set.sourceId = set.id;
68
+ result.layerIds[guid] = set.sourceId;
69
+ models.push(set);
70
+ byId.set(set.id, set);
71
+ }
72
+ set.key = plan.set.change.componentKey || 'figma-' + guid;
73
+ const variantDefs = new Map(plan.set.change.componentPropDefs.map(d => ['figma-' + guidText(d.id, guid), d]));
74
+ const orders = new Map((plan.set.change.stateGroupPropertyValueOrders ?? []).map(o => [o.property, o.values]));
75
+ const axes = plan.properties.flatMap(p => {
76
+ const def = variantDefs.get(p.id);
77
+ const option = (id) => id.slice(p.id.length + 1);
78
+ const options = [...new Set([...orders.get(def.name) ?? [], ...p.options.map(o => option(o.id))])];
79
+ const initial = def.initialValue?.textValue?.characters;
80
+ if (!members.length && typeof initial === 'string' && !options.includes(initial))
81
+ options.push(initial);
82
+ if (!options.length) {
83
+ report.push({ kind: 'left-out', what: 'variant property without options', count: 1, ids: [set.id] });
84
+ return [];
85
+ }
86
+ return [{ ...p, name: def.name, kind: 'variant', options, defaultValue: options.includes(initial) ? initial : option(p.defaultValue) }];
87
+ });
88
+ const declarations = [...axes, ...properties.map(p => p.definition),
89
+ ...members.flatMap(v => components.get(v.componentId).properties ?? [])];
90
+ const refs = declare(set, declarations, true);
91
+ for (const { variant } of plan.duplicates) {
92
+ const main = mains.get(variant.componentId);
93
+ if (main.parent !== '@components') {
94
+ const placement = { id: 'duplicate-' + main.id, kind: 'frame', name: main.name, parent: main.parent, t: main.t,
95
+ w: main.w, h: main.h, opacity: main.opacity, component: main.id };
96
+ models.splice(models.indexOf(main), 0, placement);
97
+ }
98
+ main.parent = '@components';
99
+ report.push({ kind: 'approximated', what: 'duplicate variant kept as a standalone main', count: 1, ids: [main.id] });
100
+ }
101
+ for (const [i, member] of members.entries()) {
102
+ const main = mains.get(member.componentId);
103
+ const values = plan.values[i];
104
+ main.parent = set.id;
105
+ main.variant = Object.fromEntries(plan.properties.map(p => [
106
+ refs.get(p.id).id, values[p.id].slice(p.id.length + 1),
107
+ ]));
108
+ definitions.set(member.componentId, refs);
109
+ }
110
+ }
111
+ const sourceComponent = new Map();
112
+ for (const c of result.components) {
113
+ const main = mains.get(c.id);
114
+ main.key = c.key;
115
+ if (!definitions.has(c.id))
116
+ definitions.set(c.id, declare(main, c.properties ?? [], false));
117
+ else
118
+ for (const p of c.properties ?? []) {
119
+ if (p.kind === 'slot')
120
+ continue;
121
+ const shared = definitions.get(c.id).get(p.id);
122
+ const value = p.kind === 'instance' ? mains.get(p.defaultValue).id : p.defaultValue;
123
+ if (value !== shared.default)
124
+ report.push({ kind: 'approximated', what: 'variant member property default', count: 1, ids: [main.id] });
125
+ }
126
+ const pending = [c.rootId];
127
+ while (pending.length) {
128
+ const id = pending.pop(), layer = source.get(id);
129
+ sourceComponent.set(id, c);
130
+ for (const child of layer.children ?? [])
131
+ pending.push(child);
132
+ }
133
+ }
134
+ function values(component, assignments) {
135
+ const refs = definitions.get(component);
136
+ return Object.fromEntries(Object.entries(assignments).flatMap(([key, value]) => {
137
+ const p = refs.get(key);
138
+ return p ? [[p.id, p.kind === 'swap' ? mains.get(value).id : value]] : [];
139
+ }));
140
+ }
141
+ // Reader paths cross instances and name the final layer. Native paths also include each ordinary parent.
142
+ function overridePath(key) {
143
+ return (parseLayerPath(key) ?? []).flatMap(sourceId => {
144
+ const chain = [];
145
+ for (let layer = bySource.get(sourceId); layer && layer.component !== layer.id; layer = byId.get(layer.parent))
146
+ chain.unshift(layer.id);
147
+ return chain;
148
+ }).join(';');
149
+ }
150
+ const occurrences = new Map();
151
+ const hosts = new Set(result.nodes.filter(n => n.type === 'frame' && n.slotHost).map(n => n.id));
152
+ const usedHosts = new Set();
153
+ const slots = new Set();
154
+ const enclosing = new Map();
155
+ for (const m of models) {
156
+ const main = m.component === m.id ? m : enclosing.get(m.parent);
157
+ enclosing.set(m.id, main);
158
+ const owner = sourceComponent.get(m.sourceId);
159
+ if (owner && main === mains.get(owner.id))
160
+ bySource.set(m.sourceId, m);
161
+ }
162
+ for (const m of models) {
163
+ const n = source.get(m.sourceId);
164
+ if (!n)
165
+ continue;
166
+ const component = sourceComponent.get(n.id);
167
+ const original = component && enclosing.get(m.id) === mains.get(component.id);
168
+ const properties = original ? component.properties ?? [] : [];
169
+ if (m.component && m.overrides) {
170
+ for (const [path, entry] of Object.entries(m.overrides)) {
171
+ if (entry.component && Object.keys(entry).some(k => k.startsWith('look.') || k === 'radius' || k === 'smoothing'))
172
+ report.push({ kind: 'approximated', what: 'swapped root appearance', count: 1, ids: [m.id + ';' + path] });
173
+ }
174
+ }
175
+ for (const [field, expression] of Object.entries(n.expressions ?? {})) {
176
+ const p = properties.find(p => formatExpressionName(p.name) === expression);
177
+ const bind = { characters: 'content', visible: 'visible', componentId: 'component' }[field];
178
+ if (p && bind && original && (bind !== 'component' || m.component)) {
179
+ (m.bind ??= {})[bind] = definitions.get(component.id).get(p.id).id;
180
+ }
181
+ else
182
+ report.push({ kind: 'approximated', what: 'expression', count: 1, ids: [m.id] });
183
+ }
184
+ if (n.slot && original) {
185
+ const key = component.id + '/' + n.slot;
186
+ if (slots.has(key))
187
+ report.push({ kind: 'approximated', what: 'repeated slot', ids: [m.id], count: 1 });
188
+ else {
189
+ const declaration = properties.find(p => p.id === n.slot);
190
+ m.slot = { id: n.slot, name: nameOf(declaration.name) };
191
+ for (const field of ['minChildren', 'maxChildren', 'preferredOnly', 'preferred', 'fillCrossAxisOnInsert', 'displayEmptyByDefault'])
192
+ if (field in declaration)
193
+ report.push({ kind: 'left-out', what: 'slot ' + field, count: 1, ids: [m.id] });
194
+ slots.add(key);
195
+ }
196
+ }
197
+ if (n.type !== 'instance' || m.component === m.id)
198
+ continue;
199
+ if (!m.component) {
200
+ report.push({ kind: 'approximated', what: 'expanded instance', count: 1, ids: [m.id] });
201
+ continue;
202
+ }
203
+ const fields = result.sources.occurrenceFields.get(n.id);
204
+ if (fields)
205
+ occurrences.set(m.id, new Map([...fields].map(([key, change]) => [overridePath(key), change])));
206
+ const refs = definitions.get(n.componentId);
207
+ const assignments = values(n.componentId, n.propertyValues ?? {});
208
+ // A member may override a set declaration's default. Native defaults belong to the set.
209
+ for (const p of components.get(n.componentId).properties ?? []) {
210
+ const ref = refs.get(p.id);
211
+ if (!ref || ref.id in assignments)
212
+ continue;
213
+ const value = p.kind === 'instance' ? mains.get(p.defaultValue).id : p.defaultValue;
214
+ if (value !== ref.default)
215
+ assignments[ref.id] = value;
216
+ }
217
+ if (Object.keys(assignments).length)
218
+ m.props = assignments;
219
+ for (const [key, entry] of Object.entries(n.overrides ?? {}))
220
+ if (entry.propertyValues) {
221
+ const target = source.get(parseLayerPath(key).at(-1));
222
+ const path = overridePath(key);
223
+ ((m.overrides ??= {})[path] ??= {}).props = values(entry.componentId ?? target.componentId, entry.propertyValues);
224
+ }
225
+ for (const [path, fills] of Object.entries(n.slots ?? {})) {
226
+ for (const [slot, id] of Object.entries(fills)) {
227
+ const host = bySource.get(id);
228
+ if (path) {
229
+ // Native fill frames belong to a stored instance. A virtual instance cannot own one.
230
+ report.push({ kind: 'approximated', what: 'nested slot fill', count: 1, ids: [m.id] });
231
+ }
232
+ else {
233
+ usedHosts.add(host.id);
234
+ host.parent = m.id;
235
+ host.fillsSlot = slot;
236
+ }
237
+ }
238
+ }
239
+ }
240
+ // Reparented private fills and hidden set members must follow their stored parents on load.
241
+ const children = new Map();
242
+ for (const m of models) {
243
+ if (hosts.has(m.sourceId) && !usedHosts.has(m.id) && !m.parent)
244
+ continue;
245
+ const parent = m.parent ?? '';
246
+ const list = children.get(parent);
247
+ if (list)
248
+ list.push(m);
249
+ else
250
+ children.set(parent, [m]);
251
+ }
252
+ doc.models = [];
253
+ function append(parent) {
254
+ for (const m of children.get(parent) ?? []) {
255
+ doc.models.push(m);
256
+ append(m.id);
257
+ }
258
+ }
259
+ append('');
260
+ append('@components');
261
+ return occurrences;
262
+ }
@@ -0,0 +1,29 @@
1
+ import type { ImportReportEntry } from '@moondraft/editor/core';
2
+ import { type DocumentJSON } from '@moondraft/editor/schema';
3
+ import { type FigmaObject } from '../taco/figma-import/import/fields.ts';
4
+ import type { FileMessage } from './file-components.ts';
5
+ type Corner = {
6
+ value: number;
7
+ binding?: {
8
+ data: unknown;
9
+ specific: boolean;
10
+ };
11
+ };
12
+ /** Finds instance roots that need their own radius bindings. Native instance roots take bindings from their main.
13
+ * @param result - File definitions and original instance fields.
14
+ * @returns The effective corners for each root that must remain an expanded frame.
15
+ * @internal
16
+ */
17
+ export declare function expandedRadiusRoots(result: FileMessage): Map<string, Corner[]>;
18
+ /** Writes the shared resources, layer references and mode choices of a saved file.
19
+ * @param result - Reader output retaining the source relationships.
20
+ * @param doc - Converted layers to associate with their definitions.
21
+ * @param occurrences - Original override fields at their native instance paths.
22
+ * @param expanded - Converted instance literals before the linker removes equal fields.
23
+ * @param expandedRadii - Effective corners of instance roots kept as frames.
24
+ * @param report - Receives unsupported bindings and style uses.
25
+ * @param fileId - Stable Figma file key or digest for unpublished resources.
26
+ * @returns Nothing.
27
+ */
28
+ export declare function fileResources(result: FileMessage, doc: DocumentJSON, occurrences: Map<string, Map<string, FigmaObject>>, expanded: ReadonlyMap<string, any>, expandedRadii: ReadonlyMap<string, Corner[]>, report: ImportReportEntry[], fileId: () => string): void;
29
+ export {};