@venix-sistemas/jade 1.3.0 → 1.4.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.
Files changed (46) hide show
  1. package/README.md +969 -789
  2. package/dist/module.d.mts +8 -1
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +66 -6
  5. package/dist/runtime/components/VenixThemeSwitcher.d.vue.ts +5 -1
  6. package/dist/runtime/components/VenixThemeSwitcher.vue +455 -280
  7. package/dist/runtime/components/VenixThemeSwitcher.vue.d.ts +5 -1
  8. package/dist/runtime/composables/useThemeCookies.d.ts +7 -7
  9. package/dist/runtime/composables/useVenixTheme.d.ts +12 -0
  10. package/dist/runtime/composables/useVenixTheme.js +68 -1
  11. package/dist/runtime/plugins/overlay-scrollbars.client.d.ts +1 -1
  12. package/dist/runtime/plugins/theme-init.server.d.ts +1 -1
  13. package/dist/runtime/plugins/vuetify-theme.d.ts +1 -1
  14. package/dist/shared/constants.d.ts +1 -1
  15. package/dist/shared/constants.js +3 -1
  16. package/dist/shared/css/colors.d.ts +2 -2
  17. package/dist/shared/css/colors.js +7 -2
  18. package/dist/shared/css/cursor.js +73 -9
  19. package/dist/shared/css/index.js +1 -1
  20. package/dist/shared/css/scrollbar.js +7 -1
  21. package/dist/shared/css/tokens.d.ts +40 -0
  22. package/dist/shared/css/tokens.js +119 -0
  23. package/dist/shared/theme.json +320 -308
  24. package/dist/shared/token-names.d.ts +37 -0
  25. package/dist/shared/token-names.js +53 -0
  26. package/dist/shared/types/color-options.d.ts +23 -2
  27. package/dist/shared/types/colors.d.ts +38 -0
  28. package/dist/shared/types/experimental.d.ts +19 -0
  29. package/dist/shared/types/experimental.js +0 -0
  30. package/dist/shared/types/index.d.ts +3 -1
  31. package/dist/shared/types/runtime-config.d.ts +39 -25
  32. package/dist/shared/unocss-preset.d.ts +27 -1
  33. package/dist/shared/unocss-preset.js +20 -2
  34. package/dist/shared/utils/contrast.d.ts +11 -0
  35. package/dist/shared/utils/contrast.js +24 -0
  36. package/dist/shared/utils/index.d.ts +3 -2
  37. package/dist/shared/utils/index.js +3 -2
  38. package/dist/shared/utils/merge-themes.d.ts +8 -0
  39. package/dist/shared/utils/merge-themes.js +25 -3
  40. package/dist/shared/utils/oklab.d.ts +21 -0
  41. package/dist/shared/utils/oklab.js +74 -0
  42. package/dist/shared/utils/scale.d.ts +53 -0
  43. package/dist/shared/utils/scale.js +164 -0
  44. package/dist/shared/utils/theme-config.d.ts +8 -0
  45. package/dist/shared/utils/theme-config.js +10 -1
  46. package/package.json +15 -9
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Names of the semantic color tokens (v1.4.0, experimental), kept apart from
3
+ * the code that generates their values (`css/tokens.ts`, which pulls in the
4
+ * color engine) so the UnoCSS preset can list them without loading it.
5
+ *
6
+ * Name: `--jade-<property>[-<role>][-<variant>][-<state>]`, where the
7
+ * property says what the color is for (`bg`, `text`, `fill`, `on`, `border`).
8
+ */
9
+ /** The roles that get their own tokens. */
10
+ export declare const TOKEN_ROLES: readonly ["primary", "secondary"];
11
+ /** Neutral tokens and the step (1–12) of the neutral scale each one uses. */
12
+ export declare const NEUTRAL_TOKENS: ReadonlyArray<readonly [name: string, step: number]>;
13
+ /** Per-role tokens and the step (1–12) of the role's scale each one uses. `on` is not a step: white or black. */
14
+ export declare const ROLE_TOKENS: ReadonlyArray<readonly [name: string, step: number]>;
15
+ /** `roleTokenName('fill-hover', 'primary')` → `'fill-primary-hover'`: the role goes after the property. */
16
+ export declare function roleTokenName(name: string, role: string): string;
17
+ /** Every token name a theme with both roles and a primary gets, in the order they are written. */
18
+ export declare const TOKEN_NAMES: readonly string[];
19
+ /** Tokens that can be overridden: every one except `on-<role>`, which is white or black, not a step. */
20
+ export declare const OVERRIDABLE_TOKEN_NAMES: readonly string[];
21
+ /** `tokens` of a theme: `true`, or an object of overrides (which also turns the tokens on). */
22
+ export declare function tokensEnabled(entry: {
23
+ tokens?: boolean | object;
24
+ }): boolean;
25
+ /** The overrides in `tokens`, or none when it's a boolean. */
26
+ export declare function tokenOverrides(entry: {
27
+ tokens?: boolean | Record<string, string>;
28
+ }): Record<string, string>;
29
+ /**
30
+ * A step of a generated scale: `neutral-3`, `primary-9`… (1–12). The scale
31
+ * is the same in light and dark (step 1 is the page, 12 the strongest text),
32
+ * so one reference suits both modes.
33
+ */
34
+ export declare function parseStepRef(ref: unknown): {
35
+ scale: string;
36
+ step: number;
37
+ } | null;
@@ -0,0 +1,53 @@
1
+ export const TOKEN_ROLES = ["primary", "secondary"];
2
+ export const NEUTRAL_TOKENS = [
3
+ ["bg", 1],
4
+ ["bg-subtle", 2],
5
+ ["bg-muted", 3],
6
+ ["bg-hover", 4],
7
+ ["bg-active", 5],
8
+ ["border", 6],
9
+ ["border-strong", 9],
10
+ ["text", 12],
11
+ ["text-muted", 11],
12
+ ["text-disabled", 8]
13
+ ];
14
+ export const ROLE_TOKENS = [
15
+ ["fill", 9],
16
+ ["fill-hover", 10],
17
+ ["bg", 3],
18
+ ["bg-hover", 4],
19
+ ["bg-active", 5],
20
+ ["text", 11],
21
+ ["text-strong", 12],
22
+ ["border", 7],
23
+ ["border-strong", 11]
24
+ ];
25
+ export function roleTokenName(name, role) {
26
+ const [property, ...rest] = name.split("-");
27
+ return [property, role, ...rest].join("-");
28
+ }
29
+ export const TOKEN_NAMES = [
30
+ ...NEUTRAL_TOKENS.map(([name]) => name),
31
+ "border-focus",
32
+ ...TOKEN_ROLES.flatMap((role) => [
33
+ ...ROLE_TOKENS.map(([name]) => roleTokenName(name, role)),
34
+ `on-${role}`
35
+ ])
36
+ ];
37
+ export const OVERRIDABLE_TOKEN_NAMES = TOKEN_NAMES.filter((name) => !name.startsWith("on-"));
38
+ export function tokensEnabled(entry) {
39
+ return entry.tokens === true || typeof entry.tokens === "object" && entry.tokens !== null;
40
+ }
41
+ export function tokenOverrides(entry) {
42
+ return typeof entry.tokens === "object" && entry.tokens !== null ? entry.tokens : {};
43
+ }
44
+ export function parseStepRef(ref) {
45
+ if (typeof ref !== "string") return null;
46
+ const match = /^([a-z]+)-(\d{1,2})$/.exec(ref);
47
+ if (!match) return null;
48
+ const scale = match[1];
49
+ const step = Number(match[2]);
50
+ if (step < 1 || step > 12) return null;
51
+ if (scale !== "neutral" && !TOKEN_ROLES.includes(scale)) return null;
52
+ return { scale, step };
53
+ }
@@ -1,17 +1,24 @@
1
- import type { ThemeEntry } from './colors.js';
1
+ import type { ContrastLevel, ThemeEntry } from './colors.js';
2
2
  export interface ColorOptions {
3
3
  enabled: boolean;
4
4
  apply: boolean;
5
5
  /**
6
6
  * Initial choice for new visitors: a theme name (mode follows the OS), a
7
7
  * variant id like `'dark'` (that theme in that mode) or `'system'` (both
8
- * automatic). Default: `'dark'`.
8
+ * automatic). Default: `'dark'`. To start on a project's own brand, add
9
+ * that theme to `themes` and put its name here. A value that matches no
10
+ * available theme warns at build time and falls back to `'system'`.
9
11
  */
10
12
  defaultColor: string;
11
13
  /**
12
14
  * Override or add themes. Use the grouped format
13
15
  * (`{ translations, icon, light: {...}, dark: {...} }`); the flat format
14
16
  * (`{ dark: true, primary, ... }`) still works but is deprecated.
17
+ *
18
+ * `venix` is the brand theme of Venix Sistemas: don't change its colors.
19
+ * For another identity (a client's brand, say), add a new theme here and
20
+ * set `defaultColor` to its name. Overriding Venix's colors logs a build
21
+ * warning unless `allowVenixOverride` is `true`.
15
22
  */
16
23
  themes: Record<string, Partial<ThemeEntry>>;
17
24
  /**
@@ -35,4 +42,18 @@ export interface ColorOptions {
35
42
  * removed entirely: not listed in pickers and never applied by date.
36
43
  */
37
44
  seasonal: boolean;
45
+ /**
46
+ * Override the colors of the `venix` theme without the build warning.
47
+ * Default: `false`. Venix is the Venix Sistemas brand theme, so a project
48
+ * with its own identity should add a theme instead (see `themes`).
49
+ */
50
+ allowVenixOverride: boolean;
51
+ /**
52
+ * Experimental (v1.4.0). The contrast the semantic tokens (themes with
53
+ * `tokens: true`) aim for: `'AA'` (text 4.5:1, outlines 3:1) or `'AAA'`
54
+ * (text 7:1). The build warns, per theme variant, about every token pair
55
+ * that falls short. `false` skips the warning but still generates the
56
+ * tokens, as AA. Default: `'AA'`.
57
+ */
58
+ contrast: ContrastLevel | false;
38
59
  }
@@ -26,6 +26,8 @@ export interface ThemePalette {
26
26
  background2?: string;
27
27
  background3?: string;
28
28
  }
29
+ /** Token name → step of a generated scale (`'neutral-3'`, `'primary-9'`; 1–12). */
30
+ export type TokenOverrides = Record<string, string>;
29
31
  /** One light/dark variant of a theme (`ThemeDefinition.light` / `.dark`). */
30
32
  export interface ThemeVariant extends ThemePalette {
31
33
  /**
@@ -49,6 +51,29 @@ export interface ThemeMeta {
49
51
  translations?: ThemeTranslations;
50
52
  /** A plain emoji ('🎨') or an object with per-format variants — see `ThemeIconFormats`. */
51
53
  icon?: string | ThemeIconFormats;
54
+ /**
55
+ * Experimental (v1.4.0). Also generates the semantic color tokens
56
+ * (`--jade-text-primary`, `--jade-fill-primary`, `--jade-bg-subtle`…)
57
+ * from the variant's `primary`, `secondary` and `background`, next to the
58
+ * usual `--color-*` variables, which stay unchanged. Default: `false`.
59
+ *
60
+ * An object also turns them on and re-points individual tokens at another
61
+ * step (1–12) of the generated scales, so a surface can be stronger or
62
+ * weaker without a fixed color: `{ 'bg-subtle': 'neutral-3' }`. Steps are
63
+ * the same in light and dark, so one entry covers both modes, and the
64
+ * contrast check runs on the result. `on-<role>` can't be overridden.
65
+ */
66
+ tokens?: boolean | TokenOverrides;
67
+ /**
68
+ * Only with `tokens`. The neutral tokens (`bg`, `bg-subtle`, `text`,
69
+ * `border`…) lean slightly toward the hue of `primary` by default, so the
70
+ * theme feels of one piece; a `background` with a color of its own keeps
71
+ * its hue instead, and its surfaces gain more of it the farther from the
72
+ * page. `false` makes them plain grays, like a theme built on
73
+ * `background2`/`background3` greys. Contrast is the same either way.
74
+ * Default: `true`.
75
+ */
76
+ neutralTint?: boolean;
52
77
  }
53
78
  /**
54
79
  * A theme in the grouped format: shared metadata plus a `light` and/or a
@@ -81,9 +106,22 @@ export interface ThemeModeLabel {
81
106
  translations?: ThemeTranslations;
82
107
  icon?: string | ThemeIconFormats;
83
108
  }
109
+ /** The contrast level the semantic tokens aim for: WCAG AA (4.5:1 for text) or AAA (7:1). */
110
+ export type ContrastLevel = 'AA' | 'AAA';
84
111
  export interface ColorsConfig {
85
112
  enabled: boolean;
86
113
  defaults: boolean;
114
+ /** Contrast target of the semantic tokens and their build check (`color.contrast`). Build time only. */
115
+ contrast?: ContrastLevel | false;
116
+ /**
117
+ * The variants (ids in `themes`) whose tokens are the module's own default
118
+ * for its built-in themes, not something the project asked for with
119
+ * `tokens` or `experimental`. In 1.x Vuetify leaves their colors alone, so
120
+ * its text on `primary` and its surfaces don't change under existing
121
+ * projects, and the build doesn't warn about their contrast. Build time
122
+ * only. Removed in 2.0, when the tokens become the only model.
123
+ */
124
+ defaultTokens?: string[];
87
125
  /** Initial choice for new visitors: a theme name, a variant id (`'dark'`) or `'system'`. */
88
126
  defaultColor: string;
89
127
  /** Every concrete color variant, by id — what `data-theme` receives. */
@@ -0,0 +1,19 @@
1
+ export interface ExperimentalConfig {
2
+ /**
3
+ * Turns the experimental features on. Default: `false`.
4
+ *
5
+ * Today that is the semantic color tokens (`color.themes.<name>.tokens`),
6
+ * generated for every theme that doesn't set `tokens` itself, the built-in
7
+ * ones included, so a project can try them without rewriting its themes:
8
+ * `--jade-text-primary`, `--jade-fill-primary`, `--jade-bg-subtle`… next
9
+ * to the usual `--color-*` variables, which stay unchanged, plus the
10
+ * UnoCSS token classes and `useVenixTheme().tokens`. A theme with
11
+ * `tokens: false` still opts out.
12
+ *
13
+ * A build-time choice: there is no switch for the visitor. It is the same
14
+ * as writing `tokens: true` on every theme, so Vuetify gets the token
15
+ * colors too (`on-primary`, `surface`…). Names, steps and behaviour may
16
+ * still change before the features are declared stable.
17
+ */
18
+ enabled: boolean;
19
+ }
File without changes
@@ -2,9 +2,11 @@ import './runtime-config.js';
2
2
  export type { FontConfig, TypographyConfig } from './typography.js';
3
3
  export type { ScrollbarConfig } from './scrollbar.js';
4
4
  export type { CursorConfig, CursorType, CursorImage, ThemeCursor } from './cursor.js';
5
- export type { ThemeColors, ThemeTranslations, ColorsConfig, ThemeIconFormats, ThemeMode, ThemeModePreference, ThemePalette, ThemeVariant, ThemeMeta, ThemeDefinition, ThemeEntry, ResolvedThemeGroup, ThemeModeLabel, } from './colors.js';
5
+ export type { ThemeColors, ThemeTranslations, ColorsConfig, ThemeIconFormats, ThemeMode, ThemeModePreference, ThemePalette, ThemeVariant, ThemeMeta, ThemeDefinition, ThemeEntry, ResolvedThemeGroup, ThemeModeLabel, ContrastLevel, } from './colors.js';
6
6
  export type { ThemeConfig, ResolvedTheme } from './theme.js';
7
7
  export type { TranslationConfig } from './translation.js';
8
8
  export type { ColorOptions } from './color-options.js';
9
9
  export type { VuetifyOptions } from './vuetify.js';
10
10
  export type { IconOptions } from './icon.js';
11
+ export type { ExperimentalConfig } from './experimental.js';
12
+ export type { VenixRuntimeConfig } from './runtime-config.js';
@@ -1,31 +1,45 @@
1
1
  import type { ThemeEntry } from './colors.js';
2
+ /**
3
+ * What the module puts in `runtimeConfig.public.venixTheme`. Its own
4
+ * interface (and not only the augmentation below) so `module.ts` can check
5
+ * what it assigns against this shape, not against the type Nuxt infers from
6
+ * the app's config, which names every theme of that app.
7
+ */
8
+ export interface VenixRuntimeConfig {
9
+ defaultTheme: string;
10
+ colorThemes: Record<string, Partial<ThemeEntry>>;
11
+ applyColors: boolean;
12
+ localeCookie: string;
13
+ defaultLocale: string;
14
+ locale: string;
15
+ iconFormat: 'emote' | 'css' | 'svg';
16
+ requireConsent: boolean;
17
+ seasonal: boolean;
18
+ /**
19
+ * The semantic tokens of every theme variant with `tokens: true`, by
20
+ * variant id (`{ 'light': { 'text-primary': '#CF0000', ... } }`).
21
+ * Generated at build time; empty when no theme uses tokens (the
22
+ * built-in themes do, so only with `color: false` is it empty).
23
+ */
24
+ tokens?: Record<string, Record<string, string>>;
25
+ icon: {
26
+ aliases: Record<string, string>;
27
+ };
28
+ enabled: {
29
+ typography: boolean;
30
+ customFont: boolean;
31
+ scrollbar: boolean;
32
+ cursor: boolean;
33
+ color: boolean;
34
+ translation: boolean;
35
+ manageHtmlLang: boolean;
36
+ vuetify: boolean;
37
+ icon: boolean;
38
+ };
39
+ }
2
40
  declare module '@nuxt/schema' {
3
41
  interface PublicRuntimeConfig {
4
- venixTheme?: {
5
- defaultTheme: string;
6
- colorThemes: Record<string, Partial<ThemeEntry>>;
7
- applyColors: boolean;
8
- localeCookie: string;
9
- defaultLocale: string;
10
- locale: string;
11
- iconFormat: 'emote' | 'css' | 'svg';
12
- requireConsent: boolean;
13
- seasonal: boolean;
14
- icon: {
15
- aliases: Record<string, string>;
16
- };
17
- enabled: {
18
- typography: boolean;
19
- customFont: boolean;
20
- scrollbar: boolean;
21
- cursor: boolean;
22
- color: boolean;
23
- translation: boolean;
24
- manageHtmlLang: boolean;
25
- vuetify: boolean;
26
- icon: boolean;
27
- };
28
- };
42
+ venixTheme?: VenixRuntimeConfig;
29
43
  }
30
44
  }
31
45
  declare global {
@@ -1,8 +1,22 @@
1
1
  export interface VenixUnoPreset {
2
2
  name: string;
3
+ enforce: 'post';
3
4
  theme: {
4
5
  colors: Record<string, string>;
5
6
  };
7
+ rules: Array<[string, Record<string, string>]>;
8
+ }
9
+ export interface VenixUnoPresetOptions {
10
+ /**
11
+ * Also exposes the semantic color tokens (experimental, v1.4.0) as classes
12
+ * named after the CSS variable, with the `jade-` prefix: `--jade-bg-subtle`
13
+ * → `jade-bg-subtle`, `jade-text-muted`, `jade-border-strong`,
14
+ * `jade-fill-primary`, `jade-on-primary`… The prefix keeps them from
15
+ * clashing with the classes of other color systems (Vuetify's `text-primary`,
16
+ * Bootstrap's or shadcn's `text-muted`/`bg-muted`). They only have a value on
17
+ * themes with `tokens: true`. Default: `true`.
18
+ */
19
+ tokens?: boolean;
6
20
  }
7
21
  /**
8
22
  * UnoCSS preset that exposes the theme's colors as `theme.colors` (`primary`,
@@ -10,6 +24,18 @@ export interface VenixUnoPreset {
10
24
  * generates (`--color-primary`, ...) — enables utilities like `text-primary`,
11
25
  * `bg-background2/80` or `border-accent`.
12
26
  *
27
+ * With `tokens` (the default), the semantic tokens too, one class per token
28
+ * named after its CSS variable: `--jade-text-muted` → `jade-text-muted`. They
29
+ * are rules and not theme colors: the class says `jade-`, not the utility, and
30
+ * sets the property the token is for (`bg-*`/`fill-*` the background, `text-*`/`on-*`
31
+ * the text color, `border-*` the border color). See `VenixUnoPresetOptions`.
32
+ *
33
+ * Also points `cursor-default`, `cursor-pointer` and `cursor-text` at the
34
+ * module's cursor variables (`--cursor-pointer`, ...), falling back to the
35
+ * system cursor when the module's cursor is off. `enforce: 'post'` puts these
36
+ * after `presetWind`/`presetUno`, whose own `cursor-pointer` they replace,
37
+ * wherever the preset sits in `presets`.
38
+ *
13
39
  * Must be added manually to your `uno.config.ts`:
14
40
  *
15
41
  * ```ts
@@ -29,4 +55,4 @@ export interface VenixUnoPreset {
29
55
  * itself, these colors become part of what's actually read from the file and
30
56
  * survive that merge.
31
57
  */
32
- export declare function venixUnoPreset(): VenixUnoPreset;
58
+ export declare function venixUnoPreset(options?: VenixUnoPresetOptions): VenixUnoPreset;
@@ -1,13 +1,31 @@
1
1
  import { COLOR_PROPERTIES } from "./constants.js";
2
- export function venixUnoPreset() {
2
+ import { TOKEN_NAMES } from "./token-names.js";
3
+ const CURSOR_TYPES = ["default", "pointer", "text"];
4
+ const TOKEN_PROPERTY = {
5
+ bg: "background-color",
6
+ fill: "background-color",
7
+ text: "color",
8
+ on: "color",
9
+ border: "border-color"
10
+ };
11
+ export function venixUnoPreset(options = {}) {
3
12
  const colors = {
4
13
  inverse: "var(--color-inverse)"
5
14
  };
6
15
  for (const property of COLOR_PROPERTIES) {
7
16
  colors[property] = `var(--color-${property})`;
8
17
  }
18
+ const rules = CURSOR_TYPES.map((type) => [`cursor-${type}`, { cursor: `var(--cursor-${type}, ${type})` }]);
19
+ if (options.tokens !== false) {
20
+ for (const name of TOKEN_NAMES) {
21
+ const property = TOKEN_PROPERTY[name.split("-")[0]];
22
+ rules.push([`jade-${name}`, { [property]: `var(--jade-${name})` }]);
23
+ }
24
+ }
9
25
  return {
10
26
  name: "venix-theme",
11
- theme: { colors }
27
+ enforce: "post",
28
+ theme: { colors },
29
+ rules
12
30
  };
13
31
  }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Relative luminance of a hex color: 0 for black, 1 for white.
3
+ * E.g.: "#FFFFFF" -> 1, "#000" -> 0
4
+ */
5
+ export declare function relativeLuminance(hex: string): number;
6
+ /**
7
+ * WCAG contrast ratio between two hex colors, from 1 to 21. Symmetric: the
8
+ * order of the arguments doesn't matter.
9
+ * E.g.: ("#000000", "#FFFFFF") -> 21
10
+ */
11
+ export declare function contrastRatio(a: string, b: string): number;
@@ -0,0 +1,24 @@
1
+ function parseHex(hex) {
2
+ const match = /^#([\da-f]{3}|[\da-f]{6})$/i.exec(hex.trim());
3
+ if (!match) throw new Error(`[jade] Invalid hex color: "${hex}"`);
4
+ let digits = match[1];
5
+ if (digits.length === 3) digits = digits.replace(/./g, "$&$&");
6
+ return [
7
+ Number.parseInt(digits.slice(0, 2), 16),
8
+ Number.parseInt(digits.slice(2, 4), 16),
9
+ Number.parseInt(digits.slice(4, 6), 16)
10
+ ];
11
+ }
12
+ function linearize(channel) {
13
+ const c = channel / 255;
14
+ return c <= 0.03928 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
15
+ }
16
+ export function relativeLuminance(hex) {
17
+ const [r, g, b] = parseHex(hex);
18
+ return 0.2126 * linearize(r) + 0.7152 * linearize(g) + 0.0722 * linearize(b);
19
+ }
20
+ export function contrastRatio(a, b) {
21
+ const la = relativeLuminance(a);
22
+ const lb = relativeLuminance(b);
23
+ return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05);
24
+ }
@@ -4,8 +4,9 @@ export { resolveIcon, resolveThemeIcon } from './icon.js';
4
4
  export type { IconKind, ResolvedIcon, ThemeIconFormat, ResolvedThemeIcon } from './icon.js';
5
5
  export { extractIconRefs } from './icon-refs.js';
6
6
  export { hasCookieConsent } from './consent.js';
7
+ export { contrastRatio, relativeLuminance } from './contrast.js';
7
8
  export { isColorTheme, getActiveSeasonalTheme, getEasterSunday, getDefaultSelection, normalizeThemeSelection, resolveThemeSelection, resolveThemePreference, } from './theme-resolve.js';
8
9
  export type { ColorModel, ThemeSelection } from './theme-resolve.js';
9
- export { mergeColorThemes, normalizeColorThemes, findDeprecatedThemeEntries } from './merge-themes.js';
10
- export { buildResolvedTheme, getBaseThemeEntries } from './theme-config.js';
10
+ export { mergeColorThemes, normalizeColorThemes, findDeprecatedThemeEntries, overridesBrandColors, BRAND_THEME } from './merge-themes.js';
11
+ export { buildResolvedTheme, findInvalidDefaultColor, getBaseThemeEntries } from './theme-config.js';
11
12
  export type { VenixRuntimeThemeConfig } from './theme-config.js';
@@ -6,6 +6,7 @@ export { resolveFeatureOption } from "./options.js";
6
6
  export { resolveIcon, resolveThemeIcon } from "./icon.js";
7
7
  export { extractIconRefs } from "./icon-refs.js";
8
8
  export { hasCookieConsent } from "./consent.js";
9
+ export { contrastRatio, relativeLuminance } from "./contrast.js";
9
10
  export {
10
11
  isColorTheme,
11
12
  getActiveSeasonalTheme,
@@ -15,5 +16,5 @@ export {
15
16
  resolveThemeSelection,
16
17
  resolveThemePreference
17
18
  } from "./theme-resolve.js";
18
- export { mergeColorThemes, normalizeColorThemes, findDeprecatedThemeEntries } from "./merge-themes.js";
19
- export { buildResolvedTheme, getBaseThemeEntries } from "./theme-config.js";
19
+ export { mergeColorThemes, normalizeColorThemes, findDeprecatedThemeEntries, overridesBrandColors, BRAND_THEME } from "./merge-themes.js";
20
+ export { buildResolvedTheme, findInvalidDefaultColor, getBaseThemeEntries } from "./theme-config.js";
@@ -34,6 +34,14 @@ export declare function normalizeColorThemes(entries: Record<string, ThemeEntry>
34
34
  themes: Record<string, ThemeColors>;
35
35
  groups: Record<string, ResolvedThemeGroup>;
36
36
  };
37
+ /** The built-in theme carrying the Venix Sistemas brand. */
38
+ export declare const BRAND_THEME = "venix";
39
+ /**
40
+ * Whether the overrides change any color of the brand theme (`venix`) —
41
+ * by its name, in either format, or by one of its variant ids in the flat
42
+ * format (`dark: { primary }`). Its name and icon don't count.
43
+ */
44
+ export declare function overridesBrandColors(baseThemes: Record<string, ThemeEntry>, overrides?: Record<string, Partial<ThemeEntry>>): boolean;
37
45
  /**
38
46
  * Overrides still written in the deprecated flat format, with the message to
39
47
  * show for each — logged once at build time by `module.ts`.
@@ -1,5 +1,6 @@
1
1
  import { COLOR_PROPERTIES, THEME_MODES } from "../constants.js";
2
- const META_PROPERTIES = ["seasonal", "dateRange", "translations", "icon"];
2
+ import { tokensEnabled } from "../token-names.js";
3
+ const META_PROPERTIES = ["seasonal", "dateRange", "translations", "icon", "tokens", "neutralTint"];
3
4
  export function isThemeDefinition(entry) {
4
5
  if (!entry) return false;
5
6
  return THEME_MODES.some((mode) => typeof entry[mode] === "object");
@@ -23,6 +24,12 @@ function pickPalette(entry) {
23
24
  }
24
25
  return palette;
25
26
  }
27
+ function tokensFlag(entry) {
28
+ if (entry.tokens === false) return { tokens: false };
29
+ if (!tokensEnabled(entry)) return {};
30
+ const tokens = typeof entry.tokens === "object" ? { ...entry.tokens } : true;
31
+ return entry.neutralTint === false ? { tokens, neutralTint: false } : { tokens };
32
+ }
26
33
  const variantId = (themeName, mode, variant) => variant.id || `${themeName}-${mode}`;
27
34
  function findVariantOwner(entries, id) {
28
35
  for (const [themeName, entry] of Object.entries(entries)) {
@@ -82,18 +89,33 @@ export function normalizeColorThemes(entries) {
82
89
  const variant = entry[mode];
83
90
  if (!variant) continue;
84
91
  const id = variantId(themeName, mode, variant);
85
- themes[id] = { dark: mode === "dark", ...pickPalette(variant) };
92
+ themes[id] = { dark: mode === "dark", ...tokensFlag(entry), ...pickPalette(variant) };
86
93
  group.variants[mode] = id;
87
94
  }
88
95
  } else if (isLegacyThemeEntry(entry)) {
89
96
  const mode = entry.dark === false ? "light" : "dark";
90
- themes[themeName] = { dark: mode === "dark", ...pickPalette(entry) };
97
+ themes[themeName] = { dark: mode === "dark", ...tokensFlag(entry), ...pickPalette(entry) };
91
98
  group.variants[mode] = themeName;
92
99
  }
93
100
  groups[themeName] = group;
94
101
  }
95
102
  return { themes, groups };
96
103
  }
104
+ export const BRAND_THEME = "venix";
105
+ function hasPaletteColors(entry) {
106
+ return !!entry && COLOR_PROPERTIES.some((key) => entry[key] !== void 0);
107
+ }
108
+ export function overridesBrandColors(baseThemes, overrides) {
109
+ for (const [themeName, override] of Object.entries(overrides ?? {})) {
110
+ if (themeName === BRAND_THEME) {
111
+ if (isThemeDefinition(override) ? THEME_MODES.some((mode) => hasPaletteColors(override[mode])) : hasPaletteColors(override)) return true;
112
+ continue;
113
+ }
114
+ if (baseThemes[themeName] || !isLegacyThemeEntry(override)) continue;
115
+ if (findVariantOwner(baseThemes, themeName)?.theme === BRAND_THEME && hasPaletteColors(override)) return true;
116
+ }
117
+ return false;
118
+ }
97
119
  export function findDeprecatedThemeEntries(baseThemes, overrides) {
98
120
  const messages = [];
99
121
  for (const [themeName, override] of Object.entries(overrides ?? {})) {
@@ -0,0 +1,21 @@
1
+ /** `#RRGGBB`, uppercase. Accepts `#RGB` too. */
2
+ export declare function normalizeHex(hex: string): string;
3
+ export declare function hexToOklab(hex: string): [number, number, number];
4
+ /** The hex for an OKLab color, or `null` when it falls outside the sRGB gamut. */
5
+ export declare function oklabToHex(L: number, a: number, b: number): string | null;
6
+ /** CIELAB lightness (L*, 0–100) of a hex color. */
7
+ export declare function lightnessOf(hex: string): number;
8
+ /** OKLab chroma of a color: how far it is from a gray of the same lightness (about 0–0.4). */
9
+ export declare function chromaOf(hex: string): number;
10
+ /**
11
+ * The color at OKLab lightness `L` that has the hue of `hueOf` and, as far as
12
+ * the sRGB gamut allows, `chroma`: a chroma that doesn't fit is lowered until
13
+ * it does. `null` when `hueOf` has no hue (a gray).
14
+ */
15
+ export declare function colorWithHue(L: number, hueOf: string, chroma: number): string | null;
16
+ /**
17
+ * The background nudged toward the hue of `hueSeed`: the strongest tint that
18
+ * stays inside the sRGB gamut and within `MAX_TINT_DRIFT` of the background.
19
+ * Returns the background itself when no tint fits (e.g. pure white or black).
20
+ */
21
+ export declare function tintToward(background: string, hueSeed: string): string;
@@ -0,0 +1,74 @@
1
+ import { contrastRatio, relativeLuminance } from "./contrast.js";
2
+ function parseHex(hex) {
3
+ let digits = hex.trim().replace(/^#/, "");
4
+ if (digits.length === 3) digits = digits.replace(/./g, "$&$&");
5
+ if (!/^[\da-f]{6}$/i.test(digits)) throw new Error(`[jade] Invalid hex color: "${hex}"`);
6
+ return [0, 2, 4].map((i) => Number.parseInt(digits.slice(i, i + 2), 16));
7
+ }
8
+ function toLinear(channel) {
9
+ const c = channel / 255;
10
+ return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
11
+ }
12
+ function fromLinear(linear) {
13
+ const c = linear <= 31308e-7 ? linear * 12.92 : 1.055 * linear ** (1 / 2.4) - 0.055;
14
+ return Math.round(Math.min(1, Math.max(0, c)) * 255);
15
+ }
16
+ export function normalizeHex(hex) {
17
+ return `#${parseHex(hex).map((c) => c.toString(16).padStart(2, "0")).join("").toUpperCase()}`;
18
+ }
19
+ export function hexToOklab(hex) {
20
+ const [r, g, b] = parseHex(hex).map(toLinear);
21
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
22
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
23
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
24
+ return [
25
+ 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
26
+ 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
27
+ 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s
28
+ ];
29
+ }
30
+ export function oklabToHex(L, a, b) {
31
+ const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
32
+ const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
33
+ const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
34
+ const linear = [
35
+ 4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
36
+ -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
37
+ -0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s
38
+ ];
39
+ if (linear.some((c) => c < -5e-4 || c > 1.0005)) return null;
40
+ return `#${linear.map((c) => fromLinear(c).toString(16).padStart(2, "0")).join("").toUpperCase()}`;
41
+ }
42
+ export function lightnessOf(hex) {
43
+ const y = relativeLuminance(hex);
44
+ const f = y > 216 / 24389 ? Math.cbrt(y) : (24389 / 27 * y + 16) / 116;
45
+ return 116 * f - 16;
46
+ }
47
+ export function chromaOf(hex) {
48
+ const [, a, b] = hexToOklab(hex);
49
+ return Math.hypot(a, b);
50
+ }
51
+ export function colorWithHue(L, hueOf, chroma) {
52
+ const [, a, b] = hexToOklab(hueOf);
53
+ const own = Math.hypot(a, b);
54
+ if (own < 1e-4) return null;
55
+ for (let c = chroma; c > 5e-4; c *= 0.9) {
56
+ const candidate = oklabToHex(L, a / own * c, b / own * c);
57
+ if (candidate) return candidate;
58
+ }
59
+ return oklabToHex(L, 0, 0);
60
+ }
61
+ const TINT_CHROMAS = [0.012, 0.01, 8e-3, 6e-3, 4e-3, 3e-3, 2e-3, 1e-3];
62
+ const MAX_TINT_DRIFT = 1.02;
63
+ export function tintToward(background, hueSeed) {
64
+ const base = normalizeHex(background);
65
+ const [L] = hexToOklab(base);
66
+ const [, a, b] = hexToOklab(hueSeed);
67
+ const chroma = Math.hypot(a, b);
68
+ if (chroma < 1e-4) return base;
69
+ for (const c of TINT_CHROMAS) {
70
+ const candidate = oklabToHex(L, a / chroma * c, b / chroma * c);
71
+ if (candidate && contrastRatio(candidate, base) <= MAX_TINT_DRIFT) return candidate;
72
+ }
73
+ return base;
74
+ }