@venix-sistemas/jade 1.0.0 → 1.1.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/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@venix-sistemas/jade",
3
3
  "configKey": "venixTheme",
4
- "version": "1.0.0",
4
+ "version": "1.1.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.3",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,8 +1,10 @@
1
1
  import { addComponent, addPlugin, addServerPlugin, addTemplate, installModule, addImports, defineNuxtModule, createResolver } from '@nuxt/kit';
2
2
  import { loadTheme } from '../dist/shared/utils/load.js';
3
- import { NON_COLOR_PROPERTIES, DEFAULT_LOCALE_COOKIE_NAME, DEFAULT_LOCALE } from '../dist/shared/constants.js';
3
+ import { 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 { mergeColorThemes } from '../dist/shared/utils/merge-themes.js';
5
6
  import { processTheme } from '../dist/shared/css/index.js';
7
+ import { isColorTheme, getThemeHexColors } from '../dist/shared/utils/theme-resolve.js';
6
8
  import { createRequire } from 'node:module';
7
9
  import { realpathSync } from 'node:fs';
8
10
  import { fileURLToPath } from 'node:url';
@@ -11,7 +13,7 @@ import { getIcons } from '@iconify/utils';
11
13
  import { extractIconRefs } from '../dist/shared/utils/index.js';
12
14
 
13
15
  function customizeTheme(baseTheme, options) {
14
- const customized = JSON.parse(JSON.stringify(baseTheme));
16
+ const customized = structuredClone(baseTheme);
15
17
  customized.typography = resolveFeatureOption(options.typography, customized.typography);
16
18
  customized.customScrollbar = resolveFeatureOption(options.scrollbar, customized.customScrollbar);
17
19
  customized.customCursor = resolveFeatureOption(options.cursor, customized.customCursor);
@@ -25,21 +27,7 @@ function customizeTheme(baseTheme, options) {
25
27
  if (colorOption.defaultColor) {
26
28
  customized.colors.defaultColor = colorOption.defaultColor;
27
29
  }
28
- if (colorOption.themes) {
29
- Object.entries(colorOption.themes).forEach(([themeName, customColors]) => {
30
- if (customized.colors.themes[themeName]) {
31
- customized.colors.themes[themeName] = {
32
- ...customized.colors.themes[themeName],
33
- ...customColors
34
- };
35
- } else {
36
- customized.colors.themes[themeName] = {
37
- dark: true,
38
- ...customColors
39
- };
40
- }
41
- });
42
- }
30
+ customized.colors.themes = mergeColorThemes(customized.colors.themes, colorOption.themes);
43
31
  }
44
32
  return customized;
45
33
  }
@@ -87,14 +75,9 @@ function registerThemeCSS(nuxt, theme) {
87
75
  function buildVuetifyThemes(colors) {
88
76
  const themes = {};
89
77
  for (const [name, themeColors] of Object.entries(colors.themes)) {
90
- if (!themeColors.primary && !themeColors.background) continue;
78
+ if (!isColorTheme(themeColors)) continue;
91
79
  const isDark = themeColors.dark === true;
92
- const vuetifyColors = {};
93
- for (const [key, value] of Object.entries(themeColors)) {
94
- if (NON_COLOR_PROPERTIES.includes(key)) continue;
95
- if (typeof value !== "string" || !value.startsWith("#")) continue;
96
- vuetifyColors[key] = value;
97
- }
80
+ const vuetifyColors = Object.fromEntries(getThemeHexColors(themeColors));
98
81
  if (themeColors.background2) vuetifyColors.surface = themeColors.background2;
99
82
  vuetifyColors.inverse = isDark ? "#FFFFFF" : "#000000";
100
83
  themes[name] = { dark: isDark, colors: vuetifyColors };
@@ -197,7 +180,7 @@ const module$1 = defineNuxtModule({
197
180
  const colorOptions = resolveFeatureOption(options.color, {
198
181
  enabled: theme.colors?.enabled !== false,
199
182
  apply: true,
200
- defaultColor: theme.colors?.defaultColor || "dark",
183
+ defaultColor: theme.colors?.defaultColor || DEFAULT_THEME,
201
184
  themes: {},
202
185
  iconFormat: "svg"
203
186
  });
@@ -222,7 +205,7 @@ const module$1 = defineNuxtModule({
222
205
  });
223
206
  await registerThemeIcon(nuxt, resolver, iconOptions, theme.colors);
224
207
  nuxt.options.runtimeConfig.public.venixTheme = {
225
- defaultTheme: theme.colors?.defaultColor || "dark",
208
+ defaultTheme: theme.colors?.defaultColor || DEFAULT_THEME,
226
209
  colorThemes: colorOptions.themes,
227
210
  applyColors: shouldApplyColors,
228
211
  localeCookie: translationOptions.cookieSync,
@@ -2,6 +2,7 @@ import { watch } from "vue";
2
2
  import { useRequestHeaders, useState, useRoute } from "#app";
3
3
  import { DEFAULT_LOCALE } from "../../shared/constants";
4
4
  import { normalizeLocale, extractFirstLocale } from "../../shared/utils/normalize";
5
+ import { extractLocales } from "../../shared/utils/load";
5
6
  import { hasCookieConsent } from "../../shared/utils/consent";
6
7
  export const useThemeLocale = (theme, localeCookie, options = {}) => {
7
8
  const { enabled = true, forcedLocale, defaultLocale } = options;
@@ -9,23 +10,15 @@ export const useThemeLocale = (theme, localeCookie, options = {}) => {
9
10
  const route = useRoute();
10
11
  const fallbackLocale = defaultLocale || DEFAULT_LOCALE;
11
12
  const detectLocale = () => {
12
- const getAvailableLocales = () => {
13
- const availableLocales = /* @__PURE__ */ new Set();
14
- Object.values(theme.colors.themes).forEach((themeConfig) => {
15
- if (themeConfig.translations) {
16
- Object.keys(themeConfig.translations).forEach((locale) => {
17
- availableLocales.add(normalizeLocale(locale));
18
- });
19
- }
20
- });
21
- return Array.from(availableLocales);
22
- };
13
+ const availableLocales = new Set(extractLocales(theme));
23
14
  const findLocaleInAvailable = (requestedLocale) => {
24
- const availableLocales = getAvailableLocales();
25
15
  const normalized = normalizeLocale(requestedLocale);
26
- if (availableLocales.includes(normalized)) return normalized;
16
+ if (availableLocales.has(normalized)) return normalized;
27
17
  const baseLocale = normalized.split("-")[0];
28
- return availableLocales.find((locale) => locale.split("-")[0] === baseLocale) || null;
18
+ for (const locale of availableLocales) {
19
+ if (locale.split("-")[0] === baseLocale) return locale;
20
+ }
21
+ return null;
29
22
  };
30
23
  const findBestLocale = (requestedLocale) => findLocaleInAvailable(requestedLocale) || fallbackLocale;
31
24
  if (forcedLocale) return findBestLocale(forcedLocale);
@@ -74,9 +67,10 @@ export const useThemeLocale = (theme, localeCookie, options = {}) => {
74
67
  return fallback || "";
75
68
  };
76
69
  const setLocale = (locale) => {
77
- currentLocale.value = normalizeLocale(locale);
70
+ const normalized = normalizeLocale(locale);
71
+ currentLocale.value = normalized;
78
72
  if (enabled && !forcedLocale && hasCookieConsent()) {
79
- localeCookie.value = normalizeLocale(locale);
73
+ localeCookie.value = normalized;
80
74
  }
81
75
  };
82
76
  return {
@@ -1,4 +1,4 @@
1
- import { computed, watch, onMounted, onUnmounted, getCurrentInstance } from "vue";
1
+ import { ref, computed, watch, onMounted, onUnmounted, getCurrentInstance } from "vue";
2
2
  import { useRuntimeConfig, useState } from "#app";
3
3
  import { DEFAULT_THEME, DEFAULT_LOCALE, COOKIE_PREFERENCES_UPDATED_EVENT, COOKIE_CONSENT_STORAGE_KEY, THEME_APPLIED_EVENT } from "../../shared/constants";
4
4
  import { useThemeCookies } from "./useThemeCookies.js";
@@ -36,6 +36,7 @@ export const useVenixTheme = () => {
36
36
  const colors = useThemeColors(theme, locale.translate, themeConfig?.iconFormat || "svg");
37
37
  const initialPreference = cookies.preferenceCookie.value || defaultTheme;
38
38
  const preference = useState("venix-theme-preference", () => initialPreference || "system");
39
+ const environmentVersion = ref(0);
39
40
  const getResolvedTheme = (pref) => {
40
41
  const prefersDark = typeof window !== "undefined" ? window.matchMedia("(prefers-color-scheme: dark)").matches : true;
41
42
  return resolveThemePreference(pref, theme.colors.themes, defaultTheme, prefersDark);
@@ -91,18 +92,14 @@ export const useVenixTheme = () => {
91
92
  cookies.disablePersistence();
92
93
  }
93
94
  };
94
- const grantPersistence = () => {
95
+ const setConsent = (granted) => {
95
96
  if (typeof localStorage === "undefined") return;
96
- localStorage.setItem(COOKIE_CONSENT_STORAGE_KEY, JSON.stringify({ functionality: true }));
97
- syncPersistence();
98
- window.dispatchEvent(new Event(COOKIE_PREFERENCES_UPDATED_EVENT));
99
- };
100
- const revokePersistence = () => {
101
- if (typeof localStorage === "undefined") return;
102
- localStorage.setItem(COOKIE_CONSENT_STORAGE_KEY, JSON.stringify({ functionality: false }));
97
+ localStorage.setItem(COOKIE_CONSENT_STORAGE_KEY, JSON.stringify({ functionality: granted }));
103
98
  syncPersistence();
104
99
  window.dispatchEvent(new Event(COOKIE_PREFERENCES_UPDATED_EVENT));
105
100
  };
101
+ const grantPersistence = () => setConsent(true);
102
+ const revokePersistence = () => setConsent(false);
106
103
  const instance = getCurrentInstance();
107
104
  const runOnClientMount = (fn) => {
108
105
  if (instance) {
@@ -116,18 +113,21 @@ export const useVenixTheme = () => {
116
113
  if (!shouldApplyColors) return;
117
114
  const mq = window.matchMedia("(prefers-color-scheme: dark)");
118
115
  const handleSystemThemeChange = () => {
116
+ environmentVersion.value++;
119
117
  if (preference.value === "system") applyWithTransition("system");
120
118
  };
121
119
  mq.addEventListener("change", handleSystemThemeChange);
122
- const checkSeasonalChange = () => {
120
+ let midnightTimeout;
121
+ const scheduleSeasonalCheck = () => {
123
122
  const now = /* @__PURE__ */ new Date();
124
123
  const msToMidnight = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1).getTime() - now.getTime();
125
- return setTimeout(() => {
124
+ midnightTimeout = setTimeout(() => {
125
+ environmentVersion.value++;
126
126
  if (preference.value === "system") applyWithTransition("system");
127
- checkSeasonalChange();
127
+ scheduleSeasonalCheck();
128
128
  }, msToMidnight + 1e3);
129
129
  };
130
- const midnightTimeout = checkSeasonalChange();
130
+ scheduleSeasonalCheck();
131
131
  window.addEventListener(COOKIE_PREFERENCES_UPDATED_EVENT, syncPersistence);
132
132
  if (instance) {
133
133
  onUnmounted(() => {
@@ -150,17 +150,19 @@ export const useVenixTheme = () => {
150
150
  const data = computed(
151
151
  () => colors.themes.value.find((t) => t.value === preference.value) ?? colors.themes.value[0]
152
152
  );
153
- const isSeasonalActive = computed(() => {
154
- if (preference.value !== "system") return false;
155
- return seasonal.getActiveSeasonalTheme() !== null;
153
+ const resolvedTheme = computed(() => {
154
+ void environmentVersion.value;
155
+ return getResolvedTheme(preference.value);
156
156
  });
157
157
  const activeSeasonalTheme = computed(() => {
158
+ void environmentVersion.value;
158
159
  if (preference.value !== "system") return null;
159
160
  return seasonal.getActiveSeasonalTheme();
160
161
  });
162
+ const isSeasonalActive = computed(() => activeSeasonalTheme.value !== null);
161
163
  return {
162
164
  theme: {
163
- value: computed(() => getResolvedTheme(preference.value)),
165
+ value: resolvedTheme,
164
166
  preference,
165
167
  data,
166
168
  toggle,
@@ -1,6 +1,8 @@
1
1
  import { defineNuxtPlugin, useRuntimeConfig, useCookie } from "#app";
2
2
  import { THEME_PREFERENCE_COOKIE, THEME_RESOLVED_COOKIE, THEME_APPLIED_EVENT, DEFAULT_THEME } from "../../shared/constants";
3
3
  import { buildResolvedTheme } from "../../shared/utils/theme-config";
4
+ const VUETIFY_THEME_STYLESHEET_ID = "vuetify-theme-stylesheet";
5
+ const EARLY_THEME_STYLESHEET_ID = "venix-vuetify-theme-early";
4
6
  function applyVuetifyTheme(vuetify, name) {
5
7
  if (typeof vuetify.theme.change === "function") {
6
8
  vuetify.theme.change(name);
@@ -8,6 +10,21 @@ function applyVuetifyTheme(vuetify, name) {
8
10
  vuetify.theme.global.name.value = name;
9
11
  }
10
12
  }
13
+ function writeEarlyThemeStylesheet(nuxtApp, vuetify) {
14
+ const css = vuetify.theme.styles.value;
15
+ if (!css || document.getElementById(VUETIFY_THEME_STYLESHEET_ID)) return;
16
+ const headHooks = nuxtApp.vueApp._context.provides.usehead?.hooks;
17
+ if (!headHooks) return;
18
+ const style = document.createElement("style");
19
+ style.id = EARLY_THEME_STYLESHEET_ID;
20
+ style.textContent = css;
21
+ document.head.appendChild(style);
22
+ const unhook = headHooks.hook("dom:rendered", () => {
23
+ if (!document.getElementById(VUETIFY_THEME_STYLESHEET_ID)) return;
24
+ style.remove();
25
+ unhook();
26
+ });
27
+ }
11
28
  export default defineNuxtPlugin({
12
29
  name: "venix-theme-vuetify-sync",
13
30
  enforce: "pre",
@@ -18,8 +35,8 @@ export default defineNuxtPlugin({
18
35
  const preferenceCookie = useCookie(THEME_PREFERENCE_COOKIE);
19
36
  const theme = buildResolvedTheme(themeConfig);
20
37
  const defaultTheme = theme.colors.defaultColor || DEFAULT_THEME;
21
- const hookBeforeCreate = nuxtApp.hook;
22
- hookBeforeCreate("vuetify:before-create", ({ vuetifyOptions }) => {
38
+ const hookVuetify = nuxtApp.hook;
39
+ hookVuetify("vuetify:before-create", ({ vuetifyOptions }) => {
23
40
  const themes = vuetifyOptions?.theme?.themes;
24
41
  if (!vuetifyOptions?.theme || !themes) return;
25
42
  let resolved = defaultTheme;
@@ -31,8 +48,8 @@ export default defineNuxtPlugin({
31
48
  vuetifyOptions.theme.defaultTheme = resolved;
32
49
  });
33
50
  if (import.meta.client) {
34
- const hookReady = nuxtApp.hook;
35
- hookReady("vuetify:ready", (vuetify) => {
51
+ hookVuetify("vuetify:ready", (vuetify) => {
52
+ if (!nuxtApp.payload.serverRendered) writeEarlyThemeStylesheet(nuxtApp, vuetify);
36
53
  window.addEventListener(THEME_APPLIED_EVENT, ((event) => {
37
54
  applyVuetifyTheme(vuetify, event.detail);
38
55
  }));
@@ -27,17 +27,43 @@ export default function initTheme(themeData) {
27
27
  if (!themeConfig) return false;
28
28
  return !!themeConfig.primary || !!themeConfig.background;
29
29
  }
30
+ function getEasterSunday(year) {
31
+ const a = year % 19;
32
+ const b = Math.floor(year / 100);
33
+ const c = year % 100;
34
+ const d = Math.floor(b / 4);
35
+ const e = b % 4;
36
+ const f = Math.floor((b + 8) / 25);
37
+ const g = Math.floor((b - f + 1) / 3);
38
+ const h = (19 * a + b - d - g + 15) % 30;
39
+ const i = Math.floor(c / 4);
40
+ const k = c % 4;
41
+ const l = (32 + 2 * e + 2 * i - h - k) % 7;
42
+ const m = Math.floor((a + 11 * h + 22 * l) / 451);
43
+ const month = Math.floor((h + l - 7 * m + 114) / 31);
44
+ const day = (h + l - 7 * m + 114) % 31 + 1;
45
+ return new Date(year, month - 1, day);
46
+ }
47
+ function parseDatePart(value, year) {
48
+ const easter = /^easter([+-]\d+)?$/.exec(value.trim());
49
+ if (easter) {
50
+ const date = getEasterSunday(year);
51
+ date.setDate(date.getDate() + Number(easter[1] ?? 0));
52
+ return (date.getMonth() + 1) * 100 + date.getDate();
53
+ }
54
+ const parts = value.split("-").map(Number);
55
+ if (parts.length !== 2) return null;
56
+ const [month, day] = parts;
57
+ if (month === void 0 || day === void 0) return null;
58
+ return month * 100 + day;
59
+ }
30
60
  function isDateInSeasonalRange(themeConfig, now) {
31
61
  if (themeConfig.seasonal !== true || !themeConfig.dateRange) return false;
32
- const startParts = themeConfig.dateRange.start.split("-").map(Number);
33
- const endParts = themeConfig.dateRange.end.split("-").map(Number);
34
- if (startParts.length !== 2 || endParts.length !== 2) return false;
35
- const [startMonth, startDay] = startParts;
36
- const [endMonth, endDay] = endParts;
37
- if (startMonth === void 0 || startDay === void 0 || endMonth === void 0 || endDay === void 0) return false;
62
+ const year = now.getFullYear();
63
+ const startNum = parseDatePart(themeConfig.dateRange.start, year);
64
+ const endNum = parseDatePart(themeConfig.dateRange.end, year);
65
+ if (startNum === null || endNum === null) return false;
38
66
  const current = (now.getMonth() + 1) * 100 + now.getDate();
39
- const startNum = startMonth * 100 + startDay;
40
- const endNum = endMonth * 100 + endDay;
41
67
  return startNum <= endNum ? current >= startNum && current <= endNum : current >= startNum || current <= endNum;
42
68
  }
43
69
  function getActiveSeasonalTheme(themes2, prefersDark) {
@@ -1,6 +1,6 @@
1
- import { NON_COLOR_PROPERTIES } from "../constants.js";
1
+ import { getThemeHexColors } from "../utils/theme-resolve.js";
2
2
  export function generateThemeVars(mode, colors) {
3
- const colorVars = Object.entries(colors).filter(([key]) => !NON_COLOR_PROPERTIES.includes(key)).filter(([, value]) => typeof value === "string" && value.startsWith("#")).map(([key, value]) => ` --color-${key}: ${value};`).join("\n");
3
+ const colorVars = getThemeHexColors(colors).map(([key, value]) => ` --color-${key}: ${value};`).join("\n");
4
4
  const isDark = colors.dark === true;
5
5
  const colorScheme = isDark ? "dark" : "light";
6
6
  const inverseColor = isDark ? "#FFFFFF" : "#000000";
@@ -3,6 +3,7 @@ import { generateThemeVars } from "./colors.js";
3
3
  import { generateCustomScrollbarCSS } from "./scrollbar.js";
4
4
  import { generateCustomCursorCSS } from "./cursor.js";
5
5
  import { generateThemeTransitionCSS } from "./transition.js";
6
+ import { isColorTheme } from "../utils/theme-resolve.js";
6
7
  export function processTheme(theme, options = {}) {
7
8
  const output = [];
8
9
  if (options.typography !== false && theme.typography?.enabled !== false) {
@@ -12,11 +13,10 @@ export function processTheme(theme, options = {}) {
12
13
  if (options.colors !== false && theme.colors?.enabled !== false) {
13
14
  if (theme.colors?.themes) {
14
15
  output.push(generateThemeTransitionCSS());
15
- Object.entries(theme.colors.themes).forEach(([themeName, themeColors]) => {
16
- if (themeName === "system") return;
17
- if (!themeColors.primary && !themeColors.background) return;
16
+ for (const [themeName, themeColors] of Object.entries(theme.colors.themes)) {
17
+ if (themeName === "system" || !isColorTheme(themeColors)) continue;
18
18
  output.push(generateThemeVars(themeName, themeColors));
19
- });
19
+ }
20
20
  }
21
21
  }
22
22
  if (options.customScrollbar !== false && theme.customScrollbar?.enabled !== false) {
@@ -110,8 +110,8 @@
110
110
  "dark": true,
111
111
  "seasonal": true,
112
112
  "dateRange": {
113
- "start": "02-14",
114
- "end": "03-05"
113
+ "start": "easter-65",
114
+ "end": "easter-46"
115
115
  },
116
116
  "primary": "#FF1493",
117
117
  "secondary": "#FFD000",
@@ -164,7 +164,7 @@
164
164
  "dark": true,
165
165
  "seasonal": true,
166
166
  "dateRange": {
167
- "start": "10-15",
167
+ "start": "10-01",
168
168
  "end": "10-31"
169
169
  },
170
170
  "primary": "#FF6F00",
@@ -12,6 +12,11 @@ export interface ThemeIconFormats {
12
12
  export interface ThemeColors {
13
13
  dark?: boolean;
14
14
  seasonal?: boolean;
15
+ /**
16
+ * Inclusive range, wrapping across year-end when `end` < `start`. Each bound
17
+ * is a fixed `MM-DD` date or a movable one relative to Easter Sunday
18
+ * (`easter`, `easter-47`, `easter+1`).
19
+ */
15
20
  dateRange?: {
16
21
  start: string;
17
22
  end: string;
@@ -1,4 +1,4 @@
1
- const ICONIFY_NAME = /^([\w-]+):([\w-]+)$/;
1
+ import { ICONIFY_NAME } from "./icon.js";
2
2
  function addRef(refs, value) {
3
3
  const match = value ? ICONIFY_NAME.exec(value.trim()) : null;
4
4
  if (!match) return;
@@ -1,4 +1,6 @@
1
1
  import type { ThemeIconFormats } from '../types/colors.js';
2
+ /** Iconify icon name: `collection:name` (e.g. `line-md:home`). */
3
+ export declare const ICONIFY_NAME: RegExp;
2
4
  export type IconKind = 'emoji' | 'icon' | 'svg';
3
5
  export interface ResolvedIcon {
4
6
  kind: IconKind;
@@ -1,9 +1,10 @@
1
+ export const ICONIFY_NAME = /^([\w-]+):([\w-]+)$/;
1
2
  export function resolveIcon(input, aliases = {}) {
2
3
  const value = (aliases[input] ?? input).trim();
3
4
  if (/^<svg[\s>]/i.test(value)) {
4
5
  return { kind: "svg", value };
5
6
  }
6
- if (/^[\w-]+:[\w-]+$/.test(value)) {
7
+ if (ICONIFY_NAME.test(value)) {
7
8
  return { kind: "icon", value };
8
9
  }
9
10
  return { kind: "emoji", value };
@@ -4,6 +4,7 @@ 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 { isColorTheme, getActiveSeasonalTheme, resolveThemePreference } from './theme-resolve.js';
7
+ export { isColorTheme, getActiveSeasonalTheme, getEasterSunday, resolveThemePreference } from './theme-resolve.js';
8
+ export { mergeColorThemes } from './merge-themes.js';
8
9
  export { buildResolvedTheme } from './theme-config.js';
9
10
  export type { VenixRuntimeThemeConfig } from './theme-config.js';
@@ -8,5 +8,6 @@ export { resolveFeatureOption } from "./options.js";
8
8
  export { resolveIcon, resolveThemeIcon } from "./icon.js";
9
9
  export { extractIconRefs } from "./icon-refs.js";
10
10
  export { hasCookieConsent } from "./consent.js";
11
- export { isColorTheme, getActiveSeasonalTheme, resolveThemePreference } from "./theme-resolve.js";
11
+ export { isColorTheme, getActiveSeasonalTheme, getEasterSunday, resolveThemePreference } from "./theme-resolve.js";
12
+ export { mergeColorThemes } from "./merge-themes.js";
12
13
  export { buildResolvedTheme } from "./theme-config.js";
@@ -6,13 +6,11 @@ export function loadTheme(_path) {
6
6
  }
7
7
  export function extractLocales(theme) {
8
8
  const locales = /* @__PURE__ */ new Set();
9
- Object.values(theme.colors?.themes || {}).forEach((themeConfig) => {
10
- if (themeConfig.translations) {
11
- Object.keys(themeConfig.translations).forEach((locale) => {
12
- locales.add(normalizeLocale(locale));
13
- });
9
+ for (const themeConfig of Object.values(theme.colors?.themes || {})) {
10
+ for (const locale of Object.keys(themeConfig.translations ?? {})) {
11
+ locales.add(normalizeLocale(locale));
14
12
  }
15
- });
13
+ }
16
14
  return Array.from(locales);
17
15
  }
18
16
  export function getDefaultLocale(theme) {
@@ -0,0 +1,11 @@
1
+ import type { ThemeColors } from '../types/index.js';
2
+ /**
3
+ * Layers the `color.themes` overrides from `nuxt.config` on top of the base
4
+ * themes, theme by theme: an override only replaces the keys it sets, so an
5
+ * existing theme keeps its `translations`, `icon`, `dark` flag and every
6
+ * color it doesn't touch. A theme that doesn't exist in the base is added as
7
+ * dark by default. Single implementation — used both at build time
8
+ * (`customizeTheme`, which feeds the generated CSS and Vuetify) and at
9
+ * runtime (`buildResolvedTheme`), so the two can't diverge.
10
+ */
11
+ export declare function mergeColorThemes(baseThemes: Record<string, ThemeColors>, overrides?: Record<string, Partial<ThemeColors>>): Record<string, ThemeColors>;
@@ -0,0 +1,10 @@
1
+ export function mergeColorThemes(baseThemes, overrides) {
2
+ const merged = { ...baseThemes };
3
+ for (const [themeName, customColors] of Object.entries(overrides ?? {})) {
4
+ merged[themeName] = {
5
+ ...baseThemes[themeName] ?? { dark: true },
6
+ ...customColors
7
+ };
8
+ }
9
+ return merged;
10
+ }
@@ -9,8 +9,9 @@ export declare function normalizeLocale(locale: string): string;
9
9
  */
10
10
  export declare function extractFirstLocale(acceptLanguage: string): string | null;
11
11
  /**
12
- * Normalizes a hex color.
13
- * E.g.: "fff" -> "#FFF", "ffffff" -> "#FFFFFF", "#fff" -> "#FFF"
12
+ * Normalizes a hex color: trims it and adds the leading `#` when missing
13
+ * (case is preserved).
14
+ * E.g.: "fff" -> "#fff", " #FFFFFF " -> "#FFFFFF"
14
15
  */
15
16
  export declare function normalizeColor(color: string): string;
16
17
  /**
@@ -1,5 +1,6 @@
1
1
  import themeData from "../theme.json" with { type: "json" };
2
2
  import { DEFAULT_THEME } from "../constants.js";
3
+ import { mergeColorThemes } from "./merge-themes.js";
3
4
  export function buildResolvedTheme(runtimeThemeConfig) {
4
5
  const defaultColors = {
5
6
  enabled: true,
@@ -13,10 +14,11 @@ export function buildResolvedTheme(runtimeThemeConfig) {
13
14
  colors: {
14
15
  ...baseColors,
15
16
  defaultColor: runtimeThemeConfig?.defaultTheme || baseColors.defaultColor || DEFAULT_THEME,
16
- themes: {
17
- ...baseColors.themes,
18
- ...runtimeThemeConfig?.colorThemes || {}
19
- }
17
+ // `colorThemes` holds the raw overrides from `nuxt.config` (only the
18
+ // keys the user set), so they have to be merged theme by theme — a
19
+ // shallow spread would replace e.g. the whole built-in `dark` theme,
20
+ // dropping its `translations`, `icon` and untouched colors.
21
+ themes: mergeColorThemes(baseColors.themes, runtimeThemeConfig?.colorThemes)
20
22
  }
21
23
  };
22
24
  }
@@ -6,6 +6,14 @@ import type { ThemeColors } from '../types/index.js';
6
6
  * color, and don't count.
7
7
  */
8
8
  export declare function isColorTheme(themeConfig: ThemeColors | undefined): boolean;
9
+ /**
10
+ * The theme's actual color entries (hex values only) — skips metadata like
11
+ * `dark`/`translations`/`icon`. Shared by the CSS generator and the Vuetify
12
+ * theme registration, so both always agree on what counts as a color.
13
+ */
14
+ export declare function getThemeHexColors(themeConfig: ThemeColors): Array<[string, string]>;
15
+ /** Easter Sunday (Gregorian calendar) — anonymous Gregorian algorithm (Meeus/Jones/Butcher). */
16
+ export declare function getEasterSunday(year: number): Date;
9
17
  /**
10
18
  * Active seasonal theme for today. When `prefersDark` is given, only returns
11
19
  * themes matching that mode (light/dark); when omitted, returns the first
@@ -1,22 +1,54 @@
1
+ import { NON_COLOR_PROPERTIES } from "../constants.js";
1
2
  export function isColorTheme(themeConfig) {
2
3
  if (!themeConfig) return false;
3
4
  return !!themeConfig.primary || !!themeConfig.background;
4
5
  }
5
- function parseDatePart(value) {
6
+ export function getThemeHexColors(themeConfig) {
7
+ const result = [];
8
+ for (const [key, value] of Object.entries(themeConfig)) {
9
+ if (NON_COLOR_PROPERTIES.includes(key)) continue;
10
+ if (typeof value === "string" && value.startsWith("#")) result.push([key, value]);
11
+ }
12
+ return result;
13
+ }
14
+ const EASTER_RELATIVE = /^easter([+-]\d+)?$/;
15
+ export function getEasterSunday(year) {
16
+ const a = year % 19;
17
+ const b = Math.floor(year / 100);
18
+ const c = year % 100;
19
+ const d = Math.floor(b / 4);
20
+ const e = b % 4;
21
+ const f = Math.floor((b + 8) / 25);
22
+ const g = Math.floor((b - f + 1) / 3);
23
+ const h = (19 * a + b - d - g + 15) % 30;
24
+ const i = Math.floor(c / 4);
25
+ const k = c % 4;
26
+ const l = (32 + 2 * e + 2 * i - h - k) % 7;
27
+ const m = Math.floor((a + 11 * h + 22 * l) / 451);
28
+ const month = Math.floor((h + l - 7 * m + 114) / 31);
29
+ const day = (h + l - 7 * m + 114) % 31 + 1;
30
+ return new Date(year, month - 1, day);
31
+ }
32
+ function parseDatePart(value, year) {
33
+ const easter = EASTER_RELATIVE.exec(value.trim());
34
+ if (easter) {
35
+ const date = getEasterSunday(year);
36
+ date.setDate(date.getDate() + Number(easter[1] ?? 0));
37
+ return (date.getMonth() + 1) * 100 + date.getDate();
38
+ }
6
39
  const parts = value.split("-").map(Number);
7
40
  if (parts.length !== 2) return null;
8
41
  const [month, day] = parts;
9
42
  if (month === void 0 || day === void 0) return null;
10
- return [month, day];
43
+ return month * 100 + day;
11
44
  }
12
45
  function isDateInSeasonalRange(themeConfig, now) {
13
46
  if (themeConfig.seasonal !== true || !themeConfig.dateRange) return false;
14
- const start = parseDatePart(themeConfig.dateRange.start);
15
- const end = parseDatePart(themeConfig.dateRange.end);
16
- if (!start || !end) return false;
47
+ const year = now.getFullYear();
48
+ const startNum = parseDatePart(themeConfig.dateRange.start, year);
49
+ const endNum = parseDatePart(themeConfig.dateRange.end, year);
50
+ if (startNum === null || endNum === null) return false;
17
51
  const current = (now.getMonth() + 1) * 100 + now.getDate();
18
- const startNum = start[0] * 100 + start[1];
19
- const endNum = end[0] * 100 + end[1];
20
52
  return startNum <= endNum ? current >= startNum && current <= endNum : current >= startNum || current <= endNum;
21
53
  }
22
54
  export function getActiveSeasonalTheme(themes, prefersDark, now = /* @__PURE__ */ new Date()) {