@venix-sistemas/jade 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/README.md +339 -222
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +25 -11
  4. package/dist/runtime/components/VenixThemeSwitcher.d.vue.ts +1 -1
  5. package/dist/runtime/components/VenixThemeSwitcher.vue +242 -99
  6. package/dist/runtime/components/VenixThemeSwitcher.vue.d.ts +1 -1
  7. package/dist/runtime/composables/useThemeColors.d.ts +6 -0
  8. package/dist/runtime/composables/useThemeColors.js +24 -9
  9. package/dist/runtime/composables/useThemeCookies.d.ts +9 -2
  10. package/dist/runtime/composables/useThemeCookies.js +24 -6
  11. package/dist/runtime/composables/useThemeLocale.d.ts +5 -0
  12. package/dist/runtime/composables/useThemeLocale.js +2 -2
  13. package/dist/runtime/composables/useThemeSeasonal.d.ts +2 -2
  14. package/dist/runtime/composables/useThemeSeasonal.js +1 -1
  15. package/dist/runtime/composables/useVenixTheme.d.ts +20 -0
  16. package/dist/runtime/composables/useVenixTheme.js +168 -108
  17. package/dist/runtime/nitro/theme-init.js +8 -5
  18. package/dist/runtime/plugins/theme-init.server.js +7 -12
  19. package/dist/runtime/plugins/vuetify-theme.js +8 -11
  20. package/dist/runtime/scripts/theme-init.d.ts +23 -10
  21. package/dist/runtime/scripts/theme-init.js +42 -88
  22. package/dist/shared/constants.d.ts +18 -3
  23. package/dist/shared/constants.js +6 -1
  24. package/dist/shared/css/cursor.js +9 -2
  25. package/dist/shared/css/index.d.ts +1 -7
  26. package/dist/shared/css/index.js +5 -5
  27. package/dist/shared/css/transition.d.ts +1 -1
  28. package/dist/shared/theme.json +302 -192
  29. package/dist/shared/types/color-options.d.ts +26 -2
  30. package/dist/shared/types/colors.d.ts +64 -12
  31. package/dist/shared/types/index.d.ts +1 -1
  32. package/dist/shared/types/runtime-config.d.ts +4 -2
  33. package/dist/shared/utils/icon-refs.d.ts +7 -3
  34. package/dist/shared/utils/icon.d.ts +4 -2
  35. package/dist/shared/utils/icon.js +6 -2
  36. package/dist/shared/utils/index.d.ts +5 -4
  37. package/dist/shared/utils/index.js +12 -6
  38. package/dist/shared/utils/inline-script.d.ts +6 -0
  39. package/dist/shared/utils/inline-script.js +3 -0
  40. package/dist/shared/utils/load.d.ts +0 -1
  41. package/dist/shared/utils/load.js +5 -12
  42. package/dist/shared/utils/merge-themes.d.ts +39 -9
  43. package/dist/shared/utils/merge-themes.js +101 -5
  44. package/dist/shared/utils/normalize.d.ts +0 -11
  45. package/dist/shared/utils/normalize.js +0 -12
  46. package/dist/shared/utils/theme-config.d.ts +13 -4
  47. package/dist/shared/utils/theme-config.js +28 -15
  48. package/dist/shared/utils/theme-resolve.d.ts +15 -23
  49. package/dist/shared/utils/theme-resolve.js +18 -67
  50. package/dist/shared/utils/theme-resolver.d.ts +46 -0
  51. package/dist/shared/utils/theme-resolver.js +139 -0
  52. package/package.json +13 -10
  53. package/README-default.md +0 -84
  54. package/dist/runtime/plugin.d.ts +0 -2
  55. package/dist/runtime/plugin.js +0 -3
@@ -1,14 +1,16 @@
1
- import type { ThemeColors } from './colors.js';
1
+ import type { ThemeEntry } from './colors.js';
2
2
  declare module '@nuxt/schema' {
3
3
  interface PublicRuntimeConfig {
4
4
  venixTheme?: {
5
5
  defaultTheme: string;
6
- colorThemes: Record<string, Partial<ThemeColors>>;
6
+ colorThemes: Record<string, Partial<ThemeEntry>>;
7
7
  applyColors: boolean;
8
8
  localeCookie: string;
9
9
  defaultLocale: string;
10
10
  locale: string;
11
11
  iconFormat: 'emote' | 'css' | 'svg';
12
+ requireConsent: boolean;
13
+ seasonal: boolean;
12
14
  icon: {
13
15
  aliases: Record<string, string>;
14
16
  };
@@ -1,10 +1,14 @@
1
- import type { ThemeColors } from '../types/colors.js';
1
+ import type { ThemeIconFormats } from '../types/colors.js';
2
2
  /**
3
3
  * Extracts the Iconify `collection:icon` references used in color themes
4
- * (`icon.css` / `icon.svg`) and in the configured icon aliases, grouped by
4
+ * and modes (`icon.css` / `icon.svg`) and in the configured icon aliases, grouped by
5
5
  * collection. Lets each collection be bundled with only the icons actually
6
6
  * used (tree-shaking) instead of the whole collection — essential for large
7
7
  * collections like `mdi` (thousands of icons) used for only a handful of
8
8
  * icons in the default theme.
9
9
  */
10
- export declare function extractIconRefs(themes: Record<string, ThemeColors>, aliases: Record<string, string>): Map<string, Set<string>>;
10
+ export declare function extractIconRefs(themes: Record<string, {
11
+ icon?: string | ThemeIconFormats;
12
+ }> | Array<{
13
+ icon?: string | ThemeIconFormats;
14
+ }>, aliases: Record<string, string>): Map<string, Set<string>>;
@@ -23,7 +23,9 @@ export interface ResolvedThemeIcon {
23
23
  }
24
24
  /**
25
25
  * Resolves a color theme's icon (a legacy string, always emote, or a
26
- * `ThemeIconFormats` with variants) to the preferred format, falling back to
27
- * `emote` when the theme doesn't define the chosen format.
26
+ * `ThemeIconFormats` with variants) to the preferred format. When the theme
27
+ * doesn't define it, tries the other Iconify variant before `emote`
28
+ * (`svg` → `css` → `emote`, or `css` → `svg` → `emote`), so a theme with only
29
+ * one Iconify variant still shows an icon instead of dropping to the emoji.
28
30
  */
29
31
  export declare function resolveThemeIcon(icon: string | ThemeIconFormats | undefined, preferred: ThemeIconFormat): ResolvedThemeIcon | null;
@@ -14,8 +14,12 @@ export function resolveThemeIcon(icon, preferred) {
14
14
  if (typeof icon === "string") {
15
15
  return { format: "emote", value: icon };
16
16
  }
17
- if (preferred !== "emote" && icon[preferred]) {
18
- return { format: preferred, value: icon[preferred] };
17
+ if (preferred !== "emote") {
18
+ const order = preferred === "svg" ? ["svg", "css"] : ["css", "svg"];
19
+ for (const format of order) {
20
+ const value = icon[format];
21
+ if (value) return { format, value };
22
+ }
19
23
  }
20
24
  return { format: "emote", value: icon.emote };
21
25
  }
@@ -1,10 +1,11 @@
1
- export { normalizeLocale, extractFirstLocale, normalizeColor, normalizeThemeName, } from './normalize.js';
1
+ export { normalizeLocale, extractFirstLocale, } from './normalize.js';
2
2
  export { resolveFeatureOption } from './options.js';
3
3
  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, getEasterSunday, resolveThemePreference } from './theme-resolve.js';
8
- export { mergeColorThemes } from './merge-themes.js';
9
- export { buildResolvedTheme } from './theme-config.js';
7
+ export { isColorTheme, getActiveSeasonalTheme, getEasterSunday, getDefaultSelection, normalizeThemeSelection, resolveThemeSelection, resolveThemePreference, } from './theme-resolve.js';
8
+ 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
11
  export type { VenixRuntimeThemeConfig } from './theme-config.js';
@@ -1,13 +1,19 @@
1
1
  export {
2
2
  normalizeLocale,
3
- extractFirstLocale,
4
- normalizeColor,
5
- normalizeThemeName
3
+ extractFirstLocale
6
4
  } from "./normalize.js";
7
5
  export { resolveFeatureOption } from "./options.js";
8
6
  export { resolveIcon, resolveThemeIcon } from "./icon.js";
9
7
  export { extractIconRefs } from "./icon-refs.js";
10
8
  export { hasCookieConsent } from "./consent.js";
11
- export { isColorTheme, getActiveSeasonalTheme, getEasterSunday, resolveThemePreference } from "./theme-resolve.js";
12
- export { mergeColorThemes } from "./merge-themes.js";
13
- export { buildResolvedTheme } from "./theme-config.js";
9
+ export {
10
+ isColorTheme,
11
+ getActiveSeasonalTheme,
12
+ getEasterSunday,
13
+ getDefaultSelection,
14
+ normalizeThemeSelection,
15
+ resolveThemeSelection,
16
+ resolveThemePreference
17
+ } from "./theme-resolve.js";
18
+ export { mergeColorThemes, normalizeColorThemes, findDeprecatedThemeEntries } from "./merge-themes.js";
19
+ export { buildResolvedTheme, getBaseThemeEntries } from "./theme-config.js";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * JSON is valid JS, but inside an inline `<script>` a `</script>` anywhere in
3
+ * the data (e.g. in a theme translation) would end the element early and
4
+ * break the page. `<` is the same character to the JS parser.
5
+ */
6
+ export declare function toInlineScriptJson(value: unknown): string;
@@ -0,0 +1,3 @@
1
+ export function toInlineScriptJson(value) {
2
+ return JSON.stringify(value).replace(/</g, "\\u003c");
3
+ }
@@ -1,4 +1,3 @@
1
1
  import type { ThemeConfig } from '../types/index.js';
2
2
  export declare function loadTheme(_path?: string): ThemeConfig;
3
3
  export declare function extractLocales(theme: ThemeConfig): string[];
4
- export declare function getDefaultLocale(theme: ThemeConfig): string;
@@ -1,22 +1,15 @@
1
- import defaultTheme from "../../shared/theme.json" with { type: "json" };
2
- import { DEFAULT_LOCALE } from "../constants.js";
3
1
  import { normalizeLocale } from "./normalize.js";
2
+ import { buildResolvedTheme } from "./theme-config.js";
4
3
  export function loadTheme(_path) {
5
- return defaultTheme;
4
+ return buildResolvedTheme();
6
5
  }
7
6
  export function extractLocales(theme) {
8
7
  const locales = /* @__PURE__ */ new Set();
9
- for (const themeConfig of Object.values(theme.colors?.themes || {})) {
10
- for (const locale of Object.keys(themeConfig.translations ?? {})) {
8
+ const labelled = [...Object.values(theme.colors?.groups || {}), ...Object.values(theme.colors?.modes || {})];
9
+ for (const entry of labelled) {
10
+ for (const locale of Object.keys(entry.translations ?? {})) {
11
11
  locales.add(normalizeLocale(locale));
12
12
  }
13
13
  }
14
14
  return Array.from(locales);
15
15
  }
16
- export function getDefaultLocale(theme) {
17
- const locales = extractLocales(theme);
18
- if (locales.includes("en-US")) return "en-US";
19
- const firstLocale = locales[0];
20
- if (firstLocale) return firstLocale;
21
- return DEFAULT_LOCALE;
22
- }
@@ -1,11 +1,41 @@
1
- import type { ThemeColors } from '../types/index.js';
1
+ import type { ThemeColors, ThemeDefinition, ThemeEntry, ResolvedThemeGroup } from '../types/index.js';
2
+ /** Grouped format: at least one `light`/`dark` variant object. */
3
+ export declare function isThemeDefinition(entry: Partial<ThemeEntry> | undefined): entry is ThemeDefinition;
4
+ /**
5
+ * Deprecated flat format: a boolean `dark` flag and/or colors at the top
6
+ * level. An entry with only metadata (`translations`, `icon`…) is neither —
7
+ * it's valid in both formats.
8
+ */
9
+ export declare function isLegacyThemeEntry(entry: Partial<ThemeEntry> | undefined): entry is ThemeColors;
2
10
  /**
3
11
  * 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>;
12
+ * entries (`theme.json`), still in config format:
13
+ *
14
+ * - an existing theme only gets the keys the override sets — metadata at the
15
+ * theme level, colors variant by variant;
16
+ * - a deprecated flat override named after a variant id (`dark: { primary }`)
17
+ * is merged into that variant (`venix.dark`);
18
+ * - anything else is added as a new theme (a flat one is dark unless it sets
19
+ * `dark: false`, as before).
20
+ *
21
+ * Single implementation — used both at build time (`customizeTheme`, which
22
+ * feeds the generated CSS and Vuetify) and at runtime (`buildResolvedTheme`),
23
+ * so the two can't diverge.
24
+ */
25
+ export declare function mergeColorThemes(baseThemes: Record<string, ThemeEntry>, overrides?: Record<string, Partial<ThemeEntry>>): Record<string, ThemeEntry>;
26
+ /**
27
+ * Turns config entries (both formats) into what the runtime works with:
28
+ * `themes`, every concrete variant by id (feeds `data-theme`, the CSS and
29
+ * Vuetify), and `groups`, the selectable themes pointing at their variants.
30
+ * A deprecated flat entry becomes a single-variant theme whose id is its own
31
+ * name, so its `data-theme` value doesn't change.
32
+ */
33
+ export declare function normalizeColorThemes(entries: Record<string, ThemeEntry>): {
34
+ themes: Record<string, ThemeColors>;
35
+ groups: Record<string, ResolvedThemeGroup>;
36
+ };
37
+ /**
38
+ * Overrides still written in the deprecated flat format, with the message to
39
+ * show for each — logged once at build time by `module.ts`.
40
+ */
41
+ export declare function findDeprecatedThemeEntries(baseThemes: Record<string, ThemeEntry>, overrides?: Record<string, Partial<ThemeEntry>>): string[];
@@ -1,10 +1,106 @@
1
+ import { COLOR_PROPERTIES, THEME_MODES } from "../constants.js";
2
+ const META_PROPERTIES = ["seasonal", "dateRange", "translations", "icon"];
3
+ export function isThemeDefinition(entry) {
4
+ if (!entry) return false;
5
+ return THEME_MODES.some((mode) => typeof entry[mode] === "object");
6
+ }
7
+ export function isLegacyThemeEntry(entry) {
8
+ if (!entry || isThemeDefinition(entry)) return false;
9
+ return typeof entry.dark === "boolean" || COLOR_PROPERTIES.some((key) => entry[key] !== void 0);
10
+ }
11
+ function pickMeta(entry) {
12
+ const meta = {};
13
+ for (const key of META_PROPERTIES) {
14
+ if (entry[key] !== void 0) meta[key] = entry[key];
15
+ }
16
+ return meta;
17
+ }
18
+ function pickPalette(entry) {
19
+ const palette = {};
20
+ for (const key of COLOR_PROPERTIES) {
21
+ const value = entry[key];
22
+ if (value !== void 0) palette[key] = value;
23
+ }
24
+ return palette;
25
+ }
26
+ const variantId = (themeName, mode, variant) => variant.id || `${themeName}-${mode}`;
27
+ function findVariantOwner(entries, id) {
28
+ for (const [themeName, entry] of Object.entries(entries)) {
29
+ if (!isThemeDefinition(entry)) continue;
30
+ for (const mode of THEME_MODES) {
31
+ const variant = entry[mode];
32
+ if (variant && variantId(themeName, mode, variant) === id) return { theme: themeName, mode };
33
+ }
34
+ }
35
+ return null;
36
+ }
37
+ function legacyOverrideMode(group, themeName, override) {
38
+ const byId = THEME_MODES.find((mode) => group[mode] && variantId(themeName, mode, group[mode]) === themeName);
39
+ return byId ?? (override.dark === false ? "light" : "dark");
40
+ }
1
41
  export function mergeColorThemes(baseThemes, overrides) {
2
42
  const merged = { ...baseThemes };
3
- for (const [themeName, customColors] of Object.entries(overrides ?? {})) {
4
- merged[themeName] = {
5
- ...baseThemes[themeName] ?? { dark: true },
6
- ...customColors
7
- };
43
+ for (const [themeName, override] of Object.entries(overrides ?? {})) {
44
+ const existing = merged[themeName];
45
+ if (existing && isThemeDefinition(existing)) {
46
+ const next = { ...existing, ...pickMeta(override) };
47
+ if (isThemeDefinition(override)) {
48
+ for (const mode of THEME_MODES) {
49
+ if (override[mode]) next[mode] = { ...existing[mode], ...override[mode] };
50
+ }
51
+ } else if (isLegacyThemeEntry(override)) {
52
+ const mode = legacyOverrideMode(existing, themeName, override);
53
+ next[mode] = { ...existing[mode], ...pickPalette(override) };
54
+ }
55
+ merged[themeName] = next;
56
+ continue;
57
+ }
58
+ if (existing) {
59
+ merged[themeName] = { ...existing, ...override };
60
+ continue;
61
+ }
62
+ const owner = isLegacyThemeEntry(override) ? findVariantOwner(merged, themeName) : null;
63
+ if (owner) {
64
+ const group = merged[owner.theme];
65
+ merged[owner.theme] = {
66
+ ...group,
67
+ [owner.mode]: { ...group[owner.mode], ...pickPalette(override) }
68
+ };
69
+ continue;
70
+ }
71
+ merged[themeName] = isThemeDefinition(override) ? override : { dark: true, ...override };
8
72
  }
9
73
  return merged;
10
74
  }
75
+ export function normalizeColorThemes(entries) {
76
+ const themes = {};
77
+ const groups = {};
78
+ for (const [themeName, entry] of Object.entries(entries)) {
79
+ const group = { ...pickMeta(entry), variants: {} };
80
+ if (isThemeDefinition(entry)) {
81
+ for (const mode of THEME_MODES) {
82
+ const variant = entry[mode];
83
+ if (!variant) continue;
84
+ const id = variantId(themeName, mode, variant);
85
+ themes[id] = { dark: mode === "dark", ...pickPalette(variant) };
86
+ group.variants[mode] = id;
87
+ }
88
+ } else if (isLegacyThemeEntry(entry)) {
89
+ const mode = entry.dark === false ? "light" : "dark";
90
+ themes[themeName] = { dark: mode === "dark", ...pickPalette(entry) };
91
+ group.variants[mode] = themeName;
92
+ }
93
+ groups[themeName] = group;
94
+ }
95
+ return { themes, groups };
96
+ }
97
+ export function findDeprecatedThemeEntries(baseThemes, overrides) {
98
+ const messages = [];
99
+ for (const [themeName, override] of Object.entries(overrides ?? {})) {
100
+ if (!isLegacyThemeEntry(override)) continue;
101
+ const base = baseThemes[themeName];
102
+ const owner = base && isThemeDefinition(base) ? { theme: themeName, mode: legacyOverrideMode(base, themeName, override) } : base ? null : findVariantOwner(baseThemes, themeName);
103
+ messages.push(owner ? `\`color.themes.${themeName}\` overrides a theme variant in the deprecated flat format. Use \`${owner.theme}: { ${owner.mode}: { ... } }\` instead.` : `\`color.themes.${themeName}\` uses the deprecated flat format (\`dark: true/false\` plus colors). Use \`${themeName}: { light: { ... }, dark: { ... } }\` instead.`);
104
+ }
105
+ return messages;
106
+ }
@@ -8,14 +8,3 @@ export declare function normalizeLocale(locale: string): string;
8
8
  * E.g.: "pt-BR,pt;q=0.9,en;q=0.8" -> "pt-BR"
9
9
  */
10
10
  export declare function extractFirstLocale(acceptLanguage: string): string | null;
11
- /**
12
- * Normalizes a hex color: trims it and adds the leading `#` when missing
13
- * (case is preserved).
14
- * E.g.: "fff" -> "#fff", " #FFFFFF " -> "#FFFFFF"
15
- */
16
- export declare function normalizeColor(color: string): string;
17
- /**
18
- * Normalizes a theme name.
19
- * E.g.: "dark" -> "Dark", "DARK" -> "Dark"
20
- */
21
- export declare function normalizeThemeName(name: string): string;
@@ -24,15 +24,3 @@ export function extractFirstLocale(acceptLanguage) {
24
24
  const firstLocale = localeParts[0]?.trim();
25
25
  return firstLocale || null;
26
26
  }
27
- export function normalizeColor(color) {
28
- if (!color) return color;
29
- color = color.trim();
30
- if (!color.startsWith("#")) {
31
- color = `#${color}`;
32
- }
33
- return color;
34
- }
35
- export function normalizeThemeName(name) {
36
- if (!name) return name;
37
- return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
38
- }
@@ -1,14 +1,23 @@
1
- import type { ThemeConfig, ThemeColors } from '../types/index.js';
1
+ import type { ThemeConfig, ThemeEntry } from '../types/index.js';
2
2
  export interface VenixRuntimeThemeConfig {
3
3
  defaultTheme?: string;
4
- colorThemes?: Record<string, Partial<ThemeColors>>;
4
+ colorThemes?: Record<string, Partial<ThemeEntry>>;
5
+ /** `false` drops every seasonal theme (built-in and custom). Default: `true`. */
6
+ seasonal?: boolean;
5
7
  }
8
+ /** The theme entries bundled with the module, in config format. */
9
+ export declare function getBaseThemeEntries(): Record<string, ThemeEntry>;
6
10
  /**
7
11
  * Rebuilds the full `ThemeConfig` at runtime, layering `theme.json`
8
12
  * (bundled with the module, with the "base" themes) with the customizations
9
13
  * from `runtimeConfig.public.venixTheme` (resolved at build time from the
10
14
  * module options in `nuxt.config`, see `module.ts`). Single implementation —
11
- * used by the composable (`useVenixTheme`) and the SSR/Vuetify plugins, which
12
- * used to each reimplement this merge their own way.
15
+ * used by the composable (`useVenixTheme`), the SSR/Vuetify plugins and, at
16
+ * build time, `customizeTheme`.
17
+ *
18
+ * Memoized per config object: every `useVenixTheme()` call and plugin asks
19
+ * for it with the same `runtimeConfig.public.venixTheme`, and rebuilding it
20
+ * (merge + normalization of every theme) each time was wasted work. The
21
+ * result is shared, so callers must treat it as read-only.
13
22
  */
14
23
  export declare function buildResolvedTheme(runtimeThemeConfig?: VenixRuntimeThemeConfig): ThemeConfig;
@@ -1,24 +1,37 @@
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
+ import { mergeColorThemes, normalizeColorThemes } from "./merge-themes.js";
4
+ export function getBaseThemeEntries() {
5
+ return themeData.colors?.themes ?? {};
6
+ }
7
+ const resolvedThemeCache = /* @__PURE__ */ new WeakMap();
4
8
  export function buildResolvedTheme(runtimeThemeConfig) {
5
- const defaultColors = {
6
- enabled: true,
7
- defaults: true,
8
- defaultColor: DEFAULT_THEME,
9
- themes: {}
10
- };
11
- const baseColors = themeData.colors || defaultColors;
9
+ if (!runtimeThemeConfig) return resolveTheme();
10
+ let resolved = resolvedThemeCache.get(runtimeThemeConfig);
11
+ if (!resolved) {
12
+ resolved = resolveTheme(runtimeThemeConfig);
13
+ resolvedThemeCache.set(runtimeThemeConfig, resolved);
14
+ }
15
+ return resolved;
16
+ }
17
+ function resolveTheme(runtimeThemeConfig) {
18
+ const rawColors = themeData.colors ?? {};
19
+ const baseEntries = getBaseThemeEntries();
20
+ const merged = mergeColorThemes(baseEntries, runtimeThemeConfig?.colorThemes);
21
+ const entries = runtimeThemeConfig?.seasonal === false ? Object.fromEntries(Object.entries(merged).filter(([, entry]) => entry.seasonal !== true)) : merged;
22
+ const { themes, groups } = normalizeColorThemes(entries);
23
+ for (const [name, group] of Object.entries(groups)) {
24
+ if (!(name in baseEntries)) group.custom = true;
25
+ }
12
26
  return {
13
27
  ...themeData,
14
28
  colors: {
15
- ...baseColors,
16
- defaultColor: runtimeThemeConfig?.defaultTheme || baseColors.defaultColor || DEFAULT_THEME,
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)
29
+ enabled: rawColors.enabled ?? true,
30
+ defaults: rawColors.defaults ?? true,
31
+ defaultColor: runtimeThemeConfig?.defaultTheme || rawColors.defaultColor || DEFAULT_THEME,
32
+ modes: rawColors.modes ?? {},
33
+ themes,
34
+ groups
22
35
  }
23
36
  };
24
37
  }
@@ -1,32 +1,24 @@
1
1
  import type { ThemeColors } from '../types/index.js';
2
- /**
3
- * A theme only really counts as a "color" theme if it has at least one real
4
- * color — placeholder entries like `'system'` (only used to show
5
- * "Automatic" in the UI, see `theme.json`) have `translations`/`icon` but no
6
- * color, and don't count.
7
- */
8
- export declare function isColorTheme(themeConfig: ThemeColors | undefined): boolean;
2
+ import type { ColorModel } from './theme-resolver.js';
3
+ export type { ColorModel, ThemeSelection } from './theme-resolver.js';
4
+ export declare const isColorTheme: (themeConfig: ThemeColors | undefined) => boolean, getEasterSunday: (year: number) => Date, isModePreference: (value: unknown) => value is import("../types/index.js").ThemeModePreference, isSelectableGroup: (colors: ColorModel, name: string) => boolean, findVariantOwner: (colors: ColorModel, id: string) => {
5
+ theme: string;
6
+ mode: import("../types/index.js").ThemeMode;
7
+ } | null, getDefaultSelection: (colors: ColorModel) => import("./theme-resolver.js").ThemeSelection & {
8
+ fallbackTheme: string;
9
+ }, normalizeThemeSelection: (themePreference: string | null | undefined, modePreference: string | null | undefined, colors: ColorModel) => import("./theme-resolver.js").ThemeSelection, getActiveSeasonalTheme: (groups: Record<string, import("../types/index.js").ResolvedThemeGroup>, mode?: import("../types/index.js").ThemeMode, now?: Date) => string | null, resolveMode: (mode: import("../types/index.js").ThemeModePreference, prefersDark: boolean) => import("../types/index.js").ThemeMode, resolveThemeSelection: (selection: import("./theme-resolver.js").ThemeSelection, colors: ColorModel, prefersDark: boolean, now?: Date) => string, resolveThemePreference: (themePreference: string | null | undefined, modePreference: string | null | undefined, colors: ColorModel, prefersDark: boolean, now?: Date) => string;
9
10
  /**
10
11
  * The theme's actual color entries (hex values only) — skips metadata like
11
12
  * `dark`/`translations`/`icon`. Shared by the CSS generator and the Vuetify
12
13
  * theme registration, so both always agree on what counts as a color.
13
14
  */
14
15
  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;
17
- /**
18
- * Active seasonal theme for today. When `prefersDark` is given, only returns
19
- * themes matching that mode (light/dark); when omitted, returns the first
20
- * active seasonal theme regardless of mode.
21
- */
22
- export declare function getActiveSeasonalTheme(themes: Record<string, ThemeColors>, prefersDark?: boolean, now?: Date): string | null;
23
16
  /**
24
- * Resolves a theme preference (`'system'`, a theme name, or empty) to the
25
- * concrete color theme that should be applied. Single implementation of this
26
- * rule — used by `useVenixTheme`/`useThemeSeasonal` and the SSR plugin
27
- * (`theme-init.server.ts`). The pre-hydration script
28
- * (`runtime/scripts/theme-init.ts`) is the one documented exception: it has
29
- * to run as a self-contained IIFE (no imports), so it deliberately duplicates
30
- * this logic — keep the two in sync when changing either.
17
+ * Best guess at the theme to render where `matchMedia` doesn't exist (SSR):
18
+ * the resolved cookie (the variant last applied on the client) only hints
19
+ * whether the OS prefers dark, for mode `'system'`. It's never returned as
20
+ * is: with theme `'system'` that cookie can be from another season, or from
21
+ * before the OS switched modes, and trusting it kept that stale theme. The
22
+ * pre-hydration script then corrects the mode guess before the first paint.
31
23
  */
32
- export declare function resolveThemePreference(preference: string | undefined, themes: Record<string, ThemeColors>, defaultTheme: string, prefersDark: boolean): string;
24
+ export declare function resolveServerTheme(themePreference: string | null | undefined, modePreference: string | null | undefined, resolvedHint: string | null | undefined, colors: ColorModel, now?: Date): string;
@@ -1,8 +1,18 @@
1
1
  import { NON_COLOR_PROPERTIES } from "../constants.js";
2
- export function isColorTheme(themeConfig) {
3
- if (!themeConfig) return false;
4
- return !!themeConfig.primary || !!themeConfig.background;
5
- }
2
+ import { createThemeResolver } from "./theme-resolver.js";
3
+ export const {
4
+ isColorTheme,
5
+ getEasterSunday,
6
+ isModePreference,
7
+ isSelectableGroup,
8
+ findVariantOwner,
9
+ getDefaultSelection,
10
+ normalizeThemeSelection,
11
+ getActiveSeasonalTheme,
12
+ resolveMode,
13
+ resolveThemeSelection,
14
+ resolveThemePreference
15
+ } = createThemeResolver();
6
16
  export function getThemeHexColors(themeConfig) {
7
17
  const result = [];
8
18
  for (const [key, value] of Object.entries(themeConfig)) {
@@ -11,67 +21,8 @@ export function getThemeHexColors(themeConfig) {
11
21
  }
12
22
  return result;
13
23
  }
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
- }
39
- const parts = value.split("-").map(Number);
40
- if (parts.length !== 2) return null;
41
- const [month, day] = parts;
42
- if (month === void 0 || day === void 0) return null;
43
- return month * 100 + day;
44
- }
45
- function isDateInSeasonalRange(themeConfig, now) {
46
- if (themeConfig.seasonal !== true || !themeConfig.dateRange) 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;
51
- const current = (now.getMonth() + 1) * 100 + now.getDate();
52
- return startNum <= endNum ? current >= startNum && current <= endNum : current >= startNum || current <= endNum;
53
- }
54
- export function getActiveSeasonalTheme(themes, prefersDark, now = /* @__PURE__ */ new Date()) {
55
- for (const [themeName, themeConfig] of Object.entries(themes)) {
56
- if (themeName === "system") continue;
57
- if (!isColorTheme(themeConfig)) continue;
58
- if (!isDateInSeasonalRange(themeConfig, now)) continue;
59
- if (prefersDark !== void 0 && themeConfig.dark !== prefersDark) continue;
60
- return themeName;
61
- }
62
- return null;
63
- }
64
- export function resolveThemePreference(preference, themes, defaultTheme, prefersDark) {
65
- let resolved;
66
- if (preference === "system") {
67
- resolved = getActiveSeasonalTheme(themes, prefersDark) || (prefersDark ? "dark" : "light");
68
- } else if (preference && isColorTheme(themes[preference])) {
69
- resolved = preference;
70
- } else {
71
- resolved = defaultTheme;
72
- }
73
- if (!isColorTheme(themes[resolved])) {
74
- resolved = isColorTheme(themes[defaultTheme]) ? defaultTheme : "dark";
75
- }
76
- return resolved;
24
+ export function resolveServerTheme(themePreference, modePreference, resolvedHint, colors, now = /* @__PURE__ */ new Date()) {
25
+ const hinted = resolvedHint ? colors.themes[resolvedHint] : void 0;
26
+ const prefersDark = hinted && isColorTheme(hinted) ? hinted.dark !== false : true;
27
+ return resolveThemePreference(themePreference, modePreference, colors, prefersDark, now);
77
28
  }
@@ -0,0 +1,46 @@
1
+ import type { ThemeColors, ThemeMode, ThemeModePreference, ResolvedThemeGroup } from '../types/index.js';
2
+ /** The resolved color model the functions below work on (a subset of `ColorsConfig`). */
3
+ export interface ColorModel {
4
+ themes: Record<string, ThemeColors>;
5
+ groups: Record<string, ResolvedThemeGroup>;
6
+ defaultColor?: string;
7
+ }
8
+ /** What the user picked: a theme (or `'system'`: by date) and a mode (or `'system'`: by OS). */
9
+ export interface ThemeSelection {
10
+ theme: string;
11
+ mode: ThemeModePreference;
12
+ }
13
+ /**
14
+ * The theme-resolution rule (which variant to apply for a saved choice, the
15
+ * OS color scheme and today's date), in one place.
16
+ *
17
+ * Has to stay 100% self-contained — no imports used at runtime, no references
18
+ * to anything outside this function (type imports are fine, TypeScript erases
19
+ * them): besides being called normally (see `theme-resolve.ts`), its source is
20
+ * serialized with `toString()` into the inline pre-hydration script
21
+ * (`runtime/nitro/theme-init.ts` → `runtime/scripts/theme-init.ts`), where
22
+ * anything from outside would be a `ReferenceError`. That's also why the two
23
+ * constants below are repeated here instead of imported from
24
+ * `shared/constants.ts` (a test checks they still match).
25
+ */
26
+ export declare function createThemeResolver(): {
27
+ SYSTEM_THEME: string;
28
+ DEFAULT_THEME: string;
29
+ isColorTheme: (themeConfig: ThemeColors | undefined) => boolean;
30
+ getEasterSunday: (year: number) => Date;
31
+ isModePreference: (value: unknown) => value is ThemeModePreference;
32
+ isSelectableGroup: (colors: ColorModel, name: string) => boolean;
33
+ findVariantOwner: (colors: ColorModel, id: string) => {
34
+ theme: string;
35
+ mode: ThemeMode;
36
+ } | null;
37
+ getDefaultSelection: (colors: ColorModel) => ThemeSelection & {
38
+ fallbackTheme: string;
39
+ };
40
+ normalizeThemeSelection: (themePreference: string | null | undefined, modePreference: string | null | undefined, colors: ColorModel) => ThemeSelection;
41
+ getActiveSeasonalTheme: (groups: Record<string, ResolvedThemeGroup>, mode?: ThemeMode, now?: Date) => string | null;
42
+ resolveMode: (mode: ThemeModePreference, prefersDark: boolean) => ThemeMode;
43
+ resolveThemeSelection: (selection: ThemeSelection, colors: ColorModel, prefersDark: boolean, now?: Date) => string;
44
+ resolveThemePreference: (themePreference: string | null | undefined, modePreference: string | null | undefined, colors: ColorModel, prefersDark: boolean, now?: Date) => string;
45
+ };
46
+ export type ThemeResolver = ReturnType<typeof createThemeResolver>;