@lark-apaas/miaoda-core 0.0.1-alpha.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 (192) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +8 -0
  3. package/lib/apis/components/AppContainer.d.ts +1 -0
  4. package/lib/apis/components/AppContainer.js +2 -0
  5. package/lib/apis/components/ErrorRender.d.ts +1 -0
  6. package/lib/apis/components/ErrorRender.js +2 -0
  7. package/lib/apis/components/NotFoundRender.d.ts +1 -0
  8. package/lib/apis/components/NotFoundRender.js +2 -0
  9. package/lib/apis/components/SidebarNav.d.ts +1 -0
  10. package/lib/apis/components/SidebarNav.js +2 -0
  11. package/lib/apis/components/User.d.ts +1 -0
  12. package/lib/apis/components/User.js +1 -0
  13. package/lib/apis/components/Welcome.d.ts +1 -0
  14. package/lib/apis/components/Welcome.js +2 -0
  15. package/lib/apis/constants/img-resources/avatar.d.ts +11 -0
  16. package/lib/apis/constants/img-resources/avatar.js +12 -0
  17. package/lib/apis/constants/img-resources/banner.d.ts +24 -0
  18. package/lib/apis/constants/img-resources/banner.js +25 -0
  19. package/lib/apis/constants/img-resources/cover.d.ts +36 -0
  20. package/lib/apis/constants/img-resources/cover.js +37 -0
  21. package/lib/apis/dataloom.d.ts +1 -0
  22. package/lib/apis/dataloom.js +2 -0
  23. package/lib/apis/hooks/useAppInfo.d.ts +1 -0
  24. package/lib/apis/hooks/useAppInfo.js +1 -0
  25. package/lib/apis/hooks/useCurrentUserProfile.d.ts +1 -0
  26. package/lib/apis/hooks/useCurrentUserProfile.js +1 -0
  27. package/lib/apis/logger.d.ts +1 -0
  28. package/lib/apis/logger.js +1 -0
  29. package/lib/apis/tools/generateImage.d.ts +1 -0
  30. package/lib/apis/tools/generateImage.js +1 -0
  31. package/lib/apis/tools/generateTextStream.d.ts +1 -0
  32. package/lib/apis/tools/generateTextStream.js +1 -0
  33. package/lib/apis/tools/getAppInfo.d.ts +1 -0
  34. package/lib/apis/tools/getAppInfo.js +1 -0
  35. package/lib/apis/tools/getCurrentUserProfile.d.ts +1 -0
  36. package/lib/apis/tools/getCurrentUserProfile.js +1 -0
  37. package/lib/apis/tools/storage.d.ts +1 -0
  38. package/lib/apis/tools/storage.js +4 -0
  39. package/lib/apis/udt-types.d.ts +16 -0
  40. package/lib/apis/udt-types.js +0 -0
  41. package/lib/apis/utils/registerChinaMap.d.ts +1 -0
  42. package/lib/apis/utils/registerChinaMap.js +103319 -0
  43. package/lib/components/AppContainer/IframeBridge.d.ts +4 -0
  44. package/lib/components/AppContainer/IframeBridge.js +92 -0
  45. package/lib/components/AppContainer/LogInterceptor.d.ts +1 -0
  46. package/lib/components/AppContainer/LogInterceptor.js +44 -0
  47. package/lib/components/AppContainer/PageHoc.d.ts +4 -0
  48. package/lib/components/AppContainer/PageHoc.js +40 -0
  49. package/lib/components/AppContainer/api-proxy/core.d.ts +188 -0
  50. package/lib/components/AppContainer/api-proxy/core.js +290 -0
  51. package/lib/components/AppContainer/dayjsPlugins.d.ts +1 -0
  52. package/lib/components/AppContainer/dayjsPlugins.js +69 -0
  53. package/lib/components/AppContainer/index.d.ts +7 -0
  54. package/lib/components/AppContainer/index.js +65 -0
  55. package/lib/components/AppContainer/sonner.css +101 -0
  56. package/lib/components/AppContainer/sonner.d.ts +8 -0
  57. package/lib/components/AppContainer/sonner.js +26 -0
  58. package/lib/components/AppContainer/utils/api-panel.d.ts +11 -0
  59. package/lib/components/AppContainer/utils/api-panel.js +21 -0
  60. package/lib/components/AppContainer/utils/childApi.d.ts +5 -0
  61. package/lib/components/AppContainer/utils/childApi.js +26 -0
  62. package/lib/components/AppContainer/utils/listenHot.d.ts +1 -0
  63. package/lib/components/AppContainer/utils/listenHot.js +43 -0
  64. package/lib/components/ErrorRender/index.d.ts +5 -0
  65. package/lib/components/ErrorRender/index.js +79 -0
  66. package/lib/components/NotFoundRender/index.d.ts +3 -0
  67. package/lib/components/NotFoundRender/index.js +59 -0
  68. package/lib/components/SidebarNav/DrawerNav.d.ts +3 -0
  69. package/lib/components/SidebarNav/DrawerNav.js +64 -0
  70. package/lib/components/SidebarNav/DropdownNav.d.ts +3 -0
  71. package/lib/components/SidebarNav/DropdownNav.js +40 -0
  72. package/lib/components/SidebarNav/Sidebar.d.ts +3 -0
  73. package/lib/components/SidebarNav/Sidebar.js +33 -0
  74. package/lib/components/SidebarNav/index.d.ts +5 -0
  75. package/lib/components/SidebarNav/index.js +61 -0
  76. package/lib/components/User/UserDisplay.d.ts +9 -0
  77. package/lib/components/User/UserDisplay.js +39 -0
  78. package/lib/components/User/UserProfile/UserProfile.css +34 -0
  79. package/lib/components/User/UserProfile/UserProfile.d.ts +6 -0
  80. package/lib/components/User/UserProfile/UserProfile.js +41 -0
  81. package/lib/components/User/UserProfile/UserProfileContainer.d.ts +4 -0
  82. package/lib/components/User/UserProfile/UserProfileContainer.js +8 -0
  83. package/lib/components/User/UserProfile/UserProfileSkeleton.d.ts +3 -0
  84. package/lib/components/User/UserProfile/UserProfileSkeleton.js +36 -0
  85. package/lib/components/User/UserProfile/UserProfileUI.d.ts +8 -0
  86. package/lib/components/User/UserProfile/UserProfileUI.js +113 -0
  87. package/lib/components/User/UserProfile/index.d.ts +1 -0
  88. package/lib/components/User/UserProfile/index.js +2 -0
  89. package/lib/components/User/UserProfile/type.d.ts +8 -0
  90. package/lib/components/User/UserProfile/type.js +0 -0
  91. package/lib/components/User/UserProfile/utils.d.ts +5 -0
  92. package/lib/components/User/UserProfile/utils.js +26 -0
  93. package/lib/components/User/UserSelect.css +11 -0
  94. package/lib/components/User/UserSelect.d.ts +11 -0
  95. package/lib/components/User/UserSelect.js +172 -0
  96. package/lib/components/User/UserWithAvatar.d.ts +3 -0
  97. package/lib/components/User/UserWithAvatar.js +41 -0
  98. package/lib/components/User/index.d.ts +7 -0
  99. package/lib/components/User/index.js +5 -0
  100. package/lib/components/User/type.d.ts +13 -0
  101. package/lib/components/User/type.js +0 -0
  102. package/lib/components/Welcome/index.d.ts +3 -0
  103. package/lib/components/Welcome/index.js +17 -0
  104. package/lib/components/common/LogoInfo.d.ts +5 -0
  105. package/lib/components/common/LogoInfo.js +30 -0
  106. package/lib/components/common/NavItem.d.ts +20 -0
  107. package/lib/components/common/NavItem.js +112 -0
  108. package/lib/components/common/NavMenu.d.ts +9 -0
  109. package/lib/components/common/NavMenu.js +50 -0
  110. package/lib/components/common/UserAvatarLayout.d.ts +4 -0
  111. package/lib/components/common/UserAvatarLayout.js +41 -0
  112. package/lib/components/common/UserAvatarMenu.d.ts +4 -0
  113. package/lib/components/common/UserAvatarMenu.js +58 -0
  114. package/lib/components/common/index.d.ts +9 -0
  115. package/lib/components/common/index.js +10 -0
  116. package/lib/components/index.d.ts +8 -0
  117. package/lib/components/index.js +6 -0
  118. package/lib/components/theme/ThemeProvider.d.ts +20 -0
  119. package/lib/components/theme/ThemeProvider.js +75 -0
  120. package/lib/components/theme/constants.d.ts +48 -0
  121. package/lib/components/theme/constants.js +557 -0
  122. package/lib/components/theme/index.d.ts +4 -0
  123. package/lib/components/theme/index.js +5 -0
  124. package/lib/components/theme/miaoDarkTheme.d.ts +2 -0
  125. package/lib/components/theme/miaoDarkTheme.js +310 -0
  126. package/lib/components/theme/miaoLightTheme.d.ts +2 -0
  127. package/lib/components/theme/miaoLightTheme.js +296 -0
  128. package/lib/components/theme/ui-config.d.ts +1 -0
  129. package/lib/components/theme/ui-config.js +2 -0
  130. package/lib/components/theme/util.d.ts +20 -0
  131. package/lib/components/theme/util.js +188 -0
  132. package/lib/font-family.css +40 -0
  133. package/lib/hooks/index.d.ts +5 -0
  134. package/lib/hooks/index.js +5 -0
  135. package/lib/hooks/useAppInfo.d.ts +6 -0
  136. package/lib/hooks/useAppInfo.js +21 -0
  137. package/lib/hooks/useCurrentUserProfile.d.ts +12 -0
  138. package/lib/hooks/useCurrentUserProfile.js +58 -0
  139. package/lib/hooks/useIsMobile.d.ts +1 -0
  140. package/lib/hooks/useIsMobile.js +20 -0
  141. package/lib/hooks/useLogout.d.ts +4 -0
  142. package/lib/hooks/useLogout.js +37 -0
  143. package/lib/hooks/useTheme.d.ts +4 -0
  144. package/lib/hooks/useTheme.js +8 -0
  145. package/lib/hooks/useUpdatingRef.d.ts +1 -0
  146. package/lib/hooks/useUpdatingRef.js +7 -0
  147. package/lib/index.css +5 -0
  148. package/lib/index.d.ts +4 -0
  149. package/lib/index.js +5 -0
  150. package/lib/inspector.dev.css +10 -0
  151. package/lib/integrations/dataloom.d.ts +2 -0
  152. package/lib/integrations/dataloom.js +32 -0
  153. package/lib/integrations/generateImage.d.ts +1 -0
  154. package/lib/integrations/generateImage.js +47 -0
  155. package/lib/integrations/generateTextStream.d.ts +21 -0
  156. package/lib/integrations/generateTextStream.js +98 -0
  157. package/lib/integrations/getAppInfo.d.ts +2 -0
  158. package/lib/integrations/getAppInfo.js +14 -0
  159. package/lib/integrations/getCurrentUserProfile.d.ts +6 -0
  160. package/lib/integrations/getCurrentUserProfile.js +5 -0
  161. package/lib/logger/index.d.ts +6 -0
  162. package/lib/logger/index.js +54 -0
  163. package/lib/override.css +29 -0
  164. package/lib/tailwind-theme.css +335 -0
  165. package/lib/theme-layer.css +3 -0
  166. package/lib/types/common.d.ts +4 -0
  167. package/lib/types/common.js +0 -0
  168. package/lib/types/iframe-events.d.ts +55 -0
  169. package/lib/types/iframe-events.js +0 -0
  170. package/lib/types/index.d.ts +43 -0
  171. package/lib/types/index.js +0 -0
  172. package/lib/utils/copyToClipboard.d.ts +6 -0
  173. package/lib/utils/copyToClipboard.js +32 -0
  174. package/lib/utils/getAppId.d.ts +6 -0
  175. package/lib/utils/getAppId.js +11 -0
  176. package/lib/utils/getCsrfToken.d.ts +5 -0
  177. package/lib/utils/getCsrfToken.js +10 -0
  178. package/lib/utils/getEnvPath.d.ts +4 -0
  179. package/lib/utils/getEnvPath.js +4 -0
  180. package/lib/utils/getInitialInfo.d.ts +20 -0
  181. package/lib/utils/getInitialInfo.js +32 -0
  182. package/lib/utils/getParentOrigin.d.ts +5 -0
  183. package/lib/utils/getParentOrigin.js +7 -0
  184. package/lib/utils/getUserProfile.d.ts +47 -0
  185. package/lib/utils/getUserProfile.js +39 -0
  186. package/lib/utils/postMessage.d.ts +8 -0
  187. package/lib/utils/postMessage.js +11 -0
  188. package/lib/utils/url.d.ts +8 -0
  189. package/lib/utils/url.js +22 -0
  190. package/lib/utils/utils.d.ts +20 -0
  191. package/lib/utils/utils.js +22 -0
  192. package/package.json +134 -0
@@ -0,0 +1,188 @@
1
+ import { generate } from "@ant-design/colors";
2
+ import { defaultDarkTheme } from "./miaoDarkTheme.js";
3
+ import { defaultLightTheme } from "./miaoLightTheme.js";
4
+ const generateColorPalettes = (baseColor, mode)=>{
5
+ const colors = generate(baseColor, {
6
+ theme: mode
7
+ });
8
+ return {
9
+ 1: colors[0],
10
+ 2: colors[1],
11
+ 3: colors[2],
12
+ 4: colors[3],
13
+ 5: colors[6],
14
+ 6: colors[5],
15
+ 7: colors[4],
16
+ 8: colors[6],
17
+ 9: colors[5],
18
+ 10: colors[4]
19
+ };
20
+ };
21
+ function generateColorPrimaryToken(colorPrimary, mode = 'light') {
22
+ const primaryColors = generateColorPalettes(colorPrimary, 'dark' === mode ? 'dark' : 'default');
23
+ return {
24
+ colorPrimaryBg: primaryColors[1],
25
+ colorPrimaryBgHover: primaryColors[2],
26
+ colorPrimaryBorder: primaryColors[3],
27
+ colorPrimaryBorderHover: primaryColors[4],
28
+ colorPrimaryHover: primaryColors[5],
29
+ colorPrimary: primaryColors[6],
30
+ colorPrimaryActive: primaryColors[7],
31
+ colorPrimaryTextHover: primaryColors[8],
32
+ colorPrimaryText: primaryColors[9],
33
+ colorPrimaryTextActive: primaryColors[10]
34
+ };
35
+ }
36
+ const generateBorderRadiusTokenSyncTailwind = (radiusBase)=>({
37
+ borderRadius: radiusBase,
38
+ borderRadiusXS: radiusBase - 4,
39
+ borderRadiusSM: radiusBase - 2,
40
+ borderRadiusLG: radiusBase + 2,
41
+ borderRadiusOuter: radiusBase + 4
42
+ });
43
+ const generateSpacingToken = (token)=>{
44
+ const { sizeUnit, sizeStep } = token;
45
+ return {
46
+ sizeXXL: sizeUnit * (sizeStep + 8),
47
+ sizeXL: sizeUnit * (sizeStep + 4),
48
+ sizeLG: sizeUnit * (sizeStep + 2),
49
+ sizeMD: sizeUnit * (sizeStep + 1),
50
+ sizeMS: sizeUnit * sizeStep,
51
+ size: sizeUnit * sizeStep,
52
+ sizeSM: sizeUnit * (sizeStep - 1),
53
+ sizeXS: sizeUnit * (sizeStep - 2),
54
+ sizeXXS: sizeUnit * (sizeStep - 3)
55
+ };
56
+ };
57
+ const generateTailwindRadiusToken = (radiusRemValue)=>{
58
+ try {
59
+ const rootFontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
60
+ const radiusPx = radiusRemValue * rootFontSize;
61
+ const tempElement = document.createElement('div');
62
+ tempElement.style.position = 'absolute';
63
+ tempElement.style.visibility = 'hidden';
64
+ document.body.appendChild(tempElement);
65
+ tempElement.style.borderRadius = `${radiusPx}px`;
66
+ const computed = getComputedStyle(tempElement).borderRadius;
67
+ document.body.removeChild(tempElement);
68
+ if (computed && 'auto' !== computed && 'initial' !== computed) return {
69
+ type: 'select',
70
+ options: [
71
+ {
72
+ value: 'rounded-none',
73
+ label: 'none(0px)',
74
+ rawValue: '0'
75
+ },
76
+ {
77
+ value: 'rounded-sm',
78
+ label: `sm (${Math.max(0, radiusPx - 4)}px)`,
79
+ rawValue: `${Math.max(0, radiusPx - 4)}`
80
+ },
81
+ {
82
+ value: 'rounded',
83
+ label: 's (4px)',
84
+ rawValue: '4'
85
+ },
86
+ {
87
+ value: 'rounded-md',
88
+ label: `m (${Math.max(0, radiusPx - 2)}px)`,
89
+ rawValue: `${Math.max(0, radiusPx - 2)}`
90
+ },
91
+ {
92
+ value: 'rounded-lg',
93
+ label: `l (${radiusPx}px)`,
94
+ rawValue: `${radiusPx}`
95
+ },
96
+ {
97
+ value: 'rounded-xl',
98
+ label: `xl (${radiusPx + 4}px)`,
99
+ rawValue: `${radiusPx + 4}`
100
+ },
101
+ {
102
+ value: 'rounded-2xl',
103
+ label: '2xl (16px)',
104
+ rawValue: '16'
105
+ },
106
+ {
107
+ value: 'rounded-full',
108
+ label: 'Full',
109
+ rawValue: '9999'
110
+ }
111
+ ]
112
+ };
113
+ throw new Error('Browser calculation validation failed');
114
+ } catch (error) {
115
+ console.warn('Failed to get computed values from browser, falling back to default calculation:', error);
116
+ const radiusPx = 16 * radiusRemValue;
117
+ return {
118
+ type: 'select',
119
+ options: [
120
+ {
121
+ value: 'rounded-none',
122
+ label: 'none(0px)',
123
+ rawValue: '0'
124
+ },
125
+ {
126
+ value: 'rounded-sm',
127
+ label: `sm (${Math.max(0, radiusPx - 4)}px)`,
128
+ rawValue: `${Math.max(0, radiusPx - 4)}`
129
+ },
130
+ {
131
+ value: 'rounded',
132
+ label: 's (4px)',
133
+ rawValue: '4'
134
+ },
135
+ {
136
+ value: 'rounded-md',
137
+ label: `m (${Math.max(0, radiusPx - 2)}px)`,
138
+ rawValue: `${Math.max(0, radiusPx - 2)}`
139
+ },
140
+ {
141
+ value: 'rounded-lg',
142
+ label: `l (${radiusPx}px)`,
143
+ rawValue: `${radiusPx}`
144
+ },
145
+ {
146
+ value: 'rounded-xl',
147
+ label: `xl (${radiusPx + 4}px)`,
148
+ rawValue: `${radiusPx + 4}`
149
+ },
150
+ {
151
+ value: 'rounded-2xl',
152
+ label: '2xl (16px)',
153
+ rawValue: '16'
154
+ },
155
+ {
156
+ value: 'rounded-full',
157
+ label: 'Full',
158
+ rawValue: '9999'
159
+ }
160
+ ]
161
+ };
162
+ }
163
+ };
164
+ const lightColorPrimary = '#1456f0';
165
+ const darkColorPrimary = '#336df4';
166
+ function generateLightTheme(override) {
167
+ return {
168
+ ...defaultLightTheme,
169
+ token: {
170
+ ...defaultLightTheme.token,
171
+ ...generateColorPrimaryToken(override?.colorPrimary || lightColorPrimary, 'light'),
172
+ ...generateBorderRadiusTokenSyncTailwind(override?.borderRadius),
173
+ ...generateSpacingToken(override)
174
+ }
175
+ };
176
+ }
177
+ function generateDarkTheme(override) {
178
+ return {
179
+ ...defaultDarkTheme,
180
+ token: {
181
+ ...defaultDarkTheme.token,
182
+ ...generateColorPrimaryToken(override?.colorPrimary || darkColorPrimary, 'dark'),
183
+ ...generateBorderRadiusTokenSyncTailwind(override?.borderRadius),
184
+ ...generateSpacingToken(override)
185
+ }
186
+ };
187
+ }
188
+ export { generateDarkTheme, generateLightTheme, generateTailwindRadiusToken };
@@ -0,0 +1,40 @@
1
+ @font-face {
2
+ font-family: LarkChineseQuote;
3
+ font-weight: 300;
4
+ src: local(PingFangSC-Light);
5
+ unicode-range: U+2018, U+2019, U+201A, U+201C, U+201D, U+201E;
6
+ }
7
+
8
+ @font-face {
9
+ font-family: LarkChineseQuote;
10
+ font-weight: 400;
11
+ src: local(PingFangSC-Regular);
12
+ unicode-range: U+2018, U+2019, U+201A, U+201C, U+201D, U+201E;
13
+ }
14
+
15
+ @font-face {
16
+ font-family: LarkChineseQuote;
17
+ font-weight: 500;
18
+ src: local(PingFangSC-Medium);
19
+ unicode-range: U+2018, U+2019, U+201A, U+201C, U+201D, U+201E;
20
+ }
21
+
22
+ @font-face {
23
+ font-family: LarkChineseQuote;
24
+ font-weight: 600;
25
+ src: local(PingFangSC-Semibold);
26
+ unicode-range: U+2018, U+2019, U+201A, U+201C, U+201D, U+201E;
27
+ }
28
+
29
+ @font-face {
30
+ font-family: LarkEmojiFont;
31
+ src: local(Apple Color Emoji), local(Noto Color Emoji);
32
+ unicode-range: U+1F21A, U+1F250, U+1F237, U+26A0;
33
+ }
34
+
35
+ @font-face {
36
+ font-family: LarkHackSafariFont;
37
+ src: local(Helvetica Neue);
38
+ unicode-range: U+0;
39
+ }
40
+
@@ -0,0 +1,5 @@
1
+ export * from './useAppInfo';
2
+ export * from './useCurrentUserProfile';
3
+ export * from './useIsMobile';
4
+ export * from './useLogout';
5
+ export * from './useTheme';
@@ -0,0 +1,5 @@
1
+ export * from "./useAppInfo.js";
2
+ export * from "./useCurrentUserProfile.js";
3
+ export * from "./useIsMobile.js";
4
+ export * from "./useLogout.js";
5
+ export * from "./useTheme.js";
@@ -0,0 +1,6 @@
1
+ export declare const useAppInfo: () => {
2
+ appName: string;
3
+ appLogo: string;
4
+ name?: string;
5
+ avatar?: string;
6
+ };
@@ -0,0 +1,21 @@
1
+ import { useEffect, useState } from "react";
2
+ import { getAppInfo } from "../integrations/getAppInfo.js";
3
+ const useAppInfo = ()=>{
4
+ const [appInfo, setAppInfo] = useState({});
5
+ useEffect(()=>{
6
+ const handleMetaInfoChanged = async ()=>{
7
+ setAppInfo(await getAppInfo());
8
+ };
9
+ handleMetaInfoChanged();
10
+ window.addEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
11
+ return ()=>{
12
+ window.removeEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
13
+ };
14
+ }, []);
15
+ return {
16
+ ...appInfo,
17
+ appName: appInfo.name,
18
+ appLogo: appInfo.avatar
19
+ };
20
+ };
21
+ export { useAppInfo };
@@ -0,0 +1,12 @@
1
+ import { IUserProfile } from '../apis/udt-types';
2
+ export interface ICompatibilityUserProfile extends IUserProfile {
3
+ /**
4
+ * @deprecated please use `name`
5
+ */
6
+ userName: string;
7
+ /**
8
+ * @deprecated please use `avatar`
9
+ */
10
+ userAvatar: string;
11
+ }
12
+ export declare const useCurrentUserProfile: () => ICompatibilityUserProfile;
@@ -0,0 +1,58 @@
1
+ import { useEffect, useState } from "react";
2
+ import { logger } from "../logger/index.js";
3
+ import { getCurrentUserProfile } from "../integrations/getCurrentUserProfile.js";
4
+ import { getDataloom } from "../integrations/dataloom.js";
5
+ import { isSparkRuntime } from "../utils/utils.js";
6
+ function getCompatibilityUserProfile() {
7
+ const userInfo = getCurrentUserProfile();
8
+ return {
9
+ ...userInfo,
10
+ userName: userInfo.name,
11
+ userAvatar: userInfo.avatar
12
+ };
13
+ }
14
+ const useCurrentUserProfile = ()=>{
15
+ const [userInfo, setUserInfo] = useState(()=>getCompatibilityUserProfile());
16
+ useEffect(()=>{
17
+ let handleMetaInfoChanged;
18
+ if (isSparkRuntime()) {
19
+ (async ()=>{
20
+ const dataloom = await getDataloom();
21
+ const result = await dataloom.service.session.getUserInfo();
22
+ const userInfo = result?.data?.user_info;
23
+ setUserInfo({
24
+ user_id: userInfo?.user_id?.toString(),
25
+ email: userInfo?.email,
26
+ name: userInfo?.name?.[0]?.text,
27
+ avatar: userInfo?.avatar?.image?.large,
28
+ userName: userInfo?.name?.[0]?.text,
29
+ userAvatar: userInfo?.avatar?.image?.large
30
+ });
31
+ })();
32
+ handleMetaInfoChanged = async ()=>{
33
+ const dataloom = await getDataloom();
34
+ const result = await dataloom.service.session.getUserInfo();
35
+ const userInfo = result?.data?.user_info;
36
+ const newUserInfo = {
37
+ user_id: userInfo?.user_id?.toString(),
38
+ email: userInfo?.email,
39
+ name: userInfo?.name?.[0]?.text,
40
+ avatar: userInfo?.avatar?.image?.large,
41
+ userName: userInfo?.name?.[0]?.text,
42
+ userAvatar: userInfo?.avatar?.image?.large
43
+ };
44
+ logger.info('MiaoDaMetaInfoChanged', newUserInfo);
45
+ setUserInfo(newUserInfo);
46
+ };
47
+ } else handleMetaInfoChanged = ()=>{
48
+ logger.info('MiaoDaMetaInfoChanged', getCompatibilityUserProfile());
49
+ setUserInfo(getCompatibilityUserProfile());
50
+ };
51
+ window.addEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
52
+ return ()=>{
53
+ window.removeEventListener('MiaoDaMetaInfoChanged', handleMetaInfoChanged);
54
+ };
55
+ }, []);
56
+ return userInfo;
57
+ };
58
+ export { useCurrentUserProfile };
@@ -0,0 +1 @@
1
+ export declare function useIsMobile(): boolean;
@@ -0,0 +1,20 @@
1
+ import react from "react";
2
+ import { debounce } from "lodash";
3
+ const MOBILE_BREAKPOINT = 768;
4
+ function useIsMobile() {
5
+ const [isMobile, setIsMobile] = react.useState(window.innerWidth < MOBILE_BREAKPOINT);
6
+ react.useEffect(()=>{
7
+ const handleResize = ()=>{
8
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
9
+ };
10
+ const debouncedHandleResize = debounce(handleResize, 200);
11
+ window.addEventListener('resize', debouncedHandleResize);
12
+ handleResize();
13
+ return ()=>{
14
+ window.removeEventListener('resize', debouncedHandleResize);
15
+ debouncedHandleResize.cancel();
16
+ };
17
+ }, []);
18
+ return isMobile;
19
+ }
20
+ export { useIsMobile };
@@ -0,0 +1,4 @@
1
+ export declare function useLogout(): {
2
+ handlerLogout: () => Promise<void>;
3
+ isLoading: boolean;
4
+ };
@@ -0,0 +1,37 @@
1
+ import { useState } from "react";
2
+ import { getDataloom } from "../integrations/dataloom.js";
3
+ import { isSparkRuntime } from "../utils/utils.js";
4
+ function useLogout() {
5
+ const [isLoading, setIsLoading] = useState(false);
6
+ async function handlerLogout() {
7
+ if ('production' !== process.env.NODE_ENV) return void console.log('只有生产环境才执行登出');
8
+ if (isSparkRuntime()) {
9
+ setIsLoading(true);
10
+ try {
11
+ const dataloom = await getDataloom();
12
+ await dataloom.service.session.signOut();
13
+ } catch (error) {
14
+ console.error('登出失败', error);
15
+ } finally{
16
+ setIsLoading(false);
17
+ }
18
+ return;
19
+ }
20
+ setIsLoading(true);
21
+ try {
22
+ await fetch('/ai/api/ui/page/logout', {
23
+ method: 'GET'
24
+ });
25
+ window.location.reload();
26
+ } catch (error) {
27
+ console.error('登出失败', error);
28
+ } finally{
29
+ setIsLoading(false);
30
+ }
31
+ }
32
+ return {
33
+ handlerLogout,
34
+ isLoading
35
+ };
36
+ }
37
+ export { useLogout };
@@ -0,0 +1,4 @@
1
+ export declare const useTheme: () => {
2
+ theme: import("../types").ITheme;
3
+ setTheme: (theme: import("../types").ITheme) => void;
4
+ };
@@ -0,0 +1,8 @@
1
+ import { useContext } from "react";
2
+ import { ThemeProviderContext } from "../components/theme/index.js";
3
+ const useTheme = ()=>{
4
+ const context = useContext(ThemeProviderContext);
5
+ if (void 0 === context) throw new Error('useTheme 必须在 ThemeProvider 内使用');
6
+ return context;
7
+ };
8
+ export { useTheme };
@@ -0,0 +1 @@
1
+ export declare function useUpdatingRef<T>(value: T): import("react").MutableRefObject<T>;
@@ -0,0 +1,7 @@
1
+ import { useRef } from "react";
2
+ function useUpdatingRef(value) {
3
+ const ref = useRef(value);
4
+ ref.current = value;
5
+ return ref;
6
+ }
7
+ export { useUpdatingRef };
package/lib/index.css ADDED
@@ -0,0 +1,5 @@
1
+ @import "./theme-layer.css";
2
+ @import "./tailwind-theme.css";
3
+ @import "./override.css";
4
+ @import "./font-family.css";
5
+
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ version: string;
3
+ };
4
+ export default _default;
package/lib/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { version } from "../package.json";
2
+ const src = {
3
+ version: version
4
+ };
5
+ export { src as default };
@@ -0,0 +1,10 @@
1
+ @source inline("text-{xs,sm,base,lg,xl,2xl,3xl,4xl,5xl,6xl,7xl,8xl,9xl}");
2
+
3
+ @source inline("{bg,text,border}-{blue,pink,neutral,red,orange,violet,lime,yellow,green,teal,cyan,indigo,purple,amber,emerald,slate}-{50,{100..900..100},950}");
4
+
5
+ @source inline("{bg,text,border}-{blue,pink,neutral,red,orange,violet,lime,yellow,green,teal,cyan,indigo,purple,amber,emerald,slate}");
6
+
7
+ @source inline("{bg,text,border}-neutral-{00,1000}");
8
+
9
+ @source inline("rounded-{none,sm,md,lg,xl,full}");
10
+
@@ -0,0 +1,2 @@
1
+ /** 获取dataloom实例 */
2
+ export declare function getDataloom(): Promise<import("@data-loom/js").DataloomClient<any, "public", any>>;
@@ -0,0 +1,32 @@
1
+ import { splitWorkspaceUrl } from "../utils/url.js";
2
+ import { createClient } from "@data-loom/js";
3
+ import { getAppId } from "../utils/getAppId.js";
4
+ import { getInitialInfo } from "../utils/getInitialInfo.js";
5
+ const createDataLoomClient = (url, pat)=>{
6
+ if (!url) return null;
7
+ const { baseUrl, workspace } = splitWorkspaceUrl(url);
8
+ const appId = getAppId(window.location.pathname);
9
+ return createClient(baseUrl, pat, workspace, {
10
+ global: {
11
+ enablePostgresBuilderLog: 'production' !== process.env.NODE_ENV,
12
+ requestRateLimit: 'production' !== process.env.NODE_ENV ? 100 : void 0,
13
+ brandName: 'miaoda',
14
+ appId,
15
+ onError: (error, dataloomInstance)=>{
16
+ if (error?.status === 401) {
17
+ if (error?.code === 'k_ident_013001') dataloomInstance.service.session.redirectToLogin();
18
+ }
19
+ }
20
+ }
21
+ });
22
+ };
23
+ let dataloom = null;
24
+ async function getDataloom() {
25
+ if (dataloom) return dataloom;
26
+ const info = await getInitialInfo();
27
+ const DATALOOM_CLIENT_URL = info?.app_runtime_extra?.url;
28
+ const DATALOOM_PAT = info?.app_runtime_extra?.token;
29
+ dataloom = createDataLoomClient(DATALOOM_CLIENT_URL, DATALOOM_PAT);
30
+ return dataloom;
31
+ }
32
+ export { getDataloom };
@@ -0,0 +1 @@
1
+ export declare function generateImage(prompt: string, size?: string, headers?: Record<string, string>): Promise<any>;
@@ -0,0 +1,47 @@
1
+ import { getAppId } from "../utils/getAppId.js";
2
+ import { getCsrfToken } from "../utils/getCsrfToken.js";
3
+ import { getEnvPath } from "../utils/getEnvPath.js";
4
+ import { isSparkRuntime } from "../utils/utils.js";
5
+ async function generateImage(prompt, size = '1024x1024', headers = {}) {
6
+ const appId = getAppId(window.location.pathname);
7
+ if (!appId) return {
8
+ code: 1,
9
+ msg: 'appId is required',
10
+ data: {}
11
+ };
12
+ const defaultHeaders = {
13
+ 'Content-Type': 'application/json'
14
+ };
15
+ const mergedHeaders = {
16
+ ...defaultHeaders,
17
+ ...headers,
18
+ 'X-Kunlun-Token': window.token,
19
+ 'x-miaoda-token': window.MIAODA_BUILTIN_TTT,
20
+ 'x-lgw-csrf-token': window.lgw_csrf_token,
21
+ ...window.CSRF_HEADERS || {}
22
+ };
23
+ if (isSparkRuntime()) {
24
+ mergedHeaders['X-Suda-Csrf-Token'] = getCsrfToken();
25
+ const response = await fetch(`${window.location.origin}/spark/b/${appId}/text2image`, {
26
+ method: 'POST',
27
+ headers: mergedHeaders,
28
+ credentials: 'include',
29
+ body: JSON.stringify({
30
+ prompt,
31
+ size
32
+ })
33
+ });
34
+ return await response.json();
35
+ }
36
+ const response = await fetch(`${window.location.origin}/ai/api/${getEnvPath()}/v1/apps/${appId}/text2image`, {
37
+ method: 'POST',
38
+ headers: mergedHeaders,
39
+ credentials: 'include',
40
+ body: JSON.stringify({
41
+ prompt,
42
+ size
43
+ })
44
+ });
45
+ return await response.json();
46
+ }
47
+ export { generateImage };
@@ -0,0 +1,21 @@
1
+ interface GenerateTextOptions {
2
+ text: string;
3
+ thinking_type?: 'enabled' | 'disabled';
4
+ headers?: Record<string, string>;
5
+ }
6
+ interface GenerateTextResult {
7
+ content: string;
8
+ reasoning_content: string;
9
+ success: boolean;
10
+ error?: string;
11
+ }
12
+ /**
13
+ * 文生文 - 流式版本
14
+ * 支持实时接收生成内容的回调
15
+ */
16
+ export declare function generateTextStream(options: GenerateTextOptions, onChunk?: (chunk: {
17
+ content: string;
18
+ reasoning_content: string;
19
+ finished: boolean;
20
+ }) => void): Promise<GenerateTextResult>;
21
+ export {};