@tenphi/glaze 0.16.2 → 0.18.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.cjs +70 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -7
- package/dist/index.d.mts +27 -7
- package/dist/index.mjs +68 -18
- package/dist/index.mjs.map +1 -1
- package/docs/api.md +40 -21
- package/docs/methodology.md +3 -3
- package/docs/migration.md +6 -4
- package/docs/okhst.md +49 -0
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -16,6 +16,16 @@ type MinContrast$1 = number | ContrastPreset;
|
|
|
16
16
|
* | `'min'` | 15 | Dividers/decorative; APCA "point of invisibility" |
|
|
17
17
|
*/
|
|
18
18
|
type ApcaPreset = 'preferred' | 'body' | 'content' | 'large' | 'non-text' | 'min';
|
|
19
|
+
declare const APCA_PRESETS: Record<ApcaPreset, number>;
|
|
20
|
+
/**
|
|
21
|
+
* APCA-W3 "Enhanced Level" delta added to a bare APCA target in high-contrast
|
|
22
|
+
* mode when no explicit HC value is provided (analogous to WCAG AAA over AA).
|
|
23
|
+
* Only applied when neither the outer `contrast` pair nor the inner `apca`
|
|
24
|
+
* pair carries an explicit HC entry.
|
|
25
|
+
*/
|
|
26
|
+
declare const APCA_HC_ENHANCEMENT = 15;
|
|
27
|
+
/** Upper bound for an APCA Lc target after HC enhancement. */
|
|
28
|
+
declare const APCA_MAX_LC = 106;
|
|
19
29
|
/**
|
|
20
30
|
* Resolve an APCA target — a raw Lc number (kept as-is) or an `ApcaPreset`
|
|
21
31
|
* keyword mapped to its Lc value. The magnitude is forced non-negative.
|
|
@@ -40,8 +50,18 @@ declare function resolveMinContrast(value: MinContrast$1): number;
|
|
|
40
50
|
* given mode into `{ metric, target }`. Handles the inner metric HC pair and
|
|
41
51
|
* preset resolution. `polarity` is passed through to the result for the APCA
|
|
42
52
|
* branch (it controls argument order in the solver); WCAG ignores it.
|
|
53
|
+
*
|
|
54
|
+
* `outerExplicitHC` indicates whether the caller selected this `spec` from an
|
|
55
|
+
* explicit high-contrast entry of the outer `contrast` pair. Together with the
|
|
56
|
+
* inner metric pair, it decides whether the HC auto-enhancement fires:
|
|
57
|
+
* - APCA: +15 Lc "Enhanced Level" boost when neither level is explicit.
|
|
58
|
+
* - WCAG: AA → AAA / AA-large → AAA-large promotion (SC 1.4.3 → 1.4.6) when
|
|
59
|
+
* neither level is explicit. AAA-family presets and bare numbers are left
|
|
60
|
+
* unchanged (AAA is the top WCAG tier).
|
|
61
|
+
* Defaults to `false` (correct for direct callers, which pass a single
|
|
62
|
+
* selected spec rather than an outer pair).
|
|
43
63
|
*/
|
|
44
|
-
declare function resolveContrastForMode(spec: ContrastSpec, isHighContrast: boolean, polarity?: 'fg' | 'bg'): ResolvedContrast;
|
|
64
|
+
declare function resolveContrastForMode(spec: ContrastSpec, isHighContrast: boolean, polarity?: 'fg' | 'bg', outerExplicitHC?: boolean): ResolvedContrast;
|
|
45
65
|
/**
|
|
46
66
|
* APCA lightness contrast (Lc), signed: positive for dark text on light bg,
|
|
47
67
|
* negative for light text on dark bg. Inputs are screen luminances (0–1).
|
|
@@ -248,7 +268,7 @@ interface RegularColorDef {
|
|
|
248
268
|
* Defaults to the global `autoFlip` config (default `true`). Set `false`
|
|
249
269
|
* to clamp instead.
|
|
250
270
|
*/
|
|
251
|
-
|
|
271
|
+
autoFlip?: boolean;
|
|
252
272
|
/**
|
|
253
273
|
* Fixed opacity (0–1).
|
|
254
274
|
* Output includes alpha in the CSS value.
|
|
@@ -565,7 +585,7 @@ interface GlazeColorInput {
|
|
|
565
585
|
saturationFactor?: number;
|
|
566
586
|
mode?: AdaptationMode;
|
|
567
587
|
/** Flip out-of-bounds results instead of clamping. Default: global `autoFlip`. */
|
|
568
|
-
|
|
588
|
+
autoFlip?: boolean;
|
|
569
589
|
/**
|
|
570
590
|
* Fixed opacity (0–1). Output includes alpha in the CSS value.
|
|
571
591
|
* Combining with `contrast` is not recommended (perceived tone
|
|
@@ -660,7 +680,7 @@ interface GlazeColorOverrides {
|
|
|
660
680
|
* `contrast`) to the opposite side instead of clamping. Defaults to
|
|
661
681
|
* the global `autoFlip`.
|
|
662
682
|
*/
|
|
663
|
-
|
|
683
|
+
autoFlip?: boolean;
|
|
664
684
|
/**
|
|
665
685
|
* Contrast floor. By default solved against the literal seed
|
|
666
686
|
* (the value itself); when `base` is set, solved against the base's
|
|
@@ -832,7 +852,7 @@ interface GlazeColorInputExport {
|
|
|
832
852
|
tone: HCPair<number | ExtremeValue>;
|
|
833
853
|
saturationFactor?: number;
|
|
834
854
|
mode?: AdaptationMode;
|
|
835
|
-
|
|
855
|
+
autoFlip?: boolean;
|
|
836
856
|
opacity?: number;
|
|
837
857
|
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
838
858
|
contrast?: HCPair<ContrastSpec>;
|
|
@@ -850,7 +870,7 @@ interface GlazeColorOverridesExport {
|
|
|
850
870
|
tone?: HCPair<ToneValue>;
|
|
851
871
|
saturationFactor?: number;
|
|
852
872
|
mode?: AdaptationMode;
|
|
853
|
-
|
|
873
|
+
autoFlip?: boolean;
|
|
854
874
|
contrast?: HCPair<ContrastSpec>;
|
|
855
875
|
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
856
876
|
opacity?: number;
|
|
@@ -1543,5 +1563,5 @@ declare function srgbToHex(rgb: [number, number, number]): `#${string}`;
|
|
|
1543
1563
|
*/
|
|
1544
1564
|
declare function okhslToOklch(h: number, s: number, l: number, pastel?: boolean): [number, number, number];
|
|
1545
1565
|
//#endregion
|
|
1546
|
-
export { type AdaptationMode, type ApcaPreset, type ChannelCtx, type ColorDef, type ColorMap, type ContrastPreset, type ContrastSpec, type DtcgColorSpace, type DtcgColorToken, type DtcgColorValue, type DtcgDocument, type DtcgOklchColorValue, type DtcgResolverModifier, type DtcgResolverRef, type DtcgResolverSet, type DtcgSrgbColorValue, type DtcgTokenTree, type ExtremeValue, type FindToneForContrastOptions, type FindToneForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, type GlazeColorCssOptions, type GlazeColorDtcgResolverOptions, type GlazeColorDtcgResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorInputExport, type GlazeColorOverrides, type GlazeColorOverridesExport, type GlazeColorTailwindOptions, type GlazeColorToken, type GlazeColorTokenExport, type GlazeColorValue, type GlazeConfig, type GlazeConfigOverride, type GlazeConfigResolved, type GlazeCssOptions, type GlazeCssResult, type GlazeDtcgOptions, type GlazeDtcgResolverContextNames, type GlazeDtcgResolverDocument, type GlazeDtcgResolverOptions, type GlazeDtcgResult, type GlazeExtendOptions, type GlazeFromInput, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, type GlazePaletteExportOptions, type GlazePaletteOptions, type GlazeShadowInput, type GlazeTailwindOptions, type GlazeTheme, type GlazeThemeExport, type GlazeTokenOptions, type HCPair, type HexColor, type HueDeclaration, type HuePlan, type MinContrast, type MixColorDef, type OkhslColor, type OkhstColor, type OklchColor, type Polarity, REF_EPS, type RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ResolvedContrast, type RgbColor, type Role, type RoleInput, type ShadowColorDef, type ShadowTuning, type ToneValue, type ToneWindow, apcaContrast, assertAllPastel, assertNativeFormat, contrastRatioFromLuminance, cuspLightness, findToneForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOkhst, formatOklch, formatRgb, fromTone, gamutClampedLuminance, glaze, hslToSrgb, inferRoleFromName, normalizeRole, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToOklch, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, oppositeRole, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveApcaTarget, resolveContrastForMode, resolveMinContrast, roleToPolarity, srgbToHex, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
|
|
1566
|
+
export { APCA_HC_ENHANCEMENT, APCA_MAX_LC, APCA_PRESETS, type AdaptationMode, type ApcaPreset, type ChannelCtx, type ColorDef, type ColorMap, type ContrastPreset, type ContrastSpec, type DtcgColorSpace, type DtcgColorToken, type DtcgColorValue, type DtcgDocument, type DtcgOklchColorValue, type DtcgResolverModifier, type DtcgResolverRef, type DtcgResolverSet, type DtcgSrgbColorValue, type DtcgTokenTree, type ExtremeValue, type FindToneForContrastOptions, type FindToneForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, type GlazeColorCssOptions, type GlazeColorDtcgResolverOptions, type GlazeColorDtcgResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorInputExport, type GlazeColorOverrides, type GlazeColorOverridesExport, type GlazeColorTailwindOptions, type GlazeColorToken, type GlazeColorTokenExport, type GlazeColorValue, type GlazeConfig, type GlazeConfigOverride, type GlazeConfigResolved, type GlazeCssOptions, type GlazeCssResult, type GlazeDtcgOptions, type GlazeDtcgResolverContextNames, type GlazeDtcgResolverDocument, type GlazeDtcgResolverOptions, type GlazeDtcgResult, type GlazeExtendOptions, type GlazeFromInput, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, type GlazePaletteExportOptions, type GlazePaletteOptions, type GlazeShadowInput, type GlazeTailwindOptions, type GlazeTheme, type GlazeThemeExport, type GlazeTokenOptions, type HCPair, type HexColor, type HueDeclaration, type HuePlan, type MinContrast, type MixColorDef, type OkhslColor, type OkhstColor, type OklchColor, type Polarity, REF_EPS, type RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ResolvedContrast, type RgbColor, type Role, type RoleInput, type ShadowColorDef, type ShadowTuning, type ToneValue, type ToneWindow, apcaContrast, assertAllPastel, assertNativeFormat, contrastRatioFromLuminance, cuspLightness, findToneForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOkhst, formatOklch, formatRgb, fromTone, gamutClampedLuminance, glaze, hslToSrgb, inferRoleFromName, normalizeRole, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToOklch, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, oppositeRole, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveApcaTarget, resolveContrastForMode, resolveMinContrast, roleToPolarity, srgbToHex, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
|
|
1547
1567
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -16,6 +16,16 @@ type MinContrast$1 = number | ContrastPreset;
|
|
|
16
16
|
* | `'min'` | 15 | Dividers/decorative; APCA "point of invisibility" |
|
|
17
17
|
*/
|
|
18
18
|
type ApcaPreset = 'preferred' | 'body' | 'content' | 'large' | 'non-text' | 'min';
|
|
19
|
+
declare const APCA_PRESETS: Record<ApcaPreset, number>;
|
|
20
|
+
/**
|
|
21
|
+
* APCA-W3 "Enhanced Level" delta added to a bare APCA target in high-contrast
|
|
22
|
+
* mode when no explicit HC value is provided (analogous to WCAG AAA over AA).
|
|
23
|
+
* Only applied when neither the outer `contrast` pair nor the inner `apca`
|
|
24
|
+
* pair carries an explicit HC entry.
|
|
25
|
+
*/
|
|
26
|
+
declare const APCA_HC_ENHANCEMENT = 15;
|
|
27
|
+
/** Upper bound for an APCA Lc target after HC enhancement. */
|
|
28
|
+
declare const APCA_MAX_LC = 106;
|
|
19
29
|
/**
|
|
20
30
|
* Resolve an APCA target — a raw Lc number (kept as-is) or an `ApcaPreset`
|
|
21
31
|
* keyword mapped to its Lc value. The magnitude is forced non-negative.
|
|
@@ -40,8 +50,18 @@ declare function resolveMinContrast(value: MinContrast$1): number;
|
|
|
40
50
|
* given mode into `{ metric, target }`. Handles the inner metric HC pair and
|
|
41
51
|
* preset resolution. `polarity` is passed through to the result for the APCA
|
|
42
52
|
* branch (it controls argument order in the solver); WCAG ignores it.
|
|
53
|
+
*
|
|
54
|
+
* `outerExplicitHC` indicates whether the caller selected this `spec` from an
|
|
55
|
+
* explicit high-contrast entry of the outer `contrast` pair. Together with the
|
|
56
|
+
* inner metric pair, it decides whether the HC auto-enhancement fires:
|
|
57
|
+
* - APCA: +15 Lc "Enhanced Level" boost when neither level is explicit.
|
|
58
|
+
* - WCAG: AA → AAA / AA-large → AAA-large promotion (SC 1.4.3 → 1.4.6) when
|
|
59
|
+
* neither level is explicit. AAA-family presets and bare numbers are left
|
|
60
|
+
* unchanged (AAA is the top WCAG tier).
|
|
61
|
+
* Defaults to `false` (correct for direct callers, which pass a single
|
|
62
|
+
* selected spec rather than an outer pair).
|
|
43
63
|
*/
|
|
44
|
-
declare function resolveContrastForMode(spec: ContrastSpec, isHighContrast: boolean, polarity?: 'fg' | 'bg'): ResolvedContrast;
|
|
64
|
+
declare function resolveContrastForMode(spec: ContrastSpec, isHighContrast: boolean, polarity?: 'fg' | 'bg', outerExplicitHC?: boolean): ResolvedContrast;
|
|
45
65
|
/**
|
|
46
66
|
* APCA lightness contrast (Lc), signed: positive for dark text on light bg,
|
|
47
67
|
* negative for light text on dark bg. Inputs are screen luminances (0–1).
|
|
@@ -248,7 +268,7 @@ interface RegularColorDef {
|
|
|
248
268
|
* Defaults to the global `autoFlip` config (default `true`). Set `false`
|
|
249
269
|
* to clamp instead.
|
|
250
270
|
*/
|
|
251
|
-
|
|
271
|
+
autoFlip?: boolean;
|
|
252
272
|
/**
|
|
253
273
|
* Fixed opacity (0–1).
|
|
254
274
|
* Output includes alpha in the CSS value.
|
|
@@ -565,7 +585,7 @@ interface GlazeColorInput {
|
|
|
565
585
|
saturationFactor?: number;
|
|
566
586
|
mode?: AdaptationMode;
|
|
567
587
|
/** Flip out-of-bounds results instead of clamping. Default: global `autoFlip`. */
|
|
568
|
-
|
|
588
|
+
autoFlip?: boolean;
|
|
569
589
|
/**
|
|
570
590
|
* Fixed opacity (0–1). Output includes alpha in the CSS value.
|
|
571
591
|
* Combining with `contrast` is not recommended (perceived tone
|
|
@@ -660,7 +680,7 @@ interface GlazeColorOverrides {
|
|
|
660
680
|
* `contrast`) to the opposite side instead of clamping. Defaults to
|
|
661
681
|
* the global `autoFlip`.
|
|
662
682
|
*/
|
|
663
|
-
|
|
683
|
+
autoFlip?: boolean;
|
|
664
684
|
/**
|
|
665
685
|
* Contrast floor. By default solved against the literal seed
|
|
666
686
|
* (the value itself); when `base` is set, solved against the base's
|
|
@@ -832,7 +852,7 @@ interface GlazeColorInputExport {
|
|
|
832
852
|
tone: HCPair<number | ExtremeValue>;
|
|
833
853
|
saturationFactor?: number;
|
|
834
854
|
mode?: AdaptationMode;
|
|
835
|
-
|
|
855
|
+
autoFlip?: boolean;
|
|
836
856
|
opacity?: number;
|
|
837
857
|
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
838
858
|
contrast?: HCPair<ContrastSpec>;
|
|
@@ -850,7 +870,7 @@ interface GlazeColorOverridesExport {
|
|
|
850
870
|
tone?: HCPair<ToneValue>;
|
|
851
871
|
saturationFactor?: number;
|
|
852
872
|
mode?: AdaptationMode;
|
|
853
|
-
|
|
873
|
+
autoFlip?: boolean;
|
|
854
874
|
contrast?: HCPair<ContrastSpec>;
|
|
855
875
|
base?: GlazeColorTokenExport | GlazeColorValue;
|
|
856
876
|
opacity?: number;
|
|
@@ -1543,5 +1563,5 @@ declare function srgbToHex(rgb: [number, number, number]): `#${string}`;
|
|
|
1543
1563
|
*/
|
|
1544
1564
|
declare function okhslToOklch(h: number, s: number, l: number, pastel?: boolean): [number, number, number];
|
|
1545
1565
|
//#endregion
|
|
1546
|
-
export { type AdaptationMode, type ApcaPreset, type ChannelCtx, type ColorDef, type ColorMap, type ContrastPreset, type ContrastSpec, type DtcgColorSpace, type DtcgColorToken, type DtcgColorValue, type DtcgDocument, type DtcgOklchColorValue, type DtcgResolverModifier, type DtcgResolverRef, type DtcgResolverSet, type DtcgSrgbColorValue, type DtcgTokenTree, type ExtremeValue, type FindToneForContrastOptions, type FindToneForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, type GlazeColorCssOptions, type GlazeColorDtcgResolverOptions, type GlazeColorDtcgResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorInputExport, type GlazeColorOverrides, type GlazeColorOverridesExport, type GlazeColorTailwindOptions, type GlazeColorToken, type GlazeColorTokenExport, type GlazeColorValue, type GlazeConfig, type GlazeConfigOverride, type GlazeConfigResolved, type GlazeCssOptions, type GlazeCssResult, type GlazeDtcgOptions, type GlazeDtcgResolverContextNames, type GlazeDtcgResolverDocument, type GlazeDtcgResolverOptions, type GlazeDtcgResult, type GlazeExtendOptions, type GlazeFromInput, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, type GlazePaletteExportOptions, type GlazePaletteOptions, type GlazeShadowInput, type GlazeTailwindOptions, type GlazeTheme, type GlazeThemeExport, type GlazeTokenOptions, type HCPair, type HexColor, type HueDeclaration, type HuePlan, type MinContrast, type MixColorDef, type OkhslColor, type OkhstColor, type OklchColor, type Polarity, REF_EPS, type RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ResolvedContrast, type RgbColor, type Role, type RoleInput, type ShadowColorDef, type ShadowTuning, type ToneValue, type ToneWindow, apcaContrast, assertAllPastel, assertNativeFormat, contrastRatioFromLuminance, cuspLightness, findToneForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOkhst, formatOklch, formatRgb, fromTone, gamutClampedLuminance, glaze, hslToSrgb, inferRoleFromName, normalizeRole, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToOklch, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, oppositeRole, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveApcaTarget, resolveContrastForMode, resolveMinContrast, roleToPolarity, srgbToHex, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
|
|
1566
|
+
export { APCA_HC_ENHANCEMENT, APCA_MAX_LC, APCA_PRESETS, type AdaptationMode, type ApcaPreset, type ChannelCtx, type ColorDef, type ColorMap, type ContrastPreset, type ContrastSpec, type DtcgColorSpace, type DtcgColorToken, type DtcgColorValue, type DtcgDocument, type DtcgOklchColorValue, type DtcgResolverModifier, type DtcgResolverRef, type DtcgResolverSet, type DtcgSrgbColorValue, type DtcgTokenTree, type ExtremeValue, type FindToneForContrastOptions, type FindToneForContrastResult, type FindValueForMixContrastOptions, type FindValueForMixContrastResult, type GlazeColorCssOptions, type GlazeColorDtcgResolverOptions, type GlazeColorDtcgResult, type GlazeColorFormat, type GlazeColorInput, type GlazeColorInputExport, type GlazeColorOverrides, type GlazeColorOverridesExport, type GlazeColorTailwindOptions, type GlazeColorToken, type GlazeColorTokenExport, type GlazeColorValue, type GlazeConfig, type GlazeConfigOverride, type GlazeConfigResolved, type GlazeCssOptions, type GlazeCssResult, type GlazeDtcgOptions, type GlazeDtcgResolverContextNames, type GlazeDtcgResolverDocument, type GlazeDtcgResolverOptions, type GlazeDtcgResult, type GlazeExtendOptions, type GlazeFromInput, type GlazeJsonOptions, type GlazeOutputModes, type GlazePalette, type GlazePaletteExportOptions, type GlazePaletteOptions, type GlazeShadowInput, type GlazeTailwindOptions, type GlazeTheme, type GlazeThemeExport, type GlazeTokenOptions, type HCPair, type HexColor, type HueDeclaration, type HuePlan, type MinContrast, type MixColorDef, type OkhslColor, type OkhstColor, type OklchColor, type Polarity, REF_EPS, type RegularColorDef, type RelativeValue, type ResolvedColor, type ResolvedColorVariant, type ResolvedContrast, type RgbColor, type Role, type RoleInput, type ShadowColorDef, type ShadowTuning, type ToneValue, type ToneWindow, apcaContrast, assertAllPastel, assertNativeFormat, contrastRatioFromLuminance, cuspLightness, findToneForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOkhst, formatOklch, formatRgb, fromTone, gamutClampedLuminance, glaze, hslToSrgb, inferRoleFromName, normalizeRole, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToOklch, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, oppositeRole, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveApcaTarget, resolveContrastForMode, resolveMinContrast, roleToPolarity, srgbToHex, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
|
|
1547
1567
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
CHANGED
|
@@ -1085,6 +1085,15 @@ const APCA_PRESETS = {
|
|
|
1085
1085
|
min: 15
|
|
1086
1086
|
};
|
|
1087
1087
|
/**
|
|
1088
|
+
* APCA-W3 "Enhanced Level" delta added to a bare APCA target in high-contrast
|
|
1089
|
+
* mode when no explicit HC value is provided (analogous to WCAG AAA over AA).
|
|
1090
|
+
* Only applied when neither the outer `contrast` pair nor the inner `apca`
|
|
1091
|
+
* pair carries an explicit HC entry.
|
|
1092
|
+
*/
|
|
1093
|
+
const APCA_HC_ENHANCEMENT = 15;
|
|
1094
|
+
/** Upper bound for an APCA Lc target after HC enhancement. */
|
|
1095
|
+
const APCA_MAX_LC = 106;
|
|
1096
|
+
/**
|
|
1088
1097
|
* Resolve an APCA target — a raw Lc number (kept as-is) or an `ApcaPreset`
|
|
1089
1098
|
* keyword mapped to its Lc value. The magnitude is forced non-negative.
|
|
1090
1099
|
*/
|
|
@@ -1098,10 +1107,35 @@ const CONTRAST_PRESETS = {
|
|
|
1098
1107
|
"AA-large": 3,
|
|
1099
1108
|
"AAA-large": 4.5
|
|
1100
1109
|
};
|
|
1110
|
+
/**
|
|
1111
|
+
* WCAG high-contrast auto-promotion (analog of APCA's Enhanced Level). A bare
|
|
1112
|
+
* AA / AA-large preset is promoted to its spec-defined "Enhanced" successor
|
|
1113
|
+
* (SC 1.4.3 → SC 1.4.6) in high-contrast mode. AAA / AAA-large are already
|
|
1114
|
+
* the top WCAG tier and are left unchanged. Bare numeric targets have no
|
|
1115
|
+
* defined successor tier and are also left unchanged. An explicit HC value
|
|
1116
|
+
* (outer or inner pair) always overrides.
|
|
1117
|
+
*/
|
|
1118
|
+
const WCAG_HC_PROMOTION = {
|
|
1119
|
+
AA: "AAA",
|
|
1120
|
+
"AA-large": "AAA-large"
|
|
1121
|
+
};
|
|
1101
1122
|
function resolveMinContrast(value) {
|
|
1102
1123
|
if (typeof value === "number") return Math.max(1, value);
|
|
1103
1124
|
return CONTRAST_PRESETS[value];
|
|
1104
1125
|
}
|
|
1126
|
+
/**
|
|
1127
|
+
* Resolve a WCAG target (number or preset) for a mode, applying the
|
|
1128
|
+
* high-contrast auto-promotion when `explicitHC` is false and the value is an
|
|
1129
|
+
* AA-family preset. Bare numbers and AAA-family presets pass through.
|
|
1130
|
+
*/
|
|
1131
|
+
function resolveWcagTarget(value, isHighContrast, explicitHC) {
|
|
1132
|
+
if (typeof value === "number") return resolveMinContrast(value);
|
|
1133
|
+
if (isHighContrast && !explicitHC) {
|
|
1134
|
+
const promoted = WCAG_HC_PROMOTION[value];
|
|
1135
|
+
if (promoted !== void 0) return resolveMinContrast(promoted);
|
|
1136
|
+
}
|
|
1137
|
+
return resolveMinContrast(value);
|
|
1138
|
+
}
|
|
1105
1139
|
function pickPair(p, isHighContrast) {
|
|
1106
1140
|
return Array.isArray(p) ? isHighContrast ? p[1] : p[0] : p;
|
|
1107
1141
|
}
|
|
@@ -1110,20 +1144,35 @@ function pickPair(p, isHighContrast) {
|
|
|
1110
1144
|
* given mode into `{ metric, target }`. Handles the inner metric HC pair and
|
|
1111
1145
|
* preset resolution. `polarity` is passed through to the result for the APCA
|
|
1112
1146
|
* branch (it controls argument order in the solver); WCAG ignores it.
|
|
1113
|
-
|
|
1114
|
-
|
|
1147
|
+
*
|
|
1148
|
+
* `outerExplicitHC` indicates whether the caller selected this `spec` from an
|
|
1149
|
+
* explicit high-contrast entry of the outer `contrast` pair. Together with the
|
|
1150
|
+
* inner metric pair, it decides whether the HC auto-enhancement fires:
|
|
1151
|
+
* - APCA: +15 Lc "Enhanced Level" boost when neither level is explicit.
|
|
1152
|
+
* - WCAG: AA → AAA / AA-large → AAA-large promotion (SC 1.4.3 → 1.4.6) when
|
|
1153
|
+
* neither level is explicit. AAA-family presets and bare numbers are left
|
|
1154
|
+
* unchanged (AAA is the top WCAG tier).
|
|
1155
|
+
* Defaults to `false` (correct for direct callers, which pass a single
|
|
1156
|
+
* selected spec rather than an outer pair).
|
|
1157
|
+
*/
|
|
1158
|
+
function resolveContrastForMode(spec, isHighContrast, polarity, outerExplicitHC) {
|
|
1115
1159
|
if (typeof spec === "number" || typeof spec === "string") return {
|
|
1116
1160
|
metric: "wcag",
|
|
1117
|
-
target:
|
|
1118
|
-
};
|
|
1119
|
-
if ("apca" in spec) return {
|
|
1120
|
-
metric: "apca",
|
|
1121
|
-
target: resolveApcaTarget(pickPair(spec.apca, isHighContrast)),
|
|
1122
|
-
polarity: polarity ?? "fg"
|
|
1161
|
+
target: resolveWcagTarget(spec, isHighContrast, !!outerExplicitHC)
|
|
1123
1162
|
};
|
|
1163
|
+
if ("apca" in spec) {
|
|
1164
|
+
const baseTarget = resolveApcaTarget(pickPair(spec.apca, isHighContrast));
|
|
1165
|
+
const innerExplicitHC = Array.isArray(spec.apca);
|
|
1166
|
+
return {
|
|
1167
|
+
metric: "apca",
|
|
1168
|
+
target: isHighContrast && !outerExplicitHC && !innerExplicitHC ? Math.min(baseTarget + APCA_HC_ENHANCEMENT, APCA_MAX_LC) : baseTarget,
|
|
1169
|
+
polarity: polarity ?? "fg"
|
|
1170
|
+
};
|
|
1171
|
+
}
|
|
1172
|
+
const innerExplicitHC = Array.isArray(spec.wcag);
|
|
1124
1173
|
return {
|
|
1125
1174
|
metric: "wcag",
|
|
1126
|
-
target:
|
|
1175
|
+
target: resolveWcagTarget(pickPair(spec.wcag, isHighContrast), isHighContrast, !!outerExplicitHC || innerExplicitHC)
|
|
1127
1176
|
};
|
|
1128
1177
|
}
|
|
1129
1178
|
const APCA_EXPONENTS = {
|
|
@@ -1825,7 +1874,8 @@ function resolveRole(name, def, ctx) {
|
|
|
1825
1874
|
return resolveRoleInMap(name, def, ctx.defs, ctx.config.inferRole, ctx.roles);
|
|
1826
1875
|
}
|
|
1827
1876
|
function resolveContrastSpec(spec, isHighContrast, polarity) {
|
|
1828
|
-
|
|
1877
|
+
const outerExplicitHC = Array.isArray(spec);
|
|
1878
|
+
return resolveContrastForMode(isHighContrast ? pairHC(spec) : pairNormal(spec), isHighContrast, polarity, outerExplicitHC);
|
|
1829
1879
|
}
|
|
1830
1880
|
/**
|
|
1831
1881
|
* Apply the relative-tone delta against a base, honoring `flip`.
|
|
@@ -1853,7 +1903,7 @@ function resolveDependentColor(name, def, ctx, isHighContrast, isDark, effective
|
|
|
1853
1903
|
if (!baseResolved) throw new Error(`glaze: base "${baseName}" not yet resolved for "${name}".`);
|
|
1854
1904
|
const mode = def.mode ?? "auto";
|
|
1855
1905
|
const satFactor = clamp(def.saturation ?? 1, 0, 1);
|
|
1856
|
-
const flip = def.
|
|
1906
|
+
const flip = def.autoFlip ?? ctx.config.autoFlip;
|
|
1857
1907
|
const pastel = effectivePastel;
|
|
1858
1908
|
const baseVariant = getSchemeVariant(baseResolved, isDark, isHighContrast);
|
|
1859
1909
|
const baseTone = baseVariant.t * 100;
|
|
@@ -2930,7 +2980,7 @@ function buildStandaloneValueDefs(main, options) {
|
|
|
2930
2980
|
tone: toneOption ?? seedTone,
|
|
2931
2981
|
contrast: options?.contrast,
|
|
2932
2982
|
mode: options?.mode ?? "auto",
|
|
2933
|
-
|
|
2983
|
+
autoFlip: options?.autoFlip,
|
|
2934
2984
|
opacity: options?.opacity,
|
|
2935
2985
|
pastel: options?.pastel,
|
|
2936
2986
|
role: options?.role,
|
|
@@ -3072,7 +3122,7 @@ function createColorToken(input, configOverride) {
|
|
|
3072
3122
|
tone: input.tone,
|
|
3073
3123
|
saturation: input.saturationFactor,
|
|
3074
3124
|
mode: input.mode ?? "auto",
|
|
3075
|
-
|
|
3125
|
+
autoFlip: input.autoFlip,
|
|
3076
3126
|
contrast: input.contrast,
|
|
3077
3127
|
opacity: input.opacity,
|
|
3078
3128
|
pastel: input.pastel,
|
|
@@ -3122,7 +3172,7 @@ function buildOverridesExport(options) {
|
|
|
3122
3172
|
if (options.tone !== void 0) out.tone = options.tone;
|
|
3123
3173
|
if (options.saturationFactor !== void 0) out.saturationFactor = options.saturationFactor;
|
|
3124
3174
|
if (options.mode !== void 0) out.mode = options.mode;
|
|
3125
|
-
if (options.
|
|
3175
|
+
if (options.autoFlip !== void 0) out.autoFlip = options.autoFlip;
|
|
3126
3176
|
if (options.contrast !== void 0) out.contrast = options.contrast;
|
|
3127
3177
|
if (options.opacity !== void 0) out.opacity = options.opacity;
|
|
3128
3178
|
if (options.name !== void 0) out.name = options.name;
|
|
@@ -3139,7 +3189,7 @@ function buildStructuredInputExport(input) {
|
|
|
3139
3189
|
};
|
|
3140
3190
|
if (input.saturationFactor !== void 0) out.saturationFactor = input.saturationFactor;
|
|
3141
3191
|
if (input.mode !== void 0) out.mode = input.mode;
|
|
3142
|
-
if (input.
|
|
3192
|
+
if (input.autoFlip !== void 0) out.autoFlip = input.autoFlip;
|
|
3143
3193
|
if (input.opacity !== void 0) out.opacity = input.opacity;
|
|
3144
3194
|
if (input.contrast !== void 0) out.contrast = input.contrast;
|
|
3145
3195
|
if (input.name !== void 0) out.name = input.name;
|
|
@@ -3161,7 +3211,7 @@ function rehydrateOverrides(data) {
|
|
|
3161
3211
|
if (data.tone !== void 0) out.tone = data.tone;
|
|
3162
3212
|
if (data.saturationFactor !== void 0) out.saturationFactor = data.saturationFactor;
|
|
3163
3213
|
if (data.mode !== void 0) out.mode = data.mode;
|
|
3164
|
-
if (data.
|
|
3214
|
+
if (data.autoFlip !== void 0) out.autoFlip = data.autoFlip;
|
|
3165
3215
|
if (data.contrast !== void 0) out.contrast = data.contrast;
|
|
3166
3216
|
if (data.opacity !== void 0) out.opacity = data.opacity;
|
|
3167
3217
|
if (data.name !== void 0) out.name = data.name;
|
|
@@ -3178,7 +3228,7 @@ function rehydrateStructuredInput(data) {
|
|
|
3178
3228
|
};
|
|
3179
3229
|
if (data.saturationFactor !== void 0) out.saturationFactor = data.saturationFactor;
|
|
3180
3230
|
if (data.mode !== void 0) out.mode = data.mode;
|
|
3181
|
-
if (data.
|
|
3231
|
+
if (data.autoFlip !== void 0) out.autoFlip = data.autoFlip;
|
|
3182
3232
|
if (data.opacity !== void 0) out.opacity = data.opacity;
|
|
3183
3233
|
if (data.contrast !== void 0) out.contrast = data.contrast;
|
|
3184
3234
|
if (data.name !== void 0) out.name = data.name;
|
|
@@ -3717,5 +3767,5 @@ glaze.resetConfig = function resetConfig$1() {
|
|
|
3717
3767
|
};
|
|
3718
3768
|
|
|
3719
3769
|
//#endregion
|
|
3720
|
-
export { REF_EPS, apcaContrast, assertAllPastel, assertNativeFormat, contrastRatioFromLuminance, cuspLightness, findToneForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOkhst, formatOklch, formatRgb, fromTone, gamutClampedLuminance, glaze, hslToSrgb, inferRoleFromName, normalizeRole, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToOklch, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, oppositeRole, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveApcaTarget, resolveContrastForMode, resolveMinContrast, roleToPolarity, srgbToHex, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
|
|
3770
|
+
export { APCA_HC_ENHANCEMENT, APCA_MAX_LC, APCA_PRESETS, REF_EPS, apcaContrast, assertAllPastel, assertNativeFormat, contrastRatioFromLuminance, cuspLightness, findToneForContrast, findValueForMixContrast, formatHsl, formatOkhsl, formatOkhst, formatOklch, formatRgb, fromTone, gamutClampedLuminance, glaze, hslToSrgb, inferRoleFromName, normalizeRole, okhslToLinearSrgb, okhslToOkhst, okhslToOklab, okhslToOklch, okhslToSrgb, okhstToOkhsl, oklabToOkhsl, oppositeRole, parseHex, parseHexAlpha, relativeLuminanceFromLinearRgb, resolveApcaTarget, resolveContrastForMode, resolveMinContrast, roleToPolarity, srgbToHex, srgbToOkhsl, toTone, toneFromY, variantToOkhsl, yFromTone };
|
|
3721
3771
|
//# sourceMappingURL=index.mjs.map
|