@daldalso/tailwind-base
Advanced tools
Comparing version 0.9.1-5 to 0.9.2-0
@@ -123,2 +123,3 @@ #!/usr/bin/env node | ||
'import ClientTailwindBaseInitializer from "./client";', | ||
'import tailwindBaseConfigOverride from "./config";', | ||
"", | ||
@@ -135,3 +136,4 @@ "const d = (type:string)=>[(value:string)=>Boolean(pluginUtils.typeMap[type](value))];", | ||
" conflictingClassGroupModifiers: {},", | ||
` separator: ${JSON.stringify(tailwindConfig.separator || "-")}`, | ||
` separator: ${JSON.stringify(tailwindConfig.separator || "-")},`, | ||
" ...tailwindBaseConfigOverride", | ||
'} as import("@daldalso/tailwind-base/lib").TailwindBaseConfig;', | ||
@@ -154,2 +156,11 @@ "loadTailwindBase(tailwindBaseConfig);", | ||
].join('\n')); | ||
const configPath = resolve(context.outputDirectory, "config.ts"); | ||
if (!existsSync(configPath)) | ||
writeFileSync(configPath, [ | ||
`// Auto-generated by ${context.package['name']}`, | ||
'import type { TailwindBaseConfig } from "@daldalso/tailwind-base/lib";', | ||
"export default {", | ||
" postprocessors: []", | ||
'} as Partial<TailwindBaseConfig>;' | ||
].join('\n')); | ||
logger.success("Generated!")['Size'](R.length); | ||
@@ -156,0 +167,0 @@ } |
import type { CValue } from "../react.js"; | ||
import type { TailwindBaseConfig } from "./lib/index.js"; | ||
import TailwindBase from "./lib/index.js"; | ||
declare global { | ||
var tailwindBase: TailwindBase; | ||
} | ||
export declare function loadTailwindBase(config: TailwindBaseConfig, cacheEnabled?: boolean): TailwindBase; | ||
export default function c(...args: CValue[]): string; |
import TailwindBase, { ghostSymbol } from "./lib/index.js"; | ||
let tailwindBase; | ||
export function loadTailwindBase(config, cacheEnabled) { | ||
globalThis.tailwindBase = new TailwindBase(config, cacheEnabled); | ||
return globalThis.tailwindBase; | ||
tailwindBase = new TailwindBase(config, cacheEnabled); | ||
return tailwindBase; | ||
} | ||
export default function c(...args) { | ||
if (!globalThis.tailwindBase) { | ||
if (!tailwindBase) { | ||
return Object.assign('(error)', { [ghostSymbol]: args }); | ||
} | ||
return globalThis.tailwindBase.merge(...args); | ||
return tailwindBase.merge(...args); | ||
} |
import type { CValue } from "../../react.js"; | ||
export type TailwindBaseConfig = { | ||
'classGroups': GroupDescriptor[]; | ||
'postprocessors'?: Array<(value: string) => string | void>; | ||
}; | ||
@@ -5,0 +6,0 @@ type GroupDescriptor = Array<string | Record<string, CandidateDescriptor>>; |
@@ -9,3 +9,6 @@ const dynamicValuePattern = /^(.+)-(\[.+])$/; | ||
constructor(config, cacheEnabled = false) { | ||
this.config = config; | ||
this.config = { | ||
classGroups: config.classGroups, | ||
postprocessors: config.postprocessors || [] | ||
}; | ||
this.chunkCache = {}; | ||
@@ -38,2 +41,6 @@ this.indexCache = {}; | ||
R = classes.join(' '); | ||
if (R) | ||
for (const v of this.config.postprocessors) { | ||
R = v(R) || R; | ||
} | ||
if (this.cacheEnabled) | ||
@@ -40,0 +47,0 @@ this.chunkCache[chunk] = R; |
@@ -1,1 +0,1 @@ | ||
export default function tailwindBaseTransformer(content: string): string; | ||
export default function buildTailwindBaseTransformer(postprocessors?: Array<(value: string) => string | void>): (content: string) => string; |
@@ -6,6 +6,6 @@ const pattern = /{(?=[^{]*?:[\S\s]+?["'][\S\s]+?})\s*([^}]+?)\s*}/g; | ||
const valueSpacePattern = /\s+/; | ||
export default function tailwindBaseTransformer(content) { | ||
return content.replace(pattern, (_, g1) => { | ||
export default function buildTailwindBaseTransformer(postprocessors = []) { | ||
return (content) => content.replace(pattern, (_, g1) => { | ||
let R = ""; | ||
for (const [, , complexKey, simpleKey, value] of g1.matchAll(g1Pattern)) { | ||
for (const [, , quotedKey, unquotedKey, value] of g1.matchAll(g1Pattern)) { | ||
if (functionCallPattern.test(value)) { | ||
@@ -18,8 +18,13 @@ // Not to transform `{ myClass: c("font-bold") }` | ||
for (const x of w[2].split(valueSpacePattern)) { | ||
R += `${complexKey || simpleKey}:${x} `; | ||
const key = quotedKey || unquotedKey; | ||
R += `${key}:${x} `; | ||
} | ||
} | ||
} | ||
if (R) | ||
for (const v of postprocessors) { | ||
R = v(R) || R; | ||
} | ||
return R ? `"${R}"` : _; | ||
}); | ||
} |
{ | ||
"type": "module", | ||
"name": "@daldalso/tailwind-base", | ||
"version": "0.9.1-5", | ||
"version": "0.9.2-0", | ||
"description": "Let you exploit Tailwind in React more powerful", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -11,3 +11,3 @@ # tailwind-base | ||
```js | ||
import tailwindBaseTransformer from "@daldalso/tailwind-base/transformer"; | ||
import buildTailwindBaseTransformer from "@daldalso/tailwind-base/transformer"; | ||
@@ -20,3 +20,3 @@ export default { | ||
], | ||
transform: tailwindBaseTransformer | ||
transform: buildTailwindBaseTransformer() | ||
} | ||
@@ -23,0 +23,0 @@ }; |
22514
22
428