@pantoken/utils 1.1.0 → 1.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.d.mts +2 -1
- package/dist/index.mjs +13 -8
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -78,7 +78,8 @@ interface ResolveOptions {
|
|
|
78
78
|
/**
|
|
79
79
|
* Build a resolver that expands `var(--x)` references to concrete leaf values against `base` (plus
|
|
80
80
|
* any `overrides`). With `mode` it collapses `light-dark()` to that branch; without, it leaves
|
|
81
|
-
* `light-dark()` in place.
|
|
81
|
+
* `light-dark()` in place. A token carrying a {@link Token.flatValue} resolves through that rather
|
|
82
|
+
* than its CSS-expression `value`, so callers always land on a real colour.
|
|
82
83
|
*
|
|
83
84
|
* @param base - The token set to resolve references against.
|
|
84
85
|
* @param options - {@link ResolveOptions}.
|
package/dist/index.mjs
CHANGED
|
@@ -135,7 +135,8 @@ const MAX_DEPTH = 12;
|
|
|
135
135
|
/**
|
|
136
136
|
* Build a resolver that expands `var(--x)` references to concrete leaf values against `base` (plus
|
|
137
137
|
* any `overrides`). With `mode` it collapses `light-dark()` to that branch; without, it leaves
|
|
138
|
-
* `light-dark()` in place.
|
|
138
|
+
* `light-dark()` in place. A token carrying a {@link Token.flatValue} resolves through that rather
|
|
139
|
+
* than its CSS-expression `value`, so callers always land on a real colour.
|
|
139
140
|
*
|
|
140
141
|
* @param base - The token set to resolve references against.
|
|
141
142
|
* @param options - {@link ResolveOptions}.
|
|
@@ -186,8 +187,8 @@ const MAX_DEPTH = 12;
|
|
|
186
187
|
* ```
|
|
187
188
|
*/
|
|
188
189
|
function makeResolver(base, options = {}) {
|
|
189
|
-
const map = new Map(base.map((t) => [t.name, t.value]));
|
|
190
|
-
for (const t of options.overrides ?? []) map.set(t.name, t.value);
|
|
190
|
+
const map = new Map(base.map((t) => [t.name, t.flatValue ?? t.value]));
|
|
191
|
+
for (const t of options.overrides ?? []) map.set(t.name, t.flatValue ?? t.value);
|
|
191
192
|
const pickMode = (value) => {
|
|
192
193
|
if (!options.mode) return value;
|
|
193
194
|
const m = LIGHT_DARK_RE.exec(value.trim());
|
|
@@ -224,7 +225,7 @@ function makeResolver(base, options = {}) {
|
|
|
224
225
|
*/
|
|
225
226
|
function resolveTokens(base, options = {}) {
|
|
226
227
|
const resolve = makeResolver(base, options);
|
|
227
|
-
return new Map(base.map((t) => [t.name, resolve(t.value)]));
|
|
228
|
+
return new Map(base.map((t) => [t.name, resolve(t.flatValue ?? t.value)]));
|
|
228
229
|
}
|
|
229
230
|
//#endregion
|
|
230
231
|
//#region src/drift.ts
|
|
@@ -259,6 +260,11 @@ function extractInstuiRefs(text) {
|
|
|
259
260
|
function tokenNames(ir) {
|
|
260
261
|
return new Set(ir.map((t) => t.name));
|
|
261
262
|
}
|
|
263
|
+
function declaredInstuiProperties(text) {
|
|
264
|
+
const declared = new Set([...text.matchAll(/@property\s+(--instui-[\w-]+)/g)].map((m) => m[1]));
|
|
265
|
+
for (const match of text.matchAll(/(--instui-[\w]+(?:-[\w]+)*)\s*:/g)) declared.add(match[1]);
|
|
266
|
+
return declared;
|
|
267
|
+
}
|
|
262
268
|
/**
|
|
263
269
|
* Drift check: `--instui-*` names in `text` that the IR doesn't define (sorted; empty means no
|
|
264
270
|
* drift). Use for outputs that *reference* tokens defined elsewhere — e.g. the docusaurus/vitepress
|
|
@@ -284,7 +290,8 @@ function tokenNames(ir) {
|
|
|
284
290
|
*/
|
|
285
291
|
function unknownReferences(text, ir) {
|
|
286
292
|
const names = tokenNames(ir);
|
|
287
|
-
|
|
293
|
+
const declared = declaredInstuiProperties(text);
|
|
294
|
+
return [...extractInstuiRefs(text)].filter((name) => !names.has(name) && !declared.has(name)).sort();
|
|
288
295
|
}
|
|
289
296
|
/**
|
|
290
297
|
* Self-containment check: `--instui-*` names referenced via `var()` in a stylesheet that it never
|
|
@@ -309,9 +316,7 @@ function unknownReferences(text, ir) {
|
|
|
309
316
|
*/
|
|
310
317
|
function danglingReferences(css) {
|
|
311
318
|
const referenced = new Set([...css.matchAll(/var\(\s*?(--instui-[\w-]+)/g)].map((m) => m[1]));
|
|
312
|
-
const defined =
|
|
313
|
-
for (const m of css.matchAll(/@property\s+(--instui-[\w-]+)/g)) defined.add(m[1]);
|
|
314
|
-
for (const m of css.matchAll(/(--instui-[\w]+(?:-[\w]+)*)\s*:/g)) defined.add(m[1]);
|
|
319
|
+
const defined = declaredInstuiProperties(css);
|
|
315
320
|
return [...referenced].filter((name) => !defined.has(name)).sort();
|
|
316
321
|
}
|
|
317
322
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pantoken/utils",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Shared pantoken helpers: token reference resolver, typed regexes (arkregex), name-case, and hex-colour parsing.",
|
|
5
5
|
"homepage": "https://pantoken.app",
|
|
6
6
|
"bugs": "https://github.com/thedannywahl/pantoken/issues",
|
|
@@ -26,13 +26,13 @@
|
|
|
26
26
|
"provenance": true
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@pantoken/model": "0.
|
|
29
|
+
"@pantoken/model": "0.5.0",
|
|
30
30
|
"arkregex": "^0.0.8",
|
|
31
31
|
"css-tree": "^3.2.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/css-tree": "^3.2.0",
|
|
35
|
-
"@types/node": "^26.6.
|
|
35
|
+
"@types/node": "^26.6.3",
|
|
36
36
|
"typescript": "^7.0.2",
|
|
37
37
|
"vite": "npm:@voidzero-dev/vite-plus-core@1.0.0-rc.0",
|
|
38
38
|
"vite-plus": "1.0.0-rc.0"
|