blitz-pdf 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 (370) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +355 -2
  3. package/THIRD_PARTY_NOTICES.md +25 -0
  4. package/assets/icon.svg +4 -0
  5. package/dist/api.d.ts +7 -0
  6. package/dist/api.d.ts.map +1 -0
  7. package/dist/api.js +46 -0
  8. package/dist/api.js.map +1 -0
  9. package/dist/assets.d.ts +7 -0
  10. package/dist/assets.d.ts.map +1 -0
  11. package/dist/assets.js +52 -0
  12. package/dist/assets.js.map +1 -0
  13. package/dist/browser.d.ts +3 -0
  14. package/dist/browser.d.ts.map +1 -0
  15. package/dist/browser.js +3 -0
  16. package/dist/browser.js.map +1 -0
  17. package/dist/node.d.ts +3 -0
  18. package/dist/node.d.ts.map +1 -0
  19. package/dist/node.js +10 -0
  20. package/dist/node.js.map +1 -0
  21. package/dist/options.d.ts +24 -0
  22. package/dist/options.d.ts.map +1 -0
  23. package/dist/options.js +135 -0
  24. package/dist/options.js.map +1 -0
  25. package/dist/types.d.ts +51 -0
  26. package/dist/types.d.ts.map +1 -0
  27. package/dist/types.js +2 -0
  28. package/dist/types.js.map +1 -0
  29. package/examples/bun.ts +8 -0
  30. package/examples/german-invoice/README.md +70 -0
  31. package/examples/german-invoice/data.mjs +83 -0
  32. package/examples/german-invoice/invoice.css +59 -0
  33. package/examples/german-invoice/template.mjs +49 -0
  34. package/examples/german-invoice.mjs +20 -0
  35. package/examples/invoice.html +29 -0
  36. package/examples/node.mjs +8 -0
  37. package/examples/pagination.html +40 -0
  38. package/examples/pagination.mjs +8 -0
  39. package/licenses/DejaVu.txt +187 -0
  40. package/licenses/RUST_DEPENDENCIES.txt +11577 -0
  41. package/package.json +89 -4
  42. package/src/api.ts +44 -0
  43. package/src/assets.ts +43 -0
  44. package/src/browser.ts +6 -0
  45. package/src/node.ts +12 -0
  46. package/src/options.ts +101 -0
  47. package/src/types.ts +49 -0
  48. package/vendor/README.md +17 -0
  49. package/vendor/stylo/.cargo-ok +1 -0
  50. package/vendor/stylo/.cargo_vcs_info.json +6 -0
  51. package/vendor/stylo/Cargo.lock +1485 -0
  52. package/vendor/stylo/Cargo.toml +274 -0
  53. package/vendor/stylo/LICENSE +373 -0
  54. package/vendor/stylo/README.md +6 -0
  55. package/vendor/stylo/applicable_declarations.rs +328 -0
  56. package/vendor/stylo/author_styles.rs +79 -0
  57. package/vendor/stylo/bezier.rs +176 -0
  58. package/vendor/stylo/bloom.rs +414 -0
  59. package/vendor/stylo/build.rs +91 -0
  60. package/vendor/stylo/build_gecko.rs +393 -0
  61. package/vendor/stylo/color/color_function.rs +601 -0
  62. package/vendor/stylo/color/component.rs +207 -0
  63. package/vendor/stylo/color/convert.rs +935 -0
  64. package/vendor/stylo/color/gamut/raytrace.rs +265 -0
  65. package/vendor/stylo/color/gamut.rs +227 -0
  66. package/vendor/stylo/color/mix.rs +645 -0
  67. package/vendor/stylo/color/mod.rs +750 -0
  68. package/vendor/stylo/color/parsing.rs +770 -0
  69. package/vendor/stylo/color/to_css.rs +297 -0
  70. package/vendor/stylo/context.rs +716 -0
  71. package/vendor/stylo/counter_style/mod.rs +754 -0
  72. package/vendor/stylo/counter_style/predefined.rs +61 -0
  73. package/vendor/stylo/counter_style/update_predefined.py +35 -0
  74. package/vendor/stylo/custom_properties.rs +2023 -0
  75. package/vendor/stylo/custom_properties_map.rs +220 -0
  76. package/vendor/stylo/data.rs +693 -0
  77. package/vendor/stylo/device/gecko.rs +486 -0
  78. package/vendor/stylo/device/mod.rs +304 -0
  79. package/vendor/stylo/device/servo.rs +507 -0
  80. package/vendor/stylo/dom.rs +1164 -0
  81. package/vendor/stylo/dom_apis.rs +937 -0
  82. package/vendor/stylo/driver.rs +172 -0
  83. package/vendor/stylo/error_reporting.rs +484 -0
  84. package/vendor/stylo/font_face.rs +558 -0
  85. package/vendor/stylo/font_metrics.rs +124 -0
  86. package/vendor/stylo/gecko/anon_boxes.toml +113 -0
  87. package/vendor/stylo/gecko/arc_types.rs +211 -0
  88. package/vendor/stylo/gecko/conversions.rs +59 -0
  89. package/vendor/stylo/gecko/data.rs +222 -0
  90. package/vendor/stylo/gecko/media_features.rs +971 -0
  91. package/vendor/stylo/gecko/mod.rs +20 -0
  92. package/vendor/stylo/gecko/non_ts_pseudo_class_list.rs +119 -0
  93. package/vendor/stylo/gecko/pseudo_element.rs +640 -0
  94. package/vendor/stylo/gecko/pseudo_element_definition.mako.rs +298 -0
  95. package/vendor/stylo/gecko/pseudo_elements.py +137 -0
  96. package/vendor/stylo/gecko/pseudo_elements.toml +197 -0
  97. package/vendor/stylo/gecko/regen_pseudo_elements.py +33 -0
  98. package/vendor/stylo/gecko/restyle_damage.rs +127 -0
  99. package/vendor/stylo/gecko/selector_parser.rs +627 -0
  100. package/vendor/stylo/gecko/snapshot.rs +202 -0
  101. package/vendor/stylo/gecko/snapshot_helpers.rs +334 -0
  102. package/vendor/stylo/gecko/traversal.rs +52 -0
  103. package/vendor/stylo/gecko/wrapper.rs +2258 -0
  104. package/vendor/stylo/gecko_bindings/mod.rs +34 -0
  105. package/vendor/stylo/gecko_bindings/sugar/mod.rs +12 -0
  106. package/vendor/stylo/gecko_bindings/sugar/ns_com_ptr.rs +15 -0
  107. package/vendor/stylo/gecko_bindings/sugar/ns_compatibility.rs +19 -0
  108. package/vendor/stylo/gecko_bindings/sugar/ns_style_auto_array.rs +111 -0
  109. package/vendor/stylo/gecko_bindings/sugar/origin_flags.rs +31 -0
  110. package/vendor/stylo/gecko_bindings/sugar/ownership.rs +70 -0
  111. package/vendor/stylo/gecko_bindings/sugar/refptr.rs +299 -0
  112. package/vendor/stylo/gecko_string_cache/mod.rs +543 -0
  113. package/vendor/stylo/gecko_string_cache/namespace.rs +106 -0
  114. package/vendor/stylo/global_style_data.rs +224 -0
  115. package/vendor/stylo/invalidation/element/document_state.rs +156 -0
  116. package/vendor/stylo/invalidation/element/element_wrapper.rs +432 -0
  117. package/vendor/stylo/invalidation/element/invalidation_map.rs +1631 -0
  118. package/vendor/stylo/invalidation/element/invalidator.rs +1470 -0
  119. package/vendor/stylo/invalidation/element/mod.rs +13 -0
  120. package/vendor/stylo/invalidation/element/relative_selector.rs +1399 -0
  121. package/vendor/stylo/invalidation/element/restyle_hints.rs +226 -0
  122. package/vendor/stylo/invalidation/element/state_and_attributes.rs +756 -0
  123. package/vendor/stylo/invalidation/media_queries.rs +144 -0
  124. package/vendor/stylo/invalidation/mod.rs +10 -0
  125. package/vendor/stylo/invalidation/stylesheets.rs +745 -0
  126. package/vendor/stylo/invalidation/viewport_units.rs +71 -0
  127. package/vendor/stylo/lib.rs +336 -0
  128. package/vendor/stylo/logical_geometry.rs +1684 -0
  129. package/vendor/stylo/macros.rs +70 -0
  130. package/vendor/stylo/matching.rs +1226 -0
  131. package/vendor/stylo/media_queries/media_list.rs +168 -0
  132. package/vendor/stylo/media_queries/media_query.rs +190 -0
  133. package/vendor/stylo/media_queries/mod.rs +13 -0
  134. package/vendor/stylo/parallel.rs +205 -0
  135. package/vendor/stylo/parser.rs +276 -0
  136. package/vendor/stylo/piecewise_linear.rs +282 -0
  137. package/vendor/stylo/prefs.rs +33 -0
  138. package/vendor/stylo/properties/build.py +119 -0
  139. package/vendor/stylo/properties/cascade.rs +2704 -0
  140. package/vendor/stylo/properties/computed_value_flags.rs +206 -0
  141. package/vendor/stylo/properties/counted_unknown_properties.py +104 -0
  142. package/vendor/stylo/properties/counter_style_descriptors.toml +45 -0
  143. package/vendor/stylo/properties/data.py +1375 -0
  144. package/vendor/stylo/properties/declaration_block.rs +1788 -0
  145. package/vendor/stylo/properties/font_face_descriptors.toml +50 -0
  146. package/vendor/stylo/properties/gecko.mako.rs +1555 -0
  147. package/vendor/stylo/properties/helpers/animated_properties.mako.rs +800 -0
  148. package/vendor/stylo/properties/helpers.mako.rs +812 -0
  149. package/vendor/stylo/properties/longhands.toml +4305 -0
  150. package/vendor/stylo/properties/mod.rs +1857 -0
  151. package/vendor/stylo/properties/properties.html.mako +31 -0
  152. package/vendor/stylo/properties/properties.mako.rs +3103 -0
  153. package/vendor/stylo/properties/property_descriptors.toml +18 -0
  154. package/vendor/stylo/properties/shorthands.rs +4241 -0
  155. package/vendor/stylo/properties/shorthands.toml +575 -0
  156. package/vendor/stylo/properties/vendored_python/mako-1.3.10-py3-none-any.whl +0 -0
  157. package/vendor/stylo/properties/vendored_python/markupsafe/LICENSE.txt +28 -0
  158. package/vendor/stylo/properties/vendored_python/markupsafe/__init__.py +384 -0
  159. package/vendor/stylo/properties/vendored_python/toml-0.10.2-py2.py3-none-any.whl +0 -0
  160. package/vendor/stylo/properties/view_transition_descriptors.toml +11 -0
  161. package/vendor/stylo/properties_and_values/mod.rs +12 -0
  162. package/vendor/stylo/properties_and_values/registry.rs +65 -0
  163. package/vendor/stylo/properties_and_values/rule.rs +331 -0
  164. package/vendor/stylo/properties_and_values/syntax/ascii.rs +60 -0
  165. package/vendor/stylo/properties_and_values/syntax/data_type.rs +146 -0
  166. package/vendor/stylo/properties_and_values/syntax/mod.rs +437 -0
  167. package/vendor/stylo/properties_and_values/value.rs +758 -0
  168. package/vendor/stylo/queries/condition.rs +996 -0
  169. package/vendor/stylo/queries/feature.rs +199 -0
  170. package/vendor/stylo/queries/feature_expression.rs +1170 -0
  171. package/vendor/stylo/queries/mod.rs +19 -0
  172. package/vendor/stylo/queries/values.rs +46 -0
  173. package/vendor/stylo/rule_cache.rs +267 -0
  174. package/vendor/stylo/rule_collector.rs +554 -0
  175. package/vendor/stylo/rule_tree/core.rs +787 -0
  176. package/vendor/stylo/rule_tree/level.rs +396 -0
  177. package/vendor/stylo/rule_tree/map.rs +201 -0
  178. package/vendor/stylo/rule_tree/mod.rs +427 -0
  179. package/vendor/stylo/rule_tree/source.rs +80 -0
  180. package/vendor/stylo/rule_tree/unsafe_box.rs +78 -0
  181. package/vendor/stylo/scoped_tls.rs +80 -0
  182. package/vendor/stylo/selector_map.rs +1050 -0
  183. package/vendor/stylo/selector_parser.rs +305 -0
  184. package/vendor/stylo/servo/animation.rs +1922 -0
  185. package/vendor/stylo/servo/attr.rs +714 -0
  186. package/vendor/stylo/servo/encoding_support.rs +81 -0
  187. package/vendor/stylo/servo/media_features.rs +254 -0
  188. package/vendor/stylo/servo/mod.rs +16 -0
  189. package/vendor/stylo/servo/restyle_damage.rs +215 -0
  190. package/vendor/stylo/servo/selector_parser.rs +1036 -0
  191. package/vendor/stylo/servo/shadow_parts.rs +207 -0
  192. package/vendor/stylo/shared_lock.rs +271 -0
  193. package/vendor/stylo/sharing/checks.rs +281 -0
  194. package/vendor/stylo/sharing/mod.rs +1000 -0
  195. package/vendor/stylo/simple_buckets_map.rs +52 -0
  196. package/vendor/stylo/str.rs +168 -0
  197. package/vendor/stylo/style_adjuster.rs +1086 -0
  198. package/vendor/stylo/style_resolver.rs +658 -0
  199. package/vendor/stylo/stylesheet_set.rs +658 -0
  200. package/vendor/stylo/stylesheets/appearance_base_rule.rs +51 -0
  201. package/vendor/stylo/stylesheets/container_rule.rs +769 -0
  202. package/vendor/stylo/stylesheets/counter_style_rule.rs +7 -0
  203. package/vendor/stylo/stylesheets/document_rule.rs +272 -0
  204. package/vendor/stylo/stylesheets/font_face_rule.rs +7 -0
  205. package/vendor/stylo/stylesheets/font_feature_values_rule.rs +481 -0
  206. package/vendor/stylo/stylesheets/font_palette_values_rule.rs +304 -0
  207. package/vendor/stylo/stylesheets/import_rule.rs +259 -0
  208. package/vendor/stylo/stylesheets/keyframes_rule.rs +733 -0
  209. package/vendor/stylo/stylesheets/layer_rule.rs +221 -0
  210. package/vendor/stylo/stylesheets/loader.rs +29 -0
  211. package/vendor/stylo/stylesheets/margin_rule.rs +190 -0
  212. package/vendor/stylo/stylesheets/media_rule.rs +191 -0
  213. package/vendor/stylo/stylesheets/mod.rs +918 -0
  214. package/vendor/stylo/stylesheets/namespace_rule.rs +43 -0
  215. package/vendor/stylo/stylesheets/nested_declarations_rule.rs +51 -0
  216. package/vendor/stylo/stylesheets/origin.rs +249 -0
  217. package/vendor/stylo/stylesheets/page_rule.rs +354 -0
  218. package/vendor/stylo/stylesheets/position_try_rule.rs +68 -0
  219. package/vendor/stylo/stylesheets/property_rule.rs +5 -0
  220. package/vendor/stylo/stylesheets/rule_list.rs +167 -0
  221. package/vendor/stylo/stylesheets/rule_parser.rs +1189 -0
  222. package/vendor/stylo/stylesheets/rules_iterator.rs +397 -0
  223. package/vendor/stylo/stylesheets/scope_rule.rs +511 -0
  224. package/vendor/stylo/stylesheets/starting_style_rule.rs +54 -0
  225. package/vendor/stylo/stylesheets/style_rule.rs +80 -0
  226. package/vendor/stylo/stylesheets/stylesheet.rs +570 -0
  227. package/vendor/stylo/stylesheets/supports_rule.rs +486 -0
  228. package/vendor/stylo/stylesheets/view_transition_rule.rs +81 -0
  229. package/vendor/stylo/stylist.rs +5076 -0
  230. package/vendor/stylo/thread_state.rs +87 -0
  231. package/vendor/stylo/traversal.rs +765 -0
  232. package/vendor/stylo/traversal_flags.rs +68 -0
  233. package/vendor/stylo/typed_om/mod.rs +981 -0
  234. package/vendor/stylo/typed_om/numeric.rs +128 -0
  235. package/vendor/stylo/typed_om/numeric_declaration.rs +93 -0
  236. package/vendor/stylo/typed_om/numeric_type.rs +640 -0
  237. package/vendor/stylo/typed_om/sum_value.rs +426 -0
  238. package/vendor/stylo/url/gecko.rs +367 -0
  239. package/vendor/stylo/url/mod.rs +71 -0
  240. package/vendor/stylo/url/servo.rs +239 -0
  241. package/vendor/stylo/use_counters/mod.rs +137 -0
  242. package/vendor/stylo/values/animated/color.rs +103 -0
  243. package/vendor/stylo/values/animated/effects.rs +26 -0
  244. package/vendor/stylo/values/animated/font.rs +37 -0
  245. package/vendor/stylo/values/animated/grid.rs +161 -0
  246. package/vendor/stylo/values/animated/lists.rs +141 -0
  247. package/vendor/stylo/values/animated/mod.rs +550 -0
  248. package/vendor/stylo/values/animated/svg.rs +46 -0
  249. package/vendor/stylo/values/animated/text.rs +58 -0
  250. package/vendor/stylo/values/animated/transform.rs +1592 -0
  251. package/vendor/stylo/values/computed/align.rs +90 -0
  252. package/vendor/stylo/values/computed/angle.rs +130 -0
  253. package/vendor/stylo/values/computed/animation.rs +124 -0
  254. package/vendor/stylo/values/computed/background.rs +13 -0
  255. package/vendor/stylo/values/computed/basic_shape.rs +267 -0
  256. package/vendor/stylo/values/computed/border.rs +163 -0
  257. package/vendor/stylo/values/computed/box.rs +267 -0
  258. package/vendor/stylo/values/computed/calc.rs +334 -0
  259. package/vendor/stylo/values/computed/color.rs +161 -0
  260. package/vendor/stylo/values/computed/column.rs +11 -0
  261. package/vendor/stylo/values/computed/corner_shape.rs +155 -0
  262. package/vendor/stylo/values/computed/counters.rs +26 -0
  263. package/vendor/stylo/values/computed/easing.rs +109 -0
  264. package/vendor/stylo/values/computed/effects.rs +30 -0
  265. package/vendor/stylo/values/computed/flex.rs +19 -0
  266. package/vendor/stylo/values/computed/font.rs +1517 -0
  267. package/vendor/stylo/values/computed/image.rs +273 -0
  268. package/vendor/stylo/values/computed/length.rs +576 -0
  269. package/vendor/stylo/values/computed/length_percentage.rs +1055 -0
  270. package/vendor/stylo/values/computed/list.rs +16 -0
  271. package/vendor/stylo/values/computed/mod.rs +1141 -0
  272. package/vendor/stylo/values/computed/motion.rs +73 -0
  273. package/vendor/stylo/values/computed/outline.rs +7 -0
  274. package/vendor/stylo/values/computed/page.rs +77 -0
  275. package/vendor/stylo/values/computed/param.rs +9 -0
  276. package/vendor/stylo/values/computed/percentage.rs +143 -0
  277. package/vendor/stylo/values/computed/position.rs +273 -0
  278. package/vendor/stylo/values/computed/ratio.rs +88 -0
  279. package/vendor/stylo/values/computed/rect.rs +19 -0
  280. package/vendor/stylo/values/computed/resolution.rs +76 -0
  281. package/vendor/stylo/values/computed/svg.rs +66 -0
  282. package/vendor/stylo/values/computed/table.rs +7 -0
  283. package/vendor/stylo/values/computed/text.rs +199 -0
  284. package/vendor/stylo/values/computed/time.rs +83 -0
  285. package/vendor/stylo/values/computed/transform.rs +559 -0
  286. package/vendor/stylo/values/computed/tree_counting.rs +30 -0
  287. package/vendor/stylo/values/computed/ui.rs +23 -0
  288. package/vendor/stylo/values/computed/url.rs +12 -0
  289. package/vendor/stylo/values/distance.rs +139 -0
  290. package/vendor/stylo/values/generics/animation.rs +363 -0
  291. package/vendor/stylo/values/generics/background.rs +65 -0
  292. package/vendor/stylo/values/generics/basic_shape.rs +1389 -0
  293. package/vendor/stylo/values/generics/border.rs +303 -0
  294. package/vendor/stylo/values/generics/box.rs +552 -0
  295. package/vendor/stylo/values/generics/calc.rs +2986 -0
  296. package/vendor/stylo/values/generics/color.rs +318 -0
  297. package/vendor/stylo/values/generics/column.rs +44 -0
  298. package/vendor/stylo/values/generics/counters.rs +320 -0
  299. package/vendor/stylo/values/generics/easing.rs +132 -0
  300. package/vendor/stylo/values/generics/effects.rs +131 -0
  301. package/vendor/stylo/values/generics/flex.rs +34 -0
  302. package/vendor/stylo/values/generics/font.rs +376 -0
  303. package/vendor/stylo/values/generics/grid.rs +962 -0
  304. package/vendor/stylo/values/generics/image.rs +653 -0
  305. package/vendor/stylo/values/generics/length.rs +656 -0
  306. package/vendor/stylo/values/generics/mod.rs +303 -0
  307. package/vendor/stylo/values/generics/motion.rs +274 -0
  308. package/vendor/stylo/values/generics/page.rs +167 -0
  309. package/vendor/stylo/values/generics/position.rs +669 -0
  310. package/vendor/stylo/values/generics/ratio.rs +88 -0
  311. package/vendor/stylo/values/generics/rect.rs +147 -0
  312. package/vendor/stylo/values/generics/size.rs +102 -0
  313. package/vendor/stylo/values/generics/svg.rs +226 -0
  314. package/vendor/stylo/values/generics/text.rs +268 -0
  315. package/vendor/stylo/values/generics/transform.rs +1157 -0
  316. package/vendor/stylo/values/generics/ui.rs +147 -0
  317. package/vendor/stylo/values/generics/url.rs +51 -0
  318. package/vendor/stylo/values/mod.rs +820 -0
  319. package/vendor/stylo/values/resolved/animation.rs +33 -0
  320. package/vendor/stylo/values/resolved/color.rs +53 -0
  321. package/vendor/stylo/values/resolved/counters.rs +45 -0
  322. package/vendor/stylo/values/resolved/mod.rs +316 -0
  323. package/vendor/stylo/values/specified/align.rs +711 -0
  324. package/vendor/stylo/values/specified/angle.rs +407 -0
  325. package/vendor/stylo/values/specified/animation.rs +921 -0
  326. package/vendor/stylo/values/specified/background.rs +270 -0
  327. package/vendor/stylo/values/specified/basic_shape.rs +986 -0
  328. package/vendor/stylo/values/specified/border.rs +430 -0
  329. package/vendor/stylo/values/specified/box.rs +2231 -0
  330. package/vendor/stylo/values/specified/calc.rs +1657 -0
  331. package/vendor/stylo/values/specified/color.rs +1210 -0
  332. package/vendor/stylo/values/specified/column.rs +11 -0
  333. package/vendor/stylo/values/specified/corner_shape.rs +152 -0
  334. package/vendor/stylo/values/specified/counters.rs +242 -0
  335. package/vendor/stylo/values/specified/easing.rs +225 -0
  336. package/vendor/stylo/values/specified/effects.rs +421 -0
  337. package/vendor/stylo/values/specified/flex.rs +42 -0
  338. package/vendor/stylo/values/specified/font.rs +2103 -0
  339. package/vendor/stylo/values/specified/frequency.rs +39 -0
  340. package/vendor/stylo/values/specified/grid.rs +407 -0
  341. package/vendor/stylo/values/specified/image.rs +1385 -0
  342. package/vendor/stylo/values/specified/intersection_observer.rs +80 -0
  343. package/vendor/stylo/values/specified/length.rs +2024 -0
  344. package/vendor/stylo/values/specified/list.rs +190 -0
  345. package/vendor/stylo/values/specified/mod.rs +531 -0
  346. package/vendor/stylo/values/specified/motion.rs +316 -0
  347. package/vendor/stylo/values/specified/number.rs +603 -0
  348. package/vendor/stylo/values/specified/outline.rs +69 -0
  349. package/vendor/stylo/values/specified/page.rs +94 -0
  350. package/vendor/stylo/values/specified/param.rs +121 -0
  351. package/vendor/stylo/values/specified/percentage.rs +364 -0
  352. package/vendor/stylo/values/specified/position.rs +2247 -0
  353. package/vendor/stylo/values/specified/ratio.rs +29 -0
  354. package/vendor/stylo/values/specified/rect.rs +28 -0
  355. package/vendor/stylo/values/specified/resolution.rs +237 -0
  356. package/vendor/stylo/values/specified/source_size_list.rs +135 -0
  357. package/vendor/stylo/values/specified/svg.rs +427 -0
  358. package/vendor/stylo/values/specified/svg_path.rs +1115 -0
  359. package/vendor/stylo/values/specified/table.rs +38 -0
  360. package/vendor/stylo/values/specified/text.rs +1561 -0
  361. package/vendor/stylo/values/specified/time.rs +313 -0
  362. package/vendor/stylo/values/specified/transform.rs +599 -0
  363. package/vendor/stylo/values/specified/tree_counting.rs +32 -0
  364. package/vendor/stylo/values/specified/ui.rs +344 -0
  365. package/vendor/stylo/values/specified/url.rs +12 -0
  366. package/vendor/stylo/values/tagged_numeric.rs +253 -0
  367. package/wasm/blitz_pdf.d.ts +67 -0
  368. package/wasm/blitz_pdf.js +699 -0
  369. package/wasm/blitz_pdf_bg.wasm +0 -0
  370. package/wasm/blitz_pdf_bg.wasm.d.ts +20 -0
@@ -0,0 +1,754 @@
1
+ /* This Source Code Form is subject to the terms of the Mozilla Public
2
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
3
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
+
5
+ //! The [`@counter-style`][counter-style] at-rule.
6
+ //!
7
+ //! [counter-style]: https://drafts.csswg.org/css-counter-styles/
8
+
9
+ use crate::derives::*;
10
+ use crate::error_reporting::ContextualParseError;
11
+ use crate::parser::{Parse, ParserContext};
12
+ use crate::shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
13
+ use crate::values::specified::Integer;
14
+ use crate::values::{AtomString, CustomIdent};
15
+ use crate::Atom;
16
+ use cssparser::{
17
+ ascii_case_insensitive_phf_map, match_ignore_ascii_case, CowRcStr, Parser, RuleBodyParser,
18
+ SourceLocation, Token,
19
+ };
20
+ use std::fmt::{self, Write};
21
+ use std::mem;
22
+ use std::num::Wrapping;
23
+ use style_traits::{
24
+ Comma, CssStringWriter, CssWriter, KeywordsCollectFn, OneOrMoreSeparated, ParseError,
25
+ SpecifiedValueInfo, StyleParseErrorKind, ToCss,
26
+ };
27
+
28
+ pub use crate::properties::counter_style::{DescriptorId, DescriptorParser, Descriptors};
29
+
30
+ /// https://drafts.csswg.org/css-counter-styles/#typedef-symbols-type
31
+ #[allow(missing_docs)]
32
+ #[derive(
33
+ Clone,
34
+ Copy,
35
+ Debug,
36
+ Deserialize,
37
+ Eq,
38
+ MallocSizeOf,
39
+ Parse,
40
+ PartialEq,
41
+ Serialize,
42
+ ToComputedValue,
43
+ ToCss,
44
+ ToResolvedValue,
45
+ ToShmem,
46
+ )]
47
+ #[repr(u8)]
48
+ pub enum SymbolsType {
49
+ Cyclic,
50
+ Numeric,
51
+ Alphabetic,
52
+ Symbolic,
53
+ Fixed,
54
+ }
55
+
56
+ /// <https://drafts.csswg.org/css-counter-styles/#typedef-counter-style>
57
+ ///
58
+ /// Note that 'none' is not a valid name, but we include this (along with String) for space
59
+ /// efficiency when storing list-style-type.
60
+ #[derive(
61
+ Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToCss, ToResolvedValue, ToShmem,
62
+ )]
63
+ #[repr(u8)]
64
+ pub enum CounterStyle {
65
+ /// The 'none' value.
66
+ None,
67
+ /// `<counter-style-name>`
68
+ Name(CustomIdent),
69
+ /// `symbols()`
70
+ #[css(function)]
71
+ Symbols {
72
+ /// The <symbols-type>, or symbolic if not specified.
73
+ #[css(skip_if = "is_symbolic")]
74
+ ty: SymbolsType,
75
+ /// The actual symbols.
76
+ symbols: Symbols,
77
+ },
78
+ /// A single string value, useful for `<list-style-type>`.
79
+ String(AtomString),
80
+ }
81
+
82
+ #[inline]
83
+ fn is_symbolic(symbols_type: &SymbolsType) -> bool {
84
+ *symbols_type == SymbolsType::Symbolic
85
+ }
86
+
87
+ impl CounterStyle {
88
+ /// disc value
89
+ pub fn disc() -> Self {
90
+ CounterStyle::Name(CustomIdent(atom!("disc")))
91
+ }
92
+
93
+ /// decimal value
94
+ pub fn decimal() -> Self {
95
+ CounterStyle::Name(CustomIdent(atom!("decimal")))
96
+ }
97
+
98
+ /// Is this a bullet? (i.e. `list-style-type: disc|circle|square|disclosure-closed|disclosure-open`)
99
+ #[inline]
100
+ pub fn is_bullet(&self) -> bool {
101
+ match self {
102
+ CounterStyle::Name(CustomIdent(name)) => {
103
+ name == &atom!("disc")
104
+ || name == &atom!("circle")
105
+ || name == &atom!("square")
106
+ || name == &atom!("disclosure-closed")
107
+ || name == &atom!("disclosure-open")
108
+ },
109
+ _ => false,
110
+ }
111
+ }
112
+
113
+ /// Returns whether this is a particular name.
114
+ pub fn is_name(&self, name: &Atom) -> bool {
115
+ match *self {
116
+ CounterStyle::Name(CustomIdent(ref n)) => n == name,
117
+ _ => false,
118
+ }
119
+ }
120
+ }
121
+
122
+ bitflags! {
123
+ #[derive(Clone, Copy)]
124
+ /// Flags to control parsing of counter styles.
125
+ pub struct CounterStyleParsingFlags: u8 {
126
+ /// Whether `none` is allowed.
127
+ const ALLOW_NONE = 1 << 0;
128
+ /// Whether a bare string is allowed.
129
+ const ALLOW_STRING = 1 << 1;
130
+ }
131
+ }
132
+
133
+ impl CounterStyle {
134
+ /// Parse a counter style, and optionally none|string (for list-style-type).
135
+ pub fn parse(
136
+ context: &ParserContext,
137
+ input: &mut Parser,
138
+ flags: CounterStyleParsingFlags,
139
+ ) -> Result<Self, ParseError> {
140
+ use self::CounterStyleParsingFlags as Flags;
141
+ match input.next()? {
142
+ Token::QuotedString(string) if flags.intersects(Flags::ALLOW_STRING) => {
143
+ Ok(Self::String(AtomString::from(string.as_ref())))
144
+ },
145
+ Token::Ident(ident) => {
146
+ if flags.intersects(Flags::ALLOW_NONE) && ident.eq_ignore_ascii_case("none") {
147
+ return Ok(Self::None);
148
+ }
149
+ Ok(Self::Name(counter_style_name_from_ident(ident)?))
150
+ },
151
+ Token::Function(name) if name.eq_ignore_ascii_case("symbols") => {
152
+ input.parse_nested_block(|input| {
153
+ let symbols_type = input
154
+ .try_parse(SymbolsType::parse)
155
+ .unwrap_or(SymbolsType::Symbolic);
156
+ let symbols = Symbols::parse(context, input)?;
157
+ // There must be at least two symbols for alphabetic or
158
+ // numeric system.
159
+ if (symbols_type == SymbolsType::Alphabetic
160
+ || symbols_type == SymbolsType::Numeric)
161
+ && symbols.0.len() < 2
162
+ {
163
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
164
+ }
165
+ // Identifier is not allowed in symbols() function.
166
+ if symbols.0.iter().any(|sym| !sym.is_allowed_in_symbols()) {
167
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
168
+ }
169
+ Ok(Self::Symbols {
170
+ ty: symbols_type,
171
+ symbols,
172
+ })
173
+ })
174
+ },
175
+ _ => Err(ParseError::unexpected_token()),
176
+ }
177
+ }
178
+ }
179
+
180
+ impl SpecifiedValueInfo for CounterStyle {
181
+ fn collect_completion_keywords(f: KeywordsCollectFn) {
182
+ // XXX The best approach for implementing this is probably
183
+ // having a CounterStyleName type wrapping CustomIdent, and
184
+ // put the predefined list for that type in counter_style mod.
185
+ // But that's a non-trivial change itself, so we use a simpler
186
+ // approach here.
187
+ macro_rules! predefined {
188
+ ($($name:expr,)+) => {
189
+ f(&["symbols", "none", $($name,)+])
190
+ }
191
+ }
192
+ include!("predefined.rs");
193
+ }
194
+ }
195
+
196
+ fn parse_counter_style_name(input: &mut Parser) -> Result<CustomIdent, ParseError> {
197
+ let ident = input.expect_ident()?;
198
+ counter_style_name_from_ident(ident)
199
+ }
200
+
201
+ /// This allows the reserved counter style names "decimal" and "disc".
202
+ fn counter_style_name_from_ident<'i>(ident: &CowRcStr<'i>) -> Result<CustomIdent, ParseError> {
203
+ macro_rules! predefined {
204
+ ($($name: tt,)+) => {{
205
+ ascii_case_insensitive_phf_map! {
206
+ predefined -> Atom = {
207
+ $(
208
+ $name => atom!($name),
209
+ )+
210
+ }
211
+ }
212
+
213
+ // This effectively performs case normalization only on predefined names.
214
+ if let Some(lower_case) = predefined::get(&ident) {
215
+ Ok(CustomIdent(lower_case.clone()))
216
+ } else {
217
+ // none is always an invalid <counter-style> value.
218
+ CustomIdent::from_ident(ident, &["none"])
219
+ }
220
+ }}
221
+ }
222
+ include!("predefined.rs")
223
+ }
224
+
225
+ fn is_valid_name_definition(ident: &CustomIdent) -> bool {
226
+ ident.0 != atom!("decimal")
227
+ && ident.0 != atom!("disc")
228
+ && ident.0 != atom!("circle")
229
+ && ident.0 != atom!("square")
230
+ && ident.0 != atom!("disclosure-closed")
231
+ && ident.0 != atom!("disclosure-open")
232
+ }
233
+
234
+ /// Parse the prelude of an @counter-style rule
235
+ pub fn parse_counter_style_name_definition(input: &mut Parser) -> Result<CustomIdent, ParseError> {
236
+ parse_counter_style_name(input).and_then(|ident| {
237
+ if !is_valid_name_definition(&ident) {
238
+ Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError))
239
+ } else {
240
+ Ok(ident)
241
+ }
242
+ })
243
+ }
244
+
245
+ /// A @counter-style rule
246
+ #[derive(Clone, Debug, ToShmem)]
247
+ pub struct CounterStyleRule {
248
+ name: CustomIdent,
249
+ generation: Wrapping<u32>,
250
+ descriptors: Descriptors,
251
+ /// The parser location of the @counter-style rule.
252
+ pub source_location: SourceLocation,
253
+ }
254
+
255
+ /// Parse the body (inside `{}`) of an @counter-style rule
256
+ pub fn parse_counter_style_body(
257
+ name: CustomIdent,
258
+ context: &ParserContext,
259
+ input: &mut Parser,
260
+ location: SourceLocation,
261
+ ) -> Result<CounterStyleRule, ParseError> {
262
+ let start = input.current_source_location();
263
+ let mut rule = CounterStyleRule::empty(name, location);
264
+ {
265
+ let mut parser = DescriptorParser {
266
+ context,
267
+ descriptors: &mut rule.descriptors,
268
+ };
269
+ let iter = RuleBodyParser::new(input, &mut parser);
270
+ for declaration in iter {
271
+ if let Err((error, slice, location)) = declaration {
272
+ let error = ContextualParseError::UnsupportedCounterStyleDescriptorDeclaration(
273
+ slice, error,
274
+ );
275
+ context.log_css_error(location, error)
276
+ }
277
+ }
278
+ }
279
+ let error = match *rule.resolved_system() {
280
+ ref system @ System::Cyclic
281
+ | ref system @ System::Fixed { .. }
282
+ | ref system @ System::Symbolic
283
+ | ref system @ System::Alphabetic
284
+ | ref system @ System::Numeric
285
+ if rule.descriptors.symbols.is_none() =>
286
+ {
287
+ let system = system.to_css_string();
288
+ Some(ContextualParseError::InvalidCounterStyleWithoutSymbols(
289
+ system,
290
+ ))
291
+ },
292
+ ref system @ System::Alphabetic | ref system @ System::Numeric
293
+ if rule.descriptors.symbols.as_ref().unwrap().0.len() < 2 =>
294
+ {
295
+ let system = system.to_css_string();
296
+ Some(ContextualParseError::InvalidCounterStyleNotEnoughSymbols(
297
+ system,
298
+ ))
299
+ },
300
+ System::Additive if rule.descriptors.additive_symbols.is_none() => {
301
+ Some(ContextualParseError::InvalidCounterStyleWithoutAdditiveSymbols)
302
+ },
303
+ System::Extends(_) if rule.descriptors.symbols.is_some() => {
304
+ Some(ContextualParseError::InvalidCounterStyleExtendsWithSymbols)
305
+ },
306
+ System::Extends(_) if rule.descriptors.additive_symbols.is_some() => {
307
+ Some(ContextualParseError::InvalidCounterStyleExtendsWithAdditiveSymbols)
308
+ },
309
+ _ => None,
310
+ };
311
+ if let Some(error) = error {
312
+ context.log_css_error(start, error);
313
+ Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError))
314
+ } else {
315
+ Ok(rule)
316
+ }
317
+ }
318
+
319
+ impl ToCssWithGuard for CounterStyleRule {
320
+ fn to_css(&self, _guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result {
321
+ dest.write_str("@counter-style ")?;
322
+ self.name.to_css(&mut CssWriter::new(dest))?;
323
+ dest.write_str(" { ")?;
324
+ self.descriptors.to_css(&mut CssWriter::new(dest))?;
325
+ dest.write_char('}')
326
+ }
327
+ }
328
+
329
+ // Implements the special checkers for some setters.
330
+ // See <https://drafts.csswg.org/css-counter-styles/#the-csscounterstylerule-interface>
331
+ impl CounterStyleRule {
332
+ fn empty(name: CustomIdent, source_location: SourceLocation) -> Self {
333
+ Self {
334
+ name,
335
+ generation: Wrapping(0),
336
+ descriptors: Descriptors::default(),
337
+ source_location,
338
+ }
339
+ }
340
+
341
+ /// Expose the descriptors as read-only, since we rely on updating our generation when they
342
+ /// change, and some setters need extra validation.
343
+ pub fn descriptors(&self) -> &Descriptors {
344
+ &self.descriptors
345
+ }
346
+
347
+ /// Set a descriptor, with the relevant validation. returns whether the descriptor changed.
348
+ pub fn set_descriptor(
349
+ &mut self,
350
+ id: DescriptorId,
351
+ context: &ParserContext,
352
+ input: &mut Parser,
353
+ ) -> Result<bool, ParseError> {
354
+ // Some descriptors need a couple extra checks, deal with them specially.
355
+ // TODO(emilio): Remove these, see https://github.com/w3c/csswg-drafts/issues/5717
356
+ if id == DescriptorId::AdditiveSymbols
357
+ && matches!(*self.resolved_system(), System::Extends(..))
358
+ {
359
+ // No additive symbols should be set for extends system.
360
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
361
+ }
362
+ let changed = match id {
363
+ DescriptorId::System => {
364
+ let system = input.parse_entirely(|i| System::parse(context, i))?;
365
+ if !self.check_system(&system) {
366
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
367
+ }
368
+ let new = Some(system);
369
+ if self.descriptors.system == new {
370
+ return Ok(false);
371
+ }
372
+ self.descriptors.system = new;
373
+ true
374
+ },
375
+ DescriptorId::Symbols => {
376
+ let symbols = input.parse_entirely(|i| Symbols::parse(context, i))?;
377
+ if !self.check_symbols(&symbols) {
378
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
379
+ }
380
+ let new = Some(symbols);
381
+ if self.descriptors.symbols == new {
382
+ return Ok(false);
383
+ }
384
+ self.descriptors.symbols = new;
385
+ true
386
+ },
387
+ _ => self.descriptors.set(id, context, input)?,
388
+ };
389
+ if changed {
390
+ self.generation += Wrapping(1);
391
+ }
392
+ Ok(changed)
393
+ }
394
+
395
+ /// Check that the system is effectively not changed. Only params of system descriptor is
396
+ /// changeable.
397
+ fn check_system(&self, value: &System) -> bool {
398
+ mem::discriminant(self.resolved_system()) == mem::discriminant(value)
399
+ }
400
+
401
+ fn check_symbols(&self, value: &Symbols) -> bool {
402
+ match *self.resolved_system() {
403
+ // These two systems require at least two symbols.
404
+ System::Numeric | System::Alphabetic => value.0.len() >= 2,
405
+ // No symbols should be set for extends system.
406
+ System::Extends(_) => false,
407
+ _ => true,
408
+ }
409
+ }
410
+
411
+ /// Get the name of the counter style rule.
412
+ pub fn name(&self) -> &CustomIdent {
413
+ &self.name
414
+ }
415
+
416
+ /// Set the name of the counter style rule. Caller must ensure that
417
+ /// the name is valid.
418
+ pub fn set_name(&mut self, name: CustomIdent) {
419
+ debug_assert!(is_valid_name_definition(&name));
420
+ self.name = name;
421
+ }
422
+
423
+ /// Get the current generation of the counter style rule.
424
+ pub fn generation(&self) -> u32 {
425
+ self.generation.0
426
+ }
427
+
428
+ /// Get the system of this counter style rule, default to
429
+ /// `symbolic` if not specified.
430
+ pub fn resolved_system(&self) -> &System {
431
+ match self.descriptors.system {
432
+ Some(ref system) => system,
433
+ None => &System::Symbolic,
434
+ }
435
+ }
436
+ }
437
+
438
+ /// <https://drafts.csswg.org/css-counter-styles/#counter-style-system>
439
+ #[derive(Clone, Debug, MallocSizeOf, ToShmem, PartialEq)]
440
+ pub enum System {
441
+ /// 'cyclic'
442
+ Cyclic,
443
+ /// 'numeric'
444
+ Numeric,
445
+ /// 'alphabetic'
446
+ Alphabetic,
447
+ /// 'symbolic'
448
+ Symbolic,
449
+ /// 'additive'
450
+ Additive,
451
+ /// 'fixed <integer>?'
452
+ Fixed {
453
+ /// '<integer>?'
454
+ first_symbol_value: Option<Integer>,
455
+ },
456
+ /// 'extends <counter-style-name>'
457
+ Extends(CustomIdent),
458
+ }
459
+
460
+ impl Parse for System {
461
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
462
+ try_match_ident_ignore_ascii_case! { input,
463
+ "cyclic" => Ok(System::Cyclic),
464
+ "numeric" => Ok(System::Numeric),
465
+ "alphabetic" => Ok(System::Alphabetic),
466
+ "symbolic" => Ok(System::Symbolic),
467
+ "additive" => Ok(System::Additive),
468
+ "fixed" => {
469
+ let first_symbol_value = input.try_parse(|i| Integer::parse(context, i)).ok();
470
+ Ok(System::Fixed { first_symbol_value })
471
+ },
472
+ "extends" => {
473
+ let other = parse_counter_style_name(input)?;
474
+ Ok(System::Extends(other))
475
+ },
476
+ }
477
+ }
478
+ }
479
+
480
+ impl ToCss for System {
481
+ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
482
+ where
483
+ W: Write,
484
+ {
485
+ match self {
486
+ System::Cyclic => dest.write_str("cyclic"),
487
+ System::Numeric => dest.write_str("numeric"),
488
+ System::Alphabetic => dest.write_str("alphabetic"),
489
+ System::Symbolic => dest.write_str("symbolic"),
490
+ System::Additive => dest.write_str("additive"),
491
+ System::Fixed { first_symbol_value } => {
492
+ if let Some(value) = first_symbol_value {
493
+ dest.write_str("fixed ")?;
494
+ value.to_css(dest)
495
+ } else {
496
+ dest.write_str("fixed")
497
+ }
498
+ },
499
+ System::Extends(other) => {
500
+ dest.write_str("extends ")?;
501
+ other.to_css(dest)
502
+ },
503
+ }
504
+ }
505
+ }
506
+
507
+ /// <https://drafts.csswg.org/css-counter-styles/#typedef-symbol>
508
+ #[derive(
509
+ Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToCss, ToShmem,
510
+ )]
511
+ #[repr(u8)]
512
+ pub enum Symbol {
513
+ /// <string>
514
+ String(crate::OwnedStr),
515
+ /// <custom-ident>
516
+ Ident(CustomIdent),
517
+ // Not implemented:
518
+ // /// <image>
519
+ // Image(Image),
520
+ }
521
+
522
+ impl Parse for Symbol {
523
+ fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
524
+ match *input.next()? {
525
+ Token::QuotedString(ref s) => Ok(Symbol::String(s.as_ref().to_owned().into())),
526
+ Token::Ident(ref s) => Ok(Symbol::Ident(CustomIdent::from_ident(s, &[])?)),
527
+ _ => Err(ParseError::unexpected_token()),
528
+ }
529
+ }
530
+ }
531
+
532
+ impl Symbol {
533
+ /// Returns whether this symbol is allowed in symbols() function.
534
+ pub fn is_allowed_in_symbols(&self) -> bool {
535
+ match self {
536
+ // Identifier is not allowed.
537
+ &Symbol::Ident(_) => false,
538
+ _ => true,
539
+ }
540
+ }
541
+ }
542
+
543
+ /// <https://drafts.csswg.org/css-counter-styles/#counter-style-negative>
544
+ #[derive(Clone, Debug, MallocSizeOf, ToCss, ToShmem, PartialEq)]
545
+ pub struct Negative(pub Symbol, pub Option<Symbol>);
546
+
547
+ impl Parse for Negative {
548
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
549
+ Ok(Negative(
550
+ Symbol::parse(context, input)?,
551
+ input.try_parse(|input| Symbol::parse(context, input)).ok(),
552
+ ))
553
+ }
554
+ }
555
+
556
+ /// <https://drafts.csswg.org/css-counter-styles/#counter-style-range>
557
+ #[derive(Clone, Debug, MallocSizeOf, ToCss, ToShmem, PartialEq)]
558
+ pub struct CounterRange {
559
+ /// The start of the range.
560
+ pub start: CounterBound,
561
+ /// The end of the range.
562
+ pub end: CounterBound,
563
+ }
564
+
565
+ /// <https://drafts.csswg.org/css-counter-styles/#counter-style-range>
566
+ ///
567
+ /// Empty represents 'auto'
568
+ #[derive(Clone, Debug, MallocSizeOf, ToCss, ToShmem, PartialEq)]
569
+ #[css(comma)]
570
+ pub struct CounterRanges(#[css(iterable, if_empty = "auto")] pub crate::OwnedSlice<CounterRange>);
571
+
572
+ /// A bound found in `CounterRanges`.
573
+ #[derive(Clone, Debug, MallocSizeOf, ToCss, ToShmem, PartialEq)]
574
+ pub enum CounterBound {
575
+ /// An integer bound.
576
+ Integer(Integer),
577
+ /// The infinite bound.
578
+ Infinite,
579
+ }
580
+
581
+ impl Parse for CounterRanges {
582
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
583
+ if input
584
+ .try_parse(|input| input.expect_ident_matching("auto"))
585
+ .is_ok()
586
+ {
587
+ return Ok(CounterRanges(Default::default()));
588
+ }
589
+
590
+ let ranges = input.parse_comma_separated(|input| {
591
+ let start = parse_bound(context, input)?;
592
+ let end = parse_bound(context, input)?;
593
+ if let (CounterBound::Integer(s), CounterBound::Integer(e)) = (&start, &end) {
594
+ // Rejects calc expressions that cannot be resolved at parse time,
595
+ // since @counter-style descriptors require concrete values.
596
+ let s = s.resolve();
597
+ let e = e.resolve();
598
+ if s.is_none() || e.is_none() || s.unwrap() > e.unwrap() {
599
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
600
+ }
601
+ }
602
+ Ok(CounterRange { start, end })
603
+ })?;
604
+
605
+ Ok(CounterRanges(ranges.into()))
606
+ }
607
+ }
608
+
609
+ fn parse_bound(context: &ParserContext, input: &mut Parser) -> Result<CounterBound, ParseError> {
610
+ if let Ok(integer) = input.try_parse(|input| Integer::parse(context, input)) {
611
+ return Ok(CounterBound::Integer(integer));
612
+ }
613
+ input.expect_ident_matching("infinite")?;
614
+ Ok(CounterBound::Infinite)
615
+ }
616
+
617
+ /// <https://drafts.csswg.org/css-counter-styles/#counter-style-pad>
618
+ #[derive(Clone, Debug, MallocSizeOf, ToCss, ToShmem, PartialEq)]
619
+ pub struct Pad(pub Integer, pub Symbol);
620
+
621
+ impl Parse for Pad {
622
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
623
+ let pad_with = input.try_parse(|input| Symbol::parse(context, input));
624
+ let min_length = Integer::parse_non_negative(context, input)?;
625
+ // Rejects calc expressions that cannot be resolved at parse time,
626
+ // since @counter-style descriptors require concrete values.
627
+ if min_length.resolve().is_none() {
628
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
629
+ }
630
+ let pad_with = pad_with.or_else(|_| Symbol::parse(context, input))?;
631
+ Ok(Pad(min_length, pad_with))
632
+ }
633
+ }
634
+
635
+ /// <https://drafts.csswg.org/css-counter-styles/#counter-style-fallback>
636
+ #[derive(Clone, Debug, MallocSizeOf, ToCss, ToShmem, PartialEq)]
637
+ pub struct Fallback(pub CustomIdent);
638
+
639
+ impl Parse for Fallback {
640
+ fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
641
+ Ok(Fallback(parse_counter_style_name(input)?))
642
+ }
643
+ }
644
+
645
+ /// <https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-symbols>
646
+ #[derive(
647
+ Clone, Debug, Eq, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToCss, ToShmem,
648
+ )]
649
+ #[repr(C)]
650
+ pub struct Symbols(
651
+ #[css(iterable)]
652
+ #[ignore_malloc_size_of = "Arc"]
653
+ pub crate::ArcSlice<Symbol>,
654
+ );
655
+
656
+ impl Parse for Symbols {
657
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
658
+ let mut symbols = smallvec::SmallVec::<[_; 5]>::new();
659
+ while let Ok(s) = input.try_parse(|input| Symbol::parse(context, input)) {
660
+ symbols.push(s);
661
+ }
662
+ if symbols.is_empty() {
663
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
664
+ }
665
+ Ok(Symbols(crate::ArcSlice::from_iter(symbols.drain(..))))
666
+ }
667
+ }
668
+
669
+ /// <https://drafts.csswg.org/css-counter-styles/#descdef-counter-style-additive-symbols>
670
+ #[derive(Clone, Debug, MallocSizeOf, ToCss, ToShmem, PartialEq)]
671
+ #[css(comma)]
672
+ pub struct AdditiveSymbols(#[css(iterable)] pub crate::OwnedSlice<AdditiveTuple>);
673
+
674
+ impl Parse for AdditiveSymbols {
675
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
676
+ let tuples = Vec::<AdditiveTuple>::parse(context, input)?;
677
+ if tuples.iter().any(|t| t.weight.resolve().is_none()) {
678
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
679
+ }
680
+ // FIXME maybe? https://github.com/w3c/csswg-drafts/issues/1220
681
+ if tuples
682
+ .windows(2)
683
+ .any(|window| window[0].weight.get() <= window[1].weight.get())
684
+ {
685
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
686
+ }
687
+ Ok(AdditiveSymbols(tuples.into()))
688
+ }
689
+ }
690
+
691
+ /// <integer> && <symbol>
692
+ #[derive(Clone, Debug, MallocSizeOf, ToCss, ToShmem, PartialEq)]
693
+ pub struct AdditiveTuple {
694
+ /// <integer>
695
+ pub weight: Integer,
696
+ /// <symbol>
697
+ pub symbol: Symbol,
698
+ }
699
+
700
+ impl OneOrMoreSeparated for AdditiveTuple {
701
+ type S = Comma;
702
+ }
703
+
704
+ impl Parse for AdditiveTuple {
705
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
706
+ let symbol = input.try_parse(|input| Symbol::parse(context, input));
707
+ let weight = Integer::parse_non_negative(context, input)?;
708
+ let symbol = symbol.or_else(|_| Symbol::parse(context, input))?;
709
+ Ok(Self { weight, symbol })
710
+ }
711
+ }
712
+
713
+ /// <https://drafts.csswg.org/css-counter-styles/#counter-style-speak-as>
714
+ #[derive(Clone, Debug, MallocSizeOf, ToCss, PartialEq, ToShmem)]
715
+ pub enum SpeakAs {
716
+ /// auto
717
+ Auto,
718
+ /// bullets
719
+ Bullets,
720
+ /// numbers
721
+ Numbers,
722
+ /// words
723
+ Words,
724
+ // /// spell-out, not supported, see bug 1024178
725
+ // SpellOut,
726
+ /// <counter-style-name>
727
+ Other(CustomIdent),
728
+ }
729
+
730
+ impl Parse for SpeakAs {
731
+ fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
732
+ let mut is_spell_out = false;
733
+ let result = input.try_parse(|input| {
734
+ let ident = input.expect_ident().map_err(|_| ())?;
735
+ match_ignore_ascii_case! { ident,
736
+ "auto" => Ok(SpeakAs::Auto),
737
+ "bullets" => Ok(SpeakAs::Bullets),
738
+ "numbers" => Ok(SpeakAs::Numbers),
739
+ "words" => Ok(SpeakAs::Words),
740
+ "spell-out" => {
741
+ is_spell_out = true;
742
+ Err(())
743
+ },
744
+ _ => Err(()),
745
+ }
746
+ });
747
+ if is_spell_out {
748
+ // spell-out is not supported, but don’t parse it as a <counter-style-name>.
749
+ // See bug 1024178.
750
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
751
+ }
752
+ result.or_else(|_| Ok(SpeakAs::Other(parse_counter_style_name(input)?)))
753
+ }
754
+ }