@varlet/cli 2.22.3 → 3.0.0-alpha.1707916363117

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.
Files changed (32) hide show
  1. package/README.md +30 -18
  2. package/README.zh-CN.md +16 -4
  3. package/lib/client/index.d.ts +3 -2
  4. package/lib/client/index.js +20 -11
  5. package/lib/node/bin.js +7 -0
  6. package/lib/node/commands/styleVars.d.ts +1 -0
  7. package/lib/node/commands/styleVars.js +6 -0
  8. package/lib/node/config/varlet.config.d.ts +4 -0
  9. package/lib/node/config/varlet.default.config.js +121 -9
  10. package/lib/node/index.d.ts +1 -0
  11. package/lib/node/index.js +1 -0
  12. package/package.json +9 -9
  13. package/site/mobile/App.vue +63 -23
  14. package/site/pc/Layout.vue +7 -1
  15. package/site/pc/components/AppHeader.vue +78 -35
  16. package/site/pc/components/code-example/CodeExample.vue +1 -1
  17. package/site/pc/components/code-example/codeExample.less +1 -1
  18. package/site/pc/pages/index/index.vue +10 -9
  19. package/site/utils.ts +0 -6
  20. package/template/create/example/locale/_index.ts +4 -4
  21. package/template/create/example/locale/index.ts +4 -4
  22. package/template/generators/config/i18n/base/types/locale.d.ts +14 -10
  23. package/template/generators/config/i18n/sfc/src/button/example/BasicUse.vue +2 -2
  24. package/template/generators/config/i18n/sfc/src/button/example/ModifyColor.vue +2 -2
  25. package/template/generators/config/i18n/sfc/src/button/example/index.vue +5 -5
  26. package/template/generators/config/i18n/sfc/src/button/example/locale/index.ts +4 -4
  27. package/template/generators/config/i18n/sfc/src/locale/index.ts +31 -21
  28. package/template/generators/config/i18n/tsx/src/button/example/BasicUse.vue +2 -2
  29. package/template/generators/config/i18n/tsx/src/button/example/ModifyColor.vue +2 -2
  30. package/template/generators/config/i18n/tsx/src/button/example/index.vue +5 -5
  31. package/template/generators/config/i18n/tsx/src/button/example/locale/index.ts +4 -4
  32. package/template/generators/config/i18n/tsx/src/locale/index.ts +33 -21
@@ -20,22 +20,15 @@
20
20
  </template>
21
21
  <template #right>
22
22
  <var-button
23
- v-if="darkMode"
23
+ v-if="themes.length > 1"
24
+ class="theme-button"
24
25
  text
25
- round
26
26
  color="transparent"
27
27
  text-color="#fff"
28
- :style="{
29
- transform: languages ? 'translateX(-4px)' : 'translateX(-6px)',
30
- }"
31
- @click="toggleTheme"
28
+ @click.stop="showThemeMenu = true"
32
29
  >
33
- <var-icon
34
- class="theme"
35
- color="#fff"
36
- :size="24"
37
- :name="currentTheme === 'lightTheme' ? 'white-balance-sunny' : 'weather-night'"
38
- />
30
+ <var-icon name="palette" :size="28" class="palette"/>
31
+ <var-icon name="chevron-down" class="arrow-down"/>
39
32
  </var-button>
40
33
  <var-button
41
34
  v-if="languages"
@@ -69,6 +62,21 @@
69
62
  </var-cell>
70
63
  </div>
71
64
  </transition>
65
+
66
+ <transition name="site-menu">
67
+ <div class="theme-settings var-elevation--3" v-if="showThemeMenu">
68
+ <var-cell
69
+ v-for="t in themes"
70
+ :key="t.value"
71
+ class="mobile-theme-cell"
72
+ :class="[currentTheme === t.value && 'mobile-theme-cell--active']"
73
+ v-ripple
74
+ @click="toggleTheme(t.value)"
75
+ >
76
+ {{ t[language] }}
77
+ </var-cell>
78
+ </div>
79
+ </transition>
72
80
  </div>
73
81
  </template>
74
82
 
@@ -78,11 +86,12 @@ import { computed, defineComponent, ref, watch, type Ref, type ComputedRef } fr
78
86
  import { useRoute } from 'vue-router'
79
87
  import {
80
88
  getBrowserTheme,
81
- type Theme,
82
89
  watchLang,
83
- watchTheme
90
+ watchTheme,
91
+ setTheme,
92
+ type Theme,
84
93
  } from '@varlet/cli/client'
85
- import { removeEmpty, setTheme, inIframe, isPhone } from '../utils'
94
+ import { removeEmpty, inIframe, isPhone } from '../utils'
86
95
  import { bigCamelize } from '@varlet/shared'
87
96
  import { get } from 'lodash-es'
88
97
 
@@ -92,8 +101,10 @@ export default defineComponent({
92
101
  const route = useRoute()
93
102
  const showBackIcon: Ref<boolean> = ref(false)
94
103
  const showMenu: Ref<boolean> = ref(false)
104
+ const showThemeMenu: Ref<boolean> = ref(false)
95
105
  const language: Ref<string> = ref('')
96
106
  const languages: Ref<Record<string, string>> = ref(get(config, 'mobile.header.i18n'))
107
+ const themes: Ref<Record<string, any>[]> = ref(get(config, 'mobile.header.themes'))
97
108
  const nonEmptyLanguages: ComputedRef<Record<string, string>> = computed(() => removeEmpty(languages.value))
98
109
  const redirect = get(config, 'mobile.redirect', '')
99
110
  const github: Ref<string> = ref(get(config, 'mobile.header.github'))
@@ -144,13 +155,14 @@ export default defineComponent({
144
155
 
145
156
  const setCurrentTheme = (theme: Theme) => {
146
157
  currentTheme.value = theme
147
- setTheme(config, currentTheme.value)
158
+ setTheme(currentTheme.value)
148
159
  window.localStorage.setItem(get(config, 'themeKey'), currentTheme.value)
149
160
  }
150
161
 
151
- const toggleTheme = () => {
152
- setCurrentTheme(currentTheme.value === 'darkTheme' ? 'lightTheme' : 'darkTheme')
162
+ const toggleTheme = (value: Theme) => {
163
+ setCurrentTheme(value)
153
164
  window.postMessage(getThemeMessage(), '*')
165
+ showThemeMenu.value = false
154
166
 
155
167
  if (!isPhone() && inIframe()) {
156
168
  ;(window.top as any).postMessage(getThemeMessage(), '*')
@@ -158,11 +170,12 @@ export default defineComponent({
158
170
  }
159
171
 
160
172
  ;(window as any).toggleTheme = toggleTheme
161
- setTheme(config, currentTheme.value)
173
+ setTheme(currentTheme.value)
162
174
  window.postMessage(getThemeMessage(), '*')
163
175
 
164
176
  document.body.addEventListener('click', () => {
165
177
  showMenu.value = false
178
+ showThemeMenu.value = false
166
179
  })
167
180
 
168
181
  watchTheme((theme, from) => {
@@ -175,6 +188,7 @@ export default defineComponent({
175
188
  github,
176
189
  showMenu,
177
190
  languages,
191
+ themes,
178
192
  language,
179
193
  nonEmptyLanguages,
180
194
  currentTheme,
@@ -183,6 +197,7 @@ export default defineComponent({
183
197
  back,
184
198
  changeLanguage,
185
199
  toggleTheme,
200
+ showThemeMenu,
186
201
  }
187
202
  },
188
203
  })
@@ -197,11 +212,11 @@ export default defineComponent({
197
212
  body {
198
213
  margin: 0;
199
214
  padding: 0;
200
- min-height: 100%;
215
+ min-height: 100vh;
201
216
  font-size: 16px;
202
217
  font-family: 'Roboto', sans-serif;
203
218
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
204
- background: var(--site-config-color-bar);
219
+ background: var(--site-config-color-mobile-body);
205
220
  color: var(--site-config-color-text);
206
221
  transition: background-color 0.25s, color 0.25s;
207
222
  }
@@ -248,6 +263,14 @@ header {
248
263
  background: var(--site-config-color-bar);
249
264
  }
250
265
 
266
+ .theme-settings {
267
+ position: fixed;
268
+ z-index: 200;
269
+ top: 48px;
270
+ right: 68px;
271
+ background: var(--site-config-color-bar);
272
+ }
273
+
251
274
  .router-view__block {
252
275
  padding: 55px 15px 15px;
253
276
  }
@@ -263,6 +286,17 @@ header {
263
286
  }
264
287
  }
265
288
 
289
+ .mobile-theme-cell {
290
+ color: var(--site-config-color-text) !important;
291
+ background: var(--site-config-color-bar) !important;
292
+ cursor: pointer !important;
293
+
294
+ &--active {
295
+ color: var(--site-config-color-mobile-theme-active) !important;
296
+ background: var(--site-config-color-mobile-theme-active-background) !important;
297
+ }
298
+ }
299
+
266
300
  .arrow-left {
267
301
  font-size: 28px !important;
268
302
  }
@@ -271,11 +305,11 @@ header {
271
305
  font-size: 28px !important;
272
306
  }
273
307
 
274
- .theme {
308
+ .i18n {
275
309
  font-size: 24px !important;
276
310
  }
277
311
 
278
- .i18n {
312
+ .palette {
279
313
  font-size: 24px !important;
280
314
  }
281
315
 
@@ -289,6 +323,12 @@ header {
289
323
  padding-left: 12px !important;
290
324
  }
291
325
 
326
+ .theme-button {
327
+ padding-right: 6px !important;
328
+ margin-right: 4px;
329
+ padding-left: 12px !important;
330
+ }
331
+
292
332
  .app-bar {
293
333
  background: var(--site-config-color-app-bar) !important;
294
334
  }
@@ -428,8 +428,14 @@ iframe {
428
428
  font-weight: normal;
429
429
  }
430
430
 
431
+ table strong {
432
+ border: 1px solid currentColor;
433
+ padding: 2px 8px;
434
+ border-radius: 12px;
435
+ }
436
+
431
437
  .card {
432
- border-radius: 6px;
438
+ border-radius: var(--site-config-card-border-radius);
433
439
  background: var(--site-config-color-bar);
434
440
  padding: 20px;
435
441
  margin-bottom: 30px;
@@ -42,15 +42,30 @@
42
42
  <a class="varlet-site-header__link" target="_blank" :href="github" v-ripple v-if="github">
43
43
  <var-icon name="github" :size="28"/>
44
44
  </a>
45
- <div class="varlet-site-header__theme" v-ripple v-if="darkMode" @click="toggleTheme">
46
- <var-icon
47
- size="26px"
48
- :name="currentTheme === 'lightTheme' ? 'white-balance-sunny' : 'weather-night'"
49
- :style="{
50
- marginBottom: currentTheme === 'darkTheme' && '2px',
51
- marginTop: currentTheme === 'lightTheme' && '2px',
52
- }"
53
- />
45
+ <div
46
+ class="varlet-site-header__theme"
47
+ @mouseenter="isOpenThemeMenu = true"
48
+ @mouseleave="isOpenThemeMenu = false"
49
+ v-if="themes.length > 1"
50
+ >
51
+ <var-icon name="palette" :size="28" />
52
+ <var-icon name="chevron-down"/>
53
+ <transition name="fade">
54
+ <div
55
+ class="varlet-site-header__animation-list var-elevation--5"
56
+ v-show="isOpenThemeMenu"
57
+ :style="{ pointerEvents: isOpenThemeMenu ? 'auto' : 'none' }"
58
+ >
59
+ <var-cell
60
+ v-for="t in themes"
61
+ v-ripple
62
+ :key="t.value"
63
+ :class="{ 'varlet-site-header__animation-list--active': currentTheme === t.value }"
64
+ @click="() => toggleTheme(t.value as Theme)"
65
+ >{{ t[language as keyof typeof t] }}
66
+ </var-cell>
67
+ </div>
68
+ </transition>
54
69
  </div>
55
70
  <div
56
71
  class="varlet-site-header__language"
@@ -86,8 +101,7 @@
86
101
  import config from '@config'
87
102
  import { ref, computed, defineComponent } from 'vue'
88
103
  import { get } from 'lodash-es'
89
- import { getBrowserTheme, getPCLocationInfo, Theme, watchTheme } from '@varlet/cli/client'
90
- import { setTheme } from '../../utils'
104
+ import { getBrowserTheme, getPCLocationInfo, Theme, watchTheme, setTheme } from '@varlet/cli/client'
91
105
  import { removeEmpty } from '../../utils'
92
106
  import { useRouter } from 'vue-router'
93
107
  import type { Ref, ComputedRef } from 'vue'
@@ -109,12 +123,14 @@ export default defineComponent({
109
123
  const versionItems: Ref<Array<Record<string, any>>> = ref((versions ?? []).find((i: any) => window.location.host.includes(i.name))?.items ?? versions?.[0]?.items ?? [])
110
124
  const playground: Ref<string> = ref(get(config, 'pc.header.playground'))
111
125
  const github: Ref<string> = ref(get(config, 'pc.header.github'))
126
+ const themes: Ref<Record<string, any>> = ref(get(config, 'pc.header.themes'))
112
127
  const changelog: Ref<string> = ref(get(config, 'pc.header.changelog'))
113
128
  const redirect = get(config, 'pc.redirect')
114
129
  const darkMode: Ref<boolean> = ref(get(config, 'pc.header.darkMode'))
115
130
  const currentTheme = ref(getBrowserTheme())
116
131
 
117
132
  const isOpenLanguageMenu: Ref<boolean> = ref(false)
133
+ const isOpenThemeMenu: Ref<boolean> = ref(false)
118
134
  const isOpenVersionsMenu: Ref<boolean> = ref(false)
119
135
  const router = useRouter()
120
136
  const nonEmptyLanguages: ComputedRef<Record<string, string>> = computed(() => removeEmpty(languages.value))
@@ -132,17 +148,18 @@ export default defineComponent({
132
148
 
133
149
  const setCurrentTheme = (theme: Theme) => {
134
150
  currentTheme.value = theme
135
- setTheme(config, currentTheme.value)
151
+ setTheme(currentTheme.value)
136
152
  window.localStorage.setItem(get(config, 'themeKey'), currentTheme.value)
137
153
  }
138
154
 
139
155
  const getThemeMessage = () => ({ action: 'theme-change', from: 'pc', data: currentTheme.value })
140
156
 
141
- const toggleTheme = () => {
142
- setCurrentTheme(currentTheme.value === 'darkTheme' ? 'lightTheme' : 'darkTheme')
157
+ const toggleTheme = (value: Theme) => {
158
+ setCurrentTheme(value)
143
159
 
144
160
  window.postMessage(getThemeMessage(), '*')
145
161
  notifyThemeChange('mobile')
162
+ isOpenThemeMenu.value = false
146
163
  }
147
164
 
148
165
  const notifyThemeChange = (target: 'mobile' | 'window') => {
@@ -169,7 +186,7 @@ export default defineComponent({
169
186
  }
170
187
  })
171
188
 
172
- setTheme(config, currentTheme.value)
189
+ setTheme(currentTheme.value)
173
190
  notifyThemeChange('window')
174
191
 
175
192
  return {
@@ -180,12 +197,14 @@ export default defineComponent({
180
197
  languages,
181
198
  isShowVersion,
182
199
  versionItems,
200
+ themes,
183
201
  nonEmptyLanguages,
184
202
  playground,
185
203
  changelog,
186
204
  github,
187
205
  isOpenLanguageMenu,
188
206
  isOpenVersionsMenu,
207
+ isOpenThemeMenu,
189
208
  darkMode,
190
209
  currentTheme,
191
210
  open,
@@ -244,21 +263,6 @@ export default defineComponent({
244
263
  }
245
264
  }
246
265
 
247
- &__language {
248
- border-radius: 3px;
249
- height: 40px;
250
- display: flex;
251
- align-items: center;
252
- padding: 0 10px;
253
- position: relative;
254
- cursor: pointer;
255
- transition: background-color 0.25s;
256
-
257
- &:hover {
258
- background: var(--site-config-color-nav-button-hover-background);
259
- }
260
- }
261
-
262
266
  &__versions {
263
267
  border-radius: 3px;
264
268
  height: 40px;
@@ -298,16 +302,31 @@ export default defineComponent({
298
302
  }
299
303
  }
300
304
 
305
+ &__language {
306
+ border-radius: 3px;
307
+ height: 40px;
308
+ display: flex;
309
+ align-items: center;
310
+ padding: 0 10px;
311
+ position: relative;
312
+ cursor: pointer;
313
+ transition: background-color 0.25s;
314
+
315
+ &:hover {
316
+ background: var(--site-config-color-nav-button-hover-background);
317
+ }
318
+ }
319
+
301
320
  &__theme {
302
- border-radius: 50%;
303
- width: 42px;
304
- height: 42px;
321
+ border-radius: 3px;
322
+ height: 40px;
305
323
  display: flex;
306
- justify-content: center;
307
324
  align-items: center;
325
+ padding: 0 10px;
326
+ position: relative;
308
327
  cursor: pointer;
309
328
  transition: background-color 0.25s;
310
- margin-right: 4px;
329
+ margin-right: 6px;
311
330
 
312
331
  &:hover {
313
332
  background: var(--site-config-color-nav-button-hover-background);
@@ -338,6 +357,30 @@ export default defineComponent({
338
357
  }
339
358
  }
340
359
 
360
+ &__theme-animation-list {
361
+ background: var(--site-config-color-bar);
362
+ cursor: pointer;
363
+ color: var(--site-config-color-text);
364
+ border-radius: 2px;
365
+ position: absolute;
366
+ top: 40px;
367
+ left: -20px;
368
+
369
+ .var-cell {
370
+ width: 100px !important;
371
+ color: var(--site-config-color-text);
372
+
373
+ &__content {
374
+ color: inherit !important;
375
+ }
376
+ }
377
+
378
+ &--active {
379
+ background: var(--site-config-color-pc-theme-active-background) !important;
380
+ color: var(--site-config-color-pc-theme-active) !important;
381
+ }
382
+ }
383
+
341
384
  &__animation-versions {
342
385
  left: -7px;
343
386
  }
@@ -93,7 +93,7 @@ export default defineComponent({
93
93
  const toPlayground = () => {
94
94
  const codeText = code.value?.innerText ?? ''
95
95
  const file = { 'App.vue': codeText }
96
- const initialTheme = getBrowserTheme().replace('Theme', '')
96
+ const initialTheme = getBrowserTheme()
97
97
 
98
98
  context.showPlayground = true
99
99
  context.playgroundURL = `${playground.value}/?initialTheme=${initialTheme}#${utoa(JSON.stringify(file))}`
@@ -30,7 +30,7 @@
30
30
  &__code {
31
31
  transition: all .25s;
32
32
  overflow: hidden;
33
- border-radius: 4px;
33
+ border-radius: var(--site-config-code-example-border-radius);
34
34
  }
35
35
 
36
36
  &--scroller {
@@ -7,10 +7,11 @@ import { useRoute, useRouter } from 'vue-router'
7
7
  import {
8
8
  getPCLocationInfo,
9
9
  watchTheme,
10
+ onThemeChange,
10
11
  getBrowserTheme,
12
+ setTheme,
11
13
  type Theme
12
14
  } from '@varlet/cli/client'
13
- import { setTheme } from '../../../utils'
14
15
 
15
16
  const route = useRoute()
16
17
  const router = useRouter()
@@ -32,7 +33,7 @@ const getThemeMessage = () => ({ action: 'theme-change', from: 'pc', data: curre
32
33
 
33
34
  const setCurrentTheme = (theme: Theme) => {
34
35
  currentTheme.value = theme
35
- setTheme(config, currentTheme.value)
36
+ setTheme(currentTheme.value)
36
37
  window.localStorage.setItem(get(config, 'themeKey'), currentTheme.value)
37
38
  }
38
39
 
@@ -48,7 +49,7 @@ const to = (url: string) => {
48
49
  window.open(url)
49
50
  }
50
51
 
51
- setTheme(config, currentTheme.value)
52
+ setTheme(currentTheme.value)
52
53
 
53
54
  window.postMessage(getThemeMessage(), '*')
54
55
 
@@ -56,8 +57,10 @@ watchTheme((theme, from) => {
56
57
  from === 'mobile' && setCurrentTheme(theme)
57
58
  })
58
59
 
60
+ onThemeChange()
61
+
59
62
  watch(() => route.path, () => {
60
- language.value = getPCLocationInfo().language
63
+ language.value = getPCLocationInfo().language
61
64
  setLocale()
62
65
  }, { immediate: true })
63
66
  </script>
@@ -79,7 +82,7 @@ watch(() => route.path, () => {
79
82
  <var-button class="varlet-doc-index__link-button" type="primary" style="line-height: 1.2" @click="getStar">
80
83
  {{ indexPage.started[language] }}
81
84
  </var-button>
82
- <var-button class="varlet-doc-index__github-button" type="primary" style="line-height: 1.2" @click="toGithub">
85
+ <var-button class="varlet-doc-index__github-button" style="line-height: 1.2" @click="toGithub">
83
86
  {{ indexPage.viewOnGithub[language] }}
84
87
  </var-button>
85
88
  </var-space>
@@ -239,7 +242,6 @@ watch(() => route.path, () => {
239
242
  font-size: 19px !important;
240
243
  transition: all .2s !important;
241
244
  margin-top: 38px !important;
242
- background: var(--site-config-color-index-page-get-started-button) !important;
243
245
  }
244
246
 
245
247
  &__github-button {
@@ -248,7 +250,6 @@ watch(() => route.path, () => {
248
250
  font-size: 19px !important;
249
251
  transition: all .2s !important;
250
252
  margin-top: 38px !important;
251
- background: var(--site-config-color-index-page-github-button) !important;
252
253
  }
253
254
 
254
255
  &__features {
@@ -262,7 +263,7 @@ watch(() => route.path, () => {
262
263
  width: 300px;
263
264
  margin: 12px;
264
265
  padding: 20px;
265
- border-radius: 10px;
266
+ border-radius: 12px;
266
267
  background: var(--site-config-color-index-page-feature-background);
267
268
  box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
268
269
  }
@@ -306,7 +307,7 @@ watch(() => route.path, () => {
306
307
  width: 300px;
307
308
  margin: 12px;
308
309
  padding: 30px 20px;
309
- border-radius: 10px;
310
+ border-radius: 12px;
310
311
  background: var(--site-config-color-index-page-feature-background);
311
312
  box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
312
313
 
package/site/utils.ts CHANGED
@@ -31,12 +31,6 @@ export function inIframe() {
31
31
  return window.self !== window.top
32
32
  }
33
33
 
34
- export function setTheme(config: Record<string, any>, theme: Theme) {
35
- const styleVars = withSiteConfigNamespace(get(config, theme, {}))
36
- StyleProvider({ ...styleVars, ...(theme === 'darkTheme' ? Themes.dark : {}) })
37
- setColorScheme(theme)
38
- }
39
-
40
34
  export function utoa(data: string): string {
41
35
  return btoa(unescape(encodeURIComponent(data)))
42
36
  }
@@ -2,7 +2,7 @@ import { Locale } from '@varlet/ui'
2
2
  import zhCN from './zh-CN'
3
3
  import enUS from './en-US'
4
4
 
5
- const { add, use: exampleUse, pack, packs, merge } = Locale.useLocale()
5
+ const { add, use: exampleUse, t, merge } = Locale.useLocale()
6
6
 
7
7
  const use = (lang: string) => {
8
8
  Locale.use(lang)
@@ -11,7 +11,7 @@ const use = (lang: string) => {
11
11
 
12
12
  Locale.add('zh-CN', Locale.zhCN)
13
13
  Locale.add('en-US', Locale.enUS)
14
- add('zh-CN', zhCN as any)
15
- add('en-US', enUS as any)
14
+ add('zh-CN', zhCN)
15
+ add('en-US', enUS)
16
16
 
17
- export { add, pack, packs, merge, use }
17
+ export { add, t, merge, use }
@@ -7,18 +7,18 @@ import zhCN from './zh-CN'
7
7
  import enUS from './en-US'
8
8
  import { useLocale, add as _add, use as _use } from '../../../locale'
9
9
 
10
- const { add, use: exampleUse, pack, packs, merge } = useLocale()
10
+ const { add, use: exampleUse, t, merge } = useLocale()
11
11
 
12
12
  const use = (lang: string) => {
13
13
  _use(lang)
14
14
  exampleUse(lang)
15
15
  }
16
16
 
17
- export { add, pack, packs, merge, use }
17
+ export { add, t, merge, use }
18
18
 
19
19
  // lib
20
20
  _add('zh-CN', _zhCN)
21
21
  _add('en-US', _enCN)
22
22
  // mobile example doc
23
- add('zh-CN', zhCN as any)
24
- add('en-US', enUS as any)
23
+ add('zh-CN', zhCN)
24
+ add('en-US', enUS)
@@ -1,21 +1,25 @@
1
1
  import type { Ref } from 'vue'
2
2
 
3
- export type Pack = {
3
+ export type Message = {
4
4
  button: string
5
+
6
+ [key: PropertyKey]: any
5
7
  }
6
8
 
7
9
  interface Locale {
8
- packs: Record<string, Partial<Pack>>
9
- pack: Ref<Partial<Pack>>
10
- add(lang: string, pack: Partial<Pack>): void
10
+ messages: Record<string, Partial<Message>>
11
+ currentMessage: Ref<Partial<Message>>
12
+ add(lang: string, message: Partial<Message>): void
11
13
  use(lang: string): void
12
- merge(lang: string, pack: Partial<Pack>): void
13
- useLocale<T = Pack>(): {
14
- packs: Record<string, Partial<T>>
15
- pack: Ref<Partial<T>>
16
- add(lang: string, pack: Partial<T> & { lang?: string }): void
14
+ merge(lang: string, message: Partial<Message>): void
15
+ t(id: string): string
16
+ useLocale<T = Message>(): {
17
+ messages: Record<string, Partial<T>>
18
+ currentMessage: Ref<Partial<T>>
19
+ add(lang: string, message: Partial<T> & { lang?: string }): void
17
20
  use(lang: string): void
18
- merge(lang: string, pack: Partial<T>): void
21
+ merge(lang: string, message: Partial<T>): void
22
+ t(id: string): string
19
23
  }
20
24
  }
21
25
 
@@ -1,11 +1,11 @@
1
1
  <script setup>
2
2
  import VaButton from '..'
3
3
  import { watchLang } from '@varlet/cli/client'
4
- import { pack, use } from './locale'
4
+ import { t, use } from './locale'
5
5
 
6
6
  watchLang(use, 'pc')
7
7
  </script>
8
8
 
9
9
  <template>
10
- <va-button>{{ pack.start }}</va-button>
10
+ <va-button>{{ t('start') }}</va-button>
11
11
  </template>
@@ -1,11 +1,11 @@
1
1
  <script setup>
2
2
  import VaButton from '..'
3
3
  import { watchLang } from '@varlet/cli/client'
4
- import { pack, use } from './locale'
4
+ import { t, use } from './locale'
5
5
 
6
6
  watchLang(use, 'pc')
7
7
  </script>
8
8
 
9
9
  <template>
10
- <va-button color="#03A9F4">{{ pack.start }}</va-button>
10
+ <va-button color="#03A9F4">{{ t('start') }}</va-button>
11
11
  </template>
@@ -1,15 +1,15 @@
1
1
  <script setup>
2
2
  import VaButton from '..'
3
3
  import { watchLang, AppType } from '@varlet/cli/client'
4
- import { pack, use } from './locale'
4
+ import { t, use } from './locale'
5
5
 
6
6
  watchLang(use)
7
7
  </script>
8
8
 
9
9
  <template>
10
- <app-type>{{ pack.basicUse }}</app-type>
11
- <va-button>{{ pack.start }}</va-button>
10
+ <app-type>{{ t('basicUse') }}</app-type>
11
+ <va-button>{{ t('start') }}</va-button>
12
12
 
13
- <app-type>{{ pack.modifyColor }}</app-type>
14
- <va-button color="#03A9F4">{{ pack.start }}</va-button>
13
+ <app-type>{{ t('modifyColor') }}</app-type>
14
+ <va-button color="#03A9F4">{{ t('start') }}</va-button>
15
15
  </template>
@@ -6,18 +6,18 @@ import zhCN from './zh-CN'
6
6
  import enUS from './en-US'
7
7
  import { useLocale, add as _add, use as _use } from '../../../locale'
8
8
 
9
- const { add, use: exampleUse, pack, packs, merge } = useLocale()
9
+ const { add, use: exampleUse, t, merge } = useLocale()
10
10
 
11
11
  const use = (lang: string) => {
12
12
  _use(lang)
13
13
  exampleUse(lang)
14
14
  }
15
15
 
16
- export { add, pack, packs, merge, use }
16
+ export { add, t, merge, use }
17
17
 
18
18
  // lib
19
19
  _add('zh-CN', _zhCN)
20
20
  _add('en-US', _enCN)
21
21
  // mobile example doc
22
- add('zh-CN', zhCN as any)
23
- add('en-US', enUS as any)
22
+ add('zh-CN', zhCN)
23
+ add('en-US', enUS)