@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,35 @@
1
+ import { type EllipseNode, type LineNode, type PathNode, type Rect, type RectangleNode } from "../../model/index.ts";
2
+ import type { SvgElementLike } from "../public-types.ts";
3
+ import { type Matrix } from "../transform/matrix.ts";
4
+ import { type SvgLengthContext } from "../units/length.ts";
5
+ import type { ComputedStyle } from "../style/computed.ts";
6
+ import { type PaintContext } from "../paint/paint.ts";
7
+ import { type LayerPlacement } from "../paths/paths.ts";
8
+ /** A number attribute that is a length, or null; percentages resolve against `viewportFraction`. */
9
+ export declare function lengthAttr(element: SvgElementLike, name: string, fonts: SvgLengthContext, viewportFraction: number | null): number | null;
10
+ /** What the shape builders need from the walk. */
11
+ export interface ShapeContext extends PaintContext {
12
+ readonly idSource: () => string;
13
+ readonly viewport: {
14
+ readonly width: number;
15
+ readonly height: number;
16
+ } | null;
17
+ }
18
+ /** The frame placement of a rectangle-like layer under its transform. */
19
+ export interface RasterFramePlan {
20
+ readonly frame: Rect;
21
+ readonly rotation: number;
22
+ readonly flipY: boolean;
23
+ readonly placement: LayerPlacement;
24
+ }
25
+ /**
26
+ * Places a rectangle-like natural frame: identity bake puts it at its
27
+ * natural position, a positive scale scales it, rotation and mirroring stay
28
+ * on the node. Anything else (skew) returns null and the caller decides.
29
+ */
30
+ export declare function rasterFramePlan(natural: Rect, matrix: Matrix): RasterFramePlan | null;
31
+ /**
32
+ * Builds the layer for one basic shape element. Returns the node, or null
33
+ * when the element renders nothing (the reason is reported).
34
+ */
35
+ export declare function shapeLayer(element: SvgElementLike, computed: ComputedStyle, matrix: Matrix, elementPath: string, ctx: ShapeContext): RectangleNode | EllipseNode | LineNode | PathNode | null;
@@ -0,0 +1,386 @@
1
+ import { multiplyTransforms, } from "../../model/index.js";
2
+ import { attr } from "../tree/elements.js";
3
+ import { applyMatrixToPoint, nearZero, remainderIsPositiveScale, remainderIsUniformScale, framePositionFor, frameLocalTransform, invertMatrix, } from "../transform/matrix.js";
4
+ import { parseSvgLength, parsePointList } from "../units/length.js";
5
+ import { visualStyleFromComputed } from "../paint/paint.js";
6
+ import { countPathNumbers, layerChrome, layerPlacement, pathLayerFromData } from "../paths/paths.js";
7
+ /** Shapes a browser draws nothing for either. */
8
+ const NO_AREA_NOTE = { what: "Shapes with no area", kept: "Not drawn" };
9
+ /** The default layer names, used when an element has no `id`. */
10
+ const DEFAULT_NAMES = {
11
+ rectangle: "Rectangle",
12
+ ellipse: "Ellipse",
13
+ line: "Line",
14
+ path: "Vector",
15
+ };
16
+ /**
17
+ * Formats a path-data number with every digit: the path may be transformed
18
+ * later, and a transform that magnifies would also magnify any rounding.
19
+ */
20
+ function coordinate(value) {
21
+ return Object.is(value, -0) ? "0" : String(value);
22
+ }
23
+ /** A number attribute that is a length, or null; percentages resolve against `viewportFraction`. */
24
+ export function lengthAttr(element, name, fonts, viewportFraction) {
25
+ const text = attr(element, name);
26
+ if (text === null)
27
+ return null;
28
+ const parsed = parseSvgLength(text, fonts);
29
+ if (parsed === null)
30
+ return null;
31
+ if (parsed.kind === "absolute")
32
+ return parsed.value;
33
+ return viewportFraction === null ? null : parsed.fraction * viewportFraction;
34
+ }
35
+ /** A rectangle's path data, with arcs for rounded corners. */
36
+ function rectPathData(x, y, width, height, rx, ry) {
37
+ if (rx <= 0 || ry <= 0) {
38
+ return `M${coordinate(x)} ${coordinate(y)}H${coordinate(x + width)}V${coordinate(y + height)}H${coordinate(x)}Z`;
39
+ }
40
+ const c = coordinate;
41
+ return [
42
+ `M${c(x + rx)} ${c(y)}`,
43
+ `H${c(x + width - rx)}`,
44
+ `A${c(rx)} ${c(ry)} 0 0 1 ${c(x + width)} ${c(y + ry)}`,
45
+ `V${c(y + height - ry)}`,
46
+ `A${c(rx)} ${c(ry)} 0 0 1 ${c(x + width - rx)} ${c(y + height)}`,
47
+ `H${c(x + rx)}`,
48
+ `A${c(rx)} ${c(ry)} 0 0 1 ${c(x)} ${c(y + height - ry)}`,
49
+ `V${c(y + ry)}`,
50
+ `A${c(rx)} ${c(ry)} 0 0 1 ${c(x + rx)} ${c(y)}`,
51
+ "Z",
52
+ ].join("");
53
+ }
54
+ /** An ellipse's path data: two arcs. */
55
+ function ellipsePathData(cx, cy, rx, ry) {
56
+ const c = coordinate;
57
+ return `M${c(cx - rx)} ${c(cy)}A${c(rx)} ${c(ry)} 0 1 1 ${c(cx + rx)} ${c(cy)}A${c(rx)} ${c(ry)} 0 1 1 ${c(cx - rx)} ${c(cy)}Z`;
58
+ }
59
+ /**
60
+ * Places a rectangle-like natural frame: identity bake puts it at its
61
+ * natural position, a positive scale scales it, rotation and mirroring stay
62
+ * on the node. Anything else (skew) returns null and the caller decides.
63
+ */
64
+ export function rasterFramePlan(natural, matrix) {
65
+ const placement = layerPlacement(matrix);
66
+ if (placement === null)
67
+ return null;
68
+ const { parts } = placement;
69
+ // A mirroring transform leaves a negative y scale, which flipY carries.
70
+ if (!remainderIsPositiveScale({ ...parts, uz: Math.abs(parts.uz) }))
71
+ return null;
72
+ const flipY = parts.uz < 0;
73
+ const width = natural.width * parts.ux;
74
+ const height = natural.height * Math.abs(parts.uz);
75
+ const origin = applyMatrixToPoint(matrix, natural.x, natural.y);
76
+ const position = framePositionFor(parts.rotation, flipY, width, height, origin);
77
+ return {
78
+ frame: { x: position.x, y: position.y, width, height },
79
+ rotation: parts.rotation,
80
+ flipY,
81
+ placement,
82
+ };
83
+ }
84
+ /**
85
+ * Places a framed shape: identity bake puts it at its natural frame,
86
+ * a positive scale scales the frame, and anything else sends the caller to
87
+ * the path fallback (null). Rotation stays on the node; a mirrored
88
+ * transform sets `flipY`.
89
+ */
90
+ function planFramedShape(natural, computed, matrix, placement, keepRadius, elementPath, element, ctx) {
91
+ const plan = rasterFramePlan(natural, matrix);
92
+ if (plan === null)
93
+ return null;
94
+ if (keepRadius !== null && !remainderIsUniformScale(plan.placement.parts) && keepRadius.radius > 0) {
95
+ // Corner radii only scale exactly by a uniform factor.
96
+ return null;
97
+ }
98
+ // The element's user space in the layer's own space: undo the frame's
99
+ // placement, rotation and flip that the model applies to the layer.
100
+ const localFromParent = invertMatrix(frameLocalTransform(plan.frame, plan.rotation, plan.flipY));
101
+ if (localFromParent === null)
102
+ throw new Error("the layer transform of a frame with an area cannot be inverted");
103
+ const localFromElement = multiplyTransforms(localFromParent, matrix);
104
+ const style = visualStyleFromComputed(computed, localFromElement, { x: 0, y: 0, width: plan.frame.width, height: plan.frame.height }, placement.strokeScale, placement.strokeApproximated, elementPath, element, ctx);
105
+ return {
106
+ placement: plan.placement,
107
+ frame: plan.frame,
108
+ rotation: plan.rotation,
109
+ flipY: plan.flipY,
110
+ localFromElement,
111
+ style,
112
+ };
113
+ }
114
+ /** Builds a rectangle layer, or its path fallback when the transform or the radii demand it. */
115
+ function rectangleLayer(element, computed, matrix, placement, elementPath, ctx) {
116
+ const fonts = { fontSize: computed.fontSize, rootFontSize: ctx.rules.rootFontSize };
117
+ const viewport = ctx.viewport;
118
+ const x = lengthAttr(element, "x", fonts, viewport?.width ?? null) ?? 0;
119
+ const y = lengthAttr(element, "y", fonts, viewport?.height ?? null) ?? 0;
120
+ const width = lengthAttr(element, "width", fonts, viewport?.width ?? null);
121
+ const height = lengthAttr(element, "height", fonts, viewport?.height ?? null);
122
+ if (width === null || height === null || width <= 0 || height <= 0) {
123
+ ctx.report(elementPath, element.localName, "left-out", "the rectangle has no area", NO_AREA_NOTE);
124
+ return null;
125
+ }
126
+ // An absent, unreadable or negative radius is auto, which takes the other
127
+ // side's radius; both auto means square corners (SVG 2 §10.2).
128
+ const radius = (name, fraction) => {
129
+ const value = lengthAttr(element, name, fonts, fraction);
130
+ return value === null || value < 0 ? null : value;
131
+ };
132
+ const rxValue = radius("rx", viewport?.width ?? null);
133
+ const ryValue = radius("ry", viewport?.height ?? null);
134
+ let rx = rxValue ?? ryValue ?? 0;
135
+ let ry = ryValue ?? rxValue ?? 0;
136
+ rx = Math.min(Math.max(0, rx), width / 2);
137
+ ry = Math.min(Math.max(0, ry), height / 2);
138
+ const name = attr(element, "id") ?? DEFAULT_NAMES.rectangle;
139
+ if (Math.abs(rx - ry) > 1e-9 && rx > 0 && ry > 0) {
140
+ // Unequal corner radii are elliptical corners: a path.
141
+ return pathLayerFromData(ctx.idSource(), name, rectPathData(x, y, width, height, rx, ry), computed, placement, elementPath, element, ctx)?.node ?? null;
142
+ }
143
+ const plan = planFramedShape({ x, y, width, height }, computed, matrix, placement, rx > 0 ? { radius: rx } : null, elementPath, element, ctx);
144
+ if (plan === null) {
145
+ return pathLayerFromData(ctx.idSource(), name, rectPathData(x, y, width, height, rx, ry), computed, placement, elementPath, element, ctx)?.node ?? null;
146
+ }
147
+ const chrome = layerChrome(computed);
148
+ const node = {
149
+ id: ctx.idSource(),
150
+ name,
151
+ visible: chrome.visible,
152
+ locked: false,
153
+ opacity: chrome.opacity,
154
+ type: "shape",
155
+ shape: "rectangle",
156
+ frame: plan.frame,
157
+ rotation: plan.rotation,
158
+ ...(plan.flipY ? { flipY: true } : {}),
159
+ ...(chrome.blendMode === null ? {} : { blendMode: chrome.blendMode }),
160
+ style: {
161
+ ...plan.style,
162
+ ...(rx > 0
163
+ ? { cornerRadius: rx * (remainderIsUniformScale(plan.placement.parts) ? plan.placement.parts.ux : 1) }
164
+ : {}),
165
+ },
166
+ };
167
+ return node;
168
+ }
169
+ /** Builds an ellipse layer from `circle` or `ellipse`, or its path fallback under skew. */
170
+ function ellipseLayer(element, computed, matrix, placement, elementPath, ctx) {
171
+ const fonts = { fontSize: computed.fontSize, rootFontSize: ctx.rules.rootFontSize };
172
+ const viewport = ctx.viewport;
173
+ const isCircle = element.localName === "circle";
174
+ const diagonal = viewport === null ? null : Math.hypot(viewport.width, viewport.height) / Math.SQRT2;
175
+ const cx = lengthAttr(element, "cx", fonts, viewport?.width ?? null) ?? 0;
176
+ const cy = lengthAttr(element, "cy", fonts, viewport?.height ?? null) ?? 0;
177
+ let rx;
178
+ let ry;
179
+ if (isCircle) {
180
+ rx = lengthAttr(element, "r", fonts, diagonal);
181
+ ry = rx;
182
+ }
183
+ else {
184
+ // An absent, unreadable or negative radius is auto, which takes the
185
+ // other radius (SVG 2 geometry properties); both auto draw nothing.
186
+ const radius = (name, fraction) => {
187
+ const value = lengthAttr(element, name, fonts, fraction);
188
+ return value === null || value < 0 ? null : value;
189
+ };
190
+ const rxValue = radius("rx", viewport?.width ?? null);
191
+ const ryValue = radius("ry", viewport?.height ?? null);
192
+ rx = rxValue ?? ryValue;
193
+ ry = ryValue ?? rxValue;
194
+ }
195
+ if (rx === null || ry === null || rx <= 0 || ry <= 0) {
196
+ ctx.report(elementPath, element.localName, "left-out", `the ${element.localName} has no area`, NO_AREA_NOTE);
197
+ return null;
198
+ }
199
+ const name = attr(element, "id") ?? DEFAULT_NAMES.ellipse;
200
+ const plan = planFramedShape({ x: cx - rx, y: cy - ry, width: rx * 2, height: ry * 2 }, computed, matrix, placement, null, elementPath, element, ctx);
201
+ if (plan === null) {
202
+ return pathLayerFromData(ctx.idSource(), name, ellipsePathData(cx, cy, rx, ry), computed, placement, elementPath, element, ctx)?.node ?? null;
203
+ }
204
+ const chrome = layerChrome(computed);
205
+ const node = {
206
+ id: ctx.idSource(),
207
+ name,
208
+ visible: chrome.visible,
209
+ locked: false,
210
+ opacity: chrome.opacity,
211
+ type: "shape",
212
+ shape: "ellipse",
213
+ frame: plan.frame,
214
+ rotation: plan.rotation,
215
+ ...(plan.flipY ? { flipY: true } : {}),
216
+ ...(chrome.blendMode === null ? {} : { blendMode: chrome.blendMode }),
217
+ style: plan.style,
218
+ };
219
+ return node;
220
+ }
221
+ /**
222
+ * A zero-length line draws only its caps (SVG 2, line caps): a round cap is
223
+ * a circle and a square cap an axis-aligned square in the element's user
224
+ * space, centred on the point and as wide as the stroke (for a non-scaling
225
+ * stroke, as wide in the import's space). It is built as that shape, filled
226
+ * with the stroke's paint, and reported.
227
+ */
228
+ function capLayer(element, computed, matrix, placement, elementPath, ctx, cap, x, y, name) {
229
+ const half = computed.strokeWidth / 2;
230
+ let halfX = half;
231
+ let halfY = half;
232
+ const filled = {
233
+ ...computed,
234
+ fill: computed.stroke,
235
+ fillOpacity: computed.strokeOpacity,
236
+ stroke: { kind: "none" },
237
+ };
238
+ if (computed.nonScalingStroke) {
239
+ // A non-scaling cap keeps the stroke's width in the import's space: its
240
+ // shape there, mapped back into the element's space by the inverse of
241
+ // the transform's linear part, so the transform maps it to that size.
242
+ const [a, b, c, d] = matrix;
243
+ if (b === 0 && c === 0) {
244
+ halfX = half / Math.abs(a);
245
+ halfY = half / Math.abs(d);
246
+ }
247
+ else {
248
+ const inverse = invertMatrix([a, b, c, d, 0, 0]);
249
+ if (inverse === null)
250
+ throw new Error("the transform of a zero-length line cannot be inverted");
251
+ const point = (dx, dy) => {
252
+ const mapped = applyMatrixToPoint(inverse, dx, dy);
253
+ return `${coordinate(x + mapped.x)} ${coordinate(y + mapped.y)}`;
254
+ };
255
+ // A circle as four cubic quarter arcs, or the square's corners.
256
+ const k = 0.5522847498307936 * half;
257
+ const h = half;
258
+ const pathData = cap === "round"
259
+ ? `M${point(h, 0)}C${point(h, k)} ${point(k, h)} ${point(0, h)}C${point(-k, h)} ${point(-h, k)} ${point(-h, 0)}`
260
+ + `C${point(-h, -k)} ${point(-k, -h)} ${point(0, -h)}C${point(k, -h)} ${point(h, -k)} ${point(h, 0)}Z`
261
+ : `M${point(-h, -h)}L${point(h, -h)}L${point(h, h)}L${point(-h, h)}Z`;
262
+ ctx.report(elementPath, element.localName, "approximated", `the line has zero length; its ${cap} cap is drawn as a shape filled with the stroke`, { what: "Zero-length lines with caps", kept: "The cap is drawn as a shape filled with the stroke color" });
263
+ return pathLayerFromData(ctx.idSource(), name, pathData, filled, placement, elementPath, element, ctx)?.node ?? null;
264
+ }
265
+ }
266
+ const attributes = cap === "round"
267
+ ? { cx: String(x), cy: String(y), rx: String(halfX), ry: String(halfY) }
268
+ : { x: String(x - halfX), y: String(y - halfY), width: String(2 * halfX), height: String(2 * halfY) };
269
+ // The cap's own geometry, read by the circle and rectangle builders; the
270
+ // line has no children or text, so it has none either.
271
+ const shape = {
272
+ nodeType: element.nodeType,
273
+ namespaceURI: element.namespaceURI,
274
+ localName: cap === "round" ? "ellipse" : "rect",
275
+ getAttribute: (attribute) => attributes[attribute] ?? null,
276
+ attributes: Object.entries(attributes).map(([attribute, value]) => ({ name: attribute, value })),
277
+ children: [],
278
+ textContent: null,
279
+ childNodes: [],
280
+ };
281
+ ctx.report(elementPath, element.localName, "approximated", `the line has zero length; its ${cap} cap is drawn as a shape filled with the stroke`, { what: "Zero-length lines with caps", kept: "The cap is drawn as a shape filled with the stroke color" });
282
+ const layer = cap === "round"
283
+ ? ellipseLayer(shape, filled, matrix, placement, elementPath, ctx)
284
+ : rectangleLayer(shape, filled, matrix, placement, elementPath, ctx);
285
+ return layer === null ? null : { ...layer, name };
286
+ }
287
+ /** Builds a line layer; the endpoints map by the full transform, so a line stays a line. */
288
+ function lineLayer(element, computed, matrix, placement, elementPath, ctx) {
289
+ const fonts = { fontSize: computed.fontSize, rootFontSize: ctx.rules.rootFontSize };
290
+ const viewport = ctx.viewport;
291
+ const x1 = lengthAttr(element, "x1", fonts, viewport?.width ?? null) ?? 0;
292
+ const y1 = lengthAttr(element, "y1", fonts, viewport?.height ?? null) ?? 0;
293
+ const x2 = lengthAttr(element, "x2", fonts, viewport?.width ?? null) ?? 0;
294
+ const y2 = lengthAttr(element, "y2", fonts, viewport?.height ?? null) ?? 0;
295
+ const from = applyMatrixToPoint(matrix, x1, y1);
296
+ const to = applyMatrixToPoint(matrix, x2, y2);
297
+ const width = Math.hypot(to.x - from.x, to.y - from.y);
298
+ const name = attr(element, "id") ?? DEFAULT_NAMES.line;
299
+ if (width < 1e-9) {
300
+ const cap = computed.strokeLinecap;
301
+ if (cap === "butt" || computed.stroke.kind === "none" || computed.strokeWidth <= 0) {
302
+ ctx.report(elementPath, element.localName, "left-out", "the line has zero length", NO_AREA_NOTE);
303
+ return null;
304
+ }
305
+ return capLayer(element, computed, matrix, placement, elementPath, ctx, cap, x1, y1, name);
306
+ }
307
+ const rotation = (Math.atan2(to.y - from.y, to.x - from.x) * 180) / Math.PI;
308
+ const frame = {
309
+ x: (from.x + to.x) / 2 - width / 2,
310
+ y: (from.y + to.y) / 2,
311
+ width,
312
+ height: 0,
313
+ };
314
+ // The element's user space in the line's own space, whose x axis runs
315
+ // along the line: undo the frame's placement and rotation.
316
+ const localFromParent = invertMatrix(frameLocalTransform(frame, rotation, false));
317
+ if (localFromParent === null)
318
+ throw new Error("the layer transform of a line cannot be inverted");
319
+ const localFromElement = multiplyTransforms(localFromParent, matrix);
320
+ const style = visualStyleFromComputed({ ...computed, fill: { kind: "none" } }, localFromElement, { x: 0, y: 0, width, height: 0 }, placement.strokeScale, placement.strokeApproximated, elementPath, element, ctx);
321
+ const chrome = layerChrome(computed);
322
+ const cap = computed.strokeLinecap === "butt" ? "none" : computed.strokeLinecap;
323
+ const node = {
324
+ id: ctx.idSource(),
325
+ name,
326
+ visible: chrome.visible,
327
+ locked: false,
328
+ opacity: chrome.opacity,
329
+ type: "shape",
330
+ shape: "line",
331
+ frame,
332
+ rotation,
333
+ ...(chrome.blendMode === null ? {} : { blendMode: chrome.blendMode }),
334
+ style,
335
+ startCap: cap,
336
+ endCap: cap,
337
+ };
338
+ return node;
339
+ }
340
+ /** Builds a path layer from `polyline` or `polygon` points. */
341
+ function pointsLayer(element, computed, placement, elementPath, ctx) {
342
+ const text = attr(element, "points");
343
+ // Counted against the import-wide cap before the list is split and parsed,
344
+ // so a huge list is refused before it is built into arrays and strings.
345
+ if (text !== null)
346
+ ctx.limits.countPathNumbers(countPathNumbers(text));
347
+ const numbers = text === null ? null : parsePointList(text);
348
+ if (numbers === null || numbers.length < 4 || numbers.length % 2 === 1) {
349
+ ctx.report(elementPath, element.localName, "left-out", `the ${element.localName} has fewer than two points`, NO_AREA_NOTE);
350
+ return null;
351
+ }
352
+ const c = coordinate;
353
+ const commands = [`M${c(numbers[0])} ${c(numbers[1])}`];
354
+ for (let index = 2; index < numbers.length; index += 2) {
355
+ commands.push(`L${c(numbers[index])} ${c(numbers[index + 1])}`);
356
+ }
357
+ if (element.localName === "polygon")
358
+ commands.push("Z");
359
+ const name = attr(element, "id") ?? DEFAULT_NAMES.path;
360
+ return pathLayerFromData(ctx.idSource(), name, commands.join(""), computed, placement, elementPath, element, ctx, true)?.node ?? null;
361
+ }
362
+ /**
363
+ * Builds the layer for one basic shape element. Returns the node, or null
364
+ * when the element renders nothing (the reason is reported).
365
+ */
366
+ export function shapeLayer(element, computed, matrix, elementPath, ctx) {
367
+ const placement = layerPlacement(matrix);
368
+ if (placement === null) {
369
+ ctx.report(elementPath, element.localName, "left-out", "the transform is not invertible", { what: "Transforms that cannot be inverted", kept: "Not drawn" });
370
+ return null;
371
+ }
372
+ switch (element.localName) {
373
+ case "rect":
374
+ return rectangleLayer(element, computed, matrix, placement, elementPath, ctx);
375
+ case "circle":
376
+ case "ellipse":
377
+ return ellipseLayer(element, computed, matrix, placement, elementPath, ctx);
378
+ case "line":
379
+ return lineLayer(element, computed, matrix, placement, elementPath, ctx);
380
+ case "polyline":
381
+ case "polygon":
382
+ return pointsLayer(element, computed, placement, elementPath, ctx);
383
+ default:
384
+ return null;
385
+ }
386
+ }
@@ -0,0 +1,26 @@
1
+ import { type Shadow } from "../../model/index.ts";
2
+ import type { SvgElementLike } from "../public-types.ts";
3
+ import { type ComputedStyle } from "../style/computed.ts";
4
+ import { type Matrix } from "../transform/matrix.ts";
5
+ import type { BuiltElement, WalkContext } from "./walk.ts";
6
+ /** A drop shadow or blur mapped from an SVG filter, to merge into a layer's style. */
7
+ export interface FilterEffects {
8
+ readonly shadows: readonly Shadow[];
9
+ readonly layerBlur: number | null;
10
+ }
11
+ /**
12
+ * Maps a `<filter>` to a drop shadow or a layer blur, exactly as the spec
13
+ * allows: `feDropShadow`, the `feGaussianBlur` + `feOffset` + `feFlood` +
14
+ * `feComposite` + `feMerge` chain exporters write for a drop shadow, or a
15
+ * lone `feGaussianBlur` on SourceGraphic. Anything else returns null and
16
+ * the caller reports it.
17
+ */
18
+ export declare function mapFilter(filterElement: SvgElementLike, styles: ReadonlyMap<SvgElementLike, ComputedStyle>): FilterEffects | null;
19
+ /**
20
+ * Wraps one built element in its clip and mask groups and merges its filter
21
+ * effects. The order matches SVG: the filter goes on the layer, then the
22
+ * clip group wraps it, then the mask group wraps that. The computed style
23
+ * carries the references already; one that does not start with `#` is
24
+ * external and is never fetched.
25
+ */
26
+ export declare function applyClipMaskFilter(element: SvgElementLike, computed: ComputedStyle, matrix: Matrix, elementPath: string, built: BuiltElement, ctx: WalkContext): BuiltElement;