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,11 @@
|
|
|
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 types for the column properties.
|
|
6
|
+
|
|
7
|
+
use crate::values::generics::column::GenericColumnCount;
|
|
8
|
+
use crate::values::specified::PositiveInteger;
|
|
9
|
+
|
|
10
|
+
/// A specified type for `column-count` values.
|
|
11
|
+
pub type ColumnCount = GenericColumnCount<PositiveInteger>;
|
|
@@ -0,0 +1,152 @@
|
|
|
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 types for the `corner-shape` family of properties.
|
|
6
|
+
//!
|
|
7
|
+
//! <https://drafts.csswg.org/css-borders-4/#corner-shaping>
|
|
8
|
+
|
|
9
|
+
use crate::derives::*;
|
|
10
|
+
use crate::parser::{Parse, ParserContext};
|
|
11
|
+
use crate::values::computed::corner_shape as computed;
|
|
12
|
+
use crate::values::computed::{Context, ToComputedValue};
|
|
13
|
+
use crate::values::specified::Number;
|
|
14
|
+
use cssparser::{Parser, Token};
|
|
15
|
+
use style_traits::{ParseError, StyleParseErrorKind};
|
|
16
|
+
|
|
17
|
+
/// The argument to the `superellipse()` function.
|
|
18
|
+
///
|
|
19
|
+
/// `superellipse(K)` defines the corner shape using the unit equation
|
|
20
|
+
/// `x^(2^K) + y^(2^K) = 1`. `infinity` and `-infinity` are accepted as
|
|
21
|
+
/// special-cased keyword arguments.
|
|
22
|
+
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem, ToTyped)]
|
|
23
|
+
#[typed(todo_derive_fields)]
|
|
24
|
+
pub enum SuperellipseArg {
|
|
25
|
+
/// `<number>` argument.
|
|
26
|
+
Number(Number),
|
|
27
|
+
/// The `infinity` keyword.
|
|
28
|
+
Infinity,
|
|
29
|
+
/// The `-infinity` keyword (lexed as the literal text `-infinity`).
|
|
30
|
+
#[css(keyword = "-infinity")]
|
|
31
|
+
NegativeInfinity,
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
impl SuperellipseArg {
|
|
35
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
36
|
+
if let Ok(arg) = input.try_parse(|i| -> Result<SuperellipseArg, ParseError> {
|
|
37
|
+
match i.next()? {
|
|
38
|
+
Token::Ident(ident) if ident.eq_ignore_ascii_case("infinity") => {
|
|
39
|
+
Ok(SuperellipseArg::Infinity)
|
|
40
|
+
},
|
|
41
|
+
Token::Ident(ident) if ident.eq_ignore_ascii_case("-infinity") => {
|
|
42
|
+
Ok(SuperellipseArg::NegativeInfinity)
|
|
43
|
+
},
|
|
44
|
+
_ => Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError)),
|
|
45
|
+
}
|
|
46
|
+
}) {
|
|
47
|
+
return Ok(arg);
|
|
48
|
+
}
|
|
49
|
+
Number::parse(context, input).map(SuperellipseArg::Number)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// Resolve to a numeric `K` value (possibly +/- infinity).
|
|
53
|
+
pub fn to_k(&self, context: &Context) -> f32 {
|
|
54
|
+
match self {
|
|
55
|
+
SuperellipseArg::Infinity => f32::INFINITY,
|
|
56
|
+
SuperellipseArg::NegativeInfinity => f32::NEG_INFINITY,
|
|
57
|
+
SuperellipseArg::Number(n) => n.to_computed_value(context),
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/// The specified value of a single corner-shape (e.g. `corner-top-left-shape`).
|
|
63
|
+
///
|
|
64
|
+
/// <https://drafts.csswg.org/css-borders-4/#typedef-corner-shape-value>
|
|
65
|
+
#[derive(Clone, Debug, MallocSizeOf, PartialEq, SpecifiedValueInfo, ToCss, ToShmem, ToTyped)]
|
|
66
|
+
#[typed(todo_derive_fields)]
|
|
67
|
+
pub enum CornerShape {
|
|
68
|
+
/// `round`, equivalent to `superellipse(1)`. Initial value.
|
|
69
|
+
Round,
|
|
70
|
+
/// `scoop`, equivalent to `superellipse(-1)`.
|
|
71
|
+
Scoop,
|
|
72
|
+
/// `bevel`, equivalent to `superellipse(0)`.
|
|
73
|
+
Bevel,
|
|
74
|
+
/// `notch`, equivalent to `superellipse(-infinity)`.
|
|
75
|
+
Notch,
|
|
76
|
+
/// `square`, equivalent to `superellipse(infinity)`.
|
|
77
|
+
Square,
|
|
78
|
+
/// `squircle`, equivalent to `superellipse(2)`.
|
|
79
|
+
Squircle,
|
|
80
|
+
/// `superellipse(<arg>)`.
|
|
81
|
+
#[css(function)]
|
|
82
|
+
Superellipse(SuperellipseArg),
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
impl CornerShape {
|
|
86
|
+
/// The initial value: `round`.
|
|
87
|
+
#[inline]
|
|
88
|
+
pub fn round() -> Self {
|
|
89
|
+
CornerShape::Round
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
impl Parse for CornerShape {
|
|
94
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
95
|
+
// Try the `superellipse(...)` function first.
|
|
96
|
+
if let Ok(arg) = input.try_parse(|i| {
|
|
97
|
+
i.expect_function_matching("superellipse")?;
|
|
98
|
+
i.parse_nested_block(|i| SuperellipseArg::parse(context, i))
|
|
99
|
+
}) {
|
|
100
|
+
return Ok(CornerShape::Superellipse(arg));
|
|
101
|
+
}
|
|
102
|
+
Ok(try_match_ident_ignore_ascii_case! { input,
|
|
103
|
+
"round" => CornerShape::Round,
|
|
104
|
+
"scoop" => CornerShape::Scoop,
|
|
105
|
+
"bevel" => CornerShape::Bevel,
|
|
106
|
+
"notch" => CornerShape::Notch,
|
|
107
|
+
"square" => CornerShape::Square,
|
|
108
|
+
"squircle" => CornerShape::Squircle,
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
impl ToComputedValue for CornerShape {
|
|
114
|
+
type ComputedValue = computed::CornerShape;
|
|
115
|
+
|
|
116
|
+
fn to_computed_value(&self, context: &Context) -> Self::ComputedValue {
|
|
117
|
+
// Per spec, the computed value is always the corresponding
|
|
118
|
+
// `superellipse(K)` value.
|
|
119
|
+
computed::CornerShape {
|
|
120
|
+
k: match self {
|
|
121
|
+
CornerShape::Round => 1.0,
|
|
122
|
+
CornerShape::Scoop => -1.0,
|
|
123
|
+
CornerShape::Bevel => 0.0,
|
|
124
|
+
CornerShape::Notch => f32::NEG_INFINITY,
|
|
125
|
+
CornerShape::Square => f32::INFINITY,
|
|
126
|
+
CornerShape::Squircle => 2.0,
|
|
127
|
+
CornerShape::Superellipse(arg) => arg.to_k(context),
|
|
128
|
+
},
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
fn from_computed_value(c: &Self::ComputedValue) -> Self {
|
|
133
|
+
let arg = if c.k == f32::INFINITY {
|
|
134
|
+
SuperellipseArg::Infinity
|
|
135
|
+
} else if c.k == f32::NEG_INFINITY {
|
|
136
|
+
SuperellipseArg::NegativeInfinity
|
|
137
|
+
} else {
|
|
138
|
+
SuperellipseArg::Number(Number::new(c.k))
|
|
139
|
+
};
|
|
140
|
+
CornerShape::Superellipse(arg)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/// The specified value of `corner-shape`. Stored per-corner.
|
|
145
|
+
pub type CornerShapeRect = crate::values::generics::border::GenericCornerShapeRect<CornerShape>;
|
|
146
|
+
|
|
147
|
+
impl CornerShapeRect {
|
|
148
|
+
/// Initial value: `round` for all four corners.
|
|
149
|
+
pub fn round() -> Self {
|
|
150
|
+
Self::all(CornerShape::Round)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,242 @@
|
|
|
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 types for counter properties.
|
|
6
|
+
|
|
7
|
+
use crate::counter_style::CounterStyle;
|
|
8
|
+
use crate::parser::{Parse, ParserContext};
|
|
9
|
+
use crate::values::generics::counters as generics;
|
|
10
|
+
use crate::values::generics::counters::CounterPair;
|
|
11
|
+
use crate::values::specified::image::Image;
|
|
12
|
+
use crate::values::specified::Integer;
|
|
13
|
+
use crate::values::CustomIdent;
|
|
14
|
+
use cssparser::{match_ignore_ascii_case, Parser, Token};
|
|
15
|
+
use selectors::parser::SelectorParseErrorKind;
|
|
16
|
+
use style_traits::{ParseError, StyleParseErrorKind};
|
|
17
|
+
|
|
18
|
+
#[derive(PartialEq)]
|
|
19
|
+
enum CounterType {
|
|
20
|
+
Increment,
|
|
21
|
+
Set,
|
|
22
|
+
Reset,
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
impl CounterType {
|
|
26
|
+
fn default_value(&self) -> i32 {
|
|
27
|
+
match *self {
|
|
28
|
+
Self::Increment => 1,
|
|
29
|
+
Self::Reset | Self::Set => 0,
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/// A specified value for the `counter-increment` property.
|
|
35
|
+
pub type CounterIncrement = generics::GenericCounterIncrement<Integer>;
|
|
36
|
+
|
|
37
|
+
impl Parse for CounterIncrement {
|
|
38
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
39
|
+
Ok(Self::new(parse_counters(
|
|
40
|
+
context,
|
|
41
|
+
input,
|
|
42
|
+
CounterType::Increment,
|
|
43
|
+
)?))
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// A specified value for the `counter-set` property.
|
|
48
|
+
pub type CounterSet = generics::GenericCounterSet<Integer>;
|
|
49
|
+
|
|
50
|
+
impl Parse for CounterSet {
|
|
51
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
52
|
+
Ok(Self::new(parse_counters(context, input, CounterType::Set)?))
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// A specified value for the `counter-reset` property.
|
|
57
|
+
pub type CounterReset = generics::GenericCounterReset<Integer>;
|
|
58
|
+
|
|
59
|
+
impl Parse for CounterReset {
|
|
60
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
61
|
+
Ok(Self::new(parse_counters(
|
|
62
|
+
context,
|
|
63
|
+
input,
|
|
64
|
+
CounterType::Reset,
|
|
65
|
+
)?))
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
fn parse_counters(
|
|
70
|
+
context: &ParserContext,
|
|
71
|
+
input: &mut Parser,
|
|
72
|
+
counter_type: CounterType,
|
|
73
|
+
) -> Result<Vec<CounterPair<Integer>>, ParseError> {
|
|
74
|
+
if input
|
|
75
|
+
.try_parse(|input| input.expect_ident_matching("none"))
|
|
76
|
+
.is_ok()
|
|
77
|
+
{
|
|
78
|
+
return Ok(vec![]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
let mut counters = Vec::new();
|
|
82
|
+
loop {
|
|
83
|
+
let (name, is_reversed) = match input.next() {
|
|
84
|
+
Ok(Token::Ident(ident)) => (CustomIdent::from_ident(ident, &["none"])?, false),
|
|
85
|
+
Ok(Token::Function(name))
|
|
86
|
+
if counter_type == CounterType::Reset && name.eq_ignore_ascii_case("reversed") =>
|
|
87
|
+
{
|
|
88
|
+
input
|
|
89
|
+
.parse_nested_block(|input| Ok((CustomIdent::parse(input, &["none"])?, true)))?
|
|
90
|
+
},
|
|
91
|
+
Ok(..) => {
|
|
92
|
+
return Err(ParseError::unexpected_token());
|
|
93
|
+
},
|
|
94
|
+
Err(_) => break,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
let value = match input.try_parse(|input| Integer::parse(context, input)) {
|
|
98
|
+
Ok(start) => {
|
|
99
|
+
if start.get() == Some(i32::MIN) {
|
|
100
|
+
// The spec says that values must be clamped to the valid range,
|
|
101
|
+
// and we reserve i32::MIN as an internal magic value.
|
|
102
|
+
// https://drafts.csswg.org/css-lists/#auto-numbering
|
|
103
|
+
Integer::new(i32::MIN + 1)
|
|
104
|
+
} else {
|
|
105
|
+
start
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
_ => Integer::new(if is_reversed {
|
|
109
|
+
i32::MIN
|
|
110
|
+
} else {
|
|
111
|
+
counter_type.default_value()
|
|
112
|
+
}),
|
|
113
|
+
};
|
|
114
|
+
counters.push(CounterPair {
|
|
115
|
+
name,
|
|
116
|
+
value,
|
|
117
|
+
is_reversed,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if !counters.is_empty() {
|
|
122
|
+
Ok(counters)
|
|
123
|
+
} else {
|
|
124
|
+
Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError))
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/// The specified value for the `content` property.
|
|
129
|
+
pub type Content = generics::GenericContent<Image>;
|
|
130
|
+
|
|
131
|
+
/// The specified value for a content item in the `content` property.
|
|
132
|
+
pub type ContentItem = generics::GenericContentItem<Image>;
|
|
133
|
+
|
|
134
|
+
impl Content {
|
|
135
|
+
fn parse_counter_style(context: &ParserContext, input: &mut Parser) -> CounterStyle {
|
|
136
|
+
use crate::counter_style::CounterStyleParsingFlags;
|
|
137
|
+
input
|
|
138
|
+
.try_parse(|input| {
|
|
139
|
+
input.expect_comma()?;
|
|
140
|
+
CounterStyle::parse(context, input, CounterStyleParsingFlags::empty())
|
|
141
|
+
})
|
|
142
|
+
.unwrap_or_else(|_| CounterStyle::decimal())
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
impl Parse for Content {
|
|
147
|
+
// normal | none | [ <string> | <counter> | open-quote | close-quote | no-open-quote |
|
|
148
|
+
// no-close-quote ]+
|
|
149
|
+
#[cfg_attr(feature = "servo", allow(unused_mut))]
|
|
150
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
151
|
+
if input
|
|
152
|
+
.try_parse(|input| input.expect_ident_matching("normal"))
|
|
153
|
+
.is_ok()
|
|
154
|
+
{
|
|
155
|
+
return Ok(generics::Content::Normal);
|
|
156
|
+
}
|
|
157
|
+
if input
|
|
158
|
+
.try_parse(|input| input.expect_ident_matching("none"))
|
|
159
|
+
.is_ok()
|
|
160
|
+
{
|
|
161
|
+
return Ok(generics::Content::None);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let mut items = thin_vec::ThinVec::new();
|
|
165
|
+
let mut alt_start = None;
|
|
166
|
+
loop {
|
|
167
|
+
if alt_start.is_none() {
|
|
168
|
+
if let Ok(image) = input.try_parse(|i| Image::parse_forbid_none(context, i)) {
|
|
169
|
+
items.push(generics::ContentItem::Image(image));
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
let Ok(t) = input.next() else { break };
|
|
174
|
+
match *t {
|
|
175
|
+
Token::QuotedString(ref value) => {
|
|
176
|
+
items.push(generics::ContentItem::String(
|
|
177
|
+
value.as_ref().to_owned().into(),
|
|
178
|
+
));
|
|
179
|
+
},
|
|
180
|
+
Token::Function(ref name) => {
|
|
181
|
+
// FIXME(emilio): counter() / counters() should be valid per spec past
|
|
182
|
+
// the alt marker, but it's likely non-trivial to support and other
|
|
183
|
+
// browsers don't support it either, so restricting it for now.
|
|
184
|
+
let result = match_ignore_ascii_case! { &name,
|
|
185
|
+
"counter" if alt_start.is_none() => input.parse_nested_block(|input| {
|
|
186
|
+
let name = CustomIdent::parse(input, &[])?;
|
|
187
|
+
let style = Content::parse_counter_style(context, input);
|
|
188
|
+
Ok(generics::ContentItem::Counter(name, style))
|
|
189
|
+
}),
|
|
190
|
+
"counters" if alt_start.is_none() => input.parse_nested_block(|input| {
|
|
191
|
+
let name = CustomIdent::parse(input, &[])?;
|
|
192
|
+
input.expect_comma()?;
|
|
193
|
+
let separator = input.expect_string()?.as_ref().to_owned().into();
|
|
194
|
+
let style = Content::parse_counter_style(context, input);
|
|
195
|
+
Ok(generics::ContentItem::Counters(name, separator, style))
|
|
196
|
+
}),
|
|
197
|
+
_ => {
|
|
198
|
+
use style_traits::StyleParseErrorKind;
|
|
199
|
+
return Err(ParseError::custom(
|
|
200
|
+
StyleParseErrorKind::UnexpectedFunction,
|
|
201
|
+
))
|
|
202
|
+
}
|
|
203
|
+
}?;
|
|
204
|
+
items.push(result);
|
|
205
|
+
},
|
|
206
|
+
Token::Ident(ref ident) if alt_start.is_none() => {
|
|
207
|
+
items.push(match_ignore_ascii_case! { &ident,
|
|
208
|
+
"open-quote" => generics::ContentItem::OpenQuote,
|
|
209
|
+
"close-quote" => generics::ContentItem::CloseQuote,
|
|
210
|
+
"no-open-quote" => generics::ContentItem::NoOpenQuote,
|
|
211
|
+
"no-close-quote" => generics::ContentItem::NoCloseQuote,
|
|
212
|
+
#[cfg(feature = "gecko")]
|
|
213
|
+
"-moz-alt-content" if context.in_ua_sheet() => {
|
|
214
|
+
generics::ContentItem::MozAltContent
|
|
215
|
+
},
|
|
216
|
+
#[cfg(feature = "gecko")]
|
|
217
|
+
"-moz-label-content" if context.chrome_rules_enabled() => {
|
|
218
|
+
generics::ContentItem::MozLabelContent
|
|
219
|
+
},
|
|
220
|
+
_ =>{
|
|
221
|
+
return Err(ParseError::custom(
|
|
222
|
+
SelectorParseErrorKind::UnexpectedIdent
|
|
223
|
+
));
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
},
|
|
227
|
+
Token::Delim('/') if alt_start.is_none() && !items.is_empty() => {
|
|
228
|
+
alt_start = Some(items.len());
|
|
229
|
+
},
|
|
230
|
+
_ => return Err(ParseError::unexpected_token()),
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
if items.is_empty() {
|
|
234
|
+
return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
|
|
235
|
+
}
|
|
236
|
+
let alt_start = alt_start.unwrap_or(items.len());
|
|
237
|
+
Ok(generics::Content::Items(generics::GenericContentItems {
|
|
238
|
+
items,
|
|
239
|
+
alt_start,
|
|
240
|
+
}))
|
|
241
|
+
}
|
|
242
|
+
}
|
|
@@ -0,0 +1,225 @@
|
|
|
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 types for CSS Easing functions.
|
|
6
|
+
use crate::parser::{Parse, ParserContext};
|
|
7
|
+
use crate::piecewise_linear::{PiecewiseLinearFunction, PiecewiseLinearFunctionBuilder};
|
|
8
|
+
use crate::values::computed::easing::TimingFunction as ComputedTimingFunction;
|
|
9
|
+
use crate::values::computed::{Context, ToComputedValue};
|
|
10
|
+
use crate::values::generics::easing::TimingFunction as GenericTimingFunction;
|
|
11
|
+
use crate::values::generics::easing::{StepPosition, TimingKeyword};
|
|
12
|
+
use crate::values::specified::percentage::ToPercentage;
|
|
13
|
+
use crate::values::specified::{AnimationName, Integer, Number, Percentage};
|
|
14
|
+
use cssparser::{match_ignore_ascii_case, Delimiter, Parser, Token};
|
|
15
|
+
use selectors::parser::SelectorParseErrorKind;
|
|
16
|
+
use style_traits::{ParseError, StyleParseErrorKind};
|
|
17
|
+
|
|
18
|
+
/// A specified timing function.
|
|
19
|
+
pub type TimingFunction = GenericTimingFunction<Integer, Number, PiecewiseLinearFunction>;
|
|
20
|
+
|
|
21
|
+
impl Parse for TimingFunction {
|
|
22
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
23
|
+
if let Ok(keyword) = input.try_parse(TimingKeyword::parse) {
|
|
24
|
+
return Ok(GenericTimingFunction::Keyword(keyword));
|
|
25
|
+
}
|
|
26
|
+
if let Ok(ident) = input.try_parse(|i| i.expect_ident_cloned()) {
|
|
27
|
+
let position = match_ignore_ascii_case! { &ident,
|
|
28
|
+
"step-start" => StepPosition::Start,
|
|
29
|
+
"step-end" => StepPosition::End,
|
|
30
|
+
_ => {
|
|
31
|
+
return Err(ParseError::custom(
|
|
32
|
+
SelectorParseErrorKind::UnexpectedIdent
|
|
33
|
+
));
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
return Ok(GenericTimingFunction::Steps(Integer::new(1), position));
|
|
37
|
+
}
|
|
38
|
+
let function = input.expect_function()?.clone();
|
|
39
|
+
input.parse_nested_block(move |i| {
|
|
40
|
+
match_ignore_ascii_case! { &function,
|
|
41
|
+
"cubic-bezier" => Self::parse_cubic_bezier(context, i),
|
|
42
|
+
"steps" => Self::parse_steps(context, i),
|
|
43
|
+
"linear" => Self::parse_linear_function(context, i),
|
|
44
|
+
_ => Err(ParseError::custom(StyleParseErrorKind::UnexpectedFunction)),
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
impl TimingFunction {
|
|
51
|
+
fn parse_cubic_bezier(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
52
|
+
let x1 = Number::parse(context, input)?;
|
|
53
|
+
input.expect_comma()?;
|
|
54
|
+
let y1 = Number::parse(context, input)?;
|
|
55
|
+
input.expect_comma()?;
|
|
56
|
+
let x2 = Number::parse(context, input)?;
|
|
57
|
+
input.expect_comma()?;
|
|
58
|
+
let y2 = Number::parse(context, input)?;
|
|
59
|
+
|
|
60
|
+
// TODO(Bug 2037743) - Enable calc()-expressions that can only be resolved at
|
|
61
|
+
// computed value time (due to relative lengths, sibling-index(), etc.).
|
|
62
|
+
if let (Some(x1), Some(_), Some(x2), Some(_)) =
|
|
63
|
+
(x1.resolve(), y1.resolve(), x2.resolve(), y2.resolve())
|
|
64
|
+
{
|
|
65
|
+
if !(0.0..=1.0).contains(&x1) || !(0.0..=1.0).contains(&x2) {
|
|
66
|
+
return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
Ok(GenericTimingFunction::CubicBezier { x1, y1, x2, y2 })
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
fn parse_steps(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
76
|
+
let steps = Integer::parse_positive(context, input)?;
|
|
77
|
+
let position = input
|
|
78
|
+
.try_parse(|i| {
|
|
79
|
+
i.expect_comma()?;
|
|
80
|
+
StepPosition::parse(i)
|
|
81
|
+
})
|
|
82
|
+
.unwrap_or(StepPosition::End);
|
|
83
|
+
|
|
84
|
+
// TODO(Bug 2037743) - Enable calc()-expressions that can only be resolved at
|
|
85
|
+
// computed value time (due to relative lengths, sibling-index(), etc.).
|
|
86
|
+
let num_steps = match steps.resolve() {
|
|
87
|
+
Some(v) => v,
|
|
88
|
+
None => return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError)),
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// jump-none accepts a positive integer greater than 1.
|
|
92
|
+
// FIXME(emilio): The spec asks us to avoid rejecting it at parse
|
|
93
|
+
// time except until computed value time.
|
|
94
|
+
//
|
|
95
|
+
// It's not totally clear it's worth it though, and no other browser
|
|
96
|
+
// does this.
|
|
97
|
+
if position == StepPosition::JumpNone && num_steps <= 1 {
|
|
98
|
+
return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
|
|
99
|
+
}
|
|
100
|
+
Ok(GenericTimingFunction::Steps(steps, position))
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
fn parse_linear_function(
|
|
104
|
+
context: &ParserContext,
|
|
105
|
+
input: &mut Parser,
|
|
106
|
+
) -> Result<Self, ParseError> {
|
|
107
|
+
let mut builder = PiecewiseLinearFunctionBuilder::default();
|
|
108
|
+
let mut num_specified_stops = 0;
|
|
109
|
+
// Closely follows `parse_comma_separated`, but can generate multiple entries for one comma-separated entry.
|
|
110
|
+
loop {
|
|
111
|
+
input.parse_until_before(Delimiter::Comma, |i| {
|
|
112
|
+
let builder = &mut builder;
|
|
113
|
+
let mut input_start = i.try_parse(|i| Percentage::parse(context, i)).ok();
|
|
114
|
+
let mut input_end = i.try_parse(|i| Percentage::parse(context, i)).ok();
|
|
115
|
+
|
|
116
|
+
let output = Number::parse(context, i)?;
|
|
117
|
+
if input_start.is_none() {
|
|
118
|
+
debug_assert!(input_end.is_none(), "Input end parsed without input start?");
|
|
119
|
+
input_start = i.try_parse(|i| Percentage::parse(context, i)).ok();
|
|
120
|
+
input_end = i.try_parse(|i| Percentage::parse(context, i)).ok();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// TODO(Bug 2037743) - Enable calc()-expressions that can only be resolved at
|
|
124
|
+
// computed value time (due to relative lengths, sibling-index(), etc.).
|
|
125
|
+
let output = match output.resolve() {
|
|
126
|
+
Some(v) => v,
|
|
127
|
+
None => return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError)),
|
|
128
|
+
};
|
|
129
|
+
if matches!(input_start.as_ref().or(input_end.as_ref()), Some(p) if p.resolve().is_none()) {
|
|
130
|
+
return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
let has_input_start = input_start.is_some();
|
|
134
|
+
builder.push(
|
|
135
|
+
output,
|
|
136
|
+
input_start.map(|v| v.to_percentage().unwrap()),
|
|
137
|
+
);
|
|
138
|
+
num_specified_stops += 1;
|
|
139
|
+
if input_end.is_some() {
|
|
140
|
+
debug_assert!(has_input_start, "Input end valid but not input start?");
|
|
141
|
+
builder.push(output, input_end.map(|v| v.to_percentage().unwrap()));
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
Ok(())
|
|
145
|
+
})?;
|
|
146
|
+
|
|
147
|
+
match input.next() {
|
|
148
|
+
Err(_) => break,
|
|
149
|
+
Ok(&Token::Comma) => continue,
|
|
150
|
+
Ok(_) => unreachable!(),
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
// By spec, specifying only a single stop makes the function invalid, even if that single entry may generate
|
|
154
|
+
// two entries.
|
|
155
|
+
if num_specified_stops < 2 {
|
|
156
|
+
return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
Ok(GenericTimingFunction::LinearFunction(builder.build()))
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/// Returns true if the name matches any keyword.
|
|
163
|
+
#[inline]
|
|
164
|
+
pub fn match_keywords(name: &AnimationName) -> bool {
|
|
165
|
+
if let Some(name) = name.as_atom() {
|
|
166
|
+
#[cfg(feature = "gecko")]
|
|
167
|
+
return name.with_str(|n| TimingKeyword::from_ident(n).is_ok());
|
|
168
|
+
#[cfg(feature = "servo")]
|
|
169
|
+
return TimingKeyword::from_ident(name).is_ok();
|
|
170
|
+
}
|
|
171
|
+
false
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// We need this for converting the specified TimingFunction into computed TimingFunction without
|
|
176
|
+
// Context (for some FFIs in glue.rs). In fact, we don't really need Context to get the computed
|
|
177
|
+
// value of TimingFunction.
|
|
178
|
+
impl TimingFunction {
|
|
179
|
+
/// Generate the ComputedTimingFunction without Context.
|
|
180
|
+
pub fn to_computed_value_without_context(&self) -> ComputedTimingFunction {
|
|
181
|
+
match &self {
|
|
182
|
+
GenericTimingFunction::Steps(steps, pos) => {
|
|
183
|
+
// Resolvable value was enforced at parse time
|
|
184
|
+
GenericTimingFunction::Steps(steps.resolve().unwrap(), *pos)
|
|
185
|
+
},
|
|
186
|
+
GenericTimingFunction::CubicBezier { x1, y1, x2, y2 } => {
|
|
187
|
+
// Resolvable value was enforced at parse time
|
|
188
|
+
GenericTimingFunction::CubicBezier {
|
|
189
|
+
x1: x1.resolve().unwrap(),
|
|
190
|
+
y1: y1.resolve().unwrap(),
|
|
191
|
+
x2: x2.resolve().unwrap(),
|
|
192
|
+
y2: y2.resolve().unwrap(),
|
|
193
|
+
}
|
|
194
|
+
},
|
|
195
|
+
GenericTimingFunction::Keyword(keyword) => GenericTimingFunction::Keyword(*keyword),
|
|
196
|
+
GenericTimingFunction::LinearFunction(function) => {
|
|
197
|
+
// Resolvable value was enforced at parse time
|
|
198
|
+
GenericTimingFunction::LinearFunction(function.clone())
|
|
199
|
+
},
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
impl ToComputedValue for TimingFunction {
|
|
205
|
+
type ComputedValue = ComputedTimingFunction;
|
|
206
|
+
fn to_computed_value(&self, _: &Context) -> Self::ComputedValue {
|
|
207
|
+
self.to_computed_value_without_context()
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
fn from_computed_value(computed: &Self::ComputedValue) -> Self {
|
|
211
|
+
match &computed {
|
|
212
|
+
ComputedTimingFunction::Steps(steps, pos) => Self::Steps(Integer::new(*steps), *pos),
|
|
213
|
+
ComputedTimingFunction::CubicBezier { x1, y1, x2, y2 } => Self::CubicBezier {
|
|
214
|
+
x1: Number::new(*x1),
|
|
215
|
+
y1: Number::new(*y1),
|
|
216
|
+
x2: Number::new(*x2),
|
|
217
|
+
y2: Number::new(*y2),
|
|
218
|
+
},
|
|
219
|
+
ComputedTimingFunction::Keyword(keyword) => GenericTimingFunction::Keyword(*keyword),
|
|
220
|
+
ComputedTimingFunction::LinearFunction(function) => {
|
|
221
|
+
GenericTimingFunction::LinearFunction(function.clone())
|
|
222
|
+
},
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|