Skip to content

Commit

Permalink
minify and support calc css
Browse files Browse the repository at this point in the history
  • Loading branch information
hunghg255 committed May 16, 2023
1 parent fbdf61e commit 07ee8df
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 7,147 deletions.
3,578 changes: 1 addition & 3,577 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

3,554 changes: 1 addition & 3,553 deletions dist/index.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.mjs.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "css2tailwind",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand All @@ -10,7 +10,7 @@
],
"scripts": {
"build": "tsup --dts",
"test": "tsc ./test/test.ts"
"test": "node ./test/test.mjs"
},
"author": "hunghg255",
"devDependencies": {
Expand Down
14 changes: 11 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ const isColor = (str: string, joinLinearGradient = false) => {
}

const isUnit = (str: string) => {
if (str.includes('calc')) return true;

return [
'em', 'ex', 'ch', 'rem', 'vw', 'vh', 'vmin', 'vmax',
'cm', 'mm', 'in', 'pt', 'pc', 'px', 'min-content', 'max-content', 'fit-content',
Expand Down Expand Up @@ -2191,11 +2193,14 @@ const getResultCode = (it: CssCodeParse, prefix = '', config: TranslatorConfig)
val = val.replace('!important', '').trim()
hasImportant = true
}
let pipeVal = ''
let pipeVal = '';

if (val.includes('calc')) val = val.replace(/\s/g, '_')

if (val === 'initial' || val === 'inherit') {
pipeVal = `[${key.trim()}:${val}]`
} else {
config.customTheme = config.customTheme ?? {}
config.customTheme = config.customTheme ?? {};
pipeVal = typeof pipe === 'function'
? (config.customTheme[key.trim()]?.[val] || (config.useAllDefaultValues && moreDefaultValuesMap[key.trim()]?.[val]) || pipe(val))
: (config.customTheme[key.trim()]?.[val] || (config.useAllDefaultValues && moreDefaultValuesMap[key.trim()]?.[val]) || (pipe?.[val] ?? ''))
Expand Down Expand Up @@ -2257,7 +2262,9 @@ const getResultCode = (it: CssCodeParse, prefix = '', config: TranslatorConfig)
}
}
return pipeVal
}).filter(v => v !== '')
}).filter(v => v !== '');


return {
selectorName: it.selectorName,
resultVal: [...new Set(resultVals)].join(' ')
Expand All @@ -2284,6 +2291,7 @@ const CssToTailwind = (code: string, config: TranslatorConfig = defaultTranslato
customTheme = config.customTheme ?? defaultTranslatorConfig.customTheme
const dataArray: ResultCode[] = []
parsingCode(code).map(it => {

if (typeof it.cssCode === 'string') {
return getResultCode(it, '', config)
} else if (it.selectorName.includes('@media')) {
Expand Down
6 changes: 0 additions & 6 deletions test/test.js

This file was deleted.

7 changes: 4 additions & 3 deletions test/test.ts → test/test.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { CssToTailwind } from 'css2tailwind';
import { CssToTailwind } from '../dist/index.mjs';

const cssCode = `body {
width: 100%;
height: 50%;
height: calc(100vh - 50%);
top: calc(100vh - 50%);
margin-top: calc(100vh - 50%);
margin: 0 !important;
/* asd */
background-color: transparent;
}`;

Expand Down
3 changes: 2 additions & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export default defineConfig({
splitting: false,
sourcemap: true,
clean: true,
format: ['esm', 'cjs']
format: ['esm', 'cjs'],
minify: true
})

0 comments on commit 07ee8df

Please sign in to comment.