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,750 @@
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
+ //! Color support functions.
6
+
7
+ /// cbindgen:ignore
8
+ pub mod convert;
9
+
10
+ mod color_function;
11
+ pub mod component;
12
+ pub mod gamut;
13
+ pub mod mix;
14
+ pub mod parsing;
15
+ mod to_css;
16
+
17
+ use self::parsing::ChannelKeyword;
18
+ use crate::derives::*;
19
+ pub use color_function::*;
20
+ use component::ColorComponent;
21
+ use cssparser::color::PredefinedColorSpace;
22
+
23
+ /// Number of color-mix items to reserve on the stack to avoid heap allocations.
24
+ pub const PRE_ALLOCATED_COLOR_MIX_ITEMS: usize = 3;
25
+
26
+ /// Conveniece type to use for collecting color mix items.
27
+ pub type ColorMixItemList<T> = smallvec::SmallVec<[T; PRE_ALLOCATED_COLOR_MIX_ITEMS]>;
28
+
29
+ /// The 3 components that make up a color. (Does not include the alpha component)
30
+ #[derive(Copy, Clone, Debug, Deserialize, MallocSizeOf, PartialEq, Serialize, ToShmem)]
31
+ #[repr(C)]
32
+ pub struct ColorComponents(pub f32, pub f32, pub f32);
33
+
34
+ impl ColorComponents {
35
+ /// Apply a function to each of the 3 components of the color.
36
+ #[must_use]
37
+ pub fn map(self, f: impl Fn(f32) -> f32) -> Self {
38
+ Self(f(self.0), f(self.1), f(self.2))
39
+ }
40
+
41
+ /// Return the components as an array
42
+ #[inline]
43
+ pub fn to_array(&self) -> [f32; 3] {
44
+ [self.0, self.1, self.2]
45
+ }
46
+ }
47
+
48
+ impl std::ops::Add for ColorComponents {
49
+ type Output = Self;
50
+
51
+ fn add(self, rhs: Self) -> Self::Output {
52
+ Self(self.0 + rhs.0, self.1 + rhs.1, self.2 + rhs.2)
53
+ }
54
+ }
55
+
56
+ impl std::ops::Sub for ColorComponents {
57
+ type Output = Self;
58
+
59
+ fn sub(self, rhs: Self) -> Self::Output {
60
+ Self(self.0 - rhs.0, self.1 - rhs.1, self.2 - rhs.2)
61
+ }
62
+ }
63
+
64
+ impl std::ops::Mul for ColorComponents {
65
+ type Output = Self;
66
+
67
+ fn mul(self, rhs: Self) -> Self::Output {
68
+ Self(self.0 * rhs.0, self.1 * rhs.1, self.2 * rhs.2)
69
+ }
70
+ }
71
+
72
+ impl std::ops::Div for ColorComponents {
73
+ type Output = Self;
74
+
75
+ fn div(self, rhs: Self) -> Self::Output {
76
+ Self(self.0 / rhs.0, self.1 / rhs.1, self.2 / rhs.2)
77
+ }
78
+ }
79
+
80
+ /// A color space representation in the CSS specification.
81
+ ///
82
+ /// https://drafts.csswg.org/css-color-4/#typedef-color-space
83
+ #[derive(
84
+ Clone,
85
+ Copy,
86
+ Debug,
87
+ Deserialize,
88
+ Eq,
89
+ MallocSizeOf,
90
+ Parse,
91
+ PartialEq,
92
+ Serialize,
93
+ ToAnimatedValue,
94
+ ToComputedValue,
95
+ ToCss,
96
+ ToResolvedValue,
97
+ ToShmem,
98
+ )]
99
+ #[repr(u8)]
100
+ pub enum ColorSpace {
101
+ /// A color specified in the sRGB color space with either the rgb/rgba(..)
102
+ /// functions or the newer color(srgb ..) function. If the color(..)
103
+ /// function is used, the AS_COLOR_FUNCTION flag will be set. Examples:
104
+ /// "color(srgb 0.691 0.139 0.259)", "rgb(176, 35, 66)"
105
+ Srgb = 0,
106
+ /// A color specified in the Hsl notation in the sRGB color space, e.g.
107
+ /// "hsl(289.18 93.136% 65.531%)"
108
+ /// https://drafts.csswg.org/css-color-4/#the-hsl-notation
109
+ Hsl,
110
+ /// A color specified in the Hwb notation in the sRGB color space, e.g.
111
+ /// "hwb(740deg 20% 30%)"
112
+ /// https://drafts.csswg.org/css-color-4/#the-hwb-notation
113
+ Hwb,
114
+ /// A color specified in the Lab color format, e.g.
115
+ /// "lab(29.2345% 39.3825 20.0664)".
116
+ /// https://w3c.github.io/csswg-drafts/css-color-4/#lab-colors
117
+ Lab,
118
+ /// A color specified in the Lch color format, e.g.
119
+ /// "lch(29.2345% 44.2 27)".
120
+ /// https://w3c.github.io/csswg-drafts/css-color-4/#lch-colors
121
+ Lch,
122
+ /// A color specified in the Oklab color format, e.g.
123
+ /// "oklab(40.101% 0.1147 0.0453)".
124
+ /// https://w3c.github.io/csswg-drafts/css-color-4/#lab-colors
125
+ Oklab,
126
+ /// A color specified in the Oklch color format, e.g.
127
+ /// "oklch(40.101% 0.12332 21.555)".
128
+ /// https://w3c.github.io/csswg-drafts/css-color-4/#lch-colors
129
+ Oklch,
130
+ /// A color specified with the color(..) function and the "srgb-linear"
131
+ /// color space, e.g. "color(srgb-linear 0.435 0.017 0.055)".
132
+ SrgbLinear,
133
+ /// A color specified with the color(..) function and the "display-p3"
134
+ /// color space, e.g. "color(display-p3 0.84 0.19 0.72)".
135
+ DisplayP3,
136
+ /// A color specified with the color(..) function and the "display-p3-linear"
137
+ /// color space.
138
+ DisplayP3Linear,
139
+ /// A color specified with the color(..) function and the "a98-rgb" color
140
+ /// space, e.g. "color(a98-rgb 0.44091 0.49971 0.37408)".
141
+ A98Rgb,
142
+ /// A color specified with the color(..) function and the "prophoto-rgb"
143
+ /// color space, e.g. "color(prophoto-rgb 0.36589 0.41717 0.31333)".
144
+ ProphotoRgb,
145
+ /// A color specified with the color(..) function and the "rec2020" color
146
+ /// space, e.g. "color(rec2020 0.42210 0.47580 0.35605)".
147
+ Rec2020,
148
+ /// A color specified with the color(..) function and the "xyz-d50" color
149
+ /// space, e.g. "color(xyz-d50 0.2005 0.14089 0.4472)".
150
+ XyzD50,
151
+ /// A color specified with the color(..) function and the "xyz-d65" or "xyz"
152
+ /// color space, e.g. "color(xyz-d65 0.21661 0.14602 0.59452)".
153
+ /// NOTE: https://drafts.csswg.org/css-color-4/#resolving-color-function-values
154
+ /// specifies that `xyz` is an alias for the `xyz-d65` color space.
155
+ #[parse(aliases = "xyz")]
156
+ XyzD65,
157
+ }
158
+
159
+ impl ColorSpace {
160
+ /// Returns whether this is a `<rectangular-color-space>`.
161
+ #[inline]
162
+ pub fn is_rectangular(&self) -> bool {
163
+ !self.is_polar()
164
+ }
165
+
166
+ /// Returns whether this is a `<polar-color-space>`.
167
+ #[inline]
168
+ pub fn is_polar(&self) -> bool {
169
+ matches!(self, Self::Hsl | Self::Hwb | Self::Lch | Self::Oklch)
170
+ }
171
+
172
+ /// Returns true if the color has RGB or XYZ components.
173
+ #[inline]
174
+ pub fn is_rgb_or_xyz_like(&self) -> bool {
175
+ match self {
176
+ Self::Srgb
177
+ | Self::SrgbLinear
178
+ | Self::DisplayP3
179
+ | Self::DisplayP3Linear
180
+ | Self::A98Rgb
181
+ | Self::ProphotoRgb
182
+ | Self::Rec2020
183
+ | Self::XyzD50
184
+ | Self::XyzD65 => true,
185
+ _ => false,
186
+ }
187
+ }
188
+
189
+ /// Returns an index of the hue component in the color space, otherwise
190
+ /// `None`.
191
+ #[inline]
192
+ pub fn hue_index(&self) -> Option<usize> {
193
+ match self {
194
+ Self::Hsl | Self::Hwb => Some(0),
195
+ Self::Lch | Self::Oklch => Some(2),
196
+
197
+ _ => {
198
+ debug_assert!(!self.is_polar());
199
+ None
200
+ },
201
+ }
202
+ }
203
+
204
+ /// Returns the corresponding linear version of this color space if
205
+ /// one exists, else returns `None`.
206
+ /// Linear color spaces return themselves; this includes XYZ.
207
+ /// Perceptual/non-RGB color spaces return None.
208
+ #[inline]
209
+ pub fn get_linear_color_space(self) -> Option<Self> {
210
+ match self {
211
+ Self::Srgb | Self::Hsl | Self::Hwb => Some(Self::SrgbLinear),
212
+ Self::DisplayP3 => Some(Self::DisplayP3Linear),
213
+ Self::SrgbLinear | Self::DisplayP3Linear | Self::XyzD50 | Self::XyzD65 => Some(self),
214
+ // We currently don't have the linear versions of these wide RGB spaces
215
+ // implemented, so returning `None`` for the time being. Grouping them
216
+ // separately here as a nod to future work.
217
+ Self::A98Rgb | Self::ProphotoRgb | Self::Rec2020 => None,
218
+ Self::Lab | Self::Lch | Self::Oklab | Self::Oklch => None,
219
+ }
220
+ }
221
+ }
222
+
223
+ /// Flags used when serializing colors.
224
+ #[derive(Clone, Copy, Debug, Default, MallocSizeOf, PartialEq, ToShmem)]
225
+ #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
226
+ #[repr(C)]
227
+ pub struct ColorFlags(u8);
228
+ bitflags! {
229
+ impl ColorFlags : u8 {
230
+ /// Whether the 1st color component is `none`.
231
+ const C0_IS_NONE = 1 << 0;
232
+ /// Whether the 2nd color component is `none`.
233
+ const C1_IS_NONE = 1 << 1;
234
+ /// Whether the 3rd color component is `none`.
235
+ const C2_IS_NONE = 1 << 2;
236
+ /// Whether the alpha component is `none`.
237
+ const ALPHA_IS_NONE = 1 << 3;
238
+ /// Marks that this color is in the legacy color format. This flag is
239
+ /// only valid for the `Srgb` color space.
240
+ const IS_LEGACY_SRGB = 1 << 4;
241
+ }
242
+ }
243
+
244
+ /// An absolutely specified color, using either rgb(), rgba(), lab(), lch(),
245
+ /// oklab(), oklch() or color().
246
+ #[derive(Copy, Clone, Debug, Deserialize, MallocSizeOf, Serialize, ToShmem, ToTyped)]
247
+ #[repr(C)]
248
+ #[typed(todo_derive_fields)]
249
+ pub struct AbsoluteColor {
250
+ /// The 3 components that make up colors in any color space.
251
+ pub components: ColorComponents,
252
+ /// The alpha component of the color.
253
+ pub alpha: f32,
254
+ /// The current color space that the components represent.
255
+ pub color_space: ColorSpace,
256
+ /// Extra flags used during serialization of this color.
257
+ pub flags: ColorFlags,
258
+ }
259
+
260
+ impl PartialEq for AbsoluteColor {
261
+ // See https://github.com/w3c/csswg-drafts/issues/13157#issuecomment-4165667681
262
+ fn eq(&self, other: &Self) -> bool {
263
+ let none_flags = ColorFlags::C0_IS_NONE
264
+ | ColorFlags::C1_IS_NONE
265
+ | ColorFlags::C2_IS_NONE
266
+ | ColorFlags::ALPHA_IS_NONE;
267
+ // If both colors have the same color-space, just compare components; note that
268
+ // any `none` components only match `none` in the other color.
269
+ if self.color_space == other.color_space {
270
+ return self.components == other.components
271
+ && self.alpha == other.alpha
272
+ && (self.flags & none_flags) == (other.flags & none_flags);
273
+ }
274
+ // Otherwise, if any `none` components are present in either color, return false.
275
+ if self.flags.union(other.flags).intersects(none_flags) {
276
+ return false;
277
+ }
278
+ // Otherwise, convert both colors to Oklab for comparison, and allow EPSILON
279
+ // difference in component values.
280
+ // TODO: check value of EPSILON once the spec is updated to cover this.
281
+ const EPSILON: f32 = 0.0001;
282
+ let a = self.to_color_space(ColorSpace::Oklab);
283
+ let b = other.to_color_space(ColorSpace::Oklab);
284
+ (a.components.0 - b.components.0).abs() <= EPSILON
285
+ && (a.components.1 - b.components.1).abs() <= EPSILON
286
+ && (a.components.2 - b.components.2).abs() <= EPSILON
287
+ && (a.alpha - b.alpha).abs() <= EPSILON
288
+ }
289
+ }
290
+
291
+ /// Given an [`AbsoluteColor`], return the 4 float components as the type given,
292
+ /// e.g.:
293
+ ///
294
+ /// ```rust
295
+ /// let srgb = AbsoluteColor::new(ColorSpace::Srgb, 1.0, 0.0, 0.0, 0.0);
296
+ /// let floats = color_components_as!(&srgb, [f32; 4]); // [1.0, 0.0, 0.0, 0.0]
297
+ /// ```
298
+ macro_rules! color_components_as {
299
+ ($c:expr, $t:ty) => {{
300
+ // This macro is not an inline function, because we can't use the
301
+ // generic type ($t) in a constant expression as per:
302
+ // https://github.com/rust-lang/rust/issues/76560
303
+ const_assert_eq!(std::mem::size_of::<$t>(), std::mem::size_of::<[f32; 4]>());
304
+ const_assert_eq!(std::mem::align_of::<$t>(), std::mem::align_of::<[f32; 4]>());
305
+ const_assert!(std::mem::size_of::<AbsoluteColor>() >= std::mem::size_of::<$t>());
306
+ const_assert_eq!(
307
+ std::mem::align_of::<AbsoluteColor>(),
308
+ std::mem::align_of::<$t>()
309
+ );
310
+
311
+ std::mem::transmute::<&ColorComponents, &$t>(&$c.components)
312
+ }};
313
+ }
314
+
315
+ /// Holds details about each component passed into creating a new [`AbsoluteColor`].
316
+ pub struct ComponentDetails {
317
+ value: f32,
318
+ is_none: bool,
319
+ }
320
+
321
+ impl From<f32> for ComponentDetails {
322
+ fn from(value: f32) -> Self {
323
+ Self {
324
+ value,
325
+ is_none: false,
326
+ }
327
+ }
328
+ }
329
+
330
+ impl From<u8> for ComponentDetails {
331
+ fn from(value: u8) -> Self {
332
+ Self {
333
+ value: value as f32 / 255.0,
334
+ is_none: false,
335
+ }
336
+ }
337
+ }
338
+
339
+ impl From<Option<f32>> for ComponentDetails {
340
+ fn from(value: Option<f32>) -> Self {
341
+ if let Some(value) = value {
342
+ Self {
343
+ value,
344
+ is_none: false,
345
+ }
346
+ } else {
347
+ Self {
348
+ value: 0.0,
349
+ is_none: true,
350
+ }
351
+ }
352
+ }
353
+ }
354
+
355
+ impl From<ColorComponent<f32>> for ComponentDetails {
356
+ fn from(value: ColorComponent<f32>) -> Self {
357
+ if let ColorComponent::Value(value) = value {
358
+ Self {
359
+ value,
360
+ is_none: false,
361
+ }
362
+ } else {
363
+ Self {
364
+ value: 0.0,
365
+ is_none: true,
366
+ }
367
+ }
368
+ }
369
+ }
370
+
371
+ impl AbsoluteColor {
372
+ /// A fully transparent color in the legacy syntax.
373
+ pub const TRANSPARENT_BLACK: Self = Self {
374
+ components: ColorComponents(0.0, 0.0, 0.0),
375
+ alpha: 0.0,
376
+ color_space: ColorSpace::Srgb,
377
+ flags: ColorFlags::IS_LEGACY_SRGB,
378
+ };
379
+
380
+ /// An opaque black color in the legacy syntax.
381
+ pub const BLACK: Self = Self {
382
+ components: ColorComponents(0.0, 0.0, 0.0),
383
+ alpha: 1.0,
384
+ color_space: ColorSpace::Srgb,
385
+ flags: ColorFlags::IS_LEGACY_SRGB,
386
+ };
387
+
388
+ /// An opaque white color in the legacy syntax.
389
+ pub const WHITE: Self = Self {
390
+ components: ColorComponents(1.0, 1.0, 1.0),
391
+ alpha: 1.0,
392
+ color_space: ColorSpace::Srgb,
393
+ flags: ColorFlags::IS_LEGACY_SRGB,
394
+ };
395
+
396
+ /// Create a new [`AbsoluteColor`] with the given [`ColorSpace`] and
397
+ /// components.
398
+ pub fn new(
399
+ color_space: ColorSpace,
400
+ c1: impl Into<ComponentDetails>,
401
+ c2: impl Into<ComponentDetails>,
402
+ c3: impl Into<ComponentDetails>,
403
+ alpha: impl Into<ComponentDetails>,
404
+ ) -> Self {
405
+ let mut flags = ColorFlags::empty();
406
+
407
+ macro_rules! cd {
408
+ ($c:expr,$flag:expr) => {{
409
+ let component_details = $c.into();
410
+ if component_details.is_none {
411
+ flags |= $flag;
412
+ }
413
+ component_details.value
414
+ }};
415
+ }
416
+
417
+ let mut components = ColorComponents(
418
+ cd!(c1, ColorFlags::C0_IS_NONE),
419
+ cd!(c2, ColorFlags::C1_IS_NONE),
420
+ cd!(c3, ColorFlags::C2_IS_NONE),
421
+ );
422
+
423
+ let alpha = cd!(alpha, ColorFlags::ALPHA_IS_NONE);
424
+
425
+ // Lightness for Lab and Lch is clamped to [0..100].
426
+ if matches!(color_space, ColorSpace::Lab | ColorSpace::Lch) {
427
+ components.0 = components.0.clamp(0.0, 100.0);
428
+ }
429
+
430
+ // Lightness for Oklab and Oklch is clamped to [0..1].
431
+ if matches!(color_space, ColorSpace::Oklab | ColorSpace::Oklch) {
432
+ components.0 = components.0.clamp(0.0, 1.0);
433
+ }
434
+
435
+ // Chroma must not be less than 0.
436
+ if matches!(color_space, ColorSpace::Lch | ColorSpace::Oklch) {
437
+ components.1 = components.1.max(0.0);
438
+ }
439
+
440
+ // Alpha is always clamped to [0..1].
441
+ let alpha = alpha.clamp(0.0, 1.0);
442
+
443
+ Self {
444
+ components,
445
+ alpha,
446
+ color_space,
447
+ flags,
448
+ }
449
+ }
450
+
451
+ /// Returns a copy of this color with a modified alpha value.
452
+ pub fn with_alpha(&self, alpha: impl Into<ComponentDetails>) -> Self {
453
+ let mut result = *self;
454
+ let alpha_details = alpha.into();
455
+ result.alpha = alpha_details.value;
456
+ result
457
+ .flags
458
+ .set(ColorFlags::ALPHA_IS_NONE, alpha_details.is_none);
459
+ result.flags.remove(ColorFlags::IS_LEGACY_SRGB);
460
+ result
461
+ }
462
+
463
+ /// Convert this color into the sRGB color space and set it to the legacy
464
+ /// syntax.
465
+ #[inline]
466
+ #[must_use]
467
+ pub fn into_srgb_legacy(self) -> Self {
468
+ let mut result = if !matches!(self.color_space, ColorSpace::Srgb) {
469
+ self.to_color_space(ColorSpace::Srgb)
470
+ } else {
471
+ self
472
+ };
473
+
474
+ // Explicitly set the flags to IS_LEGACY_SRGB only to clear out the
475
+ // *_IS_NONE flags, because the legacy syntax doesn't allow "none".
476
+ result.flags = ColorFlags::IS_LEGACY_SRGB;
477
+
478
+ result
479
+ }
480
+
481
+ /// Create a new [`AbsoluteColor`] from rgba legacy syntax values in the sRGB color space.
482
+ pub fn srgb_legacy(red: u8, green: u8, blue: u8, alpha: f32) -> Self {
483
+ let mut result = Self::new(ColorSpace::Srgb, red, green, blue, alpha);
484
+ result.flags = ColorFlags::IS_LEGACY_SRGB;
485
+ result
486
+ }
487
+
488
+ /// Return all the components of the color in an array. (Includes alpha)
489
+ #[inline]
490
+ pub fn raw_components(&self) -> &[f32; 4] {
491
+ unsafe { color_components_as!(self, [f32; 4]) }
492
+ }
493
+
494
+ /// Returns true if this color is in the legacy color syntax.
495
+ #[inline]
496
+ pub fn is_legacy_syntax(&self) -> bool {
497
+ // rgb(), rgba(), hsl(), hsla(), hwb(), hwba()
498
+ match self.color_space {
499
+ ColorSpace::Srgb => self.flags.contains(ColorFlags::IS_LEGACY_SRGB),
500
+ ColorSpace::Hsl | ColorSpace::Hwb => true,
501
+ _ => false,
502
+ }
503
+ }
504
+
505
+ /// Returns true if this color is fully transparent.
506
+ #[inline]
507
+ pub fn is_transparent(&self) -> bool {
508
+ self.flags.contains(ColorFlags::ALPHA_IS_NONE) || self.alpha == 0.0
509
+ }
510
+
511
+ /// Return an optional first component.
512
+ #[inline]
513
+ pub fn c0(&self) -> Option<f32> {
514
+ if self.flags.contains(ColorFlags::C0_IS_NONE) {
515
+ None
516
+ } else {
517
+ Some(self.components.0)
518
+ }
519
+ }
520
+
521
+ /// Return an optional second component.
522
+ #[inline]
523
+ pub fn c1(&self) -> Option<f32> {
524
+ if self.flags.contains(ColorFlags::C1_IS_NONE) {
525
+ None
526
+ } else {
527
+ Some(self.components.1)
528
+ }
529
+ }
530
+
531
+ /// Return an optional second component.
532
+ #[inline]
533
+ pub fn c2(&self) -> Option<f32> {
534
+ if self.flags.contains(ColorFlags::C2_IS_NONE) {
535
+ None
536
+ } else {
537
+ Some(self.components.2)
538
+ }
539
+ }
540
+
541
+ /// Return an optional alpha component.
542
+ #[inline]
543
+ pub fn alpha(&self) -> Option<f32> {
544
+ if self.flags.contains(ColorFlags::ALPHA_IS_NONE) {
545
+ None
546
+ } else {
547
+ Some(self.alpha)
548
+ }
549
+ }
550
+
551
+ /// Return the value of a component by its channel keyword.
552
+ pub fn get_component_by_channel_keyword(
553
+ &self,
554
+ channel_keyword: ChannelKeyword,
555
+ ) -> Result<Option<f32>, ()> {
556
+ if channel_keyword == ChannelKeyword::ALPHA {
557
+ return Ok(self.alpha());
558
+ }
559
+
560
+ Ok(match self.color_space {
561
+ ColorSpace::Srgb => {
562
+ if self.flags.contains(ColorFlags::IS_LEGACY_SRGB) {
563
+ match channel_keyword {
564
+ ChannelKeyword::R => self.c0().map(|v| v * 255.0),
565
+ ChannelKeyword::G => self.c1().map(|v| v * 255.0),
566
+ ChannelKeyword::B => self.c2().map(|v| v * 255.0),
567
+ _ => return Err(()),
568
+ }
569
+ } else {
570
+ match channel_keyword {
571
+ ChannelKeyword::R => self.c0(),
572
+ ChannelKeyword::G => self.c1(),
573
+ ChannelKeyword::B => self.c2(),
574
+ _ => return Err(()),
575
+ }
576
+ }
577
+ },
578
+ ColorSpace::Hsl => match channel_keyword {
579
+ ChannelKeyword::H => self.c0(),
580
+ ChannelKeyword::S => self.c1(),
581
+ ChannelKeyword::L => self.c2(),
582
+ _ => return Err(()),
583
+ },
584
+ ColorSpace::Hwb => match channel_keyword {
585
+ ChannelKeyword::H => self.c0(),
586
+ ChannelKeyword::W => self.c1(),
587
+ ChannelKeyword::B => self.c2(),
588
+ _ => return Err(()),
589
+ },
590
+ ColorSpace::Lab | ColorSpace::Oklab => match channel_keyword {
591
+ ChannelKeyword::L => self.c0(),
592
+ ChannelKeyword::A => self.c1(),
593
+ ChannelKeyword::B => self.c2(),
594
+ _ => return Err(()),
595
+ },
596
+ ColorSpace::Lch | ColorSpace::Oklch => match channel_keyword {
597
+ ChannelKeyword::L => self.c0(),
598
+ ChannelKeyword::C => self.c1(),
599
+ ChannelKeyword::H => self.c2(),
600
+ _ => return Err(()),
601
+ },
602
+ ColorSpace::SrgbLinear
603
+ | ColorSpace::DisplayP3
604
+ | ColorSpace::DisplayP3Linear
605
+ | ColorSpace::A98Rgb
606
+ | ColorSpace::ProphotoRgb
607
+ | ColorSpace::Rec2020 => match channel_keyword {
608
+ ChannelKeyword::R => self.c0(),
609
+ ChannelKeyword::G => self.c1(),
610
+ ChannelKeyword::B => self.c2(),
611
+ _ => return Err(()),
612
+ },
613
+ ColorSpace::XyzD50 | ColorSpace::XyzD65 => match channel_keyword {
614
+ ChannelKeyword::X => self.c0(),
615
+ ChannelKeyword::Y => self.c1(),
616
+ ChannelKeyword::Z => self.c2(),
617
+ _ => return Err(()),
618
+ },
619
+ })
620
+ }
621
+
622
+ /// Convert this color to the specified color space.
623
+ pub fn to_color_space(&self, color_space: ColorSpace) -> Self {
624
+ use ColorSpace::*;
625
+
626
+ if self.color_space == color_space {
627
+ return *self;
628
+ }
629
+
630
+ // Missing components are treated as 0 for the conversion math.
631
+ // Carry-forward of `none` to analogous channels is handled at call
632
+ // sites where needed.
633
+ macro_rules! missing_to_zero {
634
+ ($c:expr) => {{
635
+ crate::values::normalize($c.unwrap_or(0.0))
636
+ }};
637
+ }
638
+
639
+ let components = ColorComponents(
640
+ missing_to_zero!(self.c0()),
641
+ missing_to_zero!(self.c1()),
642
+ missing_to_zero!(self.c2()),
643
+ );
644
+
645
+ let result = match (self.color_space, color_space) {
646
+ // We have simplified conversions that do not need to convert to XYZ
647
+ // first. This improves performance, because it skips at least 2
648
+ // matrix multiplications and reduces float rounding errors.
649
+ (Srgb, Hsl) => convert::rgb_to_hsl(&components),
650
+ (Srgb, Hwb) => convert::rgb_to_hwb(&components),
651
+ (Hsl, Srgb) => convert::hsl_to_rgb(&components),
652
+ (Hwb, Srgb) => convert::hwb_to_rgb(&components),
653
+ (Lab, Lch) | (Oklab, Oklch) => convert::orthogonal_to_polar(
654
+ &components,
655
+ convert::epsilon_for_range(0.0, if color_space == Lch { 100.0 } else { 1.0 }),
656
+ ),
657
+ (Lch, Lab) | (Oklch, Oklab) => convert::polar_to_orthogonal(&components),
658
+
659
+ // All other conversions need to convert to XYZ first.
660
+ _ => {
661
+ let (xyz, white_point) = match self.color_space {
662
+ Lab => convert::to_xyz::<convert::Lab>(&components),
663
+ Lch => convert::to_xyz::<convert::Lch>(&components),
664
+ Oklab => convert::to_xyz::<convert::Oklab>(&components),
665
+ Oklch => convert::to_xyz::<convert::Oklch>(&components),
666
+ Srgb => convert::to_xyz::<convert::Srgb>(&components),
667
+ Hsl => convert::to_xyz::<convert::Hsl>(&components),
668
+ Hwb => convert::to_xyz::<convert::Hwb>(&components),
669
+ SrgbLinear => convert::to_xyz::<convert::SrgbLinear>(&components),
670
+ DisplayP3 => convert::to_xyz::<convert::DisplayP3>(&components),
671
+ DisplayP3Linear => convert::to_xyz::<convert::DisplayP3Linear>(&components),
672
+ A98Rgb => convert::to_xyz::<convert::A98Rgb>(&components),
673
+ ProphotoRgb => convert::to_xyz::<convert::ProphotoRgb>(&components),
674
+ Rec2020 => convert::to_xyz::<convert::Rec2020>(&components),
675
+ XyzD50 => convert::to_xyz::<convert::XyzD50>(&components),
676
+ XyzD65 => convert::to_xyz::<convert::XyzD65>(&components),
677
+ };
678
+
679
+ match color_space {
680
+ Lab => convert::from_xyz::<convert::Lab>(&xyz, white_point),
681
+ Lch => convert::from_xyz::<convert::Lch>(&xyz, white_point),
682
+ Oklab => convert::from_xyz::<convert::Oklab>(&xyz, white_point),
683
+ Oklch => convert::from_xyz::<convert::Oklch>(&xyz, white_point),
684
+ Srgb => convert::from_xyz::<convert::Srgb>(&xyz, white_point),
685
+ Hsl => convert::from_xyz::<convert::Hsl>(&xyz, white_point),
686
+ Hwb => convert::from_xyz::<convert::Hwb>(&xyz, white_point),
687
+ SrgbLinear => convert::from_xyz::<convert::SrgbLinear>(&xyz, white_point),
688
+ DisplayP3 => convert::from_xyz::<convert::DisplayP3>(&xyz, white_point),
689
+ DisplayP3Linear => {
690
+ convert::from_xyz::<convert::DisplayP3Linear>(&xyz, white_point)
691
+ },
692
+ A98Rgb => convert::from_xyz::<convert::A98Rgb>(&xyz, white_point),
693
+ ProphotoRgb => convert::from_xyz::<convert::ProphotoRgb>(&xyz, white_point),
694
+ Rec2020 => convert::from_xyz::<convert::Rec2020>(&xyz, white_point),
695
+ XyzD50 => convert::from_xyz::<convert::XyzD50>(&xyz, white_point),
696
+ XyzD65 => convert::from_xyz::<convert::XyzD65>(&xyz, white_point),
697
+ }
698
+ },
699
+ };
700
+
701
+ // A NAN value coming from a conversion function means the the component
702
+ // is missing, so we convert it to None.
703
+ macro_rules! nan_to_missing {
704
+ ($v:expr) => {{
705
+ if $v.is_nan() {
706
+ None
707
+ } else {
708
+ Some($v)
709
+ }
710
+ }};
711
+ }
712
+
713
+ Self::new(
714
+ color_space,
715
+ nan_to_missing!(result.0),
716
+ nan_to_missing!(result.1),
717
+ nan_to_missing!(result.2),
718
+ self.alpha(),
719
+ )
720
+ }
721
+
722
+ /// Convert a given `nscolor` to a Servo AbsoluteColor value.
723
+ pub fn from_nscolor(color: u32) -> Self {
724
+ let [r, g, b, a] = color.to_le_bytes();
725
+ Self::srgb_legacy(r, g, b, a as f32 / 255.0)
726
+ }
727
+ }
728
+
729
+ #[test]
730
+ fn from_nscolor_should_be_in_legacy_syntax() {
731
+ let result = AbsoluteColor::from_nscolor(0x336699CC);
732
+ assert!(result.flags.contains(ColorFlags::IS_LEGACY_SRGB));
733
+ assert!(result.is_legacy_syntax());
734
+ }
735
+
736
+ impl From<PredefinedColorSpace> for ColorSpace {
737
+ fn from(value: PredefinedColorSpace) -> Self {
738
+ match value {
739
+ PredefinedColorSpace::Srgb => ColorSpace::Srgb,
740
+ PredefinedColorSpace::SrgbLinear => ColorSpace::SrgbLinear,
741
+ PredefinedColorSpace::DisplayP3 => ColorSpace::DisplayP3,
742
+ PredefinedColorSpace::DisplayP3Linear => ColorSpace::DisplayP3Linear,
743
+ PredefinedColorSpace::A98Rgb => ColorSpace::A98Rgb,
744
+ PredefinedColorSpace::ProphotoRgb => ColorSpace::ProphotoRgb,
745
+ PredefinedColorSpace::Rec2020 => ColorSpace::Rec2020,
746
+ PredefinedColorSpace::XyzD50 => ColorSpace::XyzD50,
747
+ PredefinedColorSpace::XyzD65 => ColorSpace::XyzD65,
748
+ }
749
+ }
750
+ }