blitz-pdf 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (370) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +391 -2
  3. package/THIRD_PARTY_NOTICES.md +25 -0
  4. package/assets/icon.svg +4 -0
  5. package/dist/api.d.ts +7 -0
  6. package/dist/api.d.ts.map +1 -0
  7. package/dist/api.js +46 -0
  8. package/dist/api.js.map +1 -0
  9. package/dist/assets.d.ts +7 -0
  10. package/dist/assets.d.ts.map +1 -0
  11. package/dist/assets.js +52 -0
  12. package/dist/assets.js.map +1 -0
  13. package/dist/browser.d.ts +3 -0
  14. package/dist/browser.d.ts.map +1 -0
  15. package/dist/browser.js +3 -0
  16. package/dist/browser.js.map +1 -0
  17. package/dist/node.d.ts +3 -0
  18. package/dist/node.d.ts.map +1 -0
  19. package/dist/node.js +10 -0
  20. package/dist/node.js.map +1 -0
  21. package/dist/options.d.ts +24 -0
  22. package/dist/options.d.ts.map +1 -0
  23. package/dist/options.js +135 -0
  24. package/dist/options.js.map +1 -0
  25. package/dist/types.d.ts +51 -0
  26. package/dist/types.d.ts.map +1 -0
  27. package/dist/types.js +2 -0
  28. package/dist/types.js.map +1 -0
  29. package/examples/bun.ts +8 -0
  30. package/examples/german-invoice/README.md +70 -0
  31. package/examples/german-invoice/data.mjs +83 -0
  32. package/examples/german-invoice/invoice.css +59 -0
  33. package/examples/german-invoice/template.mjs +49 -0
  34. package/examples/german-invoice.mjs +20 -0
  35. package/examples/invoice.html +29 -0
  36. package/examples/node.mjs +8 -0
  37. package/examples/pagination.html +40 -0
  38. package/examples/pagination.mjs +8 -0
  39. package/licenses/DejaVu.txt +187 -0
  40. package/licenses/RUST_DEPENDENCIES.txt +11577 -0
  41. package/package.json +89 -4
  42. package/src/api.ts +44 -0
  43. package/src/assets.ts +43 -0
  44. package/src/browser.ts +6 -0
  45. package/src/node.ts +12 -0
  46. package/src/options.ts +101 -0
  47. package/src/types.ts +49 -0
  48. package/vendor/README.md +17 -0
  49. package/vendor/stylo/.cargo-ok +1 -0
  50. package/vendor/stylo/.cargo_vcs_info.json +6 -0
  51. package/vendor/stylo/Cargo.lock +1485 -0
  52. package/vendor/stylo/Cargo.toml +274 -0
  53. package/vendor/stylo/LICENSE +373 -0
  54. package/vendor/stylo/README.md +6 -0
  55. package/vendor/stylo/applicable_declarations.rs +328 -0
  56. package/vendor/stylo/author_styles.rs +79 -0
  57. package/vendor/stylo/bezier.rs +176 -0
  58. package/vendor/stylo/bloom.rs +414 -0
  59. package/vendor/stylo/build.rs +91 -0
  60. package/vendor/stylo/build_gecko.rs +393 -0
  61. package/vendor/stylo/color/color_function.rs +601 -0
  62. package/vendor/stylo/color/component.rs +207 -0
  63. package/vendor/stylo/color/convert.rs +935 -0
  64. package/vendor/stylo/color/gamut/raytrace.rs +265 -0
  65. package/vendor/stylo/color/gamut.rs +227 -0
  66. package/vendor/stylo/color/mix.rs +645 -0
  67. package/vendor/stylo/color/mod.rs +750 -0
  68. package/vendor/stylo/color/parsing.rs +770 -0
  69. package/vendor/stylo/color/to_css.rs +297 -0
  70. package/vendor/stylo/context.rs +716 -0
  71. package/vendor/stylo/counter_style/mod.rs +754 -0
  72. package/vendor/stylo/counter_style/predefined.rs +61 -0
  73. package/vendor/stylo/counter_style/update_predefined.py +35 -0
  74. package/vendor/stylo/custom_properties.rs +2023 -0
  75. package/vendor/stylo/custom_properties_map.rs +220 -0
  76. package/vendor/stylo/data.rs +693 -0
  77. package/vendor/stylo/device/gecko.rs +486 -0
  78. package/vendor/stylo/device/mod.rs +304 -0
  79. package/vendor/stylo/device/servo.rs +507 -0
  80. package/vendor/stylo/dom.rs +1164 -0
  81. package/vendor/stylo/dom_apis.rs +937 -0
  82. package/vendor/stylo/driver.rs +172 -0
  83. package/vendor/stylo/error_reporting.rs +484 -0
  84. package/vendor/stylo/font_face.rs +558 -0
  85. package/vendor/stylo/font_metrics.rs +124 -0
  86. package/vendor/stylo/gecko/anon_boxes.toml +113 -0
  87. package/vendor/stylo/gecko/arc_types.rs +211 -0
  88. package/vendor/stylo/gecko/conversions.rs +59 -0
  89. package/vendor/stylo/gecko/data.rs +222 -0
  90. package/vendor/stylo/gecko/media_features.rs +971 -0
  91. package/vendor/stylo/gecko/mod.rs +20 -0
  92. package/vendor/stylo/gecko/non_ts_pseudo_class_list.rs +119 -0
  93. package/vendor/stylo/gecko/pseudo_element.rs +640 -0
  94. package/vendor/stylo/gecko/pseudo_element_definition.mako.rs +298 -0
  95. package/vendor/stylo/gecko/pseudo_elements.py +137 -0
  96. package/vendor/stylo/gecko/pseudo_elements.toml +197 -0
  97. package/vendor/stylo/gecko/regen_pseudo_elements.py +33 -0
  98. package/vendor/stylo/gecko/restyle_damage.rs +127 -0
  99. package/vendor/stylo/gecko/selector_parser.rs +627 -0
  100. package/vendor/stylo/gecko/snapshot.rs +202 -0
  101. package/vendor/stylo/gecko/snapshot_helpers.rs +334 -0
  102. package/vendor/stylo/gecko/traversal.rs +52 -0
  103. package/vendor/stylo/gecko/wrapper.rs +2258 -0
  104. package/vendor/stylo/gecko_bindings/mod.rs +34 -0
  105. package/vendor/stylo/gecko_bindings/sugar/mod.rs +12 -0
  106. package/vendor/stylo/gecko_bindings/sugar/ns_com_ptr.rs +15 -0
  107. package/vendor/stylo/gecko_bindings/sugar/ns_compatibility.rs +19 -0
  108. package/vendor/stylo/gecko_bindings/sugar/ns_style_auto_array.rs +111 -0
  109. package/vendor/stylo/gecko_bindings/sugar/origin_flags.rs +31 -0
  110. package/vendor/stylo/gecko_bindings/sugar/ownership.rs +70 -0
  111. package/vendor/stylo/gecko_bindings/sugar/refptr.rs +299 -0
  112. package/vendor/stylo/gecko_string_cache/mod.rs +543 -0
  113. package/vendor/stylo/gecko_string_cache/namespace.rs +106 -0
  114. package/vendor/stylo/global_style_data.rs +224 -0
  115. package/vendor/stylo/invalidation/element/document_state.rs +156 -0
  116. package/vendor/stylo/invalidation/element/element_wrapper.rs +432 -0
  117. package/vendor/stylo/invalidation/element/invalidation_map.rs +1631 -0
  118. package/vendor/stylo/invalidation/element/invalidator.rs +1470 -0
  119. package/vendor/stylo/invalidation/element/mod.rs +13 -0
  120. package/vendor/stylo/invalidation/element/relative_selector.rs +1399 -0
  121. package/vendor/stylo/invalidation/element/restyle_hints.rs +226 -0
  122. package/vendor/stylo/invalidation/element/state_and_attributes.rs +756 -0
  123. package/vendor/stylo/invalidation/media_queries.rs +144 -0
  124. package/vendor/stylo/invalidation/mod.rs +10 -0
  125. package/vendor/stylo/invalidation/stylesheets.rs +745 -0
  126. package/vendor/stylo/invalidation/viewport_units.rs +71 -0
  127. package/vendor/stylo/lib.rs +336 -0
  128. package/vendor/stylo/logical_geometry.rs +1684 -0
  129. package/vendor/stylo/macros.rs +70 -0
  130. package/vendor/stylo/matching.rs +1226 -0
  131. package/vendor/stylo/media_queries/media_list.rs +168 -0
  132. package/vendor/stylo/media_queries/media_query.rs +190 -0
  133. package/vendor/stylo/media_queries/mod.rs +13 -0
  134. package/vendor/stylo/parallel.rs +205 -0
  135. package/vendor/stylo/parser.rs +276 -0
  136. package/vendor/stylo/piecewise_linear.rs +282 -0
  137. package/vendor/stylo/prefs.rs +33 -0
  138. package/vendor/stylo/properties/build.py +119 -0
  139. package/vendor/stylo/properties/cascade.rs +2704 -0
  140. package/vendor/stylo/properties/computed_value_flags.rs +206 -0
  141. package/vendor/stylo/properties/counted_unknown_properties.py +104 -0
  142. package/vendor/stylo/properties/counter_style_descriptors.toml +45 -0
  143. package/vendor/stylo/properties/data.py +1375 -0
  144. package/vendor/stylo/properties/declaration_block.rs +1788 -0
  145. package/vendor/stylo/properties/font_face_descriptors.toml +50 -0
  146. package/vendor/stylo/properties/gecko.mako.rs +1555 -0
  147. package/vendor/stylo/properties/helpers/animated_properties.mako.rs +800 -0
  148. package/vendor/stylo/properties/helpers.mako.rs +812 -0
  149. package/vendor/stylo/properties/longhands.toml +4305 -0
  150. package/vendor/stylo/properties/mod.rs +1857 -0
  151. package/vendor/stylo/properties/properties.html.mako +31 -0
  152. package/vendor/stylo/properties/properties.mako.rs +3103 -0
  153. package/vendor/stylo/properties/property_descriptors.toml +18 -0
  154. package/vendor/stylo/properties/shorthands.rs +4241 -0
  155. package/vendor/stylo/properties/shorthands.toml +575 -0
  156. package/vendor/stylo/properties/vendored_python/mako-1.3.10-py3-none-any.whl +0 -0
  157. package/vendor/stylo/properties/vendored_python/markupsafe/LICENSE.txt +28 -0
  158. package/vendor/stylo/properties/vendored_python/markupsafe/__init__.py +384 -0
  159. package/vendor/stylo/properties/vendored_python/toml-0.10.2-py2.py3-none-any.whl +0 -0
  160. package/vendor/stylo/properties/view_transition_descriptors.toml +11 -0
  161. package/vendor/stylo/properties_and_values/mod.rs +12 -0
  162. package/vendor/stylo/properties_and_values/registry.rs +65 -0
  163. package/vendor/stylo/properties_and_values/rule.rs +331 -0
  164. package/vendor/stylo/properties_and_values/syntax/ascii.rs +60 -0
  165. package/vendor/stylo/properties_and_values/syntax/data_type.rs +146 -0
  166. package/vendor/stylo/properties_and_values/syntax/mod.rs +437 -0
  167. package/vendor/stylo/properties_and_values/value.rs +758 -0
  168. package/vendor/stylo/queries/condition.rs +996 -0
  169. package/vendor/stylo/queries/feature.rs +199 -0
  170. package/vendor/stylo/queries/feature_expression.rs +1170 -0
  171. package/vendor/stylo/queries/mod.rs +19 -0
  172. package/vendor/stylo/queries/values.rs +46 -0
  173. package/vendor/stylo/rule_cache.rs +267 -0
  174. package/vendor/stylo/rule_collector.rs +554 -0
  175. package/vendor/stylo/rule_tree/core.rs +787 -0
  176. package/vendor/stylo/rule_tree/level.rs +396 -0
  177. package/vendor/stylo/rule_tree/map.rs +201 -0
  178. package/vendor/stylo/rule_tree/mod.rs +427 -0
  179. package/vendor/stylo/rule_tree/source.rs +80 -0
  180. package/vendor/stylo/rule_tree/unsafe_box.rs +78 -0
  181. package/vendor/stylo/scoped_tls.rs +80 -0
  182. package/vendor/stylo/selector_map.rs +1050 -0
  183. package/vendor/stylo/selector_parser.rs +305 -0
  184. package/vendor/stylo/servo/animation.rs +1922 -0
  185. package/vendor/stylo/servo/attr.rs +714 -0
  186. package/vendor/stylo/servo/encoding_support.rs +81 -0
  187. package/vendor/stylo/servo/media_features.rs +254 -0
  188. package/vendor/stylo/servo/mod.rs +16 -0
  189. package/vendor/stylo/servo/restyle_damage.rs +215 -0
  190. package/vendor/stylo/servo/selector_parser.rs +1036 -0
  191. package/vendor/stylo/servo/shadow_parts.rs +207 -0
  192. package/vendor/stylo/shared_lock.rs +271 -0
  193. package/vendor/stylo/sharing/checks.rs +281 -0
  194. package/vendor/stylo/sharing/mod.rs +1000 -0
  195. package/vendor/stylo/simple_buckets_map.rs +52 -0
  196. package/vendor/stylo/str.rs +168 -0
  197. package/vendor/stylo/style_adjuster.rs +1086 -0
  198. package/vendor/stylo/style_resolver.rs +658 -0
  199. package/vendor/stylo/stylesheet_set.rs +658 -0
  200. package/vendor/stylo/stylesheets/appearance_base_rule.rs +51 -0
  201. package/vendor/stylo/stylesheets/container_rule.rs +769 -0
  202. package/vendor/stylo/stylesheets/counter_style_rule.rs +7 -0
  203. package/vendor/stylo/stylesheets/document_rule.rs +272 -0
  204. package/vendor/stylo/stylesheets/font_face_rule.rs +7 -0
  205. package/vendor/stylo/stylesheets/font_feature_values_rule.rs +481 -0
  206. package/vendor/stylo/stylesheets/font_palette_values_rule.rs +304 -0
  207. package/vendor/stylo/stylesheets/import_rule.rs +259 -0
  208. package/vendor/stylo/stylesheets/keyframes_rule.rs +733 -0
  209. package/vendor/stylo/stylesheets/layer_rule.rs +221 -0
  210. package/vendor/stylo/stylesheets/loader.rs +29 -0
  211. package/vendor/stylo/stylesheets/margin_rule.rs +190 -0
  212. package/vendor/stylo/stylesheets/media_rule.rs +191 -0
  213. package/vendor/stylo/stylesheets/mod.rs +918 -0
  214. package/vendor/stylo/stylesheets/namespace_rule.rs +43 -0
  215. package/vendor/stylo/stylesheets/nested_declarations_rule.rs +51 -0
  216. package/vendor/stylo/stylesheets/origin.rs +249 -0
  217. package/vendor/stylo/stylesheets/page_rule.rs +354 -0
  218. package/vendor/stylo/stylesheets/position_try_rule.rs +68 -0
  219. package/vendor/stylo/stylesheets/property_rule.rs +5 -0
  220. package/vendor/stylo/stylesheets/rule_list.rs +167 -0
  221. package/vendor/stylo/stylesheets/rule_parser.rs +1189 -0
  222. package/vendor/stylo/stylesheets/rules_iterator.rs +397 -0
  223. package/vendor/stylo/stylesheets/scope_rule.rs +511 -0
  224. package/vendor/stylo/stylesheets/starting_style_rule.rs +54 -0
  225. package/vendor/stylo/stylesheets/style_rule.rs +80 -0
  226. package/vendor/stylo/stylesheets/stylesheet.rs +570 -0
  227. package/vendor/stylo/stylesheets/supports_rule.rs +486 -0
  228. package/vendor/stylo/stylesheets/view_transition_rule.rs +81 -0
  229. package/vendor/stylo/stylist.rs +5076 -0
  230. package/vendor/stylo/thread_state.rs +87 -0
  231. package/vendor/stylo/traversal.rs +765 -0
  232. package/vendor/stylo/traversal_flags.rs +68 -0
  233. package/vendor/stylo/typed_om/mod.rs +981 -0
  234. package/vendor/stylo/typed_om/numeric.rs +128 -0
  235. package/vendor/stylo/typed_om/numeric_declaration.rs +93 -0
  236. package/vendor/stylo/typed_om/numeric_type.rs +640 -0
  237. package/vendor/stylo/typed_om/sum_value.rs +426 -0
  238. package/vendor/stylo/url/gecko.rs +367 -0
  239. package/vendor/stylo/url/mod.rs +71 -0
  240. package/vendor/stylo/url/servo.rs +239 -0
  241. package/vendor/stylo/use_counters/mod.rs +137 -0
  242. package/vendor/stylo/values/animated/color.rs +103 -0
  243. package/vendor/stylo/values/animated/effects.rs +26 -0
  244. package/vendor/stylo/values/animated/font.rs +37 -0
  245. package/vendor/stylo/values/animated/grid.rs +161 -0
  246. package/vendor/stylo/values/animated/lists.rs +141 -0
  247. package/vendor/stylo/values/animated/mod.rs +550 -0
  248. package/vendor/stylo/values/animated/svg.rs +46 -0
  249. package/vendor/stylo/values/animated/text.rs +58 -0
  250. package/vendor/stylo/values/animated/transform.rs +1592 -0
  251. package/vendor/stylo/values/computed/align.rs +90 -0
  252. package/vendor/stylo/values/computed/angle.rs +130 -0
  253. package/vendor/stylo/values/computed/animation.rs +124 -0
  254. package/vendor/stylo/values/computed/background.rs +13 -0
  255. package/vendor/stylo/values/computed/basic_shape.rs +267 -0
  256. package/vendor/stylo/values/computed/border.rs +163 -0
  257. package/vendor/stylo/values/computed/box.rs +267 -0
  258. package/vendor/stylo/values/computed/calc.rs +334 -0
  259. package/vendor/stylo/values/computed/color.rs +161 -0
  260. package/vendor/stylo/values/computed/column.rs +11 -0
  261. package/vendor/stylo/values/computed/corner_shape.rs +155 -0
  262. package/vendor/stylo/values/computed/counters.rs +26 -0
  263. package/vendor/stylo/values/computed/easing.rs +109 -0
  264. package/vendor/stylo/values/computed/effects.rs +30 -0
  265. package/vendor/stylo/values/computed/flex.rs +19 -0
  266. package/vendor/stylo/values/computed/font.rs +1517 -0
  267. package/vendor/stylo/values/computed/image.rs +273 -0
  268. package/vendor/stylo/values/computed/length.rs +576 -0
  269. package/vendor/stylo/values/computed/length_percentage.rs +1055 -0
  270. package/vendor/stylo/values/computed/list.rs +16 -0
  271. package/vendor/stylo/values/computed/mod.rs +1141 -0
  272. package/vendor/stylo/values/computed/motion.rs +73 -0
  273. package/vendor/stylo/values/computed/outline.rs +7 -0
  274. package/vendor/stylo/values/computed/page.rs +77 -0
  275. package/vendor/stylo/values/computed/param.rs +9 -0
  276. package/vendor/stylo/values/computed/percentage.rs +143 -0
  277. package/vendor/stylo/values/computed/position.rs +273 -0
  278. package/vendor/stylo/values/computed/ratio.rs +88 -0
  279. package/vendor/stylo/values/computed/rect.rs +19 -0
  280. package/vendor/stylo/values/computed/resolution.rs +76 -0
  281. package/vendor/stylo/values/computed/svg.rs +66 -0
  282. package/vendor/stylo/values/computed/table.rs +7 -0
  283. package/vendor/stylo/values/computed/text.rs +199 -0
  284. package/vendor/stylo/values/computed/time.rs +83 -0
  285. package/vendor/stylo/values/computed/transform.rs +559 -0
  286. package/vendor/stylo/values/computed/tree_counting.rs +30 -0
  287. package/vendor/stylo/values/computed/ui.rs +23 -0
  288. package/vendor/stylo/values/computed/url.rs +12 -0
  289. package/vendor/stylo/values/distance.rs +139 -0
  290. package/vendor/stylo/values/generics/animation.rs +363 -0
  291. package/vendor/stylo/values/generics/background.rs +65 -0
  292. package/vendor/stylo/values/generics/basic_shape.rs +1389 -0
  293. package/vendor/stylo/values/generics/border.rs +303 -0
  294. package/vendor/stylo/values/generics/box.rs +552 -0
  295. package/vendor/stylo/values/generics/calc.rs +2986 -0
  296. package/vendor/stylo/values/generics/color.rs +318 -0
  297. package/vendor/stylo/values/generics/column.rs +44 -0
  298. package/vendor/stylo/values/generics/counters.rs +320 -0
  299. package/vendor/stylo/values/generics/easing.rs +132 -0
  300. package/vendor/stylo/values/generics/effects.rs +131 -0
  301. package/vendor/stylo/values/generics/flex.rs +34 -0
  302. package/vendor/stylo/values/generics/font.rs +376 -0
  303. package/vendor/stylo/values/generics/grid.rs +962 -0
  304. package/vendor/stylo/values/generics/image.rs +653 -0
  305. package/vendor/stylo/values/generics/length.rs +656 -0
  306. package/vendor/stylo/values/generics/mod.rs +303 -0
  307. package/vendor/stylo/values/generics/motion.rs +274 -0
  308. package/vendor/stylo/values/generics/page.rs +167 -0
  309. package/vendor/stylo/values/generics/position.rs +669 -0
  310. package/vendor/stylo/values/generics/ratio.rs +88 -0
  311. package/vendor/stylo/values/generics/rect.rs +147 -0
  312. package/vendor/stylo/values/generics/size.rs +102 -0
  313. package/vendor/stylo/values/generics/svg.rs +226 -0
  314. package/vendor/stylo/values/generics/text.rs +268 -0
  315. package/vendor/stylo/values/generics/transform.rs +1157 -0
  316. package/vendor/stylo/values/generics/ui.rs +147 -0
  317. package/vendor/stylo/values/generics/url.rs +51 -0
  318. package/vendor/stylo/values/mod.rs +820 -0
  319. package/vendor/stylo/values/resolved/animation.rs +33 -0
  320. package/vendor/stylo/values/resolved/color.rs +53 -0
  321. package/vendor/stylo/values/resolved/counters.rs +45 -0
  322. package/vendor/stylo/values/resolved/mod.rs +316 -0
  323. package/vendor/stylo/values/specified/align.rs +711 -0
  324. package/vendor/stylo/values/specified/angle.rs +407 -0
  325. package/vendor/stylo/values/specified/animation.rs +921 -0
  326. package/vendor/stylo/values/specified/background.rs +270 -0
  327. package/vendor/stylo/values/specified/basic_shape.rs +986 -0
  328. package/vendor/stylo/values/specified/border.rs +430 -0
  329. package/vendor/stylo/values/specified/box.rs +2231 -0
  330. package/vendor/stylo/values/specified/calc.rs +1657 -0
  331. package/vendor/stylo/values/specified/color.rs +1210 -0
  332. package/vendor/stylo/values/specified/column.rs +11 -0
  333. package/vendor/stylo/values/specified/corner_shape.rs +152 -0
  334. package/vendor/stylo/values/specified/counters.rs +242 -0
  335. package/vendor/stylo/values/specified/easing.rs +225 -0
  336. package/vendor/stylo/values/specified/effects.rs +421 -0
  337. package/vendor/stylo/values/specified/flex.rs +42 -0
  338. package/vendor/stylo/values/specified/font.rs +2103 -0
  339. package/vendor/stylo/values/specified/frequency.rs +39 -0
  340. package/vendor/stylo/values/specified/grid.rs +407 -0
  341. package/vendor/stylo/values/specified/image.rs +1385 -0
  342. package/vendor/stylo/values/specified/intersection_observer.rs +80 -0
  343. package/vendor/stylo/values/specified/length.rs +2024 -0
  344. package/vendor/stylo/values/specified/list.rs +190 -0
  345. package/vendor/stylo/values/specified/mod.rs +531 -0
  346. package/vendor/stylo/values/specified/motion.rs +316 -0
  347. package/vendor/stylo/values/specified/number.rs +603 -0
  348. package/vendor/stylo/values/specified/outline.rs +69 -0
  349. package/vendor/stylo/values/specified/page.rs +94 -0
  350. package/vendor/stylo/values/specified/param.rs +121 -0
  351. package/vendor/stylo/values/specified/percentage.rs +364 -0
  352. package/vendor/stylo/values/specified/position.rs +2247 -0
  353. package/vendor/stylo/values/specified/ratio.rs +29 -0
  354. package/vendor/stylo/values/specified/rect.rs +28 -0
  355. package/vendor/stylo/values/specified/resolution.rs +237 -0
  356. package/vendor/stylo/values/specified/source_size_list.rs +135 -0
  357. package/vendor/stylo/values/specified/svg.rs +427 -0
  358. package/vendor/stylo/values/specified/svg_path.rs +1115 -0
  359. package/vendor/stylo/values/specified/table.rs +38 -0
  360. package/vendor/stylo/values/specified/text.rs +1561 -0
  361. package/vendor/stylo/values/specified/time.rs +313 -0
  362. package/vendor/stylo/values/specified/transform.rs +599 -0
  363. package/vendor/stylo/values/specified/tree_counting.rs +32 -0
  364. package/vendor/stylo/values/specified/ui.rs +344 -0
  365. package/vendor/stylo/values/specified/url.rs +12 -0
  366. package/vendor/stylo/values/tagged_numeric.rs +253 -0
  367. package/wasm/blitz_pdf.d.ts +67 -0
  368. package/wasm/blitz_pdf.js +699 -0
  369. package/wasm/blitz_pdf_bg.wasm +0 -0
  370. package/wasm/blitz_pdf_bg.wasm.d.ts +20 -0
@@ -0,0 +1,812 @@
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
+ <%! from data import to_rust_ident, to_camel_case, SYSTEM_FONT_LONGHANDS %>
6
+
7
+ <%def name="longhand(property)">
8
+ /// ${property.spec}
9
+ pub mod ${property.ident} {
10
+ #[allow(unused_imports)]
11
+ use crate::derives::*;
12
+ #[allow(unused_imports)]
13
+ use crate::values::{computed, generics, specified};
14
+ #[allow(unused_imports)]
15
+ use crate::values::computed::ToComputedValue;
16
+ #[allow(unused_imports)]
17
+ use servo_arc::Arc;
18
+ use cssparser::Parser;
19
+ #[allow(unused_imports)]
20
+ use crate::parser::{Parse, ParserContext};
21
+ use style_traits::ParseError;
22
+ #[allow(unused_imports)]
23
+ use crate::properties::{longhands, LonghandId, CSSWideKeyword, PropertyDeclaration};
24
+
25
+ /// # Safety
26
+ ///
27
+ /// `declaration` must be a declaration of this longhand, since its value is
28
+ /// read back with `unchecked_value_as`.
29
+ #[allow(unused_variables)]
30
+ pub unsafe fn cascade_property(
31
+ declaration: &PropertyDeclaration,
32
+ context: &mut computed::Context,
33
+ ) {
34
+ % if property.logical:
35
+ declaration.debug_crash("Should physicalize before entering here");
36
+ % else:
37
+ context.for_non_inherited_property = ${"false" if property.style_struct.inherited else "true"};
38
+ % if property.logical_group:
39
+ debug_assert_eq!(
40
+ declaration.id().as_longhand().unwrap().logical_group(),
41
+ LonghandId::${property.camel_case}.logical_group(),
42
+ );
43
+ % else:
44
+ debug_assert_eq!(
45
+ declaration.id().as_longhand().unwrap(),
46
+ LonghandId::${property.camel_case},
47
+ );
48
+ % endif
49
+ let specified_value = match *declaration {
50
+ PropertyDeclaration::CSSWideKeyword(ref wk) => {
51
+ match wk.keyword {
52
+ % if not property.style_struct.inherited:
53
+ CSSWideKeyword::Unset |
54
+ % endif
55
+ CSSWideKeyword::Initial => {
56
+ % if not property.style_struct.inherited:
57
+ declaration.debug_crash("Unexpected initial or unset for non-inherited property");
58
+ % else:
59
+ context.builder.reset_${property.ident}();
60
+ % endif
61
+ },
62
+ % if property.style_struct.inherited:
63
+ CSSWideKeyword::Unset |
64
+ % endif
65
+ CSSWideKeyword::Inherit => {
66
+ % if not property.style_struct.inherited:
67
+ context.rule_cache_conditions.borrow_mut().set_uncacheable();
68
+ % endif
69
+ % if property.is_zoom_dependent():
70
+ if !context.builder.effective_zoom_for_inheritance.is_one() {
71
+ let old_zoom = context.builder.effective_zoom;
72
+ context.builder.effective_zoom = context.builder.effective_zoom_for_inheritance;
73
+ let computed = context.builder.inherited_style.clone_${property.ident}();
74
+ let specified = computed::ToComputedValue::from_computed_value(&computed);
75
+ % if property.boxed:
76
+ let specified = Box::new(specified);
77
+ % endif
78
+ let decl = PropertyDeclaration::${property.camel_case}(specified);
79
+ unsafe { cascade_property(&decl, context) };
80
+ context.builder.effective_zoom = old_zoom;
81
+ return;
82
+ }
83
+ % endif
84
+ % if property.style_struct.inherited:
85
+ declaration.debug_crash("Unexpected inherit or unset for non-zoom-dependent inherited property");
86
+ % else:
87
+ context.builder.inherit_${property.ident}();
88
+ % endif
89
+ }
90
+ CSSWideKeyword::RevertRule |
91
+ CSSWideKeyword::RevertLayer |
92
+ CSSWideKeyword::Revert => {
93
+ declaration.debug_crash("Found revert* not dealt with");
94
+ },
95
+ }
96
+ return;
97
+ },
98
+ #[cfg(debug_assertions)]
99
+ PropertyDeclaration::WithVariables(..) => {
100
+ declaration.debug_crash("Found variables not substituted");
101
+ return;
102
+ },
103
+ _ => unsafe {
104
+ declaration.unchecked_value_as::<${property.specified_type()}>()
105
+ },
106
+ };
107
+
108
+ % if property.ident in SYSTEM_FONT_LONGHANDS and engine == "gecko":
109
+ if let Some(sf) = specified_value.get_system() {
110
+ crate::properties::gecko::system_font::resolve_system_font(sf, context);
111
+ }
112
+ % endif
113
+
114
+ % if property.vector and not property.vector.simple_bindings and engine == "gecko":
115
+ // In the case of a vector property we want to pass down an
116
+ // iterator so that this can be computed without allocation.
117
+ //
118
+ // However, computing requires a context, but the style struct
119
+ // being mutated is on the context. We temporarily remove it,
120
+ // mutate it, and then put it back. Vector longhands cannot
121
+ // touch their own style struct whilst computing, else this will
122
+ // panic.
123
+ let mut s =
124
+ context.builder.take_${property.style_struct.name_lower}();
125
+ {
126
+ let iter = specified_value.compute_iter(context);
127
+ s.set_${property.ident}(iter);
128
+ }
129
+ context.builder.put_${property.style_struct.name_lower}(s);
130
+ % else:
131
+ % if property.boxed:
132
+ let computed = (**specified_value).to_computed_value(context);
133
+ % else:
134
+ let computed = specified_value.to_computed_value(context);
135
+ % endif
136
+ context.builder.set_${property.ident}(computed)
137
+ % endif
138
+ % endif
139
+ }
140
+
141
+ pub fn parse_declared(
142
+ context: &ParserContext,
143
+ input: &mut Parser,
144
+ ) -> Result<PropertyDeclaration, ParseError> {
145
+ parse(context, input)
146
+ % if property.boxed:
147
+ .map(Box::new)
148
+ % endif
149
+ .map(PropertyDeclaration::${property.camel_case})
150
+ }
151
+
152
+ % if property.vector:
153
+ pub mod single_value {
154
+ use super::*;
155
+ % endif
156
+ % if property.predefined_type:
157
+ #[allow(unused_imports)]
158
+ use app_units::Au;
159
+ #[allow(unused_imports)]
160
+ use crate::values::specified::AllowQuirks;
161
+ #[allow(unused_imports)]
162
+ use crate::Zero;
163
+ #[allow(unused_imports)]
164
+ use smallvec::SmallVec;
165
+ pub use crate::values::specified::${property.predefined_type} as SpecifiedValue;
166
+ pub mod computed_value {
167
+ pub use crate::values::computed::${property.predefined_type} as T;
168
+ }
169
+ % if property.initial_value:
170
+ #[inline]
171
+ pub fn get_initial_value() -> computed_value::T { ${property.initial_value} }
172
+ #[inline]
173
+ pub fn get_initial_specified_value() -> SpecifiedValue {
174
+ % if property.initial_specified_value:
175
+ ${property.initial_specified_value}
176
+ % else:
177
+ ToComputedValue::from_computed_value(&get_initial_value())
178
+ % endif
179
+ }
180
+ % endif
181
+ #[allow(unused_variables)]
182
+ #[inline]
183
+ pub fn parse(
184
+ context: &ParserContext,
185
+ input: &mut Parser,
186
+ ) -> Result<SpecifiedValue, ParseError> {
187
+ % if property.allow_quirks:
188
+ specified::${property.predefined_type}::${property.parse_method}_quirky(context, input, AllowQuirks::Yes)
189
+ % elif property.parse_method != "parse":
190
+ specified::${property.predefined_type}::${property.parse_method}(context, input)
191
+ % else:
192
+ <specified::${property.predefined_type} as crate::parser::Parse>::parse(context, input)
193
+ % endif
194
+ }
195
+ % elif property.keyword:
196
+ pub use self::computed_value::T as SpecifiedValue;
197
+ pub mod computed_value {
198
+ #[allow(unused_imports)]
199
+ use crate::derives::*;
200
+ #[derive(
201
+ Clone,
202
+ Copy,
203
+ Debug,
204
+ Deserialize,
205
+ Eq,
206
+ FromPrimitive,
207
+ Hash,
208
+ MallocSizeOf,
209
+ Parse,
210
+ PartialEq,
211
+ Serialize,
212
+ SpecifiedValueInfo,
213
+ ToAnimatedValue,
214
+ ToComputedValue,
215
+ ToCss,
216
+ ToResolvedValue,
217
+ ToShmem,
218
+ ToTyped,
219
+ )]
220
+ pub enum T {
221
+ % for variant in property.keyword.values_for(engine):
222
+ <%
223
+ aliases = []
224
+ for alias, v in property.keyword.aliases_for(engine).items():
225
+ if variant == v:
226
+ aliases.append(alias)
227
+ %>
228
+ % if aliases:
229
+ #[parse(aliases = "${','.join(sorted(aliases))}")]
230
+ % endif
231
+ ${to_camel_case(variant)},
232
+ % endfor
233
+ }
234
+ }
235
+ #[inline]
236
+ pub fn get_initial_value() -> computed_value::T {
237
+ computed_value::T::${to_camel_case(property.keyword.values[0])}
238
+ }
239
+ #[inline]
240
+ pub fn get_initial_specified_value() -> SpecifiedValue {
241
+ SpecifiedValue::${to_camel_case(property.keyword.values[0])}
242
+ }
243
+ #[inline]
244
+ pub fn parse(_context: &ParserContext, input: &mut Parser)
245
+ -> Result<SpecifiedValue, ParseError> {
246
+ SpecifiedValue::parse(input)
247
+ }
248
+
249
+ #[cfg(feature = "gecko")]
250
+ impl SpecifiedValue {
251
+ /// Obtain a specified value from a Gecko keyword value
252
+ ///
253
+ /// Intended for use with presentation attributes, not style structs
254
+ pub fn from_gecko_keyword(kw: u32) -> Self {
255
+ use crate::gecko_bindings::structs;
256
+ % for value in property.keyword.values_for(engine):
257
+ // We can't match on enum values if we're matching on a u32
258
+ const ${to_rust_ident(value).upper()}: u32 = structs::${property.keyword.gecko_constant(value)} as u32;
259
+ % endfor
260
+ match kw {
261
+ % for value in property.keyword.values_for(engine):
262
+ ${to_rust_ident(value).upper()} => Self::${to_camel_case(value)},
263
+ % endfor
264
+ _ => panic!("Found unexpected value in style struct for ${property.name} property"),
265
+ }
266
+ }
267
+ }
268
+ % endif
269
+ % if property.vector:
270
+ } // single_value
271
+ % endif
272
+
273
+ // The setup here is roughly:
274
+ //
275
+ // * UnderlyingList is the list that is stored in the computed value. This may
276
+ // be a shared ArcSlice if the property is inherited.
277
+ // * UnderlyingOwnedList is the list that is used for animation.
278
+ // * Specified values always use OwnedSlice, since it's more compact.
279
+ // * computed_value::List is just a convenient alias that you can use for the
280
+ // computed value list, since this is in the computed_value module.
281
+ //
282
+ // If vector.simple_bindings is true, then we don't use the complex iterator
283
+ // machinery and set_foo_from, and just compute the value like any other
284
+ // longhand.
285
+ % if property.vector:
286
+ <% allow_empty = not property.initial_value and not property.keyword %>
287
+ #[allow(unused_imports)]
288
+ use smallvec::SmallVec;
289
+
290
+ /// The definition of the computed value for ${property.name}.
291
+ pub mod computed_value {
292
+ #[allow(unused_imports)]
293
+ use crate::values::animated::ToAnimatedValue;
294
+ #[allow(unused_imports)]
295
+ use crate::values::resolved::ToResolvedValue;
296
+ #[allow(unused_imports)]
297
+ use crate::derives::*;
298
+ pub use super::single_value::computed_value as single_value;
299
+ pub use self::single_value::T as SingleComputedValue;
300
+ % if not allow_empty:
301
+ use smallvec::SmallVec;
302
+ % endif
303
+ use crate::values::computed::ComputedVecIter;
304
+
305
+ <% is_shared_list = allow_empty and property.style_struct.inherited %>
306
+
307
+ // FIXME(emilio): Add an OwnedNonEmptySlice type, and figure out
308
+ // something for transition-name, which is the only remaining user
309
+ // of NotInitial.
310
+ pub type UnderlyingList<T> =
311
+ % if allow_empty:
312
+ % if property.style_struct.inherited:
313
+ crate::ArcSlice<T>;
314
+ % else:
315
+ crate::OwnedSlice<T>;
316
+ % endif
317
+ % else:
318
+ SmallVec<[T; 1]>;
319
+ % endif
320
+
321
+ pub type UnderlyingOwnedList<T> =
322
+ % if allow_empty:
323
+ crate::OwnedSlice<T>;
324
+ % else:
325
+ SmallVec<[T; 1]>;
326
+ % endif
327
+
328
+
329
+ /// The generic type defining the animated and resolved values for
330
+ /// this property.
331
+ ///
332
+ /// Making this type generic allows the compiler to figure out the
333
+ /// animated value for us, instead of having to implement it
334
+ /// manually for every type we care about.
335
+ #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToAnimatedValue, ToResolvedValue, ToCss, ToTyped)]
336
+ % if property.vector.separator == "Comma":
337
+ #[css(comma)]
338
+ % endif
339
+ pub struct OwnedList<T>(
340
+ % if not allow_empty:
341
+ #[css(iterable)]
342
+ % else:
343
+ #[css(if_empty = "none", iterable)]
344
+ % endif
345
+ pub UnderlyingOwnedList<T>,
346
+ );
347
+
348
+ /// The computed value for this property.
349
+ % if not is_shared_list:
350
+ pub type ComputedList = OwnedList<single_value::T>;
351
+ pub use self::OwnedList as List;
352
+ % else:
353
+ pub use self::ComputedList as List;
354
+
355
+ #[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss, ToTyped)]
356
+ % if property.vector.separator == "Comma":
357
+ #[css(comma)]
358
+ % endif
359
+ pub struct ComputedList(
360
+ % if not allow_empty:
361
+ #[css(iterable)]
362
+ % else:
363
+ #[css(if_empty = "none", iterable)]
364
+ % endif
365
+ % if is_shared_list:
366
+ #[ignore_malloc_size_of = "Arc"]
367
+ % endif
368
+ pub UnderlyingList<single_value::T>,
369
+ );
370
+
371
+ type ResolvedList = <OwnedList<single_value::T> as ToResolvedValue>::ResolvedValue;
372
+ impl ToResolvedValue for ComputedList {
373
+ type ResolvedValue = ResolvedList;
374
+
375
+ fn to_resolved_value(self, context: &crate::values::resolved::Context) -> Self::ResolvedValue {
376
+ OwnedList(
377
+ self.0
378
+ .iter()
379
+ .cloned()
380
+ .map(|v| v.to_resolved_value(context))
381
+ .collect()
382
+ )
383
+ }
384
+
385
+ fn from_resolved_value(resolved: Self::ResolvedValue) -> Self {
386
+ % if not is_shared_list:
387
+ use std::iter::FromIterator;
388
+ % endif
389
+ let iter =
390
+ resolved.0.into_iter().map(ToResolvedValue::from_resolved_value);
391
+ ComputedList(UnderlyingList::from_iter(iter))
392
+ }
393
+ }
394
+ % endif
395
+
396
+ % if property.vector.simple_bindings:
397
+ impl From<ComputedList> for UnderlyingList<single_value::T> {
398
+ #[inline]
399
+ fn from(l: ComputedList) -> Self {
400
+ l.0
401
+ }
402
+ }
403
+ impl From<UnderlyingList<single_value::T>> for ComputedList {
404
+ #[inline]
405
+ fn from(l: UnderlyingList<single_value::T>) -> Self {
406
+ List(l)
407
+ }
408
+ }
409
+ % endif
410
+
411
+ % if property.vector.animation_type:
412
+ use crate::values::animated::{Animate, ToAnimatedZero, Procedure, lists};
413
+ use crate::values::distance::{SquaredDistance, ComputeSquaredDistance};
414
+
415
+ // FIXME(emilio): For some reason rust thinks that this alias is
416
+ // unused, even though it's clearly used below?
417
+ #[allow(unused)]
418
+ type AnimatedList = <OwnedList<single_value::T> as ToAnimatedValue>::AnimatedValue;
419
+ % if is_shared_list:
420
+ impl ToAnimatedValue for ComputedList {
421
+ type AnimatedValue = AnimatedList;
422
+
423
+ fn to_animated_value(self, context: &crate::values::animated::Context) -> Self::AnimatedValue {
424
+ OwnedList(
425
+ self.0.iter().map(|v| v.clone().to_animated_value(context)).collect()
426
+ )
427
+ }
428
+
429
+ fn from_animated_value(animated: Self::AnimatedValue) -> Self {
430
+ let iter =
431
+ animated.0.into_iter().map(ToAnimatedValue::from_animated_value);
432
+ ComputedList(UnderlyingList::from_iter(iter))
433
+ }
434
+ }
435
+ % endif
436
+
437
+ impl ToAnimatedZero for AnimatedList {
438
+ fn to_animated_zero(&self) -> Result<Self, ()> { Err(()) }
439
+ }
440
+
441
+ impl Animate for AnimatedList {
442
+ fn animate(
443
+ &self,
444
+ other: &Self,
445
+ procedure: Procedure,
446
+ ) -> Result<Self, ()> {
447
+ Ok(OwnedList(
448
+ lists::${property.vector.animation_type}::animate(&self.0, &other.0, procedure)?
449
+ ))
450
+ }
451
+ }
452
+ impl ComputeSquaredDistance for AnimatedList {
453
+ fn compute_squared_distance(
454
+ &self,
455
+ other: &Self,
456
+ ) -> Result<SquaredDistance, ()> {
457
+ lists::${property.vector.animation_type}::squared_distance(&self.0, &other.0)
458
+ }
459
+ }
460
+ % endif
461
+
462
+ /// The computed value, effectively a list of single values.
463
+ pub use self::ComputedList as T;
464
+
465
+ pub type Iter<'a, 'cx, 'cx_a> = ComputedVecIter<'a, 'cx, 'cx_a, super::single_value::SpecifiedValue>;
466
+ }
467
+
468
+ /// The specified value of ${property.name}.
469
+ #[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem, ToTyped)]
470
+ % if property.vector.none_value:
471
+ #[value_info(other_values = "none")]
472
+ % endif
473
+ % if property.vector.separator == "Comma":
474
+ #[css(comma)]
475
+ % endif
476
+ pub struct SpecifiedValue(
477
+ % if not allow_empty:
478
+ #[css(iterable)]
479
+ % else:
480
+ #[css(if_empty = "none", iterable)]
481
+ % endif
482
+ pub crate::OwnedSlice<single_value::SpecifiedValue>,
483
+ );
484
+
485
+ pub fn get_initial_value() -> computed_value::T {
486
+ % if allow_empty:
487
+ computed_value::List(Default::default())
488
+ % else:
489
+ let mut v = SmallVec::new();
490
+ v.push(single_value::get_initial_value());
491
+ computed_value::List(v)
492
+ % endif
493
+ }
494
+
495
+ pub fn parse(
496
+ context: &ParserContext,
497
+ input: &mut Parser,
498
+ ) -> Result<SpecifiedValue, ParseError> {
499
+ use style_traits::Separator;
500
+
501
+ % if allow_empty or property.vector.none_value:
502
+ if input.try_parse(|input| input.expect_ident_matching("none")).is_ok() {
503
+ % if allow_empty:
504
+ return Ok(SpecifiedValue(Default::default()))
505
+ % else:
506
+ return Ok(SpecifiedValue(crate::OwnedSlice::from(vec![${property.vector.none_value}])))
507
+ % endif
508
+ }
509
+ % endif
510
+
511
+ let v = style_traits::${property.vector.separator}::parse(input, |parser| {
512
+ single_value::parse(context, parser)
513
+ })?;
514
+ Ok(SpecifiedValue(v.into()))
515
+ }
516
+
517
+ pub use self::single_value::SpecifiedValue as SingleSpecifiedValue;
518
+
519
+ % if not property.vector.simple_bindings and engine == "gecko":
520
+ impl SpecifiedValue {
521
+ fn compute_iter<'a, 'cx, 'cx_a>(
522
+ &'a self,
523
+ context: &'cx computed::Context<'cx_a>,
524
+ ) -> computed_value::Iter<'a, 'cx, 'cx_a> {
525
+ computed_value::Iter::new(context, &self.0)
526
+ }
527
+ }
528
+ % endif
529
+
530
+ impl ToComputedValue for SpecifiedValue {
531
+ type ComputedValue = computed_value::T;
532
+
533
+ #[inline]
534
+ fn to_computed_value(&self, context: &computed::Context) -> computed_value::T {
535
+ % if not is_shared_list:
536
+ use std::iter::FromIterator;
537
+ % endif
538
+ computed_value::List(computed_value::UnderlyingList::from_iter(
539
+ self.0.iter().map(|i| i.to_computed_value(context))
540
+ ))
541
+ }
542
+
543
+ #[inline]
544
+ fn from_computed_value(computed: &computed_value::T) -> Self {
545
+ let iter = computed.0.iter().map(ToComputedValue::from_computed_value);
546
+ SpecifiedValue(iter.collect())
547
+ }
548
+ }
549
+ % endif
550
+ }
551
+ </%def>
552
+
553
+ <%def name="shorthand(shorthand)">
554
+ /// ${shorthand.spec}
555
+ pub mod ${shorthand.ident} {
556
+ #[allow(unused_imports)]
557
+ use crate::derives::*;
558
+ use crate::parser::ParserContext;
559
+ use crate::properties::{PropertyDeclaration, SourcePropertyDeclaration, longhands};
560
+ use cssparser::Parser;
561
+ #[allow(unused_imports)]
562
+ use std::fmt::{self, Write};
563
+ use style_traits::{CssWriter, ToCss, ParseError};
564
+
565
+ % if shorthand.derive_value_info:
566
+ #[derive(SpecifiedValueInfo)]
567
+ % endif
568
+ pub struct Longhands {
569
+ % for sub_property in shorthand.sub_properties:
570
+ pub ${sub_property.ident}:
571
+ % if sub_property.boxed:
572
+ Box<
573
+ % endif
574
+ longhands::${sub_property.ident}::SpecifiedValue
575
+ % if sub_property.boxed:
576
+ >
577
+ % endif
578
+ ,
579
+ % endfor
580
+ }
581
+
582
+ /// Represents a serializable set of all of the longhand properties that
583
+ /// correspond to a shorthand.
584
+ % if shorthand.derive_serialize:
585
+ #[derive(ToCss)]
586
+ % endif
587
+ pub struct LonghandsToSerialize<'a> {
588
+ % for sub_property in shorthand.sub_properties:
589
+ pub ${sub_property.ident}:
590
+ % if sub_property.may_be_disabled_in(shorthand, engine):
591
+ Option<
592
+ % endif
593
+ &'a longhands::${sub_property.ident}::SpecifiedValue,
594
+ % if sub_property.may_be_disabled_in(shorthand, engine):
595
+ >,
596
+ % endif
597
+ % endfor
598
+ }
599
+
600
+ impl<'a> LonghandsToSerialize<'a> {
601
+ /// Tries to get a serializable set of longhands given a set of
602
+ /// property declarations.
603
+ pub fn from_iter(iter: impl Iterator<Item = &'a PropertyDeclaration>) -> Result<Self, ()> {
604
+ // Define all of the expected variables that correspond to the shorthand
605
+ % for sub_property in shorthand.sub_properties:
606
+ let mut ${sub_property.ident} =
607
+ None::<&'a longhands::${sub_property.ident}::SpecifiedValue>;
608
+ % endfor
609
+
610
+ // Attempt to assign the incoming declarations to the expected variables
611
+ for declaration in iter {
612
+ match *declaration {
613
+ % for sub_property in shorthand.sub_properties:
614
+ PropertyDeclaration::${sub_property.camel_case}(ref value) => {
615
+ ${sub_property.ident} = Some(value)
616
+ },
617
+ % endfor
618
+ _ => {}
619
+ };
620
+ }
621
+
622
+ // If any of the expected variables are missing, return an error
623
+ match (
624
+ % for sub_property in shorthand.sub_properties:
625
+ ${sub_property.ident},
626
+ % endfor
627
+ ) {
628
+
629
+ (
630
+ % for sub_property in shorthand.sub_properties:
631
+ % if sub_property.may_be_disabled_in(shorthand, engine):
632
+ ${sub_property.ident},
633
+ % else:
634
+ Some(${sub_property.ident}),
635
+ % endif
636
+ % endfor
637
+ ) =>
638
+ Ok(LonghandsToSerialize {
639
+ % for sub_property in shorthand.sub_properties:
640
+ ${sub_property.ident},
641
+ % endfor
642
+ }),
643
+ _ => Err(())
644
+ }
645
+ }
646
+ }
647
+
648
+ /// Parse the given shorthand and fill the result into the
649
+ /// `declarations` vector.
650
+ pub fn parse_into(
651
+ declarations: &mut SourcePropertyDeclaration,
652
+ context: &ParserContext,
653
+ input: &mut Parser,
654
+ ) -> Result<(), ParseError> {
655
+ #[allow(unused_imports)]
656
+ use crate::properties::{NonCustomPropertyId, LonghandId};
657
+ % if not shorthand.kind and "IS_LEGACY_SHORTHAND" not in shorthand.flags:
658
+ use crate::properties::shorthands::${shorthand.ident}::parse_value;
659
+ % endif
660
+ input.parse_entirely(|input| parse_value(context, input)).map(|longhands| {
661
+ % for sub_property in shorthand.sub_properties:
662
+ % if sub_property.may_be_disabled_in(shorthand, engine):
663
+ if NonCustomPropertyId::from(LonghandId::${sub_property.camel_case})
664
+ .allowed_in_ignoring_rule_type(context) {
665
+ % endif
666
+ declarations.push(PropertyDeclaration::${sub_property.camel_case}(
667
+ longhands.${sub_property.ident}
668
+ ));
669
+ % if sub_property.may_be_disabled_in(shorthand, engine):
670
+ }
671
+ % endif
672
+ % endfor
673
+ })
674
+ }
675
+
676
+ /// Try to serialize a given shorthand to a string.
677
+ pub fn to_css(declarations: &[&PropertyDeclaration], dest: &mut style_traits::CssStringWriter) -> fmt::Result {
678
+ match LonghandsToSerialize::from_iter(declarations.iter().cloned()) {
679
+ Ok(longhands) => longhands.to_css(&mut CssWriter::new(dest)),
680
+ Err(_) => Ok(())
681
+ }
682
+ }
683
+ % if shorthand.kind == "two_properties":
684
+ ${self.two_properties_shorthand(shorthand)}
685
+ % endif
686
+ % if shorthand.kind == "four_sides":
687
+ ${self.four_sides_shorthand(shorthand)}
688
+ % endif
689
+ % if shorthand.kind == "single_border":
690
+ ${self.single_border_shorthand(shorthand)}
691
+ % endif
692
+ % if "IS_LEGACY_SHORTHAND" in shorthand.flags:
693
+ ${self.legacy_shorthand(shorthand)}
694
+ % endif
695
+ }
696
+ </%def>
697
+
698
+ // A shorthand of kind `<property-1> <property-2>?` where both properties have
699
+ // the same type.
700
+ <%def name="two_properties_shorthand(shorthand)">
701
+ type Single = crate::properties::longhands::${shorthand.sub_properties[0].ident}::SpecifiedValue;
702
+
703
+ fn parse_value(
704
+ context: &ParserContext,
705
+ input: &mut Parser,
706
+ ) -> Result<Longhands, ParseError> {
707
+ let first = <Single as crate::parser::Parse>::parse(context, input)?;
708
+ let second =
709
+ input.try_parse(|input| <Single as crate::parser::Parse>::parse(context, input)).unwrap_or_else(|_| first.clone());
710
+ Ok(crate::properties::shorthands::expanded! {
711
+ ${shorthand.sub_properties[0].ident}: first,
712
+ ${shorthand.sub_properties[1].ident}: second,
713
+ })
714
+ }
715
+
716
+ impl<'a> ToCss for LonghandsToSerialize<'a> {
717
+ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
718
+ let first = &self.${shorthand.sub_properties[0].ident};
719
+ let second = &self.${shorthand.sub_properties[1].ident};
720
+
721
+ first.to_css(dest)?;
722
+ if first != second {
723
+ dest.write_char(' ')?;
724
+ second.to_css(dest)?;
725
+ }
726
+ Ok(())
727
+ }
728
+ }
729
+ </%def>
730
+
731
+ <%def name="four_sides_shorthand(shorthand)">
732
+ use crate::values::generics::rect::Rect;
733
+
734
+ type Single = crate::properties::longhands::${shorthand.sub_properties[0].ident}::SpecifiedValue;
735
+ fn parse_value(
736
+ context: &ParserContext,
737
+ input: &mut Parser,
738
+ ) -> Result<Longhands, ParseError> {
739
+ let rect = Rect::parse_with(context, input, |c, i| -> Result<Single, ParseError > {
740
+ % if shorthand.allow_quirks:
741
+ Single::parse_quirky(c, i, crate::values::specified::AllowQuirks::Yes)
742
+ % else:
743
+ <Single as crate::parser::Parse>::parse(c, i)
744
+ % endif
745
+ })?;
746
+ Ok(crate::properties::shorthands::expanded! {
747
+ % for index in range(4):
748
+ ${shorthand.sub_properties[index].ident}: rect.${index},
749
+ % endfor
750
+ })
751
+ }
752
+
753
+ impl<'a> ToCss for LonghandsToSerialize<'a> {
754
+ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
755
+ where
756
+ W: fmt::Write,
757
+ {
758
+ let rect = Rect::new(
759
+ % for index in range(4):
760
+ &self.${shorthand.sub_properties[index].ident},
761
+ % endfor
762
+ );
763
+ rect.to_css(dest)
764
+ }
765
+ }
766
+ </%def>
767
+
768
+ <%def name="single_border_shorthand(shorthand)">
769
+ fn parse_value(
770
+ context: &ParserContext,
771
+ input: &mut Parser,
772
+ ) -> Result<Longhands, ParseError> {
773
+ let (width, style, color) = crate::properties::shorthands::parse_border(context, input)?;
774
+ Ok(crate::properties::shorthands::expanded! {
775
+ ${shorthand.sub_properties[0].ident}: width,
776
+ ${shorthand.sub_properties[1].ident}: style,
777
+ ${shorthand.sub_properties[2].ident}: color,
778
+ })
779
+ }
780
+
781
+ impl<'a> ToCss for LonghandsToSerialize<'a> {
782
+ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
783
+ crate::properties::shorthands::serialize_directional_border(
784
+ dest,
785
+ % for i in range(3):
786
+ self.${shorthand.sub_properties[i].ident},
787
+ % endfor
788
+ )
789
+ }
790
+ }
791
+ </%def>
792
+
793
+ <%def name="legacy_shorthand(shorthand)">
794
+ type Value = crate::properties::longhands::${shorthand.sub_properties[0].ident}::SpecifiedValue;
795
+ fn parse_value(
796
+ context: &ParserContext,
797
+ input: &mut Parser,
798
+ ) -> Result<Longhands, ParseError> {
799
+ let v = Value::parse_legacy(context, input)?;
800
+ Ok(crate::properties::shorthands::expanded! {
801
+ ${shorthand.sub_properties[0].ident}: v,
802
+ })
803
+ }
804
+
805
+ % if not shorthand.derive_serialize:
806
+ impl<'a> ToCss for LonghandsToSerialize<'a> {
807
+ fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result where W: fmt::Write {
808
+ self.${shorthand.sub_properties[0].ident}.to_css_legacy(dest)
809
+ }
810
+ }
811
+ % endif
812
+ </%def>