@dmisdm/pandatail 0.4.0 → 0.6.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 +238 -25
- package/dist/check.d.ts +14 -0
- package/dist/cli.js +991 -156
- package/dist/diagnostics.d.ts +8 -0
- package/dist/extract.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +669 -138
- package/dist/languageServer.d.ts +1 -0
- package/dist/pandaCss.d.ts +24 -0
- package/dist/preset.d.ts +10 -3
- package/dist/project.d.ts +17 -3
- package/dist/scanCss.d.ts +14 -5
- package/dist/studio.d.ts +8 -0
- package/dist/studio.js +974 -0
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +759 -178
- package/editors/pandatail.css-data.json +14 -0
- package/package.json +6 -3
package/dist/studio.js
ADDED
|
@@ -0,0 +1,974 @@
|
|
|
1
|
+
var __esm = (fn, res, err) => () => {
|
|
2
|
+
if (fn)
|
|
3
|
+
try {
|
|
4
|
+
res = fn(fn = 0);
|
|
5
|
+
} catch (e) {
|
|
6
|
+
err = [e];
|
|
7
|
+
}
|
|
8
|
+
if (err)
|
|
9
|
+
throw err[0];
|
|
10
|
+
return res;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// src/diagnostics.ts
|
|
14
|
+
function formatCheckDiagnostic(issue) {
|
|
15
|
+
const start = issue.location?.start;
|
|
16
|
+
const where = issue.file ? `${issue.file}${start ? `:${start.line}:${start.column}` : ""}: ` : "";
|
|
17
|
+
return `${where}${issue.severity} [${issue.code}] ${issue.message}`;
|
|
18
|
+
}
|
|
19
|
+
function cssIssue(error, code, file, severity = "error") {
|
|
20
|
+
const { line, column, endLine, endColumn } = error.input ?? error;
|
|
21
|
+
return {
|
|
22
|
+
code,
|
|
23
|
+
severity,
|
|
24
|
+
message: error.reason,
|
|
25
|
+
file: file ?? error.file,
|
|
26
|
+
...line && column ? {
|
|
27
|
+
location: {
|
|
28
|
+
start: { line, column },
|
|
29
|
+
end: { line: endLine ?? line, column: endColumn ?? column + 1 }
|
|
30
|
+
}
|
|
31
|
+
} : {}
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
var PandatailDiagnosticError;
|
|
35
|
+
var init_diagnostics = __esm(() => {
|
|
36
|
+
PandatailDiagnosticError = class PandatailDiagnosticError extends Error {
|
|
37
|
+
diagnostics;
|
|
38
|
+
constructor(diagnostics) {
|
|
39
|
+
super(diagnostics.filter((issue) => issue.severity === "error").map(formatCheckDiagnostic).join(`
|
|
40
|
+
`));
|
|
41
|
+
this.diagnostics = diagnostics;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// src/namespaces.ts
|
|
47
|
+
function deriveTokenPath(rest) {
|
|
48
|
+
const lastDash = rest.lastIndexOf("-");
|
|
49
|
+
if (lastDash > 0) {
|
|
50
|
+
const after = rest.slice(lastDash + 1);
|
|
51
|
+
if (/^\d+$/.test(after)) {
|
|
52
|
+
return [rest.slice(0, lastDash), after];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return [rest];
|
|
56
|
+
}
|
|
57
|
+
function matchNamespace(themeKey) {
|
|
58
|
+
if (!themeKey.startsWith("--"))
|
|
59
|
+
return null;
|
|
60
|
+
const stripped = themeKey.slice(2);
|
|
61
|
+
if (stripped.includes("--"))
|
|
62
|
+
return null;
|
|
63
|
+
for (const mapping of TAILWIND_NAMESPACES) {
|
|
64
|
+
if (stripped === mapping.prefix) {
|
|
65
|
+
return { mapping, rest: "DEFAULT" };
|
|
66
|
+
}
|
|
67
|
+
const withDash = `${mapping.prefix}-`;
|
|
68
|
+
if (stripped.startsWith(withDash)) {
|
|
69
|
+
return { mapping, rest: stripped.slice(withDash.length) };
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
var TAILWIND_NAMESPACES;
|
|
75
|
+
var init_namespaces = __esm(() => {
|
|
76
|
+
TAILWIND_NAMESPACES = [
|
|
77
|
+
{ prefix: "font-weight", category: "fontWeights" },
|
|
78
|
+
{ prefix: "inset-shadow", category: "shadows" },
|
|
79
|
+
{ prefix: "drop-shadow", category: "dropShadows" },
|
|
80
|
+
{ prefix: "text-shadow", category: "shadows" },
|
|
81
|
+
{ prefix: "color", category: "colors" },
|
|
82
|
+
{ prefix: "spacing", category: "spacing" },
|
|
83
|
+
{ prefix: "font", category: "fonts" },
|
|
84
|
+
{ prefix: "text", category: "fontSizes" },
|
|
85
|
+
{ prefix: "tracking", category: "letterSpacings" },
|
|
86
|
+
{ prefix: "leading", category: "lineHeights" },
|
|
87
|
+
{ prefix: "breakpoint", category: "breakpoints" },
|
|
88
|
+
{ prefix: "container", category: "sizes" },
|
|
89
|
+
{ prefix: "radius", category: "radii" },
|
|
90
|
+
{ prefix: "shadow", category: "shadows" },
|
|
91
|
+
{ prefix: "blur", category: "blurs" },
|
|
92
|
+
{ prefix: "aspect", category: "aspectRatios" },
|
|
93
|
+
{ prefix: "ease", category: "easings" },
|
|
94
|
+
{ prefix: "animate", category: "animations" },
|
|
95
|
+
{ prefix: "perspective", category: "sizes" }
|
|
96
|
+
];
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// src/derivedScales.ts
|
|
100
|
+
function synthesiseDerivedTokens(hasSpacingBase) {
|
|
101
|
+
const out = [];
|
|
102
|
+
if (hasSpacingBase) {
|
|
103
|
+
pushNumericScale(out);
|
|
104
|
+
}
|
|
105
|
+
pushNamed(out);
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
function pushNumericScale(out) {
|
|
109
|
+
for (const step of TAILWIND_NUMERIC_STEPS) {
|
|
110
|
+
const name = String(step);
|
|
111
|
+
const value = `calc(var(--spacing) * ${name})`;
|
|
112
|
+
const cssVar = `--spacing-${name.replace(".", "_")}`;
|
|
113
|
+
out.push({ cssVar, value, category: "spacing", path: [name] });
|
|
114
|
+
out.push({ cssVar, value, category: "sizes", path: [name] });
|
|
115
|
+
out.push({ cssVar, value, category: "lineHeights", path: [name] });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
function pushNamed(out) {
|
|
119
|
+
for (const [name, value] of Object.entries(NAMED_SIZES)) {
|
|
120
|
+
out.push({
|
|
121
|
+
cssVar: `--sizes-${name.replace(".", "_")}`,
|
|
122
|
+
value,
|
|
123
|
+
category: "sizes",
|
|
124
|
+
path: [name]
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
for (const [name, value] of Object.entries(NAMED_RADII)) {
|
|
128
|
+
out.push({
|
|
129
|
+
cssVar: `--radii-${name}`,
|
|
130
|
+
value,
|
|
131
|
+
category: "radii",
|
|
132
|
+
path: [name]
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
var TAILWIND_NUMERIC_STEPS, NAMED_SIZES, NAMED_RADII;
|
|
137
|
+
var init_derivedScales = __esm(() => {
|
|
138
|
+
TAILWIND_NUMERIC_STEPS = [
|
|
139
|
+
0,
|
|
140
|
+
0.5,
|
|
141
|
+
1,
|
|
142
|
+
1.5,
|
|
143
|
+
2,
|
|
144
|
+
2.5,
|
|
145
|
+
3,
|
|
146
|
+
3.5,
|
|
147
|
+
4,
|
|
148
|
+
5,
|
|
149
|
+
6,
|
|
150
|
+
7,
|
|
151
|
+
8,
|
|
152
|
+
9,
|
|
153
|
+
10,
|
|
154
|
+
11,
|
|
155
|
+
12,
|
|
156
|
+
14,
|
|
157
|
+
16,
|
|
158
|
+
20,
|
|
159
|
+
24,
|
|
160
|
+
28,
|
|
161
|
+
32,
|
|
162
|
+
36,
|
|
163
|
+
40,
|
|
164
|
+
44,
|
|
165
|
+
48,
|
|
166
|
+
52,
|
|
167
|
+
56,
|
|
168
|
+
60,
|
|
169
|
+
64,
|
|
170
|
+
72,
|
|
171
|
+
80,
|
|
172
|
+
96
|
|
173
|
+
];
|
|
174
|
+
NAMED_SIZES = {
|
|
175
|
+
full: "100%",
|
|
176
|
+
screen: "100vw",
|
|
177
|
+
"screen-h": "100vh",
|
|
178
|
+
min: "min-content",
|
|
179
|
+
max: "max-content",
|
|
180
|
+
fit: "fit-content",
|
|
181
|
+
auto: "auto"
|
|
182
|
+
};
|
|
183
|
+
NAMED_RADII = {
|
|
184
|
+
none: "0",
|
|
185
|
+
full: "9999px"
|
|
186
|
+
};
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// src/extract.ts
|
|
190
|
+
import { __unstable__loadDesignSystem } from "@tailwindcss/node";
|
|
191
|
+
import { readFile } from "node:fs/promises";
|
|
192
|
+
import { dirname, resolve } from "node:path";
|
|
193
|
+
async function extractTokens(opts) {
|
|
194
|
+
return tokensFromTheme(await loadThemeEntries(opts));
|
|
195
|
+
}
|
|
196
|
+
async function loadThemeEntries(opts) {
|
|
197
|
+
const base = resolve(opts.base ?? process.cwd());
|
|
198
|
+
const ds = await __unstable__loadDesignSystem(opts.css, { base });
|
|
199
|
+
const themeEntries = new Map;
|
|
200
|
+
for (const [key, entry] of ds.theme.entries())
|
|
201
|
+
themeEntries.set(key, entry.value);
|
|
202
|
+
return themeEntries;
|
|
203
|
+
}
|
|
204
|
+
function tokensFromTheme(themeEntries) {
|
|
205
|
+
const out = [];
|
|
206
|
+
for (const [key, rawValue] of themeEntries) {
|
|
207
|
+
const matched = matchNamespace(key);
|
|
208
|
+
if (!matched)
|
|
209
|
+
continue;
|
|
210
|
+
if (matched.rest === "DEFAULT")
|
|
211
|
+
continue;
|
|
212
|
+
out.push({
|
|
213
|
+
cssVar: key,
|
|
214
|
+
value: matched.mapping.category === "breakpoints" ? rawValue : `var(${key})`,
|
|
215
|
+
category: matched.mapping.category,
|
|
216
|
+
path: deriveTokenPath(matched.rest)
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
out.push(...synthesiseDerivedTokens(themeEntries.has("--spacing")));
|
|
220
|
+
return out;
|
|
221
|
+
}
|
|
222
|
+
async function extractTokensFromFile(path) {
|
|
223
|
+
const css = await readFile(path, "utf8");
|
|
224
|
+
return extractTokens({ css, base: dirname(resolve(path)) });
|
|
225
|
+
}
|
|
226
|
+
var init_extract = __esm(() => {
|
|
227
|
+
init_namespaces();
|
|
228
|
+
init_derivedScales();
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
// src/pandaCss.ts
|
|
232
|
+
import { resolve as resolve2 } from "node:path";
|
|
233
|
+
function readPandaRule(rule, base, out, file) {
|
|
234
|
+
if (rule.parent?.type !== "root")
|
|
235
|
+
throw rule.error("@panda must be at the top level");
|
|
236
|
+
const params = rule.params.trim();
|
|
237
|
+
const [kind, ...args] = params.split(/\s+/);
|
|
238
|
+
if (kind === "config") {
|
|
239
|
+
const path = quoted(params.slice(kind.length).trim());
|
|
240
|
+
if (rule.nodes || !path?.endsWith(".json")) {
|
|
241
|
+
throw rule.error('Expected @panda config "./panda.json";');
|
|
242
|
+
}
|
|
243
|
+
const file = resolve2(base, path);
|
|
244
|
+
if (out.configFile && out.configFile !== file) {
|
|
245
|
+
throw rule.error(`Only one @panda config file is supported (already using ${out.configFile})`);
|
|
246
|
+
}
|
|
247
|
+
out.configFile = file;
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const name = args[0];
|
|
251
|
+
if (!name || args.length !== 1 || !rule.nodes) {
|
|
252
|
+
throw rule.error("Expected @panda <kind> <name> { … }");
|
|
253
|
+
}
|
|
254
|
+
const { description, body } = readBody(rule.nodes);
|
|
255
|
+
if (kind === "recipe") {
|
|
256
|
+
if (!isName(name) || !/^[a-z_]/i.test(name))
|
|
257
|
+
throw rule.error(`Invalid recipe name: ${name}`);
|
|
258
|
+
(out.theme.recipes ??= {})[name] = readRecipe(name, body, description);
|
|
259
|
+
collectReferences(rule, out.references, file);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (!kind || !Object.hasOwn(compositions, kind)) {
|
|
263
|
+
throw rule.error(`Unknown @panda kind: ${kind}`, { word: kind });
|
|
264
|
+
}
|
|
265
|
+
const category = compositions[kind];
|
|
266
|
+
const path = name.split(".");
|
|
267
|
+
if (path.some((part) => !isName(part) || part === "value")) {
|
|
268
|
+
throw rule.error(`Invalid ${kind} name: ${name}`);
|
|
269
|
+
}
|
|
270
|
+
setComposition(out.theme[category] ??= {}, path, { value: readStyles(body), description }, rule);
|
|
271
|
+
collectReferences(rule, out.references, file);
|
|
272
|
+
}
|
|
273
|
+
function setComposition(tree, path, style, rule) {
|
|
274
|
+
let group = tree;
|
|
275
|
+
for (const key of path.slice(0, -1)) {
|
|
276
|
+
const entry = own(group, key);
|
|
277
|
+
if (entry && Object.hasOwn(entry, "value"))
|
|
278
|
+
throw collision(rule);
|
|
279
|
+
group = group[key] = entry ?? {};
|
|
280
|
+
}
|
|
281
|
+
const leaf = path.at(-1);
|
|
282
|
+
const existing = own(group, leaf);
|
|
283
|
+
if (existing && !Object.hasOwn(existing, "value"))
|
|
284
|
+
throw collision(rule);
|
|
285
|
+
group[leaf] = style;
|
|
286
|
+
}
|
|
287
|
+
function collision(rule) {
|
|
288
|
+
return rule.error(`@panda ${rule.params}: a style cannot also be a group; use a .DEFAULT style for the group`);
|
|
289
|
+
}
|
|
290
|
+
function readBody(nodes) {
|
|
291
|
+
let description;
|
|
292
|
+
const body = nodes.filter((node) => {
|
|
293
|
+
if (node.type !== "atrule" || node.name !== "description")
|
|
294
|
+
return true;
|
|
295
|
+
if (description !== undefined)
|
|
296
|
+
throw node.error("Only one @description is allowed per @panda block");
|
|
297
|
+
description = quoted(node.params);
|
|
298
|
+
if (node.nodes || description === undefined)
|
|
299
|
+
throw node.error('Expected @description "…";');
|
|
300
|
+
return false;
|
|
301
|
+
});
|
|
302
|
+
return { description, body };
|
|
303
|
+
}
|
|
304
|
+
function readRecipe(className, nodes, description) {
|
|
305
|
+
const variants = {};
|
|
306
|
+
const defaults = new Map;
|
|
307
|
+
const base = [];
|
|
308
|
+
for (const node of nodes) {
|
|
309
|
+
if (node.type === "atrule" && node.name === "option") {
|
|
310
|
+
const [axis, value, ...rest] = node.params.trim().split(/\s+/);
|
|
311
|
+
if (!axis || !value || rest.length || !isName(axis) || !isName(value) || !node.nodes) {
|
|
312
|
+
throw node.error("Expected @option <axis> <value> { … }");
|
|
313
|
+
}
|
|
314
|
+
const options = own(variants, axis) ?? (variants[axis] = {});
|
|
315
|
+
if (Object.hasOwn(options, value))
|
|
316
|
+
throw node.error(`Duplicate recipe option: ${axis} ${value}`);
|
|
317
|
+
options[value] = readStyles(node.nodes);
|
|
318
|
+
} else if (node.type === "atrule" && node.name === "defaults") {
|
|
319
|
+
if (node.params || !node.nodes)
|
|
320
|
+
throw node.error("Expected @defaults { axis: value; }");
|
|
321
|
+
for (const decl of node.nodes) {
|
|
322
|
+
if (decl.type === "comment")
|
|
323
|
+
continue;
|
|
324
|
+
if (decl.type !== "decl" || !isName(decl.prop) || !isName(decl.value) || decl.important) {
|
|
325
|
+
throw decl.error("Expected a recipe axis and value in @defaults");
|
|
326
|
+
}
|
|
327
|
+
if (defaults.has(decl.prop))
|
|
328
|
+
throw decl.error(`Duplicate recipe default: ${decl.prop}`);
|
|
329
|
+
defaults.set(decl.prop, decl);
|
|
330
|
+
}
|
|
331
|
+
} else {
|
|
332
|
+
base.push(node);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
for (const [axis, decl] of defaults) {
|
|
336
|
+
const options = own(variants, axis);
|
|
337
|
+
if (!options || !Object.hasOwn(options, decl.value)) {
|
|
338
|
+
const expected = options ? ` Expected one of: ${Object.keys(options).join(", ")}.` : "";
|
|
339
|
+
const index = valueStart(decl);
|
|
340
|
+
throw decl.error(`Recipe ${className} has no option ${axis} ${decl.value}.${expected}`, {
|
|
341
|
+
index,
|
|
342
|
+
endIndex: index + decl.value.length
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
className,
|
|
348
|
+
base: readStyles(base),
|
|
349
|
+
...description === undefined ? {} : { description },
|
|
350
|
+
...Object.keys(variants).length === 0 ? {} : { variants },
|
|
351
|
+
...defaults.size === 0 ? {} : {
|
|
352
|
+
defaultVariants: Object.fromEntries([...defaults].map(([axis, decl]) => [axis, decl.value]))
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
function readStyles(nodes) {
|
|
357
|
+
const styles = Object.create(null);
|
|
358
|
+
fillStyles(nodes, styles);
|
|
359
|
+
return styles;
|
|
360
|
+
}
|
|
361
|
+
function fillStyles(nodes, styles) {
|
|
362
|
+
for (const node of nodes) {
|
|
363
|
+
if (node.type === "comment")
|
|
364
|
+
continue;
|
|
365
|
+
if (node.type === "decl") {
|
|
366
|
+
styles[styleProp(node.prop)] = node.value + (node.important ? " !important" : "");
|
|
367
|
+
continue;
|
|
368
|
+
}
|
|
369
|
+
let key;
|
|
370
|
+
if (node.type === "rule") {
|
|
371
|
+
key = node.selectors.map((selector) => selector.includes("&") ? selector : `& ${selector}`).join(", ");
|
|
372
|
+
} else if (node.type === "atrule" && node.nodes && /^(media|supports|container|starting-style)$/.test(node.name)) {
|
|
373
|
+
key = `@${node.name} ${node.params}`.trimEnd();
|
|
374
|
+
} else {
|
|
375
|
+
throw node.error(`Unsupported in @panda styles: @${node.name}`);
|
|
376
|
+
}
|
|
377
|
+
const previous = styles[key];
|
|
378
|
+
const nested = typeof previous === "object" ? previous : Object.create(null);
|
|
379
|
+
fillStyles(node.nodes ?? [], nested);
|
|
380
|
+
styles[key] = nested;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
function collectReferences(rule, references, file) {
|
|
384
|
+
rule.walkDecls((decl) => {
|
|
385
|
+
if (decl.parent?.type === "atrule" && decl.parent.name === "defaults")
|
|
386
|
+
return;
|
|
387
|
+
const prop = styleProp(decl.prop);
|
|
388
|
+
const start = valueStart(decl);
|
|
389
|
+
const raw = decl.raws.value?.raw ?? decl.value;
|
|
390
|
+
const add = (category, name, index) => {
|
|
391
|
+
const range = decl.rangeBy({ index, endIndex: index + name.length });
|
|
392
|
+
const { line, column } = range.start;
|
|
393
|
+
references.push({
|
|
394
|
+
category,
|
|
395
|
+
name,
|
|
396
|
+
file,
|
|
397
|
+
location: {
|
|
398
|
+
start: { line, column },
|
|
399
|
+
end: { line: range.end.line, column: range.end.column }
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
};
|
|
403
|
+
if (Object.hasOwn(compositionProps, prop)) {
|
|
404
|
+
add(compositionProps[prop], decl.value, start);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
for (const match of raw.matchAll(/\/\*[\s\S]*?\*\/|"(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*'|(?<![\w-])token\(\s*([\w.-]+)\s*\)/g)) {
|
|
408
|
+
const name = match[1];
|
|
409
|
+
if (name)
|
|
410
|
+
add("tokens", name, start + match.index + match[0].indexOf(name, "token(".length));
|
|
411
|
+
}
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
function valueStart(decl) {
|
|
415
|
+
return decl.prop.length + (decl.raws.between?.length ?? 1);
|
|
416
|
+
}
|
|
417
|
+
function styleProp(prop) {
|
|
418
|
+
if (prop.startsWith("--"))
|
|
419
|
+
return prop;
|
|
420
|
+
return prop.replace(/^-ms-/, "ms-").replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
421
|
+
}
|
|
422
|
+
function isName(name) {
|
|
423
|
+
return /^[\w-]+$/.test(name) && !["__proto__", "constructor", "prototype"].includes(name);
|
|
424
|
+
}
|
|
425
|
+
function own(obj, key) {
|
|
426
|
+
return Object.hasOwn(obj, key) ? obj[key] : undefined;
|
|
427
|
+
}
|
|
428
|
+
function quoted(value) {
|
|
429
|
+
const match = /^(?:"([^"]*)"|'([^']*)')$/.exec(value);
|
|
430
|
+
return match?.[1] ?? match?.[2];
|
|
431
|
+
}
|
|
432
|
+
var compositions, compositionProps;
|
|
433
|
+
var init_pandaCss = __esm(() => {
|
|
434
|
+
compositions = {
|
|
435
|
+
"text-style": "textStyles",
|
|
436
|
+
"layer-style": "layerStyles",
|
|
437
|
+
"animation-style": "animationStyles"
|
|
438
|
+
};
|
|
439
|
+
compositionProps = {
|
|
440
|
+
textStyle: "textStyles",
|
|
441
|
+
layerStyle: "layerStyles",
|
|
442
|
+
animationStyle: "animationStyles"
|
|
443
|
+
};
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
// src/scanCss.ts
|
|
447
|
+
import postcss, {
|
|
448
|
+
CssSyntaxError
|
|
449
|
+
} from "postcss";
|
|
450
|
+
import { readFileSync } from "node:fs";
|
|
451
|
+
import { dirname as dirname2, resolve as resolve3 } from "node:path";
|
|
452
|
+
function scanCss(opts, rootVariables) {
|
|
453
|
+
const out = {
|
|
454
|
+
sources: [],
|
|
455
|
+
excludes: [],
|
|
456
|
+
conditions: {},
|
|
457
|
+
warnings: [],
|
|
458
|
+
diagnostics: [],
|
|
459
|
+
files: opts.file ? [opts.file] : []
|
|
460
|
+
};
|
|
461
|
+
walk(opts, out, new Map(opts.file ? [[opts.file, true]] : []), rootVariables);
|
|
462
|
+
if (!opts.recover && out.diagnostics.some((issue) => issue.severity === "error")) {
|
|
463
|
+
throw new PandatailDiagnosticError(out.diagnostics);
|
|
464
|
+
}
|
|
465
|
+
return out;
|
|
466
|
+
}
|
|
467
|
+
function walk({ css, base, file, followImports }, out, seen, rootVariables, inReference = false) {
|
|
468
|
+
let root;
|
|
469
|
+
try {
|
|
470
|
+
root = postcss.parse(css, { from: file, map: false });
|
|
471
|
+
} catch (error) {
|
|
472
|
+
if (!(error instanceof CssSyntaxError))
|
|
473
|
+
throw error;
|
|
474
|
+
out.diagnostics.push(cssIssue(error, "css-syntax", file));
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const inPandaFile = /\.panda\.css$/i.test(file ?? "") || root.nodes.some((node) => node.type === "atrule" && node.name === "panda");
|
|
478
|
+
root.walk((rule) => {
|
|
479
|
+
if (rule.type === "rule" && rootVariables)
|
|
480
|
+
collectRootVariables(rule, rootVariables);
|
|
481
|
+
if (rule.type !== "atrule")
|
|
482
|
+
return;
|
|
483
|
+
switch (rule.name) {
|
|
484
|
+
case "import":
|
|
485
|
+
case "reference": {
|
|
486
|
+
if (followImports === false)
|
|
487
|
+
return;
|
|
488
|
+
const id = quoted2(rule.params) ?? urlTarget(rule.params);
|
|
489
|
+
if (!id || !id.startsWith("."))
|
|
490
|
+
return;
|
|
491
|
+
const path = resolve3(base, id);
|
|
492
|
+
const reference = inReference || rule.name === "reference";
|
|
493
|
+
const visited = seen.get(path);
|
|
494
|
+
if (visited === true || reference && visited === false)
|
|
495
|
+
return;
|
|
496
|
+
let content;
|
|
497
|
+
try {
|
|
498
|
+
content = readFileSync(path, "utf8");
|
|
499
|
+
} catch (error) {
|
|
500
|
+
const code = error.code;
|
|
501
|
+
if (code === "ENOENT" || code === "EISDIR")
|
|
502
|
+
return;
|
|
503
|
+
const reason = `Cannot read @${rule.name} stylesheet ${id}: ${error.message}`;
|
|
504
|
+
out.diagnostics.push(cssIssue(rule.error(reason, { word: id }), "css-import", file));
|
|
505
|
+
return;
|
|
506
|
+
}
|
|
507
|
+
seen.set(path, !reference);
|
|
508
|
+
if (visited === undefined)
|
|
509
|
+
out.files.push(path);
|
|
510
|
+
walk({ css: content, base: dirname2(path), file: path }, out, seen, reference ? undefined : rootVariables, reference);
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
case "panda":
|
|
514
|
+
try {
|
|
515
|
+
readPandaRule(rule, base, out.panda ??= { theme: {}, references: [] }, file);
|
|
516
|
+
} catch (error) {
|
|
517
|
+
if (!(error instanceof CssSyntaxError))
|
|
518
|
+
throw error;
|
|
519
|
+
out.diagnostics.push(cssIssue(error, "panda-syntax", file));
|
|
520
|
+
}
|
|
521
|
+
return;
|
|
522
|
+
case "option":
|
|
523
|
+
case "defaults":
|
|
524
|
+
case "description":
|
|
525
|
+
if (inPandaFile && rule.parent?.type === "root") {
|
|
526
|
+
const parent = rule.name === "description" ? "an @panda style or recipe" : "an @panda recipe";
|
|
527
|
+
out.diagnostics.push(cssIssue(rule.error(`@${rule.name} must be inside ${parent}`), "panda-syntax", file));
|
|
528
|
+
}
|
|
529
|
+
return;
|
|
530
|
+
case "source":
|
|
531
|
+
return handleSource(rule, base, out);
|
|
532
|
+
case "custom-variant":
|
|
533
|
+
return handleCustomVariant(rule, out);
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
function collectRootVariables(rule, variables) {
|
|
538
|
+
let parent = rule.parent;
|
|
539
|
+
while (parent?.type === "atrule" && parent.name === "layer")
|
|
540
|
+
parent = parent.parent;
|
|
541
|
+
if (parent?.type !== "root" || !rule.selectors.includes(":root"))
|
|
542
|
+
return;
|
|
543
|
+
for (const node of rule.nodes) {
|
|
544
|
+
if (node.type === "decl" && node.prop.startsWith("--"))
|
|
545
|
+
variables.set(node.prop, node.value);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
function handleSource(rule, base, out) {
|
|
549
|
+
const params = rule.params.trim();
|
|
550
|
+
if (params.startsWith("inline(") || params.startsWith("not inline(")) {
|
|
551
|
+
warn(out, rule, "tailwind-source", `@source ${params}: inline sources have no Panda equivalent`);
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
const isNot = /^not\s/.test(params);
|
|
555
|
+
const target = quoted2(isNot ? params.replace(/^not\s+/, "") : params);
|
|
556
|
+
if (!target)
|
|
557
|
+
return;
|
|
558
|
+
(isNot ? out.excludes : out.sources).push(resolve3(base, target));
|
|
559
|
+
}
|
|
560
|
+
function handleCustomVariant(rule, out) {
|
|
561
|
+
const params = rule.params.trim();
|
|
562
|
+
const name = /^([\w-]+)/.exec(params)?.[1];
|
|
563
|
+
if (!name)
|
|
564
|
+
return;
|
|
565
|
+
if (!rule.nodes) {
|
|
566
|
+
const m = /^[\w-]+\s*\(([\s\S]+)\)$/.exec(params);
|
|
567
|
+
if (m)
|
|
568
|
+
out.conditions[name] = m[1].trim();
|
|
569
|
+
else
|
|
570
|
+
warn(out, rule, "tailwind-variant", `@custom-variant ${name}: unrecognised form`);
|
|
571
|
+
return;
|
|
572
|
+
}
|
|
573
|
+
const body = rule.nodes.filter((n) => n.type !== "comment");
|
|
574
|
+
const only = body.length === 1 ? body[0] : undefined;
|
|
575
|
+
if (only?.type === "atrule" && only.name !== "slot" && isSlotOnly(only)) {
|
|
576
|
+
out.conditions[name] = `@${only.name} ${only.params}`.trim();
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
if (only?.type === "rule" && isSlotOnly(only)) {
|
|
580
|
+
out.conditions[name] = only.selector;
|
|
581
|
+
return;
|
|
582
|
+
}
|
|
583
|
+
warn(out, rule, "tailwind-variant", `@custom-variant ${name}: block form is too complex to map to a Panda condition`);
|
|
584
|
+
}
|
|
585
|
+
function warn(out, rule, code, message) {
|
|
586
|
+
out.warnings.push(message);
|
|
587
|
+
out.diagnostics.push(cssIssue(rule.error(message), code, rule.source?.input.file, "warning"));
|
|
588
|
+
}
|
|
589
|
+
function isSlotOnly(node) {
|
|
590
|
+
const kids = (node.nodes ?? []).filter((n) => n.type !== "comment");
|
|
591
|
+
return kids.length === 1 && kids[0].type === "atrule" && kids[0].name === "slot";
|
|
592
|
+
}
|
|
593
|
+
function quoted2(params) {
|
|
594
|
+
return /^\s*["']([^"']+)["']/.exec(params)?.[1] ?? null;
|
|
595
|
+
}
|
|
596
|
+
function urlTarget(params) {
|
|
597
|
+
return /^\s*url\(\s*["']?([^"')]+)["']?\s*\)/.exec(params)?.[1] ?? null;
|
|
598
|
+
}
|
|
599
|
+
var init_scanCss = __esm(() => {
|
|
600
|
+
init_diagnostics();
|
|
601
|
+
init_pandaCss();
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
// src/preset.ts
|
|
605
|
+
import { definePreset } from "@pandacss/dev";
|
|
606
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
607
|
+
import { dirname as dirname3, resolve as resolve4 } from "node:path";
|
|
608
|
+
async function loadTailwind(opts, preview = false) {
|
|
609
|
+
let css;
|
|
610
|
+
let base;
|
|
611
|
+
let file;
|
|
612
|
+
if (opts.css != null) {
|
|
613
|
+
css = opts.css;
|
|
614
|
+
base = opts.base ?? process.cwd();
|
|
615
|
+
} else if (opts.cssPath != null) {
|
|
616
|
+
file = resolve4(opts.cssPath);
|
|
617
|
+
css = await readFile2(file, "utf8");
|
|
618
|
+
base = dirname3(file);
|
|
619
|
+
} else {
|
|
620
|
+
throw new Error("pandatail: provide either `css` or `cssPath`");
|
|
621
|
+
}
|
|
622
|
+
const rootVariables = preview ? new Map : undefined;
|
|
623
|
+
const scan = scanCss({ css, base, file }, rootVariables);
|
|
624
|
+
const theme = await loadThemeEntries({ css, base });
|
|
625
|
+
const tokens = tokensFromTheme(theme);
|
|
626
|
+
const variables = rootVariables && new Map([...theme, ...rootVariables]);
|
|
627
|
+
const presetTokens = variables ? tokens.map((token) => ({
|
|
628
|
+
...token,
|
|
629
|
+
value: resolvePreviewValue(token.value, variables)
|
|
630
|
+
})) : tokens;
|
|
631
|
+
return { preset: buildPreset(presetTokens, scan), scan, tokens };
|
|
632
|
+
}
|
|
633
|
+
async function tailwindPreset(opts) {
|
|
634
|
+
return (await loadTailwind(opts)).preset;
|
|
635
|
+
}
|
|
636
|
+
function resolvePreviewValue(value, variables, resolving = new Set) {
|
|
637
|
+
return value.replace(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|(?<![\w-])var\(\s*(--[\w-]+)\s*\)/gi, (match, name) => {
|
|
638
|
+
if (name === undefined || resolving.has(name))
|
|
639
|
+
return match;
|
|
640
|
+
const definition = variables.get(name);
|
|
641
|
+
if (definition === undefined)
|
|
642
|
+
return match;
|
|
643
|
+
resolving.add(name);
|
|
644
|
+
const resolved = resolvePreviewValue(definition, variables, resolving);
|
|
645
|
+
resolving.delete(name);
|
|
646
|
+
return resolved;
|
|
647
|
+
});
|
|
648
|
+
}
|
|
649
|
+
function buildPreset(tokens, scan) {
|
|
650
|
+
const breakpoints = {};
|
|
651
|
+
const tokenTokens = [];
|
|
652
|
+
for (const t of tokens) {
|
|
653
|
+
if (t.category === "breakpoints") {
|
|
654
|
+
breakpoints[t.path.join("-")] = t.value;
|
|
655
|
+
} else {
|
|
656
|
+
tokenTokens.push(t);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
const tokensByCategory = groupByCategory(tokenTokens);
|
|
660
|
+
const theme = {};
|
|
661
|
+
for (const [category, list] of Object.entries(tokensByCategory)) {
|
|
662
|
+
theme[category] = buildTree(list, category);
|
|
663
|
+
}
|
|
664
|
+
const preset = definePreset({
|
|
665
|
+
name: "tailwind",
|
|
666
|
+
theme: {
|
|
667
|
+
tokens: theme,
|
|
668
|
+
breakpoints,
|
|
669
|
+
...scan?.panda ? { extend: scan.panda.theme } : {}
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
if (scan && Object.keys(scan.conditions).length > 0) {
|
|
673
|
+
preset.conditions = {
|
|
674
|
+
extend: scan.conditions
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
return preset;
|
|
678
|
+
}
|
|
679
|
+
function groupByCategory(tokens) {
|
|
680
|
+
const out = {};
|
|
681
|
+
for (const t of tokens) {
|
|
682
|
+
(out[t.category] ??= []).push(t);
|
|
683
|
+
}
|
|
684
|
+
return out;
|
|
685
|
+
}
|
|
686
|
+
function buildTree(tokens, category) {
|
|
687
|
+
const root = {};
|
|
688
|
+
for (const t of tokens) {
|
|
689
|
+
let cursor = root;
|
|
690
|
+
for (let i = 0;i < t.path.length - 1; i++) {
|
|
691
|
+
const seg = t.path[i];
|
|
692
|
+
const next = cursor[seg];
|
|
693
|
+
if (next && "value" in next) {
|
|
694
|
+
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.`);
|
|
695
|
+
}
|
|
696
|
+
if (!next) {
|
|
697
|
+
const fresh = {};
|
|
698
|
+
cursor[seg] = fresh;
|
|
699
|
+
cursor = fresh;
|
|
700
|
+
} else {
|
|
701
|
+
cursor = next;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
const leaf = t.path[t.path.length - 1];
|
|
705
|
+
const existing = cursor[leaf];
|
|
706
|
+
if (existing && !("value" in existing)) {
|
|
707
|
+
throw new Error(`pandatail: token path collision in '${category}' at ` + `'${t.path.join(".")}': a leaf token clashes with an existing group.`);
|
|
708
|
+
}
|
|
709
|
+
cursor[leaf] = { value: t.value };
|
|
710
|
+
}
|
|
711
|
+
return root;
|
|
712
|
+
}
|
|
713
|
+
var init_preset = __esm(() => {
|
|
714
|
+
init_extract();
|
|
715
|
+
init_scanCss();
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
// src/project.ts
|
|
719
|
+
import {
|
|
720
|
+
bundleConfig,
|
|
721
|
+
createConfigSnapshot,
|
|
722
|
+
mergeConfigs
|
|
723
|
+
} from "@pandacss/config";
|
|
724
|
+
import {
|
|
725
|
+
createCompilerFromSnapshot
|
|
726
|
+
} from "@pandacss/compiler";
|
|
727
|
+
import {
|
|
728
|
+
applyConfigDefaults,
|
|
729
|
+
collectParseDiagnostics,
|
|
730
|
+
dedupeDiagnostics,
|
|
731
|
+
formatDiagnostic
|
|
732
|
+
} from "@pandacss/compiler-shared";
|
|
733
|
+
import presetBase from "@pandacss/preset-base";
|
|
734
|
+
import { createRequire } from "node:module";
|
|
735
|
+
import { existsSync, statSync } from "node:fs";
|
|
736
|
+
import { readFile as readFile3 } from "node:fs/promises";
|
|
737
|
+
import { relative, resolve as resolve5 } from "node:path";
|
|
738
|
+
async function createPandatailProject(opts) {
|
|
739
|
+
const project = await resolvePandatailConfig(opts);
|
|
740
|
+
const compiler = createCompilerFromSnapshot(createConfigSnapshot(project.config));
|
|
741
|
+
return { compiler, ...project };
|
|
742
|
+
}
|
|
743
|
+
async function resolvePandatailConfig(opts, preview = false) {
|
|
744
|
+
const cwd = resolve5(opts.cwd ?? process.cwd());
|
|
745
|
+
const cssPath = resolve5(cwd, opts.css);
|
|
746
|
+
if (!existsSync(cssPath)) {
|
|
747
|
+
throw new PandatailDiagnosticError([
|
|
748
|
+
{
|
|
749
|
+
code: "css-entry",
|
|
750
|
+
severity: "error",
|
|
751
|
+
file: cssPath,
|
|
752
|
+
message: `CSS entry not found: ${cssPath}`
|
|
753
|
+
}
|
|
754
|
+
]);
|
|
755
|
+
}
|
|
756
|
+
const tw = await loadTailwind({ cssPath }, preview);
|
|
757
|
+
const dependencies = [...tw.scan.files];
|
|
758
|
+
const cssConfigFile = tw.scan.panda?.configFile;
|
|
759
|
+
const cssConfig = cssConfigFile ? await readCssConfig(cssConfigFile) : {};
|
|
760
|
+
if (cssConfigFile)
|
|
761
|
+
dependencies.push(cssConfigFile);
|
|
762
|
+
let user = {};
|
|
763
|
+
if (typeof opts.config === "string") {
|
|
764
|
+
const file = resolve5(cwd, opts.config);
|
|
765
|
+
const bundled = await bundleConfig(file, cwd);
|
|
766
|
+
user = bundled.config;
|
|
767
|
+
dependencies.push(file, ...bundled.dependencies);
|
|
768
|
+
} else if (opts.config) {
|
|
769
|
+
user = opts.config;
|
|
770
|
+
}
|
|
771
|
+
const { presets: cssPresetList, ...cssRest } = cssConfig;
|
|
772
|
+
const { presets: userPresetList, ...userRest } = user;
|
|
773
|
+
const presets = await resolvePresets([...cssPresetList ?? [], ...userPresetList ?? []], cwd);
|
|
774
|
+
const include = opts.include ?? unique([
|
|
775
|
+
...userRest.include ?? cssRest.include ?? [`./src/**/*.${DEFAULT_EXT}`],
|
|
776
|
+
...tw.scan.sources.map((p) => sourceToGlob(p, cwd))
|
|
777
|
+
]);
|
|
778
|
+
const exclude = opts.exclude ?? unique([
|
|
779
|
+
...userRest.exclude ?? cssRest.exclude ?? [],
|
|
780
|
+
...tw.scan.excludes.map((p) => sourceToGlob(p, cwd))
|
|
781
|
+
]);
|
|
782
|
+
const defaults = {
|
|
783
|
+
cwd,
|
|
784
|
+
preflight: false,
|
|
785
|
+
jsxFramework: "react",
|
|
786
|
+
jsxStyleProps: "all",
|
|
787
|
+
outdir: "styled-system"
|
|
788
|
+
};
|
|
789
|
+
const finalOverrides = { include, exclude, cwd };
|
|
790
|
+
for (const key of [
|
|
791
|
+
"outdir",
|
|
792
|
+
"jsxFramework",
|
|
793
|
+
"jsxStyleProps",
|
|
794
|
+
"preflight",
|
|
795
|
+
"importMap",
|
|
796
|
+
"prefix",
|
|
797
|
+
"hash",
|
|
798
|
+
"minify"
|
|
799
|
+
]) {
|
|
800
|
+
if (opts[key] !== undefined)
|
|
801
|
+
finalOverrides[key] = opts[key];
|
|
802
|
+
}
|
|
803
|
+
const merged = mergeConfigs([
|
|
804
|
+
defaults,
|
|
805
|
+
presetBase,
|
|
806
|
+
...presets,
|
|
807
|
+
tw.preset,
|
|
808
|
+
cssRest,
|
|
809
|
+
userRest,
|
|
810
|
+
finalOverrides
|
|
811
|
+
]);
|
|
812
|
+
const config = applyConfigDefaults(merged, cwd);
|
|
813
|
+
return {
|
|
814
|
+
config,
|
|
815
|
+
cwd,
|
|
816
|
+
outdir: resolve5(cwd, config.outdir ?? "styled-system"),
|
|
817
|
+
dependencies: unique(dependencies),
|
|
818
|
+
warnings: tw.scan.warnings,
|
|
819
|
+
cssScan: tw.scan
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
function buildProject(project, opts = {}) {
|
|
823
|
+
return writeProject(project, scanProject(project), opts);
|
|
824
|
+
}
|
|
825
|
+
function scanProject({ compiler }) {
|
|
826
|
+
const files = compiler.scan();
|
|
827
|
+
return {
|
|
828
|
+
files,
|
|
829
|
+
diagnostics: collectParseDiagnostics(compiler.parseFiles(files))
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
function writeProject({ compiler, cwd, outdir }, { files, diagnostics }, opts = {}) {
|
|
833
|
+
let artifacts = 0;
|
|
834
|
+
if (opts.codegen !== false) {
|
|
835
|
+
artifacts = compiler.writeArtifacts({ outdir, cwd }).length;
|
|
836
|
+
}
|
|
837
|
+
let cssPath;
|
|
838
|
+
if (opts.outfile !== false) {
|
|
839
|
+
const outfile = opts.outfile ?? relative(cwd, resolve5(outdir, "styles.css"));
|
|
840
|
+
cssPath = compiler.writeCss({ outfile, cwd }).path;
|
|
841
|
+
}
|
|
842
|
+
return {
|
|
843
|
+
files,
|
|
844
|
+
artifacts,
|
|
845
|
+
cssPath,
|
|
846
|
+
diagnostics: dedupeDiagnostics([...diagnostics, ...compiler.diagnostics()])
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
async function readCssConfig(file) {
|
|
850
|
+
try {
|
|
851
|
+
const config = JSON.parse(await readFile3(file, "utf8"));
|
|
852
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
853
|
+
throw new Error("expected a Panda config object");
|
|
854
|
+
}
|
|
855
|
+
for (const key of ["include", "exclude"]) {
|
|
856
|
+
if (config[key] !== undefined && (!Array.isArray(config[key]) || config[key].some((value) => typeof value !== "string"))) {
|
|
857
|
+
throw new Error(`"${key}" must be an array of strings`);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
if (config.presets !== undefined && !Array.isArray(config.presets)) {
|
|
861
|
+
throw new Error('"presets" must be an array');
|
|
862
|
+
}
|
|
863
|
+
if (config.theme !== undefined && (!config.theme || typeof config.theme !== "object" || Array.isArray(config.theme))) {
|
|
864
|
+
throw new Error('"theme" must be an object');
|
|
865
|
+
}
|
|
866
|
+
return config;
|
|
867
|
+
} catch (error) {
|
|
868
|
+
throw new PandatailDiagnosticError([
|
|
869
|
+
{
|
|
870
|
+
code: "panda-config",
|
|
871
|
+
severity: "error",
|
|
872
|
+
file,
|
|
873
|
+
message: `Could not load @panda config ${file}: ${error.message}`
|
|
874
|
+
}
|
|
875
|
+
]);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
function sourceToGlob(path, cwd) {
|
|
879
|
+
const rel = relative(cwd, path).split("\\").join("/");
|
|
880
|
+
const p = rel.startsWith(".") ? rel : `./${rel}`;
|
|
881
|
+
const hasGlob = /[*?{}\[\]]/.test(p);
|
|
882
|
+
if (!hasGlob && existsSync(path) && statSync(path).isDirectory()) {
|
|
883
|
+
return `${p}/**/*.${DEFAULT_EXT}`;
|
|
884
|
+
}
|
|
885
|
+
return p;
|
|
886
|
+
}
|
|
887
|
+
async function resolvePresets(list, cwd) {
|
|
888
|
+
const out = [];
|
|
889
|
+
for (const entry of list ?? []) {
|
|
890
|
+
const preset = await loadPreset(entry, cwd);
|
|
891
|
+
const { presets, ...rest } = preset;
|
|
892
|
+
out.push(...await resolvePresets(presets, cwd), rest);
|
|
893
|
+
}
|
|
894
|
+
return out;
|
|
895
|
+
}
|
|
896
|
+
async function loadPreset(entry, cwd) {
|
|
897
|
+
const value = await entry;
|
|
898
|
+
if (typeof value !== "string")
|
|
899
|
+
return value;
|
|
900
|
+
const req = createRequire(resolve5(cwd, "__pandatail_anchor__"));
|
|
901
|
+
let mod;
|
|
902
|
+
try {
|
|
903
|
+
mod = await import(req.resolve(value));
|
|
904
|
+
} catch {
|
|
905
|
+
mod = await import(value);
|
|
906
|
+
}
|
|
907
|
+
return mod.default ?? mod.preset ?? mod;
|
|
908
|
+
}
|
|
909
|
+
function unique(xs) {
|
|
910
|
+
return [...new Set(xs)];
|
|
911
|
+
}
|
|
912
|
+
var DEFAULT_EXT = "{js,jsx,ts,tsx,mdx}";
|
|
913
|
+
var init_project = __esm(() => {
|
|
914
|
+
init_diagnostics();
|
|
915
|
+
init_preset();
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
// src/studio.ts
|
|
919
|
+
init_project();
|
|
920
|
+
import { spawn } from "node:child_process";
|
|
921
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
922
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
923
|
+
import { constants, tmpdir } from "node:os";
|
|
924
|
+
import { dirname as dirname4, join, resolve as resolve6 } from "node:path";
|
|
925
|
+
async function studioConfig(options) {
|
|
926
|
+
const { config, dependencies, warnings } = await resolvePandatailConfig(options, true);
|
|
927
|
+
for (const warning of warnings)
|
|
928
|
+
console.warn(`pandatail: warning: ${warning}`);
|
|
929
|
+
return { ...config, dependencies: [...config.dependencies ?? [], ...dependencies] };
|
|
930
|
+
}
|
|
931
|
+
async function runPandatailStudio(options, { port, noOpen }) {
|
|
932
|
+
const require2 = createRequire2(import.meta.url);
|
|
933
|
+
const manifestPath = require2.resolve("@pandacss/dev/package.json");
|
|
934
|
+
const { bin, version } = require2(manifestPath);
|
|
935
|
+
const [major, minor] = version.split(".");
|
|
936
|
+
if (major !== "2" || !(Number(minor) >= 4)) {
|
|
937
|
+
throw new Error(`studio requires Panda CSS 2.4 or newer (found ${version})`);
|
|
938
|
+
}
|
|
939
|
+
const cwd = resolve6(options.cwd ?? process.cwd());
|
|
940
|
+
const dir = mkdtempSync(join(tmpdir(), "pandatail-studio-"));
|
|
941
|
+
try {
|
|
942
|
+
const config = join(dir, "panda.config.mjs");
|
|
943
|
+
const entry = new URL(import.meta.url.endsWith(".ts") ? "./studio.ts" : "./studio.js", import.meta.url);
|
|
944
|
+
writeFileSync(config, `
|
|
945
|
+
const { studioConfig } = await import(new URL(${JSON.stringify(entry.href)}).href);
|
|
946
|
+
export default await studioConfig(${JSON.stringify({ ...options, cwd })});
|
|
947
|
+
`);
|
|
948
|
+
const args = [resolve6(dirname4(manifestPath), bin.panda), "studio", "--cwd", cwd, "--config", config];
|
|
949
|
+
if (port !== undefined)
|
|
950
|
+
args.push(`--port=${port}`);
|
|
951
|
+
if (noOpen)
|
|
952
|
+
args.push("--no-open");
|
|
953
|
+
const child = spawn(process.execPath, args, { stdio: "inherit" });
|
|
954
|
+
const interrupt = () => child.kill("SIGINT");
|
|
955
|
+
const terminate = () => child.kill("SIGTERM");
|
|
956
|
+
process.on("SIGINT", interrupt);
|
|
957
|
+
process.on("SIGTERM", terminate);
|
|
958
|
+
try {
|
|
959
|
+
return await new Promise((done, reject) => {
|
|
960
|
+
child.once("error", reject);
|
|
961
|
+
child.once("exit", (code, signal) => done(code ?? (signal ? 128 + constants.signals[signal] : 1)));
|
|
962
|
+
});
|
|
963
|
+
} finally {
|
|
964
|
+
process.off("SIGINT", interrupt);
|
|
965
|
+
process.off("SIGTERM", terminate);
|
|
966
|
+
}
|
|
967
|
+
} finally {
|
|
968
|
+
rmSync(dir, { recursive: true, force: true });
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
export {
|
|
972
|
+
runPandatailStudio,
|
|
973
|
+
studioConfig
|
|
974
|
+
};
|