Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
chore: Parse css backgorund support (#3635)
Ivan Starkov764ddc6f0072
diff --git a/apps/builder/app/routes/$.tsx b/apps/builder/app/routes/$.tsxindex 350130dee8..476b7bd85f 100644--- a/apps/builder/app/routes/$.tsx+++ b/apps/builder/app/routes/$.tsx@@ -26,10 +26,10 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {// This is because immutable caching rules apply to redirects, causing these files// to become permanently inaccessible. Ensure asset files are served correctly// without redirects to maintain availability and proper caching behavior.- const publicPath = "/assets/";+ const publicPaths = ["/cgi/", "/assets/"];// In case of 404 on static assets, this route will be executed- if (url.pathname.startsWith(publicPath)) {+ if (publicPaths.some((publicPath) => url.pathname.startsWith(publicPath))) {throw new Response("Not found", {status: 404,headers: {diff --git a/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.test.tsx b/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.test.tsxindex 620eb5b979..8503f96fce 100644--- a/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.test.tsx+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.test.tsx@@ -1968,3 +1968,125 @@ test("Breakpoints", async () => {}"`);});++test("background images", async () => {+ const fragment = await toWebstudioFragment({+ type: "@webflow/XscpData",+ payload: {+ nodes: [+ {+ _id: "2e9842a4-ac18-9d21-894b-026c6eb20441",+ type: "Block",+ tag: "div",+ classes: ["98133834-439c-9a8c-7e9f-c3186f2fa45f"],+ children: [],+ data: {+ text: false,+ },+ },+ ],+ styles: [+ {+ _id: "98133834-439c-9a8c-7e9f-c3186f2fa45f",+ fake: false,+ type: "class",+ name: "Div Block",+ namespace: "",+ comb: "",+ styleLess:+ "height: 400px; background-image: linear-gradient(180deg, hsla(0, 0.00%, 0.00%, 0.11), white), @img_667d0b7769e0cc3754b584f6, @img_667d0fe180995eadc1534a26; background-position: 0px 0px, 550px 0px, 0px 0px; background-size: auto, contain, auto; background-repeat: repeat, no-repeat, repeat; background-attachment: scroll, fixed, scroll;",+ variants: {},+ children: [],+ createdBy: "5b7c48038bdf56493c54eae4",+ origin: null,+ selector: null,+ },+ ],+ assets: [+ {+ cdnUrl:+ "https://uploads-ssl.webflow.com/667c32290bd6159c18dca9a0/667d0b7769e0cc3754b584f6_IMG_2882%20(1).png",+ siteId: "667c32290bd6159c18dca9a0",+ width: 800,+ height: 600,+ fileName: "IMG_2882 (1).png",+ createdOn: "2024-06-27T06:49:27.100Z",+ origFileName: "IMG_2882 (1).png",+ fileHash: "36f49907757795f0a4ecfcfdfc483115",+ variants: [+ {+ origFileName: "IMG_2882%20(1)-p-500.png",+ fileName: "667d0b7769e0cc3754b584f6_IMG_2882%20(1)-p-500.png",+ format: "png",+ size: 192728,+ width: 500,+ quality: 100,+ cdnUrl:+ "https://daks2k3a4ib2z.cloudfront.net/667c32290bd6159c18dca9a0/667d0b7769e0cc3754b584f6_IMG_2882%20(1)-p-500.png",+ s3Url:+ "https://s3.amazonaws.com/webflow-prod-assets/667c32290bd6159c18dca9a0/667d0b7769e0cc3754b584f6_IMG_2882%20(1)-p-500.png",+ },+ ],+ mimeType: "image/png",+ s3Url:+ "https://s3.amazonaws.com/webflow-prod-assets/667c32290bd6159c18dca9a0/667d0b7769e0cc3754b584f6_IMG_2882%20(1).png",+ thumbUrl: "",+ _id: "667d0b7769e0cc3754b584f6",+ markedAsDeleted: false,+ fileSize: 862053,+ },+ {+ cdnUrl:+ "https://uploads-ssl.webflow.com/667c32290bd6159c18dca9a0/667d0fe180995eadc1534a26_%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%20%D0%9C%D0%B8%D1%80%20%3A%20%252F%20.webp",+ siteId: "667c32290bd6159c18dca9a0",+ width: 1024,+ height: 1024,+ fileName: "Привет Мир : %2F .webp",+ createdOn: "2024-06-27T07:08:17.010Z",+ origFileName: "Привет Мир : %2F .webp",+ fileHash: "d86e52a94c04120f455b276effa59046",+ variants: [+ {+ origFileName:+ "%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%20%D0%9C%D0%B8%D1%80%20%3A%20%252F%20-p-500.webp",+ fileName:+ "667d0fe180995eadc1534a26_%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%20%D0%9C%D0%B8%D1%80%20%3A%20%252F%20-p-500.webp",+ format: "webp",+ size: 26992,+ width: 500,+ quality: 100,+ cdnUrl:+ "https://daks2k3a4ib2z.cloudfront.net/667c32290bd6159c18dca9a0/667d0fe180995eadc1534a26_%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%20%D0%9C%D0%B8%D1%80%20%3A%20%252F%20-p-500.webp",+ s3Url:+ "https://s3.amazonaws.com/webflow-prod-assets/667c32290bd6159c18dca9a0/667d0fe180995eadc1534a26_%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%20%D0%9C%D0%B8%D1%80%20%3A%20%252F%20-p-500.webp",+ },+ {+ origFileName:+ "%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%20%D0%9C%D0%B8%D1%80%20%3A%20%252F%20-p-800.webp",+ fileName:+ "667d0fe180995eadc1534a26_%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%20%D0%9C%D0%B8%D1%80%20%3A%20%252F%20-p-800.webp",+ format: "webp",+ size: 45964,+ width: 800,+ quality: 100,+ cdnUrl:+ "https://daks2k3a4ib2z.cloudfront.net/667c32290bd6159c18dca9a0/667d0fe180995eadc1534a26_%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%20%D0%9C%D0%B8%D1%80%20%3A%20%252F%20-p-800.webp",+ s3Url:+ "https://s3.amazonaws.com/webflow-prod-assets/667c32290bd6159c18dca9a0/667d0fe180995eadc1534a26_%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%20%D0%9C%D0%B8%D1%80%20%3A%20%252F%20-p-800.webp",+ },+ ],+ mimeType: "image/webp",+ s3Url:+ "https://s3.amazonaws.com/webflow-prod-assets/667c32290bd6159c18dca9a0/667d0fe180995eadc1534a26_%D0%9F%D1%80%D0%B8%D0%B2%D0%B5%D1%82%20%D0%9C%D0%B8%D1%80%20%3A%20%252F%20.webp",+ thumbUrl: "",+ _id: "667d0fe180995eadc1534a26",+ markedAsDeleted: false,+ fileSize: 191270,+ },+ ],+ },+ });++ // @todo finish in the following PR+ fragment;+});diff --git a/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.ts b/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.tsindex 2c899cca2b..dbece143e9 100644--- a/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.ts+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/plugin-webflow.ts@@ -14,7 +14,7 @@ import {$selectedPage,$project,} from "../../nano-states";-import { WfData, WfNode, WfStyle, wfNodeTypes } from "./schema";+import { WfData, WfNode, WfStyle, wfNodeTypes, type WfAsset } from "./schema";import { addInstanceAndProperties } from "./instances-properties";import { addStyles } from "./styles";import { builderApi } from "~/shared/builder-api";@@ -48,6 +48,11 @@ const toWebstudioFragment = async (wfData: WfData) => {const wfStyles = new Map<WfStyle["_id"], WfStyle>(wfData.payload.styles.map((style: WfStyle) => [style._id, style]));++ const wfAssets = new Map<WfAsset["_id"], WfAsset>(+ wfData.payload.assets.map((asset: WfAsset) => [asset._id, asset])+ );+// False value used to skip a node.const doneNodes = new Map<WfNode["_id"], Instance["id"] | false>();for (const wfNode of wfNodes.values()) {@@ -70,6 +75,7 @@ const toWebstudioFragment = async (wfData: WfData) => {await addStyles(wfNodes,wfStyles,+ wfAssets,doneNodes,fragment,generateStyleSourceIddiff --git a/apps/builder/app/shared/copy-paste/plugin-webflow/schema.ts b/apps/builder/app/shared/copy-paste/plugin-webflow/schema.tsindex 902ab33ed6..5168ea3a63 100644--- a/apps/builder/app/shared/copy-paste/plugin-webflow/schema.ts+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/schema.ts@@ -261,7 +261,7 @@ export const WfStyle = z.object({});export type WfStyle = z.infer<typeof WfStyle>;-const AssetVariantSchema = z.object({+const WfAssetVariant = z.object({origFileName: z.string(),fileName: z.string(),format: z.string(),@@ -273,7 +273,7 @@ const AssetVariantSchema = z.object({s3Url: z.string().url(),});-export const WfAssetSchema = z.object({+const WfAsset = z.object({cdnUrl: z.string().url(),siteId: z.string(),width: z.number(),@@ -282,7 +282,7 @@ export const WfAssetSchema = z.object({createdOn: z.string(),origFileName: z.string(),fileHash: z.string(),- variants: z.array(AssetVariantSchema),+ variants: z.array(WfAssetVariant),mimeType: z.string(),s3Url: z.string().url(),thumbUrl: z.string(),@@ -291,13 +291,15 @@ export const WfAssetSchema = z.object({fileSize: z.number(),});+export type WfAsset = z.infer<typeof WfAsset>;+export const WfData = z.object({type: z.literal("@webflow/XscpData"),payload: z.object({// Using WfBaseNode here just so we can skip a node with unknown node.type.nodes: z.array(z.union([WfNode, WfBaseNode])),styles: z.array(WfStyle),- assets: z.array(WfAssetSchema),+ assets: z.array(WfAsset),}),});export type WfData = z.infer<typeof WfData>;diff --git a/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts b/apps/builder/app/shared/copy-paste/plugin-webflow/styles.tsindex 2a1a2258ab..873e2abf7e 100644--- a/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts@@ -4,7 +4,7 @@ import type {Instance,WebstudioFragment,} from "@webstudio-is/sdk";-import type { WfElementNode, WfNode, WfStyle } from "./schema";+import type { WfAsset, WfElementNode, WfNode, WfStyle } from "./schema";import { nanoid } from "nanoid";import { $breakpoints } from "~/shared/nano-states";import { parseCss, pseudoElements } from "@webstudio-is/css-data";@@ -77,6 +77,15 @@ const replaceAtVariables = (styles: string) => {return styles.replace(/@var_[\w-]+/g, "unset");};+// Converts webflow asset references like `@img_667d0b7769e0cc3754b584f6` to valid urls like+// url("https://667d0b7769e0cc3754b584f6") to not break csstree parser+const replaceAtImages = (styles: string) => {+ return styles.replace(/@img_[\w-]+/g, (match) => {+ const assetId = match.slice(5);+ return `url("https://${assetId}")`;+ });+};+type UnparsedVariants = Map<string, string | Array<EmbedTemplateStyleDecl>>;// Variants value can be wf styleLess string which is a styles block@@ -91,9 +100,7 @@ const toParsedVariants = (variants: UnparsedVariants) => {const { breakpointName, state } = parseVariantName(variant);if (typeof styles === "string") {try {- const parsed =- parseCss(`.styles${state} {${replaceAtVariables(styles)}}`).styles ??- [];+ const parsed = parseCss(`.styles${state} {${styles}}`).styles ?? [];const allBreakpointStyles = parsedVariants.get(breakpointName) ?? [];allBreakpointStyles.push(...parsed);parsedVariants.set(breakpointName, allBreakpointStyles);@@ -298,6 +305,7 @@ const mapComponentAndPresetStyles = (export const addStyles = async (wfNodes: Map<WfNode["_id"], WfNode>,wfStyles: Map<WfStyle["_id"], WfStyle>,+ wfAssets: Map<WfAsset["_id"], WfAsset>,doneNodes: Map<WfNode["_id"], Instance["id"] | false>,fragment: WebstudioFragment,generateStyleSourceId: (sourceData: string) => Promise<string>@@ -352,12 +360,18 @@ export const addStyles = async (instance.label = style.name;}const variants = new Map();- variants.set("base", style.styleLess);+ variants.set(+ "base",+ replaceAtImages(replaceAtVariables(style.styleLess))+ );const wfVariants = style.variants ?? {};Object.keys(wfVariants).forEach((breakpointName) => {const variant = wfVariants[breakpointName as keyof typeof wfVariants];if (variant && "styleLess" in variant) {- variants.set(breakpointName, variant.styleLess);+ variants.set(+ breakpointName,+ replaceAtImages(replaceAtVariables(variant.styleLess))+ );}});diff --git a/packages/css-data/src/parse-css.test.ts b/packages/css-data/src/parse-css.test.tsindex 3f73b6e9ec..86e714358b 100644--- a/packages/css-data/src/parse-css.test.ts+++ b/packages/css-data/src/parse-css.test.ts@@ -39,9 +39,9 @@ describe("Parse CSS", () => {test("parses supported shorthand values", () => {const css = `- .test {- background: #ff0000 linear-gradient(180deg, #11181C 0%, rgba(17, 24, 28, 0) 36.09%), #EBFFFC;- }+ .test {+ background: #ff0000 linear-gradient(180deg, #11181C 0%, rgba(17, 24, 28, 0) 36.09%), #EBFFFC;+ }`;expect(parseCss(css)).toMatchInlineSnapshot(`{@@ -73,6 +73,163 @@ describe("Parse CSS", () => {`);});+ test("parses supported shorthand values 2", () => {+ const css = `+ .test {+ background-image: linear-gradient(180deg, hsla(0, 0.00%, 0.00%, 0.11), white), url("https://667d0b7769e0cc3754b584f6"), url("https://667d0fe180995eadc1534a26");+ background-position: 0px 0px, 550px 0px, 0px 0px;+ background-size: auto, contain, auto;+ background-repeat: repeat, no-repeat, repeat;+ background-attachment: scroll, fixed, scroll;+ }+ `;+ expect(parseCss(css)).toMatchInlineSnapshot(`+{+ "test": [+ {+ "property": "backgroundImage",+ "value": {+ "type": "layers",+ "value": [+ {+ "type": "unparsed",+ "value": "linear-gradient(180deg,hsla(0,0.00%,0.00%,0.11),white)",+ },+ {+ "type": "image",+ "value": {+ "type": "url",+ "url": "https://667d0b7769e0cc3754b584f6",+ },+ },+ {+ "type": "image",+ "value": {+ "type": "url",+ "url": "https://667d0fe180995eadc1534a26",+ },+ },+ ],+ },+ },+ {+ "property": "backgroundPosition",+ "value": {+ "type": "layers",+ "value": [+ {+ "type": "tuple",+ "value": [+ {+ "type": "unit",+ "unit": "px",+ "value": 0,+ },+ {+ "type": "unit",+ "unit": "px",+ "value": 0,+ },+ ],+ },+ {+ "type": "tuple",+ "value": [+ {+ "type": "unit",+ "unit": "px",+ "value": 550,+ },+ {+ "type": "unit",+ "unit": "px",+ "value": 0,+ },+ ],+ },+ {+ "type": "tuple",+ "value": [+ {+ "type": "unit",+ "unit": "px",+ "value": 0,+ },+ {+ "type": "unit",+ "unit": "px",+ "value": 0,+ },+ ],+ },+ ],+ },+ },+ {+ "property": "backgroundSize",+ "value": {+ "type": "layers",+ "value": [+ {+ "type": "keyword",+ "value": "auto",+ },+ {+ "type": "keyword",+ "value": "contain",+ },+ {+ "type": "keyword",+ "value": "auto",+ },+ ],+ },+ },+ {+ "property": "backgroundRepeat",+ "value": {+ "type": "layers",+ "value": [+ {+ "type": "keyword",+ "value": "repeat",+ },+ {+ "type": "keyword",+ "value": "no-repeat",+ },+ {+ "type": "keyword",+ "value": "repeat",+ },+ ],+ },+ },+ {+ "property": "backgroundAttachment",+ "value": {+ "type": "layers",+ "value": [+ {+ "type": "keyword",+ "value": "scroll",+ },+ {+ "type": "keyword",+ "value": "fixed",+ },+ {+ "type": "keyword",+ "value": "scroll",+ },+ ],+ },+ },+ ],+}+`);+ });+test("parse state", () => {expect(parseCss(`a:hover { color: #ff0000 }`)).toMatchInlineSnapshot(`{@@ -214,7 +371,7 @@ describe("Parse CSS", () => {margin-bottom: 10px;font-weight: bold;}-+h1 {margin-top: 20px;font-size: 38px;diff --git a/packages/css-data/src/parse-css.ts b/packages/css-data/src/parse-css.tsindex d2ea997817..42a12394b4 100644--- a/packages/css-data/src/parse-css.ts+++ b/packages/css-data/src/parse-css.ts@@ -1,11 +1,16 @@import * as csstree from "css-tree";-import { StyleValue, type StyleProperty } from "@webstudio-is/css-engine";+import {+ LayersValue,+ StyleValue,+ type StyleProperty,+} from "@webstudio-is/css-engine";import type { EmbedTemplateStyleDecl } from "@webstudio-is/react-sdk";import { parseCssValue as parseCssValueLonghand } from "./parse-css-value";import * as parsers from "./property-parsers/parsers";import * as toLonghand from "./property-parsers/to-longhand";import { camelCase } from "change-case";import { expandShorthands } from "./shorthands";+import { parseBackground } from "./property-parsers";// @todo we don't parse correctly most of them if not allconst prefixedProperties = [@@ -113,6 +118,63 @@ const cssTreeTryParse = (input: string) => {}};+const convertBackgroundProps = (styles: EmbedTemplateStyleDecl[]) => {+ const backgroundProps = [+ "backgroundAttachment",+ "backgroundClip",+ "backgroundBlendMode",+ "backgroundOrigin",+ "backgroundPosition",+ "backgroundRepeat",+ "backgroundSize",+ ];++ return styles+ .map((style) => {+ if (backgroundProps.includes(style.property)) {+ if (style.value.type !== "unparsed") {+ return style;+ }++ const layersResult = LayersValue.safeParse({+ type: "layers",+ value: style.value.value+ .split(",")+ .map((val) => parseCssValueLonghand(style.property, val)),+ });++ if (layersResult.success) {+ return {+ property: style.property,+ value: layersResult.data,+ };+ }++ console.error(+ `Failed to convert background property ${+ style.property+ } with value ${JSON.stringify(style.value)} to layers`+ );+ }+ return style;+ })+ .map((style) => {+ if (style.property === "backgroundImage") {+ if (style.value.type !== "unparsed") {+ return style;+ }++ const { backgroundImage } = parseBackground(style.value.value);++ return {+ property: style.property,+ value: backgroundImage,+ };+ }+ return style;+ });+};+export const parseCss = (css: string) => {const ast = cssTreeTryParse(css);let selectors: Selector[] = [];@@ -200,5 +262,11 @@ export const parseCss = (css: string) => {}});- return styles;+ const stylesResult: Styles = {};++ for (const [selector, declarations] of Object.entries(styles)) {+ stylesResult[selector] = convertBackgroundProps(declarations);+ }++ return stylesResult;};diff --git a/packages/css-data/src/property-parsers/background.test.ts b/packages/css-data/src/property-parsers/background.test.tsindex 75e5f6489f..ce203d4770 100644--- a/packages/css-data/src/property-parsers/background.test.ts+++ b/packages/css-data/src/property-parsers/background.test.ts@@ -97,35 +97,42 @@ describe("parseBackground", () => {"url(https://hello.world/some-image), linear-gradient(180deg, rgba(230, 60, 254, 0.33) 0%, rgba(255, 174, 60, 0) 100%), radial-gradient(54.1% 95.83% at 100% 100%, #FFFFFF 0%, rgba(255, 255, 255, 0) 100%), linear-gradient(122.33deg, rgba(74, 78, 250, 0.2) 0%, rgba(0, 0, 0, 0) 69.38%), radial-gradient(92.26% 201.29% at 98.6% 10.65%, rgba(255, 174, 60, 0.3) 0%, rgba(227, 53, 255, 0) 100%) /* warning: gradient uses a rotation that is not supported by CSS and may not behave as expected */, radial-gradient(84.64% 267.51% at 10.07% 81.45%, rgba(53, 255, 182, 0.2) 0%, rgba(74, 78, 250, 0.2) 100%) /* warning: gradient uses a rotation that is not supported by CSS and may not behave as expected */")).toMatchInlineSnapshot(`+{+ "backgroundColor": undefined,+ "backgroundImage": {+ "type": "layers",+ "value": [{- "backgroundColor": undefined,- "backgroundImage": {- "type": "layers",- "value": [- {- "type": "unparsed",- "value": "linear-gradient(180deg,rgba(230,60,254,0.33) 0%,rgba(255,174,60,0) 100%)",- },- {- "type": "unparsed",- "value": "radial-gradient(54.1% 95.83%at 100% 100%,#FFFFFF 0%,rgba(255,255,255,0) 100%)",- },- {- "type": "unparsed",- "value": "linear-gradient(122.33deg,rgba(74,78,250,0.2) 0%,rgba(0,0,0,0) 69.38%)",- },- {- "type": "unparsed",- "value": "radial-gradient(92.26% 201.29%at 98.6% 10.65%,rgba(255,174,60,0.3) 0%,rgba(227,53,255,0) 100%)",- },- {- "type": "unparsed",- "value": "radial-gradient(84.64% 267.51%at 10.07% 81.45%,rgba(53,255,182,0.2) 0%,rgba(74,78,250,0.2) 100%)",- },- ],+ "type": "image",+ "value": {+ "type": "url",+ "url": "https://hello.world/some-image",},- }- `);+ },+ {+ "type": "unparsed",+ "value": "linear-gradient(180deg,rgba(230,60,254,0.33) 0%,rgba(255,174,60,0) 100%)",+ },+ {+ "type": "unparsed",+ "value": "radial-gradient(54.1% 95.83%at 100% 100%,#FFFFFF 0%,rgba(255,255,255,0) 100%)",+ },+ {+ "type": "unparsed",+ "value": "linear-gradient(122.33deg,rgba(74,78,250,0.2) 0%,rgba(0,0,0,0) 69.38%)",+ },+ {+ "type": "unparsed",+ "value": "radial-gradient(92.26% 201.29%at 98.6% 10.65%,rgba(255,174,60,0.3) 0%,rgba(227,53,255,0) 100%)",+ },+ {+ "type": "unparsed",+ "value": "radial-gradient(84.64% 267.51%at 10.07% 81.45%,rgba(53,255,182,0.2) 0%,rgba(74,78,250,0.2) 100%)",+ },+ ],+ },+}+`);});test("parse background partially copied background", () => {diff --git a/packages/css-data/src/property-parsers/background.ts b/packages/css-data/src/property-parsers/background.tsindex 64f98cd1fa..27e0f84342 100644--- a/packages/css-data/src/property-parsers/background.ts+++ b/packages/css-data/src/property-parsers/background.ts@@ -1,5 +1,6 @@import * as csstree from "css-tree";import type {+ ImageValue,InvalidValue,LayersValue,RgbValue,@@ -89,12 +90,18 @@ export const backgroundToLonghand = (}nestingLevel++;+ return;}if (node.type === "Hash" && item.next === null && nestingLevel === 0) {// If the depth is at level 0 and the next item is null, it's likely that the backgroundColor// is written as hex #XYZFGHbackgroundColorRaw = csstree.generate(node);+ return;+ }++ if (node.type === "Url") {+ layers.push(csstree.generate(node));}},leave: (node, item, list) => {@@ -113,16 +120,31 @@ export const backgroundToLonghand = (export const parseBackgroundImage = (layers: string[]): LayersValue | InvalidValue => {- const backgroundImages: UnparsedValue[] = [];+ const backgroundImages: (UnparsedValue | ImageValue)[] = [];for (const layer of layers) {if (gradientNames.some((gradientName) => layer.startsWith(gradientName)) ===- false+ false &&+ layer.startsWith("url(") === false) {break;}+ if (layer.startsWith("url(")) {+ backgroundImages.push({+ type: "image",+ value: {+ type: "url",+ url: layer+ .replace(/^url\(/, "")+ .replace(/\)$/, "")+ .replaceAll(/\\(.)/g, "$1"),+ },+ });+ continue;+ }+const layerStyle = parseCssValue("backgroundImage", layer);if (layerStyle.type !== "unparsed") {