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,94 @@
|
|
|
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
|
+
//! Specified @page at-rule properties and named-page style properties
|
|
6
|
+
|
|
7
|
+
use crate::derives::*;
|
|
8
|
+
use crate::parser::{Parse, ParserContext};
|
|
9
|
+
use crate::values::generics::size::Size2D;
|
|
10
|
+
use crate::values::specified::length::NonNegativeLength;
|
|
11
|
+
use crate::values::{generics, CustomIdent};
|
|
12
|
+
use cssparser::{match_ignore_ascii_case, Parser};
|
|
13
|
+
use style_traits::ParseError;
|
|
14
|
+
|
|
15
|
+
pub use generics::page::PageOrientation;
|
|
16
|
+
pub use generics::page::PageSizeOrientation;
|
|
17
|
+
pub use generics::page::PaperSize;
|
|
18
|
+
/// Specified value of the @page size descriptor
|
|
19
|
+
pub type PageSize = generics::page::PageSize<Size2D<NonNegativeLength>>;
|
|
20
|
+
|
|
21
|
+
impl Parse for PageSize {
|
|
22
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
23
|
+
// Try to parse as <page-size> [ <orientation> ]
|
|
24
|
+
if let Ok(paper_size) = input.try_parse(PaperSize::parse) {
|
|
25
|
+
let orientation = input
|
|
26
|
+
.try_parse(PageSizeOrientation::parse)
|
|
27
|
+
.unwrap_or(PageSizeOrientation::Portrait);
|
|
28
|
+
return Ok(PageSize::PaperSize(paper_size, orientation));
|
|
29
|
+
}
|
|
30
|
+
// Try to parse as <orientation> [ <page-size> ]
|
|
31
|
+
if let Ok(orientation) = input.try_parse(PageSizeOrientation::parse) {
|
|
32
|
+
if let Ok(paper_size) = input.try_parse(PaperSize::parse) {
|
|
33
|
+
return Ok(PageSize::PaperSize(paper_size, orientation));
|
|
34
|
+
}
|
|
35
|
+
return Ok(PageSize::Orientation(orientation));
|
|
36
|
+
}
|
|
37
|
+
// Try to parse dimensions
|
|
38
|
+
if let Ok(size) =
|
|
39
|
+
input.try_parse(|i| Size2D::parse_with(context, i, NonNegativeLength::parse))
|
|
40
|
+
{
|
|
41
|
+
return Ok(PageSize::Size(size));
|
|
42
|
+
}
|
|
43
|
+
// auto value
|
|
44
|
+
input.expect_ident_matching("auto")?;
|
|
45
|
+
Ok(PageSize::Auto)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/// Page name value.
|
|
50
|
+
///
|
|
51
|
+
/// https://drafts.csswg.org/css-page-3/#using-named-pages
|
|
52
|
+
#[derive(
|
|
53
|
+
Clone,
|
|
54
|
+
Debug,
|
|
55
|
+
MallocSizeOf,
|
|
56
|
+
PartialEq,
|
|
57
|
+
SpecifiedValueInfo,
|
|
58
|
+
ToCss,
|
|
59
|
+
ToComputedValue,
|
|
60
|
+
ToResolvedValue,
|
|
61
|
+
ToShmem,
|
|
62
|
+
ToTyped,
|
|
63
|
+
)]
|
|
64
|
+
#[repr(C, u8)]
|
|
65
|
+
pub enum PageName {
|
|
66
|
+
/// `auto` value.
|
|
67
|
+
Auto,
|
|
68
|
+
/// Page name value
|
|
69
|
+
PageName(CustomIdent),
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
impl Parse for PageName {
|
|
73
|
+
fn parse(_context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
74
|
+
let ident = input.expect_ident()?;
|
|
75
|
+
Ok(match_ignore_ascii_case! { ident,
|
|
76
|
+
"auto" => PageName::auto(),
|
|
77
|
+
_ => PageName::PageName(CustomIdent::from_ident(ident, &[])?),
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
impl PageName {
|
|
83
|
+
/// `auto` value.
|
|
84
|
+
#[inline]
|
|
85
|
+
pub fn auto() -> Self {
|
|
86
|
+
PageName::Auto
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/// Whether this is the `auto` value.
|
|
90
|
+
#[inline]
|
|
91
|
+
pub fn is_auto(&self) -> bool {
|
|
92
|
+
matches!(*self, PageName::Auto)
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
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
|
+
//! Common handling for the specified value CSS param() values.
|
|
6
|
+
|
|
7
|
+
use crate::custom_properties::VariableValue;
|
|
8
|
+
use crate::parser::{Parse, ParserContext};
|
|
9
|
+
use crate::values::fmt;
|
|
10
|
+
use crate::values::CssWriter;
|
|
11
|
+
use crate::{derives::*, values::DashedIdent};
|
|
12
|
+
use cssparser::Parser;
|
|
13
|
+
use std::fmt::Write;
|
|
14
|
+
use style_traits::arc_slice::ArcSlice;
|
|
15
|
+
use style_traits::owned_str::OwnedStr;
|
|
16
|
+
use style_traits::{ParseError, ToCss};
|
|
17
|
+
|
|
18
|
+
/// A struct to hold a specific '<declaration-value>'.
|
|
19
|
+
#[derive(
|
|
20
|
+
Clone,
|
|
21
|
+
Debug,
|
|
22
|
+
MallocSizeOf,
|
|
23
|
+
PartialEq,
|
|
24
|
+
SpecifiedValueInfo,
|
|
25
|
+
ToComputedValue,
|
|
26
|
+
ToResolvedValue,
|
|
27
|
+
ToShmem,
|
|
28
|
+
)]
|
|
29
|
+
#[repr(transparent)]
|
|
30
|
+
pub struct LinkParamValue(pub OwnedStr);
|
|
31
|
+
|
|
32
|
+
/// A single param(--ident, value) entry: https://drafts.csswg.org/css-link-params-1/#funcdef-param
|
|
33
|
+
#[derive(
|
|
34
|
+
Clone,
|
|
35
|
+
Debug,
|
|
36
|
+
MallocSizeOf,
|
|
37
|
+
PartialEq,
|
|
38
|
+
SpecifiedValueInfo,
|
|
39
|
+
ToComputedValue,
|
|
40
|
+
ToResolvedValue,
|
|
41
|
+
ToShmem,
|
|
42
|
+
)]
|
|
43
|
+
#[repr(C)]
|
|
44
|
+
pub struct LinkParam {
|
|
45
|
+
/// link-parameters' param name, in the form of an <dashed-ident>: https://drafts.csswg.org/css-values-4/#typedef-dashed-ident
|
|
46
|
+
pub name: DashedIdent,
|
|
47
|
+
/// link-parameters' value, in the form of a <declaration-value>: https://drafts.csswg.org/css-syntax-3/#typedef-declaration-value
|
|
48
|
+
pub value: LinkParamValue,
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// A struct to hold all specified link-parameters: https://drafts.csswg.org/css-link-params-1/
|
|
52
|
+
///
|
|
53
|
+
/// We treat `none` as an empty slice and vis-versa
|
|
54
|
+
#[derive(
|
|
55
|
+
Clone,
|
|
56
|
+
Debug,
|
|
57
|
+
Default,
|
|
58
|
+
MallocSizeOf,
|
|
59
|
+
PartialEq,
|
|
60
|
+
SpecifiedValueInfo,
|
|
61
|
+
ToComputedValue,
|
|
62
|
+
ToCss,
|
|
63
|
+
ToResolvedValue,
|
|
64
|
+
ToShmem,
|
|
65
|
+
ToTyped,
|
|
66
|
+
)]
|
|
67
|
+
#[repr(C)]
|
|
68
|
+
#[css(comma)]
|
|
69
|
+
#[typed(skip_derive_fields)]
|
|
70
|
+
pub struct LinkParameters(
|
|
71
|
+
/// Slice of specified link-parameters properties: https://drafts.csswg.org/css-link-params-1/#link-param-prop
|
|
72
|
+
#[css(iterable, if_empty = "none")]
|
|
73
|
+
#[ignore_malloc_size_of = "Arc"]
|
|
74
|
+
pub ArcSlice<LinkParam>,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
impl LinkParameters {
|
|
78
|
+
/// Returns the `none` value.
|
|
79
|
+
pub fn none() -> Self {
|
|
80
|
+
Self(ArcSlice::default())
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
impl Parse for LinkParameters {
|
|
85
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
86
|
+
if input.try_parse(|i| i.expect_ident_matching("none")).is_ok() {
|
|
87
|
+
return Ok(Self::none());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let params = input.parse_comma_separated(|input| {
|
|
91
|
+
input.expect_function_matching("param")?;
|
|
92
|
+
input.parse_nested_block(|input| {
|
|
93
|
+
let name = DashedIdent::parse(context, input)?;
|
|
94
|
+
input.expect_comma()?;
|
|
95
|
+
// if a comma exists then parse it and set value as specified, even if no value provided
|
|
96
|
+
// need to handle url references properly https://bugzilla.mozilla.org/show_bug.cgi?id=2028998
|
|
97
|
+
let parsed = VariableValue::parse(input, None, context.url_data)?;
|
|
98
|
+
let value = LinkParamValue(OwnedStr::from(parsed.css));
|
|
99
|
+
Ok(LinkParam { name, value })
|
|
100
|
+
})
|
|
101
|
+
})?;
|
|
102
|
+
|
|
103
|
+
Ok(Self(crate::ArcSlice::from_iter(params.into_iter())))
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
impl ToCss for LinkParam {
|
|
108
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
109
|
+
where
|
|
110
|
+
W: Write,
|
|
111
|
+
{
|
|
112
|
+
dest.write_str("param(")?;
|
|
113
|
+
self.name.to_css(dest)?;
|
|
114
|
+
dest.write_str(", ")?;
|
|
115
|
+
if !self.value.0.is_empty() {
|
|
116
|
+
// Don't use to_css, instead write the raw CSS value without extra quoting.
|
|
117
|
+
dest.write_str(&self.value.0)?;
|
|
118
|
+
}
|
|
119
|
+
dest.write_char(')')
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,364 @@
|
|
|
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
|
+
//! Specified percentages.
|
|
6
|
+
|
|
7
|
+
use crate::derives::*;
|
|
8
|
+
use crate::parser::{Parse, ParserContext};
|
|
9
|
+
use crate::typed_om::{ToTyped, TypedValue};
|
|
10
|
+
use crate::values::computed::percentage::Percentage as ComputedPercentage;
|
|
11
|
+
use crate::values::computed::{Context, ToComputedValue};
|
|
12
|
+
use crate::values::generics::{NonNegative, Optional};
|
|
13
|
+
use crate::values::specified::calc::{CalcNode, CalcNumeric, CalcPercentageLeaf, Leaf};
|
|
14
|
+
use crate::values::specified::{CalcLengthPercentage, LengthPercentage, NoCalcNumber, Number};
|
|
15
|
+
use crate::values::tagged_numeric::{Extracted, NumericUnion, Unpacked, UnpackedMut};
|
|
16
|
+
use crate::values::{normalize, reify_percentage, serialize_percentage, CSSFloat};
|
|
17
|
+
use cssparser::{Parser, Token};
|
|
18
|
+
use std::fmt::{self, Write};
|
|
19
|
+
use style_traits::values::specified::AllowedNumericType;
|
|
20
|
+
use style_traits::{CssWriter, ParseError, SpecifiedValueInfo, ToCss};
|
|
21
|
+
use thin_vec::ThinVec;
|
|
22
|
+
|
|
23
|
+
/// A percentage value, where [0 .. 100%] maps to [0.0 .. 1.0]
|
|
24
|
+
#[derive(Clone, Copy, Debug, Default, MallocSizeOf, PartialEq, ToShmem)]
|
|
25
|
+
#[repr(C)]
|
|
26
|
+
pub struct NoCalcPercentage(CSSFloat);
|
|
27
|
+
|
|
28
|
+
impl SpecifiedValueInfo for NoCalcPercentage {}
|
|
29
|
+
|
|
30
|
+
impl ToCss for NoCalcPercentage {
|
|
31
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
32
|
+
where
|
|
33
|
+
W: Write,
|
|
34
|
+
{
|
|
35
|
+
serialize_percentage(self.0, dest)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
impl ToTyped for NoCalcPercentage {
|
|
40
|
+
fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> {
|
|
41
|
+
reify_percentage(self.0, dest)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
impl NoCalcPercentage {
|
|
46
|
+
/// Creates a percentage from a numeric value.
|
|
47
|
+
pub fn new(value: CSSFloat) -> Self {
|
|
48
|
+
Self(value)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// `0%`
|
|
52
|
+
#[inline]
|
|
53
|
+
pub fn zero() -> Self {
|
|
54
|
+
Self::new(0.)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// `100%`
|
|
58
|
+
#[inline]
|
|
59
|
+
pub fn hundred() -> Self {
|
|
60
|
+
Self::new(1.)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/// Gets the underlying value for this float.
|
|
64
|
+
#[inline]
|
|
65
|
+
pub fn get(&self) -> CSSFloat {
|
|
66
|
+
self.0
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/// Return the unit, as a string.
|
|
70
|
+
pub fn unit(&self) -> &'static str {
|
|
71
|
+
"percent"
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// Return no canonical unit (percent values do not have one).
|
|
75
|
+
pub fn canonical_unit(&self) -> Option<&'static str> {
|
|
76
|
+
None
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/// Convert only if the unit is the same (conversion to other units does
|
|
80
|
+
/// not make sense).
|
|
81
|
+
pub fn to(&self, unit: &str) -> Result<Self, ()> {
|
|
82
|
+
if !unit.eq_ignore_ascii_case("percent") {
|
|
83
|
+
return Err(());
|
|
84
|
+
}
|
|
85
|
+
Ok(*self)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
impl ToComputedValue for NoCalcPercentage {
|
|
90
|
+
type ComputedValue = ComputedPercentage;
|
|
91
|
+
|
|
92
|
+
fn to_computed_value(&self, _: &Context) -> Self::ComputedValue {
|
|
93
|
+
ComputedPercentage(normalize(self.get()))
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
|
97
|
+
Self::new(computed.0)
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
impl From<f32> for NoCalcPercentage {
|
|
102
|
+
fn from(value: f32) -> Self {
|
|
103
|
+
Self(value)
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
impl From<NoCalcPercentage> for f32 {
|
|
108
|
+
fn from(percentage: NoCalcPercentage) -> f32 {
|
|
109
|
+
percentage.0
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// A specified percentage value, either a plain value or a `calc()` expression.
|
|
114
|
+
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToShmem)]
|
|
115
|
+
pub struct Percentage(NumericUnion<(), f32, CalcNumeric>);
|
|
116
|
+
|
|
117
|
+
impl ToCss for Percentage {
|
|
118
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
119
|
+
where
|
|
120
|
+
W: Write,
|
|
121
|
+
{
|
|
122
|
+
match self.0.unpack() {
|
|
123
|
+
Unpacked::Inline((), p) => NoCalcPercentage(p).to_css(dest),
|
|
124
|
+
Unpacked::Boxed(calc) => calc.to_css(dest),
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
impl ToTyped for Percentage {
|
|
130
|
+
fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> {
|
|
131
|
+
match self.0.unpack() {
|
|
132
|
+
Unpacked::Inline((), p) => NoCalcPercentage(p).to_typed(dest),
|
|
133
|
+
Unpacked::Boxed(calc) => calc.to_typed(dest),
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
impl Percentage {
|
|
139
|
+
/// Creates a percentage from a numeric value.
|
|
140
|
+
pub fn new(value: CSSFloat) -> Self {
|
|
141
|
+
Self(NumericUnion::inline((), value))
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/// Returns a new percentage calc value with the value `val`.
|
|
145
|
+
#[inline]
|
|
146
|
+
pub fn new_calc(val: Box<CalcNumeric>) -> Self {
|
|
147
|
+
Self(NumericUnion::boxed(val))
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/// `0%`
|
|
151
|
+
#[inline]
|
|
152
|
+
pub fn zero() -> Self {
|
|
153
|
+
Self::new(0.)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/// `100%`
|
|
157
|
+
#[inline]
|
|
158
|
+
pub fn hundred() -> Self {
|
|
159
|
+
Self::new(1.)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/// Returns true if it is a calc percentage.
|
|
163
|
+
#[inline]
|
|
164
|
+
pub fn is_calc(&self) -> bool {
|
|
165
|
+
self.0.is_boxed()
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/// Returns the value if this is a plain (non-calc) percentage, or None otherwise.
|
|
169
|
+
/// Use `resolve()` to also handle resolvable calc expressions, or `to_computed_value()`
|
|
170
|
+
/// when computed context is available.
|
|
171
|
+
#[inline]
|
|
172
|
+
pub fn get(&self) -> Option<f32> {
|
|
173
|
+
match self.0.unpack() {
|
|
174
|
+
Unpacked::Inline((), f) => Some(f),
|
|
175
|
+
Unpacked::Boxed(..) => None,
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/// Returns the value if it can be resolved at parse time, including resolvable calc
|
|
180
|
+
/// expressions. Returns None for calc expressions that require computed context
|
|
181
|
+
/// (e.g. those using relative lengths or sibling-index()).
|
|
182
|
+
#[inline]
|
|
183
|
+
pub fn resolve(&self) -> Option<CSSFloat> {
|
|
184
|
+
match self.0.unpack() {
|
|
185
|
+
Unpacked::Inline((), f) => Some(f),
|
|
186
|
+
Unpacked::Boxed(calc) => calc.as_percentage().map(|p| p.get()),
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/// Returns this percentage as a number.
|
|
191
|
+
pub fn to_number(&self) -> Option<Number> {
|
|
192
|
+
Some(match self.0.unpack() {
|
|
193
|
+
Unpacked::Inline((), p) => Number::new(p),
|
|
194
|
+
Unpacked::Boxed(calc) => {
|
|
195
|
+
let p = calc.as_percentage()?.get();
|
|
196
|
+
Number::new_calc(Box::new(
|
|
197
|
+
calc.with_leaf_node(Leaf::Number(NoCalcNumber::new(p))),
|
|
198
|
+
))
|
|
199
|
+
},
|
|
200
|
+
})
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/// Returns this percentage as a LengthPercentage.
|
|
204
|
+
pub fn to_length_percentage(self) -> LengthPercentage {
|
|
205
|
+
match self.0.extract() {
|
|
206
|
+
Extracted::Inline((), p) => LengthPercentage::Percentage(NoCalcPercentage(p)),
|
|
207
|
+
Extracted::Boxed(calc) => LengthPercentage::Calc(Box::new(CalcLengthPercentage(*calc))),
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/// Reverses this percentage, preserving calc-ness.
|
|
212
|
+
///
|
|
213
|
+
/// For example: If it was 20%, convert it into 80%.
|
|
214
|
+
pub fn reverse(&mut self) {
|
|
215
|
+
match self.0.unpack_mut() {
|
|
216
|
+
UnpackedMut::Inline(_, p) => {
|
|
217
|
+
*p = 1. - *p;
|
|
218
|
+
},
|
|
219
|
+
UnpackedMut::Boxed(calc) => {
|
|
220
|
+
let mut sum = smallvec::SmallVec::<[CalcNode; 2]>::new();
|
|
221
|
+
sum.push(CalcNode::Leaf(Leaf::Percentage(CalcPercentageLeaf::new(
|
|
222
|
+
1.,
|
|
223
|
+
Optional::None,
|
|
224
|
+
))));
|
|
225
|
+
let mut node = calc.node.clone();
|
|
226
|
+
node.negate();
|
|
227
|
+
sum.push(node);
|
|
228
|
+
let mut diff = CalcNode::Sum(sum.into_boxed_slice().into());
|
|
229
|
+
diff.simplify_and_sort();
|
|
230
|
+
calc.node = diff;
|
|
231
|
+
},
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/// Parses a specific kind of percentage.
|
|
236
|
+
pub fn parse_with_clamping_mode(
|
|
237
|
+
context: &ParserContext,
|
|
238
|
+
input: &mut Parser,
|
|
239
|
+
num_context: AllowedNumericType,
|
|
240
|
+
) -> Result<Self, ParseError> {
|
|
241
|
+
Ok(Self(match *input.next()? {
|
|
242
|
+
Token::Percentage { unit_value, .. }
|
|
243
|
+
if num_context.is_ok(context.parsing_mode, unit_value) =>
|
|
244
|
+
{
|
|
245
|
+
NumericUnion::inline((), unit_value)
|
|
246
|
+
},
|
|
247
|
+
Token::Function(ref name) => {
|
|
248
|
+
let function = CalcNode::math_function(context, name)?;
|
|
249
|
+
let calc = CalcNode::parse_percentage(context, input, num_context, function)?;
|
|
250
|
+
NumericUnion::boxed(Box::new(calc))
|
|
251
|
+
},
|
|
252
|
+
_ => return Err(ParseError::unexpected_token()),
|
|
253
|
+
}))
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/// Parses a percentage token, but rejects it if it's negative.
|
|
257
|
+
pub fn parse_non_negative(
|
|
258
|
+
context: &ParserContext,
|
|
259
|
+
input: &mut Parser,
|
|
260
|
+
) -> Result<Self, ParseError> {
|
|
261
|
+
Self::parse_with_clamping_mode(context, input, AllowedNumericType::NonNegative)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/// Parses a percentage token, but rejects it if it's negative or more than
|
|
265
|
+
/// 100%.
|
|
266
|
+
pub fn parse_zero_to_a_hundred(
|
|
267
|
+
context: &ParserContext,
|
|
268
|
+
input: &mut Parser,
|
|
269
|
+
) -> Result<Self, ParseError> {
|
|
270
|
+
Self::parse_with_clamping_mode(context, input, AllowedNumericType::ZeroToOne)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/// Clamp to 100% if the value is over 100%.
|
|
274
|
+
#[inline]
|
|
275
|
+
pub fn clamp_to_hundred(&mut self) {
|
|
276
|
+
match self.0.unpack_mut() {
|
|
277
|
+
UnpackedMut::Inline((), p) => *p = p.min(1.),
|
|
278
|
+
UnpackedMut::Boxed(calc) => {
|
|
279
|
+
calc.clamping_mode = AllowedNumericType::ZeroToOne;
|
|
280
|
+
},
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
impl Parse for Percentage {
|
|
286
|
+
#[inline]
|
|
287
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
288
|
+
Self::parse_with_clamping_mode(context, input, AllowedNumericType::All)
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
impl ToComputedValue for Percentage {
|
|
293
|
+
type ComputedValue = ComputedPercentage;
|
|
294
|
+
|
|
295
|
+
#[inline]
|
|
296
|
+
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
|
297
|
+
match self.0.unpack() {
|
|
298
|
+
Unpacked::Inline((), p) => NoCalcPercentage(p).to_computed_value(context),
|
|
299
|
+
Unpacked::Boxed(calc) => {
|
|
300
|
+
let value = calc.resolve(context, |result| match result {
|
|
301
|
+
Ok(Leaf::Percentage(p)) => p.get(),
|
|
302
|
+
_ => {
|
|
303
|
+
debug_assert!(
|
|
304
|
+
false,
|
|
305
|
+
"Unexpected Percentage::Calc without resolved percentage"
|
|
306
|
+
);
|
|
307
|
+
f32::NAN
|
|
308
|
+
},
|
|
309
|
+
});
|
|
310
|
+
ComputedPercentage(crate::values::normalize(value).min(f32::MAX).max(f32::MIN))
|
|
311
|
+
},
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
#[inline]
|
|
316
|
+
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
|
317
|
+
Percentage::new(computed.0)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
impl SpecifiedValueInfo for Percentage {}
|
|
322
|
+
|
|
323
|
+
/// Turns the percentage into a plain float.
|
|
324
|
+
pub trait ToPercentage {
|
|
325
|
+
/// Returns whether this percentage used to be a calc().
|
|
326
|
+
fn is_calc(&self) -> bool {
|
|
327
|
+
false
|
|
328
|
+
}
|
|
329
|
+
/// Returns the percentage as a plain float, or None for calc expressions that require
|
|
330
|
+
/// computed context. Will always return Some if `is_calc` is false.
|
|
331
|
+
fn to_percentage(&self) -> Option<CSSFloat>;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
impl ToPercentage for Percentage {
|
|
335
|
+
fn is_calc(&self) -> bool {
|
|
336
|
+
self.0.is_boxed()
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
fn to_percentage(&self) -> Option<CSSFloat> {
|
|
340
|
+
self.resolve()
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/// A wrapper of Percentage, whose value must be >= 0.
|
|
345
|
+
pub type NonNegativePercentage = NonNegative<Percentage>;
|
|
346
|
+
|
|
347
|
+
impl Parse for NonNegativePercentage {
|
|
348
|
+
#[inline]
|
|
349
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
350
|
+
Ok(NonNegative(Percentage::parse_non_negative(context, input)?))
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
impl NonNegativePercentage {
|
|
355
|
+
/// Convert to ComputedPercentage, for FontFaceRule size-adjust getter.
|
|
356
|
+
/// Returns None if the value is a calc expression that cannot be resolved at parse time.
|
|
357
|
+
#[inline]
|
|
358
|
+
pub fn compute(&self) -> Option<ComputedPercentage> {
|
|
359
|
+
self.0
|
|
360
|
+
.resolve()
|
|
361
|
+
.map(|f| AllowedNumericType::NonNegative.clamp(f))
|
|
362
|
+
.map(ComputedPercentage)
|
|
363
|
+
}
|
|
364
|
+
}
|