@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,169 @@
1
+ /**
2
+ * Decides, conservatively, that a selector cannot match any element of one
3
+ * SVG, so a rule the importer does not support can be dropped without a
4
+ * report line: nothing visible is lost when the rule could never apply.
5
+ *
6
+ * A selector cannot match when one of its compound selectors (the parts
7
+ * between combinators) asks for a class, id or attribute that no element
8
+ * of the SVG has. Elements above the root `<svg>` count as having none:
9
+ * the import stands alone, outside any page that could add a dark-mode
10
+ * class. A `:is()` or `:where()` asks for at least one of its branches, so
11
+ * it cannot match when none of them can. Anything this reader does not
12
+ * understand (escapes, namespaces, nesting, or `:is()` nested deeper than
13
+ * MAX_SELECTOR_NESTING) counts as "might match", so such a rule is still
14
+ * reported.
15
+ */
16
+ /** True only when the selector surely matches no element of the SVG. */
17
+ export function selectorCannotMatch(selector, index) {
18
+ return complexCannotMatch(selector.trim(), index, 0) === true;
19
+ }
20
+ /**
21
+ * How deep `:is()` and `:where()` may nest before the reader stops following
22
+ * them and answers "might match". It keeps the recursion off the call stack
23
+ * limit and bounds the rescanning that each level does.
24
+ */
25
+ export const MAX_SELECTOR_NESTING = 32;
26
+ /** Pseudo-classes whose argument is a selector list of which one branch must match. */
27
+ const ANY_OF_PSEUDO_CLASSES = new Set(["is", "where", "matches", "-webkit-any", "-moz-any"]);
28
+ const NAME_START = /[a-zA-Z_\u0080-￿-]/;
29
+ const NAME_CHAR = /[\w\u0080-￿-]/;
30
+ function readName(text, from) {
31
+ let end = from;
32
+ while (end < text.length && NAME_CHAR.test(text.charAt(end)))
33
+ end += 1;
34
+ return end;
35
+ }
36
+ /** The index of the `close` that balances the opener at `open`, skipping strings; -1 if none. */
37
+ function balanced(text, open, opener, close) {
38
+ let depth = 0;
39
+ let quote = "";
40
+ for (let index = open; index < text.length; index += 1) {
41
+ const ch = text.charAt(index);
42
+ if (quote !== "") {
43
+ if (ch === "\\")
44
+ index += 1;
45
+ else if (ch === quote || ch === "\n")
46
+ quote = "";
47
+ continue;
48
+ }
49
+ if (ch === '"' || ch === "'")
50
+ quote = ch;
51
+ else if (ch === opener)
52
+ depth += 1;
53
+ else if (ch === close) {
54
+ depth -= 1;
55
+ if (depth === 0)
56
+ return index;
57
+ }
58
+ }
59
+ return -1;
60
+ }
61
+ /** Splits a selector list on commas outside parentheses, brackets and strings. */
62
+ function splitList(text) {
63
+ const parts = [];
64
+ let depth = 0;
65
+ let quote = "";
66
+ let start = 0;
67
+ for (let index = 0; index < text.length; index += 1) {
68
+ const ch = text.charAt(index);
69
+ if (quote !== "") {
70
+ if (ch === "\\")
71
+ index += 1;
72
+ else if (ch === quote || ch === "\n")
73
+ quote = "";
74
+ continue;
75
+ }
76
+ if (ch === '"' || ch === "'")
77
+ quote = ch;
78
+ else if (ch === "(" || ch === "[")
79
+ depth += 1;
80
+ else if (ch === ")" || ch === "]")
81
+ depth = Math.max(0, depth - 1);
82
+ else if (ch === "," && depth === 0) {
83
+ parts.push(text.slice(start, index));
84
+ start = index + 1;
85
+ }
86
+ }
87
+ parts.push(text.slice(start));
88
+ return parts;
89
+ }
90
+ /** A selector list cannot match when every branch cannot; null if any branch is not understood. */
91
+ function listCannotMatch(list, index, nesting) {
92
+ if (nesting > MAX_SELECTOR_NESTING)
93
+ return null;
94
+ let all = true;
95
+ for (const branch of splitList(list)) {
96
+ const answer = complexCannotMatch(branch.trim(), index, nesting);
97
+ if (answer === null)
98
+ return null;
99
+ if (!answer)
100
+ all = false;
101
+ }
102
+ return all;
103
+ }
104
+ /** Reads one complex selector; true when one of its compounds asks for something absent. */
105
+ function complexCannotMatch(text, index, nesting) {
106
+ if (text.length === 0 || text.includes("\\") || text.includes("&"))
107
+ return null;
108
+ let cannot = false;
109
+ let pos = 0;
110
+ while (pos < text.length) {
111
+ const ch = text.charAt(pos);
112
+ if (/\s/.test(ch) || ch === ">" || ch === "+" || ch === "~" || ch === "*") {
113
+ pos += 1;
114
+ }
115
+ else if (ch === "." || ch === "#") {
116
+ const end = readName(text, pos + 1);
117
+ if (end === pos + 1)
118
+ return null;
119
+ const name = text.slice(pos + 1, end);
120
+ if (!(ch === "." ? index.classes : index.ids).has(name))
121
+ cannot = true;
122
+ pos = end;
123
+ }
124
+ else if (ch === "[") {
125
+ const close = balanced(text, pos, "[", "]");
126
+ if (close === -1)
127
+ return null;
128
+ const inside = text.slice(pos + 1, close).trim();
129
+ const nameEnd = readName(inside, 0);
130
+ if (nameEnd === 0 || inside.charAt(nameEnd) === "|")
131
+ return null;
132
+ if (!index.attributes.has(inside.slice(0, nameEnd).toLowerCase()))
133
+ cannot = true;
134
+ pos = close + 1;
135
+ }
136
+ else if (ch === ":") {
137
+ const pseudoElement = text.charAt(pos + 1) === ":";
138
+ const start = pseudoElement ? pos + 2 : pos + 1;
139
+ const end = readName(text, start);
140
+ if (end === start)
141
+ return null;
142
+ const name = text.slice(start, end).toLowerCase();
143
+ pos = end;
144
+ if (text.charAt(pos) === "(") {
145
+ const close = balanced(text, pos, "(", ")");
146
+ if (close === -1)
147
+ return null;
148
+ if (!pseudoElement && ANY_OF_PSEUDO_CLASSES.has(name)) {
149
+ const answer = listCannotMatch(text.slice(pos + 1, close), index, nesting + 1);
150
+ if (answer === null)
151
+ return null;
152
+ if (answer)
153
+ cannot = true;
154
+ }
155
+ pos = close + 1;
156
+ }
157
+ }
158
+ else if (NAME_START.test(ch)) {
159
+ const end = readName(text, pos);
160
+ if (text.charAt(end) === "|")
161
+ return null;
162
+ pos = end;
163
+ }
164
+ else {
165
+ return null;
166
+ }
167
+ }
168
+ return cannot;
169
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Whether one complex selector is valid CSS (Selectors 4), as a browser
3
+ * parses it — only validity, never whether it matches. The importer applies
4
+ * only type, class and id selectors, but a valid branch it cannot evaluate
5
+ * still works in a browser, so the rule must be kept (and reported when it
6
+ * might match); an invalid branch makes the browser drop the whole rule, so
7
+ * the importer does the same. Probed against Chrome for Testing 151.
8
+ *
9
+ * When in doubt the answer is "valid": marking a valid selector invalid
10
+ * would drop a rule a browser applies, while an invalid selector read as
11
+ * valid is only reported like any other unsupported rule.
12
+ */
13
+ /** Whether one selector (a branch of a rule's selector list) is valid CSS. */
14
+ export declare function isValidSelector(selector: string): boolean;
@@ -0,0 +1,307 @@
1
+ /**
2
+ * Whether one complex selector is valid CSS (Selectors 4), as a browser
3
+ * parses it — only validity, never whether it matches. The importer applies
4
+ * only type, class and id selectors, but a valid branch it cannot evaluate
5
+ * still works in a browser, so the rule must be kept (and reported when it
6
+ * might match); an invalid branch makes the browser drop the whole rule, so
7
+ * the importer does the same. Probed against Chrome for Testing 151.
8
+ *
9
+ * When in doubt the answer is "valid": marking a valid selector invalid
10
+ * would drop a rule a browser applies, while an invalid selector read as
11
+ * valid is only reported like any other unsupported rule.
12
+ */
13
+ /** Pseudo-classes without an argument. */
14
+ const PLAIN_PSEUDO_CLASSES = new Set([
15
+ "hover", "active", "focus", "focus-visible", "focus-within", "visited", "link", "any-link", "local-link",
16
+ "target", "target-within", "scope", "host", "host-context", "playing", "paused", "muted",
17
+ "first-child", "last-child", "only-child", "first-of-type", "last-of-type", "only-of-type",
18
+ "empty", "root", "checked", "indeterminate", "disabled", "enabled", "required", "optional",
19
+ "read-only", "read-write", "valid", "invalid", "in-range", "out-of-range", "default",
20
+ "placeholder-shown", "defined", "fullscreen", "picture-in-picture", "autofill",
21
+ "user-valid", "user-invalid", "modal", "popover-open", "open",
22
+ ]);
23
+ /** Pseudo-classes whose argument is a forgiving selector list: any balanced content keeps the rule. */
24
+ const FORGIVING_LIST_PSEUDO_CLASSES = new Set(["is", "where", "matches", "-webkit-any", "-moz-any"]);
25
+ /** Pseudo-classes whose argument is a selector list in which an invalid branch invalidates the rule. */
26
+ const STRICT_LIST_PSEUDO_CLASSES = new Set(["not", "has"]);
27
+ /** Pseudo-classes whose argument is an `An+B` expression, optionally with `of <selector-list>`. */
28
+ const NTH_PSEUDO_CLASSES = new Set([
29
+ "nth-child", "nth-last-child", "nth-of-type", "nth-last-of-type", "nth-col", "nth-last-col",
30
+ ]);
31
+ /** Pseudo-classes whose argument is a loose keyword or name list (`lang`, `dir`). */
32
+ const TEXT_ARG_PSEUDO_CLASSES = new Set(["lang", "dir"]);
33
+ /** Pseudo-elements without an argument. */
34
+ const PLAIN_PSEUDO_ELEMENTS = new Set([
35
+ "before", "after", "first-line", "first-letter", "marker", "selection", "placeholder",
36
+ "backdrop", "file-selector-button", "target-text", "spelling-error", "grammar-error",
37
+ "cue", "cue-region", "details-content", "view-transition", "view-transition-group",
38
+ "view-transition-image-pair", "view-transition-old", "view-transition-new",
39
+ ]);
40
+ /** Pseudo-elements whose argument is a name or selector; any balanced content counts. */
41
+ const FUNCTIONAL_PSEUDO_ELEMENTS = new Set(["part", "slotted", "highlight"]);
42
+ /** How deep selector arguments may nest before the answer is "invalid". */
43
+ const MAX_NESTING = 32;
44
+ const NAME_CHAR = /[\w\u0080-\uffff-]/;
45
+ /** Reads a CSS identifier starting at `from`; returns its end, or `from` when there is none. */
46
+ function readName(text, from) {
47
+ let end = from;
48
+ while (end < text.length && NAME_CHAR.test(text.charAt(end)))
49
+ end += 1;
50
+ return end;
51
+ }
52
+ /** The index of the `close` balancing the opener at `open`, skipping quoted strings; -1 if none. */
53
+ function balancedClose(text, open, opener, close) {
54
+ let depth = 0;
55
+ let quote = "";
56
+ for (let index = open; index < text.length; index += 1) {
57
+ const ch = text.charAt(index);
58
+ if (quote !== "") {
59
+ if (ch === "\\")
60
+ index += 1;
61
+ else if (ch === quote || ch === "\n")
62
+ quote = "";
63
+ continue;
64
+ }
65
+ if (ch === '"' || ch === "'")
66
+ quote = ch;
67
+ else if (ch === opener)
68
+ depth += 1;
69
+ else if (ch === close) {
70
+ depth -= 1;
71
+ if (depth === 0)
72
+ return index;
73
+ }
74
+ }
75
+ return -1;
76
+ }
77
+ /** Splits on commas outside parentheses, brackets and quoted strings. */
78
+ function splitList(text) {
79
+ const parts = [];
80
+ let depth = 0;
81
+ let quote = "";
82
+ let start = 0;
83
+ for (let index = 0; index < text.length; index += 1) {
84
+ const ch = text.charAt(index);
85
+ if (quote !== "") {
86
+ if (ch === "\\")
87
+ index += 1;
88
+ else if (ch === quote || ch === "\n")
89
+ quote = "";
90
+ continue;
91
+ }
92
+ if (ch === '"' || ch === "'")
93
+ quote = ch;
94
+ else if (ch === "(" || ch === "[")
95
+ depth += 1;
96
+ else if (ch === ")" || ch === "]")
97
+ depth = Math.max(0, depth - 1);
98
+ else if (ch === "," && depth === 0) {
99
+ parts.push(text.slice(start, index));
100
+ start = index + 1;
101
+ }
102
+ }
103
+ parts.push(text.slice(start));
104
+ return parts;
105
+ }
106
+ /** An attribute selector's inside: a name (with `*` or empty namespace), then an optional operator, value and flag. */
107
+ const ATTRIBUTE_PATTERN = /^[*]?\|[a-zA-Z_][\w-]*$|^[a-zA-Z_][\w-]*$/;
108
+ /** Whether an attribute selector's inside is valid, such as `href` or `type="a" i`. */
109
+ function isValidAttribute(inside) {
110
+ const trimmed = inside.trim();
111
+ if (ATTRIBUTE_PATTERN.test(trimmed))
112
+ return true;
113
+ const match = /^([*]?\|)?([a-zA-Z_][\w-]*)\s*([~|^$*]?=)\s*("([^"\\]|\\.)*"|'([^'\\]|\\.)*'|[\w-]+)\s*([isIS])?$/.exec(trimmed);
114
+ if (match === null)
115
+ return false;
116
+ // A named namespace prefix needs an @namespace rule, which the importer
117
+ // never reads; browsers drop such a selector as invalid.
118
+ const prefix = match[1];
119
+ if (prefix !== undefined && prefix !== "*|")
120
+ return false;
121
+ return true;
122
+ }
123
+ /** The `An+B` expression of an :nth-*() argument (CSS Syntax 3). */
124
+ const AN_PLUS_B = /^[+-]?(?:\d+|\d*n(?:\s*[+-]\s*\d+)?|odd|even)$/i;
125
+ /** Whether one pseudo-class's argument makes it valid. */
126
+ function pseudoArgumentValid(name, args, nesting) {
127
+ if (FORGIVING_LIST_PSEUDO_CLASSES.has(name))
128
+ return true;
129
+ if (STRICT_LIST_PSEUDO_CLASSES.has(name)) {
130
+ const relative = name === "has";
131
+ return splitList(args).every((branch) => isValidComplexSelector(branch.trim(), relative, nesting + 1));
132
+ }
133
+ if (NTH_PSEUDO_CLASSES.has(name)) {
134
+ const ofSplit = /^([\s\S]*?)\s+of\s+([\s\S]+)$/i.exec(args.trim());
135
+ const count = (ofSplit?.[1] ?? args).trim();
136
+ if (!AN_PLUS_B.test(count))
137
+ return false;
138
+ if (ofSplit === null)
139
+ return true;
140
+ return splitList(ofSplit[2]).every((branch) => isValidComplexSelector(branch.trim(), false, nesting + 1));
141
+ }
142
+ if (TEXT_ARG_PSEUDO_CLASSES.has(name))
143
+ return args.trim().length > 0 && !args.includes("(");
144
+ return false;
145
+ }
146
+ /** Whether one compound selector (the part between combinators) is valid. */
147
+ function isValidCompound(compound, nesting) {
148
+ if (nesting > MAX_NESTING)
149
+ return false;
150
+ // An escaped character is valid CSS this reader does not look into; it
151
+ // only ever leads to "might match".
152
+ if (compound.includes("\\"))
153
+ return true;
154
+ let rest = compound;
155
+ let parts = 0;
156
+ // The optional type selector or universal selector, with a namespace
157
+ // prefix; a named prefix is invalid here, as no @namespace rule declares it.
158
+ if (rest.startsWith("|")) {
159
+ rest = rest.slice(1);
160
+ const name = /^([a-zA-Z_][\w-]*|\*)/.exec(rest);
161
+ if (name === null)
162
+ return false;
163
+ rest = rest.slice(name[0].length);
164
+ parts += 1;
165
+ }
166
+ else {
167
+ const type = /^([a-zA-Z_][\w-]*|\*)/.exec(rest);
168
+ if (type !== null) {
169
+ rest = rest.slice(type[0].length);
170
+ if (rest.startsWith("|")) {
171
+ if (type[0] !== "*")
172
+ return false;
173
+ rest = rest.slice(1);
174
+ const name = /^([a-zA-Z_][\w-]*|\*)/.exec(rest);
175
+ if (name === null)
176
+ return false;
177
+ rest = rest.slice(name[0].length);
178
+ }
179
+ parts += 1;
180
+ }
181
+ }
182
+ while (rest.length > 0) {
183
+ const ch = rest.charAt(0);
184
+ if (ch === "." || ch === "#") {
185
+ const end = readName(rest, 1);
186
+ if (end === 1)
187
+ return false;
188
+ rest = rest.slice(end);
189
+ }
190
+ else if (ch === "[") {
191
+ const close = balancedClose(rest, 0, "[", "]");
192
+ if (close === -1 || !isValidAttribute(rest.slice(1, close)))
193
+ return false;
194
+ rest = rest.slice(close + 1);
195
+ }
196
+ else if (ch === ":") {
197
+ const element = rest.charAt(1) === ":";
198
+ const start = element ? 2 : 1;
199
+ const end = readName(rest, start);
200
+ if (end === start)
201
+ return false;
202
+ const name = rest.slice(start, end).toLowerCase();
203
+ rest = rest.slice(end);
204
+ const functional = rest.startsWith("(");
205
+ let args = "";
206
+ if (functional) {
207
+ const close = balancedClose(rest, 0, "(", ")");
208
+ if (close === -1)
209
+ return false;
210
+ args = rest.slice(1, close);
211
+ rest = rest.slice(close + 1);
212
+ }
213
+ if (element) {
214
+ if (functional ? !FUNCTIONAL_PSEUDO_ELEMENTS.has(name) : !PLAIN_PSEUDO_ELEMENTS.has(name))
215
+ return false;
216
+ }
217
+ else if (functional) {
218
+ if (!pseudoArgumentValid(name, args, nesting))
219
+ return false;
220
+ }
221
+ else if (!PLAIN_PSEUDO_CLASSES.has(name)) {
222
+ return false;
223
+ }
224
+ }
225
+ else if (ch === "&" || ch === "\\") {
226
+ // A nesting selector and an escaped name are valid CSS this reader
227
+ // does not look into; they only ever lead to "might match".
228
+ return true;
229
+ }
230
+ else {
231
+ return false;
232
+ }
233
+ parts += 1;
234
+ }
235
+ return parts > 0;
236
+ }
237
+ /**
238
+ * Whether one complex selector is valid: compounds joined by combinators
239
+ * (white space, `>`, `+`, `~`), no leading or trailing combinator. A
240
+ * `relative` selector (a :has() branch) may start with one combinator.
241
+ */
242
+ function isValidComplexSelector(text, relative, nesting) {
243
+ if (nesting > MAX_NESTING)
244
+ return false;
245
+ if (text.length === 0)
246
+ return false;
247
+ let rest = text;
248
+ let first = true;
249
+ let expectCompound = true;
250
+ while (rest.length > 0) {
251
+ // One combinator: white space, or one of > + ~ with white space around.
252
+ let combinator = "";
253
+ let pos = 0;
254
+ while (pos < rest.length && /\s/.test(rest.charAt(pos)))
255
+ pos += 1;
256
+ if (pos > 0)
257
+ combinator = " ";
258
+ if (pos < rest.length && (rest.charAt(pos) === ">" || rest.charAt(pos) === "+" || rest.charAt(pos) === "~")) {
259
+ combinator = rest.charAt(pos);
260
+ pos += 1;
261
+ while (pos < rest.length && /\s/.test(rest.charAt(pos)))
262
+ pos += 1;
263
+ }
264
+ if (combinator !== "") {
265
+ if (expectCompound && !(relative && first))
266
+ return false;
267
+ expectCompound = true;
268
+ rest = rest.slice(pos);
269
+ first = false;
270
+ continue;
271
+ }
272
+ // Read one compound: everything up to the next top-level combinator.
273
+ let depth = 0;
274
+ let quote = "";
275
+ let end = 0;
276
+ while (end < rest.length) {
277
+ const ch = rest.charAt(end);
278
+ if (quote !== "") {
279
+ if (ch === "\\")
280
+ end += 1;
281
+ else if (ch === quote || ch === "\n")
282
+ quote = "";
283
+ }
284
+ else if (ch === '"' || ch === "'")
285
+ quote = ch;
286
+ else if (ch === "\\")
287
+ end += 1;
288
+ else if (ch === "(" || ch === "[")
289
+ depth += 1;
290
+ else if (ch === ")" || ch === "]")
291
+ depth -= 1;
292
+ else if (depth === 0 && (/\s/.test(ch) || ch === ">" || ch === "+" || ch === "~"))
293
+ break;
294
+ end += 1;
295
+ }
296
+ if (depth !== 0 || quote !== "" || !isValidCompound(rest.slice(0, end), nesting))
297
+ return false;
298
+ expectCompound = false;
299
+ rest = rest.slice(end);
300
+ first = false;
301
+ }
302
+ return !expectCompound;
303
+ }
304
+ /** Whether one selector (a branch of a rule's selector list) is valid CSS. */
305
+ export function isValidSelector(selector) {
306
+ return isValidComplexSelector(selector.trim(), false, 0);
307
+ }
@@ -0,0 +1,29 @@
1
+ import { type GroupNode, type TextNode } from "../../model/index.ts";
2
+ import type { SvgElementLike, SvgFontAvailable, SvgMeasureText, SvgTextFontStyle } from "../public-types.ts";
3
+ import { type ComputedStyle } from "../style/computed.ts";
4
+ import { type Matrix } from "../transform/matrix.ts";
5
+ import { type LayerPlacement } from "../paths/paths.ts";
6
+ import type { PaintContext } from "../paint/paint.ts";
7
+ import type { ReportNote } from "../report/report.ts";
8
+ /** What the text builder needs from the walk. */
9
+ export interface TextContext extends PaintContext {
10
+ /** True while building a clipPath's content, which paints by geometry only. */
11
+ readonly insideClipPath?: boolean;
12
+ readonly idSource: () => string;
13
+ readonly fontAvailable: SvgFontAvailable;
14
+ readonly measureText: SvgMeasureText;
15
+ /** The requested `font-style` of each text layer's runs, by layer ID, in run order (see `SvgImportResult.textRunStyles`). */
16
+ readonly textRunStyles: Map<string, readonly SvgTextFontStyle[]>;
17
+ readonly report: (elementPath: string, element: string, kind: "left-out" | "approximated", reason: string, note: ReportNote) => void;
18
+ }
19
+ /** The result of building one `<text>` element: the top layer plus every node created. */
20
+ export interface TextResult {
21
+ readonly top: TextNode | GroupNode;
22
+ readonly nodes: readonly (TextNode | GroupNode)[];
23
+ }
24
+ /**
25
+ * Builds the text layers of one `<text>` element: one layer when every
26
+ * `<tspan>` stays on the same line, or one layer per line wrapped in a
27
+ * group when a `<tspan>` moves. Returns null for text without content.
28
+ */
29
+ export declare function textLayer(element: SvgElementLike, computed: ComputedStyle, matrix: Matrix, placement: LayerPlacement, elementPath: string, ctx: TextContext): TextResult | null;