@venix-sistemas/jade 1.0.1 → 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 +350 -254
- package/dist/module.json +1 -1
- package/dist/module.mjs +32 -35
- 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 +12 -18
- 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 +174 -112
- 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 -62
- package/dist/shared/constants.d.ts +18 -3
- package/dist/shared/constants.js +6 -1
- package/dist/shared/css/colors.js +2 -2
- package/dist/shared/css/cursor.js +9 -2
- package/dist/shared/css/index.d.ts +1 -7
- package/dist/shared/css/index.js +9 -9
- 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 -7
- 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-refs.js +1 -1
- package/dist/shared/utils/icon.d.ts +6 -2
- package/dist/shared/utils/icon.js +8 -3
- package/dist/shared/utils/index.d.ts +5 -3
- package/dist/shared/utils/index.js +12 -5
- 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 +7 -16
- package/dist/shared/utils/merge-themes.d.ts +41 -0
- package/dist/shared/utils/merge-themes.js +106 -0
- package/dist/shared/utils/normalize.d.ts +0 -10
- 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 -13
- package/dist/shared/utils/theme-resolve.d.ts +19 -19
- package/dist/shared/utils/theme-resolve.js +25 -42
- 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,14 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ThemeEntry } from './colors.js';
|
|
2
2
|
declare module '@nuxt/schema' {
|
|
3
3
|
interface PublicRuntimeConfig {
|
|
4
4
|
venixTheme?: {
|
|
5
5
|
defaultTheme: string;
|
|
6
|
-
colorThemes: Record<string, Partial<
|
|
6
|
+
colorThemes: Record<string, Partial<ThemeEntry>>;
|
|
7
7
|
applyColors: boolean;
|
|
8
8
|
localeCookie: string;
|
|
9
9
|
defaultLocale: string;
|
|
10
10
|
locale: string;
|
|
11
11
|
iconFormat: 'emote' | 'css' | 'svg';
|
|
12
|
+
requireConsent: boolean;
|
|
13
|
+
seasonal: boolean;
|
|
12
14
|
icon: {
|
|
13
15
|
aliases: Record<string, string>;
|
|
14
16
|
};
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ThemeIconFormats } from '../types/colors.js';
|
|
2
2
|
/**
|
|
3
3
|
* Extracts the Iconify `collection:icon` references used in color themes
|
|
4
|
-
* (`icon.css` / `icon.svg`) and in the configured icon aliases, grouped by
|
|
4
|
+
* and modes (`icon.css` / `icon.svg`) and in the configured icon aliases, grouped by
|
|
5
5
|
* collection. Lets each collection be bundled with only the icons actually
|
|
6
6
|
* used (tree-shaking) instead of the whole collection — essential for large
|
|
7
7
|
* collections like `mdi` (thousands of icons) used for only a handful of
|
|
8
8
|
* icons in the default theme.
|
|
9
9
|
*/
|
|
10
|
-
export declare function extractIconRefs(themes: Record<string,
|
|
10
|
+
export declare function extractIconRefs(themes: Record<string, {
|
|
11
|
+
icon?: string | ThemeIconFormats;
|
|
12
|
+
}> | Array<{
|
|
13
|
+
icon?: string | ThemeIconFormats;
|
|
14
|
+
}>, aliases: Record<string, string>): Map<string, Set<string>>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { ThemeIconFormats } from '../types/colors.js';
|
|
2
|
+
/** Iconify icon name: `collection:name` (e.g. `line-md:home`). */
|
|
3
|
+
export declare const ICONIFY_NAME: RegExp;
|
|
2
4
|
export type IconKind = 'emoji' | 'icon' | 'svg';
|
|
3
5
|
export interface ResolvedIcon {
|
|
4
6
|
kind: IconKind;
|
|
@@ -21,7 +23,9 @@ export interface ResolvedThemeIcon {
|
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
* Resolves a color theme's icon (a legacy string, always emote, or a
|
|
24
|
-
* `ThemeIconFormats` with variants) to the preferred format
|
|
25
|
-
*
|
|
26
|
+
* `ThemeIconFormats` with variants) to the preferred format. When the theme
|
|
27
|
+
* doesn't define it, tries the other Iconify variant before `emote`
|
|
28
|
+
* (`svg` → `css` → `emote`, or `css` → `svg` → `emote`), so a theme with only
|
|
29
|
+
* one Iconify variant still shows an icon instead of dropping to the emoji.
|
|
26
30
|
*/
|
|
27
31
|
export declare function resolveThemeIcon(icon: string | ThemeIconFormats | undefined, preferred: ThemeIconFormat): ResolvedThemeIcon | null;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
export const ICONIFY_NAME = /^([\w-]+):([\w-]+)$/;
|
|
1
2
|
export function resolveIcon(input, aliases = {}) {
|
|
2
3
|
const value = (aliases[input] ?? input).trim();
|
|
3
4
|
if (/^<svg[\s>]/i.test(value)) {
|
|
4
5
|
return { kind: "svg", value };
|
|
5
6
|
}
|
|
6
|
-
if (
|
|
7
|
+
if (ICONIFY_NAME.test(value)) {
|
|
7
8
|
return { kind: "icon", value };
|
|
8
9
|
}
|
|
9
10
|
return { kind: "emoji", value };
|
|
@@ -13,8 +14,12 @@ export function resolveThemeIcon(icon, preferred) {
|
|
|
13
14
|
if (typeof icon === "string") {
|
|
14
15
|
return { format: "emote", value: icon };
|
|
15
16
|
}
|
|
16
|
-
if (preferred !== "emote"
|
|
17
|
-
|
|
17
|
+
if (preferred !== "emote") {
|
|
18
|
+
const order = preferred === "svg" ? ["svg", "css"] : ["css", "svg"];
|
|
19
|
+
for (const format of order) {
|
|
20
|
+
const value = icon[format];
|
|
21
|
+
if (value) return { format, value };
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
24
|
return { format: "emote", value: icon.emote };
|
|
20
25
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
export { normalizeLocale, extractFirstLocale,
|
|
1
|
+
export { normalizeLocale, extractFirstLocale, } from './normalize.js';
|
|
2
2
|
export { resolveFeatureOption } from './options.js';
|
|
3
3
|
export { resolveIcon, resolveThemeIcon } from './icon.js';
|
|
4
4
|
export type { IconKind, ResolvedIcon, ThemeIconFormat, ResolvedThemeIcon } from './icon.js';
|
|
5
5
|
export { extractIconRefs } from './icon-refs.js';
|
|
6
6
|
export { hasCookieConsent } from './consent.js';
|
|
7
|
-
export { isColorTheme, getActiveSeasonalTheme, resolveThemePreference } from './theme-resolve.js';
|
|
8
|
-
export {
|
|
7
|
+
export { isColorTheme, getActiveSeasonalTheme, getEasterSunday, getDefaultSelection, normalizeThemeSelection, resolveThemeSelection, resolveThemePreference, } from './theme-resolve.js';
|
|
8
|
+
export type { ColorModel, ThemeSelection } from './theme-resolve.js';
|
|
9
|
+
export { mergeColorThemes, normalizeColorThemes, findDeprecatedThemeEntries } from './merge-themes.js';
|
|
10
|
+
export { buildResolvedTheme, getBaseThemeEntries } from './theme-config.js';
|
|
9
11
|
export type { VenixRuntimeThemeConfig } from './theme-config.js';
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
export {
|
|
2
2
|
normalizeLocale,
|
|
3
|
-
extractFirstLocale
|
|
4
|
-
normalizeColor,
|
|
5
|
-
normalizeThemeName
|
|
3
|
+
extractFirstLocale
|
|
6
4
|
} from "./normalize.js";
|
|
7
5
|
export { resolveFeatureOption } from "./options.js";
|
|
8
6
|
export { resolveIcon, resolveThemeIcon } from "./icon.js";
|
|
9
7
|
export { extractIconRefs } from "./icon-refs.js";
|
|
10
8
|
export { hasCookieConsent } from "./consent.js";
|
|
11
|
-
export {
|
|
12
|
-
|
|
9
|
+
export {
|
|
10
|
+
isColorTheme,
|
|
11
|
+
getActiveSeasonalTheme,
|
|
12
|
+
getEasterSunday,
|
|
13
|
+
getDefaultSelection,
|
|
14
|
+
normalizeThemeSelection,
|
|
15
|
+
resolveThemeSelection,
|
|
16
|
+
resolveThemePreference
|
|
17
|
+
} from "./theme-resolve.js";
|
|
18
|
+
export { mergeColorThemes, normalizeColorThemes, findDeprecatedThemeEntries } from "./merge-themes.js";
|
|
19
|
+
export { buildResolvedTheme, getBaseThemeEntries } from "./theme-config.js";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON is valid JS, but inside an inline `<script>` a `</script>` anywhere in
|
|
3
|
+
* the data (e.g. in a theme translation) would end the element early and
|
|
4
|
+
* break the page. `<` is the same character to the JS parser.
|
|
5
|
+
*/
|
|
6
|
+
export declare function toInlineScriptJson(value: unknown): string;
|
|
@@ -1,24 +1,15 @@
|
|
|
1
|
-
import defaultTheme from "../../shared/theme.json" with { type: "json" };
|
|
2
|
-
import { DEFAULT_LOCALE } from "../constants.js";
|
|
3
1
|
import { normalizeLocale } from "./normalize.js";
|
|
2
|
+
import { buildResolvedTheme } from "./theme-config.js";
|
|
4
3
|
export function loadTheme(_path) {
|
|
5
|
-
return
|
|
4
|
+
return buildResolvedTheme();
|
|
6
5
|
}
|
|
7
6
|
export function extractLocales(theme) {
|
|
8
7
|
const locales = /* @__PURE__ */ new Set();
|
|
9
|
-
Object.values(theme.colors?.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
});
|
|
8
|
+
const labelled = [...Object.values(theme.colors?.groups || {}), ...Object.values(theme.colors?.modes || {})];
|
|
9
|
+
for (const entry of labelled) {
|
|
10
|
+
for (const locale of Object.keys(entry.translations ?? {})) {
|
|
11
|
+
locales.add(normalizeLocale(locale));
|
|
14
12
|
}
|
|
15
|
-
}
|
|
13
|
+
}
|
|
16
14
|
return Array.from(locales);
|
|
17
15
|
}
|
|
18
|
-
export function getDefaultLocale(theme) {
|
|
19
|
-
const locales = extractLocales(theme);
|
|
20
|
-
if (locales.includes("en-US")) return "en-US";
|
|
21
|
-
const firstLocale = locales[0];
|
|
22
|
-
if (firstLocale) return firstLocale;
|
|
23
|
-
return DEFAULT_LOCALE;
|
|
24
|
-
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { ThemeColors, ThemeDefinition, ThemeEntry, ResolvedThemeGroup } from '../types/index.js';
|
|
2
|
+
/** Grouped format: at least one `light`/`dark` variant object. */
|
|
3
|
+
export declare function isThemeDefinition(entry: Partial<ThemeEntry> | undefined): entry is ThemeDefinition;
|
|
4
|
+
/**
|
|
5
|
+
* Deprecated flat format: a boolean `dark` flag and/or colors at the top
|
|
6
|
+
* level. An entry with only metadata (`translations`, `icon`…) is neither —
|
|
7
|
+
* it's valid in both formats.
|
|
8
|
+
*/
|
|
9
|
+
export declare function isLegacyThemeEntry(entry: Partial<ThemeEntry> | undefined): entry is ThemeColors;
|
|
10
|
+
/**
|
|
11
|
+
* Layers the `color.themes` overrides from `nuxt.config` on top of the base
|
|
12
|
+
* entries (`theme.json`), still in config format:
|
|
13
|
+
*
|
|
14
|
+
* - an existing theme only gets the keys the override sets — metadata at the
|
|
15
|
+
* theme level, colors variant by variant;
|
|
16
|
+
* - a deprecated flat override named after a variant id (`dark: { primary }`)
|
|
17
|
+
* is merged into that variant (`venix.dark`);
|
|
18
|
+
* - anything else is added as a new theme (a flat one is dark unless it sets
|
|
19
|
+
* `dark: false`, as before).
|
|
20
|
+
*
|
|
21
|
+
* Single implementation — used both at build time (`customizeTheme`, which
|
|
22
|
+
* feeds the generated CSS and Vuetify) and at runtime (`buildResolvedTheme`),
|
|
23
|
+
* so the two can't diverge.
|
|
24
|
+
*/
|
|
25
|
+
export declare function mergeColorThemes(baseThemes: Record<string, ThemeEntry>, overrides?: Record<string, Partial<ThemeEntry>>): Record<string, ThemeEntry>;
|
|
26
|
+
/**
|
|
27
|
+
* Turns config entries (both formats) into what the runtime works with:
|
|
28
|
+
* `themes`, every concrete variant by id (feeds `data-theme`, the CSS and
|
|
29
|
+
* Vuetify), and `groups`, the selectable themes pointing at their variants.
|
|
30
|
+
* A deprecated flat entry becomes a single-variant theme whose id is its own
|
|
31
|
+
* name, so its `data-theme` value doesn't change.
|
|
32
|
+
*/
|
|
33
|
+
export declare function normalizeColorThemes(entries: Record<string, ThemeEntry>): {
|
|
34
|
+
themes: Record<string, ThemeColors>;
|
|
35
|
+
groups: Record<string, ResolvedThemeGroup>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Overrides still written in the deprecated flat format, with the message to
|
|
39
|
+
* show for each — logged once at build time by `module.ts`.
|
|
40
|
+
*/
|
|
41
|
+
export declare function findDeprecatedThemeEntries(baseThemes: Record<string, ThemeEntry>, overrides?: Record<string, Partial<ThemeEntry>>): string[];
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { COLOR_PROPERTIES, THEME_MODES } from "../constants.js";
|
|
2
|
+
const META_PROPERTIES = ["seasonal", "dateRange", "translations", "icon"];
|
|
3
|
+
export function isThemeDefinition(entry) {
|
|
4
|
+
if (!entry) return false;
|
|
5
|
+
return THEME_MODES.some((mode) => typeof entry[mode] === "object");
|
|
6
|
+
}
|
|
7
|
+
export function isLegacyThemeEntry(entry) {
|
|
8
|
+
if (!entry || isThemeDefinition(entry)) return false;
|
|
9
|
+
return typeof entry.dark === "boolean" || COLOR_PROPERTIES.some((key) => entry[key] !== void 0);
|
|
10
|
+
}
|
|
11
|
+
function pickMeta(entry) {
|
|
12
|
+
const meta = {};
|
|
13
|
+
for (const key of META_PROPERTIES) {
|
|
14
|
+
if (entry[key] !== void 0) meta[key] = entry[key];
|
|
15
|
+
}
|
|
16
|
+
return meta;
|
|
17
|
+
}
|
|
18
|
+
function pickPalette(entry) {
|
|
19
|
+
const palette = {};
|
|
20
|
+
for (const key of COLOR_PROPERTIES) {
|
|
21
|
+
const value = entry[key];
|
|
22
|
+
if (value !== void 0) palette[key] = value;
|
|
23
|
+
}
|
|
24
|
+
return palette;
|
|
25
|
+
}
|
|
26
|
+
const variantId = (themeName, mode, variant) => variant.id || `${themeName}-${mode}`;
|
|
27
|
+
function findVariantOwner(entries, id) {
|
|
28
|
+
for (const [themeName, entry] of Object.entries(entries)) {
|
|
29
|
+
if (!isThemeDefinition(entry)) continue;
|
|
30
|
+
for (const mode of THEME_MODES) {
|
|
31
|
+
const variant = entry[mode];
|
|
32
|
+
if (variant && variantId(themeName, mode, variant) === id) return { theme: themeName, mode };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
function legacyOverrideMode(group, themeName, override) {
|
|
38
|
+
const byId = THEME_MODES.find((mode) => group[mode] && variantId(themeName, mode, group[mode]) === themeName);
|
|
39
|
+
return byId ?? (override.dark === false ? "light" : "dark");
|
|
40
|
+
}
|
|
41
|
+
export function mergeColorThemes(baseThemes, overrides) {
|
|
42
|
+
const merged = { ...baseThemes };
|
|
43
|
+
for (const [themeName, override] of Object.entries(overrides ?? {})) {
|
|
44
|
+
const existing = merged[themeName];
|
|
45
|
+
if (existing && isThemeDefinition(existing)) {
|
|
46
|
+
const next = { ...existing, ...pickMeta(override) };
|
|
47
|
+
if (isThemeDefinition(override)) {
|
|
48
|
+
for (const mode of THEME_MODES) {
|
|
49
|
+
if (override[mode]) next[mode] = { ...existing[mode], ...override[mode] };
|
|
50
|
+
}
|
|
51
|
+
} else if (isLegacyThemeEntry(override)) {
|
|
52
|
+
const mode = legacyOverrideMode(existing, themeName, override);
|
|
53
|
+
next[mode] = { ...existing[mode], ...pickPalette(override) };
|
|
54
|
+
}
|
|
55
|
+
merged[themeName] = next;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (existing) {
|
|
59
|
+
merged[themeName] = { ...existing, ...override };
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
const owner = isLegacyThemeEntry(override) ? findVariantOwner(merged, themeName) : null;
|
|
63
|
+
if (owner) {
|
|
64
|
+
const group = merged[owner.theme];
|
|
65
|
+
merged[owner.theme] = {
|
|
66
|
+
...group,
|
|
67
|
+
[owner.mode]: { ...group[owner.mode], ...pickPalette(override) }
|
|
68
|
+
};
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
merged[themeName] = isThemeDefinition(override) ? override : { dark: true, ...override };
|
|
72
|
+
}
|
|
73
|
+
return merged;
|
|
74
|
+
}
|
|
75
|
+
export function normalizeColorThemes(entries) {
|
|
76
|
+
const themes = {};
|
|
77
|
+
const groups = {};
|
|
78
|
+
for (const [themeName, entry] of Object.entries(entries)) {
|
|
79
|
+
const group = { ...pickMeta(entry), variants: {} };
|
|
80
|
+
if (isThemeDefinition(entry)) {
|
|
81
|
+
for (const mode of THEME_MODES) {
|
|
82
|
+
const variant = entry[mode];
|
|
83
|
+
if (!variant) continue;
|
|
84
|
+
const id = variantId(themeName, mode, variant);
|
|
85
|
+
themes[id] = { dark: mode === "dark", ...pickPalette(variant) };
|
|
86
|
+
group.variants[mode] = id;
|
|
87
|
+
}
|
|
88
|
+
} else if (isLegacyThemeEntry(entry)) {
|
|
89
|
+
const mode = entry.dark === false ? "light" : "dark";
|
|
90
|
+
themes[themeName] = { dark: mode === "dark", ...pickPalette(entry) };
|
|
91
|
+
group.variants[mode] = themeName;
|
|
92
|
+
}
|
|
93
|
+
groups[themeName] = group;
|
|
94
|
+
}
|
|
95
|
+
return { themes, groups };
|
|
96
|
+
}
|
|
97
|
+
export function findDeprecatedThemeEntries(baseThemes, overrides) {
|
|
98
|
+
const messages = [];
|
|
99
|
+
for (const [themeName, override] of Object.entries(overrides ?? {})) {
|
|
100
|
+
if (!isLegacyThemeEntry(override)) continue;
|
|
101
|
+
const base = baseThemes[themeName];
|
|
102
|
+
const owner = base && isThemeDefinition(base) ? { theme: themeName, mode: legacyOverrideMode(base, themeName, override) } : base ? null : findVariantOwner(baseThemes, themeName);
|
|
103
|
+
messages.push(owner ? `\`color.themes.${themeName}\` overrides a theme variant in the deprecated flat format. Use \`${owner.theme}: { ${owner.mode}: { ... } }\` instead.` : `\`color.themes.${themeName}\` uses the deprecated flat format (\`dark: true/false\` plus colors). Use \`${themeName}: { light: { ... }, dark: { ... } }\` instead.`);
|
|
104
|
+
}
|
|
105
|
+
return messages;
|
|
106
|
+
}
|
|
@@ -8,13 +8,3 @@ export declare function normalizeLocale(locale: string): string;
|
|
|
8
8
|
* E.g.: "pt-BR,pt;q=0.9,en;q=0.8" -> "pt-BR"
|
|
9
9
|
*/
|
|
10
10
|
export declare function extractFirstLocale(acceptLanguage: string): string | null;
|
|
11
|
-
/**
|
|
12
|
-
* Normalizes a hex color.
|
|
13
|
-
* E.g.: "fff" -> "#FFF", "ffffff" -> "#FFFFFF", "#fff" -> "#FFF"
|
|
14
|
-
*/
|
|
15
|
-
export declare function normalizeColor(color: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* Normalizes a theme name.
|
|
18
|
-
* E.g.: "dark" -> "Dark", "DARK" -> "Dark"
|
|
19
|
-
*/
|
|
20
|
-
export declare function normalizeThemeName(name: string): string;
|
|
@@ -24,15 +24,3 @@ export function extractFirstLocale(acceptLanguage) {
|
|
|
24
24
|
const firstLocale = localeParts[0]?.trim();
|
|
25
25
|
return firstLocale || null;
|
|
26
26
|
}
|
|
27
|
-
export function normalizeColor(color) {
|
|
28
|
-
if (!color) return color;
|
|
29
|
-
color = color.trim();
|
|
30
|
-
if (!color.startsWith("#")) {
|
|
31
|
-
color = `#${color}`;
|
|
32
|
-
}
|
|
33
|
-
return color;
|
|
34
|
-
}
|
|
35
|
-
export function normalizeThemeName(name) {
|
|
36
|
-
if (!name) return name;
|
|
37
|
-
return name.charAt(0).toUpperCase() + name.slice(1).toLowerCase();
|
|
38
|
-
}
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import type { ThemeConfig,
|
|
1
|
+
import type { ThemeConfig, ThemeEntry } from '../types/index.js';
|
|
2
2
|
export interface VenixRuntimeThemeConfig {
|
|
3
3
|
defaultTheme?: string;
|
|
4
|
-
colorThemes?: Record<string, Partial<
|
|
4
|
+
colorThemes?: Record<string, Partial<ThemeEntry>>;
|
|
5
|
+
/** `false` drops every seasonal theme (built-in and custom). Default: `true`. */
|
|
6
|
+
seasonal?: boolean;
|
|
5
7
|
}
|
|
8
|
+
/** The theme entries bundled with the module, in config format. */
|
|
9
|
+
export declare function getBaseThemeEntries(): Record<string, ThemeEntry>;
|
|
6
10
|
/**
|
|
7
11
|
* Rebuilds the full `ThemeConfig` at runtime, layering `theme.json`
|
|
8
12
|
* (bundled with the module, with the "base" themes) with the customizations
|
|
9
13
|
* from `runtimeConfig.public.venixTheme` (resolved at build time from the
|
|
10
14
|
* module options in `nuxt.config`, see `module.ts`). Single implementation —
|
|
11
|
-
* used by the composable (`useVenixTheme`)
|
|
12
|
-
*
|
|
15
|
+
* used by the composable (`useVenixTheme`), the SSR/Vuetify plugins and, at
|
|
16
|
+
* build time, `customizeTheme`.
|
|
17
|
+
*
|
|
18
|
+
* Memoized per config object: every `useVenixTheme()` call and plugin asks
|
|
19
|
+
* for it with the same `runtimeConfig.public.venixTheme`, and rebuilding it
|
|
20
|
+
* (merge + normalization of every theme) each time was wasted work. The
|
|
21
|
+
* result is shared, so callers must treat it as read-only.
|
|
13
22
|
*/
|
|
14
23
|
export declare function buildResolvedTheme(runtimeThemeConfig?: VenixRuntimeThemeConfig): ThemeConfig;
|
|
@@ -1,22 +1,37 @@
|
|
|
1
1
|
import themeData from "../theme.json" with { type: "json" };
|
|
2
2
|
import { DEFAULT_THEME } from "../constants.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();
|
|
3
8
|
export function buildResolvedTheme(runtimeThemeConfig) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
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
|
+
}
|
|
11
26
|
return {
|
|
12
27
|
...themeData,
|
|
13
28
|
colors: {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
29
|
+
enabled: rawColors.enabled ?? true,
|
|
30
|
+
defaults: rawColors.defaults ?? true,
|
|
31
|
+
defaultColor: runtimeThemeConfig?.defaultTheme || rawColors.defaultColor || DEFAULT_THEME,
|
|
32
|
+
modes: rawColors.modes ?? {},
|
|
33
|
+
themes,
|
|
34
|
+
groups
|
|
20
35
|
}
|
|
21
36
|
};
|
|
22
37
|
}
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
import type { ThemeColors } 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, 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
|
+
* The theme's actual color entries (hex values only) — skips metadata like
|
|
12
|
+
* `dark`/`translations`/`icon`. Shared by the CSS generator and the Vuetify
|
|
13
|
+
* theme registration, so both always agree on what counts as a color.
|
|
7
14
|
*/
|
|
8
|
-
export declare function
|
|
15
|
+
export declare function getThemeHexColors(themeConfig: ThemeColors): Array<[string, string]>;
|
|
9
16
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
17
|
+
* Best guess at the theme to render where `matchMedia` doesn't exist (SSR):
|
|
18
|
+
* the resolved cookie (the variant last applied on the client) only hints
|
|
19
|
+
* whether the OS prefers dark, for mode `'system'`. It's never returned as
|
|
20
|
+
* is: with theme `'system'` that cookie can be from another season, or from
|
|
21
|
+
* before the OS switched modes, and trusting it kept that stale theme. The
|
|
22
|
+
* pre-hydration script then corrects the mode guess before the first paint.
|
|
13
23
|
*/
|
|
14
|
-
export declare function
|
|
15
|
-
/**
|
|
16
|
-
* Resolves a theme preference (`'system'`, a theme name, or empty) to the
|
|
17
|
-
* concrete color theme that should be applied. Single implementation of this
|
|
18
|
-
* rule — used by `useVenixTheme`/`useThemeSeasonal` and the SSR plugin
|
|
19
|
-
* (`theme-init.server.ts`). The pre-hydration script
|
|
20
|
-
* (`runtime/scripts/theme-init.ts`) is the one documented exception: it has
|
|
21
|
-
* to run as a self-contained IIFE (no imports), so it deliberately duplicates
|
|
22
|
-
* this logic — keep the two in sync when changing either.
|
|
23
|
-
*/
|
|
24
|
-
export declare function resolveThemePreference(preference: string | undefined, themes: Record<string, ThemeColors>, defaultTheme: string, prefersDark: boolean): string;
|
|
24
|
+
export declare function resolveServerTheme(themePreference: string | null | undefined, modePreference: string | null | undefined, resolvedHint: string | null | undefined, colors: ColorModel, now?: Date): string;
|
|
@@ -1,45 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
export function getActiveSeasonalTheme(themes, prefersDark, now = /* @__PURE__ */ new Date()) {
|
|
23
|
-
for (const [themeName, themeConfig] of Object.entries(themes)) {
|
|
24
|
-
if (themeName === "system") continue;
|
|
25
|
-
if (!isColorTheme(themeConfig)) continue;
|
|
26
|
-
if (!isDateInSeasonalRange(themeConfig, now)) continue;
|
|
27
|
-
if (prefersDark !== void 0 && themeConfig.dark !== prefersDark) continue;
|
|
28
|
-
return themeName;
|
|
1
|
+
import { NON_COLOR_PROPERTIES } from "../constants.js";
|
|
2
|
+
import { createThemeResolver } from "./theme-resolver.js";
|
|
3
|
+
export const {
|
|
4
|
+
isColorTheme,
|
|
5
|
+
getEasterSunday,
|
|
6
|
+
isModePreference,
|
|
7
|
+
isSelectableGroup,
|
|
8
|
+
findVariantOwner,
|
|
9
|
+
getDefaultSelection,
|
|
10
|
+
normalizeThemeSelection,
|
|
11
|
+
getActiveSeasonalTheme,
|
|
12
|
+
resolveMode,
|
|
13
|
+
resolveThemeSelection,
|
|
14
|
+
resolveThemePreference
|
|
15
|
+
} = createThemeResolver();
|
|
16
|
+
export function getThemeHexColors(themeConfig) {
|
|
17
|
+
const result = [];
|
|
18
|
+
for (const [key, value] of Object.entries(themeConfig)) {
|
|
19
|
+
if (NON_COLOR_PROPERTIES.includes(key)) continue;
|
|
20
|
+
if (typeof value === "string" && value.startsWith("#")) result.push([key, value]);
|
|
29
21
|
}
|
|
30
|
-
return
|
|
22
|
+
return result;
|
|
31
23
|
}
|
|
32
|
-
export function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
} else if (preference && isColorTheme(themes[preference])) {
|
|
37
|
-
resolved = preference;
|
|
38
|
-
} else {
|
|
39
|
-
resolved = defaultTheme;
|
|
40
|
-
}
|
|
41
|
-
if (!isColorTheme(themes[resolved])) {
|
|
42
|
-
resolved = isColorTheme(themes[defaultTheme]) ? defaultTheme : "dark";
|
|
43
|
-
}
|
|
44
|
-
return resolved;
|
|
24
|
+
export function resolveServerTheme(themePreference, modePreference, resolvedHint, colors, now = /* @__PURE__ */ new Date()) {
|
|
25
|
+
const hinted = resolvedHint ? colors.themes[resolvedHint] : void 0;
|
|
26
|
+
const prefersDark = hinted && isColorTheme(hinted) ? hinted.dark !== false : true;
|
|
27
|
+
return resolveThemePreference(themePreference, modePreference, colors, prefersDark, now);
|
|
45
28
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
isModePreference: (value: unknown) => value is ThemeModePreference;
|
|
32
|
+
isSelectableGroup: (colors: ColorModel, name: string) => boolean;
|
|
33
|
+
findVariantOwner: (colors: ColorModel, id: string) => {
|
|
34
|
+
theme: string;
|
|
35
|
+
mode: ThemeMode;
|
|
36
|
+
} | null;
|
|
37
|
+
getDefaultSelection: (colors: ColorModel) => ThemeSelection & {
|
|
38
|
+
fallbackTheme: string;
|
|
39
|
+
};
|
|
40
|
+
normalizeThemeSelection: (themePreference: string | null | undefined, modePreference: string | null | undefined, colors: ColorModel) => ThemeSelection;
|
|
41
|
+
getActiveSeasonalTheme: (groups: Record<string, ResolvedThemeGroup>, mode?: ThemeMode, now?: Date) => string | null;
|
|
42
|
+
resolveMode: (mode: ThemeModePreference, prefersDark: boolean) => ThemeMode;
|
|
43
|
+
resolveThemeSelection: (selection: ThemeSelection, colors: ColorModel, prefersDark: boolean, now?: Date) => string;
|
|
44
|
+
resolveThemePreference: (themePreference: string | null | undefined, modePreference: string | null | undefined, colors: ColorModel, prefersDark: boolean, now?: Date) => string;
|
|
45
|
+
};
|
|
46
|
+
export type ThemeResolver = ReturnType<typeof createThemeResolver>;
|