@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,3 @@
1
+ export { DEFAULT_SVG_IMPORT_LIMITS, SVG_IMPORT_REFUSAL_CODES, isSvgImportRefusal, type SvgElementLike, type SvgFontAvailable, type SvgImportComponent, type SvgImportImage, type SvgImportLimits, type SvgImportOptions, type SvgImportRefusal, type SvgImportRefusalCode, type SvgImportReportEntry, type SvgImportReportKind, type SvgImportResult, type SvgMeasureText, type SvgParse, type SvgTextFontStyle, type SvgTextMeasureRequest, type SvgTextMetrics, } from "./public-types.ts";
2
+ export { importSvg, importSvgMarkup, svgMarkupRootSize } from "./import-svg.ts";
3
+ export { SVG_TREE_DATA_PIECE, svgElementData, svgElementDataPieces, svgElementFromData, type SvgNodeData, type SvgTreeData, } from "./tree/element-data.ts";
@@ -0,0 +1,3 @@
1
+ export { DEFAULT_SVG_IMPORT_LIMITS, SVG_IMPORT_REFUSAL_CODES, isSvgImportRefusal, } from "./public-types.js";
2
+ export { importSvg, importSvgMarkup, svgMarkupRootSize } from "./import-svg.js";
3
+ export { SVG_TREE_DATA_PIECE, svgElementData, svgElementDataPieces, svgElementFromData, } from "./tree/element-data.js";
@@ -0,0 +1,79 @@
1
+ import type { SvgImportLimits, SvgImportRefusal, SvgImportRefusalCode } from "../public-types.ts";
2
+ /**
3
+ * Thrown inside the walk when a cap is crossed; the entry point catches it
4
+ * and returns the refusal. A refused import never leaves anything half
5
+ * imported, because the result is built only after the walk completes.
6
+ */
7
+ export declare class SvgImportRefusalError extends Error {
8
+ readonly code: SvgImportRefusalCode;
9
+ constructor(code: SvgImportRefusalCode, message: string);
10
+ /** The refusal the entry point returns. */
11
+ refusal(): SvgImportRefusal;
12
+ }
13
+ /**
14
+ * Thrown when a loop that walks references, splits curves or converges
15
+ * passes its iteration limit. Unlike a refusal this means the input made the
16
+ * importer itself spin, so it is never caught and turned into a result.
17
+ */
18
+ export declare class SvgImportIterationError extends Error {
19
+ }
20
+ /** A counter with a hard stop, for loops whose length the input can steer. */
21
+ export declare class IterationGuard {
22
+ #private;
23
+ constructor(name: string, maximum: number);
24
+ /** Counts one iteration; throws `SvgImportIterationError` past the maximum. */
25
+ step(): void;
26
+ }
27
+ /** The most iterations any single reference walk, curve split or convergence may take. */
28
+ export declare const ITERATION_LIMIT = 10000;
29
+ /** Work counted over the whole import, shared with component probes. */
30
+ interface SharedWork {
31
+ referenceSteps: number;
32
+ pathNumbers: number;
33
+ elementBuilds: number;
34
+ styleWork: number;
35
+ /** How many element builds are open, one inside another. */
36
+ buildDepth: number;
37
+ }
38
+ /** Counts the capped quantities of one import and refuses at the caps. */
39
+ export declare class LimitGuard {
40
+ #private;
41
+ constructor(limits: SvgImportLimits, work?: SharedWork);
42
+ /**
43
+ * The guard of a component probe: it counts no elements, copies,
44
+ * components or instances, since the probe's result is thrown away, but its
45
+ * reference steps, path data, element builds and style work still count
46
+ * against this import's caps, because the probe really does that work.
47
+ */
48
+ forProbe(): LimitGuard;
49
+ /** Counts one step along a gradient or `<use>` reference chain and refuses past the cap. */
50
+ countReferenceStep(): void;
51
+ /** Counts the numbers and commands of one path's data and refuses past the cap. */
52
+ countPathNumbers(count: number): void;
53
+ /** Counts one build of an element and refuses past the cap. */
54
+ countElementBuild(): void;
55
+ /**
56
+ * Opens one element build inside the open ones and refuses when they nest
57
+ * deeper than the depth cap. A `<use>` draws its target's content inside
58
+ * itself, so a chain of uses nests what is drawn deeper than the file.
59
+ * Each call that returns is matched by `leaveBuild`.
60
+ */
61
+ enterBuild(): void;
62
+ /** Closes the element build `enterBuild` opened. */
63
+ leaveBuild(): void;
64
+ /** Refuses when the input's own byte count is over the cap. */
65
+ checkInputBytes(bytes: number): void;
66
+ /** Counts one element and refuses past the cap. */
67
+ countElement(): void;
68
+ /** Refuses when the document nests deeper than the cap. */
69
+ checkDepth(depth: number): void;
70
+ /** Counts one `<use>` instantiation and refuses past the cap. */
71
+ countUseCopy(): void;
72
+ /** Counts one new component and refuses past the cap. */
73
+ countComponent(): void;
74
+ /** Counts one new instance and refuses past the cap. */
75
+ countInstance(): void;
76
+ /** Counts style sheet work (see `SvgImportLimits.styleWork`) and refuses past the cap. */
77
+ countStyleWork(units: number): void;
78
+ }
79
+ export {};
@@ -0,0 +1,160 @@
1
+ /**
2
+ * Thrown inside the walk when a cap is crossed; the entry point catches it
3
+ * and returns the refusal. A refused import never leaves anything half
4
+ * imported, because the result is built only after the walk completes.
5
+ */
6
+ export class SvgImportRefusalError extends Error {
7
+ code;
8
+ constructor(code, message) {
9
+ super(message);
10
+ this.code = code;
11
+ }
12
+ /** The refusal the entry point returns. */
13
+ refusal() {
14
+ return { code: this.code, message: this.message };
15
+ }
16
+ }
17
+ /**
18
+ * Thrown when a loop that walks references, splits curves or converges
19
+ * passes its iteration limit. Unlike a refusal this means the input made the
20
+ * importer itself spin, so it is never caught and turned into a result.
21
+ */
22
+ export class SvgImportIterationError extends Error {
23
+ }
24
+ /** A counter with a hard stop, for loops whose length the input can steer. */
25
+ export class IterationGuard {
26
+ #name;
27
+ #maximum;
28
+ #count = 0;
29
+ constructor(name, maximum) {
30
+ this.#name = name;
31
+ this.#maximum = maximum;
32
+ }
33
+ /** Counts one iteration; throws `SvgImportIterationError` past the maximum. */
34
+ step() {
35
+ this.#count += 1;
36
+ if (this.#count > this.#maximum) {
37
+ throw new SvgImportIterationError(`${this.#name} did not finish after ${String(this.#maximum)} iterations`);
38
+ }
39
+ }
40
+ }
41
+ /** The most iterations any single reference walk, curve split or convergence may take. */
42
+ export const ITERATION_LIMIT = 10_000;
43
+ /** Counts the capped quantities of one import and refuses at the caps. */
44
+ export class LimitGuard {
45
+ #limits;
46
+ #work;
47
+ #elements = 0;
48
+ #useCopies = 0;
49
+ #components = 0;
50
+ #instances = 0;
51
+ constructor(limits, work = { referenceSteps: 0, pathNumbers: 0, elementBuilds: 0, styleWork: 0, buildDepth: 0 }) {
52
+ this.#limits = limits;
53
+ this.#work = work;
54
+ }
55
+ /**
56
+ * The guard of a component probe: it counts no elements, copies,
57
+ * components or instances, since the probe's result is thrown away, but its
58
+ * reference steps, path data, element builds and style work still count
59
+ * against this import's caps, because the probe really does that work.
60
+ */
61
+ forProbe() {
62
+ return new LimitGuard({
63
+ inputBytes: Infinity,
64
+ elements: Infinity,
65
+ depth: this.#limits.depth,
66
+ useCopies: Infinity,
67
+ components: Infinity,
68
+ instances: Infinity,
69
+ styleWork: this.#limits.styleWork,
70
+ referenceSteps: this.#limits.referenceSteps,
71
+ pathNumbers: this.#limits.pathNumbers,
72
+ elementBuilds: this.#limits.elementBuilds,
73
+ }, this.#work);
74
+ }
75
+ /** Counts one step along a gradient or `<use>` reference chain and refuses past the cap. */
76
+ countReferenceStep() {
77
+ this.#work.referenceSteps += 1;
78
+ if (this.#work.referenceSteps > this.#limits.referenceSteps) {
79
+ throw new SvgImportRefusalError("too-many-reference-steps", `Following the SVG's gradient and <use> references would take more than ${String(this.#limits.referenceSteps)} steps`);
80
+ }
81
+ }
82
+ /** Counts the numbers and commands of one path's data and refuses past the cap. */
83
+ countPathNumbers(count) {
84
+ this.#work.pathNumbers += count;
85
+ if (this.#work.pathNumbers > this.#limits.pathNumbers) {
86
+ throw new SvgImportRefusalError("too-much-path-data", `The SVG's paths hold more than ${String(this.#limits.pathNumbers)} numbers and commands of path data`);
87
+ }
88
+ }
89
+ /** Counts one build of an element and refuses past the cap. */
90
+ countElementBuild() {
91
+ this.#work.elementBuilds += 1;
92
+ if (this.#work.elementBuilds > this.#limits.elementBuilds) {
93
+ throw new SvgImportRefusalError("too-many-element-builds", `Drawing the SVG's elements, counting each time one is drawn again, would build more than ${String(this.#limits.elementBuilds)} elements`);
94
+ }
95
+ }
96
+ /**
97
+ * Opens one element build inside the open ones and refuses when they nest
98
+ * deeper than the depth cap. A `<use>` draws its target's content inside
99
+ * itself, so a chain of uses nests what is drawn deeper than the file.
100
+ * Each call that returns is matched by `leaveBuild`.
101
+ */
102
+ enterBuild() {
103
+ const depth = this.#work.buildDepth + 1;
104
+ if (depth > this.#limits.depth) {
105
+ throw new SvgImportRefusalError("too-deep", `Drawing the SVG, counting what its <use> elements draw, nests ${String(depth)} levels deep, over the ${String(this.#limits.depth)} level cap`);
106
+ }
107
+ this.#work.buildDepth = depth;
108
+ }
109
+ /** Closes the element build `enterBuild` opened. */
110
+ leaveBuild() {
111
+ this.#work.buildDepth -= 1;
112
+ }
113
+ /** Refuses when the input's own byte count is over the cap. */
114
+ checkInputBytes(bytes) {
115
+ if (bytes > this.#limits.inputBytes) {
116
+ throw new SvgImportRefusalError("too-large", `The SVG is about ${String(bytes)} bytes, over the ${String(this.#limits.inputBytes)} byte cap`);
117
+ }
118
+ }
119
+ /** Counts one element and refuses past the cap. */
120
+ countElement() {
121
+ this.#elements += 1;
122
+ if (this.#elements > this.#limits.elements) {
123
+ throw new SvgImportRefusalError("too-many-elements", `The SVG has more than ${String(this.#limits.elements)} elements`);
124
+ }
125
+ }
126
+ /** Refuses when the document nests deeper than the cap. */
127
+ checkDepth(depth) {
128
+ if (depth > this.#limits.depth) {
129
+ throw new SvgImportRefusalError("too-deep", `The SVG nests ${String(depth)} levels deep, over the ${String(this.#limits.depth)} level cap`);
130
+ }
131
+ }
132
+ /** Counts one `<use>` instantiation and refuses past the cap. */
133
+ countUseCopy() {
134
+ this.#useCopies += 1;
135
+ if (this.#useCopies > this.#limits.useCopies) {
136
+ throw new SvgImportRefusalError("too-many-use-copies", `The SVG expands to more than ${String(this.#limits.useCopies)} <use> copies`);
137
+ }
138
+ }
139
+ /** Counts one new component and refuses past the cap. */
140
+ countComponent() {
141
+ this.#components += 1;
142
+ if (this.#components > this.#limits.components) {
143
+ throw new SvgImportRefusalError("too-many-components", `The SVG would create more than ${String(this.#limits.components)} components`);
144
+ }
145
+ }
146
+ /** Counts one new instance and refuses past the cap. */
147
+ countInstance() {
148
+ this.#instances += 1;
149
+ if (this.#instances > this.#limits.instances) {
150
+ throw new SvgImportRefusalError("too-many-instances", `The SVG would create more than ${String(this.#limits.instances)} instances`);
151
+ }
152
+ }
153
+ /** Counts style sheet work (see `SvgImportLimits.styleWork`) and refuses past the cap. */
154
+ countStyleWork(units) {
155
+ this.#work.styleWork += units;
156
+ if (this.#work.styleWork > this.#limits.styleWork) {
157
+ throw new SvgImportRefusalError("too-much-style-work", `Matching the SVG's style sheet to its elements and finding its fonts would take more than ${String(this.#limits.styleWork)} steps`);
158
+ }
159
+ }
160
+ }
@@ -0,0 +1,64 @@
1
+ import { type LinearGradientPaint, type RadialGradientPaint, type Rect } from "../../model/index.ts";
2
+ import type { SvgElementLike } from "../public-types.ts";
3
+ import { type Matrix } from "../transform/matrix.ts";
4
+ import type { ComputedStyle, StyleViewport } from "../style/computed.ts";
5
+ import type { ReportNote } from "../report/report.ts";
6
+ /** What a `url(#id)` paint reference resolved to. */
7
+ export type PaintServer =
8
+ /** A degenerate (zero-length) gradient paints as the last stop's solid color. */
9
+ {
10
+ readonly kind: "solid";
11
+ readonly color: string;
12
+ readonly opacity: number | undefined;
13
+ } | {
14
+ readonly kind: "gradient";
15
+ readonly paint: LinearGradientPaint | RadialGradientPaint;
16
+ }
17
+ /** A `<pattern>` reference; the caller reports it and drops the fill. */
18
+ | {
19
+ readonly kind: "pattern";
20
+ }
21
+ /** The gradient is valid but the layer cannot place it (a radial gradient's center and radius are fractions of the layer's box); the caller reports the reason and drops the fill. */
22
+ | {
23
+ readonly kind: "unsupported";
24
+ readonly reason: string;
25
+ }
26
+ /**
27
+ * An `objectBoundingBox` gradient on a bounding box with no width or
28
+ * height paints nothing, and the reference counts as invalid, so a
29
+ * fallback color applies (SVG 2, objectBoundingBox units); the caller
30
+ * reports it.
31
+ */
32
+ | {
33
+ readonly kind: "paints-nothing";
34
+ }
35
+ /** The id is not in the document; the caller reports it and drops the fill. */
36
+ | {
37
+ readonly kind: "missing";
38
+ }
39
+ /** The id names an element that is not a paint server; the caller reports it. */
40
+ | {
41
+ readonly kind: "not-paint-server";
42
+ readonly localName: string;
43
+ };
44
+ /** Everything the resolver reads from the import, without the walk's state. */
45
+ export interface PaintServerContext {
46
+ readonly ids: ReadonlyMap<string, SvgElementLike>;
47
+ readonly limits: {
48
+ readonly countReferenceStep: () => void;
49
+ };
50
+ /** Every element's computed style at its own place in the tree, from the pre-pass. */
51
+ readonly styles: ReadonlyMap<SvgElementLike, ComputedStyle>;
52
+ readonly viewport: StyleViewport | null;
53
+ /** The root <svg>'s computed font size, which `rem` lengths are of. */
54
+ readonly rootFontSize: number;
55
+ readonly report: (element: string, reason: string, note: ReportNote) => void;
56
+ }
57
+ /**
58
+ * Resolves a `url(#id)` paint reference to a model paint.
59
+ * `localFromElement` maps the referencing element's local user space into
60
+ * the layer's local geometry space, and `localBounds` is the layer's own
61
+ * bounding box in that space (the box the model's gradient coordinates are
62
+ * fractions of). Approximations are reported through `ctx.report`.
63
+ */
64
+ export declare function resolvePaintServer(id: string, localFromElement: Matrix, localBounds: Rect, ctx: PaintServerContext): PaintServer | null;