@venix-sistemas/jade 1.4.0 → 1.4.1
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/module.json +4 -1
- package/dist/module.mjs +10 -2
- package/dist/runtime/composables/useVenixTheme.js +3 -0
- package/dist/runtime/scripts/theme-init.d.ts +8 -0
- package/dist/runtime/scripts/theme-init.js +14 -1
- package/dist/shared/utils/load.d.ts +1 -1
- package/dist/shared/utils/load.js +1 -1
- package/dist/shared/utils/merge-themes.d.ts +10 -0
- package/dist/shared/utils/merge-themes.js +55 -0
- package/package.json +11 -12
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -2,7 +2,7 @@ import { addComponent, addPlugin, addServerPlugin, addTemplate, useLogger, insta
|
|
|
2
2
|
import { loadTheme } from '../dist/shared/utils/load.js';
|
|
3
3
|
import { SWITCHER_ICONS, DEFAULT_THEME, DEFAULT_LOCALE_COOKIE_NAME, DEFAULT_LOCALE } from '../dist/shared/constants.js';
|
|
4
4
|
import { resolveFeatureOption } from '../dist/shared/utils/options.js';
|
|
5
|
-
import { findDeprecatedThemeEntries, overridesBrandColors } from '../dist/shared/utils/merge-themes.js';
|
|
5
|
+
import { findDeprecatedThemeEntries, findThemeConfigIssues, overridesBrandColors } from '../dist/shared/utils/merge-themes.js';
|
|
6
6
|
import { buildResolvedTheme, getBaseThemeEntries, findInvalidDefaultColor } from '../dist/shared/utils/theme-config.js';
|
|
7
7
|
import { generateTokens, findTokenOverrideIssues, findTokenContrastIssues, collectTokens } from '../dist/shared/css/tokens.js';
|
|
8
8
|
import { tokensEnabled, TOKEN_ROLES } from '../dist/shared/token-names.js';
|
|
@@ -250,7 +250,10 @@ async function registerThemeIcon(nuxt, resolver, options, colors) {
|
|
|
250
250
|
const module$1 = defineNuxtModule({
|
|
251
251
|
meta: {
|
|
252
252
|
name: "@venix-sistemas/jade",
|
|
253
|
-
configKey: "venixTheme"
|
|
253
|
+
configKey: "venixTheme",
|
|
254
|
+
// The module is built and tested on Nuxt 4 (`@nuxt/kit` ^4). Older
|
|
255
|
+
// versions get a clear message, not the first error that comes up.
|
|
256
|
+
compatibility: { nuxt: ">=4.0.0" }
|
|
254
257
|
},
|
|
255
258
|
defaults: {
|
|
256
259
|
translation: true,
|
|
@@ -286,6 +289,11 @@ const module$1 = defineNuxtModule({
|
|
|
286
289
|
for (const message of findDeprecatedThemeEntries(getBaseThemeEntries(), colorOptions.themes)) {
|
|
287
290
|
useLogger("jade").warn(message);
|
|
288
291
|
}
|
|
292
|
+
if (colorOptions.enabled) {
|
|
293
|
+
for (const message of findThemeConfigIssues(getBaseThemeEntries(), colorOptions.themes)) {
|
|
294
|
+
useLogger("jade").warn(message);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
289
297
|
if (colorOptions.enabled && !colorOptions.allowVenixOverride && overridesBrandColors(getBaseThemeEntries(), colorOptions.themes)) {
|
|
290
298
|
useLogger("jade").warn("`color.themes` changes the colors of `venix`, the Venix Sistemas brand theme. For another identity, add a theme of your own (e.g. `color.themes.myBrand`) and set `color.defaultColor` to its name; Venix stays in the switcher next to it. Set `color.allowVenixOverride: true` if changing Venix is intended.");
|
|
291
299
|
}
|
|
@@ -281,6 +281,9 @@ function installThemeEffects(core) {
|
|
|
281
281
|
onNuxtReady(() => {
|
|
282
282
|
hasConsent.value = hasCookieConsent();
|
|
283
283
|
window.addEventListener(COOKIE_PREFERENCES_UPDATED_EVENT, core.syncPersistence);
|
|
284
|
+
window.addEventListener("storage", (event) => {
|
|
285
|
+
if (event.key === null || event.key === COOKIE_CONSENT_STORAGE_KEY) core.syncPersistence();
|
|
286
|
+
});
|
|
284
287
|
const cookieStore = window.cookieStore;
|
|
285
288
|
cookieStore?.addEventListener("change", syncFromCookies);
|
|
286
289
|
window.addEventListener("focus", syncFromCookies);
|
|
@@ -45,5 +45,13 @@ export interface InitThemeOptions {
|
|
|
45
45
|
*/
|
|
46
46
|
export default function initTheme(createThemeResolver: () => ThemeResolver, themeData: ResolvedTheme, options: InitThemeOptions): void;
|
|
47
47
|
export declare function createInitThemeOptions(requireConsent: boolean): InitThemeOptions;
|
|
48
|
+
/**
|
|
49
|
+
* Only what the script's theme resolution reads, so the HTML doesn't carry
|
|
50
|
+
* every color, translation and icon of every theme on each response: the
|
|
51
|
+
* name, variants, `seasonal` and `dateRange` of each group, and per variant
|
|
52
|
+
* whether it is a color theme (`isColorTheme` looks at `primary` and
|
|
53
|
+
* `background`). `defaultColor` stays as is.
|
|
54
|
+
*/
|
|
55
|
+
export declare function toInitThemeData(themeData: ResolvedTheme): ResolvedTheme;
|
|
48
56
|
/** The inline script's source: `initTheme` as an IIFE, with its arguments serialized. */
|
|
49
57
|
export declare function renderInitThemeScript(themeData: ResolvedTheme, options: InitThemeOptions): string;
|
|
@@ -81,6 +81,19 @@ export function createInitThemeOptions(requireConsent) {
|
|
|
81
81
|
attributes: { scrollbar: SCROLLBAR_ATTRIBUTE, cursor: CURSOR_ATTRIBUTE, font: FONT_ATTRIBUTE }
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
|
+
export function toInitThemeData(themeData) {
|
|
85
|
+
const { themes = {}, groups = {}, defaultColor } = themeData.colors ?? {};
|
|
86
|
+
const slimThemes = {};
|
|
87
|
+
for (const [id, colors] of Object.entries(themes)) {
|
|
88
|
+
const { primary, background } = colors;
|
|
89
|
+
slimThemes[id] = { ...primary && { primary }, ...background && { background } };
|
|
90
|
+
}
|
|
91
|
+
const slimGroups = {};
|
|
92
|
+
for (const [name, { variants, seasonal, dateRange }] of Object.entries(groups)) {
|
|
93
|
+
slimGroups[name] = { variants, ...seasonal !== void 0 && { seasonal }, ...dateRange && { dateRange } };
|
|
94
|
+
}
|
|
95
|
+
return { colors: { themes: slimThemes, groups: slimGroups, defaultColor } };
|
|
96
|
+
}
|
|
84
97
|
export function renderInitThemeScript(themeData, options) {
|
|
85
|
-
return `(${initTheme.toString()})(${createThemeResolver.toString()}, ${toInlineScriptJson(themeData)}, ${toInlineScriptJson(options)})`;
|
|
98
|
+
return `(${initTheme.toString()})(${createThemeResolver.toString()}, ${toInlineScriptJson(toInitThemeData(themeData))}, ${toInlineScriptJson(options)})`;
|
|
86
99
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import themeData from "../theme.json" with { type: "json" };
|
|
2
2
|
import { normalizeLocale } from "./normalize.js";
|
|
3
3
|
import { buildResolvedTheme } from "./theme-config.js";
|
|
4
|
-
export function loadTheme(
|
|
4
|
+
export function loadTheme() {
|
|
5
5
|
return { ...themeData, colors: buildResolvedTheme().colors };
|
|
6
6
|
}
|
|
7
7
|
export function extractLocales(theme) {
|
|
@@ -42,6 +42,16 @@ export declare const BRAND_THEME = "venix";
|
|
|
42
42
|
* format (`dark: { primary }`). Its name and icon don't count.
|
|
43
43
|
*/
|
|
44
44
|
export declare function overridesBrandColors(baseThemes: Record<string, ThemeEntry>, overrides?: Record<string, Partial<ThemeEntry>>): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Values in the project's `color.themes` that the module would otherwise
|
|
47
|
+
* drop or never use, without a word: a color that isn't a hex (the CSS, the
|
|
48
|
+
* tokens and Vuetify only take `#RGB`/`#RRGGBB`), a seasonal theme whose
|
|
49
|
+
* `dateRange` is missing or malformed (it would never turn on), and two
|
|
50
|
+
* variants that share an id (the last one overwrites the other). Only the
|
|
51
|
+
* themes the project set are checked; the built-in ones are the module's own.
|
|
52
|
+
* Logged once at build time by `module.ts`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function findThemeConfigIssues(baseThemes: Record<string, ThemeEntry>, overrides?: Record<string, Partial<ThemeEntry>>): string[];
|
|
45
55
|
/**
|
|
46
56
|
* Overrides still written in the deprecated flat format, with the message to
|
|
47
57
|
* show for each — logged once at build time by `module.ts`.
|
|
@@ -116,6 +116,61 @@ export function overridesBrandColors(baseThemes, overrides) {
|
|
|
116
116
|
}
|
|
117
117
|
return false;
|
|
118
118
|
}
|
|
119
|
+
const HEX_COLOR = /^#(?:[\da-f]{3}|[\da-f]{6})$/i;
|
|
120
|
+
const EASTER_BOUND = /^easter(?:[+-]\d+)?$/;
|
|
121
|
+
const DAYS_IN_MONTH = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
122
|
+
function isValidDateBound(value) {
|
|
123
|
+
if (typeof value !== "string") return false;
|
|
124
|
+
const bound = value.trim();
|
|
125
|
+
if (EASTER_BOUND.test(bound)) return true;
|
|
126
|
+
const match = /^(\d{1,2})-(\d{1,2})$/.exec(bound);
|
|
127
|
+
if (!match) return false;
|
|
128
|
+
const month = Number(match[1]);
|
|
129
|
+
const day = Number(match[2]);
|
|
130
|
+
return month >= 1 && month <= 12 && day >= 1 && day <= DAYS_IN_MONTH[month - 1];
|
|
131
|
+
}
|
|
132
|
+
export function findThemeConfigIssues(baseThemes, overrides) {
|
|
133
|
+
const messages = [];
|
|
134
|
+
const projectThemes = new Set(Object.keys(overrides ?? {}));
|
|
135
|
+
const ownersById = /* @__PURE__ */ new Map();
|
|
136
|
+
for (const [themeName, entry] of Object.entries(mergeColorThemes(baseThemes, overrides))) {
|
|
137
|
+
const variants = [];
|
|
138
|
+
if (isThemeDefinition(entry)) {
|
|
139
|
+
for (const mode of THEME_MODES) {
|
|
140
|
+
const variant = entry[mode];
|
|
141
|
+
if (variant) variants.push({ path: `${themeName}.${mode}`, id: variantId(themeName, mode, variant), palette: variant });
|
|
142
|
+
}
|
|
143
|
+
} else if (isLegacyThemeEntry(entry)) {
|
|
144
|
+
variants.push({ path: themeName, id: themeName, palette: entry });
|
|
145
|
+
}
|
|
146
|
+
for (const { path, id, palette } of variants) {
|
|
147
|
+
ownersById.set(id, [...ownersById.get(id) ?? [], { themeName, path }]);
|
|
148
|
+
if (!projectThemes.has(themeName)) continue;
|
|
149
|
+
for (const key of COLOR_PROPERTIES) {
|
|
150
|
+
const value = palette[key];
|
|
151
|
+
if (value === void 0 || typeof value === "string" && HEX_COLOR.test(value)) continue;
|
|
152
|
+
messages.push(`\`color.themes.${path}.${key}\` is \`${JSON.stringify(value)}\`, which is not a hex color (\`#RGB\` or \`#RRGGBB\`), so it is ignored.`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (!projectThemes.has(themeName)) continue;
|
|
156
|
+
const { seasonal, dateRange } = entry;
|
|
157
|
+
if (seasonal === true && !dateRange) {
|
|
158
|
+
messages.push(`\`color.themes.${themeName}\` is \`seasonal\` but has no \`dateRange\`, so it never turns on. Add \`dateRange: { start: 'MM-DD', end: 'MM-DD' }\`.`);
|
|
159
|
+
} else if (dateRange && seasonal !== true) {
|
|
160
|
+
messages.push(`\`color.themes.${themeName}.dateRange\` has no effect without \`seasonal: true\`.`);
|
|
161
|
+
} else if (dateRange) {
|
|
162
|
+
for (const bound of ["start", "end"]) {
|
|
163
|
+
if (isValidDateBound(dateRange[bound])) continue;
|
|
164
|
+
messages.push(`\`color.themes.${themeName}.dateRange.${bound}\` is \`${JSON.stringify(dateRange[bound])}\`, which is not a date, so the theme never turns on. Use \`'MM-DD'\`, \`'easter'\`, \`'easter-47'\` or \`'easter+1'\`.`);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
for (const [id, owners] of ownersById) {
|
|
169
|
+
if (owners.length < 2 || !owners.some((owner) => projectThemes.has(owner.themeName))) continue;
|
|
170
|
+
messages.push(`${owners.map((owner) => `\`color.themes.${owner.path}\``).join(" and ")} share the id \`${id}\`, so one overwrites the other. Give one of them a different \`id\` (or name).`);
|
|
171
|
+
}
|
|
172
|
+
return messages;
|
|
173
|
+
}
|
|
119
174
|
export function findDeprecatedThemeEntries(baseThemes, overrides) {
|
|
120
175
|
const messages = [];
|
|
121
176
|
for (const [themeName, override] of Object.entries(overrides ?? {})) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venix-sistemas/jade",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
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",
|
|
@@ -46,8 +46,7 @@
|
|
|
46
46
|
"exports": {
|
|
47
47
|
".": {
|
|
48
48
|
"types": "./dist/types.d.mts",
|
|
49
|
-
"import": "./dist/module.mjs"
|
|
50
|
-
"exports": "./src/module.ts"
|
|
49
|
+
"import": "./dist/module.mjs"
|
|
51
50
|
},
|
|
52
51
|
"./theme.json": "./dist/shared/theme.json",
|
|
53
52
|
"./unocss": {
|
|
@@ -74,8 +73,8 @@
|
|
|
74
73
|
"@iconify-json/line-md": "^1.2.16",
|
|
75
74
|
"@iconify-json/mdi": "^1.2.3",
|
|
76
75
|
"@iconify/utils": "^3.1.7",
|
|
77
|
-
"@nuxt/icon": "^2.
|
|
78
|
-
"@nuxt/kit": "^4.6.
|
|
76
|
+
"@nuxt/icon": "^2.6.2",
|
|
77
|
+
"@nuxt/kit": "^4.6.4"
|
|
79
78
|
},
|
|
80
79
|
"peerDependencies": {
|
|
81
80
|
"overlayscrollbars": "^2.17.0"
|
|
@@ -86,20 +85,20 @@
|
|
|
86
85
|
}
|
|
87
86
|
},
|
|
88
87
|
"devDependencies": {
|
|
89
|
-
"@nuxt/devtools": "4.
|
|
88
|
+
"@nuxt/devtools": "4.1.0",
|
|
90
89
|
"@nuxt/eslint-config": "^1.17.0",
|
|
91
90
|
"@nuxt/module-builder": "^1.0.3",
|
|
92
|
-
"@nuxt/schema": "^4.6.
|
|
93
|
-
"@nuxt/test-utils": "^4.
|
|
91
|
+
"@nuxt/schema": "^4.6.4",
|
|
92
|
+
"@nuxt/test-utils": "^4.4.0",
|
|
94
93
|
"@nuxtjs/i18n": "10.6.0",
|
|
95
94
|
"@types/node": "latest",
|
|
96
95
|
"changelogen": "^0.6.2",
|
|
97
|
-
"eslint": "^10.
|
|
98
|
-
"nuxt": "^4.6.
|
|
96
|
+
"eslint": "^10.14.0",
|
|
97
|
+
"nuxt": "^4.6.4",
|
|
99
98
|
"overlayscrollbars": "^2.17.0",
|
|
100
99
|
"typescript": "7.0.2",
|
|
101
|
-
"vitest": "5.0
|
|
102
|
-
"vue-tsc": "^3.3.
|
|
100
|
+
"vitest": "5.1.0",
|
|
101
|
+
"vue-tsc": "^3.3.14"
|
|
103
102
|
},
|
|
104
103
|
"scripts": {
|
|
105
104
|
"dev": "pnpm run dev:prepare && nuxt dev playground",
|