@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,27 +1,49 @@
1
- import type { ThemeConfig } from '../../shared/types/index.js';
1
+ import type { ResolvedTheme } from '../../shared/types/index.js';
2
+ import type { ThemeResolver } from '../../shared/utils/theme-resolver.js';
2
3
  declare global {
3
4
  interface Window {
4
5
  __VENIX_INITIAL_THEME__?: string;
5
6
  }
6
7
  }
8
+ export interface InitThemeOptions {
9
+ /** See `color.requireConsent` — when `false`, the theme cookies are always written. */
10
+ requireConsent: boolean;
11
+ cookies: {
12
+ preference: string;
13
+ mode: string;
14
+ resolved: string;
15
+ scrollbar: string;
16
+ cursor: string;
17
+ font: string;
18
+ };
19
+ /** In seconds. */
20
+ cookieMaxAge: number;
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
+ };
28
+ }
7
29
  /**
8
30
  * Runs as an inline script in `<head>`, injected via Nitro's `render:html`
9
31
  * hook by the `runtime/nitro/theme-init.ts` plugin (see
10
32
  * `setup/register-plugins.ts`) — BEFORE the Vue bundle, to avoid a
11
33
  * wrong-theme flash before hydration (SSR doesn't know the user's real
12
- * light/dark preference when the preference is 'system', nor does it have
34
+ * light/dark preference when the mode is 'system', nor does it have
13
35
  * `matchMedia`).
14
36
  *
15
37
  * Because it runs this way, this function (only this function — the rest of
16
38
  * the file, including the type imports, is erased by TypeScript and never
17
39
  * reaches the browser) has to be 100% self-contained: `initTheme.toString()`
18
- * gets serialized and executed as a standalone IIFE, so any import from
19
- * another module would become a `ReferenceError` on the client. That's why
20
- * the cookie names below and the theme-resolution rule
21
- * (`resolveThemePreference`/`getActiveSeasonalTheme`) are deliberately
22
- * duplicated — the canonical implementation, shared between the composable
23
- * and the SSR plugin, lives in `shared/constants.ts` and
24
- * `shared/utils/theme-resolve.ts`. Keep the two sides in sync when changing
25
- * either one.
40
+ * gets serialized and executed as a standalone IIFE, so anything from another
41
+ * module would be a `ReferenceError` on the client. Everything it needs comes
42
+ * in as arguments instead: the theme-resolution rule as the (equally
43
+ * self-contained) `createThemeResolver` factory, and the cookie names and
44
+ * settings from `shared/constants.ts` in `options`.
26
45
  */
27
- export default function initTheme(themeData: ThemeConfig): void;
46
+ export default function initTheme(createThemeResolver: () => ThemeResolver, themeData: ResolvedTheme, options: InitThemeOptions): void;
47
+ export declare function createInitThemeOptions(requireConsent: boolean): InitThemeOptions;
48
+ /** The inline script's source: `initTheme` as an IIFE, with its arguments serialized. */
49
+ export declare function renderInitThemeScript(themeData: ResolvedTheme, options: InitThemeOptions): string;
@@ -1,10 +1,24 @@
1
- export default function initTheme(themeData) {
2
- const THEME_PREFERENCE_COOKIE = "venix-theme-preference";
3
- const THEME_RESOLVED_COOKIE = "venix-theme-resolved";
4
- const COOKIE_CONSENT_STORAGE_KEY = "venix-cookie-consent";
1
+ import { createThemeResolver } from "../../shared/utils/theme-resolver";
2
+ import { toInlineScriptJson } from "../../shared/utils/inline-script";
3
+ import {
4
+ THEME_PREFERENCE_COOKIE,
5
+ THEME_MODE_COOKIE,
6
+ THEME_RESOLVED_COOKIE,
7
+ THEME_COOKIE_MAX_AGE,
8
+ COOKIE_CONSENT_STORAGE_KEY,
9
+ SCROLLBAR_COOKIE,
10
+ CURSOR_COOKIE,
11
+ FONT_COOKIE,
12
+ SCROLLBAR_ATTRIBUTE,
13
+ CURSOR_ATTRIBUTE,
14
+ FONT_ATTRIBUTE
15
+ } from "../../shared/constants";
16
+ export default function initTheme(createThemeResolver2, themeData, options) {
17
+ const resolver = createThemeResolver2();
18
+ const { requireConsent, cookies, cookieMaxAge, consentStorageKey, attributes } = options;
5
19
  function hasCookieConsent() {
6
20
  if (typeof localStorage === "undefined") return false;
7
- const consentData = localStorage.getItem(COOKIE_CONSENT_STORAGE_KEY);
21
+ const consentData = localStorage.getItem(consentStorageKey);
8
22
  if (!consentData) return false;
9
23
  try {
10
24
  const consent = JSON.parse(consentData);
@@ -19,97 +33,54 @@ export default function initTheme(themeData) {
19
33
  return cookieValue ? decodeURIComponent(cookieValue) : null;
20
34
  }
21
35
  function setCookieIfConsented(name, value) {
22
- if (hasCookieConsent()) {
23
- document.cookie = `${name}=${encodeURIComponent(value)}; path=/; max-age=31536000; SameSite=Lax`;
36
+ if (!requireConsent || hasCookieConsent()) {
37
+ document.cookie = `${name}=${encodeURIComponent(value)}; path=/; max-age=${cookieMaxAge}; SameSite=Lax`;
24
38
  }
25
39
  }
26
- function isColorTheme(themeConfig) {
27
- if (!themeConfig) return false;
28
- return !!themeConfig.primary || !!themeConfig.background;
29
- }
30
- function getEasterSunday(year) {
31
- const a = year % 19;
32
- const b = Math.floor(year / 100);
33
- const c = year % 100;
34
- const d = Math.floor(b / 4);
35
- const e = b % 4;
36
- const f = Math.floor((b + 8) / 25);
37
- const g = Math.floor((b - f + 1) / 3);
38
- const h = (19 * a + b - d - g + 15) % 30;
39
- const i = Math.floor(c / 4);
40
- const k = c % 4;
41
- const l = (32 + 2 * e + 2 * i - h - k) % 7;
42
- const m = Math.floor((a + 11 * h + 22 * l) / 451);
43
- const month = Math.floor((h + l - 7 * m + 114) / 31);
44
- const day = (h + l - 7 * m + 114) % 31 + 1;
45
- return new Date(year, month - 1, day);
46
- }
47
- function parseDatePart(value, year) {
48
- const easter = /^easter([+-]\d+)?$/.exec(value.trim());
49
- if (easter) {
50
- const date = getEasterSunday(year);
51
- date.setDate(date.getDate() + Number(easter[1] ?? 0));
52
- return (date.getMonth() + 1) * 100 + date.getDate();
53
- }
54
- const parts = value.split("-").map(Number);
55
- if (parts.length !== 2) return null;
56
- const [month, day] = parts;
57
- if (month === void 0 || day === void 0) return null;
58
- return month * 100 + day;
59
- }
60
- function isDateInSeasonalRange(themeConfig, now) {
61
- if (themeConfig.seasonal !== true || !themeConfig.dateRange) return false;
62
- const year = now.getFullYear();
63
- const startNum = parseDatePart(themeConfig.dateRange.start, year);
64
- const endNum = parseDatePart(themeConfig.dateRange.end, year);
65
- if (startNum === null || endNum === null) return false;
66
- const current = (now.getMonth() + 1) * 100 + now.getDate();
67
- return startNum <= endNum ? current >= startNum && current <= endNum : current >= startNum || current <= endNum;
68
- }
69
- function getActiveSeasonalTheme(themes2, prefersDark) {
70
- const now = /* @__PURE__ */ new Date();
71
- for (const [themeName, themeConfig] of Object.entries(themes2)) {
72
- if (themeName === "system") continue;
73
- if (!isColorTheme(themeConfig)) continue;
74
- if (!isDateInSeasonalRange(themeConfig, now)) continue;
75
- if (themeConfig.dark !== prefersDark) continue;
76
- return themeName;
77
- }
78
- return null;
79
- }
80
- function resolveThemePreference(preference2, themes2, defaultTheme2, prefersDark) {
81
- let resolved;
82
- if (preference2 === "system") {
83
- resolved = getActiveSeasonalTheme(themes2, prefersDark) || (prefersDark ? "dark" : "light");
84
- } else if (preference2 && isColorTheme(themes2[preference2])) {
85
- resolved = preference2;
86
- } else {
87
- resolved = defaultTheme2;
88
- }
89
- if (!isColorTheme(themes2[resolved])) {
90
- resolved = isColorTheme(themes2[defaultTheme2]) ? defaultTheme2 : "dark";
91
- }
92
- return resolved;
93
- }
40
+ const colors = {
41
+ themes: themeData.colors?.themes || {},
42
+ groups: themeData.colors?.groups || {},
43
+ defaultColor: themeData.colors?.defaultColor
44
+ };
94
45
  const html = document.documentElement;
95
- const themes = themeData.colors?.themes || {};
96
- const defaultTheme = themeData.colors?.defaultColor || "dark";
97
- const preference = getCookie(THEME_PREFERENCE_COOKIE);
98
- const resolvedCookie = getCookie(THEME_RESOLVED_COOKIE);
46
+ const preference = getCookie(cookies.preference);
47
+ const modePreference = getCookie(cookies.mode);
48
+ const resolvedCookie = getCookie(cookies.resolved);
99
49
  const systemPrefersDark = typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches;
100
- let theme;
101
- if (resolvedCookie && isColorTheme(themes[resolvedCookie])) {
102
- theme = resolvedCookie;
103
- } else {
104
- theme = resolveThemePreference(preference || void 0, themes, defaultTheme, systemPrefersDark);
105
- }
50
+ const selection = resolver.normalizeThemeSelection(preference, modePreference, colors);
51
+ const theme = resolver.resolveThemeSelection(selection, colors, systemPrefersDark);
106
52
  html.classList.add(theme);
107
53
  html.setAttribute("data-theme", theme);
108
54
  window.__VENIX_INITIAL_THEME__ = theme;
109
- if (!resolvedCookie || resolvedCookie !== theme) {
110
- setCookieIfConsented(THEME_RESOLVED_COOKIE, theme);
55
+ for (const toggle of ["scrollbar", "cursor", "font"]) {
56
+ if (getCookie(cookies[toggle]) === "off") html.setAttribute(attributes[toggle], "off");
57
+ }
58
+ if (resolvedCookie !== theme) {
59
+ setCookieIfConsented(cookies.resolved, theme);
111
60
  }
112
61
  if (!preference) {
113
- setCookieIfConsented(THEME_PREFERENCE_COOKIE, theme);
62
+ setCookieIfConsented(cookies.preference, selection.theme);
114
63
  }
64
+ if (!modePreference) {
65
+ setCookieIfConsented(cookies.mode, selection.mode);
66
+ }
67
+ }
68
+ export function createInitThemeOptions(requireConsent) {
69
+ return {
70
+ requireConsent,
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
+ },
79
+ cookieMaxAge: THEME_COOKIE_MAX_AGE,
80
+ consentStorageKey: COOKIE_CONSENT_STORAGE_KEY,
81
+ attributes: { scrollbar: SCROLLBAR_ATTRIBUTE, cursor: CURSOR_ATTRIBUTE, font: FONT_ATTRIBUTE }
82
+ };
83
+ }
84
+ export function renderInitThemeScript(themeData, options) {
85
+ return `(${initTheme.toString()})(${createThemeResolver.toString()}, ${toInlineScriptJson(themeData)}, ${toInlineScriptJson(options)})`;
115
86
  }
@@ -1,5 +1,36 @@
1
1
  export declare const THEME_PREFERENCE_COOKIE = "venix-theme-preference";
2
2
  export declare const THEME_RESOLVED_COOKIE = "venix-theme-resolved";
3
+ /** The user's mode choice (`'system'`, `'light'`, `'dark'`); the theme itself stays in `THEME_PREFERENCE_COOKIE`. */
4
+ export declare const THEME_MODE_COOKIE = "venix-theme-mode";
5
+ /**
6
+ * One year, in seconds. Without it `useCookie` writes session cookies, so a
7
+ * theme picked on the client was forgotten when the browser closed. The
8
+ * pre-hydration script (`runtime/scripts/theme-init.ts`) hardcodes the same
9
+ * value, since it can't import this.
10
+ */
11
+ export declare const THEME_COOKIE_MAX_AGE: number;
12
+ /** Options for every `useCookie` of the theme cookies, so all writers agree. */
13
+ export declare const THEME_COOKIE_OPTIONS: {
14
+ readonly maxAge: number;
15
+ readonly path: "/";
16
+ readonly sameSite: "lax";
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";
3
34
  export declare const COOKIE_PREFERENCES_UPDATED_EVENT = "venix-cookie-preferences-updated";
4
35
  /**
5
36
  * Dispatched synchronously by `apply()` (useVenixTheme.ts), inside the same
@@ -16,13 +47,51 @@ export declare const COOKIE_PREFERENCES_UPDATED_EVENT = "venix-cookie-preference
16
47
  * `data-theme` change, as part of the same transition.
17
48
  */
18
49
  export declare const THEME_APPLIED_EVENT = "venix-theme-applied";
19
- /** Read (never written) by this module — the consumer app's cookie-consent UI writes here. */
50
+ /** Where functional-cookie consent is stored — written by `persistence.grant()/revoke()` or by the consumer app's own consent UI. */
20
51
  export declare const COOKIE_CONSENT_STORAGE_KEY = "venix-cookie-consent";
21
52
  export declare const DEFAULT_LOCALE = "en-US";
22
53
  export declare const DEFAULT_LOCALE_COOKIE_NAME = "i18n_redirected";
23
54
  export declare const LOCALE_MAP: Record<string, string>;
24
55
  export declare const DEFAULT_THEME = "dark";
25
56
  export declare const SYSTEM_THEME = "system";
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
+ };
26
96
  export declare const COLOR_PROPERTIES: readonly ["primary", "secondary", "accent", "error", "info", "success", "warning", "background", "background2", "background3"];
27
- export declare const NON_COLOR_PROPERTIES: readonly ["dark", "seasonal", "dateRange", "translations", "icon"];
28
- export declare const CSS_HEADER = "/* ============================================ */";
97
+ export declare const NON_COLOR_PROPERTIES: readonly ["id", "dark", "light", "seasonal", "dateRange", "translations", "icon"];
@@ -1,5 +1,16 @@
1
1
  export const THEME_PREFERENCE_COOKIE = "venix-theme-preference";
2
2
  export const THEME_RESOLVED_COOKIE = "venix-theme-resolved";
3
+ export const THEME_MODE_COOKIE = "venix-theme-mode";
4
+ export const THEME_COOKIE_MAX_AGE = 60 * 60 * 24 * 365;
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";
3
14
  export const COOKIE_PREFERENCES_UPDATED_EVENT = "venix-cookie-preferences-updated";
4
15
  export const THEME_APPLIED_EVENT = "venix-theme-applied";
5
16
  export const COOKIE_CONSENT_STORAGE_KEY = "venix-cookie-consent";
@@ -18,6 +29,19 @@ export const LOCALE_MAP = {
18
29
  };
19
30
  export const DEFAULT_THEME = "dark";
20
31
  export const SYSTEM_THEME = "system";
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
+ };
21
45
  export const COLOR_PROPERTIES = [
22
46
  "primary",
23
47
  "secondary",
@@ -31,10 +55,11 @@ export const COLOR_PROPERTIES = [
31
55
  "background3"
32
56
  ];
33
57
  export const NON_COLOR_PROPERTIES = [
58
+ "id",
34
59
  "dark",
60
+ "light",
35
61
  "seasonal",
36
62
  "dateRange",
37
63
  "translations",
38
64
  "icon"
39
65
  ];
40
- export const CSS_HEADER = "/* ============================================ */";
@@ -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
+ }
@@ -1,47 +1,99 @@
1
+ import { isColorTheme } from "../utils/theme-resolve.js";
2
+ import { generateCursorSVG } from "./cursor-svg.js";
3
+ import { CURSOR_ATTRIBUTE } from "../constants.js";
4
+ const CURSOR_TYPES = ["default", "pointer", "text"];
5
+ const imageValue = (image, type) => `url('${image.path}')${image.hotspot ? ` ${image.hotspot}` : ""}, ${type}`;
1
6
  export function generateCustomCursorCSS(theme) {
2
7
  const cursor = theme.customCursor;
3
- if (!cursor || !cursor.enabled || !cursor.cursors) return "";
4
- const cursors = cursor.cursors;
8
+ if (!cursor || !cursor.enabled) return "";
9
+ const images = cursor.defaultCursors ?? {};
10
+ const fallback = (type) => images[type] ? imageValue(images[type], type) : type;
11
+ const owners = {};
12
+ for (const [name, group] of Object.entries(theme.colors?.groups ?? {})) {
13
+ for (const id of Object.values(group.variants)) if (id) owners[id] = name;
14
+ }
15
+ const variants = [];
16
+ if (theme.colors?.enabled !== false) {
17
+ for (const [id, colors] of Object.entries(theme.colors?.themes ?? {})) {
18
+ if (id === "system" || !isColorTheme(colors)) continue;
19
+ const entry = cursor.themeCursors?.[id] ?? (owners[id] ? cursor.themeCursors?.[owners[id]] : void 0);
20
+ const own = typeof entry === "object" ? entry : {};
21
+ const mode = typeof entry === "string" ? entry : cursor.themed === false ? "base" : "themed";
22
+ const values = {};
23
+ for (const type of CURSOR_TYPES) {
24
+ const image = own[type];
25
+ if (image) {
26
+ values[type] = imageValue(image, type);
27
+ } else if (mode === "none") {
28
+ values[type] = type;
29
+ } else if (mode === "themed" && colors.primary?.startsWith("#")) {
30
+ const { url, hotspot } = generateCursorSVG(type, colors.primary);
31
+ values[type] = `url("${url}") ${hotspot}, ${fallback(type)}`;
32
+ }
33
+ }
34
+ if (Object.keys(values).length) variants.push([id, values]);
35
+ }
36
+ }
37
+ const types = CURSOR_TYPES.filter((type) => images[type] || variants.some(([, values]) => values[type]));
38
+ if (!types.length) return "";
5
39
  let css = "\n/* ============================================ */\n";
6
40
  css += "/* Custom Cursor */\n";
7
41
  css += "/* ============================================ */\n";
8
- const cursorValue = (type) => {
9
- if (!cursors[type]) return null;
10
- const { path, hotspot } = cursors[type];
11
- const hotspotStr = hotspot ? ` ${hotspot}` : "";
12
- return `url('${path}')${hotspotStr}, ${type}`;
13
- };
14
- if (cursors.default) {
15
- const value = cursorValue("default");
42
+ css += "\n/* 0. Cursor values: the default cursors, then each theme's own (drawn in its color, its images or the system's) */\n";
43
+ css += `:root {
44
+ ${types.map((type) => ` --cursor-${type}: ${fallback(type)};`).join("\n")}
45
+ }
46
+ `;
47
+ for (const [id, values] of variants) {
48
+ const vars = types.filter((type) => values[type]).map((type) => ` --cursor-${type}: ${values[type]};`);
49
+ css += `:root[data-theme='${id}'] {
50
+ ${vars.join("\n")}
51
+ }
52
+ `;
53
+ }
54
+ css += `:root[${CURSOR_ATTRIBUTE}='off'] {
55
+ ${types.map((type) => ` --cursor-${type}: ${type};`).join("\n")}
56
+ }
57
+ `;
58
+ if (types.includes("default")) {
16
59
  css += "\n/* 1. Default cursor on everything */\n";
17
- css += `body {
18
- cursor: ${value};
60
+ css += `html {
61
+ cursor: var(--cursor-default);
62
+ }
63
+ `;
64
+ css += "\n/* 1b. Elements the browser stylesheet sets to `cursor: default`, which would show the system arrow instead of inheriting */\n";
65
+ css += `label,
66
+ select,
67
+ input[type="checkbox"], input[type="radio"],
68
+ input[type="range"], input[type="color"], input[type="file"] {
69
+ cursor: var(--cursor-default);
19
70
  }
20
71
  `;
21
72
  }
22
- if (cursors.pointer) {
23
- const value = cursorValue("pointer");
73
+ if (types.includes("pointer")) {
24
74
  css += "\n/* 2. Pointer cursor for clickable elements */\n";
25
- css += `a, a *,
75
+ css += `a[href], a[href] *,
26
76
  button, button *,
27
- [role="button"],
77
+ summary,
78
+ [role="button"], [role="link"], [role="tab"],
28
79
  input[type="button"], input[type="submit"], input[type="reset"],
29
80
  .v-btn:not(.v-btn--disabled),
30
- .v-list-item,
31
- .v-icon,
81
+ .v-icon--clickable,
82
+ .v-list-item--link,
83
+ .v-chip--link,
32
84
  .v-tab,
33
- .v-chip,
34
85
  .v-card--link,
35
86
  .v-breadcrumbs-item--link,
36
- .v-pagination__item {
37
- cursor: ${value} !important;
87
+ .v-pagination__item,
88
+ .os-scrollbar, .os-scrollbar * {
89
+ cursor: var(--cursor-pointer) !important;
38
90
  }
39
91
  `;
40
92
  }
41
- if (cursors.text) {
42
- const value = cursorValue("text");
93
+ if (types.includes("text")) {
43
94
  css += "\n/* 3. Text cursor (i-beam) for editable fields only */\n";
44
- css += `input[type="text"],
95
+ css += `input:not([type]),
96
+ input[type="text"],
45
97
  input[type="email"],
46
98
  input[type="password"],
47
99
  input[type="number"],
@@ -54,19 +106,19 @@ input[type="month"],
54
106
  input[type="week"],
55
107
  input[type="time"],
56
108
  textarea,
57
- select,
58
- [contenteditable="true"] {
59
- cursor: ${value} !important;
109
+ [contenteditable=""], [contenteditable="true"], [contenteditable="plaintext-only"] {
110
+ cursor: var(--cursor-text) !important;
60
111
  }
61
112
  `;
62
113
  }
63
- if (cursors.default) {
64
- const value = cursorValue("default");
65
- css += "\n/* 4. Disabled elements */\n";
66
- css += `.v-btn--disabled,
67
- [disabled],
68
- .disabled {
69
- cursor: ${value} !important;
114
+ if (types.includes("default")) {
115
+ css += "\n/* 4. Disabled elements, and what they contain */\n";
116
+ css += `html :disabled, html :disabled *,
117
+ html [disabled], html [disabled] *,
118
+ html [aria-disabled="true"], html [aria-disabled="true"] *,
119
+ html .disabled,
120
+ html .v-btn--disabled, html .v-btn--disabled * {
121
+ cursor: var(--cursor-default) !important;
70
122
  }
71
123
  `;
72
124
  }
@@ -1,8 +1,2 @@
1
1
  import type { ThemeConfig } from '../types/index.js';
2
- export interface ProcessOptions {
3
- typography?: boolean;
4
- customScrollbar?: boolean;
5
- customCursor?: boolean;
6
- colors?: boolean;
7
- }
8
- export declare function processTheme(theme: ThemeConfig, options?: ProcessOptions): string;
2
+ export declare function processTheme(theme: ThemeConfig): string;
@@ -4,13 +4,13 @@ import { generateCustomScrollbarCSS } from "./scrollbar.js";
4
4
  import { generateCustomCursorCSS } from "./cursor.js";
5
5
  import { generateThemeTransitionCSS } from "./transition.js";
6
6
  import { isColorTheme } from "../utils/theme-resolve.js";
7
- export function processTheme(theme, options = {}) {
7
+ export function processTheme(theme) {
8
8
  const output = [];
9
- if (options.typography !== false && theme.typography?.enabled !== false) {
9
+ if (theme.typography?.enabled !== false) {
10
10
  output.push(generateFontFaces(theme));
11
11
  output.push(generateRootVars(theme));
12
12
  }
13
- if (options.colors !== false && theme.colors?.enabled !== false) {
13
+ if (theme.colors?.enabled !== false) {
14
14
  if (theme.colors?.themes) {
15
15
  output.push(generateThemeTransitionCSS());
16
16
  for (const [themeName, themeColors] of Object.entries(theme.colors.themes)) {
@@ -19,11 +19,11 @@ export function processTheme(theme, options = {}) {
19
19
  }
20
20
  }
21
21
  }
22
- if (options.customScrollbar !== false && theme.customScrollbar?.enabled !== false) {
22
+ if (theme.customScrollbar?.enabled !== false) {
23
23
  const scrollbarCSS = generateCustomScrollbarCSS(theme);
24
24
  if (scrollbarCSS) output.push(scrollbarCSS);
25
25
  }
26
- if (options.customCursor !== false && theme.customCursor?.enabled !== false) {
26
+ if (theme.customCursor?.enabled !== false) {
27
27
  const cursorCSS = generateCustomCursorCSS(theme);
28
28
  if (cursorCSS) output.push(cursorCSS);
29
29
  }