@venix-sistemas/jade 1.0.1 → 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 (57) hide show
  1. package/README.md +350 -254
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +32 -35
  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 +12 -18
  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 +174 -112
  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 -62
  22. package/dist/shared/constants.d.ts +18 -3
  23. package/dist/shared/constants.js +6 -1
  24. package/dist/shared/css/colors.js +2 -2
  25. package/dist/shared/css/cursor.js +9 -2
  26. package/dist/shared/css/index.d.ts +1 -7
  27. package/dist/shared/css/index.js +9 -9
  28. package/dist/shared/css/transition.d.ts +1 -1
  29. package/dist/shared/theme.json +302 -192
  30. package/dist/shared/types/color-options.d.ts +26 -2
  31. package/dist/shared/types/colors.d.ts +64 -7
  32. package/dist/shared/types/index.d.ts +1 -1
  33. package/dist/shared/types/runtime-config.d.ts +4 -2
  34. package/dist/shared/utils/icon-refs.d.ts +7 -3
  35. package/dist/shared/utils/icon-refs.js +1 -1
  36. package/dist/shared/utils/icon.d.ts +6 -2
  37. package/dist/shared/utils/icon.js +8 -3
  38. package/dist/shared/utils/index.d.ts +5 -3
  39. package/dist/shared/utils/index.js +12 -5
  40. package/dist/shared/utils/inline-script.d.ts +6 -0
  41. package/dist/shared/utils/inline-script.js +3 -0
  42. package/dist/shared/utils/load.d.ts +0 -1
  43. package/dist/shared/utils/load.js +7 -16
  44. package/dist/shared/utils/merge-themes.d.ts +41 -0
  45. package/dist/shared/utils/merge-themes.js +106 -0
  46. package/dist/shared/utils/normalize.d.ts +0 -10
  47. package/dist/shared/utils/normalize.js +0 -12
  48. package/dist/shared/utils/theme-config.d.ts +13 -4
  49. package/dist/shared/utils/theme-config.js +28 -13
  50. package/dist/shared/utils/theme-resolve.d.ts +19 -19
  51. package/dist/shared/utils/theme-resolve.js +25 -42
  52. package/dist/shared/utils/theme-resolver.d.ts +46 -0
  53. package/dist/shared/utils/theme-resolver.js +139 -0
  54. package/package.json +13 -10
  55. package/README-default.md +0 -84
  56. package/dist/runtime/plugin.d.ts +0 -2
  57. package/dist/runtime/plugin.js +0 -3
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.1",
4
+ "version": "1.2.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.3",
7
7
  "unbuild": "unknown"
package/dist/module.mjs CHANGED
@@ -1,8 +1,11 @@
1
- import { addComponent, addPlugin, addServerPlugin, addTemplate, installModule, addImports, defineNuxtModule, createResolver } from '@nuxt/kit';
1
+ import { addComponent, addPlugin, addServerPlugin, addTemplate, installModule, addImports, defineNuxtModule, createResolver, useLogger } 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 { findDeprecatedThemeEntries } from '../dist/shared/utils/merge-themes.js';
6
+ import { buildResolvedTheme, getBaseThemeEntries } from '../dist/shared/utils/theme-config.js';
5
7
  import { processTheme } from '../dist/shared/css/index.js';
8
+ import { isColorTheme, getThemeHexColors } from '../dist/shared/utils/theme-resolve.js';
6
9
  import { createRequire } from 'node:module';
7
10
  import { realpathSync } from 'node:fs';
8
11
  import { fileURLToPath } from 'node:url';
@@ -11,7 +14,7 @@ import { getIcons } from '@iconify/utils';
11
14
  import { extractIconRefs } from '../dist/shared/utils/index.js';
12
15
 
13
16
  function customizeTheme(baseTheme, options) {
14
- const customized = JSON.parse(JSON.stringify(baseTheme));
17
+ const customized = structuredClone(baseTheme);
15
18
  customized.typography = resolveFeatureOption(options.typography, customized.typography);
16
19
  customized.customScrollbar = resolveFeatureOption(options.scrollbar, customized.customScrollbar);
17
20
  customized.customCursor = resolveFeatureOption(options.cursor, customized.customCursor);
@@ -22,24 +25,12 @@ function customizeTheme(baseTheme, options) {
22
25
  if (colorOption.enabled === false) {
23
26
  customized.colors.enabled = false;
24
27
  }
25
- if (colorOption.defaultColor) {
26
- customized.colors.defaultColor = colorOption.defaultColor;
27
- }
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
- }
28
+ const resolved = buildResolvedTheme({
29
+ defaultTheme: colorOption.defaultColor || customized.colors.defaultColor,
30
+ colorThemes: colorOption.themes,
31
+ seasonal: colorOption.seasonal
32
+ });
33
+ customized.colors = { ...resolved.colors, enabled: customized.colors.enabled };
43
34
  }
44
35
  return customized;
45
36
  }
@@ -49,7 +40,10 @@ function registerPublicAssets(nuxt, resolver) {
49
40
  nuxt.options.nitro.publicAssets = nuxt.options.nitro.publicAssets || [];
50
41
  nuxt.options.nitro.publicAssets.push({
51
42
  dir: resolver.resolve("./runtime/public"),
52
- maxAge: 60 * 60 * 24 * 365,
43
+ // A week, not a year: these files (cursor images, fonts) keep the same
44
+ // URL across releases (no content hash), so a long cache would keep
45
+ // serving the old file for months after an update.
46
+ maxAge: 60 * 60 * 24 * 7,
53
47
  baseURL: "/"
54
48
  });
55
49
  }
@@ -69,7 +63,6 @@ function registerThemePlugins(_nuxt, resolver, shouldApplyColors) {
69
63
  });
70
64
  addServerPlugin(resolver.resolve("./runtime/nitro/theme-init"));
71
65
  }
72
- addPlugin(resolver.resolve("./runtime/plugin"));
73
66
  }
74
67
 
75
68
  function registerThemeCSS(nuxt, theme) {
@@ -87,14 +80,9 @@ function registerThemeCSS(nuxt, theme) {
87
80
  function buildVuetifyThemes(colors) {
88
81
  const themes = {};
89
82
  for (const [name, themeColors] of Object.entries(colors.themes)) {
90
- if (!themeColors.primary && !themeColors.background) continue;
83
+ if (!isColorTheme(themeColors)) continue;
91
84
  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
- }
85
+ const vuetifyColors = Object.fromEntries(getThemeHexColors(themeColors));
98
86
  if (themeColors.background2) vuetifyColors.surface = themeColors.background2;
99
87
  vuetifyColors.inverse = isDark ? "#FFFFFF" : "#000000";
100
88
  themes[name] = { dark: isDark, colors: vuetifyColors };
@@ -149,7 +137,8 @@ async function registerThemeIcon(nuxt, resolver, options, colors) {
149
137
  }
150
138
  const explicit = new Set(options.collections);
151
139
  const collections = options.collections.map((name) => loadFullCollection(name, projectRequire));
152
- const refs = extractIconRefs(colors.themes, options.aliases);
140
+ const labelled = [...Object.values(colors.groups ?? {}), ...Object.values(colors.modes ?? {})];
141
+ const refs = extractIconRefs(labelled, options.aliases);
153
142
  for (const [name, iconNames] of refs) {
154
143
  if (explicit.has(name)) continue;
155
144
  collections.push(loadCollectionSubset(name, iconNames, projectRequire) ?? name);
@@ -197,10 +186,15 @@ const module$1 = defineNuxtModule({
197
186
  const colorOptions = resolveFeatureOption(options.color, {
198
187
  enabled: theme.colors?.enabled !== false,
199
188
  apply: true,
200
- defaultColor: theme.colors?.defaultColor || "dark",
189
+ defaultColor: theme.colors?.defaultColor || DEFAULT_THEME,
201
190
  themes: {},
202
- iconFormat: "svg"
191
+ iconFormat: "svg",
192
+ requireConsent: true,
193
+ seasonal: true
203
194
  });
195
+ for (const message of findDeprecatedThemeEntries(getBaseThemeEntries(), colorOptions.themes)) {
196
+ useLogger("jade").warn(message);
197
+ }
204
198
  const shouldApplyColors = colorOptions.enabled && colorOptions.apply && theme.colors?.defaults !== false;
205
199
  const translationOptions = resolveFeatureOption(options.translation, {
206
200
  enabled: true,
@@ -222,13 +216,16 @@ const module$1 = defineNuxtModule({
222
216
  });
223
217
  await registerThemeIcon(nuxt, resolver, iconOptions, theme.colors);
224
218
  nuxt.options.runtimeConfig.public.venixTheme = {
225
- defaultTheme: theme.colors?.defaultColor || "dark",
219
+ defaultTheme: theme.colors?.defaultColor || DEFAULT_THEME,
226
220
  colorThemes: colorOptions.themes,
227
221
  applyColors: shouldApplyColors,
228
222
  localeCookie: translationOptions.cookieSync,
229
223
  defaultLocale: translationOptions.defaultLocale,
230
224
  locale: translationOptions.locale,
231
- iconFormat: colorOptions.iconFormat,
225
+ // Without the icon module, @nuxt/icon isn't installed — only emoji can render
226
+ iconFormat: iconOptions.enabled ? colorOptions.iconFormat : "emote",
227
+ requireConsent: colorOptions.requireConsent,
228
+ seasonal: colorOptions.seasonal,
232
229
  icon: {
233
230
  aliases: iconOptions.aliases
234
231
  },
@@ -1,7 +1,7 @@
1
1
  type __VLS_Props = {
2
2
  /** Accessible label for the button and the menu. Without a value, uses the component's own translation based on the current locale. */
3
3
  label?: string;
4
- /** Shows the active theme's name next to the icon on the button. */
4
+ /** Shows the active theme's and mode's names next to the icon on the button. */
5
5
  showLabel?: boolean;
6
6
  };
7
7
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -1,115 +1,251 @@
1
1
  <template>
2
- <div
3
- ref="rootRef"
4
- class="venix-theme-switcher"
5
- @focusout="handleFocusOut"
6
- >
7
- <span
8
- class="venix-theme-switcher__sr-only"
9
- role="status"
10
- aria-live="polite"
11
- >{{ announcement }}</span>
12
-
13
- <button
14
- ref="triggerRef"
15
- type="button"
16
- class="venix-theme-switcher__trigger"
17
- :class="{ 'venix-theme-switcher__trigger--visible': visible }"
18
- :aria-label="resolvedLabel"
19
- :aria-expanded="open"
20
- aria-haspopup="menu"
21
- @click="toggleOpen"
22
- >
23
- <VenixIcon
24
- v-if="activeIcon"
25
- :key="activeIconKey"
26
- :icon="activeIcon.value"
27
- :mode="activeIcon.format === 'emote' ? void 0 : activeIcon.format"
28
- aria-hidden="true"
29
- />
30
- <span
31
- v-if="showLabel"
32
- class="venix-theme-switcher__trigger-label"
33
- >{{ theme.data.value?.name }}</span>
34
- </button>
35
-
36
- <ul
37
- v-show="open"
38
- class="venix-theme-switcher__menu"
39
- role="menu"
40
- :aria-label="resolvedLabel"
41
- @keydown="handleMenuKeydown"
42
- >
43
- <li
44
- class="venix-theme-switcher__heading"
45
- aria-hidden="true"
46
- >
47
- {{ resolvedLabel }}
48
- </li>
49
- <li
50
- v-for="item in themes"
51
- :key="item.value"
52
- role="none"
53
- >
54
- <button
55
- type="button"
56
- role="menuitemradio"
57
- class="venix-theme-switcher__item"
58
- :class="{ 'venix-theme-switcher__item--active': item.value === theme.preference.value }"
59
- :aria-checked="item.value === theme.preference.value"
60
- @click="select(item.value)"
61
- >
62
- <VenixIcon
63
- v-if="item.icon"
64
- class="venix-theme-switcher__item-icon"
65
- :icon="item.icon.value"
66
- :mode="item.icon.format === 'emote' ? void 0 : item.icon.format"
67
- aria-hidden="true"
68
- />
69
- <span>{{ item.name }}</span>
70
- </button>
71
- </li>
72
- </ul>
73
- </div>
2
+ <div
3
+ ref="rootRef"
4
+ class="venix-theme-switcher"
5
+ @focusout="handleFocusOut"
6
+ >
7
+ <span
8
+ class="venix-theme-switcher__sr-only"
9
+ role="status"
10
+ aria-live="polite"
11
+ >{{ announcement }}</span>
12
+
13
+ <button
14
+ ref="triggerRef"
15
+ type="button"
16
+ class="venix-theme-switcher__trigger"
17
+ :class="{ 'venix-theme-switcher__trigger--visible': visible }"
18
+ :aria-label="resolvedLabel"
19
+ :aria-expanded="open"
20
+ aria-haspopup="menu"
21
+ @click="toggleOpen"
22
+ >
23
+ <template v-if="activeIcon">
24
+ <span
25
+ v-if="activeIcon.format === 'emote'"
26
+ :key="activeIconKey"
27
+ class="venix-icon venix-icon--emoji"
28
+ aria-hidden="true"
29
+ >{{ activeIcon.value }}</span>
30
+ <VenixIcon
31
+ v-else
32
+ :key="activeIconKey"
33
+ :icon="activeIcon.value"
34
+ :mode="activeIcon.format"
35
+ aria-hidden="true"
36
+ />
37
+ </template>
38
+ <span
39
+ v-if="showLabel"
40
+ class="venix-theme-switcher__trigger-label"
41
+ >{{ triggerLabel }}</span>
42
+ </button>
43
+
44
+ <Transition name="venix-theme-switcher-menu">
45
+ <div
46
+ v-show="open"
47
+ class="venix-theme-switcher__menu"
48
+ role="menu"
49
+ :aria-label="resolvedLabel"
50
+ @keydown="handleMenuKeydown"
51
+ >
52
+ <div
53
+ class="venix-theme-switcher__heading"
54
+ aria-hidden="true"
55
+ >
56
+ {{ resolvedLabel }}
57
+ </div>
58
+
59
+ <div
60
+ class="venix-theme-switcher__separator"
61
+ role="separator"
62
+ />
63
+
64
+ <div
65
+ class="venix-theme-switcher__group"
66
+ role="group"
67
+ :aria-label="modeHeading"
68
+ >
69
+ <div
70
+ class="venix-theme-switcher__subheading"
71
+ aria-hidden="true"
72
+ >
73
+ {{ modeHeading }}
74
+ </div>
75
+ <div class="venix-theme-switcher__modes">
76
+ <button
77
+ v-for="item in modes"
78
+ :key="item.value"
79
+ type="button"
80
+ role="menuitemradio"
81
+ class="venix-theme-switcher__item venix-theme-switcher__item--mode"
82
+ :class="{ 'venix-theme-switcher__item--active': item.value === mode.preference.value }"
83
+ :aria-checked="item.value === mode.preference.value"
84
+ @click="selectMode(item.value)"
85
+ >
86
+ <span
87
+ v-if="item.icon?.format === 'emote'"
88
+ class="venix-icon venix-icon--emoji venix-theme-switcher__item-icon"
89
+ aria-hidden="true"
90
+ >{{ item.icon.value }}</span>
91
+ <VenixIcon
92
+ v-else-if="item.icon"
93
+ class="venix-theme-switcher__item-icon"
94
+ :icon="item.icon.value"
95
+ :mode="item.icon.format"
96
+ aria-hidden="true"
97
+ />
98
+ <span>{{ item.name }}</span>
99
+ </button>
100
+ </div>
101
+ </div>
102
+
103
+ <template
104
+ v-for="section in themeSections"
105
+ :key="section.key"
106
+ >
107
+ <div
108
+ class="venix-theme-switcher__separator"
109
+ role="separator"
110
+ />
111
+
112
+ <div
113
+ class="venix-theme-switcher__group"
114
+ role="group"
115
+ :aria-label="section.heading"
116
+ >
117
+ <div
118
+ class="venix-theme-switcher__subheading"
119
+ aria-hidden="true"
120
+ >
121
+ {{ section.heading }}
122
+ </div>
123
+ <button
124
+ v-for="item in section.items"
125
+ :key="item.value"
126
+ type="button"
127
+ role="menuitemradio"
128
+ class="venix-theme-switcher__item"
129
+ :class="{ 'venix-theme-switcher__item--active': item.value === theme.preference.value }"
130
+ :aria-checked="item.value === theme.preference.value"
131
+ @click="selectTheme(item.value)"
132
+ >
133
+ <span
134
+ v-if="item.icon?.format === 'emote'"
135
+ class="venix-icon venix-icon--emoji venix-theme-switcher__item-icon"
136
+ aria-hidden="true"
137
+ >{{ item.icon.value }}</span>
138
+ <VenixIcon
139
+ v-else-if="item.icon"
140
+ class="venix-theme-switcher__item-icon"
141
+ :icon="item.icon.value"
142
+ :mode="item.icon.format"
143
+ aria-hidden="true"
144
+ />
145
+ <span>{{ item.name }}</span>
146
+ </button>
147
+ </div>
148
+ </template>
149
+ </div>
150
+ </Transition>
151
+ </div>
74
152
  </template>
75
153
 
76
154
  <script setup>
77
155
  import { ref, computed, onMounted, onUnmounted, nextTick } from "vue";
78
156
  import { useVenixTheme } from "../composables/useVenixTheme";
157
+ import { getDefaultSelection } from "../../shared/utils/theme-resolve";
158
+ import VenixIcon from "./VenixIcon.vue";
79
159
  const LABEL_TRANSLATIONS = {
80
- "pt-BR": "Tema de cor",
81
- "en-US": "Color theme",
82
- "es-ES": "Tema de color",
83
- "fr-FR": "Th\xE8me de couleur",
84
- "de-DE": "Farbthema",
85
- "it-IT": "Tema colore",
86
- "ja-JP": "\u30AB\u30E9\u30FC\u30C6\u30FC\u30DE",
87
- "ko-KR": "\uC0C9\uC0C1 \uD14C\uB9C8",
88
- "zh-CN": "\u989C\u8272\u4E3B\u9898"
160
+ "pt-BR": "Cores do site",
161
+ "en-US": "Website color",
162
+ "es-ES": "Color del sitio",
163
+ "fr-FR": "Couleur du site",
164
+ "de-DE": "Website-Farbe",
165
+ "it-IT": "Colore del sito",
166
+ "ja-JP": "\u30B5\u30A4\u30C8\u306E\u8272",
167
+ "ko-KR": "\uC0AC\uC774\uD2B8 \uC0C9\uC0C1",
168
+ "zh-CN": "\u7F51\u7AD9\u989C\u8272"
89
169
  };
90
170
  const CHANGED_ANNOUNCEMENT_TRANSLATIONS = {
91
- "pt-BR": "Tema de cor alterado para {theme}",
92
- "en-US": "Color theme changed to {theme}",
93
- "es-ES": "Tema de color cambiado a {theme}",
94
- "fr-FR": "Th\xE8me de couleur chang\xE9 pour {theme}",
95
- "de-DE": "Farbthema ge\xE4ndert zu {theme}",
96
- "it-IT": "Tema colore cambiato in {theme}",
97
- "ja-JP": "\u30AB\u30E9\u30FC\u30C6\u30FC\u30DE\u304C{theme}\u306B\u5909\u66F4\u3055\u308C\u307E\u3057\u305F",
98
- "ko-KR": "\uC0C9\uC0C1 \uD14C\uB9C8\uAC00 {theme}(\uC73C)\uB85C \uBCC0\uACBD\uB418\uC5C8\uC2B5\uB2C8\uB2E4",
99
- "zh-CN": "\u989C\u8272\u4E3B\u9898\u5DF2\u66F4\u6539\u4E3A{theme}"
171
+ "pt-BR": "Cores do site alteradas para {theme}",
172
+ "en-US": "Website color changed to {theme}",
173
+ "es-ES": "Color del sitio cambiado a {theme}",
174
+ "fr-FR": "Couleur du site chang\xE9e pour {theme}",
175
+ "de-DE": "Website-Farbe ge\xE4ndert zu {theme}",
176
+ "it-IT": "Colore del sito cambiato in {theme}",
177
+ "ja-JP": "\u30B5\u30A4\u30C8\u306E\u8272\u304C{theme}\u306B\u5909\u66F4\u3055\u308C\u307E\u3057\u305F",
178
+ "ko-KR": "\uC0AC\uC774\uD2B8 \uC0C9\uC0C1\uC774 {theme}(\uC73C)\uB85C \uBCC0\uACBD\uB418\uC5C8\uC2B5\uB2C8\uB2E4",
179
+ "zh-CN": "\u7F51\u7AD9\u989C\u8272\u5DF2\u66F4\u6539\u4E3A{theme}"
180
+ };
181
+ const MODE_HEADING_TRANSLATIONS = {
182
+ "pt-BR": "Modo",
183
+ "en-US": "Mode",
184
+ "es-ES": "Modo",
185
+ "fr-FR": "Mode",
186
+ "de-DE": "Modus",
187
+ "it-IT": "Modalit\xE0",
188
+ "ja-JP": "\u30E2\u30FC\u30C9",
189
+ "ko-KR": "\uBAA8\uB4DC",
190
+ "zh-CN": "\u6A21\u5F0F"
191
+ };
192
+ const THEME_HEADING_TRANSLATIONS = {
193
+ "pt-BR": "Tema",
194
+ "en-US": "Theme",
195
+ "es-ES": "Tema",
196
+ "fr-FR": "Th\xE8me",
197
+ "de-DE": "Thema",
198
+ "it-IT": "Tema",
199
+ "ja-JP": "\u30C6\u30FC\u30DE",
200
+ "ko-KR": "\uD14C\uB9C8",
201
+ "zh-CN": "\u4E3B\u9898"
202
+ };
203
+ const CUSTOM_HEADING_TRANSLATIONS = {
204
+ "pt-BR": "Tema personalizado",
205
+ "en-US": "Custom theme",
206
+ "es-ES": "Tema personalizado",
207
+ "fr-FR": "Th\xE8me personnalis\xE9",
208
+ "de-DE": "Eigenes Thema",
209
+ "it-IT": "Tema personalizzato",
210
+ "ja-JP": "\u30AB\u30B9\u30BF\u30E0\u30C6\u30FC\u30DE",
211
+ "ko-KR": "\uC0AC\uC6A9\uC790 \uC9C0\uC815 \uD14C\uB9C8",
212
+ "zh-CN": "\u81EA\u5B9A\u4E49\u4E3B\u9898"
213
+ };
214
+ const MODE_CHANGED_ANNOUNCEMENT_TRANSLATIONS = {
215
+ "pt-BR": "Modo alterado para {mode}",
216
+ "en-US": "Mode changed to {mode}",
217
+ "es-ES": "Modo cambiado a {mode}",
218
+ "fr-FR": "Mode chang\xE9 pour {mode}",
219
+ "de-DE": "Modus ge\xE4ndert zu {mode}",
220
+ "it-IT": "Modalit\xE0 cambiata in {mode}",
221
+ "ja-JP": "\u30E2\u30FC\u30C9\u304C{mode}\u306B\u5909\u66F4\u3055\u308C\u307E\u3057\u305F",
222
+ "ko-KR": "\uBAA8\uB4DC\uAC00 {mode}(\uC73C)\uB85C \uBCC0\uACBD\uB418\uC5C8\uC2B5\uB2C8\uB2E4",
223
+ "zh-CN": "\u6A21\u5F0F\u5DF2\u66F4\u6539\u4E3A{mode}"
100
224
  };
101
225
  const props = defineProps({
102
226
  label: { type: String, required: false },
103
227
  showLabel: { type: Boolean, required: false }
104
228
  });
105
- const { theme, themes, locale } = useVenixTheme();
106
- const resolvedLabel = computed(() => props.label ?? locale.translate(LABEL_TRANSLATIONS, "Color theme"));
229
+ const { theme, themes, mode, modes, locale } = useVenixTheme();
230
+ const resolvedLabel = computed(() => props.label ?? locale.translate(LABEL_TRANSLATIONS, "Website color"));
231
+ const modeHeading = computed(() => locale.translate(MODE_HEADING_TRANSLATIONS, "Mode"));
232
+ const themeHeading = computed(() => locale.translate(THEME_HEADING_TRANSLATIONS, "Theme"));
233
+ const themeSections = computed(() => [
234
+ { key: "built-in", heading: themeHeading.value, items: themes.value.filter((item) => !item.custom) },
235
+ { key: "custom", heading: locale.translate(CUSTOM_HEADING_TRANSLATIONS, "Custom theme"), items: themes.value.filter((item) => item.custom) }
236
+ ].filter((section) => section.items.length > 0));
237
+ const triggerLabel = computed(() => [theme.data.value?.name, mode.data.value?.name].filter(Boolean).join(" \xB7 "));
238
+ const baseTheme = getDefaultSelection(theme.colors).fallbackTheme;
107
239
  const open = ref(false);
108
240
  const visible = ref(false);
109
241
  const announcement = ref("");
110
242
  const rootRef = ref(null);
111
243
  const triggerRef = ref(null);
112
- const activeIcon = computed(() => theme.data.value?.icon ?? null);
244
+ const activeIcon = computed(() => {
245
+ const effectiveTheme = theme.preference.value === "system" ? theme.activeSeasonalTheme.value : theme.preference.value;
246
+ if (!effectiveTheme || effectiveTheme === baseTheme) return mode.data.value?.icon ?? null;
247
+ return themes.value.find((item) => item.value === effectiveTheme)?.icon ?? null;
248
+ });
113
249
  const activeIconKey = computed(() => `${theme.value.value}:${activeIcon.value?.format ?? ""}:${activeIcon.value?.value ?? ""}`);
114
250
  const getMenuItems = () => {
115
251
  return Array.from(rootRef.value?.querySelectorAll(".venix-theme-switcher__item") ?? []);
@@ -124,30 +260,37 @@ const toggleOpen = async () => {
124
260
  if (!open.value) return;
125
261
  await nextTick();
126
262
  const items = getMenuItems();
127
- const activeIndex = themes.value.findIndex((item) => item.value === theme.preference.value);
128
- (items[activeIndex] ?? items[0])?.focus();
263
+ (items.find((el) => el.getAttribute("aria-checked") === "true") ?? items[0])?.focus();
129
264
  };
130
265
  const close = (options = {}) => {
131
266
  if (!open.value) return;
132
267
  open.value = false;
133
268
  if (options.restoreFocus) triggerRef.value?.focus();
134
269
  };
135
- const select = (value) => {
270
+ const selectTheme = (value) => {
136
271
  const selected = themes.value.find((item) => item.value === value);
137
- theme.toggle(value);
138
- const template = locale.translate(CHANGED_ANNOUNCEMENT_TRANSLATIONS, "Color theme changed to {theme}");
272
+ theme.set(value);
273
+ const template = locale.translate(CHANGED_ANNOUNCEMENT_TRANSLATIONS, "Website color changed to {theme}");
139
274
  announcement.value = template.replace("{theme}", selected?.name ?? value);
140
275
  close({ restoreFocus: true });
141
276
  };
277
+ const selectMode = (value) => {
278
+ const selected = modes.value.find((item) => item.value === value);
279
+ mode.set(value);
280
+ const template = locale.translate(MODE_CHANGED_ANNOUNCEMENT_TRANSLATIONS, "Mode changed to {mode}");
281
+ announcement.value = template.replace("{mode}", selected?.name ?? value);
282
+ };
142
283
  const handleMenuKeydown = (event) => {
143
284
  const items = getMenuItems();
144
285
  const currentIndex = items.findIndex((el) => el === document.activeElement);
145
286
  switch (event.key) {
146
287
  case "ArrowDown":
288
+ case "ArrowRight":
147
289
  event.preventDefault();
148
290
  focusItemAt(currentIndex + 1);
149
291
  break;
150
292
  case "ArrowUp":
293
+ case "ArrowLeft":
151
294
  event.preventDefault();
152
295
  focusItemAt(currentIndex - 1);
153
296
  break;
@@ -187,5 +330,5 @@ onUnmounted(() => {
187
330
  </script>
188
331
 
189
332
  <style>
190
- .venix-theme-switcher{display:inline-block;position:relative}.venix-theme-switcher__sr-only{height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;clip:rect(0,0,0,0);border:0;white-space:nowrap}.venix-theme-switcher__trigger{align-items:center;background:transparent;border:none;border-radius:999px;color:inherit;cursor:pointer;display:inline-flex;font-size:1.25rem;gap:.5rem;line-height:1;opacity:0;padding:.5rem;transition:opacity .3s ease,background-color .2s ease}.venix-theme-switcher__trigger--visible{opacity:1}.venix-theme-switcher__trigger:focus-visible,.venix-theme-switcher__trigger:hover{background:var(--color-background3,hsla(0,0%,50%,.15))}.venix-theme-switcher__trigger-label{font-size:.875rem}.venix-theme-switcher__menu{background:#1f2128;border:1px solid #3a3d46;border-radius:.75rem;box-shadow:0 8px 24px rgba(0,0,0,.25);list-style:none;margin:0;min-width:12rem;padding:.375rem;position:absolute;right:0;top:calc(100% + .5rem);z-index:50}.venix-theme-switcher__heading{color:rgba(245,245,247,.6);font-size:.75rem;font-weight:600;letter-spacing:.04em;padding:.375rem .625rem;text-align:center;text-transform:uppercase}.venix-theme-switcher__item{align-items:center;background:transparent;border:none;border-radius:.5rem;color:#f5f5f7;cursor:pointer;display:flex;font:inherit;gap:.625rem;padding:.5rem .625rem;text-align:left;width:100%}.venix-theme-switcher__item:focus-visible,.venix-theme-switcher__item:hover{background:hsla(0,0%,100%,.08)}.venix-theme-switcher__item--active{background:hsla(0,0%,100%,.14);color:#fff;font-weight:600}.venix-theme-switcher__item-icon{flex-shrink:0}
333
+ .venix-theme-switcher{display:inline-block;position:relative}.venix-theme-switcher__sr-only{height:1px;margin:-1px;overflow:hidden;padding:0;position:absolute;width:1px;clip:rect(0,0,0,0);border:0;white-space:nowrap}.venix-theme-switcher__trigger{align-items:center;background:transparent;border:none;border-radius:999px;color:inherit;cursor:pointer;display:inline-flex;font-size:1.25rem;gap:.5rem;line-height:1;opacity:0;padding:.5rem;transition:opacity .3s ease,background-color .2s ease}.venix-theme-switcher__trigger--visible{opacity:1}.venix-theme-switcher__trigger:focus-visible,.venix-theme-switcher__trigger:hover{background:var(--color-background3,hsla(0,0%,50%,.15))}.venix-theme-switcher__trigger-label{font-size:.875rem}.venix-theme-switcher__menu{border-radius:.75rem;margin:0;min-width:15rem;padding:.375rem;position:absolute;right:0;text-align:left;top:calc(100% + .5rem);z-index:50;--venix-switcher-bg:#1f2128;--venix-switcher-border:#3a3d46;--venix-switcher-text:#f5f5f7;--venix-switcher-text-strong:#fff;--venix-switcher-heading:rgba(245,245,247,.6);--venix-switcher-subheading:rgba(245,245,247,.45);--venix-switcher-hover:hsla(0,0%,100%,.08);--venix-switcher-active:hsla(0,0%,100%,.14);--venix-switcher-shadow:rgba(0,0,0,.25);background:var(--venix-switcher-bg);border:1px solid var(--venix-switcher-border);box-shadow:0 8px 24px var(--venix-switcher-shadow);transform-origin:top right}@supports (color:light-dark(#fff,#000)){.venix-theme-switcher__menu{--venix-switcher-bg:light-dark(#fff,#1f2128);--venix-switcher-border:light-dark(#e2e4ea,#3a3d46);--venix-switcher-text:light-dark(#1f2128,#f5f5f7);--venix-switcher-text-strong:light-dark(#000,#fff);--venix-switcher-heading:light-dark(rgba(31,33,40,.6),rgba(245,245,247,.6));--venix-switcher-subheading:light-dark(rgba(31,33,40,.5),rgba(245,245,247,.45));--venix-switcher-hover:light-dark(rgba(0,0,0,.05),hsla(0,0%,100%,.08));--venix-switcher-active:light-dark(rgba(0,0,0,.09),hsla(0,0%,100%,.14));--venix-switcher-shadow:light-dark(rgba(0,0,0,.12),rgba(0,0,0,.25))}}.venix-theme-switcher-menu-enter-active{transition:transform .22s cubic-bezier(0,0,.2,1),opacity .12s ease-out}.venix-theme-switcher-menu-leave-active{transition:opacity .2s ease-in}.venix-theme-switcher-menu-enter-from{opacity:0;transform:scale(.3)}.venix-theme-switcher-menu-leave-to{opacity:0}@media (prefers-reduced-motion:reduce){.venix-theme-switcher-menu-enter-active,.venix-theme-switcher-menu-leave-active{transition:none}}.venix-theme-switcher__heading{color:var(--venix-switcher-heading);font-size:.75rem;padding:.375rem .625rem}.venix-theme-switcher__heading,.venix-theme-switcher__subheading{font-weight:600;letter-spacing:.04em;text-align:center;text-transform:uppercase}.venix-theme-switcher__subheading{color:var(--venix-switcher-subheading);font-size:.6875rem;padding:.25rem .625rem}.venix-theme-switcher__modes{display:grid;gap:.25rem;grid-template-columns:repeat(3,1fr)}.venix-theme-switcher__separator{background:var(--venix-switcher-border);height:1px;margin:.375rem .25rem}.venix-theme-switcher__item{align-items:center;background:transparent;border:none;border-radius:.5rem;color:var(--venix-switcher-text);cursor:pointer;display:flex;font:inherit;gap:.625rem;padding:.5rem .625rem;text-align:left;width:100%}.venix-theme-switcher__item--mode{flex-direction:column;font-size:.75rem;gap:.25rem;justify-content:center;padding:.5rem .25rem;text-align:center}.venix-theme-switcher__item--mode .venix-theme-switcher__item-icon{font-size:1.125rem}.venix-theme-switcher__item:focus-visible,.venix-theme-switcher__item:hover{background:var(--venix-switcher-hover)}.venix-theme-switcher__item--active{background:var(--venix-switcher-active);color:var(--venix-switcher-text-strong);font-weight:600}.venix-theme-switcher__item-icon{flex-shrink:0}
191
334
  </style>
@@ -1,7 +1,7 @@
1
1
  type __VLS_Props = {
2
2
  /** Accessible label for the button and the menu. Without a value, uses the component's own translation based on the current locale. */
3
3
  label?: string;
4
- /** Shows the active theme's name next to the icon on the button. */
4
+ /** Shows the active theme's and mode's names next to the icon on the button. */
5
5
  showLabel?: boolean;
6
6
  };
7
7
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -5,6 +5,12 @@ export declare const useThemeColors: (theme: ThemeConfig, translate: (translatio
5
5
  value: string;
6
6
  name: string;
7
7
  icon: import("../../shared/utils/icon.js").ResolvedThemeIcon | null;
8
+ custom: boolean;
9
+ }[]>;
10
+ modes: import("vue").ComputedRef<{
11
+ value: "light" | "dark" | "system";
12
+ name: string;
13
+ icon: import("../../shared/utils/icon.js").ResolvedThemeIcon | null;
8
14
  }[]>;
9
15
  themeValues: import("vue").ComputedRef<string[]>;
10
16
  };
@@ -1,25 +1,40 @@
1
1
  import { computed } from "vue";
2
+ import { SYSTEM_THEME } from "../../shared/constants";
2
3
  import { resolveThemeIcon } from "../../shared/utils/icon";
4
+ import { isSelectableGroup } from "../../shared/utils/theme-resolve";
5
+ const MODE_ORDER = ["system", "dark", "light"];
3
6
  export const useThemeColors = (theme, translate, iconFormat = "svg") => {
4
7
  const themes = computed(() => {
5
- const list = Object.entries(theme.colors.themes).filter(([value]) => value !== "system").map(([value, themeConfig]) => ({
8
+ const list = Object.entries(theme.colors.groups).filter(([value]) => isSelectableGroup(theme.colors, value)).map(([value, group]) => ({
6
9
  value,
7
- name: translate(themeConfig.translations, value),
8
- icon: resolveThemeIcon(themeConfig.icon, iconFormat)
10
+ name: translate(group.translations, value),
11
+ icon: resolveThemeIcon(group.icon, iconFormat),
12
+ custom: group.custom === true
9
13
  }));
10
- const systemTheme = theme.colors.themes["system"];
11
- if (systemTheme) {
14
+ const hasSeasonal = Object.values(theme.colors.groups).some((group) => group.seasonal === true);
15
+ const systemTheme = theme.colors.groups[SYSTEM_THEME];
16
+ if (systemTheme && hasSeasonal) {
12
17
  list.unshift({
13
- value: "system",
14
- name: translate(systemTheme.translations, "System"),
15
- icon: resolveThemeIcon(systemTheme.icon, iconFormat)
18
+ value: SYSTEM_THEME,
19
+ name: translate(systemTheme.translations, "Automatic"),
20
+ icon: resolveThemeIcon(systemTheme.icon, iconFormat),
21
+ custom: false
16
22
  });
17
23
  }
18
24
  return list;
19
25
  });
20
- const themeValues = computed(() => themes.value.map((t) => t.value));
26
+ const modes = computed(() => MODE_ORDER.map((value) => {
27
+ const label = theme.colors.modes?.[value];
28
+ return {
29
+ value,
30
+ name: translate(label?.translations, value),
31
+ icon: resolveThemeIcon(label?.icon, iconFormat)
32
+ };
33
+ }));
34
+ const themeValues = computed(() => Object.keys(theme.colors.themes));
21
35
  return {
22
36
  themes,
37
+ modes,
23
38
  themeValues
24
39
  };
25
40
  };
@@ -1,7 +1,14 @@
1
- export declare const useThemeCookies: (localeCookieName?: string) => {
1
+ export interface UseThemeCookiesOptions {
2
+ localeCookieName?: string;
3
+ /** See `color.requireConsent` — when `false`, the theme cookies are always written. */
4
+ requireConsent?: boolean;
5
+ }
6
+ export declare const useThemeCookies: (options?: UseThemeCookiesOptions) => {
2
7
  preferenceCookie: import("nuxt/app").CookieRef<string>;
3
8
  resolvedCookie: import("nuxt/app").CookieRef<string>;
9
+ modeCookie: import("nuxt/app").CookieRef<string>;
4
10
  localeCookie: import("nuxt/app").CookieRef<string>;
5
- persistIfConsented: (preference: string, resolved: string) => void;
11
+ canPersist: () => boolean;
12
+ persistIfConsented: (preference: string, mode: string, resolved: string) => void;
6
13
  disablePersistence: () => void;
7
14
  };