@bndynet/vue-site 0.1.0 → 0.1.1
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 +5 -1
- package/dist/composables/useTheme.d.ts +6 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +7632 -7624
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -109,12 +109,14 @@ import config from './site.config'
|
|
|
109
109
|
createSiteApp(config).mount('#app')
|
|
110
110
|
```
|
|
111
111
|
|
|
112
|
-
Exports: `createSiteApp`, `defineConfig`, `useTheme`, `useSiteConfig`. Types: `SiteConfig`, `SiteEnvConfig`, `SiteViteConfig`, `SiteExternalLink`, `NavItem`, `ThemeConfig`, `ThemeOption`, `ThemePaletteVars`, `ResolvedNavItem`.
|
|
112
|
+
Exports: `createSiteApp`, `defineConfig`, `useTheme`, `useSiteConfig`, `themeRefKey`. Types: `SiteConfig`, `SiteEnvConfig`, `SiteViteConfig`, `SiteExternalLink`, `NavItem`, `ThemeConfig`, `ThemeOption`, `ThemePaletteVars`, `ResolvedNavItem`.
|
|
113
113
|
|
|
114
114
|
### Theme in Vue pages (`useTheme`)
|
|
115
115
|
|
|
116
116
|
Import `useTheme` from `@bndynet/vue-site`. It returns a reactive `theme` ref (the active theme id, e.g. `light`, `dark`, or an `extraThemes[].id`) plus `setTheme` and `toggleTheme`. The root layout also sets `document.documentElement` attribute `data-theme` and applies CSS variables, so you can style with `var(--color-*)` without JavaScript.
|
|
117
117
|
|
|
118
|
+
The theme ref is **provided** by `createSiteApp()` (same Vue runtime as your app), so `watch(theme, …)` works reliably even when another tool would otherwise load a second copy of `vue` from nested `node_modules`.
|
|
119
|
+
|
|
118
120
|
```vue
|
|
119
121
|
<script setup lang="ts">
|
|
120
122
|
import { watch } from 'vue'
|
|
@@ -132,6 +134,8 @@ watch(theme, (next, prev) => {
|
|
|
132
134
|
</template>
|
|
133
135
|
```
|
|
134
136
|
|
|
137
|
+
`watch` only runs when the theme **changes** after your component is set up (for example after the user clicks the theme control). It does not run on the initial value unless you pass `{ immediate: true }`.
|
|
138
|
+
|
|
135
139
|
## Upgrade
|
|
136
140
|
|
|
137
141
|
```bash
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
import { InjectionKey, Ref } from 'vue';
|
|
2
|
+
/** Use `Symbol.for` so the key matches even if multiple copies of this package are resolved. */
|
|
3
|
+
export declare const themeRefKey: InjectionKey<Ref<string>>;
|
|
1
4
|
/**
|
|
5
|
+
* @param themeRef — ref created next to `createApp` so it uses the same Vue runtime as the app (fixes `watch(theme)` when npm/Vite dedupes `vue` imperfectly).
|
|
2
6
|
* @param defaultMode — used when nothing valid is in localStorage
|
|
3
7
|
* @param themeIds — full list of allowed ids (built-in `light`/`dark` plus any `extraThemes`)
|
|
4
8
|
* @param palettes — resolved CSS variable maps per id
|
|
5
9
|
* @param overlay — optional `:root` overrides applied after the active palette
|
|
6
10
|
*/
|
|
7
|
-
export declare function initTheme(defaultMode?: string, themeIds?: readonly string[], palettes?: Record<string, Record<string, string>>, overlay?: Record<string, string>): void;
|
|
11
|
+
export declare function initTheme(themeRef: Ref<string>, defaultMode?: string, themeIds?: readonly string[], palettes?: Record<string, Record<string, string>>, overlay?: Record<string, string>): void;
|
|
8
12
|
export declare function useTheme(): {
|
|
9
|
-
theme:
|
|
13
|
+
theme: Ref<string, string>;
|
|
10
14
|
setTheme: (mode: string) => void;
|
|
11
15
|
toggleTheme: () => void;
|
|
12
16
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SiteConfig } from './types';
|
|
2
2
|
export { createSiteApp } from './create-app';
|
|
3
|
-
export { useTheme } from './composables/useTheme';
|
|
3
|
+
export { useTheme, themeRefKey } from './composables/useTheme';
|
|
4
4
|
export { useSiteConfig } from './composables/useSiteConfig';
|
|
5
5
|
export { builtinThemePalettes } from './theme/presets';
|
|
6
6
|
export type { SiteConfig, SiteEnvConfig, SiteViteConfig, SiteExternalLink, NavItem, ThemeConfig, ThemeOption, ThemePaletteVars, ResolvedNavItem, } from './types';
|