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.
- package/LICENSE +21 -0
- package/README.md +355 -2
- package/THIRD_PARTY_NOTICES.md +25 -0
- package/assets/icon.svg +4 -0
- package/dist/api.d.ts +7 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +46 -0
- package/dist/api.js.map +1 -0
- package/dist/assets.d.ts +7 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +52 -0
- package/dist/assets.js.map +1 -0
- package/dist/browser.d.ts +3 -0
- package/dist/browser.d.ts.map +1 -0
- package/dist/browser.js +3 -0
- package/dist/browser.js.map +1 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +10 -0
- package/dist/node.js.map +1 -0
- package/dist/options.d.ts +24 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +135 -0
- package/dist/options.js.map +1 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/examples/bun.ts +8 -0
- package/examples/german-invoice/README.md +70 -0
- package/examples/german-invoice/data.mjs +83 -0
- package/examples/german-invoice/invoice.css +59 -0
- package/examples/german-invoice/template.mjs +49 -0
- package/examples/german-invoice.mjs +20 -0
- package/examples/invoice.html +29 -0
- package/examples/node.mjs +8 -0
- package/examples/pagination.html +40 -0
- package/examples/pagination.mjs +8 -0
- package/licenses/DejaVu.txt +187 -0
- package/licenses/RUST_DEPENDENCIES.txt +11577 -0
- package/package.json +89 -4
- package/src/api.ts +44 -0
- package/src/assets.ts +43 -0
- package/src/browser.ts +6 -0
- package/src/node.ts +12 -0
- package/src/options.ts +101 -0
- package/src/types.ts +49 -0
- package/vendor/README.md +17 -0
- package/vendor/stylo/.cargo-ok +1 -0
- package/vendor/stylo/.cargo_vcs_info.json +6 -0
- package/vendor/stylo/Cargo.lock +1485 -0
- package/vendor/stylo/Cargo.toml +274 -0
- package/vendor/stylo/LICENSE +373 -0
- package/vendor/stylo/README.md +6 -0
- package/vendor/stylo/applicable_declarations.rs +328 -0
- package/vendor/stylo/author_styles.rs +79 -0
- package/vendor/stylo/bezier.rs +176 -0
- package/vendor/stylo/bloom.rs +414 -0
- package/vendor/stylo/build.rs +91 -0
- package/vendor/stylo/build_gecko.rs +393 -0
- package/vendor/stylo/color/color_function.rs +601 -0
- package/vendor/stylo/color/component.rs +207 -0
- package/vendor/stylo/color/convert.rs +935 -0
- package/vendor/stylo/color/gamut/raytrace.rs +265 -0
- package/vendor/stylo/color/gamut.rs +227 -0
- package/vendor/stylo/color/mix.rs +645 -0
- package/vendor/stylo/color/mod.rs +750 -0
- package/vendor/stylo/color/parsing.rs +770 -0
- package/vendor/stylo/color/to_css.rs +297 -0
- package/vendor/stylo/context.rs +716 -0
- package/vendor/stylo/counter_style/mod.rs +754 -0
- package/vendor/stylo/counter_style/predefined.rs +61 -0
- package/vendor/stylo/counter_style/update_predefined.py +35 -0
- package/vendor/stylo/custom_properties.rs +2023 -0
- package/vendor/stylo/custom_properties_map.rs +220 -0
- package/vendor/stylo/data.rs +693 -0
- package/vendor/stylo/device/gecko.rs +486 -0
- package/vendor/stylo/device/mod.rs +304 -0
- package/vendor/stylo/device/servo.rs +507 -0
- package/vendor/stylo/dom.rs +1164 -0
- package/vendor/stylo/dom_apis.rs +937 -0
- package/vendor/stylo/driver.rs +172 -0
- package/vendor/stylo/error_reporting.rs +484 -0
- package/vendor/stylo/font_face.rs +558 -0
- package/vendor/stylo/font_metrics.rs +124 -0
- package/vendor/stylo/gecko/anon_boxes.toml +113 -0
- package/vendor/stylo/gecko/arc_types.rs +211 -0
- package/vendor/stylo/gecko/conversions.rs +59 -0
- package/vendor/stylo/gecko/data.rs +222 -0
- package/vendor/stylo/gecko/media_features.rs +971 -0
- package/vendor/stylo/gecko/mod.rs +20 -0
- package/vendor/stylo/gecko/non_ts_pseudo_class_list.rs +119 -0
- package/vendor/stylo/gecko/pseudo_element.rs +640 -0
- package/vendor/stylo/gecko/pseudo_element_definition.mako.rs +298 -0
- package/vendor/stylo/gecko/pseudo_elements.py +137 -0
- package/vendor/stylo/gecko/pseudo_elements.toml +197 -0
- package/vendor/stylo/gecko/regen_pseudo_elements.py +33 -0
- package/vendor/stylo/gecko/restyle_damage.rs +127 -0
- package/vendor/stylo/gecko/selector_parser.rs +627 -0
- package/vendor/stylo/gecko/snapshot.rs +202 -0
- package/vendor/stylo/gecko/snapshot_helpers.rs +334 -0
- package/vendor/stylo/gecko/traversal.rs +52 -0
- package/vendor/stylo/gecko/wrapper.rs +2258 -0
- package/vendor/stylo/gecko_bindings/mod.rs +34 -0
- package/vendor/stylo/gecko_bindings/sugar/mod.rs +12 -0
- package/vendor/stylo/gecko_bindings/sugar/ns_com_ptr.rs +15 -0
- package/vendor/stylo/gecko_bindings/sugar/ns_compatibility.rs +19 -0
- package/vendor/stylo/gecko_bindings/sugar/ns_style_auto_array.rs +111 -0
- package/vendor/stylo/gecko_bindings/sugar/origin_flags.rs +31 -0
- package/vendor/stylo/gecko_bindings/sugar/ownership.rs +70 -0
- package/vendor/stylo/gecko_bindings/sugar/refptr.rs +299 -0
- package/vendor/stylo/gecko_string_cache/mod.rs +543 -0
- package/vendor/stylo/gecko_string_cache/namespace.rs +106 -0
- package/vendor/stylo/global_style_data.rs +224 -0
- package/vendor/stylo/invalidation/element/document_state.rs +156 -0
- package/vendor/stylo/invalidation/element/element_wrapper.rs +432 -0
- package/vendor/stylo/invalidation/element/invalidation_map.rs +1631 -0
- package/vendor/stylo/invalidation/element/invalidator.rs +1470 -0
- package/vendor/stylo/invalidation/element/mod.rs +13 -0
- package/vendor/stylo/invalidation/element/relative_selector.rs +1399 -0
- package/vendor/stylo/invalidation/element/restyle_hints.rs +226 -0
- package/vendor/stylo/invalidation/element/state_and_attributes.rs +756 -0
- package/vendor/stylo/invalidation/media_queries.rs +144 -0
- package/vendor/stylo/invalidation/mod.rs +10 -0
- package/vendor/stylo/invalidation/stylesheets.rs +745 -0
- package/vendor/stylo/invalidation/viewport_units.rs +71 -0
- package/vendor/stylo/lib.rs +336 -0
- package/vendor/stylo/logical_geometry.rs +1684 -0
- package/vendor/stylo/macros.rs +70 -0
- package/vendor/stylo/matching.rs +1226 -0
- package/vendor/stylo/media_queries/media_list.rs +168 -0
- package/vendor/stylo/media_queries/media_query.rs +190 -0
- package/vendor/stylo/media_queries/mod.rs +13 -0
- package/vendor/stylo/parallel.rs +205 -0
- package/vendor/stylo/parser.rs +276 -0
- package/vendor/stylo/piecewise_linear.rs +282 -0
- package/vendor/stylo/prefs.rs +33 -0
- package/vendor/stylo/properties/build.py +119 -0
- package/vendor/stylo/properties/cascade.rs +2704 -0
- package/vendor/stylo/properties/computed_value_flags.rs +206 -0
- package/vendor/stylo/properties/counted_unknown_properties.py +104 -0
- package/vendor/stylo/properties/counter_style_descriptors.toml +45 -0
- package/vendor/stylo/properties/data.py +1375 -0
- package/vendor/stylo/properties/declaration_block.rs +1788 -0
- package/vendor/stylo/properties/font_face_descriptors.toml +50 -0
- package/vendor/stylo/properties/gecko.mako.rs +1555 -0
- package/vendor/stylo/properties/helpers/animated_properties.mako.rs +800 -0
- package/vendor/stylo/properties/helpers.mako.rs +812 -0
- package/vendor/stylo/properties/longhands.toml +4305 -0
- package/vendor/stylo/properties/mod.rs +1857 -0
- package/vendor/stylo/properties/properties.html.mako +31 -0
- package/vendor/stylo/properties/properties.mako.rs +3103 -0
- package/vendor/stylo/properties/property_descriptors.toml +18 -0
- package/vendor/stylo/properties/shorthands.rs +4241 -0
- package/vendor/stylo/properties/shorthands.toml +575 -0
- package/vendor/stylo/properties/vendored_python/mako-1.3.10-py3-none-any.whl +0 -0
- package/vendor/stylo/properties/vendored_python/markupsafe/LICENSE.txt +28 -0
- package/vendor/stylo/properties/vendored_python/markupsafe/__init__.py +384 -0
- package/vendor/stylo/properties/vendored_python/toml-0.10.2-py2.py3-none-any.whl +0 -0
- package/vendor/stylo/properties/view_transition_descriptors.toml +11 -0
- package/vendor/stylo/properties_and_values/mod.rs +12 -0
- package/vendor/stylo/properties_and_values/registry.rs +65 -0
- package/vendor/stylo/properties_and_values/rule.rs +331 -0
- package/vendor/stylo/properties_and_values/syntax/ascii.rs +60 -0
- package/vendor/stylo/properties_and_values/syntax/data_type.rs +146 -0
- package/vendor/stylo/properties_and_values/syntax/mod.rs +437 -0
- package/vendor/stylo/properties_and_values/value.rs +758 -0
- package/vendor/stylo/queries/condition.rs +996 -0
- package/vendor/stylo/queries/feature.rs +199 -0
- package/vendor/stylo/queries/feature_expression.rs +1170 -0
- package/vendor/stylo/queries/mod.rs +19 -0
- package/vendor/stylo/queries/values.rs +46 -0
- package/vendor/stylo/rule_cache.rs +267 -0
- package/vendor/stylo/rule_collector.rs +554 -0
- package/vendor/stylo/rule_tree/core.rs +787 -0
- package/vendor/stylo/rule_tree/level.rs +396 -0
- package/vendor/stylo/rule_tree/map.rs +201 -0
- package/vendor/stylo/rule_tree/mod.rs +427 -0
- package/vendor/stylo/rule_tree/source.rs +80 -0
- package/vendor/stylo/rule_tree/unsafe_box.rs +78 -0
- package/vendor/stylo/scoped_tls.rs +80 -0
- package/vendor/stylo/selector_map.rs +1050 -0
- package/vendor/stylo/selector_parser.rs +305 -0
- package/vendor/stylo/servo/animation.rs +1922 -0
- package/vendor/stylo/servo/attr.rs +714 -0
- package/vendor/stylo/servo/encoding_support.rs +81 -0
- package/vendor/stylo/servo/media_features.rs +254 -0
- package/vendor/stylo/servo/mod.rs +16 -0
- package/vendor/stylo/servo/restyle_damage.rs +215 -0
- package/vendor/stylo/servo/selector_parser.rs +1036 -0
- package/vendor/stylo/servo/shadow_parts.rs +207 -0
- package/vendor/stylo/shared_lock.rs +271 -0
- package/vendor/stylo/sharing/checks.rs +281 -0
- package/vendor/stylo/sharing/mod.rs +1000 -0
- package/vendor/stylo/simple_buckets_map.rs +52 -0
- package/vendor/stylo/str.rs +168 -0
- package/vendor/stylo/style_adjuster.rs +1086 -0
- package/vendor/stylo/style_resolver.rs +658 -0
- package/vendor/stylo/stylesheet_set.rs +658 -0
- package/vendor/stylo/stylesheets/appearance_base_rule.rs +51 -0
- package/vendor/stylo/stylesheets/container_rule.rs +769 -0
- package/vendor/stylo/stylesheets/counter_style_rule.rs +7 -0
- package/vendor/stylo/stylesheets/document_rule.rs +272 -0
- package/vendor/stylo/stylesheets/font_face_rule.rs +7 -0
- package/vendor/stylo/stylesheets/font_feature_values_rule.rs +481 -0
- package/vendor/stylo/stylesheets/font_palette_values_rule.rs +304 -0
- package/vendor/stylo/stylesheets/import_rule.rs +259 -0
- package/vendor/stylo/stylesheets/keyframes_rule.rs +733 -0
- package/vendor/stylo/stylesheets/layer_rule.rs +221 -0
- package/vendor/stylo/stylesheets/loader.rs +29 -0
- package/vendor/stylo/stylesheets/margin_rule.rs +190 -0
- package/vendor/stylo/stylesheets/media_rule.rs +191 -0
- package/vendor/stylo/stylesheets/mod.rs +918 -0
- package/vendor/stylo/stylesheets/namespace_rule.rs +43 -0
- package/vendor/stylo/stylesheets/nested_declarations_rule.rs +51 -0
- package/vendor/stylo/stylesheets/origin.rs +249 -0
- package/vendor/stylo/stylesheets/page_rule.rs +354 -0
- package/vendor/stylo/stylesheets/position_try_rule.rs +68 -0
- package/vendor/stylo/stylesheets/property_rule.rs +5 -0
- package/vendor/stylo/stylesheets/rule_list.rs +167 -0
- package/vendor/stylo/stylesheets/rule_parser.rs +1189 -0
- package/vendor/stylo/stylesheets/rules_iterator.rs +397 -0
- package/vendor/stylo/stylesheets/scope_rule.rs +511 -0
- package/vendor/stylo/stylesheets/starting_style_rule.rs +54 -0
- package/vendor/stylo/stylesheets/style_rule.rs +80 -0
- package/vendor/stylo/stylesheets/stylesheet.rs +570 -0
- package/vendor/stylo/stylesheets/supports_rule.rs +486 -0
- package/vendor/stylo/stylesheets/view_transition_rule.rs +81 -0
- package/vendor/stylo/stylist.rs +5076 -0
- package/vendor/stylo/thread_state.rs +87 -0
- package/vendor/stylo/traversal.rs +765 -0
- package/vendor/stylo/traversal_flags.rs +68 -0
- package/vendor/stylo/typed_om/mod.rs +981 -0
- package/vendor/stylo/typed_om/numeric.rs +128 -0
- package/vendor/stylo/typed_om/numeric_declaration.rs +93 -0
- package/vendor/stylo/typed_om/numeric_type.rs +640 -0
- package/vendor/stylo/typed_om/sum_value.rs +426 -0
- package/vendor/stylo/url/gecko.rs +367 -0
- package/vendor/stylo/url/mod.rs +71 -0
- package/vendor/stylo/url/servo.rs +239 -0
- package/vendor/stylo/use_counters/mod.rs +137 -0
- package/vendor/stylo/values/animated/color.rs +103 -0
- package/vendor/stylo/values/animated/effects.rs +26 -0
- package/vendor/stylo/values/animated/font.rs +37 -0
- package/vendor/stylo/values/animated/grid.rs +161 -0
- package/vendor/stylo/values/animated/lists.rs +141 -0
- package/vendor/stylo/values/animated/mod.rs +550 -0
- package/vendor/stylo/values/animated/svg.rs +46 -0
- package/vendor/stylo/values/animated/text.rs +58 -0
- package/vendor/stylo/values/animated/transform.rs +1592 -0
- package/vendor/stylo/values/computed/align.rs +90 -0
- package/vendor/stylo/values/computed/angle.rs +130 -0
- package/vendor/stylo/values/computed/animation.rs +124 -0
- package/vendor/stylo/values/computed/background.rs +13 -0
- package/vendor/stylo/values/computed/basic_shape.rs +267 -0
- package/vendor/stylo/values/computed/border.rs +163 -0
- package/vendor/stylo/values/computed/box.rs +267 -0
- package/vendor/stylo/values/computed/calc.rs +334 -0
- package/vendor/stylo/values/computed/color.rs +161 -0
- package/vendor/stylo/values/computed/column.rs +11 -0
- package/vendor/stylo/values/computed/corner_shape.rs +155 -0
- package/vendor/stylo/values/computed/counters.rs +26 -0
- package/vendor/stylo/values/computed/easing.rs +109 -0
- package/vendor/stylo/values/computed/effects.rs +30 -0
- package/vendor/stylo/values/computed/flex.rs +19 -0
- package/vendor/stylo/values/computed/font.rs +1517 -0
- package/vendor/stylo/values/computed/image.rs +273 -0
- package/vendor/stylo/values/computed/length.rs +576 -0
- package/vendor/stylo/values/computed/length_percentage.rs +1055 -0
- package/vendor/stylo/values/computed/list.rs +16 -0
- package/vendor/stylo/values/computed/mod.rs +1141 -0
- package/vendor/stylo/values/computed/motion.rs +73 -0
- package/vendor/stylo/values/computed/outline.rs +7 -0
- package/vendor/stylo/values/computed/page.rs +77 -0
- package/vendor/stylo/values/computed/param.rs +9 -0
- package/vendor/stylo/values/computed/percentage.rs +143 -0
- package/vendor/stylo/values/computed/position.rs +273 -0
- package/vendor/stylo/values/computed/ratio.rs +88 -0
- package/vendor/stylo/values/computed/rect.rs +19 -0
- package/vendor/stylo/values/computed/resolution.rs +76 -0
- package/vendor/stylo/values/computed/svg.rs +66 -0
- package/vendor/stylo/values/computed/table.rs +7 -0
- package/vendor/stylo/values/computed/text.rs +199 -0
- package/vendor/stylo/values/computed/time.rs +83 -0
- package/vendor/stylo/values/computed/transform.rs +559 -0
- package/vendor/stylo/values/computed/tree_counting.rs +30 -0
- package/vendor/stylo/values/computed/ui.rs +23 -0
- package/vendor/stylo/values/computed/url.rs +12 -0
- package/vendor/stylo/values/distance.rs +139 -0
- package/vendor/stylo/values/generics/animation.rs +363 -0
- package/vendor/stylo/values/generics/background.rs +65 -0
- package/vendor/stylo/values/generics/basic_shape.rs +1389 -0
- package/vendor/stylo/values/generics/border.rs +303 -0
- package/vendor/stylo/values/generics/box.rs +552 -0
- package/vendor/stylo/values/generics/calc.rs +2986 -0
- package/vendor/stylo/values/generics/color.rs +318 -0
- package/vendor/stylo/values/generics/column.rs +44 -0
- package/vendor/stylo/values/generics/counters.rs +320 -0
- package/vendor/stylo/values/generics/easing.rs +132 -0
- package/vendor/stylo/values/generics/effects.rs +131 -0
- package/vendor/stylo/values/generics/flex.rs +34 -0
- package/vendor/stylo/values/generics/font.rs +376 -0
- package/vendor/stylo/values/generics/grid.rs +962 -0
- package/vendor/stylo/values/generics/image.rs +653 -0
- package/vendor/stylo/values/generics/length.rs +656 -0
- package/vendor/stylo/values/generics/mod.rs +303 -0
- package/vendor/stylo/values/generics/motion.rs +274 -0
- package/vendor/stylo/values/generics/page.rs +167 -0
- package/vendor/stylo/values/generics/position.rs +669 -0
- package/vendor/stylo/values/generics/ratio.rs +88 -0
- package/vendor/stylo/values/generics/rect.rs +147 -0
- package/vendor/stylo/values/generics/size.rs +102 -0
- package/vendor/stylo/values/generics/svg.rs +226 -0
- package/vendor/stylo/values/generics/text.rs +268 -0
- package/vendor/stylo/values/generics/transform.rs +1157 -0
- package/vendor/stylo/values/generics/ui.rs +147 -0
- package/vendor/stylo/values/generics/url.rs +51 -0
- package/vendor/stylo/values/mod.rs +820 -0
- package/vendor/stylo/values/resolved/animation.rs +33 -0
- package/vendor/stylo/values/resolved/color.rs +53 -0
- package/vendor/stylo/values/resolved/counters.rs +45 -0
- package/vendor/stylo/values/resolved/mod.rs +316 -0
- package/vendor/stylo/values/specified/align.rs +711 -0
- package/vendor/stylo/values/specified/angle.rs +407 -0
- package/vendor/stylo/values/specified/animation.rs +921 -0
- package/vendor/stylo/values/specified/background.rs +270 -0
- package/vendor/stylo/values/specified/basic_shape.rs +986 -0
- package/vendor/stylo/values/specified/border.rs +430 -0
- package/vendor/stylo/values/specified/box.rs +2231 -0
- package/vendor/stylo/values/specified/calc.rs +1657 -0
- package/vendor/stylo/values/specified/color.rs +1210 -0
- package/vendor/stylo/values/specified/column.rs +11 -0
- package/vendor/stylo/values/specified/corner_shape.rs +152 -0
- package/vendor/stylo/values/specified/counters.rs +242 -0
- package/vendor/stylo/values/specified/easing.rs +225 -0
- package/vendor/stylo/values/specified/effects.rs +421 -0
- package/vendor/stylo/values/specified/flex.rs +42 -0
- package/vendor/stylo/values/specified/font.rs +2103 -0
- package/vendor/stylo/values/specified/frequency.rs +39 -0
- package/vendor/stylo/values/specified/grid.rs +407 -0
- package/vendor/stylo/values/specified/image.rs +1385 -0
- package/vendor/stylo/values/specified/intersection_observer.rs +80 -0
- package/vendor/stylo/values/specified/length.rs +2024 -0
- package/vendor/stylo/values/specified/list.rs +190 -0
- package/vendor/stylo/values/specified/mod.rs +531 -0
- package/vendor/stylo/values/specified/motion.rs +316 -0
- package/vendor/stylo/values/specified/number.rs +603 -0
- package/vendor/stylo/values/specified/outline.rs +69 -0
- package/vendor/stylo/values/specified/page.rs +94 -0
- package/vendor/stylo/values/specified/param.rs +121 -0
- package/vendor/stylo/values/specified/percentage.rs +364 -0
- package/vendor/stylo/values/specified/position.rs +2247 -0
- package/vendor/stylo/values/specified/ratio.rs +29 -0
- package/vendor/stylo/values/specified/rect.rs +28 -0
- package/vendor/stylo/values/specified/resolution.rs +237 -0
- package/vendor/stylo/values/specified/source_size_list.rs +135 -0
- package/vendor/stylo/values/specified/svg.rs +427 -0
- package/vendor/stylo/values/specified/svg_path.rs +1115 -0
- package/vendor/stylo/values/specified/table.rs +38 -0
- package/vendor/stylo/values/specified/text.rs +1561 -0
- package/vendor/stylo/values/specified/time.rs +313 -0
- package/vendor/stylo/values/specified/transform.rs +599 -0
- package/vendor/stylo/values/specified/tree_counting.rs +32 -0
- package/vendor/stylo/values/specified/ui.rs +344 -0
- package/vendor/stylo/values/specified/url.rs +12 -0
- package/vendor/stylo/values/tagged_numeric.rs +253 -0
- package/wasm/blitz_pdf.d.ts +67 -0
- package/wasm/blitz_pdf.js +699 -0
- package/wasm/blitz_pdf_bg.wasm +0 -0
- package/wasm/blitz_pdf_bg.wasm.d.ts +20 -0
|
@@ -0,0 +1,486 @@
|
|
|
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
|
+
//! [@supports rules](https://drafts.csswg.org/css-conditional-3/#at-supports)
|
|
6
|
+
|
|
7
|
+
use crate::derives::*;
|
|
8
|
+
use crate::font_face::{FontFaceSourceFormatKeyword, FontFaceSourceTechFlags};
|
|
9
|
+
use crate::parser::ParserContext;
|
|
10
|
+
use crate::properties::{PropertyDeclaration, PropertyId, SourcePropertyDeclaration};
|
|
11
|
+
use crate::selector_parser::{SelectorImpl, SelectorParser};
|
|
12
|
+
use crate::shared_lock::{DeepCloneWithLock, Locked};
|
|
13
|
+
use crate::shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
|
|
14
|
+
use crate::stylesheets::rule_parser::AtRuleType;
|
|
15
|
+
use crate::stylesheets::{CssRuleType, CssRules};
|
|
16
|
+
use cssparser::{Delimiter, Parser, SourceLocation, Token};
|
|
17
|
+
use cssparser::{ParseError as CssParseError, match_ignore_ascii_case};
|
|
18
|
+
use cssparser::{parse_important, serialize_identifier};
|
|
19
|
+
#[cfg(feature = "gecko")]
|
|
20
|
+
use malloc_size_of::{MallocSizeOfOps, MallocUnconditionalShallowSizeOf};
|
|
21
|
+
use selectors::parser::{Selector, SelectorParseErrorKind};
|
|
22
|
+
use servo_arc::Arc;
|
|
23
|
+
use std::fmt::{self, Write};
|
|
24
|
+
use std::str;
|
|
25
|
+
use style_traits::{CssStringWriter, CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
|
26
|
+
|
|
27
|
+
/// An [`@supports`][supports] rule.
|
|
28
|
+
///
|
|
29
|
+
/// [supports]: https://drafts.csswg.org/css-conditional-3/#at-supports
|
|
30
|
+
#[derive(Debug, ToShmem)]
|
|
31
|
+
pub struct SupportsRule {
|
|
32
|
+
/// The parsed condition
|
|
33
|
+
pub condition: SupportsCondition,
|
|
34
|
+
/// Child rules
|
|
35
|
+
pub rules: Arc<Locked<CssRules>>,
|
|
36
|
+
/// The result of evaluating the condition
|
|
37
|
+
pub enabled: bool,
|
|
38
|
+
/// The line and column of the rule's source code.
|
|
39
|
+
pub source_location: SourceLocation,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
impl SupportsRule {
|
|
43
|
+
/// Measure heap usage.
|
|
44
|
+
#[cfg(feature = "gecko")]
|
|
45
|
+
pub fn size_of(&self, guard: &SharedRwLockReadGuard, ops: &mut MallocSizeOfOps) -> usize {
|
|
46
|
+
// Measurement of other fields may be added later.
|
|
47
|
+
self.rules.unconditional_shallow_size_of(ops)
|
|
48
|
+
+ self.rules.read_with(guard).size_of(guard, ops)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
impl ToCssWithGuard for SupportsRule {
|
|
53
|
+
fn to_css(&self, guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result {
|
|
54
|
+
dest.write_str("@supports ")?;
|
|
55
|
+
self.condition.to_css(&mut CssWriter::new(dest))?;
|
|
56
|
+
self.rules.read_with(guard).to_css_block(guard, dest)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
impl DeepCloneWithLock for SupportsRule {
|
|
61
|
+
fn deep_clone_with_lock(&self, lock: &SharedRwLock, guard: &SharedRwLockReadGuard) -> Self {
|
|
62
|
+
let rules = self.rules.read_with(guard);
|
|
63
|
+
SupportsRule {
|
|
64
|
+
condition: self.condition.clone(),
|
|
65
|
+
rules: Arc::new(lock.wrap(rules.deep_clone_with_lock(lock, guard))),
|
|
66
|
+
enabled: self.enabled,
|
|
67
|
+
source_location: self.source_location,
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/// An @supports condition
|
|
73
|
+
///
|
|
74
|
+
/// <https://drafts.csswg.org/css-conditional-3/#at-supports>
|
|
75
|
+
#[derive(Clone, Debug, ToShmem)]
|
|
76
|
+
pub enum SupportsCondition {
|
|
77
|
+
/// `not (condition)`
|
|
78
|
+
Not(Box<SupportsCondition>),
|
|
79
|
+
/// `(condition)`
|
|
80
|
+
Parenthesized(Box<SupportsCondition>),
|
|
81
|
+
/// `(condition) and (condition) and (condition) ..`
|
|
82
|
+
And(Vec<SupportsCondition>),
|
|
83
|
+
/// `(condition) or (condition) or (condition) ..`
|
|
84
|
+
Or(Vec<SupportsCondition>),
|
|
85
|
+
/// `property-ident: value` (value can be any tokens)
|
|
86
|
+
Declaration(Declaration),
|
|
87
|
+
/// `at-rule(<at-keyword-token>)`
|
|
88
|
+
AtRule(AtRuleKeyword),
|
|
89
|
+
/// A `selector()` function.
|
|
90
|
+
Selector(RawSelector),
|
|
91
|
+
/// `font-format(<font-format>)`
|
|
92
|
+
FontFormat(FontFaceSourceFormatKeyword),
|
|
93
|
+
/// `font-tech(<font-tech>)`
|
|
94
|
+
FontTech(FontFaceSourceTechFlags),
|
|
95
|
+
/// `named-feature(<ident>)`
|
|
96
|
+
NamedFeature(NamedFeature),
|
|
97
|
+
/// `(any tokens)` or `func(any tokens)`
|
|
98
|
+
FutureSyntax(String),
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
impl SupportsCondition {
|
|
102
|
+
/// Parse a condition
|
|
103
|
+
///
|
|
104
|
+
/// <https://drafts.csswg.org/css-conditional/#supports_condition>
|
|
105
|
+
pub fn parse(input: &mut Parser) -> Result<Self, ParseError> {
|
|
106
|
+
if input.try_parse(|i| i.expect_ident_matching("not")).is_ok() {
|
|
107
|
+
let inner = SupportsCondition::parse_in_parens(input)?;
|
|
108
|
+
return Ok(SupportsCondition::Not(Box::new(inner)));
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let in_parens = SupportsCondition::parse_in_parens(input)?;
|
|
112
|
+
|
|
113
|
+
let (keyword, wrapper) = match input.next() {
|
|
114
|
+
// End of input
|
|
115
|
+
Err(..) => return Ok(in_parens),
|
|
116
|
+
Ok(Token::Ident(ident)) => {
|
|
117
|
+
match_ignore_ascii_case! { &ident,
|
|
118
|
+
"and" => ("and", SupportsCondition::And as fn(_) -> _),
|
|
119
|
+
"or" => ("or", SupportsCondition::Or as fn(_) -> _),
|
|
120
|
+
_ => return Err(ParseError::custom(SelectorParseErrorKind::UnexpectedIdent))
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
Ok(_) => return Err(ParseError::unexpected_token()),
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
let mut conditions = Vec::with_capacity(2);
|
|
127
|
+
conditions.push(in_parens);
|
|
128
|
+
loop {
|
|
129
|
+
conditions.push(SupportsCondition::parse_in_parens(input)?);
|
|
130
|
+
if input
|
|
131
|
+
.try_parse(|input| input.expect_ident_matching(keyword))
|
|
132
|
+
.is_err()
|
|
133
|
+
{
|
|
134
|
+
// Did not find the expected keyword.
|
|
135
|
+
// If we found some other token, it will be rejected by
|
|
136
|
+
// `Parser::parse_entirely` somewhere up the stack.
|
|
137
|
+
return Ok(wrapper(conditions));
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/// Parses a functional supports condition.
|
|
143
|
+
fn parse_functional(function: &str, input: &mut Parser) -> Result<Self, ParseError> {
|
|
144
|
+
match_ignore_ascii_case! { function,
|
|
145
|
+
"at-rule" if crate::pref!("layout.css.supports.at-rule.enabled") => {
|
|
146
|
+
let kw = AtRuleKeyword::parse(input)?;
|
|
147
|
+
Ok(SupportsCondition::AtRule(kw))
|
|
148
|
+
},
|
|
149
|
+
"selector" => {
|
|
150
|
+
let pos = input.position();
|
|
151
|
+
consume_any_value(input)?;
|
|
152
|
+
Ok(SupportsCondition::Selector(RawSelector(
|
|
153
|
+
input.slice_from(pos).to_owned()
|
|
154
|
+
)))
|
|
155
|
+
},
|
|
156
|
+
"font-format" if crate::pref!("layout.css.font-tech.enabled", gecko = true) => {
|
|
157
|
+
let kw = FontFaceSourceFormatKeyword::parse(input)?;
|
|
158
|
+
Ok(SupportsCondition::FontFormat(kw))
|
|
159
|
+
},
|
|
160
|
+
"font-tech" if crate::pref!("layout.css.font-tech.enabled", gecko = true) => {
|
|
161
|
+
let flag = FontFaceSourceTechFlags::parse_one(input)?;
|
|
162
|
+
Ok(SupportsCondition::FontTech(flag))
|
|
163
|
+
},
|
|
164
|
+
"named-feature" => {
|
|
165
|
+
let feature = NamedFeature::parse(input)?;
|
|
166
|
+
Ok(SupportsCondition::NamedFeature(feature))
|
|
167
|
+
},
|
|
168
|
+
_ => {
|
|
169
|
+
Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError))
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/// Parses an `@import` condition as per
|
|
175
|
+
/// https://drafts.csswg.org/css-cascade-5/#typedef-import-conditions
|
|
176
|
+
pub fn parse_for_import(input: &mut Parser) -> Result<Self, ParseError> {
|
|
177
|
+
input.expect_function_matching("supports")?;
|
|
178
|
+
input.parse_nested_block(parse_condition_or_declaration)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/// <https://drafts.csswg.org/css-conditional-3/#supports_condition_in_parens>
|
|
182
|
+
fn parse_in_parens(input: &mut Parser) -> Result<Self, ParseError> {
|
|
183
|
+
// Whitespace is normally taken care of in `Parser::next`, but we want to not include it in
|
|
184
|
+
// `pos` for the SupportsCondition::FutureSyntax cases.
|
|
185
|
+
input.skip_whitespace();
|
|
186
|
+
let pos = input.position();
|
|
187
|
+
match *input.next()? {
|
|
188
|
+
Token::ParenthesisBlock => {
|
|
189
|
+
let nested = input
|
|
190
|
+
.try_parse(|input| input.parse_nested_block(parse_condition_or_declaration));
|
|
191
|
+
if let Ok(nested) = nested {
|
|
192
|
+
return Ok(Self::Parenthesized(Box::new(nested)));
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
Token::Function(ref ident) => {
|
|
196
|
+
let ident = ident.clone();
|
|
197
|
+
let nested = input.try_parse(|input| {
|
|
198
|
+
input.parse_nested_block(|input| {
|
|
199
|
+
SupportsCondition::parse_functional(&ident, input)
|
|
200
|
+
})
|
|
201
|
+
});
|
|
202
|
+
if nested.is_ok() {
|
|
203
|
+
return nested;
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
_ => return Err(ParseError::unexpected_token()),
|
|
207
|
+
}
|
|
208
|
+
input.parse_nested_block(consume_any_value)?;
|
|
209
|
+
Ok(SupportsCondition::FutureSyntax(
|
|
210
|
+
input.slice_from(pos).to_owned(),
|
|
211
|
+
))
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/// Evaluate a supports condition
|
|
215
|
+
pub fn eval(&self, cx: &ParserContext) -> bool {
|
|
216
|
+
match *self {
|
|
217
|
+
SupportsCondition::Not(ref cond) => !cond.eval(cx),
|
|
218
|
+
SupportsCondition::Parenthesized(ref cond) => cond.eval(cx),
|
|
219
|
+
SupportsCondition::And(ref vec) => vec.iter().all(|c| c.eval(cx)),
|
|
220
|
+
SupportsCondition::Or(ref vec) => vec.iter().any(|c| c.eval(cx)),
|
|
221
|
+
SupportsCondition::AtRule(ref kw) => kw.eval(cx),
|
|
222
|
+
SupportsCondition::Declaration(ref decl) => decl.eval(cx),
|
|
223
|
+
SupportsCondition::Selector(ref selector) => selector.eval(cx),
|
|
224
|
+
SupportsCondition::FontFormat(ref format) => eval_font_format(format),
|
|
225
|
+
SupportsCondition::FontTech(ref tech) => eval_font_tech(tech),
|
|
226
|
+
SupportsCondition::NamedFeature(ref feature) => feature.eval(),
|
|
227
|
+
SupportsCondition::FutureSyntax(_) => false,
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
#[cfg(feature = "gecko")]
|
|
233
|
+
fn eval_font_format(kw: &FontFaceSourceFormatKeyword) -> bool {
|
|
234
|
+
use crate::gecko_bindings::bindings;
|
|
235
|
+
unsafe { bindings::Gecko_IsFontFormatSupported(*kw) }
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
#[cfg(feature = "gecko")]
|
|
239
|
+
fn eval_font_tech(flag: &FontFaceSourceTechFlags) -> bool {
|
|
240
|
+
use crate::gecko_bindings::bindings;
|
|
241
|
+
unsafe { bindings::Gecko_IsFontTechSupported(*flag) }
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
#[cfg(feature = "servo")]
|
|
245
|
+
fn eval_font_format(_: &FontFaceSourceFormatKeyword) -> bool {
|
|
246
|
+
false
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
#[cfg(feature = "servo")]
|
|
250
|
+
fn eval_font_tech(_: &FontFaceSourceTechFlags) -> bool {
|
|
251
|
+
false
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/// supports_condition | declaration
|
|
255
|
+
/// <https://drafts.csswg.org/css-conditional/#dom-css-supports-conditiontext-conditiontext>
|
|
256
|
+
pub fn parse_condition_or_declaration(input: &mut Parser) -> Result<SupportsCondition, ParseError> {
|
|
257
|
+
if let Ok(condition) = input.try_parse(SupportsCondition::parse) {
|
|
258
|
+
Ok(condition)
|
|
259
|
+
} else {
|
|
260
|
+
Declaration::parse(input).map(SupportsCondition::Declaration)
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
impl ToCss for SupportsCondition {
|
|
265
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
266
|
+
where
|
|
267
|
+
W: Write,
|
|
268
|
+
{
|
|
269
|
+
match *self {
|
|
270
|
+
SupportsCondition::Not(ref cond) => {
|
|
271
|
+
dest.write_str("not ")?;
|
|
272
|
+
cond.to_css(dest)
|
|
273
|
+
},
|
|
274
|
+
SupportsCondition::Parenthesized(ref cond) => {
|
|
275
|
+
dest.write_char('(')?;
|
|
276
|
+
cond.to_css(dest)?;
|
|
277
|
+
dest.write_char(')')
|
|
278
|
+
},
|
|
279
|
+
SupportsCondition::And(ref vec) => {
|
|
280
|
+
let mut first = true;
|
|
281
|
+
for cond in vec {
|
|
282
|
+
if !first {
|
|
283
|
+
dest.write_str(" and ")?;
|
|
284
|
+
}
|
|
285
|
+
first = false;
|
|
286
|
+
cond.to_css(dest)?;
|
|
287
|
+
}
|
|
288
|
+
Ok(())
|
|
289
|
+
},
|
|
290
|
+
SupportsCondition::Or(ref vec) => {
|
|
291
|
+
let mut first = true;
|
|
292
|
+
for cond in vec {
|
|
293
|
+
if !first {
|
|
294
|
+
dest.write_str(" or ")?;
|
|
295
|
+
}
|
|
296
|
+
first = false;
|
|
297
|
+
cond.to_css(dest)?;
|
|
298
|
+
}
|
|
299
|
+
Ok(())
|
|
300
|
+
},
|
|
301
|
+
SupportsCondition::AtRule(ref kw) => {
|
|
302
|
+
dest.write_str("at-rule(")?;
|
|
303
|
+
kw.to_css(dest)?;
|
|
304
|
+
dest.write_char(')')
|
|
305
|
+
},
|
|
306
|
+
SupportsCondition::Declaration(ref decl) => decl.to_css(dest),
|
|
307
|
+
SupportsCondition::Selector(ref selector) => {
|
|
308
|
+
dest.write_str("selector(")?;
|
|
309
|
+
selector.to_css(dest)?;
|
|
310
|
+
dest.write_char(')')
|
|
311
|
+
},
|
|
312
|
+
SupportsCondition::FontFormat(ref kw) => {
|
|
313
|
+
dest.write_str("font-format(")?;
|
|
314
|
+
kw.to_css(dest)?;
|
|
315
|
+
dest.write_char(')')
|
|
316
|
+
},
|
|
317
|
+
SupportsCondition::FontTech(ref flag) => {
|
|
318
|
+
dest.write_str("font-tech(")?;
|
|
319
|
+
flag.to_css(dest)?;
|
|
320
|
+
dest.write_char(')')
|
|
321
|
+
},
|
|
322
|
+
SupportsCondition::NamedFeature(ref feature) => {
|
|
323
|
+
dest.write_str("named-feature(")?;
|
|
324
|
+
feature.to_css(dest)?;
|
|
325
|
+
dest.write_char(')')
|
|
326
|
+
},
|
|
327
|
+
SupportsCondition::FutureSyntax(ref s) => dest.write_str(s),
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
#[derive(Clone, Debug, ToShmem)]
|
|
333
|
+
/// A possibly-invalid CSS selector.
|
|
334
|
+
pub struct RawSelector(pub String);
|
|
335
|
+
|
|
336
|
+
impl ToCss for RawSelector {
|
|
337
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
338
|
+
where
|
|
339
|
+
W: Write,
|
|
340
|
+
{
|
|
341
|
+
dest.write_str(&self.0)
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
impl RawSelector {
|
|
346
|
+
/// Tries to evaluate a `selector()` function.
|
|
347
|
+
pub fn eval(&self, context: &ParserContext) -> bool {
|
|
348
|
+
let mut input = Parser::new(&self.0);
|
|
349
|
+
input
|
|
350
|
+
.parse_entirely(|input| -> Result<(), CssParseError<()>> {
|
|
351
|
+
let parser = SelectorParser {
|
|
352
|
+
namespaces: &context.namespaces,
|
|
353
|
+
stylesheet_origin: context.stylesheet_origin,
|
|
354
|
+
url_data: context.url_data,
|
|
355
|
+
for_supports_rule: true,
|
|
356
|
+
};
|
|
357
|
+
|
|
358
|
+
Selector::<SelectorImpl>::parse(&parser, input)
|
|
359
|
+
.map_err(|_| CssParseError::custom(()))?;
|
|
360
|
+
|
|
361
|
+
Ok(())
|
|
362
|
+
})
|
|
363
|
+
.is_ok()
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
#[derive(Clone, Debug, ToShmem)]
|
|
368
|
+
/// A possibly-invalid property declaration
|
|
369
|
+
pub struct Declaration(pub String);
|
|
370
|
+
|
|
371
|
+
impl ToCss for Declaration {
|
|
372
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
373
|
+
where
|
|
374
|
+
W: Write,
|
|
375
|
+
{
|
|
376
|
+
dest.write_str(&self.0)
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/// <https://drafts.csswg.org/css-syntax-3/#typedef-any-value>
|
|
381
|
+
fn consume_any_value(input: &mut Parser) -> Result<(), ParseError> {
|
|
382
|
+
input.expect_no_error_token().map_err(|err| err.into())
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
impl Declaration {
|
|
386
|
+
/// Parse a declaration
|
|
387
|
+
pub fn parse(input: &mut Parser) -> Result<Declaration, ParseError> {
|
|
388
|
+
let pos = input.position();
|
|
389
|
+
input.expect_ident()?;
|
|
390
|
+
input.expect_colon()?;
|
|
391
|
+
consume_any_value(input)?;
|
|
392
|
+
Ok(Declaration(input.slice_from(pos).to_owned()))
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
/// Determine if a declaration parses
|
|
396
|
+
///
|
|
397
|
+
/// <https://drafts.csswg.org/css-conditional-3/#support-definition>
|
|
398
|
+
pub fn eval(&self, context: &ParserContext) -> bool {
|
|
399
|
+
debug_assert!(context.rule_types().contains(CssRuleType::Style));
|
|
400
|
+
|
|
401
|
+
let mut input = Parser::new(&self.0);
|
|
402
|
+
input
|
|
403
|
+
.parse_entirely(|input| -> Result<(), CssParseError<()>> {
|
|
404
|
+
let prop = input.expect_ident_cloned().unwrap();
|
|
405
|
+
input.expect_colon().unwrap();
|
|
406
|
+
|
|
407
|
+
let id =
|
|
408
|
+
PropertyId::parse(&prop, context).map_err(|_| CssParseError::custom(()))?;
|
|
409
|
+
|
|
410
|
+
let mut declarations = SourcePropertyDeclaration::default();
|
|
411
|
+
input.parse_until_before(Delimiter::Bang, |input| {
|
|
412
|
+
PropertyDeclaration::parse_into(&mut declarations, id, context, input)
|
|
413
|
+
.map_err(|_| CssParseError::custom(()))
|
|
414
|
+
})?;
|
|
415
|
+
let _ = input.try_parse(parse_important);
|
|
416
|
+
Ok(())
|
|
417
|
+
})
|
|
418
|
+
.is_ok()
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/// A possibly-invalid at-rule keyword
|
|
423
|
+
#[derive(Clone, Debug, ToShmem)]
|
|
424
|
+
pub struct AtRuleKeyword(pub Box<str>);
|
|
425
|
+
|
|
426
|
+
impl AtRuleKeyword {
|
|
427
|
+
/// Parse an <at-keyword-token>.
|
|
428
|
+
pub fn parse(input: &mut Parser) -> Result<Self, ParseError> {
|
|
429
|
+
match input.next()? {
|
|
430
|
+
Token::AtKeyword(kw) => Ok(Self(kw.as_ref().into())),
|
|
431
|
+
_ => Err(ParseError::unexpected_token()),
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/// Determine if an at-rule is supported.
|
|
436
|
+
/// https://drafts.csswg.org/css-conditional-5/#dfn-support-at-rule
|
|
437
|
+
pub fn eval(&self, context: &ParserContext) -> bool {
|
|
438
|
+
AtRuleType::is_supported(&self.0, context)
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
impl ToCss for AtRuleKeyword {
|
|
443
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
444
|
+
where
|
|
445
|
+
W: Write,
|
|
446
|
+
{
|
|
447
|
+
dest.write_char('@')?;
|
|
448
|
+
serialize_identifier(&self.0, dest)
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/// List of named features.
|
|
453
|
+
///
|
|
454
|
+
/// <https://drafts.csswg.org/css-conditional-5/#support-definition-named-features>
|
|
455
|
+
#[derive(Clone, Copy, Debug, Parse, ToCss, ToShmem)]
|
|
456
|
+
#[repr(u8)]
|
|
457
|
+
pub enum NamedFeature {
|
|
458
|
+
/// Anchoring to a transformed element takes the anchor's transforms into account.
|
|
459
|
+
AnchorPositionFollowsTransforms,
|
|
460
|
+
/// A scroll container that scrolls in one axis and clips in the other.
|
|
461
|
+
SingleAxisScrollContainer,
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
impl NamedFeature {
|
|
465
|
+
/// Determine if a named feature is supported.
|
|
466
|
+
///
|
|
467
|
+
/// <https://drafts.csswg.org/css-conditional-5/#typedef-supports-named-feature-fn>
|
|
468
|
+
#[cfg(feature = "gecko")]
|
|
469
|
+
pub fn eval(self) -> bool {
|
|
470
|
+
match self {
|
|
471
|
+
Self::AnchorPositionFollowsTransforms => {
|
|
472
|
+
crate::pref!("layout.css.anchor-positioning.follows-transforms.enabled")
|
|
473
|
+
},
|
|
474
|
+
// Not implemented. See Bug 2044147.
|
|
475
|
+
Self::SingleAxisScrollContainer => false,
|
|
476
|
+
}
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
/// Determine if a named feature is supported.
|
|
480
|
+
///
|
|
481
|
+
/// <https://drafts.csswg.org/css-conditional-5/#typedef-supports-named-feature-fn>
|
|
482
|
+
#[cfg(feature = "servo")]
|
|
483
|
+
pub fn eval(self) -> bool {
|
|
484
|
+
false
|
|
485
|
+
}
|
|
486
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
//! A [`@view-transition`][view-transition] rule
|
|
6
|
+
//!
|
|
7
|
+
//! [view-transition]: https://drafts.csswg.org/css-view-transitions-2/#view-transition-rule
|
|
8
|
+
|
|
9
|
+
use crate::derives::*;
|
|
10
|
+
use crate::error_reporting::ContextualParseError;
|
|
11
|
+
use crate::parser::ParserContext;
|
|
12
|
+
use crate::properties::view_transition::{DescriptorParser, Descriptors};
|
|
13
|
+
use crate::shared_lock::DeepCloneWithLock;
|
|
14
|
+
use crate::shared_lock::{SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
|
|
15
|
+
use cssparser::{Parser, RuleBodyParser, SourceLocation};
|
|
16
|
+
use std::fmt::{self, Write};
|
|
17
|
+
use style_traits::{CssStringWriter, CssWriter, ToCss};
|
|
18
|
+
|
|
19
|
+
/// A view-transition rule
|
|
20
|
+
#[derive(Clone, Debug, MallocSizeOf, ToShmem)]
|
|
21
|
+
pub struct ViewTransitionRule {
|
|
22
|
+
/// The descriptors of this view-transition rule.
|
|
23
|
+
pub descriptors: Descriptors,
|
|
24
|
+
/// The source position where this view-transition rule was found.
|
|
25
|
+
pub source_location: SourceLocation,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
impl ViewTransitionRule {
|
|
29
|
+
/// Parses a ViewTransitionRule
|
|
30
|
+
pub fn parse(context: &ParserContext, input: &mut Parser, location: SourceLocation) -> Self {
|
|
31
|
+
let mut rule = ViewTransitionRule {
|
|
32
|
+
descriptors: Descriptors::default(),
|
|
33
|
+
source_location: location,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
let mut parser = DescriptorParser {
|
|
37
|
+
context,
|
|
38
|
+
descriptors: &mut rule.descriptors,
|
|
39
|
+
};
|
|
40
|
+
let iter = RuleBodyParser::new(input, &mut parser);
|
|
41
|
+
|
|
42
|
+
for declaration in iter {
|
|
43
|
+
if let Err((error, slice, location)) = declaration {
|
|
44
|
+
let error = ContextualParseError::UnsupportedViewTransitionDescriptor(slice, error);
|
|
45
|
+
context.log_css_error(location, error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
rule
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
impl ToCssWithGuard for ViewTransitionRule {
|
|
54
|
+
fn to_css(&self, _guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result {
|
|
55
|
+
dest.write_str("@view-transition { ")?;
|
|
56
|
+
self.descriptors.to_css(&mut CssWriter::new(dest))?;
|
|
57
|
+
dest.write_str("}")
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
impl DeepCloneWithLock for ViewTransitionRule {
|
|
62
|
+
fn deep_clone_with_lock(&self, _lock: &SharedRwLock, _guard: &SharedRwLockReadGuard) -> Self {
|
|
63
|
+
self.clone()
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/// <https://drafts.csswg.org/css-view-transitions-2/#view-transition-navigation>
|
|
68
|
+
#[derive(Clone, Copy, Debug, Default, MallocSizeOf, Parse, PartialEq, ToCss, ToShmem)]
|
|
69
|
+
#[repr(u8)]
|
|
70
|
+
pub enum NavigationType {
|
|
71
|
+
/// No transition
|
|
72
|
+
#[default]
|
|
73
|
+
None,
|
|
74
|
+
/// Perform transition if conditions are met
|
|
75
|
+
Auto,
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/// The `types` descriptor value: `none | <custom-ident>+`
|
|
79
|
+
///
|
|
80
|
+
/// <https://drafts.csswg.org/css-view-transitions-2/#typedef-pt-name-selector-list>
|
|
81
|
+
pub use crate::values::specified::animation::ViewTransitionClass as TransitionTypes;
|