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,44 @@
1
+ import { MagicString } from 'vue/compiler-sfc'
2
+
3
+ import { parseSFC } from './utils.js'
4
+
5
+ export async function registerUpApp(
6
+ code,
7
+ fileName = 'App.up',
8
+ rootToastHostPath = './uni_modules/uview-plus/libs/root/root-toast-host.vue'
9
+ ) {
10
+ const ms = new MagicString(code)
11
+
12
+ const importCode = `import GlobalUpRoot from "./${fileName}.vue";
13
+ import UpRootToastHost from "${rootToastHostPath}";`
14
+ const vueUseComponentCode = 'app.component("global-up-root", GlobalUpRoot);\napp.component("ku-root-toast-host", UpRootToastHost);'
15
+
16
+ ms.prepend(`${importCode}\n`).replace(
17
+ /(createApp[\s\S]*?)(return\s\{\s*app)/,
18
+ `$1${vueUseComponentCode}\n$2`,
19
+ )
20
+
21
+ return ms
22
+ }
23
+
24
+ export async function rebuildUpApp(code, enabledVirtualHost = false) {
25
+ const ms = new MagicString(code)
26
+ const rootTagNameRE = /<(UpRootView|up-root-view)(?:\s*\/>|><\/\1>)/
27
+ ms.replace(rootTagNameRE, '<slot />\n <ku-root-toast-host />')
28
+
29
+ if (enabledVirtualHost) {
30
+ const sfc = await parseSFC(code)
31
+ if (sfc.script) {
32
+ return ms
33
+ }
34
+ const langType = sfc.scriptSetup?.lang
35
+ ms.append(`<script ${langType ? `lang="${langType}"` : ''}>
36
+ export default {
37
+ options: {
38
+ virtualHost: true,
39
+ }
40
+ }\n</script>`)
41
+ }
42
+
43
+ return ms
44
+ }
@@ -0,0 +1,11 @@
1
+ // Compatibility shim for stale incremental build caches.
2
+ // New root integration no longer depends on this file.
3
+
4
+ export function createGlobalUpRoot(AppRootComponent) {
5
+ return AppRootComponent
6
+ }
7
+
8
+ export default {
9
+ createGlobalUpRoot,
10
+ }
11
+
@@ -0,0 +1,115 @@
1
+ import { existsSync, readFileSync } from 'node:fs'
2
+ import { extname, join } from 'node:path'
3
+ import process from 'node:process'
4
+
5
+ import { parse as VueParser } from 'vue/compiler-sfc'
6
+ import { normalizePath } from 'vite'
7
+
8
+ function stripJsonComments(jsonText) {
9
+ return jsonText
10
+ .replace(/\/\*[\s\S]*?\*\//g, '')
11
+ .replace(/(^|[^:\\])\/\/.*$/gm, '$1')
12
+ }
13
+
14
+ function parseJsonc(jsonText) {
15
+ const withoutComments = stripJsonComments(jsonText)
16
+ const withoutTrailingComma = withoutComments.replace(/,\s*([}\]])/g, '$1')
17
+ return JSON.parse(withoutTrailingComma)
18
+ }
19
+
20
+ export async function parseSFC(code) {
21
+ try {
22
+ return VueParser(code, { pad: 'space' }).descriptor
23
+ } catch {
24
+ throw new Error('[@up-root] Vue version must support compiler-sfc parser.')
25
+ }
26
+ }
27
+
28
+ const PAGE_FILE_EXTS = ['.vue', '.nvue', '.uvue']
29
+
30
+ export function formatPagePath(root, path) {
31
+ const joinedPath = join(root, path)
32
+ const pathExt = extname(joinedPath)
33
+
34
+ if (pathExt) {
35
+ return normalizePath(joinedPath)
36
+ }
37
+
38
+ const pageFilePath = PAGE_FILE_EXTS
39
+ .map(fileExt => `${joinedPath}${fileExt}`)
40
+ .find(filePath => existsSync(filePath))
41
+
42
+ return normalizePath(pageFilePath || `${joinedPath}.vue`)
43
+ }
44
+
45
+ export function loadPagesJson(path, rootPath) {
46
+ const pagesJsonRaw = readFileSync(path, 'utf-8')
47
+ const parsed = parseJsonc(pagesJsonRaw) || {}
48
+ const pages = parsed.pages || []
49
+ const subPackages = parsed.subPackages || []
50
+
51
+ return [
52
+ ...pages.map((page) => formatPagePath(rootPath, page.path)),
53
+ ...subPackages
54
+ .map(({ pages: subPages = [], root = '' }) => {
55
+ return subPages.map((page) => formatPagePath(join(rootPath, root), page.path))
56
+ })
57
+ .flat(),
58
+ ]
59
+ }
60
+
61
+ export function toKebabCase(str) {
62
+ return str
63
+ .replace(/([a-z])([A-Z])/g, '$1-$2')
64
+ .replace(/[_\s]+/g, '-')
65
+ .toLowerCase()
66
+ }
67
+
68
+ export function toPascalCase(str) {
69
+ return str
70
+ .replace(/(^\w|-+\w)/g, (match) => match.toUpperCase().replace(/-/g, ''))
71
+ }
72
+
73
+ export function findNode(sfc, rawTagName) {
74
+ const templateSource = sfc.template?.content
75
+ if (!templateSource) return
76
+
77
+ let tagName = ''
78
+ if (templateSource.includes(`<${toKebabCase(rawTagName)}`)) {
79
+ tagName = toKebabCase(rawTagName)
80
+ } else if (templateSource.includes(`<${toPascalCase(rawTagName)}`)) {
81
+ tagName = toPascalCase(rawTagName)
82
+ }
83
+ if (!tagName) return
84
+
85
+ const nodeAst = sfc.template?.ast
86
+ if (!nodeAst) return
87
+
88
+ const traverse = (nodes) => {
89
+ for (const node of nodes) {
90
+ if (node.type === 1) {
91
+ if (node.tag === tagName) return node
92
+ if (node.children?.length) {
93
+ const found = traverse(node.children)
94
+ if (found) return found
95
+ }
96
+ }
97
+ }
98
+ }
99
+
100
+ return traverse(nodeAst.children)
101
+ }
102
+
103
+ const platform = process.env.UNI_PLATFORM
104
+
105
+ export function normalizePlatformPath(id) {
106
+ const idExt = extname(id)
107
+ if (idExt !== '.vue') return id
108
+ if (!id.includes(`.${platform}.`)) return id
109
+ return id.replace(`.${platform}.`, '.')
110
+ }
111
+
112
+ export function toArray(value) {
113
+ if (!value) return []
114
+ return Array.isArray(value) ? value : [value]
115
+ }
@@ -0,0 +1,392 @@
1
+ const THEME_MODE_STORAGE_KEY = 'u-theme-mode'
2
+
3
+ const FALLBACK_THEME_VARS = {
4
+ light: {
5
+ '--up-main-color': 'var(--up-light-main-color, #303133)',
6
+ '--up-content-color': 'var(--up-light-content-color, #606266)',
7
+ '--up-tips-color': 'var(--up-light-tips-color, #909193)',
8
+ '--up-light-color': 'var(--up-light-light-color, #c0c4cc)',
9
+ '--up-border-color': 'var(--up-light-border-color, #dadbde)',
10
+ '--up-bg-color': 'var(--up-light-bg-color, #f3f4f6)',
11
+ '--up-hover-bg-color': '#e7ebf0',
12
+ '--up-page-bg-color': '#f3f4f6',
13
+ '--up-card-bg-color': '#ffffff',
14
+ '--up-navbar-bg-color': '#ffffff',
15
+ '--up-table2-header-bg-color': '#f5f7fa',
16
+ '--up-table2-zebra-bg-color': '#fafafa',
17
+ '--up-table2-highlight-bg-color': '#f5f7fa',
18
+ '--up-gap-bg-color': '#f3f4f6',
19
+ '--up-skeleton-bg-color': '#f1f2f4',
20
+ '--up-skeleton-shimmer-color': '#e6e6e6',
21
+ '--up-swipe-action-button-bg-color': '#c7c6cd',
22
+ '--up-index-list-indicator-bg-color': '#c9c9c9',
23
+ '--up-calendar-month-mark-color': 'rgba(231, 232, 234, 0.83)',
24
+ '--up-disabled-color': 'var(--up-light-disabled-color, #c8c9cc)',
25
+ '--up-primary': 'var(--up-light-primary, #3c9cff)',
26
+ '--up-primary-dark': 'var(--up-light-primary-dark, #398ade)',
27
+ '--up-primary-disabled': 'var(--up-light-primary-disabled, #9acafc)',
28
+ '--up-primary-light': 'var(--up-light-primary-light, #ecf5ff)',
29
+ '--up-warning': 'var(--up-light-warning, #f9ae3d)',
30
+ '--up-warning-dark': 'var(--up-light-warning-dark, #f1a532)',
31
+ '--up-warning-disabled': 'var(--up-light-warning-disabled, #f9d39b)',
32
+ '--up-warning-light': 'var(--up-light-warning-light, #fdf6ec)',
33
+ '--up-success': 'var(--up-light-success, #5ac725)',
34
+ '--up-success-dark': 'var(--up-light-success-dark, #53c21d)',
35
+ '--up-success-disabled': 'var(--up-light-success-disabled, #a9e08f)',
36
+ '--up-success-light': 'var(--up-light-success-light, #f5fff0)',
37
+ '--up-error': 'var(--up-light-error, #f56c6c)',
38
+ '--up-error-dark': 'var(--up-light-error-dark, #e45656)',
39
+ '--up-error-disabled': 'var(--up-light-error-disabled, #f7b2b2)',
40
+ '--up-error-light': 'var(--up-light-error-light, #fef0f0)',
41
+ '--up-info': 'var(--up-light-info, #909399)',
42
+ '--up-info-dark': 'var(--up-light-info-dark, #767a82)',
43
+ '--up-info-disabled': 'var(--up-light-info-disabled, #c4c6c9)',
44
+ '--up-info-light': 'var(--up-light-info-light, #f4f4f5)'
45
+ },
46
+ dark: {
47
+ '--up-main-color': '#f5f5f5',
48
+ '--up-content-color': '#d1d5db',
49
+ '--up-tips-color': '#9ca3af',
50
+ '--up-light-color': '#6b7280',
51
+ '--up-border-color': '#3a3a3c',
52
+ '--up-bg-color': '#1f1f1f',
53
+ '--up-hover-bg-color': '#343741',
54
+ '--up-page-bg-color': '#1f1f1f',
55
+ '--up-card-bg-color': '#1c1c1e',
56
+ '--up-navbar-bg-color': '#1c1c1e',
57
+ '--up-table2-header-bg-color': '#2a2d33',
58
+ '--up-table2-zebra-bg-color': '#23262b',
59
+ '--up-table2-highlight-bg-color': '#2f3440',
60
+ '--up-gap-bg-color': '#111111',
61
+ '--up-skeleton-bg-color': '#2f3135',
62
+ '--up-skeleton-shimmer-color': 'rgba(255, 255, 255, 0.12)',
63
+ '--up-swipe-action-button-bg-color': '#4b5563',
64
+ '--up-index-list-indicator-bg-color': '#4b5563',
65
+ '--up-calendar-month-mark-color': 'rgba(255, 255, 255, 0.04)',
66
+ '--up-disabled-color': '#4b5563',
67
+ '--up-primary': '#3c9cff',
68
+ '--up-primary-dark': '#5aa8ff',
69
+ '--up-primary-disabled': '#4c6f92',
70
+ '--up-primary-light': '#10243a',
71
+ '--up-warning': '#f9ae3d',
72
+ '--up-warning-dark': '#ffbf66',
73
+ '--up-warning-disabled': '#8a6a3a',
74
+ '--up-warning-light': '#3d2f1b',
75
+ '--up-success': '#5ac725',
76
+ '--up-success-dark': '#7ad94b',
77
+ '--up-success-disabled': '#5f7f4f',
78
+ '--up-success-light': '#1f3316',
79
+ '--up-error': '#f56c6c',
80
+ '--up-error-dark': '#ff8a8a',
81
+ '--up-error-disabled': '#8d5858',
82
+ '--up-error-light': '#3a2222',
83
+ '--up-info': '#909399',
84
+ '--up-info-dark': '#b0b3b8',
85
+ '--up-info-disabled': '#5f6368',
86
+ '--up-info-light': '#2f3238'
87
+ }
88
+ }
89
+
90
+ const THEME_COLOR_SYNC_MAP = {
91
+ '--up-main-color': 'mainColor',
92
+ '--up-content-color': 'contentColor',
93
+ '--up-tips-color': 'tipsColor',
94
+ '--up-light-color': 'lightColor',
95
+ '--up-border-color': 'borderColor',
96
+ '--up-bg-color': 'bgColor',
97
+ '--up-disabled-color': 'disabledColor',
98
+ '--up-primary': 'primary',
99
+ '--up-primary-dark': 'primaryDark',
100
+ '--up-primary-disabled': 'primaryDisabled',
101
+ '--up-primary-light': 'primaryLight',
102
+ '--up-warning': 'warning',
103
+ '--up-warning-dark': 'warningDark',
104
+ '--up-warning-disabled': 'warningDisabled',
105
+ '--up-warning-light': 'warningLight',
106
+ '--up-success': 'success',
107
+ '--up-success-dark': 'successDark',
108
+ '--up-success-disabled': 'successDisabled',
109
+ '--up-success-light': 'successLight',
110
+ '--up-error': 'error',
111
+ '--up-error-dark': 'errorDark',
112
+ '--up-error-disabled': 'errorDisabled',
113
+ '--up-error-light': 'errorLight',
114
+ '--up-info': 'info',
115
+ '--up-info-dark': 'infoDark',
116
+ '--up-info-disabled': 'infoDisabled',
117
+ '--up-info-light': 'infoLight'
118
+ }
119
+
120
+ function buildFallbackAliasVars(vars) {
121
+ const aliasVars = {}
122
+ Object.keys(vars).forEach((key) => {
123
+ if (typeof key === 'string' && key.indexOf('--up-') === 0) {
124
+ aliasVars[key.replace('--up-', '--u-')] = vars[key]
125
+ }
126
+ })
127
+ return aliasVars
128
+ }
129
+
130
+ function getRuntimeU(upU) {
131
+ if (upU) return upU
132
+ if (typeof uni !== 'undefined') return uni.$u
133
+ return null
134
+ }
135
+
136
+ function hasActiveRuntimePage() {
137
+ try {
138
+ if (typeof getCurrentPages === 'function') {
139
+ const pages = getCurrentPages()
140
+ return Array.isArray(pages) && pages.length > 0
141
+ }
142
+ } catch (e) {}
143
+ return false
144
+ }
145
+
146
+ function trySetNavigationBarColor(options) {
147
+ if (typeof uni === 'undefined' || typeof uni.setNavigationBarColor !== 'function') return
148
+ if (!hasActiveRuntimePage()) return
149
+ try {
150
+ const result = uni.setNavigationBarColor(options)
151
+ if (result && typeof result.catch === 'function') {
152
+ result.catch(() => {})
153
+ }
154
+ } catch (e) {}
155
+ }
156
+
157
+ function normalizeThemeMode(theme = 'light') {
158
+ return theme === 'dark' ? 'dark' : 'light'
159
+ }
160
+
161
+ function normalizeThemePreference(mode = 'system') {
162
+ return mode === 'dark' || mode === 'light' ? mode : 'system'
163
+ }
164
+
165
+ function getFallbackSystemTheme() {
166
+ let theme = 'light'
167
+ try {
168
+ if (typeof uni !== 'undefined' && typeof uni.getAppBaseInfo === 'function') {
169
+ const appBaseInfo = uni.getAppBaseInfo() || {}
170
+ if (appBaseInfo.theme) theme = appBaseInfo.theme
171
+ }
172
+ if (typeof uni !== 'undefined' && typeof uni.getSystemInfoSync === 'function') {
173
+ const systemInfo = uni.getSystemInfoSync() || {}
174
+ if (systemInfo.theme) theme = systemInfo.theme
175
+ }
176
+ } catch (e) {
177
+ theme = 'light'
178
+ }
179
+ return normalizeThemeMode(theme)
180
+ }
181
+
182
+ function getFallbackThemePreference() {
183
+ try {
184
+ if (typeof uni !== 'undefined' && typeof uni.getStorageSync === 'function') {
185
+ const preference = uni.getStorageSync(THEME_MODE_STORAGE_KEY)
186
+ return normalizeThemePreference(preference)
187
+ }
188
+ } catch (e) {}
189
+ return 'system'
190
+ }
191
+
192
+ function getFallbackThemeMode() {
193
+ const preference = getFallbackThemePreference()
194
+ if (preference === 'dark' || preference === 'light') return preference
195
+ return getFallbackSystemTheme()
196
+ }
197
+
198
+ function getFallbackThemeVarsByMode(mode) {
199
+ const vars = FALLBACK_THEME_VARS[normalizeThemeMode(mode)] || FALLBACK_THEME_VARS.light
200
+ return {
201
+ ...vars,
202
+ ...buildFallbackAliasVars(vars)
203
+ }
204
+ }
205
+
206
+ function getFallbackThemeVars(upU) {
207
+ const mode = getThemeIsDark(upU) ? 'dark' : 'light'
208
+ return getFallbackThemeVarsByMode(mode)
209
+ }
210
+
211
+ function syncRuntimeColor(runtimeU, vars) {
212
+ if (!runtimeU || !runtimeU.color) return
213
+ Object.keys(THEME_COLOR_SYNC_MAP).forEach((token) => {
214
+ const field = THEME_COLOR_SYNC_MAP[token]
215
+ runtimeU.color[field] = vars[token]
216
+ })
217
+ }
218
+
219
+ export function syncThemeRuntimeFromStorage(upU) {
220
+ const runtimeU = getRuntimeU(upU)
221
+ if (!runtimeU || !runtimeU.theme) return runtimeU?.theme
222
+ const preference = getFallbackThemePreference()
223
+ const mode = preference === 'system' ? getFallbackSystemTheme() : preference
224
+ const vars = getFallbackThemeVarsByMode(mode)
225
+ const shouldUpdate = runtimeU.theme.preference !== preference || runtimeU.theme.mode !== mode
226
+ if (shouldUpdate && typeof runtimeU.setThemePreference === 'function') {
227
+ return runtimeU.setThemePreference(preference) || runtimeU.theme
228
+ }
229
+ runtimeU.theme.preference = preference
230
+ runtimeU.theme.mode = mode
231
+ runtimeU.theme.vars = {
232
+ ...vars,
233
+ ...(runtimeU.theme.vars && !shouldUpdate ? runtimeU.theme.vars : {})
234
+ }
235
+ if (shouldUpdate) {
236
+ runtimeU.theme.version = Number(runtimeU.theme.version || 0) + 1
237
+ }
238
+ syncRuntimeColor(runtimeU, runtimeU.theme.vars)
239
+ return runtimeU.theme
240
+ }
241
+
242
+ export function getThemeIsDark(upU) {
243
+ const runtimeMode = getRuntimeU(upU)?.theme?.mode
244
+ if (runtimeMode) return runtimeMode === 'dark'
245
+ return getFallbackThemeMode() === 'dark'
246
+ }
247
+
248
+ export function getThemeVarsForStyle(upU) {
249
+ const runtimeU = getRuntimeU(upU)
250
+ if (runtimeU && typeof runtimeU.getThemeVars === 'function') {
251
+ return runtimeU.getThemeVars()
252
+ }
253
+ return getFallbackThemeVars(runtimeU)
254
+ }
255
+
256
+ export function getThemeVar(varName, fallbackColor, upU) {
257
+ const runtimeU = getRuntimeU(upU)
258
+ const themeVars = runtimeU?.theme?.vars
259
+ if (themeVars && Object.prototype.hasOwnProperty.call(themeVars, varName)) {
260
+ return themeVars[varName]
261
+ }
262
+ if (typeof varName === 'string') {
263
+ const aliasVarName = varName.indexOf('--up-') === 0
264
+ ? varName.replace('--up-', '--u-')
265
+ : (varName.indexOf('--u-') === 0 ? varName.replace('--u-', '--up-') : '')
266
+ if (aliasVarName && themeVars && Object.prototype.hasOwnProperty.call(themeVars, aliasVarName)) {
267
+ return themeVars[aliasVarName]
268
+ }
269
+ const runtimeColorMap = runtimeU?.config?.color || {}
270
+ const colorTokenKey = varName.indexOf('--') === 0 ? varName.slice(2) : varName
271
+ if (Object.prototype.hasOwnProperty.call(runtimeColorMap, colorTokenKey)) {
272
+ return runtimeColorMap[colorTokenKey]
273
+ }
274
+ const aliasColorTokenKey = colorTokenKey.indexOf('up-') === 0
275
+ ? colorTokenKey.replace('up-', 'u-')
276
+ : (colorTokenKey.indexOf('u-') === 0 ? colorTokenKey.replace('u-', 'up-') : '')
277
+ if (aliasColorTokenKey && Object.prototype.hasOwnProperty.call(runtimeColorMap, aliasColorTokenKey)) {
278
+ return runtimeColorMap[aliasColorTokenKey]
279
+ }
280
+ }
281
+ if (runtimeU && typeof runtimeU.getThemeVars === 'function') {
282
+ const vars = runtimeU.getThemeVars()
283
+ if (vars && Object.prototype.hasOwnProperty.call(vars, varName)) {
284
+ return vars[varName]
285
+ }
286
+ }
287
+ const fallbackVars = getFallbackThemeVars(runtimeU)
288
+ if (fallbackVars && Object.prototype.hasOwnProperty.call(fallbackVars, varName)) {
289
+ return fallbackVars[varName]
290
+ }
291
+ return typeof fallbackColor !== 'undefined' ? fallbackColor : ''
292
+ }
293
+
294
+ export function getThemeCssVar(varName, fallbackColor) {
295
+ if (typeof fallbackColor === 'undefined') {
296
+ return `var(${varName})`
297
+ }
298
+ return `var(${varName}, ${fallbackColor})`
299
+ }
300
+
301
+ export function getThemePageStyle(upU, preferCssVars = false) {
302
+ const runtimeU = getRuntimeU(upU)
303
+ const isDark = getThemeIsDark(runtimeU)
304
+ const fallbackBg = isDark ? '#1f1f1f' : (runtimeU?.color?.bgColor || '#f3f4f6')
305
+ if (preferCssVars) {
306
+ return {
307
+ ...getThemeVarsForStyle(runtimeU),
308
+ minHeight: '100vh',
309
+ backgroundColor: `var(--up-page-bg-color, var(--up-bg-color, ${fallbackBg}))`
310
+ }
311
+ }
312
+ return {
313
+ backgroundColor: getThemeVar(
314
+ '--up-page-bg-color',
315
+ getThemeVar('--up-bg-color', fallbackBg, runtimeU),
316
+ runtimeU
317
+ )
318
+ }
319
+ }
320
+
321
+ export function getThemeCardStyle(upU, preferCssVars = false) {
322
+ const runtimeU = getRuntimeU(upU)
323
+ const isDark = getThemeIsDark(runtimeU)
324
+ const fallbackCard = isDark ? '#1c1c1e' : '#ffffff'
325
+ const fallbackBorder = runtimeU?.color?.borderColor || '#dadbde'
326
+ if (preferCssVars) {
327
+ return {
328
+ backgroundColor: `var(--up-card-bg-color, ${fallbackCard})`,
329
+ borderColor: `var(--up-border-color, ${fallbackBorder})`
330
+ }
331
+ }
332
+ return {
333
+ backgroundColor: getThemeVar('--up-card-bg-color', fallbackCard, runtimeU),
334
+ borderColor: getThemeVar('--up-border-color', fallbackBorder, runtimeU)
335
+ }
336
+ }
337
+
338
+ export function getThemeTabBarStyle(upU) {
339
+ const runtimeU = getRuntimeU(upU)
340
+ const isDark = getThemeIsDark(runtimeU)
341
+ return {
342
+ color: isDark ? '#8e8e93' : '#909399',
343
+ selectedColor: isDark ? '#f2f2f7' : '#303133',
344
+ backgroundColor: isDark ? '#111111' : '#ffffff',
345
+ borderStyle: isDark ? 'white' : 'black'
346
+ }
347
+ }
348
+
349
+ export function applyNativeThemeUI(upU) {
350
+ if (typeof uni === 'undefined') return
351
+ const runtimeU = getRuntimeU(upU)
352
+ if (runtimeU?.config?.nativeThemeSync !== true) return
353
+ const isDark = getThemeIsDark(runtimeU)
354
+ const fallbackBg = isDark ? '#1f1f1f' : (runtimeU?.color?.bgColor || '#f3f4f6')
355
+ const pageBg = getThemeVar(
356
+ '--up-page-bg-color',
357
+ getThemeVar('--up-bg-color', fallbackBg, runtimeU),
358
+ runtimeU
359
+ )
360
+ const navBg = getThemeVar(
361
+ '--up-navbar-bg-color',
362
+ isDark ? '#1c1c1e' : '#ffffff',
363
+ runtimeU
364
+ )
365
+ trySetNavigationBarColor({
366
+ frontColor: isDark ? '#ffffff' : '#000000',
367
+ backgroundColor: navBg,
368
+ animation: {
369
+ duration: 0,
370
+ timingFunc: 'linear'
371
+ }
372
+ })
373
+ if (typeof uni.setBackgroundColor === 'function') {
374
+ uni.setBackgroundColor({
375
+ backgroundColor: pageBg,
376
+ backgroundColorTop: pageBg,
377
+ backgroundColorBottom: pageBg
378
+ })
379
+ }
380
+ if (typeof uni.setTabBarStyle === 'function') {
381
+ uni.setTabBarStyle(getThemeTabBarStyle(runtimeU))
382
+ }
383
+ }
384
+
385
+ export function applyNativeThemeUIDeferred(upU, delay = 30) {
386
+ applyNativeThemeUI(upU)
387
+ if (typeof setTimeout === 'function') {
388
+ setTimeout(() => {
389
+ applyNativeThemeUI(upU)
390
+ }, delay)
391
+ }
392
+ }