blitz-pdf 0.0.0-stage → 0.1.1
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 +391 -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,437 @@
|
|
|
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
|
+
//! Used for parsing and serializing the [`@property`] syntax string.
|
|
6
|
+
//!
|
|
7
|
+
//! <https://drafts.css-houdini.org/css-properties-values-api-1/#parsing-syntax>
|
|
8
|
+
|
|
9
|
+
use std::fmt::{self, Debug};
|
|
10
|
+
use std::{borrow::Cow, fmt::Write};
|
|
11
|
+
|
|
12
|
+
use crate::derives::*;
|
|
13
|
+
use crate::parser::{Parse, ParserContext};
|
|
14
|
+
use crate::values::CustomIdent;
|
|
15
|
+
use cssparser::{Parser as CSSParser, Token};
|
|
16
|
+
use style_traits::{
|
|
17
|
+
CssWriter, ParseError as StyleParseError, PropertySyntaxParseError as ParseError,
|
|
18
|
+
StyleParseErrorKind, ToCss,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
use self::data_type::{DataType, DependentDataTypes};
|
|
22
|
+
|
|
23
|
+
mod ascii;
|
|
24
|
+
pub mod data_type;
|
|
25
|
+
|
|
26
|
+
/// <https://drafts.css-houdini.org/css-properties-values-api-1/#parsing-syntax>
|
|
27
|
+
#[derive(Debug, Clone, Default, MallocSizeOf, PartialEq, ToShmem)]
|
|
28
|
+
pub struct Descriptor {
|
|
29
|
+
/// The parsed components, if any.
|
|
30
|
+
/// TODO: Could be a Box<[]> if that supported const construction.
|
|
31
|
+
pub components: Vec<Component>,
|
|
32
|
+
/// The specified css syntax, if any.
|
|
33
|
+
specified: Option<Box<str>>,
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
impl Descriptor {
|
|
37
|
+
/// Returns the universal descriptor.
|
|
38
|
+
pub const fn universal() -> Self {
|
|
39
|
+
Self {
|
|
40
|
+
components: Vec::new(),
|
|
41
|
+
specified: None,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// Returns whether this is the universal syntax descriptor.
|
|
46
|
+
#[inline]
|
|
47
|
+
pub fn is_universal(&self) -> bool {
|
|
48
|
+
self.components.is_empty()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// Returns the specified string, if any.
|
|
52
|
+
#[inline]
|
|
53
|
+
pub fn specified_string(&self) -> Option<&str> {
|
|
54
|
+
self.specified.as_deref()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// Parse a syntax descriptor from a stream of tokens
|
|
58
|
+
/// https://drafts.csswg.org/css-values-5/#typedef-syntax
|
|
59
|
+
#[inline]
|
|
60
|
+
pub fn from_css_parser(input: &mut CSSParser) -> Result<Self, StyleParseError> {
|
|
61
|
+
let mut components = vec![];
|
|
62
|
+
|
|
63
|
+
if input.try_parse(|i| i.expect_delim('*')).is_ok() {
|
|
64
|
+
return Ok(Self::universal());
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Parse <syntax-string> if given.
|
|
68
|
+
if let Ok(syntax_string) = input.try_parse(|i| i.expect_string_cloned()) {
|
|
69
|
+
return Self::from_str(syntax_string.as_ref(), /* save_specified = */ true).map_err(
|
|
70
|
+
|err| StyleParseError::custom(StyleParseErrorKind::PropertySyntaxField(err)),
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
loop {
|
|
75
|
+
let name = Self::try_parse_component_name(input).map_err(|err| {
|
|
76
|
+
StyleParseError::custom(StyleParseErrorKind::PropertySyntaxField(err))
|
|
77
|
+
})?;
|
|
78
|
+
|
|
79
|
+
let multiplier = if name.is_pre_multiplied() {
|
|
80
|
+
None
|
|
81
|
+
} else {
|
|
82
|
+
Self::try_parse_multiplier(input)
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
let component = Component { multiplier, name };
|
|
86
|
+
components.push(component);
|
|
87
|
+
let Ok(delim) = input.next() else { break };
|
|
88
|
+
|
|
89
|
+
if delim != &Token::Delim('|') {
|
|
90
|
+
return Err(StyleParseError::custom(
|
|
91
|
+
StyleParseErrorKind::PropertySyntaxField(
|
|
92
|
+
ParseError::ExpectedPipeBetweenComponents,
|
|
93
|
+
),
|
|
94
|
+
));
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
Ok(Self {
|
|
99
|
+
components,
|
|
100
|
+
specified: None,
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
fn try_parse_multiplier(input: &mut CSSParser) -> Option<Multiplier> {
|
|
105
|
+
input
|
|
106
|
+
.try_parse(|input| {
|
|
107
|
+
let next = input.next_including_whitespace().map_err(|_| ())?;
|
|
108
|
+
match next {
|
|
109
|
+
Token::Delim('+') => Ok(Multiplier::Space),
|
|
110
|
+
Token::Delim('#') => Ok(Multiplier::Comma),
|
|
111
|
+
_ => Err(()),
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
.ok()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
fn try_parse_component_name(input: &mut CSSParser) -> Result<ComponentName, ParseError> {
|
|
118
|
+
if input.try_parse(|input| input.expect_delim('<')).is_ok() {
|
|
119
|
+
let name = Self::parse_component_data_type_name(input)?;
|
|
120
|
+
match input.next_including_whitespace() {
|
|
121
|
+
Ok(&Token::Delim('>')) => Ok(ComponentName::DataType(name)),
|
|
122
|
+
_ => Err(ParseError::UnclosedDataTypeName),
|
|
123
|
+
}
|
|
124
|
+
} else {
|
|
125
|
+
input.try_parse(|input| {
|
|
126
|
+
let name = CustomIdent::parse(input, &[]).map_err(|_| ParseError::InvalidName)?;
|
|
127
|
+
Ok(ComponentName::Ident(name))
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
fn parse_component_data_type_name(input: &mut CSSParser) -> Result<DataType, ParseError> {
|
|
133
|
+
let ty = match input.next_including_whitespace() {
|
|
134
|
+
Ok(Token::Ident(name)) => DataType::from_str(name),
|
|
135
|
+
_ => None,
|
|
136
|
+
};
|
|
137
|
+
ty.ok_or(ParseError::UnknownDataTypeName)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/// Parse a syntax descriptor.
|
|
141
|
+
/// https://drafts.css-houdini.org/css-properties-values-api-1/#consume-a-syntax-definition
|
|
142
|
+
pub fn from_str(css: &str, save_specified: bool) -> Result<Self, ParseError> {
|
|
143
|
+
// 1. Strip leading and trailing ASCII whitespace from string.
|
|
144
|
+
let input = ascii::trim_ascii_whitespace(css);
|
|
145
|
+
|
|
146
|
+
// 2. If string's length is 0, return failure.
|
|
147
|
+
if input.is_empty() {
|
|
148
|
+
return Err(ParseError::EmptyInput);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
let specified = if save_specified {
|
|
152
|
+
Some(Box::from(css))
|
|
153
|
+
} else {
|
|
154
|
+
None
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// 3. If string's length is 1, and the only code point in string is U+002A
|
|
158
|
+
// ASTERISK (*), return the universal syntax descriptor.
|
|
159
|
+
if input.len() == 1 && input.as_bytes()[0] == b'*' {
|
|
160
|
+
return Ok(Self {
|
|
161
|
+
components: Default::default(),
|
|
162
|
+
specified,
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// 4. Let stream be an input stream created from the code points of string,
|
|
167
|
+
// preprocessed as specified in [css-syntax-3]. Let descriptor be an
|
|
168
|
+
// initially empty list of syntax components.
|
|
169
|
+
//
|
|
170
|
+
// NOTE(emilio): Instead of preprocessing we cheat and treat new-lines and
|
|
171
|
+
// nulls in the parser specially.
|
|
172
|
+
let mut components = vec![];
|
|
173
|
+
{
|
|
174
|
+
let mut input = Parser::new(input, &mut components);
|
|
175
|
+
// 5. Repeatedly consume the next input code point from stream.
|
|
176
|
+
input.parse()?;
|
|
177
|
+
}
|
|
178
|
+
Ok(Self {
|
|
179
|
+
components,
|
|
180
|
+
specified,
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/// Returns the dependent types this syntax might contain.
|
|
185
|
+
pub fn dependent_types(&self) -> DependentDataTypes {
|
|
186
|
+
let mut types = DependentDataTypes::empty();
|
|
187
|
+
for component in self.components.iter() {
|
|
188
|
+
let t = match &component.name {
|
|
189
|
+
ComponentName::DataType(t) => t,
|
|
190
|
+
ComponentName::Ident(_) => continue,
|
|
191
|
+
};
|
|
192
|
+
types.insert(t.dependent_types());
|
|
193
|
+
}
|
|
194
|
+
types
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
impl ToCss for Descriptor {
|
|
199
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
200
|
+
where
|
|
201
|
+
W: Write,
|
|
202
|
+
{
|
|
203
|
+
if let Some(ref specified) = self.specified {
|
|
204
|
+
return specified.to_css(dest);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if self.is_universal() {
|
|
208
|
+
return dest.write_char('*');
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
let mut first = true;
|
|
212
|
+
for component in &*self.components {
|
|
213
|
+
if !first {
|
|
214
|
+
dest.write_str(" | ")?;
|
|
215
|
+
}
|
|
216
|
+
component.to_css(dest)?;
|
|
217
|
+
first = false;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
Ok(())
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
impl Parse for Descriptor {
|
|
225
|
+
/// Parse a syntax descriptor.
|
|
226
|
+
fn parse(_: &ParserContext, parser: &mut CSSParser) -> Result<Self, StyleParseError> {
|
|
227
|
+
let input = parser.expect_string()?;
|
|
228
|
+
Descriptor::from_str(input.as_ref(), /* save_specified = */ true)
|
|
229
|
+
.map_err(|err| StyleParseError::custom(StyleParseErrorKind::PropertySyntaxField(err)))
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/// <https://drafts.css-houdini.org/css-properties-values-api-1/#multipliers>
|
|
234
|
+
#[derive(
|
|
235
|
+
Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToResolvedValue, ToShmem,
|
|
236
|
+
)]
|
|
237
|
+
pub enum Multiplier {
|
|
238
|
+
/// Indicates a space-separated list.
|
|
239
|
+
Space,
|
|
240
|
+
/// Indicates a comma-separated list.
|
|
241
|
+
Comma,
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
impl ToCss for Multiplier {
|
|
245
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
246
|
+
where
|
|
247
|
+
W: Write,
|
|
248
|
+
{
|
|
249
|
+
dest.write_char(match *self {
|
|
250
|
+
Multiplier::Space => '+',
|
|
251
|
+
Multiplier::Comma => '#',
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/// <https://drafts.css-houdini.org/css-properties-values-api-1/#syntax-component>
|
|
257
|
+
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToShmem)]
|
|
258
|
+
pub struct Component {
|
|
259
|
+
name: ComponentName,
|
|
260
|
+
multiplier: Option<Multiplier>,
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
impl Component {
|
|
264
|
+
/// Returns the component's name.
|
|
265
|
+
#[inline]
|
|
266
|
+
pub fn name(&self) -> &ComponentName {
|
|
267
|
+
&self.name
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/// Returns the component's multiplier, if one exists.
|
|
271
|
+
#[inline]
|
|
272
|
+
pub fn multiplier(&self) -> Option<Multiplier> {
|
|
273
|
+
self.multiplier
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/// If the component is premultiplied, return the un-premultiplied component.
|
|
277
|
+
#[inline]
|
|
278
|
+
pub fn unpremultiplied(&self) -> Cow<'_, Self> {
|
|
279
|
+
match self.name.unpremultiply() {
|
|
280
|
+
Some(component) => {
|
|
281
|
+
debug_assert!(
|
|
282
|
+
self.multiplier.is_none(),
|
|
283
|
+
"Shouldn't have parsed a multiplier for a pre-multiplied data type name",
|
|
284
|
+
);
|
|
285
|
+
Cow::Owned(component)
|
|
286
|
+
},
|
|
287
|
+
None => Cow::Borrowed(self),
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
impl ToCss for Component {
|
|
293
|
+
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> fmt::Result
|
|
294
|
+
where
|
|
295
|
+
W: Write,
|
|
296
|
+
{
|
|
297
|
+
self.name().to_css(dest)?;
|
|
298
|
+
self.multiplier().to_css(dest)
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/// <https://drafts.css-houdini.org/css-properties-values-api-1/#syntax-component-name>
|
|
303
|
+
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss, ToShmem)]
|
|
304
|
+
pub enum ComponentName {
|
|
305
|
+
/// <https://drafts.css-houdini.org/css-properties-values-api-1/#data-type-name>
|
|
306
|
+
DataType(DataType),
|
|
307
|
+
/// <https://drafts.csswg.org/css-values-4/#custom-idents>
|
|
308
|
+
Ident(CustomIdent),
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
impl ComponentName {
|
|
312
|
+
fn unpremultiply(&self) -> Option<Component> {
|
|
313
|
+
match *self {
|
|
314
|
+
ComponentName::DataType(ref t) => t.unpremultiply(),
|
|
315
|
+
ComponentName::Ident(..) => None,
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/// <https://drafts.css-houdini.org/css-properties-values-api-1/#pre-multiplied-data-type-name>
|
|
320
|
+
fn is_pre_multiplied(&self) -> bool {
|
|
321
|
+
self.unpremultiply().is_some()
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
struct Parser<'a> {
|
|
326
|
+
input: &'a str,
|
|
327
|
+
position: usize,
|
|
328
|
+
output: &'a mut Vec<Component>,
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
impl<'a> Parser<'a> {
|
|
332
|
+
fn new(input: &'a str, output: &'a mut Vec<Component>) -> Self {
|
|
333
|
+
Self {
|
|
334
|
+
input,
|
|
335
|
+
position: 0,
|
|
336
|
+
output,
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
fn peek(&self) -> Option<u8> {
|
|
341
|
+
self.input.as_bytes().get(self.position).cloned()
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
fn parse(&mut self) -> Result<(), ParseError> {
|
|
345
|
+
// 5. Repeatedly consume the next input code point from stream:
|
|
346
|
+
loop {
|
|
347
|
+
let component = self.parse_component()?;
|
|
348
|
+
self.output.push(component);
|
|
349
|
+
self.skip_whitespace();
|
|
350
|
+
|
|
351
|
+
let byte = match self.peek() {
|
|
352
|
+
None => return Ok(()),
|
|
353
|
+
Some(b) => b,
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
if byte != b'|' {
|
|
357
|
+
return Err(ParseError::ExpectedPipeBetweenComponents);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
self.position += 1;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
fn skip_whitespace(&mut self) {
|
|
365
|
+
loop {
|
|
366
|
+
match self.peek() {
|
|
367
|
+
Some(c) if c.is_ascii_whitespace() => self.position += 1,
|
|
368
|
+
_ => return,
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/// <https://drafts.css-houdini.org/css-properties-values-api-1/#consume-data-type-name>
|
|
374
|
+
fn parse_data_type_name(&mut self) -> Result<DataType, ParseError> {
|
|
375
|
+
let start = self.position;
|
|
376
|
+
loop {
|
|
377
|
+
let byte = match self.peek() {
|
|
378
|
+
Some(b) => b,
|
|
379
|
+
None => return Err(ParseError::UnclosedDataTypeName),
|
|
380
|
+
};
|
|
381
|
+
if byte != b'>' {
|
|
382
|
+
self.position += 1;
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
let ty = match DataType::from_str(&self.input[start..self.position]) {
|
|
386
|
+
Some(ty) => ty,
|
|
387
|
+
None => return Err(ParseError::UnknownDataTypeName),
|
|
388
|
+
};
|
|
389
|
+
self.position += 1;
|
|
390
|
+
return Ok(ty);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
fn parse_name(&mut self) -> Result<ComponentName, ParseError> {
|
|
395
|
+
let b = match self.peek() {
|
|
396
|
+
Some(b) => b,
|
|
397
|
+
None => return Err(ParseError::UnexpectedEOF),
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
if b == b'<' {
|
|
401
|
+
self.position += 1;
|
|
402
|
+
return Ok(ComponentName::DataType(self.parse_data_type_name()?));
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
let input = &self.input[self.position..];
|
|
406
|
+
let mut input = CSSParser::new(input);
|
|
407
|
+
let name = match CustomIdent::parse(&mut input, &[]) {
|
|
408
|
+
Ok(name) => name,
|
|
409
|
+
Err(_) => return Err(ParseError::InvalidName),
|
|
410
|
+
};
|
|
411
|
+
self.position += input.position().byte_index();
|
|
412
|
+
Ok(ComponentName::Ident(name))
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
fn parse_multiplier(&mut self) -> Option<Multiplier> {
|
|
416
|
+
let multiplier = match self.peek()? {
|
|
417
|
+
b'+' => Multiplier::Space,
|
|
418
|
+
b'#' => Multiplier::Comma,
|
|
419
|
+
_ => return None,
|
|
420
|
+
};
|
|
421
|
+
self.position += 1;
|
|
422
|
+
Some(multiplier)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/// <https://drafts.css-houdini.org/css-properties-values-api-1/#consume-a-syntax-component>
|
|
426
|
+
fn parse_component(&mut self) -> Result<Component, ParseError> {
|
|
427
|
+
// Consume as much whitespace as possible from stream.
|
|
428
|
+
self.skip_whitespace();
|
|
429
|
+
let name = self.parse_name()?;
|
|
430
|
+
let multiplier = if name.is_pre_multiplied() {
|
|
431
|
+
None
|
|
432
|
+
} else {
|
|
433
|
+
self.parse_multiplier()
|
|
434
|
+
};
|
|
435
|
+
Ok(Component { name, multiplier })
|
|
436
|
+
}
|
|
437
|
+
}
|