@venix-sistemas/jade 1.1.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 (64) hide show
  1. package/README.md +555 -228
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +89 -13
  4. package/dist/runtime/components/VenixThemeSwitcher.d.vue.ts +3 -1
  5. package/dist/runtime/components/VenixThemeSwitcher.vue +592 -106
  6. package/dist/runtime/components/VenixThemeSwitcher.vue.d.ts +3 -1
  7. package/dist/runtime/composables/useThemeColors.d.ts +8 -2
  8. package/dist/runtime/composables/useThemeColors.js +24 -9
  9. package/dist/runtime/composables/useThemeCookies.d.ts +17 -2
  10. package/dist/runtime/composables/useThemeCookies.js +44 -7
  11. package/dist/runtime/composables/useThemeLocale.d.ts +7 -2
  12. package/dist/runtime/composables/useThemeLocale.js +2 -2
  13. package/dist/runtime/composables/useThemeSeasonal.d.ts +3 -3
  14. package/dist/runtime/composables/useThemeSeasonal.js +1 -1
  15. package/dist/runtime/composables/useVenixTheme.d.ts +40 -0
  16. package/dist/runtime/composables/useVenixTheme.js +249 -112
  17. package/dist/runtime/nitro/theme-init.js +8 -5
  18. package/dist/runtime/plugins/overlay-scrollbars.client.js +89 -0
  19. package/dist/runtime/plugins/theme-init.server.js +7 -12
  20. package/dist/runtime/plugins/vuetify-theme.js +8 -11
  21. package/dist/runtime/scripts/theme-init.d.ts +33 -11
  22. package/dist/runtime/scripts/theme-init.js +59 -88
  23. package/dist/shared/constants.d.ts +72 -3
  24. package/dist/shared/constants.js +26 -1
  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 +86 -34
  28. package/dist/shared/css/index.d.ts +1 -7
  29. package/dist/shared/css/index.js +5 -5
  30. package/dist/shared/css/scrollbar.js +61 -7
  31. package/dist/shared/css/transition.d.ts +1 -1
  32. package/dist/shared/css/typography.js +13 -0
  33. package/dist/shared/theme.json +308 -192
  34. package/dist/shared/types/color-options.d.ts +26 -2
  35. package/dist/shared/types/colors.d.ts +64 -12
  36. package/dist/shared/types/cursor.d.ts +34 -4
  37. package/dist/shared/types/index.d.ts +3 -3
  38. package/dist/shared/types/runtime-config.d.ts +5 -2
  39. package/dist/shared/types/scrollbar.d.ts +11 -0
  40. package/dist/shared/types/theme.d.ts +7 -0
  41. package/dist/shared/types/typography.d.ts +2 -1
  42. package/dist/shared/utils/icon-refs.d.ts +7 -3
  43. package/dist/shared/utils/icon.d.ts +4 -2
  44. package/dist/shared/utils/icon.js +6 -2
  45. package/dist/shared/utils/index.d.ts +5 -4
  46. package/dist/shared/utils/index.js +12 -6
  47. package/dist/shared/utils/inline-script.d.ts +6 -0
  48. package/dist/shared/utils/inline-script.js +3 -0
  49. package/dist/shared/utils/load.d.ts +2 -3
  50. package/dist/shared/utils/load.js +6 -12
  51. package/dist/shared/utils/merge-themes.d.ts +39 -9
  52. package/dist/shared/utils/merge-themes.js +101 -5
  53. package/dist/shared/utils/normalize.d.ts +0 -11
  54. package/dist/shared/utils/normalize.js +0 -12
  55. package/dist/shared/utils/theme-config.d.ts +15 -6
  56. package/dist/shared/utils/theme-config.js +28 -16
  57. package/dist/shared/utils/theme-resolve.d.ts +23 -22
  58. package/dist/shared/utils/theme-resolve.js +35 -66
  59. package/dist/shared/utils/theme-resolver.d.ts +47 -0
  60. package/dist/shared/utils/theme-resolver.js +140 -0
  61. package/package.json +22 -10
  62. package/README-default.md +0 -84
  63. package/dist/runtime/plugin.js +0 -3
  64. /package/dist/runtime/{plugin.d.ts → plugins/overlay-scrollbars.client.d.ts} +0 -0
@@ -1,8 +1,10 @@
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
+ /** Hides "Save changes" in the settings, for a site whose own cookie banner already records consent. */
7
+ hideConsent?: boolean;
6
8
  };
7
9
  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>;
8
10
  declare const _default: typeof __VLS_export;
@@ -1,10 +1,16 @@
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;
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,22 @@
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
+ scrollbarCookie: import("nuxt/app").CookieRef<string>;
12
+ cursorCookie: import("nuxt/app").CookieRef<string>;
13
+ fontCookie: import("nuxt/app").CookieRef<string>;
14
+ canPersist: () => boolean;
15
+ persistIfConsented: (preference: string, mode: string, resolved: string) => void;
16
+ persistTogglesIfConsented: (toggles: {
17
+ scrollbar: boolean;
18
+ cursor: boolean;
19
+ font: boolean;
20
+ }) => void;
6
21
  disablePersistence: () => void;
7
22
  };
@@ -2,32 +2,69 @@ import { useCookie } from "#app";
2
2
  import {
3
3
  THEME_PREFERENCE_COOKIE,
4
4
  THEME_RESOLVED_COOKIE,
5
- DEFAULT_LOCALE_COOKIE_NAME
5
+ THEME_MODE_COOKIE,
6
+ THEME_COOKIE_OPTIONS,
7
+ DEFAULT_LOCALE_COOKIE_NAME,
8
+ SCROLLBAR_COOKIE,
9
+ CURSOR_COOKIE,
10
+ FONT_COOKIE
6
11
  } from "../../shared/constants";
7
12
  import { hasCookieConsent } from "../../shared/utils/consent";
8
- export const useThemeCookies = (localeCookieName = DEFAULT_LOCALE_COOKIE_NAME) => {
9
- const preferenceCookie = useCookie(THEME_PREFERENCE_COOKIE);
10
- const resolvedCookie = useCookie(THEME_RESOLVED_COOKIE);
11
- const localeCookie = useCookie(localeCookieName);
13
+ let warnedMissingConsent = false;
14
+ export const useThemeCookies = (options = {}) => {
15
+ const { localeCookieName = DEFAULT_LOCALE_COOKIE_NAME, requireConsent = true } = options;
16
+ const preferenceCookie = useCookie(THEME_PREFERENCE_COOKIE, THEME_COOKIE_OPTIONS);
17
+ const resolvedCookie = useCookie(THEME_RESOLVED_COOKIE, THEME_COOKIE_OPTIONS);
18
+ const modeCookie = useCookie(THEME_MODE_COOKIE, THEME_COOKIE_OPTIONS);
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);
12
23
  const removeCookie = (name) => {
13
24
  if (typeof document !== "undefined") {
14
25
  document.cookie = `${name}=; path=/; max-age=0; SameSite=Lax`;
15
26
  }
16
27
  };
17
- const persistIfConsented = (preference, resolved) => {
18
- if (!hasCookieConsent()) return;
28
+ const canPersist = () => !requireConsent || hasCookieConsent();
29
+ const persistIfConsented = (preference, mode, resolved) => {
30
+ if (!canPersist()) {
31
+ if (import.meta.dev && import.meta.client && !warnedMissingConsent) {
32
+ warnedMissingConsent = true;
33
+ console.warn(
34
+ "[jade] Theme change not saved: no cookie consent recorded, so it will be lost on reload. Call `persistence.grant()`, record consent from your cookie banner, or set `venixTheme.color.requireConsent: false` if this app has no consent banner."
35
+ );
36
+ }
37
+ return;
38
+ }
19
39
  preferenceCookie.value = preference;
40
+ modeCookie.value = mode;
20
41
  resolvedCookie.value = resolved;
21
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
+ };
22
49
  const disablePersistence = () => {
23
50
  removeCookie(THEME_PREFERENCE_COOKIE);
24
51
  removeCookie(THEME_RESOLVED_COOKIE);
52
+ removeCookie(THEME_MODE_COOKIE);
53
+ removeCookie(SCROLLBAR_COOKIE);
54
+ removeCookie(CURSOR_COOKIE);
55
+ removeCookie(FONT_COOKIE);
25
56
  };
26
57
  return {
27
58
  preferenceCookie,
28
59
  resolvedCookie,
60
+ modeCookie,
29
61
  localeCookie,
62
+ scrollbarCookie,
63
+ cursorCookie,
64
+ fontCookie,
65
+ canPersist,
30
66
  persistIfConsented,
67
+ persistTogglesIfConsented,
31
68
  disablePersistence
32
69
  };
33
70
  };
@@ -1,11 +1,16 @@
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;
6
6
  defaultLocale?: string;
7
+ /**
8
+ * Whether the locale cookie may be written — `useThemeCookies().canPersist`,
9
+ * so it honors `color.requireConsent` like the theme cookies.
10
+ */
11
+ canPersist?: () => boolean;
7
12
  }
8
- 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) => {
9
14
  currentLocale: Ref<string, string>;
10
15
  translate: (translations?: Record<string, string>, fallback?: string) => string;
11
16
  setLocale: (locale: string) => void;
@@ -5,7 +5,7 @@ import { normalizeLocale, extractFirstLocale } from "../../shared/utils/normaliz
5
5
  import { extractLocales } from "../../shared/utils/load";
6
6
  import { hasCookieConsent } from "../../shared/utils/consent";
7
7
  export const useThemeLocale = (theme, localeCookie, options = {}) => {
8
- const { enabled = true, forcedLocale, defaultLocale } = options;
8
+ const { enabled = true, forcedLocale, defaultLocale, canPersist = hasCookieConsent } = options;
9
9
  const headers = useRequestHeaders(["accept-language"]);
10
10
  const route = useRoute();
11
11
  const fallbackLocale = defaultLocale || DEFAULT_LOCALE;
@@ -69,7 +69,7 @@ export const useThemeLocale = (theme, localeCookie, options = {}) => {
69
69
  const setLocale = (locale) => {
70
70
  const normalized = normalizeLocale(locale);
71
71
  currentLocale.value = normalized;
72
- if (enabled && !forcedLocale && hasCookieConsent()) {
72
+ if (enabled && !forcedLocale && canPersist()) {
73
73
  localeCookie.value = normalized;
74
74
  }
75
75
  };
@@ -1,4 +1,4 @@
1
- import type { ThemeConfig } from '../../shared/types/index.js';
2
- export declare const useThemeSeasonal: (theme: ThemeConfig) => {
3
- getActiveSeasonalTheme: (prefersDark?: boolean) => string | null;
1
+ import type { ResolvedTheme, ThemeMode } from '../../shared/types/index.js';
2
+ export declare const useThemeSeasonal: (theme: ResolvedTheme) => {
3
+ getActiveSeasonalTheme: (mode?: ThemeMode) => string | null;
4
4
  };
@@ -1,6 +1,6 @@
1
1
  import { getActiveSeasonalTheme } from "../../shared/utils/theme-resolve";
2
2
  export const useThemeSeasonal = (theme) => {
3
- const getActiveSeasonalThemeFor = (prefersDark) => getActiveSeasonalTheme(theme.colors.themes, prefersDark);
3
+ const getActiveSeasonalThemeFor = (mode) => getActiveSeasonalTheme(theme.colors.groups, mode);
4
4
  return {
5
5
  getActiveSeasonalTheme: getActiveSeasonalThemeFor
6
6
  };
@@ -1,3 +1,4 @@
1
+ import type { ThemeMode, ThemeModePreference } from '../../shared/types/index.js';
1
2
  export declare const useVenixTheme: () => {
2
3
  theme: {
3
4
  value: import("vue").ComputedRef<string>;
@@ -6,7 +7,9 @@ export declare const useVenixTheme: () => {
6
7
  value: string;
7
8
  name: string;
8
9
  icon: import("../../shared/utils/icon.js").ResolvedThemeIcon | null;
10
+ custom: boolean;
9
11
  } | undefined>;
12
+ set: (name: string) => void;
10
13
  toggle: (forceTheme?: string) => void;
11
14
  isSeasonalActive: import("vue").ComputedRef<boolean>;
12
15
  activeSeasonalTheme: import("vue").ComputedRef<string | null>;
@@ -17,13 +20,50 @@ export declare const useVenixTheme: () => {
17
20
  value: string;
18
21
  name: string;
19
22
  icon: import("../../shared/utils/icon.js").ResolvedThemeIcon | null;
23
+ custom: boolean;
20
24
  }[]>;
25
+ mode: {
26
+ value: import("vue").ComputedRef<ThemeMode>;
27
+ preference: import("vue").Ref<ThemeModePreference, ThemeModePreference>;
28
+ data: import("vue").ComputedRef<{
29
+ value: "light" | "dark" | "system";
30
+ name: string;
31
+ icon: import("../../shared/utils/icon.js").ResolvedThemeIcon | null;
32
+ } | undefined>;
33
+ set: (mode: ThemeModePreference) => void;
34
+ toggle: () => void;
35
+ };
36
+ modes: import("vue").ComputedRef<{
37
+ value: "light" | "dark" | "system";
38
+ name: string;
39
+ icon: import("../../shared/utils/icon.js").ResolvedThemeIcon | null;
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
+ };
21
59
  locale: {
22
60
  current: import("vue").Ref<string, string>;
23
61
  set: (locale: string) => void;
24
62
  translate: (translations?: Record<string, string>, fallback?: string) => string;
25
63
  };
26
64
  persistence: {
65
+ /** `color.requireConsent`: whether changes are only saved after consent. */
66
+ required: boolean;
27
67
  hasConsent: import("vue").Ref<boolean, boolean>;
28
68
  grant: () => void;
29
69
  revoke: () => void;