@dmisdm/pandatail 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +82 -83
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +637 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +344 -213
- package/dist/namespaces.d.ts +10 -0
- package/dist/preset.d.ts +36 -13
- package/dist/project.d.ts +74 -0
- package/dist/scanCss.d.ts +30 -0
- package/dist/vite.d.ts +19 -0
- package/dist/vite.js +606 -0
- package/package.json +31 -14
- package/LICENSE +0 -21
- package/dist/extractSync.d.ts +0 -19
package/dist/index.js
CHANGED
|
@@ -1,20 +1,56 @@
|
|
|
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 as createRequire2 } 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";
|
|
17
|
+
import { readFile } from "node:fs/promises";
|
|
18
|
+
import { createRequire } from "node:module";
|
|
19
|
+
import { dirname, resolve } from "node:path";
|
|
20
|
+
import { pathToFileURL } from "node:url";
|
|
16
21
|
|
|
17
22
|
// src/namespaces.ts
|
|
23
|
+
var TAILWIND_NAMESPACES = [
|
|
24
|
+
{ prefix: "font-weight", category: "fontWeights" },
|
|
25
|
+
{ prefix: "inset-shadow", category: "shadows" },
|
|
26
|
+
{ prefix: "drop-shadow", category: "dropShadows" },
|
|
27
|
+
{ prefix: "text-shadow", category: "shadows" },
|
|
28
|
+
{ prefix: "color", category: "colors" },
|
|
29
|
+
{ prefix: "spacing", category: "spacing" },
|
|
30
|
+
{ prefix: "font", category: "fonts" },
|
|
31
|
+
{ prefix: "text", category: "fontSizes" },
|
|
32
|
+
{ prefix: "tracking", category: "letterSpacings" },
|
|
33
|
+
{ prefix: "leading", category: "lineHeights" },
|
|
34
|
+
{ prefix: "breakpoint", category: "breakpoints" },
|
|
35
|
+
{ prefix: "container", category: "sizes" },
|
|
36
|
+
{ prefix: "radius", category: "radii" },
|
|
37
|
+
{ prefix: "shadow", category: "shadows" },
|
|
38
|
+
{ prefix: "blur", category: "blurs" },
|
|
39
|
+
{ prefix: "aspect", category: "aspectRatios" },
|
|
40
|
+
{ prefix: "ease", category: "easings" },
|
|
41
|
+
{ prefix: "animate", category: "animations" },
|
|
42
|
+
{ prefix: "perspective", category: "sizes" }
|
|
43
|
+
];
|
|
44
|
+
function deriveTokenPath(rest) {
|
|
45
|
+
const lastDash = rest.lastIndexOf("-");
|
|
46
|
+
if (lastDash > 0) {
|
|
47
|
+
const after = rest.slice(lastDash + 1);
|
|
48
|
+
if (/^\d+$/.test(after)) {
|
|
49
|
+
return [rest.slice(0, lastDash), after];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return [rest];
|
|
53
|
+
}
|
|
18
54
|
function matchNamespace(themeKey) {
|
|
19
55
|
if (!themeKey.startsWith("--"))
|
|
20
56
|
return null;
|
|
@@ -32,32 +68,57 @@ function matchNamespace(themeKey) {
|
|
|
32
68
|
}
|
|
33
69
|
return null;
|
|
34
70
|
}
|
|
35
|
-
var TAILWIND_NAMESPACES;
|
|
36
|
-
var init_namespaces = __esm(() => {
|
|
37
|
-
TAILWIND_NAMESPACES = [
|
|
38
|
-
{ prefix: "font-weight", category: "fontWeights" },
|
|
39
|
-
{ prefix: "inset-shadow", category: "shadows" },
|
|
40
|
-
{ prefix: "drop-shadow", category: "dropShadows" },
|
|
41
|
-
{ prefix: "text-shadow", category: "shadows" },
|
|
42
|
-
{ prefix: "color", category: "colors" },
|
|
43
|
-
{ prefix: "spacing", category: "spacing" },
|
|
44
|
-
{ prefix: "font", category: "fonts" },
|
|
45
|
-
{ prefix: "text", category: "fontSizes" },
|
|
46
|
-
{ prefix: "tracking", category: "letterSpacings" },
|
|
47
|
-
{ prefix: "leading", category: "lineHeights" },
|
|
48
|
-
{ prefix: "breakpoint", category: "breakpoints" },
|
|
49
|
-
{ prefix: "container", category: "sizes" },
|
|
50
|
-
{ prefix: "radius", category: "radii" },
|
|
51
|
-
{ prefix: "shadow", category: "shadows" },
|
|
52
|
-
{ prefix: "blur", category: "blurs" },
|
|
53
|
-
{ prefix: "aspect", category: "aspectRatios" },
|
|
54
|
-
{ prefix: "ease", category: "easings" },
|
|
55
|
-
{ prefix: "animate", category: "animations" },
|
|
56
|
-
{ prefix: "perspective", category: "sizes" }
|
|
57
|
-
];
|
|
58
|
-
});
|
|
59
71
|
|
|
60
72
|
// src/derivedScales.ts
|
|
73
|
+
var TAILWIND_NUMERIC_STEPS = [
|
|
74
|
+
0,
|
|
75
|
+
0.5,
|
|
76
|
+
1,
|
|
77
|
+
1.5,
|
|
78
|
+
2,
|
|
79
|
+
2.5,
|
|
80
|
+
3,
|
|
81
|
+
3.5,
|
|
82
|
+
4,
|
|
83
|
+
5,
|
|
84
|
+
6,
|
|
85
|
+
7,
|
|
86
|
+
8,
|
|
87
|
+
9,
|
|
88
|
+
10,
|
|
89
|
+
11,
|
|
90
|
+
12,
|
|
91
|
+
14,
|
|
92
|
+
16,
|
|
93
|
+
20,
|
|
94
|
+
24,
|
|
95
|
+
28,
|
|
96
|
+
32,
|
|
97
|
+
36,
|
|
98
|
+
40,
|
|
99
|
+
44,
|
|
100
|
+
48,
|
|
101
|
+
52,
|
|
102
|
+
56,
|
|
103
|
+
60,
|
|
104
|
+
64,
|
|
105
|
+
72,
|
|
106
|
+
80,
|
|
107
|
+
96
|
|
108
|
+
];
|
|
109
|
+
var NAMED_SIZES = {
|
|
110
|
+
full: "100%",
|
|
111
|
+
screen: "100vw",
|
|
112
|
+
"screen-h": "100vh",
|
|
113
|
+
min: "min-content",
|
|
114
|
+
max: "max-content",
|
|
115
|
+
fit: "fit-content",
|
|
116
|
+
auto: "auto"
|
|
117
|
+
};
|
|
118
|
+
var NAMED_RADII = {
|
|
119
|
+
none: "0",
|
|
120
|
+
full: "9999px"
|
|
121
|
+
};
|
|
61
122
|
function synthesiseDerivedTokens(hasSpacingBase) {
|
|
62
123
|
const out = [];
|
|
63
124
|
if (hasSpacingBase) {
|
|
@@ -94,69 +155,9 @@ function pushNamed(out) {
|
|
|
94
155
|
});
|
|
95
156
|
}
|
|
96
157
|
}
|
|
97
|
-
var TAILWIND_NUMERIC_STEPS, NAMED_SIZES, NAMED_RADII;
|
|
98
|
-
var init_derivedScales = __esm(() => {
|
|
99
|
-
TAILWIND_NUMERIC_STEPS = [
|
|
100
|
-
0,
|
|
101
|
-
0.5,
|
|
102
|
-
1,
|
|
103
|
-
1.5,
|
|
104
|
-
2,
|
|
105
|
-
2.5,
|
|
106
|
-
3,
|
|
107
|
-
3.5,
|
|
108
|
-
4,
|
|
109
|
-
5,
|
|
110
|
-
6,
|
|
111
|
-
7,
|
|
112
|
-
8,
|
|
113
|
-
9,
|
|
114
|
-
10,
|
|
115
|
-
11,
|
|
116
|
-
12,
|
|
117
|
-
14,
|
|
118
|
-
16,
|
|
119
|
-
20,
|
|
120
|
-
24,
|
|
121
|
-
28,
|
|
122
|
-
32,
|
|
123
|
-
36,
|
|
124
|
-
40,
|
|
125
|
-
44,
|
|
126
|
-
48,
|
|
127
|
-
52,
|
|
128
|
-
56,
|
|
129
|
-
60,
|
|
130
|
-
64,
|
|
131
|
-
72,
|
|
132
|
-
80,
|
|
133
|
-
96
|
|
134
|
-
];
|
|
135
|
-
NAMED_SIZES = {
|
|
136
|
-
full: "100%",
|
|
137
|
-
screen: "100vw",
|
|
138
|
-
"screen-h": "100vh",
|
|
139
|
-
min: "min-content",
|
|
140
|
-
max: "max-content",
|
|
141
|
-
fit: "fit-content",
|
|
142
|
-
auto: "auto"
|
|
143
|
-
};
|
|
144
|
-
NAMED_RADII = {
|
|
145
|
-
none: "0",
|
|
146
|
-
full: "9999px"
|
|
147
|
-
};
|
|
148
|
-
});
|
|
149
158
|
|
|
150
159
|
// src/extract.ts
|
|
151
|
-
var
|
|
152
|
-
__export(exports_extract, {
|
|
153
|
-
extractTokensFromFile: () => extractTokensFromFile,
|
|
154
|
-
extractTokens: () => extractTokens
|
|
155
|
-
});
|
|
156
|
-
import { __unstable__loadDesignSystem } from "tailwindcss";
|
|
157
|
-
import { readFile } from "node:fs/promises";
|
|
158
|
-
import { createRequire } from "node:module";
|
|
159
|
-
import { dirname, resolve } from "node:path";
|
|
160
|
+
var requireFromHere = createRequire(`${process.cwd()}/__pandatail_anchor__`);
|
|
160
161
|
function resolveStylesheet(id, basedir) {
|
|
161
162
|
if (id.startsWith(".") || id.startsWith("/")) {
|
|
162
163
|
return resolve(basedir, id);
|
|
@@ -178,8 +179,10 @@ async function extractTokens(opts) {
|
|
|
178
179
|
const content = await readFile(path, "utf8");
|
|
179
180
|
return { path, base: dirname(path), content };
|
|
180
181
|
},
|
|
181
|
-
loadModule: async () => {
|
|
182
|
-
|
|
182
|
+
loadModule: async (id, basedir) => {
|
|
183
|
+
const path = resolveStylesheet(id, basedir);
|
|
184
|
+
const mod = await import(pathToFileURL(path).href);
|
|
185
|
+
return { path, base: dirname(path), module: mod.default ?? mod };
|
|
183
186
|
}
|
|
184
187
|
});
|
|
185
188
|
const themeEntries = new Map;
|
|
@@ -196,7 +199,7 @@ async function extractTokens(opts) {
|
|
|
196
199
|
cssVar: key,
|
|
197
200
|
value: matched.mapping.category === "breakpoints" ? rawValue : `var(${key})`,
|
|
198
201
|
category: matched.mapping.category,
|
|
199
|
-
path: matched.rest
|
|
202
|
+
path: deriveTokenPath(matched.rest)
|
|
200
203
|
});
|
|
201
204
|
}
|
|
202
205
|
out.push(...synthesiseDerivedTokens(themeEntries.has("--spacing")));
|
|
@@ -206,112 +209,122 @@ async function extractTokensFromFile(path) {
|
|
|
206
209
|
const css = await readFile(path, "utf8");
|
|
207
210
|
return extractTokens({ css, base: dirname(resolve(path)) });
|
|
208
211
|
}
|
|
209
|
-
var requireFromHere;
|
|
210
|
-
var init_extract = __esm(() => {
|
|
211
|
-
init_namespaces();
|
|
212
|
-
init_derivedScales();
|
|
213
|
-
requireFromHere = createRequire(`${process.cwd()}/__pandatail_anchor__`);
|
|
214
|
-
});
|
|
215
212
|
|
|
216
|
-
// src/
|
|
217
|
-
init_extract();
|
|
218
|
-
import { definePreset } from "@pandacss/dev";
|
|
219
|
-
|
|
220
|
-
// src/extractSync.ts
|
|
221
|
-
init_namespaces();
|
|
222
|
-
init_derivedScales();
|
|
213
|
+
// src/scanCss.ts
|
|
223
214
|
import postcss from "postcss";
|
|
224
|
-
import { readFileSync } from "node:fs";
|
|
225
|
-
import { createRequire as createRequire2 } from "node:module";
|
|
215
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
226
216
|
import { dirname as dirname2, resolve as resolve2 } from "node:path";
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
css = readFileSync(abs, "utf8");
|
|
237
|
-
base = dirname2(abs);
|
|
238
|
-
} else {
|
|
239
|
-
throw new Error("extractTokensSync: provide either `css` or `cssPath`");
|
|
240
|
-
}
|
|
241
|
-
const decls = new Map;
|
|
242
|
-
collectThemeDecls(css, base, decls, new Set);
|
|
243
|
-
const out = [];
|
|
244
|
-
for (const [cssVar, rawValue] of decls) {
|
|
245
|
-
const matched = matchNamespace(cssVar);
|
|
246
|
-
if (!matched)
|
|
247
|
-
continue;
|
|
248
|
-
if (matched.rest === "DEFAULT")
|
|
249
|
-
continue;
|
|
250
|
-
out.push({
|
|
251
|
-
cssVar,
|
|
252
|
-
value: matched.mapping.category === "breakpoints" ? rawValue : `var(${cssVar})`,
|
|
253
|
-
category: matched.mapping.category,
|
|
254
|
-
path: matched.rest.split("-")
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
out.push(...synthesiseDerivedTokens(decls.has("--spacing")));
|
|
217
|
+
function scanCss(opts) {
|
|
218
|
+
const out = {
|
|
219
|
+
sources: [],
|
|
220
|
+
excludes: [],
|
|
221
|
+
conditions: {},
|
|
222
|
+
warnings: [],
|
|
223
|
+
files: opts.file ? [opts.file] : []
|
|
224
|
+
};
|
|
225
|
+
walk(opts.css, opts.base, out, new Set(opts.file ? [opts.file] : []));
|
|
258
226
|
return out;
|
|
259
227
|
}
|
|
260
|
-
function
|
|
261
|
-
|
|
228
|
+
function walk(css, base, out, seen) {
|
|
229
|
+
let root;
|
|
230
|
+
try {
|
|
231
|
+
root = postcss.parse(css);
|
|
232
|
+
} catch (e) {
|
|
233
|
+
out.warnings.push(`could not parse CSS in ${base}: ${e.message}`);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
262
236
|
root.walkAtRules((rule) => {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
237
|
+
switch (rule.name) {
|
|
238
|
+
case "import": {
|
|
239
|
+
const id = quoted(rule.params) ?? urlTarget(rule.params);
|
|
240
|
+
if (!id || !id.startsWith("."))
|
|
241
|
+
return;
|
|
242
|
+
const path = resolve2(base, id);
|
|
243
|
+
if (seen.has(path) || !existsSync(path))
|
|
244
|
+
return;
|
|
245
|
+
seen.add(path);
|
|
246
|
+
out.files.push(path);
|
|
247
|
+
walk(readFileSync(path, "utf8"), dirname2(path), out, seen);
|
|
269
248
|
return;
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
if (d.prop.startsWith("--")) {
|
|
276
|
-
decls.set(d.prop, d.value);
|
|
277
|
-
}
|
|
278
|
-
});
|
|
249
|
+
}
|
|
250
|
+
case "source":
|
|
251
|
+
return handleSource(rule, base, out);
|
|
252
|
+
case "custom-variant":
|
|
253
|
+
return handleCustomVariant(rule, out);
|
|
279
254
|
}
|
|
280
255
|
});
|
|
281
256
|
}
|
|
282
|
-
function
|
|
283
|
-
const
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
return
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
257
|
+
function handleSource(rule, base, out) {
|
|
258
|
+
const params = rule.params.trim();
|
|
259
|
+
if (params.startsWith("inline(") || params.startsWith("not inline(")) {
|
|
260
|
+
out.warnings.push(`@source ${params}: inline sources have no Panda equivalent`);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const isNot = /^not\s/.test(params);
|
|
264
|
+
const target = quoted(isNot ? params.replace(/^not\s+/, "") : params);
|
|
265
|
+
if (!target)
|
|
266
|
+
return;
|
|
267
|
+
(isNot ? out.excludes : out.sources).push(resolve2(base, target));
|
|
291
268
|
}
|
|
292
|
-
function
|
|
293
|
-
|
|
294
|
-
|
|
269
|
+
function handleCustomVariant(rule, out) {
|
|
270
|
+
const params = rule.params.trim();
|
|
271
|
+
const name = /^([\w-]+)/.exec(params)?.[1];
|
|
272
|
+
if (!name)
|
|
273
|
+
return;
|
|
274
|
+
if (!rule.nodes) {
|
|
275
|
+
const m = /^[\w-]+\s*\(([\s\S]+)\)$/.exec(params);
|
|
276
|
+
if (m)
|
|
277
|
+
out.conditions[name] = m[1].trim();
|
|
278
|
+
else
|
|
279
|
+
out.warnings.push(`@custom-variant ${name}: unrecognised form`);
|
|
280
|
+
return;
|
|
295
281
|
}
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
282
|
+
const body = rule.nodes.filter((n) => n.type !== "comment");
|
|
283
|
+
const only = body.length === 1 ? body[0] : undefined;
|
|
284
|
+
if (only?.type === "atrule" && only.name !== "slot" && isSlotOnly(only)) {
|
|
285
|
+
out.conditions[name] = `@${only.name} ${only.params}`.trim();
|
|
286
|
+
return;
|
|
301
287
|
}
|
|
302
|
-
|
|
288
|
+
if (only?.type === "rule" && isSlotOnly(only)) {
|
|
289
|
+
out.conditions[name] = only.selector;
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
out.warnings.push(`@custom-variant ${name}: block form is too complex to map to a Panda condition`);
|
|
293
|
+
}
|
|
294
|
+
function isSlotOnly(node) {
|
|
295
|
+
const kids = (node.nodes ?? []).filter((n) => n.type !== "comment");
|
|
296
|
+
return kids.length === 1 && kids[0].type === "atrule" && kids[0].name === "slot";
|
|
297
|
+
}
|
|
298
|
+
function quoted(params) {
|
|
299
|
+
return /^\s*["']([^"']+)["']/.exec(params)?.[1] ?? null;
|
|
300
|
+
}
|
|
301
|
+
function urlTarget(params) {
|
|
302
|
+
return /^\s*url\(\s*["']?([^"')]+)["']?\s*\)/.exec(params)?.[1] ?? null;
|
|
303
303
|
}
|
|
304
304
|
|
|
305
305
|
// src/preset.ts
|
|
306
|
-
async function
|
|
307
|
-
|
|
308
|
-
|
|
306
|
+
async function loadTailwind(opts) {
|
|
307
|
+
let css;
|
|
308
|
+
let base;
|
|
309
|
+
let file;
|
|
310
|
+
if (opts.css != null) {
|
|
311
|
+
css = opts.css;
|
|
312
|
+
base = opts.base ?? process.cwd();
|
|
313
|
+
} else if (opts.cssPath != null) {
|
|
314
|
+
file = resolve3(opts.cssPath);
|
|
315
|
+
css = await readFile2(file, "utf8");
|
|
316
|
+
base = dirname3(file);
|
|
317
|
+
} else {
|
|
318
|
+
throw new Error("pandatail: provide either `css` or `cssPath`");
|
|
319
|
+
}
|
|
320
|
+
const tokens = await extractTokens({ css, base });
|
|
321
|
+
const scan = scanCss({ css, base, file });
|
|
322
|
+
return { preset: buildPreset(tokens, scan), scan, tokens };
|
|
309
323
|
}
|
|
310
|
-
function
|
|
311
|
-
|
|
312
|
-
return buildPreset(tokens);
|
|
324
|
+
async function tailwindPreset(opts) {
|
|
325
|
+
return (await loadTailwind(opts)).preset;
|
|
313
326
|
}
|
|
314
|
-
function buildPreset(tokens) {
|
|
327
|
+
function buildPreset(tokens, scan) {
|
|
315
328
|
const breakpoints = {};
|
|
316
329
|
const tokenTokens = [];
|
|
317
330
|
for (const t of tokens) {
|
|
@@ -324,25 +337,19 @@ function buildPreset(tokens) {
|
|
|
324
337
|
const tokensByCategory = groupByCategory(tokenTokens);
|
|
325
338
|
const theme = {};
|
|
326
339
|
for (const [category, list] of Object.entries(tokensByCategory)) {
|
|
327
|
-
theme[category] = buildTree(list);
|
|
340
|
+
theme[category] = buildTree(list, category);
|
|
328
341
|
}
|
|
329
|
-
|
|
342
|
+
const preset = definePreset({
|
|
330
343
|
name: "tailwind",
|
|
331
344
|
theme: {
|
|
332
345
|
tokens: theme,
|
|
333
346
|
breakpoints
|
|
334
347
|
}
|
|
335
348
|
});
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
if (opts.css != null) {
|
|
339
|
-
return extractTokens({ css: opts.css, base: opts.base });
|
|
349
|
+
if (scan && Object.keys(scan.conditions).length > 0) {
|
|
350
|
+
preset.conditions = { extend: scan.conditions };
|
|
340
351
|
}
|
|
341
|
-
|
|
342
|
-
const { extractTokensFromFile: extractTokensFromFile2 } = await Promise.resolve().then(() => (init_extract(), exports_extract));
|
|
343
|
-
return extractTokensFromFile2(opts.cssPath);
|
|
344
|
-
}
|
|
345
|
-
throw new Error("tailwindPreset: provide either `css` or `cssPath`");
|
|
352
|
+
return preset;
|
|
346
353
|
}
|
|
347
354
|
function groupByCategory(tokens) {
|
|
348
355
|
const out = {};
|
|
@@ -351,14 +358,17 @@ function groupByCategory(tokens) {
|
|
|
351
358
|
}
|
|
352
359
|
return out;
|
|
353
360
|
}
|
|
354
|
-
function buildTree(tokens) {
|
|
361
|
+
function buildTree(tokens, category) {
|
|
355
362
|
const root = {};
|
|
356
363
|
for (const t of tokens) {
|
|
357
364
|
let cursor = root;
|
|
358
365
|
for (let i = 0;i < t.path.length - 1; i++) {
|
|
359
366
|
const seg = t.path[i];
|
|
360
367
|
const next = cursor[seg];
|
|
361
|
-
if (
|
|
368
|
+
if (next && "value" in next) {
|
|
369
|
+
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.`);
|
|
370
|
+
}
|
|
371
|
+
if (!next) {
|
|
362
372
|
const fresh = {};
|
|
363
373
|
cursor[seg] = fresh;
|
|
364
374
|
cursor = fresh;
|
|
@@ -367,20 +377,141 @@ function buildTree(tokens) {
|
|
|
367
377
|
}
|
|
368
378
|
}
|
|
369
379
|
const leaf = t.path[t.path.length - 1];
|
|
380
|
+
const existing = cursor[leaf];
|
|
381
|
+
if (existing && !("value" in existing)) {
|
|
382
|
+
throw new Error(`pandatail: token path collision in '${category}' at ` + `'${t.path.join(".")}': a leaf token clashes with an existing group.`);
|
|
383
|
+
}
|
|
370
384
|
cursor[leaf] = { value: t.value };
|
|
371
385
|
}
|
|
372
386
|
return root;
|
|
373
387
|
}
|
|
374
388
|
|
|
375
|
-
// src/
|
|
376
|
-
|
|
377
|
-
|
|
389
|
+
// src/project.ts
|
|
390
|
+
var DEFAULT_EXT = "{js,jsx,ts,tsx,mdx}";
|
|
391
|
+
async function createPandatailProject(opts) {
|
|
392
|
+
const cwd = resolve4(opts.cwd ?? process.cwd());
|
|
393
|
+
const cssPath = resolve4(cwd, opts.css);
|
|
394
|
+
if (!existsSync2(cssPath))
|
|
395
|
+
throw new Error(`pandatail: CSS entry not found: ${cssPath}`);
|
|
396
|
+
const tw = await loadTailwind({ cssPath });
|
|
397
|
+
const dependencies = [...tw.scan.files];
|
|
398
|
+
let user = {};
|
|
399
|
+
if (typeof opts.config === "string") {
|
|
400
|
+
const file = resolve4(cwd, opts.config);
|
|
401
|
+
const bundled = await bundleConfig(file, cwd);
|
|
402
|
+
user = bundled.config;
|
|
403
|
+
dependencies.push(file, ...bundled.dependencies);
|
|
404
|
+
} else if (opts.config) {
|
|
405
|
+
user = opts.config;
|
|
406
|
+
}
|
|
407
|
+
const { presets: userPresetList, ...userRest } = user;
|
|
408
|
+
const userPresets = await resolvePresets(userPresetList, cwd);
|
|
409
|
+
const include = opts.include ?? unique([
|
|
410
|
+
...userRest.include ?? [`./src/**/*.${DEFAULT_EXT}`],
|
|
411
|
+
...tw.scan.sources.map((p) => sourceToGlob(p, cwd))
|
|
412
|
+
]);
|
|
413
|
+
const exclude = opts.exclude ?? unique([
|
|
414
|
+
...userRest.exclude ?? [],
|
|
415
|
+
...tw.scan.excludes.map((p) => sourceToGlob(p, cwd))
|
|
416
|
+
]);
|
|
417
|
+
const defaults = {
|
|
418
|
+
cwd,
|
|
419
|
+
preflight: false,
|
|
420
|
+
jsxFramework: "react",
|
|
421
|
+
jsxStyleProps: "all",
|
|
422
|
+
outdir: "styled-system"
|
|
423
|
+
};
|
|
424
|
+
const finalOverrides = { include, exclude, cwd };
|
|
425
|
+
for (const key of [
|
|
426
|
+
"outdir",
|
|
427
|
+
"jsxFramework",
|
|
428
|
+
"jsxStyleProps",
|
|
429
|
+
"preflight",
|
|
430
|
+
"importMap",
|
|
431
|
+
"prefix",
|
|
432
|
+
"hash",
|
|
433
|
+
"minify"
|
|
434
|
+
]) {
|
|
435
|
+
if (opts[key] !== undefined)
|
|
436
|
+
finalOverrides[key] = opts[key];
|
|
437
|
+
}
|
|
438
|
+
const merged = mergeConfigs([
|
|
439
|
+
defaults,
|
|
440
|
+
presetBase,
|
|
441
|
+
...userPresets,
|
|
442
|
+
tw.preset,
|
|
443
|
+
userRest,
|
|
444
|
+
finalOverrides
|
|
445
|
+
]);
|
|
446
|
+
const config = applyConfigDefaults(merged, cwd);
|
|
447
|
+
const compiler = createCompilerFromSnapshot(createConfigSnapshot(config));
|
|
448
|
+
return {
|
|
449
|
+
compiler,
|
|
450
|
+
config,
|
|
451
|
+
cwd,
|
|
452
|
+
outdir: resolve4(cwd, config.outdir ?? "styled-system"),
|
|
453
|
+
dependencies: unique(dependencies),
|
|
454
|
+
warnings: tw.scan.warnings
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
function buildProject(project, opts = {}) {
|
|
458
|
+
const { compiler, cwd, outdir } = project;
|
|
459
|
+
const files = compiler.scan();
|
|
460
|
+
compiler.parseFiles(files);
|
|
461
|
+
let artifacts = 0;
|
|
462
|
+
if (opts.codegen !== false) {
|
|
463
|
+
artifacts = compiler.writeArtifacts({ outdir, cwd }).length;
|
|
464
|
+
}
|
|
465
|
+
let cssPath;
|
|
466
|
+
if (opts.outfile !== false) {
|
|
467
|
+
const outfile = opts.outfile ?? relative(cwd, resolve4(outdir, "styles.css"));
|
|
468
|
+
cssPath = compiler.writeCss({ outfile, cwd }).path;
|
|
469
|
+
}
|
|
470
|
+
return { files, artifacts, cssPath, diagnostics: compiler.diagnostics() };
|
|
471
|
+
}
|
|
472
|
+
function sourceToGlob(path, cwd) {
|
|
473
|
+
const rel = relative(cwd, path).split("\\").join("/");
|
|
474
|
+
const p = rel.startsWith(".") ? rel : `./${rel}`;
|
|
475
|
+
const hasGlob = /[*?{}\[\]]/.test(p);
|
|
476
|
+
if (!hasGlob && existsSync2(path) && statSync(path).isDirectory()) {
|
|
477
|
+
return `${p}/**/*.${DEFAULT_EXT}`;
|
|
478
|
+
}
|
|
479
|
+
return p;
|
|
480
|
+
}
|
|
481
|
+
async function resolvePresets(list, cwd) {
|
|
482
|
+
const out = [];
|
|
483
|
+
for (const entry of list ?? []) {
|
|
484
|
+
const preset = await loadPreset(entry, cwd);
|
|
485
|
+
const { presets, ...rest } = preset;
|
|
486
|
+
out.push(...await resolvePresets(presets, cwd), rest);
|
|
487
|
+
}
|
|
488
|
+
return out;
|
|
489
|
+
}
|
|
490
|
+
async function loadPreset(entry, cwd) {
|
|
491
|
+
const value = await entry;
|
|
492
|
+
if (typeof value !== "string")
|
|
493
|
+
return value;
|
|
494
|
+
const req = createRequire2(resolve4(cwd, "__pandatail_anchor__"));
|
|
495
|
+
let mod;
|
|
496
|
+
try {
|
|
497
|
+
mod = await import(req.resolve(value));
|
|
498
|
+
} catch {
|
|
499
|
+
mod = await import(value);
|
|
500
|
+
}
|
|
501
|
+
return mod.default ?? mod.preset ?? mod;
|
|
502
|
+
}
|
|
503
|
+
function unique(xs) {
|
|
504
|
+
return [...new Set(xs)];
|
|
505
|
+
}
|
|
378
506
|
export {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
extractTokensSync,
|
|
383
|
-
extractTokensFromFile,
|
|
507
|
+
TAILWIND_NAMESPACES,
|
|
508
|
+
buildProject,
|
|
509
|
+
createPandatailProject,
|
|
384
510
|
extractTokens,
|
|
385
|
-
|
|
511
|
+
extractTokensFromFile,
|
|
512
|
+
formatDiagnostic,
|
|
513
|
+
loadTailwind,
|
|
514
|
+
matchNamespace,
|
|
515
|
+
scanCss,
|
|
516
|
+
tailwindPreset
|
|
386
517
|
};
|
package/dist/namespaces.d.ts
CHANGED
|
@@ -13,6 +13,16 @@ export interface NamespaceMapping {
|
|
|
13
13
|
category: PandaTokenCategory;
|
|
14
14
|
}
|
|
15
15
|
export declare const TAILWIND_NAMESPACES: NamespaceMapping[];
|
|
16
|
+
/**
|
|
17
|
+
* Derive a token's nested Panda path from the post-namespace remainder.
|
|
18
|
+
*
|
|
19
|
+
* Only a *trailing numeric scale step* nests (`amber-500` → `['amber','500']`);
|
|
20
|
+
* everything else stays a single flat segment with hyphens preserved
|
|
21
|
+
* (`muted-foreground` → `['muted-foreground']`). Splitting every hyphen — as we
|
|
22
|
+
* used to — collapsed shadcn's paired `--color-X` / `--color-X-foreground`
|
|
23
|
+
* tokens onto colliding leaf/parent paths, silently dropping one of each pair.
|
|
24
|
+
*/
|
|
25
|
+
export declare function deriveTokenPath(rest: string): string[];
|
|
16
26
|
export declare function matchNamespace(themeKey: string): {
|
|
17
27
|
mapping: NamespaceMapping;
|
|
18
28
|
rest: string;
|