@dmisdm/pandatail 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -9
- package/dist/cli.js +128 -47
- package/dist/extract.d.ts +2 -0
- package/dist/index.js +60 -44
- package/dist/preset.d.ts +1 -1
- package/dist/project.d.ts +7 -0
- package/dist/scanCss.d.ts +1 -1
- package/dist/studio.d.ts +8 -0
- package/dist/studio.js +580 -0
- package/dist/vite.js +60 -44
- package/package.json +6 -4
package/dist/vite.js
CHANGED
|
@@ -7,7 +7,7 @@ import { bundleConfig, createConfigSnapshot, mergeConfigs } from "@pandacss/conf
|
|
|
7
7
|
import { createCompilerFromSnapshot } from "@pandacss/compiler";
|
|
8
8
|
import { applyConfigDefaults, formatDiagnostic } from "@pandacss/compiler-shared";
|
|
9
9
|
import presetBase from "@pandacss/preset-base";
|
|
10
|
-
import { createRequire
|
|
10
|
+
import { createRequire } from "node:module";
|
|
11
11
|
import { existsSync as existsSync2, statSync } from "node:fs";
|
|
12
12
|
import { relative, resolve as resolve4 } from "node:path";
|
|
13
13
|
|
|
@@ -17,11 +17,9 @@ import { readFile as readFile2 } from "node:fs/promises";
|
|
|
17
17
|
import { dirname as dirname3, resolve as resolve3 } from "node:path";
|
|
18
18
|
|
|
19
19
|
// src/extract.ts
|
|
20
|
-
import { __unstable__loadDesignSystem } from "tailwindcss";
|
|
20
|
+
import { __unstable__loadDesignSystem } from "@tailwindcss/node";
|
|
21
21
|
import { readFile } from "node:fs/promises";
|
|
22
|
-
import { createRequire } from "node:module";
|
|
23
22
|
import { dirname, resolve } from "node:path";
|
|
24
|
-
import { pathToFileURL } from "node:url";
|
|
25
23
|
|
|
26
24
|
// src/namespaces.ts
|
|
27
25
|
var TAILWIND_NAMESPACES = [
|
|
@@ -161,37 +159,18 @@ function pushNamed(out) {
|
|
|
161
159
|
}
|
|
162
160
|
|
|
163
161
|
// src/extract.ts
|
|
164
|
-
var requireFromHere = createRequire(`${process.cwd()}/__pandatail_anchor__`);
|
|
165
|
-
function resolveStylesheet(id, basedir) {
|
|
166
|
-
if (id.startsWith(".") || id.startsWith("/")) {
|
|
167
|
-
return resolve(basedir, id);
|
|
168
|
-
}
|
|
169
|
-
const candidates = [`${id}/index.css`, `${id}.css`, id];
|
|
170
|
-
for (const candidate of candidates) {
|
|
171
|
-
try {
|
|
172
|
-
return requireFromHere.resolve(candidate, { paths: [basedir] });
|
|
173
|
-
} catch {}
|
|
174
|
-
}
|
|
175
|
-
throw new Error(`pandatail: cannot resolve stylesheet '${id}' from ${basedir}`);
|
|
176
|
-
}
|
|
177
162
|
async function extractTokens(opts) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const content = await readFile(path, "utf8");
|
|
184
|
-
return { path, base: dirname(path), content };
|
|
185
|
-
},
|
|
186
|
-
loadModule: async (id, basedir) => {
|
|
187
|
-
const path = resolveStylesheet(id, basedir);
|
|
188
|
-
const mod = await import(pathToFileURL(path).href);
|
|
189
|
-
return { path, base: dirname(path), module: mod.default ?? mod };
|
|
190
|
-
}
|
|
191
|
-
});
|
|
163
|
+
return tokensFromTheme(await loadThemeEntries(opts));
|
|
164
|
+
}
|
|
165
|
+
async function loadThemeEntries(opts) {
|
|
166
|
+
const base = resolve(opts.base ?? process.cwd());
|
|
167
|
+
const ds = await __unstable__loadDesignSystem(opts.css, { base });
|
|
192
168
|
const themeEntries = new Map;
|
|
193
169
|
for (const [key, entry] of ds.theme.entries())
|
|
194
170
|
themeEntries.set(key, entry.value);
|
|
171
|
+
return themeEntries;
|
|
172
|
+
}
|
|
173
|
+
function tokensFromTheme(themeEntries) {
|
|
195
174
|
const out = [];
|
|
196
175
|
for (const [key, rawValue] of themeEntries) {
|
|
197
176
|
const matched = matchNamespace(key);
|
|
@@ -218,7 +197,7 @@ async function extractTokensFromFile(path) {
|
|
|
218
197
|
import postcss from "postcss";
|
|
219
198
|
import { existsSync, readFileSync } from "node:fs";
|
|
220
199
|
import { dirname as dirname2, resolve as resolve2 } from "node:path";
|
|
221
|
-
function scanCss(opts) {
|
|
200
|
+
function scanCss(opts, rootVariables) {
|
|
222
201
|
const out = {
|
|
223
202
|
sources: [],
|
|
224
203
|
excludes: [],
|
|
@@ -226,10 +205,10 @@ function scanCss(opts) {
|
|
|
226
205
|
warnings: [],
|
|
227
206
|
files: opts.file ? [opts.file] : []
|
|
228
207
|
};
|
|
229
|
-
walk(opts.css, opts.base, out, new Set(opts.file ? [opts.file] : []));
|
|
208
|
+
walk(opts.css, opts.base, out, new Set(opts.file ? [opts.file] : []), rootVariables);
|
|
230
209
|
return out;
|
|
231
210
|
}
|
|
232
|
-
function walk(css, base, out, seen) {
|
|
211
|
+
function walk(css, base, out, seen, rootVariables) {
|
|
233
212
|
let root;
|
|
234
213
|
try {
|
|
235
214
|
root = postcss.parse(css);
|
|
@@ -237,7 +216,11 @@ function walk(css, base, out, seen) {
|
|
|
237
216
|
out.warnings.push(`could not parse CSS in ${base}: ${e.message}`);
|
|
238
217
|
return;
|
|
239
218
|
}
|
|
240
|
-
root.
|
|
219
|
+
root.walk((rule) => {
|
|
220
|
+
if (rule.type === "rule" && rootVariables)
|
|
221
|
+
collectRootVariables(rule, rootVariables);
|
|
222
|
+
if (rule.type !== "atrule")
|
|
223
|
+
return;
|
|
241
224
|
switch (rule.name) {
|
|
242
225
|
case "import": {
|
|
243
226
|
const id = quoted(rule.params) ?? urlTarget(rule.params);
|
|
@@ -248,7 +231,7 @@ function walk(css, base, out, seen) {
|
|
|
248
231
|
return;
|
|
249
232
|
seen.add(path);
|
|
250
233
|
out.files.push(path);
|
|
251
|
-
walk(readFileSync(path, "utf8"), dirname2(path), out, seen);
|
|
234
|
+
walk(readFileSync(path, "utf8"), dirname2(path), out, seen, rootVariables);
|
|
252
235
|
return;
|
|
253
236
|
}
|
|
254
237
|
case "source":
|
|
@@ -258,6 +241,17 @@ function walk(css, base, out, seen) {
|
|
|
258
241
|
}
|
|
259
242
|
});
|
|
260
243
|
}
|
|
244
|
+
function collectRootVariables(rule, variables) {
|
|
245
|
+
let parent = rule.parent;
|
|
246
|
+
while (parent?.type === "atrule" && parent.name === "layer")
|
|
247
|
+
parent = parent.parent;
|
|
248
|
+
if (parent?.type !== "root" || !rule.selectors.includes(":root"))
|
|
249
|
+
return;
|
|
250
|
+
for (const node of rule.nodes) {
|
|
251
|
+
if (node.type === "decl" && node.prop.startsWith("--"))
|
|
252
|
+
variables.set(node.prop, node.value);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
261
255
|
function handleSource(rule, base, out) {
|
|
262
256
|
const params = rule.params.trim();
|
|
263
257
|
if (params.startsWith("inline(") || params.startsWith("not inline(")) {
|
|
@@ -307,7 +301,7 @@ function urlTarget(params) {
|
|
|
307
301
|
}
|
|
308
302
|
|
|
309
303
|
// src/preset.ts
|
|
310
|
-
async function loadTailwind(opts) {
|
|
304
|
+
async function loadTailwind(opts, preview = false) {
|
|
311
305
|
let css;
|
|
312
306
|
let base;
|
|
313
307
|
let file;
|
|
@@ -321,13 +315,32 @@ async function loadTailwind(opts) {
|
|
|
321
315
|
} else {
|
|
322
316
|
throw new Error("pandatail: provide either `css` or `cssPath`");
|
|
323
317
|
}
|
|
324
|
-
const
|
|
325
|
-
const
|
|
326
|
-
|
|
318
|
+
const theme = await loadThemeEntries({ css, base });
|
|
319
|
+
const tokens = tokensFromTheme(theme);
|
|
320
|
+
const variables = preview ? new Map(theme) : undefined;
|
|
321
|
+
const scan = scanCss({ css, base, file }, variables);
|
|
322
|
+
const presetTokens = variables ? tokens.map((token) => ({
|
|
323
|
+
...token,
|
|
324
|
+
value: resolvePreviewValue(token.value, variables)
|
|
325
|
+
})) : tokens;
|
|
326
|
+
return { preset: buildPreset(presetTokens, scan), scan, tokens };
|
|
327
327
|
}
|
|
328
328
|
async function tailwindPreset(opts) {
|
|
329
329
|
return (await loadTailwind(opts)).preset;
|
|
330
330
|
}
|
|
331
|
+
function resolvePreviewValue(value, variables, resolving = new Set) {
|
|
332
|
+
return value.replace(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|(?<![\w-])var\(\s*(--[\w-]+)\s*\)/gi, (match, name) => {
|
|
333
|
+
if (name === undefined || resolving.has(name))
|
|
334
|
+
return match;
|
|
335
|
+
const definition = variables.get(name);
|
|
336
|
+
if (definition === undefined)
|
|
337
|
+
return match;
|
|
338
|
+
resolving.add(name);
|
|
339
|
+
const resolved = resolvePreviewValue(definition, variables, resolving);
|
|
340
|
+
resolving.delete(name);
|
|
341
|
+
return resolved;
|
|
342
|
+
});
|
|
343
|
+
}
|
|
331
344
|
function buildPreset(tokens, scan) {
|
|
332
345
|
const breakpoints = {};
|
|
333
346
|
const tokenTokens = [];
|
|
@@ -393,11 +406,16 @@ function buildTree(tokens, category) {
|
|
|
393
406
|
// src/project.ts
|
|
394
407
|
var DEFAULT_EXT = "{js,jsx,ts,tsx,mdx}";
|
|
395
408
|
async function createPandatailProject(opts) {
|
|
409
|
+
const project = await resolvePandatailConfig(opts);
|
|
410
|
+
const compiler = createCompilerFromSnapshot(createConfigSnapshot(project.config));
|
|
411
|
+
return { compiler, ...project };
|
|
412
|
+
}
|
|
413
|
+
async function resolvePandatailConfig(opts, preview = false) {
|
|
396
414
|
const cwd = resolve4(opts.cwd ?? process.cwd());
|
|
397
415
|
const cssPath = resolve4(cwd, opts.css);
|
|
398
416
|
if (!existsSync2(cssPath))
|
|
399
417
|
throw new Error(`pandatail: CSS entry not found: ${cssPath}`);
|
|
400
|
-
const tw = await loadTailwind({ cssPath });
|
|
418
|
+
const tw = await loadTailwind({ cssPath }, preview);
|
|
401
419
|
const dependencies = [...tw.scan.files];
|
|
402
420
|
let user = {};
|
|
403
421
|
if (typeof opts.config === "string") {
|
|
@@ -448,9 +466,7 @@ async function createPandatailProject(opts) {
|
|
|
448
466
|
finalOverrides
|
|
449
467
|
]);
|
|
450
468
|
const config = applyConfigDefaults(merged, cwd);
|
|
451
|
-
const compiler = createCompilerFromSnapshot(createConfigSnapshot(config));
|
|
452
469
|
return {
|
|
453
|
-
compiler,
|
|
454
470
|
config,
|
|
455
471
|
cwd,
|
|
456
472
|
outdir: resolve4(cwd, config.outdir ?? "styled-system"),
|
|
@@ -495,7 +511,7 @@ async function loadPreset(entry, cwd) {
|
|
|
495
511
|
const value = await entry;
|
|
496
512
|
if (typeof value !== "string")
|
|
497
513
|
return value;
|
|
498
|
-
const req =
|
|
514
|
+
const req = createRequire(resolve4(cwd, "__pandatail_anchor__"));
|
|
499
515
|
let mod;
|
|
500
516
|
try {
|
|
501
517
|
mod = await import(req.resolve(value));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dmisdm/pandatail",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Run PandaCSS from a Tailwind v4 stylesheet. Your @theme becomes typed Panda style props, with no panda.config.ts required.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
],
|
|
41
41
|
"scripts": {
|
|
42
42
|
"build": "bun run clean && bun run build:js && bun run build:types",
|
|
43
|
-
"build:js": "bun build src/index.ts src/cli.ts src/vite.ts --outdir dist --target node --format esm --external \"@pandacss/*\" --external tailwindcss --external postcss --external vite",
|
|
43
|
+
"build:js": "bun build src/index.ts src/cli.ts src/vite.ts src/studio.ts --outdir dist --target node --format esm --external \"@pandacss/*\" --external @tailwindcss/node --external postcss --external vite",
|
|
44
44
|
"build:types": "tsc --project tsconfig.build.json",
|
|
45
45
|
"clean": "rm -rf dist",
|
|
46
46
|
"test": "bun test",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"@pandacss/compiler": "^2.0.0",
|
|
52
52
|
"@pandacss/config": "^2.0.0",
|
|
53
53
|
"@pandacss/preset-base": "^2.0.0",
|
|
54
|
+
"@tailwindcss/node": "^4.0.0",
|
|
54
55
|
"tailwindcss": "^4.0.0",
|
|
55
56
|
"@pandacss/compiler-shared": "^2.0.0",
|
|
56
57
|
"vite": ">=5.0.0"
|
|
@@ -64,15 +65,16 @@
|
|
|
64
65
|
"@pandacss/config": "^2.6.0",
|
|
65
66
|
"@pandacss/dev": "^2.6.0",
|
|
66
67
|
"@pandacss/preset-base": "^2.6.0",
|
|
68
|
+
"@tailwindcss/node": "4.3.5",
|
|
67
69
|
"@tailwindcss/postcss": "^4.3.0",
|
|
68
70
|
"@types/bun": "latest",
|
|
69
71
|
"@types/node": "^25.8.0",
|
|
70
|
-
"tailwindcss": "
|
|
72
|
+
"tailwindcss": "4.3.5",
|
|
71
73
|
"typescript": "^5",
|
|
72
74
|
"vite": "^8.4.1"
|
|
73
75
|
},
|
|
74
76
|
"bin": {
|
|
75
|
-
"pandatail": "
|
|
77
|
+
"pandatail": "dist/cli.js"
|
|
76
78
|
},
|
|
77
79
|
"peerDependenciesMeta": {
|
|
78
80
|
"vite": {
|