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,716 @@
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
+ //! The context within which style is calculated.
6
+
7
+ #[cfg(feature = "servo")]
8
+ use crate::animation::DocumentAnimationSet;
9
+ use crate::bloom::StyleBloom;
10
+ use crate::computed_value_flags::ComputedValueFlags;
11
+ use crate::data::{EagerPseudoStyles, ElementData};
12
+ use crate::derives::*;
13
+ use crate::dom::{ElementContext, SendElement, TElement};
14
+ #[cfg(feature = "gecko")]
15
+ use crate::gecko_bindings::structs;
16
+ use crate::parallel::{STACK_SAFETY_MARGIN_KB, STYLE_THREAD_STACK_SIZE_KB};
17
+ use crate::properties::ComputedValues;
18
+ #[cfg(feature = "servo")]
19
+ use crate::properties::PropertyId;
20
+ use crate::rule_cache::RuleCache;
21
+ use crate::rule_tree::{RuleCascadeFlags, StrongRuleNode};
22
+ use crate::selector_parser::{SnapshotMap, EAGER_PSEUDO_COUNT};
23
+ use crate::shared_lock::StylesheetGuards;
24
+ use crate::sharing::StyleSharingCache;
25
+ use crate::stylist::Stylist;
26
+ use crate::thread_state::{self, ThreadState};
27
+ use crate::traversal::DomTraversal;
28
+ use crate::traversal_flags::TraversalFlags;
29
+ use crate::values::computed::TreeCountingResult;
30
+ use app_units::Au;
31
+ use euclid::default::Size2D;
32
+ use euclid::Scale;
33
+ use rustc_hash::FxHashMap;
34
+ use selectors::context::SelectorCaches;
35
+ use selectors::OpaqueElement;
36
+ #[cfg(feature = "gecko")]
37
+ use servo_arc::Arc;
38
+ use std::fmt;
39
+ use std::ops;
40
+ use std::time::{Duration, Instant};
41
+ use style_traits::dom::OpaqueNode;
42
+ use style_traits::CSSPixel;
43
+ use style_traits::DevicePixel;
44
+ #[cfg(feature = "servo")]
45
+ use style_traits::SpeculativePainter;
46
+ #[cfg(feature = "servo")]
47
+ use stylo_atoms::Atom;
48
+
49
+ pub use selectors::matching::QuirksMode;
50
+
51
+ /// A global options structure for the style system. We use this instead of
52
+ /// opts to abstract across Gecko and Servo.
53
+ #[derive(Clone)]
54
+ pub struct StyleSystemOptions {
55
+ /// Whether the style sharing cache is disabled.
56
+ pub disable_style_sharing_cache: bool,
57
+ /// Whether we should dump statistics about the style system.
58
+ pub dump_style_statistics: bool,
59
+ /// The minimum number of elements that must be traversed to trigger a dump
60
+ /// of style statistics.
61
+ pub style_statistics_threshold: usize,
62
+ }
63
+
64
+ #[cfg(feature = "gecko")]
65
+ fn get_env_bool(name: &str) -> bool {
66
+ use std::env;
67
+ match env::var(name) {
68
+ Ok(s) => !s.is_empty(),
69
+ Err(_) => false,
70
+ }
71
+ }
72
+
73
+ const DEFAULT_STATISTICS_THRESHOLD: usize = 50;
74
+
75
+ #[cfg(feature = "gecko")]
76
+ fn get_env_usize(name: &str) -> Option<usize> {
77
+ use std::env;
78
+ env::var(name).ok().map(|s| {
79
+ s.parse::<usize>()
80
+ .expect("Couldn't parse environmental variable as usize")
81
+ })
82
+ }
83
+
84
+ /// A global variable holding the state of
85
+ /// `StyleSystemOptions::default().disable_style_sharing_cache`.
86
+ /// See [#22854](https://github.com/servo/servo/issues/22854).
87
+ #[cfg(feature = "servo")]
88
+ pub static DEFAULT_DISABLE_STYLE_SHARING_CACHE: std::sync::atomic::AtomicBool =
89
+ std::sync::atomic::AtomicBool::new(false);
90
+
91
+ /// A global variable holding the state of
92
+ /// `StyleSystemOptions::default().dump_style_statistics`.
93
+ /// See [#22854](https://github.com/servo/servo/issues/22854).
94
+ #[cfg(feature = "servo")]
95
+ pub static DEFAULT_DUMP_STYLE_STATISTICS: std::sync::atomic::AtomicBool =
96
+ std::sync::atomic::AtomicBool::new(false);
97
+
98
+ impl Default for StyleSystemOptions {
99
+ #[cfg(feature = "servo")]
100
+ fn default() -> Self {
101
+ use std::sync::atomic::Ordering;
102
+
103
+ StyleSystemOptions {
104
+ disable_style_sharing_cache: DEFAULT_DISABLE_STYLE_SHARING_CACHE
105
+ .load(Ordering::Relaxed),
106
+ dump_style_statistics: DEFAULT_DUMP_STYLE_STATISTICS.load(Ordering::Relaxed),
107
+ style_statistics_threshold: DEFAULT_STATISTICS_THRESHOLD,
108
+ }
109
+ }
110
+
111
+ #[cfg(feature = "gecko")]
112
+ fn default() -> Self {
113
+ StyleSystemOptions {
114
+ disable_style_sharing_cache: get_env_bool("DISABLE_STYLE_SHARING_CACHE"),
115
+ dump_style_statistics: get_env_bool("DUMP_STYLE_STATISTICS"),
116
+ style_statistics_threshold: get_env_usize("STYLE_STATISTICS_THRESHOLD")
117
+ .unwrap_or(DEFAULT_STATISTICS_THRESHOLD),
118
+ }
119
+ }
120
+ }
121
+
122
+ /// A shared style context.
123
+ ///
124
+ /// There's exactly one of these during a given restyle traversal, and it's
125
+ /// shared among the worker threads.
126
+ pub struct SharedStyleContext<'a> {
127
+ /// The CSS selector stylist.
128
+ pub stylist: &'a Stylist,
129
+
130
+ /// Whether visited styles are enabled.
131
+ ///
132
+ /// They may be disabled when Gecko's pref layout.css.visited_links_enabled
133
+ /// is false, or when in private browsing mode.
134
+ pub visited_styles_enabled: bool,
135
+
136
+ /// Configuration options.
137
+ pub options: StyleSystemOptions,
138
+
139
+ /// Guards for pre-acquired locks
140
+ pub guards: StylesheetGuards<'a>,
141
+
142
+ /// The current time for transitions and animations. This is needed to ensure
143
+ /// a consistent sampling time and also to adjust the time for testing.
144
+ pub current_time_for_animations: f64,
145
+
146
+ /// Flags controlling how we traverse the tree.
147
+ pub traversal_flags: TraversalFlags,
148
+
149
+ /// A map with our snapshots in order to handle restyle hints.
150
+ pub snapshot_map: &'a SnapshotMap,
151
+
152
+ /// The state of all animations for our styled elements.
153
+ #[cfg(feature = "servo")]
154
+ pub animations: DocumentAnimationSet,
155
+
156
+ /// Paint worklets
157
+ #[cfg(feature = "servo")]
158
+ pub registered_speculative_painters: &'a dyn RegisteredSpeculativePainters,
159
+ }
160
+
161
+ impl<'a> SharedStyleContext<'a> {
162
+ /// Return a suitable viewport size in order to be used for viewport units.
163
+ pub fn viewport_size(&self) -> Size2D<Au> {
164
+ self.stylist.device().au_viewport_size()
165
+ }
166
+
167
+ /// The device pixel ratio
168
+ pub fn device_pixel_ratio(&self) -> Scale<f32, CSSPixel, DevicePixel> {
169
+ self.stylist.device().device_pixel_ratio()
170
+ }
171
+
172
+ /// The quirks mode of the document.
173
+ pub fn quirks_mode(&self) -> QuirksMode {
174
+ self.stylist.quirks_mode()
175
+ }
176
+ }
177
+
178
+ /// The structure holds various intermediate inputs that are eventually used by
179
+ /// by the cascade.
180
+ ///
181
+ /// The matching and cascading process stores them in this format temporarily
182
+ /// within the `CurrentElementInfo`. At the end of the cascade, they are folded
183
+ /// down into the main `ComputedValues` to reduce memory usage per element while
184
+ /// still remaining accessible.
185
+ #[derive(Clone, Debug, Default)]
186
+ pub struct CascadeInputs {
187
+ /// The rule node representing the ordered list of rules matched for this
188
+ /// node.
189
+ pub rules: Option<StrongRuleNode>,
190
+
191
+ /// The rule node representing the ordered list of rules matched for this
192
+ /// node if visited, only computed if there's a relevant link for this
193
+ /// element. A element's "relevant link" is the element being matched if it
194
+ /// is a link or the nearest ancestor link.
195
+ pub visited_rules: Option<StrongRuleNode>,
196
+
197
+ /// The set of flags from container queries that we need for invalidation.
198
+ pub flags: ComputedValueFlags,
199
+
200
+ /// The set of RuleCascadeFlags to include in the cascade.
201
+ pub included_cascade_flags: RuleCascadeFlags,
202
+ }
203
+
204
+ impl CascadeInputs {
205
+ /// Construct inputs from previous cascade results, if any.
206
+ pub fn new_from_style(style: &ComputedValues) -> Self {
207
+ Self {
208
+ rules: style.rules.clone(),
209
+ visited_rules: style.visited_style().and_then(|v| v.rules.clone()),
210
+ flags: style.flags.for_cascade_inputs(),
211
+ included_cascade_flags: RuleCascadeFlags::empty(),
212
+ }
213
+ }
214
+ }
215
+
216
+ /// A list of cascade inputs for eagerly-cascaded pseudo-elements.
217
+ /// The list is stored inline.
218
+ #[derive(Debug)]
219
+ pub struct EagerPseudoCascadeInputs(Option<[Option<CascadeInputs>; EAGER_PSEUDO_COUNT]>);
220
+
221
+ // Manually implement `Clone` here because the derived impl of `Clone` for
222
+ // array types assumes the value inside is `Copy`.
223
+ impl Clone for EagerPseudoCascadeInputs {
224
+ fn clone(&self) -> Self {
225
+ if self.0.is_none() {
226
+ return EagerPseudoCascadeInputs(None);
227
+ }
228
+ let self_inputs = self.0.as_ref().unwrap();
229
+ let mut inputs: [Option<CascadeInputs>; EAGER_PSEUDO_COUNT] = Default::default();
230
+ for i in 0..EAGER_PSEUDO_COUNT {
231
+ inputs[i] = self_inputs[i].clone();
232
+ }
233
+ EagerPseudoCascadeInputs(Some(inputs))
234
+ }
235
+ }
236
+
237
+ impl EagerPseudoCascadeInputs {
238
+ /// Construct inputs from previous cascade results, if any.
239
+ fn new_from_style(styles: &EagerPseudoStyles) -> Self {
240
+ EagerPseudoCascadeInputs(styles.as_optional_array().map(|styles| {
241
+ let mut inputs: [Option<CascadeInputs>; EAGER_PSEUDO_COUNT] = Default::default();
242
+ for i in 0..EAGER_PSEUDO_COUNT {
243
+ inputs[i] = styles[i].as_ref().map(|s| CascadeInputs::new_from_style(s));
244
+ }
245
+ inputs
246
+ }))
247
+ }
248
+
249
+ /// Returns the list of rules, if they exist.
250
+ pub fn into_array(self) -> Option<[Option<CascadeInputs>; EAGER_PSEUDO_COUNT]> {
251
+ self.0
252
+ }
253
+ }
254
+
255
+ /// The cascade inputs associated with a node, including those for any
256
+ /// pseudo-elements.
257
+ ///
258
+ /// The matching and cascading process stores them in this format temporarily
259
+ /// within the `CurrentElementInfo`. At the end of the cascade, they are folded
260
+ /// down into the main `ComputedValues` to reduce memory usage per element while
261
+ /// still remaining accessible.
262
+ #[derive(Clone, Debug)]
263
+ pub struct ElementCascadeInputs {
264
+ /// The element's cascade inputs.
265
+ pub primary: CascadeInputs,
266
+ /// A list of the inputs for the element's eagerly-cascaded pseudo-elements.
267
+ pub pseudos: EagerPseudoCascadeInputs,
268
+ }
269
+
270
+ impl ElementCascadeInputs {
271
+ /// Construct inputs from previous cascade results, if any.
272
+ #[inline]
273
+ pub fn new_from_element_data(data: &ElementData) -> Self {
274
+ debug_assert!(data.has_styles());
275
+ ElementCascadeInputs {
276
+ primary: CascadeInputs::new_from_style(data.styles.primary()),
277
+ pseudos: EagerPseudoCascadeInputs::new_from_style(&data.styles.pseudos),
278
+ }
279
+ }
280
+ }
281
+
282
+ /// Statistics gathered during the traversal. We gather statistics on each
283
+ /// thread and then combine them after the threads join via the Add
284
+ /// implementation below.
285
+ #[derive(AddAssign, Clone, Default)]
286
+ pub struct PerThreadTraversalStatistics {
287
+ /// The total number of elements traversed.
288
+ pub elements_traversed: u32,
289
+ /// The number of elements where has_styles() went from false to true.
290
+ pub elements_styled: u32,
291
+ /// The number of elements for which we performed selector matching.
292
+ pub elements_matched: u32,
293
+ /// The number of cache hits from the StyleSharingCache.
294
+ pub styles_shared: u32,
295
+ /// The number of styles reused via rule node comparison from the
296
+ /// StyleSharingCache.
297
+ pub styles_reused: u32,
298
+ }
299
+
300
+ /// Statistics gathered during the traversal plus some information from
301
+ /// other sources including stylist.
302
+ #[derive(Default)]
303
+ pub struct TraversalStatistics {
304
+ /// Aggregated statistics gathered during the traversal.
305
+ pub aggregated: PerThreadTraversalStatistics,
306
+ /// The number of selectors in the stylist.
307
+ pub selectors: u32,
308
+ /// The number of revalidation selectors.
309
+ pub revalidation_selectors: u32,
310
+ /// The number of state/attr dependencies in the dependency set.
311
+ pub dependency_selectors: u32,
312
+ /// The number of declarations in the stylist.
313
+ pub declarations: u32,
314
+ /// The number of times the stylist was rebuilt.
315
+ pub stylist_rebuilds: u32,
316
+ /// Time spent in the traversal, in milliseconds.
317
+ pub traversal_time: Duration,
318
+ /// Whether this was a parallel traversal.
319
+ pub is_parallel: bool,
320
+ /// Whether this is a "large" traversal.
321
+ pub is_large: bool,
322
+ }
323
+
324
+ /// Format the statistics in a way that the performance test harness understands.
325
+ /// See https://bugzilla.mozilla.org/show_bug.cgi?id=1331856#c2
326
+ impl fmt::Display for TraversalStatistics {
327
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
328
+ writeln!(f, "[PERF] perf block start")?;
329
+ writeln!(
330
+ f,
331
+ "[PERF],traversal,{}",
332
+ if self.is_parallel {
333
+ "parallel"
334
+ } else {
335
+ "sequential"
336
+ }
337
+ )?;
338
+ writeln!(
339
+ f,
340
+ "[PERF],elements_traversed,{}",
341
+ self.aggregated.elements_traversed
342
+ )?;
343
+ writeln!(
344
+ f,
345
+ "[PERF],elements_styled,{}",
346
+ self.aggregated.elements_styled
347
+ )?;
348
+ writeln!(
349
+ f,
350
+ "[PERF],elements_matched,{}",
351
+ self.aggregated.elements_matched
352
+ )?;
353
+ writeln!(f, "[PERF],styles_shared,{}", self.aggregated.styles_shared)?;
354
+ writeln!(f, "[PERF],styles_reused,{}", self.aggregated.styles_reused)?;
355
+ writeln!(f, "[PERF],selectors,{}", self.selectors)?;
356
+ writeln!(
357
+ f,
358
+ "[PERF],revalidation_selectors,{}",
359
+ self.revalidation_selectors
360
+ )?;
361
+ writeln!(
362
+ f,
363
+ "[PERF],dependency_selectors,{}",
364
+ self.dependency_selectors
365
+ )?;
366
+ writeln!(f, "[PERF],declarations,{}", self.declarations)?;
367
+ writeln!(f, "[PERF],stylist_rebuilds,{}", self.stylist_rebuilds)?;
368
+ writeln!(
369
+ f,
370
+ "[PERF],traversal_time_ms,{}",
371
+ self.traversal_time.as_secs_f64() * 1000.
372
+ )?;
373
+ writeln!(f, "[PERF] perf block end")
374
+ }
375
+ }
376
+
377
+ impl TraversalStatistics {
378
+ /// Generate complete traversal statistics.
379
+ ///
380
+ /// The traversal time is computed given the start time in seconds.
381
+ pub fn new<E, D>(
382
+ aggregated: PerThreadTraversalStatistics,
383
+ traversal: &D,
384
+ parallel: bool,
385
+ start: Instant,
386
+ ) -> TraversalStatistics
387
+ where
388
+ E: TElement,
389
+ D: DomTraversal<E>,
390
+ {
391
+ let threshold = traversal
392
+ .shared_context()
393
+ .options
394
+ .style_statistics_threshold;
395
+ let stylist = traversal.shared_context().stylist;
396
+ let is_large = aggregated.elements_traversed as usize >= threshold;
397
+ TraversalStatistics {
398
+ aggregated,
399
+ selectors: stylist.num_selectors() as u32,
400
+ revalidation_selectors: stylist.num_revalidation_selectors() as u32,
401
+ dependency_selectors: stylist.num_invalidations() as u32,
402
+ declarations: stylist.num_declarations() as u32,
403
+ stylist_rebuilds: stylist.num_rebuilds() as u32,
404
+ traversal_time: Instant::now() - start,
405
+ is_parallel: parallel,
406
+ is_large,
407
+ }
408
+ }
409
+ }
410
+
411
+ #[cfg(feature = "gecko")]
412
+ bitflags! {
413
+ /// Represents which tasks are performed in a SequentialTask of
414
+ /// UpdateAnimations which is a result of normal restyle.
415
+ pub struct UpdateAnimationsTasks: u8 {
416
+ /// Update CSS Animations.
417
+ const CSS_ANIMATIONS = structs::UpdateAnimationsTasks_CSSAnimations;
418
+ /// Update CSS Transitions.
419
+ const CSS_TRANSITIONS = structs::UpdateAnimationsTasks_CSSTransitions;
420
+ /// Update effect properties.
421
+ const EFFECT_PROPERTIES = structs::UpdateAnimationsTasks_EffectProperties;
422
+ /// Update animation cacade results for animations running on the compositor.
423
+ const CASCADE_RESULTS = structs::UpdateAnimationsTasks_CascadeResults;
424
+ /// Display property was changed from none.
425
+ /// Script animations keep alive on display:none elements, so we need to trigger
426
+ /// the second animation restyles for the script animations in the case where
427
+ /// the display property was changed from 'none' to others.
428
+ const DISPLAY_CHANGED_FROM_NONE = structs::UpdateAnimationsTasks_DisplayChangedFromNone;
429
+ /// Update CSS named scroll progress timelines.
430
+ const SCROLL_TIMELINES = structs::UpdateAnimationsTasks_ScrollTimelines;
431
+ /// Update CSS named view progress timelines.
432
+ const VIEW_TIMELINES = structs::UpdateAnimationsTasks_ViewTimelines;
433
+ /// Update CSS timeline scopes, which affect visibility of both scroll and view timelines.
434
+ const TIMELINE_SCOPES = structs::UpdateAnimationsTasks_TimelineScopes;
435
+ }
436
+ }
437
+
438
+ /// A task to be run in sequential mode on the parent (non-worker) thread. This
439
+ /// is used by the style system to queue up work which is not safe to do during
440
+ /// the parallel traversal.
441
+ pub enum SequentialTask<E: TElement> {
442
+ /// Entry to avoid an unused type parameter error on servo.
443
+ Unused(SendElement<E>),
444
+
445
+ /// Performs one of a number of possible tasks related to updating
446
+ /// animations based on the |tasks| field. These include updating CSS
447
+ /// animations/transitions that changed as part of the non-animation style
448
+ /// traversal, and updating the computed effect properties.
449
+ #[cfg(feature = "gecko")]
450
+ UpdateAnimations {
451
+ /// The target element or pseudo-element.
452
+ el: SendElement<E>,
453
+ /// The before-change style for transitions. We use before-change style
454
+ /// as the initial value of its Keyframe. Required if |tasks| includes
455
+ /// CSSTransitions.
456
+ before_change_style: Option<Arc<ComputedValues>>,
457
+ /// The tasks which are performed in this SequentialTask.
458
+ tasks: UpdateAnimationsTasks,
459
+ },
460
+ }
461
+
462
+ impl<E: TElement> SequentialTask<E> {
463
+ /// Executes this task.
464
+ pub fn execute(self) {
465
+ use self::SequentialTask::*;
466
+ debug_assert!(thread_state::get().contains(ThreadState::LAYOUT));
467
+ match self {
468
+ Unused(_) => unreachable!(),
469
+ #[cfg(feature = "gecko")]
470
+ UpdateAnimations {
471
+ el,
472
+ before_change_style,
473
+ tasks,
474
+ } => {
475
+ el.update_animations(before_change_style, tasks);
476
+ },
477
+ }
478
+ }
479
+
480
+ /// Creates a task to update various animation-related state on a given
481
+ /// (pseudo-)element.
482
+ #[cfg(feature = "gecko")]
483
+ pub fn update_animations(
484
+ el: E,
485
+ before_change_style: Option<Arc<ComputedValues>>,
486
+ tasks: UpdateAnimationsTasks,
487
+ ) -> Self {
488
+ use self::SequentialTask::*;
489
+ UpdateAnimations {
490
+ el: unsafe { SendElement::new(el) },
491
+ before_change_style,
492
+ tasks,
493
+ }
494
+ }
495
+ }
496
+
497
+ /// A list of SequentialTasks that get executed on Drop.
498
+ pub struct SequentialTaskList<E>(Vec<SequentialTask<E>>)
499
+ where
500
+ E: TElement;
501
+
502
+ impl<E> ops::Deref for SequentialTaskList<E>
503
+ where
504
+ E: TElement,
505
+ {
506
+ type Target = Vec<SequentialTask<E>>;
507
+
508
+ fn deref(&self) -> &Self::Target {
509
+ &self.0
510
+ }
511
+ }
512
+
513
+ impl<E> ops::DerefMut for SequentialTaskList<E>
514
+ where
515
+ E: TElement,
516
+ {
517
+ fn deref_mut(&mut self) -> &mut Self::Target {
518
+ &mut self.0
519
+ }
520
+ }
521
+
522
+ impl<E> Drop for SequentialTaskList<E>
523
+ where
524
+ E: TElement,
525
+ {
526
+ fn drop(&mut self) {
527
+ debug_assert!(thread_state::get().contains(ThreadState::LAYOUT));
528
+ for task in self.0.drain(..) {
529
+ task.execute()
530
+ }
531
+ }
532
+ }
533
+
534
+ /// A helper type for stack limit checking. This assumes that stacks grow
535
+ /// down, which is true for all non-ancient CPU architectures.
536
+ pub struct StackLimitChecker {
537
+ lower_limit: usize,
538
+ }
539
+
540
+ impl StackLimitChecker {
541
+ /// Create a new limit checker, for this thread, allowing further use
542
+ /// of up to |stack_size| bytes beyond (below) the current stack pointer.
543
+ #[inline(never)]
544
+ pub fn new(stack_size_limit: usize) -> Self {
545
+ StackLimitChecker {
546
+ lower_limit: StackLimitChecker::get_sp() - stack_size_limit,
547
+ }
548
+ }
549
+
550
+ /// Checks whether the previously stored stack limit has now been exceeded.
551
+ #[inline(never)]
552
+ pub fn limit_exceeded(&self) -> bool {
553
+ let curr_sp = StackLimitChecker::get_sp();
554
+
555
+ // Do some sanity-checking to ensure that our invariants hold, even in
556
+ // the case where we've exceeded the soft limit.
557
+ //
558
+ // The correctness of depends on the assumption that no stack wraps
559
+ // around the end of the address space.
560
+ if cfg!(debug_assertions) {
561
+ // Compute the actual bottom of the stack by subtracting our safety
562
+ // margin from our soft limit. Note that this will be slightly below
563
+ // the actual bottom of the stack, because there are a few initial
564
+ // frames on the stack before we do the measurement that computes
565
+ // the limit.
566
+ let stack_bottom = self.lower_limit - STACK_SAFETY_MARGIN_KB * 1024;
567
+
568
+ // The bottom of the stack should be below the current sp. If it
569
+ // isn't, that means we've either waited too long to check the limit
570
+ // and burned through our safety margin (in which case we probably
571
+ // would have segfaulted by now), or we're using a limit computed for
572
+ // a different thread.
573
+ debug_assert!(stack_bottom < curr_sp);
574
+
575
+ // Compute the distance between the current sp and the bottom of
576
+ // the stack, and compare it against the current stack. It should be
577
+ // no further from us than the total stack size. We allow some slop
578
+ // to handle the fact that stack_bottom is a bit further than the
579
+ // bottom of the stack, as discussed above.
580
+ let distance_to_stack_bottom = curr_sp - stack_bottom;
581
+ let max_allowable_distance = (STYLE_THREAD_STACK_SIZE_KB + 10) * 1024;
582
+ debug_assert!(distance_to_stack_bottom <= max_allowable_distance);
583
+ }
584
+
585
+ // The actual bounds check.
586
+ curr_sp <= self.lower_limit
587
+ }
588
+
589
+ // Technically, rustc can optimize this away, but shouldn't for now.
590
+ // We should fix this once black_box is stable.
591
+ #[inline(always)]
592
+ fn get_sp() -> usize {
593
+ let mut foo: usize = 42;
594
+ (&mut foo as *mut usize) as usize
595
+ }
596
+ }
597
+
598
+ /// Caches to speed up evalution of tree-counting functions. Separate caches
599
+ /// for index and count are used so that they can be populated in a single
600
+ /// traversal of an element's siblings.
601
+ ///
602
+ /// TODO(Bug 2046399) - Consider directly using the SelectorCaches instead.
603
+ #[derive(Default)]
604
+ pub struct TreeCountingCaches {
605
+ /// A cache of element sibling-index() values.
606
+ pub sibling_index: FxHashMap<OpaqueElement, u32>,
607
+ /// A cache of element sibling-count() values, keyed by the element's parent node.
608
+ pub sibling_count: FxHashMap<OpaqueNode, u32>,
609
+ }
610
+
611
+ impl TreeCountingCaches {
612
+ /// Look up the tree-counting function values for the given element. If the element and
613
+ /// its parent node are not cached, the values are computed and stored.
614
+ pub fn get_or_compute(&mut self, element_context: &dyn ElementContext) -> TreeCountingResult {
615
+ let (Some(target), Some(parent)) = (
616
+ element_context.opaque_element(),
617
+ element_context.opaque_parent(),
618
+ ) else {
619
+ return TreeCountingResult::default();
620
+ };
621
+
622
+ // Lookup from the index and count caches
623
+ let cached_index = self.sibling_index.get(&target).copied();
624
+ let cached_count = self.sibling_count.get(&parent).copied();
625
+ if let (Some(index), Some(count)) = (cached_index, cached_count) {
626
+ return TreeCountingResult::new(index, count);
627
+ }
628
+
629
+ // Compute the sibling index and sibling count for the element,
630
+ // inserting into the caches as it traverses through its siblings.
631
+ element_context.get_tree_counting_result(self)
632
+ }
633
+ }
634
+
635
+ /// A thread-local style context.
636
+ ///
637
+ /// This context contains data that needs to be used during restyling, but is
638
+ /// not required to be unique among worker threads, so we create one per worker
639
+ /// thread in order to be able to mutate it without locking.
640
+ pub struct ThreadLocalStyleContext<E: TElement> {
641
+ /// A cache to share style among siblings.
642
+ pub sharing_cache: StyleSharingCache<E>,
643
+ /// A cache from matched properties to elements that match those.
644
+ pub rule_cache: RuleCache,
645
+ /// The bloom filter used to fast-reject selector-matching.
646
+ pub bloom_filter: StyleBloom<E>,
647
+ /// The DOM depth of the element we're currently styling.
648
+ pub current_dom_depth: usize,
649
+ /// A set of tasks to be run (on the parent thread) in sequential mode after
650
+ /// the rest of the styling is complete. This is useful for
651
+ /// infrequently-needed non-threadsafe operations.
652
+ ///
653
+ /// It's important that goes after the style sharing cache and the bloom
654
+ /// filter, to ensure they're dropped before we execute the tasks, which
655
+ /// could create another ThreadLocalStyleContext for style computation.
656
+ pub tasks: SequentialTaskList<E>,
657
+ /// Statistics about the traversal.
658
+ pub statistics: PerThreadTraversalStatistics,
659
+ /// A checker used to ensure that parallel.rs does not recurse indefinitely
660
+ /// even on arbitrarily deep trees. See Gecko bug 1376883.
661
+ pub stack_limit_checker: StackLimitChecker,
662
+ /// Collection of caches (And cache-likes) for speeding up expensive selector matches.
663
+ pub selector_caches: SelectorCaches,
664
+ /// Caches for speeding up tree-counting function evaluations.
665
+ pub tree_counting_caches: TreeCountingCaches,
666
+ }
667
+
668
+ impl<E: TElement> Default for ThreadLocalStyleContext<E> {
669
+ fn default() -> Self {
670
+ Self::new()
671
+ }
672
+ }
673
+
674
+ impl<E: TElement> ThreadLocalStyleContext<E> {
675
+ /// Creates a new `ThreadLocalStyleContext`
676
+ pub fn new() -> Self {
677
+ ThreadLocalStyleContext {
678
+ sharing_cache: StyleSharingCache::new(),
679
+ rule_cache: RuleCache::new(),
680
+ bloom_filter: StyleBloom::new(),
681
+ current_dom_depth: 0,
682
+ tasks: SequentialTaskList(Vec::new()),
683
+ statistics: PerThreadTraversalStatistics::default(),
684
+ stack_limit_checker: StackLimitChecker::new(
685
+ (STYLE_THREAD_STACK_SIZE_KB - STACK_SAFETY_MARGIN_KB) * 1024,
686
+ ),
687
+ selector_caches: SelectorCaches::default(),
688
+ tree_counting_caches: TreeCountingCaches::default(),
689
+ }
690
+ }
691
+ }
692
+
693
+ /// A `StyleContext` is just a simple container for a immutable reference to a
694
+ /// shared style context, and a mutable reference to a local one.
695
+ pub struct StyleContext<'a, E: TElement + 'a> {
696
+ /// The shared style context reference.
697
+ pub shared: &'a SharedStyleContext<'a>,
698
+ /// The thread-local style context (mutable) reference.
699
+ pub thread_local: &'a mut ThreadLocalStyleContext<E>,
700
+ }
701
+
702
+ /// A registered painter
703
+ #[cfg(feature = "servo")]
704
+ pub trait RegisteredSpeculativePainter: SpeculativePainter {
705
+ /// The name it was registered with
706
+ fn name(&self) -> Atom;
707
+ /// The properties it was registered with
708
+ fn properties(&self) -> &FxHashMap<Atom, PropertyId>;
709
+ }
710
+
711
+ /// A set of registered painters
712
+ #[cfg(feature = "servo")]
713
+ pub trait RegisteredSpeculativePainters: Sync {
714
+ /// Look up a speculative painter
715
+ fn get(&self, name: &Atom) -> Option<&dyn RegisteredSpeculativePainter>;
716
+ }