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,334 @@
|
|
|
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
|
+
//! Computed-value calc() leaf types.
|
|
6
|
+
|
|
7
|
+
use super::{Angle, Length, Number, Percentage, Resolution, Time};
|
|
8
|
+
use crate::derives::*;
|
|
9
|
+
use crate::typed_om::{NumericBaseType, NumericType};
|
|
10
|
+
use crate::values::generics::calc::{
|
|
11
|
+
self, CalcType, GenericCalcPercentageLeaf, SimplificationResult,
|
|
12
|
+
};
|
|
13
|
+
use crate::values::generics::Optional;
|
|
14
|
+
use crate::Zero;
|
|
15
|
+
use debug_unreachable::debug_unreachable;
|
|
16
|
+
use serde::{Deserialize, Serialize};
|
|
17
|
+
|
|
18
|
+
/// The value of a percentage leaf node that contains an associated percent hint.
|
|
19
|
+
pub type CalcPercentageLeaf = GenericCalcPercentageLeaf<Percentage>;
|
|
20
|
+
|
|
21
|
+
/// The computed leaf of a calc() expression.
|
|
22
|
+
#[derive(
|
|
23
|
+
Clone,
|
|
24
|
+
Debug,
|
|
25
|
+
Deserialize,
|
|
26
|
+
MallocSizeOf,
|
|
27
|
+
PartialEq,
|
|
28
|
+
Serialize,
|
|
29
|
+
ToAnimatedZero,
|
|
30
|
+
ToCss,
|
|
31
|
+
ToResolvedValue,
|
|
32
|
+
ToTyped,
|
|
33
|
+
)]
|
|
34
|
+
#[allow(missing_docs)]
|
|
35
|
+
#[repr(u8)]
|
|
36
|
+
pub enum ComputedLeaf {
|
|
37
|
+
Length(Length),
|
|
38
|
+
Percentage(CalcPercentageLeaf),
|
|
39
|
+
Number(Number),
|
|
40
|
+
Angle(Angle),
|
|
41
|
+
Time(Time),
|
|
42
|
+
Resolution(Resolution),
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
impl ComputedLeaf {
|
|
46
|
+
pub(super) fn is_zero_length(&self) -> bool {
|
|
47
|
+
match *self {
|
|
48
|
+
Self::Length(ref l) => l.is_zero(),
|
|
49
|
+
Self::Percentage(..)
|
|
50
|
+
| Self::Number(..)
|
|
51
|
+
| Self::Angle(..)
|
|
52
|
+
| Self::Time(..)
|
|
53
|
+
| Self::Resolution(..) => false,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
impl calc::CalcNodeLeaf for ComputedLeaf {
|
|
59
|
+
fn numeric_type(&self) -> NumericType {
|
|
60
|
+
match self {
|
|
61
|
+
Self::Length(_) => NumericType::length(),
|
|
62
|
+
Self::Percentage(p) => p.numeric_type(),
|
|
63
|
+
Self::Number(_) => NumericType::number(),
|
|
64
|
+
Self::Angle(_) => NumericType::angle(),
|
|
65
|
+
Self::Time(_) => NumericType::time(),
|
|
66
|
+
Self::Resolution(_) => NumericType::resolution(),
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
fn unitless_value(&self) -> Option<f32> {
|
|
71
|
+
Some(match *self {
|
|
72
|
+
Self::Length(ref l) => l.px(),
|
|
73
|
+
Self::Percentage(ref p) => p.get(),
|
|
74
|
+
Self::Number(n) => n,
|
|
75
|
+
Self::Angle(ref a) => a.degrees(),
|
|
76
|
+
Self::Time(ref t) => t.seconds(),
|
|
77
|
+
Self::Resolution(ref r) => r.dppx(),
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
fn canonical_value(&self) -> Option<f32> {
|
|
82
|
+
Some(match *self {
|
|
83
|
+
Self::Length(ref l) => l.px(),
|
|
84
|
+
Self::Percentage(ref p) => match p.hint {
|
|
85
|
+
// Percentages that are relative to some other value (indicated by a
|
|
86
|
+
// percent hint other than "percent") cannot yet resolve to a numeric
|
|
87
|
+
// value, as the percentage's basis is not available.
|
|
88
|
+
Optional::Some(NumericBaseType::Percent) => p.get(),
|
|
89
|
+
_ => return None,
|
|
90
|
+
},
|
|
91
|
+
Self::Number(n) => n,
|
|
92
|
+
Self::Angle(ref a) => a.degrees(),
|
|
93
|
+
Self::Time(ref t) => t.seconds(),
|
|
94
|
+
Self::Resolution(ref r) => r.dppx(),
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
fn new_number(value: f32) -> Self {
|
|
99
|
+
Self::Number(value)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
fn as_number(&self) -> Option<f32> {
|
|
103
|
+
match *self {
|
|
104
|
+
Self::Length(_)
|
|
105
|
+
| Self::Percentage(_)
|
|
106
|
+
| Self::Angle(_)
|
|
107
|
+
| Self::Time(_)
|
|
108
|
+
| Self::Resolution(_) => None,
|
|
109
|
+
Self::Number(value) => Some(value),
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fn as_percentage(&self) -> Option<(f32, Optional<NumericBaseType>)> {
|
|
114
|
+
match *self {
|
|
115
|
+
Self::Percentage(p) => Some((p.get(), p.hint)),
|
|
116
|
+
_ => None,
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
fn as_angle_radians(&self) -> Option<f32> {
|
|
121
|
+
match *self {
|
|
122
|
+
Self::Angle(a) => Some(a.radians()),
|
|
123
|
+
_ => None,
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
fn new_angle_from_radians(radians: f32) -> Self {
|
|
128
|
+
Self::Angle(Angle::from_radians(radians))
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
fn new_from_typed_value(value: f32, numeric_type: NumericType) -> Result<Self, ()> {
|
|
132
|
+
let calc_type = numeric_type.as_calc_type()?;
|
|
133
|
+
let percent_hint = numeric_type.percent_hint();
|
|
134
|
+
Ok(match calc_type {
|
|
135
|
+
CalcType::Number => Self::new_number(value),
|
|
136
|
+
CalcType::Length => Self::Length(Length::new(value)),
|
|
137
|
+
CalcType::Angle => Self::Angle(Angle::from_degrees(value)),
|
|
138
|
+
CalcType::Time => Self::Time(Time::from_seconds(value)),
|
|
139
|
+
CalcType::Resolution => Self::Resolution(Resolution::from_dppx(value)),
|
|
140
|
+
CalcType::Percentage => Self::Percentage(CalcPercentageLeaf::new(value, percent_hint)),
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
fn compare(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
|
145
|
+
use self::ComputedLeaf::*;
|
|
146
|
+
if std::mem::discriminant(self) != std::mem::discriminant(other) {
|
|
147
|
+
return None;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Percentages that resolve against some other basis value cannot be meaningfully compared.
|
|
151
|
+
if matches!(self, Percentage(p) if p.hint != Optional::Some(NumericBaseType::Percent)) {
|
|
152
|
+
return None;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let Ok(self_negative) = self.is_negative() else {
|
|
156
|
+
return None;
|
|
157
|
+
};
|
|
158
|
+
let Ok(other_negative) = other.is_negative() else {
|
|
159
|
+
return None;
|
|
160
|
+
};
|
|
161
|
+
if self_negative != other_negative {
|
|
162
|
+
return Some(if self_negative {
|
|
163
|
+
std::cmp::Ordering::Less
|
|
164
|
+
} else {
|
|
165
|
+
std::cmp::Ordering::Greater
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
match (self, other) {
|
|
170
|
+
(Length(one), Length(other)) => one.partial_cmp(other),
|
|
171
|
+
(Percentage(one), Percentage(other)) => one.value.partial_cmp(&other.value),
|
|
172
|
+
(Number(one), Number(other)) => one.partial_cmp(other),
|
|
173
|
+
(Angle(one), Angle(other)) => one.partial_cmp(other),
|
|
174
|
+
(Time(one), Time(other)) => one.partial_cmp(other),
|
|
175
|
+
(Resolution(one), Resolution(other)) => one.partial_cmp(other),
|
|
176
|
+
_ => unsafe {
|
|
177
|
+
match *self {
|
|
178
|
+
Length(..) | Percentage(..) | Number(..) | Angle(..) | Time(..)
|
|
179
|
+
| Resolution(..) => {},
|
|
180
|
+
}
|
|
181
|
+
debug_unreachable!("Forgot to handle unit in compare()")
|
|
182
|
+
},
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
fn try_sum_in_place(&mut self, other: &Self) -> Result<(), ()> {
|
|
187
|
+
use self::ComputedLeaf::*;
|
|
188
|
+
|
|
189
|
+
// 0px plus anything else is equal to the right hand side.
|
|
190
|
+
if self.is_zero_length() {
|
|
191
|
+
*self = other.clone();
|
|
192
|
+
return Ok(());
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if other.is_zero_length() {
|
|
196
|
+
return Ok(());
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
if std::mem::discriminant(self) != std::mem::discriminant(other) {
|
|
200
|
+
return Err(());
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
match (self, other) {
|
|
204
|
+
(&mut Length(ref mut one), Length(other)) => {
|
|
205
|
+
*one += *other;
|
|
206
|
+
},
|
|
207
|
+
(&mut Percentage(ref mut one), Percentage(other)) => {
|
|
208
|
+
*one = CalcPercentageLeaf::new(one.get() + other.get(), one.combined_hint(other));
|
|
209
|
+
},
|
|
210
|
+
(&mut Number(ref mut one), Number(other)) => {
|
|
211
|
+
*one += *other;
|
|
212
|
+
},
|
|
213
|
+
(&mut Angle(ref mut one), Angle(other)) => {
|
|
214
|
+
*one += *other;
|
|
215
|
+
},
|
|
216
|
+
(&mut Time(ref mut one), Time(other)) => {
|
|
217
|
+
*one += *other;
|
|
218
|
+
},
|
|
219
|
+
(&mut Resolution(ref mut one), Resolution(other)) => {
|
|
220
|
+
*one += *other;
|
|
221
|
+
},
|
|
222
|
+
_ => unsafe {
|
|
223
|
+
match *other {
|
|
224
|
+
Length(..) | Percentage(..) | Number(..) | Angle(..) | Time(..)
|
|
225
|
+
| Resolution(..) => {},
|
|
226
|
+
}
|
|
227
|
+
debug_unreachable!("Forgot to handle unit in try_sum_in_place()")
|
|
228
|
+
},
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
Ok(())
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
fn try_product_in_place(&mut self, other: &mut Self) -> bool {
|
|
235
|
+
if let Self::Number(ref mut left) = *self {
|
|
236
|
+
if let Self::Number(ref right) = *other {
|
|
237
|
+
// Both sides are numbers, so we can just modify the left side.
|
|
238
|
+
*left *= *right;
|
|
239
|
+
true
|
|
240
|
+
} else {
|
|
241
|
+
// The right side is not a number, so the result should be in the units of the right
|
|
242
|
+
// side.
|
|
243
|
+
if other.map(|v| v * *left).is_ok() {
|
|
244
|
+
std::mem::swap(self, other);
|
|
245
|
+
true
|
|
246
|
+
} else {
|
|
247
|
+
false
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
} else if let Self::Number(ref right) = *other {
|
|
251
|
+
// The left side is not a number, but the right side is, so the result is the left
|
|
252
|
+
// side unit.
|
|
253
|
+
self.map(|v| v * *right).is_ok()
|
|
254
|
+
} else {
|
|
255
|
+
// Neither side is a number, so a product is not possible.
|
|
256
|
+
false
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
fn try_op<O>(&self, other: &Self, op: O) -> Result<Self, ()>
|
|
261
|
+
where
|
|
262
|
+
O: Fn(f32, f32) -> f32,
|
|
263
|
+
{
|
|
264
|
+
use self::ComputedLeaf::*;
|
|
265
|
+
if std::mem::discriminant(self) != std::mem::discriminant(other) {
|
|
266
|
+
return Err(());
|
|
267
|
+
}
|
|
268
|
+
Ok(match (self, other) {
|
|
269
|
+
(Length(one), Length(other)) => Length(super::Length::new(op(one.px(), other.px()))),
|
|
270
|
+
(Percentage(one), Percentage(other)) => Self::Percentage(CalcPercentageLeaf::new(
|
|
271
|
+
op(one.get(), other.get()),
|
|
272
|
+
one.combined_hint(other),
|
|
273
|
+
)),
|
|
274
|
+
(&Number(one), &Number(other)) => Self::Number(op(one, other)),
|
|
275
|
+
(Angle(one), Angle(other)) => Self::Angle(super::Angle::from_degrees(op(
|
|
276
|
+
one.degrees(),
|
|
277
|
+
other.degrees(),
|
|
278
|
+
))),
|
|
279
|
+
(Time(one), Time(other)) => Self::Time(super::Time::from_seconds(op(
|
|
280
|
+
one.seconds(),
|
|
281
|
+
other.seconds(),
|
|
282
|
+
))),
|
|
283
|
+
(Resolution(one), Resolution(other)) => {
|
|
284
|
+
Self::Resolution(super::Resolution::from_dppx(op(one.dppx(), other.dppx())))
|
|
285
|
+
},
|
|
286
|
+
_ => unsafe {
|
|
287
|
+
match *self {
|
|
288
|
+
Length(..) | Percentage(..) | Number(..) | Angle(..) | Time(..)
|
|
289
|
+
| Resolution(..) => {},
|
|
290
|
+
}
|
|
291
|
+
debug_unreachable!("Forgot to handle unit in try_op()")
|
|
292
|
+
},
|
|
293
|
+
})
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
fn map(&mut self, mut op: impl FnMut(f32) -> f32) -> Result<(), ()> {
|
|
297
|
+
let _: () = match self {
|
|
298
|
+
Self::Length(value) => {
|
|
299
|
+
*value = Length::new(op(value.px()));
|
|
300
|
+
},
|
|
301
|
+
Self::Percentage(p) => {
|
|
302
|
+
*p = CalcPercentageLeaf::new(op(p.get()), p.hint);
|
|
303
|
+
},
|
|
304
|
+
Self::Number(value) => {
|
|
305
|
+
*value = op(*value);
|
|
306
|
+
},
|
|
307
|
+
Self::Angle(value) => {
|
|
308
|
+
*value = Angle::from_degrees(op(value.degrees()));
|
|
309
|
+
},
|
|
310
|
+
Self::Time(value) => {
|
|
311
|
+
*value = Time::from_seconds(op(value.seconds()));
|
|
312
|
+
},
|
|
313
|
+
Self::Resolution(value) => {
|
|
314
|
+
*value = Resolution::from_dppx(op(value.dppx()));
|
|
315
|
+
},
|
|
316
|
+
};
|
|
317
|
+
Ok(())
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
fn simplify(&mut self) -> SimplificationResult {
|
|
321
|
+
SimplificationResult::Unchanged
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
fn sort_key(&self) -> calc::SortKey {
|
|
325
|
+
match *self {
|
|
326
|
+
Self::Length(..) => calc::SortKey::Px,
|
|
327
|
+
Self::Percentage(..) => calc::SortKey::Percentage,
|
|
328
|
+
Self::Number(..) => calc::SortKey::Number,
|
|
329
|
+
Self::Angle(..) => calc::SortKey::Deg,
|
|
330
|
+
Self::Time(..) => calc::SortKey::S,
|
|
331
|
+
Self::Resolution(..) => calc::SortKey::Dppx,
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
//! Computed color values.
|
|
6
|
+
|
|
7
|
+
use crate::color::AbsoluteColor;
|
|
8
|
+
use crate::typed_om::{KeywordValue, ToTyped, TypedValue};
|
|
9
|
+
use crate::values::animated::ToAnimatedZero;
|
|
10
|
+
use crate::values::computed::percentage::Percentage;
|
|
11
|
+
use crate::values::generics::color::{
|
|
12
|
+
GenericCaretColor, GenericColor, GenericColorMix, GenericColorOrAuto,
|
|
13
|
+
};
|
|
14
|
+
use std::fmt::{self, Write};
|
|
15
|
+
use style_traits::{CssString, CssWriter, ToCss};
|
|
16
|
+
use thin_vec::ThinVec;
|
|
17
|
+
|
|
18
|
+
pub use crate::values::specified::color::{ColorScheme, ForcedColorAdjust, PrintColorAdjust};
|
|
19
|
+
|
|
20
|
+
/// The computed value of the `color` property.
|
|
21
|
+
pub type ColorPropertyValue = AbsoluteColor;
|
|
22
|
+
|
|
23
|
+
/// A computed value for `<color>`.
|
|
24
|
+
pub type Color = GenericColor<Percentage>;
|
|
25
|
+
|
|
26
|
+
/// A computed color-mix().
|
|
27
|
+
pub type ColorMix = GenericColorMix<Color, Percentage>;
|
|
28
|
+
|
|
29
|
+
impl ToCss for Color {
|
|
30
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
31
|
+
where
|
|
32
|
+
W: fmt::Write,
|
|
33
|
+
{
|
|
34
|
+
match *self {
|
|
35
|
+
Self::Absolute(ref c) => c.to_css(dest),
|
|
36
|
+
Self::ColorFunction(ref color_function) => color_function.to_css(dest),
|
|
37
|
+
Self::CurrentColor => dest.write_str("currentcolor"),
|
|
38
|
+
Self::ColorMix(ref m) => m.to_css(dest),
|
|
39
|
+
Self::ContrastColor(ref c) => {
|
|
40
|
+
dest.write_str("contrast-color(")?;
|
|
41
|
+
c.to_css(dest)?;
|
|
42
|
+
dest.write_char(')')
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
impl ToTyped for Color {
|
|
49
|
+
fn to_typed(&self, dest: &mut ThinVec<TypedValue>) -> Result<(), ()> {
|
|
50
|
+
match *self {
|
|
51
|
+
Self::CurrentColor => {
|
|
52
|
+
dest.push(TypedValue::Keyword(KeywordValue(CssString::from(
|
|
53
|
+
"currentcolor",
|
|
54
|
+
))));
|
|
55
|
+
Ok(())
|
|
56
|
+
},
|
|
57
|
+
_ => Err(()),
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
impl Color {
|
|
63
|
+
/// A fully transparent color.
|
|
64
|
+
pub const TRANSPARENT_BLACK: Self = Self::Absolute(AbsoluteColor::TRANSPARENT_BLACK);
|
|
65
|
+
|
|
66
|
+
/// An opaque black color.
|
|
67
|
+
pub const BLACK: Self = Self::Absolute(AbsoluteColor::BLACK);
|
|
68
|
+
|
|
69
|
+
/// An opaque white color.
|
|
70
|
+
pub const WHITE: Self = Self::Absolute(AbsoluteColor::WHITE);
|
|
71
|
+
|
|
72
|
+
/// Create a new computed [`Color`] from a given color-mix, simplifying it to an absolute color
|
|
73
|
+
/// if possible.
|
|
74
|
+
pub fn from_color_mix(color_mix: ColorMix) -> Self {
|
|
75
|
+
if let Some(absolute) = color_mix.mix_to_absolute() {
|
|
76
|
+
Self::Absolute(absolute)
|
|
77
|
+
} else {
|
|
78
|
+
Self::ColorMix(Box::new(color_mix))
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/// Combine this complex color with the given foreground color into an absolute color.
|
|
83
|
+
pub fn resolve_to_absolute(&self, current_color: &AbsoluteColor) -> AbsoluteColor {
|
|
84
|
+
match *self {
|
|
85
|
+
Self::Absolute(c) => c,
|
|
86
|
+
Self::ColorFunction(ref color_function) => {
|
|
87
|
+
color_function.resolve_to_absolute(current_color)
|
|
88
|
+
},
|
|
89
|
+
Self::CurrentColor => *current_color,
|
|
90
|
+
Self::ColorMix(ref mix) => {
|
|
91
|
+
use crate::color::mix;
|
|
92
|
+
|
|
93
|
+
let fill = mix.omitted_weight().unwrap_or(0.0);
|
|
94
|
+
|
|
95
|
+
mix::mix_many(
|
|
96
|
+
mix.interpolation,
|
|
97
|
+
mix.items.iter().map(|item| {
|
|
98
|
+
mix::ColorMixItem::new(
|
|
99
|
+
item.color.resolve_to_absolute(current_color),
|
|
100
|
+
item.percentage.as_ref().map_or(fill, |p| p.0),
|
|
101
|
+
)
|
|
102
|
+
}),
|
|
103
|
+
mix.flags,
|
|
104
|
+
)
|
|
105
|
+
},
|
|
106
|
+
Self::ContrastColor(ref c) => {
|
|
107
|
+
let bg_color = c.resolve_to_absolute(current_color);
|
|
108
|
+
Self::resolve_contrast_color(&bg_color)
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// Performs the resolution of contrast-color given a background color.
|
|
114
|
+
pub fn resolve_contrast_color(bg_color: &AbsoluteColor) -> AbsoluteColor {
|
|
115
|
+
if Self::contrast_ratio(bg_color, &AbsoluteColor::BLACK)
|
|
116
|
+
> Self::contrast_ratio(bg_color, &AbsoluteColor::WHITE)
|
|
117
|
+
{
|
|
118
|
+
AbsoluteColor::BLACK
|
|
119
|
+
} else {
|
|
120
|
+
AbsoluteColor::WHITE
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
fn contrast_ratio(a: &AbsoluteColor, b: &AbsoluteColor) -> f32 {
|
|
125
|
+
// TODO: This just implements the WCAG 2.1 algorithm,
|
|
126
|
+
// https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio
|
|
127
|
+
// Consider using a more sophisticated contrast algorithm, e.g. see
|
|
128
|
+
// https://apcacontrast.com
|
|
129
|
+
let compute = |c| -> f32 {
|
|
130
|
+
if c <= 0.04045 {
|
|
131
|
+
c / 12.92
|
|
132
|
+
} else {
|
|
133
|
+
f32::powf((c + 0.055) / 1.055, 2.4)
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
let luminance = |r, g, b| -> f32 { 0.2126 * r + 0.7152 * g + 0.0722 * b };
|
|
137
|
+
let a = a.into_srgb_legacy();
|
|
138
|
+
let b = b.into_srgb_legacy();
|
|
139
|
+
let a = a.raw_components();
|
|
140
|
+
let b = b.raw_components();
|
|
141
|
+
let la = luminance(compute(a[0]), compute(a[1]), compute(a[2])) + 0.05;
|
|
142
|
+
let lb = luminance(compute(b[0]), compute(b[1]), compute(b[2])) + 0.05;
|
|
143
|
+
if la > lb {
|
|
144
|
+
la / lb
|
|
145
|
+
} else {
|
|
146
|
+
lb / la
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
impl ToAnimatedZero for AbsoluteColor {
|
|
152
|
+
fn to_animated_zero(&self) -> Result<Self, ()> {
|
|
153
|
+
Ok(Self::TRANSPARENT_BLACK)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/// auto | <color>
|
|
158
|
+
pub type ColorOrAuto = GenericColorOrAuto<Color>;
|
|
159
|
+
|
|
160
|
+
/// caret-color
|
|
161
|
+
pub type CaretColor = GenericCaretColor<Color>;
|
|
@@ -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
|
+
//! Computed types for the column properties.
|
|
6
|
+
|
|
7
|
+
use crate::values::computed::PositiveInteger;
|
|
8
|
+
use crate::values::generics::column::GenericColumnCount;
|
|
9
|
+
|
|
10
|
+
/// A computed type for `column-count` values.
|
|
11
|
+
pub type ColumnCount = GenericColumnCount<PositiveInteger>;
|
|
@@ -0,0 +1,155 @@
|
|
|
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
|
+
//! Computed type for the `corner-shape` family of properties.
|
|
6
|
+
|
|
7
|
+
use crate::derives::*;
|
|
8
|
+
use crate::values::animated::{Animate, Procedure, ToAnimatedZero};
|
|
9
|
+
use crate::values::distance::{ComputeSquaredDistance, SquaredDistance};
|
|
10
|
+
use crate::values::generics::border::GenericCornerShapeRect;
|
|
11
|
+
use std::fmt::{self, Write};
|
|
12
|
+
use style_traits::{CssWriter, ToCss};
|
|
13
|
+
|
|
14
|
+
/// The computed value for a single corner shape.
|
|
15
|
+
///
|
|
16
|
+
/// Per the spec, the computed value is always `superellipse(K)` where `K` may
|
|
17
|
+
/// be any real value, including +infinity (for `square`) and -infinity
|
|
18
|
+
/// (for `notch`).
|
|
19
|
+
#[derive(
|
|
20
|
+
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToShmem, ToTyped, ToAnimatedValue, ToResolvedValue,
|
|
21
|
+
)]
|
|
22
|
+
#[repr(C)]
|
|
23
|
+
#[typed(todo_derive_fields)]
|
|
24
|
+
pub struct CornerShape {
|
|
25
|
+
/// The K parameter from the `superellipse()` function.
|
|
26
|
+
pub k: f32,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
impl CornerShape {
|
|
30
|
+
/// `round` -> superellipse(1).
|
|
31
|
+
#[inline]
|
|
32
|
+
pub fn round() -> Self {
|
|
33
|
+
Self { k: 1.0 }
|
|
34
|
+
}
|
|
35
|
+
/// `bevel` -> superellipse(0).
|
|
36
|
+
#[inline]
|
|
37
|
+
pub fn bevel() -> Self {
|
|
38
|
+
Self { k: 0.0 }
|
|
39
|
+
}
|
|
40
|
+
/// `square` -> superellipse(infinity).
|
|
41
|
+
#[inline]
|
|
42
|
+
pub fn square() -> Self {
|
|
43
|
+
Self { k: f32::INFINITY }
|
|
44
|
+
}
|
|
45
|
+
/// `notch` -> superellipse(-infinity).
|
|
46
|
+
#[inline]
|
|
47
|
+
pub fn notch() -> Self {
|
|
48
|
+
Self {
|
|
49
|
+
k: f32::NEG_INFINITY,
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/// `scoop` -> superellipse(-1).
|
|
53
|
+
#[inline]
|
|
54
|
+
pub fn scoop() -> Self {
|
|
55
|
+
Self { k: -1.0 }
|
|
56
|
+
}
|
|
57
|
+
/// `squircle` -> superellipse(2).
|
|
58
|
+
#[inline]
|
|
59
|
+
pub fn squircle() -> Self {
|
|
60
|
+
Self { k: 2.0 }
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/// Whether this corner is the default `round` shape (K == 1).
|
|
64
|
+
#[inline]
|
|
65
|
+
pub fn is_round(&self) -> bool {
|
|
66
|
+
self.k == 1.0
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
impl ToCss for CornerShape {
|
|
71
|
+
fn to_css<W: Write>(&self, dest: &mut CssWriter<W>) -> fmt::Result {
|
|
72
|
+
dest.write_str("superellipse(")?;
|
|
73
|
+
if self.k == f32::INFINITY {
|
|
74
|
+
dest.write_str("infinity")?;
|
|
75
|
+
} else if self.k == f32::NEG_INFINITY {
|
|
76
|
+
dest.write_str("-infinity")?;
|
|
77
|
+
} else {
|
|
78
|
+
self.k.to_css(dest)?;
|
|
79
|
+
}
|
|
80
|
+
dest.write_char(')')
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/// Compute the "normalized superellipse half corner" for a superellipse
|
|
85
|
+
/// parameter `s`, per
|
|
86
|
+
/// <https://drafts.csswg.org/css-borders-4/#corner-shape-interpolation>.
|
|
87
|
+
fn s_to_interpolation_value(s: f32) -> f32 {
|
|
88
|
+
if s == f32::NEG_INFINITY {
|
|
89
|
+
return 0.0;
|
|
90
|
+
}
|
|
91
|
+
if s == f32::INFINITY {
|
|
92
|
+
return 1.0;
|
|
93
|
+
}
|
|
94
|
+
let k = 0.5f32.powf(s.abs());
|
|
95
|
+
let convex_half_corner = 0.5f32.powf(k);
|
|
96
|
+
if s < 0.0 {
|
|
97
|
+
1.0 - convex_half_corner
|
|
98
|
+
} else {
|
|
99
|
+
convex_half_corner
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/// Inverse of `s_to_interpolation_value`.
|
|
104
|
+
fn interpolation_value_to_s(v: f32) -> f32 {
|
|
105
|
+
if v <= 0.0 {
|
|
106
|
+
return f32::NEG_INFINITY;
|
|
107
|
+
}
|
|
108
|
+
if v >= 1.0 {
|
|
109
|
+
return f32::INFINITY;
|
|
110
|
+
}
|
|
111
|
+
let convex_half_corner = if v < 0.5 { 1.0 - v } else { v };
|
|
112
|
+
let k = 0.5f32.ln() / convex_half_corner.ln();
|
|
113
|
+
let s = k.log2();
|
|
114
|
+
if v < 0.5 {
|
|
115
|
+
-s
|
|
116
|
+
} else {
|
|
117
|
+
s
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
impl Animate for CornerShape {
|
|
122
|
+
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
|
|
123
|
+
let a = s_to_interpolation_value(self.k);
|
|
124
|
+
let b = s_to_interpolation_value(other.k);
|
|
125
|
+
let interp = a.animate(&b, procedure)?;
|
|
126
|
+
Ok(CornerShape {
|
|
127
|
+
k: interpolation_value_to_s(interp),
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
impl ComputeSquaredDistance for CornerShape {
|
|
133
|
+
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
|
134
|
+
let a = s_to_interpolation_value(self.k);
|
|
135
|
+
let b = s_to_interpolation_value(other.k);
|
|
136
|
+
a.compute_squared_distance(&b)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
impl ToAnimatedZero for CornerShape {
|
|
141
|
+
fn to_animated_zero(&self) -> Result<Self, ()> {
|
|
142
|
+
Ok(CornerShape::round())
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/// The four computed corner shapes for an element.
|
|
147
|
+
pub type CornerShapeRect = GenericCornerShapeRect<CornerShape>;
|
|
148
|
+
|
|
149
|
+
impl CornerShapeRect {
|
|
150
|
+
/// Initial value: `round` on every corner.
|
|
151
|
+
#[inline]
|
|
152
|
+
pub fn round_all() -> Self {
|
|
153
|
+
Self::all(CornerShape::round())
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
//! Computed values for counter properties
|
|
6
|
+
|
|
7
|
+
use crate::values::computed::image::Image;
|
|
8
|
+
use crate::values::generics::counters as generics;
|
|
9
|
+
use crate::values::generics::counters::CounterIncrement as GenericCounterIncrement;
|
|
10
|
+
use crate::values::generics::counters::CounterReset as GenericCounterReset;
|
|
11
|
+
use crate::values::generics::counters::CounterSet as GenericCounterSet;
|
|
12
|
+
|
|
13
|
+
/// A computed value for the `counter-increment` property.
|
|
14
|
+
pub type CounterIncrement = GenericCounterIncrement<i32>;
|
|
15
|
+
|
|
16
|
+
/// A computed value for the `counter-reset` property.
|
|
17
|
+
pub type CounterReset = GenericCounterReset<i32>;
|
|
18
|
+
|
|
19
|
+
/// A computed value for the `counter-set` property.
|
|
20
|
+
pub type CounterSet = GenericCounterSet<i32>;
|
|
21
|
+
|
|
22
|
+
/// A computed value for the `content` property.
|
|
23
|
+
pub type Content = generics::GenericContent<Image>;
|
|
24
|
+
|
|
25
|
+
/// A computed content item.
|
|
26
|
+
pub type ContentItem = generics::GenericContentItem<Image>;
|