@moondraft/import 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (337) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +34 -0
  3. package/README.md +36 -2
  4. package/SOURCE.md +394 -0
  5. package/dist/adapter/convert.d.ts +144 -0
  6. package/dist/adapter/convert.js +2811 -0
  7. package/dist/adapter/figma-descriptions.d.ts +7 -0
  8. package/dist/adapter/figma-descriptions.js +34 -0
  9. package/dist/adapter/figma-grids.d.ts +12 -0
  10. package/dist/adapter/figma-grids.js +175 -0
  11. package/dist/adapter/figma-handoff.d.ts +12 -0
  12. package/dist/adapter/figma-handoff.js +167 -0
  13. package/dist/adapter/figma-hyperlinks.d.ts +13 -0
  14. package/dist/adapter/figma-hyperlinks.js +77 -0
  15. package/dist/adapter/figma.d.ts +12 -0
  16. package/dist/adapter/figma.js +40 -0
  17. package/dist/adapter/file-components.d.ts +20 -0
  18. package/dist/adapter/file-components.js +352 -0
  19. package/dist/adapter/file-resources.d.ts +29 -0
  20. package/dist/adapter/file-resources.js +851 -0
  21. package/dist/adapter/image-crop.d.ts +18 -0
  22. package/dist/adapter/image-crop.js +30 -0
  23. package/dist/adapter/index.d.ts +6 -0
  24. package/dist/adapter/index.js +9 -0
  25. package/dist/adapter/link.d.ts +49 -0
  26. package/dist/adapter/link.js +892 -0
  27. package/dist/adapter/payload.d.ts +31 -0
  28. package/dist/adapter/payload.js +78 -0
  29. package/dist/adapter/shapes.d.ts +31 -0
  30. package/dist/adapter/shapes.js +75 -0
  31. package/dist/adapter/variables.d.ts +45 -0
  32. package/dist/adapter/variables.js +106 -0
  33. package/dist/figma-file.d.ts +38 -0
  34. package/dist/figma-file.js +97 -0
  35. package/dist/figma-worker.d.ts +11 -0
  36. package/dist/figma-worker.js +12 -0
  37. package/dist/figma.d.ts +26 -0
  38. package/dist/figma.js +230 -0
  39. package/dist/index.d.ts +29 -0
  40. package/dist/index.js +50 -0
  41. package/dist/report.d.ts +42 -0
  42. package/dist/report.js +142 -0
  43. package/dist/serialize.d.ts +7 -0
  44. package/dist/serialize.js +79 -0
  45. package/dist/svg.d.ts +33 -0
  46. package/dist/svg.js +44 -0
  47. package/dist/syntax.d.ts +8 -0
  48. package/dist/syntax.js +19 -0
  49. package/dist/taco/figma-import/clipboard.d.ts +25 -0
  50. package/dist/taco/figma-import/clipboard.js +87 -0
  51. package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
  52. package/dist/taco/figma-import/clipboardSize.js +107 -0
  53. package/dist/taco/figma-import/container/compression.d.ts +9 -0
  54. package/dist/taco/figma-import/container/compression.js +174 -0
  55. package/dist/taco/figma-import/container/error.d.ts +15 -0
  56. package/dist/taco/figma-import/container/error.js +19 -0
  57. package/dist/taco/figma-import/container/kiwiContainer.d.ts +41 -0
  58. package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
  59. package/dist/taco/figma-import/container/limits.d.ts +22 -0
  60. package/dist/taco/figma-import/container/limits.js +22 -0
  61. package/dist/taco/figma-import/container/zip.d.ts +14 -0
  62. package/dist/taco/figma-import/container/zip.js +154 -0
  63. package/dist/taco/figma-import/figFile.d.ts +34 -0
  64. package/dist/taco/figma-import/figFile.js +91 -0
  65. package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
  66. package/dist/taco/figma-import/figFileDocument.js +100 -0
  67. package/dist/taco/figma-import/import/blobs.d.ts +10 -0
  68. package/dist/taco/figma-import/import/blobs.js +23 -0
  69. package/dist/taco/figma-import/import/carry.d.ts +24 -0
  70. package/dist/taco/figma-import/import/carry.js +66 -0
  71. package/dist/taco/figma-import/import/componentProps.d.ts +90 -0
  72. package/dist/taco/figma-import/import/componentProps.js +329 -0
  73. package/dist/taco/figma-import/import/componentSets.d.ts +85 -0
  74. package/dist/taco/figma-import/import/componentSets.js +647 -0
  75. package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
  76. package/dist/taco/figma-import/import/converters/effects.js +127 -0
  77. package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
  78. package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
  79. package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
  80. package/dist/taco/figma-import/import/converters/exportSettings.js +49 -0
  81. package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
  82. package/dist/taco/figma-import/import/converters/frame.js +63 -0
  83. package/dist/taco/figma-import/import/converters/gradient.d.ts +74 -0
  84. package/dist/taco/figma-import/import/converters/gradient.js +108 -0
  85. package/dist/taco/figma-import/import/converters/group.d.ts +19 -0
  86. package/dist/taco/figma-import/import/converters/group.js +30 -0
  87. package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
  88. package/dist/taco/figma-import/import/converters/image.js +94 -0
  89. package/dist/taco/figma-import/import/converters/layout.d.ts +33 -0
  90. package/dist/taco/figma-import/import/converters/layout.js +187 -0
  91. package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
  92. package/dist/taco/figma-import/import/converters/line.js +40 -0
  93. package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
  94. package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
  95. package/dist/taco/figma-import/import/converters/section.d.ts +8 -0
  96. package/dist/taco/figma-import/import/converters/section.js +29 -0
  97. package/dist/taco/figma-import/import/converters/shared.d.ts +71 -0
  98. package/dist/taco/figma-import/import/converters/shared.js +372 -0
  99. package/dist/taco/figma-import/import/converters/text.d.ts +54 -0
  100. package/dist/taco/figma-import/import/converters/text.js +707 -0
  101. package/dist/taco/figma-import/import/converters/vector.d.ts +105 -0
  102. package/dist/taco/figma-import/import/converters/vector.js +609 -0
  103. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +114 -0
  104. package/dist/taco/figma-import/import/converters/vectorNetwork.js +503 -0
  105. package/dist/taco/figma-import/import/fields.d.ts +15 -0
  106. package/dist/taco/figma-import/import/fields.js +29 -0
  107. package/dist/taco/figma-import/import/instances.d.ts +184 -0
  108. package/dist/taco/figma-import/import/instances.js +1530 -0
  109. package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
  110. package/dist/taco/figma-import/import/nestingCycles.js +488 -0
  111. package/dist/taco/figma-import/import/slots.d.ts +56 -0
  112. package/dist/taco/figma-import/import/slots.js +96 -0
  113. package/dist/taco/figma-import/import/styles.d.ts +48 -0
  114. package/dist/taco/figma-import/import/styles.js +48 -0
  115. package/dist/taco/figma-import/import/tree.d.ts +66 -0
  116. package/dist/taco/figma-import/import/tree.js +194 -0
  117. package/dist/taco/figma-import/import/types.d.ts +232 -0
  118. package/dist/taco/figma-import/import/types.js +33 -0
  119. package/dist/taco/figma-import/import/variables.d.ts +137 -0
  120. package/dist/taco/figma-import/import/variables.js +769 -0
  121. package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
  122. package/dist/taco/figma-import/import/variantTrees.js +520 -0
  123. package/dist/taco/figma-import/import/walk.d.ts +207 -0
  124. package/dist/taco/figma-import/import/walk.js +1464 -0
  125. package/dist/taco/figma-import/index.d.ts +22 -0
  126. package/dist/taco/figma-import/index.js +13 -0
  127. package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
  128. package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
  129. package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
  130. package/dist/taco/figma-import/kiwi/error.js +29 -0
  131. package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
  132. package/dist/taco/figma-import/kiwi/limits.js +18 -0
  133. package/dist/taco/figma-import/kiwi/message.d.ts +12 -0
  134. package/dist/taco/figma-import/kiwi/message.js +147 -0
  135. package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
  136. package/dist/taco/figma-import/kiwi/schema.js +206 -0
  137. package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
  138. package/dist/taco/figma-import/kiwi/types.js +18 -0
  139. package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
  140. package/dist/taco/model/agent-hidden-fields.js +29 -0
  141. package/dist/taco/model/asset-users.d.ts +23 -0
  142. package/dist/taco/model/asset-users.js +128 -0
  143. package/dist/taco/model/auto-layout-lines.d.ts +32 -0
  144. package/dist/taco/model/auto-layout-lines.js +70 -0
  145. package/dist/taco/model/codec.d.ts +444 -0
  146. package/dist/taco/model/codec.js +5665 -0
  147. package/dist/taco/model/color.d.ts +11 -0
  148. package/dist/taco/model/color.js +61 -0
  149. package/dist/taco/model/comment-operations.d.ts +102 -0
  150. package/dist/taco/model/comment-operations.js +227 -0
  151. package/dist/taco/model/component-evaluation.d.ts +96 -0
  152. package/dist/taco/model/component-evaluation.js +555 -0
  153. package/dist/taco/model/component-expressions.d.ts +242 -0
  154. package/dist/taco/model/component-expressions.js +1082 -0
  155. package/dist/taco/model/component-properties.d.ts +111 -0
  156. package/dist/taco/model/component-properties.js +339 -0
  157. package/dist/taco/model/component-samples.d.ts +83 -0
  158. package/dist/taco/model/component-samples.js +290 -0
  159. package/dist/taco/model/component-validity.d.ts +85 -0
  160. package/dist/taco/model/component-validity.js +397 -0
  161. package/dist/taco/model/components.d.ts +155 -0
  162. package/dist/taco/model/components.js +505 -0
  163. package/dist/taco/model/connector-ends.d.ts +20 -0
  164. package/dist/taco/model/connector-ends.js +188 -0
  165. package/dist/taco/model/connector-geometry.d.ts +74 -0
  166. package/dist/taco/model/connector-geometry.js +293 -0
  167. package/dist/taco/model/corner-radii.d.ts +26 -0
  168. package/dist/taco/model/corner-radii.js +47 -0
  169. package/dist/taco/model/derivations.d.ts +81 -0
  170. package/dist/taco/model/derivations.js +151 -0
  171. package/dist/taco/model/export-settings.d.ts +53 -0
  172. package/dist/taco/model/export-settings.js +156 -0
  173. package/dist/taco/model/expressions/ast.d.ts +153 -0
  174. package/dist/taco/model/expressions/ast.js +6 -0
  175. package/dist/taco/model/expressions/cache.d.ts +23 -0
  176. package/dist/taco/model/expressions/cache.js +43 -0
  177. package/dist/taco/model/expressions/check.d.ts +72 -0
  178. package/dist/taco/model/expressions/check.js +517 -0
  179. package/dist/taco/model/expressions/completion.d.ts +61 -0
  180. package/dist/taco/model/expressions/completion.js +421 -0
  181. package/dist/taco/model/expressions/evaluate.d.ts +32 -0
  182. package/dist/taco/model/expressions/evaluate.js +519 -0
  183. package/dist/taco/model/expressions/forms.d.ts +84 -0
  184. package/dist/taco/model/expressions/forms.js +200 -0
  185. package/dist/taco/model/expressions/index.d.ts +14 -0
  186. package/dist/taco/model/expressions/index.js +17 -0
  187. package/dist/taco/model/expressions/lexer.d.ts +42 -0
  188. package/dist/taco/model/expressions/lexer.js +213 -0
  189. package/dist/taco/model/expressions/library.d.ts +33 -0
  190. package/dist/taco/model/expressions/library.js +117 -0
  191. package/dist/taco/model/expressions/names.d.ts +43 -0
  192. package/dist/taco/model/expressions/names.js +99 -0
  193. package/dist/taco/model/expressions/parser.d.ts +15 -0
  194. package/dist/taco/model/expressions/parser.js +438 -0
  195. package/dist/taco/model/expressions/rename.d.ts +34 -0
  196. package/dist/taco/model/expressions/rename.js +46 -0
  197. package/dist/taco/model/expressions/source.d.ts +15 -0
  198. package/dist/taco/model/expressions/source.js +161 -0
  199. package/dist/taco/model/expressions/types.d.ts +119 -0
  200. package/dist/taco/model/expressions/types.js +102 -0
  201. package/dist/taco/model/expressions/values.d.ts +97 -0
  202. package/dist/taco/model/expressions/values.js +160 -0
  203. package/dist/taco/model/geometry-limits.d.ts +16 -0
  204. package/dist/taco/model/geometry-limits.js +67 -0
  205. package/dist/taco/model/geometry.d.ts +47 -0
  206. package/dist/taco/model/geometry.js +193 -0
  207. package/dist/taco/model/group-bounds.d.ts +38 -0
  208. package/dist/taco/model/group-bounds.js +144 -0
  209. package/dist/taco/model/id-table.d.ts +37 -0
  210. package/dist/taco/model/id-table.js +80 -0
  211. package/dist/taco/model/index.d.ts +25 -0
  212. package/dist/taco/model/index.js +27 -0
  213. package/dist/taco/model/instance-resolver.d.ts +376 -0
  214. package/dist/taco/model/instance-resolver.js +1778 -0
  215. package/dist/taco/model/layer-syntax.d.ts +340 -0
  216. package/dist/taco/model/layer-syntax.js +3506 -0
  217. package/dist/taco/model/layout/constraints.d.ts +84 -0
  218. package/dist/taco/model/layout/constraints.js +445 -0
  219. package/dist/taco/model/layout/frame-layout.d.ts +46 -0
  220. package/dist/taco/model/layout/frame-layout.js +618 -0
  221. package/dist/taco/model/layout/node-sizing.d.ts +163 -0
  222. package/dist/taco/model/layout/node-sizing.js +486 -0
  223. package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
  224. package/dist/taco/model/legacy-connector-caps.js +70 -0
  225. package/dist/taco/model/linear-call.d.ts +48 -0
  226. package/dist/taco/model/linear-call.js +58 -0
  227. package/dist/taco/model/new-nodes.d.ts +145 -0
  228. package/dist/taco/model/new-nodes.js +277 -0
  229. package/dist/taco/model/node-builder.d.ts +449 -0
  230. package/dist/taco/model/node-builder.js +2294 -0
  231. package/dist/taco/model/node-table-watch.d.ts +36 -0
  232. package/dist/taco/model/node-table-watch.js +63 -0
  233. package/dist/taco/model/node-transform.d.ts +39 -0
  234. package/dist/taco/model/node-transform.js +79 -0
  235. package/dist/taco/model/node-users-index.d.ts +10 -0
  236. package/dist/taco/model/node-users-index.js +82 -0
  237. package/dist/taco/model/operation-references.d.ts +80 -0
  238. package/dist/taco/model/operation-references.js +399 -0
  239. package/dist/taco/model/operations.d.ts +610 -0
  240. package/dist/taco/model/operations.js +2882 -0
  241. package/dist/taco/model/overlay-table.d.ts +71 -0
  242. package/dist/taco/model/overlay-table.js +171 -0
  243. package/dist/taco/model/override-remap.d.ts +69 -0
  244. package/dist/taco/model/override-remap.js +230 -0
  245. package/dist/taco/model/parent-table.d.ts +53 -0
  246. package/dist/taco/model/parent-table.js +193 -0
  247. package/dist/taco/model/problem-collector.d.ts +27 -0
  248. package/dist/taco/model/problem-collector.js +101 -0
  249. package/dist/taco/model/sha256.d.ts +10 -0
  250. package/dist/taco/model/sha256.js +79 -0
  251. package/dist/taco/model/shape-geometry.d.ts +96 -0
  252. package/dist/taco/model/shape-geometry.js +368 -0
  253. package/dist/taco/model/shared-node-table.d.ts +97 -0
  254. package/dist/taco/model/shared-node-table.js +546 -0
  255. package/dist/taco/model/slots.d.ts +113 -0
  256. package/dist/taco/model/slots.js +281 -0
  257. package/dist/taco/model/stroke-settings.d.ts +37 -0
  258. package/dist/taco/model/stroke-settings.js +90 -0
  259. package/dist/taco/model/svg-path-import.d.ts +89 -0
  260. package/dist/taco/model/svg-path-import.js +219 -0
  261. package/dist/taco/model/text-measurement.d.ts +142 -0
  262. package/dist/taco/model/text-measurement.js +846 -0
  263. package/dist/taco/model/text-reads.d.ts +66 -0
  264. package/dist/taco/model/text-reads.js +128 -0
  265. package/dist/taco/model/text-sizer.d.ts +358 -0
  266. package/dist/taco/model/text-sizer.js +996 -0
  267. package/dist/taco/model/theme-users.d.ts +59 -0
  268. package/dist/taco/model/theme-users.js +312 -0
  269. package/dist/taco/model/thumbnail.d.ts +15 -0
  270. package/dist/taco/model/thumbnail.js +34 -0
  271. package/dist/taco/model/types.d.ts +2369 -0
  272. package/dist/taco/model/types.js +366 -0
  273. package/dist/taco/model/unknown-property.d.ts +5 -0
  274. package/dist/taco/model/unknown-property.js +7 -0
  275. package/dist/taco/model/validated-documents.d.ts +22 -0
  276. package/dist/taco/model/validated-documents.js +22 -0
  277. package/dist/taco/model/variable-modes.d.ts +61 -0
  278. package/dist/taco/model/variable-modes.js +438 -0
  279. package/dist/taco/model/variable-references.d.ts +54 -0
  280. package/dist/taco/model/variable-references.js +183 -0
  281. package/dist/taco/model/variables.d.ts +24 -0
  282. package/dist/taco/model/variables.js +151 -0
  283. package/dist/taco/model/vector-network.d.ts +34 -0
  284. package/dist/taco/model/vector-network.js +411 -0
  285. package/dist/taco/svg-import/import-svg.d.ts +36 -0
  286. package/dist/taco/svg-import/import-svg.js +729 -0
  287. package/dist/taco/svg-import/index.d.ts +3 -0
  288. package/dist/taco/svg-import/index.js +3 -0
  289. package/dist/taco/svg-import/limits/limits.d.ts +79 -0
  290. package/dist/taco/svg-import/limits/limits.js +160 -0
  291. package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
  292. package/dist/taco/svg-import/paint/gradients.js +429 -0
  293. package/dist/taco/svg-import/paint/paint.d.ts +32 -0
  294. package/dist/taco/svg-import/paint/paint.js +162 -0
  295. package/dist/taco/svg-import/paths/paths.d.ts +58 -0
  296. package/dist/taco/svg-import/paths/paths.js +205 -0
  297. package/dist/taco/svg-import/public-types.d.ts +279 -0
  298. package/dist/taco/svg-import/public-types.js +56 -0
  299. package/dist/taco/svg-import/report/report.d.ts +44 -0
  300. package/dist/taco/svg-import/report/report.js +79 -0
  301. package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
  302. package/dist/taco/svg-import/reuse/reuse.js +840 -0
  303. package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
  304. package/dist/taco/svg-import/shapes/shapes.js +386 -0
  305. package/dist/taco/svg-import/structure/effects.d.ts +26 -0
  306. package/dist/taco/svg-import/structure/effects.js +618 -0
  307. package/dist/taco/svg-import/structure/image.d.ts +24 -0
  308. package/dist/taco/svg-import/structure/image.js +495 -0
  309. package/dist/taco/svg-import/structure/walk.d.ts +85 -0
  310. package/dist/taco/svg-import/structure/walk.js +544 -0
  311. package/dist/taco/svg-import/style/color.d.ts +40 -0
  312. package/dist/taco/svg-import/style/color.js +275 -0
  313. package/dist/taco/svg-import/style/computed.d.ts +214 -0
  314. package/dist/taco/svg-import/style/computed.js +1534 -0
  315. package/dist/taco/svg-import/style/css.d.ts +127 -0
  316. package/dist/taco/svg-import/style/css.js +541 -0
  317. package/dist/taco/svg-import/style/media.d.ts +25 -0
  318. package/dist/taco/svg-import/style/media.js +307 -0
  319. package/dist/taco/svg-import/style/properties.d.ts +43 -0
  320. package/dist/taco/svg-import/style/properties.js +135 -0
  321. package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
  322. package/dist/taco/svg-import/style/selector-reach.js +169 -0
  323. package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
  324. package/dist/taco/svg-import/style/selector-validity.js +307 -0
  325. package/dist/taco/svg-import/text/text.d.ts +29 -0
  326. package/dist/taco/svg-import/text/text.js +545 -0
  327. package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
  328. package/dist/taco/svg-import/transform/matrix.js +229 -0
  329. package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
  330. package/dist/taco/svg-import/tree/element-data.js +155 -0
  331. package/dist/taco/svg-import/tree/elements.d.ts +36 -0
  332. package/dist/taco/svg-import/tree/elements.js +121 -0
  333. package/dist/taco/svg-import/units/length.d.ts +43 -0
  334. package/dist/taco/svg-import/units/length.js +125 -0
  335. package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
  336. package/dist/taco/svg-import/units/viewbox.js +77 -0
  337. package/package.json +55 -4
@@ -0,0 +1,495 @@
1
+ import { multiplyTransforms, pathNodeFromSvgPath, transformIsInvertible, } from "../../model/index.js";
2
+ import { attr, hrefValue } from "../tree/elements.js";
3
+ import { parseSvgLength } from "../units/length.js";
4
+ import { parsePreserveAspectRatio } from "../units/viewbox.js";
5
+ import { matrixIsDegenerate, sameScale } from "../transform/matrix.js";
6
+ import { layerChrome } from "../paths/paths.js";
7
+ import { rasterFramePlan } from "../shapes/shapes.js";
8
+ const IMAGE_NO_SIZE_NOTE = { what: "Images without a size", kept: "Not drawn" };
9
+ const IMAGE_ALIGN_NOTE = { what: "Image alignment (preserveAspectRatio)", kept: "The image is centered" };
10
+ const NESTED_SVG_NOTE = { what: "SVG images inside the SVG", kept: "Not drawn" };
11
+ /**
12
+ * Decodes base64 without Buffer or atob, so the package runs in Node and in
13
+ * browsers. It follows the browser's forgiving decoder: ASCII whitespace is
14
+ * dropped, up to two "=" may end a body whose length is a multiple of four,
15
+ * and an unpadded body may end in a group of two or three characters.
16
+ */
17
+ function base64Decode(text) {
18
+ let clean = text.replace(/[\t\n\f\r ]+/g, "");
19
+ if (clean.length % 4 === 0)
20
+ clean = clean.replace(/={1,2}$/, "");
21
+ if (clean.length % 4 === 1 || !/^[A-Za-z0-9+/]*$/.test(clean))
22
+ return null;
23
+ const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
24
+ const bytes = new Uint8Array(Math.floor((clean.length * 6) / 8));
25
+ let buffer = 0;
26
+ let bits = 0;
27
+ let written = 0;
28
+ for (let index = 0; index < clean.length; index += 1) {
29
+ buffer = ((buffer << 6) | alphabet.indexOf(clean.charAt(index))) & 0xffffff;
30
+ bits += 6;
31
+ if (bits >= 8) {
32
+ bits -= 8;
33
+ bytes[written] = (buffer >> bits) & 0xff;
34
+ written += 1;
35
+ }
36
+ }
37
+ return bytes;
38
+ }
39
+ /**
40
+ * Decodes a base64 data URI body the way the Fetch standard's data URL
41
+ * processor does: percent-decode it first, so an escaped character such as
42
+ * a trailing `%3D` counts as written, then base64 decode the result. A
43
+ * percent-decoded byte outside ASCII is not base64, so the body is refused.
44
+ */
45
+ function base64DecodeBody(body) {
46
+ if (!body.includes("%"))
47
+ return base64Decode(body);
48
+ const bytes = percentDecodeBytes(body);
49
+ let text = "";
50
+ for (const byte of bytes) {
51
+ if (byte > 0x7f)
52
+ return null;
53
+ text += String.fromCharCode(byte);
54
+ }
55
+ return base64Decode(text);
56
+ }
57
+ /** Whether a URI is a `data:` URL; the scheme is ASCII case-insensitive. */
58
+ export function isDataUri(uri) {
59
+ return uri.slice(0, 5).toLowerCase() === "data:";
60
+ }
61
+ /**
62
+ * Splits a `data:` URL into its mime type, base64 flag and body. As in the
63
+ * Fetch standard, the scheme, the mime type and the `base64` flag are ASCII
64
+ * case-insensitive, so the mime type comes back in lower case. The flag
65
+ * counts only as the LAST metadata segment: a `;base64` earlier in the list
66
+ * is a plain parameter and the body is literal text (probed in Chromium,
67
+ * which also reads the flag with white space around it). The fragment is no
68
+ * part of the payload: it starts at the first `#` of the whole URL (URL
69
+ * standard), so a literal `#` ends the data — even inside the metadata,
70
+ * where it can eat the comma — while a percent-encoded %23 stays payload.
71
+ */
72
+ function splitDataUri(uri) {
73
+ if (!isDataUri(uri))
74
+ return null;
75
+ const fragment = uri.indexOf("#");
76
+ const whole = fragment === -1 ? uri : uri.slice(0, fragment);
77
+ const comma = whole.indexOf(",");
78
+ if (comma < 0)
79
+ return null;
80
+ const parts = whole.slice(5, comma).split(";").map((part) => part.trim().toLowerCase());
81
+ return { mimeType: parts[0] ?? "", base64: parts[parts.length - 1] === "base64", body: whole.slice(comma + 1) };
82
+ }
83
+ /** The lower-case mime type of a `data:` URL, or null for anything else. */
84
+ export function dataUriMimeType(uri) {
85
+ return splitDataUri(uri)?.mimeType ?? null;
86
+ }
87
+ /** Decodes a `data:` URI: base64 or percent-encoded. Returns null for anything else. */
88
+ export function decodeDataUri(uri) {
89
+ const split = splitDataUri(uri);
90
+ if (split === null || split.mimeType.length === 0)
91
+ return null;
92
+ const { mimeType, body } = split;
93
+ if (split.base64) {
94
+ const data = base64DecodeBody(body);
95
+ return data === null ? null : { mimeType, data };
96
+ }
97
+ return { mimeType, data: percentDecodeBytes(body) };
98
+ }
99
+ const HEX_PAIR = /^[0-9a-fA-F]{2}$/;
100
+ /**
101
+ * Percent-decodes a data URI body into bytes, as the URL standard does:
102
+ * each `%XX` escape is one raw byte (so a binary payload such as a PNG's
103
+ * `%89` comes through), other characters are UTF-8 encoded, and a `%`
104
+ * without two hex digits stays as written.
105
+ */
106
+ function percentDecodeBytes(body) {
107
+ const encoded = new TextEncoder().encode(body);
108
+ const bytes = new Uint8Array(encoded.length);
109
+ let length = 0;
110
+ for (let index = 0; index < encoded.length; index += 1) {
111
+ const byte = encoded[index];
112
+ if (byte === 0x25 && index + 2 < encoded.length && HEX_PAIR.test(String.fromCharCode(encoded[index + 1], encoded[index + 2]))) {
113
+ bytes[length] = Number.parseInt(String.fromCharCode(encoded[index + 1], encoded[index + 2]), 16);
114
+ index += 2;
115
+ }
116
+ else {
117
+ bytes[length] = byte;
118
+ }
119
+ length += 1;
120
+ }
121
+ return bytes.slice(0, length);
122
+ }
123
+ /** The encoding an XML declaration names, read as ASCII bytes, or undefined. */
124
+ function declaredSvgEncoding(bytes) {
125
+ let head = "";
126
+ const limit = Math.min(bytes.length, 1024);
127
+ for (let index = 0; index < limit; index += 1) {
128
+ const byte = bytes[index];
129
+ if (byte === 0x3e)
130
+ break; // ">" ends the declaration
131
+ if (byte > 0x7f)
132
+ return undefined; // not ASCII: no readable declaration
133
+ head += String.fromCharCode(byte);
134
+ }
135
+ const match = /^<\?xml\s[\s\S]*?\bencoding\s*=\s*["']([A-Za-z0-9._-]+)["']/.exec(head);
136
+ return match?.[1];
137
+ }
138
+ /**
139
+ * Decodes SVG bytes the way XML detects encodings (XML 1.0 §F): a byte order
140
+ * mark first (UTF-8, UTF-16 little or big endian), then the byte pattern of
141
+ * UTF-16 without a mark — "<" is 3C 00 or 00 3C — then the encoding the XML
142
+ * declaration names (its characters are ASCII in every encoding detected
143
+ * here), else UTF-8. A charset TextDecoder does not support falls back to a
144
+ * fatal UTF-8 read, and undecodable bytes give null, so a garbled payload is
145
+ * left out rather than imported as replacement characters.
146
+ */
147
+ function decodeSvgBytes(bytes) {
148
+ try {
149
+ if (bytes.length >= 3 && bytes[0] === 0xef && bytes[1] === 0xbb && bytes[2] === 0xbf) {
150
+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes.subarray(3));
151
+ }
152
+ if (bytes.length >= 2 && bytes[0] === 0xff && bytes[1] === 0xfe) {
153
+ return new TextDecoder("utf-16le", { fatal: true }).decode(bytes.subarray(2));
154
+ }
155
+ if (bytes.length >= 2 && bytes[0] === 0xfe && bytes[1] === 0xff) {
156
+ return new TextDecoder("utf-16be", { fatal: true }).decode(bytes.subarray(2));
157
+ }
158
+ if (bytes.length >= 2 && bytes[0] === 0x3c && bytes[1] === 0x00) {
159
+ return new TextDecoder("utf-16le", { fatal: true }).decode(bytes);
160
+ }
161
+ if (bytes.length >= 2 && bytes[0] === 0x00 && bytes[1] === 0x3c) {
162
+ return new TextDecoder("utf-16be", { fatal: true }).decode(bytes);
163
+ }
164
+ const label = declaredSvgEncoding(bytes);
165
+ if (label !== undefined) {
166
+ try {
167
+ return new TextDecoder(label, { fatal: true }).decode(bytes);
168
+ }
169
+ catch (error) {
170
+ // An unknown charset label throws a RangeError; undecodable content
171
+ // throws a TypeError. Only the label falls back to UTF-8.
172
+ if (error instanceof RangeError)
173
+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
174
+ throw error;
175
+ }
176
+ }
177
+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
178
+ }
179
+ catch {
180
+ return null;
181
+ }
182
+ }
183
+ /** Decodes a text data URI (for SVG images). */
184
+ export function decodeTextDataUri(uri) {
185
+ const split = splitDataUri(uri);
186
+ if (split === null)
187
+ return null;
188
+ const { body } = split;
189
+ if (split.base64) {
190
+ const data = base64DecodeBody(body);
191
+ return data === null ? null : decodeSvgBytes(data);
192
+ }
193
+ // As for binary data, a `%` without two hex digits stays as written.
194
+ return decodeSvgBytes(percentDecodeBytes(body));
195
+ }
196
+ /** The intrinsic size of a raster image, read from its header, or null. */
197
+ export function intrinsicSize(mimeType, data) {
198
+ switch (mimeType) {
199
+ case "image/png":
200
+ return pngSize(data);
201
+ case "image/gif":
202
+ return gifSize(data);
203
+ case "image/jpeg":
204
+ return jpegSize(data);
205
+ case "image/webp":
206
+ return webpSize(data);
207
+ default:
208
+ return null;
209
+ }
210
+ }
211
+ /** PNG: width and height sit at bytes 16–24 of the IHDR chunk, big-endian. */
212
+ function pngSize(data) {
213
+ if (data.length < 24)
214
+ return null;
215
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
216
+ const signature = [0x89, 0x50, 0x4e, 0x47];
217
+ for (const [index, byte] of signature.entries()) {
218
+ if (data[index] !== byte)
219
+ return null;
220
+ }
221
+ return { width: view.getUint32(16), height: view.getUint32(20) };
222
+ }
223
+ /** GIF: width and height at bytes 6–10, little-endian. */
224
+ function gifSize(data) {
225
+ if (data.length < 10)
226
+ return null;
227
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
228
+ if (data[0] !== 0x47 || data[1] !== 0x49 || data[2] !== 0x46)
229
+ return null;
230
+ return { width: view.getUint16(6, true), height: view.getUint16(8, true) };
231
+ }
232
+ /**
233
+ * JPEG: scan markers for a start-of-frame, whose payload holds the size.
234
+ * Any number of 0xFF fill bytes may come before a marker, and the
235
+ * standalone markers (TEM, RST0-7) have no length (ITU T.81, B.1.1.2).
236
+ * Every step moves forward, so the scan ends within the data.
237
+ */
238
+ function jpegSize(data) {
239
+ if (data.length < 4 || data[0] !== 0xff || data[1] !== 0xd8)
240
+ return null;
241
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
242
+ let offset = 2;
243
+ while (offset + 9 < data.length) {
244
+ if (data[offset] !== 0xff)
245
+ return null;
246
+ let markerAt = offset + 1;
247
+ while (markerAt < data.length && data[markerAt] === 0xff)
248
+ markerAt += 1;
249
+ if (markerAt + 8 >= data.length)
250
+ return null;
251
+ const marker = data[markerAt];
252
+ if (marker === 0x01 || (marker >= 0xd0 && marker <= 0xd7)) {
253
+ offset = markerAt + 1;
254
+ continue;
255
+ }
256
+ if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc) {
257
+ return { width: view.getUint16(markerAt + 6), height: view.getUint16(markerAt + 4) };
258
+ }
259
+ const length = view.getUint16(markerAt + 1);
260
+ if (length < 2)
261
+ return null;
262
+ offset = markerAt + 1 + length;
263
+ }
264
+ return null;
265
+ }
266
+ /** WebP: the size hides in the VP8, VP8L or VP8X chunk. */
267
+ function webpSize(data) {
268
+ if (data.length < 30)
269
+ return null;
270
+ const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
271
+ const text = (from, length) => String.fromCharCode(...data.subarray(from, from + length));
272
+ if (text(0, 4) !== "RIFF" || text(8, 4) !== "WEBP")
273
+ return null;
274
+ const kind = text(12, 4);
275
+ if (kind === "VP8X") {
276
+ return {
277
+ width: 1 + ((data[24] ?? 0) | ((data[25] ?? 0) << 8) | ((data[26] ?? 0) << 16)),
278
+ height: 1 + ((data[27] ?? 0) | ((data[28] ?? 0) << 8) | ((data[29] ?? 0) << 16)),
279
+ };
280
+ }
281
+ if (kind === "VP8 ") {
282
+ return { width: view.getUint16(26, true) & 0x3fff, height: view.getUint16(28, true) & 0x3fff };
283
+ }
284
+ if (kind === "VP8L") {
285
+ const bits = view.getUint32(21, true);
286
+ return { width: (bits & 0x3fff) + 1, height: ((bits >> 14) & 0x3fff) + 1 };
287
+ }
288
+ return null;
289
+ }
290
+ /** The raster mime types an `<image>` may carry, per the spec. */
291
+ const RASTER_TYPES = new Set(["image/png", "image/jpeg", "image/webp", "image/gif"]);
292
+ /**
293
+ * The asset for one data URI: made the first time the URI is met and shared
294
+ * after that, so an image inside a component used many times is one asset.
295
+ * A component probe (`ctx.probing`) reuses an existing asset but never adds one.
296
+ */
297
+ function imageAsset(href, decoded, ctx) {
298
+ const existing = ctx.imageAssets.get(href);
299
+ if (existing !== undefined)
300
+ return existing;
301
+ const assetId = ctx.idSource();
302
+ if (ctx.probing)
303
+ return assetId;
304
+ const size = intrinsicSize(decoded.mimeType, decoded.data);
305
+ ctx.images.push({
306
+ id: assetId,
307
+ mimeType: decoded.mimeType,
308
+ data: decoded.data,
309
+ ...(size === null ? {} : size),
310
+ });
311
+ ctx.imageAssets.set(href, assetId);
312
+ return assetId;
313
+ }
314
+ /** Where an alignment part (`Min`, `Mid` or `Max`) puts the image in the space it leaves: 0, half or all of it. */
315
+ function alignFraction(part) {
316
+ return part === "Min" ? 0 : part === "Max" ? 1 : 0.5;
317
+ }
318
+ /** Builds the layer of one `<image>` element. */
319
+ export function imageLayer(element, computed, matrix, elementPath, ctx) {
320
+ const nothing = { top: null, nodes: [] };
321
+ const fontSize = computed.fontSize;
322
+ const viewport = ctx.viewport;
323
+ const lengthOf = (name, axis) => {
324
+ const text = attr(element, name);
325
+ if (text === null)
326
+ return null;
327
+ const parsed = parseSvgLength(text, { fontSize, rootFontSize: ctx.rules.rootFontSize });
328
+ if (parsed === null)
329
+ return null;
330
+ if (parsed.kind === "absolute")
331
+ return parsed.value;
332
+ if (viewport === null)
333
+ return null;
334
+ return parsed.fraction * (axis === "x" ? viewport.width : viewport.height);
335
+ };
336
+ // A side left out, `auto`, or unreadable (whose initial value is `auto`)
337
+ // comes from the image's own size once it is decoded.
338
+ const sideOf = (name, axis) => {
339
+ const text = attr(element, name);
340
+ if (text === null || text.toLowerCase() === "auto")
341
+ return "auto";
342
+ if (parseSvgLength(text, { fontSize, rootFontSize: ctx.rules.rootFontSize }) === null) {
343
+ ctx.report(elementPath, "image", "approximated", `the image's ${name} "${text}" cannot be read, so auto is used`, { what: "Image sizes that cannot be read", kept: "The image's own size is used" });
344
+ return "auto";
345
+ }
346
+ return lengthOf(name, axis);
347
+ };
348
+ const x = lengthOf("x", "x") ?? 0;
349
+ const y = lengthOf("y", "y") ?? 0;
350
+ const givenWidth = sideOf("width", "x");
351
+ const givenHeight = sideOf("height", "y");
352
+ if (givenWidth === null || givenHeight === null || givenWidth === 0 || givenHeight === 0
353
+ || (typeof givenWidth === "number" && givenWidth < 0) || (typeof givenHeight === "number" && givenHeight < 0)) {
354
+ ctx.report(elementPath, "image", "left-out", "the image has no area", { what: "Images with no area", kept: "Not drawn" });
355
+ return nothing;
356
+ }
357
+ const href = hrefValue(element);
358
+ if (href === null) {
359
+ ctx.report(elementPath, "image", "left-out", "the image has no href", { what: "Images without a source", kept: "Not drawn" });
360
+ return nothing;
361
+ }
362
+ if (!isDataUri(href)) {
363
+ ctx.report(elementPath, "image", "left-out", "external images are never fetched", { what: "Linked images", kept: "Not added: linked files are never fetched" });
364
+ return nothing;
365
+ }
366
+ const aspect = parsePreserveAspectRatio(attr(element, "preserveAspectRatio") ?? "") ?? {
367
+ align: "xMidYMid",
368
+ meetOrSlice: "meet",
369
+ };
370
+ const svgText = dataUriMimeType(href) === "image/svg+xml" ? decodeTextDataUri(href) : null;
371
+ if (svgText !== null) {
372
+ if (givenWidth === "auto" || givenHeight === "auto") {
373
+ ctx.report(elementPath, "image", "left-out", "an SVG image needs both a width and a height; its own size is not read", IMAGE_NO_SIZE_NOTE);
374
+ return nothing;
375
+ }
376
+ return svgImageLayer(element, computed, matrix, elementPath, x, y, givenWidth, givenHeight, svgText, aspect, ctx);
377
+ }
378
+ const decoded = decodeDataUri(href);
379
+ if (decoded === null || !RASTER_TYPES.has(decoded.mimeType)) {
380
+ ctx.report(elementPath, "image", "left-out", "the data URI is not a PNG, JPEG, WebP or GIF image", { what: "Unsupported image formats", kept: "Not drawn" });
381
+ return nothing;
382
+ }
383
+ let width;
384
+ let height;
385
+ if (givenWidth === "auto" || givenHeight === "auto") {
386
+ // Both auto: the pixel size. One auto: the other side times the
387
+ // image's aspect ratio.
388
+ const pixels = intrinsicSize(decoded.mimeType, decoded.data);
389
+ if (pixels === null || pixels.width <= 0 || pixels.height <= 0) {
390
+ ctx.report(elementPath, "image", "left-out", "the image has no width or height and its pixel size is unknown", IMAGE_NO_SIZE_NOTE);
391
+ return nothing;
392
+ }
393
+ width = givenWidth !== "auto" ? givenWidth
394
+ : givenHeight !== "auto" ? givenHeight * pixels.width / pixels.height : pixels.width;
395
+ height = givenHeight !== "auto" ? givenHeight : width * pixels.height / pixels.width;
396
+ }
397
+ else {
398
+ width = givenWidth;
399
+ height = givenHeight;
400
+ }
401
+ // Contain and cover centre the image. Off the middle, meet is kept
402
+ // exactly: the rectangle becomes the image's own fitted box at the
403
+ // requested edge, since the space beside it is empty. A slice crop off the
404
+ // middle has no image fill to say it, so it is drawn centred and reported.
405
+ let fit = aspect.align === "none" ? "fill" : aspect.meetOrSlice === "slice" ? "cover" : "contain";
406
+ let box = { x, y, width, height };
407
+ if (aspect.align !== "none" && aspect.align !== "xMidYMid") {
408
+ const size = intrinsicSize(decoded.mimeType, decoded.data);
409
+ const sameShape = size !== null && Math.abs(size.width * height - size.height * width) <= 1e-9 * size.width * height;
410
+ if (size !== null && !sameShape && aspect.meetOrSlice === "meet") {
411
+ const scale = Math.min(width / size.width, height / size.height);
412
+ const fitted = { width: size.width * scale, height: size.height * scale };
413
+ box = {
414
+ x: x + (width - fitted.width) * alignFraction(aspect.align.slice(1, 4)),
415
+ y: y + (height - fitted.height) * alignFraction(aspect.align.slice(5, 8)),
416
+ ...fitted,
417
+ };
418
+ fit = "fill";
419
+ }
420
+ else if (size === null) {
421
+ ctx.report(elementPath, "image", "approximated", `the image's ${aspect.align} ${aspect.meetOrSlice} placement is drawn centred: its pixel size is unknown`, IMAGE_ALIGN_NOTE);
422
+ }
423
+ else if (!sameShape) {
424
+ ctx.report(elementPath, "image", "approximated", `the image's ${aspect.align} slice crop is drawn centred`, IMAGE_ALIGN_NOTE);
425
+ }
426
+ }
427
+ const frame = rasterFramePlan(box, matrix);
428
+ // Meet and slice must fit the unscaled box before uneven scaling is applied.
429
+ const plan = frame && (fit === "fill" || sameScale(frame.placement.parts.ux, Math.abs(frame.placement.parts.uz))) ? frame : null;
430
+ if (plan === null && (matrixIsDegenerate(matrix) || !transformIsInvertible(matrix))) {
431
+ ctx.report(elementPath, "image", "left-out", "the image transform cannot be inverted", { what: "Images with degenerate transforms", kept: "Not drawn" });
432
+ return nothing;
433
+ }
434
+ const assetId = imageAsset(href, decoded, ctx);
435
+ const chrome = layerChrome(computed);
436
+ const common = {
437
+ id: ctx.idSource(),
438
+ name: attr(element, "id") ?? "Image",
439
+ visible: chrome.visible,
440
+ locked: false,
441
+ opacity: chrome.opacity,
442
+ style: { fills: [{ kind: "image", assetId, fit }] },
443
+ };
444
+ const blend = chrome.blendMode === null ? {} : { blendMode: chrome.blendMode };
445
+ if (plan === null) {
446
+ // The outline and the image paint both use the path's local rectangle.
447
+ const node = {
448
+ ...pathNodeFromSvgPath({
449
+ ...common,
450
+ pathData: `M0 0H${box.width}V${box.height}H0Z`,
451
+ transform: multiplyTransforms(matrix, [1, 0, 0, 1, box.x, box.y]),
452
+ }),
453
+ ...blend,
454
+ };
455
+ return { top: node, nodes: [node] };
456
+ }
457
+ const node = {
458
+ ...common,
459
+ ...blend,
460
+ type: "shape",
461
+ shape: "rectangle",
462
+ frame: plan.frame,
463
+ rotation: plan.rotation,
464
+ ...(plan.flipY ? { flipY: true } : {}),
465
+ };
466
+ return { top: node, nodes: [node] };
467
+ }
468
+ /** Imports an SVG data-URI image recursively, as a nested frame under the same caps. */
469
+ function svgImageLayer(element, computed, matrix, elementPath, x, y, width, height, svgText, aspect, ctx) {
470
+ if (ctx.runNestedImport === null) {
471
+ ctx.report(elementPath, "image", "left-out", "the host cannot parse the nested SVG image", NESTED_SVG_NOTE);
472
+ return { top: null, nodes: [] };
473
+ }
474
+ const outcome = ctx.runNestedImport(svgText, matrix, { x, y, width, height }, aspect, elementPath, ctx);
475
+ if ("reason" in outcome) {
476
+ ctx.report(elementPath, "image", "left-out", outcome.reason, NESTED_SVG_NOTE);
477
+ return { top: null, nodes: [] };
478
+ }
479
+ // The image element's chrome applies to the nested frame as it does to a
480
+ // raster image: its opacity multiplies with the nested root's own, and its
481
+ // visibility and blend mode are the frame's.
482
+ const { top, nodes } = outcome.built;
483
+ if (top === null)
484
+ return outcome.built;
485
+ const chrome = layerChrome(computed);
486
+ const blendMode = chrome.blendMode ?? top.blendMode;
487
+ const { blendMode: _rootBlend, ...rest } = top;
488
+ const framed = {
489
+ ...rest,
490
+ opacity: top.opacity * chrome.opacity,
491
+ visible: chrome.visible,
492
+ ...(blendMode === undefined ? {} : { blendMode }),
493
+ };
494
+ return { top: framed, nodes: nodes.map((node) => (node === top ? framed : node)) };
495
+ }
@@ -0,0 +1,85 @@
1
+ import { type GroupNode, type Rect, type SceneNode } from "../../model/index.ts";
2
+ import type { SvgElementLike, SvgImportComponent, SvgImportImage } from "../public-types.ts";
3
+ import type { AssetId } from "../../model/index.ts";
4
+ import type { ReportBuilder, ReportNote } from "../report/report.ts";
5
+ import type { LimitGuard } from "../limits/limits.ts";
6
+ import { type ComputedStyle, type StyleRules } from "../style/computed.ts";
7
+ import { type Matrix } from "../transform/matrix.ts";
8
+ import { type PreserveAspectRatio } from "../units/viewbox.ts";
9
+ import { type ShapeContext } from "../shapes/shapes.ts";
10
+ import { type TextContext } from "../text/text.ts";
11
+ import { type ComponentRegistry, type ReuseContext } from "../reuse/reuse.ts";
12
+ /** The shared state of one import, threaded through the whole walk. */
13
+ export interface WalkContext extends ShapeContext, TextContext, ReuseContext {
14
+ readonly idSource: () => string;
15
+ /** Set while the content of a `<clipPath>` is built, so shapes use their `clip-rule`. */
16
+ readonly insideClipPath?: boolean;
17
+ readonly rules: StyleRules;
18
+ readonly ids: ReadonlyMap<string, SvgElementLike>;
19
+ /** Every element's computed style at its own place in the tree, from the pre-pass. */
20
+ readonly styles: ReadonlyMap<SvgElementLike, ComputedStyle>;
21
+ /** Every element's path in its document, such as `svg > defs > symbol#icon > rect`. */
22
+ readonly paths: ReadonlyMap<SvgElementLike, string>;
23
+ readonly viewport: {
24
+ readonly width: number;
25
+ readonly height: number;
26
+ } | null;
27
+ readonly reportBuilder: ReportBuilder;
28
+ readonly limits: LimitGuard;
29
+ readonly components: SvgImportComponent[];
30
+ readonly images: SvgImportImage[];
31
+ /** The asset made for each data URI, so one image used many times is one asset. */
32
+ readonly imageAssets: Map<string, AssetId>;
33
+ /** The component registry of each nested SVG image's document, keyed by its markup. */
34
+ readonly nestedRegistries: Map<string, ComponentRegistry>;
35
+ /**
36
+ * Imports a nested SVG data-URI image; null when the host cannot parse SVG
37
+ * text. Gives the built frame, or the reason it could not be imported.
38
+ */
39
+ readonly runNestedImport: ((svgText: string, matrix: Matrix, rect: Rect, aspect: PreserveAspectRatio, elementPath: string, ctx: WalkContext) => {
40
+ readonly built: BuiltElement;
41
+ } | {
42
+ readonly reason: string;
43
+ }) | null;
44
+ readonly report: (elementPath: string, element: string, kind: "left-out" | "approximated" | "auto-layout", reason: string, note: ReportNote) => void;
45
+ }
46
+ /** The layers one element produced, to link into its parent. */
47
+ export interface BuiltElement {
48
+ /** The layer to link, or null when the element was dropped. */
49
+ readonly top: SceneNode | null;
50
+ /** Every node created for the element and its subtree, in creation order. */
51
+ readonly nodes: readonly SceneNode[];
52
+ }
53
+ /** Reports each conditional attribute an element carries. */
54
+ export declare function reportConditionAttributes(element: SvgElementLike, elementPath: string, report: WalkContext["report"]): void;
55
+ /**
56
+ * Builds the layers of one element's children, in document order, mapped by
57
+ * `parentMatrix` into the parent layer's coordinate space.
58
+ */
59
+ export declare function buildChildren(parentElement: SvgElementLike, parentStyle: ComputedStyle, parentMatrix: Matrix, parentPath: string, ctx: WalkContext): {
60
+ readonly children: SceneNode[];
61
+ readonly nodes: SceneNode[];
62
+ };
63
+ /** Builds the layers of one element. Definition elements return nothing. */
64
+ export declare function buildElement(element: SvgElementLike, parentStyle: ComputedStyle, parentMatrix: Matrix, elementPath: string, ctx: WalkContext): BuiltElement;
65
+ /**
66
+ * Whether the children of a `<g>` are spaced evenly, per the spec: at least
67
+ * three visible, axis-aligned children with no masks or clips; on one axis
68
+ * their boxes do not overlap and the gaps are equal within 0.5 px; on the
69
+ * other axis they share a start, center or end edge. Detection never moves
70
+ * a child more than 0.5 px.
71
+ */
72
+ export declare function detectAutoLayout(children: readonly SceneNode[], boxes: readonly Rect[]): {
73
+ readonly direction: "horizontal" | "vertical";
74
+ readonly gap: number;
75
+ readonly align: "start" | "center" | "end";
76
+ } | null;
77
+ /** Shifts one node by a delta, in place in its parent's coordinate space. */
78
+ export declare function shiftNode(node: SceneNode, dx: number, dy: number): SceneNode;
79
+ /** The union of boxes, or null for an empty list. */
80
+ export declare function unionBoxes(boxes: readonly Rect[]): Rect | null;
81
+ /** Creates a group around already-built layers (clip and mask groups use this). */
82
+ export declare function wrapInGroup(element: SvgElementLike, layers: readonly SceneNode[], name: string, ctx: WalkContext): {
83
+ readonly group: GroupNode;
84
+ readonly shifted: readonly SceneNode[];
85
+ };