@pantoken/utils 1.2.0 → 1.2.1
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.mjs +24 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -132,6 +132,28 @@ const VAR_RE = regex(VAR_SOURCE, "g");
|
|
|
132
132
|
/** A `light-dark(<light>, <dark>)` value; capture groups 1 and 2 are the two branches. */
|
|
133
133
|
const LIGHT_DARK_RE = regex(LIGHT_DARK_SOURCE);
|
|
134
134
|
const MAX_DEPTH = 12;
|
|
135
|
+
function lightDarkBranches(value) {
|
|
136
|
+
const trimmed = value.trim();
|
|
137
|
+
if (!trimmed.startsWith("light-dark(") || !trimmed.endsWith(")")) return void 0;
|
|
138
|
+
const content = trimmed.slice(11, -1);
|
|
139
|
+
let depth = 0;
|
|
140
|
+
let separator = -1;
|
|
141
|
+
for (let index = 0; index < content.length; index += 1) {
|
|
142
|
+
const char = content[index];
|
|
143
|
+
if (char === "(") depth += 1;
|
|
144
|
+
else if (char === ")") {
|
|
145
|
+
depth -= 1;
|
|
146
|
+
if (depth < 0) return void 0;
|
|
147
|
+
} else if (char === "," && depth === 0) {
|
|
148
|
+
if (separator !== -1) return void 0;
|
|
149
|
+
separator = index;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (depth !== 0 || separator === -1) return void 0;
|
|
153
|
+
const light = content.slice(0, separator).trim();
|
|
154
|
+
const dark = content.slice(separator + 1).trim();
|
|
155
|
+
return light && dark ? [light, dark] : void 0;
|
|
156
|
+
}
|
|
135
157
|
/**
|
|
136
158
|
* Build a resolver that expands `var(--x)` references to concrete leaf values against `base` (plus
|
|
137
159
|
* any `overrides`). With `mode` it collapses `light-dark()` to that branch; without, it leaves
|
|
@@ -191,8 +213,8 @@ function makeResolver(base, options = {}) {
|
|
|
191
213
|
for (const t of options.overrides ?? []) map.set(t.name, t.flatValue ?? t.value);
|
|
192
214
|
const pickMode = (value) => {
|
|
193
215
|
if (!options.mode) return value;
|
|
194
|
-
const
|
|
195
|
-
return
|
|
216
|
+
const branches = lightDarkBranches(value);
|
|
217
|
+
return branches ? branches[options.mode === "light" ? 0 : 1] : value;
|
|
196
218
|
};
|
|
197
219
|
const expand = (value, depth) => {
|
|
198
220
|
const picked = pickMode(value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pantoken/utils",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
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",
|