@dmisdm/pandatail 0.2.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/dist/index.js CHANGED
@@ -1,20 +1,46 @@
1
- var __defProp = Object.defineProperty;
2
- var __returnValue = (v) => v;
3
- function __exportSetter(name, newValue) {
4
- this[name] = __returnValue.bind(null, newValue);
5
- }
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true,
11
- configurable: true,
12
- set: __exportSetter.bind(all, name)
13
- });
14
- };
15
- var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
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
+ ];
18
44
  function deriveTokenPath(rest) {
19
45
  const lastDash = rest.lastIndexOf("-");
20
46
  if (lastDash > 0) {
@@ -42,32 +68,57 @@ function matchNamespace(themeKey) {
42
68
  }
43
69
  return null;
44
70
  }
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
71
 
70
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
+ };
71
122
  function synthesiseDerivedTokens(hasSpacingBase) {
72
123
  const out = [];
73
124
  if (hasSpacingBase) {
@@ -104,69 +155,9 @@ function pushNamed(out) {
104
155
  });
105
156
  }
106
157
  }
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
158
 
160
159
  // 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";
160
+ var requireFromHere = createRequire(`${process.cwd()}/__pandatail_anchor__`);
170
161
  function resolveStylesheet(id, basedir) {
171
162
  if (id.startsWith(".") || id.startsWith("/")) {
172
163
  return resolve(basedir, id);
@@ -188,8 +179,10 @@ async function extractTokens(opts) {
188
179
  const content = await readFile(path, "utf8");
189
180
  return { path, base: dirname(path), content };
190
181
  },
191
- loadModule: async () => {
192
- throw new Error("loadModule is not supported in pandatail extraction");
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 };
193
186
  }
194
187
  });
195
188
  const themeEntries = new Map;
@@ -216,112 +209,122 @@ async function extractTokensFromFile(path) {
216
209
  const css = await readFile(path, "utf8");
217
210
  return extractTokens({ css, base: dirname(resolve(path)) });
218
211
  }
219
- var requireFromHere;
220
- var init_extract = __esm(() => {
221
- init_namespaces();
222
- init_derivedScales();
223
- requireFromHere = createRequire(`${process.cwd()}/__pandatail_anchor__`);
224
- });
225
212
 
226
- // src/preset.ts
227
- init_extract();
228
- import { definePreset } from "@pandacss/dev";
229
-
230
- // src/extractSync.ts
231
- init_namespaces();
232
- init_derivedScales();
213
+ // src/scanCss.ts
233
214
  import postcss from "postcss";
234
- import { readFileSync } from "node:fs";
235
- import { createRequire as createRequire2 } from "node:module";
215
+ import { existsSync, readFileSync } from "node:fs";
236
216
  import { dirname as dirname2, resolve as resolve2 } from "node:path";
237
- var requireFromHere2 = createRequire2(`${process.cwd()}/__pandatail_anchor__`);
238
- function extractTokensSync(opts) {
239
- let css;
240
- let base;
241
- if (opts.css != null) {
242
- css = opts.css;
243
- base = opts.base ?? process.cwd();
244
- } else if (opts.cssPath != null) {
245
- const abs = resolve2(opts.cssPath);
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")));
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] : []));
268
226
  return out;
269
227
  }
270
- function collectThemeDecls(css, basedir, decls, seen) {
271
- const root = postcss.parse(css);
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
+ }
272
236
  root.walkAtRules((rule) => {
273
- if (rule.name === "import") {
274
- const id = parseImportTarget(rule.params);
275
- if (!id)
276
- return;
277
- const path = resolveCssImport(id, basedir);
278
- if (!path || seen.has(path))
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);
279
248
  return;
280
- seen.add(path);
281
- const content = readFileSync(path, "utf8");
282
- collectThemeDecls(content, dirname2(path), decls, seen);
283
- } else if (rule.name === "theme") {
284
- rule.walkDecls((d) => {
285
- if (d.prop.startsWith("--")) {
286
- decls.set(d.prop, d.value);
287
- }
288
- });
249
+ }
250
+ case "source":
251
+ return handleSource(rule, base, out);
252
+ case "custom-variant":
253
+ return handleCustomVariant(rule, out);
289
254
  }
290
255
  });
291
256
  }
292
- function parseImportTarget(params) {
293
- const trimmed = params.trim();
294
- const urlMatch = /^url\(\s*["']?([^"')]+)["']?\s*\)/.exec(trimmed);
295
- if (urlMatch)
296
- return urlMatch[1];
297
- const quoteMatch = /^["']([^"']+)["']/.exec(trimmed);
298
- if (quoteMatch)
299
- return quoteMatch[1];
300
- return null;
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));
301
268
  }
302
- function resolveCssImport(id, basedir) {
303
- if (id.startsWith(".") || id.startsWith("/")) {
304
- return resolve2(basedir, id);
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;
305
281
  }
306
- const candidates = [`${id}/index.css`, `${id}.css`, id];
307
- for (const candidate of candidates) {
308
- try {
309
- return requireFromHere2.resolve(candidate, { paths: [basedir] });
310
- } catch {}
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;
311
287
  }
312
- return null;
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;
313
303
  }
314
304
 
315
305
  // src/preset.ts
316
- async function tailwindPreset(opts) {
317
- const tokens = await loadTokens(opts);
318
- return buildPreset(tokens);
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 };
319
323
  }
320
- function tailwindPresetSync(opts) {
321
- const tokens = extractTokensSync(opts);
322
- return buildPreset(tokens);
324
+ async function tailwindPreset(opts) {
325
+ return (await loadTailwind(opts)).preset;
323
326
  }
324
- function buildPreset(tokens) {
327
+ function buildPreset(tokens, scan) {
325
328
  const breakpoints = {};
326
329
  const tokenTokens = [];
327
330
  for (const t of tokens) {
@@ -336,23 +339,17 @@ function buildPreset(tokens) {
336
339
  for (const [category, list] of Object.entries(tokensByCategory)) {
337
340
  theme[category] = buildTree(list, category);
338
341
  }
339
- return definePreset({
342
+ const preset = definePreset({
340
343
  name: "tailwind",
341
344
  theme: {
342
345
  tokens: theme,
343
346
  breakpoints
344
347
  }
345
348
  });
346
- }
347
- async function loadTokens(opts) {
348
- if (opts.css != null) {
349
- return extractTokens({ css: opts.css, base: opts.base });
350
- }
351
- if (opts.cssPath != null) {
352
- const { extractTokensFromFile: extractTokensFromFile2 } = await Promise.resolve().then(() => (init_extract(), exports_extract));
353
- return extractTokensFromFile2(opts.cssPath);
349
+ if (scan && Object.keys(scan.conditions).length > 0) {
350
+ preset.conditions = { extend: scan.conditions };
354
351
  }
355
- throw new Error("tailwindPreset: provide either `css` or `cssPath`");
352
+ return preset;
356
353
  }
357
354
  function groupByCategory(tokens) {
358
355
  const out = {};
@@ -369,7 +366,7 @@ function buildTree(tokens, category) {
369
366
  const seg = t.path[i];
370
367
  const next = cursor[seg];
371
368
  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.`);
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.`);
373
370
  }
374
371
  if (!next) {
375
372
  const fresh = {};
@@ -382,22 +379,139 @@ function buildTree(tokens, category) {
382
379
  const leaf = t.path[t.path.length - 1];
383
380
  const existing = cursor[leaf];
384
381
  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.`);
382
+ throw new Error(`pandatail: token path collision in '${category}' at ` + `'${t.path.join(".")}': a leaf token clashes with an existing group.`);
386
383
  }
387
384
  cursor[leaf] = { value: t.value };
388
385
  }
389
386
  return root;
390
387
  }
391
388
 
392
- // src/index.ts
393
- init_extract();
394
- init_namespaces();
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
+ }
395
506
  export {
396
- tailwindPresetSync,
397
- tailwindPreset,
398
- matchNamespace,
399
- extractTokensSync,
400
- extractTokensFromFile,
507
+ TAILWIND_NAMESPACES,
508
+ buildProject,
509
+ createPandatailProject,
401
510
  extractTokens,
402
- TAILWIND_NAMESPACES
511
+ extractTokensFromFile,
512
+ formatDiagnostic,
513
+ loadTailwind,
514
+ matchNamespace,
515
+ scanCss,
516
+ tailwindPreset
403
517
  };
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 — every Panda token resolves to `var(--<tailwind-name>)`.
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 tailwindPresetSync(opts: TailwindPresetOptions): import("@pandacss/types").Preset;
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 {};