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
refactor: reimplement atomic styles with nesting rules (#3248)
Bogdan Chadkin147a495393fc
diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx b/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsxindex 80ce4245ac..155935e267 100644--- a/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/_index.tsx@@ -24,7 +24,7 @@ const Page = ({}: { system: any }) => {<Bodydata-ws-id="MMimeobf_zi4ZkRGXapju"data-ws-component="Body"- className="c9ryj1f c1e3go07 cmhckny cr0vgwe"+ className="c1jaw2zx c1bn74oy c1vwwfi7 c1xn7xpo"><Heading data-ws-id="MYDt0guk1-vzc7yzqyN6A" data-ws-component="Heading">{"Simple Project to test CLI"}diff --git a/fixtures/webstudio-cloudflare-template/app/__generated__/index.css b/fixtures/webstudio-cloudflare-template/app/__generated__/index.cssindex 6ea394ea0b..a9ada72e47 100644--- a/fixtures/webstudio-cloudflare-template/app/__generated__/index.css+++ b/fixtures/webstudio-cloudflare-template/app/__generated__/index.css@@ -79,16 +79,16 @@ html {}}@media all {- .c9ryj1f {+ .c1jaw2zx {display: flex;}- .c1e3go07 {+ .c1bn74oy {align-items: center;}- .cmhckny {+ .c1vwwfi7 {justify-content: center;}- .cr0vgwe {+ .c1xn7xpo {flex-direction: column;}}diff --git a/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.tsx b/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.tsxindex 6fdbe557b7..9527f34891 100644--- a/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.tsx+++ b/fixtures/webstudio-custom-template/app/__generated__/[script-test]._index.tsx@@ -37,7 +37,7 @@ const Page = ({}: { system: any }) => {<Bodydata-ws-id="LW98_-srDnnagkR10lsk4"data-ws-component="Body"- className="c1vynykc c122cnm9 c15qd3jj c1jp5sfs"+ className="crro89i ca0mhw9 c1ldy0s3 c1t3ec4y"><Heading data-ws-id="SHXddDLFWST_sy44UfGQO" data-ws-component="Heading">{"Script Test"}diff --git a/fixtures/webstudio-custom-template/app/__generated__/[sitemap-html]._index.tsx b/fixtures/webstudio-custom-template/app/__generated__/[sitemap-html]._index.tsxindex a03774d184..b1d1e46995 100644--- a/fixtures/webstudio-custom-template/app/__generated__/[sitemap-html]._index.tsx+++ b/fixtures/webstudio-custom-template/app/__generated__/[sitemap-html]._index.tsx@@ -37,33 +37,33 @@ const Page = ({}: { system: any }) => {<Textdata-ws-id="FD1zWHCq5TVsTSBKWbtV3"data-ws-component="Text"- className="c1cymde0"+ className="cwnydv4">{"<url>"}</Text><Boxdata-ws-id="eSgI63Vtow0HYHYWUXn3U"data-ws-component="Box"- className="c1mhrh2o c1b095zn"+ className="cnvcd8b cxb89wn"><Textdata-ws-id="YT4punX-Bdhl0Dw8l6kum"data-ws-component="Text"- className="c15pkvqb"+ className="c1s70es7">{"<loc>"}</Text><Textdata-ws-id="85KbQ_KRH5fQsA0pDR9G9"data-ws-component="Text"- className="cjqm8t8"+ className="c5fu8k4">{origin + url?.path}</Text><Textdata-ws-id="qdI0BY3e4j8USqw370Qrs"data-ws-component="Text"- className="c15pkvqb"+ className="c1s70es7">{"</loc>"}</Text>@@ -71,26 +71,26 @@ const Page = ({}: { system: any }) => {<Boxdata-ws-id="rRH1A7WUjY-_pfauYCmKU"data-ws-component="Box"- className="c1mhrh2o c1b095zn"+ className="cnvcd8b cxb89wn"><Textdata-ws-id="6NZJcVjrr4WHS6eqNG1SF"data-ws-component="Text"- className="c12yyvw2"+ className="cgkkof0">{"<lastmod>"}</Text><Textdata-ws-id="i0u7W1XIPYHdwcD4bmm4Z"data-ws-component="Text"- className="cjqm8t8"+ className="c5fu8k4">{url?.lastModified}</Text><Textdata-ws-id="NR5D_PEUVi_P7Agy2g1Zr"data-ws-component="Text"- className="c12yyvw2"+ className="cgkkof0">{"</lastmod>"}</Text>@@ -98,7 +98,7 @@ const Page = ({}: { system: any }) => {<Textdata-ws-id="Q1mx0RlJAIT37qXjHlt95"data-ws-component="Text"- className="c1cymde0"+ className="cwnydv4">{"</url>"}</Text>diff --git a/fixtures/webstudio-custom-template/app/__generated__/_index.tsx b/fixtures/webstudio-custom-template/app/__generated__/_index.tsxindex 8bee7c0eb2..4de27416bb 100644--- a/fixtures/webstudio-custom-template/app/__generated__/_index.tsx+++ b/fixtures/webstudio-custom-template/app/__generated__/_index.tsx@@ -77,19 +77,19 @@ const Page = ({}: { system: any }) => {<Bodydata-ws-id="ibXgMoi9_ipHx1gVrvii0"data-ws-component="Body"- className="c1vynykc c15qd3jj c122cnm9 c1jp5sfs"+ className="crro89i c1ldy0s3 ca0mhw9 c1t3ec4y"><Headingdata-ws-id="7pwqBSgrfuuOfk1JblWcL"data-ws-component="Heading"- className="c11x2bo2 cykwawo c1qmshyz c12wnxll c1hzshzo c136ve95 cyttr60 c1cywb85 c187ui6a c1azrtl7"+ className="c12poxag c13p4xw cpwo0o8 cjtvnga c1dgu1f0 c1mko7pq c1ryjtry c1yhbwj4 cm4n0xq c1weo8li">{"DO NOT TOUCH THIS PROJECT, IT'S USED FOR FIXTURES"}</Heading><Boxdata-ws-id="GMg3Wi9tJBFMtKcwbIK6z"data-ws-component="Box"- className="c1b095zn c8n5d6n chg86bx c9inwkc csxkr3h"+ className="cxb89wn czqi13r ct7y0ym cy9si0i c1zln9k"><Imagedata-ws-id="Mfd_mI-VJtT4r7gICAvXi"@@ -99,12 +99,12 @@ const Page = ({}: { system: any }) => {}width={1024}height={1024}- className="cp47ozi c133k2ks c1dww8sp c15iig68"+ className="c9mecv c1xeb6ie c1cpdzfi cub4hpc"/><Boxdata-ws-id="COafOppxs73Ne4O0Geik0"data-ws-component="Box"- className="cp47ozi c133k2ks c1dww8sp c15iig68"+ className="c9mecv c1xeb6ie c1cpdzfi cub4hpc"/></Box><Heading data-ws-id="jWb8SRMYG_XPWqCYvGZjo" data-ws-component="Heading">@@ -137,7 +137,7 @@ const Page = ({}: { system: any }) => {data-ws-component="Vimeo"url={"https://player.vimeo.com/video/831343124"}showPreview={true}- className="ca1m5u0 ciuvvr7 cuk1bdz"+ className="c17osjft c53gbe c8mrdqb"><VimeoPreviewImagedata-ws-id="wxd8Wul8dl2yPRFFedNn6"@@ -145,12 +145,12 @@ const Page = ({}: { system: any }) => {alt={"Vimeo video preview image"}sizes={"100vw"}src={"/custom-folder/home_wsKvRSqvkajPPBeycZ-C8.svg"}- className="c1eccbi0 cc32szi cuk1bdz c1ge5ofh c1fwh0y5 ch160p4 c1jxoq3x cewch87 c1la265j"+ className="c13adha2 c3sa779 c8mrdqb chv0hit c14mu2ti c1dsdrfn c1id445d cf36655 c1dfx0rt"/><VimeoSpinnerdata-ws-id="o8sAMUoaOraWYZClEfRgl"data-ws-component="VimeoSpinner"- className="c1eccbi0 ce5jzw0 cq3eebu c1319rdz c1x7j4n5 c176tfq4 c1qg633k"+ className="c13adha2 c1ifzo79 c1ljqvnn c10zke2u cplzsl2 c1h30nuz czav9qc"><HtmlEmbeddata-ws-id="BeQ7sgDlUizFvf4aHqOsh"@@ -165,13 +165,13 @@ const Page = ({}: { system: any }) => {data-ws-id="9hBBPGSf7hB30ZkSHKjNd"data-ws-component="VimeoPlayButton"aria-label={"Play button"}- className="c1eccbi0 c1yx3ait c1scl4ay ce5jzw0 cq3eebu cxar3by c1fiqkhd c1b095zn cyw79s9 c2f7s8e c9bs64c c6lou2r c16c73ai c1fisnnh c82rye8 c1xaktbd c1xplc5b c5admkk ccn3fhu cyn2bny c1xs2zvh c1be0m8p"+ className="c13adha2 c1t88ri8 ca7kf99 c1ifzo79 c1ljqvnn cguufcz c1an2y3u cxb89wn c1h8v1ng c19cfw6s cv7bbk3 c1tly7k c8mtcs c7jk6jf c17y59v6 c1d4fd4d c1yj9i1y c1xqoqjh cil01r8 crmtz4w coba2o7 c11eux2f"><Boxdata-ws-id="D__QElBIIQtamhJN3a4FI"data-ws-component="Box"aria-hidden={"true"}- className="c14af118 c1xa5m0w"+ className="c1cccshn c1eyznz"><HtmlEmbeddata-ws-id="iEc6hab-WardXZc5P9wJu"diff --git a/fixtures/webstudio-custom-template/app/__generated__/index.css b/fixtures/webstudio-custom-template/app/__generated__/index.cssindex 351d871353..c284bf04b2 100644--- a/fixtures/webstudio-custom-template/app/__generated__/index.css+++ b/fixtures/webstudio-custom-template/app/__generated__/index.css@@ -234,22 +234,22 @@ html {}}@media all {- .c11x2bo2 {+ .c12poxag {font-size: 4em;}- .cykwawo {+ .c13p4xw {font-family: "Cormorant Garamond", sans-serif;}- .c1qmshyz {+ .cpwo0o8 {background-attachment: scroll, scroll, scroll;}- .c12wnxll {+ .cjtvnga {-webkit-background-clip: border-box, border-box, border-box;}- .c1hzshzo {+ .c1dgu1f0 {background-blend-mode: normal, normal, normal;}- .c136ve95 {+ .c1mko7pq {background-image: linear-gradient(rgba(255, 0, 0, 0.2),rgba(0, 255, 255, 0.2)@@ -257,181 +257,181 @@ html {url("/custom-folder/home_wsKvRSqvkajPPBeycZ-C8.svg"),linear-gradient(to right, rgba(255, 0, 255, 0.2), rgba(0, 255, 0, 0.2));}- .cyttr60 {+ .c1ryjtry {background-origin: padding-box, padding-box, padding-box;}- .c1cywb85 {+ .c1yhbwj4 {background-position: 0%, 0%, 0%;}- .c187ui6a {+ .cm4n0xq {background-repeat: repeat, repeat, repeat;}- .c1azrtl7 {+ .c1weo8li {background-size: auto, auto, auto;}- .c1vynykc {+ .crro89i {margin-top: 15px;}- .c122cnm9 {+ .ca0mhw9 {margin-bottom: 15px;}- .c15qd3jj {+ .c1ldy0s3 {margin-right: 15px;}- .c1jp5sfs {+ .c1t3ec4y {margin-left: 15px;}- .ca1m5u0 {+ .c17osjft {position: relative;}- .ciuvvr7 {+ .c53gbe {aspect-ratio: 640/360;}- .cuk1bdz {+ .c8mrdqb {width: 100%;}- .c1eccbi0 {+ .c13adha2 {position: absolute;}- .cc32szi {+ .c3sa779 {object-fit: cover;}- .c1ge5ofh {+ .chv0hit {height: 100%;}- .c1fwh0y5 {+ .c14mu2ti {border-top-left-radius: 20px;}- .ch160p4 {+ .c1dsdrfn {border-top-right-radius: 20px;}- .c1jxoq3x {+ .c1id445d {border-bottom-left-radius: 20px;}- .cewch87 {+ .cf36655 {border-bottom-right-radius: 20px;}- .c1la265j {+ .c1dfx0rt {object-position: cover;}- .c1yx3ait {+ .c1t88ri8 {width: 140px;}- .c1scl4ay {+ .ca7kf99 {height: 80px;}- .ce5jzw0 {+ .c1ifzo79 {top: 50%;}- .cq3eebu {+ .c1ljqvnn {left: 50%;}- .cxar3by {+ .cguufcz {margin-top: -40px;}- .c1fiqkhd {+ .c1an2y3u {margin-left: -70px;}- .c1b095zn {+ .cxb89wn {display: flex;}- .cyw79s9 {+ .c1h8v1ng {align-items: center;}- .c2f7s8e {+ .c19cfw6s {justify-content: center;}- .c9bs64c {+ .cv7bbk3 {border-top-style: none;}- .c6lou2r {+ .c1tly7k {border-right-style: none;}- .c16c73ai {+ .c8mtcs {border-bottom-style: none;}- .c1fisnnh {+ .c7jk6jf {border-left-style: none;}- .c82rye8 {+ .c17y59v6 {border-top-left-radius: 5px;}- .c1xaktbd {+ .c1d4fd4d {border-top-right-radius: 5px;}- .c1xplc5b {+ .c1yj9i1y {border-bottom-left-radius: 5px;}- .c5admkk {+ .c1xqoqjh {border-bottom-right-radius: 5px;}- .ccn3fhu {+ .cil01r8 {cursor: pointer;}- .cyn2bny {+ .crmtz4w {background-color: rgba(18, 18, 18, 1);}- .c1xs2zvh {+ .coba2o7 {color: rgba(255, 255, 255, 1);}- .c1be0m8p:hover {+ .c11eux2f:hover {background-color: rgba(0, 173, 239, 1);}- .c14af118 {+ .c1cccshn {width: 60px;}- .c1xa5m0w {+ .c1eyznz {height: 60px;}- .c1319rdz {+ .c10zke2u {width: 70px;}- .c1x7j4n5 {+ .cplzsl2 {height: 70px;}- .c176tfq4 {+ .c1h30nuz {margin-top: -35px;}- .c1qg633k {+ .czav9qc {margin-left: -35px;}- .c8n5d6n {+ .czqi13r {flex-direction: row;}- .chg86bx {+ .ct7y0ym {flex-wrap: nowrap;}- .c9inwkc {+ .cy9si0i {align-items: stretch;}- .csxkr3h {+ .c1zln9k {justify-content: space-between;}- .cp47ozi {+ .c9mecv {flex-grow: 1;}- .c133k2ks {+ .c1xeb6ie {flex-shrink: 0;}- .c1dww8sp {+ .c1cpdzfi {min-width: 0px;}- .c15iig68 {+ .cub4hpc {flex-basis: 0px;}- .c1cymde0 {+ .cwnydv4 {color: rgba(36, 12, 233, 1);}- .c1mhrh2o {+ .cnvcd8b {margin-left: 20px;}- .c15pkvqb {+ .c1s70es7 {color: rgba(8, 137, 17, 1);}- .cjqm8t8 {+ .c5fu8k4 {font-weight: 600;}- .c12yyvw2 {+ .cgkkof0 {color: rgba(208, 24, 79, 1);}}diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsxindex 80ce4245ac..155935e267 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/_index.tsx@@ -24,7 +24,7 @@ const Page = ({}: { system: any }) => {<Bodydata-ws-id="MMimeobf_zi4ZkRGXapju"data-ws-component="Body"- className="c9ryj1f c1e3go07 cmhckny cr0vgwe"+ className="c1jaw2zx c1bn74oy c1vwwfi7 c1xn7xpo"><Heading data-ws-id="MYDt0guk1-vzc7yzqyN6A" data-ws-component="Heading">{"Simple Project to test CLI"}diff --git a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/index.css b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/index.cssindex 6ea394ea0b..a9ada72e47 100644--- a/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/index.css+++ b/fixtures/webstudio-remix-netlify-edge-functions/app/__generated__/index.css@@ -79,16 +79,16 @@ html {}}@media all {- .c9ryj1f {+ .c1jaw2zx {display: flex;}- .c1e3go07 {+ .c1bn74oy {align-items: center;}- .cmhckny {+ .c1vwwfi7 {justify-content: center;}- .cr0vgwe {+ .c1xn7xpo {flex-direction: column;}}diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx b/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsxindex 80ce4245ac..155935e267 100644--- a/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/_index.tsx@@ -24,7 +24,7 @@ const Page = ({}: { system: any }) => {<Bodydata-ws-id="MMimeobf_zi4ZkRGXapju"data-ws-component="Body"- className="c9ryj1f c1e3go07 cmhckny cr0vgwe"+ className="c1jaw2zx c1bn74oy c1vwwfi7 c1xn7xpo"><Heading data-ws-id="MYDt0guk1-vzc7yzqyN6A" data-ws-component="Heading">{"Simple Project to test CLI"}diff --git a/fixtures/webstudio-remix-netlify-functions/app/__generated__/index.css b/fixtures/webstudio-remix-netlify-functions/app/__generated__/index.cssindex 6ea394ea0b..a9ada72e47 100644--- a/fixtures/webstudio-remix-netlify-functions/app/__generated__/index.css+++ b/fixtures/webstudio-remix-netlify-functions/app/__generated__/index.css@@ -79,16 +79,16 @@ html {}}@media all {- .c9ryj1f {+ .c1jaw2zx {display: flex;}- .c1e3go07 {+ .c1bn74oy {align-items: center;}- .cmhckny {+ .c1vwwfi7 {justify-content: center;}- .cr0vgwe {+ .c1xn7xpo {flex-direction: column;}}diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.tsxindex ee57384d0e..fc4efa63a6 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[_route_with_symbols_]._index.tsx@@ -33,7 +33,7 @@ const Page = ({}: { system: any }) => {data-ws-id="AdXSAYCx4QDo5QN6nLoGs"data-ws-component="Image"src={"/assets/small-avif-kitty_FnabJsioMWpBtXZSGf4DR.webp"}- className="c1arp7pb"+ className="czgliev"/></Body>);diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.tsxindex 15a2be2915..3dda199c77 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/[radix]._index.tsx@@ -65,17 +65,17 @@ const Page = ({}: { system: any }) => {data-ws-id="zJ927zk9txwUbYycKB7QA"data-ws-component="@webstudio-is/sdk-components-react-radix:AccordionItem"data-ws-index="0"- className="c1lk4dyo cpa46rs c1rs4a6c"+ className="c1jm23u4 c17v6wg4 c14ypr85"><AccordionHeaderdata-ws-id="sMxg7xT1hwYt05hbOvoPL"data-ws-component="@webstudio-is/sdk-components-react-radix:AccordionHeader"- className="ct8bqew"+ className="c13v7j50"><AccordionTriggerdata-ws-id="qQSA4NoyKC88O68mBiQe2"data-ws-component="@webstudio-is/sdk-components-react-radix:AccordionTrigger"- className="ct8bqew c4wr6vh c5exn1v c6th5p4 c8sklb9 cozm0zy crf2knr c16vf3pr c1u6bhyx cgivo88 c1px50mc cnog96r"+ className="c13v7j50 c1njwnl4 cr59mug cuiulls c1aj1vjn cxqmhs5 cmt2mhu c1f88uyp coehty2 c1bsiosv cg783j6 c1s4llbc"><Text data-ws-id="q-DVI4YTNrQ1LizmEyJHI" data-ws-component="Text">{"Is it accessible?"}@@ -83,7 +83,7 @@ const Page = ({}: { system: any }) => {<Boxdata-ws-id="RSk81lLj2IGXgchTuXF7V"data-ws-component="Box"- className="c1chi4tu chkajpy cmhi6j0 c1bn66w8 cw6h46e c1mmsm3k c79adhm"+ className="c14hansb c6d2sb5 cwwiftc c9oe4mg cum13td clcagvf cszwd2x"><HtmlEmbeddata-ws-id="d0sd_G-kHirxgjq6s6Uq1"@@ -98,7 +98,7 @@ const Page = ({}: { system: any }) => {<AccordionContentdata-ws-id="IUftdfjK-ilSzfOTdIx1u"data-ws-component="@webstudio-is/sdk-components-react-radix:AccordionContent"- className="c3kadi cl1n90y c11hmcmb c16vf3pr"+ className="c1mxwmum c11q6wf c11rm5bv c1f88uyp">{"Yes. It adheres to the WAI-ARIA design pattern."}</AccordionContent>@@ -107,17 +107,17 @@ const Page = ({}: { system: any }) => {data-ws-id="C838wkvIcA1BQu30Xu2G8"data-ws-component="@webstudio-is/sdk-components-react-radix:AccordionItem"data-ws-index="1"- className="c1lk4dyo cpa46rs c1rs4a6c"+ className="c1jm23u4 c17v6wg4 c14ypr85"><AccordionHeaderdata-ws-id="fYUOB_brm6s0Ky68lzMfU"data-ws-component="@webstudio-is/sdk-components-react-radix:AccordionHeader"- className="ct8bqew"+ className="c13v7j50"><AccordionTriggerdata-ws-id="dfd4gonev_AX6BpuCsxjb"data-ws-component="@webstudio-is/sdk-components-react-radix:AccordionTrigger"- className="ct8bqew c4wr6vh c5exn1v c6th5p4 c8sklb9 cozm0zy crf2knr c16vf3pr c1u6bhyx cgivo88 c1px50mc cnog96r"+ className="c13v7j50 c1njwnl4 cr59mug cuiulls c1aj1vjn cxqmhs5 cmt2mhu c1f88uyp coehty2 c1bsiosv cg783j6 c1s4llbc"><Text data-ws-id="lZ7sI6Kw_0VZkURriKscB" data-ws-component="Text">{"Is it styled?"}@@ -125,7 +125,7 @@ const Page = ({}: { system: any }) => {<Boxdata-ws-id="wRw75kuvFzl5NWD8IGJoI"data-ws-component="Box"- className="c1chi4tu chkajpy cmhi6j0 c1bn66w8 cw6h46e c1mmsm3k c79adhm"+ className="c14hansb c6d2sb5 cwwiftc c9oe4mg cum13td clcagvf cszwd2x"><HtmlEmbeddata-ws-id="StPslEr81nfBISqBE2R-Y"@@ -140,7 +140,7 @@ const Page = ({}: { system: any }) => {<AccordionContentdata-ws-id="wNRVuu0L5E8TVufKdswp1"data-ws-component="@webstudio-is/sdk-components-react-radix:AccordionContent"- className="c3kadi cl1n90y c11hmcmb c16vf3pr"+ className="c1mxwmum c11q6wf c11rm5bv c1f88uyp">{"Yes. It comes with default styles that matches the other components' aesthetic."@@ -151,17 +151,17 @@ const Page = ({}: { system: any }) => {data-ws-id="65djoTmSBGemZ2L5izQ5M"data-ws-component="@webstudio-is/sdk-components-react-radix:AccordionItem"data-ws-index="2"- className="c1lk4dyo cpa46rs c1rs4a6c"+ className="c1jm23u4 c17v6wg4 c14ypr85"><AccordionHeaderdata-ws-id="UJYfe6kH7HqhH0YYeJwe7"data-ws-component="@webstudio-is/sdk-components-react-radix:AccordionHeader"- className="ct8bqew"+ className="c13v7j50"><AccordionTriggerdata-ws-id="600nGddaNxGGdsuGgpxJR"data-ws-component="@webstudio-is/sdk-components-react-radix:AccordionTrigger"- className="ct8bqew c4wr6vh c5exn1v c6th5p4 c8sklb9 cozm0zy crf2knr c16vf3pr c1u6bhyx cgivo88 c1px50mc cnog96r"+ className="c13v7j50 c1njwnl4 cr59mug cuiulls c1aj1vjn cxqmhs5 cmt2mhu c1f88uyp coehty2 c1bsiosv cg783j6 c1s4llbc"><Text data-ws-id="1iNKIMG91n83PzJnEdxq9" data-ws-component="Text">{"Is it animated?"}@@ -169,7 +169,7 @@ const Page = ({}: { system: any }) => {<Boxdata-ws-id="Ta70VqUb_fGJXBT_zsnxQ"data-ws-component="Box"- className="c1chi4tu chkajpy cmhi6j0 c1bn66w8 cw6h46e c1mmsm3k c79adhm"+ className="c14hansb c6d2sb5 cwwiftc c9oe4mg cum13td clcagvf cszwd2x"><HtmlEmbeddata-ws-id="sO80m5u4f87jVGG91t6u8"@@ -184,7 +184,7 @@ const Page = ({}: { system: any }) => {<AccordionContentdata-ws-id="mOVPnIrlt6IwVAzI_i2Fc"data-ws-component="@webstudio-is/sdk-components-react-radix:AccordionContent"- className="c3kadi cl1n90y c11hmcmb c16vf3pr"+ className="c1mxwmum c11q6wf c11rm5bv c1f88uyp">{"Yes. It's animated by default, but you can disable it if you prefer."diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/_index.tsx b/fixtures/webstudio-remix-vercel/app/__generated__/_index.tsxindex 042386d6b1..c15daab46a 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/_index.tsx+++ b/fixtures/webstudio-remix-vercel/app/__generated__/_index.tsx@@ -50,24 +50,24 @@ const Page = ({}: { system: any }) => {<Bodydata-ws-id="On9cvWCxr5rdZtY9O1Bv0"data-ws-component="Body"- className="c1wfdiy8 cg4dwmz c1psdgn0 ciwrswx"+ className="c198lioj cr65sqc c1ucc9vx c1dhla2v"><Headingdata-ws-id="nVMWvMsaLCcb0o1wuNQgg"data-ws-component="Heading"- className="cr3bcad"+ className="c1knjlal">{"DO NOT TOUCH THIS PROJECT, IT'S USED FOR FIXTURES"}</Heading><Boxdata-ws-id="f0kF-WmL7DQg7MSyRvqY1"data-ws-component="Box"- className="ct8bqew c18lita3 c1ac63p"+ className="c13v7j50 c1ubj2iz clu0378"><Boxdata-ws-id="5XDbqPrZDeCwq4YJ3CHsc"data-ws-component="Box"- className="cdojbwh c4wr6vh cn27x24 cl3i1h5"+ className="c15heboa c1njwnl4 cxq4cho cn5joda"><Headingdata-ws-id="oLXYe1UQiVMhVnZGvJSMr"@@ -109,7 +109,7 @@ const Page = ({}: { system: any }) => {data-ws-id="9I4GRU1sev48hREkQcKQ-"data-ws-component="Link"href={"/_route_with_symbols_"}- className="cnpb7qg"+ className="ch2exr5">{"Symbols in path"}</Link>@@ -117,7 +117,7 @@ const Page = ({}: { system: any }) => {data-ws-id="81ejLVXyFEV1SxiJrWhyw"data-ws-component="Link"href={"/heading-with-id#my-heading"}- className="cnpb7qg"+ className="ch2exr5">{"Link to instance"}</Link>@@ -125,7 +125,7 @@ const Page = ({}: { system: any }) => {<Boxdata-ws-id="qPnkiFGDj8dITWb1kmpGl"data-ws-component="Box"- className="cdojbwh c4wr6vh cn27x24 cl3i1h5"+ className="c15heboa c1njwnl4 cxq4cho cn5joda"><Imagedata-ws-id="pX1ovPI7NdC0HRjkw6Kpw"@@ -133,7 +133,7 @@ const Page = ({}: { system: any }) => {src={"/assets/_937084ed-a798-49fe-8664-df93a2af605e_uiBk3o6UWdqolyakMvQJ9.jpeg"}- className="c1arp7pb"+ className="czgliev"/></Box></Box>diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/index.css b/fixtures/webstudio-remix-vercel/app/__generated__/index.cssindex 744ad4264e..b443009c70 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/index.css+++ b/fixtures/webstudio-remix-vercel/app/__generated__/index.css@@ -317,115 +317,115 @@ html {}}@media all {- .cr3bcad {+ .c1knjlal {font-size: 4em;}- .ct8bqew {+ .c13v7j50 {display: flex;}- .c18lita3 {+ .c1ubj2iz {justify-content: center;}- .c1ac63p {+ .clu0378 {align-items: start;}- .cdojbwh {+ .c15heboa {min-width: 0px;}- .c4wr6vh {+ .c1njwnl4 {flex-grow: 1;}- .cn27x24 {+ .cxq4cho {flex-shrink: 0;}- .cl3i1h5 {+ .cn5joda {flex-basis: 0px;}- .c1arp7pb {+ .czgliev {aspect-ratio: 1;}- .c1wfdiy8 {+ .c198lioj {padding-top: 16px;}- .cg4dwmz {+ .cr65sqc {padding-right: 16px;}- .c1psdgn0 {+ .c1ucc9vx {padding-left: 16px;}- .ciwrswx {+ .c1dhla2v {padding-bottom: 16px;}- .c1lk4dyo {+ .c1jm23u4 {border-bottom-width: 1px;}- .cpa46rs {+ .c17v6wg4 {border-bottom-style: solid;}- .c1rs4a6c {+ .c14ypr85 {border-bottom-color: rgba(226, 232, 240, 1);}- .c5exn1v {+ .cr59mug {flex-shrink: 1;}- .c6th5p4 {+ .cuiulls {flex-basis: 0%;}- .c8sklb9 {+ .c1aj1vjn {align-items: center;}- .cozm0zy {+ .cxqmhs5 {justify-content: space-between;}- .crf2knr {+ .cmt2mhu {padding-top: 1rem;}- .c16vf3pr {+ .c1f88uyp {padding-bottom: 1rem;}- .c1u6bhyx {+ .coehty2 {font-weight: 500;}- .cgivo88 {- --accordion-trigger-icon-transform: 0deg;- }- .c1px50mc:hover {+ .c1bsiosv:hover {text-decoration-line: underline;}- .cnog96r[data-state="open"] {+ .cg783j6 {+ --accordion-trigger-icon-transform: 0deg;+ }+ .c1s4llbc[data-state="open"] {--accordion-trigger-icon-transform: 180deg;}- .c1chi4tu {+ .c14hansb {rotate: var(--accordion-trigger-icon-transform);}- .chkajpy {+ .c6d2sb5 {height: 1rem;}- .cmhi6j0 {+ .cwwiftc {width: 1rem;}- .c1bn66w8 {+ .c9oe4mg {flex-grow: 0;}- .cw6h46e {+ .cum13td {transition-property: all;}- .c1mmsm3k {+ .clcagvf {transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);}- .c79adhm {+ .cszwd2x {transition-duration: 200ms;}- .c3kadi {+ .c1mxwmum {overflow: hidden;}- .cl1n90y {+ .c11q6wf {font-size: 0.875rem;}- .c11hmcmb {+ .c11rm5bv {line-height: 1.25rem;}- .cnpb7qg {+ .ch2exr5 {display: block;}}diff --git a/packages/css-engine/src/core/atomic.test.ts b/packages/css-engine/src/core/atomic.test.tsnew file mode 100644index 0000000000..c2fb97263f--- /dev/null+++ b/packages/css-engine/src/core/atomic.test.ts@@ -0,0 +1,177 @@+import { test, expect } from "@jest/globals";+import { createRegularStyleSheet } from "./create-style-sheet";+import { generateAtomic } from "./atomic";++const mediaRuleOptions0 = { minWidth: 0 } as const;+const mediaId0 = "0";++test("use matching media rule", () => {+ const sheet = createRegularStyleSheet();+ sheet.addMediaRule("x");+ const rule = sheet.addNestingRule("");+ rule.setDeclaration({+ breakpoint: "x",+ selector: "",+ property: "display",+ value: { type: "keyword", value: "block" },+ });+ rule.setDeclaration({+ breakpoint: "x",+ selector: "",+ property: "color",+ value: { type: "keyword", value: "red" },+ });+ expect(generateAtomic(sheet, { getKey: () => "" }).cssText)+ .toMatchInlineSnapshot(`+"@media all {+ .ccqp4le {+ display: block+ }+ .cen0ymu {+ color: red+ }+}"+`);+});++test("use nested selector", () => {+ const sheet = createRegularStyleSheet();+ sheet.addMediaRule("x");+ const rule = sheet.addNestingRule("");+ rule.setDeclaration({+ breakpoint: "x",+ selector: ":hover",+ property: "display",+ value: { type: "keyword", value: "block" },+ });+ expect(generateAtomic(sheet, { getKey: () => "" }).cssText)+ .toMatchInlineSnapshot(`+"@media all {+ .c143pt9k:hover {+ display: block+ }+}"+`);+});++test("added classes", () => {+ const sheet = createRegularStyleSheet();+ sheet.addMediaRule("x");+ const rule = sheet.addNestingRule(".instance");+ rule.setDeclaration({+ breakpoint: "x",+ selector: "",+ property: "display",+ value: { type: "keyword", value: "block" },+ });+ const instances = new Map([[rule, "instanceId"]]);+ const { classesMap } = generateAtomic(sheet, {+ getKey: (rule) => instances.get(rule) ?? "",+ });+ expect(classesMap.get("instanceId")).toEqual(["ccqp4le"]);+});++test("rule with multiple properties", () => {+ const sheet = createRegularStyleSheet();+ sheet.addMediaRule(mediaId0, mediaRuleOptions0);+ const rule = sheet.addNestingRule(".instance");+ rule.setDeclaration({+ breakpoint: mediaId0,+ selector: "",+ property: "display",+ value: { type: "keyword", value: "block" },+ });+ rule.setDeclaration({+ breakpoint: mediaId0,+ selector: "",+ property: "color",+ value: { type: "keyword", value: "red" },+ });+ expect(generateAtomic(sheet, { getKey: () => "" }).cssText)+ .toMatchInlineSnapshot(`+"@media all and (min-width: 0px) {+ .c1qg54vh {+ display: block+ }+ .ckgcokb {+ color: red+ }+}"+`);+});++test("share atomic rules", () => {+ const sheet = createRegularStyleSheet();+ sheet.addMediaRule("x");+ const rule1 = sheet.addNestingRule("1");+ rule1.setDeclaration({+ breakpoint: "x",+ selector: "",+ property: "display",+ value: { type: "keyword", value: "block" },+ });+ rule1.setDeclaration({+ breakpoint: "x",+ selector: "",+ property: "color",+ value: { type: "keyword", value: "red" },+ });+ const rule2 = sheet.addNestingRule("2");+ rule2.setDeclaration({+ breakpoint: "x",+ selector: "",+ property: "display",+ value: { type: "keyword", value: "block" },+ });+ const instances = new Map([+ [rule1, "1"],+ [rule2, "2"],+ ]);+ const { cssText, classesMap } = generateAtomic(sheet, {+ getKey: (rule) => instances.get(rule) ?? "",+ });+ expect(cssText).toMatchInlineSnapshot(`+"@media all {+ .ccqp4le {+ display: block+ }+ .cen0ymu {+ color: red+ }+}"+`);+ expect(classesMap.get("1")).toEqual(["ccqp4le", "cen0ymu"]);+ expect(classesMap.get("2")).toEqual(["ccqp4le"]);+});++test("distinct similar declarations from different breakpoints", () => {+ const sheet = createRegularStyleSheet();+ sheet.addMediaRule("a");+ sheet.addMediaRule("b");+ const rule1 = sheet.addNestingRule("1");+ rule1.setDeclaration({+ breakpoint: "a",+ selector: "",+ property: "display",+ value: { type: "keyword", value: "block" },+ });+ rule1.setDeclaration({+ breakpoint: "b",+ selector: "",+ property: "display",+ value: { type: "keyword", value: "block" },+ });+ expect(generateAtomic(sheet, { getKey: () => "" }).cssText)+ .toMatchInlineSnapshot(`+"@media all {+ .cumb2su {+ display: block+ }+}+@media all {+ .c1u3btle {+ display: block+ }+}"+`);+});diff --git a/packages/css-engine/src/core/atomic.ts b/packages/css-engine/src/core/atomic.tsnew file mode 100644index 0000000000..7cd9e3486c--- /dev/null+++ b/packages/css-engine/src/core/atomic.ts@@ -0,0 +1,44 @@+import hash from "@emotion/hash";+import type { StyleSheet } from "./style-sheet";+import { NestingRule } from "./rules";+import { toValue, type TransformValue } from "./to-value";++type Options = {+ getKey: (rule: NestingRule) => string;+ transformValue?: TransformValue;+};++export const generateAtomic = (sheet: StyleSheet, options: Options) => {+ const { getKey, transformValue } = options;+ const atomicRules = new Map<string, NestingRule>();+ const classesMap = new Map<string, string[]>();+ for (const rule of sheet.nestingRules.values()) {+ const groupKey = getKey(rule);+ const classList: string[] = [];+ // convert each declaration into separate rule+ for (const declaration of rule.getDeclarations()) {+ const atomicHash = hash(+ declaration.breakpoint ++ declaration.selector ++ declaration.property ++ toValue(declaration.value, transformValue)+ );+ // "c" makes sure hash always starts with a letter.+ const className = `c${atomicHash}`;+ // reuse atomic rules+ let atomicRule = atomicRules.get(atomicHash);+ if (atomicRule === undefined) {+ atomicRule = new NestingRule(`.${className}`, new Map());+ atomicRule.setDeclaration(declaration);+ atomicRules.set(atomicHash, atomicRule);+ }+ classList.push(className);+ }+ classesMap.set(groupKey, classList);+ }+ const cssText = sheet.generateWith({+ nestingRules: Array.from(atomicRules.values()),+ transformValue,+ });+ return { cssText, classesMap };+};diff --git a/packages/css-engine/src/core/create-style-sheet.ts b/packages/css-engine/src/core/create-style-sheet.tsindex 2df93aba5f..3ee58612d0 100644--- a/packages/css-engine/src/core/create-style-sheet.ts+++ b/packages/css-engine/src/core/create-style-sheet.ts@@ -1,13 +1,7 @@import { StyleSheetRegular } from "./style-sheet-regular";-import { StyleSheetAtomic } from "./style-sheet-atomic";import { StyleElement } from "./style-element";export const createRegularStyleSheet = (options?: { name?: string }) => {const element = new StyleElement(options?.name);return new StyleSheetRegular(element);};--export const createAtomicStyleSheet = (options?: { name?: string }) => {- const element = new StyleElement(options?.name);- return new StyleSheetAtomic(element);-};diff --git a/packages/css-engine/src/core/index.ts b/packages/css-engine/src/core/index.tsindex 2622ddfd7c..c1645515ef 100644--- a/packages/css-engine/src/core/index.ts+++ b/packages/css-engine/src/core/index.ts@@ -1,4 +1,5 @@export type {+ NestingRule,AnyRule,StyleRule,MediaRule,@@ -6,7 +7,6 @@ export type {FontFaceRule,} from "./rules";export type { StyleSheetRegular } from "./style-sheet-regular";-export type { StyleSheetAtomic } from "./style-sheet-atomic";export * from "./create-style-sheet";export * from "./to-value";export * from "./to-property";@@ -14,3 +14,4 @@ export * from "./match-media";export * from "./equal-media";export * from "./compare-media";export * from "./find-applicable-media";+export * from "./atomic";diff --git a/packages/css-engine/src/core/rules.ts b/packages/css-engine/src/core/rules.tsindex 5ba661b2ac..fc9b2a8948 100644--- a/packages/css-engine/src/core/rules.ts+++ b/packages/css-engine/src/core/rules.ts@@ -99,6 +99,23 @@ export class NestingRule {this.#declarations.delete(getDeclarationKey(declaration));this.#cache.delete(declaration.breakpoint);}+ getDeclarations() {+ // apply mixins first and then merge added declarations+ const declarations = new Map<string, Declaration>();+ for (const mixin of this.#mixins) {+ const rule = this.#mixinRules.get(mixin);+ if (rule === undefined) {+ continue;+ }+ for (const declaration of rule.getDeclarations()) {+ declarations.set(getDeclarationKey(declaration), declaration);+ }+ }+ for (const declaration of this.#declarations.values()) {+ declarations.set(getDeclarationKey(declaration), declaration);+ }+ return declarations.values();+ }generateRules({breakpoint,indent = 0,@@ -108,16 +125,12 @@ export class NestingRule {indent?: number;transformValue?: TransformValue;}) {- const mixinRules: MixinRule[] = [];for (const mixin of this.#mixins) {const rule = this.#mixinRules.get(mixin);// invalidate cache when mixin is changedif (rule?.isDirtyBreakpoint(breakpoint)) {this.#cache.delete(breakpoint);}- if (rule) {- mixinRules.push(rule);- }}const cached = this.#cache.get(breakpoint);@@ -131,17 +144,7 @@ export class NestingRule {}const spaces = " ".repeat(indent);const linesBySelector = new Map<string, string>();- // apply mixins first and then merge added declarations- const declarations = new Map<string, Declaration>();- for (const rule of mixinRules) {- for (const declaration of rule.getDeclarations()) {- declarations.set(getDeclarationKey(declaration), declaration);- }- }- for (const declaration of this.#declarations.values()) {- declarations.set(getDeclarationKey(declaration), declaration);- }- for (const declaration of declarations.values()) {+ for (const declaration of this.getDeclarations()) {// generate declarations only for specified breakpointif (declaration.breakpoint !== breakpoint) {continue;@@ -322,6 +325,10 @@ export class MediaRule {rules.push(generatedRule);}}+ // avoid rendering empty media queries+ if (rules.length === 0) {+ return "";+ }let conditionText = "";const { minWidth, maxWidth } = this.options;if (minWidth !== undefined) {diff --git a/packages/css-engine/src/core/style-sheet-atomic.test.ts b/packages/css-engine/src/core/style-sheet-atomic.test.tsdeleted file mode 100644index 30dbf58b91..0000000000--- a/packages/css-engine/src/core/style-sheet-atomic.test.ts+++ /dev/null@@ -1,132 +0,0 @@-import { describe, beforeEach, test, expect } from "@jest/globals";-import type { StyleSheetAtomic } from "./style-sheet-atomic";-import { createAtomicStyleSheet } from "./create-style-sheet";--const mediaRuleOptions0 = { minWidth: 0 } as const;-const mediaId0 = "0";--describe("Style Sheet Atomic", () => {- let sheet: StyleSheetAtomic;-- const reset = () => {- sheet = createAtomicStyleSheet();- };-- beforeEach(reset);-- test("use default media rule when there is no matching one registered", () => {- sheet.addStyleRule({- style: { display: { type: "keyword", value: "block" } },- breakpoint: "x",- });- expect(sheet.cssText).toMatchInlineSnapshot(`-"@media all {- .c19k25ej {- display: block- }-}"-`);- sheet.addStyleRule({- style: { color: { type: "keyword", value: "red" } },- breakpoint: "x",- });- expect(sheet.cssText).toMatchInlineSnapshot(`-"@media all {- .c19k25ej {- display: block- }- .cs9ip66 {- color: red- }-}"-`);- });-- test("use state suffix", () => {- sheet.addStyleRule(- {- style: { display: { type: "keyword", value: "block" } },- breakpoint: "x",- },- ":hover"- );- expect(sheet.cssText).toMatchInlineSnapshot(`-"@media all {- .cmyojan:hover {- display: block- }-}"-`);- });-- test("added classes", () => {- const { classes } = sheet.addStyleRule({- style: { display: { type: "keyword", value: "block" } },- breakpoint: "x",- });- expect(classes).toEqual(["c19k25ej"]);- });-- test("rule with multiple properties", () => {- sheet.addMediaRule(mediaId0, mediaRuleOptions0);- sheet.addStyleRule({- style: {- display: { type: "keyword", value: "block" },- color: { type: "keyword", value: "red" },- },- breakpoint: "0",- });- expect(sheet.cssText).toMatchInlineSnapshot(`-"@media all and (min-width: 0px) {- .cusz56a {- display: block- }- .cswg5vq {- color: red- }-}"-`);- });-- test("add style rule to an existing media rule", () => {- sheet.addMediaRule(mediaId0, mediaRuleOptions0);- sheet.addStyleRule({- style: {- display: { type: "keyword", value: "block" },- color: { type: "keyword", value: "red" },- },- breakpoint: "0",- });- expect(sheet.cssText).toMatchInlineSnapshot(`-"@media all and (min-width: 0px) {- .cusz56a {- display: block- }- .cswg5vq {- color: red- }-}"-`);- sheet.addStyleRule({- style: {- // It should prevent duplicates- display: { type: "keyword", value: "block" },- color: { type: "keyword", value: "green" },- },- breakpoint: "0",- });- expect(sheet.cssText).toMatchInlineSnapshot(`-"@media all and (min-width: 0px) {- .cusz56a {- display: block- }- .cswg5vq {- color: red- }- .c8jb4vi {- color: green- }-}"-`);- });-});diff --git a/packages/css-engine/src/core/style-sheet-atomic.ts b/packages/css-engine/src/core/style-sheet-atomic.tsdeleted file mode 100644index ed520885e2..0000000000--- a/packages/css-engine/src/core/style-sheet-atomic.ts+++ /dev/null@@ -1,50 +0,0 @@-import type { Style, StyleProperty } from "../schema";-import { StylePropertyMap, StyleRule } from "./rules";-import type { TransformValue } from "./to-value";-import hash from "@emotion/hash";-import { StyleSheet, type CssRule } from "./style-sheet";--const defaultMediaRuleId = "__default-media-rule__";--export class StyleSheetAtomic extends StyleSheet {- addStyleRule(- { style, breakpoint }: CssRule,- selectorSuffix: string = "",- transformValue?: TransformValue- ) {- const mediaRule = this.addMediaRule(breakpoint || defaultMediaRuleId);- const styleRules = [];- const classes = [];-- let property: StyleProperty;- for (property in style) {- const stylePropertyMap = new StylePropertyMap(- { [property]: style[property] } as Style,- transformValue- );- // "c" makes sure hash always starts with a letter.- const className = `c${hash(- stylePropertyMap + selectorSuffix + breakpoint- )}`;- classes.push(className);- const newStyleRule = new StyleRule(- `.${className}${selectorSuffix}`,- stylePropertyMap,- transformValue,- this.#onChangeRule- );- styleRules.push(newStyleRule);-- if (mediaRule.rules.has(newStyleRule.selectorText) === false) {- mediaRule.insertRule(newStyleRule);- this.markAsDirty();- }- }-- return { styleRules, classes };- }-- #onChangeRule = () => {- this.markAsDirty();- };-}diff --git a/packages/css-engine/src/core/style-sheet-regular.test.ts b/packages/css-engine/src/core/style-sheet-regular.test.tsindex 5ae13d9455..edfadbbcb2 100644--- a/packages/css-engine/src/core/style-sheet-regular.test.ts+++ b/packages/css-engine/src/core/style-sheet-regular.test.ts@@ -917,6 +917,26 @@ describe("Style Sheet Regular", () => {color: blue}}"+`);+ });++ test("avoid rendering empty media queries", () => {+ const sheet = createRegularStyleSheet();+ sheet.addMediaRule("base", {});+ sheet.addMediaRule("small", { minWidth: 768 });+ const rule = sheet.addNestingRule(".instance");+ rule.setDeclaration({+ breakpoint: "base",+ selector: "",+ property: "color",+ value: { type: "keyword", value: "blue" },+ });+ expect(sheet.cssText).toMatchInlineSnapshot(`+"@media all {+ .instance {+ color: blue+ }+}"`);});});diff --git a/packages/css-engine/src/core/style-sheet.ts b/packages/css-engine/src/core/style-sheet.tsindex a14515f83b..9175326620 100644--- a/packages/css-engine/src/core/style-sheet.ts+++ b/packages/css-engine/src/core/style-sheet.ts@@ -22,7 +22,7 @@ export class StyleSheet {#mediaRules: Map<string, MediaRule> = new Map();#plainRules: Map<string, PlaintextRule> = new Map();#mixinRules: Map<string, MixinRule> = new Map();- #nestingRules: Map<string, NestingRule> = new Map();+ nestingRules: Map<string, NestingRule> = new Map();#fontFaceRules: Array<FontFaceRule> = [];#transformValue?: TransformValue;#isDirty = false;@@ -73,10 +73,10 @@ export class StyleSheet {return rule;}addNestingRule(selector: string) {- let rule = this.#nestingRules.get(selector);+ let rule = this.nestingRules.get(selector);if (rule === undefined) {rule = new NestingRule(selector, this.#mixinRules);- this.#nestingRules.set(selector, rule);+ this.nestingRules.set(selector, rule);this.#isDirty = true;}return rule;@@ -88,7 +88,13 @@ export class StyleSheet {markAsDirty() {this.#isDirty = true;}- get cssText() {+ generateWith({+ nestingRules,+ transformValue,+ }: {+ nestingRules: NestingRule[];+ transformValue?: TransformValue;+ }) {if (this.#isDirty === false) {return this.#cssText;}@@ -105,8 +111,8 @@ export class StyleSheet {);for (const mediaRule of sortedMediaRules) {const cssText = mediaRule.generateRule({- nestingRules: Array.from(this.#nestingRules.values()),- transformValue: this.#transformValue,+ nestingRules,+ transformValue,});if (cssText !== "") {css.push(cssText);@@ -119,6 +125,12 @@ export class StyleSheet {this.#cssText = css.join("\n");return this.#cssText;}+ get cssText() {+ return this.generateWith({+ nestingRules: Array.from(this.nestingRules.values()),+ transformValue: this.#transformValue,+ });+ }clear() {this.#mediaRules.clear();this.#plainRules.clear();diff --git a/packages/react-sdk/src/css/css.test.ts b/packages/react-sdk/src/css/css.test.tsindex 2c5101c8ed..8bb6237f1f 100644--- a/packages/react-sdk/src/css/css.test.ts+++ b/packages/react-sdk/src/css/css.test.ts@@ -57,8 +57,9 @@ test("generate css for one instance with two tokens", () => {}"`);expect(atomicCssText).toMatchInlineSnapshot(`-"html {margin: 0; display: grid; min-height: 100%}@media all {- .c10nxgm2 {+"html {margin: 0; display: grid; min-height: 100%}+@media all {+ .cawkhls {color: red}}"@@ -66,7 +67,7 @@ test("generate css for one instance with two tokens", () => {expect(classesMap).toMatchInlineSnapshot(`Map {"box" => [- "c10nxgm2",+ "cawkhls",],}`);diff --git a/packages/react-sdk/src/css/css.ts b/packages/react-sdk/src/css/css.tsindex d20bf6af58..3085f8ad8a 100644--- a/packages/react-sdk/src/css/css.ts+++ b/packages/react-sdk/src/css/css.ts@@ -1,18 +1,20 @@import {createRegularStyleSheet,- createAtomicStyleSheet,+ generateAtomic,+ type NestingRule,type TransformValue,} from "@webstudio-is/css-engine";import type {Assets,Breakpoints,+ Instance,StyleSourceSelections,Styles,} from "@webstudio-is/sdk";import type { WsComponentMeta } from "../components/component-meta";import { idAttribute } from "../props";import { addGlobalRules } from "./global-rules";-import { getPresetStyleRules, getStyleRules } from "./style-rules";+import { getPresetStyleRules } from "./style-rules";export type CssConfig = {assets: Assets;@@ -59,17 +61,12 @@ export const generateCss = ({assetBaseUrl,atomic,}: CssConfig) => {- const classesMap = new Map<string, Array<string>>();+ const sheet = createRegularStyleSheet({ name: "ssr" });- const regularSheet = createRegularStyleSheet({ name: "ssr-regular" });- const atomicSheet = atomic- ? createAtomicStyleSheet({ name: "ssr-atomic" })- : undefined;-- addGlobalRules(regularSheet, { assets, assetBaseUrl });+ addGlobalRules(sheet, { assets, assetBaseUrl });for (const breakpoint of breakpoints.values()) {- (atomicSheet ?? regularSheet).addMediaRule(breakpoint.id, breakpoint);+ sheet.addMediaRule(breakpoint.id, breakpoint);}for (const [component, meta] of componentMetas) {@@ -79,39 +76,17 @@ export const generateCss = ({}const rules = getPresetStyleRules(component, presetStyle);for (const [selector, style] of rules) {- regularSheet.addStyleRule({ style }, selector);+ sheet.addStyleRule({ style }, selector);}}- const styleRules = getStyleRules(styles, styleSourceSelections);-const imageValueTransformer = createImageValueTransformer(assets, {assetBaseUrl,});- regularSheet.setTransformer(imageValueTransformer);- atomicSheet?.setTransformer(imageValueTransformer);-- if (atomicSheet) {- for (const { breakpointId, instanceId, state, style } of styleRules) {- const { classes } = atomicSheet.addStyleRule(- { breakpoint: breakpointId, style },- state,- imageValueTransformer- );- classesMap.set(instanceId, [- ...(classesMap.get(instanceId) ?? []),- ...classes,- ]);- }-- return {- cssText: regularSheet.cssText + (atomicSheet?.cssText ?? ""),- classesMap,- };- }+ sheet.setTransformer(imageValueTransformer);for (const styleDecl of styles.values()) {- const rule = regularSheet.addMixinRule(styleDecl.styleSourceId);+ const rule = sheet.addMixinRule(styleDecl.styleSourceId);rule.setDeclaration({breakpoint: styleDecl.breakpointId,selector: styleDecl.state ?? "",@@ -120,15 +95,21 @@ export const generateCss = ({});}+ const instanceByRule = new Map<NestingRule, Instance["id"]>();for (const { instanceId, values } of styleSourceSelections.values()) {- const rule = regularSheet.addNestingRule(- `[${idAttribute}="${instanceId}"]`- );+ const rule = sheet.addNestingRule(`[${idAttribute}="${instanceId}"]`);rule.applyMixins(values);+ instanceByRule.set(rule, instanceId);}+ if (atomic) {+ return generateAtomic(sheet, {+ getKey: (rule) => instanceByRule.get(rule) ?? "",+ transformValue: imageValueTransformer,+ });+ }return {- cssText: regularSheet.cssText,- classesMap,+ cssText: sheet.cssText,+ classesMap: new Map<string, Array<string>>(),};};diff --git a/packages/react-sdk/src/css/global-rules.ts b/packages/react-sdk/src/css/global-rules.tsindex 0984cd065a..1652af2eb5 100644--- a/packages/react-sdk/src/css/global-rules.ts+++ b/packages/react-sdk/src/css/global-rules.ts@@ -1,12 +1,9 @@-import type {- StyleSheetAtomic,- StyleSheetRegular,-} from "@webstudio-is/css-engine";+import type { StyleSheetRegular } from "@webstudio-is/css-engine";import type { Assets, FontAsset } from "@webstudio-is/sdk";import { getFontFaces } from "@webstudio-is/fonts";export const addGlobalRules = (- sheet: StyleSheetRegular | StyleSheetAtomic,+ sheet: StyleSheetRegular,{ assets, assetBaseUrl }: { assets: Assets; assetBaseUrl: string }) => {// @todo we need to figure out all global resets while keepingdiff --git a/packages/react-sdk/src/css/style-rules.ts b/packages/react-sdk/src/css/style-rules.tsindex 2d0d337ad9..34e1cdbd27 100644--- a/packages/react-sdk/src/css/style-rules.ts+++ b/packages/react-sdk/src/css/style-rules.ts@@ -19,6 +19,8 @@ type StyleRule = {/*** Merge styles from different style sources* and group by instance and breakpoint+ *+ * @deprecated*/export const getStyleRules = (styles: Styles,