@dmisdm/pandatail 0.1.0 → 0.2.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 +22 -5
- package/dist/namespaces.d.ts +10 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -15,6 +15,16 @@ var __export = (target, all) => {
|
|
|
15
15
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
16
16
|
|
|
17
17
|
// src/namespaces.ts
|
|
18
|
+
function deriveTokenPath(rest) {
|
|
19
|
+
const lastDash = rest.lastIndexOf("-");
|
|
20
|
+
if (lastDash > 0) {
|
|
21
|
+
const after = rest.slice(lastDash + 1);
|
|
22
|
+
if (/^\d+$/.test(after)) {
|
|
23
|
+
return [rest.slice(0, lastDash), after];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return [rest];
|
|
27
|
+
}
|
|
18
28
|
function matchNamespace(themeKey) {
|
|
19
29
|
if (!themeKey.startsWith("--"))
|
|
20
30
|
return null;
|
|
@@ -196,7 +206,7 @@ async function extractTokens(opts) {
|
|
|
196
206
|
cssVar: key,
|
|
197
207
|
value: matched.mapping.category === "breakpoints" ? rawValue : `var(${key})`,
|
|
198
208
|
category: matched.mapping.category,
|
|
199
|
-
path: matched.rest
|
|
209
|
+
path: deriveTokenPath(matched.rest)
|
|
200
210
|
});
|
|
201
211
|
}
|
|
202
212
|
out.push(...synthesiseDerivedTokens(themeEntries.has("--spacing")));
|
|
@@ -251,7 +261,7 @@ function extractTokensSync(opts) {
|
|
|
251
261
|
cssVar,
|
|
252
262
|
value: matched.mapping.category === "breakpoints" ? rawValue : `var(${cssVar})`,
|
|
253
263
|
category: matched.mapping.category,
|
|
254
|
-
path: matched.rest
|
|
264
|
+
path: deriveTokenPath(matched.rest)
|
|
255
265
|
});
|
|
256
266
|
}
|
|
257
267
|
out.push(...synthesiseDerivedTokens(decls.has("--spacing")));
|
|
@@ -324,7 +334,7 @@ function buildPreset(tokens) {
|
|
|
324
334
|
const tokensByCategory = groupByCategory(tokenTokens);
|
|
325
335
|
const theme = {};
|
|
326
336
|
for (const [category, list] of Object.entries(tokensByCategory)) {
|
|
327
|
-
theme[category] = buildTree(list);
|
|
337
|
+
theme[category] = buildTree(list, category);
|
|
328
338
|
}
|
|
329
339
|
return definePreset({
|
|
330
340
|
name: "tailwind",
|
|
@@ -351,14 +361,17 @@ function groupByCategory(tokens) {
|
|
|
351
361
|
}
|
|
352
362
|
return out;
|
|
353
363
|
}
|
|
354
|
-
function buildTree(tokens) {
|
|
364
|
+
function buildTree(tokens, category) {
|
|
355
365
|
const root = {};
|
|
356
366
|
for (const t of tokens) {
|
|
357
367
|
let cursor = root;
|
|
358
368
|
for (let i = 0;i < t.path.length - 1; i++) {
|
|
359
369
|
const seg = t.path[i];
|
|
360
370
|
const next = cursor[seg];
|
|
361
|
-
if (
|
|
371
|
+
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.`);
|
|
373
|
+
}
|
|
374
|
+
if (!next) {
|
|
362
375
|
const fresh = {};
|
|
363
376
|
cursor[seg] = fresh;
|
|
364
377
|
cursor = fresh;
|
|
@@ -367,6 +380,10 @@ function buildTree(tokens) {
|
|
|
367
380
|
}
|
|
368
381
|
}
|
|
369
382
|
const leaf = t.path[t.path.length - 1];
|
|
383
|
+
const existing = cursor[leaf];
|
|
384
|
+
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.`);
|
|
386
|
+
}
|
|
370
387
|
cursor[leaf] = { value: t.value };
|
|
371
388
|
}
|
|
372
389
|
return root;
|
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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dmisdm/pandatail",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
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
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -62,4 +62,4 @@
|
|
|
62
62
|
"tailwindcss": "^4.3.0",
|
|
63
63
|
"typescript": "^5"
|
|
64
64
|
}
|
|
65
|
-
}
|
|
65
|
+
}
|