@venix-sistemas/jade 1.0.0 โ 1.1.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-default.md +84 -0
- package/README.md +237 -256
- package/dist/module.json +1 -1
- package/dist/module.mjs +9 -26
- package/dist/runtime/composables/useThemeLocale.js +10 -16
- package/dist/runtime/composables/useVenixTheme.js +19 -17
- package/dist/runtime/plugins/vuetify-theme.js +21 -4
- package/dist/runtime/scripts/theme-init.js +34 -8
- package/dist/shared/css/colors.js +2 -2
- package/dist/shared/css/index.js +4 -4
- package/dist/shared/theme.json +3 -3
- package/dist/shared/types/colors.d.ts +5 -0
- package/dist/shared/utils/icon-refs.js +1 -1
- package/dist/shared/utils/icon.d.ts +2 -0
- package/dist/shared/utils/icon.js +2 -1
- package/dist/shared/utils/index.d.ts +2 -1
- package/dist/shared/utils/index.js +2 -1
- package/dist/shared/utils/load.js +4 -6
- package/dist/shared/utils/merge-themes.d.ts +11 -0
- package/dist/shared/utils/merge-themes.js +10 -0
- package/dist/shared/utils/normalize.d.ts +3 -2
- package/dist/shared/utils/theme-config.js +6 -4
- package/dist/shared/utils/theme-resolve.d.ts +8 -0
- package/dist/shared/utils/theme-resolve.js +39 -7
- package/package.json +12 -14
package/README.md
CHANGED
|
@@ -1,56 +1,49 @@
|
|
|
1
|
-
<p align="center">
|
|
2
|
-
<img src="./docs/images/jade-transparent.png" alt="Jade logo" width="200">
|
|
3
|
-
</p>
|
|
4
|
-
|
|
5
|
-
<h1 align="center">Jade</h1>
|
|
6
|
-
|
|
7
|
-
<p align="center">
|
|
8
|
-
<code>@venix-sistemas/jade</code>
|
|
9
|
-
</p>
|
|
10
|
-
|
|
11
|
-
<p align="center">
|
|
12
|
-
<a href="https://www.npmjs.com/package/@venix-sistemas/jade"><img src="https://badge.fury.io/js/@venix-sistemas%2Fjade.svg" alt="npm version"></a>
|
|
13
|
-
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
|
|
14
|
-
</p>
|
|
15
|
-
|
|
16
|
-
A complete centralized theming system for Nuxt applications: colors, typography, cursor, scrollbar, internationalization and seasonal themes, with UnoCSS, Vuetify and Iconify integrations.
|
|
17
|
-
|
|
18
|
-
## Features
|
|
19
|
-
|
|
20
|
-
* ๐ **Typography and font faces customization**
|
|
21
|
-
* ๐ฑ๏ธ **Cursor customization**
|
|
22
|
-
* ๐ **Scrollbar customization**
|
|
23
|
-
* ๐จ **Color customization**, with dark and light themes included
|
|
24
|
-
* ๐ฅ๏ธ **System theme preference detection**, including seasonal overrides
|
|
25
|
-
* ๐ **Seasonal themes**: Carnival, Halloween, Christmas and more
|
|
26
|
-
* ๐พ **Cookie-consent-aware persistence**: nothing is written until the user opts in
|
|
27
|
-
* ๐ **i18n**: internationalization and locale detection for theme names and your own strings
|
|
28
|
-
* โก **Nuxt-native integration**
|
|
29
|
-
* ๐ฏ **UnoCSS preset** for the theme's color variables
|
|
30
|
-
* ๐ญ **Vuetify 4** theme auto-configuration, kept in sync with live theme changes
|
|
31
|
-
* โจ **Unified icons**: emoji, Iconify (animated `line-md`, `mdi`, both bundled and tree-shaken offline) or inline SVG through one component
|
|
32
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="./docs/images/jade-transparent.png" alt="Jade logo" width="200">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
<h1 align="center">Jade</h1>
|
|
6
|
+
|
|
7
|
+
<p align="center">
|
|
8
|
+
<code>@venix-sistemas/jade</code>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
<p align="center">
|
|
12
|
+
<a href="https://www.npmjs.com/package/@venix-sistemas/jade"><img src="https://badge.fury.io/js/@venix-sistemas%2Fjade.svg" alt="npm version"></a>
|
|
13
|
+
<a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
A complete centralized theming system for Nuxt applications: colors, typography, cursor, scrollbar, internationalization and seasonal themes, with UnoCSS, Vuetify and Iconify integrations.
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
* ๐ **Typography and font faces customization**
|
|
21
|
+
* ๐ฑ๏ธ **Cursor customization**
|
|
22
|
+
* ๐ **Scrollbar customization**
|
|
23
|
+
* ๐จ **Color customization**, with dark and light themes included
|
|
24
|
+
* ๐ฅ๏ธ **System theme preference detection**, including seasonal overrides
|
|
25
|
+
* ๐ **Seasonal themes**: Carnival, Halloween, Christmas and more
|
|
26
|
+
* ๐พ **Cookie-consent-aware persistence**: nothing is written until the user opts in
|
|
27
|
+
* ๐ **i18n**: internationalization and locale detection for theme names and your own strings
|
|
28
|
+
* โก **Nuxt-native integration**
|
|
29
|
+
* ๐ฏ **UnoCSS preset** for the theme's color variables
|
|
30
|
+
* ๐ญ **Vuetify 4** theme auto-configuration, kept in sync with live theme changes
|
|
31
|
+
* โจ **Unified icons**: emoji, Iconify (animated `line-md`, `mdi`, both bundled and tree-shaken offline) or inline SVG through one component
|
|
32
|
+
|
|
33
33
|
## Installation
|
|
34
34
|
|
|
35
|
-
Install the package using your preferred package manager:
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
npm install @venix-sistemas/jade
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
Or with pnpm:
|
|
42
|
-
|
|
43
35
|
```bash
|
|
44
36
|
pnpm add @venix-sistemas/jade
|
|
37
|
+
# or
|
|
38
|
+
npm install @venix-sistemas/jade
|
|
45
39
|
```
|
|
46
40
|
|
|
47
41
|
## Quick Setup
|
|
48
42
|
|
|
49
43
|
### 1. Add the module
|
|
50
44
|
|
|
51
|
-
Add `@venix-sistemas/jade` to the `modules` section of your `nuxt.config.ts`:
|
|
52
|
-
|
|
53
45
|
```typescript
|
|
46
|
+
// nuxt.config.ts
|
|
54
47
|
export default defineNuxtConfig({
|
|
55
48
|
modules: ['@venix-sistemas/jade'],
|
|
56
49
|
|
|
@@ -66,23 +59,16 @@ export default defineNuxtConfig({
|
|
|
66
59
|
})
|
|
67
60
|
```
|
|
68
61
|
|
|
69
|
-
|
|
62
|
+
Every feature except Vuetify is on by default with built-in values, so you only configure what you want to change โ the example above just swaps the dark theme's primary color. See [Configuration](#configuration) for every option.
|
|
70
63
|
|
|
71
64
|
### 2. Use the theme
|
|
72
65
|
|
|
73
|
-
|
|
66
|
+
The auto-imported `useVenixTheme()` composable gives access to the theme. It isn't called `useTheme` to avoid colliding with UI libraries (like Vuetify) that auto-import a composable with that name.
|
|
74
67
|
|
|
75
68
|
```vue
|
|
76
69
|
<template>
|
|
77
|
-
<
|
|
78
|
-
|
|
79
|
-
Dark
|
|
80
|
-
</button>
|
|
81
|
-
|
|
82
|
-
<button @click="theme.toggle('light')">
|
|
83
|
-
Light
|
|
84
|
-
</button>
|
|
85
|
-
</div>
|
|
70
|
+
<button @click="theme.toggle('dark')">Dark</button>
|
|
71
|
+
<button @click="theme.toggle('light')">Light</button>
|
|
86
72
|
</template>
|
|
87
73
|
|
|
88
74
|
<script setup lang="ts">
|
|
@@ -90,18 +76,24 @@ const { theme } = useVenixTheme()
|
|
|
90
76
|
</script>
|
|
91
77
|
```
|
|
92
78
|
|
|
93
|
-
|
|
79
|
+
It returns four groups:
|
|
94
80
|
|
|
95
|
-
- `theme` โ
|
|
96
|
-
- `
|
|
97
|
-
- `
|
|
98
|
-
- `
|
|
81
|
+
- `theme` โ state and controls:
|
|
82
|
+
- `value`: the applied theme (e.g. `'dark'` when the preference is `'system'`)
|
|
83
|
+
- `preference`: the user's raw choice, including `'system'`
|
|
84
|
+
- `data`: the active theme's `{ value, name, icon }`
|
|
85
|
+
- `toggle(name?)`: switches to `name`, or between `light` and `dark` when called without one
|
|
86
|
+
- `isSeasonalActive`, `activeSeasonalTheme`: whether a [seasonal theme](#seasonal-themes) is currently in effect, and which one
|
|
87
|
+
- `shouldApplyColors`, `colors`: whether the module applies colors, and the raw color config
|
|
88
|
+
- `themes` โ every selectable theme, ready to render a picker (see [Theme icons](#theme-icons)).
|
|
89
|
+
- `locale` โ `current`, `set()` and `translate()` (see [Internationalization](#internationalization)).
|
|
90
|
+
- `persistence` โ cookie consent controls (see [Cookie Consent](#cookie-consent)).
|
|
99
91
|
|
|
100
|
-
|
|
92
|
+
The state is shared app-wide (via Nuxt's `useState`): every component calling `useVenixTheme()` reads and writes the same theme, so they never go out of sync.
|
|
101
93
|
|
|
102
94
|
### 3. Ready-made component
|
|
103
95
|
|
|
104
|
-
`<VenixThemeSwitcher>` is an auto-imported
|
|
96
|
+
`<VenixThemeSwitcher>` is an auto-imported dropdown for picking a theme, with no dependency on Vuetify or any other UI kit:
|
|
105
97
|
|
|
106
98
|
```vue
|
|
107
99
|
<template>
|
|
@@ -109,148 +101,163 @@ const { theme } = useVenixTheme()
|
|
|
109
101
|
</template>
|
|
110
102
|
```
|
|
111
103
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
|
115
|
-
|
|
|
116
|
-
| `label` | `string` | auto (translated, see below) | Accessible label for the trigger button and the menu heading |
|
|
117
|
-
| `showLabel` | `boolean` | `false` | Also show the active theme's name next to the icon on the button |
|
|
104
|
+
| Prop | Type | Default | Description |
|
|
105
|
+
| ----------- | --------- | ----------------------- | --------------------------------------------------- |
|
|
106
|
+
| `label` | `string` | translated, per locale | Accessible label for the button and the menu |
|
|
107
|
+
| `showLabel` | `boolean` | `false` | Show the active theme's name next to the icon |
|
|
118
108
|
|
|
119
|
-
|
|
109
|
+
- **Accessible:** arrow keys, Home/End and Esc navigate the menu, focus returns to the button on close, and each change is announced to screen readers.
|
|
110
|
+
- **Always legible:** the menu uses fixed neutral colors (dark surface, light text) instead of the active theme's, so every option stays readable whatever theme is applied. The button itself follows the active theme.
|
|
111
|
+
- **Lively:** animated icons (e.g. `line-md`) replay on every switch, and the button fades in on mount.
|
|
120
112
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
- The trigger's icon key changes on every theme switch, forcing it to remount โ so animated icons (Iconify `line-md`, etc.) replay their animation each time instead of staying frozen mid-frame.
|
|
124
|
-
- The trigger fades in from `opacity: 0` on mount rather than popping in.
|
|
125
|
-
- The dropdown's item names and icons use fixed, hardcoded neutral colors (a dark surface with light text) instead of the active theme's `--color-*` variables โ on purpose, so the list of themes stays equally legible no matter which theme is currently applied. The trigger button itself is unaffected and still uses the active theme's colors.
|
|
126
|
-
- Selecting a theme announces the change to screen readers via a visually-hidden live region, and keyboard users get arrow-key/Home/End navigation between items (`role="menu"` + `role="menuitemradio"`), with focus returning to the trigger on close.
|
|
127
|
-
|
|
128
|
-
It ships with minimal, self-contained CSS, so it looks reasonable out of the box in any project โ style it further with `.venix-theme-switcher`, `.venix-theme-switcher__trigger`, `.venix-theme-switcher__menu` and `.venix-theme-switcher__item` (see [`VenixThemeSwitcher.vue`](./src/runtime/components/VenixThemeSwitcher.vue)).
|
|
113
|
+
It ships with minimal CSS of its own. To restyle it, target `.venix-theme-switcher`, `.venix-theme-switcher__trigger`, `.venix-theme-switcher__menu` and `.venix-theme-switcher__item` (see [`VenixThemeSwitcher.vue`](./src/runtime/components/VenixThemeSwitcher.vue)).
|
|
129
114
|
|
|
130
115
|
### Theme transition
|
|
131
116
|
|
|
132
|
-
|
|
117
|
+
Every theme switch โ manual, through the switcher, or an automatic system/seasonal change โ cross-fades using the browser's native [View Transitions API](https://developer.mozilla.org/en-US/docs/Web/API/View_Transitions_API), with no setup. Browsers without support switch instantly, and the animation is skipped for users with `prefers-reduced-motion: reduce`.
|
|
133
118
|
|
|
134
119
|
## Configuration
|
|
135
120
|
|
|
136
121
|
### Module Options
|
|
137
122
|
|
|
138
|
-
|
|
123
|
+
Each option accepts `false` (disable), `true` (enable with defaults) or an object (enable and customize):
|
|
139
124
|
|
|
140
|
-
| Option |
|
|
141
|
-
| ------------- |
|
|
142
|
-
| `translation` | `
|
|
143
|
-
| `color` | `
|
|
144
|
-
| `scrollbar` | `
|
|
145
|
-
| `cursor` | `
|
|
146
|
-
| `typography` | `
|
|
147
|
-
| `
|
|
148
|
-
| `
|
|
125
|
+
| Option | Default | Description |
|
|
126
|
+
| ------------- | ------- | --------------------------------------------------------------------------- |
|
|
127
|
+
| `translation` | `true` | Locale detection for theme names โ see [`translation`](#translation-object) |
|
|
128
|
+
| `color` | `true` | Color themes โ see [`color`](#color-object) and [Themes](#themes) |
|
|
129
|
+
| `scrollbar` | `true` | Custom scrollbar โ see [`scrollbar`, `cursor`, `typography`](#scrollbar-cursor-and-typography) |
|
|
130
|
+
| `cursor` | `true` | Custom cursor images |
|
|
131
|
+
| `typography` | `true` | Base font family, font size and `@font-face` rules |
|
|
132
|
+
| `icon` | `true` | Installs `@nuxt/icon` and registers `<VenixIcon>` โ see [Icons](#icons) |
|
|
133
|
+
| `vuetify` | `false` | Vuetify theme auto-configuration โ see [Vuetify](#vuetify-integration) |
|
|
149
134
|
|
|
150
135
|
#### `translation` object
|
|
151
136
|
|
|
152
|
-
| Property
|
|
153
|
-
|
|
|
154
|
-
| `locale`
|
|
155
|
-
| `defaultLocale
|
|
156
|
-
| `cookieSync`
|
|
157
|
-
| `manageHtmlLang` | `boolean` | `false` | Keep `<html lang>` in sync
|
|
137
|
+
| Property | Type | Default | Description |
|
|
138
|
+
| ---------------- | --------- | ------------------- | -------------------------------------------------------- |
|
|
139
|
+
| `locale` | `string` | โ | Force a locale, skipping detection |
|
|
140
|
+
| `defaultLocale` | `string` | `'en-US'` | Fallback when no locale can be detected |
|
|
141
|
+
| `cookieSync` | `string` | `'i18n_redirected'` | Cookie the locale is read from (and written by `locale.set()`) |
|
|
142
|
+
| `manageHtmlLang` | `boolean` | `false` | Keep `<html lang>` in sync โ see [Internationalization](#internationalization) |
|
|
158
143
|
|
|
159
|
-
|
|
144
|
+
With `translation: false`, detection is off: theme names and the switcher's strings always use `defaultLocale`, and `locale.set()` never writes the cookie.
|
|
160
145
|
|
|
161
146
|
#### `color` object
|
|
162
147
|
|
|
163
|
-
| Property
|
|
164
|
-
|
|
|
165
|
-
| `apply`
|
|
166
|
-
| `defaultColor
|
|
167
|
-
| `themes`
|
|
168
|
-
| `iconFormat`
|
|
148
|
+
| Property | Type | Default | Description |
|
|
149
|
+
| -------------- | --------------------------- | -------- | ------------------------------------------------------------- |
|
|
150
|
+
| `apply` | `boolean` | `true` | Apply the resolved theme to `<html>` (`data-theme` and class) |
|
|
151
|
+
| `defaultColor` | `string` | `'dark'` | Theme used when there's no preference yet |
|
|
152
|
+
| `themes` | `object` | `{}` | Override or add themes โ see [Themes](#themes) |
|
|
153
|
+
| `iconFormat` | `'emote' \| 'css' \| 'svg'` | `'svg'` | Preferred theme icon variant โ see [Theme icons](#theme-icons) |
|
|
169
154
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
`jade` ships a UnoCSS preset that exposes the theme's color variables under `theme.colors` โ add it to your own `uno.config.ts`:
|
|
155
|
+
#### `scrollbar`, `cursor` and `typography`
|
|
173
156
|
|
|
174
157
|
```typescript
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
158
|
+
venixTheme: {
|
|
159
|
+
scrollbar: {
|
|
160
|
+
width: 'auto',
|
|
161
|
+
borderRadius: '8px',
|
|
162
|
+
borderWidth: '3px',
|
|
163
|
+
// A theme color name (follows the active theme) or any CSS color
|
|
164
|
+
colors: { thumb: 'primary', thumbHover: 'secondary', track: 'background2', border: 'background3' },
|
|
165
|
+
},
|
|
166
|
+
cursor: {
|
|
167
|
+
// Images served from `public/`; `hotspot` is the click point ("x y")
|
|
168
|
+
cursors: {
|
|
169
|
+
default: { path: '/cursors/default.png', hotspot: '0 0' },
|
|
170
|
+
pointer: { path: '/cursors/pointer.png', hotspot: '0 0' },
|
|
171
|
+
text: { path: '/cursors/text.png', hotspot: '0 0' },
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
typography: {
|
|
175
|
+
defaultFonts: "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
176
|
+
fontSize: '16px',
|
|
177
|
+
customFonts: [
|
|
178
|
+
{ name: 'MyFont', sources: { woff2: '/fonts/MyFont.woff2' }, weight: 'normal', style: 'normal' },
|
|
179
|
+
],
|
|
180
|
+
},
|
|
181
|
+
}
|
|
185
182
|
```
|
|
186
183
|
|
|
187
|
-
`
|
|
184
|
+
The values shown for `scrollbar` and `typography.defaultFonts`/`fontSize` are the defaults. Custom fonts come first in `--font-family-base` (also applied to Vuetify's `--v-font-body`/`--v-font-heading`), with `defaultFonts` as the fallback.
|
|
185
|
+
|
|
186
|
+
## Themes
|
|
187
|
+
|
|
188
|
+
The module ships with `dark`, `light` and the [seasonal themes](#seasonal-themes). `color.themes` extends that set:
|
|
189
|
+
|
|
190
|
+
- An **existing** name overrides only the properties you set; the rest of the theme (other colors, translations, icon) stays as shipped.
|
|
191
|
+
- A **new** name adds a theme that works like a built-in one: its own CSS variables, an entry in `useVenixTheme().themes` (so it appears in `<VenixThemeSwitcher>`), and UnoCSS/Vuetify support when enabled. New themes are dark unless you set `dark: false`.
|
|
188
192
|
|
|
189
193
|
```typescript
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
primary
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
194
|
+
color: {
|
|
195
|
+
themes: {
|
|
196
|
+
// Overrides only `primary` of the built-in dark theme
|
|
197
|
+
dark: {
|
|
198
|
+
primary: '#FF6B6B',
|
|
199
|
+
},
|
|
200
|
+
|
|
201
|
+
// Adds a project-specific theme
|
|
202
|
+
summerSale: {
|
|
203
|
+
dark: false,
|
|
204
|
+
primary: '#FF8A00',
|
|
205
|
+
background: '#FFF8EE',
|
|
206
|
+
},
|
|
203
207
|
},
|
|
204
208
|
}
|
|
205
209
|
```
|
|
206
210
|
|
|
207
|
-
|
|
211
|
+
Available colors: `primary`, `secondary`, `accent`, `error`, `info`, `success`, `warning`, `background`, `background2`, `background3`. Each becomes a `--color-<name>` CSS variable, plus `--color-inverse` (white on dark themes, black on light ones).
|
|
208
212
|
|
|
209
|
-
|
|
213
|
+
### Seasonal Themes
|
|
210
214
|
|
|
211
|
-
|
|
215
|
+
Built in: ๐ญ Carnival, ๐ Halloween and ๐ Christmas. While the preference is `'system'` and today is inside a seasonal theme's `dateRange`, it replaces `dark` or `light` โ whichever matches its own `dark` flag and the user's system mode.
|
|
212
216
|
|
|
213
|
-
|
|
217
|
+
Add your own with `seasonal: true` and a `dateRange`. Seasonal themes aren't directly selectable; they only appear through `'system'`. The range is inclusive and wraps across the new year when `end` comes before `start`. Each bound is a fixed `MM-DD` date or, for movable holidays, a number of days relative to Easter Sunday (`easter`, `easter-47`, `easter+1`):
|
|
214
218
|
|
|
215
219
|
```typescript
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
220
|
+
color: {
|
|
221
|
+
themes: {
|
|
222
|
+
blackFriday: {
|
|
223
|
+
dark: true,
|
|
224
|
+
seasonal: true,
|
|
225
|
+
dateRange: { start: '11-24', end: '11-30' },
|
|
226
|
+
primary: '#111111',
|
|
227
|
+
background: '#000000',
|
|
228
|
+
},
|
|
229
|
+
pascoa: {
|
|
230
|
+
dark: false,
|
|
231
|
+
seasonal: true,
|
|
232
|
+
dateRange: { start: 'easter-6', end: 'easter' }, // Holy Week, every year
|
|
233
|
+
primary: '#F4A6C0',
|
|
234
|
+
background: '#FFF8F0',
|
|
235
|
+
},
|
|
223
236
|
},
|
|
224
|
-
}
|
|
237
|
+
}
|
|
225
238
|
```
|
|
226
239
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
`vuetify: true` also adds a small runtime plugin that keeps Vuetify's active theme in sync at every point: it resolves the same `theme-preference`/`theme-resolved` cookies used elsewhere in the module so Vuetify's `defaultTheme` matches what's rendered from the first paint (server and client), and it applies every later runtime switch (`theme.toggle()`, the switcher, a system/seasonal auto-change) via `theme.change()` (the current, non-deprecated API), inside the same View Transition the rest of the module uses rather than racing it as a separate update.
|
|
230
|
-
|
|
231
|
-
**This must come before the Vuetify module in your `modules` array** โ the registration happens through Vuetify's own [`vuetify:registerModule`](https://nuxt.vuetifyjs.com/guide/advanced/layers-and-hooks.html) build hook, which only picks up registrations made before Vuetify resolves its configuration. If you already define `vuetify.vuetifyOptions.theme.themes` yourself, your values take precedence over the generated ones (merged per color, not replaced wholesale).
|
|
232
|
-
|
|
233
|
-
`vuetify` defaults to `false` โ unlike the other integrations, it ships a runtime plugin, so it's opt-in rather than automatic. There's no hard dependency on Vuetify: if `vuetify-nuxt-module` isn't installed, enabling this option is a no-op. Tested against Vuetify `^4.2.1` with `vuetify-nuxt-module@1.0.0-rc.6` โ as that module is still pre-1.0, its hooks may still change between releases.
|
|
240
|
+
The built-in Carnival theme uses `easter-65` to `easter-46`: 20 days, from the pre-Carnival weeks up to Ash Wednesday.
|
|
234
241
|
|
|
235
242
|
## Icons
|
|
236
243
|
|
|
237
|
-
`jade` installs and configures [`@nuxt/icon`](https://github.com/nuxt/icon)
|
|
244
|
+
`jade` installs and configures [`@nuxt/icon`](https://github.com/nuxt/icon) and registers `<VenixIcon>` (and the matching `useVenixIcon()` composable). A single `icon` value accepts three formats:
|
|
238
245
|
|
|
239
246
|
```vue
|
|
240
247
|
<template>
|
|
241
|
-
<VenixIcon icon="๐จ" />
|
|
242
248
|
<VenixIcon icon="line-md:home" />
|
|
243
|
-
<VenixIcon icon="<svg viewBox
|
|
249
|
+
<VenixIcon icon="<svg viewBox="0 0 24 24">...</svg>" />
|
|
250
|
+
<VenixIcon icon="๐จ" />
|
|
244
251
|
</template>
|
|
245
252
|
```
|
|
246
253
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
254
|
+
- **Iconify name** โ `collection:name` (e.g. `line-md:home`, `mdi:home`), including [`line-md`](https://icon-sets.iconify.design/line-md/)'s animated icons.
|
|
255
|
+
- **Inline SVG** โ a string starting with `<svg`, rendered with `v-html`. It isn't sanitized, so only pass SVGs you control, never user input.
|
|
256
|
+
- **Emoji or text** โ anything else.
|
|
250
257
|
|
|
251
258
|
### Aliases
|
|
252
259
|
|
|
253
|
-
|
|
260
|
+
`icon.aliases` gives short names to any of the three formats:
|
|
254
261
|
|
|
255
262
|
```typescript
|
|
256
263
|
venixTheme: {
|
|
@@ -270,7 +277,11 @@ venixTheme: {
|
|
|
270
277
|
|
|
271
278
|
### Offline icon collections
|
|
272
279
|
|
|
273
|
-
|
|
280
|
+
Icons are bundled at build time, so they work offline instead of being fetched from the Iconify API:
|
|
281
|
+
|
|
282
|
+
- **`line-md`** is bundled whole by default.
|
|
283
|
+
- **Icons used in theme `icon`s or in `icon.aliases`** are detected automatically, and only those icons are bundled, not their whole collection. That's how the built-in themes' `mdi` icons are included. The collection is looked up in this module's dependencies first, then in your project's `node_modules`.
|
|
284
|
+
- **To use any icon of a collection anywhere in your app**, install its `@iconify-json/<collection>` package and list it in `icon.collections` to bundle it whole. Keep `line-md` in the list if you still want it:
|
|
274
285
|
|
|
275
286
|
```typescript
|
|
276
287
|
venixTheme: {
|
|
@@ -280,21 +291,11 @@ venixTheme: {
|
|
|
280
291
|
}
|
|
281
292
|
```
|
|
282
293
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
Setting `icon: false` skips installing `@nuxt/icon` entirely โ useful if your project already configures it directly.
|
|
294
|
+
If a referenced collection can't be found, `@nuxt/icon` fetches it from the Iconify API at runtime, which needs internet. Set `icon: false` to skip `@nuxt/icon` entirely, e.g. if your project already configures it.
|
|
286
295
|
|
|
287
296
|
### Theme icons
|
|
288
297
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
```json
|
|
292
|
-
"dark": {
|
|
293
|
-
"icon": "๐"
|
|
294
|
-
}
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
...or an object offering up to three variants, letting the app pick the best one for its needs:
|
|
298
|
+
A theme's `icon` (shown by pickers such as `<VenixThemeSwitcher>`) is either a plain emoji, like `"icon": "๐"`, or an object with up to three variants:
|
|
298
299
|
|
|
299
300
|
```json
|
|
300
301
|
"light": {
|
|
@@ -306,21 +307,11 @@ Each color theme's `icon` (used by `useVenixTheme().themes` for things like a th
|
|
|
306
307
|
}
|
|
307
308
|
```
|
|
308
309
|
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
Which variant gets used is controlled globally by `color.iconFormat` (`'emote' | 'css' | 'svg'`, defaults to `'svg'`) โ it falls back to `emote` automatically for any theme that doesn't define the chosen format (including themes that just use a plain string):
|
|
310
|
+
- `emote` โ an emoji. Required, it's the fallback.
|
|
311
|
+
- `css` โ an Iconify name rendered in CSS mode: lighter, but never animated.
|
|
312
|
+
- `svg` โ an Iconify name rendered as a real `<svg>`, needed for animated icons like `line-md`'s.
|
|
314
313
|
|
|
315
|
-
|
|
316
|
-
venixTheme: {
|
|
317
|
-
color: {
|
|
318
|
-
iconFormat: 'css', // lighter weight, no animation โ trade the default 'svg' for this if you don't need line-md's animated icons
|
|
319
|
-
},
|
|
320
|
-
}
|
|
321
|
-
```
|
|
322
|
-
|
|
323
|
-
`useVenixTheme().themes` exposes the already-resolved icon as `{ format, value }`, ready to feed into `<VenixIcon>`:
|
|
314
|
+
`color.iconFormat` picks the variant for every theme (default `'svg'`), falling back to `emote` when a theme doesn't define it. `useVenixTheme().themes` already resolves it to `{ format, value }`, ready for `<VenixIcon>`:
|
|
324
315
|
|
|
325
316
|
```vue
|
|
326
317
|
<VenixIcon
|
|
@@ -330,46 +321,18 @@ venixTheme: {
|
|
|
330
321
|
/>
|
|
331
322
|
```
|
|
332
323
|
|
|
333
|
-
## Themes
|
|
334
|
-
|
|
335
|
-
The module ships with a built-in set of color themes (`dark`, `light`, plus the [seasonal ones](#seasonal-themes)) and can be extended through `color.themes`, which does two different things depending on the key:
|
|
336
|
-
|
|
337
|
-
- An **existing** name (`dark`, `light`, or any seasonal one) overrides only the properties you give it, keeping the rest of that theme intact.
|
|
338
|
-
- A **new** name registers a theme that doesn't exist in the built-in set at all โ nothing further to opt into, it works the same as any built-in theme: real CSS variables, its own entry in `useVenixTheme().themes` (so it shows up in `<VenixThemeSwitcher>`), and Vuetify/UnoCSS integration if those are enabled. Useful for a theme specific to your project, e.g. a brand color scheme or a one-off campaign theme with no equivalent in the base set.
|
|
339
|
-
|
|
340
|
-
```typescript
|
|
341
|
-
color: {
|
|
342
|
-
themes: {
|
|
343
|
-
// Overrides an existing theme โ the rest of `dark` stays as shipped
|
|
344
|
-
dark: {
|
|
345
|
-
primary: '#FF6B6B',
|
|
346
|
-
},
|
|
347
|
-
|
|
348
|
-
// Registers a brand new one, project-specific โ 'summerSale' isn't a
|
|
349
|
-
// built-in theme name, so this doesn't override anything
|
|
350
|
-
summerSale: {
|
|
351
|
-
dark: false,
|
|
352
|
-
primary: '#FF8A00',
|
|
353
|
-
background: '#FFF8EE',
|
|
354
|
-
},
|
|
355
|
-
},
|
|
356
|
-
}
|
|
357
|
-
```
|
|
358
|
-
|
|
359
|
-
This is currently the only supported way to customize colors โ there's no option yet to load a completely custom theme file in place of the built-in one.
|
|
360
|
-
|
|
361
324
|
## Cookie Consent
|
|
362
325
|
|
|
363
|
-
|
|
326
|
+
Two cookies remember the user's choice between visits:
|
|
364
327
|
|
|
365
|
-
| Cookie
|
|
366
|
-
|
|
|
367
|
-
| `venix-theme-preference`
|
|
368
|
-
| `venix-theme-resolved`
|
|
328
|
+
| Cookie | Stores |
|
|
329
|
+
| ------------------------ | ----------------------------------------------------------------------------------- |
|
|
330
|
+
| `venix-theme-preference` | The user's raw choice (`'dark'`, `'system'`, a custom themeโฆ) |
|
|
331
|
+
| `venix-theme-resolved` | The theme actually applied (e.g. `'dark'` for `'system'`), so SSR renders it with no flash |
|
|
369
332
|
|
|
370
|
-
Neither is written
|
|
333
|
+
Neither is written without consent. Switching themes always works; without consent it just isn't remembered on the next visit. (The locale cookie is covered in [Integrating with a routing-based i18n module](#integrating-with-a-routing-based-i18n-module-eg-nuxtjsi18n).)
|
|
371
334
|
|
|
372
|
-
Consent is read from `localStorage['venix-cookie-consent']
|
|
335
|
+
Consent is read from `localStorage['venix-cookie-consent']`, a JSON object with a `functionality: boolean` field โ the "functional cookies" category most consent banners already use. The module never writes this key by itself. For a minimal banner, use the built-in helpers:
|
|
373
336
|
|
|
374
337
|
```vue
|
|
375
338
|
<script setup lang="ts">
|
|
@@ -383,46 +346,43 @@ const { persistence } = useVenixTheme()
|
|
|
383
346
|
</template>
|
|
384
347
|
```
|
|
385
348
|
|
|
386
|
-
- `persistence.hasConsent` โ reactive `Ref<boolean>`,
|
|
387
|
-
- `persistence.grant()` โ records consent
|
|
388
|
-
- `persistence.revoke()` โ records the
|
|
349
|
+
- `persistence.hasConsent` โ reactive `Ref<boolean>`, shared app-wide.
|
|
350
|
+
- `persistence.grant()` โ records consent and saves the current theme to the cookies right away.
|
|
351
|
+
- `persistence.revoke()` โ records the refusal and deletes both cookies right away.
|
|
352
|
+
- `persistence.enable()` / `persistence.disable()` โ lower-level: write or delete the cookies directly (`enable()` still does nothing without consent).
|
|
389
353
|
|
|
390
|
-
If you already have
|
|
354
|
+
If you already have a consent banner or CMP, have it write the same key and then dispatch `venix-cookie-preferences-updated` on `window`, so the module re-syncs immediately:
|
|
391
355
|
|
|
392
356
|
```ts
|
|
393
357
|
localStorage.setItem('venix-cookie-consent', JSON.stringify({ functionality: true }))
|
|
394
358
|
window.dispatchEvent(new Event('venix-cookie-preferences-updated'))
|
|
395
359
|
```
|
|
396
360
|
|
|
397
|
-
`persistence.enable()` / `persistence.disable()` remain available as the lower-level primitives (`enable()` still checks the stored consent before writing, so it's safe to call speculatively โ it's a no-op without consent).
|
|
398
|
-
|
|
399
361
|
## Internationalization
|
|
400
362
|
|
|
401
|
-
The
|
|
363
|
+
The resolved locale translates the theme names (each theme's `translations`) and `<VenixThemeSwitcher>`'s own strings. It's detected in this order:
|
|
402
364
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
4. The `Accept-Language` header (SSR) / `navigator.language` (client)
|
|
409
|
-
5. The configured default locale (`translation.defaultLocale`)
|
|
365
|
+
1. `translation.locale`, if set (skips every other step)
|
|
366
|
+
2. The locale cookie (`translation.cookieSync`)
|
|
367
|
+
3. The URL's locale prefix (e.g. `/en/...`), if a theme has a translation for it
|
|
368
|
+
4. The `Accept-Language` header (SSR) or `navigator.language` (client)
|
|
369
|
+
5. `translation.defaultLocale`
|
|
410
370
|
|
|
411
371
|
### Using your own translations
|
|
412
372
|
|
|
413
|
-
`
|
|
373
|
+
`locale.translate()` applies the same matching and fallbacks to your own strings:
|
|
414
374
|
|
|
415
375
|
```ts
|
|
416
376
|
const { locale } = useVenixTheme()
|
|
417
377
|
|
|
418
|
-
locale.translate({ 'en-US': 'Hello', 'pt-BR': 'Olรก' }, 'Hello') //
|
|
378
|
+
locale.translate({ 'en-US': 'Hello', 'pt-BR': 'Olรก' }, 'Hello') // second argument: fallback
|
|
419
379
|
```
|
|
420
380
|
|
|
421
381
|
### Integrating with a routing-based i18n module (e.g. `@nuxtjs/i18n`)
|
|
422
382
|
|
|
423
|
-
`translation.cookieSync` defaults to `'i18n_redirected'
|
|
383
|
+
`translation.cookieSync` defaults to `'i18n_redirected'`, the same cookie `@nuxtjs/i18n` uses, so theme names follow your app's locale with no extra setup. If you renamed the cookie on either side, point `cookieSync` at the same name.
|
|
424
384
|
|
|
425
|
-
|
|
385
|
+
`<html lang>` isn't touched by default. If your app has **no** routing i18n module, turn on `manageHtmlLang` so `lang` reflects the resolved locale (WCAG 3.1.1 โ screen readers pronounce the theme names correctly):
|
|
426
386
|
|
|
427
387
|
```ts
|
|
428
388
|
venixTheme: {
|
|
@@ -432,41 +392,62 @@ venixTheme: {
|
|
|
432
392
|
}
|
|
433
393
|
```
|
|
434
394
|
|
|
435
|
-
|
|
395
|
+
Keep it off with `@nuxtjs/i18n` or similar: that module follows the current route and should own `lang`, while this module's detection can briefly disagree with it (e.g. right after navigating to a localized route) and the two would fight over the attribute.
|
|
396
|
+
|
|
397
|
+
## UnoCSS integration
|
|
398
|
+
|
|
399
|
+
Add the preset to your `uno.config.ts` to use the theme colors as utilities (`text-primary`, `bg-background2`, `border-accent`, โฆ):
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
// uno.config.ts
|
|
403
|
+
import { defineConfig } from 'unocss'
|
|
404
|
+
import { venixUnoPreset } from '@venix-sistemas/jade/unocss'
|
|
405
|
+
|
|
406
|
+
export default defineConfig({
|
|
407
|
+
presets: [
|
|
408
|
+
venixUnoPreset(),
|
|
409
|
+
// ...your other presets
|
|
410
|
+
],
|
|
411
|
+
})
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
It maps every [theme color](#themes), plus `inverse`, to its CSS variable (`primary: 'var(--color-primary)'`, โฆ), so utilities follow the active theme. Colors you define yourself in `uno.config.ts` take precedence.
|
|
436
415
|
|
|
437
|
-
|
|
416
|
+
The preset has to be added by hand: `@unocss/nuxt` re-reads `uno.config.ts` from disk and discards a `theme` injected by other modules whenever your file declares its own `theme` key. As a preset in your own file, the colors survive that.
|
|
438
417
|
|
|
439
|
-
|
|
418
|
+
## Vuetify integration
|
|
440
419
|
|
|
441
|
-
|
|
420
|
+
With [`vuetify-nuxt-module`](https://nuxt.vuetifyjs.com) installed, `vuetify: true` registers every color theme with Vuetify and keeps its active theme in sync โ no hand-written `theme.themes` mapping:
|
|
442
421
|
|
|
443
422
|
```typescript
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
background: '#000000',
|
|
452
|
-
},
|
|
423
|
+
export default defineNuxtConfig({
|
|
424
|
+
modules: [
|
|
425
|
+
'@venix-sistemas/jade', // must come before the Vuetify module
|
|
426
|
+
'vuetify-nuxt-module',
|
|
427
|
+
],
|
|
428
|
+
venixTheme: {
|
|
429
|
+
vuetify: true,
|
|
453
430
|
},
|
|
454
|
-
}
|
|
431
|
+
})
|
|
455
432
|
```
|
|
456
433
|
|
|
457
|
-
|
|
434
|
+
- **Order matters:** the themes are registered through Vuetify's [`vuetify:registerModule`](https://nuxt.vuetifyjs.com/guide/advanced/layers-and-hooks.html) hook, which only sees modules listed before Vuetify.
|
|
435
|
+
- **Real colors:** Vuetify computes contrast and `on-*` colors in JavaScript, so it receives the actual hex values, not `var(...)`. `background2` also fills Vuetify's `surface` slot (cards, toolbars, โฆ).
|
|
436
|
+
- **Your values win:** anything you set in `vuetify.vuetifyOptions.theme.themes` is merged per color on top of the generated themes.
|
|
437
|
+
- **Always in sync:** a small runtime plugin picks Vuetify's initial theme from the same cookies (so the first paint is right, with or without SSR) and applies every later switch with `theme.change()`, inside the same View Transition as the rest of the page.
|
|
438
|
+
- **No flash in SPA mode** (`ssr: false`): Vuetify's theme stylesheet only reaches the DOM after the first render there, so the plugin writes a temporary copy into `<head>` before mount and removes it once Vuetify's own arrives.
|
|
458
439
|
|
|
459
|
-
|
|
440
|
+
It's opt-in because it adds a runtime plugin, and it does nothing if `vuetify-nuxt-module` isn't installed. Tested with Vuetify `^4.2.1` and `vuetify-nuxt-module@1.0.0-rc.6`; that module is still pre-1.0, so its hooks may change.
|
|
460
441
|
|
|
461
|
-
|
|
462
|
-
| ------- | ----------- |
|
|
463
|
-
| `pnpm install` | Install dependencies |
|
|
464
|
-
| `pnpm dev` | Start the playground |
|
|
465
|
-
| `pnpm test` | Run the tests |
|
|
466
|
-
| `pnpm lint` | Run the linter |
|
|
467
|
-
| `pnpm prepack` | Build the package |
|
|
442
|
+
## Development
|
|
468
443
|
|
|
469
|
-
|
|
444
|
+
| Command | Description |
|
|
445
|
+
| -------------- | -------------------- |
|
|
446
|
+
| `pnpm install` | Install dependencies |
|
|
447
|
+
| `pnpm dev` | Start the [playground](./playground) |
|
|
448
|
+
| `pnpm test` | Run the tests |
|
|
449
|
+
| `pnpm lint` | Run the linter |
|
|
450
|
+
| `pnpm prepack` | Build the package |
|
|
470
451
|
|
|
471
452
|
## Brand
|
|
472
453
|
|