@ariaui/color 0.1.3 → 0.1.4

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.
@@ -0,0 +1,572 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __spreadValues = (a, b) => {
12
+ for (var prop in b || (b = {}))
13
+ if (__hasOwnProp.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop))
18
+ __defNormalProp(a, prop, b[prop]);
19
+ }
20
+ return a;
21
+ };
22
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
23
+ var __export = (target, all) => {
24
+ for (var name in all)
25
+ __defProp(target, name, { get: all[name], enumerable: true });
26
+ };
27
+ var __copyProps = (to, from, except, desc) => {
28
+ if (from && typeof from === "object" || typeof from === "function") {
29
+ for (let key of __getOwnPropNames(from))
30
+ if (!__hasOwnProp.call(to, key) && key !== except)
31
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
+ }
33
+ return to;
34
+ };
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+
37
+ // tokens.ts
38
+ var tokens_exports = {};
39
+ __export(tokens_exports, {
40
+ adjustHue: () => adjustHue,
41
+ complement: () => complement,
42
+ contrastRatio: () => contrastRatio,
43
+ darken: () => darken,
44
+ desaturate: () => desaturate,
45
+ grayscale: () => grayscale,
46
+ hexToOklch: () => hexToOklch,
47
+ invert: () => invert,
48
+ lighten: () => lighten,
49
+ listColorTokens: () => listColorTokens,
50
+ meetsAA: () => meetsAA,
51
+ meetsAAA: () => meetsAAA,
52
+ mix: () => mix,
53
+ oklabToOklch: () => oklabToOklch,
54
+ oklchToHex: () => oklchToHex,
55
+ oklchToOklab: () => oklchToOklab,
56
+ oklchToSrgb: () => oklchToSrgb,
57
+ parseHex: () => parseHex,
58
+ parseOklchChannels: () => parseOklchChannels,
59
+ parseOklchCss: () => parseOklchCss,
60
+ parseRgb: () => parseRgb,
61
+ resolveAllPrimitives: () => resolveAllPrimitives,
62
+ resolveAllSemantics: () => resolveAllSemantics,
63
+ resolveBase: () => resolveBase,
64
+ resolvePrimitive: () => resolvePrimitive,
65
+ resolveScale: () => resolveScale,
66
+ resolveSemantic: () => resolveSemantic,
67
+ saturate: () => saturate,
68
+ setAlpha: () => setAlpha,
69
+ srgbToHex: () => srgbToHex,
70
+ srgbToOklch: () => srgbToOklch,
71
+ suggestAccessible: () => suggestAccessible,
72
+ toCssChannels: () => toCssChannels,
73
+ toHexString: () => toHexString,
74
+ toOklchString: () => toOklchString,
75
+ toRgbString: () => toRgbString
76
+ });
77
+ module.exports = __toCommonJS(tokens_exports);
78
+
79
+ // src/parse.ts
80
+ function parseOklchChannels(channels) {
81
+ const normalised = channels.trim();
82
+ const [colorPart, alphaPart] = normalised.split("/").map((s) => s.trim());
83
+ const parts = colorPart.split(/\s+/);
84
+ if (parts.length !== 3) {
85
+ throw new Error(
86
+ `Invalid OKLCH channel string: expected "L C H", got "${channels}"`
87
+ );
88
+ }
89
+ const [rawL, rawC, rawH] = parts;
90
+ let l;
91
+ if (rawL.endsWith("%")) {
92
+ l = parseFloat(rawL) / 100;
93
+ } else {
94
+ l = parseFloat(rawL);
95
+ }
96
+ const c = parseFloat(rawC);
97
+ const h = parseFloat(rawH);
98
+ if (Number.isNaN(l) || Number.isNaN(c) || Number.isNaN(h)) {
99
+ throw new Error(
100
+ `Invalid OKLCH channel string: could not parse numbers from "${channels}"`
101
+ );
102
+ }
103
+ let alpha = 1;
104
+ if (alphaPart !== void 0) {
105
+ alpha = parseFloat(alphaPart);
106
+ if (Number.isNaN(alpha)) {
107
+ throw new Error(
108
+ `Invalid OKLCH alpha value: could not parse "${alphaPart}"`
109
+ );
110
+ }
111
+ }
112
+ return { l, c, h, alpha };
113
+ }
114
+ function parseOklchCss(css) {
115
+ const match = css.match(/oklch\(\s*(.+?)\s*\)/i);
116
+ if (!match) {
117
+ throw new Error(`Invalid oklch() CSS string: "${css}"`);
118
+ }
119
+ return parseOklchChannels(match[1]);
120
+ }
121
+ function parseHex(hex) {
122
+ let h = hex.startsWith("#") ? hex.slice(1) : hex;
123
+ if (h.length === 3) {
124
+ h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2];
125
+ } else if (h.length === 4) {
126
+ h = h[0] + h[0] + h[1] + h[1] + h[2] + h[2] + h[3] + h[3];
127
+ }
128
+ if (h.length !== 6 && h.length !== 8) {
129
+ throw new Error(`Invalid hex color: "${hex}"`);
130
+ }
131
+ if (!/^[0-9a-fA-F]+$/.test(h)) {
132
+ throw new Error(`Invalid hex color: "${hex}"`);
133
+ }
134
+ const r = parseInt(h.slice(0, 2), 16) / 255;
135
+ const g = parseInt(h.slice(2, 4), 16) / 255;
136
+ const b = parseInt(h.slice(4, 6), 16) / 255;
137
+ const alpha = h.length === 8 ? parseInt(h.slice(6, 8), 16) / 255 : 1;
138
+ return { r, g, b, alpha };
139
+ }
140
+ function parseRgb(css) {
141
+ const match = css.match(/rgba?\(\s*(.+?)\s*\)/i);
142
+ if (!match) {
143
+ throw new Error(`Invalid rgb()/rgba() CSS string: "${css}"`);
144
+ }
145
+ const inner = match[1];
146
+ if (inner.includes("/")) {
147
+ const [colorPart, alphaPart] = inner.split("/").map((s) => s.trim());
148
+ const [r, g, b] = colorPart.split(/\s+/).map(Number);
149
+ const alpha = parseFloat(alphaPart);
150
+ return { r: r / 255, g: g / 255, b: b / 255, alpha };
151
+ }
152
+ if (inner.includes(",")) {
153
+ const parts2 = inner.split(",").map((s) => parseFloat(s.trim()));
154
+ return {
155
+ r: parts2[0] / 255,
156
+ g: parts2[1] / 255,
157
+ b: parts2[2] / 255,
158
+ alpha: parts2.length === 4 ? parts2[3] : 1
159
+ };
160
+ }
161
+ const parts = inner.split(/\s+/).map(Number);
162
+ if (parts.length !== 3) {
163
+ throw new Error(`Invalid rgb() CSS string: "${css}"`);
164
+ }
165
+ return { r: parts[0] / 255, g: parts[1] / 255, b: parts[2] / 255, alpha: 1 };
166
+ }
167
+
168
+ // src/convert.ts
169
+ function oklchToOklab(c) {
170
+ const hRad = c.h * Math.PI / 180;
171
+ return {
172
+ L: c.l,
173
+ a: c.c * Math.cos(hRad),
174
+ b: c.c * Math.sin(hRad),
175
+ alpha: c.alpha
176
+ };
177
+ }
178
+ function oklabToOklch(lab) {
179
+ const c = Math.sqrt(lab.a * lab.a + lab.b * lab.b);
180
+ let h = Math.atan2(lab.b, lab.a) * 180 / Math.PI;
181
+ if (h < 0) h += 360;
182
+ if (c < 1e-8) h = 0;
183
+ return { l: lab.L, c, h, alpha: lab.alpha };
184
+ }
185
+ function oklabToLinearSrgb(lab) {
186
+ const l_ = lab.L + 0.3963377774 * lab.a + 0.2158037573 * lab.b;
187
+ const m_ = lab.L - 0.1055613458 * lab.a - 0.0638541728 * lab.b;
188
+ const s_ = lab.L - 0.0894841775 * lab.a - 1.291485548 * lab.b;
189
+ const l = l_ * l_ * l_;
190
+ const m = m_ * m_ * m_;
191
+ const s = s_ * s_ * s_;
192
+ const r = 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s;
193
+ const g = -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s;
194
+ const b = -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s;
195
+ return [r, g, b];
196
+ }
197
+ function linearSrgbToOklab(r, g, b) {
198
+ const l = 0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b;
199
+ const m = 0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b;
200
+ const s = 0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b;
201
+ const l_ = Math.cbrt(l);
202
+ const m_ = Math.cbrt(m);
203
+ const s_ = Math.cbrt(s);
204
+ return {
205
+ L: 0.2104542553 * l_ + 0.793617785 * m_ - 0.0040720468 * s_,
206
+ a: 1.9779984951 * l_ - 2.428592205 * m_ + 0.4505937099 * s_,
207
+ b: 0.0259040371 * l_ + 0.7827717662 * m_ - 0.808675766 * s_,
208
+ alpha: 1
209
+ };
210
+ }
211
+ function linearToGamma(c) {
212
+ if (c <= 31308e-7) return 12.92 * c;
213
+ return 1.055 * Math.pow(c, 1 / 2.4) - 0.055;
214
+ }
215
+ function gammaToLinear(c) {
216
+ if (c <= 0.04045) return c / 12.92;
217
+ return Math.pow((c + 0.055) / 1.055, 2.4);
218
+ }
219
+ var GAMUT_EPSILON = 1e-6;
220
+ var DELTA_E_TOLERANCE = 0.02;
221
+ var CHROMA_STEP = 0.01;
222
+ function deltaEOK(a, b) {
223
+ const dL = a.L - b.L;
224
+ const da = a.a - b.a;
225
+ const db = a.b - b.b;
226
+ return Math.sqrt(dL * dL + da * da + db * db);
227
+ }
228
+ function isInGamut(r, g, b) {
229
+ return r >= -GAMUT_EPSILON && r <= 1 + GAMUT_EPSILON && g >= -GAMUT_EPSILON && g <= 1 + GAMUT_EPSILON && b >= -GAMUT_EPSILON && b <= 1 + GAMUT_EPSILON;
230
+ }
231
+ function clampChannel(v) {
232
+ return Math.max(0, Math.min(1, v));
233
+ }
234
+ function gamutMapOklchToSrgb(color) {
235
+ if (color.l <= 0) return { r: 0, g: 0, b: 0, alpha: color.alpha };
236
+ if (color.l >= 1) return { r: 1, g: 1, b: 1, alpha: color.alpha };
237
+ const lab = oklchToOklab(color);
238
+ const [lr, lg, lb] = oklabToLinearSrgb(lab);
239
+ if (isInGamut(lr, lg, lb)) {
240
+ return {
241
+ r: linearToGamma(clampChannel(lr)),
242
+ g: linearToGamma(clampChannel(lg)),
243
+ b: linearToGamma(clampChannel(lb)),
244
+ alpha: color.alpha
245
+ };
246
+ }
247
+ let min = 0;
248
+ let max = color.c;
249
+ let mappedChroma = 0;
250
+ const zeroChromaLab = oklchToOklab(__spreadProps(__spreadValues({}, color), { c: 0 }));
251
+ const [zr, zg, zb] = oklabToLinearSrgb(zeroChromaLab);
252
+ if (!isInGamut(zr, zg, zb)) {
253
+ return {
254
+ r: linearToGamma(clampChannel(zr)),
255
+ g: linearToGamma(clampChannel(zg)),
256
+ b: linearToGamma(clampChannel(zb)),
257
+ alpha: color.alpha
258
+ };
259
+ }
260
+ while (max - min > CHROMA_STEP) {
261
+ const mid = (min + max) / 2;
262
+ const testColor = __spreadProps(__spreadValues({}, color), { c: mid });
263
+ const testLab = oklchToOklab(testColor);
264
+ const [tr, tg, tb] = oklabToLinearSrgb(testLab);
265
+ if (isInGamut(tr, tg, tb)) {
266
+ min = mid;
267
+ mappedChroma = mid;
268
+ } else {
269
+ const clampedR = clampChannel(tr);
270
+ const clampedG = clampChannel(tg);
271
+ const clampedB = clampChannel(tb);
272
+ const clampedLab = linearSrgbToOklab(clampedR, clampedG, clampedB);
273
+ const dE = deltaEOK(testLab, clampedLab);
274
+ if (dE <= DELTA_E_TOLERANCE) {
275
+ min = mid;
276
+ mappedChroma = mid;
277
+ } else {
278
+ max = mid;
279
+ }
280
+ }
281
+ }
282
+ const finalLab = oklchToOklab(__spreadProps(__spreadValues({}, color), { c: mappedChroma }));
283
+ const [fr, fg, fb] = oklabToLinearSrgb(finalLab);
284
+ return {
285
+ r: linearToGamma(clampChannel(fr)),
286
+ g: linearToGamma(clampChannel(fg)),
287
+ b: linearToGamma(clampChannel(fb)),
288
+ alpha: color.alpha
289
+ };
290
+ }
291
+ function oklchToSrgb(color) {
292
+ return gamutMapOklchToSrgb(color);
293
+ }
294
+ function srgbToOklch(color) {
295
+ const lr = gammaToLinear(color.r);
296
+ const lg = gammaToLinear(color.g);
297
+ const lb = gammaToLinear(color.b);
298
+ const lab = linearSrgbToOklab(lr, lg, lb);
299
+ return __spreadValues({}, oklabToOklch(__spreadProps(__spreadValues({}, lab), { alpha: color.alpha })));
300
+ }
301
+ function srgbToHex(color) {
302
+ const r = Math.round(clampChannel(color.r) * 255);
303
+ const g = Math.round(clampChannel(color.g) * 255);
304
+ const b = Math.round(clampChannel(color.b) * 255);
305
+ const hex = `#${r.toString(16).padStart(2, "0")}${g.toString(16).padStart(2, "0")}${b.toString(16).padStart(2, "0")}`;
306
+ if (color.alpha < 1) {
307
+ const a = Math.round(clampChannel(color.alpha) * 255);
308
+ return `${hex}${a.toString(16).padStart(2, "0")}`;
309
+ }
310
+ return hex;
311
+ }
312
+ function oklchToHex(color) {
313
+ return srgbToHex(oklchToSrgb(color));
314
+ }
315
+ function hexToOklch(hex) {
316
+ return srgbToOklch(parseHex(hex));
317
+ }
318
+
319
+ // src/manipulate.ts
320
+ function clamp(value, min, max) {
321
+ return Math.max(min, Math.min(max, value));
322
+ }
323
+ function normaliseHue(h) {
324
+ return (h % 360 + 360) % 360;
325
+ }
326
+ function lighten(color, amount) {
327
+ return __spreadProps(__spreadValues({}, color), { l: clamp(color.l + amount, 0, 1) });
328
+ }
329
+ function darken(color, amount) {
330
+ return __spreadProps(__spreadValues({}, color), { l: clamp(color.l - amount, 0, 1) });
331
+ }
332
+ function saturate(color, amount) {
333
+ return __spreadProps(__spreadValues({}, color), { c: Math.max(0, color.c + amount) });
334
+ }
335
+ function desaturate(color, amount) {
336
+ return __spreadProps(__spreadValues({}, color), { c: Math.max(0, color.c - amount) });
337
+ }
338
+ function setAlpha(color, alpha) {
339
+ return __spreadProps(__spreadValues({}, color), { alpha: clamp(alpha, 0, 1) });
340
+ }
341
+ function adjustHue(color, degrees) {
342
+ return __spreadProps(__spreadValues({}, color), { h: normaliseHue(color.h + degrees) });
343
+ }
344
+ function mix(color1, color2, ratio = 0.5) {
345
+ const t = clamp(ratio, 0, 1);
346
+ const l = color1.l + (color2.l - color1.l) * t;
347
+ const c = color1.c + (color2.c - color1.c) * t;
348
+ const alpha = color1.alpha + (color2.alpha - color1.alpha) * t;
349
+ let h1 = normaliseHue(color1.h);
350
+ let h2 = normaliseHue(color2.h);
351
+ let dh = h2 - h1;
352
+ if (dh > 180) dh -= 360;
353
+ if (dh < -180) dh += 360;
354
+ const h = normaliseHue(h1 + dh * t);
355
+ return { l, c, h, alpha };
356
+ }
357
+ function complement(color) {
358
+ return adjustHue(color, 180);
359
+ }
360
+ function invert(color) {
361
+ return __spreadProps(__spreadValues({}, color), { l: 1 - color.l });
362
+ }
363
+ function grayscale(color) {
364
+ return __spreadProps(__spreadValues({}, color), { c: 0, h: 0 });
365
+ }
366
+
367
+ // src/contrast.ts
368
+ function relativeLuminance(color) {
369
+ const toLinear = (c) => c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
370
+ const r = toLinear(color.r);
371
+ const g = toLinear(color.g);
372
+ const b = toLinear(color.b);
373
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
374
+ }
375
+ function contrastRatio(fg, bg) {
376
+ const fgSrgb = "l" in fg ? oklchToSrgb(fg) : fg;
377
+ const bgSrgb = "l" in bg ? oklchToSrgb(bg) : bg;
378
+ const l1 = relativeLuminance(fgSrgb);
379
+ const l2 = relativeLuminance(bgSrgb);
380
+ const lighter = Math.max(l1, l2);
381
+ const darker = Math.min(l1, l2);
382
+ return (lighter + 0.05) / (darker + 0.05);
383
+ }
384
+ function meetsAA(fg, bg, size = "normal") {
385
+ const ratio = contrastRatio(fg, bg);
386
+ return size === "large" ? ratio >= 3 : ratio >= 4.5;
387
+ }
388
+ function meetsAAA(fg, bg, size = "normal") {
389
+ const ratio = contrastRatio(fg, bg);
390
+ return size === "large" ? ratio >= 4.5 : ratio >= 7;
391
+ }
392
+ function suggestAccessible(fg, bg, target = "AA", size = "normal") {
393
+ const checker = target === "AAA" ? meetsAAA : meetsAA;
394
+ if (checker(fg, bg, size)) return fg;
395
+ const bgSrgb = "l" in bg ? oklchToSrgb(bg) : bg;
396
+ const bgLum = relativeLuminance(bgSrgb);
397
+ const directions = bgLum > 0.5 ? [(l, s) => l - s, (l, s) => l + s] : [(l, s) => l + s, (l, s) => l - s];
398
+ const step = 5e-3;
399
+ for (const adjust of directions) {
400
+ let testL = fg.l;
401
+ for (let i = 0; i < 220; i++) {
402
+ testL = adjust(testL, step);
403
+ if (testL < 0 || testL > 1) break;
404
+ testL = Math.max(0, Math.min(1, testL));
405
+ const candidate = __spreadProps(__spreadValues({}, fg), { l: testL });
406
+ if (checker(candidate, bg, size)) {
407
+ return candidate;
408
+ }
409
+ }
410
+ }
411
+ const blackRatio = contrastRatio({ l: 0, c: 0, h: 0, alpha: 1 }, bg);
412
+ const whiteRatio = contrastRatio({ l: 1, c: 0, h: 0, alpha: 1 }, bg);
413
+ return blackRatio > whiteRatio ? __spreadProps(__spreadValues({}, fg), { l: 0, c: 0 }) : __spreadProps(__spreadValues({}, fg), { l: 1, c: 0 });
414
+ }
415
+
416
+ // src/format.ts
417
+ function toOklchString(color) {
418
+ const l = `${roundTo(color.l * 100, 2)}%`;
419
+ const c = roundTo(color.c, 4);
420
+ const h = roundTo(color.h, 2);
421
+ if (color.alpha < 1) {
422
+ return `oklch(${l} ${c} ${h} / ${roundTo(color.alpha, 3)})`;
423
+ }
424
+ return `oklch(${l} ${c} ${h})`;
425
+ }
426
+ function toRgbString(color) {
427
+ const r = Math.round(clamp01(color.r) * 255);
428
+ const g = Math.round(clamp01(color.g) * 255);
429
+ const b = Math.round(clamp01(color.b) * 255);
430
+ if (color.alpha < 1) {
431
+ return `rgb(${r} ${g} ${b} / ${roundTo(color.alpha, 3)})`;
432
+ }
433
+ return `rgb(${r} ${g} ${b})`;
434
+ }
435
+ function toHexString(color) {
436
+ const srgb = "l" in color ? oklchToSrgb(color) : color;
437
+ return srgbToHex(srgb);
438
+ }
439
+ function toCssChannels(color) {
440
+ const l = `${roundTo(color.l * 100, 2)}%`;
441
+ const c = roundTo(color.c, 4);
442
+ const h = roundTo(color.h, 2);
443
+ return `${l} ${c} ${h}`;
444
+ }
445
+ function roundTo(value, decimals) {
446
+ const factor = Math.pow(10, decimals);
447
+ return Math.round(value * factor) / factor;
448
+ }
449
+ function clamp01(v) {
450
+ return Math.max(0, Math.min(1, v));
451
+ }
452
+
453
+ // src/palette.ts
454
+ var import_tokens = require("@ariaui/tokens");
455
+ function resolvePrimitive(scale, step) {
456
+ const scaleObj = import_tokens.primitives[scale];
457
+ const channels = scaleObj[step];
458
+ if (channels === void 0) {
459
+ throw new Error(
460
+ `Primitive not found: ${String(scale)}-${step}`
461
+ );
462
+ }
463
+ return parseOklchChannels(channels);
464
+ }
465
+ function resolveScale(scale) {
466
+ const scaleObj = import_tokens.primitives[scale];
467
+ const result = {};
468
+ for (const [key, value] of Object.entries(scaleObj)) {
469
+ result[Number(key)] = parseOklchChannels(value);
470
+ }
471
+ return result;
472
+ }
473
+ function resolveAllPrimitives() {
474
+ const result = {};
475
+ for (const scale of Object.keys(import_tokens.primitives)) {
476
+ result[scale] = resolveScale(scale);
477
+ }
478
+ return result;
479
+ }
480
+ function resolveBase(name) {
481
+ const channels = import_tokens.base[name];
482
+ if (!channels) {
483
+ throw new Error(`Base color not found: "${name}"`);
484
+ }
485
+ return parseOklchChannels(channels);
486
+ }
487
+
488
+ // src/resolve.ts
489
+ var import_tokens2 = require("@ariaui/tokens");
490
+ function resolveVarToChannels(value) {
491
+ const varMatch = value.match(/^var\(--color-(.+)\)$/);
492
+ if (!varMatch) return null;
493
+ const ref = varMatch[1];
494
+ if (ref in import_tokens2.base) {
495
+ return import_tokens2.base[ref];
496
+ }
497
+ const lastDash = ref.lastIndexOf("-");
498
+ if (lastDash === -1) return null;
499
+ const scale = ref.slice(0, lastDash);
500
+ const stepStr = ref.slice(lastDash + 1);
501
+ const step = parseInt(stepStr, 10);
502
+ if (Number.isNaN(step)) return null;
503
+ const scaleObj = import_tokens2.primitives[scale];
504
+ if (!scaleObj) return null;
505
+ const channels = scaleObj[step];
506
+ if (channels === void 0) return null;
507
+ return channels;
508
+ }
509
+ function resolveSemantic(tokenKey, mode = "light") {
510
+ var _a;
511
+ const map = mode === "dark" ? import_tokens2.dark : import_tokens2.light;
512
+ const value = (_a = map[tokenKey]) != null ? _a : import_tokens2.light[tokenKey];
513
+ if (value === void 0) return null;
514
+ const channels = resolveVarToChannels(value);
515
+ if (channels === null) return null;
516
+ return parseOklchChannels(channels);
517
+ }
518
+ function listColorTokens(mode = "light") {
519
+ const map = mode === "dark" ? __spreadValues(__spreadValues({}, import_tokens2.light), import_tokens2.dark) : import_tokens2.light;
520
+ return Object.keys(map).filter((key) => {
521
+ const value = map[key];
522
+ return resolveVarToChannels(value) !== null;
523
+ });
524
+ }
525
+ function resolveAllSemantics(mode = "light") {
526
+ const keys = listColorTokens(mode);
527
+ const result = {};
528
+ for (const key of keys) {
529
+ const color = resolveSemantic(key, mode);
530
+ if (color) result[key] = color;
531
+ }
532
+ return result;
533
+ }
534
+ // Annotate the CommonJS export names for ESM import in node:
535
+ 0 && (module.exports = {
536
+ adjustHue,
537
+ complement,
538
+ contrastRatio,
539
+ darken,
540
+ desaturate,
541
+ grayscale,
542
+ hexToOklch,
543
+ invert,
544
+ lighten,
545
+ listColorTokens,
546
+ meetsAA,
547
+ meetsAAA,
548
+ mix,
549
+ oklabToOklch,
550
+ oklchToHex,
551
+ oklchToOklab,
552
+ oklchToSrgb,
553
+ parseHex,
554
+ parseOklchChannels,
555
+ parseOklchCss,
556
+ parseRgb,
557
+ resolveAllPrimitives,
558
+ resolveAllSemantics,
559
+ resolveBase,
560
+ resolvePrimitive,
561
+ resolveScale,
562
+ resolveSemantic,
563
+ saturate,
564
+ setAlpha,
565
+ srgbToHex,
566
+ srgbToOklch,
567
+ suggestAccessible,
568
+ toCssChannels,
569
+ toHexString,
570
+ toOklchString,
571
+ toRgbString
572
+ });
@@ -0,0 +1,59 @@
1
+ import { OklchColor, ColorMode } from './index.cjs';
2
+ export { HexString, OklabColor, SrgbColor, adjustHue, complement, contrastRatio, darken, desaturate, grayscale, hexToOklch, invert, lighten, meetsAA, meetsAAA, mix, oklabToOklch, oklchToHex, oklchToOklab, oklchToSrgb, parseHex, parseOklchChannels, parseOklchCss, parseRgb, saturate, setAlpha, srgbToHex, srgbToOklch, suggestAccessible, toCssChannels, toHexString, toOklchString, toRgbString } from './index.cjs';
3
+ import { PrimitiveScale } from '@ariaui/tokens';
4
+
5
+ /** Scale names available in primitives. */
6
+ type ScaleName = keyof PrimitiveScale;
7
+ /** Step numbers in a typical 50–950 scale. */
8
+ type Step = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
9
+ /**
10
+ * Resolve a single primitive to an OklchColor.
11
+ *
12
+ * @example resolvePrimitive("brand", 600)
13
+ * → { l: 0.541, c: 0.247, h: 293, alpha: 1 }
14
+ */
15
+ declare function resolvePrimitive(scale: ScaleName, step: Step): OklchColor;
16
+ /**
17
+ * Resolve an entire scale to a Record of OklchColors.
18
+ *
19
+ * @example resolveScale("brand")
20
+ * → { 50: OklchColor, 100: OklchColor, ... }
21
+ */
22
+ declare function resolveScale(scale: ScaleName): Record<Step, OklchColor>;
23
+ /**
24
+ * Resolve all primitives into structured color objects.
25
+ */
26
+ declare function resolveAllPrimitives(): Record<ScaleName, Record<Step, OklchColor>>;
27
+ /**
28
+ * Resolve a base color ("white" or "black") to an OklchColor.
29
+ */
30
+ declare function resolveBase(name: "white" | "black"): OklchColor;
31
+
32
+ /**
33
+ * Resolve a semantic token key to a concrete OklchColor.
34
+ *
35
+ * Only resolves **color** tokens (those whose values are `var(--color-*)`)
36
+ * — not gradients, px values, or composite tokens.
37
+ *
38
+ * @param tokenKey - Semantic token key, e.g. "bg-brand-solid", "text-primary"
39
+ * @param mode - "light" or "dark"
40
+ * @returns OklchColor, or `null` if the token is not a resolvable color.
41
+ *
42
+ * @example
43
+ * resolveSemantic("bg-brand-solid", "light")
44
+ * // → { l: 0.541, c: 0.247, h: 293, alpha: 1 } (brand-600)
45
+ *
46
+ * resolveSemantic("bg-brand-solid", "dark")
47
+ * // → { l: 0.709, c: 0.159, h: 294, alpha: 1 } (brand-400)
48
+ */
49
+ declare function resolveSemantic(tokenKey: string, mode?: ColorMode): OklchColor | null;
50
+ /**
51
+ * List all semantic token keys that are resolvable to colors.
52
+ */
53
+ declare function listColorTokens(mode?: ColorMode): string[];
54
+ /**
55
+ * Resolve all color semantic tokens for a given mode.
56
+ */
57
+ declare function resolveAllSemantics(mode?: ColorMode): Record<string, OklchColor>;
58
+
59
+ export { ColorMode, OklchColor, type ScaleName, type Step, listColorTokens, resolveAllPrimitives, resolveAllSemantics, resolveBase, resolvePrimitive, resolveScale, resolveSemantic };
@@ -0,0 +1,59 @@
1
+ import { OklchColor, ColorMode } from './index.js';
2
+ export { HexString, OklabColor, SrgbColor, adjustHue, complement, contrastRatio, darken, desaturate, grayscale, hexToOklch, invert, lighten, meetsAA, meetsAAA, mix, oklabToOklch, oklchToHex, oklchToOklab, oklchToSrgb, parseHex, parseOklchChannels, parseOklchCss, parseRgb, saturate, setAlpha, srgbToHex, srgbToOklch, suggestAccessible, toCssChannels, toHexString, toOklchString, toRgbString } from './index.js';
3
+ import { PrimitiveScale } from '@ariaui/tokens';
4
+
5
+ /** Scale names available in primitives. */
6
+ type ScaleName = keyof PrimitiveScale;
7
+ /** Step numbers in a typical 50–950 scale. */
8
+ type Step = 50 | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
9
+ /**
10
+ * Resolve a single primitive to an OklchColor.
11
+ *
12
+ * @example resolvePrimitive("brand", 600)
13
+ * → { l: 0.541, c: 0.247, h: 293, alpha: 1 }
14
+ */
15
+ declare function resolvePrimitive(scale: ScaleName, step: Step): OklchColor;
16
+ /**
17
+ * Resolve an entire scale to a Record of OklchColors.
18
+ *
19
+ * @example resolveScale("brand")
20
+ * → { 50: OklchColor, 100: OklchColor, ... }
21
+ */
22
+ declare function resolveScale(scale: ScaleName): Record<Step, OklchColor>;
23
+ /**
24
+ * Resolve all primitives into structured color objects.
25
+ */
26
+ declare function resolveAllPrimitives(): Record<ScaleName, Record<Step, OklchColor>>;
27
+ /**
28
+ * Resolve a base color ("white" or "black") to an OklchColor.
29
+ */
30
+ declare function resolveBase(name: "white" | "black"): OklchColor;
31
+
32
+ /**
33
+ * Resolve a semantic token key to a concrete OklchColor.
34
+ *
35
+ * Only resolves **color** tokens (those whose values are `var(--color-*)`)
36
+ * — not gradients, px values, or composite tokens.
37
+ *
38
+ * @param tokenKey - Semantic token key, e.g. "bg-brand-solid", "text-primary"
39
+ * @param mode - "light" or "dark"
40
+ * @returns OklchColor, or `null` if the token is not a resolvable color.
41
+ *
42
+ * @example
43
+ * resolveSemantic("bg-brand-solid", "light")
44
+ * // → { l: 0.541, c: 0.247, h: 293, alpha: 1 } (brand-600)
45
+ *
46
+ * resolveSemantic("bg-brand-solid", "dark")
47
+ * // → { l: 0.709, c: 0.159, h: 294, alpha: 1 } (brand-400)
48
+ */
49
+ declare function resolveSemantic(tokenKey: string, mode?: ColorMode): OklchColor | null;
50
+ /**
51
+ * List all semantic token keys that are resolvable to colors.
52
+ */
53
+ declare function listColorTokens(mode?: ColorMode): string[];
54
+ /**
55
+ * Resolve all color semantic tokens for a given mode.
56
+ */
57
+ declare function resolveAllSemantics(mode?: ColorMode): Record<string, OklchColor>;
58
+
59
+ export { ColorMode, OklchColor, type ScaleName, type Step, listColorTokens, resolveAllPrimitives, resolveAllSemantics, resolveBase, resolvePrimitive, resolveScale, resolveSemantic };