uview-plus 3.7.36 → 3.8.32

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 (132) hide show
  1. package/README.md +0 -1
  2. package/changelog.md +2047 -1782
  3. package/components/u-action-sheet/u-action-sheet.vue +54 -16
  4. package/components/u-agreement/u-agreement.vue +2 -1
  5. package/components/u-alert/u-alert.vue +8 -10
  6. package/components/u-button/u-button.vue +35 -5
  7. package/components/u-calendar/calendar.js +1 -0
  8. package/components/u-calendar/header.vue +98 -9
  9. package/components/u-calendar/month.vue +10 -7
  10. package/components/u-calendar/props.js +5 -0
  11. package/components/u-calendar/u-calendar.vue +109 -2
  12. package/components/u-car-keyboard/u-car-keyboard.vue +7 -7
  13. package/components/u-card/u-card.vue +6 -6
  14. package/components/u-cascader/u-cascader.vue +32 -12
  15. package/components/u-cate-tab/u-cate-tab.vue +49 -48
  16. package/components/u-cell/u-cell.vue +24 -4
  17. package/components/u-cell-group/u-cell-group.vue +10 -3
  18. package/components/u-checkbox/u-checkbox.vue +6 -6
  19. package/components/u-choose/u-choose.vue +9 -4
  20. package/components/u-city-locate/u-city-locate.vue +28 -22
  21. package/components/u-color-picker/u-color-picker.vue +15 -15
  22. package/components/u-cropper/u-cropper.vue +409 -387
  23. package/components/u-datetime-picker/u-datetime-picker.vue +79 -10
  24. package/components/u-dragsort/u-dragsort.vue +3 -0
  25. package/components/u-dropdown/u-dropdown.vue +15 -2
  26. package/components/u-dropdown-item/u-dropdown-item.vue +3 -3
  27. package/components/u-form-item/u-form-item.vue +6 -1
  28. package/components/u-gap/u-gap.vue +5 -1
  29. package/components/u-goods-sku/u-goods-sku.vue +16 -15
  30. package/components/u-index-anchor/u-index-anchor.vue +13 -2
  31. package/components/u-index-list/u-index-list.vue +18 -5
  32. package/components/u-input/input.js +3 -3
  33. package/components/u-input/u-input.vue +27 -5
  34. package/components/u-keyboard/u-keyboard.vue +11 -6
  35. package/components/u-loading-page/loadingPage.js +1 -1
  36. package/components/u-loading-page/u-loading-page.vue +18 -12
  37. package/components/u-navbar/navbar.js +2 -3
  38. package/components/u-navbar/theme-vars.scss +21 -0
  39. package/components/u-navbar/u-navbar.vue +30 -6
  40. package/components/u-notice-bar/theme-vars.scss +25 -0
  41. package/components/u-notice-bar/u-notice-bar.vue +24 -5
  42. package/components/u-number-box/numberBox.js +4 -4
  43. package/components/u-number-box/u-number-box.vue +27 -13
  44. package/components/u-number-keyboard/u-number-keyboard.vue +6 -6
  45. package/components/u-picker/picker.js +43 -43
  46. package/components/u-picker/u-picker.vue +14 -2
  47. package/components/u-popup/popup.js +1 -1
  48. package/components/u-popup/u-popup.vue +14 -6
  49. package/components/u-poster/u-poster.vue +12 -10
  50. package/components/u-pull-refresh/u-pull-refresh.vue +6 -6
  51. package/components/u-qrcode/qrcode.js +35 -29
  52. package/components/u-qrcode/u-qrcode.vue +17 -12
  53. package/components/u-radio/u-radio.vue +6 -6
  54. package/components/u-rate/rate.js +2 -2
  55. package/components/u-rate/u-rate.vue +98 -21
  56. package/components/u-search/search.js +3 -3
  57. package/components/u-search/u-search.vue +29 -6
  58. package/components/u-select/u-select.vue +141 -73
  59. package/components/u-signature/u-signature.vue +35 -16
  60. package/components/u-skeleton/u-skeleton.vue +7 -2
  61. package/components/u-slider/u-slider.vue +30 -31
  62. package/components/u-steps-item/u-steps-item.vue +20 -17
  63. package/components/u-subsection/theme-vars.scss +41 -0
  64. package/components/u-subsection/u-subsection.vue +69 -16
  65. package/components/u-swipe-action-item/u-swipe-action-item.vue +11 -5
  66. package/components/u-switch/theme-vars.scss +41 -0
  67. package/components/u-switch/u-switch.vue +44 -15
  68. package/components/u-tabbar/u-tabbar.vue +5 -5
  69. package/components/u-tabbar-item/u-tabbar-item.vue +16 -5
  70. package/components/u-table/u-table.vue +18 -3
  71. package/components/u-table2/tableRow.vue +43 -41
  72. package/components/u-table2/u-table2.vue +56 -50
  73. package/components/u-tabs/u-tabs.vue +14 -1
  74. package/components/u-tag/theme-vars.scss +21 -0
  75. package/components/u-tag/u-tag.vue +17 -7
  76. package/components/u-td/u-td.vue +5 -3
  77. package/components/u-text/text.js +1 -1
  78. package/components/u-text/u-text.vue +15 -13
  79. package/components/u-textarea/props.js +2 -2
  80. package/components/u-textarea/textarea.js +1 -1
  81. package/components/u-textarea/u-textarea.vue +115 -61
  82. package/components/u-th/u-th.vue +5 -4
  83. package/components/u-title/u-title.vue +1 -0
  84. package/components/u-toast/u-toast.vue +13 -9
  85. package/components/u-tooltip/u-tooltip.vue +1 -0
  86. package/components/u-tree/u-tree.vue +491 -51
  87. package/components/u-upload/u-upload.vue +34 -6
  88. package/index.js +178 -27
  89. package/index.scss +5 -1
  90. package/libs/config/color.js +1 -2
  91. package/libs/config/config.js +2 -0
  92. package/libs/config/props.js +1 -1
  93. package/libs/css/theme-vars-core.scss +201 -0
  94. package/libs/css/theme-vars.scss +1 -0
  95. package/libs/function/index.js +7 -7
  96. package/libs/mixin/mixin.js +111 -4
  97. package/libs/root/index.js +151 -0
  98. package/libs/root/nvue-root.vue +72 -0
  99. package/libs/root/page.js +269 -0
  100. package/libs/root/root-toast-host.vue +31 -0
  101. package/libs/root/root.js +44 -0
  102. package/libs/root/runtime.js +11 -0
  103. package/libs/root/utils.js +115 -0
  104. package/libs/theme/runtime.js +392 -0
  105. package/libs/theme/theme.js +682 -0
  106. package/libs/util/gcanvas/bridge/bridge-weex.js +0 -0
  107. package/libs/util/gcanvas/context-2d/FillStyleLinearGradient.js +0 -0
  108. package/libs/util/gcanvas/context-2d/FillStylePattern.js +0 -0
  109. package/libs/util/gcanvas/context-2d/FillStyleRadialGradient.js +0 -0
  110. package/libs/util/gcanvas/context-2d/RenderingContext.js +0 -0
  111. package/libs/util/gcanvas/context-webgl/ActiveInfo.js +0 -0
  112. package/libs/util/gcanvas/context-webgl/Buffer.js +0 -0
  113. package/libs/util/gcanvas/context-webgl/Framebuffer.js +0 -0
  114. package/libs/util/gcanvas/context-webgl/GLenum.js +0 -0
  115. package/libs/util/gcanvas/context-webgl/GLmethod.js +0 -0
  116. package/libs/util/gcanvas/context-webgl/GLtype.js +0 -0
  117. package/libs/util/gcanvas/context-webgl/Program.js +0 -0
  118. package/libs/util/gcanvas/context-webgl/Renderbuffer.js +0 -0
  119. package/libs/util/gcanvas/context-webgl/RenderingContext.js +0 -0
  120. package/libs/util/gcanvas/context-webgl/Shader.js +0 -0
  121. package/libs/util/gcanvas/context-webgl/ShaderPrecisionFormat.js +0 -0
  122. package/libs/util/gcanvas/context-webgl/Texture.js +0 -0
  123. package/libs/util/gcanvas/context-webgl/UniformLocation.js +0 -0
  124. package/libs/util/gcanvas/context-webgl/classUtils.js +0 -0
  125. package/libs/util/gcanvas/env/canvas.js +0 -0
  126. package/libs/util/gcanvas/env/image.js +0 -0
  127. package/libs/util/gcanvas/env/tool.js +0 -0
  128. package/libs/util/gcanvas/index.js +0 -0
  129. package/package.json +3 -2
  130. package/theme.scss +113 -32
  131. package/types/comps/qrcode.d.ts +6 -0
  132. package/types/index.d.ts +47 -2
@@ -0,0 +1,682 @@
1
+ import config from '../config/config.js'
2
+ import color from '../config/color.js'
3
+ import index from '../function/index.js'
4
+
5
+ const DEFAULT_LIGHT_THEME_COLORS = Object.freeze({
6
+ primary: '#3c9cff',
7
+ info: '#909399',
8
+ warning: '#f9ae3d',
9
+ error: '#f56c6c',
10
+ success: '#5ac725',
11
+ mainColor: '#303133',
12
+ contentColor: '#606266',
13
+ tipsColor: '#909193',
14
+ lightColor: '#c0c4cc',
15
+ borderColor: '#dadbde',
16
+ bgColor: '#f3f4f6',
17
+ disabledColor: '#c8c9cc',
18
+ primaryDark: '#398ade',
19
+ primaryDisabled: '#9acafc',
20
+ primaryLight: '#ecf5ff',
21
+ warningDark: '#f1a532',
22
+ warningDisabled: '#f9d39b',
23
+ warningLight: '#fdf6ec',
24
+ successDark: '#53c21d',
25
+ successDisabled: '#a9e08f',
26
+ successLight: '#f5fff0',
27
+ errorDark: '#e45656',
28
+ errorDisabled: '#f7b2b2',
29
+ errorLight: '#fef0f0',
30
+ infoDark: '#767a82',
31
+ infoDisabled: '#c4c6c9',
32
+ infoLight: '#f4f4f5'
33
+ })
34
+
35
+ const DEFAULT_DARK_THEME_COLORS = Object.freeze({
36
+ primary: '#3c9cff',
37
+ info: '#909399',
38
+ warning: '#f9ae3d',
39
+ error: '#f56c6c',
40
+ success: '#5ac725',
41
+ mainColor: '#f5f5f5',
42
+ contentColor: '#d1d5db',
43
+ tipsColor: '#9ca3af',
44
+ lightColor: '#6b7280',
45
+ borderColor: '#3a3a3c',
46
+ bgColor: '#1f1f1f',
47
+ disabledColor: '#4b5563',
48
+ primaryDark: '#5aa8ff',
49
+ primaryDisabled: '#4c6f92',
50
+ primaryLight: '#10243a',
51
+ warningDark: '#ffbf66',
52
+ warningDisabled: '#8a6a3a',
53
+ warningLight: '#3d2f1b',
54
+ successDark: '#7ad94b',
55
+ successDisabled: '#5f7f4f',
56
+ successLight: '#1f3316',
57
+ errorDark: '#ff8a8a',
58
+ errorDisabled: '#8d5858',
59
+ errorLight: '#3a2222',
60
+ infoDark: '#b0b3b8',
61
+ infoDisabled: '#5f6368',
62
+ infoLight: '#2f3238'
63
+ })
64
+
65
+ const DEFAULT_THEME_EXTRA_VARS = Object.freeze({
66
+ light: Object.freeze({
67
+ '--up-table2-header-bg-color': '#f5f7fa',
68
+ '--up-table2-zebra-bg-color': '#fafafa',
69
+ '--up-table2-highlight-bg-color': '#f5f7fa',
70
+ '--up-gap-bg-color': '#f3f4f6',
71
+ '--up-skeleton-bg-color': '#f1f2f4',
72
+ '--up-skeleton-shimmer-color': '#e6e6e6',
73
+ '--up-swipe-action-button-bg-color': '#c7c6cd',
74
+ '--up-index-list-indicator-bg-color': '#c9c9c9',
75
+ '--up-calendar-month-mark-color': 'rgba(231, 232, 234, 0.83)'
76
+ }),
77
+ dark: Object.freeze({
78
+ '--up-table2-header-bg-color': '#2a2d33',
79
+ '--up-table2-zebra-bg-color': '#23262b',
80
+ '--up-table2-highlight-bg-color': '#2f3440',
81
+ '--up-gap-bg-color': '#111111',
82
+ '--up-skeleton-bg-color': '#2f3135',
83
+ '--up-skeleton-shimmer-color': 'rgba(255, 255, 255, 0.12)',
84
+ '--up-swipe-action-button-bg-color': '#4b5563',
85
+ '--up-index-list-indicator-bg-color': '#4b5563',
86
+ '--up-calendar-month-mark-color': 'rgba(255, 255, 255, 0.04)'
87
+ })
88
+ })
89
+
90
+ export const themeState = {
91
+ preference: 'system',
92
+ mode: 'light',
93
+ version: 0,
94
+ vars: {}
95
+ }
96
+
97
+ const THEME_MODE_STORAGE_KEY = 'u-theme-mode'
98
+ const THEME_MODE_SYSTEM = 'system'
99
+ const THEME_MODE_MANUAL = ['light', 'dark']
100
+ const LIGHT_THEME_TOKEN_FIELD_MAP = Object.freeze({
101
+ 'primary': 'primary',
102
+ 'primary-dark': 'primaryDark',
103
+ 'primary-disabled': 'primaryDisabled',
104
+ 'primary-light': 'primaryLight',
105
+ 'warning': 'warning',
106
+ 'warning-dark': 'warningDark',
107
+ 'warning-disabled': 'warningDisabled',
108
+ 'warning-light': 'warningLight',
109
+ 'success': 'success',
110
+ 'success-dark': 'successDark',
111
+ 'success-disabled': 'successDisabled',
112
+ 'success-light': 'successLight',
113
+ 'error': 'error',
114
+ 'error-dark': 'errorDark',
115
+ 'error-disabled': 'errorDisabled',
116
+ 'error-light': 'errorLight',
117
+ 'info': 'info',
118
+ 'info-dark': 'infoDark',
119
+ 'info-disabled': 'infoDisabled',
120
+ 'info-light': 'infoLight',
121
+ 'main-color': 'mainColor',
122
+ 'content-color': 'contentColor',
123
+ 'tips-color': 'tipsColor',
124
+ 'light-color': 'lightColor',
125
+ 'border-color': 'borderColor',
126
+ 'bg-color': 'bgColor',
127
+ 'disabled-color': 'disabledColor'
128
+ })
129
+ const LIGHT_THEME_FIELD_TOKEN_MAP = Object.freeze(
130
+ Object.fromEntries(
131
+ Object.entries(LIGHT_THEME_TOKEN_FIELD_MAP).map(([token, field]) => [field, token])
132
+ )
133
+ )
134
+
135
+ const runtimeThemeOverrideState = {
136
+ color: Object.create(null),
137
+ configColor: Object.create(null)
138
+ }
139
+
140
+ let cachedLightThemeColors = null
141
+ let hasRegisterThemeListener = false
142
+ let currentThemePreference = THEME_MODE_SYSTEM
143
+
144
+ function normalizeThemeMode(theme = 'light') {
145
+ return theme === 'dark' ? 'dark' : 'light'
146
+ }
147
+
148
+ function normalizeThemePreference(mode = THEME_MODE_SYSTEM) {
149
+ if (THEME_MODE_MANUAL.includes(mode)) return mode
150
+ return THEME_MODE_SYSTEM
151
+ }
152
+
153
+ function getLightBridgeVar(token, fallback) {
154
+ return `var(--up-light-${token}, ${fallback})`
155
+ }
156
+
157
+ function clearOverrideBucket(bucket) {
158
+ Object.keys(bucket).forEach((key) => {
159
+ delete bucket[key]
160
+ })
161
+ }
162
+
163
+ function normalizeLightThemeToken(token = '') {
164
+ if (typeof token !== 'string') return ''
165
+ if (token.indexOf('up-') === 0) return token.slice(3)
166
+ if (token.indexOf('u-') === 0) return token.slice(2)
167
+ return token
168
+ }
169
+
170
+ function isLightThemeConfigColorKey(token = '') {
171
+ return token.indexOf('up-') === 0 || token.indexOf('u-') === 0
172
+ }
173
+
174
+ export function syncThemeColorOverrideState({
175
+ color: colorOverrides,
176
+ configColor: configColorOverrides,
177
+ reset = false
178
+ } = {}) {
179
+ if (reset) {
180
+ clearOverrideBucket(runtimeThemeOverrideState.color)
181
+ clearOverrideBucket(runtimeThemeOverrideState.configColor)
182
+ }
183
+ if (colorOverrides && typeof colorOverrides === 'object') {
184
+ Object.keys(LIGHT_THEME_FIELD_TOKEN_MAP).forEach((field) => {
185
+ if (!Object.prototype.hasOwnProperty.call(colorOverrides, field)) return
186
+ const value = colorOverrides[field]
187
+ if (typeof value === 'string' && value) {
188
+ runtimeThemeOverrideState.color[field] = true
189
+ return
190
+ }
191
+ delete runtimeThemeOverrideState.color[field]
192
+ })
193
+ }
194
+ if (configColorOverrides && typeof configColorOverrides === 'object') {
195
+ Object.keys(configColorOverrides).forEach((key) => {
196
+ const token = normalizeLightThemeToken(key)
197
+ if (!Object.prototype.hasOwnProperty.call(LIGHT_THEME_TOKEN_FIELD_MAP, token)) return
198
+ const value = configColorOverrides[key]
199
+ if (typeof value === 'string' && value) {
200
+ const overrideKey = isLightThemeConfigColorKey(key) ? key : `up-${token}`
201
+ runtimeThemeOverrideState.configColor[overrideKey] = true
202
+ return
203
+ }
204
+ delete runtimeThemeOverrideState.configColor[key]
205
+ delete runtimeThemeOverrideState.configColor[`u-${token}`]
206
+ delete runtimeThemeOverrideState.configColor[`up-${token}`]
207
+ })
208
+ }
209
+ }
210
+
211
+ function getExplicitRuntimeColorValue(token, runtimeColorMap = {}) {
212
+ const field = LIGHT_THEME_TOKEN_FIELD_MAP[token]
213
+ if (!field) return ''
214
+ if (runtimeThemeOverrideState.color[field]) {
215
+ const value = color[field]
216
+ if (typeof value === 'string' && value) return value
217
+ }
218
+ const upKey = `up-${token}`
219
+ const uKey = `u-${token}`
220
+ if (!runtimeThemeOverrideState.configColor[upKey] && !runtimeThemeOverrideState.configColor[uKey]) return ''
221
+ const upValue = runtimeColorMap[upKey]
222
+ const uValue = runtimeColorMap[uKey]
223
+ if (runtimeThemeOverrideState.configColor[upKey] && typeof upValue === 'string' && upValue) return upValue
224
+ if (runtimeThemeOverrideState.configColor[uKey] && typeof uValue === 'string' && uValue) return uValue
225
+ return ''
226
+ }
227
+
228
+ function readThemePreferenceFromStorage() {
229
+ try {
230
+ if (typeof uni !== 'undefined' && typeof uni.getStorageSync === 'function') {
231
+ const mode = uni.getStorageSync(THEME_MODE_STORAGE_KEY)
232
+ return normalizeThemePreference(mode)
233
+ }
234
+ } catch (e) {}
235
+ return THEME_MODE_SYSTEM
236
+ }
237
+
238
+ function writeThemePreferenceToStorage(mode) {
239
+ try {
240
+ if (typeof uni !== 'undefined' && typeof uni.setStorageSync === 'function') {
241
+ uni.setStorageSync(THEME_MODE_STORAGE_KEY, mode)
242
+ }
243
+ } catch (e) {}
244
+ }
245
+
246
+ export function getSystemTheme() {
247
+ let theme = 'light'
248
+ try {
249
+ if (typeof uni !== 'undefined' && typeof uni.getAppBaseInfo === 'function') {
250
+ const appBaseInfo = uni.getAppBaseInfo() || {}
251
+ if (appBaseInfo.theme) {
252
+ theme = appBaseInfo.theme
253
+ }
254
+ }
255
+ if (typeof uni !== 'undefined' && typeof uni.getSystemInfoSync === 'function') {
256
+ const systemInfo = uni.getSystemInfoSync() || {}
257
+ if (systemInfo.theme) {
258
+ theme = systemInfo.theme
259
+ }
260
+ }
261
+ } catch (e) {
262
+ theme = 'light'
263
+ }
264
+ return normalizeThemeMode(theme)
265
+ }
266
+
267
+ function getCurrentLightThemeColors() {
268
+ const runtimeColorMap = config.color || {}
269
+ const lightThemeColors = {
270
+ ...DEFAULT_LIGHT_THEME_COLORS
271
+ }
272
+ Object.keys(LIGHT_THEME_TOKEN_FIELD_MAP).forEach((token) => {
273
+ const explicitValue = getExplicitRuntimeColorValue(token, runtimeColorMap)
274
+ if (!explicitValue) return
275
+ lightThemeColors[LIGHT_THEME_TOKEN_FIELD_MAP[token]] = explicitValue
276
+ })
277
+ return lightThemeColors
278
+ }
279
+
280
+ function getThemeColorsByMode(mode) {
281
+ if (!cachedLightThemeColors) {
282
+ cachedLightThemeColors = getCurrentLightThemeColors()
283
+ }
284
+ const themeMode = normalizeThemeMode(mode)
285
+ if (themeMode === 'dark') {
286
+ return {
287
+ ...DEFAULT_DARK_THEME_COLORS,
288
+ primary: cachedLightThemeColors.primary,
289
+ info: cachedLightThemeColors.info,
290
+ warning: cachedLightThemeColors.warning,
291
+ error: cachedLightThemeColors.error,
292
+ success: cachedLightThemeColors.success
293
+ }
294
+ }
295
+ return {
296
+ ...cachedLightThemeColors
297
+ }
298
+ }
299
+
300
+ function buildConfigColorMap(themeColors) {
301
+ return {
302
+ 'u-primary': themeColors.primary,
303
+ 'u-primary-dark': themeColors.primaryDark,
304
+ 'u-primary-disabled': themeColors.primaryDisabled,
305
+ 'u-primary-light': themeColors.primaryLight,
306
+ 'u-warning': themeColors.warning,
307
+ 'u-warning-dark': themeColors.warningDark,
308
+ 'u-warning-disabled': themeColors.warningDisabled,
309
+ 'u-warning-light': themeColors.warningLight,
310
+ 'u-success': themeColors.success,
311
+ 'u-success-dark': themeColors.successDark,
312
+ 'u-success-disabled': themeColors.successDisabled,
313
+ 'u-success-light': themeColors.successLight,
314
+ 'u-error': themeColors.error,
315
+ 'u-error-dark': themeColors.errorDark,
316
+ 'u-error-disabled': themeColors.errorDisabled,
317
+ 'u-error-light': themeColors.errorLight,
318
+ 'u-info': themeColors.info,
319
+ 'u-info-dark': themeColors.infoDark,
320
+ 'u-info-disabled': themeColors.infoDisabled,
321
+ 'u-info-light': themeColors.infoLight,
322
+ 'u-main-color': themeColors.mainColor,
323
+ 'u-content-color': themeColors.contentColor,
324
+ 'u-tips-color': themeColors.tipsColor,
325
+ 'u-light-color': themeColors.lightColor,
326
+ 'u-border-color': themeColors.borderColor,
327
+ 'u-bg-color': themeColors.bgColor,
328
+ 'u-disabled-color': themeColors.disabledColor,
329
+ 'up-primary': themeColors.primary,
330
+ 'up-primary-dark': themeColors.primaryDark,
331
+ 'up-primary-disabled': themeColors.primaryDisabled,
332
+ 'up-primary-light': themeColors.primaryLight,
333
+ 'up-warning': themeColors.warning,
334
+ 'up-warning-dark': themeColors.warningDark,
335
+ 'up-warning-disabled': themeColors.warningDisabled,
336
+ 'up-warning-light': themeColors.warningLight,
337
+ 'up-success': themeColors.success,
338
+ 'up-success-dark': themeColors.successDark,
339
+ 'up-success-disabled': themeColors.successDisabled,
340
+ 'up-success-light': themeColors.successLight,
341
+ 'up-error': themeColors.error,
342
+ 'up-error-dark': themeColors.errorDark,
343
+ 'up-error-disabled': themeColors.errorDisabled,
344
+ 'up-error-light': themeColors.errorLight,
345
+ 'up-info': themeColors.info,
346
+ 'up-info-dark': themeColors.infoDark,
347
+ 'up-info-disabled': themeColors.infoDisabled,
348
+ 'up-info-light': themeColors.infoLight,
349
+ 'up-main-color': themeColors.mainColor,
350
+ 'up-content-color': themeColors.contentColor,
351
+ 'up-tips-color': themeColors.tipsColor,
352
+ 'up-light-color': themeColors.lightColor,
353
+ 'up-border-color': themeColors.borderColor,
354
+ 'up-bg-color': themeColors.bgColor,
355
+ 'up-disabled-color': themeColors.disabledColor
356
+ }
357
+ }
358
+
359
+ function buildAliasCssVars(vars = {}) {
360
+ const aliasVars = {}
361
+ Object.keys(vars).forEach((key) => {
362
+ if (typeof key !== 'string') return
363
+ if (key.indexOf('--up-') === 0) {
364
+ aliasVars[key.replace('--up-', '--u-')] = vars[key]
365
+ return
366
+ }
367
+ if (key.indexOf('--u-') === 0) {
368
+ aliasVars[key.replace('--u-', '--up-')] = vars[key]
369
+ }
370
+ })
371
+ return aliasVars
372
+ }
373
+
374
+ function buildThemeCssVars(themeColors, mode = 'light') {
375
+ const themeMode = normalizeThemeMode(mode)
376
+ const isDark = themeMode === 'dark'
377
+ const useBridge = !isDark
378
+ const runtimeColorMap = config.color || {}
379
+ const defaultExtraVars = DEFAULT_THEME_EXTRA_VARS[themeMode] || DEFAULT_THEME_EXTRA_VARS.light
380
+ const pageBgColor = themeColors.bgColor || (isDark ? '#1f1f1f' : '#f3f4f6')
381
+ const hoverBgColor = runtimeColorMap['up-hover-bg-color']
382
+ || runtimeColorMap['u-hover-bg-color']
383
+ || (isDark ? '#343741' : '#e7ebf0')
384
+ const navbarBgColor = runtimeColorMap['up-navbar-bg-color']
385
+ || runtimeColorMap['u-navbar-bg-color']
386
+ || (isDark ? '#1c1c1e' : '#ffffff')
387
+ const resolveLightTokenValue = (token, fallback) => {
388
+ if (!useBridge) return fallback
389
+ const explicitValue = getExplicitRuntimeColorValue(token, runtimeColorMap)
390
+ return explicitValue || getLightBridgeVar(token, fallback)
391
+ }
392
+ const resolvedMainColor = resolveLightTokenValue('main-color', themeColors.mainColor)
393
+ const resolvedContentColor = resolveLightTokenValue('content-color', themeColors.contentColor)
394
+ const resolvedTipsColor = resolveLightTokenValue('tips-color', themeColors.tipsColor)
395
+ const resolvedLightColor = resolveLightTokenValue('light-color', themeColors.lightColor)
396
+ const resolvedBorderColor = resolveLightTokenValue('border-color', themeColors.borderColor)
397
+ const resolvedBgColor = resolveLightTokenValue('bg-color', themeColors.bgColor)
398
+ const resolvedDisabledColor = resolveLightTokenValue('disabled-color', themeColors.disabledColor)
399
+ const resolvedPrimary = resolveLightTokenValue('primary', themeColors.primary)
400
+ const resolvedPrimaryDark = resolveLightTokenValue('primary-dark', themeColors.primaryDark)
401
+ const resolvedPrimaryDisabled = resolveLightTokenValue('primary-disabled', themeColors.primaryDisabled)
402
+ const resolvedPrimaryLight = resolveLightTokenValue('primary-light', themeColors.primaryLight)
403
+ const resolvedWarning = resolveLightTokenValue('warning', themeColors.warning)
404
+ const resolvedWarningDark = resolveLightTokenValue('warning-dark', themeColors.warningDark)
405
+ const resolvedWarningDisabled = resolveLightTokenValue('warning-disabled', themeColors.warningDisabled)
406
+ const resolvedWarningLight = resolveLightTokenValue('warning-light', themeColors.warningLight)
407
+ const resolvedSuccess = resolveLightTokenValue('success', themeColors.success)
408
+ const resolvedSuccessDark = resolveLightTokenValue('success-dark', themeColors.successDark)
409
+ const resolvedSuccessDisabled = resolveLightTokenValue('success-disabled', themeColors.successDisabled)
410
+ const resolvedSuccessLight = resolveLightTokenValue('success-light', themeColors.successLight)
411
+ const resolvedError = resolveLightTokenValue('error', themeColors.error)
412
+ const resolvedErrorDark = resolveLightTokenValue('error-dark', themeColors.errorDark)
413
+ const resolvedErrorDisabled = resolveLightTokenValue('error-disabled', themeColors.errorDisabled)
414
+ const resolvedErrorLight = resolveLightTokenValue('error-light', themeColors.errorLight)
415
+ const resolvedInfo = resolveLightTokenValue('info', themeColors.info)
416
+ const resolvedInfoDark = resolveLightTokenValue('info-dark', themeColors.infoDark)
417
+ const resolvedInfoDisabled = resolveLightTokenValue('info-disabled', themeColors.infoDisabled)
418
+ const resolvedInfoLight = resolveLightTokenValue('info-light', themeColors.infoLight)
419
+ const coreVars = {
420
+ '--u-main-color': resolvedMainColor,
421
+ '--u-content-color': resolvedContentColor,
422
+ '--u-tips-color': resolvedTipsColor,
423
+ '--u-light-color': resolvedLightColor,
424
+ '--u-border-color': resolvedBorderColor,
425
+ '--u-bg-color': resolvedBgColor,
426
+ '--u-hover-bg-color': hoverBgColor,
427
+ '--u-disabled-color': resolvedDisabledColor,
428
+ '--u-primary': resolvedPrimary,
429
+ '--u-primary-dark': resolvedPrimaryDark,
430
+ '--u-primary-disabled': resolvedPrimaryDisabled,
431
+ '--u-primary-light': resolvedPrimaryLight,
432
+ '--u-warning': resolvedWarning,
433
+ '--u-warning-dark': resolvedWarningDark,
434
+ '--u-warning-disabled': resolvedWarningDisabled,
435
+ '--u-warning-light': resolvedWarningLight,
436
+ '--u-success': resolvedSuccess,
437
+ '--u-success-dark': resolvedSuccessDark,
438
+ '--u-success-disabled': resolvedSuccessDisabled,
439
+ '--u-success-light': resolvedSuccessLight,
440
+ '--u-error': resolvedError,
441
+ '--u-error-dark': resolvedErrorDark,
442
+ '--u-error-disabled': resolvedErrorDisabled,
443
+ '--u-error-light': resolvedErrorLight,
444
+ '--u-info': resolvedInfo,
445
+ '--u-info-dark': resolvedInfoDark,
446
+ '--u-info-disabled': resolvedInfoDisabled,
447
+ '--u-info-light': resolvedInfoLight,
448
+ '--up-main-color': resolvedMainColor,
449
+ '--up-content-color': resolvedContentColor,
450
+ '--up-tips-color': resolvedTipsColor,
451
+ '--up-light-color': resolvedLightColor,
452
+ '--up-border-color': resolvedBorderColor,
453
+ '--up-bg-color': resolvedBgColor,
454
+ '--up-hover-bg-color': hoverBgColor,
455
+ '--up-disabled-color': resolvedDisabledColor,
456
+ '--up-primary': resolvedPrimary,
457
+ '--up-primary-dark': resolvedPrimaryDark,
458
+ '--up-primary-disabled': resolvedPrimaryDisabled,
459
+ '--up-primary-light': resolvedPrimaryLight,
460
+ '--up-warning': resolvedWarning,
461
+ '--up-warning-dark': resolvedWarningDark,
462
+ '--up-warning-disabled': resolvedWarningDisabled,
463
+ '--up-warning-light': resolvedWarningLight,
464
+ '--up-success': resolvedSuccess,
465
+ '--up-success-dark': resolvedSuccessDark,
466
+ '--up-success-disabled': resolvedSuccessDisabled,
467
+ '--up-success-light': resolvedSuccessLight,
468
+ '--up-error': resolvedError,
469
+ '--up-error-dark': resolvedErrorDark,
470
+ '--up-error-disabled': resolvedErrorDisabled,
471
+ '--up-error-light': resolvedErrorLight,
472
+ '--up-info': resolvedInfo,
473
+ '--up-info-dark': resolvedInfoDark,
474
+ '--up-info-disabled': resolvedInfoDisabled,
475
+ '--up-info-light': resolvedInfoLight,
476
+ '--up-page-bg-color': pageBgColor,
477
+ '--up-card-bg-color': isDark ? '#1c1c1e' : '#ffffff',
478
+ '--up-navbar-bg-color': navbarBgColor
479
+ }
480
+ const extraVars = {}
481
+ Object.keys(runtimeColorMap).forEach((key) => {
482
+ if (typeof key !== 'string') return
483
+ const isThemeToken = key.indexOf('up-') === 0 || key.indexOf('u-') === 0
484
+ if (!isThemeToken) return
485
+ const cssVarName = `--${key}`
486
+ if (Object.prototype.hasOwnProperty.call(coreVars, cssVarName)) return
487
+ const value = runtimeColorMap[key]
488
+ if (typeof value === 'string' && value) {
489
+ extraVars[cssVarName] = value
490
+ }
491
+ })
492
+ return {
493
+ ...coreVars,
494
+ ...defaultExtraVars,
495
+ ...buildAliasCssVars(defaultExtraVars),
496
+ ...extraVars,
497
+ ...buildAliasCssVars(extraVars)
498
+ }
499
+ }
500
+
501
+ export function getThemeVars(mode) {
502
+ if (mode) {
503
+ return buildThemeCssVars(getThemeColorsByMode(mode), mode)
504
+ }
505
+ if (themeState.vars && Object.keys(themeState.vars).length > 0) {
506
+ return { ...themeState.vars }
507
+ }
508
+ return buildThemeCssVars(getThemeColorsByMode(themeState.mode), themeState.mode)
509
+ }
510
+
511
+ function syncThemeToH5(mode) {
512
+ // #ifdef H5
513
+ if (typeof document !== 'undefined' && document.documentElement) {
514
+ document.documentElement.setAttribute('data-up-theme', mode)
515
+ }
516
+ // #endif
517
+ }
518
+
519
+ function hasActiveRuntimePage() {
520
+ try {
521
+ if (typeof getCurrentPages === 'function') {
522
+ const pages = getCurrentPages()
523
+ return Array.isArray(pages) && pages.length > 0
524
+ }
525
+ } catch (e) {}
526
+ return false
527
+ }
528
+
529
+ function trySetNavigationBarColor(options) {
530
+ if (typeof uni === 'undefined' || typeof uni.setNavigationBarColor !== 'function') return
531
+ if (!hasActiveRuntimePage()) return
532
+ try {
533
+ const result = uni.setNavigationBarColor(options)
534
+ if (result && typeof result.catch === 'function') {
535
+ result.catch(() => {})
536
+ }
537
+ } catch (e) {}
538
+ }
539
+
540
+ function applyNativeThemeUI(mode, themeColors, themeVars = {}) {
541
+ if (typeof uni === 'undefined') return
542
+ if (config.nativeThemeSync !== true) return
543
+ const isDark = normalizeThemeMode(mode) === 'dark'
544
+ const pageBg = themeColors?.bgColor || (isDark ? '#1f1f1f' : '#f3f4f6')
545
+ const navBg = themeVars?.['--up-navbar-bg-color']
546
+ || themeVars?.['--u-navbar-bg-color']
547
+ || config.color?.['up-navbar-bg-color']
548
+ || config.color?.['u-navbar-bg-color']
549
+ || (isDark ? '#1c1c1e' : '#ffffff')
550
+ trySetNavigationBarColor({
551
+ frontColor: isDark ? '#ffffff' : '#000000',
552
+ backgroundColor: navBg,
553
+ animation: {
554
+ duration: 0,
555
+ timingFunc: 'linear'
556
+ }
557
+ })
558
+ if (typeof uni.setBackgroundColor === 'function') {
559
+ uni.setBackgroundColor({
560
+ backgroundColor: pageBg,
561
+ backgroundColorTop: pageBg,
562
+ backgroundColorBottom: pageBg
563
+ })
564
+ }
565
+ if (typeof uni.setTabBarStyle === 'function') {
566
+ uni.setTabBarStyle({
567
+ color: isDark ? '#8e8e93' : '#909399',
568
+ selectedColor: isDark ? '#f2f2f7' : '#303133',
569
+ backgroundColor: isDark ? '#111111' : '#ffffff',
570
+ borderStyle: isDark ? 'white' : 'black'
571
+ })
572
+ }
573
+ }
574
+
575
+ function applyTheme(mode = 'light') {
576
+ const themeMode = normalizeThemeMode(mode)
577
+ const themeColors = getThemeColorsByMode(themeMode)
578
+ const themeVars = buildThemeCssVars(themeColors, themeMode)
579
+ index.shallowMerge(color, {
580
+ primary: themeColors.primary,
581
+ primaryDark: themeColors.primaryDark,
582
+ primaryDisabled: themeColors.primaryDisabled,
583
+ primaryLight: themeColors.primaryLight,
584
+ info: themeColors.info,
585
+ infoDark: themeColors.infoDark,
586
+ infoDisabled: themeColors.infoDisabled,
587
+ infoLight: themeColors.infoLight,
588
+ default: themeColors.info,
589
+ warning: themeColors.warning,
590
+ warningDark: themeColors.warningDark,
591
+ warningDisabled: themeColors.warningDisabled,
592
+ warningLight: themeColors.warningLight,
593
+ error: themeColors.error,
594
+ errorDark: themeColors.errorDark,
595
+ errorDisabled: themeColors.errorDisabled,
596
+ errorLight: themeColors.errorLight,
597
+ success: themeColors.success,
598
+ successDark: themeColors.successDark,
599
+ successDisabled: themeColors.successDisabled,
600
+ successLight: themeColors.successLight,
601
+ mainColor: themeColors.mainColor,
602
+ contentColor: themeColors.contentColor,
603
+ tipsColor: themeColors.tipsColor,
604
+ lightColor: themeColors.lightColor,
605
+ borderColor: themeColors.borderColor,
606
+ bgColor: themeColors.bgColor,
607
+ disabledColor: themeColors.disabledColor
608
+ })
609
+ index.shallowMerge(config.color, buildConfigColorMap(themeColors))
610
+ config.themeMode = themeMode
611
+ themeState.preference = currentThemePreference
612
+ themeState.mode = themeMode
613
+ themeState.vars = { ...themeVars }
614
+ themeState.version = Number(themeState.version || 0) + 1
615
+ syncThemeToH5(themeMode)
616
+ applyNativeThemeUI(themeMode, themeColors, themeVars)
617
+
618
+ if (typeof uni !== 'undefined' && uni.$u && uni.$u.theme) {
619
+ uni.$u.theme.mode = themeState.mode
620
+ if (Object.prototype.hasOwnProperty.call(uni.$u.theme, 'colors')) {
621
+ delete uni.$u.theme.colors
622
+ }
623
+ uni.$u.theme.vars = { ...themeState.vars }
624
+ uni.$u.theme.version = themeState.version
625
+ }
626
+ if (typeof uni !== 'undefined' && typeof uni.$emit === 'function') {
627
+ uni.$emit('uThemeChange', {
628
+ mode: themeState.mode,
629
+ colors: { ...themeColors },
630
+ version: themeState.version,
631
+ vars: { ...themeState.vars }
632
+ })
633
+ }
634
+ return themeState
635
+ }
636
+
637
+ export function setTheme(mode = 'light') {
638
+ currentThemePreference = normalizeThemeMode(mode)
639
+ writeThemePreferenceToStorage(currentThemePreference)
640
+ return applyTheme(currentThemePreference)
641
+ }
642
+
643
+ export function setThemePreference(mode = THEME_MODE_SYSTEM) {
644
+ currentThemePreference = normalizeThemePreference(mode)
645
+ writeThemePreferenceToStorage(currentThemePreference)
646
+ if (currentThemePreference === THEME_MODE_SYSTEM) {
647
+ return applyTheme(getSystemTheme())
648
+ }
649
+ return applyTheme(currentThemePreference)
650
+ }
651
+
652
+ export function getThemePreference() {
653
+ return currentThemePreference
654
+ }
655
+
656
+ export function refreshThemeFromConfig() {
657
+ cachedLightThemeColors = getCurrentLightThemeColors()
658
+ if (themeState.version > 0) {
659
+ applyTheme(themeState.mode)
660
+ }
661
+ }
662
+
663
+ export function initThemeSystem() {
664
+ if (typeof uni === 'undefined') return
665
+ if (!cachedLightThemeColors) {
666
+ cachedLightThemeColors = getCurrentLightThemeColors()
667
+ }
668
+ currentThemePreference = readThemePreferenceFromStorage()
669
+ if (currentThemePreference === THEME_MODE_SYSTEM) {
670
+ applyTheme(getSystemTheme())
671
+ } else {
672
+ applyTheme(currentThemePreference)
673
+ }
674
+ if (!hasRegisterThemeListener && typeof uni.onThemeChange === 'function') {
675
+ uni.onThemeChange((res = {}) => {
676
+ if (currentThemePreference === THEME_MODE_SYSTEM) {
677
+ applyTheme(res.theme)
678
+ }
679
+ })
680
+ hasRegisterThemeListener = true
681
+ }
682
+ }
File without changes
File without changes
File without changes
File without changes