From e7d1bfd90eeb5bbb2b21d748bcce840fe7ef16d2 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Mon, 5 Aug 2024 23:44:32 -0400 Subject: [PATCH 001/133] update ast --- node/ast.d.ts | 101 ++++++++++--------- scripts/build-ast.js | 9 ++ src/macros.rs | 2 +- src/properties/animation.rs | 10 +- src/properties/svg.rs | 143 +++++++++++++++++---------- src/rules/keyframes.rs | 21 ++-- src/values/color.rs | 190 +++++++++++++++++++----------------- 7 files changed, 270 insertions(+), 206 deletions(-) diff --git a/node/ast.d.ts b/node/ast.d.ts index fba3f69e..19ab2c1f 100644 --- a/node/ast.d.ts +++ b/node/ast.d.ts @@ -4230,23 +4230,30 @@ export type PositionComponentFor_VerticalPositionKeyword = * See [RadialGradient](RadialGradient). */ export type EndingShape = - | { - type: "circle"; - value: Circle; - } | { type: "ellipse"; value: Ellipse; + } + | { + type: "circle"; + value: Circle; }; /** - * A circle ending shape for a `radial-gradient()`. + * An ellipse ending shape for a `radial-gradient()`. * * See [RadialGradient](RadialGradient). */ -export type Circle = +export type Ellipse = | { - type: "radius"; - value: Length; + type: "size"; + /** + * The x-radius of the ellipse. + */ + x: DimensionPercentageFor_LengthValue; + /** + * The y-radius of the ellipse. + */ + y: DimensionPercentageFor_LengthValue; } | { type: "extent"; @@ -4259,21 +4266,14 @@ export type Circle = */ export type ShapeExtent = "closest-side" | "farthest-side" | "closest-corner" | "farthest-corner"; /** - * An ellipse ending shape for a `radial-gradient()`. + * A circle ending shape for a `radial-gradient()`. * * See [RadialGradient](RadialGradient). */ -export type Ellipse = +export type Circle = | { - type: "size"; - /** - * The x-radius of the ellipse. - */ - x: DimensionPercentageFor_LengthValue; - /** - * The y-radius of the ellipse. - */ - y: DimensionPercentageFor_LengthValue; + type: "radius"; + value: Length; } | { type: "extent"; @@ -4438,11 +4438,11 @@ export type WebKitGradientPointComponentFor_HorizontalPositionKeyword = */ export type NumberOrPercentage = | { - type: "percentage"; + type: "number"; value: number; } | { - type: "number"; + type: "percentage"; value: number; }; /** @@ -4753,13 +4753,13 @@ export type RectFor_LengthOrNumber = [LengthOrNumber, LengthOrNumber, LengthOrNu * Either a [``](https://www.w3.org/TR/css-values-4/#lengths) or a [``](https://www.w3.org/TR/css-values-4/#numbers). */ export type LengthOrNumber = - | { - type: "length"; - value: Length; - } | { type: "number"; value: number; + } + | { + type: "length"; + value: Length; }; /** * A single [border-image-repeat](https://www.w3.org/TR/css-backgrounds-3/#border-image-repeat) keyword. @@ -5570,22 +5570,16 @@ export type AnimationRangeStart = AnimationAttachmentRange; * A value for the [animation-range-start](https://drafts.csswg.org/scroll-animations/#animation-range-start) or [animation-range-end](https://drafts.csswg.org/scroll-animations/#animation-range-end) property. */ export type AnimationAttachmentRange = - | "Normal" - | { - LengthPercentage: DimensionPercentageFor_LengthValue; - } - | { - TimelineRange: { - /** - * The name of the timeline range. - */ - name: TimelineRangeName; - /** - * The offset from the start of the named timeline range. - */ - offset: DimensionPercentageFor_LengthValue; - }; - }; + "normal" | DimensionPercentageFor_LengthValue | { + /** + * The name of the timeline range. + */ + name: TimelineRangeName; + /** + * The offset from the start of the named timeline range. + */ + offset: DimensionPercentageFor_LengthValue; + }; /** * A [view progress timeline range](https://drafts.csswg.org/scroll-animations/#view-timelines-ranges) */ @@ -5709,7 +5703,7 @@ export type Transform = /** * A value for the [transform-style](https://drafts.csswg.org/css-transforms-2/#transform-style-property) property. */ -export type TransformStyle = "flat" | "preserve-3d"; +export type TransformStyle = "flat" | "preserve3d"; /** * A value for the [transform-box](https://drafts.csswg.org/css-transforms-1/#transform-box) property. */ @@ -6105,9 +6099,6 @@ export type MarkerSide = "match-self" | "match-parent"; * An SVG [``](https://www.w3.org/TR/SVG2/painting.html#SpecifyingPaint) value used in the `fill` and `stroke` properties. */ export type SVGPaint = - | { - type: "none"; - } | { /** * A fallback to be used used in case the paint server cannot be resolved. @@ -6128,6 +6119,9 @@ export type SVGPaint = } | { type: "context-stroke"; + } + | { + type: "none"; }; /** * A fallback for an SVG paint in case a paint server `url()` cannot be resolved. @@ -6938,6 +6932,10 @@ export type KeyframeSelector = } | { type: "to"; + } + | { + type: "timeline-range-percentage"; + value: TimelineRangePercentage; }; /** * KeyframesName @@ -9164,6 +9162,19 @@ export interface Keyframe { */ selectors: KeyframeSelector[]; } +/** + * A percentage of a given timeline range + */ +export interface TimelineRangePercentage { + /** + * The name of the timeline range. + */ + name: TimelineRangeName; + /** + * The percentage progress between the start and end of the range. + */ + percentage: number; +} /** * A [@font-face](https://drafts.csswg.org/css-fonts/#font-face-rule) rule. */ diff --git a/scripts/build-ast.js b/scripts/build-ast.js index 7b7fc020..de0e7f20 100644 --- a/scripts/build-ast.js +++ b/scripts/build-ast.js @@ -66,6 +66,15 @@ compileFromFile('node/ast.json', { path.node.typeAnnotation.types[1].members[0].key.name === 'xyz' ) { path.get('typeAnnotation.types.1').replaceWith(path.node.typeAnnotation.types[1].members[0].typeAnnotation.typeAnnotation); + } else if (path.node.id.name === 'AnimationAttachmentRange' && path.node.typeAnnotation.type === 'TSUnionType') { + let types = path.node.typeAnnotation.types; + if (types[1].type === 'TSTypeLiteral' && types[1].members[0].key.name === 'lengthpercentage') { + path.get('typeAnnotation.types.1').replaceWith(path.node.typeAnnotation.types[1].members[0].typeAnnotation.typeAnnotation); + } + + if (types[2].type === 'TSTypeLiteral' && types[2].members[0].key.name === 'timelinerange') { + path.get('typeAnnotation.types.2').replaceWith(path.node.typeAnnotation.types[2].members[0].typeAnnotation.typeAnnotation); + } } } }); diff --git a/src/macros.rs b/src/macros.rs index 7e573816..8019c58c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -10,7 +10,7 @@ macro_rules! enum_property { ) => { #[derive(Debug, Clone, Copy, PartialEq, Parse, ToCss)] #[cfg_attr(feature = "visitor", derive(Visit))] - #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(rename_all = "lowercase"))] + #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(rename_all = "kebab-case"))] #[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] #[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))] $(#[$outer])* diff --git a/src/properties/animation.rs b/src/properties/animation.rs index 9855127c..f018f4af 100644 --- a/src/properties/animation.rs +++ b/src/properties/animation.rs @@ -379,7 +379,11 @@ impl ToCss for ViewTimeline { /// A [view progress timeline range](https://drafts.csswg.org/scroll-animations/#view-timelines-ranges) #[derive(Debug, Clone, PartialEq, Parse, ToCss)] #[cfg_attr(feature = "visitor", derive(Visit))] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "kebab-case") +)] #[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] #[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))] pub enum TimelineRangeName { @@ -402,15 +406,17 @@ pub enum TimelineRangeName { /// or [animation-range-end](https://drafts.csswg.org/scroll-animations/#animation-range-end) property. #[derive(Debug, Clone, PartialEq)] #[cfg_attr(feature = "visitor", derive(Visit))] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize), serde(rename_all = "lowercase"))] #[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] #[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))] pub enum AnimationAttachmentRange { /// The start of the animation’s attachment range is the start of its associated timeline. Normal, /// The animation attachment range starts at the specified point on the timeline measuring from the start of the timeline. + #[cfg_attr(feature = "serde", serde(untagged))] LengthPercentage(LengthPercentage), /// The animation attachment range starts at the specified point on the timeline measuring from the start of the specified named timeline range. + #[cfg_attr(feature = "serde", serde(untagged))] TimelineRange { /// The name of the timeline range. name: TimelineRangeName, diff --git a/src/properties/svg.rs b/src/properties/svg.rs index 150e5a25..16b38456 100644 --- a/src/properties/svg.rs +++ b/src/properties/svg.rs @@ -209,66 +209,101 @@ pub enum Marker<'i> { Url(Url<'i>), } -enum_property! { - /// A value for the [color-interpolation](https://www.w3.org/TR/SVG2/painting.html#ColorInterpolation) property. - pub enum ColorInterpolation { - /// The UA can choose between sRGB or linearRGB. - Auto, - /// Color interpolation occurs in the sRGB color space. - SRGB, - /// Color interpolation occurs in the linearized RGB color space - LinearRGB, - } +/// A value for the [color-interpolation](https://www.w3.org/TR/SVG2/painting.html#ColorInterpolation) property. +#[derive(Debug, Clone, Copy, PartialEq, Parse, ToCss)] +#[cfg_attr(feature = "visitor", derive(Visit))] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "lowercase") +)] +#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] +#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))] +pub enum ColorInterpolation { + /// The UA can choose between sRGB or linearRGB. + Auto, + /// Color interpolation occurs in the sRGB color space. + SRGB, + /// Color interpolation occurs in the linearized RGB color space + LinearRGB, } -enum_property! { - /// A value for the [color-rendering](https://www.w3.org/TR/SVG2/painting.html#ColorRendering) property. - pub enum ColorRendering { - /// The UA can choose a tradeoff between speed and quality. - Auto, - /// The UA shall optimize speed over quality. - OptimizeSpeed, - /// The UA shall optimize quality over speed. - OptimizeQuality, - } +/// A value for the [color-rendering](https://www.w3.org/TR/SVG2/painting.html#ColorRendering) property. +#[derive(Debug, Clone, Copy, PartialEq, Parse, ToCss)] +#[cfg_attr(feature = "visitor", derive(Visit))] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "lowercase") +)] +#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] +#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))] +pub enum ColorRendering { + /// The UA can choose a tradeoff between speed and quality. + Auto, + /// The UA shall optimize speed over quality. + OptimizeSpeed, + /// The UA shall optimize quality over speed. + OptimizeQuality, } -enum_property! { - /// A value for the [shape-rendering](https://www.w3.org/TR/SVG2/painting.html#ShapeRendering) property. - pub enum ShapeRendering { - /// The UA can choose an appropriate tradeoff. - Auto, - /// The UA shall optimize speed. - OptimizeSpeed, - /// The UA shall optimize crisp edges. - CrispEdges, - /// The UA shall optimize geometric precision. - GeometricPrecision, - } +/// A value for the [shape-rendering](https://www.w3.org/TR/SVG2/painting.html#ShapeRendering) property. +#[derive(Debug, Clone, Copy, PartialEq, Parse, ToCss)] +#[cfg_attr(feature = "visitor", derive(Visit))] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "lowercase") +)] +#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] +#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))] +pub enum ShapeRendering { + /// The UA can choose an appropriate tradeoff. + Auto, + /// The UA shall optimize speed. + OptimizeSpeed, + /// The UA shall optimize crisp edges. + CrispEdges, + /// The UA shall optimize geometric precision. + GeometricPrecision, } -enum_property! { - /// A value for the [text-rendering](https://www.w3.org/TR/SVG2/painting.html#TextRendering) property. - pub enum TextRendering { - /// The UA can choose an appropriate tradeoff. - Auto, - /// The UA shall optimize speed. - OptimizeSpeed, - /// The UA shall optimize legibility. - OptimizeLegibility, - /// The UA shall optimize geometric precision. - GeometricPrecision, - } +/// A value for the [text-rendering](https://www.w3.org/TR/SVG2/painting.html#TextRendering) property. +#[derive(Debug, Clone, Copy, PartialEq, Parse, ToCss)] +#[cfg_attr(feature = "visitor", derive(Visit))] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "lowercase") +)] +#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] +#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))] +pub enum TextRendering { + /// The UA can choose an appropriate tradeoff. + Auto, + /// The UA shall optimize speed. + OptimizeSpeed, + /// The UA shall optimize legibility. + OptimizeLegibility, + /// The UA shall optimize geometric precision. + GeometricPrecision, } -enum_property! { - /// A value for the [image-rendering](https://www.w3.org/TR/SVG2/painting.html#ImageRendering) property. - pub enum ImageRendering { - /// The UA can choose a tradeoff between speed and quality. - Auto, - /// The UA shall optimize speed over quality. - OptimizeSpeed, - /// The UA shall optimize quality over speed. - OptimizeQuality, - } +/// A value for the [image-rendering](https://www.w3.org/TR/SVG2/painting.html#ImageRendering) property. +#[derive(Debug, Clone, Copy, PartialEq, Parse, ToCss)] +#[cfg_attr(feature = "visitor", derive(Visit))] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "lowercase") +)] +#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] +#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))] +pub enum ImageRendering { + /// The UA can choose a tradeoff between speed and quality. + Auto, + /// The UA shall optimize speed over quality. + OptimizeSpeed, + /// The UA shall optimize quality over speed. + OptimizeQuality, } diff --git a/src/rules/keyframes.rs b/src/rules/keyframes.rs index 9d1e758d..02d0943b 100644 --- a/src/rules/keyframes.rs +++ b/src/rules/keyframes.rs @@ -277,20 +277,17 @@ impl<'i> ToCss for KeyframesRule<'i> { #[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] #[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))] pub struct TimelineRangePercentage { - /// A named timeline range - timeline_range_name: TimelineRangeName, - /// The percentage progress between the start and end of the rage - percentage: Percentage + /// The name of the timeline range. + name: TimelineRangeName, + /// The percentage progress between the start and end of the range. + percentage: Percentage, } impl<'i> Parse<'i> for TimelineRangePercentage { fn parse<'t>(input: &mut Parser<'i, 't>) -> Result<'i, ParserError<'i>>> { - let timeline_range_name = TimelineRangeName::parse(input)?; + let name = TimelineRangeName::parse(input)?; let percentage = Percentage::parse(input)?; - Ok(TimelineRangePercentage { - timeline_range_name, - percentage - }) + Ok(TimelineRangePercentage { name, percentage }) } } @@ -313,7 +310,7 @@ pub enum KeyframeSelector { /// The `to` keyword. Equivalent to 100%. To, /// A [named timeline range selector](https://drafts.csswg.org/scroll-animations-1/#named-range-keyframes) - TimelineRangePercentage(TimelineRangePercentage) + TimelineRangePercentage(TimelineRangePercentage), } impl ToCss for KeyframeSelector { @@ -338,8 +335,8 @@ impl ToCss for KeyframeSelector { } KeyframeSelector::To => dest.write_str("to"), KeyframeSelector::TimelineRangePercentage(TimelineRangePercentage { - timeline_range_name, - percentage + name: timeline_range_name, + percentage, }) => { timeline_range_name.to_css(dest)?; dest.write_char(' ')?; diff --git a/src/values/color.rs b/src/values/color.rs index b91c1426..274c3f43 100644 --- a/src/values/color.rs +++ b/src/values/color.rs @@ -3580,98 +3580,104 @@ impl<'i, V: ?Sized + Visitor<'i, T>, T: Visit<'i, T, V>> Visit<'i, T, V> for RGB } } -enum_property! { - #[css(case = lower)] - /// A CSS [system color](https://drafts.csswg.org/css-color/#css-system-colors) keyword. - pub enum SystemColor { - /// Background of accented user interface controls. - AccentColor, - /// Text of accented user interface controls. - AccentColorText, - /// Text in active links. For light backgrounds, traditionally red. - ActiveText, - /// The base border color for push buttons. - ButtonBorder, - /// The face background color for push buttons. - ButtonFace, - /// Text on push buttons. - ButtonText, - /// Background of application content or documents. - Canvas, - /// Text in application content or documents. - CanvasText, - /// Background of input fields. - Field, - /// Text in input fields. - FieldText, - /// Disabled text. (Often, but not necessarily, gray.) - GrayText, - /// Background of selected text, for example from ::selection. - Highlight, - /// Text of selected text. - HighlightText, - /// Text in non-active, non-visited links. For light backgrounds, traditionally blue. - LinkText, - /// Background of text that has been specially marked (such as by the HTML mark element). - Mark, - /// Text that has been specially marked (such as by the HTML mark element). - MarkText, - /// Background of selected items, for example a selected checkbox. - SelectedItem, - /// Text of selected items. - SelectedItemText, - /// Text in visited links. For light backgrounds, traditionally purple. - VisitedText, - - // Deprecated colors: https://drafts.csswg.org/css-color/#deprecated-system-colors - - /// Active window border. Same as ButtonBorder. - ActiveBorder, - /// Active window caption. Same as Canvas. - ActiveCaption, - /// Background color of multiple document interface. Same as Canvas. - AppWorkspace, - /// Desktop background. Same as Canvas. - Background, - /// The color of the border facing the light source for 3-D elements that appear 3-D due to one layer of surrounding border. Same as ButtonFace. - ButtonHighlight, - /// The color of the border away from the light source for 3-D elements that appear 3-D due to one layer of surrounding border. Same as ButtonFace. - ButtonShadow, - /// Text in caption, size box, and scrollbar arrow box. Same as CanvasText. - CaptionText, - /// Inactive window border. Same as ButtonBorder. - InactiveBorder, - /// Inactive window caption. Same as Canvas. - InactiveCaption, - /// Color of text in an inactive caption. Same as GrayText. - InactiveCaptionText, - /// Background color for tooltip controls. Same as Canvas. - InfoBackground, - /// Text color for tooltip controls. Same as CanvasText. - InfoText, - /// Menu background. Same as Canvas. - Menu, - /// Text in menus. Same as CanvasText. - MenuText, - /// Scroll bar gray area. Same as Canvas. - Scrollbar, - /// The color of the darker (generally outer) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border. Same as ButtonBorder. - ThreeDDarkShadow, - /// The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border. Same as ButtonFace. - ThreeDFace, - /// The color of the lighter (generally outer) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border. Same as ButtonBorder. - ThreeDHighlight, - /// The color of the darker (generally inner) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border. Same as ButtonBorder. - ThreeDLightShadow, - /// The color of the lighter (generally inner) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border. Same as ButtonBorder. - ThreeDShadow, - /// Window background. Same as Canvas. - Window, - /// Window frame. Same as ButtonBorder. - WindowFrame, - /// Text in windows. Same as CanvasText. - WindowText, - } +#[derive(Debug, Clone, Copy, PartialEq, Parse, ToCss)] +#[css(case = lower)] +#[cfg_attr(feature = "visitor", derive(Visit))] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "lowercase") +)] +#[cfg_attr(feature = "jsonschema", derive(schemars::JsonSchema))] +#[cfg_attr(feature = "into_owned", derive(static_self::IntoOwned))] +/// A CSS [system color](https://drafts.csswg.org/css-color/#css-system-colors) keyword. +pub enum SystemColor { + /// Background of accented user interface controls. + AccentColor, + /// Text of accented user interface controls. + AccentColorText, + /// Text in active links. For light backgrounds, traditionally red. + ActiveText, + /// The base border color for push buttons. + ButtonBorder, + /// The face background color for push buttons. + ButtonFace, + /// Text on push buttons. + ButtonText, + /// Background of application content or documents. + Canvas, + /// Text in application content or documents. + CanvasText, + /// Background of input fields. + Field, + /// Text in input fields. + FieldText, + /// Disabled text. (Often, but not necessarily, gray.) + GrayText, + /// Background of selected text, for example from ::selection. + Highlight, + /// Text of selected text. + HighlightText, + /// Text in non-active, non-visited links. For light backgrounds, traditionally blue. + LinkText, + /// Background of text that has been specially marked (such as by the HTML mark element). + Mark, + /// Text that has been specially marked (such as by the HTML mark element). + MarkText, + /// Background of selected items, for example a selected checkbox. + SelectedItem, + /// Text of selected items. + SelectedItemText, + /// Text in visited links. For light backgrounds, traditionally purple. + VisitedText, + + // Deprecated colors: https://drafts.csswg.org/css-color/#deprecated-system-colors + /// Active window border. Same as ButtonBorder. + ActiveBorder, + /// Active window caption. Same as Canvas. + ActiveCaption, + /// Background color of multiple document interface. Same as Canvas. + AppWorkspace, + /// Desktop background. Same as Canvas. + Background, + /// The color of the border facing the light source for 3-D elements that appear 3-D due to one layer of surrounding border. Same as ButtonFace. + ButtonHighlight, + /// The color of the border away from the light source for 3-D elements that appear 3-D due to one layer of surrounding border. Same as ButtonFace. + ButtonShadow, + /// Text in caption, size box, and scrollbar arrow box. Same as CanvasText. + CaptionText, + /// Inactive window border. Same as ButtonBorder. + InactiveBorder, + /// Inactive window caption. Same as Canvas. + InactiveCaption, + /// Color of text in an inactive caption. Same as GrayText. + InactiveCaptionText, + /// Background color for tooltip controls. Same as Canvas. + InfoBackground, + /// Text color for tooltip controls. Same as CanvasText. + InfoText, + /// Menu background. Same as Canvas. + Menu, + /// Text in menus. Same as CanvasText. + MenuText, + /// Scroll bar gray area. Same as Canvas. + Scrollbar, + /// The color of the darker (generally outer) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border. Same as ButtonBorder. + ThreeDDarkShadow, + /// The face background color for 3-D elements that appear 3-D due to two concentric layers of surrounding border. Same as ButtonFace. + ThreeDFace, + /// The color of the lighter (generally outer) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border. Same as ButtonBorder. + ThreeDHighlight, + /// The color of the darker (generally inner) of the two borders facing the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border. Same as ButtonBorder. + ThreeDLightShadow, + /// The color of the lighter (generally inner) of the two borders away from the light source for 3-D elements that appear 3-D due to two concentric layers of surrounding border. Same as ButtonBorder. + ThreeDShadow, + /// Window background. Same as Canvas. + Window, + /// Window frame. Same as ButtonBorder. + WindowFrame, + /// Text in windows. Same as CanvasText. + WindowText, } impl IsCompatible for SystemColor { From dcbb9970a2c1fac1305ebbfb9922f2548d8e2e66 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Tue, 6 Aug 2024 00:17:10 -0400 Subject: [PATCH 002/133] update compat data --- package.json | 6 ++-- src/compat.rs | 75 ++++++++++++++++++++++------------------- src/prefixes.rs | 18 +++++----- yarn.lock | 90 ++++++++++++++++++++++++------------------------- 4 files changed, 97 insertions(+), 92 deletions(-) diff --git a/package.json b/package.json index 91ffd35f..c51c2888 100644 --- a/package.json +++ b/package.json @@ -48,10 +48,10 @@ "@codemirror/lang-javascript": "^6.1.2", "@codemirror/lint": "^6.1.0", "@codemirror/theme-one-dark": "^6.1.0", - "@mdn/browser-compat-data": "~5.5.28", + "@mdn/browser-compat-data": "~5.5.44", "@napi-rs/cli": "^2.14.0", - "autoprefixer": "^10.4.19", - "caniuse-lite": "^1.0.30001620", + "autoprefixer": "^10.4.20", + "caniuse-lite": "^1.0.30001649", "codemirror": "^6.0.1", "cssnano": "^5.0.8", "esbuild": "^0.19.8", diff --git a/src/compat.rs b/src/compat.rs index b1846f34..6c86d398 100644 --- a/src/compat.rs +++ b/src/compat.rs @@ -445,7 +445,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -537,7 +537,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -582,7 +582,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -627,11 +627,16 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } - if browsers.ie.is_some() || browsers.samsung.is_some() { + if let Some(version) = browsers.samsung { + if version < 1638400 { + return false; + } + } + if browsers.ie.is_some() { return false; } } @@ -667,7 +672,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -712,7 +717,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -757,7 +762,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -802,7 +807,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -894,7 +899,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -939,7 +944,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -1019,7 +1024,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -1064,7 +1069,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -1154,7 +1159,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -1199,7 +1204,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -1249,7 +1254,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -1336,7 +1341,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -1381,7 +1386,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -1426,7 +1431,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -1466,7 +1471,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -1511,7 +1516,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -1556,7 +1561,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -1623,7 +1628,7 @@ impl Feature { } } if let Some(version) = browsers.android { - if version < 8126464 { + if version < 8323072 { return false; } } @@ -2889,7 +2894,7 @@ impl Feature { } } if let Some(version) = browsers.opera { - if version < 7274496 { + if version < 5439488 { return false; } } @@ -3496,12 +3501,12 @@ impl Feature { } Feature::CapUnit => { if let Some(version) = browsers.chrome { - if version < 7667712 { + if version < 7733248 { return false; } } if let Some(version) = browsers.edge { - if version < 7667712 { + if version < 7733248 { return false; } } @@ -3511,7 +3516,7 @@ impl Feature { } } if let Some(version) = browsers.opera { - if version < 5111808 { + if version < 5177344 { return false; } } @@ -3526,12 +3531,12 @@ impl Feature { } } if let Some(version) = browsers.samsung { - if version < 1572864 { + if version < 1638400 { return false; } } if let Some(version) = browsers.android { - if version < 7667712 { + if version < 7733248 { return false; } } @@ -3821,17 +3826,17 @@ impl Feature { } Feature::RcapUnit => { if let Some(version) = browsers.chrome { - if version < 7667712 { + if version < 7733248 { return false; } } if let Some(version) = browsers.edge { - if version < 7667712 { + if version < 7733248 { return false; } } if let Some(version) = browsers.opera { - if version < 5111808 { + if version < 5177344 { return false; } } @@ -3846,12 +3851,12 @@ impl Feature { } } if let Some(version) = browsers.samsung { - if version < 1572864 { + if version < 1638400 { return false; } } if let Some(version) = browsers.android { - if version < 7667712 { + if version < 7733248 { return false; } } @@ -5173,7 +5178,7 @@ impl Feature { } } if let Some(version) = browsers.opera { - if version < 7274496 { + if version < 5439488 { return false; } } diff --git a/src/prefixes.rs b/src/prefixes.rs index 56697404..5cb213de 100644 --- a/src/prefixes.rs +++ b/src/prefixes.rs @@ -550,12 +550,12 @@ impl Feature { } } if let Some(version) = browsers.ios_saf { - if version >= 589824 { + if version >= 589824 && version <= 1115648 { prefixes |= VendorPrefix::WebKit; } } if let Some(version) = browsers.safari { - if version >= 589824 { + if version >= 589824 && version <= 1115648 { prefixes |= VendorPrefix::WebKit; } } @@ -816,7 +816,7 @@ impl Feature { } } if let Some(version) = browsers.samsung { - if version >= 262144 { + if version >= 262144 && version <= 1572864 { prefixes |= VendorPrefix::WebKit; } } @@ -1231,11 +1231,6 @@ impl Feature { } } Feature::FitContent => { - if let Some(version) = browsers.firefox { - if version >= 196608 { - prefixes |= VendorPrefix::Moz; - } - } if let Some(version) = browsers.android { if version >= 263168 && version <= 263171 { prefixes |= VendorPrefix::WebKit; @@ -1246,6 +1241,11 @@ impl Feature { prefixes |= VendorPrefix::WebKit; } } + if let Some(version) = browsers.firefox { + if version >= 196608 && version <= 6094848 { + prefixes |= VendorPrefix::Moz; + } + } if let Some(version) = browsers.ios_saf { if version >= 458752 && version <= 852992 { prefixes |= VendorPrefix::WebKit; @@ -1478,7 +1478,7 @@ impl Feature { } } if let Some(version) = browsers.samsung { - if version >= 262144 { + if version >= 262144 && version <= 1572864 { prefixes |= VendorPrefix::WebKit; } } diff --git a/yarn.lock b/yarn.lock index af6b910d..b744a2a1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -454,10 +454,10 @@ resolved "https://registry.yarnpkg.com/@lmdb/lmdb-win32-x64/-/lmdb-win32-x64-2.5.2.tgz#28f643fbc0bec30b07fbe95b137879b6b4d1c9c5" integrity sha512-zrBczSbXKxEyK2ijtbRdICDygRqWSRPpZMN5dD1T8VMEW5RIhIbwFWw2phDRXuBQdVDpSjalCIUMWMV2h3JaZA== -"@mdn/browser-compat-data@~5.5.28": - version "5.5.28" - resolved "https://registry.yarnpkg.com/@mdn/browser-compat-data/-/browser-compat-data-5.5.28.tgz#76cd0651ebf9725916da10b686ac98288403d89f" - integrity sha512-yKS9hfVRsYx/3usEAk+86rq2KnHHyoafyvw2Xob5dXPSOZKIY56Nkas/JK3cmav8nZjjHWiYS/asv9TQy1YLbg== +"@mdn/browser-compat-data@~5.5.44": + version "5.5.44" + resolved "https://registry.yarnpkg.com/@mdn/browser-compat-data/-/browser-compat-data-5.5.44.tgz#f791d414b6f5e738c1f0dbba0f5c0136476f3b14" + integrity sha512-bG2ePe+cjEyZQ9hBB+EzsItnl0hPNs1RLjmRuWX7lS0vJ8ddxTeyoQ8yXkp+DAcprbJ0X65wUCgfjBODCRsB5w== "@mischnic/json-sourcemap@^0.1.0": version "0.1.0" @@ -1228,16 +1228,16 @@ ast-types@0.15.2: dependencies: tslib "^2.0.1" -autoprefixer@^10.4.19: - version "10.4.19" - resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.4.19.tgz#ad25a856e82ee9d7898c59583c1afeb3fa65f89f" - integrity sha512-BaENR2+zBZ8xXhM4pUaKUxlVdxZ0EZhjvbopwnXmxRUfqDmwSpC2lAi/QXvx7NRdPCo1WKEcEF6mV64si1z4Ew== +autoprefixer@^10.4.20: + version "10.4.20" + resolved "https://registry.yarnpkg.com/autoprefixer/-/autoprefixer-10.4.20.tgz#5caec14d43976ef42e32dcb4bd62878e96be5b3b" + integrity sha512-XY25y5xSv/wEoqzDyXXME4AFfkZI0P23z6Fs3YgymDnKJkCGOnkL0iTxCa85UTqaSgfcqyf3UA6+c7wUvx/16g== dependencies: - browserslist "^4.23.0" - caniuse-lite "^1.0.30001599" + browserslist "^4.23.3" + caniuse-lite "^1.0.30001646" fraction.js "^4.3.7" normalize-range "^0.1.2" - picocolors "^1.0.0" + picocolors "^1.0.1" postcss-value-parser "^4.2.0" available-typed-arrays@^1.0.5: @@ -1291,15 +1291,15 @@ braces@^3.0.2: dependencies: fill-range "^7.0.1" -browserslist@^4.0.0, browserslist@^4.16.0, browserslist@^4.16.6, browserslist@^4.23.0, browserslist@^4.6.6: - version "4.23.0" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.23.0.tgz#8f3acc2bbe73af7213399430890f86c63a5674ab" - integrity sha512-QW8HiM1shhT2GuzkvklfjcKDiWFXHOeFCIA/huJPwHsslwcydgk7X+z2zXpEijP98UCY7HbubZt5J2Zgvf0CaQ== +browserslist@^4.0.0, browserslist@^4.16.0, browserslist@^4.16.6, browserslist@^4.23.3, browserslist@^4.6.6: + version "4.23.3" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.23.3.tgz#debb029d3c93ebc97ffbc8d9cbb03403e227c800" + integrity sha512-btwCFJVjI4YWDNfau8RhZ+B1Q/VLoUITrm3RlP6y1tYGWIOa+InuYiRGXUBXo8nA1qKmHMyLB/iVQg5TT4eFoA== dependencies: - caniuse-lite "^1.0.30001587" - electron-to-chromium "^1.4.668" - node-releases "^2.0.14" - update-browserslist-db "^1.0.13" + caniuse-lite "^1.0.30001646" + electron-to-chromium "^1.5.4" + node-releases "^2.0.18" + update-browserslist-db "^1.1.0" buffer-crc32@~0.2.3: version "0.2.13" @@ -1347,10 +1347,10 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001587, caniuse-lite@^1.0.30001599, caniuse-lite@^1.0.30001620: - version "1.0.30001620" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001620.tgz#78bb6f35b8fe315b96b8590597094145d0b146b4" - integrity sha512-WJvYsOjd1/BYUY6SNGUosK9DUidBPDTnOARHp3fSmFO1ekdxaY6nKRttEVrfMmYi80ctS0kz1wiWmm14fVc3ew== +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001646, caniuse-lite@^1.0.30001649: + version "1.0.30001649" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001649.tgz#3ec700309ca0da2b0d3d5fb03c411b191761c992" + integrity sha512-fJegqZZ0ZX8HOWr6rcafGr72+xcgJKI9oWfDW5DrD7ExUtgZC7a7R7ZYmZqplh7XDocFdGeIFn7roAxhOeYrPQ== chalk@^2.0.0: version "2.4.2" @@ -1727,10 +1727,10 @@ dotenv@^7.0.0: resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-7.0.0.tgz#a2be3cd52736673206e8a85fb5210eea29628e7c" integrity sha512-M3NhsLbV1i6HuGzBUH8vXrtxOk+tWmzWKDMbAVSUp3Zsjm7ywFeuwrUXhmhQyRK1q5B5GGy7hcXPbj3bnfZg2g== -electron-to-chromium@^1.4.668: - version "1.4.773" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.773.tgz#49741af9bb4e712ad899e35d8344d8d59cdb7e12" - integrity sha512-87eHF+h3PlCRwbxVEAw9KtK3v7lWfc/sUDr0W76955AdYTG4bV/k0zrl585Qnj/skRMH2qOSiE+kqMeOQ+LOpw== +electron-to-chromium@^1.5.4: + version "1.5.4" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.4.tgz#cd477c830dd6fca41fbd5465c1ff6ce08ac22343" + integrity sha512-orzA81VqLyIGUEA77YkVA1D+N+nNfl2isJVjjmOyrlxuooZ19ynb+dOlaDTqd/idKRS9lDCSBmtzM+kyCsMnkA== end-of-stream@^1.1.0, end-of-stream@^1.4.1: version "1.4.4" @@ -1868,10 +1868,10 @@ esbuild@^0.19.8: "@esbuild/win32-ia32" "0.19.8" "@esbuild/win32-x64" "0.19.8" -escalade@^3.1.1: - version "3.1.1" - resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" - integrity sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw== +escalade@^3.1.2: + version "3.1.2" + resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.2.tgz#54076e9ab29ea5bf3d8f1ed62acffbb88272df27" + integrity sha512-ErCHMCae19vR8vQGe50xIsVomy19rg6gFu3+r3jkEO46suLMWBksvVyoGgQV+jOfl84ZSOSlmv6Gxa89PmTGmA== escape-string-regexp@^1.0.5: version "1.0.5" @@ -2787,10 +2787,10 @@ node-gyp-build@^4.3.0: resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-4.3.0.tgz#9f256b03e5826150be39c764bf51e993946d71a3" integrity sha512-iWjXZvmboq0ja1pUGULQBexmxq8CV4xBhX7VDOTbL7ZR4FOowwY/VOtRxBN/yKxmdGoIp4j5ysNT4u3S2pDQ3Q== -node-releases@^2.0.14: - version "2.0.14" - resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.14.tgz#2ffb053bceb8b2be8495ece1ab6ce600c4461b0b" - integrity sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw== +node-releases@^2.0.18: + version "2.0.18" + resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-2.0.18.tgz#f010e8d35e2fe8d6b2944f03f70213ecedc4ca3f" + integrity sha512-d9VeXT4SJ7ZeOqGX6R5EM022wpL+eWPooLI+5UpWn2jCT1aosUQEhQP214x33Wkwx3JQMvIm+tIoVOdodFS40g== normalize-range@^0.1.2: version "0.1.2" @@ -2983,10 +2983,10 @@ pend@~1.2.0: resolved "https://registry.yarnpkg.com/pend/-/pend-1.2.0.tgz#7a57eb550a6783f9115331fcf4663d5c8e007a50" integrity sha1-elfrVQpng/kRUzH89GY9XI4AelA= -picocolors@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" - integrity sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ== +picocolors@^1.0.0, picocolors@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.1.tgz#a8ad579b571952f0e5d25892de5445bcfe25aaa1" + integrity sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew== picomatch@^2.3.1: version "2.3.1" @@ -3855,13 +3855,13 @@ universalify@^0.1.0: resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.2.tgz#b646f69be3942dabcecc9d6639c80dc105efaa66" integrity sha512-rBJeI5CXAlmy1pV+617WB9J63U6XcazHHF2f2dbJix4XzpUF0RS3Zbj0FGIOCAva5P/d/GBOYaACQ1w+0azUkg== -update-browserslist-db@^1.0.13: - version "1.0.13" - resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.0.13.tgz#3c5e4f5c083661bd38ef64b6328c26ed6c8248c4" - integrity sha512-xebP81SNcPuNpPP3uzeW1NYXxI3rxyJzF3pD6sH4jE7o/IX+WtSpwnVU+qIsDPyk0d3hmFQ7mjqc6AtV604hbg== +update-browserslist-db@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/update-browserslist-db/-/update-browserslist-db-1.1.0.tgz#7ca61c0d8650766090728046e416a8cde682859e" + integrity sha512-EdRAaAyk2cUE1wOf2DkEhzxqOQvFOoRJFNS6NeyJ01Gp2beMRpBAINjM2iDXE3KCuKhwnvHIQCJm6ThL2Z+HzQ== dependencies: - escalade "^3.1.1" - picocolors "^1.0.0" + escalade "^3.1.2" + picocolors "^1.0.1" util-deprecate@^1.0.1, util-deprecate@^1.0.2: version "1.0.2" From 27b727416c16812b3117bb998ee003699dabaa07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barth=C3=A9l=C3=A9my=20Ledoux?= Date: Tue, 6 Aug 2024 06:17:33 +0200 Subject: [PATCH 003/133] feat: add wasm file to file exports (#755) --- scripts/build-wasm.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/scripts/build-wasm.js b/scripts/build-wasm.js index 9f69a9af..5816875f 100644 --- a/scripts/build-wasm.js +++ b/scripts/build-wasm.js @@ -54,14 +54,23 @@ wasmPkg.type = 'module'; wasmPkg.main = 'index.mjs'; wasmPkg.module = 'index.mjs'; wasmPkg.exports = { - types: './index.d.ts', - node: { - import: './wasm-node.mjs', - require: './wasm-node.cjs', + '.': { + types: './index.d.ts', + node: { + import: './wasm-node.mjs', + require: './wasm-node.cjs' + }, + default: { + import: './index.mjs', + require: './index.cjs' + } }, - default: { - import: './index.mjs', - require: './index.cjs', + // Allow esbuild to import the wasm file + // without copying it in the src directory. + // Simplifies loading it in the browser when used in a library. + './lightningcss_node.wasm': { + import: './lightningcss_node.wasm', + require: './lightningcss_node.wasm' } }; wasmPkg.types = 'index.d.ts'; From c7fc5a10120b1a98c603855dd319a6747e6b9409 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Tue, 6 Aug 2024 00:24:54 -0400 Subject: [PATCH 004/133] v1.26.0 --- Cargo.lock | 8 ++++---- Cargo.toml | 6 +++--- derive/Cargo.toml | 2 +- napi/Cargo.toml | 4 ++-- node/Cargo.toml | 2 +- package.json | 2 +- scripts/build-wasm.js | 7 ++----- selectors/Cargo.toml | 2 +- 8 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 29c70813..671f2e01 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -756,7 +756,7 @@ dependencies = [ [[package]] name = "lightningcss" -version = "1.0.0-alpha.57" +version = "1.0.0-alpha.58" dependencies = [ "ahash 0.8.7", "assert_cmd", @@ -792,7 +792,7 @@ dependencies = [ [[package]] name = "lightningcss-derive" -version = "1.0.0-alpha.42" +version = "1.0.0-alpha.43" dependencies = [ "convert_case", "proc-macro2", @@ -802,7 +802,7 @@ dependencies = [ [[package]] name = "lightningcss-napi" -version = "0.2.0" +version = "0.2.1" dependencies = [ "crossbeam-channel", "cssparser", @@ -990,7 +990,7 @@ checksum = "7f222829ae9293e33a9f5e9f440c6760a3d450a64affe1846486b140db81c1f4" [[package]] name = "parcel_selectors" -version = "0.26.5" +version = "0.26.6" dependencies = [ "bitflags 2.4.1", "cssparser", diff --git a/Cargo.toml b/Cargo.toml index 80e64af3..dd55452a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,7 @@ members = [ [package] authors = ["Devon Govett "] name = "lightningcss" -version = "1.0.0-alpha.57" +version = "1.0.0-alpha.58" description = "A CSS parser, transformer, and minifier" license = "MPL-2.0" edition = "2021" @@ -51,7 +51,7 @@ substitute_variables = ["visitor", "into_owned"] serde = { version = "1.0.201", features = ["derive"], optional = true } cssparser = "0.33.0" cssparser-color = "0.1.0" -parcel_selectors = { version = "0.26.5", path = "./selectors" } +parcel_selectors = { version = "0.26.6", path = "./selectors" } itertools = "0.10.1" smallvec = { version = "1.7.0", features = ["union"] } bitflags = "2.2.1" @@ -69,7 +69,7 @@ browserslist-rs = { version = "0.16.0", optional = true } rayon = { version = "1.5.1", optional = true } dashmap = { version = "5.0.0", optional = true } serde_json = { version = "1.0.78", optional = true } -lightningcss-derive = { version = "=1.0.0-alpha.42", path = "./derive" } +lightningcss-derive = { version = "=1.0.0-alpha.43", path = "./derive" } schemars = { version = "0.8.19", features = ["smallvec"], optional = true } static-self = { version = "0.1.0", path = "static-self", optional = true } diff --git a/derive/Cargo.toml b/derive/Cargo.toml index e1f82c70..ce55e5cc 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Devon Govett "] name = "lightningcss-derive" description = "Derive macros for lightningcss" -version = "1.0.0-alpha.42" +version = "1.0.0-alpha.43" license = "MPL-2.0" edition = "2021" repository = "https://github.com/parcel-bundler/lightningcss" diff --git a/napi/Cargo.toml b/napi/Cargo.toml index d8415acd..477c1898 100644 --- a/napi/Cargo.toml +++ b/napi/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Devon Govett "] name = "lightningcss-napi" -version = "0.2.0" +version = "0.2.1" description = "Node-API bindings for Lightning CSS" license = "MPL-2.0" repository = "https://github.com/parcel-bundler/lightningcss" @@ -16,7 +16,7 @@ bundler = ["dep:crossbeam-channel", "dep:rayon"] serde = { version = "1.0.201", features = ["derive"] } serde_bytes = "0.11.5" cssparser = "0.33.0" -lightningcss = { version = "1.0.0-alpha.55", path = "../", features = ["nodejs", "serde"] } +lightningcss = { version = "1.0.0-alpha.56", path = "../", features = ["nodejs", "serde"] } parcel_sourcemap = { version = "2.1.1", features = ["json"] } serde-detach = "0.0.1" smallvec = { version = "1.7.0", features = ["union"] } diff --git a/node/Cargo.toml b/node/Cargo.toml index bb472910..6cf2aa21 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -9,7 +9,7 @@ publish = false crate-type = ["cdylib"] [dependencies] -lightningcss-napi = { version = "0.2.0", path = "../napi", features = ["bundler", "visitor"] } +lightningcss-napi = { version = "0.2.1", path = "../napi", features = ["bundler", "visitor"] } napi = {version = "2.15.4", default-features = false, features = ["compat-mode"]} napi-derive = "2" diff --git a/package.json b/package.json index c51c2888..68e6701d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lightningcss", - "version": "1.25.1", + "version": "1.26.0", "license": "MPL-2.0", "description": "A CSS parser, transformer, and minifier written in Rust", "main": "node/index.js", diff --git a/scripts/build-wasm.js b/scripts/build-wasm.js index 5816875f..718821da 100644 --- a/scripts/build-wasm.js +++ b/scripts/build-wasm.js @@ -65,13 +65,10 @@ wasmPkg.exports = { require: './index.cjs' } }, - // Allow esbuild to import the wasm file + // Allow esbuild to import the wasm file // without copying it in the src directory. // Simplifies loading it in the browser when used in a library. - './lightningcss_node.wasm': { - import: './lightningcss_node.wasm', - require: './lightningcss_node.wasm' - } + './lightningcss_node.wasm': './lightningcss_node.wasm' }; wasmPkg.types = 'index.d.ts'; wasmPkg.sideEffects = false; diff --git a/selectors/Cargo.toml b/selectors/Cargo.toml index 8cad46af..4c212970 100644 --- a/selectors/Cargo.toml +++ b/selectors/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parcel_selectors" -version = "0.26.5" +version = "0.26.6" authors = ["The Servo Project Developers"] documentation = "https://docs.rs/parcel_selectors/" description = "CSS Selectors matching for Rust - forked for lightningcss" From 262d120c5a87890b72a28ec6206fa695dcff0c4c Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Tue, 6 Aug 2024 11:07:35 -0400 Subject: [PATCH 005/133] bump freebsd --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ac107a13..17214581 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -162,7 +162,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Build FreeBSD - uses: cross-platform-actions/action@v0.23.0 + uses: cross-platform-actions/action@v0.25.0 env: DEBUG: napi:* RUSTUP_HOME: /usr/local/rustup @@ -170,7 +170,7 @@ jobs: RUSTUP_IO_THREADS: 1 with: operating_system: freebsd - version: '13.2' + version: '14.0' memory: 13G cpu_count: 3 environment_variables: 'DEBUG RUSTUP_IO_THREADS' From 0bcd896e81a8a2c5d847f626a37e2cffea79e2a0 Mon Sep 17 00:00:00 2001 From: Devon Govett Date: Tue, 6 Aug 2024 11:12:52 -0400 Subject: [PATCH 006/133] Add arm Windows support Fixes #724 --- .github/workflows/release.yml | 3 +++ scripts/build-npm.js | 3 +++ 2 files changed, 6 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 17214581..0a0a9618 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -12,6 +12,9 @@ jobs: - os: windows-latest target: x86_64-pc-windows-msvc binary: lightningcss.exe + - os: windows-latest + target: aarch64-pc-windows-msvc + binary: lightningcss.exe # Mac OS - os: macos-latest target: x86_64-apple-darwin diff --git a/scripts/build-npm.js b/scripts/build-npm.js index dd4c91bc..ca89d669 100644 --- a/scripts/build-npm.js +++ b/scripts/build-npm.js @@ -15,6 +15,9 @@ const triples = [ { name: 'x86_64-pc-windows-msvc', }, + { + name: 'aarch64-pc-windows-msvc' + }, { name: 'aarch64-apple-darwin', }, From 73d4cde3b6a67b94a6d5b806c444345623927e5f Mon Sep 17 00:00:00 2001 From: Courtney Ferguson Date: Tue, 27 Aug 2024 17:13:29 -0600 Subject: [PATCH 007/133] feat: Add content-hash css module name pattern (#802) --- c/src/lib.rs | 1 + src/bundler.rs | 56 ++++++++++++++++++++++++++++++++++++ src/css_modules.rs | 56 ++++++++++++++++++++++++++++++++++-- src/lib.rs | 22 ++++++++++++++ src/printer.rs | 10 +++++++ src/stylesheet.rs | 26 +++++++++++++++-- website/pages/css-modules.md | 1 + 7 files changed, 168 insertions(+), 4 deletions(-) diff --git a/c/src/lib.rs b/c/src/lib.rs index ba689d96..759a18db 100644 --- a/c/src/lib.rs +++ b/c/src/lib.rs @@ -281,6 +281,7 @@ pub extern "C" fn lightningcss_stylesheet_parse( Some(lightningcss::css_modules::Config { pattern, dashed_idents: options.css_modules_dashed_idents, + ..Default::default() }) } else { None diff --git a/src/bundler.rs b/src/bundler.rs index d73545b8..00988487 100644 --- a/src/bundler.rs +++ b/src/bundler.rs @@ -293,6 +293,23 @@ where .flat_map(|s| s.stylesheet.as_ref().unwrap().license_comments.iter().cloned()) .collect(); + if let Some(config) = &self.options.css_modules { + if config.pattern.has_content_hash() { + stylesheet.content_hashes = Some( + self + .stylesheets + .get_mut() + .unwrap() + .iter() + .flat_map(|s| { + let s = s.stylesheet.as_ref().unwrap(); + s.content_hashes.as_ref().unwrap().iter().cloned() + }) + .collect(), + ); + } + } + Ok(stylesheet) } @@ -866,6 +883,15 @@ mod tests { fs: P, entry: &str, project_root: Option<&str>, + ) -> (String, CssModuleExports) { + bundle_css_module_with_pattern(fs, entry, project_root, "[hash]_[local]") + } + + fn bundle_css_module_with_pattern( + fs: P, + entry: &str, + project_root: Option<&str>, + pattern: &'static str, ) -> (String, CssModuleExports) { let mut bundler = Bundler::new( &fs, @@ -873,6 +899,7 @@ mod tests { ParserOptions { css_modules: Some(css_modules::Config { dashed_idents: true, + pattern: css_modules::Pattern::parse(pattern).unwrap(), ..Default::default() }), ..ParserOptions::default() @@ -1978,6 +2005,35 @@ mod tests { Some("/x/y/z"), ); assert_eq!(code, expected); + + let (code, _) = bundle_css_module_with_pattern( + TestProvider { + map: fs! { + "/a.css": r#" + @import "b.css"; + .a { color: red } + "#, + "/b.css": r#" + .a { color: green } + "# + }, + }, + "/a.css", + None, + "[content-hash]-[local]", + ); + assert_eq!( + code, + indoc! { r#" + .do5n2W-a { + color: green; + } + + .pP97eq-a { + color: red; + } + "#} + ); } #[test] diff --git a/src/css_modules.rs b/src/css_modules.rs index cfe33d71..07327315 100644 --- a/src/css_modules.rs +++ b/src/css_modules.rs @@ -107,6 +107,7 @@ impl<'i> Pattern<'i> { "[name]" => Segment::Name, "[local]" => Segment::Local, "[hash]" => Segment::Hash, + "[content-hash]" => Segment::ContentHash, s => return Err(PatternParseError::UnknownPlaceholder(s.into(), start_idx)), }; segments.push(segment); @@ -126,8 +127,20 @@ impl<'i> Pattern<'i> { Ok(Pattern { segments }) } + /// Whether the pattern contains any `[content-hash]` segments. + pub fn has_content_hash(&self) -> bool { + self.segments.iter().any(|s| matches!(s, Segment::ContentHash)) + } + /// Write the substituted pattern to a destination. - pub fn write(&self, hash: &str, path: &Path, local: &str, mut write: W) -> Result<(), E> + pub fn write( + &self, + hash: &str, + path: &Path, + local: &str, + content_hash: &str, + mut write: W, + ) -> Result<(), E> where W: FnMut(&str) -> Result<(), E>, { @@ -150,6 +163,9 @@ impl<'i> Pattern<'i> { Segment::Hash => { write(hash)?; } + Segment::ContentHash => { + write(content_hash)?; + } } } Ok(()) @@ -162,8 +178,9 @@ impl<'i> Pattern<'i> { hash: &str, path: &Path, local: &str, + content_hash: &str, ) -> Result { - self.write(hash, path, local, |s| res.write_str(s))?; + self.write(hash, path, local, content_hash, |s| res.write_str(s))?; Ok(res) } } @@ -181,6 +198,8 @@ pub enum Segment<'i> { Local, /// A hash of the file name. Hash, + /// A hash of the file contents. + ContentHash, } /// A referenced name within a CSS module, e.g. via the `composes` property. @@ -245,6 +264,7 @@ pub(crate) struct CssModule<'a, 'b, 'c> { pub config: &'a Config<'b>, pub sources: Vec<&'c Path>, pub hashes: Vec, + pub content_hashes: &'a Option>, pub exports_by_source_index: Vec, pub references: &'a mut HashMap, } @@ -255,6 +275,7 @@ impl<'a, 'b, 'c> CssModule<'a, 'b, 'c> { sources: &'c Vec, project_root: Option<&'c str>, references: &'a mut HashMap, + content_hashes: &'a Option>, ) -> Self { let project_root = project_root.map(|p| Path::new(p)); let sources: Vec<&Path> = sources.iter().map(|filename| Path::new(filename)).collect(); @@ -279,6 +300,7 @@ impl<'a, 'b, 'c> CssModule<'a, 'b, 'c> { exports_by_source_index: sources.iter().map(|_| HashMap::new()).collect(), sources, hashes, + content_hashes, references, } } @@ -295,6 +317,11 @@ impl<'a, 'b, 'c> CssModule<'a, 'b, 'c> { &self.hashes[source_index as usize], &self.sources[source_index as usize], local, + if let Some(content_hashes) = &self.content_hashes { + &content_hashes[source_index as usize] + } else { + "" + }, ) .unwrap(), composes: vec![], @@ -314,6 +341,11 @@ impl<'a, 'b, 'c> CssModule<'a, 'b, 'c> { &self.hashes[source_index as usize], &self.sources[source_index as usize], &local[2..], + if let Some(content_hashes) = &self.content_hashes { + &content_hashes[source_index as usize] + } else { + "" + }, ) .unwrap(), composes: vec![], @@ -336,6 +368,11 @@ impl<'a, 'b, 'c> CssModule<'a, 'b, 'c> { &self.hashes[source_index as usize], &self.sources[source_index as usize], name, + if let Some(content_hashes) = &self.content_hashes { + &content_hashes[source_index as usize] + } else { + "" + }, ) .unwrap(), composes: vec![], @@ -365,6 +402,11 @@ impl<'a, 'b, 'c> CssModule<'a, 'b, 'c> { &self.hashes[*source_index as usize], &self.sources[*source_index as usize], &name[2..], + if let Some(content_hashes) = &self.content_hashes { + &content_hashes[*source_index as usize] + } else { + "" + }, ) .unwrap(), ) @@ -385,6 +427,11 @@ impl<'a, 'b, 'c> CssModule<'a, 'b, 'c> { &self.hashes[source_index as usize], &self.sources[source_index as usize], &name[2..], + if let Some(content_hashes) = &self.content_hashes { + &content_hashes[source_index as usize] + } else { + "" + }, ) .unwrap(), composes: vec![], @@ -427,6 +474,11 @@ impl<'a, 'b, 'c> CssModule<'a, 'b, 'c> { &self.hashes[source_index as usize], &self.sources[source_index as usize], name.0.as_ref(), + if let Some(content_hashes) = &self.content_hashes { + &content_hashes[source_index as usize] + } else { + "" + }, ) .unwrap(), }, diff --git a/src/lib.rs b/src/lib.rs index 02bf9fcf..e30dad5b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24177,6 +24177,28 @@ mod tests { crate::css_modules::Config { ..Default::default() }, ); + css_modules_test( + r#" + .test { + composes: foo bar from "foo.css"; + background: white; + } + "#, + indoc! {r#" + ._5h2kwG-test { + background: #fff; + } + "#}, + map! { + "test" => "_5h2kwG-test" "foo" from "foo.css" "bar" from "foo.css" + }, + HashMap::new(), + crate::css_modules::Config { + pattern: crate::css_modules::Pattern::parse("[content-hash]-[local]").unwrap(), + ..Default::default() + }, + ); + // Stable hashes between project roots. fn test_project_root(project_root: &str, filename: &str, hash: &str) { let stylesheet = StyleSheet::parse( diff --git a/src/printer.rs b/src/printer.rs index d8c08e2d..235a8eab 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -276,6 +276,11 @@ impl<'a, 'b, 'c, W: std::fmt::Write + Sized> Printer<'a, 'b, 'c, W> { &css_module.hashes[self.loc.source_index as usize], &css_module.sources[self.loc.source_index as usize], ident, + if let Some(content_hashes) = &css_module.content_hashes { + &content_hashes[self.loc.source_index as usize] + } else { + "" + }, |s| { self.col += s.len() as u32; if first { @@ -306,6 +311,11 @@ impl<'a, 'b, 'c, W: std::fmt::Write + Sized> Printer<'a, 'b, 'c, W> { &css_module.hashes[self.loc.source_index as usize], &css_module.sources[self.loc.source_index as usize], &ident[2..], + if let Some(content_hashes) = &css_module.content_hashes { + &content_hashes[self.loc.source_index as usize] + } else { + "" + }, |s| { self.col += s.len() as u32; serialize_name(s, dest) diff --git a/src/stylesheet.rs b/src/stylesheet.rs index 2848bf2b..7c332b77 100644 --- a/src/stylesheet.rs +++ b/src/stylesheet.rs @@ -4,7 +4,7 @@ //! A [StyleAttribute](StyleAttribute) represents an inline `style` attribute in HTML. use crate::context::{DeclarationContext, PropertyHandlerContext}; -use crate::css_modules::{CssModule, CssModuleExports, CssModuleReferences}; +use crate::css_modules::{hash, CssModule, CssModuleExports, CssModuleReferences}; use crate::declaration::{DeclarationBlock, DeclarationHandler}; use crate::dependencies::Dependency; use crate::error::{Error, ErrorLocation, MinifyErrorKind, ParserError, PrinterError, PrinterErrorKind}; @@ -81,6 +81,10 @@ pub struct StyleSheet<'i, 'o, T = DefaultAtRule> { pub(crate) source_map_urls: Vec