@daldalso/tailwind-base
Advanced tools
Comparing version 0.9.1-2 to 0.9.1-3
#!/usr/bin/env node | ||
import { existsSync, readdirSync, readFileSync, writeFileSync } from "fs"; | ||
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "fs"; | ||
import { resolve } from "path"; | ||
@@ -12,3 +12,3 @@ import loadConfig from "tailwindcss/lib/lib/load-config.js"; | ||
tailwindConfigPath: "", | ||
outputPath: "" | ||
outputDirectory: "" | ||
}; | ||
@@ -121,2 +121,3 @@ async function main() { | ||
'const pluginUtils = require("tailwindcss/lib/util/pluginUtils.js");', | ||
'import { loadTailwindBase } from "@daldalso/tailwind-base";', | ||
"", | ||
@@ -126,3 +127,3 @@ "const d = (type:string)=>[(value:string)=>Boolean(pluginUtils.typeMap[type](value))];", | ||
"", | ||
"export default {", | ||
"export const tailwindBaseConfig = {", | ||
" cacheSize: 0,", | ||
@@ -135,6 +136,16 @@ " classGroups: [", | ||
` separator: ${JSON.stringify(tailwindConfig.separator || "-")}`, | ||
'} as import("@daldalso/tailwind-base/lib").TailwindBaseConfig;' | ||
'} as import("@daldalso/tailwind-base/lib").TailwindBaseConfig;', | ||
"loadTailwindBase(tailwindBaseConfig);", | ||
'import "./client";' | ||
].join('\n'); | ||
writeFileSync(context.outputPath, R); | ||
logger.success(`Generated ${context.outputPath}`)['Size'](R.length); | ||
writeFileSync(resolve(context.outputDirectory, "index.ts"), R); | ||
writeFileSync(resolve(context.outputDirectory, "client.ts"), [ | ||
`// Auto-generated by ${context.package['name']}`, | ||
"/* eslint-disable */", | ||
'"use client";', | ||
'import { loadTailwindBase } from "@daldalso/tailwind-base";', | ||
'import { tailwindBaseConfig } from ".";', | ||
"loadTailwindBase(tailwindBaseConfig);" | ||
].join('\n')); | ||
logger.success("Generated!")['Size'](R.length); | ||
} | ||
@@ -158,3 +169,6 @@ main(); | ||
context.tailwindConfigPath = resolve(cwd, tailwindConfigPath); | ||
context.outputPath = existsSync(resolve(cwd, "src")) ? resolve(cwd, "src/tailwind-base.ts") : resolve(cwd, "tailwind-base.ts"); | ||
context.outputDirectory = existsSync(resolve(cwd, "src")) ? resolve(cwd, "src/tailwind-base") : resolve(cwd, "tailwind-base"); | ||
if (existsSync(context.outputDirectory)) | ||
return; | ||
mkdirSync(context.outputDirectory); | ||
} |
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; |
@@ -1,8 +0,11 @@ | ||
import TailwindBase from "./lib/index.js"; | ||
let tailwindBase; | ||
import TailwindBase, { ghostSymbol } from "./lib/index.js"; | ||
export function loadTailwindBase(config, cacheEnabled) { | ||
return tailwindBase = new TailwindBase(config, cacheEnabled); | ||
globalThis.tailwindBase = new TailwindBase(config, cacheEnabled); | ||
return globalThis.tailwindBase; | ||
} | ||
export default function c(...args) { | ||
return tailwindBase.merge(...args); | ||
if (!globalThis.tailwindBase) { | ||
return Object.assign('(error)', { [ghostSymbol]: args }); | ||
} | ||
return globalThis.tailwindBase.merge(...args); | ||
} |
@@ -7,2 +7,3 @@ import type { CValue } from "../../react.js"; | ||
type CandidateDescriptor = string[] | Array<(value: string) => boolean>; | ||
export declare const ghostSymbol: unique symbol; | ||
export default class TailwindBase { | ||
@@ -9,0 +10,0 @@ private readonly config; |
const dynamicValuePattern = /^(.+)-(\[.+])$/; | ||
export const ghostSymbol = Symbol("ghost"); | ||
export default class TailwindBase { | ||
@@ -82,2 +83,4 @@ config; | ||
R += concat(v); | ||
else if (ghostSymbol in v) | ||
R += ` ${concat([v[ghostSymbol]])}`; | ||
else | ||
@@ -84,0 +87,0 @@ for (const l in v) { |
import c from "./index.js"; | ||
export default function wrapJSX(Target) { | ||
return (type, props, ...rest) => { | ||
if (typeof type === "string" && props?.['c']) { | ||
if (typeof type === "string" && props) { | ||
props['className'] = c(props['className'], props['c']); | ||
@@ -6,0 +6,0 @@ delete props['c']; |
{ | ||
"type": "module", | ||
"name": "@daldalso/tailwind-base", | ||
"version": "0.9.1-2", | ||
"version": "0.9.1-3", | ||
"description": "Let you exploit Tailwind in React more powerful", | ||
@@ -54,5 +54,7 @@ "repository": { | ||
"@daldalso/logger": "^0.9.3-0", | ||
"react": "^18", | ||
"tailwindcss": "^3.4.10" | ||
}, | ||
"peerDependencies": { | ||
"react": "^18" | ||
} | ||
} |
@@ -8,3 +8,3 @@ # tailwind-base | ||
2. `npx tailwind-base globals.css` (You should replace `globals.css` with the path of a proper Tailwind CSS file which contains something like `@tailwind base;`.) | ||
3. In the end of your root component file, call `loadTailwindBase` with the tailwind-base config object generated by the previous command. | ||
3. Import the generated TypeScript file in your root component like `import "(my-src-path)/tailwind-base";`. | ||
4. Update your Tailwind config file like below: | ||
@@ -11,0 +11,0 @@ ```js |
22024
26
431
- Removedreact@^18