@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.
- package/README.md +555 -228
- package/dist/module.json +1 -1
- package/dist/module.mjs +89 -13
- package/dist/runtime/components/VenixThemeSwitcher.d.vue.ts +3 -1
- package/dist/runtime/components/VenixThemeSwitcher.vue +592 -106
- package/dist/runtime/components/VenixThemeSwitcher.vue.d.ts +3 -1
- package/dist/runtime/composables/useThemeColors.d.ts +8 -2
- package/dist/runtime/composables/useThemeColors.js +24 -9
- package/dist/runtime/composables/useThemeCookies.d.ts +17 -2
- package/dist/runtime/composables/useThemeCookies.js +44 -7
- package/dist/runtime/composables/useThemeLocale.d.ts +7 -2
- package/dist/runtime/composables/useThemeLocale.js +2 -2
- package/dist/runtime/composables/useThemeSeasonal.d.ts +3 -3
- package/dist/runtime/composables/useThemeSeasonal.js +1 -1
- package/dist/runtime/composables/useVenixTheme.d.ts +40 -0
- package/dist/runtime/composables/useVenixTheme.js +249 -112
- package/dist/runtime/nitro/theme-init.js +8 -5
- package/dist/runtime/plugins/overlay-scrollbars.client.js +89 -0
- 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 +33 -11
- package/dist/runtime/scripts/theme-init.js +59 -88
- package/dist/shared/constants.d.ts +72 -3
- package/dist/shared/constants.js +26 -1
- package/dist/shared/css/cursor-svg.d.ts +10 -0
- package/dist/shared/css/cursor-svg.js +28 -0
- package/dist/shared/css/cursor.js +86 -34
- package/dist/shared/css/index.d.ts +1 -7
- package/dist/shared/css/index.js +5 -5
- package/dist/shared/css/scrollbar.js +61 -7
- package/dist/shared/css/transition.d.ts +1 -1
- package/dist/shared/css/typography.js +13 -0
- package/dist/shared/theme.json +308 -192
- package/dist/shared/types/color-options.d.ts +26 -2
- package/dist/shared/types/colors.d.ts +64 -12
- package/dist/shared/types/cursor.d.ts +34 -4
- package/dist/shared/types/index.d.ts +3 -3
- package/dist/shared/types/runtime-config.d.ts +5 -2
- package/dist/shared/types/scrollbar.d.ts +11 -0
- package/dist/shared/types/theme.d.ts +7 -0
- package/dist/shared/types/typography.d.ts +2 -1
- 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 +2 -3
- package/dist/shared/utils/load.js +6 -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 +15 -6
- package/dist/shared/utils/theme-config.js +28 -16
- package/dist/shared/utils/theme-resolve.d.ts +23 -22
- package/dist/shared/utils/theme-resolve.js +35 -66
- package/dist/shared/utils/theme-resolver.d.ts +47 -0
- package/dist/shared/utils/theme-resolver.js +140 -0
- package/package.json +22 -10
- package/README-default.md +0 -84
- package/dist/runtime/plugin.js +0 -3
- /package/dist/runtime/{plugin.d.ts → plugins/overlay-scrollbars.client.d.ts} +0 -0
|
@@ -1,24 +1,36 @@
|
|
|
1
1
|
import themeData from "../theme.json" with { type: "json" };
|
|
2
2
|
import { DEFAULT_THEME } from "../constants.js";
|
|
3
|
-
import { mergeColorThemes } from "./merge-themes.js";
|
|
3
|
+
import { mergeColorThemes, normalizeColorThemes } from "./merge-themes.js";
|
|
4
|
+
export function getBaseThemeEntries() {
|
|
5
|
+
return themeData.colors?.themes ?? {};
|
|
6
|
+
}
|
|
7
|
+
const resolvedThemeCache = /* @__PURE__ */ new WeakMap();
|
|
4
8
|
export function buildResolvedTheme(runtimeThemeConfig) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
9
|
+
if (!runtimeThemeConfig) return resolveTheme();
|
|
10
|
+
let resolved = resolvedThemeCache.get(runtimeThemeConfig);
|
|
11
|
+
if (!resolved) {
|
|
12
|
+
resolved = resolveTheme(runtimeThemeConfig);
|
|
13
|
+
resolvedThemeCache.set(runtimeThemeConfig, resolved);
|
|
14
|
+
}
|
|
15
|
+
return resolved;
|
|
16
|
+
}
|
|
17
|
+
function resolveTheme(runtimeThemeConfig) {
|
|
18
|
+
const rawColors = themeData.colors ?? {};
|
|
19
|
+
const baseEntries = getBaseThemeEntries();
|
|
20
|
+
const merged = mergeColorThemes(baseEntries, runtimeThemeConfig?.colorThemes);
|
|
21
|
+
const entries = runtimeThemeConfig?.seasonal === false ? Object.fromEntries(Object.entries(merged).filter(([, entry]) => entry.seasonal !== true)) : merged;
|
|
22
|
+
const { themes, groups } = normalizeColorThemes(entries);
|
|
23
|
+
for (const [name, group] of Object.entries(groups)) {
|
|
24
|
+
if (!(name in baseEntries)) group.custom = true;
|
|
25
|
+
}
|
|
12
26
|
return {
|
|
13
|
-
...themeData,
|
|
14
27
|
colors: {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
themes: mergeColorThemes(baseColors.themes, runtimeThemeConfig?.colorThemes)
|
|
28
|
+
enabled: rawColors.enabled ?? true,
|
|
29
|
+
defaults: rawColors.defaults ?? true,
|
|
30
|
+
defaultColor: runtimeThemeConfig?.defaultTheme || rawColors.defaultColor || DEFAULT_THEME,
|
|
31
|
+
modes: rawColors.modes ?? {},
|
|
32
|
+
themes,
|
|
33
|
+
groups
|
|
22
34
|
}
|
|
23
35
|
};
|
|
24
36
|
}
|
|
@@ -1,32 +1,33 @@
|
|
|
1
|
-
import type { ThemeColors } from '../types/index.js';
|
|
1
|
+
import type { ThemeColors, ThemeMeta } from '../types/index.js';
|
|
2
|
+
import type { ColorModel } from './theme-resolver.js';
|
|
3
|
+
export type { ColorModel, ThemeSelection } from './theme-resolver.js';
|
|
4
|
+
export declare const isColorTheme: (themeConfig: ThemeColors | undefined) => boolean, getEasterSunday: (year: number) => Date, parseDatePart: (value: string, year: number) => number | null, isModePreference: (value: unknown) => value is import("../types/index.js").ThemeModePreference, isSelectableGroup: (colors: ColorModel, name: string) => boolean, findVariantOwner: (colors: ColorModel, id: string) => {
|
|
5
|
+
theme: string;
|
|
6
|
+
mode: import("../types/index.js").ThemeMode;
|
|
7
|
+
} | null, getDefaultSelection: (colors: ColorModel) => import("./theme-resolver.js").ThemeSelection & {
|
|
8
|
+
fallbackTheme: string;
|
|
9
|
+
}, normalizeThemeSelection: (themePreference: string | null | undefined, modePreference: string | null | undefined, colors: ColorModel) => import("./theme-resolver.js").ThemeSelection, getActiveSeasonalTheme: (groups: Record<string, import("../types/index.js").ResolvedThemeGroup>, mode?: import("../types/index.js").ThemeMode, now?: Date) => string | null, resolveMode: (mode: import("../types/index.js").ThemeModePreference, prefersDark: boolean) => import("../types/index.js").ThemeMode, resolveThemeSelection: (selection: import("./theme-resolver.js").ThemeSelection, colors: ColorModel, prefersDark: boolean, now?: Date) => string, resolveThemePreference: (themePreference: string | null | undefined, modePreference: string | null | undefined, colors: ColorModel, prefersDark: boolean, now?: Date) => string;
|
|
2
10
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* color, and don't count.
|
|
11
|
+
* When a seasonal theme is on: the occurrence of its `dateRange` that's
|
|
12
|
+
* running or comes next from `now` (next year's once this year's is over,
|
|
13
|
+
* which moves for ranges relative to Easter). `null` without a valid range.
|
|
7
14
|
*/
|
|
8
|
-
export declare function
|
|
15
|
+
export declare function getSeasonDates(meta: ThemeMeta, now?: Date): {
|
|
16
|
+
start: Date;
|
|
17
|
+
end: Date;
|
|
18
|
+
} | null;
|
|
9
19
|
/**
|
|
10
20
|
* The theme's actual color entries (hex values only) — skips metadata like
|
|
11
21
|
* `dark`/`translations`/`icon`. Shared by the CSS generator and the Vuetify
|
|
12
22
|
* theme registration, so both always agree on what counts as a color.
|
|
13
23
|
*/
|
|
14
24
|
export declare function getThemeHexColors(themeConfig: ThemeColors): Array<[string, string]>;
|
|
15
|
-
/** Easter Sunday (Gregorian calendar) — anonymous Gregorian algorithm (Meeus/Jones/Butcher). */
|
|
16
|
-
export declare function getEasterSunday(year: number): Date;
|
|
17
25
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
26
|
+
* Best guess at the theme to render where `matchMedia` doesn't exist (SSR):
|
|
27
|
+
* the resolved cookie (the variant last applied on the client) only hints
|
|
28
|
+
* whether the OS prefers dark, for mode `'system'`. It's never returned as
|
|
29
|
+
* is: with theme `'system'` that cookie can be from another season, or from
|
|
30
|
+
* before the OS switched modes, and trusting it kept that stale theme. The
|
|
31
|
+
* pre-hydration script then corrects the mode guess before the first paint.
|
|
21
32
|
*/
|
|
22
|
-
export declare function
|
|
23
|
-
/**
|
|
24
|
-
* Resolves a theme preference (`'system'`, a theme name, or empty) to the
|
|
25
|
-
* concrete color theme that should be applied. Single implementation of this
|
|
26
|
-
* rule — used by `useVenixTheme`/`useThemeSeasonal` and the SSR plugin
|
|
27
|
-
* (`theme-init.server.ts`). The pre-hydration script
|
|
28
|
-
* (`runtime/scripts/theme-init.ts`) is the one documented exception: it has
|
|
29
|
-
* to run as a self-contained IIFE (no imports), so it deliberately duplicates
|
|
30
|
-
* this logic — keep the two in sync when changing either.
|
|
31
|
-
*/
|
|
32
|
-
export declare function resolveThemePreference(preference: string | undefined, themes: Record<string, ThemeColors>, defaultTheme: string, prefersDark: boolean): string;
|
|
33
|
+
export declare function resolveServerTheme(themePreference: string | null | undefined, modePreference: string | null | undefined, resolvedHint: string | null | undefined, colors: ColorModel, now?: Date): string;
|
|
@@ -1,7 +1,35 @@
|
|
|
1
1
|
import { NON_COLOR_PROPERTIES } from "../constants.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { createThemeResolver } from "./theme-resolver.js";
|
|
3
|
+
export const {
|
|
4
|
+
isColorTheme,
|
|
5
|
+
getEasterSunday,
|
|
6
|
+
parseDatePart,
|
|
7
|
+
isModePreference,
|
|
8
|
+
isSelectableGroup,
|
|
9
|
+
findVariantOwner,
|
|
10
|
+
getDefaultSelection,
|
|
11
|
+
normalizeThemeSelection,
|
|
12
|
+
getActiveSeasonalTheme,
|
|
13
|
+
resolveMode,
|
|
14
|
+
resolveThemeSelection,
|
|
15
|
+
resolveThemePreference
|
|
16
|
+
} = createThemeResolver();
|
|
17
|
+
export function getSeasonDates(meta, now = /* @__PURE__ */ new Date()) {
|
|
18
|
+
if (meta.seasonal !== true || !meta.dateRange) return null;
|
|
19
|
+
const { start, end } = meta.dateRange;
|
|
20
|
+
const toDate = (bound, year2) => {
|
|
21
|
+
const value = parseDatePart(bound, year2);
|
|
22
|
+
return value === null ? null : new Date(year2, Math.floor(value / 100) - 1, value % 100);
|
|
23
|
+
};
|
|
24
|
+
const year = now.getFullYear();
|
|
25
|
+
const today = new Date(year, now.getMonth(), now.getDate());
|
|
26
|
+
const startThisYear = toDate(start, year);
|
|
27
|
+
const endThisYear = toDate(end, year);
|
|
28
|
+
if (!startThisYear || !endThisYear) return null;
|
|
29
|
+
if (startThisYear > endThisYear) {
|
|
30
|
+
return today <= endThisYear ? { start: toDate(start, year - 1), end: endThisYear } : { start: startThisYear, end: toDate(end, year + 1) };
|
|
31
|
+
}
|
|
32
|
+
return today <= endThisYear ? { start: startThisYear, end: endThisYear } : { start: toDate(start, year + 1), end: toDate(end, year + 1) };
|
|
5
33
|
}
|
|
6
34
|
export function getThemeHexColors(themeConfig) {
|
|
7
35
|
const result = [];
|
|
@@ -11,67 +39,8 @@ export function getThemeHexColors(themeConfig) {
|
|
|
11
39
|
}
|
|
12
40
|
return result;
|
|
13
41
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const c = year % 100;
|
|
19
|
-
const d = Math.floor(b / 4);
|
|
20
|
-
const e = b % 4;
|
|
21
|
-
const f = Math.floor((b + 8) / 25);
|
|
22
|
-
const g = Math.floor((b - f + 1) / 3);
|
|
23
|
-
const h = (19 * a + b - d - g + 15) % 30;
|
|
24
|
-
const i = Math.floor(c / 4);
|
|
25
|
-
const k = c % 4;
|
|
26
|
-
const l = (32 + 2 * e + 2 * i - h - k) % 7;
|
|
27
|
-
const m = Math.floor((a + 11 * h + 22 * l) / 451);
|
|
28
|
-
const month = Math.floor((h + l - 7 * m + 114) / 31);
|
|
29
|
-
const day = (h + l - 7 * m + 114) % 31 + 1;
|
|
30
|
-
return new Date(year, month - 1, day);
|
|
31
|
-
}
|
|
32
|
-
function parseDatePart(value, year) {
|
|
33
|
-
const easter = EASTER_RELATIVE.exec(value.trim());
|
|
34
|
-
if (easter) {
|
|
35
|
-
const date = getEasterSunday(year);
|
|
36
|
-
date.setDate(date.getDate() + Number(easter[1] ?? 0));
|
|
37
|
-
return (date.getMonth() + 1) * 100 + date.getDate();
|
|
38
|
-
}
|
|
39
|
-
const parts = value.split("-").map(Number);
|
|
40
|
-
if (parts.length !== 2) return null;
|
|
41
|
-
const [month, day] = parts;
|
|
42
|
-
if (month === void 0 || day === void 0) return null;
|
|
43
|
-
return month * 100 + day;
|
|
44
|
-
}
|
|
45
|
-
function isDateInSeasonalRange(themeConfig, now) {
|
|
46
|
-
if (themeConfig.seasonal !== true || !themeConfig.dateRange) return false;
|
|
47
|
-
const year = now.getFullYear();
|
|
48
|
-
const startNum = parseDatePart(themeConfig.dateRange.start, year);
|
|
49
|
-
const endNum = parseDatePart(themeConfig.dateRange.end, year);
|
|
50
|
-
if (startNum === null || endNum === null) return false;
|
|
51
|
-
const current = (now.getMonth() + 1) * 100 + now.getDate();
|
|
52
|
-
return startNum <= endNum ? current >= startNum && current <= endNum : current >= startNum || current <= endNum;
|
|
53
|
-
}
|
|
54
|
-
export function getActiveSeasonalTheme(themes, prefersDark, now = /* @__PURE__ */ new Date()) {
|
|
55
|
-
for (const [themeName, themeConfig] of Object.entries(themes)) {
|
|
56
|
-
if (themeName === "system") continue;
|
|
57
|
-
if (!isColorTheme(themeConfig)) continue;
|
|
58
|
-
if (!isDateInSeasonalRange(themeConfig, now)) continue;
|
|
59
|
-
if (prefersDark !== void 0 && themeConfig.dark !== prefersDark) continue;
|
|
60
|
-
return themeName;
|
|
61
|
-
}
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
export function resolveThemePreference(preference, themes, defaultTheme, prefersDark) {
|
|
65
|
-
let resolved;
|
|
66
|
-
if (preference === "system") {
|
|
67
|
-
resolved = getActiveSeasonalTheme(themes, prefersDark) || (prefersDark ? "dark" : "light");
|
|
68
|
-
} else if (preference && isColorTheme(themes[preference])) {
|
|
69
|
-
resolved = preference;
|
|
70
|
-
} else {
|
|
71
|
-
resolved = defaultTheme;
|
|
72
|
-
}
|
|
73
|
-
if (!isColorTheme(themes[resolved])) {
|
|
74
|
-
resolved = isColorTheme(themes[defaultTheme]) ? defaultTheme : "dark";
|
|
75
|
-
}
|
|
76
|
-
return resolved;
|
|
42
|
+
export function resolveServerTheme(themePreference, modePreference, resolvedHint, colors, now = /* @__PURE__ */ new Date()) {
|
|
43
|
+
const hinted = resolvedHint ? colors.themes[resolvedHint] : void 0;
|
|
44
|
+
const prefersDark = hinted && isColorTheme(hinted) ? hinted.dark !== false : true;
|
|
45
|
+
return resolveThemePreference(themePreference, modePreference, colors, prefersDark, now);
|
|
77
46
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ThemeColors, ThemeMode, ThemeModePreference, ResolvedThemeGroup } from '../types/index.js';
|
|
2
|
+
/** The resolved color model the functions below work on (a subset of `ColorsConfig`). */
|
|
3
|
+
export interface ColorModel {
|
|
4
|
+
themes: Record<string, ThemeColors>;
|
|
5
|
+
groups: Record<string, ResolvedThemeGroup>;
|
|
6
|
+
defaultColor?: string;
|
|
7
|
+
}
|
|
8
|
+
/** What the user picked: a theme (or `'system'`: by date) and a mode (or `'system'`: by OS). */
|
|
9
|
+
export interface ThemeSelection {
|
|
10
|
+
theme: string;
|
|
11
|
+
mode: ThemeModePreference;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The theme-resolution rule (which variant to apply for a saved choice, the
|
|
15
|
+
* OS color scheme and today's date), in one place.
|
|
16
|
+
*
|
|
17
|
+
* Has to stay 100% self-contained — no imports used at runtime, no references
|
|
18
|
+
* to anything outside this function (type imports are fine, TypeScript erases
|
|
19
|
+
* them): besides being called normally (see `theme-resolve.ts`), its source is
|
|
20
|
+
* serialized with `toString()` into the inline pre-hydration script
|
|
21
|
+
* (`runtime/nitro/theme-init.ts` → `runtime/scripts/theme-init.ts`), where
|
|
22
|
+
* anything from outside would be a `ReferenceError`. That's also why the two
|
|
23
|
+
* constants below are repeated here instead of imported from
|
|
24
|
+
* `shared/constants.ts` (a test checks they still match).
|
|
25
|
+
*/
|
|
26
|
+
export declare function createThemeResolver(): {
|
|
27
|
+
SYSTEM_THEME: string;
|
|
28
|
+
DEFAULT_THEME: string;
|
|
29
|
+
isColorTheme: (themeConfig: ThemeColors | undefined) => boolean;
|
|
30
|
+
getEasterSunday: (year: number) => Date;
|
|
31
|
+
parseDatePart: (value: string, year: number) => number | null;
|
|
32
|
+
isModePreference: (value: unknown) => value is ThemeModePreference;
|
|
33
|
+
isSelectableGroup: (colors: ColorModel, name: string) => boolean;
|
|
34
|
+
findVariantOwner: (colors: ColorModel, id: string) => {
|
|
35
|
+
theme: string;
|
|
36
|
+
mode: ThemeMode;
|
|
37
|
+
} | null;
|
|
38
|
+
getDefaultSelection: (colors: ColorModel) => ThemeSelection & {
|
|
39
|
+
fallbackTheme: string;
|
|
40
|
+
};
|
|
41
|
+
normalizeThemeSelection: (themePreference: string | null | undefined, modePreference: string | null | undefined, colors: ColorModel) => ThemeSelection;
|
|
42
|
+
getActiveSeasonalTheme: (groups: Record<string, ResolvedThemeGroup>, mode?: ThemeMode, now?: Date) => string | null;
|
|
43
|
+
resolveMode: (mode: ThemeModePreference, prefersDark: boolean) => ThemeMode;
|
|
44
|
+
resolveThemeSelection: (selection: ThemeSelection, colors: ColorModel, prefersDark: boolean, now?: Date) => string;
|
|
45
|
+
resolveThemePreference: (themePreference: string | null | undefined, modePreference: string | null | undefined, colors: ColorModel, prefersDark: boolean, now?: Date) => string;
|
|
46
|
+
};
|
|
47
|
+
export type ThemeResolver = ReturnType<typeof createThemeResolver>;
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
export function createThemeResolver() {
|
|
2
|
+
const SYSTEM_THEME = "system";
|
|
3
|
+
const DEFAULT_THEME = "dark";
|
|
4
|
+
const EASTER_RELATIVE = /^easter([+-]\d+)?$/;
|
|
5
|
+
function isColorTheme(themeConfig) {
|
|
6
|
+
if (!themeConfig) return false;
|
|
7
|
+
return !!themeConfig.primary || !!themeConfig.background;
|
|
8
|
+
}
|
|
9
|
+
function getEasterSunday(year) {
|
|
10
|
+
const a = year % 19;
|
|
11
|
+
const b = Math.floor(year / 100);
|
|
12
|
+
const c = year % 100;
|
|
13
|
+
const d = Math.floor(b / 4);
|
|
14
|
+
const e = b % 4;
|
|
15
|
+
const f = Math.floor((b + 8) / 25);
|
|
16
|
+
const g = Math.floor((b - f + 1) / 3);
|
|
17
|
+
const h = (19 * a + b - d - g + 15) % 30;
|
|
18
|
+
const i = Math.floor(c / 4);
|
|
19
|
+
const k = c % 4;
|
|
20
|
+
const l = (32 + 2 * e + 2 * i - h - k) % 7;
|
|
21
|
+
const m = Math.floor((a + 11 * h + 22 * l) / 451);
|
|
22
|
+
const month = Math.floor((h + l - 7 * m + 114) / 31);
|
|
23
|
+
const day = (h + l - 7 * m + 114) % 31 + 1;
|
|
24
|
+
return new Date(year, month - 1, day);
|
|
25
|
+
}
|
|
26
|
+
function parseDatePart(value, year) {
|
|
27
|
+
const easter = EASTER_RELATIVE.exec(value.trim());
|
|
28
|
+
if (easter) {
|
|
29
|
+
const date = getEasterSunday(year);
|
|
30
|
+
date.setDate(date.getDate() + Number(easter[1] ?? 0));
|
|
31
|
+
return (date.getMonth() + 1) * 100 + date.getDate();
|
|
32
|
+
}
|
|
33
|
+
const parts = value.split("-").map(Number);
|
|
34
|
+
if (parts.length !== 2) return null;
|
|
35
|
+
const [month, day] = parts;
|
|
36
|
+
if (month === void 0 || day === void 0) return null;
|
|
37
|
+
return month * 100 + day;
|
|
38
|
+
}
|
|
39
|
+
function isDateInSeasonalRange(themeConfig, now) {
|
|
40
|
+
if (themeConfig.seasonal !== true || !themeConfig.dateRange) return false;
|
|
41
|
+
const year = now.getFullYear();
|
|
42
|
+
const startNum = parseDatePart(themeConfig.dateRange.start, year);
|
|
43
|
+
const endNum = parseDatePart(themeConfig.dateRange.end, year);
|
|
44
|
+
if (startNum === null || endNum === null) return false;
|
|
45
|
+
const current = (now.getMonth() + 1) * 100 + now.getDate();
|
|
46
|
+
return startNum <= endNum ? current >= startNum && current <= endNum : current >= startNum || current <= endNum;
|
|
47
|
+
}
|
|
48
|
+
function isModePreference(value) {
|
|
49
|
+
return value === "system" || value === "light" || value === "dark";
|
|
50
|
+
}
|
|
51
|
+
function isSelectableGroup(colors, name) {
|
|
52
|
+
const group = colors.groups[name];
|
|
53
|
+
if (!group || name === SYSTEM_THEME) return false;
|
|
54
|
+
return Object.values(group.variants).some((id) => !!id && isColorTheme(colors.themes[id]));
|
|
55
|
+
}
|
|
56
|
+
function findVariantOwner(colors, id) {
|
|
57
|
+
for (const [name, group] of Object.entries(colors.groups)) {
|
|
58
|
+
if (group.variants.dark === id) return { theme: name, mode: "dark" };
|
|
59
|
+
if (group.variants.light === id) return { theme: name, mode: "light" };
|
|
60
|
+
}
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
function getDefaultSelection(colors) {
|
|
64
|
+
const selectable = Object.keys(colors.groups).filter((name) => isSelectableGroup(colors, name));
|
|
65
|
+
const firstRegular = selectable.find((name) => colors.groups[name]?.seasonal !== true) ?? selectable[0] ?? "";
|
|
66
|
+
const defaultColor = colors.defaultColor || DEFAULT_THEME;
|
|
67
|
+
if (isSelectableGroup(colors, defaultColor)) {
|
|
68
|
+
return { theme: defaultColor, mode: "system", fallbackTheme: defaultColor };
|
|
69
|
+
}
|
|
70
|
+
const owner = findVariantOwner(colors, defaultColor);
|
|
71
|
+
if (owner && isSelectableGroup(colors, owner.theme)) {
|
|
72
|
+
return { ...owner, fallbackTheme: owner.theme };
|
|
73
|
+
}
|
|
74
|
+
return { theme: SYSTEM_THEME, mode: "system", fallbackTheme: firstRegular };
|
|
75
|
+
}
|
|
76
|
+
function normalizeThemeSelection(themePreference, modePreference, colors) {
|
|
77
|
+
const defaults = getDefaultSelection(colors);
|
|
78
|
+
let theme = defaults.theme;
|
|
79
|
+
let impliedMode = defaults.mode;
|
|
80
|
+
if (themePreference === SYSTEM_THEME) {
|
|
81
|
+
theme = SYSTEM_THEME;
|
|
82
|
+
impliedMode = "system";
|
|
83
|
+
} else if (themePreference && isSelectableGroup(colors, themePreference)) {
|
|
84
|
+
theme = themePreference;
|
|
85
|
+
} else if (themePreference) {
|
|
86
|
+
const owner = findVariantOwner(colors, themePreference);
|
|
87
|
+
if (owner && isSelectableGroup(colors, owner.theme)) {
|
|
88
|
+
theme = owner.theme;
|
|
89
|
+
impliedMode = owner.mode;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const hasSeasonal = Object.values(colors.groups).some((group) => group.seasonal === true);
|
|
93
|
+
if (theme === SYSTEM_THEME && !hasSeasonal && defaults.fallbackTheme) theme = defaults.fallbackTheme;
|
|
94
|
+
return { theme, mode: isModePreference(modePreference) ? modePreference : impliedMode };
|
|
95
|
+
}
|
|
96
|
+
function getActiveSeasonalTheme(groups, mode, now = /* @__PURE__ */ new Date()) {
|
|
97
|
+
for (const [name, group] of Object.entries(groups)) {
|
|
98
|
+
if (name === SYSTEM_THEME) continue;
|
|
99
|
+
if (!group.variants.dark && !group.variants.light) continue;
|
|
100
|
+
if (!isDateInSeasonalRange(group, now)) continue;
|
|
101
|
+
if (mode !== void 0 && !group.variants[mode]) continue;
|
|
102
|
+
return name;
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
function resolveMode(mode, prefersDark) {
|
|
107
|
+
if (mode === "system") return prefersDark ? "dark" : "light";
|
|
108
|
+
return mode;
|
|
109
|
+
}
|
|
110
|
+
function resolveThemeSelection(selection, colors, prefersDark, now = /* @__PURE__ */ new Date()) {
|
|
111
|
+
const mode = resolveMode(selection.mode, prefersDark);
|
|
112
|
+
const { fallbackTheme } = getDefaultSelection(colors);
|
|
113
|
+
const theme = selection.theme === SYSTEM_THEME ? getActiveSeasonalTheme(colors.groups, mode, now) ?? fallbackTheme : selection.theme;
|
|
114
|
+
const pick = (name) => {
|
|
115
|
+
const variants = colors.groups[name]?.variants;
|
|
116
|
+
const id = variants?.[mode] ?? variants?.[mode === "dark" ? "light" : "dark"];
|
|
117
|
+
return id && isColorTheme(colors.themes[id]) ? id : null;
|
|
118
|
+
};
|
|
119
|
+
return pick(theme) ?? pick(fallbackTheme) ?? Object.keys(colors.themes).find((id) => isColorTheme(colors.themes[id])) ?? DEFAULT_THEME;
|
|
120
|
+
}
|
|
121
|
+
function resolveThemePreference(themePreference, modePreference, colors, prefersDark, now = /* @__PURE__ */ new Date()) {
|
|
122
|
+
return resolveThemeSelection(normalizeThemeSelection(themePreference, modePreference, colors), colors, prefersDark, now);
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
SYSTEM_THEME,
|
|
126
|
+
DEFAULT_THEME,
|
|
127
|
+
isColorTheme,
|
|
128
|
+
getEasterSunday,
|
|
129
|
+
parseDatePart,
|
|
130
|
+
isModePreference,
|
|
131
|
+
isSelectableGroup,
|
|
132
|
+
findVariantOwner,
|
|
133
|
+
getDefaultSelection,
|
|
134
|
+
normalizeThemeSelection,
|
|
135
|
+
getActiveSeasonalTheme,
|
|
136
|
+
resolveMode,
|
|
137
|
+
resolveThemeSelection,
|
|
138
|
+
resolveThemePreference
|
|
139
|
+
};
|
|
140
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venix-sistemas/jade",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.3.0",
|
|
4
|
+
"description": "UI foundation for Nuxt in a single module: color themes (seasonal, SSR, cookie consent), typography, scrollbar, cursor, icons, i18n, plus UnoCSS and Vuetify integrations.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"nuxt",
|
|
7
7
|
"nuxt-module",
|
|
8
|
+
"ui",
|
|
9
|
+
"design-system",
|
|
8
10
|
"nuxt-theme",
|
|
9
11
|
"jade",
|
|
10
12
|
"jade-theme",
|
|
@@ -67,29 +69,39 @@
|
|
|
67
69
|
"@iconify-json/mdi": "^1.2.3",
|
|
68
70
|
"@iconify/utils": "^3.1.7",
|
|
69
71
|
"@nuxt/icon": "^2.5.1",
|
|
70
|
-
"@nuxt/kit": "^4.
|
|
72
|
+
"@nuxt/kit": "^4.6.1"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"overlayscrollbars": "^2.17.0"
|
|
76
|
+
},
|
|
77
|
+
"peerDependenciesMeta": {
|
|
78
|
+
"overlayscrollbars": {
|
|
79
|
+
"optional": true
|
|
80
|
+
}
|
|
71
81
|
},
|
|
72
82
|
"devDependencies": {
|
|
73
|
-
"@nuxt/devtools": "4.0.0-beta.
|
|
83
|
+
"@nuxt/devtools": "4.0.0-beta.5",
|
|
74
84
|
"@nuxt/eslint-config": "^1.17.0",
|
|
75
85
|
"@nuxt/module-builder": "^1.0.3",
|
|
76
|
-
"@nuxt/schema": "^4.
|
|
86
|
+
"@nuxt/schema": "^4.6.1",
|
|
77
87
|
"@nuxt/test-utils": "^4.3.3",
|
|
78
88
|
"@nuxtjs/i18n": "10.6.0",
|
|
79
89
|
"@types/node": "latest",
|
|
80
90
|
"changelogen": "^0.6.2",
|
|
81
91
|
"eslint": "^10.12.0",
|
|
82
|
-
"nuxt": "^4.
|
|
92
|
+
"nuxt": "^4.6.1",
|
|
93
|
+
"overlayscrollbars": "^2.17.0",
|
|
83
94
|
"typescript": "7.0.2",
|
|
84
|
-
"vitest": "5.0.
|
|
85
|
-
"vue-tsc": "^3.3.
|
|
95
|
+
"vitest": "5.0.4",
|
|
96
|
+
"vue-tsc": "^3.3.13"
|
|
86
97
|
},
|
|
87
98
|
"scripts": {
|
|
88
99
|
"dev": "pnpm run dev:prepare && nuxt dev playground",
|
|
89
100
|
"dev:build": "nuxt build playground",
|
|
90
101
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
|
|
91
|
-
"release": "pnpm
|
|
92
|
-
"release
|
|
102
|
+
"release:auth": "pnpm whoami || pnpm login",
|
|
103
|
+
"release": "pnpm run release:auth && pnpm run lint && pnpm run test && pnpm run prepack && changelogen --release && pnpm publish && git push --follow-tags",
|
|
104
|
+
"release:alpha": "pnpm run release:auth && pnpm run lint && pnpm run test && pnpm run prepack && changelogen --release --prerelease alpha && pnpm publish --tag alpha && git push --follow-tags",
|
|
93
105
|
"lint": "eslint .",
|
|
94
106
|
"test": "vitest run",
|
|
95
107
|
"test:watch": "vitest watch",
|
package/README-default.md
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
<!--
|
|
2
|
-
Get your module up and running quickly.
|
|
3
|
-
|
|
4
|
-
Find and replace all on all files (CMD+SHIFT+F):
|
|
5
|
-
- Name: My Module
|
|
6
|
-
- Package name: my-module
|
|
7
|
-
- Description: My new Nuxt module
|
|
8
|
-
-->
|
|
9
|
-
|
|
10
|
-
# My Module
|
|
11
|
-
|
|
12
|
-
[![npm version][npm-version-src]][npm-version-href]
|
|
13
|
-
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
14
|
-
[![License][license-src]][license-href]
|
|
15
|
-
[![Nuxt][nuxt-src]][nuxt-href]
|
|
16
|
-
|
|
17
|
-
My new Nuxt module for doing amazing things.
|
|
18
|
-
|
|
19
|
-
- [✨ Release Notes](/CHANGELOG.md)
|
|
20
|
-
<!-- - [🏀 Online playground](https://stackblitz.com/github/your-org/my-module?file=playground%2Fapp.vue) -->
|
|
21
|
-
<!-- - [📖 Documentation](https://example.com) -->
|
|
22
|
-
|
|
23
|
-
## Features
|
|
24
|
-
|
|
25
|
-
<!-- Highlight some of the features your module provide here -->
|
|
26
|
-
- ⛰ Foo
|
|
27
|
-
- 🚠 Bar
|
|
28
|
-
- 🌲 Baz
|
|
29
|
-
|
|
30
|
-
## Quick Setup
|
|
31
|
-
|
|
32
|
-
Install the module to your Nuxt application with one command:
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
npx nuxt module add my-module
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
That's it! You can now use My Module in your Nuxt app ✨
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
## Contribution
|
|
42
|
-
|
|
43
|
-
<details>
|
|
44
|
-
<summary>Local development</summary>
|
|
45
|
-
|
|
46
|
-
```bash
|
|
47
|
-
# Install dependencies
|
|
48
|
-
npm install
|
|
49
|
-
|
|
50
|
-
# Generate type stubs
|
|
51
|
-
npm run dev:prepare
|
|
52
|
-
|
|
53
|
-
# Develop with the playground
|
|
54
|
-
npm run dev
|
|
55
|
-
|
|
56
|
-
# Build the playground
|
|
57
|
-
npm run dev:build
|
|
58
|
-
|
|
59
|
-
# Run ESLint
|
|
60
|
-
npm run lint
|
|
61
|
-
|
|
62
|
-
# Run Vitest
|
|
63
|
-
npm run test
|
|
64
|
-
npm run test:watch
|
|
65
|
-
|
|
66
|
-
# Release new version
|
|
67
|
-
npm run release
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
</details>
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
<!-- Badges -->
|
|
74
|
-
[npm-version-src]: https://img.shields.io/npm/v/my-module/latest.svg?style=flat&colorA=020420&colorB=00DC82
|
|
75
|
-
[npm-version-href]: https://npmjs.com/package/my-module
|
|
76
|
-
|
|
77
|
-
[npm-downloads-src]: https://img.shields.io/npm/dm/my-module.svg?style=flat&colorA=020420&colorB=00DC82
|
|
78
|
-
[npm-downloads-href]: https://npm.chart.dev/my-module
|
|
79
|
-
|
|
80
|
-
[license-src]: https://img.shields.io/npm/l/my-module.svg?style=flat&colorA=020420&colorB=00DC82
|
|
81
|
-
[license-href]: https://npmjs.com/package/my-module
|
|
82
|
-
|
|
83
|
-
[nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt
|
|
84
|
-
[nuxt-href]: https://nuxt.com
|
package/dist/runtime/plugin.js
DELETED
|
File without changes
|