@venix-sistemas/jade 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +339 -222
- package/dist/module.json +1 -1
- package/dist/module.mjs +25 -11
- package/dist/runtime/components/VenixThemeSwitcher.d.vue.ts +1 -1
- package/dist/runtime/components/VenixThemeSwitcher.vue +242 -99
- package/dist/runtime/components/VenixThemeSwitcher.vue.d.ts +1 -1
- package/dist/runtime/composables/useThemeColors.d.ts +6 -0
- package/dist/runtime/composables/useThemeColors.js +24 -9
- package/dist/runtime/composables/useThemeCookies.d.ts +9 -2
- package/dist/runtime/composables/useThemeCookies.js +24 -6
- package/dist/runtime/composables/useThemeLocale.d.ts +5 -0
- package/dist/runtime/composables/useThemeLocale.js +2 -2
- package/dist/runtime/composables/useThemeSeasonal.d.ts +2 -2
- package/dist/runtime/composables/useThemeSeasonal.js +1 -1
- package/dist/runtime/composables/useVenixTheme.d.ts +20 -0
- package/dist/runtime/composables/useVenixTheme.js +168 -108
- package/dist/runtime/nitro/theme-init.js +8 -5
- package/dist/runtime/plugins/theme-init.server.js +7 -12
- package/dist/runtime/plugins/vuetify-theme.js +8 -11
- package/dist/runtime/scripts/theme-init.d.ts +23 -10
- package/dist/runtime/scripts/theme-init.js +42 -88
- package/dist/shared/constants.d.ts +18 -3
- package/dist/shared/constants.js +6 -1
- package/dist/shared/css/cursor.js +9 -2
- package/dist/shared/css/index.d.ts +1 -7
- package/dist/shared/css/index.js +5 -5
- package/dist/shared/css/transition.d.ts +1 -1
- package/dist/shared/theme.json +302 -192
- package/dist/shared/types/color-options.d.ts +26 -2
- package/dist/shared/types/colors.d.ts +64 -12
- package/dist/shared/types/index.d.ts +1 -1
- package/dist/shared/types/runtime-config.d.ts +4 -2
- package/dist/shared/utils/icon-refs.d.ts +7 -3
- package/dist/shared/utils/icon.d.ts +4 -2
- package/dist/shared/utils/icon.js +6 -2
- package/dist/shared/utils/index.d.ts +5 -4
- package/dist/shared/utils/index.js +12 -6
- package/dist/shared/utils/inline-script.d.ts +6 -0
- package/dist/shared/utils/inline-script.js +3 -0
- package/dist/shared/utils/load.d.ts +0 -1
- package/dist/shared/utils/load.js +5 -12
- package/dist/shared/utils/merge-themes.d.ts +39 -9
- package/dist/shared/utils/merge-themes.js +101 -5
- package/dist/shared/utils/normalize.d.ts +0 -11
- package/dist/shared/utils/normalize.js +0 -12
- package/dist/shared/utils/theme-config.d.ts +13 -4
- package/dist/shared/utils/theme-config.js +28 -15
- package/dist/shared/utils/theme-resolve.d.ts +15 -23
- package/dist/shared/utils/theme-resolve.js +18 -67
- package/dist/shared/utils/theme-resolver.d.ts +46 -0
- package/dist/shared/utils/theme-resolver.js +139 -0
- package/package.json +13 -10
- package/README-default.md +0 -84
- package/dist/runtime/plugin.d.ts +0 -2
- package/dist/runtime/plugin.js +0 -3
|
@@ -1,10 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
+
} from "../../shared/constants";
|
|
10
|
+
export default function initTheme(createThemeResolver2, themeData, options) {
|
|
11
|
+
const resolver = createThemeResolver2();
|
|
12
|
+
const { requireConsent, cookies, cookieMaxAge, consentStorageKey } = options;
|
|
5
13
|
function hasCookieConsent() {
|
|
6
14
|
if (typeof localStorage === "undefined") return false;
|
|
7
|
-
const consentData = localStorage.getItem(
|
|
15
|
+
const consentData = localStorage.getItem(consentStorageKey);
|
|
8
16
|
if (!consentData) return false;
|
|
9
17
|
try {
|
|
10
18
|
const consent = JSON.parse(consentData);
|
|
@@ -19,97 +27,43 @@ export default function initTheme(themeData) {
|
|
|
19
27
|
return cookieValue ? decodeURIComponent(cookieValue) : null;
|
|
20
28
|
}
|
|
21
29
|
function setCookieIfConsented(name, value) {
|
|
22
|
-
if (hasCookieConsent()) {
|
|
23
|
-
document.cookie = `${name}=${encodeURIComponent(value)}; path=/; max-age
|
|
30
|
+
if (!requireConsent || hasCookieConsent()) {
|
|
31
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; path=/; max-age=${cookieMaxAge}; SameSite=Lax`;
|
|
24
32
|
}
|
|
25
33
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
}
|
|
34
|
+
const colors = {
|
|
35
|
+
themes: themeData.colors?.themes || {},
|
|
36
|
+
groups: themeData.colors?.groups || {},
|
|
37
|
+
defaultColor: themeData.colors?.defaultColor
|
|
38
|
+
};
|
|
94
39
|
const html = document.documentElement;
|
|
95
|
-
const
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
const resolvedCookie = getCookie(THEME_RESOLVED_COOKIE);
|
|
40
|
+
const preference = getCookie(cookies.preference);
|
|
41
|
+
const modePreference = getCookie(cookies.mode);
|
|
42
|
+
const resolvedCookie = getCookie(cookies.resolved);
|
|
99
43
|
const systemPrefersDark = typeof window.matchMedia === "function" && window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
theme = resolvedCookie;
|
|
103
|
-
} else {
|
|
104
|
-
theme = resolveThemePreference(preference || void 0, themes, defaultTheme, systemPrefersDark);
|
|
105
|
-
}
|
|
44
|
+
const selection = resolver.normalizeThemeSelection(preference, modePreference, colors);
|
|
45
|
+
const theme = resolver.resolveThemeSelection(selection, colors, systemPrefersDark);
|
|
106
46
|
html.classList.add(theme);
|
|
107
47
|
html.setAttribute("data-theme", theme);
|
|
108
48
|
window.__VENIX_INITIAL_THEME__ = theme;
|
|
109
|
-
if (
|
|
110
|
-
setCookieIfConsented(
|
|
49
|
+
if (resolvedCookie !== theme) {
|
|
50
|
+
setCookieIfConsented(cookies.resolved, theme);
|
|
111
51
|
}
|
|
112
52
|
if (!preference) {
|
|
113
|
-
setCookieIfConsented(
|
|
53
|
+
setCookieIfConsented(cookies.preference, selection.theme);
|
|
114
54
|
}
|
|
55
|
+
if (!modePreference) {
|
|
56
|
+
setCookieIfConsented(cookies.mode, selection.mode);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
export function createInitThemeOptions(requireConsent) {
|
|
60
|
+
return {
|
|
61
|
+
requireConsent,
|
|
62
|
+
cookies: { preference: THEME_PREFERENCE_COOKIE, mode: THEME_MODE_COOKIE, resolved: THEME_RESOLVED_COOKIE },
|
|
63
|
+
cookieMaxAge: THEME_COOKIE_MAX_AGE,
|
|
64
|
+
consentStorageKey: COOKIE_CONSENT_STORAGE_KEY
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export function renderInitThemeScript(themeData, options) {
|
|
68
|
+
return `(${initTheme.toString()})(${createThemeResolver.toString()}, ${toInlineScriptJson(themeData)}, ${toInlineScriptJson(options)})`;
|
|
115
69
|
}
|
|
@@ -1,5 +1,20 @@
|
|
|
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
|
+
};
|
|
3
18
|
export declare const COOKIE_PREFERENCES_UPDATED_EVENT = "venix-cookie-preferences-updated";
|
|
4
19
|
/**
|
|
5
20
|
* Dispatched synchronously by `apply()` (useVenixTheme.ts), inside the same
|
|
@@ -16,13 +31,13 @@ export declare const COOKIE_PREFERENCES_UPDATED_EVENT = "venix-cookie-preference
|
|
|
16
31
|
* `data-theme` change, as part of the same transition.
|
|
17
32
|
*/
|
|
18
33
|
export declare const THEME_APPLIED_EVENT = "venix-theme-applied";
|
|
19
|
-
/**
|
|
34
|
+
/** Where functional-cookie consent is stored — written by `persistence.grant()/revoke()` or by the consumer app's own consent UI. */
|
|
20
35
|
export declare const COOKIE_CONSENT_STORAGE_KEY = "venix-cookie-consent";
|
|
21
36
|
export declare const DEFAULT_LOCALE = "en-US";
|
|
22
37
|
export declare const DEFAULT_LOCALE_COOKIE_NAME = "i18n_redirected";
|
|
23
38
|
export declare const LOCALE_MAP: Record<string, string>;
|
|
24
39
|
export declare const DEFAULT_THEME = "dark";
|
|
25
40
|
export declare const SYSTEM_THEME = "system";
|
|
41
|
+
export declare const THEME_MODES: readonly ["light", "dark"];
|
|
26
42
|
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 = "/* ============================================ */";
|
|
43
|
+
export declare const NON_COLOR_PROPERTIES: readonly ["id", "dark", "light", "seasonal", "dateRange", "translations", "icon"];
|
package/dist/shared/constants.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
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" };
|
|
3
6
|
export const COOKIE_PREFERENCES_UPDATED_EVENT = "venix-cookie-preferences-updated";
|
|
4
7
|
export const THEME_APPLIED_EVENT = "venix-theme-applied";
|
|
5
8
|
export const COOKIE_CONSENT_STORAGE_KEY = "venix-cookie-consent";
|
|
@@ -18,6 +21,7 @@ export const LOCALE_MAP = {
|
|
|
18
21
|
};
|
|
19
22
|
export const DEFAULT_THEME = "dark";
|
|
20
23
|
export const SYSTEM_THEME = "system";
|
|
24
|
+
export const THEME_MODES = ["light", "dark"];
|
|
21
25
|
export const COLOR_PROPERTIES = [
|
|
22
26
|
"primary",
|
|
23
27
|
"secondary",
|
|
@@ -31,10 +35,11 @@ export const COLOR_PROPERTIES = [
|
|
|
31
35
|
"background3"
|
|
32
36
|
];
|
|
33
37
|
export const NON_COLOR_PROPERTIES = [
|
|
38
|
+
"id",
|
|
34
39
|
"dark",
|
|
40
|
+
"light",
|
|
35
41
|
"seasonal",
|
|
36
42
|
"dateRange",
|
|
37
43
|
"translations",
|
|
38
44
|
"icon"
|
|
39
45
|
];
|
|
40
|
-
export const CSS_HEADER = "/* ============================================ */";
|
|
@@ -14,7 +14,15 @@ export function generateCustomCursorCSS(theme) {
|
|
|
14
14
|
if (cursors.default) {
|
|
15
15
|
const value = cursorValue("default");
|
|
16
16
|
css += "\n/* 1. Default cursor on everything */\n";
|
|
17
|
-
css += `
|
|
17
|
+
css += `html {
|
|
18
|
+
cursor: ${value};
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
css += "\n/* 1b. Elements the browser stylesheet sets to `cursor: default`, which would show the system arrow instead of inheriting */\n";
|
|
22
|
+
css += `label,
|
|
23
|
+
select,
|
|
24
|
+
input[type="checkbox"], input[type="radio"],
|
|
25
|
+
input[type="range"], input[type="color"], input[type="file"] {
|
|
18
26
|
cursor: ${value};
|
|
19
27
|
}
|
|
20
28
|
`;
|
|
@@ -54,7 +62,6 @@ input[type="month"],
|
|
|
54
62
|
input[type="week"],
|
|
55
63
|
input[type="time"],
|
|
56
64
|
textarea,
|
|
57
|
-
select,
|
|
58
65
|
[contenteditable="true"] {
|
|
59
66
|
cursor: ${value} !important;
|
|
60
67
|
}
|
|
@@ -1,8 +1,2 @@
|
|
|
1
1
|
import type { ThemeConfig } from '../types/index.js';
|
|
2
|
-
export
|
|
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;
|
package/dist/shared/css/index.js
CHANGED
|
@@ -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
|
|
7
|
+
export function processTheme(theme) {
|
|
8
8
|
const output = [];
|
|
9
|
-
if (
|
|
9
|
+
if (theme.typography?.enabled !== false) {
|
|
10
10
|
output.push(generateFontFaces(theme));
|
|
11
11
|
output.push(generateRootVars(theme));
|
|
12
12
|
}
|
|
13
|
-
if (
|
|
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 (
|
|
22
|
+
if (theme.customScrollbar?.enabled !== false) {
|
|
23
23
|
const scrollbarCSS = generateCustomScrollbarCSS(theme);
|
|
24
24
|
if (scrollbarCSS) output.push(scrollbarCSS);
|
|
25
25
|
}
|
|
26
|
-
if (
|
|
26
|
+
if (theme.customCursor?.enabled !== false) {
|
|
27
27
|
const cursorCSS = generateCustomCursorCSS(theme);
|
|
28
28
|
if (cursorCSS) output.push(cursorCSS);
|
|
29
29
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
/**
|
|
1
|
+
/** CSS for the native cross-fade (View Transitions API) when switching themes: its duration and pointer pass-through. */
|
|
2
2
|
export declare function generateThemeTransitionCSS(): string;
|