@venix-sistemas/jade 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/README.md +969 -579
  2. package/dist/module.d.mts +8 -1
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +131 -9
  5. package/dist/runtime/components/VenixThemeSwitcher.d.vue.ts +7 -1
  6. package/dist/runtime/components/VenixThemeSwitcher.vue +679 -161
  7. package/dist/runtime/components/VenixThemeSwitcher.vue.d.ts +7 -1
  8. package/dist/runtime/composables/useThemeColors.d.ts +2 -2
  9. package/dist/runtime/composables/useThemeCookies.d.ts +12 -4
  10. package/dist/runtime/composables/useThemeCookies.js +20 -1
  11. package/dist/runtime/composables/useThemeLocale.d.ts +2 -2
  12. package/dist/runtime/composables/useThemeSeasonal.d.ts +2 -2
  13. package/dist/runtime/composables/useVenixTheme.d.ts +32 -0
  14. package/dist/runtime/composables/useVenixTheme.js +153 -9
  15. package/dist/runtime/plugins/overlay-scrollbars.client.d.ts +2 -0
  16. package/dist/runtime/plugins/overlay-scrollbars.client.js +89 -0
  17. package/dist/runtime/plugins/theme-init.server.d.ts +1 -1
  18. package/dist/runtime/plugins/vuetify-theme.d.ts +1 -1
  19. package/dist/runtime/scripts/theme-init.d.ts +12 -3
  20. package/dist/runtime/scripts/theme-init.js +21 -4
  21. package/dist/shared/constants.d.ts +55 -1
  22. package/dist/shared/constants.js +23 -1
  23. package/dist/shared/css/colors.d.ts +2 -2
  24. package/dist/shared/css/colors.js +7 -2
  25. package/dist/shared/css/cursor-svg.d.ts +10 -0
  26. package/dist/shared/css/cursor-svg.js +28 -0
  27. package/dist/shared/css/cursor.js +146 -37
  28. package/dist/shared/css/index.js +1 -1
  29. package/dist/shared/css/scrollbar.js +68 -8
  30. package/dist/shared/css/tokens.d.ts +40 -0
  31. package/dist/shared/css/tokens.js +119 -0
  32. package/dist/shared/css/typography.js +13 -0
  33. package/dist/shared/theme.json +320 -302
  34. package/dist/shared/token-names.d.ts +37 -0
  35. package/dist/shared/token-names.js +53 -0
  36. package/dist/shared/types/color-options.d.ts +23 -2
  37. package/dist/shared/types/colors.d.ts +38 -0
  38. package/dist/shared/types/cursor.d.ts +34 -4
  39. package/dist/shared/types/experimental.d.ts +19 -0
  40. package/dist/shared/types/experimental.js +0 -0
  41. package/dist/shared/types/index.d.ts +5 -3
  42. package/dist/shared/types/runtime-config.d.ts +39 -24
  43. package/dist/shared/types/scrollbar.d.ts +11 -0
  44. package/dist/shared/types/theme.d.ts +7 -0
  45. package/dist/shared/types/typography.d.ts +2 -1
  46. package/dist/shared/unocss-preset.d.ts +27 -1
  47. package/dist/shared/unocss-preset.js +20 -2
  48. package/dist/shared/utils/contrast.d.ts +11 -0
  49. package/dist/shared/utils/contrast.js +24 -0
  50. package/dist/shared/utils/index.d.ts +3 -2
  51. package/dist/shared/utils/index.js +3 -2
  52. package/dist/shared/utils/load.d.ts +2 -2
  53. package/dist/shared/utils/load.js +2 -1
  54. package/dist/shared/utils/merge-themes.d.ts +8 -0
  55. package/dist/shared/utils/merge-themes.js +25 -3
  56. package/dist/shared/utils/oklab.d.ts +21 -0
  57. package/dist/shared/utils/oklab.js +74 -0
  58. package/dist/shared/utils/scale.d.ts +53 -0
  59. package/dist/shared/utils/scale.js +164 -0
  60. package/dist/shared/utils/theme-config.d.ts +11 -3
  61. package/dist/shared/utils/theme-config.js +10 -2
  62. package/dist/shared/utils/theme-resolve.d.ts +11 -2
  63. package/dist/shared/utils/theme-resolve.js +18 -0
  64. package/dist/shared/utils/theme-resolver.d.ts +1 -0
  65. package/dist/shared/utils/theme-resolver.js +1 -0
  66. package/package.json +24 -9
@@ -3,7 +3,13 @@ type __VLS_Props = {
3
3
  label?: string;
4
4
  /** Shows the active theme's and mode's names next to the icon on the button. */
5
5
  showLabel?: boolean;
6
+ /** Hides "Save changes" in the settings, for a site whose own cookie banner already records consent. */
7
+ hideConsent?: boolean;
6
8
  };
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>;
9
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
10
+ "consent-needed": () => any;
11
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
12
+ "onConsent-needed"?: (() => any) | undefined;
13
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
8
14
  declare const _default: typeof __VLS_export;
9
15
  export default _default;
@@ -1,6 +1,6 @@
1
- import type { ThemeConfig } from '../../shared/types/index.js';
1
+ import type { ResolvedTheme } from '../../shared/types/index.js';
2
2
  import type { ThemeIconFormat } from '../../shared/utils/icon.js';
3
- export declare const useThemeColors: (theme: ThemeConfig, translate: (translations?: Record<string, string>, fallback?: string) => string, iconFormat?: ThemeIconFormat) => {
3
+ export declare const useThemeColors: (theme: ResolvedTheme, translate: (translations?: Record<string, string>, fallback?: string) => string, iconFormat?: ThemeIconFormat) => {
4
4
  themes: import("vue").ComputedRef<{
5
5
  value: string;
6
6
  name: string;
@@ -4,11 +4,19 @@ export interface UseThemeCookiesOptions {
4
4
  requireConsent?: boolean;
5
5
  }
6
6
  export declare const useThemeCookies: (options?: UseThemeCookiesOptions) => {
7
- preferenceCookie: import("nuxt/app").CookieRef<string>;
8
- resolvedCookie: import("nuxt/app").CookieRef<string>;
9
- modeCookie: import("nuxt/app").CookieRef<string>;
10
- localeCookie: import("nuxt/app").CookieRef<string>;
7
+ preferenceCookie: import("#app").CookieRef<string>;
8
+ resolvedCookie: import("#app").CookieRef<string>;
9
+ modeCookie: import("#app").CookieRef<string>;
10
+ localeCookie: import("#app").CookieRef<string>;
11
+ scrollbarCookie: import("#app").CookieRef<string>;
12
+ cursorCookie: import("#app").CookieRef<string>;
13
+ fontCookie: import("#app").CookieRef<string>;
11
14
  canPersist: () => boolean;
12
15
  persistIfConsented: (preference: string, mode: string, resolved: string) => void;
16
+ persistTogglesIfConsented: (toggles: {
17
+ scrollbar: boolean;
18
+ cursor: boolean;
19
+ font: boolean;
20
+ }) => void;
13
21
  disablePersistence: () => void;
14
22
  };
@@ -4,7 +4,10 @@ import {
4
4
  THEME_RESOLVED_COOKIE,
5
5
  THEME_MODE_COOKIE,
6
6
  THEME_COOKIE_OPTIONS,
7
- DEFAULT_LOCALE_COOKIE_NAME
7
+ DEFAULT_LOCALE_COOKIE_NAME,
8
+ SCROLLBAR_COOKIE,
9
+ CURSOR_COOKIE,
10
+ FONT_COOKIE
8
11
  } from "../../shared/constants";
9
12
  import { hasCookieConsent } from "../../shared/utils/consent";
10
13
  let warnedMissingConsent = false;
@@ -14,6 +17,9 @@ export const useThemeCookies = (options = {}) => {
14
17
  const resolvedCookie = useCookie(THEME_RESOLVED_COOKIE, THEME_COOKIE_OPTIONS);
15
18
  const modeCookie = useCookie(THEME_MODE_COOKIE, THEME_COOKIE_OPTIONS);
16
19
  const localeCookie = useCookie(localeCookieName, THEME_COOKIE_OPTIONS);
20
+ const scrollbarCookie = useCookie(SCROLLBAR_COOKIE, THEME_COOKIE_OPTIONS);
21
+ const cursorCookie = useCookie(CURSOR_COOKIE, THEME_COOKIE_OPTIONS);
22
+ const fontCookie = useCookie(FONT_COOKIE, THEME_COOKIE_OPTIONS);
17
23
  const removeCookie = (name) => {
18
24
  if (typeof document !== "undefined") {
19
25
  document.cookie = `${name}=; path=/; max-age=0; SameSite=Lax`;
@@ -34,18 +40,31 @@ export const useThemeCookies = (options = {}) => {
34
40
  modeCookie.value = mode;
35
41
  resolvedCookie.value = resolved;
36
42
  };
43
+ const persistTogglesIfConsented = (toggles) => {
44
+ if (!canPersist()) return;
45
+ scrollbarCookie.value = toggles.scrollbar ? "on" : "off";
46
+ cursorCookie.value = toggles.cursor ? "on" : "off";
47
+ fontCookie.value = toggles.font ? "on" : "off";
48
+ };
37
49
  const disablePersistence = () => {
38
50
  removeCookie(THEME_PREFERENCE_COOKIE);
39
51
  removeCookie(THEME_RESOLVED_COOKIE);
40
52
  removeCookie(THEME_MODE_COOKIE);
53
+ removeCookie(SCROLLBAR_COOKIE);
54
+ removeCookie(CURSOR_COOKIE);
55
+ removeCookie(FONT_COOKIE);
41
56
  };
42
57
  return {
43
58
  preferenceCookie,
44
59
  resolvedCookie,
45
60
  modeCookie,
46
61
  localeCookie,
62
+ scrollbarCookie,
63
+ cursorCookie,
64
+ fontCookie,
47
65
  canPersist,
48
66
  persistIfConsented,
67
+ persistTogglesIfConsented,
49
68
  disablePersistence
50
69
  };
51
70
  };
@@ -1,5 +1,5 @@
1
1
  import type { Ref } from 'vue';
2
- import type { ThemeConfig } from '../../shared/types/index.js';
2
+ import type { ResolvedTheme } from '../../shared/types/index.js';
3
3
  export interface UseThemeLocaleOptions {
4
4
  enabled?: boolean;
5
5
  forcedLocale?: string;
@@ -10,7 +10,7 @@ export interface UseThemeLocaleOptions {
10
10
  */
11
11
  canPersist?: () => boolean;
12
12
  }
13
- export declare const useThemeLocale: (theme: ThemeConfig, localeCookie: Ref<string | undefined>, options?: UseThemeLocaleOptions) => {
13
+ export declare const useThemeLocale: (theme: ResolvedTheme, localeCookie: Ref<string | undefined>, options?: UseThemeLocaleOptions) => {
14
14
  currentLocale: Ref<string, string>;
15
15
  translate: (translations?: Record<string, string>, fallback?: string) => string;
16
16
  setLocale: (locale: string) => void;
@@ -1,4 +1,4 @@
1
- import type { ThemeConfig, ThemeMode } from '../../shared/types/index.js';
2
- export declare const useThemeSeasonal: (theme: ThemeConfig) => {
1
+ import type { ResolvedTheme, ThemeMode } from '../../shared/types/index.js';
2
+ export declare const useThemeSeasonal: (theme: ResolvedTheme) => {
3
3
  getActiveSeasonalTheme: (mode?: ThemeMode) => string | null;
4
4
  };
@@ -22,6 +22,18 @@ export declare const useVenixTheme: () => {
22
22
  icon: import("../../shared/utils/icon.js").ResolvedThemeIcon | null;
23
23
  custom: boolean;
24
24
  }[]>;
25
+ /**
26
+ * The semantic color tokens (experimental, v1.4.0) of the themes with
27
+ * `tokens: true`. `current` follows the applied theme and is `undefined`
28
+ * when it has none; `all` is every variant's tokens by `data-theme` id.
29
+ * `cssVar('text-primary')` is `'var(--jade-text-primary)'`, to use in
30
+ * styles that should follow the theme without reading the value.
31
+ */
32
+ tokens: {
33
+ all: Record<string, Record<string, string> | undefined>;
34
+ current: import("vue").ComputedRef<Record<string, string> | undefined>;
35
+ cssVar: (name: string) => string;
36
+ };
25
37
  mode: {
26
38
  value: import("vue").ComputedRef<ThemeMode>;
27
39
  preference: import("vue").Ref<ThemeModePreference, ThemeModePreference>;
@@ -38,12 +50,32 @@ export declare const useVenixTheme: () => {
38
50
  name: string;
39
51
  icon: import("../../shared/utils/icon.js").ResolvedThemeIcon | null;
40
52
  }[]>;
53
+ /** The custom scrollbar: `available` when the project has it on, `enabled` unless the visitor turned it off. */
54
+ scrollbar: {
55
+ available: boolean;
56
+ enabled: import("vue").Ref<boolean, boolean>;
57
+ set: (enabled: boolean) => void;
58
+ };
59
+ /** The custom cursor, same as `scrollbar`. */
60
+ cursor: {
61
+ available: boolean;
62
+ enabled: import("vue").Ref<boolean, boolean>;
63
+ set: (enabled: boolean) => void;
64
+ };
65
+ /** The custom font (`typography.customFonts`), same as `scrollbar`: off leaves the `defaultFonts`. */
66
+ font: {
67
+ available: boolean;
68
+ enabled: import("vue").Ref<boolean, boolean>;
69
+ set: (enabled: boolean) => void;
70
+ };
41
71
  locale: {
42
72
  current: import("vue").Ref<string, string>;
43
73
  set: (locale: string) => void;
44
74
  translate: (translations?: Record<string, string>, fallback?: string) => string;
45
75
  };
46
76
  persistence: {
77
+ /** `color.requireConsent`: whether changes are only saved after consent. */
78
+ required: boolean;
47
79
  hasConsent: import("vue").Ref<boolean, boolean>;
48
80
  grant: () => void;
49
81
  revoke: () => void;
@@ -1,6 +1,6 @@
1
1
  import { computed, effectScope, watch } from "vue";
2
2
  import { onNuxtReady, useNuxtApp, useRuntimeConfig, useState } from "#app";
3
- import { DEFAULT_LOCALE, COOKIE_PREFERENCES_UPDATED_EVENT, COOKIE_CONSENT_STORAGE_KEY, THEME_APPLIED_EVENT, SYSTEM_THEME } from "../../shared/constants";
3
+ import { DEFAULT_LOCALE, COOKIE_PREFERENCES_UPDATED_EVENT, COOKIE_CONSENT_STORAGE_KEY, THEME_APPLIED_EVENT, SYSTEM_THEME, SCROLLBAR_ATTRIBUTE, CURSOR_ATTRIBUTE, FONT_ATTRIBUTE, THEME_PREFERENCE_COOKIE, THEME_MODE_COOKIE, SCROLLBAR_COOKIE, CURSOR_COOKIE, FONT_COOKIE } from "../../shared/constants";
4
4
  import { useThemeCookies } from "./useThemeCookies.js";
5
5
  import { useThemeLocale } from "./useThemeLocale.js";
6
6
  import { useThemeSeasonal } from "./useThemeSeasonal.js";
@@ -34,6 +34,31 @@ function createThemeCore() {
34
34
  const preference = useState("venix-theme-preference", () => initialSelection.theme);
35
35
  const modePreference = useState("venix-theme-mode", () => initialSelection.mode);
36
36
  const currentSelection = () => ({ theme: preference.value, mode: modePreference.value });
37
+ const requireConsent = themeConfig?.requireConsent !== false;
38
+ const scrollbarAvailable = themeConfig?.enabled?.scrollbar !== false;
39
+ const cursorAvailable = themeConfig?.enabled?.cursor !== false;
40
+ const fontAvailable = themeConfig?.enabled?.customFont === true;
41
+ const scrollbarEnabled = useState("venix-scrollbar", () => cookies.scrollbarCookie.value !== "off");
42
+ const cursorEnabled = useState("venix-cursor", () => cookies.cursorCookie.value !== "off");
43
+ const fontEnabled = useState("venix-font", () => cookies.fontCookie.value !== "off");
44
+ const applyToggles = () => {
45
+ if (typeof document === "undefined") return;
46
+ const html = document.documentElement;
47
+ const flags = [
48
+ [SCROLLBAR_ATTRIBUTE, scrollbarEnabled.value],
49
+ [CURSOR_ATTRIBUTE, cursorEnabled.value],
50
+ [FONT_ATTRIBUTE, fontEnabled.value]
51
+ ];
52
+ for (const [attribute, enabled] of flags) {
53
+ if (enabled) html.removeAttribute(attribute);
54
+ else html.setAttribute(attribute, "off");
55
+ }
56
+ };
57
+ const persistToggles = () => cookies.persistTogglesIfConsented({
58
+ scrollbar: scrollbarEnabled.value,
59
+ cursor: cursorEnabled.value,
60
+ font: fontEnabled.value
61
+ });
37
62
  const environmentVersion = useState("venix-theme-environment", () => 0);
38
63
  const getPrefersDark = () => typeof window !== "undefined" ? window.matchMedia("(prefers-color-scheme: dark)").matches : true;
39
64
  const getResolvedTheme = (selection = currentSelection()) => resolveThemeSelection(selection, theme.colors, getPrefersDark());
@@ -56,13 +81,18 @@ function createThemeCore() {
56
81
  return;
57
82
  }
58
83
  const body = document.body;
59
- const hasCustomCursor = theme.customCursor?.enabled !== false && !!theme.customCursor?.cursors;
60
- const currentCursor = hasCustomCursor ? getComputedStyle(body).cursor : null;
61
- if (currentCursor && currentCursor !== "auto") {
62
- body.style.setProperty("cursor", currentCursor, "important");
63
- }
84
+ const hasCustomCursor = cursorAvailable && cursorEnabled.value && window.matchMedia("(any-pointer: fine)").matches;
85
+ const pinCursor = () => {
86
+ body.style.removeProperty("cursor");
87
+ const cursor = getComputedStyle(body).cursor;
88
+ if (cursor && cursor !== "auto") body.style.setProperty("cursor", cursor, "important");
89
+ };
90
+ if (hasCustomCursor) pinCursor();
64
91
  const restoreCursor = () => body.style.removeProperty("cursor");
65
- const transition = document.startViewTransition(() => apply(selection));
92
+ const transition = document.startViewTransition(() => {
93
+ apply(selection);
94
+ if (hasCustomCursor) pinCursor();
95
+ });
66
96
  transition.ready.catch(() => {
67
97
  });
68
98
  transition.finished.then(restoreCursor).catch(restoreCursor);
@@ -71,6 +101,7 @@ function createThemeCore() {
71
101
  hasConsent.value = hasCookieConsent();
72
102
  if (cookies.canPersist()) {
73
103
  cookies.persistIfConsented(preference.value, modePreference.value, getResolvedTheme());
104
+ persistToggles();
74
105
  } else {
75
106
  cookies.disablePersistence();
76
107
  }
@@ -134,7 +165,16 @@ function createThemeCore() {
134
165
  theme,
135
166
  shouldApplyColors,
136
167
  cookies,
168
+ requireConsent,
137
169
  hasConsent,
170
+ scrollbarAvailable,
171
+ cursorAvailable,
172
+ fontAvailable,
173
+ scrollbarEnabled,
174
+ cursorEnabled,
175
+ fontEnabled,
176
+ applyToggles,
177
+ persistToggles,
138
178
  locale,
139
179
  colors,
140
180
  preference,
@@ -159,14 +199,34 @@ function createThemeCore() {
159
199
  isSeasonalActive
160
200
  };
161
201
  }
202
+ function readDocumentCookie(name) {
203
+ for (const part of document.cookie.split(";")) {
204
+ const separator = part.indexOf("=");
205
+ if (separator === -1 || part.slice(0, separator).trim() !== name) continue;
206
+ let value = part.slice(separator + 1).trim();
207
+ try {
208
+ value = decodeURIComponent(value);
209
+ } catch {
210
+ return value;
211
+ }
212
+ try {
213
+ const parsed = JSON.parse(value);
214
+ return typeof parsed === "string" ? parsed : value;
215
+ } catch {
216
+ return value;
217
+ }
218
+ }
219
+ return void 0;
220
+ }
162
221
  function installThemeEffects(core) {
163
- const { themeConfig, shouldApplyColors, cookies, hasConsent, locale, preference, modePreference, environmentVersion } = core;
222
+ const { themeConfig, shouldApplyColors, cookies, hasConsent, locale, preference, modePreference, environmentVersion, scrollbarEnabled, cursorEnabled, fontEnabled } = core;
164
223
  if (themeConfig?.enabled?.manageHtmlLang) {
165
224
  document.documentElement.lang = locale.currentLocale.value;
166
225
  watch(locale.currentLocale, (newLocale) => {
167
226
  document.documentElement.lang = newLocale;
168
227
  });
169
228
  }
229
+ let skipNextThemePersist = false;
170
230
  if (shouldApplyColors) {
171
231
  if (cookies.preferenceCookie.value || cookies.modeCookie.value) {
172
232
  const fromCookies = core.readCookieSelection();
@@ -179,12 +239,54 @@ function installThemeEffects(core) {
179
239
  watch([preference, modePreference], () => {
180
240
  const selection = core.currentSelection();
181
241
  core.applyWithTransition(selection);
242
+ if (skipNextThemePersist) {
243
+ skipNextThemePersist = false;
244
+ return;
245
+ }
182
246
  cookies.persistIfConsented(selection.theme, selection.mode, core.getResolvedTheme(selection));
183
247
  });
184
248
  }
249
+ const syncFromCookies = () => {
250
+ if (!cookies.canPersist()) return;
251
+ if (shouldApplyColors) {
252
+ const themeRaw = readDocumentCookie(THEME_PREFERENCE_COOKIE);
253
+ const modeRaw = readDocumentCookie(THEME_MODE_COOKIE);
254
+ if (themeRaw !== void 0 || modeRaw !== void 0) {
255
+ const fromCookies = normalizeThemeSelection(themeRaw, modeRaw, core.theme.colors);
256
+ if (fromCookies.theme !== preference.value || fromCookies.mode !== modePreference.value) {
257
+ skipNextThemePersist = true;
258
+ preference.value = fromCookies.theme;
259
+ modePreference.value = fromCookies.mode;
260
+ }
261
+ }
262
+ }
263
+ const toggles = [
264
+ [SCROLLBAR_COOKIE, scrollbarEnabled],
265
+ [CURSOR_COOKIE, cursorEnabled],
266
+ [FONT_COOKIE, fontEnabled]
267
+ ];
268
+ for (const [name, state] of toggles) {
269
+ const raw = readDocumentCookie(name);
270
+ if (raw !== void 0 && raw !== "off" !== state.value) state.value = raw !== "off";
271
+ }
272
+ };
273
+ scrollbarEnabled.value = cookies.scrollbarCookie.value !== "off";
274
+ cursorEnabled.value = cookies.cursorCookie.value !== "off";
275
+ fontEnabled.value = cookies.fontCookie.value !== "off";
276
+ core.applyToggles();
277
+ watch([scrollbarEnabled, cursorEnabled, fontEnabled], () => {
278
+ core.applyToggles();
279
+ core.persistToggles();
280
+ });
185
281
  onNuxtReady(() => {
186
282
  hasConsent.value = hasCookieConsent();
187
283
  window.addEventListener(COOKIE_PREFERENCES_UPDATED_EVENT, core.syncPersistence);
284
+ const cookieStore = window.cookieStore;
285
+ cookieStore?.addEventListener("change", syncFromCookies);
286
+ window.addEventListener("focus", syncFromCookies);
287
+ document.addEventListener("visibilitychange", () => {
288
+ if (document.visibilityState === "visible") syncFromCookies();
289
+ });
188
290
  if (!shouldApplyColors) return;
189
291
  window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
190
292
  environmentVersion.value++;
@@ -211,6 +313,7 @@ export const useVenixTheme = () => {
211
313
  effectScope(true).run(() => installThemeEffects(createThemeCore()));
212
314
  }
213
315
  }
316
+ const tokensByTheme = core.themeConfig?.tokens ?? {};
214
317
  return {
215
318
  theme: {
216
319
  value: core.resolvedTheme,
@@ -224,6 +327,18 @@ export const useVenixTheme = () => {
224
327
  colors: core.theme.colors
225
328
  },
226
329
  themes: core.colors.themes,
330
+ /**
331
+ * The semantic color tokens (experimental, v1.4.0) of the themes with
332
+ * `tokens: true`. `current` follows the applied theme and is `undefined`
333
+ * when it has none; `all` is every variant's tokens by `data-theme` id.
334
+ * `cssVar('text-primary')` is `'var(--jade-text-primary)'`, to use in
335
+ * styles that should follow the theme without reading the value.
336
+ */
337
+ tokens: {
338
+ all: tokensByTheme,
339
+ current: computed(() => tokensByTheme[core.resolvedTheme.value]),
340
+ cssVar: (name) => `var(--jade-${name})`
341
+ },
227
342
  mode: {
228
343
  value: core.resolvedMode,
229
344
  preference: core.modePreference,
@@ -232,16 +347,45 @@ export const useVenixTheme = () => {
232
347
  toggle: core.toggleMode
233
348
  },
234
349
  modes: core.colors.modes,
350
+ /** The custom scrollbar: `available` when the project has it on, `enabled` unless the visitor turned it off. */
351
+ scrollbar: {
352
+ available: core.scrollbarAvailable,
353
+ enabled: core.scrollbarEnabled,
354
+ set: (enabled) => {
355
+ core.scrollbarEnabled.value = enabled;
356
+ }
357
+ },
358
+ /** The custom cursor, same as `scrollbar`. */
359
+ cursor: {
360
+ available: core.cursorAvailable,
361
+ enabled: core.cursorEnabled,
362
+ set: (enabled) => {
363
+ core.cursorEnabled.value = enabled;
364
+ }
365
+ },
366
+ /** The custom font (`typography.customFonts`), same as `scrollbar`: off leaves the `defaultFonts`. */
367
+ font: {
368
+ available: core.fontAvailable,
369
+ enabled: core.fontEnabled,
370
+ set: (enabled) => {
371
+ core.fontEnabled.value = enabled;
372
+ }
373
+ },
235
374
  locale: {
236
375
  current: core.locale.currentLocale,
237
376
  set: core.locale.setLocale,
238
377
  translate: core.locale.translate
239
378
  },
240
379
  persistence: {
380
+ /** `color.requireConsent`: whether changes are only saved after consent. */
381
+ required: core.requireConsent,
241
382
  hasConsent: core.hasConsent,
242
383
  grant: () => core.setConsent(true),
243
384
  revoke: () => core.setConsent(false),
244
- enable: () => core.cookies.persistIfConsented(core.preference.value, core.modePreference.value, core.getResolvedTheme()),
385
+ enable: () => {
386
+ core.cookies.persistIfConsented(core.preference.value, core.modePreference.value, core.getResolvedTheme());
387
+ core.persistToggles();
388
+ },
245
389
  disable: core.cookies.disablePersistence
246
390
  }
247
391
  };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -0,0 +1,89 @@
1
+ import { defineNuxtPlugin } from "#app";
2
+ import { OverlayScrollbars, ClickScrollPlugin } from "overlayscrollbars";
3
+ import { OVERLAY_SCROLLBAR_THEME, SCROLL_CONTAINER_ATTRIBUTE, SCROLLBAR_ATTRIBUTE } from "../../shared/constants";
4
+ const CONTAINERS = [
5
+ ".v-navigation-drawer__content",
6
+ ".v-dialog--scrollable .v-card-text",
7
+ ".v-select__content .v-list",
8
+ ".v-table__wrapper",
9
+ `[${SCROLL_CONTAINER_ATTRIBUTE}]`
10
+ ].join(", ");
11
+ const OPTIONS = {
12
+ scrollbars: { theme: OVERLAY_SCROLLBAR_THEME, autoHide: "never", clickScroll: true }
13
+ };
14
+ const SCROLL_BLOCKED_CLASS = "v-overlay-scroll-blocked";
15
+ const isOn = () => document.documentElement.getAttribute(SCROLLBAR_ATTRIBUTE) !== "off";
16
+ function followScrollBlock(instance, el) {
17
+ let previous;
18
+ const sync = () => {
19
+ const blocked = el.classList.contains(SCROLL_BLOCKED_CLASS);
20
+ if (blocked && !previous) {
21
+ previous = { ...instance.options().overflow };
22
+ instance.options({ overflow: { x: "hidden", y: "hidden" } });
23
+ } else if (!blocked && previous) {
24
+ instance.options({ overflow: previous });
25
+ previous = void 0;
26
+ }
27
+ };
28
+ const observer = new MutationObserver(sync);
29
+ observer.observe(el, { attributes: true, attributeFilter: ["class"] });
30
+ instance.on("destroyed", () => observer.disconnect());
31
+ }
32
+ function initPage() {
33
+ if (OverlayScrollbars(document.body)) return;
34
+ const instance = OverlayScrollbars(document.body, OPTIONS);
35
+ followScrollBlock(instance, document.documentElement);
36
+ }
37
+ function initContainer(el) {
38
+ const slot = el.parentElement;
39
+ if (OverlayScrollbars(el) || !slot) return;
40
+ if (getComputedStyle(slot).position === "static") slot.style.position = "relative";
41
+ const instance = OverlayScrollbars({ target: el, elements: { viewport: el }, scrollbars: { slot } }, OPTIONS);
42
+ alignScrollbars(instance, el, slot);
43
+ followScrollBlock(instance, el);
44
+ }
45
+ function alignScrollbars(instance, el, slot) {
46
+ const { scrollbarVertical, scrollbarHorizontal } = instance.elements();
47
+ for (const { scrollbar } of [scrollbarVertical, scrollbarHorizontal]) {
48
+ scrollbar.style.transition = "opacity 0.15s, visibility 0.15s";
49
+ }
50
+ const align = () => {
51
+ const top = el.offsetTop;
52
+ const left = el.offsetLeft;
53
+ const bottom = slot.clientHeight - top - el.offsetHeight;
54
+ const right = slot.clientWidth - left - el.offsetWidth;
55
+ Object.assign(scrollbarVertical.scrollbar.style, { top: `${top}px`, bottom: `${bottom}px`, right: `${right}px` });
56
+ Object.assign(scrollbarHorizontal.scrollbar.style, { left: `${left}px`, right: `${right}px`, bottom: `${bottom}px` });
57
+ };
58
+ align();
59
+ const observer = new ResizeObserver(align);
60
+ observer.observe(el);
61
+ observer.observe(slot);
62
+ instance.on("destroyed", () => observer.disconnect());
63
+ }
64
+ function containersIn(root) {
65
+ const found = [...root.querySelectorAll(CONTAINERS)];
66
+ return root.matches(CONTAINERS) ? [root, ...found] : found;
67
+ }
68
+ function initAll() {
69
+ initPage();
70
+ containersIn(document.body).forEach(initContainer);
71
+ }
72
+ function destroyAll() {
73
+ containersIn(document.body).forEach((el) => OverlayScrollbars(el)?.destroy());
74
+ OverlayScrollbars(document.body)?.destroy();
75
+ }
76
+ export default defineNuxtPlugin((nuxtApp) => {
77
+ OverlayScrollbars.plugin(ClickScrollPlugin);
78
+ nuxtApp.hook("app:mounted", () => {
79
+ if (isOn()) initAll();
80
+ new MutationObserver((mutations) => {
81
+ if (!isOn()) return;
82
+ for (const mutation of mutations) {
83
+ mutation.addedNodes.forEach((node) => node instanceof Element && containersIn(node).forEach(initContainer));
84
+ mutation.removedNodes.forEach((node) => node instanceof Element && containersIn(node).forEach((el) => OverlayScrollbars(el)?.destroy()));
85
+ }
86
+ }).observe(document.body, { childList: true, subtree: true });
87
+ new MutationObserver(() => isOn() ? initAll() : destroyAll()).observe(document.documentElement, { attributes: true, attributeFilter: [SCROLLBAR_ATTRIBUTE] });
88
+ });
89
+ });
@@ -1,2 +1,2 @@
1
- declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
1
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
2
  export default _default;
@@ -1,2 +1,2 @@
1
- declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
1
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
2
  export default _default;
@@ -1,4 +1,4 @@
1
- import type { ThemeConfig } from '../../shared/types/index.js';
1
+ import type { ResolvedTheme } from '../../shared/types/index.js';
2
2
  import type { ThemeResolver } from '../../shared/utils/theme-resolver.js';
3
3
  declare global {
4
4
  interface Window {
@@ -12,10 +12,19 @@ export interface InitThemeOptions {
12
12
  preference: string;
13
13
  mode: string;
14
14
  resolved: string;
15
+ scrollbar: string;
16
+ cursor: string;
17
+ font: string;
15
18
  };
16
19
  /** In seconds. */
17
20
  cookieMaxAge: number;
18
21
  consentStorageKey: string;
22
+ /** The `<html>` attributes that switch the custom scrollbar, cursor and font off. */
23
+ attributes: {
24
+ scrollbar: string;
25
+ cursor: string;
26
+ font: string;
27
+ };
19
28
  }
20
29
  /**
21
30
  * Runs as an inline script in `<head>`, injected via Nitro's `render:html`
@@ -34,7 +43,7 @@ export interface InitThemeOptions {
34
43
  * self-contained) `createThemeResolver` factory, and the cookie names and
35
44
  * settings from `shared/constants.ts` in `options`.
36
45
  */
37
- export default function initTheme(createThemeResolver: () => ThemeResolver, themeData: ThemeConfig, options: InitThemeOptions): void;
46
+ export default function initTheme(createThemeResolver: () => ThemeResolver, themeData: ResolvedTheme, options: InitThemeOptions): void;
38
47
  export declare function createInitThemeOptions(requireConsent: boolean): InitThemeOptions;
39
48
  /** The inline script's source: `initTheme` as an IIFE, with its arguments serialized. */
40
- export declare function renderInitThemeScript(themeData: ThemeConfig, options: InitThemeOptions): string;
49
+ export declare function renderInitThemeScript(themeData: ResolvedTheme, options: InitThemeOptions): string;
@@ -5,11 +5,17 @@ import {
5
5
  THEME_MODE_COOKIE,
6
6
  THEME_RESOLVED_COOKIE,
7
7
  THEME_COOKIE_MAX_AGE,
8
- COOKIE_CONSENT_STORAGE_KEY
8
+ COOKIE_CONSENT_STORAGE_KEY,
9
+ SCROLLBAR_COOKIE,
10
+ CURSOR_COOKIE,
11
+ FONT_COOKIE,
12
+ SCROLLBAR_ATTRIBUTE,
13
+ CURSOR_ATTRIBUTE,
14
+ FONT_ATTRIBUTE
9
15
  } from "../../shared/constants";
10
16
  export default function initTheme(createThemeResolver2, themeData, options) {
11
17
  const resolver = createThemeResolver2();
12
- const { requireConsent, cookies, cookieMaxAge, consentStorageKey } = options;
18
+ const { requireConsent, cookies, cookieMaxAge, consentStorageKey, attributes } = options;
13
19
  function hasCookieConsent() {
14
20
  if (typeof localStorage === "undefined") return false;
15
21
  const consentData = localStorage.getItem(consentStorageKey);
@@ -46,6 +52,9 @@ export default function initTheme(createThemeResolver2, themeData, options) {
46
52
  html.classList.add(theme);
47
53
  html.setAttribute("data-theme", theme);
48
54
  window.__VENIX_INITIAL_THEME__ = theme;
55
+ for (const toggle of ["scrollbar", "cursor", "font"]) {
56
+ if (getCookie(cookies[toggle]) === "off") html.setAttribute(attributes[toggle], "off");
57
+ }
49
58
  if (resolvedCookie !== theme) {
50
59
  setCookieIfConsented(cookies.resolved, theme);
51
60
  }
@@ -59,9 +68,17 @@ export default function initTheme(createThemeResolver2, themeData, options) {
59
68
  export function createInitThemeOptions(requireConsent) {
60
69
  return {
61
70
  requireConsent,
62
- cookies: { preference: THEME_PREFERENCE_COOKIE, mode: THEME_MODE_COOKIE, resolved: THEME_RESOLVED_COOKIE },
71
+ cookies: {
72
+ preference: THEME_PREFERENCE_COOKIE,
73
+ mode: THEME_MODE_COOKIE,
74
+ resolved: THEME_RESOLVED_COOKIE,
75
+ scrollbar: SCROLLBAR_COOKIE,
76
+ cursor: CURSOR_COOKIE,
77
+ font: FONT_COOKIE
78
+ },
63
79
  cookieMaxAge: THEME_COOKIE_MAX_AGE,
64
- consentStorageKey: COOKIE_CONSENT_STORAGE_KEY
80
+ consentStorageKey: COOKIE_CONSENT_STORAGE_KEY,
81
+ attributes: { scrollbar: SCROLLBAR_ATTRIBUTE, cursor: CURSOR_ATTRIBUTE, font: FONT_ATTRIBUTE }
65
82
  };
66
83
  }
67
84
  export function renderInitThemeScript(themeData, options) {