blitz-pdf 0.0.0-stage → 0.1.1

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 +391 -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,1164 @@
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
+ //! Types and traits used to access the DOM from style calculation.
6
+
7
+ #![allow(unsafe_code)]
8
+ #![deny(missing_docs)]
9
+
10
+ use crate::applicable_declarations::ApplicableDeclarationBlock;
11
+ #[cfg(feature = "gecko")]
12
+ use crate::context::UpdateAnimationsTasks;
13
+ use crate::context::{SharedStyleContext, TreeCountingCaches};
14
+ use crate::data::{ElementData, ElementDataMut, ElementDataRef};
15
+ use crate::device::Device;
16
+ use crate::properties::{AnimationDeclarations, ComputedValues, PropertyDeclarationBlock};
17
+ use crate::selector_map::PrecomputedHashMap;
18
+ use crate::selector_parser::{AttrValue, Lang, PseudoElement, RestyleDamage, SelectorImpl};
19
+ use crate::shared_lock::{Locked, SharedRwLock};
20
+ use crate::stylesheets::scope_rule::ImplicitScopeRoot;
21
+ use crate::stylist::CascadeData;
22
+ use crate::values::computed::{Display, TreeCountingResult};
23
+ use crate::values::AtomIdent;
24
+ use crate::{LocalName, Namespace, WeakAtom};
25
+ use dom::ElementState;
26
+ use selectors::matching::{ElementSelectorFlags, QuirksMode, VisitedHandlingMode};
27
+ use selectors::sink::Push;
28
+ use selectors::{Element as SelectorsElement, OpaqueElement};
29
+ use servo_arc::{Arc, ArcBorrow};
30
+ use smallvec::SmallVec;
31
+ use std::fmt;
32
+ use std::fmt::Debug;
33
+ use std::hash::Hash;
34
+ use std::ops::Deref;
35
+
36
+ pub use style_traits::dom::OpaqueNode;
37
+
38
+ /// Simple trait to provide basic information about the type of an element.
39
+ ///
40
+ /// We avoid exposing the full type id, since computing it in the general case
41
+ /// would be difficult for Gecko nodes.
42
+ pub trait NodeInfo {
43
+ /// Whether this node is an element.
44
+ fn is_element(&self) -> bool;
45
+ /// Whether this node is a text node.
46
+ fn is_text_node(&self) -> bool;
47
+ }
48
+
49
+ /// A node iterator that only returns node that don't need layout.
50
+ pub struct LayoutIterator<T>(pub T);
51
+
52
+ impl<T, N> Iterator for LayoutIterator<T>
53
+ where
54
+ T: Iterator<Item = N>,
55
+ N: NodeInfo,
56
+ {
57
+ type Item = N;
58
+
59
+ fn next(&mut self) -> Option<N> {
60
+ loop {
61
+ let n = self.0.next()?;
62
+ // Filter out nodes that layout should ignore.
63
+ if n.is_text_node() || n.is_element() {
64
+ return Some(n);
65
+ }
66
+ }
67
+ }
68
+ }
69
+
70
+ /// An iterator over the DOM children of a node.
71
+ pub struct DomChildren<N>(Option<N>);
72
+ impl<N> Iterator for DomChildren<N>
73
+ where
74
+ N: TNode,
75
+ {
76
+ type Item = N;
77
+
78
+ fn next(&mut self) -> Option<N> {
79
+ let n = self.0.take()?;
80
+ self.0 = n.next_sibling();
81
+ Some(n)
82
+ }
83
+ }
84
+
85
+ /// An iterator over the DOM descendants of a node in pre-order.
86
+ pub struct DomDescendants<N> {
87
+ previous: Option<N>,
88
+ scope: N,
89
+ }
90
+
91
+ impl<N> DomDescendants<N>
92
+ where
93
+ N: TNode,
94
+ {
95
+ /// Returns the next element ignoring all of our subtree.
96
+ #[inline]
97
+ pub fn next_skipping_children(&mut self) -> Option<N> {
98
+ let prev = self.previous.take()?;
99
+ self.previous = prev.next_in_preorder_skipping_children(self.scope);
100
+ self.previous
101
+ }
102
+ }
103
+
104
+ impl<N> Iterator for DomDescendants<N>
105
+ where
106
+ N: TNode,
107
+ {
108
+ type Item = N;
109
+
110
+ #[inline]
111
+ fn next(&mut self) -> Option<N> {
112
+ let prev = self.previous.take()?;
113
+ self.previous = prev.next_in_preorder(self.scope);
114
+ self.previous
115
+ }
116
+ }
117
+
118
+ /// The `TDocument` trait, to represent a document node.
119
+ pub trait TDocument: Sized + Copy + Clone {
120
+ /// The concrete `TNode` type.
121
+ type ConcreteNode: TNode<ConcreteDocument = Self>;
122
+
123
+ /// Get this document as a `TNode`.
124
+ fn as_node(&self) -> Self::ConcreteNode;
125
+
126
+ /// Returns whether this document is an HTML document.
127
+ fn is_html_document(&self) -> bool;
128
+
129
+ /// Returns the quirks mode of this document.
130
+ fn quirks_mode(&self) -> QuirksMode;
131
+
132
+ /// Get a list of elements with a given ID in this document, sorted by
133
+ /// tree position.
134
+ ///
135
+ /// Can return an error to signal that this list is not available, or also
136
+ /// return an empty slice.
137
+ fn elements_with_id<'a>(
138
+ &self,
139
+ _id: &AtomIdent,
140
+ ) -> Result<&'a [<Self::ConcreteNode as TNode>::ConcreteElement], ()>
141
+ where
142
+ Self: 'a,
143
+ {
144
+ Err(())
145
+ }
146
+
147
+ /// This document's shared lock.
148
+ fn shared_lock(&self) -> &SharedRwLock;
149
+ }
150
+
151
+ /// The `TNode` trait. This is the main generic trait over which the style
152
+ /// system can be implemented.
153
+ pub trait TNode: Sized + Copy + Clone + Debug + NodeInfo + PartialEq {
154
+ /// The concrete `TElement` type.
155
+ type ConcreteElement: TElement<ConcreteNode = Self>;
156
+
157
+ /// The concrete `TDocument` type.
158
+ type ConcreteDocument: TDocument<ConcreteNode = Self>;
159
+
160
+ /// The concrete `TShadowRoot` type.
161
+ type ConcreteShadowRoot: TShadowRoot<ConcreteNode = Self>;
162
+
163
+ /// Get this node's parent node.
164
+ fn parent_node(&self) -> Option<Self>;
165
+
166
+ /// Get this node's first child.
167
+ fn first_child(&self) -> Option<Self>;
168
+
169
+ /// Get this node's last child.
170
+ fn last_child(&self) -> Option<Self>;
171
+
172
+ /// Get this node's previous sibling.
173
+ fn prev_sibling(&self) -> Option<Self>;
174
+
175
+ /// Get this node's next sibling.
176
+ fn next_sibling(&self) -> Option<Self>;
177
+
178
+ /// Get the owner document of this node.
179
+ fn owner_doc(&self) -> Self::ConcreteDocument;
180
+
181
+ /// Iterate over the DOM children of a node.
182
+ #[inline(always)]
183
+ fn dom_children(&self) -> DomChildren<Self> {
184
+ DomChildren(self.first_child())
185
+ }
186
+
187
+ /// Returns whether the node is attached to a document.
188
+ fn is_in_document(&self) -> bool;
189
+
190
+ /// Iterate over the DOM children of a node, in preorder.
191
+ #[inline(always)]
192
+ fn dom_descendants(&self) -> DomDescendants<Self> {
193
+ DomDescendants {
194
+ previous: Some(*self),
195
+ scope: *self,
196
+ }
197
+ }
198
+
199
+ /// Returns the next node after this one, in a pre-order tree-traversal of
200
+ /// the subtree rooted at scoped_to.
201
+ #[inline]
202
+ fn next_in_preorder(&self, scoped_to: Self) -> Option<Self> {
203
+ if let Some(c) = self.first_child() {
204
+ return Some(c);
205
+ }
206
+ self.next_in_preorder_skipping_children(scoped_to)
207
+ }
208
+
209
+ /// Returns the next node in tree order, skipping the children of the current node.
210
+ ///
211
+ /// This is useful when we know that a subtree cannot contain matches, allowing us
212
+ /// to skip entire subtrees during traversal.
213
+ #[inline]
214
+ fn next_in_preorder_skipping_children(&self, scoped_to: Self) -> Option<Self> {
215
+ let mut current = *self;
216
+ loop {
217
+ if current == scoped_to {
218
+ return None;
219
+ }
220
+
221
+ if let Some(s) = current.next_sibling() {
222
+ return Some(s);
223
+ }
224
+
225
+ debug_assert!(
226
+ current.parent_node().is_some(),
227
+ "Not a descendant of the scope?"
228
+ );
229
+ current = current.parent_node()?;
230
+ }
231
+ }
232
+
233
+ /// Returns the depth of this node in the DOM.
234
+ fn depth(&self) -> usize {
235
+ let mut depth = 0;
236
+ let mut curr = *self;
237
+ while let Some(parent) = curr.traversal_parent() {
238
+ depth += 1;
239
+ curr = parent.as_node();
240
+ }
241
+ depth
242
+ }
243
+
244
+ /// Get this node's parent element from the perspective of a restyle
245
+ /// traversal.
246
+ fn traversal_parent(&self) -> Option<Self::ConcreteElement>;
247
+
248
+ /// Get this node's parent element if present.
249
+ fn parent_element(&self) -> Option<Self::ConcreteElement> {
250
+ self.parent_node().and_then(|n| n.as_element())
251
+ }
252
+
253
+ /// Get this node's parent element, or shadow host if it's a shadow root.
254
+ fn parent_element_or_host(&self) -> Option<Self::ConcreteElement> {
255
+ let parent = self.parent_node()?;
256
+ if let Some(e) = parent.as_element() {
257
+ return Some(e);
258
+ }
259
+ if let Some(root) = parent.as_shadow_root() {
260
+ return Some(root.host());
261
+ }
262
+ None
263
+ }
264
+
265
+ /// Converts self into an `OpaqueNode`.
266
+ fn opaque(&self) -> OpaqueNode;
267
+
268
+ /// A debug id, only useful, mm... for debugging.
269
+ fn debug_id(self) -> usize;
270
+
271
+ /// Get this node as an element, if it's one.
272
+ fn as_element(&self) -> Option<Self::ConcreteElement>;
273
+
274
+ /// Get this node as a document, if it's one.
275
+ fn as_document(&self) -> Option<Self::ConcreteDocument>;
276
+
277
+ /// Get this node as a ShadowRoot, if it's one.
278
+ fn as_shadow_root(&self) -> Option<Self::ConcreteShadowRoot>;
279
+ }
280
+
281
+ /// Wrapper to output the subtree rather than the single node when formatting
282
+ /// for Debug.
283
+ pub struct ShowSubtree<N: TNode>(pub N);
284
+ impl<N: TNode> Debug for ShowSubtree<N> {
285
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
286
+ writeln!(f, "DOM Subtree:")?;
287
+ fmt_subtree(f, &|f, n| write!(f, "{:?}", n), self.0, 1)
288
+ }
289
+ }
290
+
291
+ /// Wrapper to output the subtree along with the ElementData when formatting
292
+ /// for Debug.
293
+ pub struct ShowSubtreeData<N: TNode>(pub N);
294
+ impl<N: TNode> Debug for ShowSubtreeData<N> {
295
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
296
+ writeln!(f, "DOM Subtree:")?;
297
+ fmt_subtree(f, &|f, n| fmt_with_data(f, n), self.0, 1)
298
+ }
299
+ }
300
+
301
+ /// Wrapper to output the subtree along with the ElementData and primary
302
+ /// ComputedValues when formatting for Debug. This is extremely verbose.
303
+ #[cfg(feature = "servo")]
304
+ pub struct ShowSubtreeDataAndPrimaryValues<N: TNode>(pub N);
305
+ #[cfg(feature = "servo")]
306
+ impl<N: TNode> Debug for ShowSubtreeDataAndPrimaryValues<N> {
307
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
308
+ writeln!(f, "DOM Subtree:")?;
309
+ fmt_subtree(f, &|f, n| fmt_with_data_and_primary_values(f, n), self.0, 1)
310
+ }
311
+ }
312
+
313
+ fn fmt_with_data<N: TNode>(f: &mut fmt::Formatter, n: N) -> fmt::Result {
314
+ if let Some(el) = n.as_element() {
315
+ write!(
316
+ f,
317
+ "{:?} dd={} aodd={} data={:?}",
318
+ el,
319
+ el.has_dirty_descendants(),
320
+ el.has_animation_only_dirty_descendants(),
321
+ el.borrow_data(),
322
+ )
323
+ } else {
324
+ write!(f, "{:?}", n)
325
+ }
326
+ }
327
+
328
+ #[cfg(feature = "servo")]
329
+ fn fmt_with_data_and_primary_values<N: TNode>(f: &mut fmt::Formatter, n: N) -> fmt::Result {
330
+ if let Some(el) = n.as_element() {
331
+ let dd = el.has_dirty_descendants();
332
+ let aodd = el.has_animation_only_dirty_descendants();
333
+ let data = el.borrow_data();
334
+ let values = data.as_ref().and_then(|d| d.styles.get_primary());
335
+ write!(
336
+ f,
337
+ "{:?} dd={} aodd={} data={:?} values={:?}",
338
+ el, dd, aodd, &data, values
339
+ )
340
+ } else {
341
+ write!(f, "{:?}", n)
342
+ }
343
+ }
344
+
345
+ fn fmt_subtree<F, N: TNode>(f: &mut fmt::Formatter, stringify: &F, n: N, indent: u32) -> fmt::Result
346
+ where
347
+ F: Fn(&mut fmt::Formatter, N) -> fmt::Result,
348
+ {
349
+ for _ in 0..indent {
350
+ write!(f, " ")?;
351
+ }
352
+ stringify(f, n)?;
353
+ if let Some(e) = n.as_element() {
354
+ for kid in e.traversal_children() {
355
+ writeln!(f)?;
356
+ fmt_subtree(f, stringify, kid, indent + 1)?;
357
+ }
358
+ }
359
+
360
+ Ok(())
361
+ }
362
+
363
+ /// The ShadowRoot trait.
364
+ pub trait TShadowRoot: Sized + Copy + Clone + Debug + PartialEq {
365
+ /// The concrete node type.
366
+ type ConcreteNode: TNode<ConcreteShadowRoot = Self>;
367
+
368
+ /// Get this ShadowRoot as a node.
369
+ fn as_node(&self) -> Self::ConcreteNode;
370
+
371
+ /// Get the shadow host that hosts this ShadowRoot.
372
+ fn host(&self) -> <Self::ConcreteNode as TNode>::ConcreteElement;
373
+
374
+ /// Get the style data for this ShadowRoot.
375
+ fn style_data<'a>(&self) -> Option<&'a CascadeData>
376
+ where
377
+ Self: 'a;
378
+
379
+ /// Get the list of shadow parts for this shadow root.
380
+ fn parts<'a>(&self) -> &[<Self::ConcreteNode as TNode>::ConcreteElement]
381
+ where
382
+ Self: 'a,
383
+ {
384
+ &[]
385
+ }
386
+
387
+ /// Get a list of elements with a given ID in this shadow root, sorted by
388
+ /// tree position.
389
+ ///
390
+ /// Can return an error to signal that this list is not available, or also
391
+ /// return an empty slice.
392
+ fn elements_with_id<'a>(
393
+ &self,
394
+ _id: &AtomIdent,
395
+ ) -> Result<&'a [<Self::ConcreteNode as TNode>::ConcreteElement], ()>
396
+ where
397
+ Self: 'a,
398
+ {
399
+ Err(())
400
+ }
401
+
402
+ /// Get the implicit scope for a stylesheet in given index.
403
+ fn implicit_scope_for_sheet(&self, _sheet_index: usize) -> Option<ImplicitScopeRoot> {
404
+ None
405
+ }
406
+ }
407
+
408
+ /// The element trait, the main abstraction the style crate acts over.
409
+ pub trait TElement:
410
+ Eq
411
+ + PartialEq
412
+ + Debug
413
+ + Hash
414
+ + Sized
415
+ + Copy
416
+ + Clone
417
+ + SelectorsElement<Impl = SelectorImpl>
418
+ + ElementContext
419
+ {
420
+ /// The concrete node type.
421
+ type ConcreteNode: TNode<ConcreteElement = Self>;
422
+
423
+ /// A concrete children iterator type in order to iterate over the `Node`s.
424
+ ///
425
+ /// TODO(emilio): We should eventually replace this with the `impl Trait`
426
+ /// syntax.
427
+ type TraversalChildrenIterator: Iterator<Item = Self::ConcreteNode>;
428
+
429
+ /// Get this element as a node.
430
+ fn as_node(&self) -> Self::ConcreteNode;
431
+
432
+ /// A debug-only check that the device's owner doc matches the actual doc
433
+ /// we're the root of.
434
+ ///
435
+ /// Otherwise we may set document-level state incorrectly, like the root
436
+ /// font-size used for rem units.
437
+ fn owner_doc_matches_for_testing(&self, _: &Device) -> bool {
438
+ true
439
+ }
440
+
441
+ /// Whether this element should match user and content rules.
442
+ ///
443
+ /// We use this for Native Anonymous Content in Gecko.
444
+ fn matches_user_and_content_rules(&self) -> bool {
445
+ true
446
+ }
447
+
448
+ /// Get this node's parent element from the perspective of a restyle
449
+ /// traversal.
450
+ fn traversal_parent(&self) -> Option<Self> {
451
+ self.as_node().traversal_parent()
452
+ }
453
+
454
+ /// Get this node's children from the perspective of a restyle traversal.
455
+ fn traversal_children(&self) -> LayoutIterator<Self::TraversalChildrenIterator>;
456
+
457
+ /// Returns the parent element we should inherit from.
458
+ ///
459
+ /// This is pretty much always the parent element itself, except in the case
460
+ /// of Gecko's Native Anonymous Content, which uses the traversal parent
461
+ /// (i.e. the flattened tree parent) and which also may need to find the
462
+ /// closest non-NAC ancestor.
463
+ fn inheritance_parent(&self) -> Option<Self> {
464
+ self.parent_element()
465
+ }
466
+
467
+ /// Execute `f` for each anonymous content child (apart from ::before and
468
+ /// ::after) whose originating element is `self`.
469
+ fn each_anonymous_content_child<F>(&self, _f: F)
470
+ where
471
+ F: FnMut(Self),
472
+ {
473
+ }
474
+
475
+ /// Return whether this element is an element in the HTML namespace.
476
+ fn is_html_element(&self) -> bool;
477
+
478
+ /// Return whether this element is an element in the MathML namespace.
479
+ fn is_mathml_element(&self) -> bool;
480
+
481
+ /// Return whether this element is an element in the SVG namespace.
482
+ fn is_svg_element(&self) -> bool;
483
+
484
+ /// Return whether this element is an element in the XUL namespace.
485
+ fn is_xul_element(&self) -> bool {
486
+ false
487
+ }
488
+
489
+ /// Return whether this element is an HTML <video> or <audio> element.
490
+ fn is_html_media_element(&self) -> bool {
491
+ false
492
+ }
493
+
494
+ /// Returns the bloom filter for this element's subtree, used for fast
495
+ /// querySelector optimization by allowing subtrees to be skipped.
496
+ /// Each element's filter includes hashes for all of it's class names and
497
+ /// attribute names (not values), along with the names for all descendent
498
+ /// elements.
499
+ ///
500
+ /// The default implementation returns all bits set, meaning the bloom filter
501
+ /// never filters anything.
502
+ fn subtree_bloom_filter(&self) -> u64 {
503
+ u64::MAX
504
+ }
505
+
506
+ /// Check if this element's subtree may contain elements with the given bloom hash.
507
+ fn bloom_may_have_hash(&self, bloom_hash: u64) -> bool {
508
+ let bloom = self.subtree_bloom_filter();
509
+ (bloom & bloom_hash) == bloom_hash
510
+ }
511
+
512
+ /// Convert a 32-bit atom hash to a bloom filter value using k=2 hash functions.
513
+ /// This must match the C++ implementation of AttrArray::HashForBloomFilter.
514
+ fn hash_for_bloom_filter(hash: u32) -> u64 {
515
+ // On 32-bit platforms, we have 31 bits available + 1 tag bit.
516
+ // On 64-bit platforms, we have 63 bits available + 1 tag bit.
517
+ #[cfg(target_pointer_width = "32")]
518
+ const BLOOM_BITS: u32 = 31;
519
+
520
+ #[cfg(target_pointer_width = "64")]
521
+ const BLOOM_BITS: u32 = 63;
522
+
523
+ let mut filter = 1u64;
524
+ filter |= 1u64 << (1 + (hash % BLOOM_BITS));
525
+ filter |= 1u64 << (1 + ((hash >> 6) % BLOOM_BITS));
526
+ filter
527
+ }
528
+
529
+ /// Return the list of slotted nodes of this node.
530
+ fn slotted_nodes(&self) -> &[Self::ConcreteNode] {
531
+ &[]
532
+ }
533
+
534
+ /// Get this element's style attribute.
535
+ fn style_attribute(&self) -> Option<ArcBorrow<'_, Locked<PropertyDeclarationBlock>>>;
536
+
537
+ /// Get this element's SMIL override declarations.
538
+ fn smil_override(&self) -> Option<ArcBorrow<'_, Locked<PropertyDeclarationBlock>>> {
539
+ None
540
+ }
541
+
542
+ /// Get the combined animation and transition rules.
543
+ ///
544
+ /// FIXME(emilio): Is this really useful?
545
+ fn animation_declarations(&self, context: &SharedStyleContext) -> AnimationDeclarations {
546
+ if !self.may_have_animations() {
547
+ return Default::default();
548
+ }
549
+
550
+ AnimationDeclarations {
551
+ animations: self.animation_rule(context),
552
+ transitions: self.transition_rule(context),
553
+ }
554
+ }
555
+
556
+ /// Get this element's animation rule.
557
+ fn animation_rule(
558
+ &self,
559
+ _: &SharedStyleContext,
560
+ ) -> Option<Arc<Locked<PropertyDeclarationBlock>>>;
561
+
562
+ /// Get this element's transition rule.
563
+ fn transition_rule(
564
+ &self,
565
+ context: &SharedStyleContext,
566
+ ) -> Option<Arc<Locked<PropertyDeclarationBlock>>>;
567
+
568
+ /// Get this element's state, for non-tree-structural pseudos.
569
+ fn state(&self) -> ElementState;
570
+
571
+ /// Returns whether this element has a `part` attribute.
572
+ fn has_part_attr(&self) -> bool;
573
+
574
+ /// Returns whether this element exports any part from its shadow tree.
575
+ fn exports_any_part(&self) -> bool;
576
+
577
+ /// The ID for this element.
578
+ fn id(&self) -> Option<&WeakAtom>;
579
+
580
+ /// Internal iterator for the classes of this element.
581
+ fn each_class<F>(&self, callback: F)
582
+ where
583
+ F: FnMut(&AtomIdent);
584
+
585
+ /// Internal iterator for the classes of this element.
586
+ fn each_custom_state<F>(&self, callback: F)
587
+ where
588
+ F: FnMut(&AtomIdent);
589
+
590
+ /// Internal iterator for the part names of this element.
591
+ fn each_part<F>(&self, _callback: F)
592
+ where
593
+ F: FnMut(&AtomIdent),
594
+ {
595
+ }
596
+
597
+ /// Internal iterator for the attribute names of this element.
598
+ fn each_attr_name<F>(&self, callback: F)
599
+ where
600
+ F: FnMut(&LocalName);
601
+
602
+ /// Internal iterator for the part names that this element exports for a
603
+ /// given part name.
604
+ fn each_exported_part<F>(&self, _name: &AtomIdent, _callback: F)
605
+ where
606
+ F: FnMut(&AtomIdent),
607
+ {
608
+ }
609
+
610
+ /// Whether a given element may generate a pseudo-element.
611
+ ///
612
+ /// This is useful to avoid computing, for example, pseudo styles for
613
+ /// `::-first-line` or `::-first-letter`, when we know it won't affect us.
614
+ ///
615
+ /// TODO(emilio, bz): actually implement the logic for it.
616
+ fn may_generate_pseudo(&self, pseudo: &PseudoElement, _primary_style: &ComputedValues) -> bool {
617
+ // ::before/::after are always supported for now, though we could try to
618
+ // optimize out leaf elements.
619
+
620
+ // ::first-letter and ::first-line are only supported for block-inside
621
+ // things, and only in Gecko, not Servo. Unfortunately, Gecko has
622
+ // block-inside things that might have any computed display value due to
623
+ // things like fieldsets, legends, etc. Need to figure out how this
624
+ // should work.
625
+ debug_assert!(
626
+ pseudo.is_eager(),
627
+ "Someone called may_generate_pseudo with a non-eager pseudo."
628
+ );
629
+ true
630
+ }
631
+
632
+ /// Returns true if this element may have a descendant needing style processing.
633
+ ///
634
+ /// Note that we cannot guarantee the existence of such an element, because
635
+ /// it may have been removed from the DOM between marking it for restyle and
636
+ /// the actual restyle traversal.
637
+ fn has_dirty_descendants(&self) -> bool;
638
+
639
+ /// Returns whether state or attributes that may change style have changed
640
+ /// on the element, and thus whether the element has been snapshotted to do
641
+ /// restyle hint computation.
642
+ fn has_snapshot(&self) -> bool;
643
+
644
+ /// Returns whether the current snapshot if present has been handled.
645
+ fn handled_snapshot(&self) -> bool;
646
+
647
+ /// Flags this element as having handled already its snapshot.
648
+ unsafe fn set_handled_snapshot(&self);
649
+
650
+ /// Returns whether the element's styles are up-to-date after traversal
651
+ /// (i.e. in post traversal).
652
+ fn has_current_styles(&self, data: &ElementData) -> bool {
653
+ if self.has_snapshot() && !self.handled_snapshot() {
654
+ return false;
655
+ }
656
+
657
+ data.has_styles() &&
658
+ // TODO(hiro): When an animating element moved into subtree of
659
+ // contenteditable element, there remains animation restyle hints in
660
+ // post traversal. It's generally harmless since the hints will be
661
+ // processed in a next styling but ideally it should be processed soon.
662
+ //
663
+ // Without this, we get failures in:
664
+ // layout/style/crashtests/1383319.html
665
+ // layout/style/crashtests/1383001.html
666
+ //
667
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=1389675 tracks fixing
668
+ // this.
669
+ !data.hint.has_non_animation_invalidations()
670
+ }
671
+
672
+ /// Flag that this element has a descendant for style processing.
673
+ ///
674
+ /// Only safe to call with exclusive access to the element.
675
+ unsafe fn set_dirty_descendants(&self);
676
+
677
+ /// Flag that this element has no descendant for style processing.
678
+ ///
679
+ /// Only safe to call with exclusive access to the element.
680
+ unsafe fn unset_dirty_descendants(&self);
681
+
682
+ /// Similar to the dirty_descendants but for representing a descendant of
683
+ /// the element needs to be updated in animation-only traversal.
684
+ fn has_animation_only_dirty_descendants(&self) -> bool {
685
+ false
686
+ }
687
+
688
+ /// Flag that this element has a descendant for animation-only restyle
689
+ /// processing.
690
+ ///
691
+ /// Only safe to call with exclusive access to the element.
692
+ unsafe fn set_animation_only_dirty_descendants(&self) {}
693
+
694
+ /// Flag that this element has no descendant for animation-only restyle processing.
695
+ ///
696
+ /// Only safe to call with exclusive access to the element.
697
+ unsafe fn unset_animation_only_dirty_descendants(&self) {}
698
+
699
+ /// Clear all bits related describing the dirtiness of descendants.
700
+ ///
701
+ /// In Gecko, this corresponds to the regular dirty descendants bit, the
702
+ /// animation-only dirty descendants bit, and the lazy frame construction
703
+ /// descendants bit.
704
+ unsafe fn clear_descendant_bits(&self) {
705
+ unsafe {
706
+ self.unset_dirty_descendants();
707
+ }
708
+ }
709
+
710
+ /// Returns true if this element is a visited link.
711
+ ///
712
+ /// Servo doesn't support visited styles yet.
713
+ fn is_visited_link(&self) -> bool {
714
+ false
715
+ }
716
+
717
+ /// Returns the pseudo-element implemented by this element, if any.
718
+ ///
719
+ /// Gecko traverses pseudo-elements during the style traversal, and we need
720
+ /// to know this so we can properly grab the pseudo-element style from the
721
+ /// parent element.
722
+ ///
723
+ /// Note that we still need to compute the pseudo-elements before-hand,
724
+ /// given otherwise we don't know if we need to create an element or not.
725
+ fn implemented_pseudo_element(&self) -> Option<PseudoElement> {
726
+ None
727
+ }
728
+
729
+ /// Atomically stores the number of children of this node that we will
730
+ /// need to process during bottom-up traversal.
731
+ fn store_children_to_process(&self, n: isize);
732
+
733
+ /// Atomically notes that a child has been processed during bottom-up
734
+ /// traversal. Returns the number of children left to process.
735
+ fn did_process_child(&self) -> isize;
736
+
737
+ /// Gets a reference to the ElementData container, or creates one.
738
+ ///
739
+ /// Unsafe because it can race to allocate and leak if not used with
740
+ /// exclusive access to the element.
741
+ unsafe fn ensure_data(&self) -> ElementDataMut<'_>;
742
+
743
+ /// Clears the element data reference, if any.
744
+ ///
745
+ /// Unsafe following the same reasoning as ensure_data.
746
+ unsafe fn clear_data(&self);
747
+
748
+ /// Whether there is an ElementData container.
749
+ fn has_data(&self) -> bool;
750
+
751
+ /// Immutably borrows the ElementData.
752
+ fn borrow_data(&self) -> Option<ElementDataRef<'_>>;
753
+
754
+ /// Mutably borrows the ElementData.
755
+ fn mutate_data(&self) -> Option<ElementDataMut<'_>>;
756
+
757
+ /// Whether we should skip any root- or item-based display property
758
+ /// blockification on this element. (This function exists so that Gecko
759
+ /// native anonymous content can opt out of this style fixup.)
760
+ fn skip_item_display_fixup(&self) -> bool;
761
+
762
+ /// In Gecko, element has a flag that represents the element may have
763
+ /// any type of animations or not to bail out animation stuff early.
764
+ /// Whereas Servo doesn't have such flag.
765
+ fn may_have_animations(&self) -> bool;
766
+
767
+ /// Creates a task to update various animation state on a given (pseudo-)element.
768
+ #[cfg(feature = "gecko")]
769
+ fn update_animations(
770
+ &self,
771
+ before_change_style: Option<Arc<ComputedValues>>,
772
+ tasks: UpdateAnimationsTasks,
773
+ );
774
+
775
+ /// Returns true if the element has relevant animations. Relevant
776
+ /// animations are those animations that are affecting the element's style
777
+ /// or are scheduled to do so in the future.
778
+ fn has_animations(&self, context: &SharedStyleContext) -> bool;
779
+
780
+ /// Returns true if the element has a CSS animation. The `context` and `pseudo_element`
781
+ /// arguments are only used by Servo, since it stores animations globally and pseudo-elements
782
+ /// are not in the DOM.
783
+ fn has_css_animations(
784
+ &self,
785
+ context: &SharedStyleContext,
786
+ pseudo_element: Option<PseudoElement>,
787
+ ) -> bool;
788
+
789
+ /// Returns true if the element has a CSS transition (including running transitions and
790
+ /// completed transitions). The `context` and `pseudo_element` arguments are only used
791
+ /// by Servo, since it stores animations globally and pseudo-elements are not in the DOM.
792
+ fn has_css_transitions(
793
+ &self,
794
+ context: &SharedStyleContext,
795
+ pseudo_element: Option<PseudoElement>,
796
+ ) -> bool;
797
+
798
+ /// Returns true if the element has animation restyle hints.
799
+ fn has_animation_restyle_hints(&self) -> bool {
800
+ let data = match self.borrow_data() {
801
+ Some(d) => d,
802
+ None => return false,
803
+ };
804
+ data.hint.has_animation_hint()
805
+ }
806
+
807
+ /// Called when a highlight pseudo-element (::selection, ::highlight,
808
+ /// ::target-text) style is invalidated. These pseudos need explicit repaint
809
+ /// triggering since their styles are resolved lazily during painting.
810
+ fn note_highlight_pseudo_style_invalidated(&self) {}
811
+
812
+ /// The shadow root this element is a host of.
813
+ fn shadow_root(&self) -> Option<<Self::ConcreteNode as TNode>::ConcreteShadowRoot>;
814
+
815
+ /// The shadow root which roots the subtree this element is contained in.
816
+ fn containing_shadow(&self) -> Option<<Self::ConcreteNode as TNode>::ConcreteShadowRoot>;
817
+
818
+ /// If this element is not a pseudo-element, return self. Otherwise,
819
+ /// return the ultimate originating element [1]. This is the element
820
+ /// used to look up rules in the selector maps.
821
+ /// [1]: https://drafts.csswg.org/selectors-4/#ultimate-originating-element
822
+ fn ultimate_originating_element(&self) -> Self {
823
+ let mut cur = *self;
824
+ while cur.is_pseudo_element() {
825
+ cur = cur
826
+ .pseudo_element_originating_element()
827
+ .expect("Trying to collect rules for a detached pseudo-element")
828
+ }
829
+ cur
830
+ }
831
+
832
+ /// Executes the callback for each applicable style rule data which isn't
833
+ /// the main document's data (which stores UA / author rules).
834
+ ///
835
+ /// The element passed to the callback is the containing shadow host for the
836
+ /// data if it comes from Shadow DOM.
837
+ ///
838
+ /// Returns whether normal document author rules should apply.
839
+ ///
840
+ /// TODO(emilio): We could separate the invalidation data for elements
841
+ /// matching in other scopes to avoid over-invalidation.
842
+ fn each_applicable_non_document_style_rule_data<'a, F>(&self, mut f: F) -> bool
843
+ where
844
+ Self: 'a,
845
+ F: FnMut(&'a CascadeData, Self),
846
+ {
847
+ use crate::rule_collector::containing_shadow_ignoring_svg_use;
848
+
849
+ let target = self.ultimate_originating_element();
850
+ let matches_user_and_content_rules = target.matches_user_and_content_rules();
851
+ let mut doc_rules_apply = matches_user_and_content_rules;
852
+
853
+ // Use the same rules to look for the containing host as we do for rule
854
+ // collection.
855
+ if let Some(shadow) = containing_shadow_ignoring_svg_use(target) {
856
+ doc_rules_apply = false;
857
+ if let Some(data) = shadow.style_data() {
858
+ f(data, shadow.host());
859
+ }
860
+ }
861
+
862
+ if let Some(shadow) = target.shadow_root() {
863
+ if let Some(data) = shadow.style_data() {
864
+ f(data, shadow.host());
865
+ }
866
+ }
867
+
868
+ let mut current = target.assigned_slot();
869
+ while let Some(slot) = current {
870
+ // Slots can only have assigned nodes when in a shadow tree.
871
+ let shadow = slot.containing_shadow().unwrap();
872
+ if let Some(data) = shadow.style_data() {
873
+ if data.any_slotted_rule() {
874
+ f(data, shadow.host());
875
+ }
876
+ }
877
+ current = slot.assigned_slot();
878
+ }
879
+
880
+ if target.has_part_attr() {
881
+ if let Some(mut inner_shadow) = target.containing_shadow() {
882
+ loop {
883
+ let inner_shadow_host = inner_shadow.host();
884
+ match inner_shadow_host.containing_shadow() {
885
+ Some(shadow) => {
886
+ if let Some(data) = shadow.style_data() {
887
+ if data.any_part_rule() {
888
+ f(data, shadow.host())
889
+ }
890
+ }
891
+ // TODO: Could be more granular.
892
+ if !inner_shadow_host.exports_any_part() {
893
+ break;
894
+ }
895
+ inner_shadow = shadow;
896
+ },
897
+ None => {
898
+ // TODO(emilio): Should probably distinguish with
899
+ // MatchesDocumentRules::{No,Yes,IfPart} or something so that we could
900
+ // skip some work.
901
+ doc_rules_apply = matches_user_and_content_rules;
902
+ break;
903
+ },
904
+ }
905
+ }
906
+ }
907
+ }
908
+
909
+ doc_rules_apply
910
+ }
911
+
912
+ /// Returns true if one of the transitions needs to be updated on this element. We check all
913
+ /// the transition properties to make sure that updating transitions is necessary.
914
+ /// This method should only be called if might_needs_transitions_update returns true when
915
+ /// passed the same parameters.
916
+ #[cfg(feature = "gecko")]
917
+ fn needs_transitions_update(
918
+ &self,
919
+ before_change_style: &ComputedValues,
920
+ after_change_style: &ComputedValues,
921
+ ) -> bool;
922
+
923
+ /// Returns the value of the `xml:lang=""` attribute (or, if appropriate,
924
+ /// the `lang=""` attribute) on this element.
925
+ fn lang_attr(&self) -> Option<AttrValue>;
926
+
927
+ /// Returns whether this element's language matches the language tag
928
+ /// `value`. If `override_lang` is not `None`, it specifies the value
929
+ /// of the `xml:lang=""` or `lang=""` attribute to use in place of
930
+ /// looking at the element and its ancestors. (This argument is used
931
+ /// to implement matching of `:lang()` against snapshots.)
932
+ fn match_element_lang(&self, override_lang: Option<Option<AttrValue>>, value: &Lang) -> bool;
933
+
934
+ /// Returns whether this element is the main body element of the HTML
935
+ /// document it is on.
936
+ fn is_html_document_body_element(&self) -> bool;
937
+
938
+ /// Generate the proper applicable declarations due to presentational hints,
939
+ /// and insert them into `hints`.
940
+ fn synthesize_presentational_hints_for_legacy_attributes<V>(
941
+ &self,
942
+ visited_handling: VisitedHandlingMode,
943
+ hints: &mut V,
944
+ ) where
945
+ V: Push<ApplicableDeclarationBlock>;
946
+
947
+ /// Generate the proper applicable declarations due to view transition dynamic rules, and
948
+ /// insert them into `rules`.
949
+ /// https://drafts.csswg.org/css-view-transitions-1/#document-dynamic-view-transition-style-sheet
950
+ fn synthesize_view_transition_dynamic_rules<V>(&self, _rules: &mut V)
951
+ where
952
+ V: Push<ApplicableDeclarationBlock>,
953
+ {
954
+ }
955
+
956
+ /// Returns element's local name.
957
+ fn local_name(&self) -> &<SelectorImpl as selectors::parser::SelectorImpl>::BorrowedLocalName;
958
+
959
+ /// Returns element's namespace.
960
+ fn namespace(&self)
961
+ -> &<SelectorImpl as selectors::parser::SelectorImpl>::BorrowedNamespaceUrl;
962
+
963
+ /// Returns the size of the element to be used in container size queries.
964
+ /// This will usually be the size of the content area of the primary box,
965
+ /// but can be None if there is no box or if some axis lacks size containment.
966
+ fn query_container_size(
967
+ &self,
968
+ display: &Display,
969
+ ) -> euclid::default::Size2D<Option<app_units::Au>>;
970
+
971
+ /// Returns true if the element has all of specified selector flags.
972
+ fn has_selector_flags(&self, flags: ElementSelectorFlags) -> bool;
973
+
974
+ /// Returns the search direction for relative selector invalidation, if it is on the search path.
975
+ fn relative_selector_search_direction(&self) -> ElementSelectorFlags;
976
+
977
+ /// Returns the implicit scope root for given sheet index and host.
978
+ fn implicit_scope_for_sheet_in_shadow_root(
979
+ _opaque_host: OpaqueElement,
980
+ _sheet_index: usize,
981
+ ) -> Option<ImplicitScopeRoot> {
982
+ None
983
+ }
984
+
985
+ /// Compute the damage incurred by the change from the `_old` to `_new`.
986
+ fn compute_layout_damage(_old: &ComputedValues, _new: &ComputedValues) -> RestyleDamage {
987
+ Default::default()
988
+ }
989
+
990
+ /// Return the value of the given custom attribute if it exists.
991
+ fn get_attr(&self, attr: &LocalName, namespace: &Namespace) -> Option<String>;
992
+
993
+ /// Traverse the siblings of the element, returning the element's sibling-index()
994
+ /// and sibling-count(). Also populates `caches` with the sibling-index() and
995
+ /// sibling-count() values for all siblings of this element.
996
+ fn get_tree_counting_result(&self, caches: &mut TreeCountingCaches) -> TreeCountingResult {
997
+ let Some(parent) = self.as_node().parent_node() else {
998
+ return TreeCountingResult::default();
999
+ };
1000
+
1001
+ let mut curr = parent.first_child();
1002
+ let mut index = 0u32;
1003
+ let mut count = 0u32;
1004
+ while let Some(node) = curr {
1005
+ if let Some(element) = node.as_element() {
1006
+ count += 1;
1007
+ if *self == element {
1008
+ index = count;
1009
+ }
1010
+ caches.sibling_index.insert(element.opaque(), count);
1011
+ }
1012
+ curr = node.next_sibling();
1013
+ }
1014
+ caches.sibling_count.insert(parent.opaque(), count);
1015
+
1016
+ TreeCountingResult::new(index, count)
1017
+ }
1018
+ }
1019
+
1020
+ /// Provides element-level context needed during style computation.
1021
+ pub trait ElementContext {
1022
+ /// Opaque handle to the element.
1023
+ fn opaque_element(&self) -> Option<OpaqueElement>;
1024
+
1025
+ /// Opaque handle to the element's parent node.
1026
+ fn opaque_parent(&self) -> Option<OpaqueNode>;
1027
+
1028
+ /// Return the value of the given custom attribute if it exists.
1029
+ fn get_attr(&self, attr: &LocalName, namespace: &Namespace) -> Option<String>;
1030
+
1031
+ /// Traverse the siblings of the element, returning the element's sibling-index()
1032
+ /// and sibling-count(). Also populates `caches` with the sibling-index() and
1033
+ /// sibling-count() values for all siblings of this element.
1034
+ fn get_tree_counting_result(&self, caches: &mut TreeCountingCaches) -> TreeCountingResult;
1035
+ }
1036
+
1037
+ impl<T: TElement> ElementContext for T {
1038
+ fn opaque_element(&self) -> Option<OpaqueElement> {
1039
+ Some(self.opaque())
1040
+ }
1041
+
1042
+ fn opaque_parent(&self) -> Option<OpaqueNode> {
1043
+ self.as_node().parent_node().map(|n| n.opaque())
1044
+ }
1045
+
1046
+ fn get_attr(&self, attr: &LocalName, namespace: &Namespace) -> Option<String> {
1047
+ TElement::get_attr(self, attr, namespace)
1048
+ }
1049
+
1050
+ fn get_tree_counting_result(&self, caches: &mut TreeCountingCaches) -> TreeCountingResult {
1051
+ TElement::get_tree_counting_result(self, caches)
1052
+ }
1053
+ }
1054
+
1055
+ /// A set of the attributes used to compute a style that uses `attr()`
1056
+ pub type AttributeReferences = Option<Box<PrecomputedHashMap<LocalName, SmallVec<[Namespace; 1]>>>>;
1057
+
1058
+ /// A data structure to keep track of the names queried from an element.
1059
+ pub struct AttributeTracker<'a> {
1060
+ /// The element that queries for attributes.
1061
+ pub context: &'a dyn ElementContext,
1062
+ /// The set of attributes we have queried.
1063
+ pub references: AttributeReferences,
1064
+ }
1065
+
1066
+ impl<'a> AttributeTracker<'a> {
1067
+ /// Construct a new attribute tracker trivially.
1068
+ pub fn new(context: &'a dyn ElementContext) -> Self {
1069
+ Self {
1070
+ context,
1071
+ references: None,
1072
+ }
1073
+ }
1074
+
1075
+ /// Construct a new dummy attribute tracker
1076
+ pub fn new_dummy() -> Self {
1077
+ Self {
1078
+ context: &DummyElementContext {},
1079
+ references: None,
1080
+ }
1081
+ }
1082
+
1083
+ /// Extract the queried references and consume self
1084
+ pub fn finalize(self) -> AttributeReferences {
1085
+ self.references
1086
+ }
1087
+
1088
+ /// Query the value and save the name of the attribtue.
1089
+ pub fn query(&mut self, name: &LocalName, namespace: &Namespace) -> Option<String> {
1090
+ // We need to save namespaces in case we are thinking of sharing this element's
1091
+ // style with another.
1092
+ // i.e if elment a has ns1::attr="blue"
1093
+ // and element b has ns2::attr="blue"
1094
+ // a and b can only share style if ns1 and ns2 resolve to the same namespace.
1095
+ self.references
1096
+ .get_or_insert_default()
1097
+ .entry(name.clone())
1098
+ .or_default()
1099
+ .push(namespace.clone());
1100
+ self.context.get_attr(name, namespace)
1101
+ }
1102
+ }
1103
+
1104
+ /// A dummy ElementContext that returns default values to any query.
1105
+ #[derive(Clone, Debug, PartialEq)]
1106
+ pub struct DummyElementContext;
1107
+
1108
+ impl ElementContext for DummyElementContext {
1109
+ fn get_attr(&self, _attr: &LocalName, _namespace: &Namespace) -> Option<String> {
1110
+ None
1111
+ }
1112
+
1113
+ fn opaque_element(&self) -> Option<OpaqueElement> {
1114
+ None
1115
+ }
1116
+
1117
+ fn opaque_parent(&self) -> Option<OpaqueNode> {
1118
+ None
1119
+ }
1120
+
1121
+ fn get_tree_counting_result(&self, _: &mut TreeCountingCaches) -> TreeCountingResult {
1122
+ TreeCountingResult::default()
1123
+ }
1124
+ }
1125
+
1126
+ /// TNode and TElement aren't Send because we want to be careful and explicit
1127
+ /// about our parallel traversal. However, there are certain situations
1128
+ /// (including but not limited to the traversal) where we need to send DOM
1129
+ /// objects to other threads.
1130
+ ///
1131
+ /// That's the reason why `SendNode` exists.
1132
+ #[derive(Clone, Debug, PartialEq)]
1133
+ pub struct SendNode<N: TNode>(N);
1134
+ unsafe impl<N: TNode> Send for SendNode<N> {}
1135
+ impl<N: TNode> SendNode<N> {
1136
+ /// Unsafely construct a SendNode.
1137
+ pub unsafe fn new(node: N) -> Self {
1138
+ SendNode(node)
1139
+ }
1140
+ }
1141
+ impl<N: TNode> Deref for SendNode<N> {
1142
+ type Target = N;
1143
+ fn deref(&self) -> &N {
1144
+ &self.0
1145
+ }
1146
+ }
1147
+
1148
+ /// Same reason as for the existence of SendNode, SendElement does the proper
1149
+ /// things for a given `TElement`.
1150
+ #[derive(Debug, Eq, Hash, PartialEq)]
1151
+ pub struct SendElement<E: TElement>(E);
1152
+ unsafe impl<E: TElement> Send for SendElement<E> {}
1153
+ impl<E: TElement> SendElement<E> {
1154
+ /// Unsafely construct a SendElement.
1155
+ pub unsafe fn new(el: E) -> Self {
1156
+ SendElement(el)
1157
+ }
1158
+ }
1159
+ impl<E: TElement> Deref for SendElement<E> {
1160
+ type Target = E;
1161
+ fn deref(&self) -> &E {
1162
+ &self.0
1163
+ }
1164
+ }