@maz-ui/themes 5.0.0-canary.ef64a02.0 → 5.2.0-beta.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 +62 -17
- package/dist/build/index.d.ts +10 -13
- package/dist/build/index.d.ts.map +1 -1
- package/dist/build/index.js +42 -1
- package/dist/composables/index.js +1 -1
- package/dist/composables/useTheme.d.ts +10 -2
- package/dist/composables/useTheme.d.ts.map +1 -1
- package/dist/composables/useTheme.js +95 -1
- package/dist/define-preset.js +8 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -1
- package/dist/plugin.js +12 -1
- package/dist/presets/_defaults.d.ts +33 -6
- package/dist/presets/_defaults.d.ts.map +1 -1
- package/dist/presets/_defaults.js +34 -1
- package/dist/presets/index.js +6 -1
- package/dist/presets/mazUi.d.ts.map +1 -1
- package/dist/presets/mazUi.js +90 -1
- package/dist/presets/nova.d.ts.map +1 -1
- package/dist/presets/nova.js +88 -1
- package/dist/presets/obsidian.d.ts.map +1 -1
- package/dist/presets/obsidian.js +90 -1
- package/dist/presets/ocean.d.ts.map +1 -1
- package/dist/presets/ocean.js +90 -1
- package/dist/presets/pristine.d.ts.map +1 -1
- package/dist/presets/pristine.js +94 -1
- package/dist/types/index.d.ts +62 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/color-conversions.d.ts +29 -0
- package/dist/utils/color-conversions.d.ts.map +1 -0
- package/dist/utils/color-conversions.js +162 -0
- package/dist/utils/color-parser.d.ts +3 -27
- package/dist/utils/color-parser.d.ts.map +1 -1
- package/dist/utils/color-parser.js +17 -1
- package/dist/utils/color-scheme-meta.d.ts +15 -0
- package/dist/utils/color-scheme-meta.d.ts.map +1 -0
- package/dist/utils/color-scheme-meta.js +12 -0
- package/dist/utils/cookie-storage.d.ts +17 -7
- package/dist/utils/cookie-storage.d.ts.map +1 -1
- package/dist/utils/cookie-storage.js +25 -1
- package/dist/utils/css-generator.d.ts +6 -4
- package/dist/utils/css-generator.d.ts.map +1 -1
- package/dist/utils/css-generator.js +75 -4
- package/dist/utils/get-color-mode.js +26 -1
- package/dist/utils/get-preset.js +30 -1
- package/dist/utils/index.d.ts +2 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +13 -1
- package/dist/utils/inject-theme-css.d.ts.map +1 -1
- package/dist/utils/inject-theme-css.js +12 -1
- package/dist/utils/inject.js +7 -1
- package/dist/utils/no-transition.js +11 -5
- package/dist/utils/preset-merger.d.ts.map +1 -1
- package/dist/utils/preset-merger.js +72 -1
- package/dist/utils/setup-theme.d.ts +9 -0
- package/dist/utils/setup-theme.d.ts.map +1 -1
- package/dist/utils/setup-theme.js +133 -1
- package/dist/utils/update-document-class.d.ts +2 -2
- package/dist/utils/update-document-class.d.ts.map +1 -1
- package/dist/utils/update-document-class.js +13 -1
- package/dist/utils/use-mutation-observer.js +11 -1
- package/dist/utils/view-transition.d.ts +10 -0
- package/dist/utils/view-transition.d.ts.map +1 -0
- package/dist/utils/view-transition.js +11 -0
- package/package.json +41 -14
- package/dist/utils/color-utils.d.ts +0 -35
- package/dist/utils/color-utils.d.ts.map +0 -1
- package/dist/utils/color-utils.js +0 -1
package/README.md
CHANGED
|
@@ -4,9 +4,11 @@ High-performance and typed theme system for Maz-UI.
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
- 🎨 **
|
|
8
|
-
- 🌓 **
|
|
9
|
-
-
|
|
7
|
+
- 🎨 **Native `light-dark()` + `color-scheme`** - Modern CSS theming with zero JS overhead for the light/dark switch
|
|
8
|
+
- 🌓 **Native dark mode** - `color-scheme` makes native form controls, scrollbars, and built-in widgets adapt automatically
|
|
9
|
+
- ✨ **View Transitions** - Optional full-page animated theme switch via `document.startViewTransition()`
|
|
10
|
+
- 🛡️ **Anti-FART** - `<meta name="color-scheme">` injected at boot to prevent any Flash of inAccurate coloR Theme
|
|
11
|
+
- 🚀 **Automatic generation** - Automatically generates color variants (50-950) via OKLCh relative color syntax
|
|
10
12
|
- ⚡ **Flexible strategies** - Runtime injection or build-time generation
|
|
11
13
|
- 🛡️ **Strict TypeScript** - Complete types for optimal DX
|
|
12
14
|
- 🎯 **Zero FOUC** - Pass the preset object so the full CSS renders synchronously on first paint
|
|
@@ -34,6 +36,10 @@ app.use(MazUiTheme, {
|
|
|
34
36
|
preset: mazUi,
|
|
35
37
|
strategy: 'runtime',
|
|
36
38
|
darkModeStrategy: 'class',
|
|
39
|
+
// Class added to <html> when dark mode is forced (default: 'dark')
|
|
40
|
+
darkClass: 'dark',
|
|
41
|
+
// Class added to <html> when light mode is forced (default: 'light')
|
|
42
|
+
lightClass: 'light',
|
|
37
43
|
// remember the active preset name across reloads (default: true)
|
|
38
44
|
persistPreset: true,
|
|
39
45
|
})
|
|
@@ -41,7 +47,7 @@ app.use(MazUiTheme, {
|
|
|
41
47
|
|
|
42
48
|
### Preset persistence
|
|
43
49
|
|
|
44
|
-
The active preset
|
|
50
|
+
The active preset is stored in a `maz-preset` cookie (1-year TTL, `SameSite=Lax`) as a `base:active` pair, where `base` is the identity of the preset declared in `options.preset` and `active` is the one currently applied. The configured `options.preset` is always authoritative: a runtime switch made via `useTheme().updateTheme()` is only restored on reload when its `base` matches the configured preset, so a stale cookie - or a cookie written by another app on the same host - can never override the preset your app declares. A foreign or legacy (plain-name) cookie is ignored and healed on the next resolution. Set `persistPreset: false` to opt out - no cookie is read or written.
|
|
45
51
|
|
|
46
52
|
### 2. Usage in components
|
|
47
53
|
|
|
@@ -64,6 +70,41 @@ const { toggleDarkMode, isDark } = useTheme()
|
|
|
64
70
|
</template>
|
|
65
71
|
```
|
|
66
72
|
|
|
73
|
+
## Color modes and class toggling
|
|
74
|
+
|
|
75
|
+
`darkClass` and `lightClass` interact with `darkModeStrategy` to control how `<html>` is decorated.
|
|
76
|
+
|
|
77
|
+
### `darkModeStrategy: 'class'` (default)
|
|
78
|
+
|
|
79
|
+
- `setColorMode('dark')` → adds `darkClass` (default `.dark`) to `<html>` → CSS applies `color-scheme: only dark`.
|
|
80
|
+
- `setColorMode('light')` → adds `lightClass` (default `.light`) to `<html>` → CSS applies `color-scheme: only light`.
|
|
81
|
+
- `setColorMode('auto')` → removes both classes, leaving only `color-scheme: light dark` on `:root` so the browser follows the system `prefers-color-scheme`.
|
|
82
|
+
|
|
83
|
+
Forcing both classes (light/dark) on the root ensures the browser-native widgets (scrollbars, native `<select>`, date pickers, autofill backgrounds, …) match the explicit user choice rather than the OS preference.
|
|
84
|
+
|
|
85
|
+
### `darkModeStrategy: 'media'`
|
|
86
|
+
|
|
87
|
+
- No class is ever added to `<html>`.
|
|
88
|
+
- The browser always follows `prefers-color-scheme` via `color-scheme: light dark`.
|
|
89
|
+
- `setColorMode()` still updates the persisted cookie but does **not** force a visual override — system preference always wins.
|
|
90
|
+
|
|
91
|
+
## Animated theme switch (View Transitions)
|
|
92
|
+
|
|
93
|
+
For a full-page animated swap (rather than per-variable color tweens), pass `{ animate: true }` to `setColorMode` or `toggleDarkMode`:
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
import { useTheme } from '@maz-ui/themes'
|
|
97
|
+
|
|
98
|
+
const { toggleDarkMode, setColorMode } = useTheme()
|
|
99
|
+
|
|
100
|
+
await toggleDarkMode({ animate: true })
|
|
101
|
+
await setColorMode('dark', { animate: true })
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
- Wraps the switch in `document.startViewTransition()` so the browser captures a snapshot of the page before/after and crossfades between them.
|
|
105
|
+
- The helper is **lazy-imported** — when `animate` is not used, the View Transitions glue stays out of the boot bundle.
|
|
106
|
+
- **Graceful degradation:** in browsers that don't support the API (e.g., Firefox stable as of mid-2026), the change is applied immediately with no animation — no error thrown.
|
|
107
|
+
|
|
67
108
|
## Available presets
|
|
68
109
|
|
|
69
110
|
### Default
|
|
@@ -106,16 +147,16 @@ const myPreset = definePreset({
|
|
|
106
147
|
overrides: {
|
|
107
148
|
name: 'my-theme',
|
|
108
149
|
scales: {
|
|
109
|
-
|
|
150
|
+
rounded: { md: '0.75rem' },
|
|
110
151
|
},
|
|
111
152
|
colors: {
|
|
112
153
|
light: {
|
|
113
|
-
primary: '
|
|
114
|
-
secondary: '
|
|
154
|
+
primary: 'oklch(0.6 0.2 250)',
|
|
155
|
+
secondary: 'oklch(0.96 0.01 250)',
|
|
115
156
|
},
|
|
116
157
|
dark: {
|
|
117
|
-
primary: '
|
|
118
|
-
secondary: '
|
|
158
|
+
primary: 'oklch(0.7 0.2 250)',
|
|
159
|
+
secondary: 'oklch(0.2 0.01 250)',
|
|
119
160
|
},
|
|
120
161
|
},
|
|
121
162
|
},
|
|
@@ -133,12 +174,16 @@ const {
|
|
|
133
174
|
colorMode, // Ref<'light' | 'dark' | 'auto'>
|
|
134
175
|
isDark, // ComputedRef<boolean>
|
|
135
176
|
strategy, // ComputedRef<'runtime' | 'buildtime'>
|
|
136
|
-
updateTheme, // (preset: ThemePreset | ThemePresetName | ThemePresetOverrides) => void
|
|
137
|
-
setColorMode, // (mode: 'light' | 'dark' | 'auto') => void
|
|
138
|
-
toggleDarkMode, // () => void
|
|
177
|
+
updateTheme, // (preset: ThemePreset | ThemePresetName | ThemePresetOverrides) => Promise<void>
|
|
178
|
+
setColorMode, // (mode: 'light' | 'dark' | 'auto', options?: { animate?: boolean }) => Promise<void>
|
|
179
|
+
toggleDarkMode, // (options?: { animate?: boolean }) => Promise<void>
|
|
139
180
|
} = useTheme()
|
|
140
181
|
```
|
|
141
182
|
|
|
183
|
+
`setColorMode` and `toggleDarkMode` are **async** (`Promise<void>`). The promise resolves once the change — and the optional View Transition — has been applied. Callers can ignore the return value when no transition is needed.
|
|
184
|
+
|
|
185
|
+
The optional `{ animate?: boolean }` parameter enables the View Transitions API (see [Animated theme switch](#animated-theme-switch-view-transitions)).
|
|
186
|
+
|
|
142
187
|
## Strategies
|
|
143
188
|
|
|
144
189
|
### Runtime (recommended)
|
|
@@ -151,12 +196,12 @@ CSS generated at build-time and included in the bundle. Nothing is injected at r
|
|
|
151
196
|
|
|
152
197
|
## Generated CSS variables
|
|
153
198
|
|
|
154
|
-
The
|
|
199
|
+
The generator produces a modern, native CSS contract:
|
|
155
200
|
|
|
156
|
-
- Base
|
|
157
|
-
-
|
|
158
|
-
-
|
|
159
|
-
-
|
|
201
|
+
- **Base colors** are emitted as `light-dark(L, D)` when `mode: 'both'` — a single declaration that the browser resolves to the active scheme. Example: `--maz-primary: light-dark(oklch(0.6 0.2 250), oklch(0.7 0.2 250));`.
|
|
202
|
+
- **Scale palettes** `--maz-X-50` through `--maz-X-950` are derived from the base via OKLCh relative color syntax — `oklch(from var(--maz-X) clamp(0, calc(l ± offset), 1) calc(c * mult) h)`. Lightness offsets follow Tailwind v4's perceptual spread; chroma is preserved (and tapered near extremes) so derived shades stay vibrant rather than washed-out.
|
|
203
|
+
- **Color scheme** is declared on `:root` as `color-scheme: light dark`. With `darkModeStrategy: 'class'`, the generator also emits `.dark { color-scheme: only dark; }` and `.light { color-scheme: only light; }` so an explicit user choice overrides the system preference (and native widgets follow).
|
|
204
|
+
- **Design tokens** — `--maz-rounded-*`, `--maz-shadow-*`, `--maz-font-family`, motion durations, easings, etc. — are bridged into Tailwind v4 via `@theme inline`.
|
|
160
205
|
|
|
161
206
|
## Build-time
|
|
162
207
|
|
package/dist/build/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ThemePreset } from '../types';
|
|
2
|
-
|
|
3
|
-
preset: ThemePreset;
|
|
2
|
+
interface SharedOptions {
|
|
4
3
|
/** Theme mode to generate */
|
|
5
4
|
mode?: 'light' | 'dark' | 'both';
|
|
6
5
|
/** Dark mode selector: 'class' (.dark) | 'media' (@media) */
|
|
@@ -9,24 +8,22 @@ export interface BuildThemeOptions {
|
|
|
9
8
|
prefix?: string;
|
|
10
9
|
/** Dark class name */
|
|
11
10
|
darkClass?: string;
|
|
11
|
+
/** Light class name (default 'light') */
|
|
12
|
+
lightClass?: string;
|
|
12
13
|
}
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}): Record<string, string>;
|
|
14
|
+
export interface BuildThemeOptions extends SharedOptions {
|
|
15
|
+
preset: ThemePreset;
|
|
16
|
+
}
|
|
17
|
+
export declare function buildThemeCSS({ preset, mode, darkSelector, prefix, darkClass, lightClass, }: BuildThemeOptions): string;
|
|
18
|
+
export declare function generateThemeBundle(presets: ThemePreset[], options?: SharedOptions): Record<string, string>;
|
|
19
19
|
export declare function createThemeStylesheet(css: string, options?: {
|
|
20
20
|
id?: string;
|
|
21
21
|
media?: string;
|
|
22
22
|
}): string;
|
|
23
|
-
export declare function buildSeparateThemeFiles(preset: ThemePreset, options?: {
|
|
24
|
-
prefix?: string;
|
|
25
|
-
darkSelector?: 'class' | 'media';
|
|
26
|
-
darkClass?: string;
|
|
27
|
-
}): {
|
|
23
|
+
export declare function buildSeparateThemeFiles(preset: ThemePreset, options?: Omit<SharedOptions, 'mode'>): {
|
|
28
24
|
full: string;
|
|
29
25
|
lightOnly: string;
|
|
30
26
|
darkOnly: string;
|
|
31
27
|
};
|
|
28
|
+
export {};
|
|
32
29
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAG3C,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/build/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAG3C,UAAU,aAAa;IACrB,6BAA6B;IAC7B,IAAI,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;IAChC,6DAA6D;IAC7D,YAAY,CAAC,EAAE,OAAO,GAAG,OAAO,CAAA;IAChC,2BAA2B;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,sBAAsB;IACtB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,yCAAyC;IACzC,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD,MAAM,EAAE,WAAW,CAAA;CACpB;AAED,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,IAAa,EACb,YAAsB,EACtB,MAAc,EACd,SAAkB,EAClB,UAAoB,GACrB,EAAE,iBAAiB,GAAG,MAAM,CAQ5B;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,OAAO,GAAE,aAAkB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAK/G;AAED,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,EAAE,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAO,GAAG,MAAM,CAIxG;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,MAAM,CAAM,GAAG;IACvG,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAMA"}
|
package/dist/build/index.js
CHANGED
|
@@ -1 +1,42 @@
|
|
|
1
|
-
import{generateCSS}from"../utils/css-generator.js";
|
|
1
|
+
import { generateCSS } from "../utils/css-generator.js";
|
|
2
|
+
//#region src/build/index.ts
|
|
3
|
+
function buildThemeCSS({ preset, mode = "both", darkSelector = "class", prefix = "maz", darkClass = "dark", lightClass = "light" }) {
|
|
4
|
+
return generateCSS(preset, {
|
|
5
|
+
mode,
|
|
6
|
+
darkSelectorStrategy: darkSelector,
|
|
7
|
+
prefix,
|
|
8
|
+
darkClass,
|
|
9
|
+
lightClass
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
function generateThemeBundle(presets, options = {}) {
|
|
13
|
+
return presets.reduce((bundle, preset) => (bundle[preset.name] = buildThemeCSS({
|
|
14
|
+
preset,
|
|
15
|
+
...options
|
|
16
|
+
}), bundle), {});
|
|
17
|
+
}
|
|
18
|
+
function createThemeStylesheet(css, options = {}) {
|
|
19
|
+
let { id = "maz-theme", media } = options;
|
|
20
|
+
return `<style id="${id}"${media ? ` media="${media}"` : ""}>\n${css}\n</style>`;
|
|
21
|
+
}
|
|
22
|
+
function buildSeparateThemeFiles(preset, options = {}) {
|
|
23
|
+
return {
|
|
24
|
+
full: buildThemeCSS({
|
|
25
|
+
preset,
|
|
26
|
+
mode: "both",
|
|
27
|
+
...options
|
|
28
|
+
}),
|
|
29
|
+
lightOnly: buildThemeCSS({
|
|
30
|
+
preset,
|
|
31
|
+
mode: "light",
|
|
32
|
+
...options
|
|
33
|
+
}),
|
|
34
|
+
darkOnly: buildThemeCSS({
|
|
35
|
+
preset,
|
|
36
|
+
mode: "dark",
|
|
37
|
+
...options
|
|
38
|
+
})
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { buildSeparateThemeFiles, buildThemeCSS, createThemeStylesheet, generateThemeBundle };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export { useTheme } from "./useTheme.js";
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { ColorMode, ThemePreset, ThemePresetName, ThemePresetOverrides } from '../types';
|
|
2
2
|
declare function updateTheme(preset: ThemePreset | ThemePresetOverrides | ThemePresetName): Promise<void>;
|
|
3
|
-
declare function setColorMode(colorMode: ColorMode
|
|
4
|
-
|
|
3
|
+
declare function setColorMode(colorMode: ColorMode, options?: {
|
|
4
|
+
animate?: boolean;
|
|
5
|
+
}): Promise<void>;
|
|
6
|
+
declare function toggleDarkMode(options?: {
|
|
7
|
+
animate?: boolean;
|
|
8
|
+
}): Promise<void>;
|
|
5
9
|
export declare function useTheme(): {
|
|
6
10
|
/**
|
|
7
11
|
* Current theme preset
|
|
@@ -34,11 +38,15 @@ export declare function useTheme(): {
|
|
|
34
38
|
* Set the color mode
|
|
35
39
|
* @description Set the color mode - Can be 'auto', 'dark' or 'light'
|
|
36
40
|
* @param colorMode The new color mode
|
|
41
|
+
* @param options.animate When `true`, wrap the change in a View Transition for a smooth full-page animation. Lazy-imports the helper so unused code stays out of the boot bundle.
|
|
42
|
+
* @returns A `Promise<void>` that resolves once the change (and optional transition) is applied. Callers may ignore the return.
|
|
37
43
|
*/
|
|
38
44
|
setColorMode: typeof setColorMode;
|
|
39
45
|
/**
|
|
40
46
|
* Toggle the dark mode
|
|
41
47
|
* @description Toggle the dark mode
|
|
48
|
+
* @param options.animate When `true`, wrap the toggle in a View Transition.
|
|
49
|
+
* @returns A `Promise<void>` that resolves once the change (and optional transition) is applied.
|
|
42
50
|
*/
|
|
43
51
|
toggleDarkMode: typeof toggleDarkMode;
|
|
44
52
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/composables/useTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,oBAAoB,EAAc,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"useTheme.d.ts","sourceRoot":"","sources":["../../src/composables/useTheme.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,eAAe,EAAE,oBAAoB,EAAc,MAAM,UAAU,CAAA;AAgCzG,iBAAe,WAAW,CAAC,MAAM,EAAE,WAAW,GAAG,oBAAoB,GAAG,eAAe,iBAmCtF;AAED,iBAAe,YAAY,CAAC,SAAS,EAAE,SAAS,EAAE,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAmBpG;AAED,iBAAS,cAAc,CAAC,OAAO,GAAE;IAAE,OAAO,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAE1E;AAiCD,wBAAgB,QAAQ;IAkBpB;;OAEG;;IAEH;;OAEG;;IAEH;;;OAGG;;IAEH;;OAEG;;IAEH;;OAEG;;IAEH;;;;OAIG;wBACiB,WAAW,GAAG,oBAAoB,GAAG,eAAe,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC;IAGzG;;;;;;OAMG;;IAEH;;;;;OAKG;;IAEH;;;OAGG;;IAEH;;;OAGG;;IAEH;;OAEG;;EAGN"}
|
|
@@ -1 +1,95 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { getSavedPreset, savePreset } from "../utils/cookie-storage.js";
|
|
2
|
+
import { CSS_ID, generateCSS, injectCSS } from "../utils/css-generator.js";
|
|
3
|
+
import { getPreset } from "../utils/get-preset.js";
|
|
4
|
+
import { noTransition } from "../utils/no-transition.js";
|
|
5
|
+
import { mergePresets } from "../utils/preset-merger.js";
|
|
6
|
+
import { getSystemColorMode, saveResolvedColorMode } from "../utils/get-color-mode.js";
|
|
7
|
+
import { isServer } from "@maz-ui/utils/helpers/isServer";
|
|
8
|
+
import { setCookie } from "@maz-ui/utils/helpers/cookie";
|
|
9
|
+
import { computed, getCurrentInstance, inject, ref, watch } from "vue";
|
|
10
|
+
//#region src/composables/useTheme.ts
|
|
11
|
+
var themeState = ref();
|
|
12
|
+
var colorMode = computed({
|
|
13
|
+
get: () => themeState.value?.colorMode,
|
|
14
|
+
set: (mode) => void setColorMode(mode)
|
|
15
|
+
});
|
|
16
|
+
var isDark = computed(() => themeState.value?.isDark || !1);
|
|
17
|
+
var strategy = computed(() => themeState.value?.strategy);
|
|
18
|
+
var mode = computed(() => themeState.value?.mode);
|
|
19
|
+
var darkModeStrategy = computed(() => themeState.value?.darkModeStrategy);
|
|
20
|
+
var preset = computed(() => themeState.value?.preset);
|
|
21
|
+
var presetName = computed(() => preset.value?.name);
|
|
22
|
+
async function updateTheme(preset) {
|
|
23
|
+
if (!themeState.value) return;
|
|
24
|
+
let _preset = typeof preset == "string" ? await getPreset(preset) : preset;
|
|
25
|
+
if (!_preset || !themeState.value.preset) {
|
|
26
|
+
console.error("[@maz-ui/themes] No preset found — with buildtime strategy you must pass a full preset");
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
let newPreset = "name" in _preset && _preset.name !== themeState.value.preset.name ? _preset : mergePresets(themeState.value.preset, _preset);
|
|
30
|
+
if (themeState.value.preset = newPreset, themeState.value.persistPreset) {
|
|
31
|
+
let base = getSavedPreset()?.base ?? newPreset.name;
|
|
32
|
+
savePreset(base, newPreset.name);
|
|
33
|
+
}
|
|
34
|
+
if (themeState.value.strategy === "runtime") {
|
|
35
|
+
let fullCSS = generateCSS(newPreset, {
|
|
36
|
+
mode: themeState.value.mode,
|
|
37
|
+
darkSelectorStrategy: themeState.value.darkModeStrategy,
|
|
38
|
+
prefix: "maz",
|
|
39
|
+
darkClass: themeState.value.darkClass,
|
|
40
|
+
lightClass: themeState.value.lightClass
|
|
41
|
+
});
|
|
42
|
+
injectCSS(CSS_ID, fullCSS);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async function setColorMode(colorMode, options = {}) {
|
|
46
|
+
if (!themeState.value) return;
|
|
47
|
+
let apply = () => {
|
|
48
|
+
themeState.value.colorMode = colorMode, setCookie("maz-color-mode", colorMode), colorMode === "auto" && saveResolvedColorMode(getSystemColorMode() === "dark" ? "dark" : "light");
|
|
49
|
+
};
|
|
50
|
+
if (options.animate) {
|
|
51
|
+
let { runViewTransition } = await import("../utils/view-transition.js");
|
|
52
|
+
await runViewTransition(apply);
|
|
53
|
+
} else apply();
|
|
54
|
+
}
|
|
55
|
+
function toggleDarkMode(options = {}) {
|
|
56
|
+
return setColorMode(isDark.value ? "light" : "dark", options);
|
|
57
|
+
}
|
|
58
|
+
var stopInjectedWatch;
|
|
59
|
+
function setThemeStateFromGlobalProperties() {
|
|
60
|
+
themeState.value = void 0, stopInjectedWatch?.(), stopInjectedWatch = void 0;
|
|
61
|
+
try {
|
|
62
|
+
let injectedState = inject("mazThemeState", void 0);
|
|
63
|
+
if (themeState.value = injectedState?.value, injectedState && (stopInjectedWatch = watch(injectedState, (newState) => {
|
|
64
|
+
newState && (themeState.value = newState);
|
|
65
|
+
}, { deep: !0 })), !themeState.value) throw Error("mazThemeState not found");
|
|
66
|
+
} catch {
|
|
67
|
+
let instance = getCurrentInstance();
|
|
68
|
+
instance?.appContext?.app?.config?.globalProperties && (themeState.value = instance.appContext.app.config.globalProperties.$mazThemeState.value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function useTheme() {
|
|
72
|
+
isServer() && (themeState.value = void 0);
|
|
73
|
+
try {
|
|
74
|
+
if (themeState.value || setThemeStateFromGlobalProperties(), !themeState.value) throw Error("[@maz-ui/themes] no theme state found");
|
|
75
|
+
} catch {
|
|
76
|
+
throw Error("[@maz-ui/themes] useTheme requires the MazUi/MazUiTheme plugin or a MazUiProvider wrapper");
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
preset,
|
|
80
|
+
presetName,
|
|
81
|
+
colorMode,
|
|
82
|
+
isDark,
|
|
83
|
+
strategy,
|
|
84
|
+
updateTheme(preset) {
|
|
85
|
+
return noTransition(updateTheme, preset);
|
|
86
|
+
},
|
|
87
|
+
setColorMode,
|
|
88
|
+
toggleDarkMode,
|
|
89
|
+
mode,
|
|
90
|
+
darkModeStrategy,
|
|
91
|
+
currentPreset: preset
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { useTheme };
|
package/dist/define-preset.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
import{getPreset}from"./utils/get-preset.js";
|
|
1
|
+
import { getPreset } from "./utils/get-preset.js";
|
|
2
|
+
import { mergePresets } from "./utils/preset-merger.js";
|
|
3
|
+
//#region src/define-preset.ts
|
|
4
|
+
function definePreset({ base = "maz-ui", overrides = {} }) {
|
|
5
|
+
return typeof base == "string" ? getPreset(base).then((basePreset) => mergePresets(basePreset, overrides)) : mergePresets(base, overrides);
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { definePreset };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,6 @@ export * from './define-preset';
|
|
|
4
4
|
export * from './plugin';
|
|
5
5
|
export * from './presets';
|
|
6
6
|
export * from './types';
|
|
7
|
-
export * from './utils/color-utils';
|
|
8
7
|
export * from './utils/css-generator';
|
|
9
8
|
export * from './utils/inject-theme-css';
|
|
10
9
|
export * from './utils/preset-merger';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,wBAAwB,CAAA;AACtC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA;AACvB,cAAc,uBAAuB,CAAA;AACrC,cAAc,0BAA0B,CAAA;AACxC,cAAc,uBAAuB,CAAA;AACrC,cAAc,qBAAqB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1,15 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import { CSS_ID, generateCSS, injectCSS, removeCSS } from "./utils/css-generator.js";
|
|
2
|
+
import { injectThemeCSS } from "./utils/inject-theme-css.js";
|
|
3
|
+
import { deepMerge, mergePresets } from "./utils/preset-merger.js";
|
|
4
|
+
import { defaultOptions, setupTheme } from "./utils/setup-theme.js";
|
|
5
|
+
import { MazUiTheme } from "./plugin.js";
|
|
6
|
+
import { definePreset } from "./define-preset.js";
|
|
7
|
+
import { pristine } from "./presets/pristine.js";
|
|
8
|
+
import { ocean } from "./presets/ocean.js";
|
|
9
|
+
import { obsidian } from "./presets/obsidian.js";
|
|
10
|
+
import { nova } from "./presets/nova.js";
|
|
11
|
+
import { mazUi } from "./presets/mazUi.js";
|
|
12
|
+
import { useTheme } from "./composables/useTheme.js";
|
|
13
|
+
import { buildSeparateThemeFiles, buildThemeCSS, createThemeStylesheet, generateThemeBundle } from "./build/index.js";
|
|
14
|
+
import "./presets/index.js";
|
|
15
|
+
export { CSS_ID, MazUiTheme, buildSeparateThemeFiles, buildThemeCSS, createThemeStylesheet, deepMerge, defaultOptions, definePreset, generateCSS, generateThemeBundle, injectCSS, injectThemeCSS, mazUi, mergePresets, nova, obsidian, ocean, pristine, removeCSS, setupTheme, useTheme };
|
package/dist/plugin.js
CHANGED
|
@@ -1 +1,12 @@
|
|
|
1
|
-
import{injectThemeState}from"./utils/inject.js";
|
|
1
|
+
import { injectThemeState } from "./utils/inject.js";
|
|
2
|
+
import { setupTheme } from "./utils/setup-theme.js";
|
|
3
|
+
//#region src/plugin.ts
|
|
4
|
+
var MazUiTheme = { install(app, options) {
|
|
5
|
+
let { themeState } = setupTheme(options);
|
|
6
|
+
injectThemeState({
|
|
7
|
+
app,
|
|
8
|
+
themeState
|
|
9
|
+
});
|
|
10
|
+
} };
|
|
11
|
+
//#endregion
|
|
12
|
+
export { MazUiTheme };
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import { ThemeComponentBg, ThemeFoundation, ThemeScales } from '../types';
|
|
1
|
+
import { RoundedScaleKey, ThemeComponentBg, ThemeComponents, ThemeFoundation, ThemeScales } from '../types';
|
|
2
2
|
/**
|
|
3
3
|
* Defaults shared across the bundled presets. Each preset can spread these
|
|
4
|
-
* and override the keys it cares about.
|
|
5
|
-
* —
|
|
4
|
+
* and override the keys it cares about. The bundled presets only declare
|
|
5
|
+
* `scales.rounded.md` — the other rounded keys are filled at CSS-generation
|
|
6
|
+
* time via `calc(var(--maz-rounded-md) * DEFAULT_ROUNDED_RATIOS[key])`. A
|
|
7
|
+
* preset (or user override) may still set any rounded key to a literal value
|
|
8
|
+
* to opt out of the calc fallback for that key.
|
|
6
9
|
*/
|
|
7
10
|
export declare const DEFAULT_SPACE: NonNullable<ThemeFoundation['space']>;
|
|
11
|
+
/**
|
|
12
|
+
* Multipliers used to derive the rounded scale from `md` when a key is not
|
|
13
|
+
* explicitly set. Anchored on `md = 1` (implicit). Picked to match the
|
|
14
|
+
* scale shared by `nova`, `obsidian` and `ocean`.
|
|
15
|
+
*/
|
|
16
|
+
export declare const DEFAULT_ROUNDED_RATIOS: Record<Exclude<RoundedScaleKey, 'md'>, number>;
|
|
8
17
|
export declare const DEFAULT_SHADOW: ThemeScales['shadow'];
|
|
9
18
|
export declare const DEFAULT_DISABLED_OPACITY = "0.5";
|
|
10
19
|
export declare const DEFAULT_DISABLED_CURSOR = "not-allowed";
|
|
@@ -19,15 +28,33 @@ export declare const DEFAULT_FONT_MONO = "ui-monospace, SFMono-Regular, Menlo, M
|
|
|
19
28
|
*/
|
|
20
29
|
export declare const DEFAULT_CONTAINER_BG: ThemeComponentBg;
|
|
21
30
|
/**
|
|
22
|
-
* Per-mode default bg for inputs. Light uses the bare `surface`; dark
|
|
23
|
-
*
|
|
24
|
-
* same contrast pattern the
|
|
31
|
+
* Per-mode default bg for inputs. Light uses the bare `surface`; dark
|
|
32
|
+
* derives one tier above the page background via relative OKLCh syntax
|
|
33
|
+
* (mirrors SCALE_OFFSETS step -400: l+0.06) — same contrast pattern the
|
|
34
|
+
* v4 components shipped with. Self-contained, no Tailwind dependency.
|
|
25
35
|
*/
|
|
26
36
|
export declare const DEFAULT_INPUT_BG: ThemeComponentBg;
|
|
37
|
+
/**
|
|
38
|
+
* Default font-weight used by the top-label in `.m-input` when the
|
|
39
|
+
* `top-label` prop is set. The value is '600' by default, allowing
|
|
40
|
+
* presets to easily increase or decrease it when needed.
|
|
41
|
+
*/
|
|
42
|
+
export declare const DEFAULT_INPUT_TOP_LABEL_FONT_WEIGHT = "600";
|
|
27
43
|
/**
|
|
28
44
|
* Default font weight used by `MazBtn` — medium (500). Presets can
|
|
29
45
|
* override via `components.btn.font-weight` to bias the button text
|
|
30
46
|
* heavier or lighter for their visual identity.
|
|
31
47
|
*/
|
|
32
48
|
export declare const DEFAULT_BTN_FONT_WEIGHT = "500";
|
|
49
|
+
/**
|
|
50
|
+
* Default `max-width` / `min-width` for `MazDialog` on tablet and up.
|
|
51
|
+
* Anchored on a 14px `base-font-size` (38rem ≈ 532px, 32rem ≈ 448px).
|
|
52
|
+
* Presets with a different `base-font-size` (e.g. ocean at 16px) should
|
|
53
|
+
* scale these in rem to keep the rendered pixel width consistent.
|
|
54
|
+
* Consumed by the component via `var(--maz-dialog-max-width, 38rem)` /
|
|
55
|
+
* `var(--maz-dialog-min-width, 32rem)`, and still overridable per-instance
|
|
56
|
+
* through the `max-width` / `min-width` props.
|
|
57
|
+
*/
|
|
58
|
+
export declare const DEFAULT_DIALOG_MAX_WIDTH: NonNullable<ThemeComponents['dialog']>['max-width'];
|
|
59
|
+
export declare const DEFAULT_DIALOG_MIN_WIDTH: NonNullable<ThemeComponents['dialog']>['min-width'];
|
|
33
60
|
//# sourceMappingURL=_defaults.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_defaults.d.ts","sourceRoot":"","sources":["../../src/presets/_defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"_defaults.d.ts","sourceRoot":"","sources":["../../src/presets/_defaults.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAEhH;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,eAAe,CAAC,OAAO,CAAC,CAAa,CAAA;AAE7E;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,EAAE,MAAM,CAAC,OAAO,CAAC,eAAe,EAAE,IAAI,CAAC,EAAE,MAAM,CAOjF,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,QAAQ,CAMhD,CAAA;AAED,eAAO,MAAM,wBAAwB,QAAQ,CAAA;AAC7C,eAAO,MAAM,uBAAuB,gBAAgB,CAAA;AAEpD;;GAEG;AACH,eAAO,MAAM,iBAAiB,uGAC0E,CAAA;AAExG;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,gBAGlC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBAG9B,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,mCAAmC,QAAQ,CAAA;AAExD;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,QAAQ,CAAA;AAE5C;;;;;;;;GAQG;AACH,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAW,CAAA;AACpG,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAW,CAAA"}
|
|
@@ -1 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/presets/_defaults.ts
|
|
2
|
+
var DEFAULT_SPACE = "0.25rem";
|
|
3
|
+
var DEFAULT_ROUNDED_RATIOS = {
|
|
4
|
+
xs: .25,
|
|
5
|
+
sm: .5,
|
|
6
|
+
lg: 1.5,
|
|
7
|
+
xl: 2,
|
|
8
|
+
"2xl": 3,
|
|
9
|
+
"3xl": 4
|
|
10
|
+
};
|
|
11
|
+
var DEFAULT_SHADOW = {
|
|
12
|
+
sm: "0 1px 2px 0 rgb(0 0 0 / 0.05)",
|
|
13
|
+
md: "0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)",
|
|
14
|
+
lg: "0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)",
|
|
15
|
+
xl: "0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1)",
|
|
16
|
+
elevation: "0 4px 12px -2px rgb(0 0 0 / 0.08), 0 2px 4px -1px rgb(0 0 0 / 0.06)"
|
|
17
|
+
};
|
|
18
|
+
var DEFAULT_DISABLED_OPACITY = "0.5";
|
|
19
|
+
var DEFAULT_DISABLED_CURSOR = "not-allowed";
|
|
20
|
+
var DEFAULT_FONT_MONO = "ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace";
|
|
21
|
+
var DEFAULT_CONTAINER_BG = {
|
|
22
|
+
light: "var(--maz-surface)",
|
|
23
|
+
dark: "var(--maz-surface)"
|
|
24
|
+
};
|
|
25
|
+
var DEFAULT_INPUT_BG = {
|
|
26
|
+
light: "var(--maz-surface)",
|
|
27
|
+
dark: "oklch(from var(--maz-surface) clamp(0, calc(l + 0.06), 1) c h)"
|
|
28
|
+
};
|
|
29
|
+
var DEFAULT_INPUT_TOP_LABEL_FONT_WEIGHT = "600";
|
|
30
|
+
var DEFAULT_BTN_FONT_WEIGHT = "500";
|
|
31
|
+
var DEFAULT_DIALOG_MAX_WIDTH = "38rem";
|
|
32
|
+
var DEFAULT_DIALOG_MIN_WIDTH = "32rem";
|
|
33
|
+
//#endregion
|
|
34
|
+
export { DEFAULT_BTN_FONT_WEIGHT, DEFAULT_CONTAINER_BG, DEFAULT_DIALOG_MAX_WIDTH, DEFAULT_DIALOG_MIN_WIDTH, DEFAULT_DISABLED_CURSOR, DEFAULT_DISABLED_OPACITY, DEFAULT_FONT_MONO, DEFAULT_INPUT_BG, DEFAULT_INPUT_TOP_LABEL_FONT_WEIGHT, DEFAULT_ROUNDED_RATIOS, DEFAULT_SHADOW, DEFAULT_SPACE };
|
package/dist/presets/index.js
CHANGED
|
@@ -1 +1,6 @@
|
|
|
1
|
-
import{pristine}from"./pristine.js";
|
|
1
|
+
import { pristine } from "./pristine.js";
|
|
2
|
+
import { ocean } from "./ocean.js";
|
|
3
|
+
import { obsidian } from "./obsidian.js";
|
|
4
|
+
import { nova } from "./nova.js";
|
|
5
|
+
import { mazUi } from "./mazUi.js";
|
|
6
|
+
export { mazUi, nova, obsidian, ocean, pristine };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mazUi.d.ts","sourceRoot":"","sources":["../../src/presets/mazUi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"mazUi.d.ts","sourceRoot":"","sources":["../../src/presets/mazUi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAiB3C,eAAO,MAAM,KAAK,EAAE,WA8EnB,CAAA"}
|