@dloizides/design-tokens 1.13.0 → 1.14.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.d.mts CHANGED
@@ -418,6 +418,46 @@ type ZIndexLayer = keyof typeof Z_INDEX;
418
418
  /** The layers in stacking order, lowest first. */
419
419
  declare const Z_INDEX_ORDER: readonly ZIndexLayer[];
420
420
 
421
+ /** Geometry of the one fleet focus ring: a 2 px solid outline drawn 2 px outside the control. */
422
+ declare const FOCUS_RING: {
423
+ readonly width: 2;
424
+ readonly offset: 2;
425
+ readonly style: "solid";
426
+ };
427
+ /** Colours {@link resolveFocusRingColor} chooses from, all for the current mode. */
428
+ interface FocusRingColorInput {
429
+ /** The mode's explicit `focusRing` token; used as-is when set. */
430
+ focusRing?: string;
431
+ /** Brand primary (main step). */
432
+ primary: string;
433
+ /** A lighter brand step, tried when `primary` is too dark for the ground. */
434
+ primaryLight?: string;
435
+ /** Primary text; the last resort, always readable on `background`. */
436
+ text: string;
437
+ /** The ground the ring is drawn on. */
438
+ background: string;
439
+ }
440
+ /** Outline style keys for the focus ring in `color`. */
441
+ interface FocusRingOutline {
442
+ outlineColor: string;
443
+ outlineOffset: number;
444
+ outlineStyle: typeof FOCUS_RING.style;
445
+ outlineWidth: number;
446
+ }
447
+ /**
448
+ * The focus-ring colour for one mode: the explicit `focusRing` token, else the first of
449
+ * primary, primaryLight and text that reaches 3:1 (WCAG 1.4.11) on the background.
450
+ */
451
+ declare function resolveFocusRingColor(input: FocusRingColorInput): string;
452
+ /** The outline style object for the focus ring in `color`. */
453
+ declare function focusRingOutline(color: string): FocusRingOutline;
454
+ /**
455
+ * True when a focus event's target is keyboard focus (`:focus-visible`). Targets without
456
+ * `matches` (native hosts) and browsers that reject the selector count as visible, so the
457
+ * ring is never lost.
458
+ */
459
+ declare function isFocusVisible(target: unknown): boolean;
460
+
421
461
  /**
422
462
  * CSS custom-property NAME MAPS — the cross-stack naming contract.
423
463
  *
@@ -1056,4 +1096,4 @@ declare function onBrandRatio(background: string, explicit?: string): number | n
1056
1096
  */
1057
1097
  declare function canCarryAccessibleInk(background: string): boolean;
1058
1098
 
1059
- export { AA_LARGE_TEXT_RATIO, AA_NON_TEXT_RATIO, AA_NORMAL_TEXT_RATIO, AML_CSS_VAR_NAMES, AML_TOKENS, type BrandExtras, type Branding, type ContrastMoreOverrides, type CssVarNames, DEFAULT_CSS_VAR_NAMES, DEFAULT_MOTION, DIGITALKIN_TOKENS, type DesignTokens, EREVNA_TOKENS, FINREG_MODULE_COLORS, FINREG_SURFACE_COLORS, type FinregModuleColor, type FinregModuleColors, type FinregSurfaceColors, INTERVIEWPREP_CSS_VAR_NAMES, INTERVIEWPREP_TOKENS, type InkScale, KATALOGOS_TOKENS, type ModeColors, type Motion, type MotionDurations, type MotionEasing, type MotionEasings, type MotionSpring, type MotionSprings, NEXTGAME_TOKENS, ON_BRAND_DARK_INK, ON_BRAND_LIGHT_INK, PRESETS, RN_WEB_MODAL_Z_INDEX, type Radii, type RnThemeConfig, type SemanticColors, type Shadows, type ShellColors, type TailwindColors, type TailwindPreset, type ToCssVarsOptions, type TokenExtensions, type Typography, UI_DEEP_STEP, UI_MAIN_STEP, UI_TINT_STEP, type UiColorScale, type UiThemeColors, type UiThemeConfig, type UiThemeMode, type UiThemePalette, type UiThemeSemantic, type VerdictColors, type WorkspaceExtras, type ZIndexLayer, Z_INDEX, Z_INDEX_ORDER, canCarryAccessibleInk, contrastRatio, isHexColor, meetsContrast, onBrandRatio, relativeLuminance, resolveOnBrand, toCssVars, toRnTheme, toTailwindPreset, toUiTheme };
1099
+ export { AA_LARGE_TEXT_RATIO, AA_NON_TEXT_RATIO, AA_NORMAL_TEXT_RATIO, AML_CSS_VAR_NAMES, AML_TOKENS, type BrandExtras, type Branding, type ContrastMoreOverrides, type CssVarNames, DEFAULT_CSS_VAR_NAMES, DEFAULT_MOTION, DIGITALKIN_TOKENS, type DesignTokens, EREVNA_TOKENS, FINREG_MODULE_COLORS, FINREG_SURFACE_COLORS, FOCUS_RING, type FinregModuleColor, type FinregModuleColors, type FinregSurfaceColors, type FocusRingColorInput, type FocusRingOutline, INTERVIEWPREP_CSS_VAR_NAMES, INTERVIEWPREP_TOKENS, type InkScale, KATALOGOS_TOKENS, type ModeColors, type Motion, type MotionDurations, type MotionEasing, type MotionEasings, type MotionSpring, type MotionSprings, NEXTGAME_TOKENS, ON_BRAND_DARK_INK, ON_BRAND_LIGHT_INK, PRESETS, RN_WEB_MODAL_Z_INDEX, type Radii, type RnThemeConfig, type SemanticColors, type Shadows, type ShellColors, type TailwindColors, type TailwindPreset, type ToCssVarsOptions, type TokenExtensions, type Typography, UI_DEEP_STEP, UI_MAIN_STEP, UI_TINT_STEP, type UiColorScale, type UiThemeColors, type UiThemeConfig, type UiThemeMode, type UiThemePalette, type UiThemeSemantic, type VerdictColors, type WorkspaceExtras, type ZIndexLayer, Z_INDEX, Z_INDEX_ORDER, canCarryAccessibleInk, contrastRatio, focusRingOutline, isFocusVisible, isHexColor, meetsContrast, onBrandRatio, relativeLuminance, resolveFocusRingColor, resolveOnBrand, toCssVars, toRnTheme, toTailwindPreset, toUiTheme };
package/dist/index.d.ts CHANGED
@@ -418,6 +418,46 @@ type ZIndexLayer = keyof typeof Z_INDEX;
418
418
  /** The layers in stacking order, lowest first. */
419
419
  declare const Z_INDEX_ORDER: readonly ZIndexLayer[];
420
420
 
421
+ /** Geometry of the one fleet focus ring: a 2 px solid outline drawn 2 px outside the control. */
422
+ declare const FOCUS_RING: {
423
+ readonly width: 2;
424
+ readonly offset: 2;
425
+ readonly style: "solid";
426
+ };
427
+ /** Colours {@link resolveFocusRingColor} chooses from, all for the current mode. */
428
+ interface FocusRingColorInput {
429
+ /** The mode's explicit `focusRing` token; used as-is when set. */
430
+ focusRing?: string;
431
+ /** Brand primary (main step). */
432
+ primary: string;
433
+ /** A lighter brand step, tried when `primary` is too dark for the ground. */
434
+ primaryLight?: string;
435
+ /** Primary text; the last resort, always readable on `background`. */
436
+ text: string;
437
+ /** The ground the ring is drawn on. */
438
+ background: string;
439
+ }
440
+ /** Outline style keys for the focus ring in `color`. */
441
+ interface FocusRingOutline {
442
+ outlineColor: string;
443
+ outlineOffset: number;
444
+ outlineStyle: typeof FOCUS_RING.style;
445
+ outlineWidth: number;
446
+ }
447
+ /**
448
+ * The focus-ring colour for one mode: the explicit `focusRing` token, else the first of
449
+ * primary, primaryLight and text that reaches 3:1 (WCAG 1.4.11) on the background.
450
+ */
451
+ declare function resolveFocusRingColor(input: FocusRingColorInput): string;
452
+ /** The outline style object for the focus ring in `color`. */
453
+ declare function focusRingOutline(color: string): FocusRingOutline;
454
+ /**
455
+ * True when a focus event's target is keyboard focus (`:focus-visible`). Targets without
456
+ * `matches` (native hosts) and browsers that reject the selector count as visible, so the
457
+ * ring is never lost.
458
+ */
459
+ declare function isFocusVisible(target: unknown): boolean;
460
+
421
461
  /**
422
462
  * CSS custom-property NAME MAPS — the cross-stack naming contract.
423
463
  *
@@ -1056,4 +1096,4 @@ declare function onBrandRatio(background: string, explicit?: string): number | n
1056
1096
  */
1057
1097
  declare function canCarryAccessibleInk(background: string): boolean;
1058
1098
 
1059
- export { AA_LARGE_TEXT_RATIO, AA_NON_TEXT_RATIO, AA_NORMAL_TEXT_RATIO, AML_CSS_VAR_NAMES, AML_TOKENS, type BrandExtras, type Branding, type ContrastMoreOverrides, type CssVarNames, DEFAULT_CSS_VAR_NAMES, DEFAULT_MOTION, DIGITALKIN_TOKENS, type DesignTokens, EREVNA_TOKENS, FINREG_MODULE_COLORS, FINREG_SURFACE_COLORS, type FinregModuleColor, type FinregModuleColors, type FinregSurfaceColors, INTERVIEWPREP_CSS_VAR_NAMES, INTERVIEWPREP_TOKENS, type InkScale, KATALOGOS_TOKENS, type ModeColors, type Motion, type MotionDurations, type MotionEasing, type MotionEasings, type MotionSpring, type MotionSprings, NEXTGAME_TOKENS, ON_BRAND_DARK_INK, ON_BRAND_LIGHT_INK, PRESETS, RN_WEB_MODAL_Z_INDEX, type Radii, type RnThemeConfig, type SemanticColors, type Shadows, type ShellColors, type TailwindColors, type TailwindPreset, type ToCssVarsOptions, type TokenExtensions, type Typography, UI_DEEP_STEP, UI_MAIN_STEP, UI_TINT_STEP, type UiColorScale, type UiThemeColors, type UiThemeConfig, type UiThemeMode, type UiThemePalette, type UiThemeSemantic, type VerdictColors, type WorkspaceExtras, type ZIndexLayer, Z_INDEX, Z_INDEX_ORDER, canCarryAccessibleInk, contrastRatio, isHexColor, meetsContrast, onBrandRatio, relativeLuminance, resolveOnBrand, toCssVars, toRnTheme, toTailwindPreset, toUiTheme };
1099
+ export { AA_LARGE_TEXT_RATIO, AA_NON_TEXT_RATIO, AA_NORMAL_TEXT_RATIO, AML_CSS_VAR_NAMES, AML_TOKENS, type BrandExtras, type Branding, type ContrastMoreOverrides, type CssVarNames, DEFAULT_CSS_VAR_NAMES, DEFAULT_MOTION, DIGITALKIN_TOKENS, type DesignTokens, EREVNA_TOKENS, FINREG_MODULE_COLORS, FINREG_SURFACE_COLORS, FOCUS_RING, type FinregModuleColor, type FinregModuleColors, type FinregSurfaceColors, type FocusRingColorInput, type FocusRingOutline, INTERVIEWPREP_CSS_VAR_NAMES, INTERVIEWPREP_TOKENS, type InkScale, KATALOGOS_TOKENS, type ModeColors, type Motion, type MotionDurations, type MotionEasing, type MotionEasings, type MotionSpring, type MotionSprings, NEXTGAME_TOKENS, ON_BRAND_DARK_INK, ON_BRAND_LIGHT_INK, PRESETS, RN_WEB_MODAL_Z_INDEX, type Radii, type RnThemeConfig, type SemanticColors, type Shadows, type ShellColors, type TailwindColors, type TailwindPreset, type ToCssVarsOptions, type TokenExtensions, type Typography, UI_DEEP_STEP, UI_MAIN_STEP, UI_TINT_STEP, type UiColorScale, type UiThemeColors, type UiThemeConfig, type UiThemeMode, type UiThemePalette, type UiThemeSemantic, type VerdictColors, type WorkspaceExtras, type ZIndexLayer, Z_INDEX, Z_INDEX_ORDER, canCarryAccessibleInk, contrastRatio, focusRingOutline, isFocusVisible, isHexColor, meetsContrast, onBrandRatio, relativeLuminance, resolveFocusRingColor, resolveOnBrand, toCssVars, toRnTheme, toTailwindPreset, toUiTheme };
package/dist/index.js CHANGED
@@ -68,6 +68,110 @@ var Z_INDEX_ORDER = [
68
68
  "blocking"
69
69
  ];
70
70
 
71
+ // src/contrast.ts
72
+ var AA_NORMAL_TEXT_RATIO = 4.5;
73
+ var AA_LARGE_TEXT_RATIO = 3;
74
+ var AA_NON_TEXT_RATIO = 3;
75
+ var SRGB_CHANNEL_MAX = 255;
76
+ var GAMMA_LINEAR_THRESHOLD = 0.03928;
77
+ var GAMMA_LINEAR_DIVISOR = 12.92;
78
+ var GAMMA_OFFSET = 0.055;
79
+ var GAMMA_DIVISOR = 1.055;
80
+ var GAMMA_EXPONENT = 2.4;
81
+ var LUMA_COEFFICIENT_RED = 0.2126;
82
+ var LUMA_COEFFICIENT_GREEN = 0.7152;
83
+ var LUMA_COEFFICIENT_BLUE = 0.0722;
84
+ var CONTRAST_FLARE = 0.05;
85
+ var HEX_RADIX = 16;
86
+ var HEX_PAIR_LENGTH = 2;
87
+ var HEX_SHORTHAND_LENGTH = 3;
88
+ var HEX_FULL_LENGTH = 6;
89
+ var CHANNEL_OFFSET_RED = 0;
90
+ var CHANNEL_OFFSET_GREEN = 2;
91
+ var CHANNEL_OFFSET_BLUE = 4;
92
+ function normalizeHexDigits(hex) {
93
+ const clean = hex.trim().replace("#", "").toLowerCase();
94
+ if (clean.length === HEX_SHORTHAND_LENGTH) {
95
+ return [...clean].map((digit) => digit + digit).join("");
96
+ }
97
+ return clean;
98
+ }
99
+ function parseChannel(digits, offset) {
100
+ const pair = digits.slice(offset, offset + HEX_PAIR_LENGTH);
101
+ return parseInt(pair, HEX_RADIX) / SRGB_CHANNEL_MAX;
102
+ }
103
+ function linearizeChannel(channel) {
104
+ if (channel <= GAMMA_LINEAR_THRESHOLD) {
105
+ return channel / GAMMA_LINEAR_DIVISOR;
106
+ }
107
+ return Math.pow((channel + GAMMA_OFFSET) / GAMMA_DIVISOR, GAMMA_EXPONENT);
108
+ }
109
+ function isHexColor(value) {
110
+ const digits = normalizeHexDigits(value);
111
+ return digits.length === HEX_FULL_LENGTH && /^[0-9a-f]{6}$/.test(digits);
112
+ }
113
+ function relativeLuminance(hex) {
114
+ if (!isHexColor(hex)) {
115
+ throw new Error(`relativeLuminance: not a hex colour: ${hex}`);
116
+ }
117
+ const digits = normalizeHexDigits(hex);
118
+ const red = linearizeChannel(parseChannel(digits, CHANNEL_OFFSET_RED));
119
+ const green = linearizeChannel(parseChannel(digits, CHANNEL_OFFSET_GREEN));
120
+ const blue = linearizeChannel(parseChannel(digits, CHANNEL_OFFSET_BLUE));
121
+ return LUMA_COEFFICIENT_RED * red + LUMA_COEFFICIENT_GREEN * green + LUMA_COEFFICIENT_BLUE * blue;
122
+ }
123
+ function contrastRatio(foreground, background) {
124
+ const first = relativeLuminance(foreground);
125
+ const second = relativeLuminance(background);
126
+ const lighter = Math.max(first, second);
127
+ const darker = Math.min(first, second);
128
+ return (lighter + CONTRAST_FLARE) / (darker + CONTRAST_FLARE);
129
+ }
130
+ function meetsContrast(foreground, background, requiredRatio) {
131
+ return contrastRatio(foreground, background) >= requiredRatio;
132
+ }
133
+
134
+ // src/focusRing.ts
135
+ var RING_WIDTH_PX = 2;
136
+ var RING_OFFSET_PX = 2;
137
+ var FOCUS_RING = {
138
+ width: RING_WIDTH_PX,
139
+ offset: RING_OFFSET_PX,
140
+ style: "solid"
141
+ };
142
+ function passesOnGround(color, background) {
143
+ return color !== void 0 && isHexColor(color) && contrastRatio(color, background) >= AA_NON_TEXT_RATIO;
144
+ }
145
+ function resolveFocusRingColor(input) {
146
+ if (input.focusRing) {
147
+ return input.focusRing;
148
+ }
149
+ if (!isHexColor(input.background)) {
150
+ return input.primary;
151
+ }
152
+ const candidates = [input.primary, input.primaryLight];
153
+ return candidates.find((color) => passesOnGround(color, input.background)) ?? input.text;
154
+ }
155
+ function focusRingOutline(color) {
156
+ return {
157
+ outlineColor: color,
158
+ outlineOffset: FOCUS_RING.offset,
159
+ outlineStyle: FOCUS_RING.style,
160
+ outlineWidth: FOCUS_RING.width
161
+ };
162
+ }
163
+ function isFocusVisible(target) {
164
+ const candidate = target;
165
+ if (typeof candidate?.matches !== "function") {
166
+ return true;
167
+ }
168
+ try {
169
+ return candidate.matches(":focus-visible");
170
+ } catch {
171
+ return true;
172
+ }
173
+ }
174
+
71
175
  // src/varNames.ts
72
176
  var DEFAULT_CSS_VAR_NAMES = {
73
177
  primary: "--primary",
@@ -195,69 +299,6 @@ var INTERVIEWPREP_CSS_VAR_NAMES = {
195
299
  monoFamily: "--font-mono"
196
300
  };
197
301
 
198
- // src/contrast.ts
199
- var AA_NORMAL_TEXT_RATIO = 4.5;
200
- var AA_LARGE_TEXT_RATIO = 3;
201
- var AA_NON_TEXT_RATIO = 3;
202
- var SRGB_CHANNEL_MAX = 255;
203
- var GAMMA_LINEAR_THRESHOLD = 0.03928;
204
- var GAMMA_LINEAR_DIVISOR = 12.92;
205
- var GAMMA_OFFSET = 0.055;
206
- var GAMMA_DIVISOR = 1.055;
207
- var GAMMA_EXPONENT = 2.4;
208
- var LUMA_COEFFICIENT_RED = 0.2126;
209
- var LUMA_COEFFICIENT_GREEN = 0.7152;
210
- var LUMA_COEFFICIENT_BLUE = 0.0722;
211
- var CONTRAST_FLARE = 0.05;
212
- var HEX_RADIX = 16;
213
- var HEX_PAIR_LENGTH = 2;
214
- var HEX_SHORTHAND_LENGTH = 3;
215
- var HEX_FULL_LENGTH = 6;
216
- var CHANNEL_OFFSET_RED = 0;
217
- var CHANNEL_OFFSET_GREEN = 2;
218
- var CHANNEL_OFFSET_BLUE = 4;
219
- function normalizeHexDigits(hex) {
220
- const clean = hex.trim().replace("#", "").toLowerCase();
221
- if (clean.length === HEX_SHORTHAND_LENGTH) {
222
- return `${clean[0] ?? ""}${clean[0] ?? ""}${clean[1] ?? ""}${clean[1] ?? ""}${clean[2] ?? ""}${clean[2] ?? ""}`;
223
- }
224
- return clean;
225
- }
226
- function parseChannel(digits, offset) {
227
- const pair = digits.slice(offset, offset + HEX_PAIR_LENGTH);
228
- return parseInt(pair, HEX_RADIX) / SRGB_CHANNEL_MAX;
229
- }
230
- function linearizeChannel(channel) {
231
- if (channel <= GAMMA_LINEAR_THRESHOLD) {
232
- return channel / GAMMA_LINEAR_DIVISOR;
233
- }
234
- return Math.pow((channel + GAMMA_OFFSET) / GAMMA_DIVISOR, GAMMA_EXPONENT);
235
- }
236
- function isHexColor(value) {
237
- const digits = normalizeHexDigits(value);
238
- return digits.length === HEX_FULL_LENGTH && /^[0-9a-f]{6}$/.test(digits);
239
- }
240
- function relativeLuminance(hex) {
241
- if (!isHexColor(hex)) {
242
- throw new Error(`relativeLuminance: not a hex colour: ${hex}`);
243
- }
244
- const digits = normalizeHexDigits(hex);
245
- const red = linearizeChannel(parseChannel(digits, CHANNEL_OFFSET_RED));
246
- const green = linearizeChannel(parseChannel(digits, CHANNEL_OFFSET_GREEN));
247
- const blue = linearizeChannel(parseChannel(digits, CHANNEL_OFFSET_BLUE));
248
- return LUMA_COEFFICIENT_RED * red + LUMA_COEFFICIENT_GREEN * green + LUMA_COEFFICIENT_BLUE * blue;
249
- }
250
- function contrastRatio(foreground, background) {
251
- const first = relativeLuminance(foreground);
252
- const second = relativeLuminance(background);
253
- const lighter = Math.max(first, second);
254
- const darker = Math.min(first, second);
255
- return (lighter + CONTRAST_FLARE) / (darker + CONTRAST_FLARE);
256
- }
257
- function meetsContrast(foreground, background, requiredRatio) {
258
- return contrastRatio(foreground, background) >= requiredRatio;
259
- }
260
-
261
302
  // src/onBrand.ts
262
303
  var ON_BRAND_LIGHT_INK = "#ffffff";
263
304
  var ON_BRAND_DARK_INK = "#03121f";
@@ -968,6 +1009,7 @@ exports.DIGITALKIN_TOKENS = DIGITALKIN_TOKENS;
968
1009
  exports.EREVNA_TOKENS = EREVNA_TOKENS;
969
1010
  exports.FINREG_MODULE_COLORS = FINREG_MODULE_COLORS;
970
1011
  exports.FINREG_SURFACE_COLORS = FINREG_SURFACE_COLORS;
1012
+ exports.FOCUS_RING = FOCUS_RING;
971
1013
  exports.INTERVIEWPREP_CSS_VAR_NAMES = INTERVIEWPREP_CSS_VAR_NAMES;
972
1014
  exports.INTERVIEWPREP_TOKENS = INTERVIEWPREP_TOKENS;
973
1015
  exports.KATALOGOS_TOKENS = KATALOGOS_TOKENS;
@@ -983,10 +1025,13 @@ exports.Z_INDEX = Z_INDEX;
983
1025
  exports.Z_INDEX_ORDER = Z_INDEX_ORDER;
984
1026
  exports.canCarryAccessibleInk = canCarryAccessibleInk;
985
1027
  exports.contrastRatio = contrastRatio;
1028
+ exports.focusRingOutline = focusRingOutline;
1029
+ exports.isFocusVisible = isFocusVisible;
986
1030
  exports.isHexColor = isHexColor;
987
1031
  exports.meetsContrast = meetsContrast;
988
1032
  exports.onBrandRatio = onBrandRatio;
989
1033
  exports.relativeLuminance = relativeLuminance;
1034
+ exports.resolveFocusRingColor = resolveFocusRingColor;
990
1035
  exports.resolveOnBrand = resolveOnBrand;
991
1036
  exports.toCssVars = toCssVars;
992
1037
  exports.toRnTheme = toRnTheme;