@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,307 @@
1
+ /**
2
+ * Evaluates the query of an `@media` rule for the one screen an import
3
+ * draws on: a light-scheme screen the size of the SVG's root, with no
4
+ * reduced motion, contrast or forced colours asked for. That is the look
5
+ * the import keeps (an import takes the light look, as Figma does).
6
+ *
7
+ * Only a small part of Media Queries is read: media types, `not`/`only`,
8
+ * `and`/`or` chains, and the features listed in `DISCRETE_FEATURES`.
9
+ * Anything else makes the answer `null` (cannot be evaluated), so the
10
+ * caller reports the rule instead of guessing. An unknown media type or
11
+ * feature name is not "anything else": it is a valid query that is false —
12
+ * a feature even under `not` (Media Queries 4 §4.1).
13
+ */
14
+ /** Whether the media query list applies; null when it cannot be evaluated. */
15
+ export function evaluateMediaQueryList(prelude, environment) {
16
+ const text = prelude.trim();
17
+ if (text.length === 0)
18
+ return true;
19
+ const answers = splitCommas(text).map((query) => evaluateQuery(query.trim().toLowerCase(), environment));
20
+ if (answers.includes(true))
21
+ return true;
22
+ return answers.includes(null) ? null : false;
23
+ }
24
+ function evaluateQuery(query, environment) {
25
+ const tokens = tokenize(query);
26
+ if (tokens === null || tokens.length === 0)
27
+ return null;
28
+ const unknown = { seen: false };
29
+ const first = tokens[0];
30
+ const second = tokens[1];
31
+ let result;
32
+ if (first.kind === "word" && (first.text === "not" || first.text === "only") && second?.kind === "word") {
33
+ const rest = evaluateTypeQuery(tokens.slice(1), environment, unknown);
34
+ result = first.text === "not" ? not(rest) : rest;
35
+ }
36
+ else if (first.kind === "word" && first.text !== "not") {
37
+ result = evaluateTypeQuery(tokens, environment, unknown);
38
+ }
39
+ else {
40
+ result = evaluateCondition(tokens, environment, 0, unknown);
41
+ }
42
+ // An unknown media feature makes the whole query false, and `not` does
43
+ // not flip it (Media Queries 4 §4.1; probed in Chromium). A query that
44
+ // cannot be parsed stays unevaluable instead.
45
+ return unknown.seen && result !== null ? false : result;
46
+ }
47
+ /** `type [and (feature)]*`. */
48
+ function evaluateTypeQuery(tokens, environment, unknown) {
49
+ const type = tokens[0];
50
+ if (type.kind !== "word")
51
+ return null;
52
+ const answers = [mediaType(type.text)];
53
+ for (let index = 1; index < tokens.length; index += 2) {
54
+ const joiner = tokens[index];
55
+ const group = tokens[index + 1];
56
+ if (joiner.kind !== "word" || joiner.text !== "and" || group?.kind !== "group")
57
+ return null;
58
+ answers.push(evaluateGroup(group.text, environment, 0, unknown));
59
+ }
60
+ return and(answers);
61
+ }
62
+ /** `not (x)`, or `(x) [and (y)]*`, or `(x) [or (y)]*`. */
63
+ function evaluateCondition(tokens, environment, depth, unknown) {
64
+ const first = tokens[0];
65
+ if (first.kind === "word") {
66
+ if (first.text !== "not" || tokens.length !== 2 || tokens[1].kind !== "group")
67
+ return null;
68
+ return not(evaluateGroup(tokens[1].text, environment, depth, unknown));
69
+ }
70
+ const answers = [evaluateGroup(first.text, environment, depth, unknown)];
71
+ let joinerText = null;
72
+ for (let index = 1; index < tokens.length; index += 2) {
73
+ const joiner = tokens[index];
74
+ const group = tokens[index + 1];
75
+ if (joiner.kind !== "word" || (joiner.text !== "and" && joiner.text !== "or") || group?.kind !== "group")
76
+ return null;
77
+ if (joinerText !== null && joinerText !== joiner.text)
78
+ return null;
79
+ joinerText = joiner.text;
80
+ answers.push(evaluateGroup(group.text, environment, depth, unknown));
81
+ }
82
+ return joinerText === "or" ? or(answers) : and(answers);
83
+ }
84
+ /** Maximum nesting of condition groups read; a deeper query cannot be evaluated, so the stack stays bounded. */
85
+ const MAX_CONDITION_DEPTH = 32;
86
+ /** The inside of a parenthesised group: a nested condition or one feature. */
87
+ function evaluateGroup(inside, environment, depth, unknown) {
88
+ const text = inside.trim();
89
+ if (text.startsWith("(") || text.startsWith("not ") || text.startsWith("not(")) {
90
+ if (depth + 1 >= MAX_CONDITION_DEPTH)
91
+ return null;
92
+ const tokens = tokenize(text);
93
+ return tokens === null || tokens.length === 0 ? null : evaluateCondition(tokens, environment, depth + 1, unknown);
94
+ }
95
+ return evaluateFeature(text, environment, unknown);
96
+ }
97
+ const MEDIA_TYPES = { all: true, screen: true, print: false, speech: false };
98
+ /**
99
+ * A media type's truth on the import's screen. An unknown type is a valid
100
+ * query that is false (Media Queries 4 §4.1), so `not` on it applies and
101
+ * `and` with it does not; only a query that cannot be parsed is null.
102
+ */
103
+ function mediaType(name) {
104
+ return MEDIA_TYPES[name] ?? false;
105
+ }
106
+ /** The value a discrete feature has on the import's screen, and its value in a boolean context. */
107
+ const DISCRETE_FEATURES = {
108
+ "prefers-color-scheme": { value: "light", known: ["light", "dark"] },
109
+ "prefers-reduced-motion": { value: "no-preference", known: ["no-preference", "reduce"] },
110
+ "prefers-reduced-transparency": { value: "no-preference", known: ["no-preference", "reduce"] },
111
+ "prefers-reduced-data": { value: "no-preference", known: ["no-preference", "reduce"] },
112
+ "prefers-contrast": { value: "no-preference", known: ["no-preference", "more", "less", "custom"] },
113
+ "forced-colors": { value: "none", known: ["none", "active"] },
114
+ "inverted-colors": { value: "none", known: ["none", "inverted"] },
115
+ };
116
+ /** Values that are false in a boolean context, such as `(prefers-reduced-motion)`. */
117
+ const BOOLEAN_FALSE = new Set(["no-preference", "none"]);
118
+ const RANGE_PATTERN = /^([a-z-]+)\s*(<=|>=|<|>|=)\s*(.+)$/;
119
+ /**
120
+ * Every media feature name a browser knows (Media Queries 4 and 5, plus the
121
+ * deprecated device-* ones), the modeled ones included. A name outside this
122
+ * set is an unknown feature, which makes its query false; a name inside it
123
+ * that the import does not model stays "cannot be evaluated", so the rule
124
+ * is reported instead of guessed.
125
+ */
126
+ const KNOWN_FEATURES = new Set([
127
+ "width", "height", "aspect-ratio", "orientation",
128
+ "prefers-color-scheme", "prefers-reduced-motion", "prefers-reduced-transparency", "prefers-reduced-data",
129
+ "prefers-contrast", "forced-colors", "inverted-colors",
130
+ "any-hover", "any-pointer", "color", "color-gamut", "color-index",
131
+ "device-aspect-ratio", "device-height", "device-width", "display-mode", "dynamic-range",
132
+ "environment-blending", "grid", "horizontal-viewport-segments", "hover", "light-level",
133
+ "monochrome", "overflow-block", "overflow-inline", "pointer", "resolution",
134
+ "scan", "scripting", "update", "vertical-viewport-segments", "video-dynamic-range",
135
+ ]);
136
+ /** A feature's leading name, such as `min-width`, if the text starts with one. */
137
+ const FEATURE_NAME_PATTERN = /^([a-z][a-z0-9-]*)/;
138
+ function evaluateFeature(text, environment, unknown) {
139
+ const nameMatch = FEATURE_NAME_PATTERN.exec(text);
140
+ if (nameMatch !== null) {
141
+ const name = nameMatch[1];
142
+ const base = name.startsWith("min-") || name.startsWith("max-") ? name.slice(4) : name;
143
+ if (!KNOWN_FEATURES.has(base)) {
144
+ unknown.seen = true;
145
+ return false;
146
+ }
147
+ }
148
+ const colon = text.indexOf(":");
149
+ if (colon === -1) {
150
+ const range = RANGE_PATTERN.exec(text);
151
+ if (range !== null)
152
+ return compareRange(range[1], range[2], range[3].trim(), environment);
153
+ return booleanFeature(text, environment);
154
+ }
155
+ const name = text.slice(0, colon).trim();
156
+ const value = text.slice(colon + 1).trim();
157
+ const discrete = DISCRETE_FEATURES[name];
158
+ if (discrete !== undefined)
159
+ return discrete.known.includes(value) ? value === discrete.value : null;
160
+ if (name === "orientation") {
161
+ if (environment.size === null || (value !== "portrait" && value !== "landscape"))
162
+ return null;
163
+ const portrait = environment.size.height >= environment.size.width;
164
+ return value === (portrait ? "portrait" : "landscape");
165
+ }
166
+ for (const prefix of ["min-", "max-", ""]) {
167
+ if (!name.startsWith(prefix))
168
+ continue;
169
+ const op = prefix === "min-" ? ">=" : prefix === "max-" ? "<=" : "=";
170
+ const base = name.slice(prefix.length);
171
+ if (base === "width" || base === "height" || base === "aspect-ratio")
172
+ return compareRange(base, op, value, environment);
173
+ }
174
+ return null;
175
+ }
176
+ function booleanFeature(name, environment) {
177
+ const discrete = DISCRETE_FEATURES[name];
178
+ if (discrete !== undefined)
179
+ return !BOOLEAN_FALSE.has(discrete.value);
180
+ if (name === "width" || name === "height") {
181
+ return environment.size === null ? null : environment.size[name] !== 0;
182
+ }
183
+ return null;
184
+ }
185
+ /** `name op value` for width, height and aspect-ratio, on the import's screen. */
186
+ function compareRange(name, op, valueText, environment) {
187
+ if (environment.size === null)
188
+ return null;
189
+ const { width, height } = environment.size;
190
+ let actual;
191
+ let wanted;
192
+ if (name === "width" || name === "height") {
193
+ actual = name === "width" ? width : height;
194
+ wanted = lengthInPixels(valueText);
195
+ }
196
+ else if (name === "aspect-ratio") {
197
+ actual = width / height;
198
+ wanted = ratio(valueText);
199
+ }
200
+ else {
201
+ return null;
202
+ }
203
+ if (wanted === null)
204
+ return null;
205
+ switch (op) {
206
+ case "<": return actual < wanted;
207
+ case "<=": return actual <= wanted;
208
+ case ">": return actual > wanted;
209
+ case ">=": return actual >= wanted;
210
+ default: return actual === wanted;
211
+ }
212
+ }
213
+ const LENGTH_PATTERN = /^(-?\d*\.?\d+)(px|em|rem)?$/;
214
+ /** A length in CSS pixels: `px`, or `em`/`rem` at the initial 16 px font size; a unitless number only when it is 0. */
215
+ function lengthInPixels(text) {
216
+ const match = LENGTH_PATTERN.exec(text);
217
+ if (match === null)
218
+ return null;
219
+ const value = Number(match[1]);
220
+ const unit = match[2];
221
+ if (unit === undefined)
222
+ return value === 0 ? 0 : null;
223
+ return unit === "px" ? value : value * 16;
224
+ }
225
+ const RATIO_PATTERN = /^(\d*\.?\d+)\s*(?:\/\s*(\d*\.?\d+))?$/;
226
+ function ratio(text) {
227
+ const match = RATIO_PATTERN.exec(text);
228
+ if (match === null)
229
+ return null;
230
+ const top = Number(match[1]);
231
+ const bottom = match[2] === undefined ? 1 : Number(match[2]);
232
+ return bottom === 0 ? null : top / bottom;
233
+ }
234
+ function not(value) {
235
+ return value === null ? null : !value;
236
+ }
237
+ function and(values) {
238
+ if (values.includes(false))
239
+ return false;
240
+ return values.includes(null) ? null : true;
241
+ }
242
+ function or(values) {
243
+ if (values.includes(true))
244
+ return true;
245
+ return values.includes(null) ? null : false;
246
+ }
247
+ /** Splits words and parenthesised groups; null on unbalanced parentheses or any other character. */
248
+ function tokenize(text) {
249
+ const tokens = [];
250
+ let pos = 0;
251
+ while (pos < text.length) {
252
+ const ch = text.charAt(pos);
253
+ if (/\s/.test(ch)) {
254
+ pos += 1;
255
+ }
256
+ else if (ch === "(") {
257
+ let depth = 0;
258
+ let end = -1;
259
+ for (let index = pos; index < text.length; index += 1) {
260
+ const inner = text.charAt(index);
261
+ if (inner === "(")
262
+ depth += 1;
263
+ else if (inner === ")") {
264
+ depth -= 1;
265
+ if (depth === 0) {
266
+ end = index;
267
+ break;
268
+ }
269
+ }
270
+ }
271
+ if (end === -1)
272
+ return null;
273
+ tokens.push({ kind: "group", text: text.slice(pos + 1, end) });
274
+ pos = end + 1;
275
+ }
276
+ else if (/[a-z-]/.test(ch)) {
277
+ let end = pos;
278
+ while (end < text.length && /[a-z0-9-]/.test(text.charAt(end)))
279
+ end += 1;
280
+ tokens.push({ kind: "word", text: text.slice(pos, end) });
281
+ pos = end;
282
+ }
283
+ else {
284
+ return null;
285
+ }
286
+ }
287
+ return tokens;
288
+ }
289
+ /** Splits on commas outside parentheses. */
290
+ function splitCommas(text) {
291
+ const parts = [];
292
+ let depth = 0;
293
+ let start = 0;
294
+ for (let index = 0; index < text.length; index += 1) {
295
+ const ch = text.charAt(index);
296
+ if (ch === "(")
297
+ depth += 1;
298
+ else if (ch === ")")
299
+ depth = Math.max(0, depth - 1);
300
+ else if (ch === "," && depth === 0) {
301
+ parts.push(text.slice(start, index));
302
+ start = index + 1;
303
+ }
304
+ }
305
+ parts.push(text.slice(start));
306
+ return parts;
307
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Every SVG presentation property (and the CSS properties SVG content
3
+ * commonly carries) the import recognises, with what it does with each one.
4
+ * This is the one list: the cascade reads the `applied` ones as presentation
5
+ * attributes and declarations, passes the `ignored` ones by and reports any
6
+ * `unsupported` one whose value is not one of its defaults.
7
+ *
8
+ * - `applied`: the cascade reads it into the computed style (or, for
9
+ * `transform`, the walk reads the attribute and the cascade notes a winning
10
+ * CSS transform, which overrides the attribute). `cssOnly` marks a
11
+ * shorthand that is not a presentation attribute.
12
+ * - `ignored`: it never changes the drawing the model can make, so any value
13
+ * passes silently; `why` says why.
14
+ * - `unsupported`: it can change the drawing and the import does not apply
15
+ * it. A value in `defaults` (compared lower case, spaces collapsed) draws
16
+ * the same as leaving it out, so it passes; any other value adds the
17
+ * property to the element's "not supported" report line.
18
+ *
19
+ * An `unsupported` entry with `cssOnly` is read only from CSS, as browsers
20
+ * read no attribute of that name.
21
+ *
22
+ * Geometry properties (`x`, `y`, `width`, `height`, `cx`, `cy`, `r`, `rx`,
23
+ * `ry`, `d`) are read from attributes by each shape. SVG 2 lets CSS set them
24
+ * too, which the import does not apply, so they are listed `unsupported`
25
+ * with `cssOnly`: the cascade reports a non-default CSS value and leaves the
26
+ * attributes to the shapes.
27
+ */
28
+ export type PropertySupport = {
29
+ readonly kind: "applied";
30
+ readonly cssOnly?: true;
31
+ } | {
32
+ readonly kind: "ignored";
33
+ readonly why: string;
34
+ } | {
35
+ readonly kind: "unsupported";
36
+ readonly defaults: readonly string[];
37
+ readonly cssOnly?: true;
38
+ };
39
+ export declare const PRESENTATION_PROPERTIES: Readonly<Record<string, PropertySupport>>;
40
+ /** Whether a value of a listed `unsupported` property changes the drawing, so it must be reported. */
41
+ export declare function isUnsupportedValue(property: string, value: string): boolean;
42
+ /** The presentation attributes the cascade reads: every listed property but the CSS-only ones. */
43
+ export declare const PRESENTATION_ATTRIBUTE_NAMES: readonly string[];
@@ -0,0 +1,135 @@
1
+ const APPLIED = { kind: "applied" };
2
+ const CSS_ONLY = { kind: "applied", cssOnly: true };
3
+ const ignored = (why) => ({ kind: "ignored", why });
4
+ const unsupported = (...defaults) => ({ kind: "unsupported", defaults });
5
+ const unsupportedInCss = (...defaults) => ({ kind: "unsupported", defaults, cssOnly: true });
6
+ const NO_DRAWING = "it changes interaction, not the drawing";
7
+ const RENDERING_HINT = "it is a rendering-quality hint; the editor's renderer chooses its own";
8
+ const BROWSERS_IGNORE = "browsers ignore it, so it does not change the drawing";
9
+ export const PRESENTATION_PROPERTIES = {
10
+ // Paint, stroke and compositing.
11
+ "fill": APPLIED,
12
+ "fill-opacity": APPLIED,
13
+ "fill-rule": APPLIED,
14
+ "clip-rule": APPLIED,
15
+ "stroke": APPLIED,
16
+ "stroke-width": APPLIED,
17
+ "stroke-opacity": APPLIED,
18
+ "stroke-linecap": APPLIED,
19
+ "stroke-linejoin": APPLIED,
20
+ "stroke-miterlimit": APPLIED,
21
+ "stroke-dasharray": APPLIED,
22
+ "stroke-dashoffset": APPLIED,
23
+ "color": APPLIED,
24
+ "opacity": APPLIED,
25
+ "display": APPLIED,
26
+ "visibility": APPLIED,
27
+ "clip-path": APPLIED,
28
+ "mask": APPLIED,
29
+ "filter": APPLIED,
30
+ "mix-blend-mode": APPLIED,
31
+ "vector-effect": APPLIED,
32
+ "mask-type": APPLIED,
33
+ "overflow": APPLIED,
34
+ "paint-order": APPLIED,
35
+ "marker-start": APPLIED,
36
+ "marker-mid": APPLIED,
37
+ "marker-end": APPLIED,
38
+ "marker": CSS_ONLY,
39
+ "stop-color": APPLIED,
40
+ "stop-opacity": APPLIED,
41
+ // The offset attribute is read by the gradient's stops, outside the
42
+ // cascade; as a CSS declaration, Chromium parses `offset` as the
43
+ // motion-path shorthand, which never moves a stop.
44
+ "offset": ignored("a stop's offset attribute is read by the gradient; a CSS offset declaration is the motion-path shorthand in browsers, which never moves a stop"),
45
+ "flood-color": APPLIED,
46
+ "flood-opacity": APPLIED,
47
+ "transform": APPLIED,
48
+ "isolation": unsupported("auto"),
49
+ "transform-origin": unsupported("0 0", "0px 0px", "0", "0px", "0 0 0", "0px 0px 0px", "left top", "top left"),
50
+ "transform-box": unsupported("view-box"),
51
+ "clip": unsupported("auto"),
52
+ "image-rendering": unsupported("auto", "optimizequality", "smooth", "high-quality"),
53
+ // Text.
54
+ "font": CSS_ONLY,
55
+ "font-family": APPLIED,
56
+ "font-size": APPLIED,
57
+ "font-weight": APPLIED,
58
+ "font-style": APPLIED,
59
+ "letter-spacing": APPLIED,
60
+ "text-decoration": APPLIED,
61
+ "text-anchor": APPLIED,
62
+ "font-stretch": unsupported("normal", "100%"),
63
+ "font-variant": unsupported("normal"),
64
+ "font-variant-caps": unsupported("normal"),
65
+ "font-variant-ligatures": unsupported("normal"),
66
+ "font-variant-numeric": unsupported("normal"),
67
+ "font-variant-east-asian": unsupported("normal"),
68
+ "font-variant-position": unsupported("normal"),
69
+ "font-feature-settings": unsupported("normal"),
70
+ "font-variation-settings": unsupported("normal"),
71
+ "font-kerning": unsupported("auto", "normal"),
72
+ "font-size-adjust": unsupported("none"),
73
+ "word-spacing": unsupported("normal", "0", "0px"),
74
+ "writing-mode": unsupported("horizontal-tb", "lr", "lr-tb", "rl", "rl-tb"),
75
+ "direction": unsupported("ltr"),
76
+ "unicode-bidi": unsupported("normal"),
77
+ "dominant-baseline": unsupported("auto"),
78
+ "alignment-baseline": unsupported("auto", "baseline"),
79
+ "baseline-shift": unsupported("baseline", "0", "0px"),
80
+ "white-space": unsupported("normal"),
81
+ "inline-size": unsupported("auto", "0", "0px"),
82
+ "shape-inside": unsupported("none"),
83
+ "text-decoration-line": unsupported("none"),
84
+ "text-decoration-style": unsupported("solid"),
85
+ "text-decoration-color": unsupported("currentcolor"),
86
+ "text-decoration-thickness": unsupported("auto"),
87
+ "text-overflow": unsupported("clip"),
88
+ // Not a presentation attribute in SVG 2 or browsers; CSS only.
89
+ "text-transform": unsupportedInCss("none"),
90
+ "line-height": ignored("SVG text is laid out one line per position, so the line height never moves it"),
91
+ "glyph-orientation-vertical": ignored("it only turns glyphs in vertical text, which writing-mode reports"),
92
+ "glyph-orientation-horizontal": ignored(BROWSERS_IGNORE),
93
+ "kerning": ignored(BROWSERS_IGNORE),
94
+ // Geometry set from CSS; the attributes are read by each shape.
95
+ "x": unsupportedInCss("0", "0px"),
96
+ "y": unsupportedInCss("0", "0px"),
97
+ "width": unsupportedInCss("auto"),
98
+ "height": unsupportedInCss("auto"),
99
+ "cx": unsupportedInCss("0", "0px"),
100
+ "cy": unsupportedInCss("0", "0px"),
101
+ "r": unsupportedInCss("0", "0px"),
102
+ "rx": unsupportedInCss("auto"),
103
+ "ry": unsupportedInCss("auto"),
104
+ "d": unsupportedInCss("none"),
105
+ // Rendering hints and interaction.
106
+ "shape-rendering": ignored(RENDERING_HINT),
107
+ "text-rendering": ignored(RENDERING_HINT),
108
+ "color-rendering": ignored(RENDERING_HINT),
109
+ // linearRGB changes the colours between gradient stops; the model mixes them in sRGB.
110
+ "color-interpolation": unsupported("auto", "srgb"),
111
+ "color-profile": ignored(BROWSERS_IGNORE),
112
+ "enable-background": ignored(BROWSERS_IGNORE),
113
+ "color-interpolation-filters": ignored("the drop shadows and blurs the import maps differ between sRGB and linearRGB only at their blurred edges"),
114
+ "lighting-color": ignored("only lighting filters read it, and the import reports those filters"),
115
+ "pointer-events": ignored(NO_DRAWING),
116
+ "cursor": ignored(NO_DRAWING),
117
+ };
118
+ /** A value lower cased with its white space collapsed, as `defaults` lists it. */
119
+ function normalised(value) {
120
+ return value.trim().toLowerCase().replace(/\s+/g, " ");
121
+ }
122
+ /** CSS-wide keywords that leave an unsupported property at its default here. */
123
+ const WIDE_KEYWORDS = new Set(["initial", "unset", "revert", "revert-layer"]);
124
+ /** Whether a value of a listed `unsupported` property changes the drawing, so it must be reported. */
125
+ export function isUnsupportedValue(property, value) {
126
+ const support = PRESENTATION_PROPERTIES[property];
127
+ if (support?.kind !== "unsupported")
128
+ return false;
129
+ const keyword = normalised(value);
130
+ return !WIDE_KEYWORDS.has(keyword) && !support.defaults.includes(keyword);
131
+ }
132
+ /** The presentation attributes the cascade reads: every listed property but the CSS-only ones. */
133
+ export const PRESENTATION_ATTRIBUTE_NAMES = Object.entries(PRESENTATION_PROPERTIES)
134
+ .filter(([name, support]) => name !== "transform" && !("cssOnly" in support && support.cssOnly === true))
135
+ .map(([name]) => name);
@@ -0,0 +1,30 @@
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
+ /** What the elements of one SVG carry, collected by the pre-pass. */
17
+ export interface SelectorReachIndex {
18
+ readonly classes: ReadonlySet<string>;
19
+ readonly ids: ReadonlySet<string>;
20
+ /** Attribute names, lowercased. */
21
+ readonly attributes: ReadonlySet<string>;
22
+ }
23
+ /** True only when the selector surely matches no element of the SVG. */
24
+ export declare function selectorCannotMatch(selector: string, index: SelectorReachIndex): boolean;
25
+ /**
26
+ * How deep `:is()` and `:where()` may nest before the reader stops following
27
+ * them and answers "might match". It keeps the recursion off the call stack
28
+ * limit and bounds the rescanning that each level does.
29
+ */
30
+ export declare const MAX_SELECTOR_NESTING = 32;