@adea-ai/themes 0.11.9 → 0.11.13
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/accents.d.ts +19 -19
- package/dist/accents.d.ts.map +1 -1
- package/dist/accents.js +45 -93
- package/dist/accents.js.map +1 -1
- package/dist/adapters/base24.d.ts +21 -12
- package/dist/adapters/base24.d.ts.map +1 -1
- package/dist/adapters/base24.js +47 -72
- package/dist/adapters/base24.js.map +1 -1
- package/dist/adapters/css-variables.d.ts +29 -0
- package/dist/adapters/css-variables.d.ts.map +1 -0
- package/dist/adapters/css-variables.js +56 -0
- package/dist/adapters/css-variables.js.map +1 -0
- package/dist/adapters/css.d.ts +2 -4
- package/dist/adapters/css.d.ts.map +1 -1
- package/dist/adapters/css.js +7 -39
- package/dist/adapters/css.js.map +1 -1
- package/dist/adapters/shadcn.d.ts +8 -4
- package/dist/adapters/shadcn.d.ts.map +1 -1
- package/dist/adapters/shadcn.js +38 -57
- package/dist/adapters/shadcn.js.map +1 -1
- package/dist/adapters/shiki.d.ts +2 -10
- package/dist/adapters/shiki.d.ts.map +1 -1
- package/dist/adapters/shiki.js +16 -29
- package/dist/adapters/shiki.js.map +1 -1
- package/dist/adapters/tailwind.d.ts +3 -3
- package/dist/adapters/tailwind.d.ts.map +1 -1
- package/dist/adapters/tailwind.js +7 -28
- package/dist/adapters/tailwind.js.map +1 -1
- package/dist/adapters/xterm.d.ts.map +1 -1
- package/dist/adapters/xterm.js +9 -21
- package/dist/adapters/xterm.js.map +1 -1
- package/dist/base24-synthesis.d.ts +31 -0
- package/dist/base24-synthesis.d.ts.map +1 -0
- package/dist/base24-synthesis.js +25 -0
- package/dist/base24-synthesis.js.map +1 -0
- package/dist/derive.d.ts +1 -1
- package/dist/derive.d.ts.map +1 -1
- package/dist/derive.js +11 -26
- package/dist/derive.js.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/normalize.d.ts +0 -8
- package/dist/normalize.d.ts.map +1 -1
- package/dist/normalize.js +105 -232
- package/dist/normalize.js.map +1 -1
- package/dist/oklch.d.ts +1 -7
- package/dist/oklch.d.ts.map +1 -1
- package/dist/oklch.js +15 -35
- package/dist/oklch.js.map +1 -1
- package/dist/policy.d.ts +14 -4
- package/dist/policy.d.ts.map +1 -1
- package/dist/policy.js +16 -4
- package/dist/policy.js.map +1 -1
- package/dist/render.d.ts +30 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +74 -0
- package/dist/render.js.map +1 -0
- package/dist/sources.d.ts +26 -33
- package/dist/sources.d.ts.map +1 -1
- package/dist/sources.js +136 -305
- package/dist/sources.js.map +1 -1
- package/dist/step-search.d.ts +10 -0
- package/dist/step-search.d.ts.map +1 -0
- package/dist/step-search.js +21 -0
- package/dist/step-search.js.map +1 -0
- package/dist/theme-token-projection-script.js +1 -1
- package/dist/theme-token-projection.d.ts +34 -3
- package/dist/theme-token-projection.d.ts.map +1 -1
- package/dist/theme-token-projection.js +78 -2
- package/dist/theme-token-projection.js.map +1 -1
- package/dist/validate.d.ts +12 -17
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +17 -63
- package/dist/validate.js.map +1 -1
- package/package.json +1 -1
- package/src/accents.ts +57 -96
- package/src/adapters/base24.ts +53 -75
- package/src/adapters/css-variables.ts +67 -0
- package/src/adapters/css.ts +9 -54
- package/src/adapters/shadcn.ts +34 -60
- package/src/adapters/shiki.ts +17 -30
- package/src/adapters/tailwind.ts +7 -37
- package/src/adapters/xterm.ts +9 -21
- package/src/base24-synthesis.ts +29 -0
- package/src/derive.ts +12 -27
- package/src/index.ts +6 -5
- package/src/normalize.ts +140 -267
- package/src/oklch.ts +20 -35
- package/src/policy.ts +18 -4
- package/src/render.ts +82 -0
- package/src/sources.ts +160 -330
- package/src/step-search.ts +25 -0
- package/src/theme-token-projection.ts +126 -12
- package/src/validate.ts +31 -74
- package/dist/theme-token-projection-core.d.ts +0 -35
- package/dist/theme-token-projection-core.d.ts.map +0 -1
- package/dist/theme-token-projection-core.js +0 -84
- package/dist/theme-token-projection-core.js.map +0 -1
- package/src/theme-token-projection-core.ts +0 -131
package/dist/normalize.js
CHANGED
|
@@ -44,14 +44,13 @@
|
|
|
44
44
|
* reported as failing rather than silently shipping a colour that is no longer the
|
|
45
45
|
* one the palette's author chose.
|
|
46
46
|
*/
|
|
47
|
-
import {
|
|
48
|
-
import {
|
|
49
|
-
import { repairContrast } from './oklch.js';
|
|
50
|
-
import { ACCENT_SUBTLE_MINIMUM_ALPHA,
|
|
51
|
-
import { ACCENT_PREFERENCE, CONTRAST_FLOORS, MINIMUM_ACCENT_CHROMA, REPAIR_BUDGET, } from './policy.js';
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
export { ACCENT_PREFERENCE, CONTRAST_FLOORS, MINIMUM_ACCENT_CHROMA, REPAIR_BUDGET };
|
|
47
|
+
import { ANSI_KEYS } from './schema.js';
|
|
48
|
+
import { BASE24_TO_ANSI, parseBase24Palette } from './adapters/base24.js';
|
|
49
|
+
import { canonical, contrastRatio, contrastDirection, deltaEok, formatOklch, mix, parseColor, repairContrast, shiftLightness, } from './oklch.js';
|
|
50
|
+
import { ACCENT_SUBTLE_MINIMUM_ALPHA, tintCheck } from './accents.js';
|
|
51
|
+
import { ACCENT_PREFERENCE, CONTRAST_FLOORS, MINIMUM_ACCENT_CHROMA, REPAIR_BUDGET, REPAIR_STEP, } from './policy.js';
|
|
52
|
+
import { mostContrasting } from './render.js';
|
|
53
|
+
import { offsetSize, smallestOffset } from './step-search.js';
|
|
55
54
|
/**
|
|
56
55
|
* How much a repair changed the palette's colour.
|
|
57
56
|
*
|
|
@@ -89,10 +88,6 @@ const SURFACE_STEPS = Object.freeze({
|
|
|
89
88
|
function ladderDirection(background) {
|
|
90
89
|
return background.l <= 0.5 ? 1 : -1;
|
|
91
90
|
}
|
|
92
|
-
/** True when the declared variant and the measured canvas agree. */
|
|
93
|
-
export function appearanceMatchesCanvas(appearance, background) {
|
|
94
|
-
return (background.l <= 0.5 ? 'dark' : 'light') === appearance;
|
|
95
|
-
}
|
|
96
91
|
/**
|
|
97
92
|
* Builds one rung of the surface ladder.
|
|
98
93
|
*
|
|
@@ -110,8 +105,8 @@ function surfaceRung(background, step, direction) {
|
|
|
110
105
|
/**
|
|
111
106
|
* Assigns the greyscale ANSI roles.
|
|
112
107
|
*
|
|
113
|
-
* Base24 does not name `black`, `white` or `
|
|
114
|
-
* foreground slots do double duty — so the mapping is Adea's, and two things about
|
|
108
|
+
* Base24 does not name `black`, `brightBlack`, `white` or `brightWhite` — the
|
|
109
|
+
* background and foreground slots do double duty — so the mapping is Adea's, and two things about
|
|
115
110
|
* it are not obvious.
|
|
116
111
|
*
|
|
117
112
|
* **It is appearance-aware, because the ANSI greyscale ramp means opposite things
|
|
@@ -128,8 +123,7 @@ function surfaceRung(background, step, direction) {
|
|
|
128
123
|
* and `base11`. Where a palette leaves those darker than its canvas, the foreground
|
|
129
124
|
* ramp is used instead.
|
|
130
125
|
*
|
|
131
|
-
* Candidates are
|
|
132
|
-
* schemes routinely set `base05`, `base06` and `base07` to the same value — without
|
|
126
|
+
* Candidates are de-duplicated first, because light schemes routinely set `base05`, `base06` and `base07` to the same value — without
|
|
133
127
|
* de-duplication the ramp collapses to three members and the roles collide.
|
|
134
128
|
*/
|
|
135
129
|
function buildAnsiRamp(palette, background, appearance) {
|
|
@@ -160,8 +154,6 @@ function buildAnsiRamp(palette, background, appearance) {
|
|
|
160
154
|
if (distinct.every((kept) => deltaEok(kept, candidate) > 0.02))
|
|
161
155
|
distinct.push(candidate);
|
|
162
156
|
}
|
|
163
|
-
// Strongest first: the ramp is ranked by measured contrast, not by slot number,
|
|
164
|
-
// because a slot's contrast depends on which appearance the palette is.
|
|
165
157
|
distinct.sort((a, b) => contrastRatio(b, background) - contrastRatio(a, background));
|
|
166
158
|
const strongest = distinct[0] ?? palette.base05;
|
|
167
159
|
const dimmest = distinct[distinct.length - 1] ?? palette.base03;
|
|
@@ -240,25 +232,7 @@ function chooseAccent(themeId, ansi, surfaces, preferred, anchor) {
|
|
|
240
232
|
const candidate = ansi[role];
|
|
241
233
|
if (!candidate || candidate.c < MINIMUM_ACCENT_CHROMA)
|
|
242
234
|
continue;
|
|
243
|
-
|
|
244
|
-
// component floor on a raised surface, applied in sequence.
|
|
245
|
-
const onCanvas = repairRole(candidate, [background], anchor, CONTRAST_FLOORS.accent, REPAIR_BUDGET.accent);
|
|
246
|
-
if (!onCanvas.repair.satisfied) {
|
|
247
|
-
if (!fallback || onCanvas.repair.ratio > fallback.repair.ratio) {
|
|
248
|
-
fallback = { role, repair: onCanvas.repair };
|
|
249
|
-
}
|
|
250
|
-
continue;
|
|
251
|
-
}
|
|
252
|
-
const onRaised = repairRole(onCanvas.repair.color, surfaces.slice(1), anchor, CONTRAST_FLOORS.accentRaised, REPAIR_BUDGET.accent);
|
|
253
|
-
const attempt = {
|
|
254
|
-
repair: {
|
|
255
|
-
color: onRaised.repair.color,
|
|
256
|
-
ratio: onRaised.repair.ratio,
|
|
257
|
-
delta: onCanvas.repair.delta + onRaised.repair.delta,
|
|
258
|
-
satisfied: onRaised.repair.satisfied,
|
|
259
|
-
},
|
|
260
|
-
blended: onCanvas.blended || onRaised.blended,
|
|
261
|
-
};
|
|
235
|
+
const attempt = repairTwoTier(candidate, surfaces, anchor, { canvas: CONTRAST_FLOORS.accent, raised: CONTRAST_FLOORS.accentRaised }, REPAIR_BUDGET.accent);
|
|
262
236
|
if (attempt.repair.satisfied) {
|
|
263
237
|
satisfying.push({
|
|
264
238
|
role,
|
|
@@ -268,8 +242,6 @@ function chooseAccent(themeId, ansi, surfaces, preferred, anchor) {
|
|
|
268
242
|
});
|
|
269
243
|
continue;
|
|
270
244
|
}
|
|
271
|
-
// Track the best attempt so a theme that cannot satisfy the floor still gets
|
|
272
|
-
// its most legible candidate rather than an arbitrary one.
|
|
273
245
|
if (!fallback || attempt.repair.ratio > fallback.repair.ratio) {
|
|
274
246
|
fallback = { role, repair: attempt.repair };
|
|
275
247
|
}
|
|
@@ -299,7 +271,7 @@ function chooseAccent(themeId, ansi, surfaces, preferred, anchor) {
|
|
|
299
271
|
: `the declared accent slot ${preferred} could not clear the floor; used ${chosen.role} instead`,
|
|
300
272
|
});
|
|
301
273
|
}
|
|
302
|
-
if (chosen.repair.delta > 0
|
|
274
|
+
if (chosen.repair.delta > 0) {
|
|
303
275
|
findings.push({
|
|
304
276
|
themeId,
|
|
305
277
|
role: 'accent',
|
|
@@ -329,21 +301,18 @@ function chooseAccent(themeId, ansi, surfaces, preferred, anchor) {
|
|
|
329
301
|
* Not derived from the appearance, which is the tempting shortcut and is wrong:
|
|
330
302
|
* Catppuccin Mocha's blue accent is light enough that black is the legible label,
|
|
331
303
|
* while Nord's is dark enough that white is. The pick is whichever of the
|
|
332
|
-
* palette's
|
|
304
|
+
* palette's canvas and foreground slots measures better, repaired if none clears
|
|
305
|
+
* the floor.
|
|
333
306
|
*/
|
|
334
307
|
function chooseAccentForeground(themeId, accent, palette) {
|
|
335
308
|
const findings = [];
|
|
336
|
-
const
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
bestRatio = ratio;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
const repair = repairContrast(best, accent, CONTRAST_FLOORS.accentForeground, 0.6);
|
|
309
|
+
const best = mostContrasting(accent, [
|
|
310
|
+
palette.base00,
|
|
311
|
+
palette.base07,
|
|
312
|
+
palette.base05,
|
|
313
|
+
palette.base06,
|
|
314
|
+
]);
|
|
315
|
+
const repair = repairContrast(best, accent, CONTRAST_FLOORS.accentForeground, REPAIR_BUDGET.accentForeground);
|
|
347
316
|
if (!repair.satisfied) {
|
|
348
317
|
findings.push({
|
|
349
318
|
themeId,
|
|
@@ -364,15 +333,8 @@ function chooseAccentForeground(themeId, accent, palette) {
|
|
|
364
333
|
* as likely to appear inside a card or a popover as on the canvas, and those rungs
|
|
365
334
|
* are deliberately moved away from the canvas, so a colour tuned to exactly 4.5:1
|
|
366
335
|
* on the background lands at roughly 4.0:1 on a card.
|
|
367
|
-
*
|
|
368
|
-
* The surfaces of one theme all sit on the same side of the canvas, so the surface
|
|
369
|
-
* with the *lowest* current ratio is the furthest from the colour, and moving away
|
|
370
|
-
* from it moves away from all of them. The worst surface is recomputed on every
|
|
371
|
-
* step rather than chosen once, because a colour can cross between them.
|
|
372
336
|
*/
|
|
373
337
|
function repairAcrossSurfaces(color, surfaces, minimum, budget) {
|
|
374
|
-
// Measured in the canonical form the catalogue commits, so a repair cannot
|
|
375
|
-
// converge on a value that rounding then pushes back below the floor.
|
|
376
338
|
const worst = (candidate) => {
|
|
377
339
|
const rounded = canonical(candidate);
|
|
378
340
|
let result = { surface: surfaces[0], ratio: Number.POSITIVE_INFINITY };
|
|
@@ -387,24 +349,21 @@ function repairAcrossSurfaces(color, surfaces, minimum, budget) {
|
|
|
387
349
|
if (initial.ratio >= minimum) {
|
|
388
350
|
return { color, ratio: initial.ratio, delta: 0, satisfied: true };
|
|
389
351
|
}
|
|
390
|
-
const
|
|
391
|
-
const
|
|
392
|
-
const
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
return { color, ratio: initial.ratio, delta: 0, satisfied: false };
|
|
352
|
+
const step = REPAIR_STEP;
|
|
353
|
+
const shifted = (offset) => ({ ...color, l: color.l + offset });
|
|
354
|
+
const offset = smallestOffset(step, Math.floor(budget / step), [contrastDirection(color, initial.surface)], (trial) => {
|
|
355
|
+
const candidate = shifted(trial);
|
|
356
|
+
return candidate.l > 0 && candidate.l < 1 && worst(candidate).ratio >= minimum;
|
|
357
|
+
});
|
|
358
|
+
if (offset === undefined)
|
|
359
|
+
return { color, ratio: initial.ratio, delta: 0, satisfied: false };
|
|
360
|
+
const repaired = shifted(offset);
|
|
361
|
+
return {
|
|
362
|
+
color: repaired,
|
|
363
|
+
ratio: worst(repaired).ratio,
|
|
364
|
+
delta: offsetSize(offset),
|
|
365
|
+
satisfied: true,
|
|
366
|
+
};
|
|
408
367
|
}
|
|
409
368
|
/**
|
|
410
369
|
* Repairs a colour that cannot reach the floor by lightness alone, by blending it
|
|
@@ -422,9 +381,8 @@ function repairAcrossSurfaces(color, surfaces, minimum, budget) {
|
|
|
422
381
|
* The result is a muted, deeper version of the accent — which is what Everforest's
|
|
423
382
|
* light themes actually look like.
|
|
424
383
|
*
|
|
425
|
-
*
|
|
426
|
-
*
|
|
427
|
-
* an invented colour.
|
|
384
|
+
* When even a full blend cannot clear the floor, the theme is reported rather than
|
|
385
|
+
* shipped with an invented colour.
|
|
428
386
|
*/
|
|
429
387
|
function repairByBlending(color, surfaces, anchor, minimum) {
|
|
430
388
|
const worstRatio = (candidate) => Math.min(...surfaces.map((surface) => contrastRatio(canonical(candidate), surface)));
|
|
@@ -433,8 +391,6 @@ function repairByBlending(color, surfaces, anchor, minimum) {
|
|
|
433
391
|
if (worstRatio(anchor) < minimum) {
|
|
434
392
|
return { color, ratio: worstRatio(color), delta: 0, satisfied: false };
|
|
435
393
|
}
|
|
436
|
-
// The smallest blend that works: 20 iterations resolve the amount far below the
|
|
437
|
-
// precision the catalogue is committed at.
|
|
438
394
|
for (let iteration = 0; iteration < 20; iteration += 1) {
|
|
439
395
|
const mid = (low + high) / 2;
|
|
440
396
|
if (worstRatio(mix(color, anchor, mid)) >= minimum)
|
|
@@ -466,6 +422,25 @@ function repairRole(color, surfaces, anchor, minimum, budget) {
|
|
|
466
422
|
return { repair: blend, blended: true };
|
|
467
423
|
return { repair: lightness, blended: false };
|
|
468
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* The repair chain applied in two tiers: the `canvas` floor against the background,
|
|
427
|
+
* then the `raised` floor against the raised rungs, starting from the first result.
|
|
428
|
+
*/
|
|
429
|
+
function repairTwoTier(color, surfaces, anchor, floors, budget) {
|
|
430
|
+
const onCanvas = repairRole(color, surfaces.slice(0, 1), anchor, floors.canvas, budget);
|
|
431
|
+
if (!onCanvas.repair.satisfied)
|
|
432
|
+
return onCanvas;
|
|
433
|
+
const onRaised = repairRole(onCanvas.repair.color, surfaces.slice(1), anchor, floors.raised, budget);
|
|
434
|
+
return {
|
|
435
|
+
repair: {
|
|
436
|
+
color: onRaised.repair.color,
|
|
437
|
+
ratio: onRaised.repair.ratio,
|
|
438
|
+
delta: onCanvas.repair.delta + onRaised.repair.delta,
|
|
439
|
+
satisfied: onRaised.repair.satisfied,
|
|
440
|
+
},
|
|
441
|
+
blended: onCanvas.blended || onRaised.blended,
|
|
442
|
+
};
|
|
443
|
+
}
|
|
469
444
|
/**
|
|
470
445
|
* The Base24 slots that carry a hue rather than a grey.
|
|
471
446
|
*
|
|
@@ -506,8 +481,7 @@ const NORMAL_HUE_SLOTS = ['base08', 'base0A', 'base0B', 'base0C', 'base0D', 'bas
|
|
|
506
481
|
* Moving the group by one step instead transposes the whole set: every hue keeps its
|
|
507
482
|
* angle and chroma exactly, every relative lightness is preserved, and the palette
|
|
508
483
|
* stays internally consistent. The step is the smallest one that brings every *normal*
|
|
509
|
-
* hue to the floor
|
|
510
|
-
* rounding cannot push one back under.
|
|
484
|
+
* hue to the floor.
|
|
511
485
|
*/
|
|
512
486
|
function transposeHues(themeId, palette, floor, findings) {
|
|
513
487
|
const background = palette.base00;
|
|
@@ -518,20 +492,11 @@ function transposeHues(themeId, palette, floor, findings) {
|
|
|
518
492
|
// Both directions are tried, nearest first, as in `repairContrast`: a dark canvas
|
|
519
493
|
// needs its hues lightened and a light canvas needs them darkened, and a palette
|
|
520
494
|
// moved to the other kind of canvas is the whole point of the operation.
|
|
521
|
-
const step =
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
const probe = shiftLightness(palette[NORMAL_HUE_SLOTS[0]], candidate);
|
|
527
|
-
if (probe.l <= 0.02 || probe.l >= 0.98)
|
|
528
|
-
continue;
|
|
529
|
-
if (worst(candidate) >= floor) {
|
|
530
|
-
chosen = candidate;
|
|
531
|
-
break;
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
}
|
|
495
|
+
const step = REPAIR_STEP;
|
|
496
|
+
const chosen = smallestOffset(step, Math.floor(0.45 / step), [1, -1], (offset) => {
|
|
497
|
+
const probe = shiftLightness(palette[NORMAL_HUE_SLOTS[0]], offset);
|
|
498
|
+
return probe.l > 0.02 && probe.l < 0.98 && worst(offset) >= floor;
|
|
499
|
+
});
|
|
535
500
|
if (chosen === undefined) {
|
|
536
501
|
findings.push({
|
|
537
502
|
themeId,
|
|
@@ -558,10 +523,6 @@ function transposeHues(themeId, palette, floor, findings) {
|
|
|
558
523
|
export function normalizeTheme(source) {
|
|
559
524
|
const findings = [];
|
|
560
525
|
const vendored = parseBase24Palette(source.scheme.palette);
|
|
561
|
-
// Corrections are applied to the palette before anything derives from it, so the
|
|
562
|
-
// surface ladder, the accent and every floor are computed from the value that
|
|
563
|
-
// will actually ship. Correcting the output instead would leave the ladder built
|
|
564
|
-
// around a background that is not the background.
|
|
565
526
|
const palette = { ...vendored };
|
|
566
527
|
for (const [slot, value] of Object.entries(source.palette ?? {})) {
|
|
567
528
|
const parsed = parseColor(value);
|
|
@@ -575,9 +536,6 @@ export function normalizeTheme(source) {
|
|
|
575
536
|
message: `replaced the vendored ${slot} with the upstream project's own value`,
|
|
576
537
|
});
|
|
577
538
|
}
|
|
578
|
-
// The hue transpose, applied at the same stage as the corrections and for the same
|
|
579
|
-
// reason: the semantic roles derive from these slots, so transposing afterwards
|
|
580
|
-
// would leave `error` built from the untransposed red and the two disagreeing.
|
|
581
539
|
if (source.hueTranspose) {
|
|
582
540
|
const transposed = transposeHues(source.id, palette, source.hueTranspose.floor, findings);
|
|
583
541
|
for (const [slot, value] of Object.entries(transposed)) {
|
|
@@ -585,7 +543,8 @@ export function normalizeTheme(source) {
|
|
|
585
543
|
}
|
|
586
544
|
}
|
|
587
545
|
const background = palette.base00;
|
|
588
|
-
const
|
|
546
|
+
const direction = ladderDirection(background);
|
|
547
|
+
const appearance = direction === 1 ? 'dark' : 'light';
|
|
589
548
|
if (appearance !== source.appearance) {
|
|
590
549
|
findings.push({
|
|
591
550
|
themeId: source.id,
|
|
@@ -594,7 +553,6 @@ export function normalizeTheme(source) {
|
|
|
594
553
|
message: `declared ${source.appearance} but the canvas measures ${appearance}; used the measurement`,
|
|
595
554
|
});
|
|
596
555
|
}
|
|
597
|
-
const direction = ladderDirection(background);
|
|
598
556
|
const surface = surfaceRung(background, SURFACE_STEPS.surface, direction);
|
|
599
557
|
const surfaceElevated = surfaceRung(background, SURFACE_STEPS.surfaceElevated, direction);
|
|
600
558
|
const surfaceHover = surfaceRung(background, SURFACE_STEPS.surfaceHover, direction);
|
|
@@ -634,8 +592,6 @@ export function normalizeTheme(source) {
|
|
|
634
592
|
error: '',
|
|
635
593
|
info: '',
|
|
636
594
|
};
|
|
637
|
-
// Body text first: several palettes publish a foreground that fails on their own
|
|
638
|
-
// background, and every other role's floors are measured against the canvas.
|
|
639
595
|
const textFloor = source.textFloor ?? CONTRAST_FLOORS.text;
|
|
640
596
|
const textRepair = repairAcrossSurfaces(palette.base05, surfaces, textFloor, REPAIR_BUDGET.text);
|
|
641
597
|
const text = emit(source.id, 'text', textRepair, textFloor);
|
|
@@ -646,7 +602,7 @@ export function normalizeTheme(source) {
|
|
|
646
602
|
// Muted and subtle text are blends toward the canvas, then measured. Blending in
|
|
647
603
|
// OKLCH rather than alpha-compositing keeps the result a real colour that CSS can
|
|
648
604
|
// use without a backdrop.
|
|
649
|
-
const mutedRepair = repairAcrossSurfaces(mix(textRepair.color, background, 0.32), surfaces, CONTRAST_FLOORS.textMuted,
|
|
605
|
+
const mutedRepair = repairAcrossSurfaces(mix(textRepair.color, background, 0.32), surfaces, CONTRAST_FLOORS.textMuted, REPAIR_BUDGET.textMuted);
|
|
650
606
|
const muted = emit(source.id, 'textMuted', mutedRepair, CONTRAST_FLOORS.textMuted);
|
|
651
607
|
colors.textMuted = muted.value;
|
|
652
608
|
if (muted.finding)
|
|
@@ -665,12 +621,12 @@ export function normalizeTheme(source) {
|
|
|
665
621
|
* it does not, and either way the rung is reported.
|
|
666
622
|
*/
|
|
667
623
|
const mutedContrast = contrastRatio(mutedRepair.color, background);
|
|
668
|
-
const fromPalette = repairAcrossSurfaces(palette.base03, surfaces, CONTRAST_FLOORS.textSubtle,
|
|
624
|
+
const fromPalette = repairAcrossSurfaces(palette.base03, surfaces, CONTRAST_FLOORS.textSubtle, REPAIR_BUDGET.textSubtle);
|
|
669
625
|
const paletteSubtleContrast = contrastRatio(fromPalette.color, background);
|
|
670
626
|
const subtleFromPalette = paletteSubtleContrast < mutedContrast;
|
|
671
627
|
const subtleRepair = subtleFromPalette
|
|
672
628
|
? fromPalette
|
|
673
|
-
: repairAcrossSurfaces(mix(textRepair.color, background, 0.55), surfaces, CONTRAST_FLOORS.textSubtle,
|
|
629
|
+
: repairAcrossSurfaces(mix(textRepair.color, background, 0.55), surfaces, CONTRAST_FLOORS.textSubtle, REPAIR_BUDGET.textSubtle);
|
|
674
630
|
const subtle = emit(source.id, 'textSubtle', subtleRepair, CONTRAST_FLOORS.textSubtle);
|
|
675
631
|
colors.textSubtle = subtle.value;
|
|
676
632
|
if (subtle.finding)
|
|
@@ -683,20 +639,6 @@ export function normalizeTheme(source) {
|
|
|
683
639
|
message: `base03 measures ${paletteSubtleContrast.toFixed(1)}:1, no dimmer than textMuted's ${mutedContrast.toFixed(1)}:1, so the tertiary rung is a blend rather than the palette's comment colour`,
|
|
684
640
|
});
|
|
685
641
|
}
|
|
686
|
-
/**
|
|
687
|
-
* The status roles, each with fallback candidates.
|
|
688
|
-
*
|
|
689
|
-
* A palette's yellow is chosen to be *a* yellow, not to be legible as text — Ayu
|
|
690
|
-
* Light's `#ffcc66` measures 1.9:1 on its own near-white canvas, and no amount of
|
|
691
|
-
* lightness repair fixes that without turning it into olive, which is no longer
|
|
692
|
-
* Ayu. So each status role has candidates and takes the first that clears the
|
|
693
|
-
* floor: warnings fall back to the palette's orange slot, which is Base24's
|
|
694
|
-
* constants colour and in practice the warning colour this palette already uses;
|
|
695
|
-
* reds and greens fall back to their bright variants.
|
|
696
|
-
*
|
|
697
|
-
* The order is not "brightest first" — on a light canvas the bright variants are
|
|
698
|
-
* worse, so the declared ANSI colour is always tried before its bright sibling.
|
|
699
|
-
*/
|
|
700
642
|
/*
|
|
701
643
|
* Body text gets enough headroom above the secondary rung to stay the stronger of the
|
|
702
644
|
* two.
|
|
@@ -724,6 +666,20 @@ export function normalizeTheme(source) {
|
|
|
724
666
|
});
|
|
725
667
|
}
|
|
726
668
|
}
|
|
669
|
+
/**
|
|
670
|
+
* The status roles, each with fallback candidates.
|
|
671
|
+
*
|
|
672
|
+
* A palette's yellow is chosen to be *a* yellow, not to be legible as text — Ayu
|
|
673
|
+
* Light's `#ffcc66` measures 1.9:1 on its own near-white canvas, and no amount of
|
|
674
|
+
* lightness repair fixes that without turning it into olive, which is no longer
|
|
675
|
+
* Ayu. So each status role has candidates and takes the first that clears the
|
|
676
|
+
* floor: warnings fall back to the palette's orange slot, which is Base24's
|
|
677
|
+
* constants colour and in practice the warning colour this palette already uses;
|
|
678
|
+
* reds and greens fall back to their bright variants.
|
|
679
|
+
*
|
|
680
|
+
* The order is not "brightest first" — on a light canvas the bright variants are
|
|
681
|
+
* worse, so the declared ANSI colour is always tried before its bright sibling.
|
|
682
|
+
*/
|
|
727
683
|
const statusCandidates = {
|
|
728
684
|
error: [palette.base08, palette.base12],
|
|
729
685
|
success: [palette.base0B, palette.base14],
|
|
@@ -734,30 +690,11 @@ export function normalizeTheme(source) {
|
|
|
734
690
|
const key = role;
|
|
735
691
|
let chosen;
|
|
736
692
|
for (const candidate of candidates) {
|
|
737
|
-
// Two tiers, applied in sequence: the body floor on the canvas, then the
|
|
738
|
-
// indicator floor on the raised surfaces. Both push the colour the same way,
|
|
739
|
-
// so applying the second to the result of the first cannot undo it.
|
|
740
|
-
//
|
|
741
693
|
// The blend anchor is the *repaired* text colour rather than the palette's
|
|
742
694
|
// raw foreground: when a palette's own body text fails the floor on a raised
|
|
743
695
|
// surface, blending toward the raw value inherits that failure and the blend
|
|
744
696
|
// has no valid endpoint.
|
|
745
|
-
const
|
|
746
|
-
if (!onCanvas.repair.satisfied) {
|
|
747
|
-
if (!chosen || onCanvas.repair.ratio > chosen.repair.ratio)
|
|
748
|
-
chosen = onCanvas;
|
|
749
|
-
continue;
|
|
750
|
-
}
|
|
751
|
-
const onRaised = repairRole(onCanvas.repair.color, surfaces.slice(1), textRepair.color, CONTRAST_FLOORS.statusRaised, REPAIR_BUDGET.status);
|
|
752
|
-
const combined = {
|
|
753
|
-
repair: {
|
|
754
|
-
color: onRaised.repair.color,
|
|
755
|
-
ratio: onRaised.repair.ratio,
|
|
756
|
-
delta: onCanvas.repair.delta + onRaised.repair.delta,
|
|
757
|
-
satisfied: onRaised.repair.satisfied,
|
|
758
|
-
},
|
|
759
|
-
blended: onCanvas.blended || onRaised.blended,
|
|
760
|
-
};
|
|
697
|
+
const combined = repairTwoTier(candidate, surfaces, textRepair.color, { canvas: CONTRAST_FLOORS.status, raised: CONTRAST_FLOORS.statusRaised }, REPAIR_BUDGET.status);
|
|
761
698
|
if (combined.repair.satisfied) {
|
|
762
699
|
chosen = combined;
|
|
763
700
|
break;
|
|
@@ -779,36 +716,15 @@ export function normalizeTheme(source) {
|
|
|
779
716
|
}
|
|
780
717
|
}
|
|
781
718
|
const ramp = buildAnsiRamp(palette, background, appearance);
|
|
782
|
-
const
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
magenta: formatOklch(palette.base0E),
|
|
789
|
-
cyan: formatOklch(palette.base0C),
|
|
790
|
-
white: formatOklch(ramp.white),
|
|
791
|
-
brightBlack: formatOklch(ramp.brightBlack),
|
|
792
|
-
brightRed: formatOklch(palette.base12),
|
|
793
|
-
brightGreen: formatOklch(palette.base14),
|
|
794
|
-
brightYellow: formatOklch(palette.base13),
|
|
795
|
-
brightBlue: formatOklch(palette.base16),
|
|
796
|
-
brightMagenta: formatOklch(palette.base17),
|
|
797
|
-
brightCyan: formatOklch(palette.base15),
|
|
798
|
-
brightWhite: formatOklch(ramp.brightWhite),
|
|
799
|
-
};
|
|
800
|
-
const ansiColors = Object.fromEntries(Object.entries(ansi).map(([key]) => [key, palette[ansiToSlot(key, palette, ramp)]]));
|
|
719
|
+
const slotOf = BASE24_TO_ANSI;
|
|
720
|
+
const ansiColors = Object.fromEntries(ANSI_KEYS.map((key) => {
|
|
721
|
+
const slot = slotOf[key];
|
|
722
|
+
return [key, slot ? palette[slot] : ramp[key]];
|
|
723
|
+
}));
|
|
724
|
+
const ansi = Object.fromEntries(ANSI_KEYS.map((key) => [key, formatOklch(ansiColors[key])]));
|
|
801
725
|
const accent = chooseAccent(source.id, ansiColors, surfaces, source.accentSlot, textRepair.color);
|
|
802
726
|
findings.push(...accent.findings);
|
|
803
727
|
colors.accent = formatOklch(accent.repair.color);
|
|
804
|
-
if (accent.repair.delta > 0) {
|
|
805
|
-
findings.push({
|
|
806
|
-
themeId: source.id,
|
|
807
|
-
role: 'accent',
|
|
808
|
-
kind: 'repaired',
|
|
809
|
-
message: `lightness moved ${accent.repair.delta.toFixed(3)} to reach ${CONTRAST_FLOORS.accent}:1 against the canvas`,
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
728
|
const accentForeground = chooseAccentForeground(source.id, accent.repair.color, palette);
|
|
813
729
|
colors.accentForeground = formatOklch(accentForeground.value);
|
|
814
730
|
findings.push(...accentForeground.findings);
|
|
@@ -817,8 +733,8 @@ export function normalizeTheme(source) {
|
|
|
817
733
|
* applies to it either way.
|
|
818
734
|
*
|
|
819
735
|
* A composition can carry its structure donor's selection explicitly, and taking that
|
|
820
|
-
* on trust
|
|
821
|
-
* canvas —
|
|
736
|
+
* on trust once shipped an Adea Light selection measuring 1.11:1 against its own
|
|
737
|
+
* canvas — a donor's deliberately subtle selection is not the same as visible. An
|
|
822
738
|
* invisible selection is a functional defect rather than a matter of taste: the user
|
|
823
739
|
* cannot see what they have selected. So the declared value is used as given and still
|
|
824
740
|
* measured, and moving it is reported.
|
|
@@ -829,14 +745,12 @@ export function normalizeTheme(source) {
|
|
|
829
745
|
* (see `adapters/xterm.ts`).
|
|
830
746
|
*/
|
|
831
747
|
const declaredSelection = source.selection ? parseColor(source.selection) : undefined;
|
|
832
|
-
const selectionRepair = repairContrast(declaredSelection ?? palette.base02, background, CONTRAST_FLOORS.selection,
|
|
748
|
+
const selectionRepair = repairContrast(declaredSelection ?? palette.base02, background, CONTRAST_FLOORS.selection, REPAIR_BUDGET.selection);
|
|
833
749
|
const selection = emit(source.id, 'selection', selectionRepair, CONTRAST_FLOORS.selection);
|
|
834
750
|
if (selection.finding)
|
|
835
751
|
findings.push(selection.finding);
|
|
836
|
-
// Authored overrides
|
|
837
|
-
//
|
|
838
|
-
// role is an `oklch()` string, and an override written as hex in the source list
|
|
839
|
-
// must not be the one place that contract leaks.
|
|
752
|
+
// Authored overrides go through the same conversion as every derived value: a
|
|
753
|
+
// role is an `oklch()` string even when the source list writes it as hex.
|
|
840
754
|
if (source.colors) {
|
|
841
755
|
for (const [role, value] of Object.entries(source.colors)) {
|
|
842
756
|
colors[role] = authoredColor(source.id, role, value);
|
|
@@ -858,8 +772,6 @@ export function normalizeTheme(source) {
|
|
|
858
772
|
cursor: source.cursor
|
|
859
773
|
? authoredColor(source.id, 'cursor', source.cursor)
|
|
860
774
|
: formatOklch(palette.base05),
|
|
861
|
-
// The repaired value, not the declared one: `selectionRepair` above started from
|
|
862
|
-
// whatever the source declared.
|
|
863
775
|
selection: selection.value,
|
|
864
776
|
family: source.family,
|
|
865
777
|
familyLabel: source.familyLabel,
|
|
@@ -874,11 +786,6 @@ export function normalizeTheme(source) {
|
|
|
874
786
|
}
|
|
875
787
|
/** The resolution the interaction rungs are fitted at. */
|
|
876
788
|
const RUNG_FIT_STEP = 0.001;
|
|
877
|
-
/** Every fitting step from `from` down to `to`, inclusive, largest first. */
|
|
878
|
-
function stepsBetween(from, to) {
|
|
879
|
-
const count = Math.round((from - to) / RUNG_FIT_STEP);
|
|
880
|
-
return Array.from({ length: count + 1 }, (_, index) => from - index * RUNG_FIT_STEP);
|
|
881
|
-
}
|
|
882
789
|
/**
|
|
883
790
|
* Fits the hover and active rungs so body text stays legible on them.
|
|
884
791
|
*
|
|
@@ -889,9 +796,8 @@ function stepsBetween(from, to) {
|
|
|
889
796
|
* afford the full step: its hover rung measured 4.45:1 and its active rung 3.86:1.
|
|
890
797
|
*
|
|
891
798
|
* So each rung keeps its fixed step unless body text fails on it, and then gives up
|
|
892
|
-
* only as much as it must
|
|
893
|
-
*
|
|
894
|
-
* and hue its fixed step gave it, and the text and the canvas are untouched. The hover rung also reserves room for the primary tint at
|
|
799
|
+
* only as much lightness as it must; the text and the canvas are untouched. The
|
|
800
|
+
* hover rung also reserves room for the primary tint at
|
|
895
801
|
* `ACCENT_SUBTLE_MINIMUM_ALPHA`, because a selected row that is hovered paints the
|
|
896
802
|
* tint over it; without the reservation the tint would have to fall to nothing.
|
|
897
803
|
*
|
|
@@ -904,11 +810,12 @@ function fitInteractionRungs(source, theme, background, direction, findings) {
|
|
|
904
810
|
const fit = (role, from, floor, holds) => {
|
|
905
811
|
if (source.colors?.[role] !== undefined)
|
|
906
812
|
return from;
|
|
907
|
-
// Lightness only: the rung keeps the chroma and hue its fixed step gave it.
|
|
908
813
|
const original = surfaceRung(background, from, direction);
|
|
909
814
|
const rungAt = (step) => formatOklch({ ...original, l: background.l + step * direction });
|
|
910
|
-
const
|
|
911
|
-
|
|
815
|
+
const shrink = holds(rungAt(from))
|
|
816
|
+
? 0
|
|
817
|
+
: smallestOffset(RUNG_FIT_STEP, Math.round((from - floor) / RUNG_FIT_STEP), [-1], (offset) => holds(rungAt(from + offset)));
|
|
818
|
+
if (shrink === undefined) {
|
|
912
819
|
findings.push({
|
|
913
820
|
themeId: source.id,
|
|
914
821
|
role,
|
|
@@ -917,7 +824,8 @@ function fitInteractionRungs(source, theme, background, direction, findings) {
|
|
|
917
824
|
});
|
|
918
825
|
return from;
|
|
919
826
|
}
|
|
920
|
-
|
|
827
|
+
const step = from + shrink;
|
|
828
|
+
if (shrink !== 0) {
|
|
921
829
|
theme.colors[role] = rungAt(step);
|
|
922
830
|
findings.push({
|
|
923
831
|
themeId: source.id,
|
|
@@ -928,11 +836,9 @@ function fitInteractionRungs(source, theme, background, direction, findings) {
|
|
|
928
836
|
}
|
|
929
837
|
return step;
|
|
930
838
|
};
|
|
931
|
-
const
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
// does hold, where none does.
|
|
935
|
-
fit('surfaceActive', SURFACE_STEPS.surfaceActive, hover, (rung) => primaryTintClears(theme, rung, 0));
|
|
839
|
+
const clears = tintCheck(theme);
|
|
840
|
+
const hover = fit('surfaceHover', SURFACE_STEPS.surfaceHover, SURFACE_STEPS.surfaceElevated, (rung) => clears(rung, 0) && clears(rung, ACCENT_SUBTLE_MINIMUM_ALPHA));
|
|
841
|
+
fit('surfaceActive', SURFACE_STEPS.surfaceActive, hover, (rung) => clears(rung, 0));
|
|
936
842
|
}
|
|
937
843
|
/** Parses an authored value and re-serialises it in the catalogue's notation. */
|
|
938
844
|
function authoredColor(themeId, role, value) {
|
|
@@ -941,37 +847,4 @@ function authoredColor(themeId, role, value) {
|
|
|
941
847
|
throw new Error(`${themeId}: ${role} is not a colour: ${value}`);
|
|
942
848
|
return formatOklch(parsed);
|
|
943
849
|
}
|
|
944
|
-
/** Maps an ANSI role back to the Base24 slot it was read from. */
|
|
945
|
-
function ansiToSlot(role, palette, ramp) {
|
|
946
|
-
const direct = {
|
|
947
|
-
red: 'base08',
|
|
948
|
-
green: 'base0B',
|
|
949
|
-
yellow: 'base0A',
|
|
950
|
-
blue: 'base0D',
|
|
951
|
-
magenta: 'base0E',
|
|
952
|
-
cyan: 'base0C',
|
|
953
|
-
brightRed: 'base12',
|
|
954
|
-
brightYellow: 'base13',
|
|
955
|
-
brightGreen: 'base14',
|
|
956
|
-
brightCyan: 'base15',
|
|
957
|
-
brightBlue: 'base16',
|
|
958
|
-
brightMagenta: 'base17',
|
|
959
|
-
};
|
|
960
|
-
const slot = direct[role];
|
|
961
|
-
if (slot)
|
|
962
|
-
return slot;
|
|
963
|
-
const rampSlots = {
|
|
964
|
-
black: ramp.black,
|
|
965
|
-
white: ramp.white,
|
|
966
|
-
brightBlack: ramp.brightBlack,
|
|
967
|
-
brightWhite: ramp.brightWhite,
|
|
968
|
-
};
|
|
969
|
-
const target = rampSlots[role];
|
|
970
|
-
if (!target)
|
|
971
|
-
return 'base05';
|
|
972
|
-
const match = Object.keys(palette).find((candidate) => deltaEok(palette[candidate], target) < 1e-9);
|
|
973
|
-
return match ?? 'base05';
|
|
974
|
-
}
|
|
975
|
-
/** Re-exported so the normalizer's callers do not need a second import. */
|
|
976
|
-
export { contrastDirection };
|
|
977
850
|
//# sourceMappingURL=normalize.js.map
|