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,986 @@
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
+ //! CSS handling for the specified value of
6
+ //! [`basic-shape`][basic-shape]s
7
+ //!
8
+ //! [basic-shape]: https://drafts.csswg.org/css-shapes/#typedef-basic-shape
9
+
10
+ use crate::derives::*;
11
+ use crate::parser::{Parse, ParserContext};
12
+ use crate::values::computed::basic_shape::InsetRect as ComputedInsetRect;
13
+ use crate::values::computed::{
14
+ Context, LengthPercentage as ComputedLengthPercentage, ToComputedValue,
15
+ };
16
+ use crate::values::generics::basic_shape as generic;
17
+ use crate::values::generics::basic_shape::{Path, PolygonCoord};
18
+ use crate::values::generics::position::GenericPositionOrAuto;
19
+ use crate::values::generics::rect::Rect;
20
+ use crate::values::specified::angle::Angle;
21
+ use crate::values::specified::border::BorderRadius;
22
+ use crate::values::specified::image::Image;
23
+ use crate::values::specified::length::LengthPercentageOrAuto;
24
+ use crate::values::specified::position::Position;
25
+ use crate::values::specified::url::SpecifiedUrl;
26
+ use crate::values::specified::{
27
+ LengthPercentage, NoCalcPercentage, NonNegativeLengthPercentage, SVGPathData,
28
+ };
29
+ use crate::values::CSSFloat;
30
+ use crate::Zero;
31
+ use cssparser::{match_ignore_ascii_case, Parser};
32
+ use std::fmt::{self, Write};
33
+ use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
34
+
35
+ /// A specified alias for FillRule.
36
+ pub use crate::values::generics::basic_shape::FillRule;
37
+
38
+ /// A specified `clip-path` value.
39
+ pub type ClipPath = generic::GenericClipPath<BasicShape, SpecifiedUrl>;
40
+
41
+ /// A specified `shape-outside` value.
42
+ pub type ShapeOutside = generic::GenericShapeOutside<BasicShape, Image>;
43
+
44
+ /// A specified basic shape.
45
+ pub type BasicShape = generic::GenericBasicShape<Angle, Position, LengthPercentage, BasicShapeRect>;
46
+
47
+ /// The specified value of `inset()`.
48
+ pub type InsetRect = generic::GenericInsetRect<LengthPercentage>;
49
+
50
+ /// A specified circle.
51
+ pub type Circle = generic::Circle<Position, LengthPercentage>;
52
+
53
+ /// A specified ellipse.
54
+ pub type Ellipse = generic::Ellipse<Position, LengthPercentage>;
55
+
56
+ /// The specified value of `ShapeRadius`.
57
+ pub type ShapeRadius = generic::ShapeRadius<LengthPercentage>;
58
+
59
+ /// The specified value of `Polygon`.
60
+ pub type Polygon = generic::GenericPolygon<LengthPercentage>;
61
+
62
+ /// The specified value of `PathOrShapeFunction`.
63
+ pub type PathOrShapeFunction =
64
+ generic::GenericPathOrShapeFunction<Angle, Position, LengthPercentage>;
65
+
66
+ /// The specified value of `ShapeCommand`.
67
+ pub type ShapeCommand = generic::GenericShapeCommand<Angle, Position, LengthPercentage>;
68
+
69
+ /// The specified value of `xywh()`.
70
+ /// Defines a rectangle via offsets from the top and left edge of the reference box, and a
71
+ /// specified width and height.
72
+ ///
73
+ /// The four <length-percentage>s define, respectively, the inset from the left edge of the
74
+ /// reference box, the inset from the top edge of the reference box, the width of the rectangle,
75
+ /// and the height of the rectangle.
76
+ ///
77
+ /// https://drafts.csswg.org/css-shapes-1/#funcdef-basic-shape-xywh
78
+ #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToShmem)]
79
+ pub struct Xywh {
80
+ /// The left edge of the reference box.
81
+ pub x: LengthPercentage,
82
+ /// The top edge of the reference box.
83
+ pub y: LengthPercentage,
84
+ /// The specified width.
85
+ pub width: NonNegativeLengthPercentage,
86
+ /// The specified height.
87
+ pub height: NonNegativeLengthPercentage,
88
+ /// The optional <border-radius> argument(s) define rounded corners for the inset rectangle
89
+ /// using the border-radius shorthand syntax.
90
+ pub round: BorderRadius,
91
+ }
92
+
93
+ /// Defines a rectangle via insets from the top and left edges of the reference box.
94
+ ///
95
+ /// https://drafts.csswg.org/css-shapes-1/#funcdef-basic-shape-rect
96
+ #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToShmem)]
97
+ #[repr(C)]
98
+ pub struct ShapeRectFunction {
99
+ /// The four <length-percentage>s define the position of the top, right, bottom, and left edges
100
+ /// of a rectangle, respectively, as insets from the top edge of the reference box (for the
101
+ /// first and third values) or the left edge of the reference box (for the second and fourth
102
+ /// values).
103
+ ///
104
+ /// An auto value makes the edge of the box coincide with the corresponding edge of the
105
+ /// reference box: it’s equivalent to 0% as the first (top) or fourth (left) value, and
106
+ /// equivalent to 100% as the second (right) or third (bottom) value.
107
+ pub rect: Rect<LengthPercentageOrAuto>,
108
+ /// The optional <border-radius> argument(s) define rounded corners for the inset rectangle
109
+ /// using the border-radius shorthand syntax.
110
+ pub round: BorderRadius,
111
+ }
112
+
113
+ /// The specified value of <basic-shape-rect>.
114
+ /// <basic-shape-rect> = <inset()> | <rect()> | <xywh()>
115
+ ///
116
+ /// https://drafts.csswg.org/css-shapes-1/#supported-basic-shapes
117
+ #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem)]
118
+ pub enum BasicShapeRect {
119
+ /// Defines an inset rectangle via insets from each edge of the reference box.
120
+ Inset(InsetRect),
121
+ /// Defines a xywh function.
122
+ #[css(function)]
123
+ Xywh(Xywh),
124
+ /// Defines a rect function.
125
+ #[css(function)]
126
+ Rect(ShapeRectFunction),
127
+ }
128
+
129
+ /// For filled shapes, we use fill-rule, and store it for path() and polygon().
130
+ /// For outline shapes, we should ignore fill-rule.
131
+ ///
132
+ /// https://github.com/w3c/fxtf-drafts/issues/512
133
+ /// https://github.com/w3c/csswg-drafts/issues/7390
134
+ /// https://github.com/w3c/csswg-drafts/issues/3468
135
+ pub enum ShapeType {
136
+ /// The CSS property uses filled shapes. The default behavior.
137
+ Filled,
138
+ /// The CSS property uses outline shapes. This is especially useful for offset-path.
139
+ Outline,
140
+ }
141
+
142
+ bitflags! {
143
+ /// The flags to represent which basic shapes we would like to support.
144
+ ///
145
+ /// Different properties may use different subsets of <basic-shape>:
146
+ /// e.g.
147
+ /// clip-path: all basic shapes.
148
+ /// motion-path: all basic shapes (but ignore fill-rule).
149
+ /// shape-outside: inset(), circle(), ellipse(), polygon().
150
+ ///
151
+ /// Also there are some properties we don't support for now:
152
+ /// shape-inside: inset(), circle(), ellipse(), polygon().
153
+ /// SVG shape-inside and shape-subtract: circle(), ellipse(), polygon().
154
+ ///
155
+ /// The spec issue proposes some better ways to clarify the usage of basic shapes, so for now
156
+ /// we use the bitflags to choose the supported basic shapes for each property at the parse
157
+ /// time.
158
+ /// https://github.com/w3c/csswg-drafts/issues/7390
159
+ #[derive(Clone, Copy)]
160
+ #[repr(C)]
161
+ pub struct AllowedBasicShapes: u8 {
162
+ /// inset().
163
+ const INSET = 1 << 0;
164
+ /// xywh().
165
+ const XYWH = 1 << 1;
166
+ /// rect().
167
+ const RECT = 1 << 2;
168
+ /// circle().
169
+ const CIRCLE = 1 << 3;
170
+ /// ellipse().
171
+ const ELLIPSE = 1 << 4;
172
+ /// polygon().
173
+ const POLYGON = 1 << 5;
174
+ /// path().
175
+ const PATH = 1 << 6;
176
+ /// shape().
177
+ const SHAPE = 1 << 7;
178
+
179
+ /// All flags.
180
+ const ALL =
181
+ Self::INSET.bits() |
182
+ Self::XYWH.bits() |
183
+ Self::RECT.bits() |
184
+ Self::CIRCLE.bits() |
185
+ Self::ELLIPSE.bits() |
186
+ Self::POLYGON.bits() |
187
+ Self::PATH.bits() |
188
+ Self::SHAPE.bits();
189
+
190
+ /// For shape-outside.
191
+ const SHAPE_OUTSIDE =
192
+ Self::INSET.bits() |
193
+ Self::XYWH.bits() |
194
+ Self::RECT.bits() |
195
+ Self::CIRCLE.bits() |
196
+ Self::ELLIPSE.bits() |
197
+ Self::POLYGON.bits();
198
+ }
199
+ }
200
+
201
+ /// A helper for both clip-path and shape-outside parsing of shapes.
202
+ fn parse_shape_or_box<R, ReferenceBox>(
203
+ context: &ParserContext,
204
+ input: &mut Parser,
205
+ to_shape: impl FnOnce(Box<BasicShape>, ReferenceBox) -> R,
206
+ to_reference_box: impl FnOnce(ReferenceBox) -> R,
207
+ flags: AllowedBasicShapes,
208
+ ) -> Result<R, ParseError>
209
+ where
210
+ ReferenceBox: Default + Parse,
211
+ {
212
+ let mut shape = None;
213
+ let mut ref_box = None;
214
+ loop {
215
+ if shape.is_none() {
216
+ shape = input
217
+ .try_parse(|i| BasicShape::parse(context, i, flags, ShapeType::Filled))
218
+ .ok();
219
+ }
220
+
221
+ if ref_box.is_none() {
222
+ ref_box = input.try_parse(|i| ReferenceBox::parse(context, i)).ok();
223
+ if ref_box.is_some() {
224
+ continue;
225
+ }
226
+ }
227
+ break;
228
+ }
229
+
230
+ if let Some(shp) = shape {
231
+ return Ok(to_shape(Box::new(shp), ref_box.unwrap_or_default()));
232
+ }
233
+
234
+ match ref_box {
235
+ Some(r) => Ok(to_reference_box(r)),
236
+ None => Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError)),
237
+ }
238
+ }
239
+
240
+ impl Parse for ClipPath {
241
+ #[inline]
242
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
243
+ if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
244
+ return Ok(ClipPath::None);
245
+ }
246
+
247
+ if let Ok(url) = input.try_parse(|i| SpecifiedUrl::parse(context, i)) {
248
+ return Ok(ClipPath::Url(url));
249
+ }
250
+
251
+ parse_shape_or_box(
252
+ context,
253
+ input,
254
+ ClipPath::Shape,
255
+ ClipPath::Box,
256
+ AllowedBasicShapes::ALL,
257
+ )
258
+ }
259
+ }
260
+
261
+ impl Parse for ShapeOutside {
262
+ #[inline]
263
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
264
+ // Need to parse this here so that `Image::parse_with_cors_anonymous`
265
+ // doesn't parse it.
266
+ if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
267
+ return Ok(ShapeOutside::None);
268
+ }
269
+
270
+ if let Ok(image) = input.try_parse(|i| Image::parse_with_cors_anonymous(context, i)) {
271
+ debug_assert_ne!(image, Image::None);
272
+ return Ok(ShapeOutside::Image(image));
273
+ }
274
+
275
+ parse_shape_or_box(
276
+ context,
277
+ input,
278
+ ShapeOutside::Shape,
279
+ ShapeOutside::Box,
280
+ AllowedBasicShapes::SHAPE_OUTSIDE,
281
+ )
282
+ }
283
+ }
284
+
285
+ impl BasicShape {
286
+ /// Parse with some parameters.
287
+ /// 1. The supported <basic-shape>.
288
+ /// 2. The type of shapes. Should we ignore fill-rule?
289
+ /// 3. The default value of `at <position>`.
290
+ pub fn parse(
291
+ context: &ParserContext,
292
+ input: &mut Parser,
293
+ flags: AllowedBasicShapes,
294
+ shape_type: ShapeType,
295
+ ) -> Result<Self, ParseError> {
296
+ let function = input.expect_function()?.clone();
297
+ input.parse_nested_block(move |i| {
298
+ match_ignore_ascii_case! { &function,
299
+ "inset" if flags.contains(AllowedBasicShapes::INSET) => {
300
+ InsetRect::parse_function_arguments(context, i)
301
+ .map(BasicShapeRect::Inset)
302
+ .map(BasicShape::Rect)
303
+ },
304
+ "xywh" if flags.contains(AllowedBasicShapes::XYWH) => {
305
+ Xywh::parse_function_arguments(context, i)
306
+ .map(BasicShapeRect::Xywh)
307
+ .map(BasicShape::Rect)
308
+ },
309
+ "rect" if flags.contains(AllowedBasicShapes::RECT) => {
310
+ ShapeRectFunction::parse_function_arguments(context, i)
311
+ .map(BasicShapeRect::Rect)
312
+ .map(BasicShape::Rect)
313
+ },
314
+ "circle" if flags.contains(AllowedBasicShapes::CIRCLE) => {
315
+ Circle::parse_function_arguments(context, i)
316
+ .map(BasicShape::Circle)
317
+ },
318
+ "ellipse" if flags.contains(AllowedBasicShapes::ELLIPSE) => {
319
+ Ellipse::parse_function_arguments(context, i)
320
+ .map(BasicShape::Ellipse)
321
+ },
322
+ "polygon" if flags.contains(AllowedBasicShapes::POLYGON) => {
323
+ Polygon::parse_function_arguments(context, i, shape_type)
324
+ .map(BasicShape::Polygon)
325
+ },
326
+ "path" if flags.contains(AllowedBasicShapes::PATH) => {
327
+ Path::parse_function_arguments(i, shape_type)
328
+ .map(PathOrShapeFunction::Path)
329
+ .map(BasicShape::PathOrShape)
330
+ },
331
+ "shape"
332
+ if flags.contains(AllowedBasicShapes::SHAPE)
333
+ && crate::pref!("layout.css.basic-shape-shape.enabled") =>
334
+ {
335
+ generic::Shape::parse_function_arguments(context, i, shape_type)
336
+ .map(PathOrShapeFunction::Shape)
337
+ .map(BasicShape::PathOrShape)
338
+ },
339
+ _ => Err(ParseError::custom(StyleParseErrorKind::UnexpectedFunction)),
340
+ }
341
+ })
342
+ }
343
+ }
344
+
345
+ impl Parse for InsetRect {
346
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
347
+ input.expect_function_matching("inset")?;
348
+ input.parse_nested_block(|i| Self::parse_function_arguments(context, i))
349
+ }
350
+ }
351
+
352
+ fn parse_round(context: &ParserContext, input: &mut Parser) -> Result<BorderRadius, ParseError> {
353
+ if input
354
+ .try_parse(|i| i.expect_ident_matching("round"))
355
+ .is_ok()
356
+ {
357
+ return BorderRadius::parse(context, input);
358
+ }
359
+
360
+ Ok(BorderRadius::zero())
361
+ }
362
+
363
+ impl InsetRect {
364
+ /// Parse the inner function arguments of `inset()`
365
+ fn parse_function_arguments(
366
+ context: &ParserContext,
367
+ input: &mut Parser,
368
+ ) -> Result<Self, ParseError> {
369
+ let rect = Rect::parse_with(context, input, LengthPercentage::parse)?;
370
+ let round = parse_round(context, input)?;
371
+ Ok(generic::InsetRect { rect, round })
372
+ }
373
+ }
374
+
375
+ fn parse_at_position(
376
+ context: &ParserContext,
377
+ input: &mut Parser,
378
+ ) -> Result<GenericPositionOrAuto<Position>, ParseError> {
379
+ if input.try_parse(|i| i.expect_ident_matching("at")).is_ok() {
380
+ Position::parse(context, input).map(GenericPositionOrAuto::Position)
381
+ } else {
382
+ Ok(GenericPositionOrAuto::Auto)
383
+ }
384
+ }
385
+
386
+ impl Parse for Circle {
387
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
388
+ input.expect_function_matching("circle")?;
389
+ input.parse_nested_block(|i| Self::parse_function_arguments(context, i))
390
+ }
391
+ }
392
+
393
+ impl Circle {
394
+ fn parse_function_arguments(
395
+ context: &ParserContext,
396
+ input: &mut Parser,
397
+ ) -> Result<Self, ParseError> {
398
+ let radius = input
399
+ .try_parse(|i| ShapeRadius::parse(context, i))
400
+ .unwrap_or_default();
401
+ let position = parse_at_position(context, input)?;
402
+
403
+ Ok(generic::Circle { radius, position })
404
+ }
405
+ }
406
+
407
+ impl Parse for Ellipse {
408
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
409
+ input.expect_function_matching("ellipse")?;
410
+ input.parse_nested_block(|i| Self::parse_function_arguments(context, i))
411
+ }
412
+ }
413
+
414
+ impl Ellipse {
415
+ fn parse_function_arguments(
416
+ context: &ParserContext,
417
+ input: &mut Parser,
418
+ ) -> Result<Self, ParseError> {
419
+ let (semiaxis_x, semiaxis_y) = input
420
+ .try_parse(|i| -> Result<_, ParseError> {
421
+ let s_x = ShapeRadius::parse(context, i)?;
422
+ let s_y = ShapeRadius::parse(context, i)?;
423
+ if !crate::pref!("layout.css.ellipse-corners.enabled")
424
+ && (matches!(
425
+ s_x,
426
+ ShapeRadius::ClosestCorner | ShapeRadius::FarthestCorner
427
+ ) || matches!(
428
+ s_y,
429
+ ShapeRadius::ClosestCorner | ShapeRadius::FarthestCorner
430
+ ))
431
+ {
432
+ Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError))
433
+ } else {
434
+ Ok((s_x, s_y))
435
+ }
436
+ })
437
+ .unwrap_or_default();
438
+ let position = parse_at_position(context, input)?;
439
+
440
+ Ok(generic::Ellipse {
441
+ semiaxis_x,
442
+ semiaxis_y,
443
+ position,
444
+ })
445
+ }
446
+ }
447
+
448
+ fn parse_fill_rule(input: &mut Parser, shape_type: ShapeType, expect_comma: bool) -> FillRule {
449
+ match shape_type {
450
+ // Per [1] and [2], we ignore `<fill-rule>` for outline shapes, so always use a default
451
+ // value.
452
+ // [1] https://github.com/w3c/csswg-drafts/issues/3468
453
+ // [2] https://github.com/w3c/csswg-drafts/issues/7390
454
+ //
455
+ // Also, per [3] and [4], we would like the ignore `<file-rule>` from outline shapes, e.g.
456
+ // offset-path, which means we don't parse it when setting `ShapeType::Outline`.
457
+ // This should be web compatible because the shipped "offset-path:path()" doesn't have
458
+ // `<fill-rule>` and "offset-path:polygon()" is a new feature and still behind the
459
+ // preference.
460
+ // [3] https://github.com/w3c/fxtf-drafts/issues/512#issuecomment-1545393321
461
+ // [4] https://github.com/w3c/fxtf-drafts/issues/512#issuecomment-1555330929
462
+ ShapeType::Outline => Default::default(),
463
+ ShapeType::Filled => input
464
+ .try_parse(|i| -> Result<_, ParseError> {
465
+ let fill = FillRule::parse(i)?;
466
+ if expect_comma {
467
+ i.expect_comma()?;
468
+ }
469
+ Ok(fill)
470
+ })
471
+ .unwrap_or_default(),
472
+ }
473
+ }
474
+
475
+ impl Parse for Polygon {
476
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
477
+ input.expect_function_matching("polygon")?;
478
+ input.parse_nested_block(|i| Self::parse_function_arguments(context, i, ShapeType::Filled))
479
+ }
480
+ }
481
+
482
+ impl Polygon {
483
+ /// Parse the inner arguments of a `polygon` function.
484
+ fn parse_function_arguments(
485
+ context: &ParserContext,
486
+ input: &mut Parser,
487
+ shape_type: ShapeType,
488
+ ) -> Result<Self, ParseError> {
489
+ let fill = parse_fill_rule(input, shape_type, true /* has comma */);
490
+ let coordinates = input
491
+ .parse_comma_separated(|i| {
492
+ Ok(PolygonCoord(
493
+ LengthPercentage::parse(context, i)?,
494
+ LengthPercentage::parse(context, i)?,
495
+ ))
496
+ })?
497
+ .into();
498
+
499
+ Ok(Polygon { fill, coordinates })
500
+ }
501
+ }
502
+
503
+ impl Path {
504
+ /// Parse the inner arguments of a `path` function.
505
+ fn parse_function_arguments(
506
+ input: &mut Parser,
507
+ shape_type: ShapeType,
508
+ ) -> Result<Self, ParseError> {
509
+ use crate::values::specified::svg_path::AllowEmpty;
510
+
511
+ let fill = parse_fill_rule(input, shape_type, true /* has comma */);
512
+ let path = SVGPathData::parse(input, AllowEmpty::No)?;
513
+ Ok(Path { fill, path })
514
+ }
515
+ }
516
+
517
+ fn round_to_css<W>(round: &BorderRadius, dest: &mut CssWriter<W>) -> fmt::Result
518
+ where
519
+ W: Write,
520
+ {
521
+ if !round.is_zero() {
522
+ dest.write_str(" round ")?;
523
+ round.to_css(dest)?;
524
+ }
525
+ Ok(())
526
+ }
527
+
528
+ impl ToCss for Xywh {
529
+ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
530
+ where
531
+ W: Write,
532
+ {
533
+ self.x.to_css(dest)?;
534
+ dest.write_char(' ')?;
535
+ self.y.to_css(dest)?;
536
+ dest.write_char(' ')?;
537
+ self.width.to_css(dest)?;
538
+ dest.write_char(' ')?;
539
+ self.height.to_css(dest)?;
540
+ round_to_css(&self.round, dest)
541
+ }
542
+ }
543
+
544
+ impl Xywh {
545
+ /// Parse the inner function arguments of `xywh()`.
546
+ fn parse_function_arguments(
547
+ context: &ParserContext,
548
+ input: &mut Parser,
549
+ ) -> Result<Self, ParseError> {
550
+ let x = LengthPercentage::parse(context, input)?;
551
+ let y = LengthPercentage::parse(context, input)?;
552
+ let width = NonNegativeLengthPercentage::parse(context, input)?;
553
+ let height = NonNegativeLengthPercentage::parse(context, input)?;
554
+ let round = parse_round(context, input)?;
555
+ Ok(Xywh {
556
+ x,
557
+ y,
558
+ width,
559
+ height,
560
+ round,
561
+ })
562
+ }
563
+ }
564
+
565
+ impl ToCss for ShapeRectFunction {
566
+ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
567
+ where
568
+ W: Write,
569
+ {
570
+ self.rect.0.to_css(dest)?;
571
+ dest.write_char(' ')?;
572
+ self.rect.1.to_css(dest)?;
573
+ dest.write_char(' ')?;
574
+ self.rect.2.to_css(dest)?;
575
+ dest.write_char(' ')?;
576
+ self.rect.3.to_css(dest)?;
577
+ round_to_css(&self.round, dest)
578
+ }
579
+ }
580
+
581
+ impl ShapeRectFunction {
582
+ /// Parse the inner function arguments of `rect()`.
583
+ fn parse_function_arguments(
584
+ context: &ParserContext,
585
+ input: &mut Parser,
586
+ ) -> Result<Self, ParseError> {
587
+ let rect = Rect::parse_all_components_with(context, input, LengthPercentageOrAuto::parse)?;
588
+ let round = parse_round(context, input)?;
589
+ Ok(ShapeRectFunction { rect, round })
590
+ }
591
+ }
592
+
593
+ impl ToComputedValue for BasicShapeRect {
594
+ type ComputedValue = ComputedInsetRect;
595
+
596
+ #[inline]
597
+ fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
598
+ use crate::values::computed::LengthPercentage;
599
+ use crate::values::computed::LengthPercentageOrAuto;
600
+ use style_traits::values::specified::AllowedNumericType;
601
+
602
+ match self {
603
+ Self::Inset(inset) => inset.to_computed_value(context),
604
+ Self::Xywh(xywh) => {
605
+ // Given `xywh(x y w h)`, construct the equivalent inset() function,
606
+ // `inset(y calc(100% - x - w) calc(100% - y - h) x)`.
607
+ //
608
+ // https://drafts.csswg.org/css-shapes-1/#basic-shape-computed-values
609
+ // https://github.com/w3c/csswg-drafts/issues/9053
610
+ let x = xywh.x.to_computed_value(context);
611
+ let y = xywh.y.to_computed_value(context);
612
+ let w = xywh.width.to_computed_value(context);
613
+ let h = xywh.height.to_computed_value(context);
614
+ // calc(100% - x - w).
615
+ let right = LengthPercentage::hundred_percent_minus_list(
616
+ &[&x, &w.0],
617
+ AllowedNumericType::All,
618
+ );
619
+ // calc(100% - y - h).
620
+ let bottom = LengthPercentage::hundred_percent_minus_list(
621
+ &[&y, &h.0],
622
+ AllowedNumericType::All,
623
+ );
624
+
625
+ ComputedInsetRect {
626
+ rect: Rect::new(y, right, bottom, x),
627
+ round: xywh.round.to_computed_value(context),
628
+ }
629
+ },
630
+ Self::Rect(rect) => {
631
+ // Given `rect(t r b l)`, the equivalent function is
632
+ // `inset(t calc(100% - r) calc(100% - b) l)`.
633
+ //
634
+ // https://drafts.csswg.org/css-shapes-1/#basic-shape-computed-values
635
+ fn compute_top_or_left(v: LengthPercentageOrAuto) -> LengthPercentage {
636
+ match v {
637
+ // it’s equivalent to 0% as the first (top) or fourth (left) value.
638
+ // https://drafts.csswg.org/css-shapes-1/#funcdef-basic-shape-rect
639
+ LengthPercentageOrAuto::Auto => LengthPercentage::zero_percent(),
640
+ LengthPercentageOrAuto::LengthPercentage(lp) => lp,
641
+ }
642
+ }
643
+ fn compute_bottom_or_right(v: LengthPercentageOrAuto) -> LengthPercentage {
644
+ match v {
645
+ // It's equivalent to 100% as the second (right) or third (bottom) value.
646
+ // So calc(100% - 100%) = 0%.
647
+ // https://drafts.csswg.org/css-shapes-1/#funcdef-basic-shape-rect
648
+ LengthPercentageOrAuto::Auto => LengthPercentage::zero_percent(),
649
+ LengthPercentageOrAuto::LengthPercentage(lp) => {
650
+ LengthPercentage::hundred_percent_minus(lp, AllowedNumericType::All)
651
+ },
652
+ }
653
+ }
654
+
655
+ let round = rect.round.to_computed_value(context);
656
+ let rect = rect.rect.to_computed_value(context);
657
+ let rect = Rect::new(
658
+ compute_top_or_left(rect.0),
659
+ compute_bottom_or_right(rect.1),
660
+ compute_bottom_or_right(rect.2),
661
+ compute_top_or_left(rect.3),
662
+ );
663
+
664
+ ComputedInsetRect { rect, round }
665
+ },
666
+ }
667
+ }
668
+
669
+ #[inline]
670
+ fn from_computed_value(computed: &Self::ComputedValue) -> Self {
671
+ Self::Inset(ToComputedValue::from_computed_value(computed))
672
+ }
673
+ }
674
+
675
+ impl generic::Shape<Angle, Position, LengthPercentage> {
676
+ /// Parse the inner arguments of a `shape` function.
677
+ /// shape() = shape(<fill-rule>? from <coordinate-pair>, <shape-command>#)
678
+ fn parse_function_arguments(
679
+ context: &ParserContext,
680
+ input: &mut Parser,
681
+ shape_type: ShapeType,
682
+ ) -> Result<Self, ParseError> {
683
+ let fill = parse_fill_rule(input, shape_type, false /* no following comma */);
684
+
685
+ let mut first = true;
686
+ let commands = input.parse_comma_separated(|i| {
687
+ if first {
688
+ first = false;
689
+
690
+ // The starting point for the first shape-command. It adds an initial absolute
691
+ // moveto to the list of path data commands, with the <coordinate-pair> measured
692
+ // from the top-left corner of the reference
693
+ i.expect_ident_matching("from")?;
694
+ Ok(ShapeCommand::Move {
695
+ point: generic::CommandEndPoint::parse_endpoint_as_abs(context, i)?,
696
+ })
697
+ } else {
698
+ // The further path data commands.
699
+ ShapeCommand::parse(context, i)
700
+ }
701
+ })?;
702
+
703
+ // We must have one starting point and at least one following <shape-command>.
704
+ if commands.len() < 2 {
705
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
706
+ }
707
+
708
+ Ok(Self {
709
+ fill,
710
+ commands: commands.into(),
711
+ })
712
+ }
713
+ }
714
+
715
+ impl Parse for ShapeCommand {
716
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
717
+ use crate::values::generics::basic_shape::{
718
+ ArcRadii, ArcSize, ArcSweep, AxisEndPoint, CommandEndPoint, ControlPoint,
719
+ };
720
+
721
+ // <shape-command> = <move-command> | <line-command> | <hv-line-command> |
722
+ // <curve-command> | <smooth-command> | <arc-command> | close
723
+ Ok(try_match_ident_ignore_ascii_case! { input,
724
+ "close" => Self::Close,
725
+ "move" => {
726
+ let point = CommandEndPoint::parse(context, input)?;
727
+ Self::Move { point }
728
+ },
729
+ "line" => {
730
+ let point = CommandEndPoint::parse(context, input)?;
731
+ Self::Line { point }
732
+ },
733
+ "hline" => {
734
+ let x = AxisEndPoint::parse_hline(context, input)?;
735
+ Self::HLine { x }
736
+ },
737
+ "vline" => {
738
+ let y = AxisEndPoint::parse_vline(context, input)?;
739
+ Self::VLine { y }
740
+ },
741
+ "curve" => {
742
+ let point = CommandEndPoint::parse(context, input)?;
743
+ input.expect_ident_matching("with")?;
744
+ let control1 = ControlPoint::parse(context, input, point.is_abs())?;
745
+ if input.try_parse(|i| i.expect_delim('/')).is_ok() {
746
+ let control2 = ControlPoint::parse(context, input, point.is_abs())?;
747
+ Self::CubicCurve {
748
+ point,
749
+ control1,
750
+ control2,
751
+ }
752
+ } else {
753
+ Self::QuadCurve {
754
+ point,
755
+ control1,
756
+ }
757
+ }
758
+ },
759
+ "smooth" => {
760
+ let point = CommandEndPoint::parse(context, input)?;
761
+ if input.try_parse(|i| i.expect_ident_matching("with")).is_ok() {
762
+ let control2 = ControlPoint::parse(context, input, point.is_abs())?;
763
+ Self::SmoothCubic {
764
+ point,
765
+ control2,
766
+ }
767
+ } else {
768
+ Self::SmoothQuad { point }
769
+ }
770
+ },
771
+ "arc" => {
772
+ let point = CommandEndPoint::parse(context, input)?;
773
+ input.expect_ident_matching("of")?;
774
+ let rx = LengthPercentage::parse(context, input)?;
775
+ let ry = input.try_parse(|i| LengthPercentage::parse(context, i)).ok();
776
+ let radii = ArcRadii { rx, ry: ry.into() };
777
+
778
+ // [<arc-sweep> || <arc-size> || rotate <angle>]?
779
+ let mut arc_sweep = None;
780
+ let mut arc_size = None;
781
+ let mut rotate = None;
782
+ loop {
783
+ if arc_sweep.is_none() {
784
+ arc_sweep = input.try_parse(ArcSweep::parse).ok();
785
+ }
786
+
787
+ if arc_size.is_none() {
788
+ arc_size = input.try_parse(ArcSize::parse).ok();
789
+ if arc_size.is_some() {
790
+ continue;
791
+ }
792
+ }
793
+
794
+ if rotate.is_none()
795
+ && input
796
+ .try_parse(|i| i.expect_ident_matching("rotate"))
797
+ .is_ok()
798
+ {
799
+ rotate = Some(Angle::parse(context, input)?);
800
+ continue;
801
+ }
802
+ break;
803
+ }
804
+ Self::Arc {
805
+ point,
806
+ radii,
807
+ arc_sweep: arc_sweep.unwrap_or(ArcSweep::Ccw),
808
+ arc_size: arc_size.unwrap_or(ArcSize::Small),
809
+ rotate: rotate.unwrap_or(Angle::zero()),
810
+ }
811
+ },
812
+ })
813
+ }
814
+ }
815
+
816
+ impl Parse for generic::CoordinatePair<LengthPercentage> {
817
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
818
+ let x = LengthPercentage::parse(context, input)?;
819
+ let y = LengthPercentage::parse(context, input)?;
820
+ Ok(Self::new(x, y))
821
+ }
822
+ }
823
+
824
+ impl generic::ControlPoint<Position, LengthPercentage> {
825
+ /// Parse <control-point> = [ <position> | <relative-control-point> ]
826
+ fn parse(
827
+ context: &ParserContext,
828
+ input: &mut Parser,
829
+ is_end_point_abs: bool,
830
+ ) -> Result<Self, ParseError> {
831
+ use generic::ControlReference;
832
+ let coord = input.try_parse(|i| generic::CoordinatePair::parse(context, i));
833
+
834
+ // Parse <position>
835
+ if is_end_point_abs && coord.is_err() {
836
+ let pos = Position::parse(context, input)?;
837
+ return Ok(Self::Absolute(pos));
838
+ }
839
+
840
+ // Parse <relative-control-point> = <coordinate-pair> [from [ start | end | origin ]]?
841
+ let coord = coord?;
842
+ let mut reference = if is_end_point_abs {
843
+ ControlReference::Origin
844
+ } else {
845
+ ControlReference::Start
846
+ };
847
+ if input.try_parse(|i| i.expect_ident_matching("from")).is_ok() {
848
+ reference = ControlReference::parse(input)?;
849
+ }
850
+
851
+ Ok(Self::Relative(generic::RelativeControlPoint {
852
+ coord,
853
+ reference,
854
+ }))
855
+ }
856
+ }
857
+
858
+ impl Parse for generic::CommandEndPoint<Position, LengthPercentage> {
859
+ /// Parse <command-end-point> = to <position> | by <coordinate-pair>
860
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
861
+ if ByTo::parse(input)?.is_abs() {
862
+ Self::parse_endpoint_as_abs(context, input)
863
+ } else {
864
+ let point = generic::CoordinatePair::parse(context, input)?;
865
+ Ok(Self::ByCoordinate(point))
866
+ }
867
+ }
868
+ }
869
+
870
+ impl generic::CommandEndPoint<Position, LengthPercentage> {
871
+ /// Parse <command-end-point> = to <position>
872
+ fn parse_endpoint_as_abs(
873
+ context: &ParserContext,
874
+ input: &mut Parser,
875
+ ) -> Result<Self, ParseError> {
876
+ let point = Position::parse(context, input)?;
877
+ Ok(generic::CommandEndPoint::ToPosition(point))
878
+ }
879
+ }
880
+
881
+ impl generic::AxisEndPoint<LengthPercentage> {
882
+ /// Parse <horizontal-line-command>
883
+ pub fn parse_hline(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
884
+ use cssparser::Token;
885
+ use generic::{AxisPosition, AxisPositionKeyword};
886
+
887
+ // If the command is relative, parse for <length-percentage> only.
888
+ if !ByTo::parse(input)?.is_abs() {
889
+ return Ok(Self::ByCoordinate(LengthPercentage::parse(context, input)?));
890
+ }
891
+
892
+ let x = AxisPosition::parse(context, input)?;
893
+ if let AxisPosition::Keyword(
894
+ _word @ (AxisPositionKeyword::Top
895
+ | AxisPositionKeyword::Bottom
896
+ | AxisPositionKeyword::YStart
897
+ | AxisPositionKeyword::YEnd),
898
+ ) = &x
899
+ {
900
+ let _ = Token::Ident(x.to_css_string().into());
901
+ return Err(ParseError::unexpected_token());
902
+ }
903
+ Ok(Self::ToPosition(x))
904
+ }
905
+
906
+ /// Parse <vertical-line-command>
907
+ pub fn parse_vline(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
908
+ use cssparser::Token;
909
+ use generic::{AxisPosition, AxisPositionKeyword};
910
+
911
+ // If the command is relative, parse for <length-percentage> only.
912
+ if !ByTo::parse(input)?.is_abs() {
913
+ return Ok(Self::ByCoordinate(LengthPercentage::parse(context, input)?));
914
+ }
915
+
916
+ let y = AxisPosition::parse(context, input)?;
917
+ if let AxisPosition::Keyword(
918
+ _word @ (AxisPositionKeyword::Left
919
+ | AxisPositionKeyword::Right
920
+ | AxisPositionKeyword::XStart
921
+ | AxisPositionKeyword::XEnd),
922
+ ) = &y
923
+ {
924
+ // Return an error if we parsed a different keyword.
925
+ let _ = Token::Ident(y.to_css_string().into());
926
+ return Err(ParseError::unexpected_token());
927
+ }
928
+ Ok(Self::ToPosition(y))
929
+ }
930
+ }
931
+
932
+ impl ToComputedValue for generic::AxisPosition<LengthPercentage> {
933
+ type ComputedValue = generic::AxisPosition<ComputedLengthPercentage>;
934
+
935
+ fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
936
+ match self {
937
+ Self::LengthPercent(lp) => {
938
+ Self::ComputedValue::LengthPercent(lp.to_computed_value(context))
939
+ },
940
+ Self::Keyword(word) => {
941
+ let lp =
942
+ LengthPercentage::Percentage(NoCalcPercentage::new(word.as_percentage().0));
943
+ Self::ComputedValue::LengthPercent(lp.to_computed_value(context))
944
+ },
945
+ }
946
+ }
947
+
948
+ fn from_computed_value(computed: &Self::ComputedValue) -> Self {
949
+ match computed {
950
+ Self::ComputedValue::LengthPercent(lp) => {
951
+ Self::LengthPercent(LengthPercentage::from_computed_value(lp))
952
+ },
953
+ _ => unreachable!("Invalid state: computed value cannot be a keyword."),
954
+ }
955
+ }
956
+ }
957
+
958
+ impl ToComputedValue for generic::AxisPosition<CSSFloat> {
959
+ type ComputedValue = Self;
960
+
961
+ fn to_computed_value(&self, _context: &Context) -> Self {
962
+ *self
963
+ }
964
+
965
+ fn from_computed_value(computed: &Self) -> Self {
966
+ *computed
967
+ }
968
+ }
969
+
970
+ /// This determines whether the command is absolutely or relatively positioned.
971
+ /// https://drafts.csswg.org/css-shapes-1/#typedef-shape-command-end-point
972
+ #[derive(Clone, Copy, Debug, Parse, PartialEq)]
973
+ enum ByTo {
974
+ /// Command is relative to the command’s starting point.
975
+ By,
976
+ /// Command is relative to the top-left corner of the reference box.
977
+ To,
978
+ }
979
+
980
+ impl ByTo {
981
+ /// Return true if it is absolute, i.e. it is To.
982
+ #[inline]
983
+ pub fn is_abs(&self) -> bool {
984
+ matches!(self, ByTo::To)
985
+ }
986
+ }