@venix-sistemas/jade 1.2.0 → 1.3.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 (40) hide show
  1. package/README.md +367 -157
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +66 -4
  4. package/dist/runtime/components/VenixThemeSwitcher.d.vue.ts +2 -0
  5. package/dist/runtime/components/VenixThemeSwitcher.vue +413 -70
  6. package/dist/runtime/components/VenixThemeSwitcher.vue.d.ts +2 -0
  7. package/dist/runtime/composables/useThemeColors.d.ts +2 -2
  8. package/dist/runtime/composables/useThemeCookies.d.ts +8 -0
  9. package/dist/runtime/composables/useThemeCookies.js +20 -1
  10. package/dist/runtime/composables/useThemeLocale.d.ts +2 -2
  11. package/dist/runtime/composables/useThemeSeasonal.d.ts +2 -2
  12. package/dist/runtime/composables/useVenixTheme.d.ts +20 -0
  13. package/dist/runtime/composables/useVenixTheme.js +86 -9
  14. package/dist/runtime/plugins/overlay-scrollbars.client.d.ts +2 -0
  15. package/dist/runtime/plugins/overlay-scrollbars.client.js +89 -0
  16. package/dist/runtime/scripts/theme-init.d.ts +12 -3
  17. package/dist/runtime/scripts/theme-init.js +21 -4
  18. package/dist/shared/constants.d.ts +54 -0
  19. package/dist/shared/constants.js +20 -0
  20. package/dist/shared/css/cursor-svg.d.ts +10 -0
  21. package/dist/shared/css/cursor-svg.js +28 -0
  22. package/dist/shared/css/cursor.js +78 -33
  23. package/dist/shared/css/scrollbar.js +61 -7
  24. package/dist/shared/css/typography.js +13 -0
  25. package/dist/shared/theme.json +14 -8
  26. package/dist/shared/types/cursor.d.ts +34 -4
  27. package/dist/shared/types/index.d.ts +2 -2
  28. package/dist/shared/types/runtime-config.d.ts +1 -0
  29. package/dist/shared/types/scrollbar.d.ts +11 -0
  30. package/dist/shared/types/theme.d.ts +7 -0
  31. package/dist/shared/types/typography.d.ts +2 -1
  32. package/dist/shared/utils/load.d.ts +2 -2
  33. package/dist/shared/utils/load.js +2 -1
  34. package/dist/shared/utils/theme-config.d.ts +3 -3
  35. package/dist/shared/utils/theme-config.js +0 -1
  36. package/dist/shared/utils/theme-resolve.d.ts +11 -2
  37. package/dist/shared/utils/theme-resolve.js +18 -0
  38. package/dist/shared/utils/theme-resolver.d.ts +1 -0
  39. package/dist/shared/utils/theme-resolver.js +1 -0
  40. package/package.json +10 -1
@@ -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
  };
@@ -38,12 +38,32 @@ export declare const useVenixTheme: () => {
38
38
  name: string;
39
39
  icon: import("../../shared/utils/icon.js").ResolvedThemeIcon | null;
40
40
  }[]>;
41
+ /** The custom scrollbar: `available` when the project has it on, `enabled` unless the visitor turned it off. */
42
+ scrollbar: {
43
+ available: boolean;
44
+ enabled: import("vue").Ref<boolean, boolean>;
45
+ set: (enabled: boolean) => void;
46
+ };
47
+ /** The custom cursor, same as `scrollbar`. */
48
+ cursor: {
49
+ available: boolean;
50
+ enabled: import("vue").Ref<boolean, boolean>;
51
+ set: (enabled: boolean) => void;
52
+ };
53
+ /** The custom font (`typography.customFonts`), same as `scrollbar`: off leaves the `defaultFonts`. */
54
+ font: {
55
+ available: boolean;
56
+ enabled: import("vue").Ref<boolean, boolean>;
57
+ set: (enabled: boolean) => void;
58
+ };
41
59
  locale: {
42
60
  current: import("vue").Ref<string, string>;
43
61
  set: (locale: string) => void;
44
62
  translate: (translations?: Record<string, string>, fallback?: string) => string;
45
63
  };
46
64
  persistence: {
65
+ /** `color.requireConsent`: whether changes are only saved after consent. */
66
+ required: boolean;
47
67
  hasConsent: import("vue").Ref<boolean, boolean>;
48
68
  grant: () => void;
49
69
  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 } 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,
@@ -160,7 +200,7 @@ function createThemeCore() {
160
200
  };
161
201
  }
162
202
  function installThemeEffects(core) {
163
- const { themeConfig, shouldApplyColors, cookies, hasConsent, locale, preference, modePreference, environmentVersion } = core;
203
+ const { themeConfig, shouldApplyColors, cookies, hasConsent, locale, preference, modePreference, environmentVersion, scrollbarEnabled, cursorEnabled, fontEnabled } = core;
164
204
  if (themeConfig?.enabled?.manageHtmlLang) {
165
205
  document.documentElement.lang = locale.currentLocale.value;
166
206
  watch(locale.currentLocale, (newLocale) => {
@@ -182,6 +222,14 @@ function installThemeEffects(core) {
182
222
  cookies.persistIfConsented(selection.theme, selection.mode, core.getResolvedTheme(selection));
183
223
  });
184
224
  }
225
+ scrollbarEnabled.value = cookies.scrollbarCookie.value !== "off";
226
+ cursorEnabled.value = cookies.cursorCookie.value !== "off";
227
+ fontEnabled.value = cookies.fontCookie.value !== "off";
228
+ core.applyToggles();
229
+ watch([scrollbarEnabled, cursorEnabled, fontEnabled], () => {
230
+ core.applyToggles();
231
+ core.persistToggles();
232
+ });
185
233
  onNuxtReady(() => {
186
234
  hasConsent.value = hasCookieConsent();
187
235
  window.addEventListener(COOKIE_PREFERENCES_UPDATED_EVENT, core.syncPersistence);
@@ -232,16 +280,45 @@ export const useVenixTheme = () => {
232
280
  toggle: core.toggleMode
233
281
  },
234
282
  modes: core.colors.modes,
283
+ /** The custom scrollbar: `available` when the project has it on, `enabled` unless the visitor turned it off. */
284
+ scrollbar: {
285
+ available: core.scrollbarAvailable,
286
+ enabled: core.scrollbarEnabled,
287
+ set: (enabled) => {
288
+ core.scrollbarEnabled.value = enabled;
289
+ }
290
+ },
291
+ /** The custom cursor, same as `scrollbar`. */
292
+ cursor: {
293
+ available: core.cursorAvailable,
294
+ enabled: core.cursorEnabled,
295
+ set: (enabled) => {
296
+ core.cursorEnabled.value = enabled;
297
+ }
298
+ },
299
+ /** The custom font (`typography.customFonts`), same as `scrollbar`: off leaves the `defaultFonts`. */
300
+ font: {
301
+ available: core.fontAvailable,
302
+ enabled: core.fontEnabled,
303
+ set: (enabled) => {
304
+ core.fontEnabled.value = enabled;
305
+ }
306
+ },
235
307
  locale: {
236
308
  current: core.locale.currentLocale,
237
309
  set: core.locale.setLocale,
238
310
  translate: core.locale.translate
239
311
  },
240
312
  persistence: {
313
+ /** `color.requireConsent`: whether changes are only saved after consent. */
314
+ required: core.requireConsent,
241
315
  hasConsent: core.hasConsent,
242
316
  grant: () => core.setConsent(true),
243
317
  revoke: () => core.setConsent(false),
244
- enable: () => core.cookies.persistIfConsented(core.preference.value, core.modePreference.value, core.getResolvedTheme()),
318
+ enable: () => {
319
+ core.cookies.persistIfConsented(core.preference.value, core.modePreference.value, core.getResolvedTheme());
320
+ core.persistToggles();
321
+ },
245
322
  disable: core.cookies.disablePersistence
246
323
  }
247
324
  };
@@ -0,0 +1,2 @@
1
+ declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/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,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) {
@@ -15,6 +15,22 @@ export declare const THEME_COOKIE_OPTIONS: {
15
15
  readonly path: "/";
16
16
  readonly sameSite: "lax";
17
17
  };
18
+ /** `'off'` when the visitor turned the custom scrollbar off (`scrollbar.set(false)`); missing or `'on'` keeps it. Same consent rule as the theme cookies. */
19
+ export declare const SCROLLBAR_COOKIE = "venix-scrollbar";
20
+ /** Same as `SCROLLBAR_COOKIE`, for the custom cursor (`cursor.set(false)`). */
21
+ export declare const CURSOR_COOKIE = "venix-cursor";
22
+ /** Same as `SCROLLBAR_COOKIE`, for the custom font (`font.set(false)`). */
23
+ export declare const FONT_COOKIE = "venix-font";
24
+ /** `'off'` on `<html>` switches the custom scrollbar off: its CSS only applies without it (see shared/css/scrollbar.ts). */
25
+ export declare const SCROLLBAR_ATTRIBUTE = "data-venix-scrollbar";
26
+ /** On any element that scrolls, gets it the overlay scrollbar too (see runtime/plugins/overlay-scrollbars.client.ts). */
27
+ export declare const SCROLL_CONTAINER_ATTRIBUTE = "data-venix-scroll";
28
+ /** The OverlayScrollbars theme the module styles (see shared/css/scrollbar.ts). */
29
+ export declare const OVERLAY_SCROLLBAR_THEME = "os-theme-jade";
30
+ /** `'off'` on `<html>` puts the browser's own cursors back (see shared/css/cursor.ts). */
31
+ export declare const CURSOR_ATTRIBUTE = "data-venix-cursor";
32
+ /** `'off'` on `<html>` leaves only the `defaultFonts` in the font variables (see shared/css/typography.ts). */
33
+ export declare const FONT_ATTRIBUTE = "data-venix-font";
18
34
  export declare const COOKIE_PREFERENCES_UPDATED_EVENT = "venix-cookie-preferences-updated";
19
35
  /**
20
36
  * Dispatched synchronously by `apply()` (useVenixTheme.ts), inside the same
@@ -39,5 +55,43 @@ export declare const LOCALE_MAP: Record<string, string>;
39
55
  export declare const DEFAULT_THEME = "dark";
40
56
  export declare const SYSTEM_THEME = "system";
41
57
  export declare const THEME_MODES: readonly ["light", "dark"];
58
+ /**
59
+ * The icons of <VenixThemeSwitcher>'s own controls, in the same formats as a
60
+ * theme's icon. Listed here so `setup/register-icon.ts` bundles them along
61
+ * with the themes' (line-md has no save, scroll, cursor or font icon, hence `mdi`).
62
+ */
63
+ export declare const SWITCHER_ICONS: {
64
+ readonly settings: {
65
+ readonly emote: "⚙️";
66
+ readonly css: "mdi:cog-outline";
67
+ readonly svg: "line-md:cog";
68
+ };
69
+ readonly back: {
70
+ readonly emote: "⬅️";
71
+ readonly css: "mdi:arrow-left";
72
+ readonly svg: "line-md:arrow-left";
73
+ };
74
+ readonly save: {
75
+ readonly emote: "💾";
76
+ readonly css: "mdi:content-save-outline";
77
+ };
78
+ readonly scrollbar: {
79
+ readonly emote: "↕️";
80
+ readonly css: "mdi:mouse-scroll-wheel";
81
+ };
82
+ readonly cursor: {
83
+ readonly emote: "🖱️";
84
+ readonly css: "mdi:cursor-default-outline";
85
+ };
86
+ readonly font: {
87
+ readonly emote: "🔤";
88
+ readonly css: "mdi:format-font";
89
+ };
90
+ };
91
+ /** The credit at the bottom of <VenixThemeSwitcher>'s settings. */
92
+ export declare const SWITCHER_CREDIT: {
93
+ readonly name: "@venix-sistemas/jade";
94
+ readonly url: "https://github.com/Venix-Sistemas/jade";
95
+ };
42
96
  export declare const COLOR_PROPERTIES: readonly ["primary", "secondary", "accent", "error", "info", "success", "warning", "background", "background2", "background3"];
43
97
  export declare const NON_COLOR_PROPERTIES: readonly ["id", "dark", "light", "seasonal", "dateRange", "translations", "icon"];
@@ -3,6 +3,14 @@ export const THEME_RESOLVED_COOKIE = "venix-theme-resolved";
3
3
  export const THEME_MODE_COOKIE = "venix-theme-mode";
4
4
  export const THEME_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
5
5
  export const THEME_COOKIE_OPTIONS = { maxAge: THEME_COOKIE_MAX_AGE, path: "/", sameSite: "lax" };
6
+ export const SCROLLBAR_COOKIE = "venix-scrollbar";
7
+ export const CURSOR_COOKIE = "venix-cursor";
8
+ export const FONT_COOKIE = "venix-font";
9
+ export const SCROLLBAR_ATTRIBUTE = "data-venix-scrollbar";
10
+ export const SCROLL_CONTAINER_ATTRIBUTE = "data-venix-scroll";
11
+ export const OVERLAY_SCROLLBAR_THEME = "os-theme-jade";
12
+ export const CURSOR_ATTRIBUTE = "data-venix-cursor";
13
+ export const FONT_ATTRIBUTE = "data-venix-font";
6
14
  export const COOKIE_PREFERENCES_UPDATED_EVENT = "venix-cookie-preferences-updated";
7
15
  export const THEME_APPLIED_EVENT = "venix-theme-applied";
8
16
  export const COOKIE_CONSENT_STORAGE_KEY = "venix-cookie-consent";
@@ -22,6 +30,18 @@ export const LOCALE_MAP = {
22
30
  export const DEFAULT_THEME = "dark";
23
31
  export const SYSTEM_THEME = "system";
24
32
  export const THEME_MODES = ["light", "dark"];
33
+ export const SWITCHER_ICONS = {
34
+ settings: { emote: "\u2699\uFE0F", css: "mdi:cog-outline", svg: "line-md:cog" },
35
+ back: { emote: "\u2B05\uFE0F", css: "mdi:arrow-left", svg: "line-md:arrow-left" },
36
+ save: { emote: "\u{1F4BE}", css: "mdi:content-save-outline" },
37
+ scrollbar: { emote: "\u2195\uFE0F", css: "mdi:mouse-scroll-wheel" },
38
+ cursor: { emote: "\u{1F5B1}\uFE0F", css: "mdi:cursor-default-outline" },
39
+ font: { emote: "\u{1F524}", css: "mdi:format-font" }
40
+ };
41
+ export const SWITCHER_CREDIT = {
42
+ name: "@venix-sistemas/jade",
43
+ url: "https://github.com/Venix-Sistemas/jade"
44
+ };
25
45
  export const COLOR_PROPERTIES = [
26
46
  "primary",
27
47
  "secondary",
@@ -0,0 +1,10 @@
1
+ import type { CursorType } from '../types/index.js';
2
+ /**
3
+ * A cursor drawn in a theme's color, as a `data:` URI ready for `url()`:
4
+ * a black outline, so it reads on light and dark backgrounds alike, and a
5
+ * soft highlight on the upper half that keeps flat colors from looking dull.
6
+ */
7
+ export declare function generateCursorSVG(type: CursorType, color: string): {
8
+ url: string;
9
+ hotspot: string;
10
+ };
@@ -0,0 +1,28 @@
1
+ const SHAPES = {
2
+ default: {
3
+ hotspot: "3 2",
4
+ shape: `<path d='M3 2v22l5.5-5 4 9.5 3.5-1.5-4-9h7.5z'/>`
5
+ },
6
+ // Traced from a high-resolution render of the module's fire hand
7
+ // (cursor-hand.png): index finger up, the other three stepping down to the
8
+ // right, the thumb out to the left. The gaps between fingers are deepened a
9
+ // little, or the outline would fill them at cursor size, and the index finger is
10
+ // slimmer (4px), so its tip doesn't look swollen inside the outline.
11
+ pointer: {
12
+ hotspot: "11 1",
13
+ shape: `<path d='M9 4.4C9 3.1 9.9 2.2 11 2.2s2 .9 2 2.2v4.2l.5.1c1-.7 3.8-.8 3.8 1.4.2-.9 3.9-1.2 4 1.3.2-.6 4.2-.6 4.2 2.2V21c0 2.5-.7 4.5-2 5.8C22 28.5 19 29 16 29c-2.5 0-4.6-.8-5.7-2.5l-2.8-5.2-3.2-3.7c-1-1.2-.7-3 .3-3.6 1-.7 2.4-.4 3.2.3l1.2.9z'/>`,
14
+ details: `<path d='M13.1 8.8v3.7M17.3 10.1l-.2 3.4M21.3 11.3l-.2 3.2'/>`
15
+ },
16
+ text: {
17
+ hotspot: "16 16",
18
+ shape: `<path d='M11 3h10a1 1 0 0 1 0 3h-3.5v20H21a1 1 0 0 1 0 3H11a1 1 0 0 1 0-3h3.5V6H11a1 1 0 0 1 0-3z'/>`
19
+ }
20
+ };
21
+ const SIZE = 28;
22
+ const scaleHotspot = (hotspot) => hotspot.split(" ").map((n) => Math.round(Number(n) * SIZE / 32)).join(" ");
23
+ const encodeSVG = (svg) => svg.replace(/[%#<>]/g, (char) => encodeURIComponent(char));
24
+ export function generateCursorSVG(type, color) {
25
+ const { hotspot, shape, details } = SHAPES[type];
26
+ const svg = `<svg xmlns='http://www.w3.org/2000/svg' width='${SIZE}' height='${SIZE}' viewBox='0 0 32 32'><defs><g id='c'>${shape}</g><linearGradient id='s' x2='0' y2='1'><stop stop-color='white' stop-opacity='.45'/><stop offset='.6' stop-color='white' stop-opacity='0'/></linearGradient></defs><use href='#c' stroke='black' stroke-width='3' stroke-linejoin='round'/><use href='#c' fill='${color}'/><use href='#c' fill='url(#s)'/>` + (details ? `<g fill='none' stroke='black' stroke-opacity='.5' stroke-linecap='round'>${details}</g>` : "") + `</svg>`;
27
+ return { url: `data:image/svg+xml,${encodeSVG(svg)}`, hotspot: scaleHotspot(hotspot) };
28
+ }