@dmisdm/pandatail 0.2.0 → 0.4.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 +90 -83
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +610 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +320 -233
- package/dist/preset.d.ts +36 -13
- package/dist/project.d.ts +74 -0
- package/dist/scanCss.d.ts +30 -0
- package/dist/vite.d.ts +19 -0
- package/dist/vite.js +579 -0
- package/package.json +33 -14
- package/LICENSE +0 -21
- package/dist/extractSync.d.ts +0 -19
package/dist/index.js
CHANGED
|
@@ -1,20 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
// src/project.ts
|
|
2
|
+
import { bundleConfig, createConfigSnapshot, mergeConfigs } from "@pandacss/config";
|
|
3
|
+
import { createCompilerFromSnapshot } from "@pandacss/compiler";
|
|
4
|
+
import { applyConfigDefaults, formatDiagnostic } from "@pandacss/compiler-shared";
|
|
5
|
+
import presetBase from "@pandacss/preset-base";
|
|
6
|
+
import { createRequire } from "node:module";
|
|
7
|
+
import { existsSync as existsSync2, statSync } from "node:fs";
|
|
8
|
+
import { relative, resolve as resolve4 } from "node:path";
|
|
9
|
+
|
|
10
|
+
// src/preset.ts
|
|
11
|
+
import { definePreset } from "@pandacss/dev";
|
|
12
|
+
import { readFile as readFile2 } from "node:fs/promises";
|
|
13
|
+
import { dirname as dirname3, resolve as resolve3 } from "node:path";
|
|
14
|
+
|
|
15
|
+
// src/extract.ts
|
|
16
|
+
import { __unstable__loadDesignSystem } from "@tailwindcss/node";
|
|
17
|
+
import { readFile } from "node:fs/promises";
|
|
18
|
+
import { dirname, resolve } from "node:path";
|
|
16
19
|
|
|
17
20
|
// src/namespaces.ts
|
|
21
|
+
var TAILWIND_NAMESPACES = [
|
|
22
|
+
{ prefix: "font-weight", category: "fontWeights" },
|
|
23
|
+
{ prefix: "inset-shadow", category: "shadows" },
|
|
24
|
+
{ prefix: "drop-shadow", category: "dropShadows" },
|
|
25
|
+
{ prefix: "text-shadow", category: "shadows" },
|
|
26
|
+
{ prefix: "color", category: "colors" },
|
|
27
|
+
{ prefix: "spacing", category: "spacing" },
|
|
28
|
+
{ prefix: "font", category: "fonts" },
|
|
29
|
+
{ prefix: "text", category: "fontSizes" },
|
|
30
|
+
{ prefix: "tracking", category: "letterSpacings" },
|
|
31
|
+
{ prefix: "leading", category: "lineHeights" },
|
|
32
|
+
{ prefix: "breakpoint", category: "breakpoints" },
|
|
33
|
+
{ prefix: "container", category: "sizes" },
|
|
34
|
+
{ prefix: "radius", category: "radii" },
|
|
35
|
+
{ prefix: "shadow", category: "shadows" },
|
|
36
|
+
{ prefix: "blur", category: "blurs" },
|
|
37
|
+
{ prefix: "aspect", category: "aspectRatios" },
|
|
38
|
+
{ prefix: "ease", category: "easings" },
|
|
39
|
+
{ prefix: "animate", category: "animations" },
|
|
40
|
+
{ prefix: "perspective", category: "sizes" }
|
|
41
|
+
];
|
|
18
42
|
function deriveTokenPath(rest) {
|
|
19
43
|
const lastDash = rest.lastIndexOf("-");
|
|
20
44
|
if (lastDash > 0) {
|
|
@@ -42,32 +66,57 @@ function matchNamespace(themeKey) {
|
|
|
42
66
|
}
|
|
43
67
|
return null;
|
|
44
68
|
}
|
|
45
|
-
var TAILWIND_NAMESPACES;
|
|
46
|
-
var init_namespaces = __esm(() => {
|
|
47
|
-
TAILWIND_NAMESPACES = [
|
|
48
|
-
{ prefix: "font-weight", category: "fontWeights" },
|
|
49
|
-
{ prefix: "inset-shadow", category: "shadows" },
|
|
50
|
-
{ prefix: "drop-shadow", category: "dropShadows" },
|
|
51
|
-
{ prefix: "text-shadow", category: "shadows" },
|
|
52
|
-
{ prefix: "color", category: "colors" },
|
|
53
|
-
{ prefix: "spacing", category: "spacing" },
|
|
54
|
-
{ prefix: "font", category: "fonts" },
|
|
55
|
-
{ prefix: "text", category: "fontSizes" },
|
|
56
|
-
{ prefix: "tracking", category: "letterSpacings" },
|
|
57
|
-
{ prefix: "leading", category: "lineHeights" },
|
|
58
|
-
{ prefix: "breakpoint", category: "breakpoints" },
|
|
59
|
-
{ prefix: "container", category: "sizes" },
|
|
60
|
-
{ prefix: "radius", category: "radii" },
|
|
61
|
-
{ prefix: "shadow", category: "shadows" },
|
|
62
|
-
{ prefix: "blur", category: "blurs" },
|
|
63
|
-
{ prefix: "aspect", category: "aspectRatios" },
|
|
64
|
-
{ prefix: "ease", category: "easings" },
|
|
65
|
-
{ prefix: "animate", category: "animations" },
|
|
66
|
-
{ prefix: "perspective", category: "sizes" }
|
|
67
|
-
];
|
|
68
|
-
});
|
|
69
69
|
|
|
70
70
|
// src/derivedScales.ts
|
|
71
|
+
var TAILWIND_NUMERIC_STEPS = [
|
|
72
|
+
0,
|
|
73
|
+
0.5,
|
|
74
|
+
1,
|
|
75
|
+
1.5,
|
|
76
|
+
2,
|
|
77
|
+
2.5,
|
|
78
|
+
3,
|
|
79
|
+
3.5,
|
|
80
|
+
4,
|
|
81
|
+
5,
|
|
82
|
+
6,
|
|
83
|
+
7,
|
|
84
|
+
8,
|
|
85
|
+
9,
|
|
86
|
+
10,
|
|
87
|
+
11,
|
|
88
|
+
12,
|
|
89
|
+
14,
|
|
90
|
+
16,
|
|
91
|
+
20,
|
|
92
|
+
24,
|
|
93
|
+
28,
|
|
94
|
+
32,
|
|
95
|
+
36,
|
|
96
|
+
40,
|
|
97
|
+
44,
|
|
98
|
+
48,
|
|
99
|
+
52,
|
|
100
|
+
56,
|
|
101
|
+
60,
|
|
102
|
+
64,
|
|
103
|
+
72,
|
|
104
|
+
80,
|
|
105
|
+
96
|
|
106
|
+
];
|
|
107
|
+
var NAMED_SIZES = {
|
|
108
|
+
full: "100%",
|
|
109
|
+
screen: "100vw",
|
|
110
|
+
"screen-h": "100vh",
|
|
111
|
+
min: "min-content",
|
|
112
|
+
max: "max-content",
|
|
113
|
+
fit: "fit-content",
|
|
114
|
+
auto: "auto"
|
|
115
|
+
};
|
|
116
|
+
var NAMED_RADII = {
|
|
117
|
+
none: "0",
|
|
118
|
+
full: "9999px"
|
|
119
|
+
};
|
|
71
120
|
function synthesiseDerivedTokens(hasSpacingBase) {
|
|
72
121
|
const out = [];
|
|
73
122
|
if (hasSpacingBase) {
|
|
@@ -104,94 +153,11 @@ function pushNamed(out) {
|
|
|
104
153
|
});
|
|
105
154
|
}
|
|
106
155
|
}
|
|
107
|
-
var TAILWIND_NUMERIC_STEPS, NAMED_SIZES, NAMED_RADII;
|
|
108
|
-
var init_derivedScales = __esm(() => {
|
|
109
|
-
TAILWIND_NUMERIC_STEPS = [
|
|
110
|
-
0,
|
|
111
|
-
0.5,
|
|
112
|
-
1,
|
|
113
|
-
1.5,
|
|
114
|
-
2,
|
|
115
|
-
2.5,
|
|
116
|
-
3,
|
|
117
|
-
3.5,
|
|
118
|
-
4,
|
|
119
|
-
5,
|
|
120
|
-
6,
|
|
121
|
-
7,
|
|
122
|
-
8,
|
|
123
|
-
9,
|
|
124
|
-
10,
|
|
125
|
-
11,
|
|
126
|
-
12,
|
|
127
|
-
14,
|
|
128
|
-
16,
|
|
129
|
-
20,
|
|
130
|
-
24,
|
|
131
|
-
28,
|
|
132
|
-
32,
|
|
133
|
-
36,
|
|
134
|
-
40,
|
|
135
|
-
44,
|
|
136
|
-
48,
|
|
137
|
-
52,
|
|
138
|
-
56,
|
|
139
|
-
60,
|
|
140
|
-
64,
|
|
141
|
-
72,
|
|
142
|
-
80,
|
|
143
|
-
96
|
|
144
|
-
];
|
|
145
|
-
NAMED_SIZES = {
|
|
146
|
-
full: "100%",
|
|
147
|
-
screen: "100vw",
|
|
148
|
-
"screen-h": "100vh",
|
|
149
|
-
min: "min-content",
|
|
150
|
-
max: "max-content",
|
|
151
|
-
fit: "fit-content",
|
|
152
|
-
auto: "auto"
|
|
153
|
-
};
|
|
154
|
-
NAMED_RADII = {
|
|
155
|
-
none: "0",
|
|
156
|
-
full: "9999px"
|
|
157
|
-
};
|
|
158
|
-
});
|
|
159
156
|
|
|
160
157
|
// src/extract.ts
|
|
161
|
-
var exports_extract = {};
|
|
162
|
-
__export(exports_extract, {
|
|
163
|
-
extractTokensFromFile: () => extractTokensFromFile,
|
|
164
|
-
extractTokens: () => extractTokens
|
|
165
|
-
});
|
|
166
|
-
import { __unstable__loadDesignSystem } from "tailwindcss";
|
|
167
|
-
import { readFile } from "node:fs/promises";
|
|
168
|
-
import { createRequire } from "node:module";
|
|
169
|
-
import { dirname, resolve } from "node:path";
|
|
170
|
-
function resolveStylesheet(id, basedir) {
|
|
171
|
-
if (id.startsWith(".") || id.startsWith("/")) {
|
|
172
|
-
return resolve(basedir, id);
|
|
173
|
-
}
|
|
174
|
-
const candidates = [`${id}/index.css`, `${id}.css`, id];
|
|
175
|
-
for (const candidate of candidates) {
|
|
176
|
-
try {
|
|
177
|
-
return requireFromHere.resolve(candidate, { paths: [basedir] });
|
|
178
|
-
} catch {}
|
|
179
|
-
}
|
|
180
|
-
throw new Error(`pandatail: cannot resolve stylesheet '${id}' from ${basedir}`);
|
|
181
|
-
}
|
|
182
158
|
async function extractTokens(opts) {
|
|
183
|
-
const base = opts.base ?? process.cwd();
|
|
184
|
-
const ds = await __unstable__loadDesignSystem(opts.css, {
|
|
185
|
-
base,
|
|
186
|
-
loadStylesheet: async (id, basedir) => {
|
|
187
|
-
const path = resolveStylesheet(id, basedir);
|
|
188
|
-
const content = await readFile(path, "utf8");
|
|
189
|
-
return { path, base: dirname(path), content };
|
|
190
|
-
},
|
|
191
|
-
loadModule: async () => {
|
|
192
|
-
throw new Error("loadModule is not supported in pandatail extraction");
|
|
193
|
-
}
|
|
194
|
-
});
|
|
159
|
+
const base = resolve(opts.base ?? process.cwd());
|
|
160
|
+
const ds = await __unstable__loadDesignSystem(opts.css, { base });
|
|
195
161
|
const themeEntries = new Map;
|
|
196
162
|
for (const [key, entry] of ds.theme.entries())
|
|
197
163
|
themeEntries.set(key, entry.value);
|
|
@@ -216,112 +182,122 @@ async function extractTokensFromFile(path) {
|
|
|
216
182
|
const css = await readFile(path, "utf8");
|
|
217
183
|
return extractTokens({ css, base: dirname(resolve(path)) });
|
|
218
184
|
}
|
|
219
|
-
var requireFromHere;
|
|
220
|
-
var init_extract = __esm(() => {
|
|
221
|
-
init_namespaces();
|
|
222
|
-
init_derivedScales();
|
|
223
|
-
requireFromHere = createRequire(`${process.cwd()}/__pandatail_anchor__`);
|
|
224
|
-
});
|
|
225
185
|
|
|
226
|
-
// src/
|
|
227
|
-
init_extract();
|
|
228
|
-
import { definePreset } from "@pandacss/dev";
|
|
229
|
-
|
|
230
|
-
// src/extractSync.ts
|
|
231
|
-
init_namespaces();
|
|
232
|
-
init_derivedScales();
|
|
186
|
+
// src/scanCss.ts
|
|
233
187
|
import postcss from "postcss";
|
|
234
|
-
import { readFileSync } from "node:fs";
|
|
235
|
-
import { createRequire as createRequire2 } from "node:module";
|
|
188
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
236
189
|
import { dirname as dirname2, resolve as resolve2 } from "node:path";
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
css = readFileSync(abs, "utf8");
|
|
247
|
-
base = dirname2(abs);
|
|
248
|
-
} else {
|
|
249
|
-
throw new Error("extractTokensSync: provide either `css` or `cssPath`");
|
|
250
|
-
}
|
|
251
|
-
const decls = new Map;
|
|
252
|
-
collectThemeDecls(css, base, decls, new Set);
|
|
253
|
-
const out = [];
|
|
254
|
-
for (const [cssVar, rawValue] of decls) {
|
|
255
|
-
const matched = matchNamespace(cssVar);
|
|
256
|
-
if (!matched)
|
|
257
|
-
continue;
|
|
258
|
-
if (matched.rest === "DEFAULT")
|
|
259
|
-
continue;
|
|
260
|
-
out.push({
|
|
261
|
-
cssVar,
|
|
262
|
-
value: matched.mapping.category === "breakpoints" ? rawValue : `var(${cssVar})`,
|
|
263
|
-
category: matched.mapping.category,
|
|
264
|
-
path: deriveTokenPath(matched.rest)
|
|
265
|
-
});
|
|
266
|
-
}
|
|
267
|
-
out.push(...synthesiseDerivedTokens(decls.has("--spacing")));
|
|
190
|
+
function scanCss(opts) {
|
|
191
|
+
const out = {
|
|
192
|
+
sources: [],
|
|
193
|
+
excludes: [],
|
|
194
|
+
conditions: {},
|
|
195
|
+
warnings: [],
|
|
196
|
+
files: opts.file ? [opts.file] : []
|
|
197
|
+
};
|
|
198
|
+
walk(opts.css, opts.base, out, new Set(opts.file ? [opts.file] : []));
|
|
268
199
|
return out;
|
|
269
200
|
}
|
|
270
|
-
function
|
|
271
|
-
|
|
201
|
+
function walk(css, base, out, seen) {
|
|
202
|
+
let root;
|
|
203
|
+
try {
|
|
204
|
+
root = postcss.parse(css);
|
|
205
|
+
} catch (e) {
|
|
206
|
+
out.warnings.push(`could not parse CSS in ${base}: ${e.message}`);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
272
209
|
root.walkAtRules((rule) => {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
210
|
+
switch (rule.name) {
|
|
211
|
+
case "import": {
|
|
212
|
+
const id = quoted(rule.params) ?? urlTarget(rule.params);
|
|
213
|
+
if (!id || !id.startsWith("."))
|
|
214
|
+
return;
|
|
215
|
+
const path = resolve2(base, id);
|
|
216
|
+
if (seen.has(path) || !existsSync(path))
|
|
217
|
+
return;
|
|
218
|
+
seen.add(path);
|
|
219
|
+
out.files.push(path);
|
|
220
|
+
walk(readFileSync(path, "utf8"), dirname2(path), out, seen);
|
|
279
221
|
return;
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
if (d.prop.startsWith("--")) {
|
|
286
|
-
decls.set(d.prop, d.value);
|
|
287
|
-
}
|
|
288
|
-
});
|
|
222
|
+
}
|
|
223
|
+
case "source":
|
|
224
|
+
return handleSource(rule, base, out);
|
|
225
|
+
case "custom-variant":
|
|
226
|
+
return handleCustomVariant(rule, out);
|
|
289
227
|
}
|
|
290
228
|
});
|
|
291
229
|
}
|
|
292
|
-
function
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
return
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
230
|
+
function handleSource(rule, base, out) {
|
|
231
|
+
const params = rule.params.trim();
|
|
232
|
+
if (params.startsWith("inline(") || params.startsWith("not inline(")) {
|
|
233
|
+
out.warnings.push(`@source ${params}: inline sources have no Panda equivalent`);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
const isNot = /^not\s/.test(params);
|
|
237
|
+
const target = quoted(isNot ? params.replace(/^not\s+/, "") : params);
|
|
238
|
+
if (!target)
|
|
239
|
+
return;
|
|
240
|
+
(isNot ? out.excludes : out.sources).push(resolve2(base, target));
|
|
301
241
|
}
|
|
302
|
-
function
|
|
303
|
-
|
|
304
|
-
|
|
242
|
+
function handleCustomVariant(rule, out) {
|
|
243
|
+
const params = rule.params.trim();
|
|
244
|
+
const name = /^([\w-]+)/.exec(params)?.[1];
|
|
245
|
+
if (!name)
|
|
246
|
+
return;
|
|
247
|
+
if (!rule.nodes) {
|
|
248
|
+
const m = /^[\w-]+\s*\(([\s\S]+)\)$/.exec(params);
|
|
249
|
+
if (m)
|
|
250
|
+
out.conditions[name] = m[1].trim();
|
|
251
|
+
else
|
|
252
|
+
out.warnings.push(`@custom-variant ${name}: unrecognised form`);
|
|
253
|
+
return;
|
|
305
254
|
}
|
|
306
|
-
const
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
255
|
+
const body = rule.nodes.filter((n) => n.type !== "comment");
|
|
256
|
+
const only = body.length === 1 ? body[0] : undefined;
|
|
257
|
+
if (only?.type === "atrule" && only.name !== "slot" && isSlotOnly(only)) {
|
|
258
|
+
out.conditions[name] = `@${only.name} ${only.params}`.trim();
|
|
259
|
+
return;
|
|
311
260
|
}
|
|
312
|
-
|
|
261
|
+
if (only?.type === "rule" && isSlotOnly(only)) {
|
|
262
|
+
out.conditions[name] = only.selector;
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
out.warnings.push(`@custom-variant ${name}: block form is too complex to map to a Panda condition`);
|
|
266
|
+
}
|
|
267
|
+
function isSlotOnly(node) {
|
|
268
|
+
const kids = (node.nodes ?? []).filter((n) => n.type !== "comment");
|
|
269
|
+
return kids.length === 1 && kids[0].type === "atrule" && kids[0].name === "slot";
|
|
270
|
+
}
|
|
271
|
+
function quoted(params) {
|
|
272
|
+
return /^\s*["']([^"']+)["']/.exec(params)?.[1] ?? null;
|
|
273
|
+
}
|
|
274
|
+
function urlTarget(params) {
|
|
275
|
+
return /^\s*url\(\s*["']?([^"')]+)["']?\s*\)/.exec(params)?.[1] ?? null;
|
|
313
276
|
}
|
|
314
277
|
|
|
315
278
|
// src/preset.ts
|
|
316
|
-
async function
|
|
317
|
-
|
|
318
|
-
|
|
279
|
+
async function loadTailwind(opts) {
|
|
280
|
+
let css;
|
|
281
|
+
let base;
|
|
282
|
+
let file;
|
|
283
|
+
if (opts.css != null) {
|
|
284
|
+
css = opts.css;
|
|
285
|
+
base = opts.base ?? process.cwd();
|
|
286
|
+
} else if (opts.cssPath != null) {
|
|
287
|
+
file = resolve3(opts.cssPath);
|
|
288
|
+
css = await readFile2(file, "utf8");
|
|
289
|
+
base = dirname3(file);
|
|
290
|
+
} else {
|
|
291
|
+
throw new Error("pandatail: provide either `css` or `cssPath`");
|
|
292
|
+
}
|
|
293
|
+
const tokens = await extractTokens({ css, base });
|
|
294
|
+
const scan = scanCss({ css, base, file });
|
|
295
|
+
return { preset: buildPreset(tokens, scan), scan, tokens };
|
|
319
296
|
}
|
|
320
|
-
function
|
|
321
|
-
|
|
322
|
-
return buildPreset(tokens);
|
|
297
|
+
async function tailwindPreset(opts) {
|
|
298
|
+
return (await loadTailwind(opts)).preset;
|
|
323
299
|
}
|
|
324
|
-
function buildPreset(tokens) {
|
|
300
|
+
function buildPreset(tokens, scan) {
|
|
325
301
|
const breakpoints = {};
|
|
326
302
|
const tokenTokens = [];
|
|
327
303
|
for (const t of tokens) {
|
|
@@ -336,23 +312,17 @@ function buildPreset(tokens) {
|
|
|
336
312
|
for (const [category, list] of Object.entries(tokensByCategory)) {
|
|
337
313
|
theme[category] = buildTree(list, category);
|
|
338
314
|
}
|
|
339
|
-
|
|
315
|
+
const preset = definePreset({
|
|
340
316
|
name: "tailwind",
|
|
341
317
|
theme: {
|
|
342
318
|
tokens: theme,
|
|
343
319
|
breakpoints
|
|
344
320
|
}
|
|
345
321
|
});
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
if (opts.css != null) {
|
|
349
|
-
return extractTokens({ css: opts.css, base: opts.base });
|
|
322
|
+
if (scan && Object.keys(scan.conditions).length > 0) {
|
|
323
|
+
preset.conditions = { extend: scan.conditions };
|
|
350
324
|
}
|
|
351
|
-
|
|
352
|
-
const { extractTokensFromFile: extractTokensFromFile2 } = await Promise.resolve().then(() => (init_extract(), exports_extract));
|
|
353
|
-
return extractTokensFromFile2(opts.cssPath);
|
|
354
|
-
}
|
|
355
|
-
throw new Error("tailwindPreset: provide either `css` or `cssPath`");
|
|
325
|
+
return preset;
|
|
356
326
|
}
|
|
357
327
|
function groupByCategory(tokens) {
|
|
358
328
|
const out = {};
|
|
@@ -369,7 +339,7 @@ function buildTree(tokens, category) {
|
|
|
369
339
|
const seg = t.path[i];
|
|
370
340
|
const next = cursor[seg];
|
|
371
341
|
if (next && "value" in next) {
|
|
372
|
-
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.`);
|
|
342
|
+
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.`);
|
|
373
343
|
}
|
|
374
344
|
if (!next) {
|
|
375
345
|
const fresh = {};
|
|
@@ -382,22 +352,139 @@ function buildTree(tokens, category) {
|
|
|
382
352
|
const leaf = t.path[t.path.length - 1];
|
|
383
353
|
const existing = cursor[leaf];
|
|
384
354
|
if (existing && !("value" in existing)) {
|
|
385
|
-
throw new Error(`pandatail: token path collision in '${category}' at '${t.path.join(".")}': a leaf token clashes with an existing group.`);
|
|
355
|
+
throw new Error(`pandatail: token path collision in '${category}' at ` + `'${t.path.join(".")}': a leaf token clashes with an existing group.`);
|
|
386
356
|
}
|
|
387
357
|
cursor[leaf] = { value: t.value };
|
|
388
358
|
}
|
|
389
359
|
return root;
|
|
390
360
|
}
|
|
391
361
|
|
|
392
|
-
// src/
|
|
393
|
-
|
|
394
|
-
|
|
362
|
+
// src/project.ts
|
|
363
|
+
var DEFAULT_EXT = "{js,jsx,ts,tsx,mdx}";
|
|
364
|
+
async function createPandatailProject(opts) {
|
|
365
|
+
const cwd = resolve4(opts.cwd ?? process.cwd());
|
|
366
|
+
const cssPath = resolve4(cwd, opts.css);
|
|
367
|
+
if (!existsSync2(cssPath))
|
|
368
|
+
throw new Error(`pandatail: CSS entry not found: ${cssPath}`);
|
|
369
|
+
const tw = await loadTailwind({ cssPath });
|
|
370
|
+
const dependencies = [...tw.scan.files];
|
|
371
|
+
let user = {};
|
|
372
|
+
if (typeof opts.config === "string") {
|
|
373
|
+
const file = resolve4(cwd, opts.config);
|
|
374
|
+
const bundled = await bundleConfig(file, cwd);
|
|
375
|
+
user = bundled.config;
|
|
376
|
+
dependencies.push(file, ...bundled.dependencies);
|
|
377
|
+
} else if (opts.config) {
|
|
378
|
+
user = opts.config;
|
|
379
|
+
}
|
|
380
|
+
const { presets: userPresetList, ...userRest } = user;
|
|
381
|
+
const userPresets = await resolvePresets(userPresetList, cwd);
|
|
382
|
+
const include = opts.include ?? unique([
|
|
383
|
+
...userRest.include ?? [`./src/**/*.${DEFAULT_EXT}`],
|
|
384
|
+
...tw.scan.sources.map((p) => sourceToGlob(p, cwd))
|
|
385
|
+
]);
|
|
386
|
+
const exclude = opts.exclude ?? unique([
|
|
387
|
+
...userRest.exclude ?? [],
|
|
388
|
+
...tw.scan.excludes.map((p) => sourceToGlob(p, cwd))
|
|
389
|
+
]);
|
|
390
|
+
const defaults = {
|
|
391
|
+
cwd,
|
|
392
|
+
preflight: false,
|
|
393
|
+
jsxFramework: "react",
|
|
394
|
+
jsxStyleProps: "all",
|
|
395
|
+
outdir: "styled-system"
|
|
396
|
+
};
|
|
397
|
+
const finalOverrides = { include, exclude, cwd };
|
|
398
|
+
for (const key of [
|
|
399
|
+
"outdir",
|
|
400
|
+
"jsxFramework",
|
|
401
|
+
"jsxStyleProps",
|
|
402
|
+
"preflight",
|
|
403
|
+
"importMap",
|
|
404
|
+
"prefix",
|
|
405
|
+
"hash",
|
|
406
|
+
"minify"
|
|
407
|
+
]) {
|
|
408
|
+
if (opts[key] !== undefined)
|
|
409
|
+
finalOverrides[key] = opts[key];
|
|
410
|
+
}
|
|
411
|
+
const merged = mergeConfigs([
|
|
412
|
+
defaults,
|
|
413
|
+
presetBase,
|
|
414
|
+
...userPresets,
|
|
415
|
+
tw.preset,
|
|
416
|
+
userRest,
|
|
417
|
+
finalOverrides
|
|
418
|
+
]);
|
|
419
|
+
const config = applyConfigDefaults(merged, cwd);
|
|
420
|
+
const compiler = createCompilerFromSnapshot(createConfigSnapshot(config));
|
|
421
|
+
return {
|
|
422
|
+
compiler,
|
|
423
|
+
config,
|
|
424
|
+
cwd,
|
|
425
|
+
outdir: resolve4(cwd, config.outdir ?? "styled-system"),
|
|
426
|
+
dependencies: unique(dependencies),
|
|
427
|
+
warnings: tw.scan.warnings
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
function buildProject(project, opts = {}) {
|
|
431
|
+
const { compiler, cwd, outdir } = project;
|
|
432
|
+
const files = compiler.scan();
|
|
433
|
+
compiler.parseFiles(files);
|
|
434
|
+
let artifacts = 0;
|
|
435
|
+
if (opts.codegen !== false) {
|
|
436
|
+
artifacts = compiler.writeArtifacts({ outdir, cwd }).length;
|
|
437
|
+
}
|
|
438
|
+
let cssPath;
|
|
439
|
+
if (opts.outfile !== false) {
|
|
440
|
+
const outfile = opts.outfile ?? relative(cwd, resolve4(outdir, "styles.css"));
|
|
441
|
+
cssPath = compiler.writeCss({ outfile, cwd }).path;
|
|
442
|
+
}
|
|
443
|
+
return { files, artifacts, cssPath, diagnostics: compiler.diagnostics() };
|
|
444
|
+
}
|
|
445
|
+
function sourceToGlob(path, cwd) {
|
|
446
|
+
const rel = relative(cwd, path).split("\\").join("/");
|
|
447
|
+
const p = rel.startsWith(".") ? rel : `./${rel}`;
|
|
448
|
+
const hasGlob = /[*?{}\[\]]/.test(p);
|
|
449
|
+
if (!hasGlob && existsSync2(path) && statSync(path).isDirectory()) {
|
|
450
|
+
return `${p}/**/*.${DEFAULT_EXT}`;
|
|
451
|
+
}
|
|
452
|
+
return p;
|
|
453
|
+
}
|
|
454
|
+
async function resolvePresets(list, cwd) {
|
|
455
|
+
const out = [];
|
|
456
|
+
for (const entry of list ?? []) {
|
|
457
|
+
const preset = await loadPreset(entry, cwd);
|
|
458
|
+
const { presets, ...rest } = preset;
|
|
459
|
+
out.push(...await resolvePresets(presets, cwd), rest);
|
|
460
|
+
}
|
|
461
|
+
return out;
|
|
462
|
+
}
|
|
463
|
+
async function loadPreset(entry, cwd) {
|
|
464
|
+
const value = await entry;
|
|
465
|
+
if (typeof value !== "string")
|
|
466
|
+
return value;
|
|
467
|
+
const req = createRequire(resolve4(cwd, "__pandatail_anchor__"));
|
|
468
|
+
let mod;
|
|
469
|
+
try {
|
|
470
|
+
mod = await import(req.resolve(value));
|
|
471
|
+
} catch {
|
|
472
|
+
mod = await import(value);
|
|
473
|
+
}
|
|
474
|
+
return mod.default ?? mod.preset ?? mod;
|
|
475
|
+
}
|
|
476
|
+
function unique(xs) {
|
|
477
|
+
return [...new Set(xs)];
|
|
478
|
+
}
|
|
395
479
|
export {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
extractTokensSync,
|
|
400
|
-
extractTokensFromFile,
|
|
480
|
+
TAILWIND_NAMESPACES,
|
|
481
|
+
buildProject,
|
|
482
|
+
createPandatailProject,
|
|
401
483
|
extractTokens,
|
|
402
|
-
|
|
484
|
+
extractTokensFromFile,
|
|
485
|
+
formatDiagnostic,
|
|
486
|
+
loadTailwind,
|
|
487
|
+
matchNamespace,
|
|
488
|
+
scanCss,
|
|
489
|
+
tailwindPreset
|
|
403
490
|
};
|
package/dist/preset.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type ExtractedToken } from "./extract";
|
|
2
|
+
import { type CssScan } from "./scanCss";
|
|
1
3
|
export interface TailwindPresetOptions {
|
|
2
4
|
/**
|
|
3
5
|
* Inline Tailwind v4 CSS source. Either this or {@link cssPath} must be set.
|
|
@@ -13,21 +15,42 @@ export interface TailwindPresetOptions {
|
|
|
13
15
|
*/
|
|
14
16
|
base?: string;
|
|
15
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Everything pandatail learns from a Tailwind entry stylesheet: the Panda
|
|
20
|
+
* preset (tokens + conditions) and the project info (`@source`s etc.) that
|
|
21
|
+
* the config-less compiler uses.
|
|
22
|
+
*/
|
|
23
|
+
export interface LoadedTailwind {
|
|
24
|
+
preset: ReturnType<typeof buildPreset>;
|
|
25
|
+
scan: CssScan;
|
|
26
|
+
tokens: ExtractedToken[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Load a Tailwind v4 stylesheet (via Tailwind's own design-system loader, so
|
|
30
|
+
* `@import`, `@theme` and `@plugin` behave exactly as they do in Tailwind) and
|
|
31
|
+
* project it into Panda.
|
|
32
|
+
*/
|
|
33
|
+
export declare function loadTailwind(opts: TailwindPresetOptions): Promise<LoadedTailwind>;
|
|
16
34
|
/**
|
|
17
35
|
* Build a PandaCSS preset whose token layer references the CSS custom
|
|
18
|
-
* properties that Tailwind v4 emits from the user's `@theme` blocks
|
|
36
|
+
* properties that Tailwind v4 emits from the user's `@theme` blocks, and whose
|
|
37
|
+
* conditions mirror the stylesheet's `@custom-variant`s.
|
|
19
38
|
*
|
|
20
39
|
* Tailwind owns the values; Panda owns the typed API. There is no value
|
|
21
|
-
* duplication
|
|
22
|
-
*
|
|
23
|
-
* Async variant — uses Tailwind's own design-system loader for highest
|
|
24
|
-
* fidelity. Prefer {@link tailwindPresetSync} from inside a Panda config,
|
|
25
|
-
* since Panda bundles configs to CJS and disallows top-level `await`.
|
|
26
|
-
*/
|
|
27
|
-
export declare function tailwindPreset(opts: TailwindPresetOptions): Promise<import("@pandacss/types").Preset>;
|
|
28
|
-
/**
|
|
29
|
-
* Synchronous form of {@link tailwindPreset}. Parses `@theme` blocks via
|
|
30
|
-
* PostCSS instead of invoking Tailwind's loader, so it can be called
|
|
31
|
-
* directly from a `panda.config.ts` without top-level await.
|
|
40
|
+
* duplication: every Panda token resolves to `var(--<tailwind-name>)`.
|
|
32
41
|
*/
|
|
33
|
-
export declare function
|
|
42
|
+
export declare function tailwindPreset(opts: TailwindPresetOptions): Promise<{
|
|
43
|
+
readonly name: "tailwind";
|
|
44
|
+
readonly theme: {
|
|
45
|
+
readonly tokens: Record<string, any>;
|
|
46
|
+
readonly breakpoints: Record<string, string>;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
declare function buildPreset(tokens: ExtractedToken[], scan?: CssScan): {
|
|
50
|
+
readonly name: "tailwind";
|
|
51
|
+
readonly theme: {
|
|
52
|
+
readonly tokens: Record<string, any>;
|
|
53
|
+
readonly breakpoints: Record<string, string>;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export {};
|