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: add transparent color when paste bg clip from webflow (#3739)

Bogdan Chadkin308acbbaf72f
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 c8b19eed5c..ab48a5bccc 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
@@ -3075,12 +3075,81 @@ describe("Styles", () => {
const fragment = await toWebstudioFragment(input);
expect(toCss(fragment)).toMatchInlineSnapshot(`
-"@media all {
- Div Block {
- color: black;
- background-color: red
- }
-}"
-`);
+ "@media all {
+ Div Block {
+ color: black;
+ background-color: red
+ }
+ }"
+ `);
+ });
+
+ test("append transparent color when background-clip is used", async () => {
+ const input = WfData.parse({
+ type: "@webflow/XscpData",
+ payload: {
+ nodes: [
+ {
+ _id: "15c3fb65-b871-abe4-f9a4-3747c8a882e0",
+ type: "Heading",
+ tag: "h2",
+ classes: ["069649be-a33a-1a9a-3763-c0bd9d1f3a3d"],
+ children: ["b69a5869-f046-5a0c-151e-9b134a6852aa"],
+ data: {
+ tag: "h2",
+ devlink: { runtimeProps: {}, slot: "" },
+ displayName: "",
+ attr: { id: "" },
+ xattr: [],
+ search: { exclude: false },
+ visibility: { conditions: [] },
+ },
+ },
+ {
+ _id: "b69a5869-f046-5a0c-151e-9b134a6852aa",
+ text: true,
+ v: "Protect your systems securely with Prism",
+ },
+ ],
+ styles: [
+ {
+ _id: "069649be-a33a-1a9a-3763-c0bd9d1f3a3d",
+ fake: false,
+ type: "class",
+ name: "H2 Heading 2",
+ namespace: "",
+ comb: "",
+ styleLess:
+ "background-image: linear-gradient(350deg, hsla(256.3636363636363, 72.13%, 23.92%, 0.00), hsla(256.2162162162162, 72.55%, 80.00%, 1.00) 49%, #bba7f1); color: hsla(0, 0.00%, 100.00%, 1.00); background-clip: text;",
+ variants: {},
+ children: [],
+ createdBy: "58b4b8186ceb395341fcf640",
+ origin: null,
+ selector: null,
+ },
+ ],
+ assets: [],
+ },
+ });
+
+ const fragment = await toWebstudioFragment(input);
+
+ expect(toCss(fragment)).toMatchInlineSnapshot(`
+ "@media all {
+ h2 {
+ margin-bottom: 10px;
+ font-weight: bold;
+ margin-top: 20px;
+ font-size: 32px;
+ line-height: 36px
+ }
+ H2 Heading 2 {
+ background-image: linear-gradient(350deg,hsla(256.3636363636363,72.13%,23.92%,0.00),hsla(256.2162162162162,72.55%,80.00%,1.00) 49%,#bba7f1);
+ -webkit-background-clip: text;
+ background-clip: text;
+ color: transparent
+ }
+ }"
+ `);
});
});
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 7028f88e72..e6fc623df8 100644
--- a/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts
+++ b/apps/builder/app/shared/copy-paste/plugin-webflow/styles.ts
@@ -102,6 +102,30 @@ const replaceAtImages = (
});
};
+const processStyles = (parsedStyles: ParsedStyleDecl[]) => {
+ const styles = new Map();
+ for (const parsedStyleDecl of parsedStyles) {
+ const { breakpoint, selector, state, property } = parsedStyleDecl;
+ const key = `${breakpoint}:${selector}:${state}:${property}`;
+ styles.set(key, parsedStyleDecl);
+ }
+ for (const parsedStyleDecl of styles.values()) {
+ const { breakpoint, selector, state, property } = parsedStyleDecl;
+ const key = `${breakpoint}:${selector}:${state}:${property}`;
+ styles.set(key, parsedStyleDecl);
+ if (property === "backgroundClip") {
+ const colorKey = `${breakpoint}:${selector}:${state}:color`;
+ styles.delete(colorKey);
+ styles.set(colorKey, {
+ ...parsedStyleDecl,
+ property: "color",
+ value: { type: "keyword", value: "transparent" },
+ });
+ }
+ }
+ return Array.from(styles.values());
+};
+
type UnparsedVariants = Map<string, string | Array<ParsedStyleDecl>>;
// Variants value can be wf styleLess string which is a styles block
@@ -114,7 +138,9 @@ const toParsedVariants = (variants: UnparsedVariants) => {
if (typeof styles === "string") {
try {
const sanitizedStyles = styles.replaceAll(/@raw<\|([^@]+)\|>/g, "$1");
- const parsed = parseCss(`.styles${state} {${sanitizedStyles}}`) ?? [];
+ const parsed = processStyles(
+ parseCss(`.styles${state} {${sanitizedStyles}}`) ?? []
+ );
const allBreakpointStyles = parsedVariants.get(breakpointName) ?? [];
allBreakpointStyles.push(...parsed);
parsedVariants.set(breakpointName, allBreakpointStyles);