sa2kit 2.0.1 → 2.0.2

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 (264) hide show
  1. package/README.md +1 -1
  2. package/dist/CollisionBalls-BpHufX3H.d.mts +41 -0
  3. package/dist/CollisionBalls-BpHufX3H.d.ts +41 -0
  4. package/dist/ConfigService-BxK06xP6.d.mts +262 -0
  5. package/dist/ConfigService-BxK06xP6.d.ts +262 -0
  6. package/dist/UniversalFileService-BpvbZitV.d.mts +139 -0
  7. package/dist/UniversalFileService-GsP6D3Rc.d.ts +139 -0
  8. package/dist/audioDetection/index.d.mts +449 -0
  9. package/dist/audioDetection/index.d.ts +449 -0
  10. package/dist/audioDetection/index.js +1244 -0
  11. package/dist/audioDetection/index.js.map +1 -0
  12. package/dist/audioDetection/index.mjs +1227 -0
  13. package/dist/audioDetection/index.mjs.map +1 -0
  14. package/dist/auth/legacy/core/index.d.mts +42 -0
  15. package/dist/auth/legacy/core/index.d.ts +42 -0
  16. package/dist/auth/legacy/core/index.js +242 -0
  17. package/dist/auth/legacy/core/index.js.map +1 -0
  18. package/dist/auth/legacy/core/index.mjs +226 -0
  19. package/dist/auth/legacy/core/index.mjs.map +1 -0
  20. package/dist/auth/legacy/db/index.d.mts +5 -0
  21. package/dist/auth/legacy/db/index.d.ts +5 -0
  22. package/dist/auth/legacy/db/index.js +261 -0
  23. package/dist/auth/legacy/db/index.js.map +1 -0
  24. package/dist/auth/legacy/db/index.mjs +250 -0
  25. package/dist/auth/legacy/db/index.mjs.map +1 -0
  26. package/dist/auth/legacy/index.d.mts +5 -0
  27. package/dist/auth/legacy/index.d.ts +5 -0
  28. package/dist/auth/legacy/index.js +1107 -0
  29. package/dist/auth/legacy/index.js.map +1 -0
  30. package/dist/auth/legacy/index.mjs +1086 -0
  31. package/dist/auth/legacy/index.mjs.map +1 -0
  32. package/dist/auth/legacy/logic/index.d.mts +9 -0
  33. package/dist/auth/legacy/logic/index.d.ts +9 -0
  34. package/dist/auth/legacy/logic/index.js +194 -0
  35. package/dist/auth/legacy/logic/index.js.map +1 -0
  36. package/dist/auth/legacy/logic/index.mjs +187 -0
  37. package/dist/auth/legacy/logic/index.mjs.map +1 -0
  38. package/dist/auth/legacy/miniapp/index.d.mts +5 -0
  39. package/dist/auth/legacy/miniapp/index.d.ts +5 -0
  40. package/dist/auth/legacy/miniapp/index.js +506 -0
  41. package/dist/auth/legacy/miniapp/index.js.map +1 -0
  42. package/dist/auth/legacy/miniapp/index.mjs +487 -0
  43. package/dist/auth/legacy/miniapp/index.mjs.map +1 -0
  44. package/dist/auth/legacy/routes/index.d.mts +53 -0
  45. package/dist/auth/legacy/routes/index.d.ts +53 -0
  46. package/dist/auth/legacy/routes/index.js +278 -0
  47. package/dist/auth/legacy/routes/index.js.map +1 -0
  48. package/dist/auth/legacy/routes/index.mjs +271 -0
  49. package/dist/auth/legacy/routes/index.mjs.map +1 -0
  50. package/dist/auth/legacy/schema/index.d.mts +401 -0
  51. package/dist/auth/legacy/schema/index.d.ts +401 -0
  52. package/dist/auth/legacy/schema/index.js +50 -0
  53. package/dist/auth/legacy/schema/index.js.map +1 -0
  54. package/dist/auth/legacy/schema/index.mjs +44 -0
  55. package/dist/auth/legacy/schema/index.mjs.map +1 -0
  56. package/dist/auth/legacy/server/index.d.mts +13 -0
  57. package/dist/auth/legacy/server/index.d.ts +13 -0
  58. package/dist/auth/legacy/server/index.js +21 -0
  59. package/dist/auth/legacy/server/index.js.map +1 -0
  60. package/dist/auth/legacy/server/index.mjs +19 -0
  61. package/dist/auth/legacy/server/index.mjs.map +1 -0
  62. package/dist/auth/legacy/services/index.d.mts +40 -0
  63. package/dist/auth/legacy/services/index.d.ts +40 -0
  64. package/dist/auth/legacy/services/index.js +258 -0
  65. package/dist/auth/legacy/services/index.js.map +1 -0
  66. package/dist/auth/legacy/services/index.mjs +252 -0
  67. package/dist/auth/legacy/services/index.mjs.map +1 -0
  68. package/dist/auth/legacy/ui/miniapp/index.d.mts +10 -0
  69. package/dist/auth/legacy/ui/miniapp/index.d.ts +10 -0
  70. package/dist/auth/legacy/ui/miniapp/index.js +298 -0
  71. package/dist/auth/legacy/ui/miniapp/index.js.map +1 -0
  72. package/dist/auth/legacy/ui/miniapp/index.mjs +290 -0
  73. package/dist/auth/legacy/ui/miniapp/index.mjs.map +1 -0
  74. package/dist/auth/legacy/ui/web/index.d.mts +22 -0
  75. package/dist/auth/legacy/ui/web/index.d.ts +22 -0
  76. package/dist/auth/legacy/ui/web/index.js +899 -0
  77. package/dist/auth/legacy/ui/web/index.js.map +1 -0
  78. package/dist/auth/legacy/ui/web/index.mjs +889 -0
  79. package/dist/auth/legacy/ui/web/index.mjs.map +1 -0
  80. package/dist/auth/legacy/web/index.d.mts +5 -0
  81. package/dist/auth/legacy/web/index.d.ts +5 -0
  82. package/dist/auth/legacy/web/index.js +1107 -0
  83. package/dist/auth/legacy/web/index.js.map +1 -0
  84. package/dist/auth/legacy/web/index.mjs +1086 -0
  85. package/dist/auth/legacy/web/index.mjs.map +1 -0
  86. package/dist/auth/rn/index.d.mts +64 -0
  87. package/dist/auth/rn/index.d.ts +64 -0
  88. package/dist/auth/rn/index.js +765 -0
  89. package/dist/auth/rn/index.js.map +1 -0
  90. package/dist/auth/rn/index.mjs +754 -0
  91. package/dist/auth/rn/index.mjs.map +1 -0
  92. package/dist/base-api-client-ACKKt13v.d.mts +277 -0
  93. package/dist/base-api-client-ACKKt13v.d.ts +277 -0
  94. package/dist/boothVaultService-Cn4WPhjg.d.mts +83 -0
  95. package/dist/boothVaultService-Cn4WPhjg.d.ts +83 -0
  96. package/dist/business/index.d.mts +6 -0
  97. package/dist/business/index.d.ts +6 -0
  98. package/dist/business/index.js +1682 -0
  99. package/dist/business/index.js.map +1 -0
  100. package/dist/business/index.mjs +1675 -0
  101. package/dist/business/index.mjs.map +1 -0
  102. package/dist/calendar/index.d.mts +1325 -0
  103. package/dist/calendar/index.d.ts +1325 -0
  104. package/dist/calendar/index.js +5964 -0
  105. package/dist/calendar/index.js.map +1 -0
  106. package/dist/calendar/index.mjs +5878 -0
  107. package/dist/calendar/index.mjs.map +1 -0
  108. package/dist/components/index.d.mts +405 -0
  109. package/dist/components/index.d.ts +405 -0
  110. package/dist/components/index.js +2516 -0
  111. package/dist/components/index.js.map +1 -0
  112. package/dist/components/index.mjs +2396 -0
  113. package/dist/components/index.mjs.map +1 -0
  114. package/dist/drizzle-schema-BNhqj2AZ.d.mts +1114 -0
  115. package/dist/drizzle-schema-BNhqj2AZ.d.ts +1114 -0
  116. package/dist/festivalCard/index.d.mts +75 -0
  117. package/dist/festivalCard/index.d.ts +75 -0
  118. package/dist/festivalCard/index.js +1492 -0
  119. package/dist/festivalCard/index.js.map +1 -0
  120. package/dist/festivalCard/index.mjs +1475 -0
  121. package/dist/festivalCard/index.mjs.map +1 -0
  122. package/dist/festivalCard/server/index.d.mts +120 -0
  123. package/dist/festivalCard/server/index.d.ts +120 -0
  124. package/dist/festivalCard/server/index.js +272 -0
  125. package/dist/festivalCard/server/index.js.map +1 -0
  126. package/dist/festivalCard/server/index.mjs +265 -0
  127. package/dist/festivalCard/server/index.mjs.map +1 -0
  128. package/dist/festivalCardService-CZomuQ4E.d.mts +80 -0
  129. package/dist/festivalCardService-CZomuQ4E.d.ts +80 -0
  130. package/dist/index-1Ag7IBXN.d.ts +144 -0
  131. package/dist/index-DNKZ7-R_.d.mts +184 -0
  132. package/dist/index-DNKZ7-R_.d.ts +184 -0
  133. package/dist/index-DSel44Ke.d.mts +93 -0
  134. package/dist/index-DSel44Ke.d.ts +93 -0
  135. package/dist/index-DdeZSeTJ.d.mts +144 -0
  136. package/dist/index-DrPcMJPc.d.mts +250 -0
  137. package/dist/index-DrPcMJPc.d.ts +250 -0
  138. package/dist/index.d.mts +5333 -0
  139. package/dist/index.d.ts +5333 -0
  140. package/dist/index.js +18809 -0
  141. package/dist/index.js.map +1 -0
  142. package/dist/index.mjs +18533 -0
  143. package/dist/index.mjs.map +1 -0
  144. package/dist/mikuContest/ui/web/index.d.mts +2 -0
  145. package/dist/mikuContest/ui/web/index.d.ts +2 -0
  146. package/dist/mikuContest/ui/web/index.js +353 -0
  147. package/dist/mikuContest/ui/web/index.js.map +1 -0
  148. package/dist/mikuContest/ui/web/index.mjs +343 -0
  149. package/dist/mikuContest/ui/web/index.mjs.map +1 -0
  150. package/dist/mikuFireworks3D/index.d.mts +268 -0
  151. package/dist/mikuFireworks3D/index.d.ts +268 -0
  152. package/dist/mikuFireworks3D/index.js +1267 -0
  153. package/dist/mikuFireworks3D/index.js.map +1 -0
  154. package/dist/mikuFireworks3D/index.mjs +1228 -0
  155. package/dist/mikuFireworks3D/index.mjs.map +1 -0
  156. package/dist/mikuFusionGame/index.d.mts +117 -0
  157. package/dist/mikuFusionGame/index.d.ts +117 -0
  158. package/dist/mikuFusionGame/index.js +1208 -0
  159. package/dist/mikuFusionGame/index.js.map +1 -0
  160. package/dist/mikuFusionGame/index.mjs +1195 -0
  161. package/dist/mikuFusionGame/index.mjs.map +1 -0
  162. package/dist/mmd/admin/index.d.mts +487 -0
  163. package/dist/mmd/admin/index.d.ts +487 -0
  164. package/dist/mmd/admin/index.js +1058 -0
  165. package/dist/mmd/admin/index.js.map +1 -0
  166. package/dist/mmd/admin/index.mjs +1027 -0
  167. package/dist/mmd/admin/index.mjs.map +1 -0
  168. package/dist/mmd/index.d.mts +2467 -0
  169. package/dist/mmd/index.d.ts +2467 -0
  170. package/dist/mmd/index.js +10119 -0
  171. package/dist/mmd/index.js.map +1 -0
  172. package/dist/mmd/index.mjs +10028 -0
  173. package/dist/mmd/index.mjs.map +1 -0
  174. package/dist/mmd/server/index.d.mts +139 -0
  175. package/dist/mmd/server/index.d.ts +139 -0
  176. package/dist/mmd/server/index.js +424 -0
  177. package/dist/mmd/server/index.js.map +1 -0
  178. package/dist/mmd/server/index.mjs +404 -0
  179. package/dist/mmd/server/index.mjs.map +1 -0
  180. package/dist/music/index.d.mts +74 -0
  181. package/dist/music/index.d.ts +74 -0
  182. package/dist/music/index.js +830 -0
  183. package/dist/music/index.js.map +1 -0
  184. package/dist/music/index.mjs +809 -0
  185. package/dist/music/index.mjs.map +1 -0
  186. package/dist/music/server/index.d.mts +1 -0
  187. package/dist/music/server/index.d.ts +1 -0
  188. package/dist/music/server/index.js +194 -0
  189. package/dist/music/server/index.js.map +1 -0
  190. package/dist/music/server/index.mjs +182 -0
  191. package/dist/music/server/index.mjs.map +1 -0
  192. package/dist/navigation/index.d.mts +93 -0
  193. package/dist/navigation/index.d.ts +93 -0
  194. package/dist/navigation/index.js +453 -0
  195. package/dist/navigation/index.js.map +1 -0
  196. package/dist/navigation/index.mjs +443 -0
  197. package/dist/navigation/index.mjs.map +1 -0
  198. package/dist/portfolio/index.d.mts +66 -0
  199. package/dist/portfolio/index.d.ts +66 -0
  200. package/dist/portfolio/index.js +736 -0
  201. package/dist/portfolio/index.js.map +1 -0
  202. package/dist/portfolio/index.mjs +724 -0
  203. package/dist/portfolio/index.mjs.map +1 -0
  204. package/dist/qqbot/server/index.d.mts +216 -0
  205. package/dist/qqbot/server/index.d.ts +216 -0
  206. package/dist/qqbot/server/index.js +394 -0
  207. package/dist/qqbot/server/index.js.map +1 -0
  208. package/dist/qqbot/server/index.mjs +385 -0
  209. package/dist/qqbot/server/index.mjs.map +1 -0
  210. package/dist/qqbot/ui/web/index.d.mts +10 -0
  211. package/dist/qqbot/ui/web/index.d.ts +10 -0
  212. package/dist/qqbot/ui/web/index.js +105 -0
  213. package/dist/qqbot/ui/web/index.js.map +1 -0
  214. package/dist/qqbot/ui/web/index.mjs +99 -0
  215. package/dist/qqbot/ui/web/index.mjs.map +1 -0
  216. package/dist/screenReceiver/index.d.mts +86 -0
  217. package/dist/screenReceiver/index.d.ts +86 -0
  218. package/dist/screenReceiver/index.js +281 -0
  219. package/dist/screenReceiver/index.js.map +1 -0
  220. package/dist/screenReceiver/index.mjs +273 -0
  221. package/dist/screenReceiver/index.mjs.map +1 -0
  222. package/dist/testYourself/admin/index.d.mts +58 -0
  223. package/dist/testYourself/admin/index.d.ts +58 -0
  224. package/dist/testYourself/admin/index.js +1009 -0
  225. package/dist/testYourself/admin/index.js.map +1 -0
  226. package/dist/testYourself/admin/index.mjs +1002 -0
  227. package/dist/testYourself/admin/index.mjs.map +1 -0
  228. package/dist/testYourself/index.d.mts +53 -0
  229. package/dist/testYourself/index.d.ts +53 -0
  230. package/dist/testYourself/index.js +2551 -0
  231. package/dist/testYourself/index.js.map +1 -0
  232. package/dist/testYourself/index.mjs +2531 -0
  233. package/dist/testYourself/index.mjs.map +1 -0
  234. package/dist/testYourself/server/index.d.mts +1029 -0
  235. package/dist/testYourself/server/index.d.ts +1029 -0
  236. package/dist/testYourself/server/index.js +825 -0
  237. package/dist/testYourself/server/index.js.map +1 -0
  238. package/dist/testYourself/server/index.mjs +816 -0
  239. package/dist/testYourself/server/index.mjs.map +1 -0
  240. package/dist/types-BTiaMsBz.d.mts +292 -0
  241. package/dist/types-DyG3ZV9V.d.mts +270 -0
  242. package/dist/types-DyG3ZV9V.d.ts +270 -0
  243. package/dist/types-ERmJyjx8.d.ts +292 -0
  244. package/dist/types-HorDyIRv.d.mts +303 -0
  245. package/dist/types-HorDyIRv.d.ts +303 -0
  246. package/dist/vocaloidBooth/index.d.mts +64 -0
  247. package/dist/vocaloidBooth/index.d.ts +64 -0
  248. package/dist/vocaloidBooth/index.js +376 -0
  249. package/dist/vocaloidBooth/index.js.map +1 -0
  250. package/dist/vocaloidBooth/index.mjs +362 -0
  251. package/dist/vocaloidBooth/index.mjs.map +1 -0
  252. package/dist/vocaloidBooth/server/index.d.mts +111 -0
  253. package/dist/vocaloidBooth/server/index.d.ts +111 -0
  254. package/dist/vocaloidBooth/server/index.js +247 -0
  255. package/dist/vocaloidBooth/server/index.js.map +1 -0
  256. package/dist/vocaloidBooth/server/index.mjs +237 -0
  257. package/dist/vocaloidBooth/server/index.mjs.map +1 -0
  258. package/dist/vocaloidBooth/web/index.d.mts +3 -0
  259. package/dist/vocaloidBooth/web/index.d.ts +3 -0
  260. package/dist/vocaloidBooth/web/index.js +376 -0
  261. package/dist/vocaloidBooth/web/index.js.map +1 -0
  262. package/dist/vocaloidBooth/web/index.mjs +362 -0
  263. package/dist/vocaloidBooth/web/index.mjs.map +1 -0
  264. package/package.json +1 -1
@@ -0,0 +1,1675 @@
1
+ import React5, { createContext, useState, useRef, useCallback, useEffect, useContext, useMemo } from 'react';
2
+ import { createPortal } from 'react-dom';
3
+ import { X, Phone, Lock, EyeOff, Eye, User, LogOut, LogIn } from 'lucide-react';
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+
11
+ // src/business/auth-legacy/index.ts
12
+ var auth_legacy_exports = {};
13
+ __export(auth_legacy_exports, {
14
+ AuthGuard: () => AuthGuard,
15
+ AuthProvider: () => AuthProvider,
16
+ ForgotPasswordModal: () => ForgotPasswordModal,
17
+ LoginModal: () => LoginModal,
18
+ RegisterModal: () => RegisterModal,
19
+ UserMenu: () => UserMenu,
20
+ UserRole: () => UserRole,
21
+ calculateSessionExpiry: () => calculateSessionExpiry,
22
+ generateSessionToken: () => generateSessionToken,
23
+ getUserDisplayName: () => getUserDisplayName,
24
+ isActiveUser: () => isActiveUser,
25
+ isAdmin: () => isAdmin,
26
+ isSessionExpired: () => isSessionExpired,
27
+ useAuth: () => useAuth,
28
+ validatePassword: () => validatePassword,
29
+ validatePhoneNumber: () => validatePhoneNumber
30
+ });
31
+ var AuthContext = createContext(void 0);
32
+ function extractUser(data) {
33
+ return data?.user ?? data?.data?.user ?? null;
34
+ }
35
+ function extractValid(data) {
36
+ if (typeof data?.valid === "boolean") return data.valid;
37
+ if (typeof data?.data?.valid === "boolean") return data.data.valid;
38
+ return false;
39
+ }
40
+ function AuthProvider({ children }) {
41
+ const [user, setUser] = useState(null);
42
+ const [loading, setLoading] = useState(true);
43
+ const [isAuthenticated, setIsAuthenticated] = useState(false);
44
+ const isMountedRef = useRef(true);
45
+ const safeSetState = useCallback((updater) => {
46
+ if (isMountedRef.current) {
47
+ updater();
48
+ }
49
+ }, []);
50
+ const validateSession = useCallback(async () => {
51
+ console.log("\u{1F50D} [AuthContext] \u5F00\u59CB\u9A8C\u8BC1\u4F1A\u8BDD...");
52
+ try {
53
+ const response = await fetch("/api/auth/validate");
54
+ console.log("\u{1F4E1} [AuthContext] \u4F1A\u8BDD\u9A8C\u8BC1\u54CD\u5E94\u72B6\u6001:", response.status);
55
+ const data = await response.json();
56
+ console.log("\u{1F4C4} [AuthContext] \u4F1A\u8BDD\u9A8C\u8BC1\u54CD\u5E94\u6570\u636E:", data);
57
+ const resolvedUser = extractUser(data);
58
+ const resolvedValid = extractValid(data);
59
+ safeSetState(() => {
60
+ if (resolvedValid && resolvedUser) {
61
+ console.log("\u2705 [AuthContext] \u4F1A\u8BDD\u9A8C\u8BC1\u6210\u529F, \u7528\u6237:", resolvedUser);
62
+ setUser(resolvedUser);
63
+ setIsAuthenticated(true);
64
+ } else {
65
+ console.log("\u274C [AuthContext] \u4F1A\u8BDD\u9A8C\u8BC1\u5931\u8D25:", data.message);
66
+ setUser(null);
67
+ setIsAuthenticated(false);
68
+ }
69
+ setLoading(false);
70
+ });
71
+ } catch (error) {
72
+ console.error("\u{1F4A5} [AuthContext] \u4F1A\u8BDD\u9A8C\u8BC1\u5F02\u5E38:", error);
73
+ safeSetState(() => {
74
+ setUser(null);
75
+ setIsAuthenticated(false);
76
+ setLoading(false);
77
+ });
78
+ }
79
+ }, [safeSetState]);
80
+ const login = useCallback(async (credentials) => {
81
+ console.log("\u{1F511} [AuthContext] \u5F00\u59CB\u767B\u5F55...");
82
+ console.log("\u{1F4DD} [AuthContext] \u767B\u5F55\u51ED\u636E:", { phone: credentials.phone, password: "***" });
83
+ try {
84
+ console.log("\u{1F4E4} [AuthContext] \u53D1\u9001\u767B\u5F55\u8BF7\u6C42\u5230 /api/auth/login");
85
+ const response = await fetch("/api/auth/login", {
86
+ method: "POST",
87
+ headers: { "Content-Type": "application/json" },
88
+ body: JSON.stringify(credentials)
89
+ });
90
+ console.log("\u{1F4E1} [AuthContext] \u6536\u5230\u54CD\u5E94\uFF0C\u72B6\u6001\u7801:", response.status);
91
+ const data = await response.json();
92
+ console.log("\u{1F4C4} [AuthContext] \u54CD\u5E94\u6570\u636E:", data);
93
+ const resolvedUser = extractUser(data);
94
+ if (data.success && resolvedUser) {
95
+ console.log("\u2705 [AuthContext] \u767B\u5F55\u6210\u529F, \u5F00\u59CB\u66F4\u65B0\u5168\u5C40\u72B6\u6001");
96
+ console.log("\u{1F464} [AuthContext] \u7528\u6237\u6570\u636E:", resolvedUser);
97
+ console.log("\u{1F4CA} [AuthContext] \u66F4\u65B0\u524D\u72B6\u6001:", {
98
+ currentUser: user ? `${user.name || "\u672A\u8BBE\u7F6E"} (${user.phone})` : null,
99
+ currentIsAuthenticated: isAuthenticated,
100
+ currentLoading: loading
101
+ });
102
+ console.log("\u{1F504} [AuthContext] \u6267\u884C\u5168\u5C40\u72B6\u6001\u66F4\u65B0...");
103
+ safeSetState(() => {
104
+ console.log("\u{1F504} [AuthContext] \u6B63\u5728\u8BBE\u7F6E\u7528\u6237:", resolvedUser);
105
+ setUser(resolvedUser);
106
+ console.log("\u{1F504} [AuthContext] \u6B63\u5728\u8BBE\u7F6E\u8BA4\u8BC1\u72B6\u6001: true");
107
+ setIsAuthenticated(true);
108
+ console.log("\u{1F504} [AuthContext] \u6B63\u5728\u8BBE\u7F6E\u52A0\u8F7D\u72B6\u6001: false");
109
+ setLoading(false);
110
+ console.log("\u2705 [AuthContext] \u5168\u5C40\u72B6\u6001\u66F4\u65B0\u5B8C\u6210");
111
+ });
112
+ setTimeout(() => {
113
+ console.log("\u{1F389} [AuthContext] \u5EF6\u8FDF\u786E\u8BA4 - \u5168\u5C40\u767B\u5F55\u72B6\u6001\u5E94\u8BE5\u5DF2\u66F4\u65B0:", {
114
+ user: resolvedUser,
115
+ isAuthenticated: true
116
+ });
117
+ }, 0);
118
+ console.log("\u{1F680} [AuthContext] \u8FD4\u56DE\u6210\u529F\u7ED3\u679C");
119
+ return { success: true, user: resolvedUser };
120
+ } else {
121
+ console.log("\u274C [AuthContext] \u767B\u5F55\u5931\u8D25:", data.message);
122
+ return { success: false, message: data.message };
123
+ }
124
+ } catch (error) {
125
+ console.error("\u{1F4A5} [AuthContext] \u767B\u5F55\u5F02\u5E38:", error);
126
+ return { success: false, message: "\u767B\u5F55\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5" };
127
+ }
128
+ }, [safeSetState, user, isAuthenticated, loading]);
129
+ const register = useCallback(async (userData) => {
130
+ console.log("\u{1F4DD} [AuthContext] \u5F00\u59CB\u6CE8\u518C...");
131
+ try {
132
+ const response = await fetch("/api/auth/register", {
133
+ method: "POST",
134
+ headers: { "Content-Type": "application/json" },
135
+ body: JSON.stringify(userData)
136
+ });
137
+ const data = await response.json();
138
+ console.log("\u{1F4E1} [AuthContext] \u6CE8\u518C\u54CD\u5E94:", data);
139
+ const resolvedUser = extractUser(data);
140
+ if (data.success && resolvedUser) {
141
+ console.log("\u2705 [AuthContext] \u6CE8\u518C\u6210\u529F, \u7ACB\u5373\u66F4\u65B0\u5168\u5C40\u72B6\u6001");
142
+ safeSetState(() => {
143
+ setUser(resolvedUser);
144
+ setIsAuthenticated(true);
145
+ setLoading(false);
146
+ });
147
+ console.log("\u{1F680} [AuthContext] \u8FD4\u56DE\u6CE8\u518C\u6210\u529F\u7ED3\u679C");
148
+ return { success: true, user: resolvedUser };
149
+ } else {
150
+ console.log("\u274C [AuthContext] \u6CE8\u518C\u5931\u8D25:", data.message);
151
+ return { success: false, message: data.message };
152
+ }
153
+ } catch (error) {
154
+ console.error("\u{1F4A5} [AuthContext] \u6CE8\u518C\u5F02\u5E38:", error);
155
+ return { success: false, message: "\u6CE8\u518C\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5" };
156
+ }
157
+ }, [safeSetState]);
158
+ const logout = useCallback(async () => {
159
+ console.log("\u{1F6AA} [AuthContext] \u5F00\u59CB\u767B\u51FA...");
160
+ try {
161
+ await fetch("/api/auth/logout", { method: "POST" });
162
+ safeSetState(() => {
163
+ setUser(null);
164
+ setIsAuthenticated(false);
165
+ });
166
+ console.log("\u2705 [AuthContext] \u767B\u51FA\u6210\u529F, \u5168\u5C40\u72B6\u6001\u5DF2\u6E05\u9664");
167
+ } catch (error) {
168
+ console.error("\u{1F4A5} [AuthContext] \u767B\u51FA\u5931\u8D25:", error);
169
+ }
170
+ }, [safeSetState]);
171
+ const refreshUser = useCallback(() => {
172
+ console.log("\u{1F504} [AuthContext] \u5237\u65B0\u7528\u6237\u4FE1\u606F...");
173
+ setLoading(true);
174
+ validateSession();
175
+ }, [validateSession]);
176
+ useEffect(() => {
177
+ isMountedRef.current = true;
178
+ return () => {
179
+ isMountedRef.current = false;
180
+ };
181
+ }, []);
182
+ useEffect(() => {
183
+ console.log("\u{1F680} [AuthContext] \u521D\u59CB\u5316, \u5F00\u59CB\u9A8C\u8BC1\u4F1A\u8BDD");
184
+ validateSession();
185
+ }, [validateSession]);
186
+ useEffect(() => {
187
+ console.log("\u{1F4CA} [AuthContext] \u5168\u5C40\u72B6\u6001\u53D8\u5316:", {
188
+ isAuthenticated,
189
+ user: user ? `${user.name || "\u672A\u8BBE\u7F6E"} (${user.phone})` : null,
190
+ loading
191
+ });
192
+ }, [isAuthenticated, user, loading]);
193
+ const value = {
194
+ user,
195
+ loading,
196
+ isAuthenticated,
197
+ login,
198
+ register,
199
+ logout,
200
+ refreshUser
201
+ };
202
+ return /* @__PURE__ */ React5.createElement(AuthContext.Provider, { value }, children);
203
+ }
204
+ function useAuth() {
205
+ const context = useContext(AuthContext);
206
+ if (context === void 0) {
207
+ throw new Error("useAuth must be used within an AuthProvider");
208
+ }
209
+ return context;
210
+ }
211
+
212
+ // src/business/auth-legacy/utils/authUtils.ts
213
+ function validatePhoneNumber(phone) {
214
+ return /^1[3-9]\d{9}$/.test(phone);
215
+ }
216
+ function validatePassword(password) {
217
+ if (!password) {
218
+ return { valid: false, message: "\u5BC6\u7801\u4E0D\u80FD\u4E3A\u7A7A" };
219
+ }
220
+ if (password.length < 6) {
221
+ return { valid: false, message: "\u5BC6\u7801\u957F\u5EA6\u81F3\u5C116\u4F4D" };
222
+ }
223
+ return { valid: true };
224
+ }
225
+ function generateSessionToken() {
226
+ return Math.random().toString(36).substring(2) + Date.now().toString(36) + Math.random().toString(36).substring(2);
227
+ }
228
+ function isAdmin(user) {
229
+ return user?.role === "admin";
230
+ }
231
+ function isActiveUser(user) {
232
+ return user?.isActive === true;
233
+ }
234
+ function getUserDisplayName(user) {
235
+ return user.name || user.phone || "\u672A\u77E5\u7528\u6237";
236
+ }
237
+ function calculateSessionExpiry(days = 30) {
238
+ return new Date(Date.now() + days * 24 * 60 * 60 * 1e3);
239
+ }
240
+ function isSessionExpired(expiresAt) {
241
+ return /* @__PURE__ */ new Date() > new Date(expiresAt);
242
+ }
243
+ function ForgotPasswordModal({ isOpen, onClose, onSuccess }) {
244
+ const [formData, setFormData] = useState({
245
+ phone: "",
246
+ newPassword: "",
247
+ confirmPassword: "",
248
+ verificationCode: ""
249
+ });
250
+ const [showPassword, setShowPassword] = useState(false);
251
+ const [showConfirmPassword, setShowConfirmPassword] = useState(false);
252
+ const [error, setError] = useState("");
253
+ const [loading, setLoading] = useState(false);
254
+ const [countdown, setCountdown] = useState(0);
255
+ const [mounted, setMounted] = useState(false);
256
+ useEffect(() => {
257
+ setMounted(true);
258
+ }, []);
259
+ const handleInputChange = (e) => {
260
+ const { name, value } = e.target;
261
+ setFormData((prev) => ({ ...prev, [name]: value }));
262
+ if (error) setError("");
263
+ };
264
+ const validateForm = () => {
265
+ if (!formData.phone || !formData.newPassword || !formData.confirmPassword || !formData.verificationCode) {
266
+ setError("\u8BF7\u586B\u5199\u5B8C\u6574\u4FE1\u606F");
267
+ return false;
268
+ }
269
+ if (!validatePhoneNumber(formData.phone)) {
270
+ setError("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7\u683C\u5F0F");
271
+ return false;
272
+ }
273
+ const passwordValidation = validatePassword(formData.newPassword);
274
+ if (!passwordValidation.valid) {
275
+ setError(passwordValidation.message || "\u5BC6\u7801\u683C\u5F0F\u9519\u8BEF");
276
+ return false;
277
+ }
278
+ if (formData.newPassword !== formData.confirmPassword) {
279
+ setError("\u4E24\u6B21\u8F93\u5165\u7684\u5BC6\u7801\u4E0D\u4E00\u81F4");
280
+ return false;
281
+ }
282
+ if (!/^\d{6}$/.test(formData.verificationCode)) {
283
+ setError("\u8BF7\u8F93\u51656\u4F4D\u6570\u5B57\u9A8C\u8BC1\u7801");
284
+ return false;
285
+ }
286
+ return true;
287
+ };
288
+ const handleSendCode = async () => {
289
+ if (!formData.phone) {
290
+ setError("\u8BF7\u8F93\u5165\u624B\u673A\u53F7");
291
+ return;
292
+ }
293
+ if (!validatePhoneNumber(formData.phone)) {
294
+ setError("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7\u683C\u5F0F");
295
+ return;
296
+ }
297
+ try {
298
+ setLoading(true);
299
+ setError("");
300
+ const response = await fetch("/api/auth/send-verification-code", {
301
+ method: "POST",
302
+ headers: { "Content-Type": "application/json" },
303
+ body: JSON.stringify({ phone: formData.phone })
304
+ });
305
+ const data = await response.json();
306
+ if (data.success) {
307
+ setCountdown(60);
308
+ const timer = setInterval(() => {
309
+ setCountdown((prev) => {
310
+ if (prev <= 1) {
311
+ clearInterval(timer);
312
+ return 0;
313
+ }
314
+ return prev - 1;
315
+ });
316
+ }, 1e3);
317
+ console.log("\u2705 \u9A8C\u8BC1\u7801\u53D1\u9001\u6210\u529F");
318
+ } else {
319
+ setError(data.message || "\u53D1\u9001\u9A8C\u8BC1\u7801\u5931\u8D25");
320
+ }
321
+ } catch (error2) {
322
+ console.error("\u53D1\u9001\u9A8C\u8BC1\u7801\u5F02\u5E38:", error2);
323
+ setError("\u53D1\u9001\u9A8C\u8BC1\u7801\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
324
+ } finally {
325
+ setLoading(false);
326
+ }
327
+ };
328
+ const handleSubmit = async (e) => {
329
+ e.preventDefault();
330
+ setError("");
331
+ setLoading(true);
332
+ try {
333
+ if (!validateForm()) {
334
+ return;
335
+ }
336
+ const response = await fetch("/api/auth/reset-password", {
337
+ method: "POST",
338
+ headers: { "Content-Type": "application/json" },
339
+ body: JSON.stringify({
340
+ phone: formData.phone,
341
+ newPassword: formData.newPassword,
342
+ verificationCode: formData.verificationCode
343
+ })
344
+ });
345
+ const data = await response.json();
346
+ if (data.success) {
347
+ onSuccess();
348
+ } else {
349
+ setError(data.message || "\u91CD\u7F6E\u5BC6\u7801\u5931\u8D25");
350
+ }
351
+ } catch (error2) {
352
+ setError("\u91CD\u7F6E\u5BC6\u7801\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
353
+ } finally {
354
+ setLoading(false);
355
+ }
356
+ };
357
+ const handleOverlayClick = (e) => {
358
+ if (e.target === e.currentTarget) {
359
+ onClose();
360
+ }
361
+ };
362
+ if (!isOpen || !mounted) return null;
363
+ const modalContent = /* @__PURE__ */ React5.createElement(
364
+ "div",
365
+ {
366
+ className: "fixed top-0 left-0 right-0 bottom-0 w-screen h-screen bg-black/50 backdrop-blur-sm flex items-center justify-center z-[9999] p-4",
367
+ style: { margin: 0 },
368
+ onClick: handleOverlayClick
369
+ },
370
+ /* @__PURE__ */ React5.createElement(
371
+ "div",
372
+ {
373
+ className: "bg-white rounded-2xl shadow-xl w-full max-w-[420px] max-h-[90vh] overflow-y-auto relative",
374
+ onClick: (e) => e.stopPropagation()
375
+ },
376
+ /* @__PURE__ */ React5.createElement(
377
+ "button",
378
+ {
379
+ className: "absolute top-5 right-5 bg-transparent border-none text-gray-500 cursor-pointer p-2 rounded-lg transition-all hover:bg-gray-100 hover:text-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 min-w-9 min-h-9 flex items-center justify-center",
380
+ onClick: onClose
381
+ },
382
+ /* @__PURE__ */ React5.createElement(X, { size: 20 })
383
+ ),
384
+ /* @__PURE__ */ React5.createElement("div", { className: "px-6 pt-6 pb-4 text-center border-b border-gray-100" }, /* @__PURE__ */ React5.createElement("h2", { className: "text-2xl font-semibold text-gray-800 mb-2" }, "\u91CD\u7F6E\u5BC6\u7801"), /* @__PURE__ */ React5.createElement("p", { className: "text-gray-500 text-sm" }, "\u8BF7\u8F93\u5165\u624B\u673A\u53F7\u548C\u9A8C\u8BC1\u7801\u91CD\u7F6E\u5BC6\u7801")),
385
+ /* @__PURE__ */ React5.createElement("form", { onSubmit: handleSubmit, className: "p-6" }, /* @__PURE__ */ React5.createElement("div", { className: "mb-5" }, /* @__PURE__ */ React5.createElement("label", { htmlFor: "phone", className: "block mb-1.5 text-sm font-medium text-gray-700" }, "\u624B\u673A\u53F7"), /* @__PURE__ */ React5.createElement("div", { className: "relative flex items-center" }, /* @__PURE__ */ React5.createElement(Phone, { size: 18, className: "absolute left-4 text-gray-400 z-[1] pointer-events-none" }), /* @__PURE__ */ React5.createElement(
386
+ "input",
387
+ {
388
+ id: "phone",
389
+ name: "phone",
390
+ type: "tel",
391
+ value: formData.phone,
392
+ onChange: handleInputChange,
393
+ placeholder: "\u8BF7\u8F93\u5165\u624B\u673A\u53F7",
394
+ className: "w-full py-3 px-4 pl-12 border-2 border-gray-200 rounded-lg text-base transition-all box-border min-h-12 bg-white focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/10 placeholder:text-gray-400 disabled:bg-gray-50 disabled:text-gray-500 disabled:cursor-not-allowed",
395
+ disabled: loading
396
+ }
397
+ ))), /* @__PURE__ */ React5.createElement("div", { className: "mb-5" }, /* @__PURE__ */ React5.createElement("label", { htmlFor: "verificationCode", className: "block mb-1.5 text-sm font-medium text-gray-700" }, "\u9A8C\u8BC1\u7801"), /* @__PURE__ */ React5.createElement("div", { className: "relative flex items-center" }, /* @__PURE__ */ React5.createElement(
398
+ "input",
399
+ {
400
+ id: "verificationCode",
401
+ name: "verificationCode",
402
+ type: "text",
403
+ value: formData.verificationCode,
404
+ onChange: handleInputChange,
405
+ placeholder: "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801",
406
+ className: "w-full py-3 px-4 pr-28 border-2 border-gray-200 rounded-lg text-base transition-all box-border min-h-12 bg-white focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/10 placeholder:text-gray-400 disabled:bg-gray-50 disabled:text-gray-500 disabled:cursor-not-allowed",
407
+ disabled: loading,
408
+ maxLength: 6
409
+ }
410
+ ), /* @__PURE__ */ React5.createElement(
411
+ "button",
412
+ {
413
+ type: "button",
414
+ className: "absolute right-2 top-1/2 -translate-y-1/2 bg-transparent border-none text-blue-500 text-sm font-medium cursor-pointer px-2 py-1 rounded transition-all whitespace-nowrap hover:bg-blue-50 disabled:text-gray-400 disabled:cursor-not-allowed",
415
+ onClick: handleSendCode,
416
+ disabled: loading || countdown > 0
417
+ },
418
+ countdown > 0 ? `${countdown}\u79D2\u540E\u91CD\u8BD5` : "\u53D1\u9001\u9A8C\u8BC1\u7801"
419
+ ))), /* @__PURE__ */ React5.createElement("div", { className: "mb-5" }, /* @__PURE__ */ React5.createElement("label", { htmlFor: "newPassword", className: "block mb-1.5 text-sm font-medium text-gray-700" }, "\u65B0\u5BC6\u7801"), /* @__PURE__ */ React5.createElement("div", { className: "relative flex items-center" }, /* @__PURE__ */ React5.createElement(Lock, { size: 18, className: "absolute left-4 text-gray-400 z-[1] pointer-events-none" }), /* @__PURE__ */ React5.createElement(
420
+ "input",
421
+ {
422
+ id: "newPassword",
423
+ name: "newPassword",
424
+ type: showPassword ? "text" : "password",
425
+ value: formData.newPassword,
426
+ onChange: handleInputChange,
427
+ placeholder: "\u8BF7\u8F93\u5165\u65B0\u5BC6\u7801",
428
+ className: "w-full py-3 px-4 pl-12 pr-12 border-2 border-gray-200 rounded-lg text-base transition-all box-border min-h-12 bg-white focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/10 placeholder:text-gray-400 disabled:bg-gray-50 disabled:text-gray-500 disabled:cursor-not-allowed",
429
+ disabled: loading
430
+ }
431
+ ), /* @__PURE__ */ React5.createElement(
432
+ "button",
433
+ {
434
+ type: "button",
435
+ className: "absolute right-4 bg-transparent border-none text-gray-400 cursor-pointer p-1 rounded transition-all flex items-center justify-center min-w-6 min-h-6 hover:text-gray-600 hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50",
436
+ onClick: () => setShowPassword(!showPassword),
437
+ disabled: loading
438
+ },
439
+ showPassword ? /* @__PURE__ */ React5.createElement(EyeOff, { size: 18 }) : /* @__PURE__ */ React5.createElement(Eye, { size: 18 })
440
+ ))), /* @__PURE__ */ React5.createElement("div", { className: "mb-5" }, /* @__PURE__ */ React5.createElement("label", { htmlFor: "confirmPassword", className: "block mb-1.5 text-sm font-medium text-gray-700" }, "\u786E\u8BA4\u5BC6\u7801"), /* @__PURE__ */ React5.createElement("div", { className: "relative flex items-center" }, /* @__PURE__ */ React5.createElement(Lock, { size: 18, className: "absolute left-4 text-gray-400 z-[1] pointer-events-none" }), /* @__PURE__ */ React5.createElement(
441
+ "input",
442
+ {
443
+ id: "confirmPassword",
444
+ name: "confirmPassword",
445
+ type: showConfirmPassword ? "text" : "password",
446
+ value: formData.confirmPassword,
447
+ onChange: handleInputChange,
448
+ placeholder: "\u8BF7\u518D\u6B21\u8F93\u5165\u65B0\u5BC6\u7801",
449
+ className: "w-full py-3 px-4 pl-12 pr-12 border-2 border-gray-200 rounded-lg text-base transition-all box-border min-h-12 bg-white focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/10 placeholder:text-gray-400 disabled:bg-gray-50 disabled:text-gray-500 disabled:cursor-not-allowed",
450
+ disabled: loading
451
+ }
452
+ ), /* @__PURE__ */ React5.createElement(
453
+ "button",
454
+ {
455
+ type: "button",
456
+ className: "absolute right-4 bg-transparent border-none text-gray-400 cursor-pointer p-1 rounded transition-all flex items-center justify-center min-w-6 min-h-6 hover:text-gray-600 hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50",
457
+ onClick: () => setShowConfirmPassword(!showConfirmPassword),
458
+ disabled: loading
459
+ },
460
+ showConfirmPassword ? /* @__PURE__ */ React5.createElement(EyeOff, { size: 18 }) : /* @__PURE__ */ React5.createElement(Eye, { size: 18 })
461
+ ))), error && /* @__PURE__ */ React5.createElement("div", { className: "text-red-500 text-sm my-4 p-3 bg-red-50 border border-red-200 rounded-lg leading-relaxed" }, error), /* @__PURE__ */ React5.createElement(
462
+ "button",
463
+ {
464
+ type: "submit",
465
+ className: "w-full bg-blue-500 text-white border-none py-3.5 px-6 rounded-lg text-base font-medium cursor-pointer transition-all mt-2 min-h-[52px] hover:bg-blue-600 hover:-translate-y-0.5 hover:shadow-lg hover:shadow-blue-500/30 active:translate-y-0 disabled:bg-gray-400 disabled:cursor-not-allowed disabled:transform-none disabled:shadow-none focus:outline-none focus:ring-2 focus:ring-blue-700 focus:ring-offset-2",
466
+ disabled: loading
467
+ },
468
+ loading ? "\u63D0\u4EA4\u4E2D..." : "\u91CD\u7F6E\u5BC6\u7801"
469
+ ))
470
+ )
471
+ );
472
+ return createPortal(modalContent, document.body);
473
+ }
474
+
475
+ // src/business/auth-legacy/components/LoginModal.tsx
476
+ function LoginModal({ isOpen, onClose, onSuccess, onSwitchToRegister }) {
477
+ const { login } = useAuth();
478
+ const [formData, setFormData] = useState({
479
+ phone: "",
480
+ password: ""
481
+ });
482
+ const [showPassword, setShowPassword] = useState(false);
483
+ const [error, setError] = useState("");
484
+ const [loading, setLoading] = useState(false);
485
+ const [showForgotPassword, setShowForgotPassword] = useState(false);
486
+ const [mounted, setMounted] = useState(false);
487
+ useEffect(() => {
488
+ setMounted(true);
489
+ }, []);
490
+ const fillDemoAccount = (type) => {
491
+ if (process.env.NODE_ENV === "development") {
492
+ const accounts = {
493
+ admin: { phone: "13800138000", password: "admin123456" },
494
+ user: { phone: "13900139000", password: "test123456" }
495
+ };
496
+ setFormData(accounts[type]);
497
+ setError("");
498
+ }
499
+ };
500
+ const handleInputChange = (e) => {
501
+ const { name, value } = e.target;
502
+ setFormData((prev) => ({ ...prev, [name]: value }));
503
+ if (error) setError("");
504
+ };
505
+ const handleSubmit = async (e) => {
506
+ e.preventDefault();
507
+ setError("");
508
+ setLoading(true);
509
+ console.log("\u{1F504} [LoginModal] handleSubmit \u5F00\u59CB");
510
+ try {
511
+ if (!formData.phone || !formData.password) {
512
+ console.log("\u274C [LoginModal] \u524D\u7AEF\u9A8C\u8BC1\u5931\u8D25: \u4FE1\u606F\u4E0D\u5B8C\u6574");
513
+ setError("\u8BF7\u586B\u5199\u5B8C\u6574\u4FE1\u606F");
514
+ return;
515
+ }
516
+ if (!validatePhoneNumber(formData.phone)) {
517
+ console.log("\u274C [LoginModal] \u524D\u7AEF\u9A8C\u8BC1\u5931\u8D25: \u624B\u673A\u53F7\u683C\u5F0F\u9519\u8BEF");
518
+ setError("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7");
519
+ return;
520
+ }
521
+ console.log("\u2705 [LoginModal] \u524D\u7AEF\u9A8C\u8BC1\u901A\u8FC7");
522
+ console.log("\u{1F511} [LoginModal] \u63D0\u4EA4\u767B\u5F55\u8868\u5355:", {
523
+ phone: formData.phone,
524
+ password: "***"
525
+ });
526
+ console.log("\u{1F4DE} [LoginModal] \u51C6\u5907\u8C03\u7528 useAuth.login()...");
527
+ const result = await login(formData);
528
+ console.log("\u{1F4E1} [LoginModal] useAuth.login() \u8FD4\u56DE\u7ED3\u679C:", result);
529
+ if (result.success) {
530
+ console.log("\u2705 [LoginModal] \u767B\u5F55\u6210\u529F\uFF0C\u51C6\u5907\u8C03\u7528 onSuccess()");
531
+ console.log("\u{1F464} [LoginModal] \u767B\u5F55\u6210\u529F\u7684\u7528\u6237\u4FE1\u606F:", result.user);
532
+ setTimeout(() => {
533
+ console.log("\u{1F3AF} [LoginModal] \u8C03\u7528 onSuccess \u56DE\u8C03");
534
+ onSuccess();
535
+ console.log("\u{1F3C1} [LoginModal] onSuccess \u8C03\u7528\u5B8C\u6210");
536
+ }, 100);
537
+ } else {
538
+ console.log("\u274C [LoginModal] \u767B\u5F55\u5931\u8D25:", result.message);
539
+ setError(result.message || "\u767B\u5F55\u5931\u8D25");
540
+ }
541
+ } catch (error2) {
542
+ console.error("\u{1F4A5} [LoginModal] \u767B\u5F55\u5F02\u5E38:", error2);
543
+ setError("\u767B\u5F55\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
544
+ } finally {
545
+ console.log("\u{1F51A} [LoginModal] handleSubmit \u7ED3\u675F\uFF0C\u8BBE\u7F6E loading = false");
546
+ setLoading(false);
547
+ }
548
+ };
549
+ const handleOverlayClick = (e) => {
550
+ if (e.target === e.currentTarget) {
551
+ onClose();
552
+ }
553
+ };
554
+ if (!isOpen || !mounted) return null;
555
+ const modalContent = /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
556
+ "div",
557
+ {
558
+ className: "fixed top-0 left-0 right-0 bottom-0 w-screen h-screen bg-black/50 backdrop-blur-sm flex items-center justify-center z-[9999] p-4",
559
+ style: { margin: 0 },
560
+ onClick: handleOverlayClick
561
+ },
562
+ /* @__PURE__ */ React5.createElement(
563
+ "div",
564
+ {
565
+ className: "bg-white rounded-2xl shadow-xl w-full max-w-[420px] max-h-[90vh] overflow-y-auto relative",
566
+ onClick: (e) => e.stopPropagation()
567
+ },
568
+ /* @__PURE__ */ React5.createElement(
569
+ "button",
570
+ {
571
+ className: "absolute top-5 right-5 bg-transparent border-none text-gray-500 cursor-pointer p-2 rounded-lg transition-all hover:bg-gray-100 hover:text-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 min-w-9 min-h-9 flex items-center justify-center",
572
+ onClick: onClose
573
+ },
574
+ /* @__PURE__ */ React5.createElement(X, { size: 20 })
575
+ ),
576
+ /* @__PURE__ */ React5.createElement("div", { className: "px-6 pt-6 pb-4 text-center border-b border-gray-100" }, /* @__PURE__ */ React5.createElement("h2", { className: "text-2xl font-semibold text-gray-800 mb-2" }, "\u7528\u6237\u767B\u5F55"), /* @__PURE__ */ React5.createElement("p", { className: "text-gray-500 text-sm" }, "\u8BF7\u8F93\u5165\u60A8\u7684\u624B\u673A\u53F7\u548C\u5BC6\u7801")),
577
+ process.env.NODE_ENV === "development" && /* @__PURE__ */ React5.createElement("div", { className: "px-6 py-4 bg-amber-50 border-b border-gray-100" }, /* @__PURE__ */ React5.createElement("p", { className: "text-xs text-amber-800 font-medium mb-2" }, "\u5F00\u53D1\u73AF\u5883\u5FEB\u6377\u767B\u5F55\uFF1A"), /* @__PURE__ */ React5.createElement("div", { className: "flex gap-2" }, /* @__PURE__ */ React5.createElement(
578
+ "button",
579
+ {
580
+ type: "button",
581
+ onClick: () => fillDemoAccount("admin"),
582
+ className: "px-3 py-1.5 text-xs bg-amber-400 text-amber-900 border-none rounded-md cursor-pointer transition-all font-medium hover:bg-amber-500"
583
+ },
584
+ "\u7BA1\u7406\u5458\u8D26\u53F7"
585
+ ), /* @__PURE__ */ React5.createElement(
586
+ "button",
587
+ {
588
+ type: "button",
589
+ onClick: () => fillDemoAccount("user"),
590
+ className: "px-3 py-1.5 text-xs bg-amber-400 text-amber-900 border-none rounded-md cursor-pointer transition-all font-medium hover:bg-amber-500"
591
+ },
592
+ "\u7528\u6237\u8D26\u53F7"
593
+ ))),
594
+ /* @__PURE__ */ React5.createElement("form", { onSubmit: handleSubmit, className: "p-6" }, /* @__PURE__ */ React5.createElement("div", { className: "mb-5" }, /* @__PURE__ */ React5.createElement("label", { htmlFor: "phone", className: "block mb-1.5 text-sm font-medium text-gray-700" }, "\u624B\u673A\u53F7"), /* @__PURE__ */ React5.createElement("div", { className: "relative flex items-center" }, /* @__PURE__ */ React5.createElement(User, { size: 18, className: "absolute left-4 text-gray-400 z-[1] pointer-events-none" }), /* @__PURE__ */ React5.createElement(
595
+ "input",
596
+ {
597
+ id: "phone",
598
+ name: "phone",
599
+ type: "tel",
600
+ autoComplete: "tel",
601
+ value: formData.phone,
602
+ onChange: handleInputChange,
603
+ placeholder: "\u8BF7\u8F93\u5165\u624B\u673A\u53F7",
604
+ className: "w-full py-3 px-4 pl-12 border-2 border-gray-200 rounded-lg text-base transition-all box-border min-h-12 bg-white focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/10 placeholder:text-gray-400 disabled:bg-gray-50 disabled:text-gray-500 disabled:cursor-not-allowed",
605
+ disabled: loading
606
+ }
607
+ ))), /* @__PURE__ */ React5.createElement("div", { className: "mb-5" }, /* @__PURE__ */ React5.createElement("label", { htmlFor: "password", className: "block mb-1.5 text-sm font-medium text-gray-700" }, "\u5BC6\u7801"), /* @__PURE__ */ React5.createElement("div", { className: "relative flex items-center" }, /* @__PURE__ */ React5.createElement(Lock, { size: 18, className: "absolute left-4 text-gray-400 z-[1] pointer-events-none" }), /* @__PURE__ */ React5.createElement(
608
+ "input",
609
+ {
610
+ id: "password",
611
+ name: "password",
612
+ type: showPassword ? "text" : "password",
613
+ autoComplete: "current-password",
614
+ value: formData.password,
615
+ onChange: handleInputChange,
616
+ placeholder: "\u8BF7\u8F93\u5165\u5BC6\u7801",
617
+ className: "w-full py-3 px-4 pl-12 pr-12 border-2 border-gray-200 rounded-lg text-base transition-all box-border min-h-12 bg-white focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/10 placeholder:text-gray-400 disabled:bg-gray-50 disabled:text-gray-500 disabled:cursor-not-allowed",
618
+ disabled: loading
619
+ }
620
+ ), /* @__PURE__ */ React5.createElement(
621
+ "button",
622
+ {
623
+ type: "button",
624
+ className: "absolute right-4 bg-transparent border-none text-gray-400 cursor-pointer p-1 rounded transition-all flex items-center justify-center min-w-6 min-h-6 hover:text-gray-600 hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50",
625
+ onClick: () => setShowPassword(!showPassword),
626
+ disabled: loading
627
+ },
628
+ showPassword ? /* @__PURE__ */ React5.createElement(EyeOff, { size: 18 }) : /* @__PURE__ */ React5.createElement(Eye, { size: 18 })
629
+ ))), /* @__PURE__ */ React5.createElement("div", { className: "text-right -mt-2 mb-4" }, /* @__PURE__ */ React5.createElement(
630
+ "button",
631
+ {
632
+ type: "button",
633
+ onClick: () => setShowForgotPassword(true),
634
+ className: "bg-transparent border-none text-blue-500 cursor-pointer text-sm font-medium underline px-1 py-0.5 rounded transition-all hover:text-blue-600 hover:bg-blue-50 hover:no-underline focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
635
+ },
636
+ "\u5FD8\u8BB0\u5BC6\u7801\uFF1F"
637
+ )), error && /* @__PURE__ */ React5.createElement("div", { className: "text-red-500 text-sm my-4 p-3 bg-red-50 border border-red-200 rounded-lg leading-relaxed" }, error), /* @__PURE__ */ React5.createElement(
638
+ "button",
639
+ {
640
+ type: "submit",
641
+ className: "w-full bg-blue-500 text-white border-none py-3.5 px-6 rounded-lg text-base font-medium cursor-pointer transition-all mt-2 min-h-[52px] hover:bg-blue-600 hover:-translate-y-0.5 hover:shadow-lg hover:shadow-blue-500/30 active:translate-y-0 disabled:bg-gray-400 disabled:cursor-not-allowed disabled:transform-none disabled:shadow-none focus:outline-none focus:ring-2 focus:ring-blue-700 focus:ring-offset-2",
642
+ disabled: loading
643
+ },
644
+ loading ? "\u767B\u5F55\u4E2D..." : "\u767B\u5F55"
645
+ ), onSwitchToRegister && /* @__PURE__ */ React5.createElement("div", { className: "text-center mt-5 pt-4 border-t border-gray-100" }, /* @__PURE__ */ React5.createElement("span", { className: "text-gray-500 text-sm mr-1" }, "\u8FD8\u6CA1\u6709\u8D26\u53F7\uFF1F"), /* @__PURE__ */ React5.createElement(
646
+ "button",
647
+ {
648
+ type: "button",
649
+ onClick: onSwitchToRegister,
650
+ className: "bg-transparent border-none text-blue-500 cursor-pointer text-sm font-medium underline px-1 py-0.5 rounded transition-all hover:text-blue-600 hover:bg-blue-50 hover:no-underline focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
651
+ },
652
+ "\u7ACB\u5373\u6CE8\u518C"
653
+ )))
654
+ )
655
+ ), /* @__PURE__ */ React5.createElement(
656
+ ForgotPasswordModal,
657
+ {
658
+ isOpen: showForgotPassword,
659
+ onClose: () => setShowForgotPassword(false),
660
+ onSuccess: () => {
661
+ setShowForgotPassword(false);
662
+ onSuccess();
663
+ }
664
+ }
665
+ ));
666
+ return createPortal(modalContent, document.body);
667
+ }
668
+
669
+ // src/business/auth-legacy/components/AuthGuard.tsx
670
+ function AuthGuard({
671
+ children,
672
+ fallback,
673
+ requireAuth = true
674
+ }) {
675
+ const { isAuthenticated, loading, refreshUser } = useAuth();
676
+ const [showLoginModal, setShowLoginModal] = useState(false);
677
+ useEffect(() => {
678
+ if (!loading && requireAuth && !isAuthenticated) {
679
+ setShowLoginModal(true);
680
+ }
681
+ }, [loading, requireAuth, isAuthenticated]);
682
+ const handleLoginSuccess = () => {
683
+ refreshUser();
684
+ setShowLoginModal(false);
685
+ };
686
+ if (loading) {
687
+ return /* @__PURE__ */ React5.createElement("div", { style: {
688
+ display: "flex",
689
+ alignItems: "center",
690
+ justifyContent: "center",
691
+ minHeight: "200px",
692
+ color: "#6b7280",
693
+ flexDirection: "column",
694
+ gap: "12px"
695
+ } }, /* @__PURE__ */ React5.createElement("div", { style: {
696
+ width: "32px",
697
+ height: "32px",
698
+ border: "3px solid #e5e7eb",
699
+ borderTop: "3px solid #3b82f6",
700
+ borderRadius: "50%",
701
+ animation: "spin 1s linear infinite"
702
+ } }), /* @__PURE__ */ React5.createElement("div", null, "\u9A8C\u8BC1\u767B\u5F55\u72B6\u6001..."));
703
+ }
704
+ if (requireAuth && !isAuthenticated) {
705
+ return /* @__PURE__ */ React5.createElement(React5.Fragment, null, fallback || /* @__PURE__ */ React5.createElement("div", { style: {
706
+ display: "flex",
707
+ alignItems: "center",
708
+ justifyContent: "center",
709
+ minHeight: "200px",
710
+ color: "#6b7280",
711
+ flexDirection: "column",
712
+ gap: "16px",
713
+ padding: "24px",
714
+ textAlign: "center"
715
+ } }, /* @__PURE__ */ React5.createElement("div", { style: {
716
+ fontSize: "48px",
717
+ opacity: 0.5
718
+ } }, "\u{1F512}"), /* @__PURE__ */ React5.createElement("div", { style: {
719
+ fontSize: "18px",
720
+ fontWeight: "500"
721
+ } }, "\u8BF7\u5148\u767B\u5F55\u4EE5\u8BBF\u95EE\u6B64\u9875\u9762"), /* @__PURE__ */ React5.createElement("div", { style: {
722
+ fontSize: "14px",
723
+ opacity: 0.7
724
+ } }, "\u767B\u5F55\u540E\u5373\u53EF\u67E5\u770B\u76F8\u5173\u5185\u5BB9")), /* @__PURE__ */ React5.createElement(
725
+ LoginModal,
726
+ {
727
+ isOpen: showLoginModal,
728
+ onClose: () => setShowLoginModal(false),
729
+ onSuccess: handleLoginSuccess
730
+ }
731
+ ));
732
+ }
733
+ return /* @__PURE__ */ React5.createElement(React5.Fragment, null, children);
734
+ }
735
+ function RegisterModal({ isOpen, onClose, onSuccess, onSwitchToLogin }) {
736
+ const { register } = useAuth();
737
+ const [formData, setFormData] = useState({
738
+ phone: "",
739
+ password: "",
740
+ confirmPassword: "",
741
+ name: ""
742
+ });
743
+ const [showPassword, setShowPassword] = useState(false);
744
+ const [showConfirmPassword, setShowConfirmPassword] = useState(false);
745
+ const [error, setError] = useState("");
746
+ const [loading, setLoading] = useState(false);
747
+ const [mounted, setMounted] = useState(false);
748
+ useEffect(() => {
749
+ setMounted(true);
750
+ }, []);
751
+ const handleInputChange = (e) => {
752
+ const { name, value } = e.target;
753
+ setFormData((prev) => ({ ...prev, [name]: value }));
754
+ if (error) setError("");
755
+ };
756
+ const validateForm = () => {
757
+ if (!formData.phone || !formData.password || !formData.confirmPassword) {
758
+ setError("\u8BF7\u586B\u5199\u5FC5\u8981\u4FE1\u606F");
759
+ return false;
760
+ }
761
+ if (!validatePhoneNumber(formData.phone)) {
762
+ setError("\u8BF7\u8F93\u5165\u6B63\u786E\u7684\u624B\u673A\u53F7\u683C\u5F0F");
763
+ return false;
764
+ }
765
+ const passwordValidation = validatePassword(formData.password);
766
+ if (!passwordValidation.valid) {
767
+ setError(passwordValidation.message || "\u5BC6\u7801\u683C\u5F0F\u9519\u8BEF");
768
+ return false;
769
+ }
770
+ if (formData.password !== formData.confirmPassword) {
771
+ setError("\u4E24\u6B21\u8F93\u5165\u7684\u5BC6\u7801\u4E0D\u4E00\u81F4");
772
+ return false;
773
+ }
774
+ return true;
775
+ };
776
+ const handleSubmit = async (e) => {
777
+ e.preventDefault();
778
+ setError("");
779
+ setLoading(true);
780
+ try {
781
+ if (!validateForm()) {
782
+ return;
783
+ }
784
+ console.log("\u{1F4DD} [RegisterModal] \u63D0\u4EA4\u6CE8\u518C\u8868\u5355:", {
785
+ phone: formData.phone,
786
+ name: formData.name || "\u672A\u8BBE\u7F6E",
787
+ password: "***"
788
+ });
789
+ const result = await register({
790
+ phone: formData.phone,
791
+ password: formData.password,
792
+ name: formData.name || void 0
793
+ });
794
+ if (result.success) {
795
+ console.log("\u2705 [RegisterModal] \u6CE8\u518C\u6210\u529F");
796
+ onSuccess();
797
+ } else {
798
+ console.log("\u274C [RegisterModal] \u6CE8\u518C\u5931\u8D25:", result.message);
799
+ setError(result.message || "\u6CE8\u518C\u5931\u8D25");
800
+ }
801
+ } catch (error2) {
802
+ console.error("\u{1F4A5} [RegisterModal] \u6CE8\u518C\u5F02\u5E38:", error2);
803
+ setError("\u6CE8\u518C\u5931\u8D25\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5");
804
+ } finally {
805
+ setLoading(false);
806
+ }
807
+ };
808
+ const handleOverlayClick = (e) => {
809
+ if (e.target === e.currentTarget) {
810
+ onClose();
811
+ }
812
+ };
813
+ if (!isOpen || !mounted) return null;
814
+ const modalContent = /* @__PURE__ */ React5.createElement(
815
+ "div",
816
+ {
817
+ className: "fixed top-0 left-0 right-0 bottom-0 w-screen h-screen bg-black/50 backdrop-blur-sm flex items-center justify-center z-[9999] p-4",
818
+ style: { margin: 0 },
819
+ onClick: handleOverlayClick
820
+ },
821
+ /* @__PURE__ */ React5.createElement(
822
+ "div",
823
+ {
824
+ className: "bg-white rounded-2xl shadow-xl w-full max-w-[420px] max-h-[90vh] overflow-y-auto relative",
825
+ onClick: (e) => e.stopPropagation()
826
+ },
827
+ /* @__PURE__ */ React5.createElement(
828
+ "button",
829
+ {
830
+ className: "absolute top-5 right-5 bg-transparent border-none text-gray-500 cursor-pointer p-2 rounded-lg transition-all hover:bg-gray-100 hover:text-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 min-w-9 min-h-9 flex items-center justify-center",
831
+ onClick: onClose
832
+ },
833
+ /* @__PURE__ */ React5.createElement(X, { size: 20 })
834
+ ),
835
+ /* @__PURE__ */ React5.createElement("div", { className: "px-6 pt-6 pb-4 text-center border-b border-gray-100" }, /* @__PURE__ */ React5.createElement("h2", { className: "text-2xl font-semibold text-gray-800 mb-2" }, "\u7528\u6237\u6CE8\u518C"), /* @__PURE__ */ React5.createElement("p", { className: "text-gray-500 text-sm" }, "\u8BF7\u586B\u5199\u4EE5\u4E0B\u4FE1\u606F\u521B\u5EFA\u8D26\u6237")),
836
+ /* @__PURE__ */ React5.createElement("form", { onSubmit: handleSubmit, className: "p-6" }, /* @__PURE__ */ React5.createElement("div", { className: "mb-5" }, /* @__PURE__ */ React5.createElement("label", { htmlFor: "phone", className: "block mb-1.5 text-sm font-medium text-gray-700" }, "\u624B\u673A\u53F7 *"), /* @__PURE__ */ React5.createElement("div", { className: "relative flex items-center" }, /* @__PURE__ */ React5.createElement(Phone, { size: 18, className: "absolute left-4 text-gray-400 z-[1] pointer-events-none" }), /* @__PURE__ */ React5.createElement(
837
+ "input",
838
+ {
839
+ id: "phone",
840
+ name: "phone",
841
+ type: "tel",
842
+ autoComplete: "tel",
843
+ value: formData.phone,
844
+ onChange: handleInputChange,
845
+ placeholder: "\u8BF7\u8F93\u5165\u624B\u673A\u53F7",
846
+ className: "w-full py-3 px-4 pl-12 border-2 border-gray-200 rounded-lg text-base transition-all box-border min-h-12 bg-white focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/10 placeholder:text-gray-400 disabled:bg-gray-50 disabled:text-gray-500 disabled:cursor-not-allowed",
847
+ disabled: loading
848
+ }
849
+ ))), /* @__PURE__ */ React5.createElement("div", { className: "mb-5" }, /* @__PURE__ */ React5.createElement("label", { htmlFor: "name", className: "block mb-1.5 text-sm font-medium text-gray-700" }, "\u59D3\u540D"), /* @__PURE__ */ React5.createElement("div", { className: "relative flex items-center" }, /* @__PURE__ */ React5.createElement(User, { size: 18, className: "absolute left-4 text-gray-400 z-[1] pointer-events-none" }), /* @__PURE__ */ React5.createElement(
850
+ "input",
851
+ {
852
+ id: "name",
853
+ name: "name",
854
+ type: "text",
855
+ autoComplete: "name",
856
+ value: formData.name,
857
+ onChange: handleInputChange,
858
+ placeholder: "\u8BF7\u8F93\u5165\u59D3\u540D\uFF08\u53EF\u9009\uFF09",
859
+ className: "w-full py-3 px-4 pl-12 border-2 border-gray-200 rounded-lg text-base transition-all box-border min-h-12 bg-white focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/10 placeholder:text-gray-400 disabled:bg-gray-50 disabled:text-gray-500 disabled:cursor-not-allowed",
860
+ disabled: loading
861
+ }
862
+ ))), /* @__PURE__ */ React5.createElement("div", { className: "mb-5" }, /* @__PURE__ */ React5.createElement("label", { htmlFor: "password", className: "block mb-1.5 text-sm font-medium text-gray-700" }, "\u5BC6\u7801 *"), /* @__PURE__ */ React5.createElement("div", { className: "relative flex items-center" }, /* @__PURE__ */ React5.createElement(Lock, { size: 18, className: "absolute left-4 text-gray-400 z-[1] pointer-events-none" }), /* @__PURE__ */ React5.createElement(
863
+ "input",
864
+ {
865
+ id: "password",
866
+ name: "password",
867
+ type: showPassword ? "text" : "password",
868
+ autoComplete: "new-password",
869
+ value: formData.password,
870
+ onChange: handleInputChange,
871
+ placeholder: "\u8BF7\u8F93\u5165\u5BC6\u7801\uFF08\u81F3\u5C116\u4F4D\uFF09",
872
+ className: "w-full py-3 px-4 pl-12 pr-12 border-2 border-gray-200 rounded-lg text-base transition-all box-border min-h-12 bg-white focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/10 placeholder:text-gray-400 disabled:bg-gray-50 disabled:text-gray-500 disabled:cursor-not-allowed",
873
+ disabled: loading
874
+ }
875
+ ), /* @__PURE__ */ React5.createElement(
876
+ "button",
877
+ {
878
+ type: "button",
879
+ className: "absolute right-4 bg-transparent border-none text-gray-400 cursor-pointer p-1 rounded transition-all flex items-center justify-center min-w-6 min-h-6 hover:text-gray-600 hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50",
880
+ onClick: () => setShowPassword(!showPassword),
881
+ disabled: loading
882
+ },
883
+ showPassword ? /* @__PURE__ */ React5.createElement(EyeOff, { size: 18 }) : /* @__PURE__ */ React5.createElement(Eye, { size: 18 })
884
+ ))), /* @__PURE__ */ React5.createElement("div", { className: "mb-5" }, /* @__PURE__ */ React5.createElement("label", { htmlFor: "confirmPassword", className: "block mb-1.5 text-sm font-medium text-gray-700" }, "\u786E\u8BA4\u5BC6\u7801 *"), /* @__PURE__ */ React5.createElement("div", { className: "relative flex items-center" }, /* @__PURE__ */ React5.createElement(Lock, { size: 18, className: "absolute left-4 text-gray-400 z-[1] pointer-events-none" }), /* @__PURE__ */ React5.createElement(
885
+ "input",
886
+ {
887
+ id: "confirmPassword",
888
+ name: "confirmPassword",
889
+ type: showConfirmPassword ? "text" : "password",
890
+ autoComplete: "new-password",
891
+ value: formData.confirmPassword,
892
+ onChange: handleInputChange,
893
+ placeholder: "\u8BF7\u518D\u6B21\u8F93\u5165\u5BC6\u7801",
894
+ className: "w-full py-3 px-4 pl-12 pr-12 border-2 border-gray-200 rounded-lg text-base transition-all box-border min-h-12 bg-white focus:outline-none focus:border-blue-500 focus:ring-2 focus:ring-blue-500/10 placeholder:text-gray-400 disabled:bg-gray-50 disabled:text-gray-500 disabled:cursor-not-allowed",
895
+ disabled: loading
896
+ }
897
+ ), /* @__PURE__ */ React5.createElement(
898
+ "button",
899
+ {
900
+ type: "button",
901
+ className: "absolute right-4 bg-transparent border-none text-gray-400 cursor-pointer p-1 rounded transition-all flex items-center justify-center min-w-6 min-h-6 hover:text-gray-600 hover:bg-gray-100 disabled:cursor-not-allowed disabled:opacity-50",
902
+ onClick: () => setShowConfirmPassword(!showConfirmPassword),
903
+ disabled: loading
904
+ },
905
+ showConfirmPassword ? /* @__PURE__ */ React5.createElement(EyeOff, { size: 18 }) : /* @__PURE__ */ React5.createElement(Eye, { size: 18 })
906
+ ))), error && /* @__PURE__ */ React5.createElement("div", { className: "text-red-500 text-sm my-4 p-3 bg-red-50 border border-red-200 rounded-lg leading-relaxed" }, error), /* @__PURE__ */ React5.createElement(
907
+ "button",
908
+ {
909
+ type: "submit",
910
+ className: "w-full bg-blue-500 text-white border-none py-3.5 px-6 rounded-lg text-base font-medium cursor-pointer transition-all mt-2 min-h-[52px] hover:bg-blue-600 hover:-translate-y-0.5 hover:shadow-lg hover:shadow-blue-500/30 active:translate-y-0 disabled:bg-gray-400 disabled:cursor-not-allowed disabled:transform-none disabled:shadow-none focus:outline-none focus:ring-2 focus:ring-blue-700 focus:ring-offset-2",
911
+ disabled: loading
912
+ },
913
+ loading ? "\u6CE8\u518C\u4E2D..." : "\u6CE8\u518C"
914
+ ), onSwitchToLogin && /* @__PURE__ */ React5.createElement("div", { className: "text-center mt-5 pt-4 border-t border-gray-100" }, /* @__PURE__ */ React5.createElement("span", { className: "text-gray-500 text-sm mr-1" }, "\u5DF2\u6709\u8D26\u53F7\uFF1F"), /* @__PURE__ */ React5.createElement(
915
+ "button",
916
+ {
917
+ type: "button",
918
+ onClick: onSwitchToLogin,
919
+ className: "bg-transparent border-none text-blue-500 cursor-pointer text-sm font-medium underline px-1 py-0.5 rounded transition-all hover:text-blue-600 hover:bg-blue-50 hover:no-underline focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2"
920
+ },
921
+ "\u7ACB\u5373\u767B\u5F55"
922
+ )))
923
+ )
924
+ );
925
+ return createPortal(modalContent, document.body);
926
+ }
927
+
928
+ // src/business/auth-legacy/components/UserMenu.tsx
929
+ function UserMenu({ customMenuItems = [], className }) {
930
+ const { user, isAuthenticated, logout } = useAuth();
931
+ const [isOpen, setIsOpen] = useState(false);
932
+ const [showLoginModal, setShowLoginModal] = useState(false);
933
+ const [showRegisterModal, setShowRegisterModal] = useState(false);
934
+ const toggleMenu = () => {
935
+ setIsOpen(!isOpen);
936
+ };
937
+ const handleMenuClick = (e) => {
938
+ e.stopPropagation();
939
+ };
940
+ const handleCustomMenuClick = (item) => {
941
+ console.log(`\u{1F527} [UserMenu] \u81EA\u5B9A\u4E49\u83DC\u5355\u9879\u88AB\u70B9\u51FB: ${item.label}`);
942
+ item.onClick();
943
+ setIsOpen(false);
944
+ };
945
+ const handleLogin = () => {
946
+ console.log("\u{1F511} [UserMenu] \u767B\u5F55\u6309\u94AE\u88AB\u70B9\u51FB");
947
+ setShowLoginModal(true);
948
+ setIsOpen(false);
949
+ };
950
+ const handleRegister = () => {
951
+ console.log("\u{1F4DD} [UserMenu] \u6CE8\u518C\u6309\u94AE\u88AB\u70B9\u51FB");
952
+ setShowRegisterModal(true);
953
+ setIsOpen(false);
954
+ };
955
+ const handleLogout = async () => {
956
+ console.log("\u{1F6AA} [UserMenu] \u9000\u51FA\u767B\u5F55\u6309\u94AE\u88AB\u70B9\u51FB");
957
+ try {
958
+ await logout();
959
+ console.log("\u2705 [UserMenu] \u9000\u51FA\u767B\u5F55\u6210\u529F");
960
+ } catch (error) {
961
+ console.error("\u9000\u51FA\u767B\u5F55\u5931\u8D25:", error);
962
+ }
963
+ setIsOpen(false);
964
+ };
965
+ const handleAuthSuccess = () => {
966
+ console.log("\u{1F389} [UserMenu] \u8BA4\u8BC1\u6210\u529F\u56DE\u8C03\u88AB\u8C03\u7528");
967
+ console.log("\u{1F464} [UserMenu] \u5F53\u524DuseAuth\u72B6\u6001:", {
968
+ user: user ? `${user.name || "\u672A\u8BBE\u7F6E"} (${user.phone})` : null,
969
+ isAuthenticated
970
+ });
971
+ setShowLoginModal(false);
972
+ setShowRegisterModal(false);
973
+ console.log("\u2705 [UserMenu] \u8BA4\u8BC1\u6210\u529F\u5904\u7406\u5B8C\u6210 - \u6A21\u6001\u6846\u5DF2\u5173\u95ED");
974
+ setTimeout(() => {
975
+ console.log("\u{1F50D} [UserMenu] \u5EF6\u8FDF\u72B6\u6001\u68C0\u67E5:", {
976
+ user: user ? `${user.name || "\u672A\u8BBE\u7F6E"} (${user.phone})` : null,
977
+ isAuthenticated
978
+ });
979
+ }, 500);
980
+ };
981
+ const handleSwitchToRegister = () => {
982
+ console.log("\u{1F504} [UserMenu] \u4ECE\u767B\u5F55\u5207\u6362\u5230\u6CE8\u518C");
983
+ setShowLoginModal(false);
984
+ setShowRegisterModal(true);
985
+ };
986
+ const handleSwitchToLogin = () => {
987
+ console.log("\u{1F504} [UserMenu] \u4ECE\u6CE8\u518C\u5207\u6362\u5230\u767B\u5F55");
988
+ setShowRegisterModal(false);
989
+ setShowLoginModal(true);
990
+ };
991
+ const getVisibleCustomMenuItems = () => {
992
+ return customMenuItems.filter((item) => {
993
+ if (item.requireAuth === true) {
994
+ return isAuthenticated;
995
+ }
996
+ if (item.requireAuth === false) {
997
+ return !isAuthenticated;
998
+ }
999
+ return true;
1000
+ });
1001
+ };
1002
+ React5.useEffect(() => {
1003
+ const handleGlobalClick = () => {
1004
+ setIsOpen(false);
1005
+ };
1006
+ if (isOpen) {
1007
+ document.addEventListener("click", handleGlobalClick);
1008
+ }
1009
+ return () => {
1010
+ document.removeEventListener("click", handleGlobalClick);
1011
+ };
1012
+ }, [isOpen]);
1013
+ const visibleCustomMenuItems = getVisibleCustomMenuItems();
1014
+ return /* @__PURE__ */ React5.createElement("div", { className: `relative inline-block ${className || ""}` }, /* @__PURE__ */ React5.createElement(
1015
+ "button",
1016
+ {
1017
+ className: "flex items-center gap-2 px-3 py-2 bg-slate-50 text-slate-500 border border-slate-200 rounded-lg cursor-pointer transition-all min-w-11 min-h-11 text-sm font-medium hover:bg-slate-200 hover:text-slate-800 focus:outline-none focus:ring-2 focus:ring-blue-500/10",
1018
+ onClick: toggleMenu
1019
+ },
1020
+ /* @__PURE__ */ React5.createElement(User, { size: 24 }),
1021
+ isAuthenticated && user && /* @__PURE__ */ React5.createElement("span", { className: "max-w-[120px] overflow-hidden text-ellipsis whitespace-nowrap" }, user.name || user.phone)
1022
+ ), isOpen && /* @__PURE__ */ React5.createElement(
1023
+ "div",
1024
+ {
1025
+ className: "absolute top-[calc(100%+0.5rem)] right-0 z-[1000] min-w-[200px] bg-white border border-slate-200 rounded-xl shadow-lg max-h-[90vh] overflow-y-auto p-2 animate-in slide-in-from-top-2 fade-in duration-200",
1026
+ onClick: handleMenuClick
1027
+ },
1028
+ isAuthenticated && user ? (
1029
+ // 已登录状态的菜单
1030
+ /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("div", { className: "p-3 mb-2 bg-slate-50 rounded-lg" }, /* @__PURE__ */ React5.createElement("div", { className: "text-sm font-semibold text-slate-800 mb-1 overflow-hidden text-ellipsis whitespace-nowrap" }, user.name || "\u672A\u8BBE\u7F6E\u540D\u79F0"), /* @__PURE__ */ React5.createElement("div", { className: "text-xs text-slate-500 mb-1 overflow-hidden text-ellipsis whitespace-nowrap" }, user.phone), /* @__PURE__ */ React5.createElement("div", { className: "text-xs text-blue-500 font-medium" }, user.role === "admin" ? "\u7BA1\u7406\u5458" : "\u666E\u901A\u7528\u6237")), visibleCustomMenuItems.length > 0 && /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("div", { className: "h-px bg-slate-200 my-2" }), visibleCustomMenuItems.map((item) => {
1031
+ const IconComponent = item.icon;
1032
+ return /* @__PURE__ */ React5.createElement(
1033
+ "button",
1034
+ {
1035
+ key: item.id,
1036
+ className: "flex items-center gap-3 w-full p-3 bg-transparent border-none rounded-lg text-gray-700 text-sm font-medium cursor-pointer transition-all text-left min-h-11 hover:bg-slate-100 hover:text-slate-800 focus:outline-none focus:bg-slate-100 focus:ring-2 focus:ring-blue-500/10",
1037
+ onClick: () => handleCustomMenuClick(item)
1038
+ },
1039
+ IconComponent && /* @__PURE__ */ React5.createElement(IconComponent, { size: 16 }),
1040
+ /* @__PURE__ */ React5.createElement("span", null, item.label)
1041
+ );
1042
+ })), /* @__PURE__ */ React5.createElement("div", { className: "h-px bg-slate-200 my-2" }), /* @__PURE__ */ React5.createElement(
1043
+ "button",
1044
+ {
1045
+ className: "flex items-center gap-3 w-full p-3 bg-transparent border-none rounded-lg text-gray-700 text-sm font-medium cursor-pointer transition-all text-left min-h-11 hover:bg-red-50 hover:text-red-600 focus:outline-none focus:bg-red-50 focus:text-red-600 focus:ring-2 focus:ring-red-500/10",
1046
+ onClick: handleLogout
1047
+ },
1048
+ /* @__PURE__ */ React5.createElement(LogOut, { size: 16 }),
1049
+ /* @__PURE__ */ React5.createElement("span", null, "\u9000\u51FA\u767B\u5F55")
1050
+ ))
1051
+ ) : (
1052
+ // 未登录状态的菜单
1053
+ /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
1054
+ "button",
1055
+ {
1056
+ className: "flex items-center gap-3 w-full p-3 bg-transparent border-none rounded-lg text-gray-700 text-sm font-medium cursor-pointer transition-all text-left min-h-11 hover:bg-slate-100 hover:text-slate-800 focus:outline-none focus:bg-slate-100 focus:ring-2 focus:ring-blue-500/10",
1057
+ onClick: handleLogin
1058
+ },
1059
+ /* @__PURE__ */ React5.createElement(LogIn, { size: 16 }),
1060
+ /* @__PURE__ */ React5.createElement("span", null, "\u767B\u5F55")
1061
+ ), /* @__PURE__ */ React5.createElement(
1062
+ "button",
1063
+ {
1064
+ className: "flex items-center gap-3 w-full p-3 bg-transparent border-none rounded-lg text-gray-700 text-sm font-medium cursor-pointer transition-all text-left min-h-11 hover:bg-slate-100 hover:text-slate-800 focus:outline-none focus:bg-slate-100 focus:ring-2 focus:ring-blue-500/10",
1065
+ onClick: handleRegister
1066
+ },
1067
+ /* @__PURE__ */ React5.createElement(User, { size: 16 }),
1068
+ /* @__PURE__ */ React5.createElement("span", null, "\u6CE8\u518C")
1069
+ ), visibleCustomMenuItems.length > 0 && /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("div", { className: "h-px bg-slate-200 my-2" }), visibleCustomMenuItems.map((item) => {
1070
+ const IconComponent = item.icon;
1071
+ return /* @__PURE__ */ React5.createElement(
1072
+ "button",
1073
+ {
1074
+ key: item.id,
1075
+ className: "flex items-center gap-3 w-full p-3 bg-transparent border-none rounded-lg text-gray-700 text-sm font-medium cursor-pointer transition-all text-left min-h-11 hover:bg-slate-100 hover:text-slate-800 focus:outline-none focus:bg-slate-100 focus:ring-2 focus:ring-blue-500/10",
1076
+ onClick: () => handleCustomMenuClick(item)
1077
+ },
1078
+ IconComponent && /* @__PURE__ */ React5.createElement(IconComponent, { size: 16 }),
1079
+ /* @__PURE__ */ React5.createElement("span", null, item.label)
1080
+ );
1081
+ })))
1082
+ )
1083
+ ), /* @__PURE__ */ React5.createElement(
1084
+ LoginModal,
1085
+ {
1086
+ isOpen: showLoginModal,
1087
+ onClose: () => setShowLoginModal(false),
1088
+ onSuccess: handleAuthSuccess,
1089
+ onSwitchToRegister: handleSwitchToRegister
1090
+ }
1091
+ ), /* @__PURE__ */ React5.createElement(
1092
+ RegisterModal,
1093
+ {
1094
+ isOpen: showRegisterModal,
1095
+ onClose: () => setShowRegisterModal(false),
1096
+ onSuccess: handleAuthSuccess,
1097
+ onSwitchToLogin: handleSwitchToLogin
1098
+ }
1099
+ ));
1100
+ }
1101
+
1102
+ // src/business/auth-legacy/types/index.ts
1103
+ var UserRole = /* @__PURE__ */ ((UserRole2) => {
1104
+ UserRole2["USER"] = "user";
1105
+ UserRole2["ADMIN"] = "admin";
1106
+ return UserRole2;
1107
+ })(UserRole || {});
1108
+
1109
+ // src/business/bubbleShooter/index.ts
1110
+ var bubbleShooter_exports = {};
1111
+ __export(bubbleShooter_exports, {
1112
+ DEFAULT_BUBBLE_SHOOTER_CONFIG: () => DEFAULT_BUBBLE_SHOOTER_CONFIG,
1113
+ createEmptyGrid: () => createEmptyGrid,
1114
+ createInitialGrid: () => createInitialGrid,
1115
+ findAttachSlot: () => findAttachSlot,
1116
+ findCollisionSlot: () => findCollisionSlot,
1117
+ getBoardHeight: () => getBoardHeight,
1118
+ getBoardWidth: () => getBoardWidth,
1119
+ getBubbleDiameter: () => getBubbleDiameter,
1120
+ getBubblePosition: () => getBubblePosition,
1121
+ getNearestSlot: () => getNearestSlot,
1122
+ getNeighbors: () => getNeighbors,
1123
+ getRowStep: () => getRowStep,
1124
+ hasAnyBubble: () => hasAnyBubble,
1125
+ hasReachedDangerLine: () => hasReachedDangerLine,
1126
+ isValidSlot: () => isValidSlot,
1127
+ pickRandomColor: () => pickRandomColor,
1128
+ resolveMatches: () => resolveMatches,
1129
+ webUI: () => web_exports
1130
+ });
1131
+
1132
+ // src/business/bubbleShooter/logic/game.ts
1133
+ var slotKey = (row, col) => `${row}:${col}`;
1134
+ var cloneGrid = (grid) => grid.map((row) => [...row]);
1135
+ var DEFAULT_BUBBLE_SHOOTER_CONFIG = {
1136
+ rows: 12,
1137
+ cols: 8,
1138
+ initialRows: 5,
1139
+ bubbleRadius: 16,
1140
+ topOffset: 18,
1141
+ palette: ["#fb7185", "#60a5fa", "#34d399", "#fbbf24", "#a78bfa"],
1142
+ launchSpeed: 440,
1143
+ minMatchCount: 3
1144
+ };
1145
+ var getBubbleDiameter = (config) => config.bubbleRadius * 2;
1146
+ var getRowStep = (config) => Math.round(config.bubbleRadius * 1.73);
1147
+ var getBoardWidth = (config) => {
1148
+ return getBubbleDiameter(config) * config.cols + config.bubbleRadius;
1149
+ };
1150
+ var getBoardHeight = (config) => {
1151
+ return config.topOffset + getRowStep(config) * (config.rows + 1) + config.bubbleRadius;
1152
+ };
1153
+ var createEmptyGrid = (config) => {
1154
+ return Array.from({ length: config.rows }, () => Array.from({ length: config.cols }, () => null));
1155
+ };
1156
+ var createInitialGrid = (config) => {
1157
+ const grid = createEmptyGrid(config);
1158
+ for (let row = 0; row < config.initialRows; row += 1) {
1159
+ for (let col = 0; col < config.cols; col += 1) {
1160
+ const color = config.palette[Math.floor(Math.random() * config.palette.length)] || config.palette[0] || "#60a5fa";
1161
+ const targetRow = grid[row];
1162
+ if (targetRow) {
1163
+ targetRow[col] = color;
1164
+ }
1165
+ }
1166
+ }
1167
+ return grid;
1168
+ };
1169
+ var pickRandomColor = (palette) => {
1170
+ return palette[Math.floor(Math.random() * palette.length)] || "#60a5fa";
1171
+ };
1172
+ var getBubblePosition = (row, col, config) => {
1173
+ const diameter = getBubbleDiameter(config);
1174
+ const rowStep = getRowStep(config);
1175
+ const x = config.bubbleRadius + col * diameter + (row % 2 === 1 ? config.bubbleRadius : 0);
1176
+ const y = config.topOffset + config.bubbleRadius + row * rowStep;
1177
+ return { x, y };
1178
+ };
1179
+ var isValidSlot = (slot, config) => {
1180
+ return slot.row >= 0 && slot.row < config.rows && slot.col >= 0 && slot.col < config.cols;
1181
+ };
1182
+ var getNeighbors = (slot, config) => {
1183
+ const evenDirections = [
1184
+ { row: -1, col: -1 },
1185
+ { row: -1, col: 0 },
1186
+ { row: 0, col: -1 },
1187
+ { row: 0, col: 1 },
1188
+ { row: 1, col: -1 },
1189
+ { row: 1, col: 0 }
1190
+ ];
1191
+ const oddDirections = [
1192
+ { row: -1, col: 0 },
1193
+ { row: -1, col: 1 },
1194
+ { row: 0, col: -1 },
1195
+ { row: 0, col: 1 },
1196
+ { row: 1, col: 0 },
1197
+ { row: 1, col: 1 }
1198
+ ];
1199
+ const directions = slot.row % 2 === 0 ? evenDirections : oddDirections;
1200
+ return directions.map((direction) => ({ row: slot.row + direction.row, col: slot.col + direction.col })).filter((candidate) => isValidSlot(candidate, config));
1201
+ };
1202
+ var getNearestSlot = (x, y, config) => {
1203
+ const rowStep = getRowStep(config);
1204
+ const diameter = getBubbleDiameter(config);
1205
+ const row = Math.max(0, Math.min(config.rows - 1, Math.round((y - config.topOffset - config.bubbleRadius) / rowStep)));
1206
+ const rowOffset = row % 2 === 1 ? config.bubbleRadius : 0;
1207
+ const col = Math.max(0, Math.min(config.cols - 1, Math.round((x - config.bubbleRadius - rowOffset) / diameter)));
1208
+ return { row, col };
1209
+ };
1210
+ var hasAdjacentBubble = (row, col, grid, config) => {
1211
+ if (row === 0) {
1212
+ return true;
1213
+ }
1214
+ return getNeighbors({ row, col }, config).some((neighbor) => {
1215
+ const targetRow = grid[neighbor.row];
1216
+ return Boolean(targetRow?.[neighbor.col]);
1217
+ });
1218
+ };
1219
+ var findAttachSlot = (x, y, grid, config, preferred) => {
1220
+ const candidates = [];
1221
+ if (preferred && isValidSlot(preferred, config)) {
1222
+ candidates.push(preferred, ...getNeighbors(preferred, config));
1223
+ }
1224
+ const nearest = getNearestSlot(x, y, config);
1225
+ candidates.push(nearest, ...getNeighbors(nearest, config));
1226
+ const uniqueCandidates = Array.from(
1227
+ new Map(candidates.map((slot) => [slotKey(slot.row, slot.col), slot])).values()
1228
+ );
1229
+ let best = null;
1230
+ let bestDistance = Number.POSITIVE_INFINITY;
1231
+ uniqueCandidates.forEach((slot) => {
1232
+ const targetRow = grid[slot.row];
1233
+ if (!targetRow || targetRow[slot.col] || !hasAdjacentBubble(slot.row, slot.col, grid, config)) {
1234
+ return;
1235
+ }
1236
+ const position = getBubblePosition(slot.row, slot.col, config);
1237
+ const dx = position.x - x;
1238
+ const dy = position.y - y;
1239
+ const distance = dx * dx + dy * dy;
1240
+ if (distance < bestDistance) {
1241
+ bestDistance = distance;
1242
+ best = slot;
1243
+ }
1244
+ });
1245
+ return best;
1246
+ };
1247
+ var findCollisionSlot = (x, y, grid, config) => {
1248
+ const threshold = (config.bubbleRadius * 2 - 1) ** 2;
1249
+ for (let row = 0; row < config.rows; row += 1) {
1250
+ for (let col = 0; col < config.cols; col += 1) {
1251
+ const targetRow = grid[row];
1252
+ if (!targetRow?.[col]) {
1253
+ continue;
1254
+ }
1255
+ const position = getBubblePosition(row, col, config);
1256
+ const dx = position.x - x;
1257
+ const dy = position.y - y;
1258
+ if (dx * dx + dy * dy <= threshold) {
1259
+ return { row, col };
1260
+ }
1261
+ }
1262
+ }
1263
+ return null;
1264
+ };
1265
+ var collectGroup = (start, grid, config, color) => {
1266
+ const queue = [start];
1267
+ const visited = /* @__PURE__ */ new Set();
1268
+ const group = [];
1269
+ while (queue.length > 0) {
1270
+ const current = queue.shift();
1271
+ if (!current) {
1272
+ continue;
1273
+ }
1274
+ const key = slotKey(current.row, current.col);
1275
+ if (visited.has(key)) {
1276
+ continue;
1277
+ }
1278
+ visited.add(key);
1279
+ const currentColor = grid[current.row]?.[current.col];
1280
+ if (currentColor !== color) {
1281
+ continue;
1282
+ }
1283
+ group.push(current);
1284
+ getNeighbors(current, config).forEach((neighbor) => {
1285
+ const neighborKey = slotKey(neighbor.row, neighbor.col);
1286
+ if (!visited.has(neighborKey)) {
1287
+ queue.push(neighbor);
1288
+ }
1289
+ });
1290
+ }
1291
+ return group;
1292
+ };
1293
+ var collectTopConnected = (grid, config) => {
1294
+ const visited = /* @__PURE__ */ new Set();
1295
+ const queue = [];
1296
+ for (let col = 0; col < config.cols; col += 1) {
1297
+ if (grid[0]?.[col]) {
1298
+ queue.push({ row: 0, col });
1299
+ }
1300
+ }
1301
+ while (queue.length > 0) {
1302
+ const current = queue.shift();
1303
+ if (!current) {
1304
+ continue;
1305
+ }
1306
+ const key = slotKey(current.row, current.col);
1307
+ if (visited.has(key)) {
1308
+ continue;
1309
+ }
1310
+ if (!grid[current.row]?.[current.col]) {
1311
+ continue;
1312
+ }
1313
+ visited.add(key);
1314
+ getNeighbors(current, config).forEach((neighbor) => {
1315
+ const neighborKey = slotKey(neighbor.row, neighbor.col);
1316
+ if (!visited.has(neighborKey)) {
1317
+ queue.push(neighbor);
1318
+ }
1319
+ });
1320
+ }
1321
+ return visited;
1322
+ };
1323
+ var resolveMatches = (grid, placed, config) => {
1324
+ const nextGrid = cloneGrid(grid);
1325
+ const placedColor = nextGrid[placed.row]?.[placed.col];
1326
+ if (!placedColor) {
1327
+ return { grid: nextGrid, removed: 0, matched: 0, dropped: 0 };
1328
+ }
1329
+ const group = collectGroup(placed, nextGrid, config, placedColor);
1330
+ let matched = 0;
1331
+ if (group.length >= config.minMatchCount) {
1332
+ group.forEach((slot) => {
1333
+ const targetRow = nextGrid[slot.row];
1334
+ if (targetRow?.[slot.col]) {
1335
+ targetRow[slot.col] = null;
1336
+ matched += 1;
1337
+ }
1338
+ });
1339
+ }
1340
+ let dropped = 0;
1341
+ if (matched > 0) {
1342
+ const topConnected = collectTopConnected(nextGrid, config);
1343
+ for (let row = 0; row < config.rows; row += 1) {
1344
+ for (let col = 0; col < config.cols; col += 1) {
1345
+ const targetRow = nextGrid[row];
1346
+ if (targetRow?.[col] && !topConnected.has(slotKey(row, col))) {
1347
+ targetRow[col] = null;
1348
+ dropped += 1;
1349
+ }
1350
+ }
1351
+ }
1352
+ }
1353
+ return {
1354
+ grid: nextGrid,
1355
+ matched,
1356
+ dropped,
1357
+ removed: matched + dropped
1358
+ };
1359
+ };
1360
+ var hasAnyBubble = (grid) => {
1361
+ return grid.some((row) => row.some(Boolean));
1362
+ };
1363
+ var hasReachedDangerLine = (grid, config, dangerRowOffset = 2) => {
1364
+ const limitRow = Math.max(0, config.rows - dangerRowOffset);
1365
+ for (let row = limitRow; row < config.rows; row += 1) {
1366
+ const targetRow = grid[row];
1367
+ if (targetRow?.some(Boolean)) {
1368
+ return true;
1369
+ }
1370
+ }
1371
+ return false;
1372
+ };
1373
+
1374
+ // src/business/bubbleShooter/ui/web/index.ts
1375
+ var web_exports = {};
1376
+ __export(web_exports, {
1377
+ BubbleShooterBoard: () => BubbleShooterBoard_default,
1378
+ BubbleShooterGamePage: () => BubbleShooterGamePage_default
1379
+ });
1380
+ var clampAim = (angle) => {
1381
+ const minAngle = -Math.PI + 0.15;
1382
+ const maxAngle = -0.15;
1383
+ return Math.max(minAngle, Math.min(maxAngle, angle));
1384
+ };
1385
+ var drawCircle = (context, x, y, radius, color) => {
1386
+ context.beginPath();
1387
+ context.arc(x, y, radius, 0, Math.PI * 2);
1388
+ context.fillStyle = color;
1389
+ context.fill();
1390
+ context.strokeStyle = "rgba(15, 23, 42, 0.15)";
1391
+ context.lineWidth = 1;
1392
+ context.stroke();
1393
+ };
1394
+ var normalizeConfig = (input) => {
1395
+ return {
1396
+ ...DEFAULT_BUBBLE_SHOOTER_CONFIG,
1397
+ ...input,
1398
+ palette: input?.palette?.length ? input.palette : DEFAULT_BUBBLE_SHOOTER_CONFIG.palette
1399
+ };
1400
+ };
1401
+ var BubbleShooterBoard = ({ config: inputConfig, className }) => {
1402
+ const config = useMemo(() => normalizeConfig(inputConfig), [inputConfig]);
1403
+ const boardWidth = useMemo(() => getBoardWidth(config), [config]);
1404
+ const boardHeight = useMemo(() => getBoardHeight(config), [config]);
1405
+ const shooterX = boardWidth / 2;
1406
+ const shooterY = boardHeight - config.bubbleRadius - 12;
1407
+ const canvasRef = useRef(null);
1408
+ const rafRef = useRef(null);
1409
+ const lastTsRef = useRef(0);
1410
+ const [grid, setGrid] = useState(() => createInitialGrid(config));
1411
+ const [status, setStatus] = useState("ready");
1412
+ const [score, setScore] = useState(0);
1413
+ const [shots, setShots] = useState(0);
1414
+ const [aimAngle, setAimAngle] = useState(-Math.PI / 2);
1415
+ const [currentColor, setCurrentColor] = useState(() => pickRandomColor(config.palette));
1416
+ const [nextColor, setNextColor] = useState(() => pickRandomColor(config.palette));
1417
+ const [projectile, setProjectile] = useState(null);
1418
+ const gridRef = useRef(grid);
1419
+ const currentColorRef = useRef(currentColor);
1420
+ const nextColorRef = useRef(nextColor);
1421
+ const statusRef = useRef(status);
1422
+ useEffect(() => {
1423
+ gridRef.current = grid;
1424
+ }, [grid]);
1425
+ useEffect(() => {
1426
+ currentColorRef.current = currentColor;
1427
+ }, [currentColor]);
1428
+ useEffect(() => {
1429
+ nextColorRef.current = nextColor;
1430
+ }, [nextColor]);
1431
+ useEffect(() => {
1432
+ statusRef.current = status;
1433
+ }, [status]);
1434
+ const restart = useCallback(() => {
1435
+ setGrid(createInitialGrid(config));
1436
+ setScore(0);
1437
+ setShots(0);
1438
+ setStatus("ready");
1439
+ setProjectile(null);
1440
+ setAimAngle(-Math.PI / 2);
1441
+ setCurrentColor(pickRandomColor(config.palette));
1442
+ setNextColor(pickRandomColor(config.palette));
1443
+ lastTsRef.current = 0;
1444
+ }, [config]);
1445
+ useEffect(() => {
1446
+ restart();
1447
+ }, [restart]);
1448
+ const settleProjectile = useCallback(
1449
+ (x, y, preferredSlot) => {
1450
+ const working = gridRef.current.map((row) => [...row]);
1451
+ const attach = findAttachSlot(x, y, working, config, preferredSlot);
1452
+ if (!attach) {
1453
+ setProjectile(null);
1454
+ setStatus("lost");
1455
+ return;
1456
+ }
1457
+ const rowData = working[attach.row];
1458
+ if (!rowData || rowData[attach.col]) {
1459
+ setProjectile(null);
1460
+ setStatus("lost");
1461
+ return;
1462
+ }
1463
+ rowData[attach.col] = currentColorRef.current;
1464
+ const resolved = resolveMatches(working, attach, config);
1465
+ setGrid(resolved.grid);
1466
+ setProjectile(null);
1467
+ setShots((prev) => prev + 1);
1468
+ if (resolved.removed > 0) {
1469
+ setScore((prev) => prev + resolved.matched * 10 + resolved.dropped * 15);
1470
+ }
1471
+ const hasBubbleLeft = hasAnyBubble(resolved.grid);
1472
+ if (!hasBubbleLeft) {
1473
+ setStatus("won");
1474
+ } else if (hasReachedDangerLine(resolved.grid, config)) {
1475
+ setStatus("lost");
1476
+ } else {
1477
+ setStatus("ready");
1478
+ }
1479
+ const nextCurrent = nextColorRef.current;
1480
+ const nextQueued = pickRandomColor(config.palette);
1481
+ setCurrentColor(nextCurrent);
1482
+ setNextColor(nextQueued);
1483
+ },
1484
+ [config]
1485
+ );
1486
+ useEffect(() => {
1487
+ if (status !== "shooting") {
1488
+ return;
1489
+ }
1490
+ const step = (timestamp) => {
1491
+ if (statusRef.current !== "shooting") {
1492
+ lastTsRef.current = 0;
1493
+ return;
1494
+ }
1495
+ const previousTs = lastTsRef.current || timestamp;
1496
+ const deltaSec = Math.min((timestamp - previousTs) / 1e3, 0.05);
1497
+ lastTsRef.current = timestamp;
1498
+ let shouldContinue = true;
1499
+ setProjectile((prev) => {
1500
+ if (!prev || statusRef.current !== "shooting") {
1501
+ shouldContinue = false;
1502
+ return prev;
1503
+ }
1504
+ let nextX = prev.x + prev.vx * deltaSec;
1505
+ const nextY = prev.y + prev.vy * deltaSec;
1506
+ let nextVx = prev.vx;
1507
+ if (nextX <= config.bubbleRadius) {
1508
+ nextX = config.bubbleRadius;
1509
+ nextVx = Math.abs(nextVx);
1510
+ } else if (nextX >= boardWidth - config.bubbleRadius) {
1511
+ nextX = boardWidth - config.bubbleRadius;
1512
+ nextVx = -Math.abs(nextVx);
1513
+ }
1514
+ if (nextY <= config.topOffset + config.bubbleRadius) {
1515
+ shouldContinue = false;
1516
+ settleProjectile(nextX, config.topOffset + config.bubbleRadius, getNearestSlot(nextX, nextY, config));
1517
+ return null;
1518
+ }
1519
+ const collision = findCollisionSlot(nextX, nextY, gridRef.current, config);
1520
+ if (collision) {
1521
+ shouldContinue = false;
1522
+ settleProjectile(nextX, nextY, collision);
1523
+ return null;
1524
+ }
1525
+ return {
1526
+ ...prev,
1527
+ x: nextX,
1528
+ y: nextY,
1529
+ vx: nextVx
1530
+ };
1531
+ });
1532
+ if (shouldContinue) {
1533
+ rafRef.current = window.requestAnimationFrame(step);
1534
+ } else {
1535
+ rafRef.current = null;
1536
+ lastTsRef.current = 0;
1537
+ }
1538
+ };
1539
+ rafRef.current = window.requestAnimationFrame(step);
1540
+ return () => {
1541
+ if (rafRef.current) {
1542
+ window.cancelAnimationFrame(rafRef.current);
1543
+ rafRef.current = null;
1544
+ }
1545
+ lastTsRef.current = 0;
1546
+ };
1547
+ }, [boardWidth, config, settleProjectile, status]);
1548
+ const shoot = useCallback(() => {
1549
+ if (status !== "ready") {
1550
+ return;
1551
+ }
1552
+ const vx = Math.cos(aimAngle) * config.launchSpeed;
1553
+ const vy = Math.sin(aimAngle) * config.launchSpeed;
1554
+ setProjectile({
1555
+ x: shooterX,
1556
+ y: shooterY - config.bubbleRadius,
1557
+ vx,
1558
+ vy,
1559
+ color: currentColor
1560
+ });
1561
+ setStatus("shooting");
1562
+ }, [aimAngle, config.bubbleRadius, config.launchSpeed, currentColor, shooterX, shooterY, status]);
1563
+ const updateAimFromPointer = useCallback(
1564
+ (event) => {
1565
+ const canvas = canvasRef.current;
1566
+ if (!canvas || status !== "ready") {
1567
+ return;
1568
+ }
1569
+ const rect = canvas.getBoundingClientRect();
1570
+ const x = event.clientX - rect.left;
1571
+ const y = event.clientY - rect.top;
1572
+ const rawAngle = Math.atan2(y - shooterY, x - shooterX);
1573
+ setAimAngle(clampAim(rawAngle));
1574
+ },
1575
+ [shooterX, shooterY, status]
1576
+ );
1577
+ const handlePointerDown = (event) => {
1578
+ event.currentTarget.setPointerCapture(event.pointerId);
1579
+ updateAimFromPointer(event);
1580
+ };
1581
+ const handlePointerUp = (event) => {
1582
+ updateAimFromPointer(event);
1583
+ shoot();
1584
+ event.currentTarget.releasePointerCapture(event.pointerId);
1585
+ };
1586
+ useEffect(() => {
1587
+ const canvas = canvasRef.current;
1588
+ if (!canvas) {
1589
+ return;
1590
+ }
1591
+ const context = canvas.getContext("2d");
1592
+ if (!context) {
1593
+ return;
1594
+ }
1595
+ const gradient = context.createLinearGradient(0, 0, 0, boardHeight);
1596
+ gradient.addColorStop(0, "#f8fafc");
1597
+ gradient.addColorStop(1, "#e2e8f0");
1598
+ context.fillStyle = gradient;
1599
+ context.fillRect(0, 0, boardWidth, boardHeight);
1600
+ context.fillStyle = "rgba(148, 163, 184, 0.2)";
1601
+ context.fillRect(0, shooterY - config.bubbleRadius * 1.3, boardWidth, 2);
1602
+ for (let row = 0; row < config.rows; row += 1) {
1603
+ for (let col = 0; col < config.cols; col += 1) {
1604
+ const color = grid[row]?.[col];
1605
+ if (!color) {
1606
+ continue;
1607
+ }
1608
+ const position = getBubblePosition(row, col, config);
1609
+ drawCircle(context, position.x, position.y, config.bubbleRadius - 0.5, color);
1610
+ }
1611
+ }
1612
+ const aimLength = config.bubbleRadius * 9;
1613
+ const aimX = shooterX + Math.cos(aimAngle) * aimLength;
1614
+ const aimY = shooterY + Math.sin(aimAngle) * aimLength;
1615
+ context.strokeStyle = "rgba(71, 85, 105, 0.75)";
1616
+ context.lineWidth = 2;
1617
+ context.setLineDash([4, 6]);
1618
+ context.beginPath();
1619
+ context.moveTo(shooterX, shooterY);
1620
+ context.lineTo(aimX, aimY);
1621
+ context.stroke();
1622
+ context.setLineDash([]);
1623
+ drawCircle(context, shooterX, shooterY, config.bubbleRadius - 0.5, currentColor);
1624
+ if (projectile) {
1625
+ drawCircle(context, projectile.x, projectile.y, config.bubbleRadius - 0.5, projectile.color);
1626
+ }
1627
+ drawCircle(context, boardWidth - config.bubbleRadius * 1.6, shooterY, config.bubbleRadius * 0.72, nextColor);
1628
+ context.fillStyle = "#334155";
1629
+ context.font = "12px sans-serif";
1630
+ context.textAlign = "right";
1631
+ context.fillText("Next", boardWidth - config.bubbleRadius * 0.5, shooterY - config.bubbleRadius * 1.05);
1632
+ if (status === "won" || status === "lost") {
1633
+ context.fillStyle = "rgba(15, 23, 42, 0.48)";
1634
+ context.fillRect(0, 0, boardWidth, boardHeight);
1635
+ context.fillStyle = "#ffffff";
1636
+ context.font = "bold 26px sans-serif";
1637
+ context.textAlign = "center";
1638
+ context.fillText(status === "won" ? "You Win!" : "Game Over", boardWidth / 2, boardHeight / 2);
1639
+ }
1640
+ }, [aimAngle, boardHeight, boardWidth, config, currentColor, grid, nextColor, projectile, shooterX, shooterY, status]);
1641
+ return /* @__PURE__ */ React5.createElement("div", { className }, /* @__PURE__ */ React5.createElement("div", { style: { display: "flex", gap: 16, marginBottom: 10, flexWrap: "wrap", color: "#334155" } }, /* @__PURE__ */ React5.createElement("span", null, "\u72B6\u6001\uFF1A", status === "ready" ? "\u5F85\u53D1\u5C04" : status === "shooting" ? "\u53D1\u5C04\u4E2D" : status === "won" ? "\u80DC\u5229" : "\u5931\u8D25"), /* @__PURE__ */ React5.createElement("span", null, "\u5206\u6570\uFF1A", score), /* @__PURE__ */ React5.createElement("span", null, "\u53D1\u5C04\u6B21\u6570\uFF1A", shots)), /* @__PURE__ */ React5.createElement(
1642
+ "canvas",
1643
+ {
1644
+ ref: canvasRef,
1645
+ width: boardWidth,
1646
+ height: boardHeight,
1647
+ onPointerMove: updateAimFromPointer,
1648
+ onPointerDown: handlePointerDown,
1649
+ onPointerUp: handlePointerUp,
1650
+ style: {
1651
+ width: "100%",
1652
+ maxWidth: boardWidth,
1653
+ borderRadius: 12,
1654
+ border: "1px solid #cbd5e1",
1655
+ boxShadow: "0 8px 28px rgba(15, 23, 42, 0.12)",
1656
+ touchAction: "none",
1657
+ cursor: status === "ready" ? "crosshair" : "default",
1658
+ display: "block"
1659
+ }
1660
+ }
1661
+ ), /* @__PURE__ */ React5.createElement("div", { style: { marginTop: 10, display: "flex", gap: 10 } }, /* @__PURE__ */ React5.createElement("button", { type: "button", onClick: restart, style: { padding: "8px 12px" } }, "\u91CD\u65B0\u5F00\u59CB")));
1662
+ };
1663
+ var BubbleShooterBoard_default = BubbleShooterBoard;
1664
+ var BubbleShooterGamePage = ({
1665
+ config,
1666
+ title = "\u6CE1\u6CE1\u9F99",
1667
+ description = "\u57FA\u7840\u7248\uFF1A\u7784\u51C6\u3001\u53D1\u5C04\u3001\u8FDE\u6D88\u3001\u60AC\u7A7A\u6389\u843D\u3002"
1668
+ }) => {
1669
+ return /* @__PURE__ */ React5.createElement("section", null, /* @__PURE__ */ React5.createElement("h2", null, title), /* @__PURE__ */ React5.createElement("p", { style: { color: "#64748b" } }, description), /* @__PURE__ */ React5.createElement(BubbleShooterBoard_default, { config }));
1670
+ };
1671
+ var BubbleShooterGamePage_default = BubbleShooterGamePage;
1672
+
1673
+ export { auth_legacy_exports as authLegacy, bubbleShooter_exports as bubbleShooter };
1674
+ //# sourceMappingURL=index.mjs.map
1675
+ //# sourceMappingURL=index.mjs.map