From 0356c893b729d8e8ae1a9bf41f18828a1389d516 Mon Sep 17 00:00:00 2001 From: sibbng Date: Sat, 17 Apr 2021 15:59:33 +0300 Subject: [PATCH 1/3] fix: properly handle arbitrary var names with dashed digits --- src/__tests__/api.json | 2 ++ src/twind/theme.ts | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/__tests__/api.json b/src/__tests__/api.json index 2457e1340..c6eb4c1c0 100644 --- a/src/__tests__/api.json +++ b/src/__tests__/api.json @@ -852,11 +852,13 @@ "grid-cols-[repeat(auto-fit,minmax(150px,1fr))]": ".grid-cols-\\[repeat\\(auto-fit\\,minmax\\(150px\\,1fr\\)\\)\\]{grid-template-columns:repeat(auto-fit,minmax(150px,1fr))}", "w-[clamp(23ch,50%,46ch)]": ".w-\\[clamp\\(23ch\\,50\\%\\,46ch\\)\\]{width:clamp(23ch,50%,46ch)}", "w-[calc(var(--width-10px,calc(-20px-(-30px--40px)))-50px)]": ".w-\\[calc\\(var\\(--width-10px\\,calc\\(-20px-\\(-30px--40px\\)\\)\\)-50px\\)\\]{width:calc(var(--width-10px,calc(-20px - (-30px - -40px))) - 50px)}", + "w-[calc(var(--10-10px,calc(-20px-(-30px--40px)))-50px)]": ".w-\\[calc\\(var\\(--10-10px\\,calc\\(-20px-\\(-30px--40px\\)\\)\\)-50px\\)\\]{width:calc(var(--10-10px,calc(-20px - (-30px - -40px))) - 50px)}", "w-[calc(1rem+((1vw-7.68px)*0.6944))]": ".w-\\[calc\\(1rem\\+\\(\\(1vw-7\\.68px\\)\\*0\\.6944\\)\\)\\]{width:calc(1rem + ((1vw - 7.68px) * 0.6944))}", "w-[calc(100%-80px)]": ".w-\\[calc\\(100\\%-80px\\)\\]{width:calc(100% - 80px)}", "w-[calc(var(--width-10px,calc(-2px-(-30px--40px)))-50px)]": ".w-\\[calc\\(var\\(--width-10px\\,calc\\(-2px-\\(-30px--40px\\)\\)\\)-50px\\)\\]{width:calc(var(--width-10px,calc(-2px - (-30px - -40px))) - 50px)}", "w-[calc(var(--top,calc(10px+10vh))-1rem)]": ".w-\\[calc\\(var\\(--top\\,calc\\(10px\\+10vh\\)\\)-1rem\\)\\]{width:calc(var(--top,calc(10px + 10vh)) - 1rem)}", "w-[calc(var(--variable-width)+20px)]": ".w-\\[calc\\(var\\(--variable-width\\)\\+20px\\)\\]{width:calc(var(--variable-width) + 20px)}", + "w-[calc(var(--10-10px)+20px)]": ".w-\\[calc\\(var\\(--10-10px\\)\\+20px\\)\\]{width:calc(var(--10-10px) + 20px)}", "w-[calc(5*2em)]": ".w-\\[calc\\(5\\*2em\\)\\]{width:calc(5 * 2em)}", "w-[calc(100%-30px)]": ".w-\\[calc\\(100\\%-30px\\)\\]{width:calc(100% - 30px)}", "w-[calc(10px+100px)]": ".w-\\[calc\\(10px\\+100px\\)\\]{width:calc(10px + 100px)}", diff --git a/src/twind/theme.ts b/src/twind/theme.ts index f367ca70e..ec99d555b 100644 --- a/src/twind/theme.ts +++ b/src/twind/theme.ts @@ -916,7 +916,9 @@ const resolveContext: ThemeSectionResolverContext = { const handleArbitraryValues = (section: keyof Theme, key: string): string | false => (key = (key[0] == '[' && key.slice(-1) == ']' && key.slice(1, -1)) as string) && includes(section, 'olor') == /^(#|(hsl|rgb)a?\(|[a-z]+$)/.test(key) && - (includes(key, 'calc(') ? key.replace(/(-?\d*\.?\d(?:%|[a-z]+)?|\))([+\-/*])/g, '$1 $2 ') : key) + (includes(key, 'calc(') + ? key.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*]))(?:%|[a-z]+)?|\))([+\-/*])/g, '$1 $2 ') + : key) export const makeThemeResolver = (config?: ThemeConfiguration): ThemeResolver => { const cache = new Map>() From 02756d6d8d7c7b94bc6931530c37f15faa65df8a Mon Sep 17 00:00:00 2001 From: sibbng Date: Sun, 18 Apr 2021 17:19:29 +0300 Subject: [PATCH 2/3] fix regex --- src/twind/theme.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/twind/theme.ts b/src/twind/theme.ts index ec99d555b..795e313f3 100644 --- a/src/twind/theme.ts +++ b/src/twind/theme.ts @@ -917,7 +917,7 @@ const handleArbitraryValues = (section: keyof Theme, key: string): string | fals (key = (key[0] == '[' && key.slice(-1) == ']' && key.slice(1, -1)) as string) && includes(section, 'olor') == /^(#|(hsl|rgb)a?\(|[a-z]+$)/.test(key) && (includes(key, 'calc(') - ? key.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*]))(?:%|[a-z]+)?|\))([+\-/*])/g, '$1 $2 ') + ? key.replace(/(-?\d*\.?\d(?!\b-.+[,)](?![^+\-/*])\D)(?:%|[a-z]+)?|\))([+\-/*])/g, '$1 $2 ') : key) export const makeThemeResolver = (config?: ThemeConfiguration): ThemeResolver => { From 4f69c7e7b7df67b73f31ebc5934e92f951e92a16 Mon Sep 17 00:00:00 2001 From: sibbng Date: Tue, 20 Apr 2021 19:22:02 +0300 Subject: [PATCH 3/3] fix: increase size limit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 94b017a3a..25520a059 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "name": "twind", "path": "dist/twind.js", "brotli": true, - "limit": "12kb" + "limit": "12.1kb" }, { "name": "twind/colors",