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.

refactor: generate modern color syntax (#5456)

Bogdan Chadkin8d14d1b5e3b4
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/gradient-utils.test.ts b/apps/builder/app/builder/features/style-panel/sections/backgrounds/gradient-utils.test.ts
index 48852396e0..0b5c44916b 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/gradient-utils.test.ts
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/gradient-utils.test.ts
@@ -71,7 +71,7 @@ describe("formatGradientValue", () => {
],
});
expect(formatGradientValue(gradient)).toBe(
- "linear-gradient(rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
+ "linear-gradient(rgb(0 0 0 / 1), rgb(255 255 255 / 1))"
);
});
@@ -84,7 +84,7 @@ describe("formatGradientValue", () => {
],
});
expect(formatGradientValue(gradient)).toBe(
- "repeating-linear-gradient(rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
+ "repeating-linear-gradient(rgb(0 0 0 / 1), rgb(255 255 255 / 1))"
);
});
@@ -96,7 +96,7 @@ describe("formatGradientValue", () => {
],
});
expect(formatGradientValue(gradient)).toBe(
- "conic-gradient(rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
+ "conic-gradient(rgb(0 0 0 / 1), rgb(255 255 255 / 1))"
);
});
@@ -109,7 +109,7 @@ describe("formatGradientValue", () => {
],
});
expect(formatGradientValue(gradient)).toBe(
- "repeating-conic-gradient(rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
+ "repeating-conic-gradient(rgb(0 0 0 / 1), rgb(255 255 255 / 1))"
);
});
@@ -124,7 +124,7 @@ describe("formatGradientValue", () => {
],
});
expect(formatGradientValue(gradient)).toBe(
- "radial-gradient(circle closest-side at center, rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
+ "radial-gradient(circle closest-side at center, rgb(0 0 0 / 1), rgb(255 255 255 / 1))"
);
});
@@ -139,7 +139,7 @@ describe("formatGradientValue", () => {
],
});
expect(formatGradientValue(gradient)).toBe(
- "repeating-radial-gradient(circle at center, rgba(0, 0, 0, 1), rgba(255, 255, 255, 1))"
+ "repeating-radial-gradient(circle at center, rgb(0 0 0 / 1), rgb(255 255 255 / 1))"
);
});
});
@@ -152,19 +152,19 @@ describe("formatGradientForType", () => {
test("formats solid color target", () => {
expect(formatGradientForType(solidStyle, "solid")).toBe(
- "linear-gradient(rgba(255, 0, 0, 1) 0%, rgba(255, 0, 0, 1) 100%)"
+ "linear-gradient(rgb(255 0 0 / 1) 0%, rgb(255 0 0 / 1) 100%)"
);
});
test("formats linear target", () => {
expect(formatGradientForType(solidStyle, "linearGradient")).toBe(
- "linear-gradient(rgba(255, 0, 0, 1), rgba(255, 0, 0, 1))"
+ "linear-gradient(rgb(255 0 0 / 1), rgb(255 0 0 / 1))"
);
});
test("formats conic target", () => {
expect(formatGradientForType(undefined, "conicGradient")).toBe(
- "conic-gradient(rgba(0, 0, 0, 1) 0%, rgba(0, 0, 0, 0) 100%)"
+ "conic-gradient(rgb(0 0 0 / 1) 0%, rgb(0 0 0 / 0) 100%)"
);
});
@@ -174,7 +174,7 @@ describe("formatGradientForType", () => {
value: "radial-gradient(circle at center, red, blue)",
};
expect(formatGradientForType(radialStyle, "radialGradient")).toBe(
- "radial-gradient(circle at center, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ "radial-gradient(circle at center, rgb(255 0 0 / 1), rgb(0 0 255 / 1))"
);
});
@@ -184,7 +184,7 @@ describe("formatGradientForType", () => {
value: "repeating-linear-gradient(red, blue)",
};
expect(formatGradientForType(value, "linearGradient")).toBe(
- "repeating-linear-gradient(rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ "repeating-linear-gradient(rgb(255 0 0 / 1), rgb(0 0 255 / 1))"
);
});
@@ -194,7 +194,7 @@ describe("formatGradientForType", () => {
value: "repeating-conic-gradient(red, blue)",
};
expect(formatGradientForType(value, "conicGradient")).toBe(
- "repeating-conic-gradient(rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ "repeating-conic-gradient(rgb(255 0 0 / 1), rgb(0 0 255 / 1))"
);
});
@@ -204,7 +204,7 @@ describe("formatGradientForType", () => {
value: "repeating-radial-gradient(circle, red, blue)",
};
expect(formatGradientForType(value, "radialGradient")).toBe(
- "repeating-radial-gradient(circle, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ "repeating-radial-gradient(circle, rgb(255 0 0 / 1), rgb(0 0 255 / 1))"
);
});
@@ -214,7 +214,7 @@ describe("formatGradientForType", () => {
value: "conic-gradient(red, blue)",
};
expect(formatGradientForType(conicStyle, "radialGradient")).toBe(
- "radial-gradient(rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ "radial-gradient(rgb(255 0 0 / 1), rgb(0 0 255 / 1))"
);
});
});
@@ -225,7 +225,7 @@ describe("convertGradientToTarget", () => {
conic: "conic-gradient(red 0%, blue 100%)",
radial: "radial-gradient(circle, red 0%, blue 100%)",
};
- const expectedColors = ["rgba(255, 0, 0, 1)", "rgba(0, 0, 255, 1)"];
+ const expectedColors = ["rgb(255 0 0 / 1)", "rgb(0 0 255 / 1)"];
const gradientTypes: GradientType[] = ["linear", "conic", "radial"];
const getStopColors = (stops: GradientStop[]) =>
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 c481af2a9d..271a945741 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
@@ -188,7 +188,7 @@ test("Link Block, Button, Text Link", async () => {
expect(toCss(fragment)).toMatchInlineSnapshot(`
"@media all {
a {
- background-color: rgba(0, 0, 0, 0)
+ background-color: rgb(0 0 0 / 0)
}
a:active {
outline: 0 none currentcolor
@@ -369,7 +369,7 @@ test("Blockquote", async () => {
padding-left: 20px;
font-size: 18px;
line-height: 22px;
- border-left: 5px solid rgba(226, 226, 226, 1)
+ border-left: 5px solid rgb(226 226 226 / 1)
}
}"
`);
@@ -1510,7 +1510,7 @@ test("RichText", async () => {
padding-left: 20px;
font-size: 18px;
line-height: 22px;
- border-left: 5px solid rgba(226, 226, 226, 1)
+ border-left: 5px solid rgb(226 226 226 / 1)
}
ol {
margin-top: 0;
@@ -1523,7 +1523,7 @@ test("RichText", async () => {
padding-left: 40px
}
a {
- background-color: rgba(0, 0, 0, 0)
+ background-color: rgb(0 0 0 / 0)
}
a:active {
outline: 0 none currentcolor
@@ -1684,9 +1684,9 @@ test("Form", async () => {
padding: 0
}
w-input {
- color: rgba(51, 51, 51, 1);
+ color: rgb(51 51 51 / 1);
vertical-align: middle;
- background-color: rgba(238, 238, 238, 1);
+ background-color: rgb(238 238 238 / 1);
width: 100%;
height: auto;
margin-bottom: 10px;
@@ -1698,23 +1698,23 @@ test("Form", async () => {
line-height: 1.42857;
display: block;
cursor: not-allowed;
- border: 1px solid rgba(204, 204, 204, 1)
+ border: 1px solid rgb(204 204 204 / 1)
}
w-input:-moz-placeholder {
- color: rgba(153, 153, 153, 1)
+ color: rgb(153 153 153 / 1)
}
w-input::-moz-placeholder {
- color: rgba(153, 153, 153, 1);
+ color: rgb(153 153 153 / 1);
opacity: 1
}
w-input::-webkit-input-placeholder {
- color: rgba(153, 153, 153, 1)
+ color: rgb(153 153 153 / 1)
}
w-input:focus {
- border-top-color: rgba(56, 152, 236, 1);
- border-right-color: rgba(56, 152, 236, 1);
- border-bottom-color: rgba(56, 152, 236, 1);
- border-left-color: rgba(56, 152, 236, 1);
+ border-top-color: rgb(56 152 236 / 1);
+ border-right-color: rgb(56 152 236 / 1);
+ border-bottom-color: rgb(56 152 236 / 1);
+ border-left-color: rgb(56 152 236 / 1);
outline: 0 none currentcolor
}
}"
@@ -1768,10 +1768,10 @@ test("FormButton", async () => {
padding: 0
}
w-button {
- color: rgba(255, 255, 255, 1);
+ color: rgb(255 255 255 / 1);
line-height: inherit;
cursor: pointer;
- background-color: rgba(56, 152, 236, 1);
+ background-color: rgb(56 152 236 / 1);
border-top-left-radius: 0;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
@@ -1856,9 +1856,9 @@ test("FormTextInput", async () => {
padding: 0
}
w-input {
- color: rgba(51, 51, 51, 1);
+ color: rgb(51 51 51 / 1);
vertical-align: middle;
- background-color: rgba(238, 238, 238, 1);
+ background-color: rgb(238 238 238 / 1);
width: 100%;
height: auto;
margin-bottom: 10px;
@@ -1870,23 +1870,23 @@ test("FormTextInput", async () => {
line-height: 1.42857;
display: block;
cursor: not-allowed;
- border: 1px solid rgba(204, 204, 204, 1)
+ border: 1px solid rgb(204 204 204 / 1)
}
w-input:-moz-placeholder {
- color: rgba(153, 153, 153, 1)
+ color: rgb(153 153 153 / 1)
}
w-input::-moz-placeholder {
- color: rgba(153, 153, 153, 1);
+ color: rgb(153 153 153 / 1);
opacity: 1
}
w-input::-webkit-input-placeholder {
- color: rgba(153, 153, 153, 1)
+ color: rgb(153 153 153 / 1)
}
w-input:focus {
- border-top-color: rgba(56, 152, 236, 1);
- border-right-color: rgba(56, 152, 236, 1);
- border-bottom-color: rgba(56, 152, 236, 1);
- border-left-color: rgba(56, 152, 236, 1);
+ border-top-color: rgb(56 152 236 / 1);
+ border-right-color: rgb(56 152 236 / 1);
+ border-bottom-color: rgb(56 152 236 / 1);
+ border-left-color: rgb(56 152 236 / 1);
outline: 0 none currentcolor
}
}"
@@ -1990,9 +1990,9 @@ test("FormTextarea", async () => {
margin: 0
}
w-input {
- color: rgba(51, 51, 51, 1);
+ color: rgb(51 51 51 / 1);
vertical-align: middle;
- background-color: rgba(238, 238, 238, 1);
+ background-color: rgb(238 238 238 / 1);
width: 100%;
height: auto;
margin-bottom: 10px;
@@ -2004,23 +2004,23 @@ test("FormTextarea", async () => {
line-height: 1.42857;
display: block;
cursor: not-allowed;
- border: 1px solid rgba(204, 204, 204, 1)
+ border: 1px solid rgb(204 204 204 / 1)
}
w-input:-moz-placeholder {
- color: rgba(153, 153, 153, 1)
+ color: rgb(153 153 153 / 1)
}
w-input::-moz-placeholder {
- color: rgba(153, 153, 153, 1);
+ color: rgb(153 153 153 / 1);
opacity: 1
}
w-input::-webkit-input-placeholder {
- color: rgba(153, 153, 153, 1)
+ color: rgb(153 153 153 / 1)
}
w-input:focus {
- border-top-color: rgba(56, 152, 236, 1);
- border-right-color: rgba(56, 152, 236, 1);
- border-bottom-color: rgba(56, 152, 236, 1);
- border-left-color: rgba(56, 152, 236, 1);
+ border-top-color: rgb(56 152 236 / 1);
+ border-right-color: rgb(56 152 236 / 1);
+ border-bottom-color: rgb(56 152 236 / 1);
+ border-left-color: rgb(56 152 236 / 1);
outline: 0 none currentcolor
}
}"
@@ -2567,7 +2567,7 @@ describe("Styles", () => {
line-height: 44px
}
Heading {
- color: rgba(219, 24, 24, 1)
+ color: rgb(219 24 24 / 1)
}
}"
`);
@@ -2695,7 +2695,7 @@ describe("Styles", () => {
expect(toCss(fragment)).toMatchInlineSnapshot(`
"@media all {
a {
- background-color: rgba(0, 0, 0, 0)
+ background-color: rgb(0 0 0 / 0)
}
a:active {
outline: 0 none currentcolor
@@ -2787,7 +2787,7 @@ describe("Styles", () => {
expect(toCss(fragment)).toMatchInlineSnapshot(`
"@media all {
d1 {
- color: rgba(209, 36, 36, 1)
+ color: rgb(209 36 36 / 1)
}
d2 {
font-size: 200px
@@ -2906,7 +2906,7 @@ describe("Styles", () => {
expect(toCss(fragment)).toMatchInlineSnapshot(`
"@media all {
a {
- background-color: rgba(0, 0, 0, 0)
+ background-color: rgb(0 0 0 / 0)
}
a:active {
outline: 0 none currentcolor
@@ -2918,24 +2918,24 @@ describe("Styles", () => {
transform: translate3d(7px, 74px, 16px)
}
x:hover {
- background-color: rgba(199, 16, 16, 1)
+ background-color: rgb(199 16 16 / 1)
}
}
@media all and (max-width: 479px) {
x:active {
- background-color: rgba(189, 75, 75, 1)
+ background-color: rgb(189 75 75 / 1)
}
x:focus {
- background-color: rgba(83, 26, 170, 1)
+ background-color: rgb(83 26 170 / 1)
}
x:focus-visible {
- background-color: rgba(98, 67, 145, 1)
+ background-color: rgb(98 67 145 / 1)
}
x:hover {
- background-color: rgba(214, 87, 87, 1)
+ background-color: rgb(214 87 87 / 1)
}
x:visited {
- background-color: rgba(197, 18, 18, 1)
+ background-color: rgb(197 18 18 / 1)
}
}"
`);
@@ -3001,27 +3001,27 @@ describe("Styles", () => {
expect(toCss(fragment)).toMatchInlineSnapshot(`
"@media all {
Div Block 2 {
- background-color: rgba(0, 208, 255, 1)
+ background-color: rgb(0 208 255 / 1)
}
}
@media all and (max-width: 991px) {
Div Block 2 {
- background-color: rgba(68, 0, 255, 1)
+ background-color: rgb(68 0 255 / 1)
}
}
@media all and (max-width: 767px) {
Div Block 2 {
- background-color: rgba(255, 0, 221, 1)
+ background-color: rgb(255 0 221 / 1)
}
}
@media all and (max-width: 479px) {
Div Block 2 {
- background-color: rgba(255, 0, 4, 1)
+ background-color: rgb(255 0 4 / 1)
}
}
@media all and (min-width: 1280px) {
Div Block 2 {
- background-color: rgba(0, 255, 128, 1)
+ background-color: rgb(0 255 128 / 1)
}
}"
`);
@@ -3264,7 +3264,7 @@ describe("Styles", () => {
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;",
+ "background-image: linear-gradient(350deg, hsl(256.3636363636363 72.13% 23.92% / 0.00), hsl(256.2162162162162 72.55% 80.00% / 1.00) 49%, #bba7f1); color: hsl(0 0.00% 100.00% / 1.00); background-clip: text;",
variants: {},
children: [],
createdBy: "58b4b8186ceb395341fcf640",
@@ -3288,7 +3288,7 @@ describe("Styles", () => {
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);
+ background-image: linear-gradient(350deg,hsl(256.3636363636363 72.13% 23.92%/0.00),hsl(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/instance-utils.ts b/apps/builder/app/shared/instance-utils.ts
index a251e81521..36d214788c 100644
--- a/apps/builder/app/shared/instance-utils.ts
+++ b/apps/builder/app/shared/instance-utils.ts
@@ -619,6 +619,7 @@ const traverseStyleValue = (
value.type === "unparsed" ||
value.type === "invalid" ||
value.type === "unset" ||
+ value.type === "color" ||
value.type === "rgb" ||
value.type === "function" ||
value.type === "guaranteedInvalid"
diff --git a/fixtures/webstudio-features/app/__generated__/[content-block]._index.tsx b/fixtures/webstudio-features/app/__generated__/[content-block]._index.tsx
index 70cebf7270..94e5a886c7 100644
--- a/fixtures/webstudio-features/app/__generated__/[content-block]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[content-block]._index.tsx
@@ -32,24 +32,24 @@ export const pageBackgroundImageAssets: string[] = [];
const Page = (_props: { system: any }) => {
return (
<Body className={`w-body`}>
- <Box className={`w-box coklr1z`}>
+ <Box className={`w-box c620822`}>
<Heading className={`w-heading cc5h0no`}>
{"Content Block With Templates And Content"}
</Heading>
<Heading className={`w-heading`}>{"H1"}</Heading>
<Paragraph className={`w-paragraph`}>{"Paragraph"}</Paragraph>
</Box>
- <Box className={`w-box c1cqkpk9`}>
+ <Box className={`w-box ch21dzk`}>
<Heading className={`w-heading cc5h0no`}>
{"Content Block With Templates Only"}
</Heading>
</Box>
- <Box className={`w-box ccxj65f`}>
+ <Box className={`w-box c44hi06`}>
<Heading className={`w-heading cc5h0no`}>{"With Content Only"}</Heading>
<Heading className={`w-heading`}>{"H1"}</Heading>
<Paragraph className={`w-paragraph`}>{"Paragraph"}</Paragraph>
</Box>
- <Box className={`w-box c1a2hnxl`}>
+ <Box className={`w-box cno1tjk`}>
<Heading className={`w-heading cc5h0no`}>{"Empty"}</Heading>
</Box>
</Body>
diff --git a/fixtures/webstudio-features/app/__generated__/[radix]._index.tsx b/fixtures/webstudio-features/app/__generated__/[radix]._index.tsx
index 8cfb39cab4..0ed12fe1ec 100644
--- a/fixtures/webstudio-features/app/__generated__/[radix]._index.tsx
+++ b/fixtures/webstudio-features/app/__generated__/[radix]._index.tsx
@@ -49,7 +49,7 @@ const Page = (_props: { system: any }) => {
}}
className={`w-accordion`}
>
- <AccordionItem data-ws-index="0" className={`w-item c2onvcp`}>
+ <AccordionItem data-ws-index="0" className={`w-item c6gjj8k`}>
<AccordionHeader className={`w-item-header c13v7j50`}>
<AccordionTrigger
className={`w-item-trigger c13v7j50 c1qxdkbn chhejm9 c13bviim cpjvam0 c1tw5o2 cqw88jp c44srea c14kxsax cg783j6 c1ad236a c1s4llbc`}
@@ -73,7 +73,7 @@ const Page = (_props: { system: any }) => {
{"Yes. It adheres to the WAI-ARIA design pattern."}
</AccordionContent>
</AccordionItem>
- <AccordionItem data-ws-index="1" className={`w-item c2onvcp`}>
+ <AccordionItem data-ws-index="1" className={`w-item c6gjj8k`}>
<AccordionHeader className={`w-item-header c13v7j50`}>
<AccordionTrigger
className={`w-item-trigger c13v7j50 c1qxdkbn chhejm9 c13bviim cpjvam0 c1tw5o2 cqw88jp c44srea c14kxsax cg783j6 c1ad236a c1s4llbc`}
@@ -99,7 +99,7 @@ const Page = (_props: { system: any }) => {
}
</AccordionContent>
</AccordionItem>
- <AccordionItem data-ws-index="2" className={`w-item c2onvcp`}>
+ <AccordionItem data-ws-index="2" className={`w-item c6gjj8k`}>
<AccordionHeader className={`w-item-header c13v7j50`}>
<AccordionTrigger
className={`w-item-trigger c13v7j50 c1qxdkbn chhejm9 c13bviim cpjvam0 c1tw5o2 cqw88jp c44srea c14kxsax cg783j6 c1ad236a c1s4llbc`}
diff --git a/fixtures/webstudio-features/app/__generated__/index.css b/fixtures/webstudio-features/app/__generated__/index.css
index 95aff7b1ff..fe52cf1ef5 100644
--- a/fixtures/webstudio-features/app/__generated__/index.css
+++ b/fixtures/webstudio-features/app/__generated__/index.css
@@ -62,7 +62,7 @@
text-transform: none;
background-color: transparent;
background-image: none;
- border: 0px solid rgba(226, 232, 240, 1);
+ border: 0px solid rgb(226 232 240 / 1);
margin: 0;
padding: 0px;
}
@@ -140,8 +140,8 @@
.cielobv {
padding: 16px;
}
- .c2onvcp {
- border-bottom: 1px solid rgba(226, 232, 240, 1);
+ .c6gjj8k {
+ border-bottom: 1px solid rgb(226 232 240 / 1);
}
.chhejm9 {
flex-shrink: 1;
@@ -224,17 +224,17 @@
.cc5h0no {
font-size: 1em;
}
- .coklr1z {
- background-color: rgba(251, 247, 3, 1);
+ .c620822 {
+ background-color: rgb(251 247 3 / 1);
}
- .c1cqkpk9 {
- background-color: rgba(89, 250, 2, 1);
+ .ch21dzk {
+ background-color: rgb(89 250 2 / 1);
}
- .ccxj65f {
- background-color: rgba(2, 250, 168, 1);
+ .c44hi06 {
+ background-color: rgb(2 250 168 / 1);
}
- .c1a2hnxl {
- background-color: rgba(2, 139, 250, 1);
+ .cno1tjk {
+ background-color: rgb(2 139 250 / 1);
}
.c1m04i8w {
height: 100dvh;
diff --git a/packages/css-data/src/property-parsers/conic-gradient.test.ts b/packages/css-data/src/property-parsers/conic-gradient.test.ts
index 783981df49..127e8289ab 100644
--- a/packages/css-data/src/property-parsers/conic-gradient.test.ts
+++ b/packages/css-data/src/property-parsers/conic-gradient.test.ts
@@ -141,7 +141,7 @@ describe("parse conic-gradient", () => {
})
);
expect(formatConicGradient(parsed!)).toBe(
- "repeating-conic-gradient(rgba(255, 0, 0, 1) 0% 25%, rgba(0, 0, 255, 1) 50% 75%)"
+ "repeating-conic-gradient(rgb(255 0 0 / 1) 0% 25%, rgb(0 0 255 / 1) 50% 75%)"
);
});
@@ -243,7 +243,7 @@ describe("parse conic-gradient", () => {
})
);
expect(formatConicGradient(parsed!)).toBe(
- "conic-gradient(rgba(255, 0, 0, 1) var(--start, 10%) var(--hint, 20%), rgba(0, 0, 255, 1) var(--end))"
+ "conic-gradient(rgb(255 0 0 / 1) var(--start, 10%) var(--hint, 20%), rgb(0 0 255 / 1) var(--end))"
);
});
@@ -275,7 +275,7 @@ describe("parse conic-gradient", () => {
})
);
expect(formatConicGradient(parsed!)).toBe(
- "conic-gradient(rgba(0, 128, 0, 1) 0%, rgba(0, 0, 255, 1) 50%, rgba(255, 255, 0, 1) 100%)"
+ "conic-gradient(rgb(0 128 0 / 1) 0%, rgb(0 0 255 / 1) 50%, rgb(255 255 0 / 1) 100%)"
);
});
@@ -307,7 +307,7 @@ describe("parse conic-gradient", () => {
})
);
expect(formatConicGradient(parsed!)).toBe(
- "conic-gradient(rgba(255, 0, 0, 1), rgba(0, 255, 0, 1), rgba(0, 0, 255, 1))"
+ "conic-gradient(rgb(255 0 0 / 1), rgb(0 255 0 / 1), rgb(0 0 255 / 1))"
);
});
diff --git a/packages/css-data/src/property-parsers/linear-gradient.test.ts b/packages/css-data/src/property-parsers/linear-gradient.test.ts
index 0536c30d6c..a7e6551f85 100644
--- a/packages/css-data/src/property-parsers/linear-gradient.test.ts
+++ b/packages/css-data/src/property-parsers/linear-gradient.test.ts
@@ -142,7 +142,7 @@ describe("parses linear-gradient", () => {
}
expect(formatLinearGradient(parsed)).toEqual(
- "linear-gradient(rgba(255, 0, 0, 1), rgba(0, 255, 0, 1), rgba(0, 0, 255, 1))"
+ "linear-gradient(rgb(255 0 0 / 1), rgb(0 255 0 / 1), rgb(0 0 255 / 1))"
);
});
@@ -154,7 +154,7 @@ describe("parses linear-gradient", () => {
expect(parsed.repeating).toBe(true);
expect(formatLinearGradient(parsed)).toEqual(
- "repeating-linear-gradient(rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ "repeating-linear-gradient(rgb(255 0 0 / 1), rgb(0 0 255 / 1))"
);
});
@@ -237,7 +237,7 @@ describe("parses linear-gradient", () => {
);
if (parsed) {
expect(formatLinearGradient(parsed)).toEqual(
- "linear-gradient(to bottom, rgba(0, 128, 0, 1) 0%, var(--accent))"
+ "linear-gradient(to bottom, rgb(0 128 0 / 1) 0%, var(--accent))"
);
}
});
@@ -270,7 +270,7 @@ describe("parses linear-gradient", () => {
);
if (parsed) {
expect(formatLinearGradient(parsed)).toEqual(
- "linear-gradient(rgba(255, 0, 0, 1) var(--start, 10%), rgba(0, 0, 255, 1) var(--end))"
+ "linear-gradient(rgb(255 0 0 / 1) var(--start, 10%), rgb(0 0 255 / 1) var(--end))"
);
}
});
@@ -361,7 +361,7 @@ describe("parses linear-gradient", () => {
value: "angle",
});
expect(formatLinearGradient(parsed)).toEqual(
- "linear-gradient(var(--angle, 45deg), rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ "linear-gradient(var(--angle, 45deg), rgb(255 0 0 / 1), rgb(0 0 255 / 1))"
);
});
diff --git a/packages/css-data/src/property-parsers/radial-gradient.test.ts b/packages/css-data/src/property-parsers/radial-gradient.test.ts
index e9aa82804e..07198dd488 100644
--- a/packages/css-data/src/property-parsers/radial-gradient.test.ts
+++ b/packages/css-data/src/property-parsers/radial-gradient.test.ts
@@ -267,7 +267,7 @@ describe("parse radial-gradient", () => {
expect(parsed.repeating).toBe(true);
expect(formatRadialGradient(parsed)).toEqual(
- "repeating-radial-gradient(rgba(255, 0, 0, 1) 0%, rgba(0, 0, 255, 1) 100%)"
+ "repeating-radial-gradient(rgb(255 0 0 / 1) 0%, rgb(0 0 255 / 1) 100%)"
);
});
@@ -280,7 +280,7 @@ describe("parse radial-gradient", () => {
}
expect(formatRadialGradient(parsed)).toEqual(
- "radial-gradient(circle 40px at top, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"
+ "radial-gradient(circle 40px at top, rgb(255 0 0 / 1), rgb(0 0 255 / 1))"
);
});
});
diff --git a/packages/css-engine/src/core/to-value.test.ts b/packages/css-engine/src/core/to-value.test.ts
index 3e61ee011e..adf3fcd705 100644
--- a/packages/css-engine/src/core/to-value.test.ts
+++ b/packages/css-engine/src/core/to-value.test.ts
@@ -233,6 +233,148 @@ describe("Convert WS CSS Values to native CSS strings", () => {
});
expect(value).toBe("");
});
+
+ test("color with srgb color space", () => {
+ const value = toValue({
+ type: "color",
+ colorSpace: "srgb",
+ components: [1, 0.5, 0.2],
+ alpha: 1,
+ });
+ expect(value).toBe("rgb(255 127.5 51 / 1)");
+ });
+
+ test("color with srgb and alpha channel", () => {
+ const value = toValue({
+ type: "color",
+ colorSpace: "srgb",
+ components: [1, 0, 0],
+ alpha: 0.5,
+ });
+ expect(value).toBe("rgb(255 0 0 / 0.5)");
+ });
+
+ test("color with srgb and zero alpha", () => {
+ const value = toValue({
+ type: "color",
+ colorSpace: "srgb",
+ components: [0.5, 0.5, 0.5],
+ alpha: 0,
+ });
+ expect(value).toBe("rgb(127.5 127.5 127.5 / 0)");
+ });
+
+ test("color with hsl color space", () => {
+ const value = toValue({
+ type: "color",
+ colorSpace: "hsl",
+ components: [120, 100, 50],
+ alpha: 1,
+ });
+ expect(value).toBe("hsl(120 100% 50% / 1)");
+ });
+
+ test("color with hwb color space", () => {
+ const value = toValue({
+ type: "color",
+ colorSpace: "hwb",
+ components: [45, 10, 20],
+ alpha: 1,
+ });
+ expect(value).toBe("hwb(45 10% 20% / 1)");
+ });
+
+ test("color with lab color space", () => {
+ const value = toValue({
+ type: "color",
+ colorSpace: "lab",
+ components: [50, 20, 30],
+ alpha: 1,
+ });
+ expect(value).toBe("lab(50% 20 30 / 1)");
+ });
+
+ test("color with lch color space", () => {
+ const value = toValue({
+ type: "color",
+ colorSpace: "lch",
+ components: [50, 20, 120],
+ alpha: 1,
+ });
+ expect(value).toBe("lch(50% 20 120 / 1)");
+ });
+
+ test("color with oklab color space", () => {
+ const value = toValue({
+ type: "color",
+ colorSpace: "oklab",
+ components: [0.6, 0.1, -0.1],
+ alpha: 1,
+ });
+ expect(value).toBe("oklab(0.6 0.1 -0.1 / 1)");
+ });
+
+ test("color with oklch color space", () => {
+ const value = toValue({
+ type: "color",
+ colorSpace: "oklch",
+ components: [0.5, 0.1, 180],
+ alpha: 1,
+ });
+ expect(value).toBe("oklch(0.5 0.1 180 / 1)");
+ });
+
+ test("color with p3 color space uses color() function", () => {
+ const value = toValue({
+ type: "color",
+ colorSpace: "p3",
+ components: [0.8, 0.4, 0.6],
+ alpha: 0.8,
+ });
+ expect(value).toBe("color(p3 0.8 0.4 0.6 / 0.8)");
+ });
+
+ test("color with xyz-d65 uses color() function", () => {
+ const value = toValue({
+ type: "color",
+ colorSpace: "xyz-d65",
+ components: [0.5, 0.3, 0.2],
+ alpha: 1,
+ });
+ expect(value).toBe("color(xyz-d65 0.5 0.3 0.2 / 1)");
+ });
+
+ test("color in tuple", () => {
+ const value = toValue({
+ type: "tuple",
+ value: [
+ {
+ type: "color",
+ colorSpace: "oklch",
+ components: [0.5, 0.1, 180],
+ alpha: 1,
+ },
+ { type: "unit", value: 10, unit: "px" },
+ ],
+ });
+ expect(value).toBe("oklch(0.5 0.1 180 / 1) 10px");
+ });
+
+ test("color in shadow", () => {
+ const value = toValue({
+ type: "shadow",
+ position: "outset",
+ offsetX: { type: "unit", value: 1, unit: "px" },
+ offsetY: { type: "unit", value: 2, unit: "px" },
+ color: {
+ type: "color",
+ colorSpace: "hsl",
+ components: [240, 100, 50],
+ alpha: 0.7,
+ },
+ });
+ expect(value).toBe("1px 2px hsl(240 100% 50% / 0.7)");
+ });
});
describe("serialize shadow value", () => {
@@ -268,7 +410,7 @@ describe("serialize shadow value", () => {
},
],
})
- ).toEqual("1px 2px 3px 4px rgba(0, 0, 0, 1) inset");
+ ).toEqual("1px 2px 3px 4px rgb(0 0 0 / 1) inset");
});
test("hidden value", () => {
diff --git a/packages/css-engine/src/core/to-value.ts b/packages/css-engine/src/core/to-value.ts
index efaf8f5dc9..140c50f4ec 100644
--- a/packages/css-engine/src/core/to-value.ts
+++ b/packages/css-engine/src/core/to-value.ts
@@ -84,7 +84,40 @@ export const toValue = (
}
if (value.type === "rgb") {
- return `rgba(${value.r}, ${value.g}, ${value.b}, ${value.alpha})`;
+ return `rgb(${value.r} ${value.g} ${value.b} / ${value.alpha})`;
+ }
+
+ if (value.type === "color") {
+ const [c1, c2, c3] = value.components;
+ const alpha = value.alpha;
+
+ // Use specific CSS functions when available
+ switch (value.colorSpace) {
+ case "srgb":
+ return `rgb(${c1 * 255} ${c2 * 255} ${c3 * 255} / ${alpha})`;
+ case "hsl":
+ return `hsl(${c1} ${c2}% ${c3}% / ${alpha})`;
+ case "hwb":
+ return `hwb(${c1} ${c2}% ${c3}% / ${alpha})`;
+ case "lab":
+ return `lab(${c1}% ${c2} ${c3} / ${alpha})`;
+ case "lch":
+ return `lch(${c1}% ${c2} ${c3} / ${alpha})`;
+ case "oklab":
+ return `oklab(${c1} ${c2} ${c3} / ${alpha})`;
+ case "oklch":
+ return `oklch(${c1} ${c2} ${c3} / ${alpha})`;
+ // Fall back to color() function for less common color spaces
+ case "p3":
+ case "srgb-linear":
+ case "a98rgb":
+ case "prophoto":
+ case "rec2020":
+ case "xyz-d65":
+ case "xyz-d50":
+ default:
+ return `color(${value.colorSpace} ${c1} ${c2} ${c3} / ${alpha})`;
+ }
}
if (value.type === "image") {
diff --git a/packages/css-engine/src/schema.ts b/packages/css-engine/src/schema.ts
index 9aa2bc5e12..1edab23349 100644
--- a/packages/css-engine/src/schema.ts
+++ b/packages/css-engine/src/schema.ts
@@ -64,6 +64,30 @@ const RgbValue = z.object({
});
export type RgbValue = z.infer<typeof RgbValue>;
+export const ColorValue = z.object({
+ type: z.literal("color"),
+ colorSpace: z.union([
+ z.literal("srgb"),
+ z.literal("p3"),
+ z.literal("srgb-linear"),
+ z.literal("hsl"),
+ z.literal("hwb"),
+ z.literal("lab"),
+ z.literal("lch"),
+ z.literal("oklab"),
+ z.literal("oklch"),
+ z.literal("a98rgb"),
+ z.literal("prophoto"),
+ z.literal("rec2020"),
+ z.literal("xyz-d65"),
+ z.literal("xyz-d50"),
+ ]),
+ components: z.tuple([z.number(), z.number(), z.number()]),
+ alpha: z.number(),
+ hidden: z.boolean().optional(),
+});
+export type ColorValue = z.infer<typeof ColorValue>;
+
export type FunctionValue = z.infer<typeof FunctionValue>;
export const FunctionValue: z.ZodType<{
@@ -124,6 +148,7 @@ export const VarFallback = z.union([
UnparsedValue,
KeywordValue,
UnitValue,
+ ColorValue,
RgbValue,
]);
export type VarFallback = z.infer<typeof VarFallback>;
@@ -136,6 +161,7 @@ export const toVarFallback = (
styleValue.type === "unparsed" ||
styleValue.type === "keyword" ||
styleValue.type === "unit" ||
+ styleValue.type === "color" ||
styleValue.type === "rgb"
) {
return styleValue;
@@ -157,6 +183,7 @@ export const TupleValueItem = z.union([
KeywordValue,
UnparsedValue,
ImageValue,
+ ColorValue,
RgbValue,
FunctionValue,
VarValue,
@@ -179,7 +206,7 @@ export const ShadowValue = z.object({
offsetY: z.union([UnitValue, VarValue]),
blur: z.union([UnitValue, VarValue]).optional(),
spread: z.union([UnitValue, VarValue]).optional(),
- color: z.union([RgbValue, KeywordValue, VarValue]).optional(),
+ color: z.union([ColorValue, RgbValue, KeywordValue, VarValue]).optional(),
});
export type ShadowValue = z.infer<typeof ShadowValue>;
@@ -191,6 +218,7 @@ const LayerValueItem = z.union([
ImageValue,
TupleValue,
ShadowValue,
+ ColorValue,
RgbValue,
InvalidValue,
FunctionValue,
@@ -215,6 +243,7 @@ export const StyleValue = z.union([
UnitValue,
KeywordValue,
FontFamilyValue,
+ ColorValue,
RgbValue,
UnparsedValue,
TupleValue,