@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,53 @@
1
+ import type { ContrastLevel, ThemeMode } from '../types/index.js';
2
+ /**
3
+ * Build-time color scales for the semantic tokens (v1.4.0, experimental).
4
+ *
5
+ * A scale has 12 steps, defined by their contrast ratio against the theme's
6
+ * background (not by fixed lightness), so the same ratios work in light and
7
+ * dark mode. Importing this file pulls in the color engine: use it only at
8
+ * build time (module setup), never from `src/runtime/`.
9
+ */
10
+ export type { ContrastLevel };
11
+ export interface RoleScale {
12
+ /** The 12 steps, light to strong, as `#RRGGBB`. Step 9 (index 8) is the seed. */
13
+ steps: string[];
14
+ /** Text and icon color on steps 9 and 10: white or black, whichever contrasts more. */
15
+ on: '#FFFFFF' | '#000000';
16
+ }
17
+ export interface GeneratedScales {
18
+ /** The neutral scale; step 1 (index 0) is exactly the background. */
19
+ neutral: string[];
20
+ roles: Record<string, RoleScale>;
21
+ }
22
+ /**
23
+ * The neutral scale: the theme's background and 11 steps leaning toward the
24
+ * hue of `tintSeed` (usually the primary), or plain grays when it is `null`.
25
+ * Step 1 is exactly `background`.
26
+ * A background that has a color of its own (a peach `#FFF8F0`) is not pulled
27
+ * toward the seed: its own hue is kept, and the surfaces and borders (steps
28
+ * 2–8) get more of it the farther they sit from the page, as a hand-made
29
+ * palette would, so a card doesn't look grayer than the page behind it.
30
+ * Step 9 (outline) reaches 3:1 on steps 1–2 and step 11 (muted text) reaches
31
+ * the level on steps 1–3; step 12 is main text.
32
+ */
33
+ export declare function generateNeutralScale(background: string, tintSeed: string | null, mode: ThemeMode, level?: ContrastLevel): string[];
34
+ /**
35
+ * A role's 12 steps, generated against the neutral scale it sits on.
36
+ *
37
+ * - Step 9 is the seed itself (the engine only gets close to it).
38
+ * - `on` is white or black, whichever contrasts more with the seed.
39
+ * - Step 10 (hover) moves away from `on`: lighter when `on` is black, darker
40
+ * when it's white, so the text on it never loses contrast.
41
+ * - Steps 11 and 12 (colored and strong colored text) reach the level over
42
+ * the surfaces they sit on: neutral steps 1–3 and this role's step 3 for 11,
43
+ * this role's steps 4–5 for 12.
44
+ */
45
+ export declare function generateScale(seed: string, neutral: string[], mode: ThemeMode, level?: ContrastLevel): RoleScale;
46
+ /**
47
+ * The neutral scale and one scale per role, for one theme variant.
48
+ * `seeds` maps each role (`primary`, `secondary`…) to its seed color; the
49
+ * neutral scale leans toward the first one unless `options.tint` is `false`.
50
+ */
51
+ export declare function generateScales(background: string, seeds: Record<string, string>, mode: ThemeMode, level?: ContrastLevel, options?: {
52
+ tint?: boolean;
53
+ }): GeneratedScales;
@@ -0,0 +1,164 @@
1
+ import { BackgroundColor, Color, Theme } from "@adobe/leonardo-contrast-colors";
2
+ import { contrastRatio, relativeLuminance } from "./contrast.js";
3
+ import { chromaOf, colorWithHue, hexToOklab, lightnessOf, normalizeHex, tintToward } from "./oklab.js";
4
+ const NEUTRAL_RATIOS = [1, 1.05, 1.12, 1.2, 1.3, 1.5, 1.8, 2.3, 3, 3.5, 4.5, 12];
5
+ const ROLE_RATIOS = [1.05, 1.12, 1.2, 1.3, 1.5, 1.8, 2.3, 3];
6
+ const STEP_GAP = 0.01;
7
+ const SEED_GAP = 0.1;
8
+ const HOVER_FACTOR = 1.12;
9
+ const TEXT_FACTOR = 1.15;
10
+ const STRONG_TEXT_FACTOR = 1.4;
11
+ const MAX_RATIO = 15;
12
+ const OUTLINE_TARGET = 3;
13
+ const NUDGE = 1.01;
14
+ const MAX_NUDGES = 8;
15
+ const TARGETS = {
16
+ AA: { text: 4.5, strongText: 7 },
17
+ AAA: { text: 7, strongText: 10 }
18
+ };
19
+ const ENGINE_NOISE = "`colorspace` is deprecated";
20
+ function withoutEngineNoise(run) {
21
+ const warn = console.warn;
22
+ console.warn = (...args) => {
23
+ if (typeof args[0] === "string" && args[0].includes(ENGINE_NOISE)) return;
24
+ warn(...args);
25
+ };
26
+ try {
27
+ return run();
28
+ } finally {
29
+ console.warn = warn;
30
+ }
31
+ }
32
+ function generateSteps(key, background, mode, ratios) {
33
+ const generated = withoutEngineNoise(() => runEngine(key, background, ratios));
34
+ const steps = generated.map(normalizeHex);
35
+ if (steps.length !== ratios.length) {
36
+ throw new Error(`[jade] The color engine returned ${steps.length} steps for ${ratios.length} ratios (${mode} mode, key ${key}).`);
37
+ }
38
+ return steps;
39
+ }
40
+ function runEngine(key, background, ratios) {
41
+ const bg = new BackgroundColor({ name: "background", colorKeys: [background], ratios: [1], colorSpace: "OKLCH" });
42
+ const color = new Color({ name: "scale", colorKeys: [key], ratios, colorSpace: "OKLCH", smooth: true });
43
+ const theme = new Theme({
44
+ colors: [bg, color],
45
+ backgroundColor: bg,
46
+ lightness: Math.round(lightnessOf(background)),
47
+ contrast: 1,
48
+ output: "HEX"
49
+ });
50
+ const generated = theme.contrastColors.at(-1);
51
+ return generated.values.map((v) => v.value);
52
+ }
53
+ function isGray(hex) {
54
+ return hex.slice(1, 3) === hex.slice(3, 5) && hex.slice(3, 5) === hex.slice(5, 7);
55
+ }
56
+ function grayWithLuminanceOf(hex) {
57
+ const y = relativeLuminance(hex);
58
+ const encoded = y <= 31308e-7 ? y * 12.92 : 1.055 * y ** (1 / 2.4) - 0.055;
59
+ const channel = Math.round(Math.min(1, Math.max(0, encoded)) * 255).toString(16).padStart(2, "0").toUpperCase();
60
+ return `#${channel}${channel}${channel}`;
61
+ }
62
+ function worstContrast(text, surfaces) {
63
+ return Math.min(...surfaces.map((surface) => contrastRatio(text, surface)));
64
+ }
65
+ function reachTarget(ratio, target, surfaces, place) {
66
+ let current = Math.min(ratio, MAX_RATIO);
67
+ let color = place(current);
68
+ for (let i = 0; i < MAX_NUDGES && current < MAX_RATIO; i++) {
69
+ const worst = worstContrast(color, surfaces);
70
+ if (worst >= target) break;
71
+ current = Math.min(MAX_RATIO, current * (target / worst) * NUDGE);
72
+ color = place(current);
73
+ }
74
+ return { ratio: current, color };
75
+ }
76
+ const THEMED_BACKGROUND_CHROMA = 4e-3;
77
+ const SURFACE_CHROMA_GROWTH = 6;
78
+ const SURFACE_MAX_GROWTH = 3;
79
+ const SURFACE_MAX_CHROMA = 0.04;
80
+ const SURFACE_LIGHTNESS_RANGE = 0.03;
81
+ function enrichSurface(step, background, ratio, ownChroma) {
82
+ const growth = Math.min(SURFACE_MAX_GROWTH, 1 + SURFACE_CHROMA_GROWTH * (ratio - 1));
83
+ const chroma = Math.min(SURFACE_MAX_CHROMA, ownChroma * growth);
84
+ const L = hexToOklab(step)[0];
85
+ let best = step;
86
+ let bestOff = Number.POSITIVE_INFINITY;
87
+ for (let i = -30; i <= 30; i++) {
88
+ const candidate = colorWithHue(L + i / 30 * SURFACE_LIGHTNESS_RANGE, background, chroma);
89
+ if (!candidate) continue;
90
+ const off = Math.abs(contrastRatio(candidate, background) - ratio);
91
+ if (off < bestOff) {
92
+ best = candidate;
93
+ bestOff = off;
94
+ }
95
+ }
96
+ return best;
97
+ }
98
+ export function generateNeutralScale(background, tintSeed, mode, level = "AA") {
99
+ const exact = normalizeHex(background);
100
+ const ownChroma = chromaOf(exact);
101
+ const themed = tintSeed !== null && ownChroma >= THEMED_BACKGROUND_CHROMA;
102
+ const key = tintSeed && !themed ? tintToward(exact, tintSeed) : exact;
103
+ const keepGray = !tintSeed && isGray(exact);
104
+ const generate = (ratios2) => {
105
+ const steps2 = generateSteps(key, key, mode, ratios2);
106
+ return keepGray ? steps2.map(grayWithLuminanceOf) : steps2;
107
+ };
108
+ const ratios = [...NEUTRAL_RATIOS];
109
+ ratios[10] = TARGETS[level].text;
110
+ const steps = generate(ratios);
111
+ steps[0] = exact;
112
+ if (themed) {
113
+ for (let i = 1; i <= 7; i++) steps[i] = enrichSurface(steps[i], exact, ratios[i], ownChroma);
114
+ }
115
+ const withRatio = (index, ratio) => {
116
+ const attempt = [...ratios];
117
+ attempt[index] = ratio;
118
+ return generate(attempt)[index];
119
+ };
120
+ steps[8] = reachTarget(ratios[8], OUTLINE_TARGET, steps.slice(0, 2), (r) => withRatio(8, r)).color;
121
+ steps[10] = reachTarget(ratios[10], TARGETS[level].text, steps.slice(0, 3), (r) => withRatio(10, r)).color;
122
+ return steps;
123
+ }
124
+ function fitUnderSeed(seedRatio) {
125
+ const top = ROLE_RATIOS.at(-1);
126
+ const ceiling = seedRatio - SEED_GAP;
127
+ if (ceiling >= top) return [...ROLE_RATIOS];
128
+ const squeeze = Math.max(0, (ceiling - 1) / (top - 1));
129
+ return ROLE_RATIOS.map((ratio, i) => Math.max(1 + STEP_GAP * (i + 1), 1 + (ratio - 1) * squeeze));
130
+ }
131
+ export function generateScale(seed, neutral, mode, level = "AA") {
132
+ const background = neutral[0];
133
+ const exactSeed = normalizeHex(seed);
134
+ const seedRatio = contrastRatio(exactSeed, background);
135
+ const on = contrastRatio(exactSeed, "#000000") >= contrastRatio(exactSeed, "#FFFFFF") ? "#000000" : "#FFFFFF";
136
+ const darkBackground = contrastRatio(background, "#000000") < contrastRatio(background, "#FFFFFF");
137
+ const hoverFarther = on === "#000000" === darkBackground;
138
+ const hoverRatio = Math.min(MAX_RATIO, Math.max(1.05, hoverFarther ? seedRatio * HOVER_FACTOR : seedRatio / HOVER_FACTOR));
139
+ const targets = TARGETS[level];
140
+ const textRatio = Math.max(targets.text, seedRatio * TEXT_FACTOR);
141
+ const strongTextRatio = Math.max(targets.strongText, seedRatio * STRONG_TEXT_FACTOR, textRatio * TEXT_FACTOR);
142
+ const ratios = [...fitUnderSeed(seedRatio), seedRatio, hoverRatio, textRatio, strongTextRatio];
143
+ const steps = generateSteps(exactSeed, background, mode, ratios);
144
+ steps[8] = exactSeed;
145
+ const withRatio = (index, ratio) => {
146
+ const attempt = [...ratios];
147
+ attempt[index] = ratio;
148
+ return generateSteps(exactSeed, background, mode, attempt)[index];
149
+ };
150
+ const text = reachTarget(textRatio, targets.text, [neutral[0], neutral[1], neutral[2], steps[2]], (r) => withRatio(10, r));
151
+ steps[10] = text.color;
152
+ const strongStart = Math.max(strongTextRatio, text.ratio * TEXT_FACTOR);
153
+ const strong = reachTarget(strongStart, targets.text, [steps[3], steps[4]], (r) => withRatio(11, r));
154
+ steps[11] = strong.color;
155
+ return { steps, on };
156
+ }
157
+ export function generateScales(background, seeds, mode, level = "AA", options = {}) {
158
+ const entries = Object.entries(seeds);
159
+ const tintSeed = options.tint === false ? null : entries[0]?.[1] ?? background;
160
+ const neutral = generateNeutralScale(background, tintSeed, mode, level);
161
+ const roles = {};
162
+ for (const [role, seed] of entries) roles[role] = generateScale(seed, neutral, mode, level);
163
+ return { neutral, roles };
164
+ }
@@ -1,4 +1,5 @@
1
1
  import type { ResolvedTheme, ThemeEntry } from '../types/index.js';
2
+ import type { ColorModel } from './theme-resolve.js';
2
3
  export interface VenixRuntimeThemeConfig {
3
4
  defaultTheme?: string;
4
5
  colorThemes?: Record<string, Partial<ThemeEntry>>;
@@ -7,6 +8,13 @@ export interface VenixRuntimeThemeConfig {
7
8
  }
8
9
  /** The theme entries bundled with the module, in config format. */
9
10
  export declare function getBaseThemeEntries(): Record<string, ThemeEntry>;
11
+ /**
12
+ * The build-time message for a `defaultColor` that names no theme a visitor
13
+ * can get (a typo, a theme that isn't defined, a seasonal one with
14
+ * `seasonal: false`), or `null` when it's fine. The runtime then falls back
15
+ * to `'system'` (see `getDefaultSelection`), so this only makes that visible.
16
+ */
17
+ export declare function findInvalidDefaultColor(colors: ColorModel): string | null;
10
18
  /**
11
19
  * Rebuilds the color themes at runtime, layering `theme.json`
12
20
  * (bundled with the module, with the "base" themes) with the customizations
@@ -1,9 +1,18 @@
1
1
  import themeData from "../theme.json" with { type: "json" };
2
- import { DEFAULT_THEME } from "../constants.js";
2
+ import { DEFAULT_THEME, SYSTEM_THEME } from "../constants.js";
3
3
  import { mergeColorThemes, normalizeColorThemes } from "./merge-themes.js";
4
+ import { findVariantOwner, isSelectableGroup } from "./theme-resolve.js";
4
5
  export function getBaseThemeEntries() {
5
6
  return themeData.colors?.themes ?? {};
6
7
  }
8
+ export function findInvalidDefaultColor(colors) {
9
+ const defaultColor = colors.defaultColor || DEFAULT_THEME;
10
+ if (defaultColor === SYSTEM_THEME || isSelectableGroup(colors, defaultColor)) return null;
11
+ const owner = findVariantOwner(colors, defaultColor);
12
+ if (owner && isSelectableGroup(colors, owner.theme)) return null;
13
+ const available = Object.keys(colors.groups).filter((name) => isSelectableGroup(colors, name));
14
+ return `\`color.defaultColor\` is \`'${defaultColor}'\`, which matches no available theme, so new visitors get \`'system'\` instead. Use a theme name (${available.map((name) => `\`'${name}'\``).join(", ")}), one of its variant ids or \`'system'\`.`;
15
+ }
7
16
  const resolvedThemeCache = /* @__PURE__ */ new WeakMap();
8
17
  export function buildResolvedTheme(runtimeThemeConfig) {
9
18
  if (!runtimeThemeConfig) return resolveTheme();
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@venix-sistemas/jade",
3
- "version": "1.3.0",
4
- "description": "UI foundation for Nuxt in a single module: color themes (seasonal, SSR, cookie consent), typography, scrollbar, cursor, icons, i18n, plus UnoCSS and Vuetify integrations.",
3
+ "version": "1.4.0",
4
+ "description": "UI foundation for Nuxt in one module: light/dark and seasonal color themes that switch by date or OS, with SSR and cookie consent; semantic color tokens built for WCAG contrast; plus typography, custom scrollbar and cursor, Iconify icons, i18n, and UnoCSS and Vuetify integrations.",
5
5
  "keywords": [
6
6
  "nuxt",
7
7
  "nuxt-module",
8
8
  "ui",
9
9
  "design-system",
10
+ "design-tokens",
10
11
  "nuxt-theme",
11
12
  "jade",
12
13
  "jade-theme",
@@ -14,7 +15,11 @@
14
15
  "theming",
15
16
  "colors",
16
17
  "dark-mode",
18
+ "accessibility",
19
+ "wcag",
17
20
  "seasonal-theme",
21
+ "ssr",
22
+ "cookie-consent",
18
23
  "typography",
19
24
  "scrollbar",
20
25
  "cursor",
@@ -65,11 +70,12 @@
65
70
  "playground"
66
71
  ],
67
72
  "dependencies": {
73
+ "@adobe/leonardo-contrast-colors": "^1.1.0",
68
74
  "@iconify-json/line-md": "^1.2.16",
69
75
  "@iconify-json/mdi": "^1.2.3",
70
76
  "@iconify/utils": "^3.1.7",
71
77
  "@nuxt/icon": "^2.5.1",
72
- "@nuxt/kit": "^4.6.1"
78
+ "@nuxt/kit": "^4.6.2"
73
79
  },
74
80
  "peerDependencies": {
75
81
  "overlayscrollbars": "^2.17.0"
@@ -80,19 +86,19 @@
80
86
  }
81
87
  },
82
88
  "devDependencies": {
83
- "@nuxt/devtools": "4.0.0-beta.5",
89
+ "@nuxt/devtools": "4.0.0-beta.7",
84
90
  "@nuxt/eslint-config": "^1.17.0",
85
91
  "@nuxt/module-builder": "^1.0.3",
86
- "@nuxt/schema": "^4.6.1",
87
- "@nuxt/test-utils": "^4.3.3",
92
+ "@nuxt/schema": "^4.6.2",
93
+ "@nuxt/test-utils": "^4.3.4",
88
94
  "@nuxtjs/i18n": "10.6.0",
89
95
  "@types/node": "latest",
90
96
  "changelogen": "^0.6.2",
91
- "eslint": "^10.12.0",
92
- "nuxt": "^4.6.1",
97
+ "eslint": "^10.13.0",
98
+ "nuxt": "^4.6.2",
93
99
  "overlayscrollbars": "^2.17.0",
94
100
  "typescript": "7.0.2",
95
- "vitest": "5.0.4",
101
+ "vitest": "5.0.5",
96
102
  "vue-tsc": "^3.3.13"
97
103
  },
98
104
  "scripts": {