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,1000 @@
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
+ //! Code related to the style sharing cache, an optimization that allows similar
6
+ //! nodes to share style without having to run selector matching twice.
7
+ //!
8
+ //! The basic setup is as follows. We have an LRU cache of style sharing
9
+ //! candidates. When we try to style a target element, we first check whether
10
+ //! we can quickly determine that styles match something in this cache, and if
11
+ //! so we just use the cached style information. This check is done with a
12
+ //! StyleBloom filter set up for the target element, which may not be a correct
13
+ //! state for the cached candidate element if they're cousins instead of
14
+ //! siblings.
15
+ //!
16
+ //! The complicated part is determining that styles match. This is subject to
17
+ //! the following constraints:
18
+ //!
19
+ //! 1) The target and candidate must be inheriting the same styles.
20
+ //! 2) The target and candidate must have exactly the same rules matching them.
21
+ //! 3) The target and candidate must have exactly the same non-selector-based
22
+ //! style information (inline styles, presentation hints).
23
+ //! 4) The target and candidate must have exactly the same rules matching their
24
+ //! pseudo-elements, because an element's style data points to the style
25
+ //! data for its pseudo-elements.
26
+ //!
27
+ //! These constraints are satisfied in the following ways:
28
+ //!
29
+ //! * We check that the parents of the target and the candidate have the same
30
+ //! computed style. This addresses constraint 1.
31
+ //!
32
+ //! * We check that the target and candidate have the same inline style and
33
+ //! presentation hint declarations. This addresses constraint 3.
34
+ //!
35
+ //! * We ensure that a target matches a candidate only if they have the same
36
+ //! matching result for all selectors that target either elements or the
37
+ //! originating elements of pseudo-elements. This addresses constraint 4
38
+ //! (because it prevents a target that has pseudo-element styles from matching
39
+ //! a candidate that has different pseudo-element styles) as well as
40
+ //! constraint 2.
41
+ //!
42
+ //! The actual checks that ensure that elements match the same rules are
43
+ //! conceptually split up into two pieces. First, we do various checks on
44
+ //! elements that make sure that the set of possible rules in all selector maps
45
+ //! in the stylist (for normal styling and for pseudo-elements) that might match
46
+ //! the two elements is the same. For example, we enforce that the target and
47
+ //! candidate must have the same localname and namespace. Second, we have a
48
+ //! selector map of "revalidation selectors" that the stylist maintains that we
49
+ //! actually match against the target and candidate and then check whether the
50
+ //! two sets of results were the same. Due to the up-front selector map checks,
51
+ //! we know that the target and candidate will be matched against the same exact
52
+ //! set of revalidation selectors, so the match result arrays can be compared
53
+ //! directly.
54
+ //!
55
+ //! It's very important that a selector be added to the set of revalidation
56
+ //! selectors any time there are two elements that could pass all the up-front
57
+ //! checks but match differently against some ComplexSelector in the selector.
58
+ //! If that happens, then they can have descendants that might themselves pass
59
+ //! the up-front checks but would have different matching results for the
60
+ //! selector in question. In this case, "descendants" includes pseudo-elements,
61
+ //! so there is a single selector map of revalidation selectors that includes
62
+ //! both selectors targeting elements and selectors targeting pseudo-element
63
+ //! originating elements. We ensure that the pseudo-element parts of all these
64
+ //! selectors are effectively stripped off, so that matching them all against
65
+ //! elements makes sense.
66
+
67
+ use crate::applicable_declarations::ApplicableDeclarationBlock;
68
+ use crate::bloom::StyleBloom;
69
+ use crate::computed_value_flags::ComputedValueFlags;
70
+ use crate::context::{CascadeInputs, SharedStyleContext, StyleContext};
71
+ use crate::dom::{SendElement, TElement, TNode};
72
+ use crate::properties::ComputedValues;
73
+ use crate::selector_map::RelevantAttributes;
74
+ use crate::style_resolver::{PrimaryStyle, ResolvedElementStyles};
75
+ use crate::stylist::Stylist;
76
+ use crate::values::AtomIdent;
77
+ use atomic_refcell::{AtomicRefCell, AtomicRefMut};
78
+ use selectors::matching::{NeedsSelectorFlags, SelectorCaches, VisitedHandlingMode};
79
+ use smallbitvec::SmallBitVec;
80
+ use smallvec::SmallVec;
81
+ use std::marker::PhantomData;
82
+ use std::mem;
83
+ use std::ops::Deref;
84
+ use std::ptr::NonNull;
85
+ use thin_vec::ThinVec;
86
+ use uluru::LRUCache;
87
+
88
+ mod checks;
89
+
90
+ /// The amount of nodes that the style sharing candidate cache should hold at most.
91
+ ///
92
+ /// The cache size was chosen by measuring style sharing and resulting performance on a few pages;
93
+ /// sizes up to about 32 were giving good sharing improvements (e.g. 3x fewer styles having to be
94
+ /// resolved than at size 8) and slight performance improvements. Sizes larger than 32 haven't
95
+ /// really been tested.
96
+ pub const SHARING_CACHE_SIZE: usize = 32;
97
+
98
+ /// The max amount of DOM depths we keep around to share styles across. See bug 2052731.
99
+ const SHARING_MAX_LEVELS: usize = 8;
100
+
101
+ /// Opaque pointer type to compare ComputedValues identities.
102
+ #[derive(Clone, Debug, Eq, PartialEq)]
103
+ pub struct OpaqueComputedValues(NonNull<()>);
104
+
105
+ unsafe impl Send for OpaqueComputedValues {}
106
+ unsafe impl Sync for OpaqueComputedValues {}
107
+
108
+ impl OpaqueComputedValues {
109
+ fn from(cv: &ComputedValues) -> Self {
110
+ let p =
111
+ unsafe { NonNull::new_unchecked(cv as *const ComputedValues as *const () as *mut ()) };
112
+ OpaqueComputedValues(p)
113
+ }
114
+
115
+ fn eq(&self, cv: &ComputedValues) -> bool {
116
+ Self::from(cv) == *self
117
+ }
118
+ }
119
+
120
+ /// The results from the revalidation step.
121
+ ///
122
+ /// Rather than either:
123
+ ///
124
+ /// * Plainly rejecting sharing for elements with different attributes (which would be unfortunate
125
+ /// because a lot of elements have different attributes yet those attributes are not
126
+ /// style-relevant).
127
+ ///
128
+ /// * Having to give up on per-attribute bucketing, which would be unfortunate because it
129
+ /// increases the cost of revalidation for pages with lots of global attribute selectors (see
130
+ /// bug 1868316).
131
+ ///
132
+ /// * We also store the style-relevant attributes for these elements, in order to guarantee that
133
+ /// we end up looking at the same selectors.
134
+ ///
135
+ #[derive(Debug, Default)]
136
+ pub struct RevalidationResult {
137
+ /// A bit for each selector matched. This is sound because we guarantee we look up into the
138
+ /// same buckets via the pre-revalidation checks and relevant_attributes.
139
+ pub selectors_matched: SmallBitVec,
140
+ /// The set of attributes of this element that were relevant for its style.
141
+ pub relevant_attributes: RelevantAttributes,
142
+ }
143
+
144
+ /// The results from trying to revalidate scopes this element is in.
145
+ #[derive(Debug, Default, PartialEq)]
146
+ pub struct ScopeRevalidationResult {
147
+ /// A bit for each scope activated.
148
+ pub scopes_matched: SmallBitVec,
149
+ }
150
+
151
+ impl PartialEq for RevalidationResult {
152
+ fn eq(&self, other: &Self) -> bool {
153
+ if self.relevant_attributes != other.relevant_attributes {
154
+ return false;
155
+ }
156
+
157
+ // This assert "ensures", to some extent, that the two candidates have matched the
158
+ // same rulehash buckets, and as such, that the bits we're comparing represent the
159
+ // same set of selectors.
160
+ debug_assert_eq!(self.selectors_matched.len(), other.selectors_matched.len());
161
+ self.selectors_matched == other.selectors_matched
162
+ }
163
+ }
164
+
165
+ /// We use this as an inline capacity for the class_list member below, but also as a reasonable cap
166
+ /// to avoid sorting too large class lists.
167
+ const REASONABLE_CLASS_LIST_SIZE: usize = 5;
168
+
169
+ /// Some data we want to avoid recomputing all the time while trying to share style.
170
+ #[derive(Debug, Default)]
171
+ pub struct ValidationData {
172
+ /// The class list of this element.
173
+ ///
174
+ /// TODO(emilio): Maybe check whether rules for these classes apply to the element?
175
+ /// TODO(emilio): Maybe this should be another ThinVec... But classes are definitely more common
176
+ /// than everything else on this struct.
177
+ class_list: Option<SmallVec<[AtomIdent; REASONABLE_CLASS_LIST_SIZE]>>,
178
+
179
+ /// The part list of this element.
180
+ ///
181
+ /// TODO(emilio): Maybe check whether rules with these part names apply to
182
+ /// the element?
183
+ part_list: Option<ThinVec<AtomIdent>>,
184
+
185
+ /// The list of presentational attributes of the element.
186
+ pres_hints: Option<ThinVec<ApplicableDeclarationBlock>>,
187
+
188
+ /// The pointer identity of the parent ComputedValues.
189
+ parent_style_identity: Option<OpaqueComputedValues>,
190
+
191
+ /// The cached result of matching this entry against the revalidation
192
+ /// selectors.
193
+ revalidation_match_results: Option<RevalidationResult>,
194
+ }
195
+
196
+ impl ValidationData {
197
+ /// Move the cached data to a new instance, and return it.
198
+ pub fn take(&mut self) -> Self {
199
+ std::mem::take(self)
200
+ }
201
+
202
+ /// Get or compute the list of presentational attributes associated with
203
+ /// this element.
204
+ pub fn pres_hints<E>(&mut self, element: E) -> &[ApplicableDeclarationBlock]
205
+ where
206
+ E: TElement,
207
+ {
208
+ self.pres_hints.get_or_insert_with(|| {
209
+ // This should basically never spill.
210
+ let mut pres_hints = SmallVec::<[_; 5]>::new();
211
+ element.synthesize_presentational_hints_for_legacy_attributes(
212
+ VisitedHandlingMode::AllLinksUnvisited,
213
+ &mut pres_hints,
214
+ );
215
+ ThinVec::from_iter(pres_hints.drain(..))
216
+ })
217
+ }
218
+
219
+ /// Get or compute the part-list associated with this element.
220
+ pub fn part_list<E>(&mut self, element: E) -> &[AtomIdent]
221
+ where
222
+ E: TElement,
223
+ {
224
+ if !element.has_part_attr() {
225
+ return &[];
226
+ }
227
+ self.part_list.get_or_insert_with(|| {
228
+ let mut list = ThinVec::new();
229
+ element.each_part(|p| list.push(p.clone()));
230
+ // See below for the reasoning.
231
+ if list.len() <= REASONABLE_CLASS_LIST_SIZE {
232
+ list.sort_unstable_by_key(|a| a.get_hash());
233
+ }
234
+ list
235
+ })
236
+ }
237
+
238
+ /// Get or compute the class-list associated with this element.
239
+ pub fn class_list<E>(&mut self, element: E) -> &[AtomIdent]
240
+ where
241
+ E: TElement,
242
+ {
243
+ self.class_list.get_or_insert_with(|| {
244
+ let mut list = SmallVec::<[_; REASONABLE_CLASS_LIST_SIZE]>::new();
245
+ element.each_class(|c| list.push(c.clone()));
246
+ // Assuming there are a reasonable number of classes, sort them to so that we don't
247
+ // mistakenly reject sharing candidates when one element has "foo bar" and the other has
248
+ // "bar foo".
249
+ if list.len() <= REASONABLE_CLASS_LIST_SIZE {
250
+ list.sort_unstable_by_key(|a| a.get_hash());
251
+ }
252
+ list
253
+ })
254
+ }
255
+
256
+ /// Get or compute the parent style identity.
257
+ pub fn parent_style_identity<E>(&mut self, el: E) -> OpaqueComputedValues
258
+ where
259
+ E: TElement,
260
+ {
261
+ self.parent_style_identity
262
+ .get_or_insert_with(|| {
263
+ let parent = el.inheritance_parent().unwrap();
264
+ let values =
265
+ OpaqueComputedValues::from(parent.borrow_data().unwrap().styles.primary());
266
+ values
267
+ })
268
+ .clone()
269
+ }
270
+
271
+ /// Computes the revalidation results if needed, and returns it.
272
+ /// Inline so we know at compile time what bloom_known_valid is.
273
+ #[inline]
274
+ fn revalidation_match_results<E>(
275
+ &mut self,
276
+ element: E,
277
+ stylist: &Stylist,
278
+ bloom: &StyleBloom<E>,
279
+ selector_caches: &mut SelectorCaches,
280
+ bloom_known_valid: bool,
281
+ needs_selector_flags: NeedsSelectorFlags,
282
+ ) -> &RevalidationResult
283
+ where
284
+ E: TElement,
285
+ {
286
+ self.revalidation_match_results.get_or_insert_with(|| {
287
+ // The bloom filter may already be set up for our element.
288
+ // If it is, use it. If not, we must be in a candidate
289
+ // (i.e. something in the cache), and the element is one
290
+ // of our cousins, not a sibling. In that case, we'll
291
+ // just do revalidation selector matching without a bloom
292
+ // filter, to avoid thrashing the filter.
293
+ let bloom_to_use = if bloom_known_valid {
294
+ debug_assert_eq!(bloom.current_parent(), element.traversal_parent());
295
+ Some(bloom.filter())
296
+ } else if bloom.current_parent() == element.traversal_parent() {
297
+ Some(bloom.filter())
298
+ } else {
299
+ None
300
+ };
301
+ stylist.match_revalidation_selectors(
302
+ element,
303
+ bloom_to_use,
304
+ selector_caches,
305
+ needs_selector_flags,
306
+ )
307
+ })
308
+ }
309
+ }
310
+
311
+ /// Information regarding a style sharing candidate, that is, an entry in the
312
+ /// style sharing cache.
313
+ ///
314
+ /// Note that this information is stored in TLS and cleared after the traversal,
315
+ /// and once here, the style information of the element is immutable, so it's
316
+ /// safe to access.
317
+ #[derive(Debug)]
318
+ pub struct StyleSharingCandidate<E> {
319
+ /// The element.
320
+ element: E,
321
+ validation_data: ValidationData,
322
+ considered_nontrivial_scoped_style: bool,
323
+ }
324
+
325
+ impl<E: TElement> Deref for StyleSharingCandidate<E> {
326
+ type Target = E;
327
+
328
+ fn deref(&self) -> &Self::Target {
329
+ &self.element
330
+ }
331
+ }
332
+
333
+ impl<E: TElement> StyleSharingCandidate<E> {
334
+ /// Get the classlist of this candidate.
335
+ fn class_list(&mut self) -> &[AtomIdent] {
336
+ self.validation_data.class_list(self.element)
337
+ }
338
+
339
+ /// Get the part list of this candidate.
340
+ fn part_list(&mut self) -> &[AtomIdent] {
341
+ self.validation_data.part_list(self.element)
342
+ }
343
+
344
+ /// Get the pres hints of this candidate.
345
+ fn pres_hints(&mut self) -> &[ApplicableDeclarationBlock] {
346
+ self.validation_data.pres_hints(self.element)
347
+ }
348
+
349
+ /// Get the parent style identity.
350
+ fn parent_style_identity(&mut self) -> OpaqueComputedValues {
351
+ self.validation_data.parent_style_identity(self.element)
352
+ }
353
+
354
+ /// Compute the bit vector of revalidation selector match results
355
+ /// for this candidate.
356
+ fn revalidation_match_results(
357
+ &mut self,
358
+ stylist: &Stylist,
359
+ bloom: &StyleBloom<E>,
360
+ selector_caches: &mut SelectorCaches,
361
+ ) -> &RevalidationResult {
362
+ self.validation_data.revalidation_match_results(
363
+ self.element,
364
+ stylist,
365
+ bloom,
366
+ selector_caches,
367
+ /* bloom_known_valid = */ false,
368
+ // The candidate must already have the right bits already, if
369
+ // needed.
370
+ NeedsSelectorFlags::No,
371
+ )
372
+ }
373
+
374
+ fn scope_revalidation_results(
375
+ &mut self,
376
+ stylist: &Stylist,
377
+ selector_caches: &mut SelectorCaches,
378
+ ) -> ScopeRevalidationResult {
379
+ stylist.revalidate_scopes(&self.element, selector_caches, NeedsSelectorFlags::No)
380
+ }
381
+ }
382
+
383
+ impl<E: TElement> PartialEq<StyleSharingCandidate<E>> for StyleSharingCandidate<E> {
384
+ fn eq(&self, other: &Self) -> bool {
385
+ self.element == other.element
386
+ }
387
+ }
388
+
389
+ /// An element we want to test against the style sharing cache.
390
+ pub struct StyleSharingTarget<E: TElement> {
391
+ element: E,
392
+ validation_data: ValidationData,
393
+ }
394
+
395
+ impl<E: TElement> Deref for StyleSharingTarget<E> {
396
+ type Target = E;
397
+
398
+ fn deref(&self) -> &Self::Target {
399
+ &self.element
400
+ }
401
+ }
402
+
403
+ impl<E: TElement> StyleSharingTarget<E> {
404
+ /// Trivially construct a new StyleSharingTarget to test against the cache.
405
+ pub fn new(element: E) -> Self {
406
+ Self {
407
+ element,
408
+ validation_data: ValidationData::default(),
409
+ }
410
+ }
411
+
412
+ fn class_list(&mut self) -> &[AtomIdent] {
413
+ self.validation_data.class_list(self.element)
414
+ }
415
+
416
+ fn part_list(&mut self) -> &[AtomIdent] {
417
+ self.validation_data.part_list(self.element)
418
+ }
419
+
420
+ /// Get the pres hints of this candidate.
421
+ fn pres_hints(&mut self) -> &[ApplicableDeclarationBlock] {
422
+ self.validation_data.pres_hints(self.element)
423
+ }
424
+
425
+ /// Get the parent style identity.
426
+ fn parent_style_identity(&mut self) -> OpaqueComputedValues {
427
+ self.validation_data.parent_style_identity(self.element)
428
+ }
429
+
430
+ fn revalidation_match_results(
431
+ &mut self,
432
+ stylist: &Stylist,
433
+ bloom: &StyleBloom<E>,
434
+ selector_caches: &mut SelectorCaches,
435
+ ) -> &RevalidationResult {
436
+ // It's important to set the selector flags. Otherwise, if we succeed in
437
+ // sharing the style, we may not set the slow selector flags for the
438
+ // right elements (which may not necessarily be |element|), causing
439
+ // missed restyles after future DOM mutations.
440
+ //
441
+ // Gecko's test_bug534804.html exercises this. A minimal testcase is:
442
+ // <style> #e:empty + span { ... } </style>
443
+ // <span id="e">
444
+ // <span></span>
445
+ // </span>
446
+ // <span></span>
447
+ //
448
+ // The style sharing cache will get a hit for the second span. When the
449
+ // child span is subsequently removed from the DOM, missing selector
450
+ // flags would cause us to miss the restyle on the second span.
451
+ self.validation_data.revalidation_match_results(
452
+ self.element,
453
+ stylist,
454
+ bloom,
455
+ selector_caches,
456
+ /* bloom_known_valid = */ true,
457
+ NeedsSelectorFlags::Yes,
458
+ )
459
+ }
460
+
461
+ fn scope_revalidation_results(
462
+ &mut self,
463
+ stylist: &Stylist,
464
+ selector_caches: &mut SelectorCaches,
465
+ ) -> ScopeRevalidationResult {
466
+ stylist.revalidate_scopes(&self.element, selector_caches, NeedsSelectorFlags::Yes)
467
+ }
468
+
469
+ /// Attempts to share a style with another node.
470
+ pub fn share_style_if_possible(
471
+ &mut self,
472
+ context: &mut StyleContext<E>,
473
+ ) -> Option<ResolvedElementStyles> {
474
+ let cache = &mut context.thread_local.sharing_cache;
475
+ let shared_context = &context.shared;
476
+ let bloom_filter = &context.thread_local.bloom_filter;
477
+ let selector_caches = &mut context.thread_local.selector_caches;
478
+
479
+ debug_assert_eq!(
480
+ bloom_filter.current_parent(),
481
+ self.element.traversal_parent()
482
+ );
483
+
484
+ cache.share_style_if_possible(shared_context, bloom_filter, selector_caches, self)
485
+ }
486
+
487
+ /// Gets the validation data used to match against this target, if any.
488
+ pub fn take_validation_data(&mut self) -> ValidationData {
489
+ self.validation_data.take()
490
+ }
491
+ }
492
+
493
+ struct SharingCacheBase<Candidate> {
494
+ /// The DOM depth of the candidates in this cache, if any.
495
+ dom_depth: usize,
496
+ entries: LRUCache<Candidate, SHARING_CACHE_SIZE>,
497
+ }
498
+
499
+ impl<Candidate> Default for SharingCacheBase<Candidate> {
500
+ fn default() -> Self {
501
+ Self {
502
+ dom_depth: 0,
503
+ entries: LRUCache::default(),
504
+ }
505
+ }
506
+ }
507
+
508
+ impl<Candidate> SharingCacheBase<Candidate> {
509
+ fn clear(&mut self) {
510
+ self.entries.clear();
511
+ self.dom_depth = 0
512
+ }
513
+
514
+ fn is_empty(&self) -> bool {
515
+ self.entries.len() == 0
516
+ }
517
+ }
518
+
519
+ impl<E: TElement> SharingCache<E> {
520
+ fn insert(
521
+ &mut self,
522
+ element: E,
523
+ validation_data_holder: Option<&mut StyleSharingTarget<E>>,
524
+ considered_nontrivial_scoped_style: bool,
525
+ ) {
526
+ let validation_data = match validation_data_holder {
527
+ Some(v) => v.take_validation_data(),
528
+ None => ValidationData::default(),
529
+ };
530
+ self.entries.insert(StyleSharingCandidate {
531
+ element,
532
+ validation_data,
533
+ considered_nontrivial_scoped_style,
534
+ });
535
+ }
536
+ }
537
+
538
+ /// Style sharing caches are are large allocations, so we store them in thread-local
539
+ /// storage such that they can be reused across style traversals. Ideally, we'd just
540
+ /// stack-allocate these buffers with uninitialized memory, but right now rustc can't
541
+ /// avoid memmoving the entire cache during setup, which gets very expensive. See
542
+ /// issues like [1] and [2].
543
+ ///
544
+ /// Given that the cache stores entries of type TElement, we transmute to usize
545
+ /// before storing in TLS. This is safe as long as we make sure to empty the cache
546
+ /// before we let it go.
547
+ ///
548
+ /// [1] https://github.com/rust-lang/rust/issues/42763
549
+ /// [2] https://github.com/rust-lang/rust/issues/13707
550
+ type SharingCache<E> = SharingCacheBase<StyleSharingCandidate<E>>;
551
+ type TypelessSharingCache = SharingCacheBase<StyleSharingCandidate<usize>>;
552
+
553
+ thread_local! {
554
+ // See the comment on bloom.rs about why do we leak this.
555
+ static SHARING_CACHE_KEY: &'static AtomicRefCell<[TypelessSharingCache; SHARING_MAX_LEVELS]> =
556
+ Box::leak(Default::default());
557
+ }
558
+
559
+ /// A set of LRU caches of the last few nodes seen, one per DOM depth, so that we can try to
560
+ /// aggressively try to share their styles.
561
+ ///
562
+ /// We key the candidates by DOM depth, because sharing requires an identical inheritance parent
563
+ /// (see `test_candidate`), which in practice means the candidates worth testing are the ones at the
564
+ /// target's own depth.
565
+ ///
566
+ /// Note that these caches only live for the duration of one traversal so storing nodes here
567
+ /// temporarily is safe.
568
+ pub struct StyleSharingCache<E: TElement> {
569
+ /// The per-depth LRU caches, with the type cast away to allow persisting the allocation across
570
+ /// traversals.
571
+ cache_typeless: AtomicRefMut<'static, [TypelessSharingCache; SHARING_MAX_LEVELS]>,
572
+ /// Bind this structure to the lifetime of E, since that's what we effectively store.
573
+ marker: PhantomData<SendElement<E>>,
574
+ }
575
+
576
+ impl<E: TElement> Drop for StyleSharingCache<E> {
577
+ fn drop(&mut self) {
578
+ self.clear();
579
+ }
580
+ }
581
+
582
+ impl<E: TElement> Default for StyleSharingCache<E> {
583
+ fn default() -> Self {
584
+ Self::new()
585
+ }
586
+ }
587
+
588
+ impl<E: TElement> StyleSharingCache<E> {
589
+ fn cache_mut_at(&mut self, index: usize) -> &mut SharingCache<E> {
590
+ let base: &mut TypelessSharingCache = &mut self.cache_typeless[index % SHARING_MAX_LEVELS];
591
+ unsafe { mem::transmute(base) }
592
+ }
593
+
594
+ /// Create a new style sharing candidate cache.
595
+
596
+ // Forced out of line to limit stack frame sizes after extra inlining from
597
+ // https://github.com/rust-lang/rust/pull/43931
598
+ //
599
+ // See https://github.com/servo/servo/pull/18420#issuecomment-328769322
600
+ #[inline(never)]
601
+ pub fn new() -> Self {
602
+ assert_eq!(
603
+ mem::size_of::<SharingCache<E>>(),
604
+ mem::size_of::<TypelessSharingCache>()
605
+ );
606
+ assert_eq!(
607
+ mem::align_of::<SharingCache<E>>(),
608
+ mem::align_of::<TypelessSharingCache>()
609
+ );
610
+ let cache = SHARING_CACHE_KEY.with(|c| c.borrow_mut());
611
+ debug_assert!(cache.iter().all(|c| c.is_empty()));
612
+ StyleSharingCache {
613
+ cache_typeless: cache,
614
+ marker: PhantomData,
615
+ }
616
+ }
617
+
618
+ /// Tries to insert an element in the style sharing cache.
619
+ ///
620
+ /// Fails if we know it should never be in the cache.
621
+ ///
622
+ /// NB: We pass a source for the validation data, rather than the data itself,
623
+ /// to avoid memmoving at each function call. See rust issue #42763.
624
+ pub fn insert_if_possible(
625
+ &mut self,
626
+ element: &E,
627
+ style: &PrimaryStyle,
628
+ validation_data_holder: Option<&mut StyleSharingTarget<E>>,
629
+ dom_depth: usize,
630
+ shared_context: &SharedStyleContext,
631
+ ) {
632
+ let parent = match element.traversal_parent() {
633
+ Some(element) => element,
634
+ None => {
635
+ debug!("Failing to insert to the cache: no parent element");
636
+ return;
637
+ },
638
+ };
639
+
640
+ if !element.matches_user_and_content_rules() {
641
+ debug!("Failing to insert into the cache: no tree rules:");
642
+ return;
643
+ }
644
+
645
+ // If the element has running animations, we can't share style.
646
+ //
647
+ // This is distinct from the specifies_{animations,transitions} check below,
648
+ // because:
649
+ // * Animations can be triggered directly via the Web Animations API.
650
+ // * Our computed style can still be affected by animations after we no
651
+ // longer match any animation rules, since removing animations involves
652
+ // a sequential task and an additional traversal.
653
+ if element.has_animations(shared_context) {
654
+ debug!("Failing to insert to the cache: running animations");
655
+ return;
656
+ }
657
+
658
+ if element.smil_override().is_some() {
659
+ debug!("Failing to insert to the cache: SMIL");
660
+ return;
661
+ }
662
+
663
+ debug!(
664
+ "Inserting into cache: {:?} with parent {:?}",
665
+ element, parent
666
+ );
667
+ debug_assert_eq!(element.as_node().depth(), dom_depth);
668
+
669
+ let cache = self.cache_mut_at(dom_depth);
670
+ if cache.dom_depth != dom_depth {
671
+ debug!(
672
+ "Clearing cache because depth changed from {:?} to {:?}, element: {:?}",
673
+ cache.dom_depth, dom_depth, element
674
+ );
675
+ cache.clear();
676
+ cache.dom_depth = dom_depth;
677
+ }
678
+ cache.insert(
679
+ *element,
680
+ validation_data_holder,
681
+ style
682
+ .style()
683
+ .flags
684
+ .intersects(ComputedValueFlags::CONSIDERED_NONTRIVIAL_SCOPED_STYLE),
685
+ );
686
+ }
687
+
688
+ /// Clear the style sharing candidate cache (all depths).
689
+ pub fn clear(&mut self) {
690
+ for c in &mut *self.cache_typeless {
691
+ c.clear();
692
+ }
693
+ }
694
+
695
+ /// Attempts to share a style with another node.
696
+ fn share_style_if_possible(
697
+ &mut self,
698
+ shared_context: &SharedStyleContext,
699
+ bloom_filter: &StyleBloom<E>,
700
+ selector_caches: &mut SelectorCaches,
701
+ target: &mut StyleSharingTarget<E>,
702
+ ) -> Option<ResolvedElementStyles> {
703
+ if shared_context.options.disable_style_sharing_cache {
704
+ debug!(
705
+ "{:?} Cannot share style: style sharing cache disabled",
706
+ target.element
707
+ );
708
+ return None;
709
+ }
710
+
711
+ if target.inheritance_parent().is_none() {
712
+ debug!(
713
+ "{:?} Cannot share style: element has no parent",
714
+ target.element
715
+ );
716
+ return None;
717
+ }
718
+
719
+ if !target.matches_user_and_content_rules() {
720
+ debug!("{:?} Cannot share style: content rules", target.element);
721
+ return None;
722
+ }
723
+
724
+ let dom_depth = bloom_filter.matching_depth();
725
+ debug_assert_eq!(target.element.as_node().depth(), dom_depth);
726
+ let cache = self.cache_mut_at(dom_depth);
727
+ if cache.dom_depth != dom_depth {
728
+ debug!(
729
+ "{:?} Cannot share style: cache holds depth {:?}, not {:?}",
730
+ target.element, cache.dom_depth, dom_depth
731
+ );
732
+ return None;
733
+ }
734
+
735
+ cache.entries.lookup(|candidate| {
736
+ Self::test_candidate(
737
+ target,
738
+ candidate,
739
+ shared_context,
740
+ bloom_filter,
741
+ selector_caches,
742
+ shared_context,
743
+ )
744
+ })
745
+ }
746
+
747
+ fn test_candidate(
748
+ target: &mut StyleSharingTarget<E>,
749
+ candidate: &mut StyleSharingCandidate<E>,
750
+ shared: &SharedStyleContext,
751
+ bloom: &StyleBloom<E>,
752
+ selector_caches: &mut SelectorCaches,
753
+ shared_context: &SharedStyleContext,
754
+ ) -> Option<ResolvedElementStyles> {
755
+ debug_assert!(target.matches_user_and_content_rules());
756
+ debug_assert!(candidate.element.matches_user_and_content_rules());
757
+
758
+ // Check that we have the same parent, or at least that the parents
759
+ // share styles and permit sharing across their children. The latter
760
+ // check allows us to share style between cousins if the parents
761
+ // shared style.
762
+ if !checks::parents_allow_sharing(target, candidate) {
763
+ trace!("Miss: Parent");
764
+ return None;
765
+ }
766
+
767
+ if target.local_name() != candidate.element.local_name() {
768
+ trace!("Miss: Local Name");
769
+ return None;
770
+ }
771
+
772
+ if target.namespace() != candidate.element.namespace() {
773
+ trace!("Miss: Namespace");
774
+ return None;
775
+ }
776
+
777
+ // We do not ignore visited state here, because Gecko needs to store
778
+ // extra bits on visited styles, so these contexts cannot be shared.
779
+ if target.element.state() != candidate.state() {
780
+ trace!("Miss: User and Author State");
781
+ return None;
782
+ }
783
+
784
+ if target.is_link() != candidate.element.is_link() {
785
+ trace!("Miss: Link");
786
+ return None;
787
+ }
788
+
789
+ // If two elements belong to different shadow trees, different rules may apply to them, from
790
+ // the respective trees, so check their cascade data pointers.
791
+ if !checks::shadow_root_style_data_equals(
792
+ target.element.containing_shadow(),
793
+ candidate.element.containing_shadow(),
794
+ ) {
795
+ trace!("Miss: Different containing shadow root style data");
796
+ return None;
797
+ }
798
+
799
+ // Shadow hosts can share style when they have matching CascadeData pointers, which ensures
800
+ // they match the same :host rules.
801
+ if !checks::shadow_root_style_data_equals(
802
+ target.element.shadow_root(),
803
+ candidate.element.shadow_root(),
804
+ ) {
805
+ trace!("Miss: Different shadow root style data");
806
+ return None;
807
+ }
808
+
809
+ // If the elements are not assigned to the same slot they could match
810
+ // different ::slotted() rules in the slot scope.
811
+ //
812
+ // If two elements are assigned to different slots, even within the same
813
+ // shadow root, they could match different rules, due to the slot being
814
+ // assigned to yet another slot in another shadow root.
815
+ if target.element.assigned_slot() != candidate.element.assigned_slot() {
816
+ // TODO(emilio): We could have a look at whether the shadow roots
817
+ // actually have slotted rules and such.
818
+ trace!("Miss: Different assigned slots");
819
+ return None;
820
+ }
821
+
822
+ if target.implemented_pseudo_element() != candidate.implemented_pseudo_element() {
823
+ trace!("Miss: Element backed pseudo-element");
824
+ return None;
825
+ }
826
+
827
+ if target.element.has_animations(shared_context)
828
+ || candidate.element.has_animations(shared_context)
829
+ {
830
+ trace!("Miss: Has Animations");
831
+ return None;
832
+ }
833
+
834
+ if target.element.smil_override().is_some() {
835
+ trace!("Miss: SMIL");
836
+ return None;
837
+ }
838
+
839
+ // It's possible that there are no styles for either id.
840
+ if checks::may_match_different_id_rules(shared, target.element, candidate.element) {
841
+ trace!("Miss: ID Attr");
842
+ return None;
843
+ }
844
+
845
+ if !checks::have_same_style_attribute(target, candidate, shared_context) {
846
+ trace!("Miss: Style Attr");
847
+ return None;
848
+ }
849
+
850
+ if !checks::have_same_class(target, candidate) {
851
+ trace!("Miss: Class");
852
+ return None;
853
+ }
854
+
855
+ if !checks::have_same_presentational_hints(target, candidate) {
856
+ trace!("Miss: Pres Hints");
857
+ return None;
858
+ }
859
+
860
+ if !checks::have_same_parts(target, candidate) {
861
+ trace!("Miss: Shadow parts");
862
+ return None;
863
+ }
864
+
865
+ if !checks::have_same_referenced_attrs(target, candidate) {
866
+ trace!("Miss: Attr references");
867
+ return None;
868
+ }
869
+
870
+ if !checks::have_shareable_tree_counting_functions(target, candidate) {
871
+ trace!("Miss: Tree counting functions");
872
+ return None;
873
+ }
874
+
875
+ if !checks::revalidate(target, candidate, shared, bloom, selector_caches) {
876
+ trace!("Miss: Revalidation");
877
+ return None;
878
+ }
879
+
880
+ // While the scoped style rules may be different (e.g. `@scope { .foo + .foo { /* .. */} }`),
881
+ // we rely on revalidation to handle that.
882
+ if candidate.considered_nontrivial_scoped_style
883
+ && !checks::revalidate_scope(target, candidate, shared, selector_caches)
884
+ {
885
+ trace!("Miss: Active Scopes");
886
+ return None;
887
+ }
888
+
889
+ debug!(
890
+ "Sharing allowed between {:?} and {:?}",
891
+ target.element, candidate.element
892
+ );
893
+ Some(candidate.element.borrow_data().unwrap().share_styles())
894
+ }
895
+
896
+ /// Attempts to find an element in the cache with the given primary rule
897
+ /// node and parent.
898
+ ///
899
+ /// FIXME(emilio): re-measure this optimization, and remove if it's not very
900
+ /// useful... It's probably not worth the complexity / obscure bugs.
901
+ pub fn lookup_by_rules(
902
+ &mut self,
903
+ shared_context: &SharedStyleContext,
904
+ inherited: &ComputedValues,
905
+ inputs: &CascadeInputs,
906
+ target: E,
907
+ dom_depth: usize,
908
+ ) -> Option<PrimaryStyle> {
909
+ debug_assert_eq!(target.as_node().depth(), dom_depth);
910
+ if shared_context.options.disable_style_sharing_cache {
911
+ return None;
912
+ }
913
+
914
+ let cache = self.cache_mut_at(dom_depth);
915
+ if cache.dom_depth != dom_depth {
916
+ return None;
917
+ }
918
+
919
+ cache.entries.lookup(|candidate| {
920
+ debug_assert_ne!(candidate.element, target);
921
+ if !candidate.parent_style_identity().eq(inherited) {
922
+ return None;
923
+ }
924
+ let data = candidate.element.borrow_data().unwrap();
925
+ let style = data.styles.primary();
926
+ if style.rules.as_ref() != Some(inputs.rules.as_ref().unwrap()) {
927
+ return None;
928
+ }
929
+ if style.visited_rules() != inputs.visited_rules.as_ref() {
930
+ return None;
931
+ }
932
+ let sharing_target = StyleSharingTarget::new(target);
933
+ if !checks::have_same_referenced_attrs(&sharing_target, candidate) {
934
+ return None;
935
+ }
936
+ if !checks::have_shareable_tree_counting_functions(&sharing_target, candidate) {
937
+ return None;
938
+ }
939
+ // NOTE(emilio): We only need to check name / namespace because we
940
+ // do name-dependent style adjustments, like the display: contents
941
+ // to display: none adjustment.
942
+ if target.namespace() != candidate.element.namespace()
943
+ || target.local_name() != candidate.element.local_name()
944
+ {
945
+ return None;
946
+ }
947
+ // When using container units, inherited style + rules matched aren't enough to
948
+ // determine whether the style is the same. We could actually do a full container
949
+ // lookup but for now we just check that our actual traversal parent matches.
950
+ if data
951
+ .styles
952
+ .primary()
953
+ .flags
954
+ .intersects(ComputedValueFlags::USES_CONTAINER_UNITS)
955
+ && candidate.element.traversal_parent() != target.traversal_parent()
956
+ {
957
+ return None;
958
+ }
959
+ // Rule nodes and styles are computed independent of the element's actual visitedness,
960
+ // but at the end of the cascade (in `adjust_for_visited`) we do store the
961
+ // RELEVANT_LINK_VISITED flag, so we can't share by rule node between visited and
962
+ // unvisited styles. We don't check for visitedness and just refuse to share for links
963
+ // entirely, so that visitedness doesn't affect timing.
964
+ if target.is_link() || candidate.element.is_link() {
965
+ return None;
966
+ }
967
+
968
+ let target_depends_on_style_queries = inputs
969
+ .flags
970
+ .contains(ComputedValueFlags::DEPENDS_ON_CONTAINER_STYLE_QUERY);
971
+ let candidate_depends_on_style_queries = style
972
+ .flags
973
+ .contains(ComputedValueFlags::DEPENDS_ON_CONTAINER_STYLE_QUERY);
974
+
975
+ if target_depends_on_style_queries != candidate_depends_on_style_queries {
976
+ // If we're considering sharing across two elements, target
977
+ // depends on style queries and candidate doesn't, right
978
+ // now we can share it, but by cloning the candidate style
979
+ // if we adjust the flags.
980
+ // If we're considering sharing across two elements, target
981
+ // does not depend on style queries and candidate does, we
982
+ // can share them with the same flags, but that would
983
+ // overinvalidate if we already know we don't need to keep
984
+ // `DEPENDS_ON_CONTAINER_STYLE_QUERY`.
985
+ let mut new_flags = inputs.flags | style.flags;
986
+ new_flags.set(
987
+ ComputedValueFlags::DEPENDS_ON_CONTAINER_STYLE_QUERY,
988
+ target_depends_on_style_queries,
989
+ );
990
+
991
+ return Some(PrimaryStyle {
992
+ style: data.clone_style_with_flags(new_flags),
993
+ reused_via_rule_node: true,
994
+ });
995
+ }
996
+
997
+ Some(data.share_primary_style())
998
+ })
999
+ }
1000
+ }