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,714 @@
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
+ //! Parsed representations of [DOM attributes][attr].
6
+ //!
7
+ //! [attr]: https://dom.spec.whatwg.org/#interface-attr
8
+
9
+ use std::str::FromStr;
10
+ use std::sync::OnceLock;
11
+
12
+ use app_units::Au;
13
+ use euclid::num::Zero;
14
+ use num_traits::ToPrimitive;
15
+ use selectors::attr::AttrSelectorOperation;
16
+ use servo_arc::Arc;
17
+
18
+ use super::shadow_parts::ShadowParts;
19
+ use crate::color::parsing::parse_color_keyword;
20
+ use crate::color::AbsoluteColor;
21
+ use crate::derives::*;
22
+ use crate::properties::PropertyDeclarationBlock;
23
+ use crate::shared_lock::{Locked, SharedRwLock};
24
+ use crate::str::{
25
+ read_exponent, read_fraction, read_numbers, split_commas, split_html_space_chars, str_join,
26
+ HTML_SPACE_CHARACTERS,
27
+ };
28
+ use crate::values::specified::color::Color;
29
+ use crate::values::specified::LengthPercentage;
30
+ use crate::values::AtomString;
31
+ use crate::{Atom, LocalName, Namespace, Prefix};
32
+
33
+ // Duplicated from script::dom::values.
34
+ const UNSIGNED_LONG_MAX: u32 = 2147483647;
35
+
36
+ #[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq)]
37
+ pub enum LengthOrPercentageOrAuto {
38
+ Auto,
39
+ Percentage(f32),
40
+ Length(Au),
41
+ }
42
+
43
+ #[derive(Clone, Debug, MallocSizeOf)]
44
+ pub enum AttrValue {
45
+ //
46
+ // Variants that are stored in their serialized form.
47
+ //
48
+ String(String),
49
+ Atom(Atom),
50
+
51
+ //
52
+ // Variants that support lazy serialization.
53
+ //
54
+ TokenList(OnceLock<String>, Vec<Atom>),
55
+ UInt(OnceLock<String>, u32),
56
+ Int(OnceLock<String>, i32),
57
+ Double(OnceLock<String>, f64),
58
+ /// Note that this variant is only used transitively as a fast path to set
59
+ /// the property declaration block relevant to the style of an element when
60
+ /// set from the inline declaration of that element (that is,
61
+ /// `element.style`).
62
+ Declaration {
63
+ #[ignore_malloc_size_of = "Arc"]
64
+ block: Arc<Locked<PropertyDeclarationBlock>>,
65
+ lock: SharedRwLock,
66
+ serialization: OnceLock<String>,
67
+ },
68
+
69
+ //
70
+ // Variants without a serialization implementation which must be eagerly serialized.
71
+ //
72
+ LengthPercentage(String, Option<LengthPercentage>),
73
+ Color(String, Option<AbsoluteColor>),
74
+ Dimension(String, LengthOrPercentageOrAuto),
75
+ /// Stores a URL, computed from the input string and a document's base URL.
76
+ ///
77
+ /// The URL is resolved at setting-time, so this kind of attribute value is
78
+ /// not actually suitable for most URL-reflecting IDL attributes.
79
+ ResolvedUrl(
80
+ String,
81
+ #[ignore_malloc_size_of = "Arc"] Option<Arc<url::Url>>,
82
+ ),
83
+ /// The value of an `exportparts` attribute.
84
+ ShadowParts(String, ShadowParts),
85
+ }
86
+
87
+ impl From<String> for AttrValue {
88
+ fn from(value: String) -> Self {
89
+ Self::String(value)
90
+ }
91
+ }
92
+
93
+ impl From<u32> for AttrValue {
94
+ fn from(value: u32) -> Self {
95
+ Self::UInt(OnceLock::new(), value)
96
+ }
97
+ }
98
+
99
+ impl From<i32> for AttrValue {
100
+ fn from(value: i32) -> Self {
101
+ Self::Int(OnceLock::new(), value)
102
+ }
103
+ }
104
+
105
+ impl From<f64> for AttrValue {
106
+ fn from(value: f64) -> Self {
107
+ Self::Double(OnceLock::new(), value)
108
+ }
109
+ }
110
+
111
+ impl From<Vec<Atom>> for AttrValue {
112
+ fn from(value: Vec<Atom>) -> Self {
113
+ Self::TokenList(OnceLock::new(), value)
114
+ }
115
+ }
116
+
117
+ /// Shared implementation to parse an integer according to
118
+ /// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-integers> or
119
+ /// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-non-negative-integers>
120
+ fn do_parse_integer<T: Iterator<Item = char>>(input: T) -> Result<i64, ()> {
121
+ let mut input = input
122
+ .skip_while(|c| HTML_SPACE_CHARACTERS.iter().any(|s| s == c))
123
+ .peekable();
124
+
125
+ let sign = match input.peek() {
126
+ None => return Err(()),
127
+ Some(&'-') => {
128
+ input.next();
129
+ -1
130
+ },
131
+ Some(&'+') => {
132
+ input.next();
133
+ 1
134
+ },
135
+ Some(_) => 1,
136
+ };
137
+
138
+ let (value, _) = read_numbers(input);
139
+
140
+ value.and_then(|value| value.checked_mul(sign)).ok_or(())
141
+ }
142
+
143
+ /// Parse an integer according to
144
+ /// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-integers>.
145
+ pub fn parse_integer<T: Iterator<Item = char>>(input: T) -> Result<i32, ()> {
146
+ do_parse_integer(input).and_then(|result| result.to_i32().ok_or(()))
147
+ }
148
+
149
+ /// Parse an integer according to
150
+ /// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-non-negative-integers>
151
+ pub fn parse_unsigned_integer<T: Iterator<Item = char>>(input: T) -> Result<u32, ()> {
152
+ do_parse_integer(input).and_then(|result| result.to_u32().ok_or(()))
153
+ }
154
+
155
+ /// Parse a floating-point number according to
156
+ /// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-floating-point-number-values>
157
+ pub fn parse_double(string: &str) -> Result<f64, ()> {
158
+ let trimmed = string.trim_matches(HTML_SPACE_CHARACTERS);
159
+ let mut input = trimmed.chars().peekable();
160
+
161
+ let (value, divisor, chars_skipped) = match input.peek() {
162
+ None => return Err(()),
163
+ Some(&'-') => {
164
+ input.next();
165
+ (-1f64, -1f64, 1)
166
+ },
167
+ Some(&'+') => {
168
+ input.next();
169
+ (1f64, 1f64, 1)
170
+ },
171
+ _ => (1f64, 1f64, 0),
172
+ };
173
+
174
+ let (value, value_digits) = if let Some(&'.') = input.peek() {
175
+ (0f64, 0)
176
+ } else {
177
+ let (read_val, read_digits) = read_numbers(input);
178
+ (
179
+ value * read_val.and_then(|result| result.to_f64()).unwrap_or(1f64),
180
+ read_digits,
181
+ )
182
+ };
183
+
184
+ let input = trimmed
185
+ .chars()
186
+ .skip(value_digits + chars_skipped)
187
+ .peekable();
188
+
189
+ let (mut value, fraction_digits) = read_fraction(input, divisor, value);
190
+
191
+ let input = trimmed
192
+ .chars()
193
+ .skip(value_digits + chars_skipped + fraction_digits)
194
+ .peekable();
195
+
196
+ if let Some(exp) = read_exponent(input) {
197
+ value *= 10f64.powi(exp)
198
+ };
199
+
200
+ Ok(value)
201
+ }
202
+
203
+ impl AttrValue {
204
+ pub fn from_serialized_tokenlist(tokens: String) -> AttrValue {
205
+ let atoms =
206
+ split_html_space_chars(&tokens)
207
+ .map(Atom::from)
208
+ .fold(vec![], |mut acc, atom| {
209
+ if !acc.contains(&atom) {
210
+ acc.push(atom)
211
+ }
212
+ acc
213
+ });
214
+ AttrValue::TokenList(tokens.into(), atoms)
215
+ }
216
+
217
+ pub fn from_comma_separated_tokenlist(tokens: String) -> AttrValue {
218
+ let atoms = split_commas(&tokens)
219
+ .map(Atom::from)
220
+ .fold(vec![], |mut acc, atom| {
221
+ if !acc.contains(&atom) {
222
+ acc.push(atom)
223
+ }
224
+ acc
225
+ });
226
+ AttrValue::TokenList(tokens.into(), atoms)
227
+ }
228
+
229
+ // https://html.spec.whatwg.org/multipage/#reflecting-content-attributes-in-idl-attributes:idl-unsigned-long
230
+ pub fn from_u32(string: String, default: u32) -> AttrValue {
231
+ let result = parse_unsigned_integer(string.chars()).unwrap_or(default);
232
+ let result = if result > UNSIGNED_LONG_MAX {
233
+ default
234
+ } else {
235
+ result
236
+ };
237
+ AttrValue::UInt(string.into(), result)
238
+ }
239
+
240
+ pub fn from_i32(string: String, default: i32) -> AttrValue {
241
+ let result = parse_integer(string.chars()).unwrap_or(default);
242
+ AttrValue::Int(string.into(), result)
243
+ }
244
+
245
+ // https://html.spec.whatwg.org/multipage/#reflecting-content-attributes-in-idl-attributes:idl-double
246
+ pub fn from_double(string: String, default: f64) -> AttrValue {
247
+ let result = parse_double(&string).unwrap_or(default);
248
+
249
+ if result.is_normal() {
250
+ AttrValue::Double(string.into(), result)
251
+ } else {
252
+ AttrValue::Double(string.into(), default)
253
+ }
254
+ }
255
+
256
+ // https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers
257
+ pub fn from_limited_i32(string: String, default: i32) -> AttrValue {
258
+ let result = parse_integer(string.chars()).unwrap_or(default);
259
+
260
+ if result < 0 {
261
+ AttrValue::Int(string.into(), default)
262
+ } else {
263
+ AttrValue::Int(string.into(), result)
264
+ }
265
+ }
266
+
267
+ // https://html.spec.whatwg.org/multipage/#limited-to-only-non-negative-numbers-greater-than-zero
268
+ pub fn from_limited_u32(string: String, default: u32) -> AttrValue {
269
+ let result = parse_unsigned_integer(string.chars()).unwrap_or(default);
270
+ let result = if result == 0 || result > UNSIGNED_LONG_MAX {
271
+ default
272
+ } else {
273
+ result
274
+ };
275
+ AttrValue::UInt(string.into(), result)
276
+ }
277
+
278
+ pub fn from_atomic(string: String) -> AttrValue {
279
+ AttrValue::Atom(string.into())
280
+ }
281
+
282
+ pub fn from_resolved_url(base: &Arc<::url::Url>, url: String) -> AttrValue {
283
+ let joined = base.join(&url).ok().map(Arc::new);
284
+ AttrValue::ResolvedUrl(url, joined)
285
+ }
286
+
287
+ pub fn from_legacy_color(string: String) -> AttrValue {
288
+ let parsed = parse_legacy_color(&string).ok();
289
+ AttrValue::Color(string, parsed)
290
+ }
291
+
292
+ pub fn from_dimension(string: String) -> AttrValue {
293
+ let parsed = parse_length(&string);
294
+ AttrValue::Dimension(string, parsed)
295
+ }
296
+
297
+ pub fn from_nonzero_dimension(string: String) -> AttrValue {
298
+ let parsed = parse_nonzero_length(&string);
299
+ AttrValue::Dimension(string, parsed)
300
+ }
301
+
302
+ pub fn from_shadow_parts(string: String) -> AttrValue {
303
+ let shadow_parts = ShadowParts::parse(&string);
304
+ AttrValue::ShadowParts(string, shadow_parts)
305
+ }
306
+
307
+ pub fn from_declaration(
308
+ block: Arc<Locked<PropertyDeclarationBlock>>,
309
+ lock: SharedRwLock,
310
+ ) -> AttrValue {
311
+ AttrValue::Declaration {
312
+ block,
313
+ lock,
314
+ serialization: OnceLock::new(),
315
+ }
316
+ }
317
+
318
+ /// Assumes the `AttrValue` is a `TokenList` and returns its tokens
319
+ ///
320
+ /// ## Panics
321
+ ///
322
+ /// Panics if the `AttrValue` is not a `TokenList`
323
+ pub fn as_tokens(&self) -> &[Atom] {
324
+ match *self {
325
+ AttrValue::TokenList(_, ref tokens) => tokens,
326
+ _ => panic!("Tokens not found"),
327
+ }
328
+ }
329
+
330
+ /// Assumes the `AttrValue` is an `Atom` and returns its value
331
+ ///
332
+ /// ## Panics
333
+ ///
334
+ /// Panics if the `AttrValue` is not an `Atom`
335
+ pub fn as_atom(&self) -> &Atom {
336
+ match *self {
337
+ AttrValue::Atom(ref value) => value,
338
+ _ => panic!("Atom not found"),
339
+ }
340
+ }
341
+
342
+ /// Assumes the `AttrValue` is a `LengthPercentage` and returns its value
343
+ ///
344
+ /// ## Panics
345
+ ///
346
+ /// Panics if the `AttrValue` is not a `LengthPercentage`
347
+ pub fn as_length_percentage(&self) -> Option<&LengthPercentage> {
348
+ match *self {
349
+ AttrValue::LengthPercentage(_, ref length_percentage) => length_percentage.as_ref(),
350
+ _ => panic!("LengthPercentage not found"),
351
+ }
352
+ }
353
+
354
+ /// Assumes the `AttrValue` is a `Color` and returns its value
355
+ ///
356
+ /// ## Panics
357
+ ///
358
+ /// Panics if the `AttrValue` is not a `Color`
359
+ pub fn as_color(&self) -> Option<&AbsoluteColor> {
360
+ match *self {
361
+ AttrValue::Color(_, ref color) => color.as_ref(),
362
+ _ => panic!("Color not found"),
363
+ }
364
+ }
365
+
366
+ /// Assumes the `AttrValue` is a `Dimension` and returns its value
367
+ ///
368
+ /// ## Panics
369
+ ///
370
+ /// Panics if the `AttrValue` is not a `Dimension`
371
+ pub fn as_dimension(&self) -> &LengthOrPercentageOrAuto {
372
+ match *self {
373
+ AttrValue::Dimension(_, ref l) => l,
374
+ _ => panic!("Dimension not found"),
375
+ }
376
+ }
377
+
378
+ /// Assumes the `AttrValue` is a `ResolvedUrl` and returns its value.
379
+ ///
380
+ /// ## Panics
381
+ ///
382
+ /// Panics if the `AttrValue` is not a `ResolvedUrl`
383
+ pub fn as_resolved_url(&self) -> Option<&Arc<::url::Url>> {
384
+ match *self {
385
+ AttrValue::ResolvedUrl(_, ref url) => url.as_ref(),
386
+ _ => panic!("Url not found"),
387
+ }
388
+ }
389
+
390
+ /// Return the AttrValue as its signed integer representation, if any.
391
+ /// This corresponds to attribute values returned as `AttrValue::Int(_)`
392
+ /// by `VirtualMethods::parse_plain_attribute()`.
393
+ ///
394
+ /// ## Panics
395
+ ///
396
+ /// Panics if the `AttrValue` is not a `Int`
397
+ pub fn as_int(&self) -> i32 {
398
+ if let AttrValue::Int(_, value) = *self {
399
+ value
400
+ } else {
401
+ panic!("Int not found");
402
+ }
403
+ }
404
+
405
+ /// Return the AttrValue as its unsigned integer representation, if any.
406
+ /// This corresponds to attribute values returned as `AttrValue::UInt(_)`
407
+ /// by `VirtualMethods::parse_plain_attribute()`.
408
+ ///
409
+ /// ## Panics
410
+ ///
411
+ /// Panics if the `AttrValue` is not a `UInt`
412
+ pub fn as_uint(&self) -> u32 {
413
+ if let AttrValue::UInt(_, value) = *self {
414
+ value
415
+ } else {
416
+ panic!("Uint not found");
417
+ }
418
+ }
419
+
420
+ /// Return the AttrValue as a dimension computed from its unsigned integer
421
+ /// representation, assuming that integer representation specifies pixels.
422
+ ///
423
+ /// This corresponds to attribute values returned as `AttrValue::UInt(_)`
424
+ /// by `VirtualMethods::parse_plain_attribute()`.
425
+ ///
426
+ /// ## Panics
427
+ ///
428
+ /// Panics if the `AttrValue` is not a `UInt`
429
+ pub fn as_uint_px_dimension(&self) -> LengthOrPercentageOrAuto {
430
+ if let AttrValue::UInt(_, value) = *self {
431
+ LengthOrPercentageOrAuto::Length(Au::from_px(value as i32))
432
+ } else {
433
+ panic!("Uint not found");
434
+ }
435
+ }
436
+
437
+ /// Return the AttrValue as it's shadow-part representation.
438
+ ///
439
+ /// This corresponds to attribute values returned as `AttrValue::ShadowParts(_)`
440
+ /// by `VirtualMethods::parse_plain_attribute()`.
441
+ ///
442
+ /// ## Panics
443
+ ///
444
+ /// Panics if the `AttrValue` is not a shadow-part.
445
+ pub fn as_shadow_parts(&self) -> &ShadowParts {
446
+ if let AttrValue::ShadowParts(_, value) = &self {
447
+ value
448
+ } else {
449
+ panic!("Not a shadowpart attribute");
450
+ }
451
+ }
452
+
453
+ pub fn eval_selector(&self, selector: &AttrSelectorOperation<&AtomString>) -> bool {
454
+ // FIXME(SimonSapin) this can be more efficient by matching on `(self, selector)` variants
455
+ // and doing Atom comparisons instead of string comparisons where possible,
456
+ // with SelectorImpl::AttrValue changed to Atom.
457
+ selector.eval_str(self)
458
+ }
459
+ }
460
+
461
+ impl ::std::ops::Deref for AttrValue {
462
+ type Target = str;
463
+
464
+ fn deref(&self) -> &str {
465
+ match self {
466
+ AttrValue::String(value) => &value,
467
+ AttrValue::Atom(atom) => &atom,
468
+ AttrValue::TokenList(serialization, tokens) => {
469
+ serialization.get_or_init(|| {
470
+ // TODO(ajeffrey): Efficient conversion of Vec<Atom> to String
471
+ str_join(tokens, "\x20")
472
+ })
473
+ },
474
+ AttrValue::UInt(serialization, value) => {
475
+ serialization.get_or_init(|| value.to_string())
476
+ },
477
+ AttrValue::Double(serialization, value) => {
478
+ serialization.get_or_init(|| value.to_string())
479
+ },
480
+ AttrValue::Int(serialization, value) => serialization.get_or_init(|| value.to_string()),
481
+ AttrValue::Declaration {
482
+ block,
483
+ lock,
484
+ serialization,
485
+ } => serialization.get_or_init(|| {
486
+ let mut serialization = String::new();
487
+ block
488
+ .read_with(&lock.read())
489
+ .to_css(&mut serialization)
490
+ .expect("Should always be able to produce a valid serialization");
491
+ serialization
492
+ }),
493
+ AttrValue::LengthPercentage(serialization, _)
494
+ | AttrValue::Color(serialization, _)
495
+ | AttrValue::Dimension(serialization, _)
496
+ | AttrValue::ResolvedUrl(serialization, _)
497
+ | AttrValue::ShadowParts(serialization, _) => &serialization,
498
+ }
499
+ }
500
+ }
501
+
502
+ impl PartialEq<Atom> for AttrValue {
503
+ fn eq(&self, other: &Atom) -> bool {
504
+ match *self {
505
+ AttrValue::Atom(ref value) => value == other,
506
+ _ => other == &**self,
507
+ }
508
+ }
509
+ }
510
+
511
+ /// <https://html.spec.whatwg.org/multipage/#rules-for-parsing-non-zero-dimension-values>
512
+ pub fn parse_nonzero_length(value: &str) -> LengthOrPercentageOrAuto {
513
+ match parse_length(value) {
514
+ LengthOrPercentageOrAuto::Length(x) if x == Au::zero() => LengthOrPercentageOrAuto::Auto,
515
+ LengthOrPercentageOrAuto::Percentage(x) if x == 0. => LengthOrPercentageOrAuto::Auto,
516
+ x => x,
517
+ }
518
+ }
519
+
520
+ /// Parses a [legacy color][color]. If unparseable, `Err` is returned.
521
+ ///
522
+ /// [color]: https://html.spec.whatwg.org/multipage/#rules-for-parsing-a-legacy-colour-value
523
+ pub fn parse_legacy_color(mut input: &str) -> Result<AbsoluteColor, ()> {
524
+ // Steps 1 and 2.
525
+ if input.is_empty() {
526
+ return Err(());
527
+ }
528
+
529
+ // Step 3.
530
+ input = input.trim_matches(HTML_SPACE_CHARACTERS);
531
+
532
+ // Step 4.
533
+ if input.eq_ignore_ascii_case("transparent") {
534
+ return Err(());
535
+ }
536
+
537
+ // Step 5.
538
+ if let Ok(Color::Absolute(ref absolute)) = parse_color_keyword(input) {
539
+ return Ok(absolute.color);
540
+ }
541
+
542
+ // Step 6.
543
+ if input.len() == 4 {
544
+ if let (b'#', Ok(r), Ok(g), Ok(b)) = (
545
+ input.as_bytes()[0],
546
+ hex(input.as_bytes()[1] as char),
547
+ hex(input.as_bytes()[2] as char),
548
+ hex(input.as_bytes()[3] as char),
549
+ ) {
550
+ return Ok(AbsoluteColor::srgb_legacy(r * 17, g * 17, b * 17, 1.0));
551
+ }
552
+ }
553
+
554
+ // Step 7.
555
+ let mut new_input = String::new();
556
+ for ch in input.chars() {
557
+ if ch as u32 > 0xffff {
558
+ new_input.push_str("00")
559
+ } else {
560
+ new_input.push(ch)
561
+ }
562
+ }
563
+ let mut input = &*new_input;
564
+
565
+ // Step 8.
566
+ for (char_count, (index, _)) in input.char_indices().enumerate() {
567
+ if char_count == 128 {
568
+ input = &input[..index];
569
+ break;
570
+ }
571
+ }
572
+
573
+ // Step 9.
574
+ if input.as_bytes()[0] == b'#' {
575
+ input = &input[1..]
576
+ }
577
+
578
+ // Step 10.
579
+ let mut new_input = Vec::new();
580
+ for ch in input.chars() {
581
+ if hex(ch).is_ok() {
582
+ new_input.push(ch as u8)
583
+ } else {
584
+ new_input.push(b'0')
585
+ }
586
+ }
587
+ let mut input = new_input;
588
+
589
+ // Step 11.
590
+ while input.is_empty() || (input.len() % 3) != 0 {
591
+ input.push(b'0')
592
+ }
593
+
594
+ // Step 12.
595
+ let mut length = input.len() / 3;
596
+ let (mut red, mut green, mut blue) = (
597
+ &input[..length],
598
+ &input[length..length * 2],
599
+ &input[length * 2..],
600
+ );
601
+
602
+ // Step 13.
603
+ if length > 8 {
604
+ red = &red[length - 8..];
605
+ green = &green[length - 8..];
606
+ blue = &blue[length - 8..];
607
+ length = 8
608
+ }
609
+
610
+ // Step 14.
611
+ while length > 2 && red[0] == b'0' && green[0] == b'0' && blue[0] == b'0' {
612
+ red = &red[1..];
613
+ green = &green[1..];
614
+ blue = &blue[1..];
615
+ length -= 1
616
+ }
617
+
618
+ // Steps 15-20.
619
+ return Ok(AbsoluteColor::srgb_legacy(
620
+ hex_string(red).unwrap(),
621
+ hex_string(green).unwrap(),
622
+ hex_string(blue).unwrap(),
623
+ 1.0,
624
+ ));
625
+
626
+ fn hex(ch: char) -> Result<u8, ()> {
627
+ match ch {
628
+ '0'..='9' => Ok((ch as u8) - b'0'),
629
+ 'a'..='f' => Ok((ch as u8) - b'a' + 10),
630
+ 'A'..='F' => Ok((ch as u8) - b'A' + 10),
631
+ _ => Err(()),
632
+ }
633
+ }
634
+
635
+ fn hex_string(string: &[u8]) -> Result<u8, ()> {
636
+ match string.len() {
637
+ 0 => Err(()),
638
+ 1 => hex(string[0] as char),
639
+ _ => {
640
+ let upper = hex(string[0] as char)?;
641
+ let lower = hex(string[1] as char)?;
642
+ Ok((upper << 4) | lower)
643
+ },
644
+ }
645
+ }
646
+ }
647
+
648
+ /// Parses a [dimension value][dim]. If unparseable, `Auto` is returned.
649
+ ///
650
+ /// [dim]: https://html.spec.whatwg.org/multipage/#rules-for-parsing-dimension-values
651
+ // TODO: this function can be rewritten to return Result<LengthPercentage, _>
652
+ pub fn parse_length(mut value: &str) -> LengthOrPercentageOrAuto {
653
+ // Steps 1 & 2 are not relevant
654
+
655
+ // Step 3
656
+ value = value.trim_start_matches(HTML_SPACE_CHARACTERS);
657
+
658
+ // Step 4
659
+ match value.chars().nth(0) {
660
+ Some('0'..='9') => {},
661
+ _ => return LengthOrPercentageOrAuto::Auto,
662
+ }
663
+
664
+ // Steps 5 to 8
665
+ // We trim the string length to the minimum of:
666
+ // 1. the end of the string
667
+ // 2. the first occurence of a '%' (U+0025 PERCENT SIGN)
668
+ // 3. the second occurrence of a '.' (U+002E FULL STOP)
669
+ // 4. the occurrence of a character that is neither a digit nor '%' nor '.'
670
+ // Note: Step 7.4 is directly subsumed by FromStr::from_str
671
+ let mut end_index = value.len();
672
+ let (mut found_full_stop, mut found_percent) = (false, false);
673
+ for (i, ch) in value.chars().enumerate() {
674
+ match ch {
675
+ '0'..='9' => continue,
676
+ '%' => {
677
+ found_percent = true;
678
+ end_index = i;
679
+ break;
680
+ },
681
+ '.' if !found_full_stop => {
682
+ found_full_stop = true;
683
+ continue;
684
+ },
685
+ _ => {
686
+ end_index = i;
687
+ break;
688
+ },
689
+ }
690
+ }
691
+ value = &value[..end_index];
692
+
693
+ if found_percent {
694
+ let result: Result<f32, _> = FromStr::from_str(value);
695
+ match result {
696
+ Ok(number) => return LengthOrPercentageOrAuto::Percentage((number as f32) / 100.0),
697
+ Err(_) => return LengthOrPercentageOrAuto::Auto,
698
+ }
699
+ }
700
+
701
+ match FromStr::from_str(value) {
702
+ Ok(number) => LengthOrPercentageOrAuto::Length(Au::from_f64_px(number)),
703
+ Err(_) => LengthOrPercentageOrAuto::Auto,
704
+ }
705
+ }
706
+
707
+ /// A struct that uniquely identifies an element's attribute.
708
+ #[derive(Clone, Debug, MallocSizeOf)]
709
+ pub struct AttrIdentifier {
710
+ pub local_name: LocalName,
711
+ pub name: LocalName,
712
+ pub namespace: Namespace,
713
+ pub prefix: Option<Prefix>,
714
+ }