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,1210 @@
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
+ //! Specified color values.
6
+
7
+ use super::AllowQuirks;
8
+ use crate::color::mix::ColorInterpolationMethod;
9
+ use crate::color::{parsing, AbsoluteColor, ColorFunction, ColorMixItemList, ColorSpace};
10
+ use crate::derives::*;
11
+ use crate::device::Device;
12
+ use crate::parser::{Parse, ParserContext};
13
+ use crate::typed_om::{KeywordValue, ToTyped, TypedValue};
14
+ use crate::values::computed::{
15
+ Color as ComputedColor, Context, Percentage as ComputedPercentage, ToComputedValue,
16
+ };
17
+ use crate::values::generics::color::{
18
+ ColorMixFlags, GenericCaretColor, GenericColorMix, GenericColorMixItem, GenericColorOrAuto,
19
+ GenericLightDark,
20
+ };
21
+ use crate::values::generics::Optional;
22
+ use crate::values::specified::percentage::ToPercentage;
23
+ use crate::values::specified::Percentage;
24
+ use crate::values::{normalize, CustomIdent};
25
+ use cssparser::{match_ignore_ascii_case, Parser, Token};
26
+ use std::fmt::{self, Write};
27
+ use std::io::Write as IoWrite;
28
+ use style_traits::{
29
+ owned_slice::OwnedSlice, CssString, CssType, CssWriter, KeywordsCollectFn, ParseError,
30
+ SpecifiedValueInfo, StyleParseErrorKind, ToCss,
31
+ };
32
+ use thin_vec::ThinVec;
33
+
34
+ /// A specified color-mix().
35
+ pub type ColorMix = GenericColorMix<Color, Percentage>;
36
+
37
+ impl ColorMix {
38
+ fn parse(
39
+ context: &ParserContext,
40
+ input: &mut Parser,
41
+ preserve_authored: PreserveAuthored,
42
+ ) -> Result<Self, ParseError> {
43
+ input.expect_function_matching("color-mix")?;
44
+
45
+ input.parse_nested_block(|input| {
46
+ // If the color interpolation method is omitted, default to "in oklab".
47
+ // See: https://github.com/web-platform-tests/interop/issues/1166
48
+ let interpolation = input
49
+ .try_parse(|input| -> Result<_, ParseError> {
50
+ let interpolation = ColorInterpolationMethod::parse(context, input)?;
51
+ input.expect_comma()?;
52
+ Ok(interpolation)
53
+ })
54
+ .unwrap_or_default();
55
+
56
+ let try_parse_percentage = |input: &mut Parser| -> Option<Percentage> {
57
+ input
58
+ .try_parse(|input| Percentage::parse_zero_to_a_hundred(context, input))
59
+ .ok()
60
+ };
61
+
62
+ let allow_multiple_items =
63
+ crate::pref!("layout.css.color-mix-multi-color.enabled");
64
+
65
+ let mut items = ColorMixItemList::default();
66
+
67
+ loop {
68
+ let mut percentage = try_parse_percentage(input);
69
+
70
+ let color = Color::parse_internal(context, input, preserve_authored)?;
71
+
72
+ if percentage.is_none() {
73
+ percentage = try_parse_percentage(input);
74
+ }
75
+
76
+ // TODO(Bug 2037742) - Enable calc()-expressions that can only be resolved at
77
+ // computed value time (due to relative lengths, sibling-index(), etc.).
78
+ if matches!(percentage, Some(ref p) if p.to_percentage().is_none()) {
79
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
80
+ }
81
+
82
+ items.push((color, percentage));
83
+
84
+ if input.try_parse(|i| i.expect_comma()).is_err() {
85
+ break;
86
+ }
87
+
88
+ // Early exit to avoid parsing more than 2 colors if the pref is not enabled.
89
+ if !allow_multiple_items && items.len() == 2 {
90
+ break;
91
+ }
92
+ }
93
+
94
+ // ...the color-mix() function takes a list of one or more <color> specifications...
95
+ // <https://drafts.csswg.org/css-color-5/#color-mix>
96
+ let min_item_count = if allow_multiple_items { 1 } else { 2 };
97
+ if items.len() < min_item_count {
98
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
99
+ }
100
+
101
+ // Normalize percentages per:
102
+ // https://drafts.csswg.org/css-values-5/#normalize-mix-percentages
103
+ let (mut sum_specified, mut missing) = (0.0, 0);
104
+ for (_, percentage) in items.iter() {
105
+ if let Some(p) = percentage {
106
+ // Percentage was enforced to be resolvable at parse time.
107
+ sum_specified += p.to_percentage().unwrap();
108
+ } else {
109
+ missing += 1;
110
+ }
111
+ }
112
+
113
+ // When any specified percentage is a calc(), omitted percentages are left
114
+ // unresolved so they serialize to nothing per
115
+ // https://drafts.csswg.org/css-color-5/#serial-color-mix, and are filled in
116
+ // at mix time instead.
117
+ let any_calc = items
118
+ .iter()
119
+ .any(|(_, p)| matches!(p, Some(p) if p.is_calc()));
120
+
121
+ let default_for_missing_items = if any_calc {
122
+ None
123
+ } else {
124
+ match missing {
125
+ 0 => None,
126
+ m if m == items.len() => Some(Percentage::new(1.0 / items.len() as f32)),
127
+ m => Some(Percentage::new((1.0 - sum_specified) / m as f32)),
128
+ }
129
+ };
130
+
131
+ if let Some(default) = default_for_missing_items {
132
+ for (_, percentage) in items.iter_mut() {
133
+ if percentage.is_none() {
134
+ *percentage = Some(default.clone());
135
+ }
136
+ }
137
+ }
138
+
139
+ let finalized = items
140
+ .into_iter()
141
+ .map(|(color, percentage)| GenericColorMixItem {
142
+ color,
143
+ percentage: percentage.into(),
144
+ })
145
+ .collect::<ColorMixItemList<_>>();
146
+
147
+ // Pass RESULT_IN_MODERN_SYNTAX here, because the result of the color-mix() function
148
+ // should always be in the modern color syntax to allow for out of gamut results and
149
+ // to preserve floating point precision.
150
+ Ok(ColorMix {
151
+ interpolation,
152
+ items: OwnedSlice::from_slice(&finalized),
153
+ flags: ColorMixFlags::NORMALIZE_WEIGHTS | ColorMixFlags::RESULT_IN_MODERN_SYNTAX,
154
+ })
155
+ })
156
+ }
157
+ }
158
+
159
+ /// Container holding an absolute color and the text specified by an author.
160
+ #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToShmem)]
161
+ pub struct Absolute {
162
+ /// The specified color.
163
+ pub color: AbsoluteColor,
164
+ /// Authored representation.
165
+ pub authored: Option<Box<str>>,
166
+ }
167
+
168
+ impl ToCss for Absolute {
169
+ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
170
+ where
171
+ W: Write,
172
+ {
173
+ if let Some(ref authored) = self.authored {
174
+ dest.write_str(authored)
175
+ } else {
176
+ self.color.to_css(dest)
177
+ }
178
+ }
179
+ }
180
+
181
+ /// Specified color value
182
+ #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToShmem)]
183
+ pub enum Color {
184
+ /// The 'currentColor' keyword
185
+ CurrentColor,
186
+ /// An absolute color.
187
+ /// https://w3c.github.io/csswg-drafts/css-color-4/#typedef-absolute-color-function
188
+ Absolute(Box<Absolute>),
189
+ /// A color function that could not be resolved to a [Color::Absolute] color at parse time.
190
+ ColorFunction(Box<ColorFunction<Self>>),
191
+ /// A system color.
192
+ System(SystemColor),
193
+ /// A color mix.
194
+ ColorMix(Box<ColorMix>),
195
+ /// A light-dark() color.
196
+ LightDark(Box<GenericLightDark<Self>>),
197
+ /// The contrast-color function.
198
+ ContrastColor(Box<Color>),
199
+ /// Quirksmode-only rule for inheriting color from the body
200
+ InheritFromBodyQuirk,
201
+ }
202
+
203
+ impl From<AbsoluteColor> for Color {
204
+ #[inline]
205
+ fn from(value: AbsoluteColor) -> Self {
206
+ Self::from_absolute_color(value)
207
+ }
208
+ }
209
+
210
+ /// System colors. A bunch of these are ad-hoc, others come from Windows:
211
+ ///
212
+ /// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsyscolor
213
+ ///
214
+ /// Others are HTML/CSS specific. Spec is:
215
+ ///
216
+ /// https://drafts.csswg.org/css-color/#css-system-colors
217
+ /// https://drafts.csswg.org/css-color/#deprecated-system-colors
218
+ #[allow(missing_docs)]
219
+ #[cfg(feature = "gecko")]
220
+ #[derive(Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, ToCss, ToShmem)]
221
+ #[repr(u8)]
222
+ pub enum SystemColor {
223
+ Activeborder,
224
+ /// Background in the (active) titlebar.
225
+ Activecaption,
226
+ Appworkspace,
227
+ Background,
228
+ Buttonface,
229
+ Buttonhighlight,
230
+ Buttonshadow,
231
+ Buttontext,
232
+ Buttonborder,
233
+ /// Text color in the (active) titlebar.
234
+ Captiontext,
235
+ #[parse(aliases = "-moz-field")]
236
+ Field,
237
+ /// Used for disabled field backgrounds.
238
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
239
+ MozDisabledfield,
240
+ #[parse(aliases = "-moz-fieldtext")]
241
+ Fieldtext,
242
+
243
+ Mark,
244
+ Marktext,
245
+
246
+ /// Combobox widgets
247
+ MozComboboxtext,
248
+ MozCombobox,
249
+
250
+ Graytext,
251
+ Highlight,
252
+ Highlighttext,
253
+ Inactiveborder,
254
+ /// Background in the (inactive) titlebar.
255
+ Inactivecaption,
256
+ /// Text color in the (inactive) titlebar.
257
+ Inactivecaptiontext,
258
+ Infobackground,
259
+ Infotext,
260
+ Menu,
261
+ Menutext,
262
+ Scrollbar,
263
+ Threeddarkshadow,
264
+ Threedface,
265
+ Threedhighlight,
266
+ Threedlightshadow,
267
+ Threedshadow,
268
+ Window,
269
+ Windowframe,
270
+ Windowtext,
271
+ #[parse(aliases = "-moz-default-color")]
272
+ Canvastext,
273
+ #[parse(aliases = "-moz-default-background-color")]
274
+ Canvas,
275
+ MozDialog,
276
+ MozDialogtext,
277
+ /// Used for selected but not focused cell backgrounds.
278
+ #[parse(aliases = "-moz-html-cellhighlight")]
279
+ MozCellhighlight,
280
+ /// Used for selected but not focused cell text.
281
+ #[parse(aliases = "-moz-html-cellhighlighttext")]
282
+ MozCellhighlighttext,
283
+ /// Used for selected and focused html cell backgrounds.
284
+ Selecteditem,
285
+ /// Used for selected and focused html cell text.
286
+ Selecteditemtext,
287
+ /// Used for menu item backgrounds when hovered.
288
+ MozMenuhover,
289
+ /// Used for menu item backgrounds when hovered and disabled.
290
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
291
+ MozMenuhoverdisabled,
292
+ /// Used for menu item text when hovered.
293
+ MozMenuhovertext,
294
+ /// Used for menubar item text when hovered.
295
+ MozMenubarhovertext,
296
+
297
+ /// On platforms where this color is the same as field, or transparent, use fieldtext as
298
+ /// foreground color.
299
+ MozOddtreerow,
300
+
301
+ /// Used for button text background when hovered.
302
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
303
+ MozButtonhoverface,
304
+ /// Used for button text color when hovered.
305
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
306
+ MozButtonhovertext,
307
+ /// Used for button border color when hovered.
308
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
309
+ MozButtonhoverborder,
310
+ /// Used for button background when pressed.
311
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
312
+ MozButtonactiveface,
313
+ /// Used for button text when pressed.
314
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
315
+ MozButtonactivetext,
316
+ /// Used for button border when pressed.
317
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
318
+ MozButtonactiveborder,
319
+
320
+ /// Used for button background when disabled.
321
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
322
+ MozButtondisabledface,
323
+ /// Used for button border when disabled.
324
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
325
+ MozButtondisabledborder,
326
+
327
+ /// Colors used for the header bar (sorta like the tab bar / menubar).
328
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
329
+ MozHeaderbar,
330
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
331
+ MozHeaderbartext,
332
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
333
+ MozHeaderbarinactive,
334
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
335
+ MozHeaderbarinactivetext,
336
+
337
+ /// Foreground color of default buttons.
338
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
339
+ MozMacDefaultbuttontext,
340
+ /// Ring color around text fields and lists.
341
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
342
+ MozMacFocusring,
343
+ /// Text color of disabled text on toolbars.
344
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
345
+ MozMacDisabledtoolbartext,
346
+ /// The background of a sidebar.
347
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
348
+ MozSidebar,
349
+ /// The foreground color of a sidebar.
350
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
351
+ MozSidebartext,
352
+ /// The border color of a sidebar.
353
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
354
+ MozSidebarborder,
355
+
356
+ /// Theme accent color.
357
+ /// https://drafts.csswg.org/css-color-4/#valdef-system-color-accentcolor
358
+ Accentcolor,
359
+
360
+ /// Foreground for the accent color.
361
+ /// https://drafts.csswg.org/css-color-4/#valdef-system-color-accentcolortext
362
+ Accentcolortext,
363
+
364
+ /// The background-color for :autofill-ed inputs.
365
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
366
+ MozAutofillBackground,
367
+
368
+ #[parse(aliases = "-moz-hyperlinktext")]
369
+ Linktext,
370
+ #[parse(aliases = "-moz-activehyperlinktext")]
371
+ Activetext,
372
+ #[parse(aliases = "-moz-visitedhyperlinktext")]
373
+ Visitedtext,
374
+
375
+ /// Color of tree column headers
376
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
377
+ MozColheader,
378
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
379
+ MozColheadertext,
380
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
381
+ MozColheaderhover,
382
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
383
+ MozColheaderhovertext,
384
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
385
+ MozColheaderactive,
386
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
387
+ MozColheaderactivetext,
388
+
389
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
390
+ TextSelectDisabledBackground,
391
+ #[css(skip)]
392
+ TextSelectAttentionBackground,
393
+ #[css(skip)]
394
+ TextSelectAttentionForeground,
395
+ #[css(skip)]
396
+ TextHighlightBackground,
397
+ #[css(skip)]
398
+ TextHighlightForeground,
399
+ #[css(skip)]
400
+ TargetTextBackground,
401
+ #[css(skip)]
402
+ TargetTextForeground,
403
+ #[css(skip)]
404
+ IMERawInputBackground,
405
+ #[css(skip)]
406
+ IMERawInputForeground,
407
+ #[css(skip)]
408
+ IMERawInputUnderline,
409
+ #[css(skip)]
410
+ IMESelectedRawTextBackground,
411
+ #[css(skip)]
412
+ IMESelectedRawTextForeground,
413
+ #[css(skip)]
414
+ IMESelectedRawTextUnderline,
415
+ #[css(skip)]
416
+ IMEConvertedTextBackground,
417
+ #[css(skip)]
418
+ IMEConvertedTextForeground,
419
+ #[css(skip)]
420
+ IMEConvertedTextUnderline,
421
+ #[css(skip)]
422
+ IMESelectedConvertedTextBackground,
423
+ #[css(skip)]
424
+ IMESelectedConvertedTextForeground,
425
+ #[css(skip)]
426
+ IMESelectedConvertedTextUnderline,
427
+ #[css(skip)]
428
+ SpellCheckerUnderline,
429
+ #[css(skip)]
430
+ ThemedScrollbar,
431
+ #[css(skip)]
432
+ ThemedScrollbarThumb,
433
+ #[css(skip)]
434
+ ThemedScrollbarThumbHover,
435
+ #[css(skip)]
436
+ ThemedScrollbarThumbActive,
437
+
438
+ #[css(skip)]
439
+ End, // Just for array-indexing purposes.
440
+ }
441
+
442
+ #[cfg(feature = "gecko")]
443
+ impl SystemColor {
444
+ #[inline]
445
+ fn compute(&self, cx: &Context) -> ComputedColor {
446
+ use crate::gecko_bindings::bindings;
447
+
448
+ let color = cx.device().system_nscolor(*self, cx.builder.color_scheme);
449
+ if cx.for_non_inherited_property {
450
+ cx.rule_cache_conditions
451
+ .borrow_mut()
452
+ .set_color_scheme_dependency(cx.builder.color_scheme);
453
+ }
454
+ if color == bindings::NS_SAME_AS_FOREGROUND_COLOR {
455
+ return ComputedColor::currentcolor();
456
+ }
457
+ ComputedColor::Absolute(AbsoluteColor::from_nscolor(color))
458
+ }
459
+ }
460
+
461
+ /// System colors. A bunch of these are ad-hoc, others come from Windows:
462
+ ///
463
+ /// https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsyscolor
464
+ ///
465
+ /// Others are HTML/CSS specific. Spec is:
466
+ ///
467
+ /// https://drafts.csswg.org/css-color/#css-system-colors
468
+ /// https://drafts.csswg.org/css-color/#deprecated-system-colors
469
+ #[allow(missing_docs)]
470
+ #[cfg(feature = "servo")]
471
+ #[derive(Clone, Copy, Debug, MallocSizeOf, Parse, PartialEq, ToCss, ToShmem)]
472
+ #[repr(u8)]
473
+ pub enum SystemColor {
474
+ Accentcolor,
475
+ Accentcolortext,
476
+ Activetext,
477
+ Linktext,
478
+ Visitedtext,
479
+ Buttonborder,
480
+ Buttonface,
481
+ Buttontext,
482
+ Canvas,
483
+ Canvastext,
484
+ Field,
485
+ Fieldtext,
486
+ Graytext,
487
+ Highlight,
488
+ Highlighttext,
489
+ Mark,
490
+ Marktext,
491
+ Selecteditem,
492
+ Selecteditemtext,
493
+
494
+ // Deprecated system colors.
495
+ Activeborder,
496
+ Inactiveborder,
497
+ Threeddarkshadow,
498
+ Threedhighlight,
499
+ Threedlightshadow,
500
+ Threedshadow,
501
+ Windowframe,
502
+ Buttonhighlight,
503
+ Buttonshadow,
504
+ Threedface,
505
+ Activecaption,
506
+ Appworkspace,
507
+ Background,
508
+ Inactivecaption,
509
+ Infobackground,
510
+ Menu,
511
+ Scrollbar,
512
+ Window,
513
+ Captiontext,
514
+ Infotext,
515
+ Menutext,
516
+ Windowtext,
517
+ Inactivecaptiontext,
518
+ }
519
+
520
+ #[cfg(feature = "servo")]
521
+ impl SystemColor {
522
+ #[inline]
523
+ fn compute(&self, cx: &Context) -> ComputedColor {
524
+ if cx.for_non_inherited_property {
525
+ cx.rule_cache_conditions
526
+ .borrow_mut()
527
+ .set_color_scheme_dependency(cx.builder.color_scheme);
528
+ }
529
+
530
+ ComputedColor::Absolute(cx.device().system_color(*self, cx.builder.color_scheme))
531
+ }
532
+ }
533
+
534
+ /// Whether to preserve authored colors during parsing. That's useful only if we
535
+ /// plan to serialize the color back.
536
+ #[derive(Copy, Clone)]
537
+ enum PreserveAuthored {
538
+ No,
539
+ Yes,
540
+ }
541
+
542
+ impl Parse for Color {
543
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
544
+ Self::parse_internal(context, input, PreserveAuthored::Yes)
545
+ }
546
+ }
547
+
548
+ impl Color {
549
+ fn parse_internal(
550
+ context: &ParserContext,
551
+ input: &mut Parser,
552
+ preserve_authored: PreserveAuthored,
553
+ ) -> Result<Self, ParseError> {
554
+ let authored = match preserve_authored {
555
+ PreserveAuthored::No => None,
556
+ PreserveAuthored::Yes => {
557
+ // Currently we only store authored value for color keywords,
558
+ // because all browsers serialize those values as keywords for
559
+ // specified value.
560
+ let start = input.state();
561
+ let authored = input.expect_ident_cloned().ok();
562
+ input.reset(&start);
563
+ authored
564
+ },
565
+ };
566
+
567
+ match input.try_parse(|i| parsing::parse_color_with(context, i)) {
568
+ Ok(mut color) => {
569
+ if let Color::Absolute(ref mut absolute) = color {
570
+ // Because we can't set the `authored` value at construction time, we have to set it
571
+ // here.
572
+ absolute.authored = authored.map(|s| s.to_ascii_lowercase().into_boxed_str());
573
+ }
574
+ Ok(color)
575
+ },
576
+ Err(e) => {
577
+ {
578
+ #[cfg(feature = "gecko")]
579
+ if let Ok(system) = input.try_parse(|i| SystemColor::parse(context, i)) {
580
+ return Ok(Color::System(system));
581
+ }
582
+ #[cfg(feature = "servo")]
583
+ if let Ok(system) = input.try_parse(SystemColor::parse) {
584
+ return Ok(Color::System(system));
585
+ }
586
+ }
587
+ if let Ok(mix) = input.try_parse(|i| ColorMix::parse(context, i, preserve_authored))
588
+ {
589
+ return Ok(Color::ColorMix(Box::new(mix)));
590
+ }
591
+
592
+ if let Ok(ld) = input.try_parse(|i| {
593
+ GenericLightDark::parse_with(i, |i| {
594
+ Self::parse_internal(context, i, preserve_authored)
595
+ })
596
+ }) {
597
+ return Ok(Color::LightDark(Box::new(ld)));
598
+ }
599
+
600
+ if let Ok(c) = input.try_parse(|i| {
601
+ i.expect_function_matching("contrast-color")?;
602
+ i.parse_nested_block(|i| Self::parse_internal(context, i, preserve_authored))
603
+ }) {
604
+ return Ok(Color::ContrastColor(Box::new(c)));
605
+ }
606
+
607
+ Err(e)
608
+ },
609
+ }
610
+ }
611
+
612
+ /// Returns whether a given color is valid for authors.
613
+ pub fn is_valid(context: &ParserContext, input: &mut Parser) -> bool {
614
+ input
615
+ .parse_entirely(|input| Self::parse_internal(context, input, PreserveAuthored::No))
616
+ .is_ok()
617
+ }
618
+
619
+ /// Tries to parse a color and compute it with a given device.
620
+ pub fn parse_and_compute(
621
+ context: &ParserContext,
622
+ input: &mut Parser,
623
+ device: Option<&Device>,
624
+ ) -> Result<ComputedColor, ()> {
625
+ let result = input
626
+ .parse_entirely(|input| Self::parse_internal(context, input, PreserveAuthored::No));
627
+
628
+ let specified = match result {
629
+ Ok(s) => s,
630
+ Err(..) => return Err(()),
631
+ };
632
+
633
+ match device {
634
+ Some(device) => {
635
+ Context::for_media_query_evaluation(device, device.quirks_mode(), |context| {
636
+ specified.to_computed_color(Some(context))
637
+ })
638
+ },
639
+ None => specified.to_computed_color(None),
640
+ }
641
+ }
642
+ }
643
+
644
+ impl ToCss for Color {
645
+ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
646
+ where
647
+ W: Write,
648
+ {
649
+ match *self {
650
+ Color::CurrentColor => dest.write_str("currentcolor"),
651
+ Color::Absolute(ref absolute) => absolute.to_css(dest),
652
+ Color::ColorFunction(ref color_function) => color_function.to_css(dest),
653
+ Color::ColorMix(ref mix) => mix.to_css(dest),
654
+ Color::LightDark(ref ld) => ld.to_css(dest),
655
+ Color::ContrastColor(ref c) => {
656
+ dest.write_str("contrast-color(")?;
657
+ c.to_css(dest)?;
658
+ dest.write_char(')')
659
+ },
660
+ Color::System(system) => system.to_css(dest),
661
+ Color::InheritFromBodyQuirk => dest.write_str("-moz-inherit-from-body-quirk"),
662
+ }
663
+ }
664
+ }
665
+
666
+ impl ToTyped for Color {
667
+ fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> {
668
+ match *self {
669
+ Color::CurrentColor => {
670
+ dest.push(TypedValue::Keyword(KeywordValue(CssString::from(
671
+ "currentcolor",
672
+ ))));
673
+ Ok(())
674
+ },
675
+ _ => Err(()),
676
+ }
677
+ }
678
+ }
679
+
680
+ impl Color {
681
+ /// Returns whether this color is allowed in forced-colors mode.
682
+ pub fn honored_in_forced_colors_mode(
683
+ &self,
684
+ context: &Context,
685
+ allow_transparent: bool,
686
+ ) -> bool {
687
+ match *self {
688
+ Self::InheritFromBodyQuirk => false,
689
+ Self::CurrentColor => true,
690
+ Self::System(..) => true,
691
+ Self::Absolute(ref absolute) => allow_transparent && absolute.color.is_transparent(),
692
+ Self::ColorFunction(ref color_function) => {
693
+ // For now we allow transparent colors if we can resolve the color function.
694
+ // <https://bugzilla.mozilla.org/show_bug.cgi?id=1923053>
695
+ color_function
696
+ .to_computed_color(Some(context))
697
+ .ok()
698
+ .and_then(|c| c.as_absolute().copied())
699
+ .map(|resolved| allow_transparent && resolved.is_transparent())
700
+ .unwrap_or(false)
701
+ },
702
+ Self::LightDark(ref ld) => {
703
+ ld.light
704
+ .honored_in_forced_colors_mode(context, allow_transparent)
705
+ && ld
706
+ .dark
707
+ .honored_in_forced_colors_mode(context, allow_transparent)
708
+ },
709
+ Self::ColorMix(ref mix) => mix.items.iter().all(|item| {
710
+ item.color
711
+ .honored_in_forced_colors_mode(context, allow_transparent)
712
+ }),
713
+ Self::ContrastColor(ref c) => {
714
+ c.honored_in_forced_colors_mode(context, allow_transparent)
715
+ },
716
+ }
717
+ }
718
+
719
+ /// Returns currentcolor value.
720
+ #[inline]
721
+ pub fn currentcolor() -> Self {
722
+ Self::CurrentColor
723
+ }
724
+
725
+ /// Returns transparent value.
726
+ #[inline]
727
+ pub fn transparent() -> Self {
728
+ // We should probably set authored to "transparent", but maybe it doesn't matter.
729
+ Self::from_absolute_color(AbsoluteColor::TRANSPARENT_BLACK)
730
+ }
731
+
732
+ /// Create a color from an [`AbsoluteColor`].
733
+ pub fn from_absolute_color(color: AbsoluteColor) -> Self {
734
+ Color::Absolute(Box::new(Absolute {
735
+ color,
736
+ authored: None,
737
+ }))
738
+ }
739
+
740
+ /// Parse a color, with quirks.
741
+ ///
742
+ /// <https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk>
743
+ pub fn parse_quirky(
744
+ context: &ParserContext,
745
+ input: &mut Parser,
746
+ allow_quirks: AllowQuirks,
747
+ ) -> Result<Self, ParseError> {
748
+ input.try_parse(|i| Self::parse(context, i)).or_else(|e| {
749
+ if !allow_quirks.allowed(context.quirks_mode) {
750
+ return Err(e);
751
+ }
752
+ Color::parse_quirky_color(input).map_err(|_| e)
753
+ })
754
+ }
755
+
756
+ fn parse_hash(bytes: &[u8]) -> Result<Self, ParseError> {
757
+ match cssparser::color::parse_hash_color(bytes) {
758
+ Ok((r, g, b, a)) => Ok(Self::from_absolute_color(AbsoluteColor::srgb_legacy(
759
+ r, g, b, a,
760
+ ))),
761
+ Err(()) => Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError)),
762
+ }
763
+ }
764
+
765
+ /// Parse a <quirky-color> value.
766
+ ///
767
+ /// <https://quirks.spec.whatwg.org/#the-hashless-hex-color-quirk>
768
+ fn parse_quirky_color(input: &mut Parser) -> Result<Self, ParseError> {
769
+ let (value, unit) = match *input.next()? {
770
+ Token::Number {
771
+ int_value: Some(integer),
772
+ ..
773
+ } => (integer, None),
774
+ Token::Dimension {
775
+ int_value: Some(integer),
776
+ ref unit,
777
+ ..
778
+ } => (integer, Some(unit)),
779
+ Token::Ident(ref ident) => {
780
+ if ident.len() != 3 && ident.len() != 6 {
781
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
782
+ }
783
+ return Self::parse_hash(ident.as_bytes());
784
+ },
785
+ _ => {
786
+ return Err(ParseError::unexpected_token());
787
+ },
788
+ };
789
+ if value < 0 {
790
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
791
+ }
792
+ let length = if value <= 9 {
793
+ 1
794
+ } else if value <= 99 {
795
+ 2
796
+ } else if value <= 999 {
797
+ 3
798
+ } else if value <= 9999 {
799
+ 4
800
+ } else if value <= 99999 {
801
+ 5
802
+ } else if value <= 999999 {
803
+ 6
804
+ } else {
805
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
806
+ };
807
+ let total = length + unit.as_ref().map_or(0, |d| d.len());
808
+ if total > 6 {
809
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
810
+ }
811
+ let mut serialization = [b'0'; 6];
812
+ let space_padding = 6 - total;
813
+ let mut written = space_padding;
814
+ let mut buf = itoa::Buffer::new();
815
+ let s = buf.format(value);
816
+ (&mut serialization[written..])
817
+ .write_all(s.as_bytes())
818
+ .unwrap();
819
+ written += s.len();
820
+ if let Some(unit) = unit {
821
+ written += (&mut serialization[written..])
822
+ .write(unit.as_bytes())
823
+ .unwrap();
824
+ }
825
+ debug_assert_eq!(written, 6);
826
+ Self::parse_hash(&serialization)
827
+ }
828
+ }
829
+
830
+ impl Color {
831
+ /// Converts this Color into a ComputedColor.
832
+ ///
833
+ /// If `context` is `None`, and the specified color requires data from
834
+ /// the context to resolve, then `None` is returned.
835
+ pub fn to_computed_color(&self, context: Option<&Context>) -> Result<ComputedColor, ()> {
836
+ macro_rules! adjust_absolute_color {
837
+ ($color:expr) => {{
838
+ // Computed lightness values can not be NaN.
839
+ if matches!(
840
+ $color.color_space,
841
+ ColorSpace::Lab | ColorSpace::Oklab | ColorSpace::Lch | ColorSpace::Oklch
842
+ ) {
843
+ $color.components.0 = normalize($color.components.0);
844
+ }
845
+
846
+ // Computed RGB and XYZ components can not be NaN.
847
+ if !$color.is_legacy_syntax() && $color.color_space.is_rgb_or_xyz_like() {
848
+ $color.components = $color.components.map(normalize);
849
+ }
850
+
851
+ $color.alpha = normalize($color.alpha);
852
+ }};
853
+ }
854
+
855
+ Ok(match *self {
856
+ Color::CurrentColor => ComputedColor::CurrentColor,
857
+ Color::Absolute(ref absolute) => {
858
+ let mut color = absolute.color;
859
+ adjust_absolute_color!(color);
860
+ ComputedColor::Absolute(color)
861
+ },
862
+ Color::ColorFunction(ref color_function) => {
863
+ color_function.to_computed_color(context)?
864
+ },
865
+ Color::LightDark(ref ld) => ld.compute(context.ok_or(())?),
866
+ Color::ColorMix(ref mix) => {
867
+ let mut items = ColorMixItemList::with_capacity(mix.items.len());
868
+ for item in mix.items.iter() {
869
+ items.push(GenericColorMixItem {
870
+ color: item.color.to_computed_color(context)?,
871
+ percentage: match item.percentage.as_ref() {
872
+ None => Optional::None,
873
+ Some(percentage) => Optional::Some(match context {
874
+ None => ComputedPercentage(percentage.to_percentage().ok_or(())?),
875
+ Some(ctx) => percentage.to_computed_value(ctx),
876
+ }),
877
+ },
878
+ });
879
+ }
880
+
881
+ ComputedColor::from_color_mix(GenericColorMix {
882
+ interpolation: mix.interpolation,
883
+ items: OwnedSlice::from_slice(items.as_slice()),
884
+ flags: mix.flags,
885
+ })
886
+ },
887
+ Color::ContrastColor(ref c) => {
888
+ let computed = c.to_computed_color(context)?;
889
+ if let Some(abs) = computed.as_absolute() {
890
+ ComputedColor::Absolute(ComputedColor::resolve_contrast_color(abs))
891
+ } else {
892
+ ComputedColor::ContrastColor(Box::new(computed))
893
+ }
894
+ },
895
+ Color::System(system) => system.compute(context.ok_or(())?),
896
+ Color::InheritFromBodyQuirk => {
897
+ ComputedColor::Absolute(context.ok_or(())?.device().body_text_color())
898
+ },
899
+ })
900
+ }
901
+ }
902
+
903
+ impl ToComputedValue for Color {
904
+ type ComputedValue = ComputedColor;
905
+
906
+ fn to_computed_value(&self, context: &Context) -> ComputedColor {
907
+ self.to_computed_color(Some(context)).unwrap_or_else(|_| {
908
+ debug_assert!(
909
+ false,
910
+ "Specified color could not be resolved to a computed color!"
911
+ );
912
+ ComputedColor::Absolute(AbsoluteColor::BLACK)
913
+ })
914
+ }
915
+
916
+ fn from_computed_value(computed: &ComputedColor) -> Self {
917
+ match *computed {
918
+ ComputedColor::Absolute(ref color) => Self::from_absolute_color(*color),
919
+ ComputedColor::ColorFunction(ref color_function) => {
920
+ let color_function = color_function
921
+ .map_origin_color(|o| Ok(Self::from_computed_value(o)))
922
+ .unwrap();
923
+ Self::ColorFunction(Box::new(color_function))
924
+ },
925
+ ComputedColor::CurrentColor => Color::CurrentColor,
926
+ ComputedColor::ColorMix(ref mix) => {
927
+ Color::ColorMix(Box::new(ToComputedValue::from_computed_value(&**mix)))
928
+ },
929
+ ComputedColor::ContrastColor(ref c) => {
930
+ Self::ContrastColor(Box::new(ToComputedValue::from_computed_value(&**c)))
931
+ },
932
+ }
933
+ }
934
+ }
935
+
936
+ impl SpecifiedValueInfo for Color {
937
+ const SUPPORTED_TYPES: u8 = CssType::COLOR;
938
+
939
+ fn collect_completion_keywords(f: KeywordsCollectFn) {
940
+ // We are not going to insert all the color names here. Caller and
941
+ // devtools should take care of them. XXX Actually, transparent
942
+ // should probably be handled that way as well.
943
+ // XXX `currentColor` should really be `currentcolor`. But let's
944
+ // keep it consistent with the old system for now.
945
+ f(&[
946
+ "currentColor",
947
+ "transparent",
948
+ "rgb",
949
+ "rgba",
950
+ "hsl",
951
+ "hsla",
952
+ "hwb",
953
+ "color",
954
+ "lab",
955
+ "lch",
956
+ "oklab",
957
+ "oklch",
958
+ "color-mix",
959
+ "contrast-color",
960
+ "light-dark",
961
+ ]);
962
+ }
963
+ }
964
+
965
+ /// Specified value for the "color" property, which resolves the `currentcolor`
966
+ /// keyword to the parent color instead of self's color.
967
+ #[cfg_attr(feature = "gecko", derive(MallocSizeOf))]
968
+ #[derive(Clone, Debug, PartialEq, SpecifiedValueInfo, ToCss, ToShmem, ToTyped)]
969
+ pub struct ColorPropertyValue(pub Color);
970
+
971
+ impl ToComputedValue for ColorPropertyValue {
972
+ type ComputedValue = AbsoluteColor;
973
+
974
+ #[inline]
975
+ fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
976
+ let current_color = context.builder.get_parent_inherited_text().clone_color();
977
+ self.0
978
+ .to_computed_value(context)
979
+ .resolve_to_absolute(&current_color)
980
+ }
981
+
982
+ #[inline]
983
+ fn from_computed_value(computed: &Self::ComputedValue) -> Self {
984
+ ColorPropertyValue(Color::from_absolute_color(*computed))
985
+ }
986
+ }
987
+
988
+ impl Parse for ColorPropertyValue {
989
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
990
+ Color::parse_quirky(context, input, AllowQuirks::Yes).map(ColorPropertyValue)
991
+ }
992
+ }
993
+
994
+ /// auto | <color>
995
+ pub type ColorOrAuto = GenericColorOrAuto<Color>;
996
+
997
+ /// caret-color
998
+ pub type CaretColor = GenericCaretColor<Color>;
999
+
1000
+ impl Parse for CaretColor {
1001
+ fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
1002
+ ColorOrAuto::parse(context, input).map(GenericCaretColor)
1003
+ }
1004
+ }
1005
+
1006
+ /// Various flags to represent the color-scheme property in an efficient
1007
+ /// way.
1008
+ #[derive(
1009
+ Clone,
1010
+ Copy,
1011
+ Debug,
1012
+ Default,
1013
+ Eq,
1014
+ MallocSizeOf,
1015
+ PartialEq,
1016
+ SpecifiedValueInfo,
1017
+ ToComputedValue,
1018
+ ToResolvedValue,
1019
+ ToShmem,
1020
+ )]
1021
+ #[repr(C)]
1022
+ #[value_info(other_values = "light,dark,only")]
1023
+ pub struct ColorSchemeFlags(u8);
1024
+ bitflags! {
1025
+ impl ColorSchemeFlags: u8 {
1026
+ /// Whether the author specified `light`.
1027
+ const LIGHT = 1 << 0;
1028
+ /// Whether the author specified `dark`.
1029
+ const DARK = 1 << 1;
1030
+ /// Whether the author specified `only`.
1031
+ const ONLY = 1 << 2;
1032
+ }
1033
+ }
1034
+
1035
+ /// <https://drafts.csswg.org/css-color-adjust/#color-scheme-prop>
1036
+ #[derive(
1037
+ Clone,
1038
+ Debug,
1039
+ Default,
1040
+ MallocSizeOf,
1041
+ PartialEq,
1042
+ SpecifiedValueInfo,
1043
+ ToComputedValue,
1044
+ ToResolvedValue,
1045
+ ToShmem,
1046
+ ToTyped,
1047
+ )]
1048
+ #[repr(C)]
1049
+ #[typed(todo_derive_fields)]
1050
+ #[value_info(other_values = "normal")]
1051
+ pub struct ColorScheme {
1052
+ #[ignore_malloc_size_of = "Arc"]
1053
+ idents: crate::ArcSlice<CustomIdent>,
1054
+ /// The computed bits for the known color schemes (plus the only keyword).
1055
+ pub bits: ColorSchemeFlags,
1056
+ }
1057
+
1058
+ impl ColorScheme {
1059
+ /// Returns the `normal` value.
1060
+ pub fn normal() -> Self {
1061
+ Self {
1062
+ idents: Default::default(),
1063
+ bits: ColorSchemeFlags::empty(),
1064
+ }
1065
+ }
1066
+
1067
+ /// Returns the raw bitfield.
1068
+ pub fn raw_bits(&self) -> u8 {
1069
+ self.bits.bits()
1070
+ }
1071
+ }
1072
+
1073
+ impl Parse for ColorScheme {
1074
+ fn parse(_: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
1075
+ let mut idents = vec![];
1076
+ let mut bits = ColorSchemeFlags::empty();
1077
+
1078
+ while let Ok(ident) = input.try_parse(|i| i.expect_ident_cloned()) {
1079
+ let mut is_only = false;
1080
+ match_ignore_ascii_case! { &ident,
1081
+ "normal" => {
1082
+ if idents.is_empty() && bits.is_empty() {
1083
+ return Ok(Self::normal());
1084
+ }
1085
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
1086
+ },
1087
+ "light" => bits.insert(ColorSchemeFlags::LIGHT),
1088
+ "dark" => bits.insert(ColorSchemeFlags::DARK),
1089
+ "only" => {
1090
+ if bits.intersects(ColorSchemeFlags::ONLY) {
1091
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
1092
+ }
1093
+ bits.insert(ColorSchemeFlags::ONLY);
1094
+ is_only = true;
1095
+ },
1096
+ _ => {},
1097
+ };
1098
+
1099
+ if is_only {
1100
+ if !idents.is_empty() {
1101
+ // Only is allowed either at the beginning or at the end,
1102
+ // but not in the middle.
1103
+ break;
1104
+ }
1105
+ } else {
1106
+ idents.push(CustomIdent::from_ident(&ident, &[])?);
1107
+ }
1108
+ }
1109
+
1110
+ if idents.is_empty() {
1111
+ return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
1112
+ }
1113
+
1114
+ Ok(Self {
1115
+ idents: crate::ArcSlice::from_iter(idents.into_iter()),
1116
+ bits,
1117
+ })
1118
+ }
1119
+ }
1120
+
1121
+ impl ToCss for ColorScheme {
1122
+ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
1123
+ where
1124
+ W: Write,
1125
+ {
1126
+ if self.idents.is_empty() {
1127
+ debug_assert!(self.bits.is_empty());
1128
+ return dest.write_str("normal");
1129
+ }
1130
+ let mut first = true;
1131
+ for ident in self.idents.iter() {
1132
+ if !first {
1133
+ dest.write_char(' ')?;
1134
+ }
1135
+ first = false;
1136
+ ident.to_css(dest)?;
1137
+ }
1138
+ if self.bits.intersects(ColorSchemeFlags::ONLY) {
1139
+ dest.write_str(" only")?;
1140
+ }
1141
+ Ok(())
1142
+ }
1143
+ }
1144
+
1145
+ /// https://drafts.csswg.org/css-color-adjust/#print-color-adjust
1146
+ #[derive(
1147
+ Clone,
1148
+ Copy,
1149
+ Debug,
1150
+ MallocSizeOf,
1151
+ Parse,
1152
+ PartialEq,
1153
+ SpecifiedValueInfo,
1154
+ ToCss,
1155
+ ToComputedValue,
1156
+ ToResolvedValue,
1157
+ ToShmem,
1158
+ ToTyped,
1159
+ )]
1160
+ #[repr(u8)]
1161
+ pub enum PrintColorAdjust {
1162
+ /// Ignore backgrounds and darken text.
1163
+ Economy,
1164
+ /// Respect specified colors.
1165
+ Exact,
1166
+ }
1167
+
1168
+ /// https://drafts.csswg.org/css-color-adjust-1/#forced-color-adjust-prop
1169
+ #[derive(
1170
+ Clone,
1171
+ Copy,
1172
+ Debug,
1173
+ MallocSizeOf,
1174
+ Parse,
1175
+ PartialEq,
1176
+ SpecifiedValueInfo,
1177
+ ToCss,
1178
+ ToComputedValue,
1179
+ ToResolvedValue,
1180
+ ToShmem,
1181
+ ToTyped,
1182
+ )]
1183
+ #[repr(u8)]
1184
+ pub enum ForcedColorAdjust {
1185
+ /// Adjust colors if needed.
1186
+ Auto,
1187
+ /// Respect specified colors.
1188
+ None,
1189
+ }
1190
+
1191
+ /// Possible values for the forced-colors media query.
1192
+ /// <https://drafts.csswg.org/mediaqueries-5/#forced-colors>
1193
+ #[derive(Clone, Copy, Debug, FromPrimitive, Parse, PartialEq, ToCss)]
1194
+ #[repr(u8)]
1195
+ pub enum ForcedColors {
1196
+ /// Page colors are not being forced.
1197
+ None,
1198
+ /// Page colors would be forced in content.
1199
+ #[parse(condition = "ParserContext::chrome_rules_enabled")]
1200
+ Requested,
1201
+ /// Page colors are being forced.
1202
+ Active,
1203
+ }
1204
+
1205
+ impl ForcedColors {
1206
+ /// Returns whether forced-colors is active for this page.
1207
+ pub fn is_active(self) -> bool {
1208
+ matches!(self, Self::Active)
1209
+ }
1210
+ }