@varlet/cli 2.16.0-alpha.1693855048345 → 2.16.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/lib/client/index.d.ts +2 -2
- package/lib/client/index.js +3 -20
- package/package.json +9 -8
- package/site/mobile/App.vue +5 -6
- package/site/utils.ts +2 -2
package/lib/client/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import AppType from './appType';
|
|
2
|
+
import { StyleProvider } from '@varlet/ui';
|
|
2
3
|
interface PCLocationInfo {
|
|
3
4
|
language: string;
|
|
4
5
|
menuName: string;
|
|
@@ -6,7 +7,6 @@ interface PCLocationInfo {
|
|
|
6
7
|
}
|
|
7
8
|
export type Theme = 'lightTheme' | 'darkTheme';
|
|
8
9
|
export type StyleVars = Record<string, string>;
|
|
9
|
-
export declare function StyleProvider(styleVars?: StyleVars | null): void;
|
|
10
10
|
export declare function getPCLocationInfo(): PCLocationInfo;
|
|
11
11
|
export declare function getBrowserTheme(): Theme;
|
|
12
12
|
export declare function watchLang(cb: (lang: string) => void, platform?: 'pc' | 'mobile'): void;
|
|
@@ -16,4 +16,4 @@ export declare function useRouteListener(cb: () => void): void;
|
|
|
16
16
|
export declare function watchDarkMode(dark: StyleVars, cb?: (theme: Theme) => void): void;
|
|
17
17
|
export declare function setColorScheme(theme: Theme): void;
|
|
18
18
|
export declare function watchTheme(cb: (theme: Theme, from: 'pc' | 'mobile' | 'default' | 'playground') => void, shouldUnmount?: boolean): void;
|
|
19
|
-
export { AppType };
|
|
19
|
+
export { AppType, StyleProvider };
|
package/lib/client/index.js
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
import config from '@config';
|
|
2
2
|
import AppType from './appType';
|
|
3
|
+
import { Themes, StyleProvider } from '@varlet/ui';
|
|
3
4
|
import { onMounted, onUnmounted } from 'vue';
|
|
4
|
-
import { kebabCase } from '@varlet/shared';
|
|
5
5
|
import { get } from 'lodash-es';
|
|
6
|
-
const mountedVarKeys = [];
|
|
7
|
-
function formatStyleVars(styleVars) {
|
|
8
|
-
return Object.entries(styleVars !== null && styleVars !== void 0 ? styleVars : {}).reduce((styles, [key, value]) => {
|
|
9
|
-
const cssVar = key.startsWith('--') ? key : `--${kebabCase(key)}`;
|
|
10
|
-
styles[cssVar] = value;
|
|
11
|
-
return styles;
|
|
12
|
-
}, {});
|
|
13
|
-
}
|
|
14
|
-
export function StyleProvider(styleVars = {}) {
|
|
15
|
-
mountedVarKeys.forEach((key) => document.documentElement.style.removeProperty(key));
|
|
16
|
-
mountedVarKeys.length = 0;
|
|
17
|
-
const styles = formatStyleVars(styleVars);
|
|
18
|
-
Object.entries(styles).forEach(([key, value]) => {
|
|
19
|
-
document.documentElement.style.setProperty(key, value);
|
|
20
|
-
mountedVarKeys.push(key);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
6
|
export function getPCLocationInfo() {
|
|
24
7
|
var _a;
|
|
25
8
|
const [, language, path] = window.location.hash.split('/');
|
|
@@ -87,7 +70,7 @@ export function useRouteListener(cb) {
|
|
|
87
70
|
export function watchDarkMode(dark, cb) {
|
|
88
71
|
watchTheme((theme) => {
|
|
89
72
|
const siteStyleVars = withSiteConfigNamespace(get(config, theme, {}));
|
|
90
|
-
const darkStyleVars = Object.assign(Object.assign({}, siteStyleVars), dark);
|
|
73
|
+
const darkStyleVars = Object.assign(Object.assign(Object.assign({}, siteStyleVars), Themes.dark), dark);
|
|
91
74
|
StyleProvider(theme === 'darkTheme' ? darkStyleVars : siteStyleVars);
|
|
92
75
|
setColorScheme(theme);
|
|
93
76
|
cb === null || cb === void 0 ? void 0 : cb(theme);
|
|
@@ -111,4 +94,4 @@ export function watchTheme(cb, shouldUnmount = true) {
|
|
|
111
94
|
}
|
|
112
95
|
cb(getBrowserTheme(), 'default');
|
|
113
96
|
}
|
|
114
|
-
export { AppType };
|
|
97
|
+
export { AppType, StyleProvider };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@varlet/cli",
|
|
3
|
-
"version": "2.16.0
|
|
3
|
+
"version": "2.16.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "cli of varlet",
|
|
6
6
|
"bin": {
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"vite": "4.3.5",
|
|
68
68
|
"vue": "3.3.4",
|
|
69
69
|
"webfont": "^9.0.0",
|
|
70
|
-
"@varlet/shared": "2.16.0
|
|
71
|
-
"@varlet/vite-plugins": "2.16.0
|
|
70
|
+
"@varlet/shared": "2.16.0",
|
|
71
|
+
"@varlet/vite-plugins": "2.16.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"@types/babel__core": "^7.20.1",
|
|
@@ -83,9 +83,9 @@
|
|
|
83
83
|
"@types/semver": "^7.3.9",
|
|
84
84
|
"@types/sharp": "0.31.1",
|
|
85
85
|
"rimraf": "^5.0.1",
|
|
86
|
-
"@varlet/
|
|
87
|
-
"@varlet/
|
|
88
|
-
"@varlet/touch-emulator": "2.16.0
|
|
86
|
+
"@varlet/ui": "2.16.0",
|
|
87
|
+
"@varlet/icons": "2.16.0",
|
|
88
|
+
"@varlet/touch-emulator": "2.16.0"
|
|
89
89
|
},
|
|
90
90
|
"peerDependencies": {
|
|
91
91
|
"@vue/runtime-core": "3.3.4",
|
|
@@ -98,8 +98,9 @@
|
|
|
98
98
|
"lodash-es": "^4.17.21",
|
|
99
99
|
"vue": "3.3.4",
|
|
100
100
|
"vue-router": "4.2.0",
|
|
101
|
-
"@varlet/icons": "2.16.0
|
|
102
|
-
"@varlet/touch-emulator": "2.16.0
|
|
101
|
+
"@varlet/icons": "2.16.0",
|
|
102
|
+
"@varlet/touch-emulator": "2.16.0",
|
|
103
|
+
"@varlet/ui": "2.16.0"
|
|
103
104
|
},
|
|
104
105
|
"scripts": {
|
|
105
106
|
"dev": "tsc --watch",
|
package/site/mobile/App.vue
CHANGED
|
@@ -149,16 +149,15 @@ export default defineComponent({
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
const toggleTheme = () => {
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
setCurrentTheme(currentTheme.value === 'darkTheme' ? 'lightTheme' : 'darkTheme')
|
|
153
|
+
window.postMessage(getThemeMessage(), '*')
|
|
154
154
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
155
|
+
if (!isPhone() && inIframe()) {
|
|
156
|
+
;(window.top as any).postMessage(getThemeMessage(), '*')
|
|
158
157
|
}
|
|
158
|
+
}
|
|
159
159
|
|
|
160
160
|
;(window as any).toggleTheme = toggleTheme
|
|
161
|
-
|
|
162
161
|
setTheme(config, currentTheme.value)
|
|
163
162
|
window.postMessage(getThemeMessage(), '*')
|
|
164
163
|
|
package/site/utils.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { get } from 'lodash-es'
|
|
2
|
+
import { Themes } from '@varlet/ui'
|
|
2
3
|
import { StyleProvider, type Theme, withSiteConfigNamespace, setColorScheme } from '@varlet/cli/client'
|
|
3
4
|
|
|
4
5
|
export interface Menu {
|
|
@@ -32,8 +33,7 @@ export function inIframe() {
|
|
|
32
33
|
|
|
33
34
|
export function setTheme(config: Record<string, any>, theme: Theme) {
|
|
34
35
|
const styleVars = withSiteConfigNamespace(get(config, theme, {}))
|
|
35
|
-
|
|
36
|
-
StyleProvider(styleVars)
|
|
36
|
+
StyleProvider({ ...styleVars, ...(theme === 'darkTheme' ? Themes.dark : {}) })
|
|
37
37
|
setColorScheme(theme)
|
|
38
38
|
}
|
|
39
39
|
|