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,656 @@
|
|
|
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
|
+
//! Generic types for CSS values related to length.
|
|
6
|
+
|
|
7
|
+
use crate::derives::*;
|
|
8
|
+
use crate::logical_geometry::PhysicalSide;
|
|
9
|
+
use crate::parser::{Parse, ParserContext};
|
|
10
|
+
use crate::values::computed::position::TryTacticAdjustment;
|
|
11
|
+
use crate::values::generics::box_::PositionProperty;
|
|
12
|
+
use crate::values::generics::position::TreeScoped;
|
|
13
|
+
use crate::values::generics::Optional;
|
|
14
|
+
use crate::values::DashedIdent;
|
|
15
|
+
use crate::Zero;
|
|
16
|
+
use cssparser::Parser;
|
|
17
|
+
use std::fmt::Write;
|
|
18
|
+
use style_derive::Animate;
|
|
19
|
+
use style_traits::ParseError;
|
|
20
|
+
use style_traits::ToCss;
|
|
21
|
+
use style_traits::{CssWriter, SpecifiedValueInfo};
|
|
22
|
+
|
|
23
|
+
/// A `<length-percentage> | auto` value.
|
|
24
|
+
#[allow(missing_docs)]
|
|
25
|
+
#[derive(
|
|
26
|
+
Animate,
|
|
27
|
+
Clone,
|
|
28
|
+
ComputeSquaredDistance,
|
|
29
|
+
Copy,
|
|
30
|
+
Debug,
|
|
31
|
+
Deserialize,
|
|
32
|
+
MallocSizeOf,
|
|
33
|
+
PartialEq,
|
|
34
|
+
Serialize,
|
|
35
|
+
SpecifiedValueInfo,
|
|
36
|
+
ToAnimatedValue,
|
|
37
|
+
ToAnimatedZero,
|
|
38
|
+
ToComputedValue,
|
|
39
|
+
ToCss,
|
|
40
|
+
ToResolvedValue,
|
|
41
|
+
ToShmem,
|
|
42
|
+
ToTyped,
|
|
43
|
+
)]
|
|
44
|
+
#[repr(C, u8)]
|
|
45
|
+
pub enum GenericLengthPercentageOrAuto<LengthPercent> {
|
|
46
|
+
LengthPercentage(LengthPercent),
|
|
47
|
+
Auto,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
pub use self::GenericLengthPercentageOrAuto as LengthPercentageOrAuto;
|
|
51
|
+
|
|
52
|
+
impl<LengthPercentage> LengthPercentageOrAuto<LengthPercentage> {
|
|
53
|
+
/// `auto` value.
|
|
54
|
+
#[inline]
|
|
55
|
+
pub fn auto() -> Self {
|
|
56
|
+
LengthPercentageOrAuto::Auto
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// Whether this is the `auto` value.
|
|
60
|
+
#[inline]
|
|
61
|
+
pub fn is_auto(&self) -> bool {
|
|
62
|
+
matches!(*self, LengthPercentageOrAuto::Auto)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// A helper function to parse this with quirks or not and so forth.
|
|
66
|
+
pub fn parse_with(
|
|
67
|
+
context: &ParserContext,
|
|
68
|
+
input: &mut Parser,
|
|
69
|
+
parser: impl FnOnce(&ParserContext, &mut Parser) -> Result<LengthPercentage, ParseError>,
|
|
70
|
+
) -> Result<Self, ParseError> {
|
|
71
|
+
if input.try_parse(|i| i.expect_ident_matching("auto")).is_ok() {
|
|
72
|
+
return Ok(LengthPercentageOrAuto::Auto);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
Ok(LengthPercentageOrAuto::LengthPercentage(parser(
|
|
76
|
+
context, input,
|
|
77
|
+
)?))
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
impl<LengthPercentage> LengthPercentageOrAuto<LengthPercentage>
|
|
82
|
+
where
|
|
83
|
+
LengthPercentage: Clone,
|
|
84
|
+
{
|
|
85
|
+
/// Resolves `auto` values by calling `f`.
|
|
86
|
+
#[inline]
|
|
87
|
+
pub fn auto_is(&self, f: impl FnOnce() -> LengthPercentage) -> LengthPercentage {
|
|
88
|
+
match self {
|
|
89
|
+
LengthPercentageOrAuto::LengthPercentage(length) => length.clone(),
|
|
90
|
+
LengthPercentageOrAuto::Auto => f(),
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/// Returns the non-`auto` value, if any.
|
|
95
|
+
#[inline]
|
|
96
|
+
pub fn non_auto(&self) -> Option<LengthPercentage> {
|
|
97
|
+
match self {
|
|
98
|
+
LengthPercentageOrAuto::LengthPercentage(length) => Some(length.clone()),
|
|
99
|
+
LengthPercentageOrAuto::Auto => None,
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// Maps the length of this value.
|
|
104
|
+
pub fn map<T>(&self, f: impl FnOnce(LengthPercentage) -> T) -> LengthPercentageOrAuto<T> {
|
|
105
|
+
match self {
|
|
106
|
+
LengthPercentageOrAuto::LengthPercentage(l) => {
|
|
107
|
+
LengthPercentageOrAuto::LengthPercentage(f(l.clone()))
|
|
108
|
+
},
|
|
109
|
+
LengthPercentageOrAuto::Auto => LengthPercentageOrAuto::Auto,
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
impl<LengthPercentage: Zero> Zero for LengthPercentageOrAuto<LengthPercentage> {
|
|
115
|
+
fn zero() -> Self {
|
|
116
|
+
LengthPercentageOrAuto::LengthPercentage(Zero::zero())
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
fn is_zero(&self) -> bool {
|
|
120
|
+
match *self {
|
|
121
|
+
LengthPercentageOrAuto::LengthPercentage(ref l) => l.is_zero(),
|
|
122
|
+
LengthPercentageOrAuto::Auto => false,
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
impl<LengthPercentage: Parse> Parse for LengthPercentageOrAuto<LengthPercentage> {
|
|
128
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
129
|
+
Self::parse_with(context, input, LengthPercentage::parse)
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/// A generic value for the `width`, `height`, `min-width`, or `min-height` property.
|
|
134
|
+
///
|
|
135
|
+
/// Unlike `max-width` or `max-height` properties, a Size can be `auto`,
|
|
136
|
+
/// and cannot be `none`.
|
|
137
|
+
///
|
|
138
|
+
/// Note that it only accepts non-negative values.
|
|
139
|
+
#[allow(missing_docs)]
|
|
140
|
+
#[derive(
|
|
141
|
+
Animate,
|
|
142
|
+
ComputeSquaredDistance,
|
|
143
|
+
Clone,
|
|
144
|
+
Debug,
|
|
145
|
+
MallocSizeOf,
|
|
146
|
+
PartialEq,
|
|
147
|
+
ToAnimatedValue,
|
|
148
|
+
ToAnimatedZero,
|
|
149
|
+
ToComputedValue,
|
|
150
|
+
ToCss,
|
|
151
|
+
ToResolvedValue,
|
|
152
|
+
ToShmem,
|
|
153
|
+
ToTyped,
|
|
154
|
+
)]
|
|
155
|
+
#[repr(C, u8)]
|
|
156
|
+
pub enum GenericSize<LengthPercent> {
|
|
157
|
+
LengthPercentage(LengthPercent),
|
|
158
|
+
Auto,
|
|
159
|
+
#[animation(error)]
|
|
160
|
+
MaxContent,
|
|
161
|
+
#[animation(error)]
|
|
162
|
+
MinContent,
|
|
163
|
+
#[animation(error)]
|
|
164
|
+
FitContent,
|
|
165
|
+
#[cfg(feature = "gecko")]
|
|
166
|
+
#[animation(error)]
|
|
167
|
+
MozAvailable,
|
|
168
|
+
#[animation(error)]
|
|
169
|
+
WebkitFillAvailable,
|
|
170
|
+
#[animation(error)]
|
|
171
|
+
Stretch,
|
|
172
|
+
#[animation(error)]
|
|
173
|
+
#[css(function = "fit-content")]
|
|
174
|
+
FitContentFunction(LengthPercent),
|
|
175
|
+
AnchorSizeFunction(Box<GenericAnchorSizeFunction<Self>>),
|
|
176
|
+
AnchorContainingCalcFunction(LengthPercent),
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
impl<LengthPercent> SpecifiedValueInfo for GenericSize<LengthPercent>
|
|
180
|
+
where
|
|
181
|
+
LengthPercent: SpecifiedValueInfo,
|
|
182
|
+
{
|
|
183
|
+
fn collect_completion_keywords(f: style_traits::KeywordsCollectFn) {
|
|
184
|
+
LengthPercent::collect_completion_keywords(f);
|
|
185
|
+
f(&[
|
|
186
|
+
"auto",
|
|
187
|
+
"fit-content",
|
|
188
|
+
"max-content",
|
|
189
|
+
"min-content",
|
|
190
|
+
]);
|
|
191
|
+
if crate::pref!("layout.css.anchor-positioning.enabled", gecko = true) {
|
|
192
|
+
f(&["anchor-size"]);
|
|
193
|
+
}
|
|
194
|
+
if cfg!(feature = "gecko") {
|
|
195
|
+
f(&["-moz-available"]);
|
|
196
|
+
}
|
|
197
|
+
if crate::pref!("layout.css.stretch-size-keyword.enabled") {
|
|
198
|
+
f(&["stretch"]);
|
|
199
|
+
}
|
|
200
|
+
if crate::pref!("layout.css.webkit-fill-available.enabled") {
|
|
201
|
+
f(&["-webkit-fill-available"]);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
pub use self::GenericSize as Size;
|
|
207
|
+
|
|
208
|
+
impl<LengthPercentage> Size<LengthPercentage> {
|
|
209
|
+
/// `auto` value.
|
|
210
|
+
#[inline]
|
|
211
|
+
pub fn auto() -> Self {
|
|
212
|
+
Size::Auto
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/// Returns whether we're the auto value.
|
|
216
|
+
#[inline]
|
|
217
|
+
pub fn is_auto(&self) -> bool {
|
|
218
|
+
matches!(*self, Size::Auto)
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/// A generic value for the `max-width` or `max-height` property.
|
|
223
|
+
#[allow(missing_docs)]
|
|
224
|
+
#[derive(
|
|
225
|
+
Animate,
|
|
226
|
+
Clone,
|
|
227
|
+
ComputeSquaredDistance,
|
|
228
|
+
Debug,
|
|
229
|
+
MallocSizeOf,
|
|
230
|
+
PartialEq,
|
|
231
|
+
ToAnimatedValue,
|
|
232
|
+
ToAnimatedZero,
|
|
233
|
+
ToComputedValue,
|
|
234
|
+
ToCss,
|
|
235
|
+
ToResolvedValue,
|
|
236
|
+
ToShmem,
|
|
237
|
+
ToTyped,
|
|
238
|
+
)]
|
|
239
|
+
#[repr(C, u8)]
|
|
240
|
+
pub enum GenericMaxSize<LengthPercent> {
|
|
241
|
+
LengthPercentage(LengthPercent),
|
|
242
|
+
None,
|
|
243
|
+
#[animation(error)]
|
|
244
|
+
MaxContent,
|
|
245
|
+
#[animation(error)]
|
|
246
|
+
MinContent,
|
|
247
|
+
#[animation(error)]
|
|
248
|
+
FitContent,
|
|
249
|
+
#[cfg(feature = "gecko")]
|
|
250
|
+
#[animation(error)]
|
|
251
|
+
MozAvailable,
|
|
252
|
+
#[animation(error)]
|
|
253
|
+
WebkitFillAvailable,
|
|
254
|
+
#[animation(error)]
|
|
255
|
+
Stretch,
|
|
256
|
+
#[animation(error)]
|
|
257
|
+
#[css(function = "fit-content")]
|
|
258
|
+
FitContentFunction(LengthPercent),
|
|
259
|
+
AnchorSizeFunction(Box<GenericAnchorSizeFunction<Self>>),
|
|
260
|
+
AnchorContainingCalcFunction(LengthPercent),
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
impl<LP> SpecifiedValueInfo for GenericMaxSize<LP>
|
|
264
|
+
where
|
|
265
|
+
LP: SpecifiedValueInfo,
|
|
266
|
+
{
|
|
267
|
+
fn collect_completion_keywords(f: style_traits::KeywordsCollectFn) {
|
|
268
|
+
LP::collect_completion_keywords(f);
|
|
269
|
+
f(&[
|
|
270
|
+
"none",
|
|
271
|
+
"fit-content",
|
|
272
|
+
"max-content",
|
|
273
|
+
"min-content",
|
|
274
|
+
"anchor-size",
|
|
275
|
+
]);
|
|
276
|
+
if cfg!(feature = "gecko") {
|
|
277
|
+
f(&["-moz-available"]);
|
|
278
|
+
}
|
|
279
|
+
if crate::pref!("layout.css.stretch-size-keyword.enabled") {
|
|
280
|
+
f(&["stretch"]);
|
|
281
|
+
}
|
|
282
|
+
if crate::pref!("layout.css.webkit-fill-available.enabled") {
|
|
283
|
+
f(&["-webkit-fill-available"]);
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
pub use self::GenericMaxSize as MaxSize;
|
|
289
|
+
|
|
290
|
+
impl<LengthPercentage> MaxSize<LengthPercentage> {
|
|
291
|
+
/// `none` value.
|
|
292
|
+
#[inline]
|
|
293
|
+
pub fn none() -> Self {
|
|
294
|
+
MaxSize::None
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/// A generic `<length>` | `<number>` value for the `tab-size` property.
|
|
299
|
+
#[derive(
|
|
300
|
+
Animate,
|
|
301
|
+
Clone,
|
|
302
|
+
ComputeSquaredDistance,
|
|
303
|
+
Copy,
|
|
304
|
+
Debug,
|
|
305
|
+
MallocSizeOf,
|
|
306
|
+
Parse,
|
|
307
|
+
PartialEq,
|
|
308
|
+
SpecifiedValueInfo,
|
|
309
|
+
ToAnimatedValue,
|
|
310
|
+
ToAnimatedZero,
|
|
311
|
+
ToComputedValue,
|
|
312
|
+
ToCss,
|
|
313
|
+
ToResolvedValue,
|
|
314
|
+
ToShmem,
|
|
315
|
+
ToTyped,
|
|
316
|
+
)]
|
|
317
|
+
#[repr(C, u8)]
|
|
318
|
+
pub enum GenericLengthOrNumber<L, N> {
|
|
319
|
+
/// A number.
|
|
320
|
+
///
|
|
321
|
+
/// NOTE: Numbers need to be before lengths, in order to parse them
|
|
322
|
+
/// first, since `0` should be a number, not the `0px` length.
|
|
323
|
+
Number(N),
|
|
324
|
+
/// A length.
|
|
325
|
+
Length(L),
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
pub use self::GenericLengthOrNumber as LengthOrNumber;
|
|
329
|
+
|
|
330
|
+
impl<L, N: Zero> Zero for LengthOrNumber<L, N> {
|
|
331
|
+
fn zero() -> Self {
|
|
332
|
+
LengthOrNumber::Number(Zero::zero())
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
fn is_zero(&self) -> bool {
|
|
336
|
+
match *self {
|
|
337
|
+
LengthOrNumber::Number(ref n) => n.is_zero(),
|
|
338
|
+
LengthOrNumber::Length(..) => false,
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/// A generic `<length-percentage>` | normal` value.
|
|
344
|
+
#[derive(
|
|
345
|
+
Animate,
|
|
346
|
+
Clone,
|
|
347
|
+
ComputeSquaredDistance,
|
|
348
|
+
Copy,
|
|
349
|
+
Debug,
|
|
350
|
+
MallocSizeOf,
|
|
351
|
+
Parse,
|
|
352
|
+
PartialEq,
|
|
353
|
+
SpecifiedValueInfo,
|
|
354
|
+
ToAnimatedValue,
|
|
355
|
+
ToAnimatedZero,
|
|
356
|
+
ToComputedValue,
|
|
357
|
+
ToCss,
|
|
358
|
+
ToResolvedValue,
|
|
359
|
+
ToShmem,
|
|
360
|
+
ToTyped,
|
|
361
|
+
)]
|
|
362
|
+
#[repr(C, u8)]
|
|
363
|
+
#[allow(missing_docs)]
|
|
364
|
+
pub enum GenericLengthPercentageOrNormal<LengthPercent> {
|
|
365
|
+
LengthPercentage(LengthPercent),
|
|
366
|
+
Normal,
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
pub use self::GenericLengthPercentageOrNormal as LengthPercentageOrNormal;
|
|
370
|
+
|
|
371
|
+
impl<LengthPercent> LengthPercentageOrNormal<LengthPercent> {
|
|
372
|
+
/// Returns the normal value.
|
|
373
|
+
#[inline]
|
|
374
|
+
pub fn normal() -> Self {
|
|
375
|
+
LengthPercentageOrNormal::Normal
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/// Anchor size function used by sizing, margin and inset properties.
|
|
380
|
+
/// This resolves to the size of the anchor at computed time.
|
|
381
|
+
///
|
|
382
|
+
/// https://drafts.csswg.org/css-anchor-position-1/#funcdef-anchor-size
|
|
383
|
+
#[derive(
|
|
384
|
+
Animate,
|
|
385
|
+
Clone,
|
|
386
|
+
ComputeSquaredDistance,
|
|
387
|
+
Debug,
|
|
388
|
+
MallocSizeOf,
|
|
389
|
+
PartialEq,
|
|
390
|
+
SpecifiedValueInfo,
|
|
391
|
+
ToShmem,
|
|
392
|
+
ToAnimatedValue,
|
|
393
|
+
ToAnimatedZero,
|
|
394
|
+
ToComputedValue,
|
|
395
|
+
ToResolvedValue,
|
|
396
|
+
Serialize,
|
|
397
|
+
Deserialize,
|
|
398
|
+
ToTyped,
|
|
399
|
+
)]
|
|
400
|
+
#[repr(C)]
|
|
401
|
+
#[typed(todo_derive_fields)]
|
|
402
|
+
pub struct GenericAnchorSizeFunction<Fallback> {
|
|
403
|
+
/// Anchor name of the element to anchor to.
|
|
404
|
+
/// If omitted (i.e. empty), selects the implicit anchor element.
|
|
405
|
+
#[animation(constant)]
|
|
406
|
+
pub target_element: TreeScoped<DashedIdent>,
|
|
407
|
+
/// Size of the positioned element, expressed in that of the anchor element.
|
|
408
|
+
/// If omitted, defaults to the axis of the property the function is used in.
|
|
409
|
+
pub size: AnchorSizeKeyword,
|
|
410
|
+
/// Value to use in case the anchor function is invalid.
|
|
411
|
+
pub fallback: Optional<Fallback>,
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
impl<Fallback: TryTacticAdjustment> TryTacticAdjustment for GenericAnchorSizeFunction<Fallback> {
|
|
415
|
+
fn try_tactic_adjustment(&mut self, old_side: PhysicalSide, new_side: PhysicalSide) {
|
|
416
|
+
self.size.try_tactic_adjustment(old_side, new_side);
|
|
417
|
+
if let Some(fallback) = self.fallback.as_mut() {
|
|
418
|
+
fallback.try_tactic_adjustment(old_side, new_side);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
impl<Fallback> ToCss for GenericAnchorSizeFunction<Fallback>
|
|
424
|
+
where
|
|
425
|
+
Fallback: ToCss,
|
|
426
|
+
{
|
|
427
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> std::fmt::Result
|
|
428
|
+
where
|
|
429
|
+
W: Write,
|
|
430
|
+
{
|
|
431
|
+
dest.write_str("anchor-size(")?;
|
|
432
|
+
let mut previous_entry_printed = false;
|
|
433
|
+
if !self.target_element.value.0.is_empty() {
|
|
434
|
+
previous_entry_printed = true;
|
|
435
|
+
self.target_element.to_css(dest)?;
|
|
436
|
+
}
|
|
437
|
+
if self.size != AnchorSizeKeyword::None {
|
|
438
|
+
if previous_entry_printed {
|
|
439
|
+
dest.write_str(" ")?;
|
|
440
|
+
}
|
|
441
|
+
previous_entry_printed = true;
|
|
442
|
+
self.size.to_css(dest)?;
|
|
443
|
+
}
|
|
444
|
+
if let Some(f) = self.fallback.as_ref() {
|
|
445
|
+
if previous_entry_printed {
|
|
446
|
+
dest.write_str(", ")?;
|
|
447
|
+
}
|
|
448
|
+
f.to_css(dest)?;
|
|
449
|
+
}
|
|
450
|
+
dest.write_str(")")
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
impl<Fallback> Parse for GenericAnchorSizeFunction<Fallback>
|
|
455
|
+
where
|
|
456
|
+
Fallback: Parse,
|
|
457
|
+
{
|
|
458
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
459
|
+
input.expect_function_matching("anchor-size")?;
|
|
460
|
+
Self::parse_inner(context, input, |i| Fallback::parse(context, i))
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
impl<Fallback> GenericAnchorSizeFunction<Fallback> {
|
|
464
|
+
/// Is the anchor-size use valid for given property?
|
|
465
|
+
pub fn valid_for(&self, position_property: PositionProperty) -> bool {
|
|
466
|
+
position_property.is_absolutely_positioned()
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/// Result of resolving an anchor function.
|
|
471
|
+
pub enum AnchorResolutionResult<'a, LengthPercentage> {
|
|
472
|
+
/// Function resolved to a valid anchor.
|
|
473
|
+
Resolved(LengthPercentage),
|
|
474
|
+
/// Referenced anchor is invalid, but fallback is used.
|
|
475
|
+
Fallback(&'a LengthPercentage),
|
|
476
|
+
/// Referenced anchor is invalid.
|
|
477
|
+
Invalid,
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
impl<'a, LengthPercentage> AnchorResolutionResult<'a, LengthPercentage> {
|
|
481
|
+
/// Return result for an invalid anchor function, depending on if it has any fallback.
|
|
482
|
+
pub fn new_anchor_invalid(fallback: Option<&'a LengthPercentage>) -> Self {
|
|
483
|
+
if let Some(fb) = fallback {
|
|
484
|
+
return Self::Fallback(fb);
|
|
485
|
+
}
|
|
486
|
+
Self::Invalid
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
impl<LengthPercentage> GenericAnchorSizeFunction<LengthPercentage> {
|
|
491
|
+
/// Parse the inner part of `anchor-size()`, after the parser has consumed "anchor-size(".
|
|
492
|
+
pub fn parse_inner<F>(
|
|
493
|
+
context: &ParserContext,
|
|
494
|
+
input: &mut Parser,
|
|
495
|
+
f: F,
|
|
496
|
+
) -> Result<Self, ParseError>
|
|
497
|
+
where
|
|
498
|
+
F: FnOnce(&mut Parser) -> Result<LengthPercentage, ParseError>,
|
|
499
|
+
{
|
|
500
|
+
input.parse_nested_block(|i| {
|
|
501
|
+
let mut target_element = i
|
|
502
|
+
.try_parse(|i| DashedIdent::parse(context, i))
|
|
503
|
+
.unwrap_or(DashedIdent::empty());
|
|
504
|
+
let size = i
|
|
505
|
+
.try_parse(AnchorSizeKeyword::parse)
|
|
506
|
+
.unwrap_or(AnchorSizeKeyword::None);
|
|
507
|
+
if target_element.is_empty() {
|
|
508
|
+
target_element = i
|
|
509
|
+
.try_parse(|i| DashedIdent::parse(context, i))
|
|
510
|
+
.unwrap_or(DashedIdent::empty());
|
|
511
|
+
}
|
|
512
|
+
let previous_parsed = !target_element.is_empty() || size != AnchorSizeKeyword::None;
|
|
513
|
+
let fallback = i
|
|
514
|
+
.try_parse(|i| {
|
|
515
|
+
if previous_parsed {
|
|
516
|
+
i.expect_comma()?;
|
|
517
|
+
}
|
|
518
|
+
f(i)
|
|
519
|
+
})
|
|
520
|
+
.ok();
|
|
521
|
+
Ok(GenericAnchorSizeFunction {
|
|
522
|
+
target_element: TreeScoped::with_default_level(target_element),
|
|
523
|
+
size,
|
|
524
|
+
fallback: fallback.into(),
|
|
525
|
+
})
|
|
526
|
+
})
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
/// Keyword values for the anchor size function.
|
|
531
|
+
#[derive(
|
|
532
|
+
Animate,
|
|
533
|
+
Clone,
|
|
534
|
+
ComputeSquaredDistance,
|
|
535
|
+
Copy,
|
|
536
|
+
Debug,
|
|
537
|
+
MallocSizeOf,
|
|
538
|
+
PartialEq,
|
|
539
|
+
Parse,
|
|
540
|
+
SpecifiedValueInfo,
|
|
541
|
+
ToCss,
|
|
542
|
+
ToShmem,
|
|
543
|
+
ToAnimatedValue,
|
|
544
|
+
ToAnimatedZero,
|
|
545
|
+
ToComputedValue,
|
|
546
|
+
ToResolvedValue,
|
|
547
|
+
Serialize,
|
|
548
|
+
Deserialize,
|
|
549
|
+
)]
|
|
550
|
+
#[repr(u8)]
|
|
551
|
+
pub enum AnchorSizeKeyword {
|
|
552
|
+
/// Magic value for nothing.
|
|
553
|
+
#[css(skip)]
|
|
554
|
+
None,
|
|
555
|
+
/// Width of the anchor element.
|
|
556
|
+
Width,
|
|
557
|
+
/// Height of the anchor element.
|
|
558
|
+
Height,
|
|
559
|
+
/// Block size of the anchor element.
|
|
560
|
+
Block,
|
|
561
|
+
/// Inline size of the anchor element.
|
|
562
|
+
Inline,
|
|
563
|
+
/// Same as `Block`, resolved against the positioned element's writing mode.
|
|
564
|
+
SelfBlock,
|
|
565
|
+
/// Same as `Inline`, resolved against the positioned element's writing mode.
|
|
566
|
+
SelfInline,
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
impl TryTacticAdjustment for AnchorSizeKeyword {
|
|
570
|
+
fn try_tactic_adjustment(&mut self, old_side: PhysicalSide, new_side: PhysicalSide) {
|
|
571
|
+
if old_side.parallel_to(new_side) {
|
|
572
|
+
return;
|
|
573
|
+
}
|
|
574
|
+
*self = match *self {
|
|
575
|
+
Self::None => Self::None,
|
|
576
|
+
Self::Width => Self::Height,
|
|
577
|
+
Self::Height => Self::Width,
|
|
578
|
+
Self::Block => Self::Inline,
|
|
579
|
+
Self::Inline => Self::Block,
|
|
580
|
+
Self::SelfBlock => Self::SelfInline,
|
|
581
|
+
Self::SelfInline => Self::SelfBlock,
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
/// Specified type for `margin` properties, which allows
|
|
587
|
+
/// the use of the `anchor-size()` function.
|
|
588
|
+
#[derive(
|
|
589
|
+
Animate,
|
|
590
|
+
Clone,
|
|
591
|
+
ComputeSquaredDistance,
|
|
592
|
+
Debug,
|
|
593
|
+
MallocSizeOf,
|
|
594
|
+
PartialEq,
|
|
595
|
+
ToCss,
|
|
596
|
+
ToShmem,
|
|
597
|
+
ToAnimatedValue,
|
|
598
|
+
ToAnimatedZero,
|
|
599
|
+
ToComputedValue,
|
|
600
|
+
ToResolvedValue,
|
|
601
|
+
ToTyped,
|
|
602
|
+
)]
|
|
603
|
+
#[repr(C)]
|
|
604
|
+
pub enum GenericMargin<LP> {
|
|
605
|
+
/// A `<length-percentage>` value.
|
|
606
|
+
LengthPercentage(LP),
|
|
607
|
+
/// An `auto` value.
|
|
608
|
+
Auto,
|
|
609
|
+
/// Margin size defined by the anchor element.
|
|
610
|
+
///
|
|
611
|
+
/// https://drafts.csswg.org/css-anchor-position-1/#funcdef-anchor-size
|
|
612
|
+
AnchorSizeFunction(Box<GenericAnchorSizeFunction<Self>>),
|
|
613
|
+
/// A `<length-percentage>` value, guaranteed to contain `calc()`,
|
|
614
|
+
/// which then is guaranteed to contain `anchor()` or `anchor-size()`.
|
|
615
|
+
AnchorContainingCalcFunction(LP),
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
#[cfg(feature = "servo")]
|
|
619
|
+
impl<LP> GenericMargin<LP> {
|
|
620
|
+
/// Return true if it is 'auto'.
|
|
621
|
+
#[inline]
|
|
622
|
+
pub fn is_auto(&self) -> bool {
|
|
623
|
+
matches!(self, Self::Auto)
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
impl<LP> SpecifiedValueInfo for GenericMargin<LP>
|
|
628
|
+
where
|
|
629
|
+
LP: SpecifiedValueInfo,
|
|
630
|
+
{
|
|
631
|
+
fn collect_completion_keywords(f: style_traits::KeywordsCollectFn) {
|
|
632
|
+
LP::collect_completion_keywords(f);
|
|
633
|
+
f(&["auto"]);
|
|
634
|
+
if crate::pref!("layout.css.anchor-positioning.enabled", gecko = true) {
|
|
635
|
+
f(&["anchor-size"]);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
impl<LP> Zero for GenericMargin<LP>
|
|
641
|
+
where
|
|
642
|
+
LP: Zero,
|
|
643
|
+
{
|
|
644
|
+
fn is_zero(&self) -> bool {
|
|
645
|
+
match self {
|
|
646
|
+
Self::LengthPercentage(l) => l.is_zero(),
|
|
647
|
+
Self::Auto | Self::AnchorSizeFunction(_) | Self::AnchorContainingCalcFunction(_) => {
|
|
648
|
+
false
|
|
649
|
+
},
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
fn zero() -> Self {
|
|
654
|
+
Self::LengthPercentage(LP::zero())
|
|
655
|
+
}
|
|
656
|
+
}
|