@dmisdm/pandatail 0.2.0 → 0.3.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 +82 -83
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +637 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +325 -211
- package/dist/preset.d.ts +36 -13
- package/dist/project.d.ts +74 -0
- package/dist/scanCss.d.ts +30 -0
- package/dist/vite.d.ts +19 -0
- package/dist/vite.js +606 -0
- package/package.json +30 -13
- package/LICENSE +0 -21
- package/dist/extractSync.d.ts +0 -19
package/dist/vite.js
ADDED
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
// src/vite.ts
|
|
2
|
+
import { existsSync as existsSync3 } from "node:fs";
|
|
3
|
+
import { relative as relative2, resolve as resolve5, sep } from "node:path";
|
|
4
|
+
|
|
5
|
+
// src/project.ts
|
|
6
|
+
import { bundleConfig, createConfigSnapshot, mergeConfigs } from "@pandacss/config";
|
|
7
|
+
import { createCompilerFromSnapshot } from "@pandacss/compiler";
|
|
8
|
+
import { applyConfigDefaults, formatDiagnostic } from "@pandacss/compiler-shared";
|
|
9
|
+
import presetBase from "@pandacss/preset-base";
|
|
10
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
11
|
+
import { existsSync as existsSync2, statSync } from "node:fs";
|
|
12
|
+
import { relative, resolve as resolve4 } from "node:path";
|
|
13
|
+
|
|
14
|
+
// src/preset.ts
|
|
15
|
+
import { definePreset } from "@pandacss/dev";
|
|
16
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
17
|
+
import { dirname as dirname3, resolve as resolve3 } from "node:path";
|
|
18
|
+
|
|
19
|
+
// src/extract.ts
|
|
20
|
+
import { __unstable__loadDesignSystem } from "tailwindcss";
|
|
21
|
+
import { readFile } from "node:fs/promises";
|
|
22
|
+
import { createRequire } from "node:module";
|
|
23
|
+
import { dirname, resolve } from "node:path";
|
|
24
|
+
import { pathToFileURL } from "node:url";
|
|
25
|
+
|
|
26
|
+
// src/namespaces.ts
|
|
27
|
+
var TAILWIND_NAMESPACES = [
|
|
28
|
+
{ prefix: "font-weight", category: "fontWeights" },
|
|
29
|
+
{ prefix: "inset-shadow", category: "shadows" },
|
|
30
|
+
{ prefix: "drop-shadow", category: "dropShadows" },
|
|
31
|
+
{ prefix: "text-shadow", category: "shadows" },
|
|
32
|
+
{ prefix: "color", category: "colors" },
|
|
33
|
+
{ prefix: "spacing", category: "spacing" },
|
|
34
|
+
{ prefix: "font", category: "fonts" },
|
|
35
|
+
{ prefix: "text", category: "fontSizes" },
|
|
36
|
+
{ prefix: "tracking", category: "letterSpacings" },
|
|
37
|
+
{ prefix: "leading", category: "lineHeights" },
|
|
38
|
+
{ prefix: "breakpoint", category: "breakpoints" },
|
|
39
|
+
{ prefix: "container", category: "sizes" },
|
|
40
|
+
{ prefix: "radius", category: "radii" },
|
|
41
|
+
{ prefix: "shadow", category: "shadows" },
|
|
42
|
+
{ prefix: "blur", category: "blurs" },
|
|
43
|
+
{ prefix: "aspect", category: "aspectRatios" },
|
|
44
|
+
{ prefix: "ease", category: "easings" },
|
|
45
|
+
{ prefix: "animate", category: "animations" },
|
|
46
|
+
{ prefix: "perspective", category: "sizes" }
|
|
47
|
+
];
|
|
48
|
+
function deriveTokenPath(rest) {
|
|
49
|
+
const lastDash = rest.lastIndexOf("-");
|
|
50
|
+
if (lastDash > 0) {
|
|
51
|
+
const after = rest.slice(lastDash + 1);
|
|
52
|
+
if (/^\d+$/.test(after)) {
|
|
53
|
+
return [rest.slice(0, lastDash), after];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return [rest];
|
|
57
|
+
}
|
|
58
|
+
function matchNamespace(themeKey) {
|
|
59
|
+
if (!themeKey.startsWith("--"))
|
|
60
|
+
return null;
|
|
61
|
+
const stripped = themeKey.slice(2);
|
|
62
|
+
if (stripped.includes("--"))
|
|
63
|
+
return null;
|
|
64
|
+
for (const mapping of TAILWIND_NAMESPACES) {
|
|
65
|
+
if (stripped === mapping.prefix) {
|
|
66
|
+
return { mapping, rest: "DEFAULT" };
|
|
67
|
+
}
|
|
68
|
+
const withDash = `${mapping.prefix}-`;
|
|
69
|
+
if (stripped.startsWith(withDash)) {
|
|
70
|
+
return { mapping, rest: stripped.slice(withDash.length) };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// src/derivedScales.ts
|
|
77
|
+
var TAILWIND_NUMERIC_STEPS = [
|
|
78
|
+
0,
|
|
79
|
+
0.5,
|
|
80
|
+
1,
|
|
81
|
+
1.5,
|
|
82
|
+
2,
|
|
83
|
+
2.5,
|
|
84
|
+
3,
|
|
85
|
+
3.5,
|
|
86
|
+
4,
|
|
87
|
+
5,
|
|
88
|
+
6,
|
|
89
|
+
7,
|
|
90
|
+
8,
|
|
91
|
+
9,
|
|
92
|
+
10,
|
|
93
|
+
11,
|
|
94
|
+
12,
|
|
95
|
+
14,
|
|
96
|
+
16,
|
|
97
|
+
20,
|
|
98
|
+
24,
|
|
99
|
+
28,
|
|
100
|
+
32,
|
|
101
|
+
36,
|
|
102
|
+
40,
|
|
103
|
+
44,
|
|
104
|
+
48,
|
|
105
|
+
52,
|
|
106
|
+
56,
|
|
107
|
+
60,
|
|
108
|
+
64,
|
|
109
|
+
72,
|
|
110
|
+
80,
|
|
111
|
+
96
|
|
112
|
+
];
|
|
113
|
+
var NAMED_SIZES = {
|
|
114
|
+
full: "100%",
|
|
115
|
+
screen: "100vw",
|
|
116
|
+
"screen-h": "100vh",
|
|
117
|
+
min: "min-content",
|
|
118
|
+
max: "max-content",
|
|
119
|
+
fit: "fit-content",
|
|
120
|
+
auto: "auto"
|
|
121
|
+
};
|
|
122
|
+
var NAMED_RADII = {
|
|
123
|
+
none: "0",
|
|
124
|
+
full: "9999px"
|
|
125
|
+
};
|
|
126
|
+
function synthesiseDerivedTokens(hasSpacingBase) {
|
|
127
|
+
const out = [];
|
|
128
|
+
if (hasSpacingBase) {
|
|
129
|
+
pushNumericScale(out);
|
|
130
|
+
}
|
|
131
|
+
pushNamed(out);
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
134
|
+
function pushNumericScale(out) {
|
|
135
|
+
for (const step of TAILWIND_NUMERIC_STEPS) {
|
|
136
|
+
const name = String(step);
|
|
137
|
+
const value = `calc(var(--spacing) * ${name})`;
|
|
138
|
+
const cssVar = `--spacing-${name.replace(".", "_")}`;
|
|
139
|
+
out.push({ cssVar, value, category: "spacing", path: [name] });
|
|
140
|
+
out.push({ cssVar, value, category: "sizes", path: [name] });
|
|
141
|
+
out.push({ cssVar, value, category: "lineHeights", path: [name] });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function pushNamed(out) {
|
|
145
|
+
for (const [name, value] of Object.entries(NAMED_SIZES)) {
|
|
146
|
+
out.push({
|
|
147
|
+
cssVar: `--sizes-${name.replace(".", "_")}`,
|
|
148
|
+
value,
|
|
149
|
+
category: "sizes",
|
|
150
|
+
path: [name]
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
for (const [name, value] of Object.entries(NAMED_RADII)) {
|
|
154
|
+
out.push({
|
|
155
|
+
cssVar: `--radii-${name}`,
|
|
156
|
+
value,
|
|
157
|
+
category: "radii",
|
|
158
|
+
path: [name]
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// 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
|
+
async function extractTokens(opts) {
|
|
178
|
+
const base = opts.base ?? process.cwd();
|
|
179
|
+
const ds = await __unstable__loadDesignSystem(opts.css, {
|
|
180
|
+
base,
|
|
181
|
+
loadStylesheet: async (id, basedir) => {
|
|
182
|
+
const path = resolveStylesheet(id, basedir);
|
|
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
|
+
});
|
|
192
|
+
const themeEntries = new Map;
|
|
193
|
+
for (const [key, entry] of ds.theme.entries())
|
|
194
|
+
themeEntries.set(key, entry.value);
|
|
195
|
+
const out = [];
|
|
196
|
+
for (const [key, rawValue] of themeEntries) {
|
|
197
|
+
const matched = matchNamespace(key);
|
|
198
|
+
if (!matched)
|
|
199
|
+
continue;
|
|
200
|
+
if (matched.rest === "DEFAULT")
|
|
201
|
+
continue;
|
|
202
|
+
out.push({
|
|
203
|
+
cssVar: key,
|
|
204
|
+
value: matched.mapping.category === "breakpoints" ? rawValue : `var(${key})`,
|
|
205
|
+
category: matched.mapping.category,
|
|
206
|
+
path: deriveTokenPath(matched.rest)
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
out.push(...synthesiseDerivedTokens(themeEntries.has("--spacing")));
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
async function extractTokensFromFile(path) {
|
|
213
|
+
const css = await readFile(path, "utf8");
|
|
214
|
+
return extractTokens({ css, base: dirname(resolve(path)) });
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// src/scanCss.ts
|
|
218
|
+
import postcss from "postcss";
|
|
219
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
220
|
+
import { dirname as dirname2, resolve as resolve2 } from "node:path";
|
|
221
|
+
function scanCss(opts) {
|
|
222
|
+
const out = {
|
|
223
|
+
sources: [],
|
|
224
|
+
excludes: [],
|
|
225
|
+
conditions: {},
|
|
226
|
+
warnings: [],
|
|
227
|
+
files: opts.file ? [opts.file] : []
|
|
228
|
+
};
|
|
229
|
+
walk(opts.css, opts.base, out, new Set(opts.file ? [opts.file] : []));
|
|
230
|
+
return out;
|
|
231
|
+
}
|
|
232
|
+
function walk(css, base, out, seen) {
|
|
233
|
+
let root;
|
|
234
|
+
try {
|
|
235
|
+
root = postcss.parse(css);
|
|
236
|
+
} catch (e) {
|
|
237
|
+
out.warnings.push(`could not parse CSS in ${base}: ${e.message}`);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
root.walkAtRules((rule) => {
|
|
241
|
+
switch (rule.name) {
|
|
242
|
+
case "import": {
|
|
243
|
+
const id = quoted(rule.params) ?? urlTarget(rule.params);
|
|
244
|
+
if (!id || !id.startsWith("."))
|
|
245
|
+
return;
|
|
246
|
+
const path = resolve2(base, id);
|
|
247
|
+
if (seen.has(path) || !existsSync(path))
|
|
248
|
+
return;
|
|
249
|
+
seen.add(path);
|
|
250
|
+
out.files.push(path);
|
|
251
|
+
walk(readFileSync(path, "utf8"), dirname2(path), out, seen);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
case "source":
|
|
255
|
+
return handleSource(rule, base, out);
|
|
256
|
+
case "custom-variant":
|
|
257
|
+
return handleCustomVariant(rule, out);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
function handleSource(rule, base, out) {
|
|
262
|
+
const params = rule.params.trim();
|
|
263
|
+
if (params.startsWith("inline(") || params.startsWith("not inline(")) {
|
|
264
|
+
out.warnings.push(`@source ${params}: inline sources have no Panda equivalent`);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const isNot = /^not\s/.test(params);
|
|
268
|
+
const target = quoted(isNot ? params.replace(/^not\s+/, "") : params);
|
|
269
|
+
if (!target)
|
|
270
|
+
return;
|
|
271
|
+
(isNot ? out.excludes : out.sources).push(resolve2(base, target));
|
|
272
|
+
}
|
|
273
|
+
function handleCustomVariant(rule, out) {
|
|
274
|
+
const params = rule.params.trim();
|
|
275
|
+
const name = /^([\w-]+)/.exec(params)?.[1];
|
|
276
|
+
if (!name)
|
|
277
|
+
return;
|
|
278
|
+
if (!rule.nodes) {
|
|
279
|
+
const m = /^[\w-]+\s*\(([\s\S]+)\)$/.exec(params);
|
|
280
|
+
if (m)
|
|
281
|
+
out.conditions[name] = m[1].trim();
|
|
282
|
+
else
|
|
283
|
+
out.warnings.push(`@custom-variant ${name}: unrecognised form`);
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const body = rule.nodes.filter((n) => n.type !== "comment");
|
|
287
|
+
const only = body.length === 1 ? body[0] : undefined;
|
|
288
|
+
if (only?.type === "atrule" && only.name !== "slot" && isSlotOnly(only)) {
|
|
289
|
+
out.conditions[name] = `@${only.name} ${only.params}`.trim();
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
if (only?.type === "rule" && isSlotOnly(only)) {
|
|
293
|
+
out.conditions[name] = only.selector;
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
out.warnings.push(`@custom-variant ${name}: block form is too complex to map to a Panda condition`);
|
|
297
|
+
}
|
|
298
|
+
function isSlotOnly(node) {
|
|
299
|
+
const kids = (node.nodes ?? []).filter((n) => n.type !== "comment");
|
|
300
|
+
return kids.length === 1 && kids[0].type === "atrule" && kids[0].name === "slot";
|
|
301
|
+
}
|
|
302
|
+
function quoted(params) {
|
|
303
|
+
return /^\s*["']([^"']+)["']/.exec(params)?.[1] ?? null;
|
|
304
|
+
}
|
|
305
|
+
function urlTarget(params) {
|
|
306
|
+
return /^\s*url\(\s*["']?([^"')]+)["']?\s*\)/.exec(params)?.[1] ?? null;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// src/preset.ts
|
|
310
|
+
async function loadTailwind(opts) {
|
|
311
|
+
let css;
|
|
312
|
+
let base;
|
|
313
|
+
let file;
|
|
314
|
+
if (opts.css != null) {
|
|
315
|
+
css = opts.css;
|
|
316
|
+
base = opts.base ?? process.cwd();
|
|
317
|
+
} else if (opts.cssPath != null) {
|
|
318
|
+
file = resolve3(opts.cssPath);
|
|
319
|
+
css = await readFile2(file, "utf8");
|
|
320
|
+
base = dirname3(file);
|
|
321
|
+
} else {
|
|
322
|
+
throw new Error("pandatail: provide either `css` or `cssPath`");
|
|
323
|
+
}
|
|
324
|
+
const tokens = await extractTokens({ css, base });
|
|
325
|
+
const scan = scanCss({ css, base, file });
|
|
326
|
+
return { preset: buildPreset(tokens, scan), scan, tokens };
|
|
327
|
+
}
|
|
328
|
+
async function tailwindPreset(opts) {
|
|
329
|
+
return (await loadTailwind(opts)).preset;
|
|
330
|
+
}
|
|
331
|
+
function buildPreset(tokens, scan) {
|
|
332
|
+
const breakpoints = {};
|
|
333
|
+
const tokenTokens = [];
|
|
334
|
+
for (const t of tokens) {
|
|
335
|
+
if (t.category === "breakpoints") {
|
|
336
|
+
breakpoints[t.path.join("-")] = t.value;
|
|
337
|
+
} else {
|
|
338
|
+
tokenTokens.push(t);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
const tokensByCategory = groupByCategory(tokenTokens);
|
|
342
|
+
const theme = {};
|
|
343
|
+
for (const [category, list] of Object.entries(tokensByCategory)) {
|
|
344
|
+
theme[category] = buildTree(list, category);
|
|
345
|
+
}
|
|
346
|
+
const preset = definePreset({
|
|
347
|
+
name: "tailwind",
|
|
348
|
+
theme: {
|
|
349
|
+
tokens: theme,
|
|
350
|
+
breakpoints
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
if (scan && Object.keys(scan.conditions).length > 0) {
|
|
354
|
+
preset.conditions = { extend: scan.conditions };
|
|
355
|
+
}
|
|
356
|
+
return preset;
|
|
357
|
+
}
|
|
358
|
+
function groupByCategory(tokens) {
|
|
359
|
+
const out = {};
|
|
360
|
+
for (const t of tokens) {
|
|
361
|
+
(out[t.category] ??= []).push(t);
|
|
362
|
+
}
|
|
363
|
+
return out;
|
|
364
|
+
}
|
|
365
|
+
function buildTree(tokens, category) {
|
|
366
|
+
const root = {};
|
|
367
|
+
for (const t of tokens) {
|
|
368
|
+
let cursor = root;
|
|
369
|
+
for (let i = 0;i < t.path.length - 1; i++) {
|
|
370
|
+
const seg = t.path[i];
|
|
371
|
+
const next = cursor[seg];
|
|
372
|
+
if (next && "value" in next) {
|
|
373
|
+
throw new Error(`pandatail: token path collision in '${category}' at ` + `'${t.path.slice(0, i + 1).join(".")}': ` + `'${t.path.join(".")}' nests under a token that is already a leaf.`);
|
|
374
|
+
}
|
|
375
|
+
if (!next) {
|
|
376
|
+
const fresh = {};
|
|
377
|
+
cursor[seg] = fresh;
|
|
378
|
+
cursor = fresh;
|
|
379
|
+
} else {
|
|
380
|
+
cursor = next;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
const leaf = t.path[t.path.length - 1];
|
|
384
|
+
const existing = cursor[leaf];
|
|
385
|
+
if (existing && !("value" in existing)) {
|
|
386
|
+
throw new Error(`pandatail: token path collision in '${category}' at ` + `'${t.path.join(".")}': a leaf token clashes with an existing group.`);
|
|
387
|
+
}
|
|
388
|
+
cursor[leaf] = { value: t.value };
|
|
389
|
+
}
|
|
390
|
+
return root;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// src/project.ts
|
|
394
|
+
var DEFAULT_EXT = "{js,jsx,ts,tsx,mdx}";
|
|
395
|
+
async function createPandatailProject(opts) {
|
|
396
|
+
const cwd = resolve4(opts.cwd ?? process.cwd());
|
|
397
|
+
const cssPath = resolve4(cwd, opts.css);
|
|
398
|
+
if (!existsSync2(cssPath))
|
|
399
|
+
throw new Error(`pandatail: CSS entry not found: ${cssPath}`);
|
|
400
|
+
const tw = await loadTailwind({ cssPath });
|
|
401
|
+
const dependencies = [...tw.scan.files];
|
|
402
|
+
let user = {};
|
|
403
|
+
if (typeof opts.config === "string") {
|
|
404
|
+
const file = resolve4(cwd, opts.config);
|
|
405
|
+
const bundled = await bundleConfig(file, cwd);
|
|
406
|
+
user = bundled.config;
|
|
407
|
+
dependencies.push(file, ...bundled.dependencies);
|
|
408
|
+
} else if (opts.config) {
|
|
409
|
+
user = opts.config;
|
|
410
|
+
}
|
|
411
|
+
const { presets: userPresetList, ...userRest } = user;
|
|
412
|
+
const userPresets = await resolvePresets(userPresetList, cwd);
|
|
413
|
+
const include = opts.include ?? unique([
|
|
414
|
+
...userRest.include ?? [`./src/**/*.${DEFAULT_EXT}`],
|
|
415
|
+
...tw.scan.sources.map((p) => sourceToGlob(p, cwd))
|
|
416
|
+
]);
|
|
417
|
+
const exclude = opts.exclude ?? unique([
|
|
418
|
+
...userRest.exclude ?? [],
|
|
419
|
+
...tw.scan.excludes.map((p) => sourceToGlob(p, cwd))
|
|
420
|
+
]);
|
|
421
|
+
const defaults = {
|
|
422
|
+
cwd,
|
|
423
|
+
preflight: false,
|
|
424
|
+
jsxFramework: "react",
|
|
425
|
+
jsxStyleProps: "all",
|
|
426
|
+
outdir: "styled-system"
|
|
427
|
+
};
|
|
428
|
+
const finalOverrides = { include, exclude, cwd };
|
|
429
|
+
for (const key of [
|
|
430
|
+
"outdir",
|
|
431
|
+
"jsxFramework",
|
|
432
|
+
"jsxStyleProps",
|
|
433
|
+
"preflight",
|
|
434
|
+
"importMap",
|
|
435
|
+
"prefix",
|
|
436
|
+
"hash",
|
|
437
|
+
"minify"
|
|
438
|
+
]) {
|
|
439
|
+
if (opts[key] !== undefined)
|
|
440
|
+
finalOverrides[key] = opts[key];
|
|
441
|
+
}
|
|
442
|
+
const merged = mergeConfigs([
|
|
443
|
+
defaults,
|
|
444
|
+
presetBase,
|
|
445
|
+
...userPresets,
|
|
446
|
+
tw.preset,
|
|
447
|
+
userRest,
|
|
448
|
+
finalOverrides
|
|
449
|
+
]);
|
|
450
|
+
const config = applyConfigDefaults(merged, cwd);
|
|
451
|
+
const compiler = createCompilerFromSnapshot(createConfigSnapshot(config));
|
|
452
|
+
return {
|
|
453
|
+
compiler,
|
|
454
|
+
config,
|
|
455
|
+
cwd,
|
|
456
|
+
outdir: resolve4(cwd, config.outdir ?? "styled-system"),
|
|
457
|
+
dependencies: unique(dependencies),
|
|
458
|
+
warnings: tw.scan.warnings
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
function buildProject(project, opts = {}) {
|
|
462
|
+
const { compiler, cwd, outdir } = project;
|
|
463
|
+
const files = compiler.scan();
|
|
464
|
+
compiler.parseFiles(files);
|
|
465
|
+
let artifacts = 0;
|
|
466
|
+
if (opts.codegen !== false) {
|
|
467
|
+
artifacts = compiler.writeArtifacts({ outdir, cwd }).length;
|
|
468
|
+
}
|
|
469
|
+
let cssPath;
|
|
470
|
+
if (opts.outfile !== false) {
|
|
471
|
+
const outfile = opts.outfile ?? relative(cwd, resolve4(outdir, "styles.css"));
|
|
472
|
+
cssPath = compiler.writeCss({ outfile, cwd }).path;
|
|
473
|
+
}
|
|
474
|
+
return { files, artifacts, cssPath, diagnostics: compiler.diagnostics() };
|
|
475
|
+
}
|
|
476
|
+
function sourceToGlob(path, cwd) {
|
|
477
|
+
const rel = relative(cwd, path).split("\\").join("/");
|
|
478
|
+
const p = rel.startsWith(".") ? rel : `./${rel}`;
|
|
479
|
+
const hasGlob = /[*?{}\[\]]/.test(p);
|
|
480
|
+
if (!hasGlob && existsSync2(path) && statSync(path).isDirectory()) {
|
|
481
|
+
return `${p}/**/*.${DEFAULT_EXT}`;
|
|
482
|
+
}
|
|
483
|
+
return p;
|
|
484
|
+
}
|
|
485
|
+
async function resolvePresets(list, cwd) {
|
|
486
|
+
const out = [];
|
|
487
|
+
for (const entry of list ?? []) {
|
|
488
|
+
const preset = await loadPreset(entry, cwd);
|
|
489
|
+
const { presets, ...rest } = preset;
|
|
490
|
+
out.push(...await resolvePresets(presets, cwd), rest);
|
|
491
|
+
}
|
|
492
|
+
return out;
|
|
493
|
+
}
|
|
494
|
+
async function loadPreset(entry, cwd) {
|
|
495
|
+
const value = await entry;
|
|
496
|
+
if (typeof value !== "string")
|
|
497
|
+
return value;
|
|
498
|
+
const req = createRequire2(resolve4(cwd, "__pandatail_anchor__"));
|
|
499
|
+
let mod;
|
|
500
|
+
try {
|
|
501
|
+
mod = await import(req.resolve(value));
|
|
502
|
+
} catch {
|
|
503
|
+
mod = await import(value);
|
|
504
|
+
}
|
|
505
|
+
return mod.default ?? mod.preset ?? mod;
|
|
506
|
+
}
|
|
507
|
+
function unique(xs) {
|
|
508
|
+
return [...new Set(xs)];
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// src/vite.ts
|
|
512
|
+
function pandatail(options) {
|
|
513
|
+
const { outfile, verbose, ...projectOptions } = options;
|
|
514
|
+
let root = process.cwd();
|
|
515
|
+
let isServe = false;
|
|
516
|
+
let project;
|
|
517
|
+
const log = (msg) => {
|
|
518
|
+
if (verbose ?? isServe)
|
|
519
|
+
console.log(`[pandatail] ${msg}`);
|
|
520
|
+
};
|
|
521
|
+
const load = async () => {
|
|
522
|
+
const p = await createPandatailProject({ cwd: root, ...projectOptions });
|
|
523
|
+
for (const w of p.warnings)
|
|
524
|
+
console.warn(`[pandatail] warning: ${w}`);
|
|
525
|
+
project = p;
|
|
526
|
+
return p;
|
|
527
|
+
};
|
|
528
|
+
const run = (p, codegen) => {
|
|
529
|
+
const r = buildProject(p, { codegen, outfile: outfile ?? undefined });
|
|
530
|
+
for (const d of r.diagnostics)
|
|
531
|
+
console.warn(formatDiagnostic(d));
|
|
532
|
+
const rel = (f) => relative2(p.cwd, f) || f;
|
|
533
|
+
log([
|
|
534
|
+
`${r.files.length} source file(s)`,
|
|
535
|
+
codegen ? `${r.artifacts} generated file(s) → ${rel(p.outdir)}/` : "",
|
|
536
|
+
r.cssPath ? `css → ${rel(r.cssPath)}` : ""
|
|
537
|
+
].filter(Boolean).join(", "));
|
|
538
|
+
};
|
|
539
|
+
return {
|
|
540
|
+
name: "pandatail",
|
|
541
|
+
enforce: "pre",
|
|
542
|
+
configResolved(config) {
|
|
543
|
+
root = config.root;
|
|
544
|
+
isServe = config.command === "serve";
|
|
545
|
+
},
|
|
546
|
+
async buildStart() {
|
|
547
|
+
const p = await load();
|
|
548
|
+
run(p, true);
|
|
549
|
+
for (const dep of p.dependencies)
|
|
550
|
+
this.addWatchFile(dep);
|
|
551
|
+
},
|
|
552
|
+
configureServer(server) {
|
|
553
|
+
const pending = new Set;
|
|
554
|
+
let timer;
|
|
555
|
+
let chain = Promise.resolve();
|
|
556
|
+
const flush = async () => {
|
|
557
|
+
const changed = [...pending];
|
|
558
|
+
pending.clear();
|
|
559
|
+
const p = project;
|
|
560
|
+
if (!p || changed.length === 0)
|
|
561
|
+
return;
|
|
562
|
+
try {
|
|
563
|
+
if (changed.some((f) => p.dependencies.includes(f))) {
|
|
564
|
+
const next = await load();
|
|
565
|
+
server.watcher.add(next.dependencies);
|
|
566
|
+
run(next, true);
|
|
567
|
+
server.ws.send({ type: "full-reload" });
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
for (const f of changed) {
|
|
571
|
+
if (existsSync3(f))
|
|
572
|
+
p.compiler.refreshFile(f);
|
|
573
|
+
else
|
|
574
|
+
p.compiler.removeFile(f);
|
|
575
|
+
}
|
|
576
|
+
run(p, false);
|
|
577
|
+
} catch (e) {
|
|
578
|
+
server.config.logger.error(`[pandatail] ${e.message}`);
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
const onFsEvent = (file) => {
|
|
582
|
+
const p = project;
|
|
583
|
+
if (!p)
|
|
584
|
+
return;
|
|
585
|
+
const abs = resolve5(file);
|
|
586
|
+
if (abs.startsWith(p.outdir + sep) || abs.split(sep).includes("node_modules"))
|
|
587
|
+
return;
|
|
588
|
+
if (!p.dependencies.includes(abs) && !p.compiler.isSourceFile(abs))
|
|
589
|
+
return;
|
|
590
|
+
pending.add(abs);
|
|
591
|
+
clearTimeout(timer);
|
|
592
|
+
timer = setTimeout(() => {
|
|
593
|
+
chain = chain.then(flush);
|
|
594
|
+
}, 40);
|
|
595
|
+
};
|
|
596
|
+
server.watcher.on("change", onFsEvent);
|
|
597
|
+
server.watcher.on("add", onFsEvent);
|
|
598
|
+
server.watcher.on("unlink", onFsEvent);
|
|
599
|
+
}
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
var vite_default = pandatail;
|
|
603
|
+
export {
|
|
604
|
+
vite_default as default,
|
|
605
|
+
pandatail
|
|
606
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dmisdm/pandatail",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "PandaCSS
|
|
3
|
+
"version": "0.3.0",
|
|
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": [
|
|
7
7
|
"pandacss",
|
|
@@ -27,7 +27,11 @@
|
|
|
27
27
|
"types": "./dist/index.d.ts",
|
|
28
28
|
"import": "./dist/index.js"
|
|
29
29
|
},
|
|
30
|
-
"./package.json": "./package.json"
|
|
30
|
+
"./package.json": "./package.json",
|
|
31
|
+
"./vite": {
|
|
32
|
+
"types": "./dist/vite.d.ts",
|
|
33
|
+
"import": "./dist/vite.js"
|
|
34
|
+
}
|
|
31
35
|
},
|
|
32
36
|
"files": [
|
|
33
37
|
"dist",
|
|
@@ -36,30 +40,43 @@
|
|
|
36
40
|
],
|
|
37
41
|
"scripts": {
|
|
38
42
|
"build": "bun run clean && bun run build:js && bun run build:types",
|
|
39
|
-
"build:js": "bun build src/index.ts --outdir dist --target node --format esm --external @pandacss
|
|
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",
|
|
40
44
|
"build:types": "tsc --project tsconfig.build.json",
|
|
41
45
|
"clean": "rm -rf dist",
|
|
42
46
|
"test": "bun test",
|
|
43
47
|
"prepublishOnly": "bun run test && bun run build"
|
|
44
48
|
},
|
|
45
49
|
"peerDependencies": {
|
|
46
|
-
"@pandacss/dev": "^
|
|
47
|
-
"
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"tailwindcss":
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
"@pandacss/dev": "^2.0.0",
|
|
51
|
+
"@pandacss/compiler": "^2.0.0",
|
|
52
|
+
"@pandacss/config": "^2.0.0",
|
|
53
|
+
"@pandacss/preset-base": "^2.0.0",
|
|
54
|
+
"tailwindcss": "^4.0.0",
|
|
55
|
+
"@pandacss/compiler-shared": "^2.0.0",
|
|
56
|
+
"vite": ">=5.0.0"
|
|
53
57
|
},
|
|
54
58
|
"dependencies": {
|
|
55
59
|
"postcss": "^8.4.0"
|
|
56
60
|
},
|
|
57
61
|
"devDependencies": {
|
|
58
|
-
"@pandacss/
|
|
62
|
+
"@pandacss/compiler": "^2.6.0",
|
|
63
|
+
"@pandacss/compiler-shared": "^2.6.0",
|
|
64
|
+
"@pandacss/config": "^2.6.0",
|
|
65
|
+
"@pandacss/dev": "^2.6.0",
|
|
66
|
+
"@pandacss/preset-base": "^2.6.0",
|
|
59
67
|
"@tailwindcss/postcss": "^4.3.0",
|
|
60
68
|
"@types/bun": "latest",
|
|
61
69
|
"@types/node": "^25.8.0",
|
|
62
70
|
"tailwindcss": "^4.3.0",
|
|
63
|
-
"typescript": "^5"
|
|
71
|
+
"typescript": "^5",
|
|
72
|
+
"vite": "^8.4.1"
|
|
73
|
+
},
|
|
74
|
+
"bin": {
|
|
75
|
+
"pandatail": "./dist/cli.js"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"vite": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
64
81
|
}
|
|
65
82
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Daniel Manning
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|