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,304 @@
|
|
|
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
|
+
//! The [`@font-palette-values`][font-palette-values] at-rule.
|
|
6
|
+
//!
|
|
7
|
+
//! [font-palette-values]: https://drafts.csswg.org/css-fonts/#font-palette-values
|
|
8
|
+
|
|
9
|
+
use crate::derives::*;
|
|
10
|
+
use crate::error_reporting::ContextualParseError;
|
|
11
|
+
#[cfg(feature = "gecko")]
|
|
12
|
+
use crate::gecko_bindings::{
|
|
13
|
+
bindings::Gecko_AppendPaletteValueHashEntry,
|
|
14
|
+
bindings::{Gecko_SetFontPaletteBase, Gecko_SetFontPaletteOverride},
|
|
15
|
+
structs::gfx::FontPaletteValueSet,
|
|
16
|
+
structs::gfx::FontPaletteValueSet_PaletteValues_kDark,
|
|
17
|
+
structs::gfx::FontPaletteValueSet_PaletteValues_kLight,
|
|
18
|
+
};
|
|
19
|
+
use crate::parser::{Parse, ParserContext};
|
|
20
|
+
use crate::shared_lock::{SharedRwLockReadGuard, ToCssWithGuard};
|
|
21
|
+
use crate::stylesheets::font_feature_values_rule::parse_family_name_list;
|
|
22
|
+
use crate::values::computed::font::FamilyName;
|
|
23
|
+
use crate::values::specified::Color as SpecifiedColor;
|
|
24
|
+
use crate::values::specified::NonNegativeInteger;
|
|
25
|
+
use crate::values::DashedIdent;
|
|
26
|
+
use cssparser::{
|
|
27
|
+
match_ignore_ascii_case, AtRuleParser, CowRcStr, DeclarationParser, Parser, ParserState,
|
|
28
|
+
QualifiedRuleParser, RuleBodyItemParser, RuleBodyParser, SourceLocation,
|
|
29
|
+
};
|
|
30
|
+
use selectors::parser::SelectorParseErrorKind;
|
|
31
|
+
use std::fmt::{self, Write};
|
|
32
|
+
use style_traits::{Comma, OneOrMoreSeparated};
|
|
33
|
+
use style_traits::{CssStringWriter, CssWriter, ParseError, StyleParseErrorKind, ToCss};
|
|
34
|
+
|
|
35
|
+
#[allow(missing_docs)]
|
|
36
|
+
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToShmem)]
|
|
37
|
+
pub struct FontPaletteOverrideColor {
|
|
38
|
+
index: NonNegativeInteger,
|
|
39
|
+
color: SpecifiedColor,
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
impl Parse for FontPaletteOverrideColor {
|
|
43
|
+
fn parse(
|
|
44
|
+
context: &ParserContext,
|
|
45
|
+
input: &mut Parser,
|
|
46
|
+
) -> Result<FontPaletteOverrideColor, ParseError> {
|
|
47
|
+
let index = NonNegativeInteger::parse(context, input)?;
|
|
48
|
+
if index.0.resolve().is_none() {
|
|
49
|
+
return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let color = SpecifiedColor::parse(context, input)?;
|
|
53
|
+
// Only absolute colors are accepted here:
|
|
54
|
+
// https://drafts.csswg.org/css-fonts/#override-color
|
|
55
|
+
// https://drafts.csswg.org/css-color-5/#absolute-color
|
|
56
|
+
// so check that the specified color can be resolved without a context
|
|
57
|
+
// or currentColor value.
|
|
58
|
+
if color.to_computed_color(None).is_ok_and(|c| c.is_absolute()) {
|
|
59
|
+
// We store the specified color (not the resolved absolute color)
|
|
60
|
+
// because that is what the rule exposes to authors.
|
|
61
|
+
return Ok(FontPaletteOverrideColor { index, color });
|
|
62
|
+
}
|
|
63
|
+
Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError))
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
impl ToCss for FontPaletteOverrideColor {
|
|
68
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
69
|
+
where
|
|
70
|
+
W: fmt::Write,
|
|
71
|
+
{
|
|
72
|
+
self.index.to_css(dest)?;
|
|
73
|
+
dest.write_char(' ')?;
|
|
74
|
+
self.color.to_css(dest)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
impl OneOrMoreSeparated for FontPaletteOverrideColor {
|
|
79
|
+
type S = Comma;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
impl OneOrMoreSeparated for FamilyName {
|
|
83
|
+
type S = Comma;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
#[allow(missing_docs)]
|
|
87
|
+
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss, ToShmem)]
|
|
88
|
+
pub enum FontPaletteBase {
|
|
89
|
+
Light,
|
|
90
|
+
Dark,
|
|
91
|
+
Index(NonNegativeInteger),
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
impl Parse for FontPaletteBase {
|
|
95
|
+
#[inline]
|
|
96
|
+
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ParseError> {
|
|
97
|
+
if let Ok(v) = input.try_parse(|input| NonNegativeInteger::parse(context, input)) {
|
|
98
|
+
if v.0.resolve().is_none() {
|
|
99
|
+
return Err(ParseError::custom(StyleParseErrorKind::UnspecifiedError));
|
|
100
|
+
}
|
|
101
|
+
return Ok(FontPaletteBase::Index(v));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let ident = input.expect_ident()?;
|
|
105
|
+
match_ignore_ascii_case! { &ident,
|
|
106
|
+
"light" => Ok(FontPaletteBase::Light),
|
|
107
|
+
"dark" => Ok(FontPaletteBase::Dark),
|
|
108
|
+
_ => Err(ParseError::unexpected_token())
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/// The [`@font-palette-values`][font-palette-values] at-rule.
|
|
114
|
+
///
|
|
115
|
+
/// [font-palette-values]: https://drafts.csswg.org/css-fonts/#font-palette-values
|
|
116
|
+
#[derive(Clone, Debug, PartialEq, ToShmem)]
|
|
117
|
+
pub struct FontPaletteValuesRule {
|
|
118
|
+
/// Palette name.
|
|
119
|
+
pub name: DashedIdent,
|
|
120
|
+
/// Font family list for @font-palette-values rule.
|
|
121
|
+
/// Family names cannot contain generic families. FamilyName
|
|
122
|
+
/// also accepts only non-generic names.
|
|
123
|
+
pub family_names: Vec<FamilyName>,
|
|
124
|
+
/// The base palette.
|
|
125
|
+
pub base_palette: Option<FontPaletteBase>,
|
|
126
|
+
/// The list of override colors.
|
|
127
|
+
pub override_colors: Vec<FontPaletteOverrideColor>,
|
|
128
|
+
/// The line and column of the rule's source code.
|
|
129
|
+
pub source_location: SourceLocation,
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
impl FontPaletteValuesRule {
|
|
133
|
+
/// Creates an empty FontPaletteValuesRule with given location and name.
|
|
134
|
+
fn new(name: DashedIdent, location: SourceLocation) -> Self {
|
|
135
|
+
FontPaletteValuesRule {
|
|
136
|
+
name,
|
|
137
|
+
family_names: vec![],
|
|
138
|
+
base_palette: None,
|
|
139
|
+
override_colors: vec![],
|
|
140
|
+
source_location: location,
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/// Parses a `FontPaletteValuesRule`.
|
|
145
|
+
pub fn parse(
|
|
146
|
+
context: &ParserContext,
|
|
147
|
+
input: &mut Parser,
|
|
148
|
+
name: DashedIdent,
|
|
149
|
+
location: SourceLocation,
|
|
150
|
+
) -> Self {
|
|
151
|
+
let mut rule = FontPaletteValuesRule::new(name, location);
|
|
152
|
+
let mut parser = FontPaletteValuesDeclarationParser {
|
|
153
|
+
context,
|
|
154
|
+
rule: &mut rule,
|
|
155
|
+
};
|
|
156
|
+
let iter = RuleBodyParser::new(input, &mut parser);
|
|
157
|
+
for declaration in iter {
|
|
158
|
+
if let Err((error, slice, location)) = declaration {
|
|
159
|
+
let error =
|
|
160
|
+
ContextualParseError::UnsupportedFontPaletteValuesDescriptor(slice, error);
|
|
161
|
+
context.log_css_error(location, error);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
rule
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/// Prints inside of `@font-palette-values` block.
|
|
168
|
+
fn value_to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
169
|
+
where
|
|
170
|
+
W: Write,
|
|
171
|
+
{
|
|
172
|
+
if !self.family_names.is_empty() {
|
|
173
|
+
dest.write_str("font-family: ")?;
|
|
174
|
+
self.family_names.to_css(dest)?;
|
|
175
|
+
dest.write_str("; ")?;
|
|
176
|
+
}
|
|
177
|
+
if let Some(base) = &self.base_palette {
|
|
178
|
+
dest.write_str("base-palette: ")?;
|
|
179
|
+
base.to_css(dest)?;
|
|
180
|
+
dest.write_str("; ")?;
|
|
181
|
+
}
|
|
182
|
+
if !self.override_colors.is_empty() {
|
|
183
|
+
dest.write_str("override-colors: ")?;
|
|
184
|
+
self.override_colors.to_css(dest)?;
|
|
185
|
+
dest.write_str("; ")?;
|
|
186
|
+
}
|
|
187
|
+
Ok(())
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/// Convert to Gecko FontPaletteValueSet.
|
|
191
|
+
#[cfg(feature = "gecko")]
|
|
192
|
+
pub fn to_gecko_palette_value_set(&self, dest: *mut FontPaletteValueSet) {
|
|
193
|
+
for family in self.family_names.iter() {
|
|
194
|
+
let family = family.name.to_ascii_lowercase();
|
|
195
|
+
let palette_values = unsafe {
|
|
196
|
+
Gecko_AppendPaletteValueHashEntry(dest, family.as_ptr(), self.name.0.as_ptr())
|
|
197
|
+
};
|
|
198
|
+
if let Some(base_palette) = &self.base_palette {
|
|
199
|
+
unsafe {
|
|
200
|
+
Gecko_SetFontPaletteBase(
|
|
201
|
+
palette_values,
|
|
202
|
+
match &base_palette {
|
|
203
|
+
FontPaletteBase::Light => FontPaletteValueSet_PaletteValues_kLight,
|
|
204
|
+
FontPaletteBase::Dark => FontPaletteValueSet_PaletteValues_kDark,
|
|
205
|
+
// We checked at parse time that the index is resolvable.
|
|
206
|
+
FontPaletteBase::Index(i) => i.0.resolve().unwrap(),
|
|
207
|
+
},
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
for c in &self.override_colors {
|
|
212
|
+
// We checked at parse time that the specified color can be resolved
|
|
213
|
+
// in this way, so the unwrap() here will succeed.
|
|
214
|
+
let absolute = c
|
|
215
|
+
.color
|
|
216
|
+
.to_computed_color(None)
|
|
217
|
+
.ok()
|
|
218
|
+
.and_then(|c| c.as_absolute().copied())
|
|
219
|
+
.unwrap();
|
|
220
|
+
// We checked at parse time that the index is resolvable.
|
|
221
|
+
let index = c.index.0.resolve().unwrap();
|
|
222
|
+
unsafe {
|
|
223
|
+
Gecko_SetFontPaletteOverride(
|
|
224
|
+
palette_values,
|
|
225
|
+
index,
|
|
226
|
+
(&absolute) as *const _ as *mut _,
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
impl ToCssWithGuard for FontPaletteValuesRule {
|
|
235
|
+
fn to_css(&self, _guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result {
|
|
236
|
+
dest.write_str("@font-palette-values ")?;
|
|
237
|
+
self.name.to_css(&mut CssWriter::new(dest))?;
|
|
238
|
+
dest.write_str(" { ")?;
|
|
239
|
+
self.value_to_css(&mut CssWriter::new(dest))?;
|
|
240
|
+
dest.write_char('}')
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/// Parser for declarations in `FontPaletteValuesRule`.
|
|
245
|
+
struct FontPaletteValuesDeclarationParser<'a> {
|
|
246
|
+
context: &'a ParserContext<'a>,
|
|
247
|
+
rule: &'a mut FontPaletteValuesRule,
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
impl<'a, 'i> AtRuleParser<'i> for FontPaletteValuesDeclarationParser<'a> {
|
|
251
|
+
type Prelude = ();
|
|
252
|
+
type AtRule = ();
|
|
253
|
+
type Error = StyleParseErrorKind;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
impl<'a, 'i> QualifiedRuleParser<'i> for FontPaletteValuesDeclarationParser<'a> {
|
|
257
|
+
type Prelude = ();
|
|
258
|
+
type QualifiedRule = ();
|
|
259
|
+
type Error = StyleParseErrorKind;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
fn parse_override_colors(
|
|
263
|
+
context: &ParserContext,
|
|
264
|
+
input: &mut Parser,
|
|
265
|
+
) -> Result<Vec<FontPaletteOverrideColor>, ParseError> {
|
|
266
|
+
input.parse_comma_separated(|i| FontPaletteOverrideColor::parse(context, i))
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
impl<'a, 'b, 'i> DeclarationParser<'i> for FontPaletteValuesDeclarationParser<'a> {
|
|
270
|
+
type Declaration = ();
|
|
271
|
+
type Error = StyleParseErrorKind;
|
|
272
|
+
|
|
273
|
+
fn parse_value(
|
|
274
|
+
&mut self,
|
|
275
|
+
name: CowRcStr<'i>,
|
|
276
|
+
input: &mut Parser<'i>,
|
|
277
|
+
_declaration_start: &ParserState,
|
|
278
|
+
) -> Result<(), ParseError> {
|
|
279
|
+
match_ignore_ascii_case! { &*name,
|
|
280
|
+
"font-family" => {
|
|
281
|
+
self.rule.family_names = parse_family_name_list(self.context, input)?
|
|
282
|
+
},
|
|
283
|
+
"base-palette" => {
|
|
284
|
+
self.rule.base_palette = Some(input.parse_entirely(|i| FontPaletteBase::parse(self.context, i))?)
|
|
285
|
+
},
|
|
286
|
+
"override-colors" => {
|
|
287
|
+
self.rule.override_colors = parse_override_colors(self.context, input)?
|
|
288
|
+
},
|
|
289
|
+
_ => return Err(ParseError::custom(SelectorParseErrorKind::UnexpectedIdent)),
|
|
290
|
+
}
|
|
291
|
+
Ok(())
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
impl<'a, 'i> RuleBodyItemParser<'i, (), StyleParseErrorKind>
|
|
296
|
+
for FontPaletteValuesDeclarationParser<'a>
|
|
297
|
+
{
|
|
298
|
+
fn parse_declarations(&self) -> bool {
|
|
299
|
+
true
|
|
300
|
+
}
|
|
301
|
+
fn parse_qualified(&self) -> bool {
|
|
302
|
+
false
|
|
303
|
+
}
|
|
304
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
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
|
+
//! The [`@import`][import] at-rule.
|
|
6
|
+
//!
|
|
7
|
+
//! [import]: https://drafts.csswg.org/css-cascade-3/#at-import
|
|
8
|
+
|
|
9
|
+
use crate::media_queries::MediaList;
|
|
10
|
+
use crate::parser::{Parse, ParserContext};
|
|
11
|
+
use crate::shared_lock::{DeepCloneWithLock, SharedRwLock, SharedRwLockReadGuard, ToCssWithGuard};
|
|
12
|
+
use crate::stylesheets::{
|
|
13
|
+
layer_rule::LayerName, supports_rule::SupportsCondition, CssRule, CssRuleType,
|
|
14
|
+
StylesheetInDocument,
|
|
15
|
+
};
|
|
16
|
+
use crate::values::CssUrl;
|
|
17
|
+
use cssparser::{Parser, SourceLocation};
|
|
18
|
+
use std::fmt::{self, Write};
|
|
19
|
+
use style_traits::{CssStringWriter, CssWriter, ToCss};
|
|
20
|
+
use to_shmem::{SharedMemoryBuilder, ToShmem};
|
|
21
|
+
|
|
22
|
+
#[cfg(feature = "gecko")]
|
|
23
|
+
type StyleSheet = crate::gecko::data::GeckoStyleSheet;
|
|
24
|
+
#[cfg(feature = "servo")]
|
|
25
|
+
type StyleSheet = ::servo_arc::Arc<crate::stylesheets::Stylesheet>;
|
|
26
|
+
|
|
27
|
+
/// A sheet that is held from an import rule.
|
|
28
|
+
#[derive(Debug)]
|
|
29
|
+
pub enum ImportSheet {
|
|
30
|
+
/// A bonafide stylesheet.
|
|
31
|
+
Sheet(StyleSheet),
|
|
32
|
+
|
|
33
|
+
/// An @import created while parsing off-main-thread, whose Gecko sheet has
|
|
34
|
+
/// yet to be created and attached.
|
|
35
|
+
Pending,
|
|
36
|
+
|
|
37
|
+
/// An @import created with a false <supports-condition>, so will never be fetched.
|
|
38
|
+
Refused,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
impl ImportSheet {
|
|
42
|
+
/// Creates a new ImportSheet from a stylesheet.
|
|
43
|
+
pub fn new(sheet: StyleSheet) -> Self {
|
|
44
|
+
ImportSheet::Sheet(sheet)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/// Creates a pending ImportSheet for a load that has not started yet.
|
|
48
|
+
pub fn new_pending() -> Self {
|
|
49
|
+
ImportSheet::Pending
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// Creates a refused ImportSheet for a load that will not happen.
|
|
53
|
+
pub fn new_refused() -> Self {
|
|
54
|
+
ImportSheet::Refused
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// Returns a reference to the stylesheet in this ImportSheet, if it exists.
|
|
58
|
+
pub fn as_sheet(&self) -> Option<&StyleSheet> {
|
|
59
|
+
match *self {
|
|
60
|
+
#[cfg(feature = "gecko")]
|
|
61
|
+
ImportSheet::Sheet(ref s) => {
|
|
62
|
+
debug_assert!(!s.hack_is_null());
|
|
63
|
+
if s.hack_is_null() {
|
|
64
|
+
return None;
|
|
65
|
+
}
|
|
66
|
+
Some(s)
|
|
67
|
+
},
|
|
68
|
+
#[cfg(feature = "servo")]
|
|
69
|
+
ImportSheet::Sheet(ref s) => Some(s),
|
|
70
|
+
ImportSheet::Refused | ImportSheet::Pending => None,
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// Returns the media list for this import rule.
|
|
75
|
+
pub fn media<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> Option<&'a MediaList> {
|
|
76
|
+
self.as_sheet().and_then(|s| s.media(guard))
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/// Returns the rule list for this import rule.
|
|
80
|
+
pub fn rules<'a>(&'a self, guard: &'a SharedRwLockReadGuard) -> &'a [CssRule] {
|
|
81
|
+
match self.as_sheet() {
|
|
82
|
+
Some(s) => s.contents(guard).rules(guard),
|
|
83
|
+
None => &[],
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
impl DeepCloneWithLock for ImportSheet {
|
|
89
|
+
fn deep_clone_with_lock(&self, _lock: &SharedRwLock, _guard: &SharedRwLockReadGuard) -> Self {
|
|
90
|
+
match *self {
|
|
91
|
+
#[cfg(feature = "gecko")]
|
|
92
|
+
ImportSheet::Sheet(ref s) => {
|
|
93
|
+
use crate::gecko_bindings::bindings;
|
|
94
|
+
let clone = unsafe { bindings::Gecko_StyleSheet_Clone(s.raw() as *const _) };
|
|
95
|
+
ImportSheet::Sheet(unsafe { StyleSheet::from_addrefed(clone) })
|
|
96
|
+
},
|
|
97
|
+
#[cfg(feature = "servo")]
|
|
98
|
+
ImportSheet::Sheet(ref s) => {
|
|
99
|
+
use servo_arc::Arc;
|
|
100
|
+
ImportSheet::Sheet(Arc::new((&**s).clone()))
|
|
101
|
+
},
|
|
102
|
+
ImportSheet::Pending => ImportSheet::Pending,
|
|
103
|
+
ImportSheet::Refused => ImportSheet::Refused,
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/// The layer specified in an import rule (can be none, anonymous, or named).
|
|
109
|
+
#[derive(Debug, Clone)]
|
|
110
|
+
pub enum ImportLayer {
|
|
111
|
+
/// No layer specified
|
|
112
|
+
None,
|
|
113
|
+
|
|
114
|
+
/// Anonymous layer (`layer`)
|
|
115
|
+
Anonymous,
|
|
116
|
+
|
|
117
|
+
/// Named layer (`layer(name)`)
|
|
118
|
+
Named(LayerName),
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/// The supports condition in an import rule.
|
|
122
|
+
#[derive(Debug, Clone)]
|
|
123
|
+
pub struct ImportSupportsCondition {
|
|
124
|
+
/// The supports condition.
|
|
125
|
+
pub condition: SupportsCondition,
|
|
126
|
+
|
|
127
|
+
/// If the import is enabled, from the result of the import condition.
|
|
128
|
+
pub enabled: bool,
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
impl ToCss for ImportLayer {
|
|
132
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
133
|
+
where
|
|
134
|
+
W: Write,
|
|
135
|
+
{
|
|
136
|
+
match *self {
|
|
137
|
+
ImportLayer::None => Ok(()),
|
|
138
|
+
ImportLayer::Anonymous => dest.write_str("layer"),
|
|
139
|
+
ImportLayer::Named(ref name) => {
|
|
140
|
+
dest.write_str("layer(")?;
|
|
141
|
+
name.to_css(dest)?;
|
|
142
|
+
dest.write_char(')')
|
|
143
|
+
},
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/// The [`@import`][import] at-rule.
|
|
149
|
+
///
|
|
150
|
+
/// [import]: https://drafts.csswg.org/css-cascade-3/#at-import
|
|
151
|
+
#[derive(Debug)]
|
|
152
|
+
pub struct ImportRule {
|
|
153
|
+
/// The `<url>` this `@import` rule is loading.
|
|
154
|
+
pub url: CssUrl,
|
|
155
|
+
|
|
156
|
+
/// The stylesheet is always present. However, in the case of gecko async
|
|
157
|
+
/// parsing, we don't actually have a Gecko sheet at first, and so the
|
|
158
|
+
/// ImportSheet just has stub behavior until it appears.
|
|
159
|
+
pub stylesheet: ImportSheet,
|
|
160
|
+
|
|
161
|
+
/// A <supports-condition> for the rule.
|
|
162
|
+
pub supports: Option<ImportSupportsCondition>,
|
|
163
|
+
|
|
164
|
+
/// A `layer()` function name.
|
|
165
|
+
pub layer: ImportLayer,
|
|
166
|
+
|
|
167
|
+
/// The line and column of the rule's source code.
|
|
168
|
+
pub source_location: SourceLocation,
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
impl ImportRule {
|
|
172
|
+
/// Parses the layer() / layer / supports() part of the import header, as per
|
|
173
|
+
/// https://drafts.csswg.org/css-cascade-5/#at-import:
|
|
174
|
+
///
|
|
175
|
+
/// [ layer | layer(<layer-name>) ]?
|
|
176
|
+
/// [ supports([ <supports-condition> | <declaration> ]) ]?
|
|
177
|
+
///
|
|
178
|
+
/// We do this here so that the import preloader can look at this without having to parse the
|
|
179
|
+
/// whole import rule or parse the media query list or what not.
|
|
180
|
+
pub fn parse_layer_and_supports(
|
|
181
|
+
input: &mut Parser,
|
|
182
|
+
context: &mut ParserContext,
|
|
183
|
+
) -> (ImportLayer, Option<ImportSupportsCondition>) {
|
|
184
|
+
let layer = if input
|
|
185
|
+
.try_parse(|input| input.expect_ident_matching("layer"))
|
|
186
|
+
.is_ok()
|
|
187
|
+
{
|
|
188
|
+
ImportLayer::Anonymous
|
|
189
|
+
} else {
|
|
190
|
+
input
|
|
191
|
+
.try_parse(|input| {
|
|
192
|
+
input.expect_function_matching("layer")?;
|
|
193
|
+
input
|
|
194
|
+
.parse_nested_block(|input| LayerName::parse(context, input))
|
|
195
|
+
.map(ImportLayer::Named)
|
|
196
|
+
})
|
|
197
|
+
.ok()
|
|
198
|
+
.unwrap_or(ImportLayer::None)
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
let supports = input
|
|
202
|
+
.try_parse(SupportsCondition::parse_for_import)
|
|
203
|
+
.map(|condition| {
|
|
204
|
+
let enabled =
|
|
205
|
+
context.nest_for_rule(CssRuleType::Style, |context| condition.eval(context));
|
|
206
|
+
ImportSupportsCondition { condition, enabled }
|
|
207
|
+
})
|
|
208
|
+
.ok();
|
|
209
|
+
|
|
210
|
+
(layer, supports)
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
impl ToShmem for ImportRule {
|
|
215
|
+
fn to_shmem(&self, _builder: &mut SharedMemoryBuilder) -> to_shmem::Result<Self> {
|
|
216
|
+
Err(String::from(
|
|
217
|
+
"ToShmem failed for ImportRule: cannot handle imported style sheets",
|
|
218
|
+
))
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
impl DeepCloneWithLock for ImportRule {
|
|
223
|
+
fn deep_clone_with_lock(&self, lock: &SharedRwLock, guard: &SharedRwLockReadGuard) -> Self {
|
|
224
|
+
ImportRule {
|
|
225
|
+
url: self.url.clone(),
|
|
226
|
+
stylesheet: self.stylesheet.deep_clone_with_lock(lock, guard),
|
|
227
|
+
supports: self.supports.clone(),
|
|
228
|
+
layer: self.layer.clone(),
|
|
229
|
+
source_location: self.source_location,
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
impl ToCssWithGuard for ImportRule {
|
|
235
|
+
fn to_css(&self, guard: &SharedRwLockReadGuard, dest: &mut CssStringWriter) -> fmt::Result {
|
|
236
|
+
dest.write_str("@import ")?;
|
|
237
|
+
self.url.to_css(&mut CssWriter::new(dest))?;
|
|
238
|
+
|
|
239
|
+
if !matches!(self.layer, ImportLayer::None) {
|
|
240
|
+
dest.write_char(' ')?;
|
|
241
|
+
self.layer.to_css(&mut CssWriter::new(dest))?;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if let Some(ref supports) = self.supports {
|
|
245
|
+
dest.write_str(" supports(")?;
|
|
246
|
+
supports.condition.to_css(&mut CssWriter::new(dest))?;
|
|
247
|
+
dest.write_char(')')?;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
if let Some(media) = self.stylesheet.media(guard) {
|
|
251
|
+
if !media.is_empty() {
|
|
252
|
+
dest.write_char(' ')?;
|
|
253
|
+
media.to_css(&mut CssWriter::new(dest))?;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
dest.write_char(';')
|
|
258
|
+
}
|
|
259
|
+
}
|