@tuya-sat/sdf-main-sdk 0.0.1-beta.1

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 (147) hide show
  1. package/.vscode/settings.json +5 -0
  2. package/README.md +1 -0
  3. package/antd.less.overwrite.js +56 -0
  4. package/color.js +140 -0
  5. package/dark-variable.less +1449 -0
  6. package/package.json +74 -0
  7. package/scripts/gen-localize-file.mjs +56 -0
  8. package/src/App.less +156 -0
  9. package/src/App.tsx +87 -0
  10. package/src/api/index.ts +52 -0
  11. package/src/api/req.ts +23 -0
  12. package/src/api/res.ts +29 -0
  13. package/src/api/urls.ts +30 -0
  14. package/src/api/utils.ts +41 -0
  15. package/src/assets/imgs/404.svg +194 -0
  16. package/src/assets/imgs/reLogin.png +0 -0
  17. package/src/components/404/index.tsx +44 -0
  18. package/src/components/500/index.tsx +49 -0
  19. package/src/components/BCustomNav/index.module.less +17 -0
  20. package/src/components/BCustomNav/index.tsx +108 -0
  21. package/src/components/BForgot/index.module.less +5 -0
  22. package/src/components/BForgot/index.tsx +96 -0
  23. package/src/components/BHeaderUser/account.png +0 -0
  24. package/src/components/BHeaderUser/app-scan-en.png +0 -0
  25. package/src/components/BHeaderUser/app-scan-zh.png +0 -0
  26. package/src/components/BHeaderUser/app-scan.png +0 -0
  27. package/src/components/BHeaderUser/components/BSwitchLang/index.module.less +6 -0
  28. package/src/components/BHeaderUser/components/BSwitchLang/index.tsx +56 -0
  29. package/src/components/BHeaderUser/components/Badge/components/Notice/Drawer/Content.tsx +199 -0
  30. package/src/components/BHeaderUser/components/Badge/components/Notice/Drawer/index.module.less +11 -0
  31. package/src/components/BHeaderUser/components/Badge/components/Notice/Drawer/index.tsx +27 -0
  32. package/src/components/BHeaderUser/components/Badge/components/Notice/hooks.ts +104 -0
  33. package/src/components/BHeaderUser/components/Badge/components/Notice/index.module.less +70 -0
  34. package/src/components/BHeaderUser/components/Badge/components/Notice/index.tsx +184 -0
  35. package/src/components/BHeaderUser/components/Badge/components/Notice/table/index.tsx +184 -0
  36. package/src/components/BHeaderUser/components/Badge/components/Notice/table/read.tsx +67 -0
  37. package/src/components/BHeaderUser/components/Badge/components/Notice/tools/index.tsx +116 -0
  38. package/src/components/BHeaderUser/components/Badge/index.module.less +99 -0
  39. package/src/components/BHeaderUser/components/Badge/index.tsx +179 -0
  40. package/src/components/BHeaderUser/index.module.less +105 -0
  41. package/src/components/BHeaderUser/index.tsx +261 -0
  42. package/src/components/BHeaderUser/logout.tsx +26 -0
  43. package/src/components/BLayout/components/Header/index.module.less +27 -0
  44. package/src/components/BLayout/components/Header/index.tsx +36 -0
  45. package/src/components/BLayout/components/Layout/empty.tsx +35 -0
  46. package/src/components/BLayout/components/Layout/emptyPage.png +0 -0
  47. package/src/components/BLayout/components/Layout/index.tsx +72 -0
  48. package/src/components/BLayout/components/Logo.tsx +6 -0
  49. package/src/components/BLayout/components/Menu/collapse.tsx +41 -0
  50. package/src/components/BLayout/components/Menu/image/close.tsx +26 -0
  51. package/src/components/BLayout/components/Menu/image/closedefault.tsx +26 -0
  52. package/src/components/BLayout/components/Menu/image/open.tsx +38 -0
  53. package/src/components/BLayout/components/Menu/image/opendefault.tsx +38 -0
  54. package/src/components/BLayout/components/Menu/index.module.less +125 -0
  55. package/src/components/BLayout/components/Menu/index.tsx +244 -0
  56. package/src/components/BLayout/components/MenuIcon.module.less +5 -0
  57. package/src/components/BLayout/components/MenuIcon.tsx +46 -0
  58. package/src/components/BLayout/components/MultiSider/index.module.less +104 -0
  59. package/src/components/BLayout/components/MultiSider/index.tsx +172 -0
  60. package/src/components/BLayout/components/Sider/index.less +64 -0
  61. package/src/components/BLayout/components/Sider/index.module.less +17 -0
  62. package/src/components/BLayout/components/Sider/index.tsx +34 -0
  63. package/src/components/BLayout/index.tsx +78 -0
  64. package/src/components/BLayoutLogin/index.module.less +65 -0
  65. package/src/components/BLayoutLogin/index.tsx +68 -0
  66. package/src/components/BLayoutLogin/login.jpg +0 -0
  67. package/src/components/BLogin/component/Clause/index.module.less +25 -0
  68. package/src/components/BLogin/component/Clause/index.tsx +58 -0
  69. package/src/components/BLogin/component/ForgotBtn/index.module.less +9 -0
  70. package/src/components/BLogin/component/ForgotBtn/index.tsx +18 -0
  71. package/src/components/BLogin/component/Password/index.tsx +39 -0
  72. package/src/components/BLogin/component/SubmitBtn/index.tsx +30 -0
  73. package/src/components/BLogin/component/TenanSpace/index.tsx +28 -0
  74. package/src/components/BLogin/component/Title/index.module.less +6 -0
  75. package/src/components/BLogin/component/Title/index.tsx +12 -0
  76. package/src/components/BLogin/component/UserName/index.tsx +48 -0
  77. package/src/components/BLogin/component/VerifyCode/index.module.less +11 -0
  78. package/src/components/BLogin/component/VerifyCode/index.tsx +165 -0
  79. package/src/components/BLogin/index.module.less +31 -0
  80. package/src/components/BLogin/index.tsx +210 -0
  81. package/src/components/BRegister/components/TenantName/index.tsx +26 -0
  82. package/src/components/BRegister/index.module.less +5 -0
  83. package/src/components/BRegister/index.tsx +71 -0
  84. package/src/components/Back/index.tsx +25 -0
  85. package/src/components/IconFont/font.js +66 -0
  86. package/src/components/IconFont/index.tsx +18 -0
  87. package/src/components/MicroComponent/Header/index.module.less +7 -0
  88. package/src/components/MicroComponent/Header/index.tsx +220 -0
  89. package/src/components/PForgot/index.tsx +10 -0
  90. package/src/components/PLogin/index.tsx +12 -0
  91. package/src/components/PRegister/index.tsx +10 -0
  92. package/src/components/PSetting/index.module.less +53 -0
  93. package/src/components/PSetting/index.tsx +420 -0
  94. package/src/constant/chargeStatus.ts +6 -0
  95. package/src/constant/imgs.ts +6 -0
  96. package/src/constant/index.ts +293 -0
  97. package/src/dark-variable.less +1449 -0
  98. package/src/global.d.ts +54 -0
  99. package/src/hooks/index.ts +133 -0
  100. package/src/index.css +1493 -0
  101. package/src/index.tsx +105 -0
  102. package/src/lang/en.json +266 -0
  103. package/src/lang/index.ts +44 -0
  104. package/src/lang/utils.ts +285 -0
  105. package/src/lang/zh.json +270 -0
  106. package/src/micro-script/theme/index.ts +29 -0
  107. package/src/micro-script/theme/theme-css/static.js +73 -0
  108. package/src/micro-script/theme/theme-css/subscriber.ts +201 -0
  109. package/src/micro-script/theme/util/index.ts +58 -0
  110. package/src/mqtt/index.ts +121 -0
  111. package/src/pages/403.tsx +18 -0
  112. package/src/pages/404.tsx +17 -0
  113. package/src/pages/expiration.tsx +23 -0
  114. package/src/pages/forgot.tsx +9 -0
  115. package/src/pages/home/index.tsx +172 -0
  116. package/src/pages/home/setting/index.tsx +7 -0
  117. package/src/pages/index.ts +50 -0
  118. package/src/pages/login.tsx +46 -0
  119. package/src/pages/register.tsx +9 -0
  120. package/src/pages/relogin/index.module.less +0 -0
  121. package/src/pages/relogin/index.tsx +54 -0
  122. package/src/plugins/index.ts +11 -0
  123. package/src/public-path.js +8 -0
  124. package/src/qiankun/globalState.ts +6 -0
  125. package/src/qiankun/index.ts +174 -0
  126. package/src/qiankun/utils/index.ts +69 -0
  127. package/src/qiankun/xhook/index.ts +193 -0
  128. package/src/reportWebVitals.ts +15 -0
  129. package/src/sentry/index.ts +33 -0
  130. package/src/sky/index.ts +57 -0
  131. package/src/theme/custom-dark.less +64 -0
  132. package/src/theme/custom-light.less +48 -0
  133. package/src/theme/index.less +327 -0
  134. package/src/theme/variable.less +13 -0
  135. package/src/utils/checkPass.ts +21 -0
  136. package/src/utils/common.ts +195 -0
  137. package/src/utils/eventBus.ts +112 -0
  138. package/src/utils/gt.js +293 -0
  139. package/src/utils/index.ts +89 -0
  140. package/src/utils/theme/base.ts +110 -0
  141. package/src/utils/theme/changeCssVariable.ts +157 -0
  142. package/src/utils/theme/changeMenuCssVariable.ts +176 -0
  143. package/src/utils/theme/index.ts +85 -0
  144. package/src/utils/theme/store.ts +37 -0
  145. package/tsconfig.json +28 -0
  146. package/typings.d.ts +10 -0
  147. package/webpack.config.js +103 -0
@@ -0,0 +1,293 @@
1
+ /* eslint-disable */
2
+ /* initGeetest 1.0.0
3
+ * 用于加载id对应的验证码库,并支持宕机模式
4
+ * 暴露 initGeetest 进行验证码的初始化
5
+ * 一般不需要用户进行修改
6
+ */
7
+ (function (global, factory) {
8
+ 'use strict';
9
+ if (typeof module === 'object' && typeof module.exports === 'object') {
10
+ // CommonJS
11
+ module.exports = global.document
12
+ ? factory(global, true)
13
+ : function (w) {
14
+ if (!w.document) {
15
+ throw new Error('Geetest requires a window with a document');
16
+ }
17
+ return factory(w);
18
+ };
19
+ } else {
20
+ factory(global);
21
+ }
22
+ })(typeof window !== 'undefined' ? window : this, function (window, noGlobal) {
23
+ 'use strict';
24
+ if (typeof window === 'undefined') {
25
+ throw new Error('Geetest requires browser environment');
26
+ }
27
+ var document = window.document;
28
+ var Math = window.Math;
29
+ var head = document.getElementsByTagName('head')[0];
30
+
31
+ function _Object(obj) {
32
+ this._obj = obj;
33
+ }
34
+
35
+ _Object.prototype = {
36
+ _each: function (process) {
37
+ var _obj = this._obj;
38
+ for (var k in _obj) {
39
+ if (_obj.hasOwnProperty(k)) {
40
+ process(k, _obj[k]);
41
+ }
42
+ }
43
+ return this;
44
+ },
45
+ };
46
+ function Config(config) {
47
+ var self = this;
48
+ new _Object(config)._each(function (key, value) {
49
+ self[key] = value;
50
+ });
51
+ }
52
+
53
+ Config.prototype = {
54
+ api_server: 'api.geetest.com',
55
+ protocol: 'http://',
56
+ type_path: '/gettype.php',
57
+ fallback_config: {
58
+ slide: {
59
+ static_servers: ['static.geetest.com', 'dn-staticdown.qbox.me'],
60
+ type: 'slide',
61
+ slide: '/static/js/geetest.0.0.0.js',
62
+ },
63
+ fullpage: {
64
+ static_servers: ['static.geetest.com', 'dn-staticdown.qbox.me'],
65
+ type: 'fullpage',
66
+ fullpage: '/static/js/fullpage.0.0.0.js',
67
+ },
68
+ },
69
+ _get_fallback_config: function () {
70
+ var self = this;
71
+ if (isString(self.type)) {
72
+ return self.fallback_config[self.type];
73
+ } else if (self.new_captcha) {
74
+ return self.fallback_config.fullpage;
75
+ } else {
76
+ return self.fallback_config.slide;
77
+ }
78
+ },
79
+ _extend: function (obj) {
80
+ var self = this;
81
+ new _Object(obj)._each(function (key, value) {
82
+ self[key] = value;
83
+ });
84
+ },
85
+ };
86
+ var isNumber = function (value) {
87
+ return typeof value === 'number';
88
+ };
89
+ var isString = function (value) {
90
+ return typeof value === 'string';
91
+ };
92
+ var isBoolean = function (value) {
93
+ return typeof value === 'boolean';
94
+ };
95
+ var isObject = function (value) {
96
+ return typeof value === 'object' && value !== null;
97
+ };
98
+ var isFunction = function (value) {
99
+ return typeof value === 'function';
100
+ };
101
+ var callbacks = {};
102
+ var status = {};
103
+ var random = function () {
104
+ return parseInt(Math.random() * 10000) + new Date().valueOf();
105
+ };
106
+ var loadScript = function (url, cb) {
107
+ var script = document.createElement('script');
108
+ script.charset = 'UTF-8';
109
+ script.async = true;
110
+ script.onerror = function () {
111
+ cb(true);
112
+ };
113
+ var loaded = false;
114
+ script.onload = script.onreadystatechange = function () {
115
+ if (
116
+ !loaded &&
117
+ (!script.readyState ||
118
+ 'loaded' === script.readyState ||
119
+ 'complete' === script.readyState)
120
+ ) {
121
+ loaded = true;
122
+ setTimeout(function () {
123
+ cb(false);
124
+ }, 0);
125
+ }
126
+ };
127
+ script.src = url;
128
+ head.appendChild(script);
129
+ };
130
+ var normalizeDomain = function (domain) {
131
+ return domain.replace(/^https?:\/\/|\/$/g, '');
132
+ };
133
+ var normalizePath = function (path) {
134
+ path = path.replace(/\/+/g, '/');
135
+ if (path.indexOf('/') !== 0) {
136
+ path = '/' + path;
137
+ }
138
+ return path;
139
+ };
140
+ var normalizeQuery = function (query) {
141
+ if (!query) {
142
+ return '';
143
+ }
144
+ var q = '?';
145
+ new _Object(query)._each(function (key, value) {
146
+ if (isString(value) || isNumber(value) || isBoolean(value)) {
147
+ q = q + encodeURIComponent(key) + '=' + encodeURIComponent(value) + '&';
148
+ }
149
+ });
150
+ if (q === '?') {
151
+ q = '';
152
+ }
153
+ return q.replace(/&$/, '');
154
+ };
155
+ var makeURL = function (protocol, domain, path, query) {
156
+ domain = normalizeDomain(domain);
157
+
158
+ var url = normalizePath(path) + normalizeQuery(query);
159
+ if (domain) {
160
+ url = protocol + domain + url;
161
+ }
162
+
163
+ return url;
164
+ };
165
+ var load = function (protocol, domains, path, query, cb) {
166
+ var tryRequest = function (at) {
167
+ var url = makeURL(protocol, domains[at], path, query);
168
+ loadScript(url, function (err) {
169
+ if (err) {
170
+ if (at >= domains.length - 1) {
171
+ cb(true);
172
+ } else {
173
+ tryRequest(at + 1);
174
+ }
175
+ } else {
176
+ cb(false);
177
+ }
178
+ });
179
+ };
180
+ tryRequest(0);
181
+ };
182
+ var jsonp = function (domains, path, config, callback) {
183
+ if (isObject(config.getLib)) {
184
+ config._extend(config.getLib);
185
+ callback(config);
186
+ return;
187
+ }
188
+ if (config.offline) {
189
+ callback(config._get_fallback_config());
190
+ return;
191
+ }
192
+ var cb = 'geetest_' + random();
193
+ window[cb] = function (data) {
194
+ if (data.status === 'success') {
195
+ callback(data.data);
196
+ } else if (!data.status) {
197
+ callback(data);
198
+ } else {
199
+ callback(config._get_fallback_config());
200
+ }
201
+ window[cb] = undefined;
202
+ try {
203
+ delete window[cb];
204
+ } catch (e) {}
205
+ };
206
+ load(
207
+ config.protocol,
208
+ domains,
209
+ path,
210
+ {
211
+ gt: config.gt,
212
+ callback: cb,
213
+ },
214
+ function (err) {
215
+ if (err) {
216
+ callback(config._get_fallback_config());
217
+ }
218
+ },
219
+ );
220
+ };
221
+ var throwError = function (errorType, config) {
222
+ var errors = {
223
+ networkError: '网络错误',
224
+ };
225
+ if (typeof config.onError === 'function') {
226
+ config.onError(errors[errorType]);
227
+ } else {
228
+ throw new Error(errors[errorType]);
229
+ }
230
+ };
231
+ var detect = function () {
232
+ return !!window.Geetest;
233
+ };
234
+ if (detect()) {
235
+ status.slide = 'loaded';
236
+ }
237
+ var initGeetest = function (userConfig, callback) {
238
+ var config = new Config(userConfig);
239
+ if (userConfig.https) {
240
+ config.protocol = 'https://';
241
+ } else if (!userConfig.protocol) {
242
+ config.protocol = window.location.protocol + '//';
243
+ }
244
+ jsonp(
245
+ [config.api_server || config.apiserver],
246
+ config.type_path,
247
+ config,
248
+ function (newConfig) {
249
+ var type = newConfig.type;
250
+ var init = function () {
251
+ config._extend(newConfig);
252
+ callback(new window.Geetest(config));
253
+ };
254
+ callbacks[type] = callbacks[type] || [];
255
+ var s = status[type] || 'init';
256
+ if (s === 'init') {
257
+ status[type] = 'loading';
258
+ callbacks[type].push(init);
259
+ load(
260
+ config.protocol,
261
+ newConfig.static_servers || newConfig.domains,
262
+ newConfig[type] || newConfig.path,
263
+ null,
264
+ function (err) {
265
+ if (err) {
266
+ status[type] = 'fail';
267
+ throwError('networkError', config);
268
+ } else {
269
+ status[type] = 'loaded';
270
+ var cbs = callbacks[type];
271
+ for (var i = 0, len = cbs.length; i < len; i = i + 1) {
272
+ var cb = cbs[i];
273
+ if (isFunction(cb)) {
274
+ cb();
275
+ }
276
+ }
277
+ callbacks[type] = [];
278
+ }
279
+ },
280
+ );
281
+ } else if (s === 'loaded') {
282
+ init();
283
+ } else if (s === 'fail') {
284
+ throwError('networkError', config);
285
+ } else if (s === 'loading') {
286
+ callbacks[type].push(init);
287
+ }
288
+ },
289
+ );
290
+ };
291
+ window.initGeetest = initGeetest;
292
+ return initGeetest;
293
+ });
@@ -0,0 +1,89 @@
1
+ import { EventEmitter } from 'events';
2
+ import type { IMenu } from '@/components/BLayout/components/Menu';
3
+
4
+ /**
5
+ * 检查menus数组是否带标签
6
+ * @param menus 菜单数组
7
+ * @returns boolean true表示有标签
8
+ */
9
+ export function checkMenuVersion(menus: IMenu[]): boolean {
10
+ let hasTag = false;
11
+ for (let i = 0; i < menus.length; i++) {
12
+ const group = menus[i].sub_entry_list;
13
+ for (let j = 0; j < group.length; j++) {
14
+ const menu = group[j].tag_code;
15
+ if (menu !== 'STABLE') hasTag = true;
16
+ }
17
+ }
18
+ return hasTag;
19
+ }
20
+
21
+ export function browserType() {
22
+ const userAgent = navigator.userAgent;
23
+ if (userAgent.indexOf('Chrome') > -1 && userAgent.indexOf('Safari') > -1) {
24
+ return 'Chrome';
25
+ }
26
+ if (userAgent.indexOf('Safari') > -1 && userAgent.indexOf('Chrome') == -1) {
27
+ return 'Safari';
28
+ }
29
+ if (userAgent.indexOf('Firefox') > -1) {
30
+ return 'Firefox';
31
+ }
32
+ if (userAgent.indexOf('Edge') > -1) {
33
+ return 'Edge';
34
+ }
35
+ if (userAgent.indexOf('compatible') > -1 && userAgent.indexOf('MSIE') > -1) {
36
+ return 'IE';
37
+ }
38
+ if (userAgent.indexOf('Opera') > -1) {
39
+ return 'Opera';
40
+ }
41
+ return 'Other';
42
+ }
43
+
44
+ export const eventNames = {
45
+ USER_NAME: 'USER_NAME',
46
+ HIDE_MSG_TOOL: 'HIDE_MSG_TOOL',
47
+ };
48
+ export const eventEmiter = new EventEmitter();
49
+
50
+ export const getMicroAppId = () => {
51
+ const pathname = window.location.pathname;
52
+ if (pathname.includes('/apps/')) {
53
+ return /\/apps\/([^\/]+)/.exec(pathname)?.[1];
54
+ } else {
55
+ return 'main-app';
56
+ }
57
+ };
58
+
59
+ export const curMicroAppName = () => {
60
+ const result = micApps()?.filter(
61
+ (app) => app.oem_micro_app_id === getMicroAppId()
62
+ );
63
+ if (result && result.length > 0) {
64
+ return result[0].micro_app_name;
65
+ }
66
+ return 'main-app';
67
+ };
68
+
69
+ export const curMicroAppCode = () => {
70
+ const result = micApps()?.filter(
71
+ (app) => app.oem_micro_app_id === getMicroAppId()
72
+ );
73
+ if (result && result.length > 0) {
74
+ return result[0].microAppCode;
75
+ }
76
+ return 'main-app';
77
+ };
78
+
79
+ export const micApps = () =>
80
+ window._SDF?.saasInfo?.apps?.map((element) => {
81
+ return {
82
+ ...element,
83
+ active_rule:
84
+ (window.location.pathname.match(/\/g\/\d+/)?.[0] || '') +
85
+ element.active_rule,
86
+ };
87
+ });
88
+
89
+ export const saasApis = () => window._SDF?.saasInfo?.apis || [];
@@ -0,0 +1,110 @@
1
+ import type { MenuType } from 'src/components/BLayout/components/Menu';
2
+
3
+ export const LIGHT = 'light';
4
+ export const DARK = 'dark';
5
+
6
+ export type Theme = typeof LIGHT | typeof DARK;
7
+
8
+ export interface ColorConfig {
9
+ menuBg?: string;
10
+ menuText?: string;
11
+ menuBgExpand?: string;
12
+ menuTextExpand?: string;
13
+ menuBgActived?: string;
14
+ menuTextActived?: string;
15
+ menuSlideBg?: string;
16
+ menuSlideText?: string;
17
+ menuSlideBgActived?: string;
18
+ menuSlideTextActived?: string;
19
+ menuSlideBoundary?: string;
20
+ navigateBg?: string;
21
+ navigateText?: string;
22
+ navigateTextHover?: string;
23
+ navigateBoundary?: string;
24
+ }
25
+
26
+ export interface UserConfigItem {
27
+ hex: string;
28
+ a: number;
29
+ }
30
+
31
+ export type UserColorConfig = {
32
+ [p in keyof ColorConfig]?: UserConfigItem;
33
+ };
34
+
35
+ export type UserColorConfigWithTheme = Record<Theme, UserColorConfig>;
36
+
37
+ export type UserColorConfigWithThemeAndMenu = Record<
38
+ MenuType,
39
+ UserColorConfigWithTheme
40
+ >;
41
+
42
+ interface DynamicTheme {
43
+ supportedTheme?: Theme | 'all';
44
+ primaryColor?: string | UserConfigItem;
45
+ primaryColorInAll?: string | UserConfigItem;
46
+ dynamicMenuColors?: UserColorConfigWithThemeAndMenu;
47
+ }
48
+
49
+ const dynamicTheme: DynamicTheme = (function getDynamicTheme() {
50
+ let config;
51
+ try {
52
+ config = JSON.parse(
53
+ window._SDF.saas.custom_configs?.find(
54
+ (item) => item.config_key === 'dynamic_theme',
55
+ )?.config_value_json,
56
+ );
57
+ } catch (e) {
58
+ config = {};
59
+ }
60
+ return config;
61
+ })();
62
+
63
+ function isSupportCssVariable() {
64
+ return !!dynamicTheme.primaryColor;
65
+ }
66
+
67
+ function isSupportLightDarkSwitch() {
68
+ return dynamicTheme.supportedTheme === 'all';
69
+ }
70
+
71
+ function getSupportedTheme() {
72
+ return dynamicTheme.supportedTheme;
73
+ }
74
+ function isSpecificTheme() {
75
+ return !!getSupportedTheme();
76
+ }
77
+
78
+ function getCssVarible() {
79
+ const { primaryColor, primaryColorInAll } = dynamicTheme;
80
+ return {
81
+ primaryColor,
82
+ primaryColorInAll,
83
+ };
84
+ }
85
+
86
+ function getDynamicMenuTheme() {
87
+ return dynamicTheme.dynamicMenuColors;
88
+ }
89
+
90
+ function getRenderTheme() {
91
+ const supportedTheme = getSupportedTheme();
92
+ const localTheme = localStorage.getItem('theme');
93
+ const validTheme = [LIGHT, DARK] as const;
94
+ if (supportedTheme === 'all') {
95
+ return validTheme.find((theme) => theme === localTheme) || LIGHT;
96
+ } else if (validTheme.includes(supportedTheme)) {
97
+ return supportedTheme;
98
+ }
99
+ return LIGHT;
100
+ }
101
+
102
+ export {
103
+ isSupportCssVariable,
104
+ isSupportLightDarkSwitch,
105
+ getSupportedTheme,
106
+ isSpecificTheme,
107
+ getCssVarible,
108
+ getDynamicMenuTheme,
109
+ getRenderTheme,
110
+ };
@@ -0,0 +1,157 @@
1
+ /* eslint-disable import/prefer-default-export, prefer-destructuring */
2
+
3
+ import { updateCSS } from 'rc-util/lib/Dom/dynamicCSS';
4
+ import { TinyColor } from '@ctrl/tinycolor';
5
+ import { generate } from '@ant-design/colors';
6
+ import type { Theme } from './base';
7
+
8
+ export interface ThemeColor {
9
+ primaryColor?: string;
10
+ infoColor?: string;
11
+ successColor?: string;
12
+ processingColor?: string;
13
+ errorColor?: string;
14
+ warningColor?: string;
15
+ }
16
+
17
+ const dynamicStyleMark = `${Date.now()}-${Math.random()}`;
18
+
19
+ const dynamicId = (prefix = 'ant') => {
20
+ return `-${prefix}-${dynamicStyleMark}`;
21
+ };
22
+
23
+ //只会在dark环境下生成相关主题色的时候,消费。
24
+ const backgroundColor = '#232E48';
25
+
26
+ const themeColor = {
27
+ primaryColor: '#1890ff',
28
+ successColor: '#52c41a',
29
+ warningColor: '#faad14',
30
+ errorColor: '#ff4d4f',
31
+ infoColor: '#1890ff',
32
+ };
33
+
34
+ export function changeCssVarible(
35
+ setTheme: ThemeColor,
36
+ globalPrefixCls = 'ant',
37
+ themeVarint: Theme
38
+ ) {
39
+ const variables: Record<string, string> = {};
40
+ const themeInGenerate = themeVarint === 'dark' ? 'dark' : 'default';
41
+ const theme = Object.keys(themeColor).reduce((pre, val) => {
42
+ if (setTheme && setTheme[val]) {
43
+ return { ...pre, [val]: setTheme[val] };
44
+ } else {
45
+ return { ...pre, [val]: themeColor[val] };
46
+ }
47
+ }, {}) as typeof themeColor;
48
+
49
+ const formatColor = (
50
+ color: TinyColor,
51
+ updater?: (cloneColor: TinyColor) => TinyColor | undefined
52
+ ) => {
53
+ let clone = color.clone();
54
+ clone = updater?.(clone) || clone;
55
+ return clone.toRgbString();
56
+ };
57
+
58
+ const fillColor = (colorVal: string, type: string) => {
59
+ const baseColor = new TinyColor(colorVal);
60
+ const colorPalettes = generate(baseColor.toRgbString(), {
61
+ theme: themeInGenerate,
62
+ backgroundColor,
63
+ });
64
+
65
+ variables[`${type}-color`] = formatColor(baseColor);
66
+ variables[`${type}-color-disabled`] = colorPalettes[1];
67
+ variables[`${type}-color-hover`] = colorPalettes[4];
68
+ variables[`${type}-color-active`] = colorPalettes[6];
69
+ variables[`${type}-color-outline`] = baseColor
70
+ .clone()
71
+ .setAlpha(0.2)
72
+ .toRgbString();
73
+ variables[`${type}-color-deprecated-bg`] = colorPalettes[0];
74
+ variables[`${type}-color-deprecated-border`] = colorPalettes[2];
75
+ };
76
+
77
+ // ================ Primary Color ================
78
+ if (theme.primaryColor) {
79
+ fillColor(theme.primaryColor, 'primary');
80
+
81
+ const primaryColor = new TinyColor(theme.primaryColor);
82
+ const primaryColors = generate(primaryColor.toRgbString(), {
83
+ theme: themeInGenerate,
84
+ backgroundColor,
85
+ });
86
+
87
+ // Legacy - We should use semantic naming standard
88
+ primaryColors.forEach((color, index) => {
89
+ variables[`primary-${index + 1}`] = color;
90
+ });
91
+ // Deprecated
92
+ variables['primary-color-deprecated-l-35'] = formatColor(
93
+ primaryColor,
94
+ (c) => c.lighten(35)
95
+ );
96
+ variables['primary-color-deprecated-l-20'] = formatColor(
97
+ primaryColor,
98
+ (c) => c.lighten(20)
99
+ );
100
+ variables['primary-color-deprecated-t-20'] = formatColor(
101
+ primaryColor,
102
+ (c) => c.tint(20)
103
+ );
104
+ variables['primary-color-deprecated-t-50'] = formatColor(
105
+ primaryColor,
106
+ (c) => c.tint(50)
107
+ );
108
+ variables['primary-color-deprecated-f-12'] = formatColor(
109
+ primaryColor,
110
+ (c) => c.setAlpha(c.getAlpha() * 0.12)
111
+ );
112
+
113
+ const primaryActiveColor = new TinyColor(primaryColors[0]);
114
+ variables['primary-color-active-deprecated-f-30'] = formatColor(
115
+ primaryActiveColor,
116
+ (c) => c.setAlpha(c.getAlpha() * 0.3)
117
+ );
118
+ variables['primary-color-active-deprecated-d-02'] = formatColor(
119
+ primaryActiveColor,
120
+ (c) => c.darken(2)
121
+ );
122
+ }
123
+
124
+ // ================ Success Color ================
125
+ if (theme.successColor) {
126
+ fillColor(theme.successColor, 'success');
127
+ }
128
+
129
+ // ================ Warning Color ================
130
+ if (theme.warningColor) {
131
+ fillColor(theme.warningColor, 'warning');
132
+ }
133
+
134
+ // ================= Error Color =================
135
+ if (theme.errorColor) {
136
+ fillColor(theme.errorColor, 'error');
137
+ }
138
+
139
+ // ================= Info Color ==================
140
+ if (theme.infoColor) {
141
+ fillColor(theme.infoColor, 'info');
142
+ }
143
+
144
+ // Convert to css variables
145
+ const cssList = Object.keys(variables).map(
146
+ (key) => `--${globalPrefixCls}-${key}: ${variables[key]};`
147
+ );
148
+
149
+ updateCSS(
150
+ `
151
+ :root {
152
+ ${cssList.join('\n')}
153
+ }
154
+ `,
155
+ `${dynamicId(globalPrefixCls)}-dynamic-theme`
156
+ );
157
+ }