@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/studio.js
ADDED
|
@@ -0,0 +1,580 @@
|
|
|
1
|
+
// src/studio.ts
|
|
2
|
+
import { spawn } from "node:child_process";
|
|
3
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
5
|
+
import { constants, tmpdir } from "node:os";
|
|
6
|
+
import { dirname as dirname4, join, resolve as resolve5 } from "node:path";
|
|
7
|
+
|
|
8
|
+
// src/project.ts
|
|
9
|
+
import { bundleConfig, createConfigSnapshot, mergeConfigs } from "@pandacss/config";
|
|
10
|
+
import { createCompilerFromSnapshot } from "@pandacss/compiler";
|
|
11
|
+
import { applyConfigDefaults, formatDiagnostic } from "@pandacss/compiler-shared";
|
|
12
|
+
import presetBase from "@pandacss/preset-base";
|
|
13
|
+
import { createRequire } from "node:module";
|
|
14
|
+
import { existsSync as existsSync2, statSync } from "node:fs";
|
|
15
|
+
import { relative, resolve as resolve4 } from "node:path";
|
|
16
|
+
|
|
17
|
+
// src/preset.ts
|
|
18
|
+
import { definePreset } from "@pandacss/dev";
|
|
19
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
20
|
+
import { dirname as dirname3, resolve as resolve3 } from "node:path";
|
|
21
|
+
|
|
22
|
+
// src/extract.ts
|
|
23
|
+
import { __unstable__loadDesignSystem } from "@tailwindcss/node";
|
|
24
|
+
import { readFile } from "node:fs/promises";
|
|
25
|
+
import { dirname, resolve } from "node:path";
|
|
26
|
+
|
|
27
|
+
// src/namespaces.ts
|
|
28
|
+
var TAILWIND_NAMESPACES = [
|
|
29
|
+
{ prefix: "font-weight", category: "fontWeights" },
|
|
30
|
+
{ prefix: "inset-shadow", category: "shadows" },
|
|
31
|
+
{ prefix: "drop-shadow", category: "dropShadows" },
|
|
32
|
+
{ prefix: "text-shadow", category: "shadows" },
|
|
33
|
+
{ prefix: "color", category: "colors" },
|
|
34
|
+
{ prefix: "spacing", category: "spacing" },
|
|
35
|
+
{ prefix: "font", category: "fonts" },
|
|
36
|
+
{ prefix: "text", category: "fontSizes" },
|
|
37
|
+
{ prefix: "tracking", category: "letterSpacings" },
|
|
38
|
+
{ prefix: "leading", category: "lineHeights" },
|
|
39
|
+
{ prefix: "breakpoint", category: "breakpoints" },
|
|
40
|
+
{ prefix: "container", category: "sizes" },
|
|
41
|
+
{ prefix: "radius", category: "radii" },
|
|
42
|
+
{ prefix: "shadow", category: "shadows" },
|
|
43
|
+
{ prefix: "blur", category: "blurs" },
|
|
44
|
+
{ prefix: "aspect", category: "aspectRatios" },
|
|
45
|
+
{ prefix: "ease", category: "easings" },
|
|
46
|
+
{ prefix: "animate", category: "animations" },
|
|
47
|
+
{ prefix: "perspective", category: "sizes" }
|
|
48
|
+
];
|
|
49
|
+
function deriveTokenPath(rest) {
|
|
50
|
+
const lastDash = rest.lastIndexOf("-");
|
|
51
|
+
if (lastDash > 0) {
|
|
52
|
+
const after = rest.slice(lastDash + 1);
|
|
53
|
+
if (/^\d+$/.test(after)) {
|
|
54
|
+
return [rest.slice(0, lastDash), after];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return [rest];
|
|
58
|
+
}
|
|
59
|
+
function matchNamespace(themeKey) {
|
|
60
|
+
if (!themeKey.startsWith("--"))
|
|
61
|
+
return null;
|
|
62
|
+
const stripped = themeKey.slice(2);
|
|
63
|
+
if (stripped.includes("--"))
|
|
64
|
+
return null;
|
|
65
|
+
for (const mapping of TAILWIND_NAMESPACES) {
|
|
66
|
+
if (stripped === mapping.prefix) {
|
|
67
|
+
return { mapping, rest: "DEFAULT" };
|
|
68
|
+
}
|
|
69
|
+
const withDash = `${mapping.prefix}-`;
|
|
70
|
+
if (stripped.startsWith(withDash)) {
|
|
71
|
+
return { mapping, rest: stripped.slice(withDash.length) };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/derivedScales.ts
|
|
78
|
+
var TAILWIND_NUMERIC_STEPS = [
|
|
79
|
+
0,
|
|
80
|
+
0.5,
|
|
81
|
+
1,
|
|
82
|
+
1.5,
|
|
83
|
+
2,
|
|
84
|
+
2.5,
|
|
85
|
+
3,
|
|
86
|
+
3.5,
|
|
87
|
+
4,
|
|
88
|
+
5,
|
|
89
|
+
6,
|
|
90
|
+
7,
|
|
91
|
+
8,
|
|
92
|
+
9,
|
|
93
|
+
10,
|
|
94
|
+
11,
|
|
95
|
+
12,
|
|
96
|
+
14,
|
|
97
|
+
16,
|
|
98
|
+
20,
|
|
99
|
+
24,
|
|
100
|
+
28,
|
|
101
|
+
32,
|
|
102
|
+
36,
|
|
103
|
+
40,
|
|
104
|
+
44,
|
|
105
|
+
48,
|
|
106
|
+
52,
|
|
107
|
+
56,
|
|
108
|
+
60,
|
|
109
|
+
64,
|
|
110
|
+
72,
|
|
111
|
+
80,
|
|
112
|
+
96
|
|
113
|
+
];
|
|
114
|
+
var NAMED_SIZES = {
|
|
115
|
+
full: "100%",
|
|
116
|
+
screen: "100vw",
|
|
117
|
+
"screen-h": "100vh",
|
|
118
|
+
min: "min-content",
|
|
119
|
+
max: "max-content",
|
|
120
|
+
fit: "fit-content",
|
|
121
|
+
auto: "auto"
|
|
122
|
+
};
|
|
123
|
+
var NAMED_RADII = {
|
|
124
|
+
none: "0",
|
|
125
|
+
full: "9999px"
|
|
126
|
+
};
|
|
127
|
+
function synthesiseDerivedTokens(hasSpacingBase) {
|
|
128
|
+
const out = [];
|
|
129
|
+
if (hasSpacingBase) {
|
|
130
|
+
pushNumericScale(out);
|
|
131
|
+
}
|
|
132
|
+
pushNamed(out);
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
function pushNumericScale(out) {
|
|
136
|
+
for (const step of TAILWIND_NUMERIC_STEPS) {
|
|
137
|
+
const name = String(step);
|
|
138
|
+
const value = `calc(var(--spacing) * ${name})`;
|
|
139
|
+
const cssVar = `--spacing-${name.replace(".", "_")}`;
|
|
140
|
+
out.push({ cssVar, value, category: "spacing", path: [name] });
|
|
141
|
+
out.push({ cssVar, value, category: "sizes", path: [name] });
|
|
142
|
+
out.push({ cssVar, value, category: "lineHeights", path: [name] });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function pushNamed(out) {
|
|
146
|
+
for (const [name, value] of Object.entries(NAMED_SIZES)) {
|
|
147
|
+
out.push({
|
|
148
|
+
cssVar: `--sizes-${name.replace(".", "_")}`,
|
|
149
|
+
value,
|
|
150
|
+
category: "sizes",
|
|
151
|
+
path: [name]
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
for (const [name, value] of Object.entries(NAMED_RADII)) {
|
|
155
|
+
out.push({
|
|
156
|
+
cssVar: `--radii-${name}`,
|
|
157
|
+
value,
|
|
158
|
+
category: "radii",
|
|
159
|
+
path: [name]
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/extract.ts
|
|
165
|
+
async function extractTokens(opts) {
|
|
166
|
+
return tokensFromTheme(await loadThemeEntries(opts));
|
|
167
|
+
}
|
|
168
|
+
async function loadThemeEntries(opts) {
|
|
169
|
+
const base = resolve(opts.base ?? process.cwd());
|
|
170
|
+
const ds = await __unstable__loadDesignSystem(opts.css, { base });
|
|
171
|
+
const themeEntries = new Map;
|
|
172
|
+
for (const [key, entry] of ds.theme.entries())
|
|
173
|
+
themeEntries.set(key, entry.value);
|
|
174
|
+
return themeEntries;
|
|
175
|
+
}
|
|
176
|
+
function tokensFromTheme(themeEntries) {
|
|
177
|
+
const out = [];
|
|
178
|
+
for (const [key, rawValue] of themeEntries) {
|
|
179
|
+
const matched = matchNamespace(key);
|
|
180
|
+
if (!matched)
|
|
181
|
+
continue;
|
|
182
|
+
if (matched.rest === "DEFAULT")
|
|
183
|
+
continue;
|
|
184
|
+
out.push({
|
|
185
|
+
cssVar: key,
|
|
186
|
+
value: matched.mapping.category === "breakpoints" ? rawValue : `var(${key})`,
|
|
187
|
+
category: matched.mapping.category,
|
|
188
|
+
path: deriveTokenPath(matched.rest)
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
out.push(...synthesiseDerivedTokens(themeEntries.has("--spacing")));
|
|
192
|
+
return out;
|
|
193
|
+
}
|
|
194
|
+
async function extractTokensFromFile(path) {
|
|
195
|
+
const css = await readFile(path, "utf8");
|
|
196
|
+
return extractTokens({ css, base: dirname(resolve(path)) });
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// src/scanCss.ts
|
|
200
|
+
import postcss from "postcss";
|
|
201
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
202
|
+
import { dirname as dirname2, resolve as resolve2 } from "node:path";
|
|
203
|
+
function scanCss(opts, rootVariables) {
|
|
204
|
+
const out = {
|
|
205
|
+
sources: [],
|
|
206
|
+
excludes: [],
|
|
207
|
+
conditions: {},
|
|
208
|
+
warnings: [],
|
|
209
|
+
files: opts.file ? [opts.file] : []
|
|
210
|
+
};
|
|
211
|
+
walk(opts.css, opts.base, out, new Set(opts.file ? [opts.file] : []), rootVariables);
|
|
212
|
+
return out;
|
|
213
|
+
}
|
|
214
|
+
function walk(css, base, out, seen, rootVariables) {
|
|
215
|
+
let root;
|
|
216
|
+
try {
|
|
217
|
+
root = postcss.parse(css);
|
|
218
|
+
} catch (e) {
|
|
219
|
+
out.warnings.push(`could not parse CSS in ${base}: ${e.message}`);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
root.walk((rule) => {
|
|
223
|
+
if (rule.type === "rule" && rootVariables)
|
|
224
|
+
collectRootVariables(rule, rootVariables);
|
|
225
|
+
if (rule.type !== "atrule")
|
|
226
|
+
return;
|
|
227
|
+
switch (rule.name) {
|
|
228
|
+
case "import": {
|
|
229
|
+
const id = quoted(rule.params) ?? urlTarget(rule.params);
|
|
230
|
+
if (!id || !id.startsWith("."))
|
|
231
|
+
return;
|
|
232
|
+
const path = resolve2(base, id);
|
|
233
|
+
if (seen.has(path) || !existsSync(path))
|
|
234
|
+
return;
|
|
235
|
+
seen.add(path);
|
|
236
|
+
out.files.push(path);
|
|
237
|
+
walk(readFileSync(path, "utf8"), dirname2(path), out, seen, rootVariables);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
case "source":
|
|
241
|
+
return handleSource(rule, base, out);
|
|
242
|
+
case "custom-variant":
|
|
243
|
+
return handleCustomVariant(rule, out);
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
function collectRootVariables(rule, variables) {
|
|
248
|
+
let parent = rule.parent;
|
|
249
|
+
while (parent?.type === "atrule" && parent.name === "layer")
|
|
250
|
+
parent = parent.parent;
|
|
251
|
+
if (parent?.type !== "root" || !rule.selectors.includes(":root"))
|
|
252
|
+
return;
|
|
253
|
+
for (const node of rule.nodes) {
|
|
254
|
+
if (node.type === "decl" && node.prop.startsWith("--"))
|
|
255
|
+
variables.set(node.prop, node.value);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
function handleSource(rule, base, out) {
|
|
259
|
+
const params = rule.params.trim();
|
|
260
|
+
if (params.startsWith("inline(") || params.startsWith("not inline(")) {
|
|
261
|
+
out.warnings.push(`@source ${params}: inline sources have no Panda equivalent`);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const isNot = /^not\s/.test(params);
|
|
265
|
+
const target = quoted(isNot ? params.replace(/^not\s+/, "") : params);
|
|
266
|
+
if (!target)
|
|
267
|
+
return;
|
|
268
|
+
(isNot ? out.excludes : out.sources).push(resolve2(base, target));
|
|
269
|
+
}
|
|
270
|
+
function handleCustomVariant(rule, out) {
|
|
271
|
+
const params = rule.params.trim();
|
|
272
|
+
const name = /^([\w-]+)/.exec(params)?.[1];
|
|
273
|
+
if (!name)
|
|
274
|
+
return;
|
|
275
|
+
if (!rule.nodes) {
|
|
276
|
+
const m = /^[\w-]+\s*\(([\s\S]+)\)$/.exec(params);
|
|
277
|
+
if (m)
|
|
278
|
+
out.conditions[name] = m[1].trim();
|
|
279
|
+
else
|
|
280
|
+
out.warnings.push(`@custom-variant ${name}: unrecognised form`);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const body = rule.nodes.filter((n) => n.type !== "comment");
|
|
284
|
+
const only = body.length === 1 ? body[0] : undefined;
|
|
285
|
+
if (only?.type === "atrule" && only.name !== "slot" && isSlotOnly(only)) {
|
|
286
|
+
out.conditions[name] = `@${only.name} ${only.params}`.trim();
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (only?.type === "rule" && isSlotOnly(only)) {
|
|
290
|
+
out.conditions[name] = only.selector;
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
out.warnings.push(`@custom-variant ${name}: block form is too complex to map to a Panda condition`);
|
|
294
|
+
}
|
|
295
|
+
function isSlotOnly(node) {
|
|
296
|
+
const kids = (node.nodes ?? []).filter((n) => n.type !== "comment");
|
|
297
|
+
return kids.length === 1 && kids[0].type === "atrule" && kids[0].name === "slot";
|
|
298
|
+
}
|
|
299
|
+
function quoted(params) {
|
|
300
|
+
return /^\s*["']([^"']+)["']/.exec(params)?.[1] ?? null;
|
|
301
|
+
}
|
|
302
|
+
function urlTarget(params) {
|
|
303
|
+
return /^\s*url\(\s*["']?([^"')]+)["']?\s*\)/.exec(params)?.[1] ?? null;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// src/preset.ts
|
|
307
|
+
async function loadTailwind(opts, preview = false) {
|
|
308
|
+
let css;
|
|
309
|
+
let base;
|
|
310
|
+
let file;
|
|
311
|
+
if (opts.css != null) {
|
|
312
|
+
css = opts.css;
|
|
313
|
+
base = opts.base ?? process.cwd();
|
|
314
|
+
} else if (opts.cssPath != null) {
|
|
315
|
+
file = resolve3(opts.cssPath);
|
|
316
|
+
css = await readFile2(file, "utf8");
|
|
317
|
+
base = dirname3(file);
|
|
318
|
+
} else {
|
|
319
|
+
throw new Error("pandatail: provide either `css` or `cssPath`");
|
|
320
|
+
}
|
|
321
|
+
const theme = await loadThemeEntries({ css, base });
|
|
322
|
+
const tokens = tokensFromTheme(theme);
|
|
323
|
+
const variables = preview ? new Map(theme) : undefined;
|
|
324
|
+
const scan = scanCss({ css, base, file }, variables);
|
|
325
|
+
const presetTokens = variables ? tokens.map((token) => ({
|
|
326
|
+
...token,
|
|
327
|
+
value: resolvePreviewValue(token.value, variables)
|
|
328
|
+
})) : tokens;
|
|
329
|
+
return { preset: buildPreset(presetTokens, scan), scan, tokens };
|
|
330
|
+
}
|
|
331
|
+
async function tailwindPreset(opts) {
|
|
332
|
+
return (await loadTailwind(opts)).preset;
|
|
333
|
+
}
|
|
334
|
+
function resolvePreviewValue(value, variables, resolving = new Set) {
|
|
335
|
+
return value.replace(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|(?<![\w-])var\(\s*(--[\w-]+)\s*\)/gi, (match, name) => {
|
|
336
|
+
if (name === undefined || resolving.has(name))
|
|
337
|
+
return match;
|
|
338
|
+
const definition = variables.get(name);
|
|
339
|
+
if (definition === undefined)
|
|
340
|
+
return match;
|
|
341
|
+
resolving.add(name);
|
|
342
|
+
const resolved = resolvePreviewValue(definition, variables, resolving);
|
|
343
|
+
resolving.delete(name);
|
|
344
|
+
return resolved;
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
function buildPreset(tokens, scan) {
|
|
348
|
+
const breakpoints = {};
|
|
349
|
+
const tokenTokens = [];
|
|
350
|
+
for (const t of tokens) {
|
|
351
|
+
if (t.category === "breakpoints") {
|
|
352
|
+
breakpoints[t.path.join("-")] = t.value;
|
|
353
|
+
} else {
|
|
354
|
+
tokenTokens.push(t);
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
const tokensByCategory = groupByCategory(tokenTokens);
|
|
358
|
+
const theme = {};
|
|
359
|
+
for (const [category, list] of Object.entries(tokensByCategory)) {
|
|
360
|
+
theme[category] = buildTree(list, category);
|
|
361
|
+
}
|
|
362
|
+
const preset = definePreset({
|
|
363
|
+
name: "tailwind",
|
|
364
|
+
theme: {
|
|
365
|
+
tokens: theme,
|
|
366
|
+
breakpoints
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
if (scan && Object.keys(scan.conditions).length > 0) {
|
|
370
|
+
preset.conditions = { extend: scan.conditions };
|
|
371
|
+
}
|
|
372
|
+
return preset;
|
|
373
|
+
}
|
|
374
|
+
function groupByCategory(tokens) {
|
|
375
|
+
const out = {};
|
|
376
|
+
for (const t of tokens) {
|
|
377
|
+
(out[t.category] ??= []).push(t);
|
|
378
|
+
}
|
|
379
|
+
return out;
|
|
380
|
+
}
|
|
381
|
+
function buildTree(tokens, category) {
|
|
382
|
+
const root = {};
|
|
383
|
+
for (const t of tokens) {
|
|
384
|
+
let cursor = root;
|
|
385
|
+
for (let i = 0;i < t.path.length - 1; i++) {
|
|
386
|
+
const seg = t.path[i];
|
|
387
|
+
const next = cursor[seg];
|
|
388
|
+
if (next && "value" in next) {
|
|
389
|
+
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.`);
|
|
390
|
+
}
|
|
391
|
+
if (!next) {
|
|
392
|
+
const fresh = {};
|
|
393
|
+
cursor[seg] = fresh;
|
|
394
|
+
cursor = fresh;
|
|
395
|
+
} else {
|
|
396
|
+
cursor = next;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const leaf = t.path[t.path.length - 1];
|
|
400
|
+
const existing = cursor[leaf];
|
|
401
|
+
if (existing && !("value" in existing)) {
|
|
402
|
+
throw new Error(`pandatail: token path collision in '${category}' at ` + `'${t.path.join(".")}': a leaf token clashes with an existing group.`);
|
|
403
|
+
}
|
|
404
|
+
cursor[leaf] = { value: t.value };
|
|
405
|
+
}
|
|
406
|
+
return root;
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
// src/project.ts
|
|
410
|
+
var DEFAULT_EXT = "{js,jsx,ts,tsx,mdx}";
|
|
411
|
+
async function createPandatailProject(opts) {
|
|
412
|
+
const project = await resolvePandatailConfig(opts);
|
|
413
|
+
const compiler = createCompilerFromSnapshot(createConfigSnapshot(project.config));
|
|
414
|
+
return { compiler, ...project };
|
|
415
|
+
}
|
|
416
|
+
async function resolvePandatailConfig(opts, preview = false) {
|
|
417
|
+
const cwd = resolve4(opts.cwd ?? process.cwd());
|
|
418
|
+
const cssPath = resolve4(cwd, opts.css);
|
|
419
|
+
if (!existsSync2(cssPath))
|
|
420
|
+
throw new Error(`pandatail: CSS entry not found: ${cssPath}`);
|
|
421
|
+
const tw = await loadTailwind({ cssPath }, preview);
|
|
422
|
+
const dependencies = [...tw.scan.files];
|
|
423
|
+
let user = {};
|
|
424
|
+
if (typeof opts.config === "string") {
|
|
425
|
+
const file = resolve4(cwd, opts.config);
|
|
426
|
+
const bundled = await bundleConfig(file, cwd);
|
|
427
|
+
user = bundled.config;
|
|
428
|
+
dependencies.push(file, ...bundled.dependencies);
|
|
429
|
+
} else if (opts.config) {
|
|
430
|
+
user = opts.config;
|
|
431
|
+
}
|
|
432
|
+
const { presets: userPresetList, ...userRest } = user;
|
|
433
|
+
const userPresets = await resolvePresets(userPresetList, cwd);
|
|
434
|
+
const include = opts.include ?? unique([
|
|
435
|
+
...userRest.include ?? [`./src/**/*.${DEFAULT_EXT}`],
|
|
436
|
+
...tw.scan.sources.map((p) => sourceToGlob(p, cwd))
|
|
437
|
+
]);
|
|
438
|
+
const exclude = opts.exclude ?? unique([
|
|
439
|
+
...userRest.exclude ?? [],
|
|
440
|
+
...tw.scan.excludes.map((p) => sourceToGlob(p, cwd))
|
|
441
|
+
]);
|
|
442
|
+
const defaults = {
|
|
443
|
+
cwd,
|
|
444
|
+
preflight: false,
|
|
445
|
+
jsxFramework: "react",
|
|
446
|
+
jsxStyleProps: "all",
|
|
447
|
+
outdir: "styled-system"
|
|
448
|
+
};
|
|
449
|
+
const finalOverrides = { include, exclude, cwd };
|
|
450
|
+
for (const key of [
|
|
451
|
+
"outdir",
|
|
452
|
+
"jsxFramework",
|
|
453
|
+
"jsxStyleProps",
|
|
454
|
+
"preflight",
|
|
455
|
+
"importMap",
|
|
456
|
+
"prefix",
|
|
457
|
+
"hash",
|
|
458
|
+
"minify"
|
|
459
|
+
]) {
|
|
460
|
+
if (opts[key] !== undefined)
|
|
461
|
+
finalOverrides[key] = opts[key];
|
|
462
|
+
}
|
|
463
|
+
const merged = mergeConfigs([
|
|
464
|
+
defaults,
|
|
465
|
+
presetBase,
|
|
466
|
+
...userPresets,
|
|
467
|
+
tw.preset,
|
|
468
|
+
userRest,
|
|
469
|
+
finalOverrides
|
|
470
|
+
]);
|
|
471
|
+
const config = applyConfigDefaults(merged, cwd);
|
|
472
|
+
return {
|
|
473
|
+
config,
|
|
474
|
+
cwd,
|
|
475
|
+
outdir: resolve4(cwd, config.outdir ?? "styled-system"),
|
|
476
|
+
dependencies: unique(dependencies),
|
|
477
|
+
warnings: tw.scan.warnings
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
function buildProject(project, opts = {}) {
|
|
481
|
+
const { compiler, cwd, outdir } = project;
|
|
482
|
+
const files = compiler.scan();
|
|
483
|
+
compiler.parseFiles(files);
|
|
484
|
+
let artifacts = 0;
|
|
485
|
+
if (opts.codegen !== false) {
|
|
486
|
+
artifacts = compiler.writeArtifacts({ outdir, cwd }).length;
|
|
487
|
+
}
|
|
488
|
+
let cssPath;
|
|
489
|
+
if (opts.outfile !== false) {
|
|
490
|
+
const outfile = opts.outfile ?? relative(cwd, resolve4(outdir, "styles.css"));
|
|
491
|
+
cssPath = compiler.writeCss({ outfile, cwd }).path;
|
|
492
|
+
}
|
|
493
|
+
return { files, artifacts, cssPath, diagnostics: compiler.diagnostics() };
|
|
494
|
+
}
|
|
495
|
+
function sourceToGlob(path, cwd) {
|
|
496
|
+
const rel = relative(cwd, path).split("\\").join("/");
|
|
497
|
+
const p = rel.startsWith(".") ? rel : `./${rel}`;
|
|
498
|
+
const hasGlob = /[*?{}\[\]]/.test(p);
|
|
499
|
+
if (!hasGlob && existsSync2(path) && statSync(path).isDirectory()) {
|
|
500
|
+
return `${p}/**/*.${DEFAULT_EXT}`;
|
|
501
|
+
}
|
|
502
|
+
return p;
|
|
503
|
+
}
|
|
504
|
+
async function resolvePresets(list, cwd) {
|
|
505
|
+
const out = [];
|
|
506
|
+
for (const entry of list ?? []) {
|
|
507
|
+
const preset = await loadPreset(entry, cwd);
|
|
508
|
+
const { presets, ...rest } = preset;
|
|
509
|
+
out.push(...await resolvePresets(presets, cwd), rest);
|
|
510
|
+
}
|
|
511
|
+
return out;
|
|
512
|
+
}
|
|
513
|
+
async function loadPreset(entry, cwd) {
|
|
514
|
+
const value = await entry;
|
|
515
|
+
if (typeof value !== "string")
|
|
516
|
+
return value;
|
|
517
|
+
const req = createRequire(resolve4(cwd, "__pandatail_anchor__"));
|
|
518
|
+
let mod;
|
|
519
|
+
try {
|
|
520
|
+
mod = await import(req.resolve(value));
|
|
521
|
+
} catch {
|
|
522
|
+
mod = await import(value);
|
|
523
|
+
}
|
|
524
|
+
return mod.default ?? mod.preset ?? mod;
|
|
525
|
+
}
|
|
526
|
+
function unique(xs) {
|
|
527
|
+
return [...new Set(xs)];
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// src/studio.ts
|
|
531
|
+
async function studioConfig(options) {
|
|
532
|
+
const { config, dependencies, warnings } = await resolvePandatailConfig(options, true);
|
|
533
|
+
for (const warning of warnings)
|
|
534
|
+
console.warn(`pandatail: warning: ${warning}`);
|
|
535
|
+
return { ...config, dependencies: [...config.dependencies ?? [], ...dependencies] };
|
|
536
|
+
}
|
|
537
|
+
async function runPandatailStudio(options, { port, noOpen }) {
|
|
538
|
+
const require2 = createRequire2(import.meta.url);
|
|
539
|
+
const manifestPath = require2.resolve("@pandacss/dev/package.json");
|
|
540
|
+
const { bin, version } = require2(manifestPath);
|
|
541
|
+
const [major, minor] = version.split(".");
|
|
542
|
+
if (major !== "2" || !(Number(minor) >= 4)) {
|
|
543
|
+
throw new Error(`studio requires Panda CSS 2.4 or newer (found ${version})`);
|
|
544
|
+
}
|
|
545
|
+
const cwd = resolve5(options.cwd ?? process.cwd());
|
|
546
|
+
const dir = mkdtempSync(join(tmpdir(), "pandatail-studio-"));
|
|
547
|
+
try {
|
|
548
|
+
const config = join(dir, "panda.config.mjs");
|
|
549
|
+
const entry = new URL(import.meta.url.endsWith(".ts") ? "./studio.ts" : "./studio.js", import.meta.url);
|
|
550
|
+
writeFileSync(config, `
|
|
551
|
+
const { studioConfig } = await import(new URL(${JSON.stringify(entry.href)}).href);
|
|
552
|
+
export default await studioConfig(${JSON.stringify({ ...options, cwd })});
|
|
553
|
+
`);
|
|
554
|
+
const args = [resolve5(dirname4(manifestPath), bin.panda), "studio", "--cwd", cwd, "--config", config];
|
|
555
|
+
if (port !== undefined)
|
|
556
|
+
args.push(`--port=${port}`);
|
|
557
|
+
if (noOpen)
|
|
558
|
+
args.push("--no-open");
|
|
559
|
+
const child = spawn(process.execPath, args, { stdio: "inherit" });
|
|
560
|
+
const interrupt = () => child.kill("SIGINT");
|
|
561
|
+
const terminate = () => child.kill("SIGTERM");
|
|
562
|
+
process.on("SIGINT", interrupt);
|
|
563
|
+
process.on("SIGTERM", terminate);
|
|
564
|
+
try {
|
|
565
|
+
return await new Promise((done, reject) => {
|
|
566
|
+
child.once("error", reject);
|
|
567
|
+
child.once("exit", (code, signal) => done(code ?? (signal ? 128 + constants.signals[signal] : 1)));
|
|
568
|
+
});
|
|
569
|
+
} finally {
|
|
570
|
+
process.off("SIGINT", interrupt);
|
|
571
|
+
process.off("SIGTERM", terminate);
|
|
572
|
+
}
|
|
573
|
+
} finally {
|
|
574
|
+
rmSync(dir, { recursive: true, force: true });
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
export {
|
|
578
|
+
runPandatailStudio,
|
|
579
|
+
studioConfig
|
|
580
|
+
};
|