@dmisdm/pandatail 0.5.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 +217 -17
- package/dist/check.d.ts +14 -0
- package/dist/cli.js +879 -152
- package/dist/diagnostics.d.ts +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +619 -131
- package/dist/languageServer.d.ts +1 -0
- package/dist/pandaCss.d.ts +24 -0
- package/dist/preset.d.ts +9 -2
- package/dist/project.d.ts +10 -3
- package/dist/scanCss.d.ts +13 -4
- package/dist/studio.js +534 -140
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +709 -171
- package/editors/pandatail.css-data.json +14 -0
- package/package.json +6 -3
package/dist/vite.js
CHANGED
|
@@ -1,48 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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";
|
|
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
|
+
};
|
|
18
12
|
|
|
19
|
-
// src/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
+
});
|
|
23
45
|
|
|
24
46
|
// src/namespaces.ts
|
|
25
|
-
var TAILWIND_NAMESPACES = [
|
|
26
|
-
{ prefix: "font-weight", category: "fontWeights" },
|
|
27
|
-
{ prefix: "inset-shadow", category: "shadows" },
|
|
28
|
-
{ prefix: "drop-shadow", category: "dropShadows" },
|
|
29
|
-
{ prefix: "text-shadow", category: "shadows" },
|
|
30
|
-
{ prefix: "color", category: "colors" },
|
|
31
|
-
{ prefix: "spacing", category: "spacing" },
|
|
32
|
-
{ prefix: "font", category: "fonts" },
|
|
33
|
-
{ prefix: "text", category: "fontSizes" },
|
|
34
|
-
{ prefix: "tracking", category: "letterSpacings" },
|
|
35
|
-
{ prefix: "leading", category: "lineHeights" },
|
|
36
|
-
{ prefix: "breakpoint", category: "breakpoints" },
|
|
37
|
-
{ prefix: "container", category: "sizes" },
|
|
38
|
-
{ prefix: "radius", category: "radii" },
|
|
39
|
-
{ prefix: "shadow", category: "shadows" },
|
|
40
|
-
{ prefix: "blur", category: "blurs" },
|
|
41
|
-
{ prefix: "aspect", category: "aspectRatios" },
|
|
42
|
-
{ prefix: "ease", category: "easings" },
|
|
43
|
-
{ prefix: "animate", category: "animations" },
|
|
44
|
-
{ prefix: "perspective", category: "sizes" }
|
|
45
|
-
];
|
|
46
47
|
function deriveTokenPath(rest) {
|
|
47
48
|
const lastDash = rest.lastIndexOf("-");
|
|
48
49
|
if (lastDash > 0) {
|
|
@@ -70,57 +71,32 @@ function matchNamespace(themeKey) {
|
|
|
70
71
|
}
|
|
71
72
|
return null;
|
|
72
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
|
+
});
|
|
73
98
|
|
|
74
99
|
// src/derivedScales.ts
|
|
75
|
-
var TAILWIND_NUMERIC_STEPS = [
|
|
76
|
-
0,
|
|
77
|
-
0.5,
|
|
78
|
-
1,
|
|
79
|
-
1.5,
|
|
80
|
-
2,
|
|
81
|
-
2.5,
|
|
82
|
-
3,
|
|
83
|
-
3.5,
|
|
84
|
-
4,
|
|
85
|
-
5,
|
|
86
|
-
6,
|
|
87
|
-
7,
|
|
88
|
-
8,
|
|
89
|
-
9,
|
|
90
|
-
10,
|
|
91
|
-
11,
|
|
92
|
-
12,
|
|
93
|
-
14,
|
|
94
|
-
16,
|
|
95
|
-
20,
|
|
96
|
-
24,
|
|
97
|
-
28,
|
|
98
|
-
32,
|
|
99
|
-
36,
|
|
100
|
-
40,
|
|
101
|
-
44,
|
|
102
|
-
48,
|
|
103
|
-
52,
|
|
104
|
-
56,
|
|
105
|
-
60,
|
|
106
|
-
64,
|
|
107
|
-
72,
|
|
108
|
-
80,
|
|
109
|
-
96
|
|
110
|
-
];
|
|
111
|
-
var NAMED_SIZES = {
|
|
112
|
-
full: "100%",
|
|
113
|
-
screen: "100vw",
|
|
114
|
-
"screen-h": "100vh",
|
|
115
|
-
min: "min-content",
|
|
116
|
-
max: "max-content",
|
|
117
|
-
fit: "fit-content",
|
|
118
|
-
auto: "auto"
|
|
119
|
-
};
|
|
120
|
-
var NAMED_RADII = {
|
|
121
|
-
none: "0",
|
|
122
|
-
full: "9999px"
|
|
123
|
-
};
|
|
124
100
|
function synthesiseDerivedTokens(hasSpacingBase) {
|
|
125
101
|
const out = [];
|
|
126
102
|
if (hasSpacingBase) {
|
|
@@ -157,8 +133,63 @@ function pushNamed(out) {
|
|
|
157
133
|
});
|
|
158
134
|
}
|
|
159
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
|
+
});
|
|
160
188
|
|
|
161
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";
|
|
162
193
|
async function extractTokens(opts) {
|
|
163
194
|
return tokensFromTheme(await loadThemeEntries(opts));
|
|
164
195
|
}
|
|
@@ -192,48 +223,310 @@ async function extractTokensFromFile(path) {
|
|
|
192
223
|
const css = await readFile(path, "utf8");
|
|
193
224
|
return extractTokens({ css, base: dirname(resolve(path)) });
|
|
194
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
|
+
});
|
|
195
445
|
|
|
196
446
|
// src/scanCss.ts
|
|
197
|
-
import postcss
|
|
198
|
-
|
|
199
|
-
|
|
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";
|
|
200
452
|
function scanCss(opts, rootVariables) {
|
|
201
453
|
const out = {
|
|
202
454
|
sources: [],
|
|
203
455
|
excludes: [],
|
|
204
456
|
conditions: {},
|
|
205
457
|
warnings: [],
|
|
458
|
+
diagnostics: [],
|
|
206
459
|
files: opts.file ? [opts.file] : []
|
|
207
460
|
};
|
|
208
|
-
walk(opts
|
|
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
|
+
}
|
|
209
465
|
return out;
|
|
210
466
|
}
|
|
211
|
-
function walk(css, base, out, seen, rootVariables) {
|
|
467
|
+
function walk({ css, base, file, followImports }, out, seen, rootVariables, inReference = false) {
|
|
212
468
|
let root;
|
|
213
469
|
try {
|
|
214
|
-
root = postcss.parse(css);
|
|
215
|
-
} catch (
|
|
216
|
-
|
|
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));
|
|
217
475
|
return;
|
|
218
476
|
}
|
|
477
|
+
const inPandaFile = /\.panda\.css$/i.test(file ?? "") || root.nodes.some((node) => node.type === "atrule" && node.name === "panda");
|
|
219
478
|
root.walk((rule) => {
|
|
220
479
|
if (rule.type === "rule" && rootVariables)
|
|
221
480
|
collectRootVariables(rule, rootVariables);
|
|
222
481
|
if (rule.type !== "atrule")
|
|
223
482
|
return;
|
|
224
483
|
switch (rule.name) {
|
|
225
|
-
case "import":
|
|
226
|
-
|
|
484
|
+
case "import":
|
|
485
|
+
case "reference": {
|
|
486
|
+
if (followImports === false)
|
|
487
|
+
return;
|
|
488
|
+
const id = quoted2(rule.params) ?? urlTarget(rule.params);
|
|
227
489
|
if (!id || !id.startsWith("."))
|
|
228
490
|
return;
|
|
229
|
-
const path =
|
|
230
|
-
|
|
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)
|
|
231
495
|
return;
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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);
|
|
235
511
|
return;
|
|
236
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;
|
|
237
530
|
case "source":
|
|
238
531
|
return handleSource(rule, base, out);
|
|
239
532
|
case "custom-variant":
|
|
@@ -255,14 +548,14 @@ function collectRootVariables(rule, variables) {
|
|
|
255
548
|
function handleSource(rule, base, out) {
|
|
256
549
|
const params = rule.params.trim();
|
|
257
550
|
if (params.startsWith("inline(") || params.startsWith("not inline(")) {
|
|
258
|
-
out
|
|
551
|
+
warn(out, rule, "tailwind-source", `@source ${params}: inline sources have no Panda equivalent`);
|
|
259
552
|
return;
|
|
260
553
|
}
|
|
261
554
|
const isNot = /^not\s/.test(params);
|
|
262
|
-
const target =
|
|
555
|
+
const target = quoted2(isNot ? params.replace(/^not\s+/, "") : params);
|
|
263
556
|
if (!target)
|
|
264
557
|
return;
|
|
265
|
-
(isNot ? out.excludes : out.sources).push(
|
|
558
|
+
(isNot ? out.excludes : out.sources).push(resolve3(base, target));
|
|
266
559
|
}
|
|
267
560
|
function handleCustomVariant(rule, out) {
|
|
268
561
|
const params = rule.params.trim();
|
|
@@ -274,7 +567,7 @@ function handleCustomVariant(rule, out) {
|
|
|
274
567
|
if (m)
|
|
275
568
|
out.conditions[name] = m[1].trim();
|
|
276
569
|
else
|
|
277
|
-
out
|
|
570
|
+
warn(out, rule, "tailwind-variant", `@custom-variant ${name}: unrecognised form`);
|
|
278
571
|
return;
|
|
279
572
|
}
|
|
280
573
|
const body = rule.nodes.filter((n) => n.type !== "comment");
|
|
@@ -287,20 +580,31 @@ function handleCustomVariant(rule, out) {
|
|
|
287
580
|
out.conditions[name] = only.selector;
|
|
288
581
|
return;
|
|
289
582
|
}
|
|
290
|
-
out
|
|
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"));
|
|
291
588
|
}
|
|
292
589
|
function isSlotOnly(node) {
|
|
293
590
|
const kids = (node.nodes ?? []).filter((n) => n.type !== "comment");
|
|
294
591
|
return kids.length === 1 && kids[0].type === "atrule" && kids[0].name === "slot";
|
|
295
592
|
}
|
|
296
|
-
function
|
|
593
|
+
function quoted2(params) {
|
|
297
594
|
return /^\s*["']([^"']+)["']/.exec(params)?.[1] ?? null;
|
|
298
595
|
}
|
|
299
596
|
function urlTarget(params) {
|
|
300
597
|
return /^\s*url\(\s*["']?([^"')]+)["']?\s*\)/.exec(params)?.[1] ?? null;
|
|
301
598
|
}
|
|
599
|
+
var init_scanCss = __esm(() => {
|
|
600
|
+
init_diagnostics();
|
|
601
|
+
init_pandaCss();
|
|
602
|
+
});
|
|
302
603
|
|
|
303
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";
|
|
304
608
|
async function loadTailwind(opts, preview = false) {
|
|
305
609
|
let css;
|
|
306
610
|
let base;
|
|
@@ -309,16 +613,17 @@ async function loadTailwind(opts, preview = false) {
|
|
|
309
613
|
css = opts.css;
|
|
310
614
|
base = opts.base ?? process.cwd();
|
|
311
615
|
} else if (opts.cssPath != null) {
|
|
312
|
-
file =
|
|
616
|
+
file = resolve4(opts.cssPath);
|
|
313
617
|
css = await readFile2(file, "utf8");
|
|
314
618
|
base = dirname3(file);
|
|
315
619
|
} else {
|
|
316
620
|
throw new Error("pandatail: provide either `css` or `cssPath`");
|
|
317
621
|
}
|
|
622
|
+
const rootVariables = preview ? new Map : undefined;
|
|
623
|
+
const scan = scanCss({ css, base, file }, rootVariables);
|
|
318
624
|
const theme = await loadThemeEntries({ css, base });
|
|
319
625
|
const tokens = tokensFromTheme(theme);
|
|
320
|
-
const variables =
|
|
321
|
-
const scan = scanCss({ css, base, file }, variables);
|
|
626
|
+
const variables = rootVariables && new Map([...theme, ...rootVariables]);
|
|
322
627
|
const presetTokens = variables ? tokens.map((token) => ({
|
|
323
628
|
...token,
|
|
324
629
|
value: resolvePreviewValue(token.value, variables)
|
|
@@ -360,11 +665,14 @@ function buildPreset(tokens, scan) {
|
|
|
360
665
|
name: "tailwind",
|
|
361
666
|
theme: {
|
|
362
667
|
tokens: theme,
|
|
363
|
-
breakpoints
|
|
668
|
+
breakpoints,
|
|
669
|
+
...scan?.panda ? { extend: scan.panda.theme } : {}
|
|
364
670
|
}
|
|
365
671
|
});
|
|
366
672
|
if (scan && Object.keys(scan.conditions).length > 0) {
|
|
367
|
-
preset.conditions = {
|
|
673
|
+
preset.conditions = {
|
|
674
|
+
extend: scan.conditions
|
|
675
|
+
};
|
|
368
676
|
}
|
|
369
677
|
return preset;
|
|
370
678
|
}
|
|
@@ -402,38 +710,73 @@ function buildTree(tokens, category) {
|
|
|
402
710
|
}
|
|
403
711
|
return root;
|
|
404
712
|
}
|
|
713
|
+
var init_preset = __esm(() => {
|
|
714
|
+
init_extract();
|
|
715
|
+
init_scanCss();
|
|
716
|
+
});
|
|
405
717
|
|
|
406
718
|
// src/project.ts
|
|
407
|
-
|
|
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";
|
|
408
738
|
async function createPandatailProject(opts) {
|
|
409
739
|
const project = await resolvePandatailConfig(opts);
|
|
410
740
|
const compiler = createCompilerFromSnapshot(createConfigSnapshot(project.config));
|
|
411
741
|
return { compiler, ...project };
|
|
412
742
|
}
|
|
413
743
|
async function resolvePandatailConfig(opts, preview = false) {
|
|
414
|
-
const cwd =
|
|
415
|
-
const cssPath =
|
|
416
|
-
if (!
|
|
417
|
-
throw new
|
|
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
|
+
}
|
|
418
756
|
const tw = await loadTailwind({ cssPath }, preview);
|
|
419
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);
|
|
420
762
|
let user = {};
|
|
421
763
|
if (typeof opts.config === "string") {
|
|
422
|
-
const file =
|
|
764
|
+
const file = resolve5(cwd, opts.config);
|
|
423
765
|
const bundled = await bundleConfig(file, cwd);
|
|
424
766
|
user = bundled.config;
|
|
425
767
|
dependencies.push(file, ...bundled.dependencies);
|
|
426
768
|
} else if (opts.config) {
|
|
427
769
|
user = opts.config;
|
|
428
770
|
}
|
|
771
|
+
const { presets: cssPresetList, ...cssRest } = cssConfig;
|
|
429
772
|
const { presets: userPresetList, ...userRest } = user;
|
|
430
|
-
const
|
|
773
|
+
const presets = await resolvePresets([...cssPresetList ?? [], ...userPresetList ?? []], cwd);
|
|
431
774
|
const include = opts.include ?? unique([
|
|
432
|
-
...userRest.include ?? [`./src/**/*.${DEFAULT_EXT}`],
|
|
775
|
+
...userRest.include ?? cssRest.include ?? [`./src/**/*.${DEFAULT_EXT}`],
|
|
433
776
|
...tw.scan.sources.map((p) => sourceToGlob(p, cwd))
|
|
434
777
|
]);
|
|
435
778
|
const exclude = opts.exclude ?? unique([
|
|
436
|
-
...userRest.exclude ?? [],
|
|
779
|
+
...userRest.exclude ?? cssRest.exclude ?? [],
|
|
437
780
|
...tw.scan.excludes.map((p) => sourceToGlob(p, cwd))
|
|
438
781
|
]);
|
|
439
782
|
const defaults = {
|
|
@@ -460,8 +803,9 @@ async function resolvePandatailConfig(opts, preview = false) {
|
|
|
460
803
|
const merged = mergeConfigs([
|
|
461
804
|
defaults,
|
|
462
805
|
presetBase,
|
|
463
|
-
...
|
|
806
|
+
...presets,
|
|
464
807
|
tw.preset,
|
|
808
|
+
cssRest,
|
|
465
809
|
userRest,
|
|
466
810
|
finalOverrides
|
|
467
811
|
]);
|
|
@@ -469,31 +813,73 @@ async function resolvePandatailConfig(opts, preview = false) {
|
|
|
469
813
|
return {
|
|
470
814
|
config,
|
|
471
815
|
cwd,
|
|
472
|
-
outdir:
|
|
816
|
+
outdir: resolve5(cwd, config.outdir ?? "styled-system"),
|
|
473
817
|
dependencies: unique(dependencies),
|
|
474
|
-
warnings: tw.scan.warnings
|
|
818
|
+
warnings: tw.scan.warnings,
|
|
819
|
+
cssScan: tw.scan
|
|
475
820
|
};
|
|
476
821
|
}
|
|
477
822
|
function buildProject(project, opts = {}) {
|
|
478
|
-
|
|
823
|
+
return writeProject(project, scanProject(project), opts);
|
|
824
|
+
}
|
|
825
|
+
function scanProject({ compiler }) {
|
|
479
826
|
const files = compiler.scan();
|
|
480
|
-
|
|
827
|
+
return {
|
|
828
|
+
files,
|
|
829
|
+
diagnostics: collectParseDiagnostics(compiler.parseFiles(files))
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
function writeProject({ compiler, cwd, outdir }, { files, diagnostics }, opts = {}) {
|
|
481
833
|
let artifacts = 0;
|
|
482
834
|
if (opts.codegen !== false) {
|
|
483
835
|
artifacts = compiler.writeArtifacts({ outdir, cwd }).length;
|
|
484
836
|
}
|
|
485
837
|
let cssPath;
|
|
486
838
|
if (opts.outfile !== false) {
|
|
487
|
-
const outfile = opts.outfile ?? relative(cwd,
|
|
839
|
+
const outfile = opts.outfile ?? relative(cwd, resolve5(outdir, "styles.css"));
|
|
488
840
|
cssPath = compiler.writeCss({ outfile, cwd }).path;
|
|
489
841
|
}
|
|
490
|
-
return {
|
|
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
|
+
}
|
|
491
877
|
}
|
|
492
878
|
function sourceToGlob(path, cwd) {
|
|
493
879
|
const rel = relative(cwd, path).split("\\").join("/");
|
|
494
880
|
const p = rel.startsWith(".") ? rel : `./${rel}`;
|
|
495
881
|
const hasGlob = /[*?{}\[\]]/.test(p);
|
|
496
|
-
if (!hasGlob &&
|
|
882
|
+
if (!hasGlob && existsSync(path) && statSync(path).isDirectory()) {
|
|
497
883
|
return `${p}/**/*.${DEFAULT_EXT}`;
|
|
498
884
|
}
|
|
499
885
|
return p;
|
|
@@ -511,7 +897,7 @@ async function loadPreset(entry, cwd) {
|
|
|
511
897
|
const value = await entry;
|
|
512
898
|
if (typeof value !== "string")
|
|
513
899
|
return value;
|
|
514
|
-
const req = createRequire(
|
|
900
|
+
const req = createRequire(resolve5(cwd, "__pandatail_anchor__"));
|
|
515
901
|
let mod;
|
|
516
902
|
try {
|
|
517
903
|
mod = await import(req.resolve(value));
|
|
@@ -523,28 +909,156 @@ async function loadPreset(entry, cwd) {
|
|
|
523
909
|
function unique(xs) {
|
|
524
910
|
return [...new Set(xs)];
|
|
525
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/check.ts
|
|
919
|
+
import { dedupeDiagnostics as dedupeDiagnostics2 } from "@pandacss/compiler-shared";
|
|
920
|
+
import { dirname as dirname4, resolve as resolve6 } from "node:path";
|
|
921
|
+
function checkPandaDocument(css, file) {
|
|
922
|
+
return scanCss({
|
|
923
|
+
css,
|
|
924
|
+
base: dirname4(file),
|
|
925
|
+
file,
|
|
926
|
+
recover: true,
|
|
927
|
+
followImports: false
|
|
928
|
+
}).diagnostics.filter((issue) => issue.severity === "error");
|
|
929
|
+
}
|
|
930
|
+
async function checkProject(options) {
|
|
931
|
+
try {
|
|
932
|
+
return checkLoadedProject(await createPandatailProject(options));
|
|
933
|
+
} catch (error) {
|
|
934
|
+
return {
|
|
935
|
+
files: [],
|
|
936
|
+
diagnostics: projectIssues(error, resolve6(options.cwd ?? process.cwd(), options.css))
|
|
937
|
+
};
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
function checkLoadedProject(project) {
|
|
941
|
+
const { files, diagnostics } = scanProject(project);
|
|
942
|
+
return {
|
|
943
|
+
files,
|
|
944
|
+
diagnostics: dedupeDiagnostics2([
|
|
945
|
+
...project.cssScan?.diagnostics ?? [],
|
|
946
|
+
...checkReferences(project),
|
|
947
|
+
...diagnostics,
|
|
948
|
+
...project.compiler.diagnostics()
|
|
949
|
+
])
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
function projectIssues(error, file) {
|
|
953
|
+
if (error instanceof PandatailDiagnosticError)
|
|
954
|
+
return dedupeDiagnostics2(error.diagnostics);
|
|
955
|
+
return [
|
|
956
|
+
{
|
|
957
|
+
code: "project-load",
|
|
958
|
+
severity: "error",
|
|
959
|
+
file,
|
|
960
|
+
message: error instanceof Error ? error.message : String(error)
|
|
961
|
+
}
|
|
962
|
+
];
|
|
963
|
+
}
|
|
964
|
+
function checkReferences(project) {
|
|
965
|
+
const references = project.cssScan?.panda?.references ?? [];
|
|
966
|
+
if (!references.length)
|
|
967
|
+
return [];
|
|
968
|
+
const spec = project.compiler.spec();
|
|
969
|
+
return references.flatMap(({ category, name, ...site }) => {
|
|
970
|
+
if (category === "tokens") {
|
|
971
|
+
return Object.hasOwn(spec.tokens.values, name) ? [] : [
|
|
972
|
+
{
|
|
973
|
+
...site,
|
|
974
|
+
severity: "error",
|
|
975
|
+
code: "panda-token-reference",
|
|
976
|
+
message: `Unknown Panda token: ${name}. Use a full token path, or var() for a CSS variable.`
|
|
977
|
+
}
|
|
978
|
+
];
|
|
979
|
+
}
|
|
980
|
+
const property = category.slice(0, -1);
|
|
981
|
+
const names = spec.utilities.properties[property]?.literals ?? [];
|
|
982
|
+
if (names.includes(name))
|
|
983
|
+
return [];
|
|
984
|
+
const choices = names.slice(0, 5).join(", ");
|
|
985
|
+
return [
|
|
986
|
+
{
|
|
987
|
+
...site,
|
|
988
|
+
severity: "error",
|
|
989
|
+
code: "panda-composition-reference",
|
|
990
|
+
message: `Unknown ${property}: ${name}.${choices ? ` Available: ${choices}.` : ""}`
|
|
991
|
+
}
|
|
992
|
+
];
|
|
993
|
+
});
|
|
994
|
+
}
|
|
995
|
+
var init_check = __esm(() => {
|
|
996
|
+
init_diagnostics();
|
|
997
|
+
init_project();
|
|
998
|
+
init_scanCss();
|
|
999
|
+
});
|
|
526
1000
|
|
|
527
1001
|
// src/vite.ts
|
|
1002
|
+
init_check();
|
|
1003
|
+
init_diagnostics();
|
|
1004
|
+
init_project();
|
|
1005
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
1006
|
+
import { relative as relative2, resolve as resolve7, sep } from "node:path";
|
|
528
1007
|
function pandatail(options) {
|
|
529
1008
|
const { outfile, verbose, ...projectOptions } = options;
|
|
530
1009
|
let root = process.cwd();
|
|
531
1010
|
let isServe = false;
|
|
532
1011
|
let project;
|
|
1012
|
+
let dependencies = new Set;
|
|
1013
|
+
let devServer;
|
|
1014
|
+
let hadError = false;
|
|
1015
|
+
let updates = Promise.resolve();
|
|
1016
|
+
let warn = console.warn;
|
|
533
1017
|
const log = (msg) => {
|
|
534
1018
|
if (verbose ?? isServe)
|
|
535
1019
|
console.log(`[pandatail] ${msg}`);
|
|
536
1020
|
};
|
|
537
|
-
const load = async () => {
|
|
538
|
-
const
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
1021
|
+
const load = async (watchFile) => {
|
|
1022
|
+
const cwd = resolve7(projectOptions.cwd ?? root);
|
|
1023
|
+
const watched = new Set;
|
|
1024
|
+
const remember = (file) => {
|
|
1025
|
+
const path = resolve7(cwd, file);
|
|
1026
|
+
if (watched.has(path))
|
|
1027
|
+
return;
|
|
1028
|
+
watched.add(path);
|
|
1029
|
+
dependencies.add(path);
|
|
1030
|
+
watchFile(path);
|
|
1031
|
+
};
|
|
1032
|
+
remember(projectOptions.css);
|
|
1033
|
+
if (typeof projectOptions.config === "string")
|
|
1034
|
+
remember(projectOptions.config);
|
|
1035
|
+
try {
|
|
1036
|
+
const next = await createPandatailProject({ ...projectOptions, cwd });
|
|
1037
|
+
for (const dep of next.dependencies)
|
|
1038
|
+
remember(dep);
|
|
1039
|
+
dependencies = watched;
|
|
1040
|
+
project = next;
|
|
1041
|
+
return next;
|
|
1042
|
+
} catch (error) {
|
|
1043
|
+
if (error instanceof PandatailDiagnosticError) {
|
|
1044
|
+
for (const { file } of error.diagnostics)
|
|
1045
|
+
if (file)
|
|
1046
|
+
remember(file);
|
|
1047
|
+
}
|
|
1048
|
+
throw error;
|
|
1049
|
+
}
|
|
543
1050
|
};
|
|
544
1051
|
const run = (p, codegen) => {
|
|
545
|
-
const
|
|
546
|
-
|
|
547
|
-
|
|
1052
|
+
const checked = checkLoadedProject(p);
|
|
1053
|
+
if (checked.diagnostics.some((issue) => issue.severity === "error")) {
|
|
1054
|
+
throw new PandatailDiagnosticError(checked.diagnostics);
|
|
1055
|
+
}
|
|
1056
|
+
const r = writeProject(p, checked, { codegen, outfile });
|
|
1057
|
+
if (r.diagnostics.some((issue) => issue.severity === "error")) {
|
|
1058
|
+
throw new PandatailDiagnosticError(r.diagnostics);
|
|
1059
|
+
}
|
|
1060
|
+
for (const issue of r.diagnostics)
|
|
1061
|
+
warn(`[pandatail] ${formatCheckDiagnostic(issue)}`);
|
|
548
1062
|
const rel = (f) => relative2(p.cwd, f) || f;
|
|
549
1063
|
log([
|
|
550
1064
|
`${r.files.length} source file(s)`,
|
|
@@ -552,61 +1066,75 @@ function pandatail(options) {
|
|
|
552
1066
|
r.cssPath ? `css → ${rel(r.cssPath)}` : ""
|
|
553
1067
|
].filter(Boolean).join(", "));
|
|
554
1068
|
};
|
|
1069
|
+
const reportDevError = (server, error) => {
|
|
1070
|
+
hadError = true;
|
|
1071
|
+
const err = toViteError(error);
|
|
1072
|
+
server.config.logger.error(`[pandatail] ${err.message}`);
|
|
1073
|
+
server.ws.send({ type: "error", err: { ...err, plugin: "pandatail" } });
|
|
1074
|
+
};
|
|
555
1075
|
return {
|
|
556
1076
|
name: "pandatail",
|
|
557
1077
|
enforce: "pre",
|
|
558
1078
|
configResolved(config) {
|
|
559
1079
|
root = config.root;
|
|
560
1080
|
isServe = config.command === "serve";
|
|
1081
|
+
warn = (message) => config.logger.warn(message);
|
|
561
1082
|
},
|
|
562
1083
|
async buildStart() {
|
|
563
|
-
const
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
1084
|
+
const build = async () => run(await load((file) => this.addWatchFile(file)), true);
|
|
1085
|
+
const server = isServe ? devServer : undefined;
|
|
1086
|
+
if (server) {
|
|
1087
|
+
updates = updates.then(build).catch((error) => reportDevError(server, error));
|
|
1088
|
+
await updates;
|
|
1089
|
+
} else {
|
|
1090
|
+
try {
|
|
1091
|
+
await build();
|
|
1092
|
+
} catch (error) {
|
|
1093
|
+
this.error(toViteError(error));
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
567
1096
|
},
|
|
568
1097
|
configureServer(server) {
|
|
1098
|
+
devServer = server;
|
|
569
1099
|
const pending = new Set;
|
|
570
1100
|
let timer;
|
|
571
|
-
let chain = Promise.resolve();
|
|
572
1101
|
const flush = async () => {
|
|
573
1102
|
const changed = [...pending];
|
|
574
1103
|
pending.clear();
|
|
575
1104
|
const p = project;
|
|
576
|
-
if (
|
|
1105
|
+
if (changed.length === 0)
|
|
577
1106
|
return;
|
|
1107
|
+
const reloadProject = !p || changed.some((file) => dependencies.has(file));
|
|
578
1108
|
try {
|
|
579
|
-
if (
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
1109
|
+
if (reloadProject) {
|
|
1110
|
+
run(await load((file) => server.watcher.add(file)), true);
|
|
1111
|
+
} else {
|
|
1112
|
+
for (const file of changed) {
|
|
1113
|
+
if (existsSync2(file))
|
|
1114
|
+
p.compiler.refreshFile(file);
|
|
1115
|
+
else
|
|
1116
|
+
p.compiler.removeFile(file);
|
|
1117
|
+
}
|
|
1118
|
+
run(p, false);
|
|
585
1119
|
}
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
}
|
|
592
|
-
run(p, false);
|
|
593
|
-
} catch (e) {
|
|
594
|
-
server.config.logger.error(`[pandatail] ${e.message}`);
|
|
1120
|
+
if (reloadProject || hadError)
|
|
1121
|
+
server.ws.send({ type: "full-reload" });
|
|
1122
|
+
hadError = false;
|
|
1123
|
+
} catch (error) {
|
|
1124
|
+
reportDevError(server, error);
|
|
595
1125
|
}
|
|
596
1126
|
};
|
|
597
1127
|
const onFsEvent = (file) => {
|
|
598
1128
|
const p = project;
|
|
599
|
-
|
|
1129
|
+
const abs = resolve7(file);
|
|
1130
|
+
if (p && abs.startsWith(p.outdir + sep) || abs.split(sep).includes("node_modules"))
|
|
600
1131
|
return;
|
|
601
|
-
|
|
602
|
-
if (abs.startsWith(p.outdir + sep) || abs.split(sep).includes("node_modules"))
|
|
603
|
-
return;
|
|
604
|
-
if (!p.dependencies.includes(abs) && !p.compiler.isSourceFile(abs))
|
|
1132
|
+
if (!dependencies.has(abs) && !p?.compiler.isSourceFile(abs))
|
|
605
1133
|
return;
|
|
606
1134
|
pending.add(abs);
|
|
607
1135
|
clearTimeout(timer);
|
|
608
1136
|
timer = setTimeout(() => {
|
|
609
|
-
|
|
1137
|
+
updates = updates.then(flush);
|
|
610
1138
|
}, 40);
|
|
611
1139
|
};
|
|
612
1140
|
server.watcher.on("change", onFsEvent);
|
|
@@ -615,6 +1143,16 @@ function pandatail(options) {
|
|
|
615
1143
|
}
|
|
616
1144
|
};
|
|
617
1145
|
}
|
|
1146
|
+
function toViteError(error) {
|
|
1147
|
+
const issue = error instanceof PandatailDiagnosticError ? error.diagnostics.find((issue) => issue.severity === "error" && issue.file) : undefined;
|
|
1148
|
+
const loc = issue?.location?.start;
|
|
1149
|
+
return {
|
|
1150
|
+
message: error instanceof Error ? error.message : String(error),
|
|
1151
|
+
stack: error instanceof PandatailDiagnosticError ? "" : error instanceof Error ? error.stack ?? "" : "",
|
|
1152
|
+
id: issue?.file,
|
|
1153
|
+
loc: loc && { file: issue?.file, line: loc.line, column: loc.column - 1 }
|
|
1154
|
+
};
|
|
1155
|
+
}
|
|
618
1156
|
var vite_default = pandatail;
|
|
619
1157
|
export {
|
|
620
1158
|
vite_default as default,
|