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
fix: Resolve longhand-to-shorthand expansion in Tailwind conversion (#2411)
Ivan Starkovd2528d707f3f
diff --git a/packages/css-data/src/tailwind-parser/shorthand.test.ts b/packages/css-data/src/tailwind-parser/shorthand.test.tsindex afd1fca85d..7d8782ab2d 100644--- a/packages/css-data/src/tailwind-parser/shorthand.test.ts+++ b/packages/css-data/src/tailwind-parser/shorthand.test.ts@@ -6,6 +6,10 @@ describe("expandTailwindShorthand", () => {expect(expandTailwindShorthand("mx-4")).toBe("mr-4 ml-4");});+ test("do not expand mb-4", () => {+ expect(expandTailwindShorthand("mb-4")).toBe("mb-4");+ });+test("expand flex-initial to grow-0 shrink basis-auto", () => {expect(expandTailwindShorthand("flex-initial")).toBe("grow-0 shrink basis-auto"@@ -41,4 +45,18 @@ describe("expandTailwindShorthand", () => {"border-t border-r border-b border-l border-t-sky-500 border-r-sky-500 border-b-sky-500 border-l-sky-500");});++ test("expand rounded-lg", () => {+ expect(expandTailwindShorthand("rounded-lg")).toBe(+ "rounded-tl-lg rounded-tr-lg rounded-br-lg rounded-bl-lg"+ );+ });++ test("do not expand rounded-tl-lg", () => {+ expect(expandTailwindShorthand("rounded-tl-lg")).toBe("rounded-tl-lg");+ });++ test("do not expand border-r", () => {+ expect(expandTailwindShorthand("border-r")).toBe("border-r");+ });});diff --git a/packages/css-data/src/tailwind-parser/shorthand.ts b/packages/css-data/src/tailwind-parser/shorthand.tsindex 7a1bef1980..a77a32d63e 100644--- a/packages/css-data/src/tailwind-parser/shorthand.ts+++ b/packages/css-data/src/tailwind-parser/shorthand.ts@@ -9,9 +9,10 @@ export const expandTailwindShorthand = (classnames: string) => {.trim().split(/\s+/).map((classname) => {- const groupKey = Object.keys(conflictingClassGroups).find((key) =>- classname.startsWith(key)+ const groupKey = Object.keys(conflictingClassGroups).find(+ (key) => classname.startsWith(`${key}-`) || classname === key);+if (groupKey === undefined) {return classname;}@@ -71,10 +72,19 @@ const conflictingClassGroups: Record<string, string[]> = orderByKeysDesc({"rounded-b": ["rounded-br", "rounded-bl"],"rounded-l": ["rounded-tl", "rounded-bl"],+ "rounded-tl": ["rounded-tl"],+ "rounded-tr": ["rounded-tr"],+ "rounded-br": ["rounded-br"],+ "rounded-bl": ["rounded-bl"],+"border-spacing": ["border-spacing-x", "border-spacing-y"],"border-x": ["border-r", "border-l"],"border-y": ["border-t", "border-b"],+ "border-r": ["border-r"],+ "border-l": ["border-l"],+ "border-b": ["border-b"],+ "border-t": ["border-t"],border: ["border-t", "border-r", "border-b", "border-l"],});