@dmisdm/pandatail 0.1.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/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/derivedScales.d.ts +2 -0
- package/dist/extract.d.ts +47 -0
- package/dist/extractSync.d.ts +19 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +386 -0
- package/dist/namespaces.d.ts +19 -0
- package/dist/preset.d.ts +33 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Daniel Manning
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# pandatail
|
|
2
|
+
|
|
3
|
+
A **PandaCSS preset** that mirrors every token in your Tailwind v4
|
|
4
|
+
`@theme { … }` block into typed Panda style props.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
npm install -D @dmisdm/pandatail
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
Then install Panda itself if you don't have it:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
npm install -D @pandacss/dev
|
|
16
|
+
npx panda init --postcss
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- Tailwind owns the values; Panda owns the typed API. There is **no value
|
|
20
|
+
duplication** — every Panda token resolves to `var(--<tailwind-name>)`.
|
|
21
|
+
- Default Tailwind palettes (`blue.500`, `mauve.300`, …) and your custom
|
|
22
|
+
`@theme` additions (`brand.500`, `--radius-pill`, …) are typed
|
|
23
|
+
automatically.
|
|
24
|
+
- Tailwind utilities and Panda style props coexist in the same JSX. Refactor
|
|
25
|
+
one side at a time.
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
// CSS — your @theme block is the single source of truth
|
|
29
|
+
@import "tailwindcss";
|
|
30
|
+
@theme {
|
|
31
|
+
--color-brand-500: oklch(0.62 0.21 260);
|
|
32
|
+
--radius-pill: 999px;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// TSX — Panda autocomplete & TS errors against the same tokens
|
|
36
|
+
<tw.span bg="brand.500" rounded="pill" px={3} py={1} color="white">
|
|
37
|
+
New release
|
|
38
|
+
</tw.span>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Tailwind v4 (`tailwindcss@^4`) is a peer dependency and is loaded from your
|
|
42
|
+
existing setup — the preset doesn't require its own copy.
|
|
43
|
+
|
|
44
|
+
## Configure
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
// panda.config.ts
|
|
48
|
+
import { defineConfig } from "@pandacss/dev";
|
|
49
|
+
import { tailwindPresetSync } from "@dmisdm/pandatail";
|
|
50
|
+
|
|
51
|
+
export default defineConfig({
|
|
52
|
+
preflight: false, // Tailwind already ships preflight
|
|
53
|
+
jsxFramework: "react",
|
|
54
|
+
presets: [
|
|
55
|
+
"@pandacss/preset-base",
|
|
56
|
+
tailwindPresetSync({ cssPath: "./src/tailwind.css" }),
|
|
57
|
+
],
|
|
58
|
+
include: ["./src/**/*.{ts,tsx}"],
|
|
59
|
+
outdir: "styled-system",
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Then:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
npx panda codegen
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## How it works
|
|
70
|
+
|
|
71
|
+
The preset reads your Tailwind entry CSS, finds every `--*` token inside
|
|
72
|
+
`@theme { … }` blocks (including the ones Tailwind itself ships in
|
|
73
|
+
`tailwindcss/theme.css`), and registers each one as a Panda token whose value
|
|
74
|
+
is a `var()` reference back to the CSS variable.
|
|
75
|
+
|
|
76
|
+
Namespaces map to Panda categories:
|
|
77
|
+
|
|
78
|
+
| Tailwind namespace | Panda category |
|
|
79
|
+
| ------------------ | ----------------------------------- |
|
|
80
|
+
| `--color-*` | `colors` |
|
|
81
|
+
| `--spacing-*` | `spacing` + `sizes` |
|
|
82
|
+
| `--radius-*` | `radii` |
|
|
83
|
+
| `--shadow-*` | `shadows` |
|
|
84
|
+
| `--text-*` | `fontSizes` |
|
|
85
|
+
| `--font-*` | `fonts` |
|
|
86
|
+
| `--font-weight-*` | `fontWeights` |
|
|
87
|
+
| `--leading-*` | `lineHeights` |
|
|
88
|
+
| `--tracking-*` | `letterSpacings` |
|
|
89
|
+
| `--breakpoint-*` | `theme.breakpoints` (media queries) |
|
|
90
|
+
| `--container-*` | `sizes` |
|
|
91
|
+
|
|
92
|
+
Tailwind derives numeric scales (`p-4`, `leading-6`) from the single
|
|
93
|
+
`--spacing` token; the preset synthesises those steps into Panda's
|
|
94
|
+
`spacing`, `sizes`, and `lineHeights` categories so the typed APIs match
|
|
95
|
+
Tailwind's coverage.
|
|
96
|
+
|
|
97
|
+
## API
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
import {
|
|
101
|
+
tailwindPreset, // async — uses Tailwind's design-system loader
|
|
102
|
+
tailwindPresetSync, // sync — call from panda.config.ts (recommended)
|
|
103
|
+
extractTokens,
|
|
104
|
+
extractTokensSync,
|
|
105
|
+
} from "@dmisdm/pandatail";
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Use `tailwindPresetSync` in `panda.config.ts` — Panda bundles configs to CJS
|
|
109
|
+
and rejects top-level `await`.
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
MIT
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type PandaTokenCategory } from "./namespaces";
|
|
2
|
+
/**
|
|
3
|
+
* A single Tailwind theme entry resolved to its CSS-variable reference and
|
|
4
|
+
* the Panda category it should be projected into.
|
|
5
|
+
*/
|
|
6
|
+
export interface ExtractedToken {
|
|
7
|
+
/**
|
|
8
|
+
* Source CSS variable. Informational — kept so consumers can introspect
|
|
9
|
+
* which Tailwind var a Panda token came from. The actual Panda token value
|
|
10
|
+
* is in {@link ExtractedToken.value}.
|
|
11
|
+
*/
|
|
12
|
+
cssVar: string;
|
|
13
|
+
/**
|
|
14
|
+
* Value Panda should emit for this token. Typically `var(--color-blue-500)`
|
|
15
|
+
* (a reference to Tailwind's CSS variable, so user overrides flow through),
|
|
16
|
+
* but synthesised tokens may use `calc(...)` or literal expressions.
|
|
17
|
+
*/
|
|
18
|
+
value: string;
|
|
19
|
+
/** Panda token category, e.g. `colors`. */
|
|
20
|
+
category: PandaTokenCategory;
|
|
21
|
+
/**
|
|
22
|
+
* Nested path inside the category, as an array of segments. Stored as
|
|
23
|
+
* segments (not a dot-joined string) so step names containing literal
|
|
24
|
+
* dots — `spacing.0.5` is a *single* leaf at path `['0.5']`, not a leaf
|
|
25
|
+
* nested under `0` — round-trip without ambiguity.
|
|
26
|
+
*/
|
|
27
|
+
path: string[];
|
|
28
|
+
}
|
|
29
|
+
export interface ExtractOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Inline CSS source. Typically `@import "tailwindcss";` plus any `@theme {}`
|
|
32
|
+
* blocks the user has authored. Required.
|
|
33
|
+
*/
|
|
34
|
+
css: string;
|
|
35
|
+
/**
|
|
36
|
+
* Base directory for resolving `@import` / `@source` relative paths.
|
|
37
|
+
* Defaults to `process.cwd()`.
|
|
38
|
+
*/
|
|
39
|
+
base?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Load a Tailwind v4 design system from CSS source and project its resolved
|
|
43
|
+
* theme into a flat list of {@link ExtractedToken}s ready for Panda.
|
|
44
|
+
*/
|
|
45
|
+
export declare function extractTokens(opts: ExtractOptions): Promise<ExtractedToken[]>;
|
|
46
|
+
/** Convenience: load CSS from a file path then extract. */
|
|
47
|
+
export declare function extractTokensFromFile(path: string): Promise<ExtractedToken[]>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ExtractedToken } from "./extract";
|
|
2
|
+
export interface ExtractSyncOptions {
|
|
3
|
+
/** Inline CSS source. Either this or {@link cssPath} must be set. */
|
|
4
|
+
css?: string;
|
|
5
|
+
/** Path to the user's Tailwind entry CSS. */
|
|
6
|
+
cssPath?: string;
|
|
7
|
+
/** Base dir for resolving `@import` relative paths. */
|
|
8
|
+
base?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Synchronous token extraction. Walks the user's CSS, follows `@import` to
|
|
12
|
+
* `tailwindcss` (and friends) by reading those files from disk, and collects
|
|
13
|
+
* every `--*` declaration that appears inside an `@theme {}` block.
|
|
14
|
+
*
|
|
15
|
+
* This sidesteps Tailwind's async design-system loader so it can be called
|
|
16
|
+
* from inside PandaCSS configs (which Panda bundles to CJS — no top-level
|
|
17
|
+
* await).
|
|
18
|
+
*/
|
|
19
|
+
export declare function extractTokensSync(opts: ExtractSyncOptions): ExtractedToken[];
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { tailwindPreset, tailwindPresetSync, type TailwindPresetOptions, } from "./preset";
|
|
2
|
+
export { extractTokens, extractTokensFromFile, type ExtractedToken, type ExtractOptions, } from "./extract";
|
|
3
|
+
export { extractTokensSync, type ExtractSyncOptions } from "./extractSync";
|
|
4
|
+
export { matchNamespace, TAILWIND_NAMESPACES, type NamespaceMapping, type PandaTokenCategory, } from "./namespaces";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,386 @@
|
|
|
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);
|
|
16
|
+
|
|
17
|
+
// src/namespaces.ts
|
|
18
|
+
function matchNamespace(themeKey) {
|
|
19
|
+
if (!themeKey.startsWith("--"))
|
|
20
|
+
return null;
|
|
21
|
+
const stripped = themeKey.slice(2);
|
|
22
|
+
if (stripped.includes("--"))
|
|
23
|
+
return null;
|
|
24
|
+
for (const mapping of TAILWIND_NAMESPACES) {
|
|
25
|
+
if (stripped === mapping.prefix) {
|
|
26
|
+
return { mapping, rest: "DEFAULT" };
|
|
27
|
+
}
|
|
28
|
+
const withDash = `${mapping.prefix}-`;
|
|
29
|
+
if (stripped.startsWith(withDash)) {
|
|
30
|
+
return { mapping, rest: stripped.slice(withDash.length) };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
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
|
+
|
|
60
|
+
// src/derivedScales.ts
|
|
61
|
+
function synthesiseDerivedTokens(hasSpacingBase) {
|
|
62
|
+
const out = [];
|
|
63
|
+
if (hasSpacingBase) {
|
|
64
|
+
pushNumericScale(out);
|
|
65
|
+
}
|
|
66
|
+
pushNamed(out);
|
|
67
|
+
return out;
|
|
68
|
+
}
|
|
69
|
+
function pushNumericScale(out) {
|
|
70
|
+
for (const step of TAILWIND_NUMERIC_STEPS) {
|
|
71
|
+
const name = String(step);
|
|
72
|
+
const value = `calc(var(--spacing) * ${name})`;
|
|
73
|
+
const cssVar = `--spacing-${name.replace(".", "_")}`;
|
|
74
|
+
out.push({ cssVar, value, category: "spacing", path: [name] });
|
|
75
|
+
out.push({ cssVar, value, category: "sizes", path: [name] });
|
|
76
|
+
out.push({ cssVar, value, category: "lineHeights", path: [name] });
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function pushNamed(out) {
|
|
80
|
+
for (const [name, value] of Object.entries(NAMED_SIZES)) {
|
|
81
|
+
out.push({
|
|
82
|
+
cssVar: `--sizes-${name.replace(".", "_")}`,
|
|
83
|
+
value,
|
|
84
|
+
category: "sizes",
|
|
85
|
+
path: [name]
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
for (const [name, value] of Object.entries(NAMED_RADII)) {
|
|
89
|
+
out.push({
|
|
90
|
+
cssVar: `--radii-${name}`,
|
|
91
|
+
value,
|
|
92
|
+
category: "radii",
|
|
93
|
+
path: [name]
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
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
|
+
|
|
150
|
+
// src/extract.ts
|
|
151
|
+
var exports_extract = {};
|
|
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
|
+
function resolveStylesheet(id, basedir) {
|
|
161
|
+
if (id.startsWith(".") || id.startsWith("/")) {
|
|
162
|
+
return resolve(basedir, id);
|
|
163
|
+
}
|
|
164
|
+
const candidates = [`${id}/index.css`, `${id}.css`, id];
|
|
165
|
+
for (const candidate of candidates) {
|
|
166
|
+
try {
|
|
167
|
+
return requireFromHere.resolve(candidate, { paths: [basedir] });
|
|
168
|
+
} catch {}
|
|
169
|
+
}
|
|
170
|
+
throw new Error(`pandatail: cannot resolve stylesheet '${id}' from ${basedir}`);
|
|
171
|
+
}
|
|
172
|
+
async function extractTokens(opts) {
|
|
173
|
+
const base = opts.base ?? process.cwd();
|
|
174
|
+
const ds = await __unstable__loadDesignSystem(opts.css, {
|
|
175
|
+
base,
|
|
176
|
+
loadStylesheet: async (id, basedir) => {
|
|
177
|
+
const path = resolveStylesheet(id, basedir);
|
|
178
|
+
const content = await readFile(path, "utf8");
|
|
179
|
+
return { path, base: dirname(path), content };
|
|
180
|
+
},
|
|
181
|
+
loadModule: async () => {
|
|
182
|
+
throw new Error("loadModule is not supported in pandatail extraction");
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const themeEntries = new Map;
|
|
186
|
+
for (const [key, entry] of ds.theme.entries())
|
|
187
|
+
themeEntries.set(key, entry.value);
|
|
188
|
+
const out = [];
|
|
189
|
+
for (const [key, rawValue] of themeEntries) {
|
|
190
|
+
const matched = matchNamespace(key);
|
|
191
|
+
if (!matched)
|
|
192
|
+
continue;
|
|
193
|
+
if (matched.rest === "DEFAULT")
|
|
194
|
+
continue;
|
|
195
|
+
out.push({
|
|
196
|
+
cssVar: key,
|
|
197
|
+
value: matched.mapping.category === "breakpoints" ? rawValue : `var(${key})`,
|
|
198
|
+
category: matched.mapping.category,
|
|
199
|
+
path: matched.rest.split("-")
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
out.push(...synthesiseDerivedTokens(themeEntries.has("--spacing")));
|
|
203
|
+
return out;
|
|
204
|
+
}
|
|
205
|
+
async function extractTokensFromFile(path) {
|
|
206
|
+
const css = await readFile(path, "utf8");
|
|
207
|
+
return extractTokens({ css, base: dirname(resolve(path)) });
|
|
208
|
+
}
|
|
209
|
+
var requireFromHere;
|
|
210
|
+
var init_extract = __esm(() => {
|
|
211
|
+
init_namespaces();
|
|
212
|
+
init_derivedScales();
|
|
213
|
+
requireFromHere = createRequire(`${process.cwd()}/__pandatail_anchor__`);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// src/preset.ts
|
|
217
|
+
init_extract();
|
|
218
|
+
import { definePreset } from "@pandacss/dev";
|
|
219
|
+
|
|
220
|
+
// src/extractSync.ts
|
|
221
|
+
init_namespaces();
|
|
222
|
+
init_derivedScales();
|
|
223
|
+
import postcss from "postcss";
|
|
224
|
+
import { readFileSync } from "node:fs";
|
|
225
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
226
|
+
import { dirname as dirname2, resolve as resolve2 } from "node:path";
|
|
227
|
+
var requireFromHere2 = createRequire2(`${process.cwd()}/__pandatail_anchor__`);
|
|
228
|
+
function extractTokensSync(opts) {
|
|
229
|
+
let css;
|
|
230
|
+
let base;
|
|
231
|
+
if (opts.css != null) {
|
|
232
|
+
css = opts.css;
|
|
233
|
+
base = opts.base ?? process.cwd();
|
|
234
|
+
} else if (opts.cssPath != null) {
|
|
235
|
+
const abs = resolve2(opts.cssPath);
|
|
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")));
|
|
258
|
+
return out;
|
|
259
|
+
}
|
|
260
|
+
function collectThemeDecls(css, basedir, decls, seen) {
|
|
261
|
+
const root = postcss.parse(css);
|
|
262
|
+
root.walkAtRules((rule) => {
|
|
263
|
+
if (rule.name === "import") {
|
|
264
|
+
const id = parseImportTarget(rule.params);
|
|
265
|
+
if (!id)
|
|
266
|
+
return;
|
|
267
|
+
const path = resolveCssImport(id, basedir);
|
|
268
|
+
if (!path || seen.has(path))
|
|
269
|
+
return;
|
|
270
|
+
seen.add(path);
|
|
271
|
+
const content = readFileSync(path, "utf8");
|
|
272
|
+
collectThemeDecls(content, dirname2(path), decls, seen);
|
|
273
|
+
} else if (rule.name === "theme") {
|
|
274
|
+
rule.walkDecls((d) => {
|
|
275
|
+
if (d.prop.startsWith("--")) {
|
|
276
|
+
decls.set(d.prop, d.value);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
function parseImportTarget(params) {
|
|
283
|
+
const trimmed = params.trim();
|
|
284
|
+
const urlMatch = /^url\(\s*["']?([^"')]+)["']?\s*\)/.exec(trimmed);
|
|
285
|
+
if (urlMatch)
|
|
286
|
+
return urlMatch[1];
|
|
287
|
+
const quoteMatch = /^["']([^"']+)["']/.exec(trimmed);
|
|
288
|
+
if (quoteMatch)
|
|
289
|
+
return quoteMatch[1];
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
function resolveCssImport(id, basedir) {
|
|
293
|
+
if (id.startsWith(".") || id.startsWith("/")) {
|
|
294
|
+
return resolve2(basedir, id);
|
|
295
|
+
}
|
|
296
|
+
const candidates = [`${id}/index.css`, `${id}.css`, id];
|
|
297
|
+
for (const candidate of candidates) {
|
|
298
|
+
try {
|
|
299
|
+
return requireFromHere2.resolve(candidate, { paths: [basedir] });
|
|
300
|
+
} catch {}
|
|
301
|
+
}
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// src/preset.ts
|
|
306
|
+
async function tailwindPreset(opts) {
|
|
307
|
+
const tokens = await loadTokens(opts);
|
|
308
|
+
return buildPreset(tokens);
|
|
309
|
+
}
|
|
310
|
+
function tailwindPresetSync(opts) {
|
|
311
|
+
const tokens = extractTokensSync(opts);
|
|
312
|
+
return buildPreset(tokens);
|
|
313
|
+
}
|
|
314
|
+
function buildPreset(tokens) {
|
|
315
|
+
const breakpoints = {};
|
|
316
|
+
const tokenTokens = [];
|
|
317
|
+
for (const t of tokens) {
|
|
318
|
+
if (t.category === "breakpoints") {
|
|
319
|
+
breakpoints[t.path.join("-")] = t.value;
|
|
320
|
+
} else {
|
|
321
|
+
tokenTokens.push(t);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
const tokensByCategory = groupByCategory(tokenTokens);
|
|
325
|
+
const theme = {};
|
|
326
|
+
for (const [category, list] of Object.entries(tokensByCategory)) {
|
|
327
|
+
theme[category] = buildTree(list);
|
|
328
|
+
}
|
|
329
|
+
return definePreset({
|
|
330
|
+
name: "tailwind",
|
|
331
|
+
theme: {
|
|
332
|
+
tokens: theme,
|
|
333
|
+
breakpoints
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
async function loadTokens(opts) {
|
|
338
|
+
if (opts.css != null) {
|
|
339
|
+
return extractTokens({ css: opts.css, base: opts.base });
|
|
340
|
+
}
|
|
341
|
+
if (opts.cssPath != null) {
|
|
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`");
|
|
346
|
+
}
|
|
347
|
+
function groupByCategory(tokens) {
|
|
348
|
+
const out = {};
|
|
349
|
+
for (const t of tokens) {
|
|
350
|
+
(out[t.category] ??= []).push(t);
|
|
351
|
+
}
|
|
352
|
+
return out;
|
|
353
|
+
}
|
|
354
|
+
function buildTree(tokens) {
|
|
355
|
+
const root = {};
|
|
356
|
+
for (const t of tokens) {
|
|
357
|
+
let cursor = root;
|
|
358
|
+
for (let i = 0;i < t.path.length - 1; i++) {
|
|
359
|
+
const seg = t.path[i];
|
|
360
|
+
const next = cursor[seg];
|
|
361
|
+
if (!next || "value" in next) {
|
|
362
|
+
const fresh = {};
|
|
363
|
+
cursor[seg] = fresh;
|
|
364
|
+
cursor = fresh;
|
|
365
|
+
} else {
|
|
366
|
+
cursor = next;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const leaf = t.path[t.path.length - 1];
|
|
370
|
+
cursor[leaf] = { value: t.value };
|
|
371
|
+
}
|
|
372
|
+
return root;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/index.ts
|
|
376
|
+
init_extract();
|
|
377
|
+
init_namespaces();
|
|
378
|
+
export {
|
|
379
|
+
tailwindPresetSync,
|
|
380
|
+
tailwindPreset,
|
|
381
|
+
matchNamespace,
|
|
382
|
+
extractTokensSync,
|
|
383
|
+
extractTokensFromFile,
|
|
384
|
+
extractTokens,
|
|
385
|
+
TAILWIND_NAMESPACES
|
|
386
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mapping from Tailwind v4 theme namespace prefix to PandaCSS token category.
|
|
3
|
+
*
|
|
4
|
+
* The prefix is the part after `--` and before the trailing identifier.
|
|
5
|
+
* Order matters: longer, more specific prefixes must come before shorter ones
|
|
6
|
+
* (e.g. `font-weight` before `font`) so longest-prefix-wins.
|
|
7
|
+
*/
|
|
8
|
+
export type PandaTokenCategory = "colors" | "fonts" | "fontSizes" | "fontWeights" | "letterSpacings" | "lineHeights" | "spacing" | "sizes" | "radii" | "shadows" | "dropShadows" | "blurs" | "borders" | "aspectRatios" | "easings" | "animations" | "durations" | "breakpoints";
|
|
9
|
+
export interface NamespaceMapping {
|
|
10
|
+
/** Tailwind namespace prefix, without leading `--`, without trailing `-`. */
|
|
11
|
+
prefix: string;
|
|
12
|
+
/** Panda token category this namespace projects into. */
|
|
13
|
+
category: PandaTokenCategory;
|
|
14
|
+
}
|
|
15
|
+
export declare const TAILWIND_NAMESPACES: NamespaceMapping[];
|
|
16
|
+
export declare function matchNamespace(themeKey: string): {
|
|
17
|
+
mapping: NamespaceMapping;
|
|
18
|
+
rest: string;
|
|
19
|
+
} | null;
|
package/dist/preset.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface TailwindPresetOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Inline Tailwind v4 CSS source. Either this or {@link cssPath} must be set.
|
|
4
|
+
*/
|
|
5
|
+
css?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Path to the user's Tailwind entry CSS (the file containing
|
|
8
|
+
* `@import "tailwindcss"` and any `@theme {}` blocks).
|
|
9
|
+
*/
|
|
10
|
+
cssPath?: string;
|
|
11
|
+
/**
|
|
12
|
+
* Base directory for resolving CSS imports.
|
|
13
|
+
*/
|
|
14
|
+
base?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Build a PandaCSS preset whose token layer references the CSS custom
|
|
18
|
+
* properties that Tailwind v4 emits from the user's `@theme` blocks.
|
|
19
|
+
*
|
|
20
|
+
* 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.
|
|
32
|
+
*/
|
|
33
|
+
export declare function tailwindPresetSync(opts: TailwindPresetOptions): import("@pandacss/types").Preset;
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@dmisdm/pandatail",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "PandaCSS preset that mirrors every token in your Tailwind v4 @theme into typed Panda style props. One source of truth, full TS type safety.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"pandacss",
|
|
8
|
+
"panda-preset",
|
|
9
|
+
"tailwindcss",
|
|
10
|
+
"tailwind",
|
|
11
|
+
"tailwind-v4",
|
|
12
|
+
"design-tokens",
|
|
13
|
+
"typescript",
|
|
14
|
+
"preset",
|
|
15
|
+
"css-in-js"
|
|
16
|
+
],
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/dmisdm/pandatail.git"
|
|
20
|
+
},
|
|
21
|
+
"type": "module",
|
|
22
|
+
"main": "./dist/index.js",
|
|
23
|
+
"module": "./dist/index.js",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
},
|
|
30
|
+
"./package.json": "./package.json"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE"
|
|
36
|
+
],
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "bun run clean && bun run build:js && bun run build:types",
|
|
39
|
+
"build:js": "bun build src/index.ts --outdir dist --target node --format esm --external @pandacss/dev --external tailwindcss --external postcss",
|
|
40
|
+
"build:types": "tsc --project tsconfig.build.json",
|
|
41
|
+
"clean": "rm -rf dist",
|
|
42
|
+
"test": "bun test",
|
|
43
|
+
"prepublishOnly": "bun run test && bun run build"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"@pandacss/dev": "^1.0.0",
|
|
47
|
+
"tailwindcss": "^4.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"tailwindcss": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"postcss": "^8.4.0"
|
|
56
|
+
},
|
|
57
|
+
"devDependencies": {
|
|
58
|
+
"@pandacss/dev": "^1.11.1",
|
|
59
|
+
"@tailwindcss/postcss": "^4.3.0",
|
|
60
|
+
"@types/bun": "latest",
|
|
61
|
+
"@types/node": "^25.8.0",
|
|
62
|
+
"tailwindcss": "^4.3.0",
|
|
63
|
+
"typescript": "^5"
|
|
64
|
+
}
|
|
65
|
+
}
|