@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,544 @@
1
+ import { multiplyTransforms, getNodeBounds, nodeLocalTransform, } from "../../model/index.js";
2
+ import { computeElementStyle, initialComputedStyle } from "../style/computed.js";
3
+ import { attr, childElements, elementId, isSvgElement, pathStep, sameTagIndex, } from "../tree/elements.js";
4
+ import { applyMatrixToPoint, IDENTITY_MATRIX, invertMatrix, parseTransform, } from "../transform/matrix.js";
5
+ import { DEFAULT_PRESERVE_ASPECT_RATIO, parsePreserveAspectRatio, parseViewBox, viewBoxTransform } from "../units/viewbox.js";
6
+ import { lengthAttr, rasterFramePlan, shapeLayer } from "../shapes/shapes.js";
7
+ import { pathLayerFromData, layerChrome, layerPlacement } from "../paths/paths.js";
8
+ import { textLayer } from "../text/text.js";
9
+ import { applyClipMaskFilter } from "./effects.js";
10
+ import { imageLayer } from "./image.js";
11
+ import { useLayer, drawnTargetLayer } from "../reuse/reuse.js";
12
+ /** Definition elements that never paint where they sit. */
13
+ const DEFINITION_ELEMENTS = new Set([
14
+ "defs", "title", "desc", "metadata", "style",
15
+ "linearGradient", "radialGradient", "pattern", "clipPath", "mask", "filter",
16
+ "symbol", "marker", "solidColor", "hatch", "cursor", "font", "font-face",
17
+ "color-profile", "view",
18
+ ]);
19
+ /** Elements always named in the report when met, per the spec's list. */
20
+ const ALWAYS_REPORTED = {
21
+ script: "scripts are never run",
22
+ foreignObject: "foreignObject is not supported",
23
+ animate: "animation is not supported",
24
+ animateTransform: "animation is not supported",
25
+ animateMotion: "animation is not supported",
26
+ set: "animation is not supported",
27
+ marker: "markers are not supported",
28
+ };
29
+ const ANIMATION_NOTE = { what: "Animation", kept: "The design is kept as it first appears, without moving" };
30
+ /** The plain words of each `ALWAYS_REPORTED` element, for grouping. */
31
+ const ALWAYS_REPORTED_NOTES = {
32
+ script: { what: "Scripts", kept: "Not part of the design" },
33
+ foreignObject: { what: "Embedded HTML (foreignObject)", kept: "Not drawn" },
34
+ animate: ANIMATION_NOTE,
35
+ animateTransform: ANIMATION_NOTE,
36
+ animateMotion: ANIMATION_NOTE,
37
+ set: ANIMATION_NOTE,
38
+ marker: { what: "Markers", kept: "The shapes are kept without their markers" },
39
+ };
40
+ const FOREIGN_NOTE = { what: "Elements that are not SVG", kept: "Not drawn" };
41
+ const UNSUPPORTED_NOTE = { what: "Unsupported elements", kept: "Not drawn" };
42
+ const BAD_TRANSFORM_NOTE = { what: "Transforms that cannot be inverted", kept: "Not drawn" };
43
+ /**
44
+ * Why an element from another XML namespace is left out: a browser draws
45
+ * only SVG elements, even when the local name matches one, and nothing
46
+ * inside a foreign element.
47
+ */
48
+ function foreignReason(element) {
49
+ return `<${element.localName}> in the namespace "${element.namespaceURI ?? ""}" is not SVG and is not drawn`;
50
+ }
51
+ /**
52
+ * The conditional attributes a browser tests to decide whether to draw an
53
+ * element (against its language, or extensions it supports). The import
54
+ * does not test them, so it draws the element and reports the condition.
55
+ */
56
+ const CONDITION_ATTRIBUTES = ["systemLanguage", "requiredExtensions"];
57
+ /** Reports each conditional attribute an element carries. */
58
+ export function reportConditionAttributes(element, elementPath, report) {
59
+ for (const attribute of CONDITION_ATTRIBUTES) {
60
+ // An empty value is a condition too: a browser reads it as false.
61
+ const value = element.getAttribute(attribute);
62
+ if (value === null)
63
+ continue;
64
+ report(elementPath, element.localName, "left-out", `the condition ${attribute}="${value}" is not applied; the element is always drawn`, { what: "Conditions on elements", kept: "The element is always drawn" });
65
+ }
66
+ }
67
+ /** Reports an element's `on*` event attributes, once per element. */
68
+ function reportEventAttributes(element, elementPath, ctx) {
69
+ for (let index = 0; index < element.attributes.length; index += 1) {
70
+ const attribute = element.attributes[index];
71
+ if (/^on/i.test(attribute.name)) {
72
+ ctx.report(elementPath, element.localName, "left-out", `the script attribute "${attribute.name}" is ignored`, { what: "Script attributes", kept: "Not part of the design" });
73
+ return;
74
+ }
75
+ }
76
+ }
77
+ /**
78
+ * Builds the layers of one element's children, in document order, mapped by
79
+ * `parentMatrix` into the parent layer's coordinate space.
80
+ */
81
+ export function buildChildren(parentElement, parentStyle, parentMatrix, parentPath, ctx) {
82
+ const children = [];
83
+ const nodes = [];
84
+ for (const child of childElements(parentElement)) {
85
+ const elementPath = `${parentPath} > ${pathStep(child, sameTagIndex(parentElement, child))}`;
86
+ const built = buildElement(child, parentStyle, parentMatrix, elementPath, ctx);
87
+ if (built.top !== null)
88
+ children.push(built.top);
89
+ nodes.push(...built.nodes);
90
+ }
91
+ return { children, nodes };
92
+ }
93
+ /** Builds the layers of one element. Definition elements return nothing. */
94
+ export function buildElement(element, parentStyle, parentMatrix, elementPath, ctx) {
95
+ // Builds nest through <use> targets as well as children, so their depth
96
+ // is capped here, before it can overflow the call stack.
97
+ ctx.limits.enterBuild();
98
+ const mark = ctx.reportBuilder.mark();
99
+ try {
100
+ const built = buildOneElement(element, parentStyle, parentMatrix, elementPath, ctx);
101
+ // The report lines of this element and of dropped elements inside it
102
+ // apply to the layer it became. Inside a component's content (or a
103
+ // plain copy's) they wait for the instance or copy that shows it.
104
+ if (built.top !== null && ctx.buildingComponentTree !== true) {
105
+ ctx.reportBuilder.placeSince(mark, elementPath, built.top.id);
106
+ }
107
+ return built;
108
+ }
109
+ finally {
110
+ ctx.limits.leaveBuild();
111
+ }
112
+ }
113
+ function buildOneElement(element, parentStyle, parentMatrix, elementPath, ctx) {
114
+ const nothing = { top: null, nodes: [] };
115
+ if (!isSvgElement(element)) {
116
+ ctx.report(elementPath, element.localName, "left-out", foreignReason(element), FOREIGN_NOTE);
117
+ return nothing;
118
+ }
119
+ reportEventAttributes(element, elementPath, ctx);
120
+ reportConditionAttributes(element, elementPath, ctx.report);
121
+ const name = element.localName;
122
+ const alwaysReason = ALWAYS_REPORTED[name];
123
+ if (alwaysReason !== undefined) {
124
+ ctx.report(elementPath, name, "left-out", alwaysReason, ALWAYS_REPORTED_NOTES[name]);
125
+ return nothing;
126
+ }
127
+ if (DEFINITION_ELEMENTS.has(name))
128
+ return nothing;
129
+ const viewport = ctx.viewport;
130
+ const cascaded = computeElementStyle(element, parentStyle, ctx.rules, viewport);
131
+ // Inside a <clipPath>, clip-rule and not fill-rule decides which regions a shape covers.
132
+ const computed = ctx.insideClipPath === true ? { ...cascaded, fillRule: cascaded.clipRule } : cascaded;
133
+ if (computed.display === "none") {
134
+ ctx.report(elementPath, name, "left-out", "display:none", { what: "Hidden elements (display:none)", kept: "Not drawn" });
135
+ return nothing;
136
+ }
137
+ const targetId = elementId(element);
138
+ if (targetId !== null && ctx.buildingComponentTree !== true && ctx.insideClipPath !== true
139
+ && ctx.reuse.targets.get(targetId) === element
140
+ && ctx.reuse.decisions.get(targetId) === "component") {
141
+ // A component target drawn in place becomes an instance in place. The
142
+ // component holds the element's own transform, opacity and effects, so
143
+ // the instance is placed in the parent's space and not wrapped again.
144
+ // Inside a clipPath it is drawn plainly, so the clip can force it opaque.
145
+ const inPlace = drawnTargetLayer(element, targetId, parentStyle, parentMatrix, elementPath, ctx);
146
+ if (inPlace !== null)
147
+ return inPlace;
148
+ }
149
+ const transformText = computed.cssTransformWins ? null : attr(element, "transform");
150
+ let matrix = parentMatrix;
151
+ if (transformText !== null) {
152
+ const parsed = parseTransform(transformText);
153
+ if (parsed === null) {
154
+ // An invalid transform attribute is ignored, as a browser ignores it:
155
+ // the element draws untransformed.
156
+ ctx.report(elementPath, name, "left-out", `the transform "${transformText}" cannot be read, so it is ignored`, { what: "Transforms that cannot be read", kept: "Drawn without the transform" });
157
+ }
158
+ else {
159
+ matrix = multiplyTransforms(parentMatrix, parsed);
160
+ }
161
+ }
162
+ const built = buildRawElement(element, computed, matrix, elementPath, ctx);
163
+ reportMarkers(element, computed, elementPath, ctx);
164
+ const wrapped = applyClipMaskFilter(element, computed, matrix, elementPath, built, ctx);
165
+ sweepUnprocessedChildren(element, elementPath, ctx);
166
+ return wrapped;
167
+ }
168
+ /** The elements markers draw on (SVG 2 §11.6, markable elements). */
169
+ const MARKABLE = new Set(["path", "line", "polyline", "polygon"]);
170
+ /** Lists the markers a markable shape names: the model has none, so they are not drawn. */
171
+ function reportMarkers(element, computed, elementPath, ctx) {
172
+ if (!MARKABLE.has(element.localName))
173
+ return;
174
+ const named = [["marker-start", computed.markerStart], ["marker-mid", computed.markerMid], ["marker-end", computed.markerEnd]]
175
+ .filter(([, reference]) => reference !== null)
176
+ .map(([property]) => property);
177
+ if (named.length === 0)
178
+ return;
179
+ ctx.report(elementPath, element.localName, "left-out", `markers are not supported: ${named.join(", ")} ${named.length === 1 ? "is" : "are"} not drawn`, ALWAYS_REPORTED_NOTES["marker"]);
180
+ }
181
+ /** The elements whose children are walked (or deliberately not) elsewhere. */
182
+ const CHILDREN_HANDLED = new Set([
183
+ "a", "g", "svg", "defs", "symbol", "clipPath", "mask", "filter", "pattern",
184
+ "linearGradient", "radialGradient", "marker", "foreignObject", "script", "style",
185
+ ]);
186
+ /** Elements inside `<text>` that its own builder reads. */
187
+ const TEXT_INLINE = new Set(["tspan", "a", "textPath"]);
188
+ /**
189
+ * Reports the children a builder never looked at — animation, scripts and
190
+ * anything else hiding inside a leaf element — so nothing is dropped
191
+ * silently. Recursion covers nesting inside the swept elements.
192
+ */
193
+ function sweepUnprocessedChildren(element, elementPath, ctx) {
194
+ const name = element.localName;
195
+ if (CHILDREN_HANDLED.has(name))
196
+ return;
197
+ for (const child of childElements(element)) {
198
+ if (name === "text" && TEXT_INLINE.has(child.localName) && isSvgElement(child))
199
+ continue;
200
+ sweep(child, `${elementPath} > ${pathStep(child, sameTagIndex(element, child))}`, ctx);
201
+ }
202
+ }
203
+ /** One recursive step of the sweep. */
204
+ function sweep(element, elementPath, ctx) {
205
+ const reason = ALWAYS_REPORTED[element.localName];
206
+ if (!isSvgElement(element)) {
207
+ ctx.report(elementPath, element.localName, "left-out", foreignReason(element), FOREIGN_NOTE);
208
+ }
209
+ else if (reason !== undefined) {
210
+ ctx.report(elementPath, element.localName, "left-out", reason, ALWAYS_REPORTED_NOTES[element.localName]);
211
+ }
212
+ else if (DEFINITION_ELEMENTS.has(element.localName)) {
213
+ // Structural metadata (title, desc, style and friends): not layers, not reported.
214
+ }
215
+ else {
216
+ ctx.report(elementPath, element.localName, "left-out", `<${element.localName}> is not supported here`, UNSUPPORTED_NOTE);
217
+ }
218
+ for (const child of childElements(element)) {
219
+ sweep(child, `${elementPath} > ${pathStep(child, sameTagIndex(element, child))}`, ctx);
220
+ }
221
+ }
222
+ /** Builds one element's own layers, before clip, mask and filter wrapping. */
223
+ function buildRawElement(element, computed, matrix, elementPath, ctx) {
224
+ const nothing = { top: null, nodes: [] };
225
+ const name = element.localName;
226
+ switch (name) {
227
+ case "g":
228
+ // A link draws its content like a group (SVG 2, <a>); only the
229
+ // hyperlink is interaction, which the model has no concept of, so
230
+ // nothing is reported.
231
+ case "a":
232
+ return groupLayer(element, computed, matrix, elementPath, ctx);
233
+ case "rect":
234
+ case "circle":
235
+ case "ellipse":
236
+ case "line":
237
+ case "polyline":
238
+ case "polygon": {
239
+ const node = shapeLayer(element, computed, matrix, elementPath, ctx);
240
+ if (node === null)
241
+ return nothing;
242
+ return { top: node, nodes: [node] };
243
+ }
244
+ case "path": {
245
+ const data = attr(element, "d");
246
+ if (data === null) {
247
+ ctx.report(elementPath, name, "left-out", "the path has no d attribute", { what: "Paths without data", kept: "Not drawn" });
248
+ return nothing;
249
+ }
250
+ const placement = layerPlacement(matrix);
251
+ if (placement === null) {
252
+ ctx.report(elementPath, name, "left-out", "the transform is not invertible", BAD_TRANSFORM_NOTE);
253
+ return nothing;
254
+ }
255
+ const built = pathLayerFromData(ctx.idSource(), elementId(element) ?? "Vector", data, computed, placement, elementPath, element, ctx);
256
+ if (built === null)
257
+ return nothing;
258
+ return { top: built.node, nodes: [built.node] };
259
+ }
260
+ case "text": {
261
+ const placement = layerPlacement(matrix);
262
+ if (placement === null) {
263
+ ctx.report(elementPath, name, "left-out", "the transform is not invertible", BAD_TRANSFORM_NOTE);
264
+ return nothing;
265
+ }
266
+ const built = textLayer(element, computed, matrix, placement, elementPath, ctx);
267
+ if (built === null)
268
+ return nothing;
269
+ return { top: built.top, nodes: built.nodes };
270
+ }
271
+ case "image":
272
+ return imageLayer(element, computed, matrix, elementPath, ctx);
273
+ case "use":
274
+ return useLayer(element, computed, matrix, elementPath, ctx);
275
+ case "svg":
276
+ return viewportLayer(element, computed, matrix, elementPath, ctx);
277
+ case "switch":
278
+ ctx.report(elementPath, name, "left-out", "<switch> is not supported", UNSUPPORTED_NOTE);
279
+ return nothing;
280
+ default:
281
+ ctx.report(elementPath, name, "left-out", `<${name}> is not supported`, UNSUPPORTED_NOTE);
282
+ return nothing;
283
+ }
284
+ }
285
+ /** Places the viewport as a clipping frame and maps children into its local coordinates. */
286
+ function viewportLayer(element, computed, matrix, path, ctx) {
287
+ const { viewport } = ctx;
288
+ const fonts = { fontSize: computed.fontSize, rootFontSize: ctx.rules.rootFontSize };
289
+ const x = lengthAttr(element, "x", fonts, viewport?.width ?? null) ?? 0;
290
+ const y = lengthAttr(element, "y", fonts, viewport?.height ?? null) ?? 0;
291
+ const width = lengthAttr(element, "width", fonts, viewport?.width ?? null) ?? viewport?.width ?? 0;
292
+ const height = lengthAttr(element, "height", fonts, viewport?.height ?? null) ?? viewport?.height ?? 0;
293
+ const viewBox = parseViewBox(attr(element, "viewBox") ?? "");
294
+ if (width <= 0 || height <= 0 || (viewBox && (viewBox.width <= 0 || viewBox.height <= 0)))
295
+ return { top: null, nodes: [] };
296
+ const plan = rasterFramePlan({ x, y, width, height }, matrix);
297
+ const placed = multiplyTransforms(matrix, [1, 0, 0, 1, x, y]);
298
+ const skew = plan === null ? layerPlacement(placed) : null;
299
+ if (plan === null && skew === null) {
300
+ ctx.report(path, "svg", "left-out", "the viewport transform cannot be inverted", BAD_TRANSFORM_NOTE);
301
+ return { top: null, nodes: [] };
302
+ }
303
+ const corners = [[0, 0], [width, 0], [width, height], [0, height]];
304
+ const bounds = plan?.frame ?? unionBoxes(corners.map(([px, py]) => {
305
+ const point = applyMatrixToPoint(placed, px, py);
306
+ return { ...point, width: 0, height: 0 };
307
+ }));
308
+ const chrome = layerChrome(computed);
309
+ const frame = {
310
+ id: ctx.idSource(),
311
+ type: "frame",
312
+ name: elementId(element) ?? "SVG",
313
+ visible: chrome.visible,
314
+ locked: false,
315
+ opacity: chrome.opacity,
316
+ ...(chrome.blendMode === null ? {} : { blendMode: chrome.blendMode }),
317
+ frame: bounds,
318
+ rotation: plan?.rotation ?? 0,
319
+ children: [],
320
+ layout: { kind: "absolute" },
321
+ clipContent: true,
322
+ };
323
+ const local = multiplyTransforms(invertMatrix(nodeLocalTransform(frame)), placed);
324
+ const deferred = skew !== null || plan?.flipY === true;
325
+ const aspect = parsePreserveAspectRatio(attr(element, "preserveAspectRatio") ?? "") ?? DEFAULT_PRESERVE_ASPECT_RATIO;
326
+ const view = viewBox ? viewBoxTransform(viewBox, width, height, aspect) : IDENTITY_MATRIX;
327
+ // Read children in viewport space before the adapter transforms their geometry. A walker given a skew would drop
328
+ // layers such as raster images and reused components even though the destination supports their affine transforms.
329
+ const childMatrix = deferred ? view : multiplyTransforms(local, view);
330
+ const { children, nodes } = buildChildren(element, computed, childMatrix, path, { ...ctx, viewport: viewBox ?? { width, height } });
331
+ if (skew && children.length) {
332
+ // The viewport's box is axis-aligned. The actual skewed clip is a vector mask inside it.
333
+ const outline = `M0 0H${width}V${height}H0Z`;
334
+ const clip = pathLayerFromData(ctx.idSource(), "Viewport clip", outline, initialComputedStyle(), layerPlacement(IDENTITY_MATRIX), path, element, ctx);
335
+ const mask = { ...clip.node, mask: true };
336
+ children.unshift(mask);
337
+ nodes.unshift(mask);
338
+ }
339
+ const top = { ...frame, children: children.map((child) => child.id), ...(deferred && { metadata: { svgViewportTransform: local } }) };
340
+ return { top, nodes: [top, ...nodes] };
341
+ }
342
+ /** Whether a child is axis-aligned, as auto layout detection requires. */
343
+ function childIsAxisAligned(node) {
344
+ if (node.mask === true)
345
+ return false;
346
+ if (node.type === "shape" && node.shape === "path") {
347
+ const [a, b, c, d] = node.transform;
348
+ return Math.abs(a - 1) < 1e-9 && Math.abs(b) < 1e-9 && Math.abs(c) < 1e-9 && Math.abs(d - 1) < 1e-9;
349
+ }
350
+ if ("rotation" in node) {
351
+ return Math.abs(node.rotation) < 1e-9 && node.flipX !== true && node.flipY !== true;
352
+ }
353
+ return false;
354
+ }
355
+ /** The shared edge of a set of children on the cross axis, within 0.5 px. */
356
+ function sharedCrossEdge(boxes, axis) {
357
+ const edges = boxes.map((box) => {
358
+ const start = axis === "horizontal" ? box.y : box.x;
359
+ const size = axis === "horizontal" ? box.height : box.width;
360
+ return { start, center: start + size / 2, end: start + size };
361
+ });
362
+ const first = edges[0];
363
+ const close = (a, b) => Math.abs(a - b) <= 0.5;
364
+ if (edges.every((edge) => close(edge.start, first.start)))
365
+ return "start";
366
+ if (edges.every((edge) => close(edge.center, first.center)))
367
+ return "center";
368
+ if (edges.every((edge) => close(edge.end, first.end)))
369
+ return "end";
370
+ return null;
371
+ }
372
+ /**
373
+ * Whether the children of a `<g>` are spaced evenly, per the spec: at least
374
+ * three visible, axis-aligned children with no masks or clips; on one axis
375
+ * their boxes do not overlap and the gaps are equal within 0.5 px; on the
376
+ * other axis they share a start, center or end edge. Detection never moves
377
+ * a child more than 0.5 px.
378
+ */
379
+ export function detectAutoLayout(children, boxes) {
380
+ const visible = children
381
+ .map((node, index) => ({ node, box: boxes[index] }))
382
+ .filter((entry) => entry.node.visible !== false);
383
+ if (visible.length < 3)
384
+ return null;
385
+ if (!visible.every((entry) => childIsAxisAligned(entry.node)))
386
+ return null;
387
+ for (const direction of ["horizontal", "vertical"]) {
388
+ const sorted = [...visible].sort((left, right) => (direction === "horizontal" ? left.box.x - right.box.x : left.box.y - right.box.y));
389
+ const inDocumentOrder = sorted.every((entry, index) => entry === visible[index]);
390
+ if (!inDocumentOrder)
391
+ continue;
392
+ let overlaps = false;
393
+ let minGap = Infinity;
394
+ let maxGap = -Infinity;
395
+ for (let index = 1; index < sorted.length; index += 1) {
396
+ const previous = sorted[index - 1].box;
397
+ const current = sorted[index].box;
398
+ const previousEnd = direction === "horizontal" ? previous.x + previous.width : previous.y + previous.height;
399
+ const gap = (direction === "horizontal" ? current.x : current.y) - previousEnd;
400
+ if (gap < -0.5) {
401
+ overlaps = true;
402
+ break;
403
+ }
404
+ minGap = Math.min(minGap, gap);
405
+ maxGap = Math.max(maxGap, gap);
406
+ }
407
+ if (overlaps || maxGap - minGap > 0.5)
408
+ continue;
409
+ const align = sharedCrossEdge(sorted.map((entry) => entry.box), direction);
410
+ if (align === null)
411
+ continue;
412
+ const gap = (minGap + maxGap) / 2;
413
+ // Detection never moves a child: the layout's positions must match the
414
+ // drawn ones within 0.5 px on both axes.
415
+ let cursor = direction === "horizontal" ? sorted[0].box.x : sorted[0].box.y;
416
+ let moves = false;
417
+ for (const entry of sorted) {
418
+ const start = direction === "horizontal" ? entry.box.x : entry.box.y;
419
+ if (Math.abs(start - cursor) > 0.5) {
420
+ moves = true;
421
+ break;
422
+ }
423
+ cursor = start + (direction === "horizontal" ? entry.box.width : entry.box.height) + gap;
424
+ }
425
+ if (moves)
426
+ continue;
427
+ return { direction, gap, align };
428
+ }
429
+ return null;
430
+ }
431
+ /** Shifts one node by a delta, in place in its parent's coordinate space. */
432
+ export function shiftNode(node, dx, dy) {
433
+ if (node.type === "shape" && node.shape === "path") {
434
+ const [a, b, c, d, e, f] = node.transform;
435
+ return { ...node, transform: [a, b, c, d, e + dx, f + dy] };
436
+ }
437
+ if ("frame" in node) {
438
+ return { ...node, frame: { ...node.frame, x: node.frame.x + dx, y: node.frame.y + dy } };
439
+ }
440
+ return node;
441
+ }
442
+ /** The union of boxes, or null for an empty list. */
443
+ export function unionBoxes(boxes) {
444
+ if (boxes.length === 0)
445
+ return null;
446
+ let minX = Infinity;
447
+ let minY = Infinity;
448
+ let maxX = -Infinity;
449
+ let maxY = -Infinity;
450
+ for (const box of boxes) {
451
+ minX = Math.min(minX, box.x);
452
+ minY = Math.min(minY, box.y);
453
+ maxX = Math.max(maxX, box.x + box.width);
454
+ maxY = Math.max(maxY, box.y + box.height);
455
+ }
456
+ return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
457
+ }
458
+ /** Builds a `<g>`: an auto layout frame when its children are evenly spaced, else a group. */
459
+ function groupLayer(element, computed, matrix, elementPath, ctx) {
460
+ const { children, nodes } = buildChildren(element, computed, matrix, elementPath, ctx);
461
+ const name = elementId(element) ?? "Group";
462
+ if (children.length === 0) {
463
+ ctx.report(elementPath, "g", "left-out", "the group has no visible children", { what: "Empty groups", kept: "Not added" });
464
+ return { top: null, nodes };
465
+ }
466
+ const boxes = children.map((child) => getNodeBounds(child));
467
+ const layout = detectAutoLayout(children, boxes);
468
+ // An auto layout frame lays out and hugs its visible children only: the
469
+ // model would give a hidden child a slot in the flow, so it is taken out
470
+ // of the flow at its drawn place, and the frame's box leaves it out.
471
+ const union = (layout === null
472
+ ? unionBoxes(boxes)
473
+ : unionBoxes(boxes.filter((_, index) => children[index].visible !== false)));
474
+ const chrome = layerChrome(computed);
475
+ const shifted = children.map((child) => {
476
+ const moved = shiftNode(child, -union.x, -union.y);
477
+ return layout !== null && child.visible === false ? { ...moved, layoutPositioning: "absolute" } : moved;
478
+ });
479
+ // The children the subtree built sit in the parent's coordinates; replace
480
+ // the top-level ones with their shifted copies so the group's local
481
+ // coordinates start at its own origin.
482
+ const shiftedById = new Map(shifted.map((child) => [child.id, child]));
483
+ const relinked = nodes.map((entry) => shiftedById.get(entry.id) ?? entry);
484
+ // Visibility is inherited and a child may set it back to visible, so the
485
+ // group stays visible and each drawn layer carries its own computed value.
486
+ const chromeFields = {
487
+ visible: true,
488
+ locked: false,
489
+ opacity: chrome.opacity,
490
+ ...(chrome.blendMode === null ? {} : { blendMode: chrome.blendMode }),
491
+ };
492
+ if (layout !== null) {
493
+ const node = {
494
+ id: ctx.idSource(),
495
+ name,
496
+ ...chromeFields,
497
+ type: "frame",
498
+ frame: { x: union.x, y: union.y, width: union.width, height: union.height },
499
+ rotation: 0,
500
+ children: shifted.map((child) => child.id),
501
+ layout: {
502
+ kind: layout.direction,
503
+ widthSizing: "hug",
504
+ heightSizing: "hug",
505
+ gap: layout.gap,
506
+ padding: { top: 0, right: 0, bottom: 0, left: 0 },
507
+ align: layout.align,
508
+ justify: "start",
509
+ },
510
+ };
511
+ ctx.report(elementPath, "g", "auto-layout", `evenly spaced children became a ${layout.direction} auto layout frame`, { what: "Evenly spaced groups", kept: "Became auto layout frames" });
512
+ return { top: node, nodes: [node, ...relinked] };
513
+ }
514
+ const node = {
515
+ id: ctx.idSource(),
516
+ name,
517
+ ...chromeFields,
518
+ type: "group",
519
+ frame: { x: union.x, y: union.y, width: union.width, height: union.height },
520
+ rotation: 0,
521
+ children: shifted.map((child) => child.id),
522
+ };
523
+ return { top: node, nodes: [node, ...relinked] };
524
+ }
525
+ /** Creates a group around already-built layers (clip and mask groups use this). */
526
+ export function wrapInGroup(element, layers, name, ctx) {
527
+ const boxes = layers.map((layer) => getNodeBounds(layer));
528
+ const union = unionBoxes(boxes);
529
+ const shifted = layers.map((layer) => shiftNode(layer, -union.x, -union.y));
530
+ return {
531
+ group: {
532
+ id: ctx.idSource(),
533
+ name,
534
+ visible: true,
535
+ locked: false,
536
+ opacity: 1,
537
+ type: "group",
538
+ frame: { x: union.x, y: union.y, width: union.width, height: union.height },
539
+ rotation: 0,
540
+ children: shifted.map((layer) => layer.id),
541
+ },
542
+ shifted,
543
+ };
544
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * SVG/CSS color parsing for paint attributes: hex, `rgb()`/`rgba()`,
3
+ * `hsl()`/`hsla()`, the CSS named colors, `currentColor` and `none`.
4
+ * Parsing never throws: text this file does not understand parses to null
5
+ * and the caller reports it. No dates, randomness or globals: the same
6
+ * input always parses to the same color.
7
+ */
8
+ /** Red, green and blue as 0–255, alpha as 0–1. */
9
+ export interface Rgba {
10
+ readonly r: number;
11
+ readonly g: number;
12
+ readonly b: number;
13
+ readonly a: number;
14
+ }
15
+ /** A parsed SVG paint color: an actual color, `currentColor`, or `none`. */
16
+ export type SvgColor = {
17
+ readonly kind: "color";
18
+ readonly value: Rgba;
19
+ } | {
20
+ readonly kind: "currentColor";
21
+ } | {
22
+ readonly kind: "none";
23
+ };
24
+ /**
25
+ * Parses an SVG/CSS color. Returns null when the text is not a color this
26
+ * package understands (the caller reports that; nothing is guessed).
27
+ * Keywords are ASCII case-insensitive; surrounding whitespace is ignored.
28
+ */
29
+ export declare function parseSvgColor(text: string): SvgColor | null;
30
+ /** "#RRGGBB", or "#RRGGBBAA" when the alpha is below 1. */
31
+ export declare function hexColor(rgba: Rgba): string;
32
+ /**
33
+ * "#RRGGBB" plus a separate opacity: undefined when the alpha is 1. Solid
34
+ * paints in the model carry their alpha as a paint opacity, so callers emit
35
+ * the color and the opacity separately.
36
+ */
37
+ export declare function hexColorAndOpacity(rgba: Rgba): {
38
+ readonly color: string;
39
+ readonly opacity: number | undefined;
40
+ };