@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
|
@@ -0,0 +1,139 @@
|
|
|
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
|
+
isModePreference,
|
|
130
|
+
isSelectableGroup,
|
|
131
|
+
findVariantOwner,
|
|
132
|
+
getDefaultSelection,
|
|
133
|
+
normalizeThemeSelection,
|
|
134
|
+
getActiveSeasonalTheme,
|
|
135
|
+
resolveMode,
|
|
136
|
+
resolveThemeSelection,
|
|
137
|
+
resolveThemePreference
|
|
138
|
+
};
|
|
139
|
+
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@venix-sistemas/jade",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.2.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,30 @@
|
|
|
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"
|
|
71
73
|
},
|
|
72
74
|
"devDependencies": {
|
|
73
|
-
"@nuxt/devtools": "4.0.0-beta.
|
|
75
|
+
"@nuxt/devtools": "4.0.0-beta.5",
|
|
74
76
|
"@nuxt/eslint-config": "^1.17.0",
|
|
75
77
|
"@nuxt/module-builder": "^1.0.3",
|
|
76
|
-
"@nuxt/schema": "^4.
|
|
78
|
+
"@nuxt/schema": "^4.6.1",
|
|
77
79
|
"@nuxt/test-utils": "^4.3.3",
|
|
78
80
|
"@nuxtjs/i18n": "10.6.0",
|
|
79
81
|
"@types/node": "latest",
|
|
80
82
|
"changelogen": "^0.6.2",
|
|
81
83
|
"eslint": "^10.12.0",
|
|
82
|
-
"nuxt": "^4.
|
|
84
|
+
"nuxt": "^4.6.1",
|
|
83
85
|
"typescript": "7.0.2",
|
|
84
|
-
"vitest": "5.0.
|
|
85
|
-
"vue-tsc": "^3.3.
|
|
86
|
+
"vitest": "5.0.4",
|
|
87
|
+
"vue-tsc": "^3.3.13"
|
|
86
88
|
},
|
|
87
89
|
"scripts": {
|
|
88
90
|
"dev": "pnpm run dev:prepare && nuxt dev playground",
|
|
89
91
|
"dev:build": "nuxt build playground",
|
|
90
92
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt prepare playground",
|
|
91
|
-
"release": "pnpm
|
|
92
|
-
"release
|
|
93
|
+
"release:auth": "pnpm whoami || pnpm login",
|
|
94
|
+
"release": "pnpm run release:auth && pnpm run lint && pnpm run test && pnpm run prepack && changelogen --release && pnpm publish && git push --follow-tags",
|
|
95
|
+
"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
96
|
"lint": "eslint .",
|
|
94
97
|
"test": "vitest run",
|
|
95
98
|
"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.d.ts
DELETED
package/dist/runtime/plugin.js
DELETED