Skip to content

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.

experimental: support webflow custom properties (#3706)

Bogdan Chadkin4abb5ce83e4f
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.tsx
index 632cdecccc..427067cc7f 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
@@ -3016,4 +3016,50 @@ describe("Styles", () => {
}"
`);
});
+
+ test("@raw webflow custom properties", async () => {
+ const input = WfData.parse({
+ type: "@webflow/XscpData",
+ payload: {
+ nodes: [
+ {
+ _id: "89ed49d8-2d32-5bab-22e1-264acb8d2d84",
+ type: "Block",
+ tag: "div",
+ classes: ["393ac121-a395-7678-e598-994e30fb7880"],
+ children: [],
+ data: { text: false, tag: "div" },
+ },
+ ],
+ styles: [
+ {
+ _id: "393ac121-a395-7678-e598-994e30fb7880",
+ fake: false,
+ type: "class",
+ name: "Div Block",
+ namespace: "",
+ comb: "",
+ styleLess: "color: @raw<|black|>; background-color: @raw<|red|>;",
+ variants: {},
+ children: [],
+ createdBy: "635e72dd77408d16b581b4bc",
+ origin: null,
+ selector: null,
+ },
+ ],
+ assets: [],
+ },
+ });
+
+ const fragment = await toWebstudioFragment(input);
+
+ expect(toCss(fragment)).toMatchInlineSnapshot(`
+"@media all {
+ Div Block {
+ color: black;
+ background-color: red
+ }
+}"
+`);
+ });
});
diff --git a/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts b/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts
index af22a3ffb5..b898e07823 100644
--- a/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts
+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts
@@ -113,7 +113,8 @@ const toParsedVariants = (variants: UnparsedVariants) => {
const { breakpointName, state } = parseVariantName(variant);
if (typeof styles === "string") {
try {
- const parsed = parseCss(`.styles${state} {${styles}}`) ?? [];
+ const sanitizedStyles = styles.replaceAll(/@raw<\|([^@]+)\|>/g, "$1");
+ const parsed = parseCss(`.styles${state} {${sanitizedStyles}}`) ?? [];
const allBreakpointStyles = parsedVariants.get(breakpointName) ?? [];
allBreakpointStyles.push(...parsed);
parsedVariants.set(breakpointName, allBreakpointStyles);