vue3-router-tab 1.1.1 → 1.1.3
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 +30 -0
- package/dist/vue3-router-tab.css +1 -1
- package/dist/vue3-router-tab.js +298 -263
- package/dist/vue3-router-tab.umd.cjs +1 -1
- package/index.d.ts +102 -0
- package/lib/components/RouterTab.vue +8 -4
- package/lib/index.ts +27 -3
- package/lib/persistence.ts +3 -1
- package/lib/scss/index.scss +108 -137
- package/lib/theme.ts +75 -0
- package/package.json +1 -3
package/lib/theme.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const STYLE_KEY = 'tab-theme-style'
|
|
2
|
+
const PRIMARY_KEY = 'tab-theme-primary-color'
|
|
3
|
+
const DEFAULT_STYLE: 'light' | 'dark' | 'system' = 'system'
|
|
4
|
+
const DEFAULT_PRIMARY = '#635bff'
|
|
5
|
+
const MEDIA_QUERY = '(prefers-color-scheme: dark)'
|
|
6
|
+
|
|
7
|
+
let mediaListener: ((event: MediaQueryListEvent) => void) | null = null
|
|
8
|
+
|
|
9
|
+
export interface RouterTabsThemeOptions {
|
|
10
|
+
styleKey?: string
|
|
11
|
+
primaryKey?: string
|
|
12
|
+
defaultStyle?: 'light' | 'dark' | 'system'
|
|
13
|
+
defaultPrimary?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function applyPrimary(color: string) {
|
|
17
|
+
if (typeof document === 'undefined') return
|
|
18
|
+
document.documentElement.style.setProperty('--theme-primary', color)
|
|
19
|
+
document.documentElement.style.setProperty('--router-tab-primary', color)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function applyStyle(style: 'light' | 'dark' | 'system') {
|
|
23
|
+
if (typeof document === 'undefined') return
|
|
24
|
+
|
|
25
|
+
const root = document.documentElement
|
|
26
|
+
const media = window.matchMedia(MEDIA_QUERY)
|
|
27
|
+
|
|
28
|
+
const updateFromSystem = () => {
|
|
29
|
+
root.dataset.theme = media.matches ? 'dark' : 'light'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (mediaListener) {
|
|
33
|
+
media.removeEventListener('change', mediaListener)
|
|
34
|
+
mediaListener = null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (style === 'system') {
|
|
38
|
+
updateFromSystem()
|
|
39
|
+
mediaListener = () => updateFromSystem()
|
|
40
|
+
media.addEventListener('change', mediaListener)
|
|
41
|
+
} else {
|
|
42
|
+
root.dataset.theme = style
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function initRouterTabsTheme(options: RouterTabsThemeOptions = {}) {
|
|
47
|
+
if (typeof window === 'undefined') return
|
|
48
|
+
|
|
49
|
+
const {
|
|
50
|
+
styleKey = STYLE_KEY,
|
|
51
|
+
primaryKey = PRIMARY_KEY,
|
|
52
|
+
defaultStyle = DEFAULT_STYLE,
|
|
53
|
+
defaultPrimary = DEFAULT_PRIMARY
|
|
54
|
+
} = options
|
|
55
|
+
|
|
56
|
+
const storedStyle = (window.localStorage.getItem(styleKey) as 'light' | 'dark' | 'system' | null) ?? defaultStyle
|
|
57
|
+
const storedPrimary = window.localStorage.getItem(primaryKey) ?? defaultPrimary
|
|
58
|
+
|
|
59
|
+
applyStyle(storedStyle)
|
|
60
|
+
applyPrimary(storedPrimary)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function setRouterTabsTheme(style: 'light' | 'dark' | 'system', options?: RouterTabsThemeOptions) {
|
|
64
|
+
if (typeof window === 'undefined') return
|
|
65
|
+
const key = options?.styleKey ?? STYLE_KEY
|
|
66
|
+
window.localStorage.setItem(key, style)
|
|
67
|
+
applyStyle(style)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function setRouterTabsPrimary(color: string, options?: RouterTabsThemeOptions) {
|
|
71
|
+
if (typeof window === 'undefined') return
|
|
72
|
+
const key = options?.primaryKey ?? PRIMARY_KEY
|
|
73
|
+
window.localStorage.setItem(key, color)
|
|
74
|
+
applyPrimary(color)
|
|
75
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue3-router-tab",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist",
|
|
@@ -24,7 +24,6 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@vitejs/plugin-vue": "^6.0.1",
|
|
27
|
-
"pinia": "^3.0.3",
|
|
28
27
|
"sass": "^1.93.2",
|
|
29
28
|
"sass-loader": "^16.0.5",
|
|
30
29
|
"typescript": "^5.9.2",
|
|
@@ -65,7 +64,6 @@
|
|
|
65
64
|
]
|
|
66
65
|
},
|
|
67
66
|
"peerDependencies": {
|
|
68
|
-
"pinia": "^2.1.7",
|
|
69
67
|
"vue": "^3.3.0",
|
|
70
68
|
"vue-router": "^4.2.0"
|
|
71
69
|
}
|