@tenphi/glaze 1.3.0 → 1.3.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.cjs +49 -37
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +49 -37
- package/dist/index.mjs.map +1 -1
- package/docs/api.md +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2186,9 +2186,12 @@ function applyToneFlip(delta, baseTone, flip) {
|
|
|
2186
2186
|
* result is clamped to `[0, 100]` only — crossing the dark tone window is
|
|
2187
2187
|
* intended, since the author asked for the extreme.
|
|
2188
2188
|
*/
|
|
2189
|
-
function extremeDarkTone(authorTone, mode, isHighContrast, baseResolved,
|
|
2190
|
-
const
|
|
2191
|
-
|
|
2189
|
+
function extremeDarkTone(authorTone, mode, isHighContrast, baseResolved, config) {
|
|
2190
|
+
const extremeLightTone = mapToneForScheme(authorTone, mode, false, isHighContrast, config);
|
|
2191
|
+
const lightBase = getSchemeVariant(baseResolved, false, isHighContrast);
|
|
2192
|
+
const darkBase = getSchemeVariant(baseResolved, true, isHighContrast);
|
|
2193
|
+
const shift = extremeLightTone - lightBase.t * 100;
|
|
2194
|
+
return clamp(darkBase.t * 100 + (mode === "auto" ? -shift : shift), 0, 100);
|
|
2192
2195
|
}
|
|
2193
2196
|
function resolveRootColor(def, isHighContrast, config) {
|
|
2194
2197
|
return clamp(passTone(def.tone, isHighContrast, config).value, 0, 100);
|
|
@@ -2241,12 +2244,10 @@ function resolveDependentColor(name, def, ctx, isHighContrast, isDark, channels,
|
|
|
2241
2244
|
const baseLightTone = getSchemeVariant(baseResolved, false, isHighContrast).t * 100;
|
|
2242
2245
|
preferredTone = mapToneForScheme(clamp(baseLightTone + applyToneFlip(parsed.value, baseLightTone, flip), 0, 100), "auto", true, isHighContrast, ctx.config);
|
|
2243
2246
|
} else preferredTone = clamp(baseTone + applyToneFlip(parsed.value, baseTone, flip), 0, 100);
|
|
2244
|
-
else
|
|
2245
|
-
isExtreme = true;
|
|
2246
|
-
preferredTone = extremeDarkTone(parsed.value, mode, isHighContrast, baseResolved, baseTone, ctx.config);
|
|
2247
|
-
} else {
|
|
2247
|
+
else {
|
|
2248
2248
|
isExtreme = parsed.kind === "extreme";
|
|
2249
|
-
preferredTone =
|
|
2249
|
+
if (isExtreme && isDark && mode !== "static") preferredTone = extremeDarkTone(parsed.value, mode, isHighContrast, baseResolved, ctx.config);
|
|
2250
|
+
else preferredTone = mapToneForScheme(parsed.value, mode, isDark, isHighContrast, ctx.config);
|
|
2250
2251
|
}
|
|
2251
2252
|
}
|
|
2252
2253
|
const rawContrast = def.contrast;
|
|
@@ -2254,15 +2255,14 @@ function resolveDependentColor(name, def, ctx, isHighContrast, isDark, channels,
|
|
|
2254
2255
|
const resolvedContrast = resolveContrastSpec(rawContrast, isHighContrast, ctx.config, polarity);
|
|
2255
2256
|
const baseOkhsl = toOkhslVariant(baseVariant);
|
|
2256
2257
|
const baseLinearRgb = okhslToLinearSrgb(baseOkhsl.h, baseOkhsl.s, baseOkhsl.l, baseVariant.pastel ?? ctx.config.pastel);
|
|
2257
|
-
const
|
|
2258
|
+
const preferredRange = isExtreme ? [0, 1] : schemeToneRange(isDark, mode, isHighContrast, ctx.config);
|
|
2258
2259
|
let initialDirection;
|
|
2259
2260
|
if (preferredTone < baseTone) initialDirection = "darker";
|
|
2260
2261
|
else if (preferredTone > baseTone) initialDirection = "lighter";
|
|
2261
|
-
const seedTone = isExtreme ? clamp(preferredTone / 100, 0, 1) : clamp(preferredTone / 100, toneRange[0], toneRange[1]);
|
|
2262
2262
|
const solve = {
|
|
2263
2263
|
hue: channels.hue,
|
|
2264
2264
|
saturation: channels.saturation,
|
|
2265
|
-
preferredTone:
|
|
2265
|
+
preferredTone: clamp(preferredTone / 100, preferredRange[0], preferredRange[1]),
|
|
2266
2266
|
baseLinearRgb,
|
|
2267
2267
|
toneRange: [0, 1],
|
|
2268
2268
|
flip,
|
|
@@ -2559,7 +2559,9 @@ function resolveAllColors(seed, defs, config, externalBases) {
|
|
|
2559
2559
|
*
|
|
2560
2560
|
* Hue is scheme-independent unless the theme or a color authors a dark hue,
|
|
2561
2561
|
* so declarations are collected per scheme (`'light'` / `'dark'`) and the dark
|
|
2562
|
-
* set is emitted only when it actually differs — see `
|
|
2562
|
+
* set is emitted only when it actually differs — see `buildHueDeclarations`.
|
|
2563
|
+
* A color that authors a hue in *either* scheme gets its own var in both, so
|
|
2564
|
+
* the shared `var()` reference stays valid.
|
|
2563
2565
|
*/
|
|
2564
2566
|
const ACHROMATIC_EPSILON = 1e-6;
|
|
2565
2567
|
function cssProp(prefix, name, suffix) {
|
|
@@ -2581,23 +2583,28 @@ function themeHuePlan(name, def, variant, ctx, scheme) {
|
|
|
2581
2583
|
const regDef = def;
|
|
2582
2584
|
const baseHueVar = `var(--${ctx.baseName}-hue)`;
|
|
2583
2585
|
const prop = cssProp(ctx.prefix, name, "-hue");
|
|
2584
|
-
if ((regDef.mode ?? "auto") === "static" && schemeSeedHue(ctx, "dark") !== ctx.seedHue) {
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2588
|
-
|
|
2589
|
-
|
|
2590
|
-
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
};
|
|
2594
|
-
}
|
|
2595
|
-
const authored = scheme === "dark" ? regDef.darkHue ?? regDef.hue : regDef.hue;
|
|
2596
|
-
if (authored === void 0) return {
|
|
2586
|
+
if ((regDef.mode ?? "auto") === "static" && schemeSeedHue(ctx, "dark") !== ctx.seedHue) return {
|
|
2587
|
+
hueVar: `var(${prop})`,
|
|
2588
|
+
inline: false,
|
|
2589
|
+
declarations: [{
|
|
2590
|
+
prop,
|
|
2591
|
+
value: String(variant.h)
|
|
2592
|
+
}]
|
|
2593
|
+
};
|
|
2594
|
+
if (regDef.hue === void 0 && regDef.darkHue === void 0) return {
|
|
2597
2595
|
hueVar: baseHueVar,
|
|
2598
2596
|
inline: false,
|
|
2599
2597
|
declarations: []
|
|
2600
2598
|
};
|
|
2599
|
+
const authored = scheme === "dark" ? regDef.darkHue ?? regDef.hue : regDef.hue;
|
|
2600
|
+
if (authored === void 0) return {
|
|
2601
|
+
hueVar: `var(${prop})`,
|
|
2602
|
+
inline: false,
|
|
2603
|
+
declarations: [{
|
|
2604
|
+
prop,
|
|
2605
|
+
value: baseHueVar
|
|
2606
|
+
}]
|
|
2607
|
+
};
|
|
2601
2608
|
const parsed = parseRelativeOrAbsolute(authored);
|
|
2602
2609
|
if (parsed.relative) {
|
|
2603
2610
|
const sign = parsed.value >= 0 ? "+" : "-";
|
|
@@ -2644,7 +2651,7 @@ function buildHuePlan(name, def, variant, ctx, scheme = "light") {
|
|
|
2644
2651
|
return themeHuePlan(name, def, variant, ctx, scheme);
|
|
2645
2652
|
}
|
|
2646
2653
|
/** Collect unique hue declarations across all colors (theme + per-color). */
|
|
2647
|
-
function collectHueDeclarations(resolved, ctx, scheme
|
|
2654
|
+
function collectHueDeclarations(resolved, ctx, scheme) {
|
|
2648
2655
|
if (ctx.emitDeclarations === false) return [];
|
|
2649
2656
|
const seen = /* @__PURE__ */ new Set();
|
|
2650
2657
|
const out = [];
|
|
@@ -2665,21 +2672,24 @@ function collectHueDeclarations(resolved, ctx, scheme = "light") {
|
|
|
2665
2672
|
return out;
|
|
2666
2673
|
}
|
|
2667
2674
|
/**
|
|
2668
|
-
*
|
|
2669
|
-
* light
|
|
2675
|
+
* Hue declarations for both schemes. `dark` is empty when it resolves to the
|
|
2676
|
+
* same hues as light — the common case, with no `darkHue` anywhere.
|
|
2670
2677
|
*
|
|
2671
|
-
* When they differ, the **whole** set is returned rather than only the
|
|
2672
|
-
* whose text changed. A relative declaration reads
|
|
2678
|
+
* When they differ, the **whole** dark set is returned rather than only the
|
|
2679
|
+
* entries whose text changed. A relative declaration reads
|
|
2673
2680
|
* `calc(var(--theme-hue) + N)` in both schemes even though its resolved value
|
|
2674
2681
|
* moves with the seed, and custom properties substitute `var()` at
|
|
2675
2682
|
* computed-value time on the declaring element — so re-declaring
|
|
2676
2683
|
* `--{baseName}-hue` alone would leave inherited per-color vars still holding
|
|
2677
2684
|
* the light-substituted value.
|
|
2678
2685
|
*/
|
|
2679
|
-
function
|
|
2680
|
-
const dark = collectHueDeclarations(resolved, ctx, "dark");
|
|
2686
|
+
function buildHueDeclarations(resolved, ctx) {
|
|
2681
2687
|
const light = collectHueDeclarations(resolved, ctx, "light");
|
|
2682
|
-
|
|
2688
|
+
const dark = collectHueDeclarations(resolved, ctx, "dark");
|
|
2689
|
+
return {
|
|
2690
|
+
light,
|
|
2691
|
+
dark: dark.length === light.length && dark.every((decl, i) => decl.prop === light[i].prop && decl.value === light[i].value) ? [] : dark
|
|
2692
|
+
};
|
|
2683
2693
|
}
|
|
2684
2694
|
function buildHuePlans(resolved, ctx) {
|
|
2685
2695
|
const plans = /* @__PURE__ */ new Map();
|
|
@@ -2769,8 +2779,9 @@ function buildTokenMap(resolved, prefix, states, modes, format = "oklch", pastel
|
|
|
2769
2779
|
const tokens = {};
|
|
2770
2780
|
const huePlans = channelCtx !== void 0 && format === "oklch" ? buildHuePlans(resolved, channelCtx) : void 0;
|
|
2771
2781
|
if (huePlans !== void 0 && channelCtx !== void 0) {
|
|
2772
|
-
|
|
2773
|
-
|
|
2782
|
+
const hueDecls = buildHueDeclarations(resolved, channelCtx);
|
|
2783
|
+
for (const decl of hueDecls.light) tokens[`$${decl.prop.slice(2)}`] = { "": decl.value };
|
|
2784
|
+
if (modes.dark) for (const decl of hueDecls.dark) {
|
|
2774
2785
|
const key = `$${decl.prop.slice(2)}`;
|
|
2775
2786
|
tokens[key] = {
|
|
2776
2787
|
...tokens[key],
|
|
@@ -2827,8 +2838,9 @@ function buildCssMap(resolved, prefix, suffix, format, pastel = false, channelCt
|
|
|
2827
2838
|
};
|
|
2828
2839
|
const huePlans = channelCtx !== void 0 && format === "oklch" ? buildHuePlans(resolved, channelCtx) : void 0;
|
|
2829
2840
|
if (huePlans !== void 0 && channelCtx !== void 0) {
|
|
2830
|
-
|
|
2831
|
-
for (const decl of
|
|
2841
|
+
const hueDecls = buildHueDeclarations(resolved, channelCtx);
|
|
2842
|
+
for (const decl of hueDecls.light) lines.light.push(`${decl.prop}: ${decl.value};`);
|
|
2843
|
+
for (const decl of hueDecls.dark) {
|
|
2832
2844
|
lines.dark.push(`${decl.prop}: ${decl.value};`);
|
|
2833
2845
|
lines.darkContrast.push(`${decl.prop}: ${decl.value};`);
|
|
2834
2846
|
}
|