@dloizides/design-tokens 1.0.1 → 1.2.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.ts CHANGED
@@ -35,13 +35,36 @@ interface ModeColors {
35
35
  border: string;
36
36
  /** Divider lines */
37
37
  divider: string;
38
+ /**
39
+ * Subtle inset surface — table header rows, chips, wells. Distinct from both
40
+ * `surface` (cards) and `surfaceElevated` (modals): it recedes rather than
41
+ * lifts. Optional; consumers fall back to `surface` when a preset omits it.
42
+ */
43
+ surfaceMuted?: string;
38
44
  }
39
- /** Semantic/status colours. Field names match `TenantThemeConfig`'s `SemanticColorOverrides`. */
45
+ /**
46
+ * Semantic/status colours. The four base fields match `TenantThemeConfig`'s
47
+ * `SemanticColorOverrides` exactly.
48
+ *
49
+ * Each base colour may also carry a `*Bg` **background tint** — the soft fill a
50
+ * status badge, banner or row-highlight paints behind text of the base colour.
51
+ * A tint is NOT derivable from its base (it is hand-picked for contrast), so it
52
+ * needs its own slot; without one a status surface cannot be themed at all.
53
+ * Optional, so existing presets are unchanged.
54
+ */
40
55
  interface SemanticColors {
41
56
  success: string;
42
57
  warning: string;
43
58
  error: string;
44
59
  info: string;
60
+ /** Soft background tint behind `success` content. */
61
+ successBg?: string;
62
+ /** Soft background tint behind `warning` content. */
63
+ warningBg?: string;
64
+ /** Soft background tint behind `error` content. */
65
+ errorBg?: string;
66
+ /** Soft background tint behind `info` content. */
67
+ infoBg?: string;
45
68
  }
46
69
  /** Typography tokens. `fontFamily` mirrors `TenantThemeConfig`; `monoFamily` is an optional superset. */
47
70
  interface Typography {
@@ -152,6 +175,14 @@ interface DesignTokens {
152
175
  secondary: string;
153
176
  /** Accent/highlight colour */
154
177
  accent: string;
178
+ /**
179
+ * Foreground colour for content sitting ON a `primary`-filled surface — a
180
+ * filled button's label, a brand header's text. It is a *contrast partner* of
181
+ * `primary`, not a mode colour, so it lives beside it rather than in
182
+ * `light`/`dark`. Optional; consumers fall back to white, the safe default for
183
+ * a saturated brand. A preset with a pale `primary` MUST set it explicitly.
184
+ */
185
+ onBrand?: string;
155
186
  /** Semantic/status colours */
156
187
  semantic: SemanticColors;
157
188
  /** Light-mode colours */
@@ -193,13 +224,19 @@ interface CssVarNames {
193
224
  primary?: string;
194
225
  secondary?: string;
195
226
  accent?: string;
227
+ onBrand?: string;
196
228
  success?: string;
197
229
  warning?: string;
198
230
  error?: string;
199
231
  info?: string;
232
+ successBg?: string;
233
+ warningBg?: string;
234
+ errorBg?: string;
235
+ infoBg?: string;
200
236
  lightBackground?: string;
201
237
  lightSurface?: string;
202
238
  lightSurfaceElevated?: string;
239
+ lightSurfaceMuted?: string;
203
240
  lightText?: string;
204
241
  lightTextSecondary?: string;
205
242
  lightBorder?: string;
@@ -207,6 +244,7 @@ interface CssVarNames {
207
244
  darkBackground?: string;
208
245
  darkSurface?: string;
209
246
  darkSurfaceElevated?: string;
247
+ darkSurfaceMuted?: string;
210
248
  darkText?: string;
211
249
  darkTextSecondary?: string;
212
250
  darkBorder?: string;
@@ -325,13 +363,22 @@ interface TailwindColors {
325
363
  primary: string;
326
364
  secondary: string;
327
365
  accent: string;
366
+ /** Emitted only when the preset declares `onBrand`. */
367
+ 'on-brand'?: string;
328
368
  success: string;
329
369
  warning: string;
330
370
  error: string;
331
371
  info: string;
372
+ /** Status background tints. Emitted only when the preset declares them. */
373
+ 'success-bg'?: string;
374
+ 'warning-bg'?: string;
375
+ 'error-bg'?: string;
376
+ 'info-bg'?: string;
332
377
  background: string;
333
378
  surface: string;
334
379
  'surface-elevated': string;
380
+ /** Emitted only when the preset declares `light.surfaceMuted`. */
381
+ 'surface-muted'?: string;
335
382
  text: string;
336
383
  'text-secondary': string;
337
384
  border: string;
@@ -340,6 +387,8 @@ interface TailwindColors {
340
387
  background: string;
341
388
  surface: string;
342
389
  'surface-elevated': string;
390
+ /** Emitted only when the preset declares `dark.surfaceMuted`. */
391
+ 'surface-muted'?: string;
343
392
  text: string;
344
393
  'text-secondary': string;
345
394
  border: string;
@@ -359,11 +408,89 @@ interface TailwindPreset {
359
408
  }
360
409
  /**
361
410
  * Emit a {@link DesignTokens} as a Tailwind preset for the DOM-React ThemeStudio.
362
- * Colours are always present; `borderRadius`/`boxShadow`/`fontFamily` are emitted
363
- * only when the preset defines the corresponding token group.
411
+ * The core colours are always present; the optional colour slots,
412
+ * `borderRadius`/`boxShadow`/`fontFamily` are emitted only when the preset
413
+ * defines the corresponding token.
364
414
  */
365
415
  declare function toTailwindPreset(tokens: DesignTokens): TailwindPreset;
366
416
 
417
+ /**
418
+ * Emit a {@link DesignTokens} as the shared RN UI kit's theme object — the value
419
+ * `@dloizides/ui-feedback`'s `UiProvider` broadcasts and every kit component
420
+ * (NavShell, DataTable, Filters, Pager, StatusBadge, ThemedTextInput, StatCard)
421
+ * reads via `useUi()`.
422
+ *
423
+ * WHY THIS LIVES HERE
424
+ * -------------------
425
+ * Two apps (ichnos, kefi) independently wrote the same adapter, and both hit the
426
+ * same wall: a naive projection assigns ONE value to every step of a scale, which
427
+ * silently discards the deeper brand step and the status background tints. Each
428
+ * then bolted a private overlay onto the result to smuggle the lost values into
429
+ * free slots. That overlay is this function, done twice — so it belongs in the
430
+ * token package, where the token shape that lost the values is defined.
431
+ *
432
+ * The emitted theme is a LOSSLESS carrier: every token the shape can express has
433
+ * an addressable slot, so an app can round-trip its whole palette back out
434
+ * (see the `*Colors` accessors in each app) instead of keeping a parallel static
435
+ * copy that cannot follow a dark-mode toggle or a per-tenant brand.
436
+ *
437
+ * The type is declared structurally here rather than imported, exactly as
438
+ * {@link RnThemeConfig} declares the `TenantThemeConfig` shape: this package
439
+ * stays framework-agnostic and takes no dependency on the kit it feeds.
440
+ */
441
+
442
+ /** Flat colour fields the kit reads directly. Mirrors `ui-feedback`'s `FeedbackThemeColors`. */
443
+ interface UiThemeColors {
444
+ background: string;
445
+ surface: string;
446
+ surfaceElevated: string;
447
+ text: string;
448
+ textSecondary: string;
449
+ border: string;
450
+ }
451
+ /** A colour scale. The `500` step is guaranteed; other steps are addressable. */
452
+ interface UiColorScale {
453
+ '500': string;
454
+ [step: string]: string;
455
+ }
456
+ /** Brand scales. `primary` is guaranteed; other names are addressable. */
457
+ interface UiThemePalette {
458
+ primary: UiColorScale;
459
+ [name: string]: UiColorScale;
460
+ }
461
+ /** Status scales. `error` is guaranteed; other names are addressable. */
462
+ interface UiThemeSemantic {
463
+ error: UiColorScale;
464
+ [name: string]: UiColorScale;
465
+ }
466
+ /** The kit theme. Structurally identical to `@dloizides/ui-feedback`'s `UiTheme`. */
467
+ interface UiThemeConfig {
468
+ colors: UiThemeColors;
469
+ palette: UiThemePalette;
470
+ semantic: UiThemeSemantic;
471
+ }
472
+ /** Which mode block ({@link DesignTokens.light} / {@link DesignTokens.dark}) to project. */
473
+ type UiThemeMode = 'light' | 'dark';
474
+ /** The soft/tint step of a scale — status background tints, muted brand fills. */
475
+ declare const UI_TINT_STEP = "100";
476
+ /** The step every shipped kit component reads. */
477
+ declare const UI_MAIN_STEP = "500";
478
+ /** The deep/pressed step of a scale. */
479
+ declare const UI_DEEP_STEP = "700";
480
+ /**
481
+ * Project a token set onto the shared kit's theme shape.
482
+ *
483
+ * Every value is carried into an addressable slot:
484
+ * - `palette.primary` / `secondary` / `accent` — the brand scales.
485
+ * - `palette.onBrand` — {@link DesignTokens.onBrand}, the primary's contrast partner.
486
+ * - `palette.surfaceMuted` — the mode's {@link ModeColors.surfaceMuted}.
487
+ * - `semantic.*` — each status colour at `500`, its `*Bg` tint at `100`.
488
+ *
489
+ * @param tokens the app's token set
490
+ * @param mode which mode block to project (default `'light'`)
491
+ */
492
+ declare function toUiTheme(tokens: DesignTokens, mode?: UiThemeMode): UiThemeConfig;
493
+
367
494
  /**
368
495
  * PROOViD AML console (Stack A — vanilla JS) tokens.
369
496
  *
@@ -389,10 +516,17 @@ declare const AML_TOKENS: DesignTokens;
389
516
  *
390
517
  * Seeded byte-for-byte from `erevna-web/src/theme/presets/default.ts`
391
518
  * (`DEFAULT_THEME_CONFIG`) and `erevna-web/src/theme/utils/palette.ts`
392
- * (`basePalette`). Adopting this preset via `toRnTheme(EREVNA_TOKENS)` yields the
393
- * app's current `DEFAULT_THEME_CONFIG` unchanged. No `typography`/`radii`/
394
- * `shadows` — the RN theme has no centralized tokens for those today, so they are
395
- * omitted (nothing to emit → zero visual change).
519
+ * (`basePalette`). No `typography`/`radii`/`shadows` — the RN theme has no
520
+ * centralized tokens for those today, so they are omitted (nothing to emit →
521
+ * zero visual change).
522
+ *
523
+ * ONE deliberate divergence from that seed (UX-11): `light.textSecondary` is
524
+ * `#717171`, not the app's `#777777`. `#777777` measures 4.48:1 on `#ffffff` and
525
+ * 4.18:1 on the `#f7f7f7` card surface — both under the WCAG AA 4.5:1 floor for
526
+ * normal text, and form-field labels render in this colour. `#717171` measures
527
+ * 4.88:1 and 4.56:1 against those same two surfaces. Do not "restore" it to
528
+ * match the app; `presets.contrast.test.ts` will fail if you do. The app's own
529
+ * local preset still carries `#777777` and needs the same fix separately.
396
530
  */
397
531
  declare const EREVNA_TOKENS: DesignTokens;
398
532
 
@@ -402,12 +536,74 @@ declare const EREVNA_TOKENS: DesignTokens;
402
536
  * Seeded byte-for-byte from `katalogos-web/src/theme/presets/default.ts`
403
537
  * (`DEFAULT_THEME_CONFIG`), which is currently identical to Erevna's default.
404
538
  * Kept as a separate preset so the two apps can diverge later without touching
405
- * the other. Adopting via `toRnTheme(KATALOGOS_TOKENS)` yields the app's current
406
- * `DEFAULT_THEME_CONFIG` unchanged.
539
+ * the other.
540
+ *
541
+ * ONE deliberate divergence from that seed (UX-11): `light.textSecondary` is
542
+ * `#717171`, not the app's `#777777`. `#777777` measures 4.48:1 on `#ffffff` and
543
+ * 4.18:1 on the `#f7f7f7` card surface — both under the WCAG AA 4.5:1 floor for
544
+ * normal text, and form-field labels render in this colour. `#717171` measures
545
+ * 4.88:1 and 4.56:1 against those same two surfaces. Do not "restore" it to
546
+ * match the app; `presets.contrast.test.ts` will fail if you do. The app's own
547
+ * local preset still carries `#777777` and needs the same fix separately.
407
548
  */
408
549
  declare const KATALOGOS_TOKENS: DesignTokens;
409
550
 
410
551
  /** Every shipped app preset keyed by app slug. */
411
552
  declare const PRESETS: Readonly<Record<string, DesignTokens>>;
412
553
 
413
- export { AML_CSS_VAR_NAMES, AML_TOKENS, type BrandExtras, type Branding, type CssVarNames, DEFAULT_CSS_VAR_NAMES, type DesignTokens, EREVNA_TOKENS, type InkScale, KATALOGOS_TOKENS, type ModeColors, PRESETS, type Radii, type RnThemeConfig, type SemanticColors, type Shadows, type ShellColors, type TailwindColors, type TailwindPreset, type ToCssVarsOptions, type TokenExtensions, type Typography, type VerdictColors, type WorkspaceExtras, toCssVars, toRnTheme, toTailwindPreset };
554
+ /**
555
+ * WCAG 2.1 contrast-ratio maths.
556
+ *
557
+ * Exists so every packaged preset can be *proved* accessible instead of
558
+ * eyeballed. `presets/presets.contrast.test.ts` uses it as a permanent guard:
559
+ * any future edit to a text-role colour that drops it under the AA floor fails
560
+ * the build.
561
+ *
562
+ * This is a deliberate COPY of the same function in `@dloizides/theme-web`, not
563
+ * an import. `@dloizides/design-tokens` ships zero dependencies and zero peers
564
+ * by design — it is framework-agnostic values only — so taking a dependency on
565
+ * a React theming package to borrow ~60 lines of pure arithmetic would invert
566
+ * the layering (theme-web already depends on this package). The duplication is
567
+ * bounded, pure, and pinned by `contrast.test.ts` against external reference
568
+ * pairs, so the two copies cannot silently disagree.
569
+ *
570
+ * The relative-luminance formula is the real one from WCAG 2.1 §"relative
571
+ * luminance" — sRGB channels are linearized through the gamma transfer function
572
+ * before the ITU-R BT.709 weighting. A naive channel average (or an HSL
573
+ * lightness comparison) is NOT equivalent and will silently pass colours that
574
+ * fail in a browser, which is exactly how `#777777` shipped at 4.48:1.
575
+ *
576
+ * @see https://www.w3.org/TR/WCAG21/#dfn-relative-luminance
577
+ * @see https://www.w3.org/TR/WCAG21/#dfn-contrast-ratio
578
+ */
579
+ /** WCAG 1.4.3 Contrast (Minimum), AA, normal-size text. */
580
+ declare const AA_NORMAL_TEXT_RATIO = 4.5;
581
+ /** WCAG 1.4.3 AA for large text (>=18.66px bold, or >=24px). */
582
+ declare const AA_LARGE_TEXT_RATIO = 3;
583
+ /** WCAG 1.4.11 Non-text Contrast — UI-component boundaries and graphical objects. */
584
+ declare const AA_NON_TEXT_RATIO = 3;
585
+ /**
586
+ * True when `value` is an `#rgb` / `#rrggbb` colour this module can score.
587
+ *
588
+ * Tokens may legitimately hold `rgba()` (AML's dark border is a white overlay),
589
+ * which has no fixed luminance without knowing the backdrop. The guard uses this
590
+ * to EXCLUDE such values explicitly rather than let them throw or, worse, be
591
+ * silently skipped.
592
+ */
593
+ declare function isHexColor(value: string): boolean;
594
+ /**
595
+ * WCAG relative luminance (0 = black, 1 = white) of an `#rgb` / `#rrggbb` colour.
596
+ *
597
+ * @throws if the value is not a parseable hex colour — a typo must be loud, not
598
+ * silently scored as black (which would make every ratio look compliant).
599
+ */
600
+ declare function relativeLuminance(hex: string): number;
601
+ /**
602
+ * WCAG contrast ratio between two colours, in the range 1 (identical) to 21
603
+ * (black on white). Order-independent.
604
+ */
605
+ declare function contrastRatio(foreground: string, background: string): number;
606
+ /** True when `foreground` on `background` meets `requiredRatio`. */
607
+ declare function meetsContrast(foreground: string, background: string, requiredRatio: number): boolean;
608
+
609
+ export { AA_LARGE_TEXT_RATIO, AA_NON_TEXT_RATIO, AA_NORMAL_TEXT_RATIO, AML_CSS_VAR_NAMES, AML_TOKENS, type BrandExtras, type Branding, type CssVarNames, DEFAULT_CSS_VAR_NAMES, type DesignTokens, EREVNA_TOKENS, type InkScale, KATALOGOS_TOKENS, type ModeColors, PRESETS, 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, contrastRatio, isHexColor, meetsContrast, relativeLuminance, toCssVars, toRnTheme, toTailwindPreset, toUiTheme };
package/dist/index.js CHANGED
@@ -5,13 +5,19 @@ var DEFAULT_CSS_VAR_NAMES = {
5
5
  primary: "--primary",
6
6
  secondary: "--secondary",
7
7
  accent: "--accent",
8
+ onBrand: "--on-brand",
8
9
  success: "--success",
9
10
  warning: "--warning",
10
11
  error: "--error",
11
12
  info: "--info",
13
+ successBg: "--success-bg",
14
+ warningBg: "--warning-bg",
15
+ errorBg: "--error-bg",
16
+ infoBg: "--info-bg",
12
17
  lightBackground: "--background",
13
18
  lightSurface: "--surface",
14
19
  lightSurfaceElevated: "--surface-elevated",
20
+ lightSurfaceMuted: "--surface-muted",
15
21
  lightText: "--text",
16
22
  lightTextSecondary: "--text-secondary",
17
23
  lightBorder: "--border",
@@ -19,6 +25,7 @@ var DEFAULT_CSS_VAR_NAMES = {
19
25
  darkBackground: "--background",
20
26
  darkSurface: "--surface",
21
27
  darkSurfaceElevated: "--surface-elevated",
28
+ darkSurfaceMuted: "--surface-muted",
22
29
  darkText: "--text",
23
30
  darkTextSecondary: "--text-secondary",
24
31
  darkBorder: "--border",
@@ -104,13 +111,19 @@ function toCssVars(tokens, names, options) {
104
111
  declaration(names.primary, tokens.primary),
105
112
  declaration(names.secondary, tokens.secondary),
106
113
  declaration(names.accent, tokens.accent),
114
+ declaration(names.onBrand, tokens.onBrand),
107
115
  declaration(names.success, tokens.semantic.success),
108
116
  declaration(names.warning, tokens.semantic.warning),
109
117
  declaration(names.error, tokens.semantic.error),
110
118
  declaration(names.info, tokens.semantic.info),
119
+ declaration(names.successBg, tokens.semantic.successBg),
120
+ declaration(names.warningBg, tokens.semantic.warningBg),
121
+ declaration(names.errorBg, tokens.semantic.errorBg),
122
+ declaration(names.infoBg, tokens.semantic.infoBg),
111
123
  declaration(names.lightBackground, tokens.light.background),
112
124
  declaration(names.lightSurface, tokens.light.surface),
113
125
  declaration(names.lightSurfaceElevated, tokens.light.surfaceElevated),
126
+ declaration(names.lightSurfaceMuted, tokens.light.surfaceMuted),
114
127
  declaration(names.lightText, tokens.light.text),
115
128
  declaration(names.lightTextSecondary, tokens.light.textSecondary),
116
129
  declaration(names.lightBorder, tokens.light.border),
@@ -155,6 +168,7 @@ function toCssVars(tokens, names, options) {
155
168
  declaration(names.darkBackground, tokens.dark.background),
156
169
  declaration(names.darkSurface, tokens.dark.surface),
157
170
  declaration(names.darkSurfaceElevated, tokens.dark.surfaceElevated),
171
+ declaration(names.darkSurfaceMuted, tokens.dark.surfaceMuted),
158
172
  declaration(names.darkText, tokens.dark.text),
159
173
  declaration(names.darkTextSecondary, tokens.dark.textSecondary),
160
174
  declaration(names.darkBorder, tokens.dark.border),
@@ -191,6 +205,30 @@ function toRnTheme(tokens) {
191
205
  }
192
206
 
193
207
  // src/emit/toTailwindPreset.ts
208
+ function addOptionalColors(colors, tokens) {
209
+ const { semantic } = tokens;
210
+ if (tokens.onBrand !== void 0) {
211
+ colors["on-brand"] = tokens.onBrand;
212
+ }
213
+ if (semantic.successBg !== void 0) {
214
+ colors["success-bg"] = semantic.successBg;
215
+ }
216
+ if (semantic.warningBg !== void 0) {
217
+ colors["warning-bg"] = semantic.warningBg;
218
+ }
219
+ if (semantic.errorBg !== void 0) {
220
+ colors["error-bg"] = semantic.errorBg;
221
+ }
222
+ if (semantic.infoBg !== void 0) {
223
+ colors["info-bg"] = semantic.infoBg;
224
+ }
225
+ if (tokens.light.surfaceMuted !== void 0) {
226
+ colors["surface-muted"] = tokens.light.surfaceMuted;
227
+ }
228
+ if (tokens.dark.surfaceMuted !== void 0) {
229
+ colors.dark["surface-muted"] = tokens.dark.surfaceMuted;
230
+ }
231
+ }
194
232
  function toTailwindPreset(tokens) {
195
233
  const colors = {
196
234
  primary: tokens.primary,
@@ -217,6 +255,7 @@ function toTailwindPreset(tokens) {
217
255
  divider: tokens.dark.divider
218
256
  }
219
257
  };
258
+ addOptionalColors(colors, tokens);
220
259
  const extend = { colors };
221
260
  if (tokens.radii !== void 0) {
222
261
  extend.borderRadius = {
@@ -244,6 +283,47 @@ function toTailwindPreset(tokens) {
244
283
  return { theme: { extend } };
245
284
  }
246
285
 
286
+ // src/emit/toUiTheme.ts
287
+ var UI_TINT_STEP = "100";
288
+ var UI_MAIN_STEP = "500";
289
+ var UI_DEEP_STEP = "700";
290
+ var DEFAULT_ON_BRAND = "#ffffff";
291
+ var ON_BRAND_SCALE = "onBrand";
292
+ var SURFACE_MUTED_SCALE = "surfaceMuted";
293
+ function flat(value) {
294
+ return { [UI_TINT_STEP]: value, [UI_MAIN_STEP]: value, [UI_DEEP_STEP]: value };
295
+ }
296
+ function tinted(base, tint) {
297
+ return { [UI_TINT_STEP]: tint ?? base, [UI_MAIN_STEP]: base, [UI_DEEP_STEP]: base };
298
+ }
299
+ function toUiTheme(tokens, mode = "light") {
300
+ const modeColors = mode === "dark" ? tokens.dark : tokens.light;
301
+ const { semantic } = tokens;
302
+ return {
303
+ colors: {
304
+ background: modeColors.background,
305
+ surface: modeColors.surface,
306
+ surfaceElevated: modeColors.surfaceElevated,
307
+ text: modeColors.text,
308
+ textSecondary: modeColors.textSecondary,
309
+ border: modeColors.border
310
+ },
311
+ palette: {
312
+ primary: flat(tokens.primary),
313
+ secondary: flat(tokens.secondary),
314
+ accent: flat(tokens.accent),
315
+ [ON_BRAND_SCALE]: flat(tokens.onBrand ?? DEFAULT_ON_BRAND),
316
+ [SURFACE_MUTED_SCALE]: flat(modeColors.surfaceMuted ?? modeColors.surface)
317
+ },
318
+ semantic: {
319
+ error: tinted(semantic.error, semantic.errorBg),
320
+ success: tinted(semantic.success, semantic.successBg),
321
+ warning: tinted(semantic.warning, semantic.warningBg),
322
+ info: tinted(semantic.info, semantic.infoBg)
323
+ }
324
+ };
325
+ }
326
+
247
327
  // src/presets/aml.ts
248
328
  var AML_TOKENS = {
249
329
  primary: "#4f46e5",
@@ -349,7 +429,7 @@ var EREVNA_TOKENS = {
349
429
  surface: "#f7f7f7",
350
430
  surfaceElevated: "#ffffff",
351
431
  text: "#001219",
352
- textSecondary: "#777777",
432
+ textSecondary: "#717171",
353
433
  border: "#e6e6e6",
354
434
  divider: "#e6e6e6"
355
435
  },
@@ -385,7 +465,7 @@ var KATALOGOS_TOKENS = {
385
465
  surface: "#f7f7f7",
386
466
  surfaceElevated: "#ffffff",
387
467
  text: "#001219",
388
- textSecondary: "#777777",
468
+ textSecondary: "#717171",
389
469
  border: "#e6e6e6",
390
470
  divider: "#e6e6e6"
391
471
  },
@@ -412,14 +492,88 @@ var PRESETS = {
412
492
  katalogos: KATALOGOS_TOKENS
413
493
  };
414
494
 
495
+ // src/contrast.ts
496
+ var AA_NORMAL_TEXT_RATIO = 4.5;
497
+ var AA_LARGE_TEXT_RATIO = 3;
498
+ var AA_NON_TEXT_RATIO = 3;
499
+ var SRGB_CHANNEL_MAX = 255;
500
+ var GAMMA_LINEAR_THRESHOLD = 0.03928;
501
+ var GAMMA_LINEAR_DIVISOR = 12.92;
502
+ var GAMMA_OFFSET = 0.055;
503
+ var GAMMA_DIVISOR = 1.055;
504
+ var GAMMA_EXPONENT = 2.4;
505
+ var LUMA_COEFFICIENT_RED = 0.2126;
506
+ var LUMA_COEFFICIENT_GREEN = 0.7152;
507
+ var LUMA_COEFFICIENT_BLUE = 0.0722;
508
+ var CONTRAST_FLARE = 0.05;
509
+ var HEX_RADIX = 16;
510
+ var HEX_PAIR_LENGTH = 2;
511
+ var HEX_SHORTHAND_LENGTH = 3;
512
+ var HEX_FULL_LENGTH = 6;
513
+ var CHANNEL_OFFSET_RED = 0;
514
+ var CHANNEL_OFFSET_GREEN = 2;
515
+ var CHANNEL_OFFSET_BLUE = 4;
516
+ function normalizeHexDigits(hex) {
517
+ const clean = hex.trim().replace("#", "").toLowerCase();
518
+ if (clean.length === HEX_SHORTHAND_LENGTH) {
519
+ return `${clean[0] ?? ""}${clean[0] ?? ""}${clean[1] ?? ""}${clean[1] ?? ""}${clean[2] ?? ""}${clean[2] ?? ""}`;
520
+ }
521
+ return clean;
522
+ }
523
+ function parseChannel(digits, offset) {
524
+ const pair = digits.slice(offset, offset + HEX_PAIR_LENGTH);
525
+ return parseInt(pair, HEX_RADIX) / SRGB_CHANNEL_MAX;
526
+ }
527
+ function linearizeChannel(channel) {
528
+ if (channel <= GAMMA_LINEAR_THRESHOLD) {
529
+ return channel / GAMMA_LINEAR_DIVISOR;
530
+ }
531
+ return Math.pow((channel + GAMMA_OFFSET) / GAMMA_DIVISOR, GAMMA_EXPONENT);
532
+ }
533
+ function isHexColor(value) {
534
+ const digits = normalizeHexDigits(value);
535
+ return digits.length === HEX_FULL_LENGTH && /^[0-9a-f]{6}$/.test(digits);
536
+ }
537
+ function relativeLuminance(hex) {
538
+ if (!isHexColor(hex)) {
539
+ throw new Error(`relativeLuminance: not a hex colour: ${hex}`);
540
+ }
541
+ const digits = normalizeHexDigits(hex);
542
+ const red = linearizeChannel(parseChannel(digits, CHANNEL_OFFSET_RED));
543
+ const green = linearizeChannel(parseChannel(digits, CHANNEL_OFFSET_GREEN));
544
+ const blue = linearizeChannel(parseChannel(digits, CHANNEL_OFFSET_BLUE));
545
+ return LUMA_COEFFICIENT_RED * red + LUMA_COEFFICIENT_GREEN * green + LUMA_COEFFICIENT_BLUE * blue;
546
+ }
547
+ function contrastRatio(foreground, background) {
548
+ const first = relativeLuminance(foreground);
549
+ const second = relativeLuminance(background);
550
+ const lighter = Math.max(first, second);
551
+ const darker = Math.min(first, second);
552
+ return (lighter + CONTRAST_FLARE) / (darker + CONTRAST_FLARE);
553
+ }
554
+ function meetsContrast(foreground, background, requiredRatio) {
555
+ return contrastRatio(foreground, background) >= requiredRatio;
556
+ }
557
+
558
+ exports.AA_LARGE_TEXT_RATIO = AA_LARGE_TEXT_RATIO;
559
+ exports.AA_NON_TEXT_RATIO = AA_NON_TEXT_RATIO;
560
+ exports.AA_NORMAL_TEXT_RATIO = AA_NORMAL_TEXT_RATIO;
415
561
  exports.AML_CSS_VAR_NAMES = AML_CSS_VAR_NAMES;
416
562
  exports.AML_TOKENS = AML_TOKENS;
417
563
  exports.DEFAULT_CSS_VAR_NAMES = DEFAULT_CSS_VAR_NAMES;
418
564
  exports.EREVNA_TOKENS = EREVNA_TOKENS;
419
565
  exports.KATALOGOS_TOKENS = KATALOGOS_TOKENS;
420
566
  exports.PRESETS = PRESETS;
567
+ exports.UI_DEEP_STEP = UI_DEEP_STEP;
568
+ exports.UI_MAIN_STEP = UI_MAIN_STEP;
569
+ exports.UI_TINT_STEP = UI_TINT_STEP;
570
+ exports.contrastRatio = contrastRatio;
571
+ exports.isHexColor = isHexColor;
572
+ exports.meetsContrast = meetsContrast;
573
+ exports.relativeLuminance = relativeLuminance;
421
574
  exports.toCssVars = toCssVars;
422
575
  exports.toRnTheme = toRnTheme;
423
576
  exports.toTailwindPreset = toTailwindPreset;
577
+ exports.toUiTheme = toUiTheme;
424
578
  //# sourceMappingURL=index.js.map
425
579
  //# sourceMappingURL=index.js.map