sa2kit 2.0.1 → 2.0.3

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 (278) 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/calendar/routes/index.d.mts +118 -0
  109. package/dist/calendar/routes/index.d.ts +118 -0
  110. package/dist/calendar/routes/index.js +755 -0
  111. package/dist/calendar/routes/index.js.map +1 -0
  112. package/dist/calendar/routes/index.mjs +747 -0
  113. package/dist/calendar/routes/index.mjs.map +1 -0
  114. package/dist/components/index.d.mts +405 -0
  115. package/dist/components/index.d.ts +405 -0
  116. package/dist/components/index.js +2516 -0
  117. package/dist/components/index.js.map +1 -0
  118. package/dist/components/index.mjs +2396 -0
  119. package/dist/components/index.mjs.map +1 -0
  120. package/dist/drizzle-schema-BNhqj2AZ.d.mts +1114 -0
  121. package/dist/drizzle-schema-BNhqj2AZ.d.ts +1114 -0
  122. package/dist/festivalCard/index.d.mts +76 -0
  123. package/dist/festivalCard/index.d.ts +76 -0
  124. package/dist/festivalCard/index.js +1492 -0
  125. package/dist/festivalCard/index.js.map +1 -0
  126. package/dist/festivalCard/index.mjs +1475 -0
  127. package/dist/festivalCard/index.mjs.map +1 -0
  128. package/dist/festivalCard/routes/index.d.mts +42 -0
  129. package/dist/festivalCard/routes/index.d.ts +42 -0
  130. package/dist/festivalCard/routes/index.js +361 -0
  131. package/dist/festivalCard/routes/index.js.map +1 -0
  132. package/dist/festivalCard/routes/index.mjs +356 -0
  133. package/dist/festivalCard/routes/index.mjs.map +1 -0
  134. package/dist/festivalCard/server/index.d.mts +120 -0
  135. package/dist/festivalCard/server/index.d.ts +120 -0
  136. package/dist/festivalCard/server/index.js +272 -0
  137. package/dist/festivalCard/server/index.js.map +1 -0
  138. package/dist/festivalCard/server/index.mjs +265 -0
  139. package/dist/festivalCard/server/index.mjs.map +1 -0
  140. package/dist/festivalCardService-BFCRhJrq.d.ts +13 -0
  141. package/dist/festivalCardService-GriR2VMc.d.mts +13 -0
  142. package/dist/index-1Ag7IBXN.d.ts +144 -0
  143. package/dist/index-DNKZ7-R_.d.mts +184 -0
  144. package/dist/index-DNKZ7-R_.d.ts +184 -0
  145. package/dist/index-DSel44Ke.d.mts +93 -0
  146. package/dist/index-DSel44Ke.d.ts +93 -0
  147. package/dist/index-DdeZSeTJ.d.mts +144 -0
  148. package/dist/index-DrPcMJPc.d.mts +250 -0
  149. package/dist/index-DrPcMJPc.d.ts +250 -0
  150. package/dist/index.d.mts +5334 -0
  151. package/dist/index.d.ts +5334 -0
  152. package/dist/index.js +18809 -0
  153. package/dist/index.js.map +1 -0
  154. package/dist/index.mjs +18533 -0
  155. package/dist/index.mjs.map +1 -0
  156. package/dist/mikuContest/ui/web/index.d.mts +2 -0
  157. package/dist/mikuContest/ui/web/index.d.ts +2 -0
  158. package/dist/mikuContest/ui/web/index.js +353 -0
  159. package/dist/mikuContest/ui/web/index.js.map +1 -0
  160. package/dist/mikuContest/ui/web/index.mjs +343 -0
  161. package/dist/mikuContest/ui/web/index.mjs.map +1 -0
  162. package/dist/mikuFireworks3D/index.d.mts +268 -0
  163. package/dist/mikuFireworks3D/index.d.ts +268 -0
  164. package/dist/mikuFireworks3D/index.js +1267 -0
  165. package/dist/mikuFireworks3D/index.js.map +1 -0
  166. package/dist/mikuFireworks3D/index.mjs +1228 -0
  167. package/dist/mikuFireworks3D/index.mjs.map +1 -0
  168. package/dist/mikuFusionGame/index.d.mts +117 -0
  169. package/dist/mikuFusionGame/index.d.ts +117 -0
  170. package/dist/mikuFusionGame/index.js +1208 -0
  171. package/dist/mikuFusionGame/index.js.map +1 -0
  172. package/dist/mikuFusionGame/index.mjs +1195 -0
  173. package/dist/mikuFusionGame/index.mjs.map +1 -0
  174. package/dist/mmd/admin/index.d.mts +487 -0
  175. package/dist/mmd/admin/index.d.ts +487 -0
  176. package/dist/mmd/admin/index.js +1058 -0
  177. package/dist/mmd/admin/index.js.map +1 -0
  178. package/dist/mmd/admin/index.mjs +1027 -0
  179. package/dist/mmd/admin/index.mjs.map +1 -0
  180. package/dist/mmd/index.d.mts +2467 -0
  181. package/dist/mmd/index.d.ts +2467 -0
  182. package/dist/mmd/index.js +10119 -0
  183. package/dist/mmd/index.js.map +1 -0
  184. package/dist/mmd/index.mjs +10028 -0
  185. package/dist/mmd/index.mjs.map +1 -0
  186. package/dist/mmd/server/index.d.mts +139 -0
  187. package/dist/mmd/server/index.d.ts +139 -0
  188. package/dist/mmd/server/index.js +424 -0
  189. package/dist/mmd/server/index.js.map +1 -0
  190. package/dist/mmd/server/index.mjs +404 -0
  191. package/dist/mmd/server/index.mjs.map +1 -0
  192. package/dist/music/index.d.mts +74 -0
  193. package/dist/music/index.d.ts +74 -0
  194. package/dist/music/index.js +830 -0
  195. package/dist/music/index.js.map +1 -0
  196. package/dist/music/index.mjs +809 -0
  197. package/dist/music/index.mjs.map +1 -0
  198. package/dist/music/server/index.d.mts +1 -0
  199. package/dist/music/server/index.d.ts +1 -0
  200. package/dist/music/server/index.js +194 -0
  201. package/dist/music/server/index.js.map +1 -0
  202. package/dist/music/server/index.mjs +182 -0
  203. package/dist/music/server/index.mjs.map +1 -0
  204. package/dist/navigation/index.d.mts +93 -0
  205. package/dist/navigation/index.d.ts +93 -0
  206. package/dist/navigation/index.js +453 -0
  207. package/dist/navigation/index.js.map +1 -0
  208. package/dist/navigation/index.mjs +443 -0
  209. package/dist/navigation/index.mjs.map +1 -0
  210. package/dist/portfolio/index.d.mts +66 -0
  211. package/dist/portfolio/index.d.ts +66 -0
  212. package/dist/portfolio/index.js +736 -0
  213. package/dist/portfolio/index.js.map +1 -0
  214. package/dist/portfolio/index.mjs +724 -0
  215. package/dist/portfolio/index.mjs.map +1 -0
  216. package/dist/qqbot/server/index.d.mts +216 -0
  217. package/dist/qqbot/server/index.d.ts +216 -0
  218. package/dist/qqbot/server/index.js +394 -0
  219. package/dist/qqbot/server/index.js.map +1 -0
  220. package/dist/qqbot/server/index.mjs +385 -0
  221. package/dist/qqbot/server/index.mjs.map +1 -0
  222. package/dist/qqbot/ui/web/index.d.mts +10 -0
  223. package/dist/qqbot/ui/web/index.d.ts +10 -0
  224. package/dist/qqbot/ui/web/index.js +105 -0
  225. package/dist/qqbot/ui/web/index.js.map +1 -0
  226. package/dist/qqbot/ui/web/index.mjs +99 -0
  227. package/dist/qqbot/ui/web/index.mjs.map +1 -0
  228. package/dist/screenReceiver/index.d.mts +86 -0
  229. package/dist/screenReceiver/index.d.ts +86 -0
  230. package/dist/screenReceiver/index.js +281 -0
  231. package/dist/screenReceiver/index.js.map +1 -0
  232. package/dist/screenReceiver/index.mjs +273 -0
  233. package/dist/screenReceiver/index.mjs.map +1 -0
  234. package/dist/testYourself/admin/index.d.mts +58 -0
  235. package/dist/testYourself/admin/index.d.ts +58 -0
  236. package/dist/testYourself/admin/index.js +1009 -0
  237. package/dist/testYourself/admin/index.js.map +1 -0
  238. package/dist/testYourself/admin/index.mjs +1002 -0
  239. package/dist/testYourself/admin/index.mjs.map +1 -0
  240. package/dist/testYourself/index.d.mts +53 -0
  241. package/dist/testYourself/index.d.ts +53 -0
  242. package/dist/testYourself/index.js +2551 -0
  243. package/dist/testYourself/index.js.map +1 -0
  244. package/dist/testYourself/index.mjs +2531 -0
  245. package/dist/testYourself/index.mjs.map +1 -0
  246. package/dist/testYourself/server/index.d.mts +1029 -0
  247. package/dist/testYourself/server/index.d.ts +1029 -0
  248. package/dist/testYourself/server/index.js +825 -0
  249. package/dist/testYourself/server/index.js.map +1 -0
  250. package/dist/testYourself/server/index.mjs +816 -0
  251. package/dist/testYourself/server/index.mjs.map +1 -0
  252. package/dist/types-BTiaMsBz.d.mts +292 -0
  253. package/dist/types-DyG3ZV9V.d.mts +270 -0
  254. package/dist/types-DyG3ZV9V.d.ts +270 -0
  255. package/dist/types-ERmJyjx8.d.ts +292 -0
  256. package/dist/types-HorDyIRv.d.mts +303 -0
  257. package/dist/types-HorDyIRv.d.ts +303 -0
  258. package/dist/types-tQfupO6d.d.mts +70 -0
  259. package/dist/types-tQfupO6d.d.ts +70 -0
  260. package/dist/vocaloidBooth/index.d.mts +64 -0
  261. package/dist/vocaloidBooth/index.d.ts +64 -0
  262. package/dist/vocaloidBooth/index.js +376 -0
  263. package/dist/vocaloidBooth/index.js.map +1 -0
  264. package/dist/vocaloidBooth/index.mjs +362 -0
  265. package/dist/vocaloidBooth/index.mjs.map +1 -0
  266. package/dist/vocaloidBooth/server/index.d.mts +111 -0
  267. package/dist/vocaloidBooth/server/index.d.ts +111 -0
  268. package/dist/vocaloidBooth/server/index.js +247 -0
  269. package/dist/vocaloidBooth/server/index.js.map +1 -0
  270. package/dist/vocaloidBooth/server/index.mjs +237 -0
  271. package/dist/vocaloidBooth/server/index.mjs.map +1 -0
  272. package/dist/vocaloidBooth/web/index.d.mts +3 -0
  273. package/dist/vocaloidBooth/web/index.d.ts +3 -0
  274. package/dist/vocaloidBooth/web/index.js +376 -0
  275. package/dist/vocaloidBooth/web/index.js.map +1 -0
  276. package/dist/vocaloidBooth/web/index.mjs +362 -0
  277. package/dist/vocaloidBooth/web/index.mjs.map +1 -0
  278. package/package.json +11 -1
@@ -0,0 +1,2551 @@
1
+ 'use strict';
2
+
3
+ var React2 = require('react');
4
+ var clsx = require('clsx');
5
+ var lucideReact = require('lucide-react');
6
+ var drizzleOrm = require('drizzle-orm');
7
+ var pgCore = require('drizzle-orm/pg-core');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var React2__default = /*#__PURE__*/_interopDefault(React2);
12
+
13
+ var __defProp = Object.defineProperty;
14
+ var __getOwnPropNames = Object.getOwnPropertyNames;
15
+ var __esm = (fn, res) => function __init() {
16
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
17
+ };
18
+ var __export = (target, all) => {
19
+ for (var name in all)
20
+ __defProp(target, name, { get: all[name], enumerable: true });
21
+ };
22
+
23
+ // src/testYourself/server/ConfigService.ts
24
+ var ConfigService_exports = {};
25
+ __export(ConfigService_exports, {
26
+ ConfigService: () => exports.ConfigService,
27
+ createConfigService: () => createConfigService,
28
+ getDefaultConfigService: () => getDefaultConfigService
29
+ });
30
+ function createConfigService(options) {
31
+ return new exports.ConfigService(options);
32
+ }
33
+ function getDefaultConfigService() {
34
+ if (!defaultServiceInstance) {
35
+ defaultServiceInstance = createConfigService();
36
+ }
37
+ return defaultServiceInstance;
38
+ }
39
+ var LocalStorageAdapter, MemoryStorageAdapter; exports.ConfigService = void 0; var defaultServiceInstance;
40
+ var init_ConfigService = __esm({
41
+ "src/testYourself/server/ConfigService.ts"() {
42
+ LocalStorageAdapter = class {
43
+ constructor() {
44
+ this.STORAGE_KEY = "test-yourself-configs";
45
+ this.DEFAULT_KEY = "test-yourself-default-config";
46
+ }
47
+ async getAllConfigsData() {
48
+ if (typeof window === "undefined") return [];
49
+ try {
50
+ const data = localStorage.getItem(this.STORAGE_KEY);
51
+ return data ? JSON.parse(data) : [];
52
+ } catch (error) {
53
+ console.error("\u8BFB\u53D6\u914D\u7F6E\u5931\u8D25:", error);
54
+ return [];
55
+ }
56
+ }
57
+ async saveAllConfigsData(configs) {
58
+ if (typeof window === "undefined") return;
59
+ try {
60
+ localStorage.setItem(this.STORAGE_KEY, JSON.stringify(configs));
61
+ } catch (error) {
62
+ console.error("\u4FDD\u5B58\u914D\u7F6E\u5931\u8D25:", error);
63
+ throw error;
64
+ }
65
+ }
66
+ async saveConfig(config) {
67
+ const configs = await this.getAllConfigsData();
68
+ const existingIndex = configs.findIndex((c) => c.id === config.id);
69
+ if (existingIndex >= 0) {
70
+ configs[existingIndex] = config;
71
+ } else {
72
+ configs.push(config);
73
+ }
74
+ await this.saveAllConfigsData(configs);
75
+ }
76
+ async getConfig(id) {
77
+ const configs = await this.getAllConfigsData();
78
+ return configs.find((c) => c.id === id) || null;
79
+ }
80
+ async getAllConfigs() {
81
+ return this.getAllConfigsData();
82
+ }
83
+ async deleteConfig(id) {
84
+ const configs = await this.getAllConfigsData();
85
+ const filtered = configs.filter((c) => c.id !== id);
86
+ await this.saveAllConfigsData(filtered);
87
+ }
88
+ async updateConfig(id, config) {
89
+ const configs = await this.getAllConfigsData();
90
+ const index2 = configs.findIndex((c) => c.id === id);
91
+ if (index2 >= 0) {
92
+ configs[index2] = { ...config, updatedAt: Date.now() };
93
+ await this.saveAllConfigsData(configs);
94
+ } else {
95
+ throw new Error("\u914D\u7F6E\u4E0D\u5B58\u5728: " + id);
96
+ }
97
+ }
98
+ async setDefaultConfig(id) {
99
+ if (typeof window === "undefined") return;
100
+ const config = await this.getConfig(id);
101
+ if (!config) {
102
+ throw new Error("\u914D\u7F6E\u4E0D\u5B58\u5728: " + id);
103
+ }
104
+ const configs = await this.getAllConfigsData();
105
+ configs.forEach((c) => c.isDefault = c.id === id);
106
+ await this.saveAllConfigsData(configs);
107
+ localStorage.setItem(this.DEFAULT_KEY, id);
108
+ }
109
+ async getDefaultConfig() {
110
+ if (typeof window === "undefined") return null;
111
+ try {
112
+ const defaultId = localStorage.getItem(this.DEFAULT_KEY);
113
+ if (defaultId) {
114
+ return await this.getConfig(defaultId);
115
+ }
116
+ const configs = await this.getAllConfigsData();
117
+ return configs.find((c) => c.isDefault) || null;
118
+ } catch (error) {
119
+ console.error("\u83B7\u53D6\u9ED8\u8BA4\u914D\u7F6E\u5931\u8D25:", error);
120
+ return null;
121
+ }
122
+ }
123
+ };
124
+ MemoryStorageAdapter = class {
125
+ constructor() {
126
+ this.configs = /* @__PURE__ */ new Map();
127
+ this.defaultConfigId = null;
128
+ }
129
+ async saveConfig(config) {
130
+ this.configs.set(config.id, config);
131
+ }
132
+ async getConfig(id) {
133
+ return this.configs.get(id) || null;
134
+ }
135
+ async getAllConfigs() {
136
+ return Array.from(this.configs.values());
137
+ }
138
+ async deleteConfig(id) {
139
+ this.configs.delete(id);
140
+ if (this.defaultConfigId === id) {
141
+ this.defaultConfigId = null;
142
+ }
143
+ }
144
+ async updateConfig(id, config) {
145
+ if (!this.configs.has(id)) {
146
+ throw new Error("\u914D\u7F6E\u4E0D\u5B58\u5728: " + id);
147
+ }
148
+ this.configs.set(id, { ...config, updatedAt: Date.now() });
149
+ }
150
+ async setDefaultConfig(id) {
151
+ if (!this.configs.has(id)) {
152
+ throw new Error("\u914D\u7F6E\u4E0D\u5B58\u5728: " + id);
153
+ }
154
+ this.configs.forEach((c) => c.isDefault = c.id === id);
155
+ this.defaultConfigId = id;
156
+ }
157
+ async getDefaultConfig() {
158
+ if (this.defaultConfigId) {
159
+ return this.configs.get(this.defaultConfigId) || null;
160
+ }
161
+ for (const config of this.configs.values()) {
162
+ if (config.isDefault) {
163
+ return config;
164
+ }
165
+ }
166
+ return null;
167
+ }
168
+ };
169
+ exports.ConfigService = class {
170
+ constructor(options = {}) {
171
+ this.cache = /* @__PURE__ */ new Map();
172
+ const {
173
+ storageType = "localStorage",
174
+ customStorage,
175
+ enableCache = true
176
+ } = options;
177
+ this.enableCache = enableCache;
178
+ if (customStorage) {
179
+ this.storage = customStorage;
180
+ } else if (storageType === "memory") {
181
+ this.storage = new MemoryStorageAdapter();
182
+ } else {
183
+ this.storage = new LocalStorageAdapter();
184
+ }
185
+ }
186
+ /**
187
+ * 初始化服务(如果需要)
188
+ */
189
+ async init() {
190
+ }
191
+ /**
192
+ * 生成唯一ID
193
+ */
194
+ generateId() {
195
+ return "config_" + Date.now() + "_" + Math.random().toString(36).substring(2, 9);
196
+ }
197
+ /**
198
+ * 保存配置
199
+ */
200
+ async saveConfig(config) {
201
+ await this.storage.saveConfig(config);
202
+ if (config.isDefault) {
203
+ await this.storage.setDefaultConfig(config.id);
204
+ }
205
+ if (this.enableCache) {
206
+ this.cache.set(config.id, config);
207
+ }
208
+ }
209
+ /**
210
+ * 创建新配置
211
+ */
212
+ async createConfig(name, config, description, isDefault = false) {
213
+ const savedConfig = {
214
+ id: this.generateId(),
215
+ name,
216
+ description,
217
+ config,
218
+ createdAt: Date.now(),
219
+ updatedAt: Date.now(),
220
+ isDefault
221
+ };
222
+ await this.storage.saveConfig(savedConfig);
223
+ if (isDefault) {
224
+ await this.storage.setDefaultConfig(savedConfig.id);
225
+ }
226
+ if (this.enableCache) {
227
+ this.cache.set(savedConfig.id, savedConfig);
228
+ }
229
+ return savedConfig;
230
+ }
231
+ /**
232
+ * 获取配置
233
+ */
234
+ async getConfig(id) {
235
+ if (this.enableCache && this.cache.has(id)) {
236
+ return this.cache.get(id);
237
+ }
238
+ const config = await this.storage.getConfig(id);
239
+ if (config && this.enableCache) {
240
+ this.cache.set(id, config);
241
+ }
242
+ return config;
243
+ }
244
+ /**
245
+ * 获取所有配置列表
246
+ */
247
+ async getAllConfigs() {
248
+ return await this.storage.getAllConfigs();
249
+ }
250
+ /**
251
+ * 获取配置列表(精简版)
252
+ */
253
+ async getConfigList() {
254
+ const configs = await this.getAllConfigs();
255
+ return configs.map((c) => ({
256
+ id: c.id,
257
+ name: c.name,
258
+ description: c.description,
259
+ resultCount: c.config.results.length,
260
+ createdAt: c.createdAt,
261
+ updatedAt: c.updatedAt,
262
+ isDefault: c.isDefault
263
+ }));
264
+ }
265
+ /**
266
+ * 更新配置
267
+ */
268
+ async updateConfig(id, updates) {
269
+ const existing = await this.getConfig(id);
270
+ if (!existing) {
271
+ throw new Error("\u914D\u7F6E\u4E0D\u5B58\u5728: " + id);
272
+ }
273
+ const updated = {
274
+ ...existing,
275
+ ...updates,
276
+ updatedAt: Date.now()
277
+ };
278
+ await this.storage.updateConfig(id, updated);
279
+ if (updates.isDefault) {
280
+ await this.storage.setDefaultConfig(id);
281
+ }
282
+ if (this.enableCache) {
283
+ this.cache.set(id, updated);
284
+ }
285
+ return updated;
286
+ }
287
+ /**
288
+ * 删除配置
289
+ */
290
+ async deleteConfig(id) {
291
+ await this.storage.deleteConfig(id);
292
+ if (this.enableCache) {
293
+ this.cache.delete(id);
294
+ }
295
+ }
296
+ /**
297
+ * 设置默认配置
298
+ */
299
+ async setDefaultConfig(id) {
300
+ await this.storage.setDefaultConfig(id);
301
+ if (this.enableCache) {
302
+ this.cache.clear();
303
+ }
304
+ }
305
+ /**
306
+ * 获取默认配置
307
+ */
308
+ async getDefaultConfig() {
309
+ return await this.storage.getDefaultConfig();
310
+ }
311
+ /**
312
+ * 清空缓存
313
+ */
314
+ clearCache() {
315
+ this.cache.clear();
316
+ }
317
+ /**
318
+ * 导出配置(JSON格式)
319
+ */
320
+ async exportConfig(id) {
321
+ const config = await this.getConfig(id);
322
+ if (!config) {
323
+ throw new Error("\u914D\u7F6E\u4E0D\u5B58\u5728: " + id);
324
+ }
325
+ return JSON.stringify(config, null, 2);
326
+ }
327
+ /**
328
+ * 导入配置
329
+ */
330
+ async importConfig(jsonString) {
331
+ try {
332
+ const data = JSON.parse(jsonString);
333
+ const newConfig = {
334
+ ...data,
335
+ id: this.generateId(),
336
+ createdAt: Date.now(),
337
+ updatedAt: Date.now(),
338
+ isDefault: false
339
+ // 导入的配置不设为默认
340
+ };
341
+ await this.storage.saveConfig(newConfig);
342
+ if (this.enableCache) {
343
+ this.cache.set(newConfig.id, newConfig);
344
+ }
345
+ return newConfig;
346
+ } catch (error) {
347
+ throw new Error("\u5BFC\u5165\u914D\u7F6E\u5931\u8D25: " + error);
348
+ }
349
+ }
350
+ /**
351
+ * 复制配置
352
+ */
353
+ async duplicateConfig(id, newName) {
354
+ const original = await this.getConfig(id);
355
+ if (!original) {
356
+ throw new Error("\u914D\u7F6E\u4E0D\u5B58\u5728: " + id);
357
+ }
358
+ const duplicated = {
359
+ ...original,
360
+ id: this.generateId(),
361
+ name: newName || original.name + " (\u526F\u672C)",
362
+ createdAt: Date.now(),
363
+ updatedAt: Date.now(),
364
+ isDefault: false
365
+ };
366
+ await this.storage.saveConfig(duplicated);
367
+ if (this.enableCache) {
368
+ this.cache.set(duplicated.id, duplicated);
369
+ }
370
+ return duplicated;
371
+ }
372
+ /**
373
+ * 批量删除配置
374
+ */
375
+ async deleteConfigs(ids) {
376
+ for (const id of ids) {
377
+ await this.deleteConfig(id);
378
+ }
379
+ }
380
+ };
381
+ defaultServiceInstance = null;
382
+ }
383
+ });
384
+
385
+ // src/testYourself/utils/fingerprint.ts
386
+ function getCanvasFingerprint() {
387
+ try {
388
+ const canvas = document.createElement("canvas");
389
+ const ctx = canvas.getContext("2d");
390
+ if (!ctx) return "no-canvas";
391
+ canvas.width = 200;
392
+ canvas.height = 50;
393
+ ctx.textBaseline = "top";
394
+ ctx.font = "14px Arial";
395
+ ctx.fillStyle = "#f60";
396
+ ctx.fillRect(0, 0, 200, 50);
397
+ ctx.fillStyle = "#069";
398
+ ctx.fillText("Canvas Fingerprint \u{1F3A8}", 2, 15);
399
+ return canvas.toDataURL();
400
+ } catch (error) {
401
+ return "canvas-error";
402
+ }
403
+ }
404
+ function getWebGLFingerprint() {
405
+ try {
406
+ const canvas = document.createElement("canvas");
407
+ const gl = canvas.getContext("webgl") || canvas.getContext("experimental-webgl");
408
+ if (!gl) return "no-webgl";
409
+ const glContext = gl;
410
+ const debugInfo = glContext.getExtension("WEBGL_debug_renderer_info");
411
+ if (debugInfo) {
412
+ const vendor = glContext.getParameter(debugInfo.UNMASKED_VENDOR_WEBGL);
413
+ const renderer = glContext.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL);
414
+ return vendor + "~" + renderer;
415
+ }
416
+ return "webgl-no-debug";
417
+ } catch (error) {
418
+ return "webgl-error";
419
+ }
420
+ }
421
+ function getAvailableFonts() {
422
+ const testFonts = [
423
+ "Arial",
424
+ "Verdana",
425
+ "Courier New",
426
+ "Georgia",
427
+ "Times New Roman",
428
+ "Comic Sans MS",
429
+ "Trebuchet MS",
430
+ "Arial Black",
431
+ "Impact",
432
+ "Courier",
433
+ "Helvetica",
434
+ "Monaco",
435
+ "Consolas",
436
+ "Menlo"
437
+ ];
438
+ const availableFonts = [];
439
+ const canvas = document.createElement("canvas");
440
+ const ctx = canvas.getContext("2d");
441
+ if (!ctx) return "no-fonts";
442
+ const baseFonts = ["monospace", "sans-serif", "serif"];
443
+ const testString = "mmmmmmmmmmlli";
444
+ const baseWidths = {};
445
+ baseFonts.forEach((font) => {
446
+ ctx.font = "72px " + font;
447
+ baseWidths[font] = ctx.measureText(testString).width;
448
+ });
449
+ testFonts.forEach((font) => {
450
+ let detected = false;
451
+ baseFonts.forEach((baseFont) => {
452
+ ctx.font = "72px " + font + ", " + baseFont;
453
+ const width = ctx.measureText(testString).width;
454
+ if (width !== baseWidths[baseFont]) {
455
+ detected = true;
456
+ }
457
+ });
458
+ if (detected) {
459
+ availableFonts.push(font);
460
+ }
461
+ });
462
+ return availableFonts.join(",") || "no-custom-fonts";
463
+ }
464
+ function getDeviceFingerprint() {
465
+ const fingerprint = {
466
+ // 基础信息
467
+ userAgent: navigator.userAgent,
468
+ screenResolution: window.screen.width + "x" + window.screen.height,
469
+ timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
470
+ language: navigator.language,
471
+ platform: navigator.platform,
472
+ // 显示信息
473
+ colorDepth: window.screen.colorDepth,
474
+ devicePixelRatio: window.devicePixelRatio,
475
+ // 硬件信息
476
+ hardwareConcurrency: navigator.hardwareConcurrency || 0,
477
+ maxTouchPoints: navigator.maxTouchPoints || 0,
478
+ // Canvas和WebGL指纹
479
+ canvasFingerprint: getCanvasFingerprint(),
480
+ webglFingerprint: getWebGLFingerprint(),
481
+ // 字体检测
482
+ fonts: getAvailableFonts(),
483
+ // 浏览器能力
484
+ cookieEnabled: navigator.cookieEnabled,
485
+ localStorageEnabled: (() => {
486
+ try {
487
+ return typeof localStorage !== "undefined";
488
+ } catch {
489
+ return false;
490
+ }
491
+ })(),
492
+ sessionStorageEnabled: (() => {
493
+ try {
494
+ return typeof sessionStorage !== "undefined";
495
+ } catch {
496
+ return false;
497
+ }
498
+ })(),
499
+ indexedDBEnabled: (() => {
500
+ try {
501
+ return typeof indexedDB !== "undefined";
502
+ } catch {
503
+ return false;
504
+ }
505
+ })()
506
+ };
507
+ return fingerprint;
508
+ }
509
+ async function tryGetIPAddress() {
510
+ try {
511
+ const response = await fetch("https://api.ipify.org?format=json", {
512
+ method: "GET",
513
+ mode: "cors"
514
+ });
515
+ if (response.ok) {
516
+ const data = await response.json();
517
+ return data.ip || null;
518
+ }
519
+ } catch (error) {
520
+ console.warn("\u65E0\u6CD5\u83B7\u53D6IP\u5730\u5740:", error);
521
+ }
522
+ return null;
523
+ }
524
+ function simpleHash(str) {
525
+ let hash = 5381;
526
+ for (let i = 0; i < str.length; i++) {
527
+ hash = (hash << 5) + hash + str.charCodeAt(i);
528
+ }
529
+ return Math.abs(hash);
530
+ }
531
+ function generateDeviceHash(fingerprint, salt = "test-yourself-salt-2024") {
532
+ const components = [
533
+ // 基础信息
534
+ fingerprint.userAgent,
535
+ fingerprint.ip || "no-ip",
536
+ fingerprint.screenResolution,
537
+ fingerprint.timezone,
538
+ fingerprint.language,
539
+ fingerprint.platform,
540
+ // 显示信息
541
+ fingerprint.colorDepth?.toString() || "0",
542
+ fingerprint.devicePixelRatio?.toString() || "0",
543
+ // 硬件信息
544
+ fingerprint.hardwareConcurrency?.toString() || "0",
545
+ fingerprint.maxTouchPoints?.toString() || "0",
546
+ // Canvas和WebGL指纹(这些是最独特的)
547
+ fingerprint.canvasFingerprint || "no-canvas",
548
+ fingerprint.webglFingerprint || "no-webgl",
549
+ // 字体(不同设备安装的字体不同)
550
+ fingerprint.fonts || "no-fonts",
551
+ // 浏览器能力
552
+ fingerprint.cookieEnabled ? "1" : "0",
553
+ fingerprint.localStorageEnabled ? "1" : "0",
554
+ fingerprint.sessionStorageEnabled ? "1" : "0",
555
+ fingerprint.indexedDBEnabled ? "1" : "0",
556
+ // 盐值
557
+ salt
558
+ ];
559
+ const combined = components.join("|");
560
+ const hash = simpleHash(combined);
561
+ return hash.toString(36);
562
+ }
563
+ function selectResultIndex(hash, totalResults) {
564
+ const numHash = parseInt(hash, 36);
565
+ return numHash % totalResults;
566
+ }
567
+
568
+ // src/testYourself/data/defaultResults.ts
569
+ var DEFAULT_RESULTS = [
570
+ // 动物系列 (1-15)
571
+ {
572
+ id: "animal-cat",
573
+ title: "\u6175\u61D2\u7684\u732B\u54AA \u{1F431}",
574
+ description: "\u4F60\u5C31\u50CF\u4E00\u53EA\u4F18\u96C5\u7684\u732B\uFF0C\u72EC\u7ACB\u81EA\u4E3B\uFF0C\u559C\u6B22\u6309\u7167\u81EA\u5DF1\u7684\u8282\u594F\u751F\u6D3B\u3002\u6709\u65F6\u9AD8\u51B7\uFF0C\u6709\u65F6\u7C98\u4EBA\uFF0C\u5145\u6EE1\u795E\u79D8\u9B45\u529B\u3002",
575
+ image: "\u{1F431}",
576
+ imageType: "emoji"
577
+ },
578
+ {
579
+ id: "animal-dog",
580
+ title: "\u5FE0\u8BDA\u7684\u72D7\u72D7 \u{1F415}",
581
+ description: "\u4F60\u50CF\u4E00\u53EA\u70ED\u60C5\u7684\u72D7\u72D7\uFF0C\u5BF9\u670B\u53CB\u5FE0\u8BDA\uFF0C\u5145\u6EE1\u6D3B\u529B\u3002\u603B\u662F\u80FD\u7ED9\u5468\u56F4\u7684\u4EBA\u5E26\u6765\u6B22\u4E50\u548C\u6E29\u6696\u3002",
582
+ image: "\u{1F415}",
583
+ imageType: "emoji"
584
+ },
585
+ {
586
+ id: "animal-panda",
587
+ title: "\u53EF\u7231\u7684\u718A\u732B \u{1F43C}",
588
+ description: "\u4F60\u5C31\u50CF\u56FD\u5B9D\u718A\u732B\u4E00\u6837\uFF0C\u5446\u840C\u53EF\u7231\uFF0C\u4EBA\u89C1\u4EBA\u7231\u3002\u6162\u8282\u594F\u7684\u751F\u6D3B\u65B9\u5F0F\u8BA9\u4F60\u5145\u6EE1\u6CBB\u6108\u529B\u3002",
589
+ image: "\u{1F43C}",
590
+ imageType: "emoji"
591
+ },
592
+ {
593
+ id: "animal-fox",
594
+ title: "\u673A\u667A\u7684\u72D0\u72F8 \u{1F98A}",
595
+ description: "\u806A\u660E\u4F36\u4FD0\uFF0C\u53CD\u5E94\u654F\u6377\u3002\u4F60\u603B\u80FD\u7528\u667A\u6167\u89E3\u51B3\u95EE\u9898\uFF0C\u662F\u56E2\u961F\u4E2D\u7684\u667A\u56CA\u62C5\u5F53\u3002",
596
+ image: "\u{1F98A}",
597
+ imageType: "emoji"
598
+ },
599
+ {
600
+ id: "animal-owl",
601
+ title: "\u777F\u667A\u7684\u732B\u5934\u9E70 \u{1F989}",
602
+ description: "\u4F60\u50CF\u732B\u5934\u9E70\u4E00\u6837\u5145\u6EE1\u667A\u6167\uFF0C\u559C\u6B22\u5728\u591C\u6DF1\u4EBA\u9759\u65F6\u601D\u8003\u3002\u7406\u6027\u3001\u6C89\u7A33\u662F\u4F60\u7684\u6807\u7B7E\u3002",
603
+ image: "\u{1F989}",
604
+ imageType: "emoji"
605
+ },
606
+ {
607
+ id: "animal-dolphin",
608
+ title: "\u5FEB\u4E50\u7684\u6D77\u8C5A \u{1F42C}",
609
+ description: "\u6D3B\u6CFC\u5F00\u6717\uFF0C\u793E\u4EA4\u8FBE\u4EBA\u3002\u4F60\u7684\u7B11\u5BB9\u80FD\u591F\u611F\u67D3\u8EAB\u8FB9\u7684\u6BCF\u4E00\u4E2A\u4EBA\u3002",
610
+ image: "\u{1F42C}",
611
+ imageType: "emoji"
612
+ },
613
+ {
614
+ id: "animal-butterfly",
615
+ title: "\u81EA\u7531\u7684\u8774\u8776 \u{1F98B}",
616
+ description: "\u8FFD\u6C42\u81EA\u7531\uFF0C\u70ED\u7231\u7F8E\u597D\u4E8B\u7269\u3002\u4F60\u7684\u4EBA\u751F\u5145\u6EE1\u8272\u5F69\uFF0C\u4ECE\u4E0D\u88AB\u675F\u7F1A\u3002",
617
+ image: "\u{1F98B}",
618
+ imageType: "emoji"
619
+ },
620
+ {
621
+ id: "animal-lion",
622
+ title: "\u52C7\u6562\u7684\u72EE\u5B50 \u{1F981}",
623
+ description: "\u5929\u751F\u7684\u9886\u5BFC\u8005\uFF0C\u52C7\u6562\u679C\u65AD\u3002\u4F60\u7684\u6C14\u573A\u5F3A\u5927\uFF0C\u603B\u80FD\u6FC0\u52B1\u4ED6\u4EBA\u3002",
624
+ image: "\u{1F981}",
625
+ imageType: "emoji"
626
+ },
627
+ {
628
+ id: "animal-rabbit",
629
+ title: "\u6E29\u67D4\u7684\u5154\u5B50 \u{1F430}",
630
+ description: "\u5FC3\u5730\u5584\u826F\uFF0C\u6E29\u67D4\u4F53\u8D34\u3002\u4F60\u7684\u5B58\u5728\u5C31\u50CF\u6625\u5929\u7684\u5FAE\u98CE\uFF0C\u8BA9\u4EBA\u611F\u5230\u6E29\u6696\u3002",
631
+ image: "\u{1F430}",
632
+ imageType: "emoji"
633
+ },
634
+ {
635
+ id: "animal-penguin",
636
+ title: "\u5446\u840C\u7684\u4F01\u9E45 \u{1F427}",
637
+ description: "\u61A8\u6001\u53EF\u63AC\uFF0C\u8BA4\u771F\u6267\u7740\u3002\u867D\u7136\u770B\u8D77\u6765\u7B28\u62D9\uFF0C\u4F46\u505A\u4E8B\u4E00\u4E1D\u4E0D\u82DF\u3002",
638
+ image: "\u{1F427}",
639
+ imageType: "emoji"
640
+ },
641
+ {
642
+ id: "animal-eagle",
643
+ title: "\u7FF1\u7FD4\u7684\u96C4\u9E70 \u{1F985}",
644
+ description: "\u76EE\u5149\u8FDC\u5927\uFF0C\u5FD7\u5411\u9AD8\u8FDC\u3002\u4F60\u603B\u662F\u80FD\u770B\u5230\u522B\u4EBA\u770B\u4E0D\u5230\u7684\u673A\u4F1A\u3002",
645
+ image: "\u{1F985}",
646
+ imageType: "emoji"
647
+ },
648
+ {
649
+ id: "animal-koala",
650
+ title: "\u6175\u61D2\u7684\u8003\u62C9 \u{1F428}",
651
+ description: "\u4F5B\u7CFB\u751F\u6D3B\uFF0C\u77E5\u8DB3\u5E38\u4E50\u3002\u4F60\u61C2\u5F97\u4EAB\u53D7\u5F53\u4E0B\uFF0C\u6D3B\u5728\u81EA\u5DF1\u7684\u8282\u594F\u91CC\u3002",
652
+ image: "\u{1F428}",
653
+ imageType: "emoji"
654
+ },
655
+ {
656
+ id: "animal-sloth",
657
+ title: "\u60A0\u95F2\u7684\u6811\u61D2 \u{1F9A5}",
658
+ description: "\u6162\u6162\u6765\uFF0C\u6BD4\u8F83\u5FEB\u3002\u4F60\u76F8\u4FE1\u6025\u4E0D\u6765\u7684\u4E8B\u5C31\u4E0D\u8981\u6025\uFF0C\u4FDD\u6301\u81EA\u5DF1\u7684pace\u3002",
659
+ image: "\u{1F9A5}",
660
+ imageType: "emoji"
661
+ },
662
+ {
663
+ id: "animal-unicorn",
664
+ title: "\u68A6\u5E7B\u7684\u72EC\u89D2\u517D \u{1F984}",
665
+ description: "\u5145\u6EE1\u5E7B\u60F3\uFF0C\u8FFD\u6C42\u5B8C\u7F8E\u3002\u4F60\u7684\u4E16\u754C\u4E94\u5F69\u6591\u6593\uFF0C\u603B\u6709\u72EC\u7279\u7684\u60F3\u6CD5\u3002",
666
+ image: "\u{1F984}",
667
+ imageType: "emoji"
668
+ },
669
+ {
670
+ id: "animal-dragon",
671
+ title: "\u795E\u79D8\u7684\u9F99 \u{1F409}",
672
+ description: "\u5F3A\u5927\u800C\u795E\u79D8\uFF0C\u5145\u6EE1\u9B45\u529B\u3002\u4F60\u662F\u4F20\u8BF4\u4E2D\u7684\u5B58\u5728\uFF0C\u4EE4\u4EBA\u5411\u5F80\u3002",
673
+ image: "\u{1F409}",
674
+ imageType: "emoji"
675
+ },
676
+ // 星球系列 (16-25)
677
+ {
678
+ id: "planet-sun",
679
+ title: "\u6E29\u6696\u7684\u592A\u9633 \u2600\uFE0F",
680
+ description: "\u4F60\u5C31\u50CF\u592A\u9633\u4E00\u6837\uFF0C\u662F\u56E2\u961F\u7684\u80FD\u91CF\u6765\u6E90\uFF0C\u6E29\u6696\u7740\u5468\u56F4\u7684\u6BCF\u4E2A\u4EBA\u3002",
681
+ image: "\u2600\uFE0F",
682
+ imageType: "emoji"
683
+ },
684
+ {
685
+ id: "planet-moon",
686
+ title: "\u6E29\u67D4\u7684\u6708\u4EAE \u{1F319}",
687
+ description: "\u5B89\u9759\u800C\u6E29\u67D4\uFF0C\u5728\u9ED1\u6697\u4E2D\u7ED9\u4EBA\u5149\u660E\u3002\u4F60\u662F\u591C\u665A\u6700\u7F8E\u7684\u966A\u4F34\u3002",
688
+ image: "\u{1F319}",
689
+ imageType: "emoji"
690
+ },
691
+ {
692
+ id: "planet-star",
693
+ title: "\u95EA\u8000\u7684\u661F\u661F \u2B50",
694
+ description: "\u867D\u7136\u6E3A\u5C0F\uFF0C\u4F46\u59CB\u7EC8\u95EA\u8000\u3002\u4F60\u7528\u81EA\u5DF1\u7684\u65B9\u5F0F\u53D1\u5149\u53D1\u70ED\u3002",
695
+ image: "\u2B50",
696
+ imageType: "emoji"
697
+ },
698
+ {
699
+ id: "planet-earth",
700
+ title: "\u5305\u5BB9\u7684\u5730\u7403 \u{1F30D}",
701
+ description: "\u5305\u5BB9\u4E07\u7269\uFF0C\u751F\u673A\u52C3\u52C3\u3002\u4F60\u6709\u7740\u5BBD\u5E7F\u7684\u80F8\u6000\u548C\u65E0\u9650\u7684\u53EF\u80FD\u3002",
702
+ image: "\u{1F30D}",
703
+ imageType: "emoji"
704
+ },
705
+ {
706
+ id: "planet-saturn",
707
+ title: "\u72EC\u7279\u7684\u571F\u661F \u{1FA90}",
708
+ description: "\u4E0E\u4F17\u4E0D\u540C\uFF0C\u81EA\u6210\u4E00\u683C\u3002\u4F60\u7684\u4E2A\u6027\u5C31\u50CF\u571F\u661F\u73AF\u4E00\u6837\u4EE4\u4EBA\u7740\u8FF7\u3002",
709
+ image: "\u{1FA90}",
710
+ imageType: "emoji"
711
+ },
712
+ {
713
+ id: "weather-rainbow",
714
+ title: "\u7EDA\u4E3D\u7684\u5F69\u8679 \u{1F308}",
715
+ description: "\u98CE\u96E8\u8FC7\u540E\u89C1\u5F69\u8679\uFF0C\u4F60\u603B\u80FD\u5728\u56F0\u96BE\u540E\u770B\u5230\u5E0C\u671B\u548C\u7F8E\u597D\u3002",
716
+ image: "\u{1F308}",
717
+ imageType: "emoji"
718
+ },
719
+ {
720
+ id: "weather-cloud",
721
+ title: "\u98D8\u9038\u7684\u4E91\u6735 \u2601\uFE0F",
722
+ description: "\u81EA\u7531\u81EA\u5728\uFF0C\u968F\u98CE\u98D8\u8361\u3002\u4F60\u4E0D\u88AB\u5B9A\u4E49\uFF0C\u6C38\u8FDC\u5145\u6EE1\u53EF\u80FD\u3002",
723
+ image: "\u2601\uFE0F",
724
+ imageType: "emoji"
725
+ },
726
+ {
727
+ id: "weather-lightning",
728
+ title: "\u95EA\u7535 \u26A1",
729
+ description: "\u7206\u53D1\u529B\u5F3A\uFF0C\u884C\u52A8\u8FC5\u901F\u3002\u4F60\u7684\u80FD\u91CF\u5C31\u50CF\u95EA\u7535\u4E00\u6837\u4EE4\u4EBA\u9707\u64BC\u3002",
730
+ image: "\u26A1",
731
+ imageType: "emoji"
732
+ },
733
+ {
734
+ id: "weather-snowflake",
735
+ title: "\u72EC\u7279\u7684\u96EA\u82B1 \u2744\uFE0F",
736
+ description: "\u4E16\u754C\u4E0A\u6CA1\u6709\u4E24\u7247\u76F8\u540C\u7684\u96EA\u82B1\uFF0C\u4F60\u4E5F\u662F\u72EC\u4E00\u65E0\u4E8C\u7684\u5B58\u5728\u3002",
737
+ image: "\u2744\uFE0F",
738
+ imageType: "emoji"
739
+ },
740
+ {
741
+ id: "weather-fire",
742
+ title: "\u70ED\u60C5\u7684\u706B\u7130 \u{1F525}",
743
+ description: "\u70ED\u60C5\u4F3C\u706B\uFF0C\u5145\u6EE1\u6FC0\u60C5\u3002\u4F60\u7684\u5B58\u5728\u80FD\u70B9\u71C3\u5468\u56F4\u7684\u6C14\u6C1B\u3002",
744
+ image: "\u{1F525}",
745
+ imageType: "emoji"
746
+ },
747
+ // 植物系列 (26-35)
748
+ {
749
+ id: "plant-tree",
750
+ title: "\u575A\u97E7\u7684\u5927\u6811 \u{1F333}",
751
+ description: "\u7A33\u91CD\u53EF\u9760\uFF0C\u6839\u57FA\u6DF1\u539A\u3002\u4F60\u662F\u5927\u5BB6\u53EF\u4EE5\u4F9D\u9760\u7684\u5B58\u5728\u3002",
752
+ image: "\u{1F333}",
753
+ imageType: "emoji"
754
+ },
755
+ {
756
+ id: "plant-flower",
757
+ title: "\u7F8E\u4E3D\u7684\u82B1\u6735 \u{1F338}",
758
+ description: "\u7EFD\u653E\u81EA\u6211\uFF0C\u7F8E\u4E3D\u52A8\u4EBA\u3002\u4F60\u7684\u5B58\u5728\u5C31\u662F\u4E00\u9053\u9753\u4E3D\u7684\u98CE\u666F\u3002",
759
+ image: "\u{1F338}",
760
+ imageType: "emoji"
761
+ },
762
+ {
763
+ id: "plant-sunflower",
764
+ title: "\u5411\u9633\u7684\u5411\u65E5\u8475 \u{1F33B}",
765
+ description: "\u6C38\u8FDC\u5411\u7740\u9633\u5149\uFF0C\u79EF\u6781\u5411\u4E0A\u3002\u4F60\u7684\u4E50\u89C2\u611F\u67D3\u7740\u6BCF\u4E2A\u4EBA\u3002",
766
+ image: "\u{1F33B}",
767
+ imageType: "emoji"
768
+ },
769
+ {
770
+ id: "plant-rose",
771
+ title: "\u4F18\u96C5\u7684\u73AB\u7470 \u{1F339}",
772
+ description: "\u9AD8\u8D35\u4F18\u96C5\uFF0C\u5145\u6EE1\u9B45\u529B\u3002\u867D\u6709\u523A\u4F46\u66F4\u6709\u7F8E\u4E3D\u3002",
773
+ image: "\u{1F339}",
774
+ imageType: "emoji"
775
+ },
776
+ {
777
+ id: "plant-cactus",
778
+ title: "\u575A\u5F3A\u7684\u4ED9\u4EBA\u638C \u{1F335}",
779
+ description: "\u5728\u8270\u96BE\u73AF\u5883\u4E2D\u4F9D\u7136\u575A\u5F3A\u3002\u4F60\u7684\u97E7\u6027\u4EE4\u4EBA\u656C\u4F69\u3002",
780
+ image: "\u{1F335}",
781
+ imageType: "emoji"
782
+ },
783
+ {
784
+ id: "plant-clover",
785
+ title: "\u5E78\u8FD0\u7684\u56DB\u53F6\u8349 \u{1F340}",
786
+ description: "\u5E78\u8FD0\u7684\u8C61\u5F81\uFF0C\u603B\u80FD\u7ED9\u4EBA\u5E26\u6765\u597D\u8FD0\u548C\u5E0C\u671B\u3002",
787
+ image: "\u{1F340}",
788
+ imageType: "emoji"
789
+ },
790
+ {
791
+ id: "plant-maple",
792
+ title: "\u6D6A\u6F2B\u7684\u67AB\u53F6 \u{1F341}",
793
+ description: "\u6D6A\u6F2B\u800C\u8BD7\u610F\uFF0C\u4F60\u7684\u4E16\u754C\u5145\u6EE1\u827A\u672F\u6C14\u606F\u3002",
794
+ image: "\u{1F341}",
795
+ imageType: "emoji"
796
+ },
797
+ {
798
+ id: "plant-mushroom",
799
+ title: "\u795E\u79D8\u7684\u8611\u83C7 \u{1F344}",
800
+ description: "\u4F4E\u8C03\u795E\u79D8\uFF0C\u603B\u6709\u610F\u60F3\u4E0D\u5230\u7684\u60CA\u559C\u3002",
801
+ image: "\u{1F344}",
802
+ imageType: "emoji"
803
+ },
804
+ {
805
+ id: "plant-cherry",
806
+ title: "\u6D6A\u6F2B\u7684\u6A31\u82B1 \u{1F338}",
807
+ description: "\u77ED\u6682\u800C\u7F8E\u597D\uFF0C\u4F60\u73CD\u60DC\u6BCF\u4E00\u4E2A\u77AC\u95F4\u7684\u7F8E\u4E3D\u3002",
808
+ image: "\u{1F338}",
809
+ imageType: "emoji"
810
+ },
811
+ {
812
+ id: "plant-bamboo",
813
+ title: "\u575A\u97E7\u7684\u7AF9\u5B50 \u{1F38B}",
814
+ description: "\u865A\u5FC3\u6709\u8282\uFF0C\u6108\u632B\u6108\u52C7\u3002\u4F60\u7684\u7CBE\u795E\u503C\u5F97\u5B66\u4E60\u3002",
815
+ image: "\u{1F38B}",
816
+ imageType: "emoji"
817
+ },
818
+ // 食物系列 (36-45)
819
+ {
820
+ id: "food-coffee",
821
+ title: "\u63D0\u795E\u7684\u5496\u5561 \u2615",
822
+ description: "\u4F60\u5C31\u50CF\u5496\u5561\uFF0C\u662F\u5927\u5BB6\u7684\u80FD\u91CF\u6765\u6E90\uFF0C\u5E2E\u52A9\u4ED6\u4EBA\u4FDD\u6301\u6D3B\u529B\u3002",
823
+ image: "\u2615",
824
+ imageType: "emoji"
825
+ },
826
+ {
827
+ id: "food-pizza",
828
+ title: "\u5FEB\u4E50\u7684\u62AB\u8428 \u{1F355}",
829
+ description: "\u4EBA\u89C1\u4EBA\u7231\uFF0C\u603B\u80FD\u5E26\u6765\u5FEB\u4E50\u3002\u4F60\u662F\u805A\u4F1A\u7684\u7075\u9B42\u3002",
830
+ image: "\u{1F355}",
831
+ imageType: "emoji"
832
+ },
833
+ {
834
+ id: "food-cookie",
835
+ title: "\u751C\u871C\u7684\u997C\u5E72 \u{1F36A}",
836
+ description: "\u6E29\u6696\u751C\u871C\uFF0C\u7ED9\u4EBAcomfort\u3002\u4F60\u662F\u6700\u597D\u7684\u6CBB\u6108\u7CFB\u5B58\u5728\u3002",
837
+ image: "\u{1F36A}",
838
+ imageType: "emoji"
839
+ },
840
+ {
841
+ id: "food-icecream",
842
+ title: "\u6E05\u51C9\u7684\u51B0\u6DC7\u6DCB \u{1F366}",
843
+ description: "\u751C\u7F8E\u53EF\u7231\uFF0C\u5728\u708E\u70ED\u65F6\u7ED9\u4EBA\u6E05\u51C9\u3002\u4F60\u603B\u80FD\u5728\u5173\u952E\u65F6\u523B\u51FA\u73B0\u3002",
844
+ image: "\u{1F366}",
845
+ imageType: "emoji"
846
+ },
847
+ {
848
+ id: "food-honey",
849
+ title: "\u751C\u871C\u7684\u8702\u871C \u{1F36F}",
850
+ description: "\u5929\u7136\u751C\u7F8E\uFF0C\u7EAF\u7CB9\u53EF\u7231\u3002\u4F60\u7684\u5B58\u5728\u5C31\u662F\u5E78\u798F\u7684\u5473\u9053\u3002",
851
+ image: "\u{1F36F}",
852
+ imageType: "emoji"
853
+ },
854
+ {
855
+ id: "food-sushi",
856
+ title: "\u7CBE\u81F4\u7684\u5BFF\u53F8 \u{1F363}",
857
+ description: "\u7CBE\u81F4\u4F18\u96C5\uFF0C\u6CE8\u91CD\u7EC6\u8282\u3002\u4F60\u5BF9\u751F\u6D3B\u6709\u7740\u72EC\u7279\u7684\u54C1\u5473\u3002",
858
+ image: "\u{1F363}",
859
+ imageType: "emoji"
860
+ },
861
+ {
862
+ id: "food-cake",
863
+ title: "\u751C\u7F8E\u7684\u86CB\u7CD5 \u{1F382}",
864
+ description: "\u751C\u871C\u7F8E\u597D\uFF0C\u662F\u5E86\u795D\u7684\u8C61\u5F81\u3002\u4F60\u603B\u80FD\u7ED9\u4EBA\u5E26\u6765\u60CA\u559C\u3002",
865
+ image: "\u{1F382}",
866
+ imageType: "emoji"
867
+ },
868
+ {
869
+ id: "food-donut",
870
+ title: "\u53EF\u7231\u7684\u751C\u751C\u5708 \u{1F369}",
871
+ description: "\u5706\u5706\u6EE1\u6EE1\uFF0C\u751C\u871C\u53EF\u7231\u3002\u4F60\u7684\u5B58\u5728\u8BA9\u751F\u6D3B\u66F4\u7F8E\u597D\u3002",
872
+ image: "\u{1F369}",
873
+ imageType: "emoji"
874
+ },
875
+ {
876
+ id: "food-lollipop",
877
+ title: "\u7AE5\u771F\u7684\u68D2\u68D2\u7CD6 \u{1F36D}",
878
+ description: "\u4FDD\u6301\u7AE5\u5FC3\uFF0C\u6C38\u8FDC\u5E74\u8F7B\u3002\u4F60\u7684\u7EAF\u771F\u4EE4\u4EBA\u7FA1\u6155\u3002",
879
+ image: "\u{1F36D}",
880
+ imageType: "emoji"
881
+ },
882
+ {
883
+ id: "food-watermelon",
884
+ title: "\u6E05\u723D\u7684\u897F\u74DC \u{1F349}",
885
+ description: "\u6E05\u723D\u89E3\u6E34\uFF0C\u590F\u65E5\u5FC5\u5907\u3002\u4F60\u603B\u80FD\u5E26\u6765\u6E05\u65B0\u7684\u611F\u89C9\u3002",
886
+ image: "\u{1F349}",
887
+ imageType: "emoji"
888
+ }
889
+ ];
890
+ if (DEFAULT_RESULTS.length !== 45) {
891
+ console.warn("\u7ED3\u679C\u6570\u636E\u96C6\u5E94\u5305\u542B45\u9879\uFF0C\u5F53\u524D: " + DEFAULT_RESULTS.length);
892
+ }
893
+
894
+ // src/testYourself/components/TestYourself.tsx
895
+ var STORAGE_KEY = "test-yourself-result";
896
+ var TestYourself = ({
897
+ config: propConfig,
898
+ configId,
899
+ onResult,
900
+ className = ""
901
+ }) => {
902
+ const [loadedConfig, setLoadedConfig] = React2.useState(null);
903
+ const [configLoading, setConfigLoading] = React2.useState(false);
904
+ React2.useEffect(() => {
905
+ const loadConfig = async () => {
906
+ if (configId) {
907
+ setConfigLoading(true);
908
+ try {
909
+ const { getDefaultConfigService: getDefaultConfigService2 } = await Promise.resolve().then(() => (init_ConfigService(), ConfigService_exports));
910
+ const service = getDefaultConfigService2();
911
+ const savedConfig = await service.getConfig(configId);
912
+ if (savedConfig) {
913
+ setLoadedConfig(savedConfig.config);
914
+ } else {
915
+ console.warn("\u914D\u7F6E " + configId + " \u4E0D\u5B58\u5728\uFF0C\u4F7F\u7528\u9ED8\u8BA4\u914D\u7F6E");
916
+ }
917
+ } catch (error) {
918
+ console.error("\u52A0\u8F7D\u914D\u7F6E\u5931\u8D25:", error);
919
+ } finally {
920
+ setConfigLoading(false);
921
+ }
922
+ }
923
+ };
924
+ loadConfig();
925
+ }, [configId]);
926
+ const config = loadedConfig || propConfig || {
927
+ gameTitle: "\u6D4B\u6D4B\u4F60\u662F\u4EC0\u4E48",
928
+ gameDescription: "\u957F\u6309\u6309\u94AE\uFF0C\u53D1\u73B0\u4F60\u7684\u4E13\u5C5E\u5C5E\u6027",
929
+ results: DEFAULT_RESULTS
930
+ };
931
+ const {
932
+ gameTitle,
933
+ gameDescription,
934
+ buttonText = "\u957F\u6309\u5F00\u59CB\u6D4B\u8BD5",
935
+ longPressDuration = 2e3,
936
+ results = DEFAULT_RESULTS,
937
+ enableIPFetch = false,
938
+ customSalt,
939
+ resultStyle = "card"
940
+ } = config;
941
+ const [status, setStatus] = React2.useState("idle");
942
+ const [result, setResult] = React2.useState(null);
943
+ const [pressProgress, setPressProgress] = React2.useState(0);
944
+ const [ipWarning, setIpWarning] = React2.useState(null);
945
+ const [isLoading, setIsLoading] = React2.useState(true);
946
+ const pressTimerRef = React2.useRef(null);
947
+ const progressIntervalRef = React2.useRef(null);
948
+ const startTimeRef = React2.useRef(0);
949
+ React2.useEffect(() => {
950
+ const initializeTest = async () => {
951
+ if (configLoading) {
952
+ return;
953
+ }
954
+ const storageKey = configId ? STORAGE_KEY + "_" + configId : STORAGE_KEY;
955
+ const savedResult = localStorage.getItem(storageKey);
956
+ if (savedResult) {
957
+ try {
958
+ const parsed = JSON.parse(savedResult);
959
+ setResult(parsed);
960
+ setStatus("completed");
961
+ setIsLoading(false);
962
+ return;
963
+ } catch (error) {
964
+ console.error("\u89E3\u6790\u4FDD\u5B58\u7684\u7ED3\u679C\u5931\u8D25:", error);
965
+ }
966
+ }
967
+ if (enableIPFetch) {
968
+ const ip = await tryGetIPAddress();
969
+ if (!ip) {
970
+ setIpWarning("\u26A0\uFE0F \u65E0\u6CD5\u83B7\u53D6IP\u5730\u5740\uFF0C\u5C06\u4EC5\u4F7F\u7528\u6D4F\u89C8\u5668\u6307\u7EB9\u751F\u6210\u7ED3\u679C");
971
+ }
972
+ }
973
+ setIsLoading(false);
974
+ };
975
+ initializeTest();
976
+ }, [enableIPFetch, configLoading, configId]);
977
+ const calculateResult = async () => {
978
+ try {
979
+ const fingerprint = getDeviceFingerprint();
980
+ if (enableIPFetch) {
981
+ const ip = await tryGetIPAddress();
982
+ if (ip) {
983
+ fingerprint.ip = ip;
984
+ }
985
+ }
986
+ const actualResults = results.length > 0 ? results : DEFAULT_RESULTS;
987
+ const hash = generateDeviceHash(fingerprint, customSalt);
988
+ const index2 = selectResultIndex(hash, actualResults.length);
989
+ const selectedResult = actualResults[index2];
990
+ if (!selectedResult) {
991
+ console.error("\u65E0\u6CD5\u83B7\u53D6\u6D4B\u8BD5\u7ED3\u679C\uFF0Cindex:", index2, "total:", actualResults.length);
992
+ throw new Error("\u65E0\u6CD5\u83B7\u53D6\u6D4B\u8BD5\u7ED3\u679C");
993
+ }
994
+ console.log("\u8BA1\u7B97\u7ED3\u679C\u6210\u529F:", selectedResult);
995
+ const storageKey = configId ? STORAGE_KEY + "_" + configId : STORAGE_KEY;
996
+ localStorage.setItem(storageKey, JSON.stringify(selectedResult));
997
+ return selectedResult;
998
+ } catch (error) {
999
+ console.error("\u8BA1\u7B97\u7ED3\u679C\u5931\u8D25:", error);
1000
+ throw error;
1001
+ }
1002
+ };
1003
+ const handlePressStart = (e) => {
1004
+ if (status !== "idle") return;
1005
+ e.preventDefault();
1006
+ setStatus("pressing");
1007
+ startTimeRef.current = Date.now();
1008
+ progressIntervalRef.current = setInterval(() => {
1009
+ const elapsed = Date.now() - startTimeRef.current;
1010
+ const progress = Math.min(elapsed / longPressDuration * 100, 100);
1011
+ setPressProgress(progress);
1012
+ }, 16);
1013
+ pressTimerRef.current = setTimeout(async () => {
1014
+ try {
1015
+ setPressProgress(100);
1016
+ if (progressIntervalRef.current) {
1017
+ clearInterval(progressIntervalRef.current);
1018
+ progressIntervalRef.current = null;
1019
+ }
1020
+ console.log("\u5F00\u59CB\u8BA1\u7B97\u7ED3\u679C...");
1021
+ const testResult = await calculateResult();
1022
+ console.log("\u7ED3\u679C\u8BA1\u7B97\u5B8C\u6210\uFF0C\u66F4\u65B0\u72B6\u6001:", testResult);
1023
+ setResult(testResult);
1024
+ setTimeout(() => {
1025
+ setStatus("completed");
1026
+ console.log("\u72B6\u6001\u5DF2\u66F4\u65B0\u4E3A completed");
1027
+ }, 0);
1028
+ if (onResult) {
1029
+ onResult(testResult);
1030
+ }
1031
+ } catch (error) {
1032
+ console.error("\u6D4B\u8BD5\u5931\u8D25:", error);
1033
+ setStatus("idle");
1034
+ setPressProgress(0);
1035
+ alert("\u6D4B\u8BD5\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5");
1036
+ }
1037
+ }, longPressDuration);
1038
+ if ("button" in e && e.button === 0) {
1039
+ const handleGlobalMouseUp = () => {
1040
+ handlePressEnd();
1041
+ document.removeEventListener("mouseup", handleGlobalMouseUp);
1042
+ };
1043
+ document.addEventListener("mouseup", handleGlobalMouseUp);
1044
+ }
1045
+ };
1046
+ const handlePressEnd = () => {
1047
+ if (status !== "pressing") return;
1048
+ if (pressTimerRef.current) {
1049
+ clearTimeout(pressTimerRef.current);
1050
+ pressTimerRef.current = null;
1051
+ }
1052
+ if (progressIntervalRef.current) {
1053
+ clearInterval(progressIntervalRef.current);
1054
+ progressIntervalRef.current = null;
1055
+ }
1056
+ setStatus("idle");
1057
+ setPressProgress(0);
1058
+ };
1059
+ const handleMouseLeave = (e) => {
1060
+ };
1061
+ const handleTouchMove = (e) => {
1062
+ const touch = e.touches[0];
1063
+ if (!touch) return;
1064
+ const target = e.currentTarget;
1065
+ const rect = target.getBoundingClientRect();
1066
+ const isInside = touch.clientX >= rect.left && touch.clientX <= rect.right && touch.clientY >= rect.top && touch.clientY <= rect.bottom;
1067
+ if (!isInside && status === "pressing") {
1068
+ handlePressEnd();
1069
+ }
1070
+ };
1071
+ React2.useEffect(() => {
1072
+ return () => {
1073
+ if (pressTimerRef.current) {
1074
+ clearTimeout(pressTimerRef.current);
1075
+ }
1076
+ if (progressIntervalRef.current) {
1077
+ clearInterval(progressIntervalRef.current);
1078
+ }
1079
+ };
1080
+ }, []);
1081
+ const handleReset = () => {
1082
+ const storageKey = configId ? STORAGE_KEY + "_" + configId : STORAGE_KEY;
1083
+ localStorage.removeItem(storageKey);
1084
+ setResult(null);
1085
+ setStatus("idle");
1086
+ setPressProgress(0);
1087
+ };
1088
+ const backgroundStyle = {
1089
+ position: "relative",
1090
+ minHeight: "100vh",
1091
+ overflow: "hidden",
1092
+ background: "linear-gradient(135deg, #f3e8ff 0%, #fce7f3 50%, #dbeafe 100%)"
1093
+ };
1094
+ const DecorativeBackground = () => /* @__PURE__ */ React2__default.default.createElement(React2__default.default.Fragment, null, /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1095
+ position: "absolute",
1096
+ top: 0,
1097
+ left: 0,
1098
+ width: "384px",
1099
+ height: "384px",
1100
+ background: "radial-gradient(circle, rgba(192, 132, 252, 0.3) 0%, transparent 70%)",
1101
+ borderRadius: "50%",
1102
+ filter: "blur(60px)",
1103
+ transform: "translate(-50%, -50%)",
1104
+ pointerEvents: "none"
1105
+ } }), /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1106
+ position: "absolute",
1107
+ top: "50%",
1108
+ right: 0,
1109
+ width: "384px",
1110
+ height: "384px",
1111
+ background: "radial-gradient(circle, rgba(244, 114, 182, 0.3) 0%, transparent 70%)",
1112
+ borderRadius: "50%",
1113
+ filter: "blur(60px)",
1114
+ transform: "translateX(50%)",
1115
+ pointerEvents: "none"
1116
+ } }), /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1117
+ position: "absolute",
1118
+ bottom: 0,
1119
+ left: "50%",
1120
+ width: "384px",
1121
+ height: "384px",
1122
+ background: "radial-gradient(circle, rgba(147, 197, 253, 0.3) 0%, transparent 70%)",
1123
+ borderRadius: "50%",
1124
+ filter: "blur(60px)",
1125
+ transform: "translate(-50%, 50%)",
1126
+ pointerEvents: "none"
1127
+ } }));
1128
+ if (isLoading) {
1129
+ return /* @__PURE__ */ React2__default.default.createElement("div", { className, style: backgroundStyle }, /* @__PURE__ */ React2__default.default.createElement(DecorativeBackground, null), /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1130
+ position: "relative",
1131
+ zIndex: 10,
1132
+ display: "flex",
1133
+ alignItems: "center",
1134
+ justifyContent: "center",
1135
+ minHeight: "100vh"
1136
+ } }, /* @__PURE__ */ React2__default.default.createElement("div", { style: { textAlign: "center" } }, /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1137
+ position: "relative",
1138
+ width: "64px",
1139
+ height: "64px",
1140
+ margin: "0 auto 16px"
1141
+ } }, /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1142
+ position: "absolute",
1143
+ inset: 0,
1144
+ border: "4px solid #e9d5ff",
1145
+ borderRadius: "50%"
1146
+ } }), /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1147
+ position: "absolute",
1148
+ inset: 0,
1149
+ border: "4px solid transparent",
1150
+ borderTopColor: "#a855f7",
1151
+ borderRadius: "50%",
1152
+ animation: "spin 1s linear infinite"
1153
+ } })), /* @__PURE__ */ React2__default.default.createElement("p", { style: { fontSize: "14px", color: "#6b7280" } }, "\u2728 \u52A0\u8F7D\u4E2D"))));
1154
+ }
1155
+ if (status === "completed" && result) {
1156
+ return /* @__PURE__ */ React2__default.default.createElement("div", { className, style: backgroundStyle }, /* @__PURE__ */ React2__default.default.createElement(DecorativeBackground, null), /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1157
+ position: "relative",
1158
+ zIndex: 10,
1159
+ minHeight: "100vh",
1160
+ display: "flex",
1161
+ alignItems: "center",
1162
+ justifyContent: "center",
1163
+ padding: "24px"
1164
+ } }, /* @__PURE__ */ React2__default.default.createElement("div", { style: { maxWidth: "420px", width: "100%" } }, /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1165
+ position: "relative",
1166
+ background: "linear-gradient(135deg, #fdf2f8 0%, #faf5ff 50%, #eff6ff 100%)",
1167
+ borderRadius: "32px",
1168
+ boxShadow: "0 25px 50px -12px rgba(168, 85, 247, 0.25), 0 0 0 1px rgba(168, 85, 247, 0.1)",
1169
+ overflow: "hidden",
1170
+ padding: "40px 32px",
1171
+ textAlign: "center"
1172
+ } }, /* @__PURE__ */ React2__default.default.createElement("div", { style: { position: "absolute", top: "20px", left: "20px", fontSize: "24px", opacity: 0.6 } }, "\u2728"), /* @__PURE__ */ React2__default.default.createElement("div", { style: { position: "absolute", top: "40px", right: "30px", fontSize: "20px", opacity: 0.5 } }, "\u2B50"), /* @__PURE__ */ React2__default.default.createElement("div", { style: { position: "absolute", bottom: "30px", left: "40px", fontSize: "18px", opacity: 0.4 } }, "\u{1F4AB}"), /* @__PURE__ */ React2__default.default.createElement("div", { style: { position: "absolute", bottom: "50px", right: "25px", fontSize: "22px", opacity: 0.5 } }, "\u{1F31F}"), /* @__PURE__ */ React2__default.default.createElement("div", { style: { marginBottom: "24px" } }, /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1173
+ display: "inline-block",
1174
+ fontSize: "80px",
1175
+ animation: "bounce-slow 2s ease-in-out infinite",
1176
+ filter: "drop-shadow(0 10px 20px rgba(0,0,0,0.1))"
1177
+ } }, result.imageType === "emoji" ? result.image : "\u{1F389}")), /* @__PURE__ */ React2__default.default.createElement("h2", { style: {
1178
+ fontSize: "32px",
1179
+ fontWeight: 800,
1180
+ background: "linear-gradient(135deg, #9333ea 0%, #ec4899 100%)",
1181
+ WebkitBackgroundClip: "text",
1182
+ WebkitTextFillColor: "transparent",
1183
+ backgroundClip: "text",
1184
+ marginBottom: "16px",
1185
+ lineHeight: 1.3
1186
+ } }, result.title), /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1187
+ background: "rgba(255, 255, 255, 0.8)",
1188
+ borderRadius: "20px",
1189
+ padding: "20px 24px",
1190
+ marginBottom: "28px",
1191
+ boxShadow: "0 4px 15px rgba(168, 85, 247, 0.1)",
1192
+ border: "2px dashed rgba(168, 85, 247, 0.2)"
1193
+ } }, /* @__PURE__ */ React2__default.default.createElement("p", { style: {
1194
+ fontSize: "16px",
1195
+ color: "#6b7280",
1196
+ lineHeight: 1.7,
1197
+ margin: 0
1198
+ } }, result.description)), /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1199
+ display: "flex",
1200
+ alignItems: "center",
1201
+ justifyContent: "center",
1202
+ gap: "8px",
1203
+ marginBottom: "24px"
1204
+ } }, /* @__PURE__ */ React2__default.default.createElement("span", { style: { width: "40px", height: "3px", background: "linear-gradient(to right, #a855f7, transparent)", borderRadius: "999px" } }), /* @__PURE__ */ React2__default.default.createElement("span", { style: { fontSize: "16px" } }, "\u{1F495}"), /* @__PURE__ */ React2__default.default.createElement("span", { style: { width: "40px", height: "3px", background: "linear-gradient(to left, #ec4899, transparent)", borderRadius: "999px" } })), /* @__PURE__ */ React2__default.default.createElement(
1205
+ "button",
1206
+ {
1207
+ onClick: handleReset,
1208
+ style: {
1209
+ display: "inline-flex",
1210
+ alignItems: "center",
1211
+ justifyContent: "center",
1212
+ gap: "8px",
1213
+ padding: "14px 32px",
1214
+ fontSize: "16px",
1215
+ fontWeight: 600,
1216
+ color: "white",
1217
+ background: "linear-gradient(135deg, #a855f7 0%, #ec4899 100%)",
1218
+ border: "none",
1219
+ borderRadius: "9999px",
1220
+ cursor: "pointer",
1221
+ boxShadow: "0 10px 25px -5px rgba(168, 85, 247, 0.4)",
1222
+ transition: "all 0.3s ease"
1223
+ },
1224
+ onMouseEnter: (e) => {
1225
+ e.currentTarget.style.transform = "scale(1.05) translateY(-2px)";
1226
+ e.currentTarget.style.boxShadow = "0 15px 35px -5px rgba(168, 85, 247, 0.5)";
1227
+ },
1228
+ onMouseLeave: (e) => {
1229
+ e.currentTarget.style.transform = "scale(1) translateY(0)";
1230
+ e.currentTarget.style.boxShadow = "0 10px 25px -5px rgba(168, 85, 247, 0.4)";
1231
+ }
1232
+ },
1233
+ /* @__PURE__ */ React2__default.default.createElement("span", null, "\u{1F504}"),
1234
+ /* @__PURE__ */ React2__default.default.createElement("span", null, "\u91CD\u65B0\u6D4B\u8BD5")
1235
+ )))));
1236
+ }
1237
+ return /* @__PURE__ */ React2__default.default.createElement("div", { className, style: backgroundStyle }, /* @__PURE__ */ React2__default.default.createElement(DecorativeBackground, null), /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1238
+ position: "relative",
1239
+ zIndex: 10,
1240
+ minHeight: "100vh",
1241
+ display: "flex",
1242
+ alignItems: "center",
1243
+ justifyContent: "center",
1244
+ padding: "16px"
1245
+ } }, /* @__PURE__ */ React2__default.default.createElement("div", { style: { maxWidth: "512px", width: "100%", textAlign: "center", userSelect: "none" } }, /* @__PURE__ */ React2__default.default.createElement("div", { style: { marginBottom: "48px" } }, /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1246
+ display: "inline-block",
1247
+ marginBottom: "16px",
1248
+ animation: "bounce-slow 2s ease-in-out infinite"
1249
+ } }, /* @__PURE__ */ React2__default.default.createElement("span", { style: { fontSize: "56px" } }, "\u{1F3B2}")), /* @__PURE__ */ React2__default.default.createElement("h1", { style: {
1250
+ fontSize: "48px",
1251
+ fontWeight: 900,
1252
+ marginBottom: "12px",
1253
+ background: "linear-gradient(135deg, #9333ea 0%, #ec4899 50%, #3b82f6 100%)",
1254
+ WebkitBackgroundClip: "text",
1255
+ WebkitTextFillColor: "transparent",
1256
+ backgroundClip: "text",
1257
+ lineHeight: 1.2
1258
+ } }, gameTitle), gameDescription && /* @__PURE__ */ React2__default.default.createElement("p", { style: {
1259
+ fontSize: "18px",
1260
+ color: "#6b7280",
1261
+ fontWeight: 500
1262
+ } }, gameDescription)), /* @__PURE__ */ React2__default.default.createElement("div", { style: { marginBottom: "24px" } }, /* @__PURE__ */ React2__default.default.createElement(
1263
+ "button",
1264
+ {
1265
+ onMouseDown: handlePressStart,
1266
+ onMouseLeave: handleMouseLeave,
1267
+ onTouchStart: handlePressStart,
1268
+ onTouchEnd: handlePressEnd,
1269
+ onTouchMove: handleTouchMove,
1270
+ onTouchCancel: handlePressEnd,
1271
+ onContextMenu: (e) => e.preventDefault(),
1272
+ onDragStart: (e) => e.preventDefault(),
1273
+ style: {
1274
+ display: "block",
1275
+ margin: "0 auto",
1276
+ width: "200px",
1277
+ height: "200px",
1278
+ borderRadius: "50%",
1279
+ border: "none",
1280
+ fontSize: "20px",
1281
+ fontWeight: "bold",
1282
+ cursor: "pointer",
1283
+ position: "relative",
1284
+ overflow: "hidden",
1285
+ userSelect: "none",
1286
+ WebkitTouchCallout: "none",
1287
+ WebkitUserSelect: "none",
1288
+ touchAction: "none",
1289
+ transition: "transform 0.3s ease",
1290
+ transform: status === "pressing" ? "scale(0.95)" : "scale(1)",
1291
+ background: status === "pressing" ? "linear-gradient(to top, rgb(168, 85, 247) " + pressProgress + "%, rgb(236, 72, 153) " + pressProgress + "%)" : "linear-gradient(135deg, #4f46e5 0%, #7c3aed 25%, #db2777 50%, #f97316 75%, #059669 100%)",
1292
+ boxShadow: status === "pressing" ? "inset 0 4px 12px rgba(0,0,0,0.3), 0 0 0 4px rgba(168, 85, 247, 0.5)" : "0 15px 35px -10px rgba(79, 70, 229, 0.6), 0 0 0 4px rgba(255,255,255,0.8)"
1293
+ }
1294
+ },
1295
+ /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1296
+ position: "absolute",
1297
+ top: 0,
1298
+ left: 0,
1299
+ right: 0,
1300
+ bottom: 0,
1301
+ display: "flex",
1302
+ flexDirection: "column",
1303
+ alignItems: "center",
1304
+ justifyContent: "center",
1305
+ color: "white",
1306
+ pointerEvents: "none"
1307
+ } }, status === "pressing" ? /* @__PURE__ */ React2__default.default.createElement(React2__default.default.Fragment, null, /* @__PURE__ */ React2__default.default.createElement("span", { style: { fontSize: "36px", fontWeight: 900, marginBottom: "4px" } }, Math.round(pressProgress), "%"), /* @__PURE__ */ React2__default.default.createElement("span", { style: { fontSize: "14px", opacity: 0.8 } }, "\u7EE7\u7EED\u6309\u4F4F")) : /* @__PURE__ */ React2__default.default.createElement(React2__default.default.Fragment, null, /* @__PURE__ */ React2__default.default.createElement("span", { style: { fontSize: "32px", marginBottom: "8px" } }, "\u{1F446}"), /* @__PURE__ */ React2__default.default.createElement("span", { style: { fontSize: "16px", fontWeight: "bold", padding: "0 16px" } }, buttonText))),
1308
+ status === "idle" && /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1309
+ position: "absolute",
1310
+ top: "16px",
1311
+ left: "16px",
1312
+ right: "16px",
1313
+ bottom: "16px",
1314
+ border: "2px solid rgba(255,255,255,0.3)",
1315
+ borderRadius: "50%"
1316
+ } })
1317
+ ), status === "pressing" && /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1318
+ marginTop: "16px",
1319
+ marginLeft: "auto",
1320
+ marginRight: "auto",
1321
+ width: "192px",
1322
+ height: "8px",
1323
+ backgroundColor: "#e5e7eb",
1324
+ borderRadius: "9999px",
1325
+ overflow: "hidden"
1326
+ } }, /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1327
+ height: "100%",
1328
+ width: pressProgress + "%",
1329
+ background: "linear-gradient(to right, #a855f7, #ec4899)",
1330
+ transition: "width 0.1s ease"
1331
+ } }))), /* @__PURE__ */ React2__default.default.createElement("div", { style: { marginTop: "24px" } }, status === "pressing" ? /* @__PURE__ */ React2__default.default.createElement("p", { style: {
1332
+ fontSize: "18px",
1333
+ fontWeight: 500,
1334
+ color: "#9333ea",
1335
+ animation: "pulse 2s ease-in-out infinite"
1336
+ } }, "\u2728 \u6B63\u5728\u5206\u6790\u4E2D...") : /* @__PURE__ */ React2__default.default.createElement("div", { style: {
1337
+ display: "flex",
1338
+ alignItems: "center",
1339
+ justifyContent: "center",
1340
+ gap: "8px"
1341
+ } }, /* @__PURE__ */ React2__default.default.createElement("span", { style: {
1342
+ display: "inline-block",
1343
+ width: "6px",
1344
+ height: "6px",
1345
+ backgroundColor: "#a855f7",
1346
+ borderRadius: "50%",
1347
+ animation: "bounce 1s infinite"
1348
+ } }), /* @__PURE__ */ React2__default.default.createElement("span", { style: {
1349
+ display: "inline-block",
1350
+ width: "6px",
1351
+ height: "6px",
1352
+ backgroundColor: "#ec4899",
1353
+ borderRadius: "50%",
1354
+ animation: "bounce 1s infinite 0.1s"
1355
+ } }), /* @__PURE__ */ React2__default.default.createElement("span", { style: {
1356
+ display: "inline-block",
1357
+ width: "6px",
1358
+ height: "6px",
1359
+ backgroundColor: "#3b82f6",
1360
+ borderRadius: "50%",
1361
+ animation: "bounce 1s infinite 0.2s"
1362
+ } }))))));
1363
+ };
1364
+ var touchOptimizationStyles = `
1365
+ @keyframes bounce-slow {
1366
+ 0%, 100% {
1367
+ transform: translateY(0);
1368
+ }
1369
+ 50% {
1370
+ transform: translateY(-10px);
1371
+ }
1372
+ }
1373
+
1374
+ @keyframes bounce {
1375
+ 0%, 100% {
1376
+ transform: translateY(0);
1377
+ }
1378
+ 50% {
1379
+ transform: translateY(-4px);
1380
+ }
1381
+ }
1382
+
1383
+ @keyframes pulse {
1384
+ 0%, 100% {
1385
+ opacity: 1;
1386
+ }
1387
+ 50% {
1388
+ opacity: 0.5;
1389
+ }
1390
+ }
1391
+
1392
+ @keyframes spin {
1393
+ from {
1394
+ transform: rotate(0deg);
1395
+ }
1396
+ to {
1397
+ transform: rotate(360deg);
1398
+ }
1399
+ }
1400
+ `;
1401
+ if (typeof document !== "undefined" && !document.getElementById("test-yourself-styles")) {
1402
+ const style = document.createElement("style");
1403
+ style.id = "test-yourself-styles";
1404
+ style.textContent = touchOptimizationStyles;
1405
+ document.head.appendChild(style);
1406
+ }
1407
+ var ConfigManager = ({
1408
+ configService,
1409
+ onConfigChange,
1410
+ className = "",
1411
+ onImageUpload
1412
+ }) => {
1413
+ const [configs, setConfigs] = React2.useState([]);
1414
+ const [selectedConfig, setSelectedConfig] = React2.useState(null);
1415
+ const [isEditing, setIsEditing] = React2.useState(false);
1416
+ const [isCreating, setIsCreating] = React2.useState(false);
1417
+ const [loading, setLoading] = React2.useState(true);
1418
+ const [error, setError] = React2.useState(null);
1419
+ const [success, setSuccess] = React2.useState(null);
1420
+ const [editForm, setEditForm] = React2.useState({
1421
+ name: "",
1422
+ description: "",
1423
+ gameTitle: "",
1424
+ gameDescription: "",
1425
+ buttonText: "\u957F\u6309\u5F00\u59CB\u6D4B\u8BD5",
1426
+ longPressDuration: 2e3,
1427
+ results: []
1428
+ });
1429
+ const loadConfigs = React2.useCallback(async () => {
1430
+ try {
1431
+ setLoading(true);
1432
+ const allConfigs = await configService.getAllConfigs();
1433
+ setConfigs(allConfigs);
1434
+ onConfigChange?.(allConfigs);
1435
+ } catch (err) {
1436
+ setError("\u52A0\u8F7D\u914D\u7F6E\u5931\u8D25: " + err.message);
1437
+ } finally {
1438
+ setLoading(false);
1439
+ }
1440
+ }, [configService, onConfigChange]);
1441
+ React2.useEffect(() => {
1442
+ loadConfigs();
1443
+ }, [loadConfigs]);
1444
+ const handleStartCreate = () => {
1445
+ setEditForm({
1446
+ name: "\u65B0\u914D\u7F6E",
1447
+ description: "",
1448
+ gameTitle: "\u6D4B\u6D4B\u4F60\u662F\u4EC0\u4E48",
1449
+ gameDescription: "\u957F\u6309\u6309\u94AE\uFF0C\u53D1\u73B0\u4F60\u7684\u4E13\u5C5E\u5C5E\u6027",
1450
+ buttonText: "\u957F\u6309\u5F00\u59CB\u6D4B\u8BD5",
1451
+ longPressDuration: 2e3,
1452
+ results: []
1453
+ });
1454
+ setIsCreating(true);
1455
+ setIsEditing(true);
1456
+ setSelectedConfig(null);
1457
+ };
1458
+ const handleStartEdit = (config) => {
1459
+ setEditForm({
1460
+ name: config.name,
1461
+ description: config.description || "",
1462
+ gameTitle: config.config.gameTitle,
1463
+ gameDescription: config.config.gameDescription || "",
1464
+ buttonText: config.config.buttonText || "\u957F\u6309\u5F00\u59CB\u6D4B\u8BD5",
1465
+ longPressDuration: config.config.longPressDuration || 2e3,
1466
+ results: config.config.results
1467
+ });
1468
+ setIsCreating(false);
1469
+ setIsEditing(true);
1470
+ setSelectedConfig(config);
1471
+ };
1472
+ const handleCancelEdit = () => {
1473
+ setIsEditing(false);
1474
+ setIsCreating(false);
1475
+ setSelectedConfig(null);
1476
+ setError(null);
1477
+ };
1478
+ const handleSave = async () => {
1479
+ try {
1480
+ setError(null);
1481
+ if (!editForm.name.trim()) {
1482
+ setError("\u8BF7\u8F93\u5165\u914D\u7F6E\u540D\u79F0");
1483
+ return;
1484
+ }
1485
+ if (!editForm.gameTitle.trim()) {
1486
+ setError("\u8BF7\u8F93\u5165\u6E38\u620F\u6807\u9898");
1487
+ return;
1488
+ }
1489
+ if (editForm.results.length === 0) {
1490
+ setError("\u8BF7\u81F3\u5C11\u6DFB\u52A0\u4E00\u4E2A\u7ED3\u679C\u9879");
1491
+ return;
1492
+ }
1493
+ const testConfig = {
1494
+ gameTitle: editForm.gameTitle,
1495
+ gameDescription: editForm.gameDescription,
1496
+ buttonText: editForm.buttonText,
1497
+ longPressDuration: editForm.longPressDuration,
1498
+ results: editForm.results
1499
+ };
1500
+ if (isCreating) {
1501
+ await configService.createConfig(
1502
+ editForm.name,
1503
+ testConfig,
1504
+ editForm.description
1505
+ );
1506
+ setSuccess("\u521B\u5EFA\u914D\u7F6E\u6210\u529F\uFF01");
1507
+ } else if (selectedConfig) {
1508
+ await configService.updateConfig(selectedConfig.id, {
1509
+ name: editForm.name,
1510
+ description: editForm.description,
1511
+ config: testConfig
1512
+ });
1513
+ setSuccess("\u66F4\u65B0\u914D\u7F6E\u6210\u529F\uFF01");
1514
+ }
1515
+ await loadConfigs();
1516
+ handleCancelEdit();
1517
+ setTimeout(() => setSuccess(null), 3e3);
1518
+ } catch (err) {
1519
+ setError("\u4FDD\u5B58\u5931\u8D25: " + err.message);
1520
+ }
1521
+ };
1522
+ const handleDelete = async (id) => {
1523
+ if (!confirm("\u786E\u5B9A\u8981\u5220\u9664\u8FD9\u4E2A\u914D\u7F6E\u5417\uFF1F")) return;
1524
+ try {
1525
+ await configService.deleteConfig(id);
1526
+ await loadConfigs();
1527
+ setSuccess("\u5220\u9664\u6210\u529F\uFF01");
1528
+ setTimeout(() => setSuccess(null), 3e3);
1529
+ } catch (err) {
1530
+ setError("\u5220\u9664\u5931\u8D25: " + err.message);
1531
+ }
1532
+ };
1533
+ const handleDuplicate = async (id) => {
1534
+ try {
1535
+ await configService.duplicateConfig(id);
1536
+ await loadConfigs();
1537
+ setSuccess("\u590D\u5236\u6210\u529F\uFF01");
1538
+ setTimeout(() => setSuccess(null), 3e3);
1539
+ } catch (err) {
1540
+ setError("\u590D\u5236\u5931\u8D25: " + err.message);
1541
+ }
1542
+ };
1543
+ const handleSetDefault = async (id) => {
1544
+ try {
1545
+ await configService.setDefaultConfig(id);
1546
+ await loadConfigs();
1547
+ setSuccess("\u8BBE\u7F6E\u9ED8\u8BA4\u914D\u7F6E\u6210\u529F\uFF01");
1548
+ setTimeout(() => setSuccess(null), 3e3);
1549
+ } catch (err) {
1550
+ setError("\u8BBE\u7F6E\u5931\u8D25: " + err.message);
1551
+ }
1552
+ };
1553
+ const handleExport = async (id) => {
1554
+ try {
1555
+ const jsonString = await configService.exportConfig(id);
1556
+ const blob = new Blob([jsonString], { type: "application/json" });
1557
+ const url = URL.createObjectURL(blob);
1558
+ const a = document.createElement("a");
1559
+ a.href = url;
1560
+ a.download = "config_" + id + ".json";
1561
+ document.body.appendChild(a);
1562
+ a.click();
1563
+ document.body.removeChild(a);
1564
+ URL.revokeObjectURL(url);
1565
+ setSuccess("\u5BFC\u51FA\u6210\u529F\uFF01");
1566
+ setTimeout(() => setSuccess(null), 3e3);
1567
+ } catch (err) {
1568
+ setError("\u5BFC\u51FA\u5931\u8D25: " + err.message);
1569
+ }
1570
+ };
1571
+ const handleImport = async () => {
1572
+ const input = document.createElement("input");
1573
+ input.type = "file";
1574
+ input.accept = ".json";
1575
+ input.onchange = async (e) => {
1576
+ const file = e.target.files?.[0];
1577
+ if (!file) return;
1578
+ try {
1579
+ const text2 = await file.text();
1580
+ await configService.importConfig(text2);
1581
+ await loadConfigs();
1582
+ setSuccess("\u5BFC\u5165\u6210\u529F\uFF01");
1583
+ setTimeout(() => setSuccess(null), 3e3);
1584
+ } catch (err) {
1585
+ setError("\u5BFC\u5165\u5931\u8D25: " + err.message);
1586
+ }
1587
+ };
1588
+ input.click();
1589
+ };
1590
+ const handleAddResult = () => {
1591
+ const newResult = {
1592
+ id: "temp_" + Date.now(),
1593
+ _tempId: "temp_" + Date.now(),
1594
+ title: "\u65B0\u7ED3\u679C",
1595
+ description: "\u8FD9\u662F\u4E00\u4E2A\u65B0\u7684\u7ED3\u679C\u63CF\u8FF0",
1596
+ image: "\u{1F389}",
1597
+ imageType: "emoji"
1598
+ };
1599
+ setEditForm({
1600
+ ...editForm,
1601
+ results: [...editForm.results, newResult]
1602
+ });
1603
+ };
1604
+ const handleDeleteResult = (index2) => {
1605
+ const newResults = [...editForm.results];
1606
+ newResults.splice(index2, 1);
1607
+ setEditForm({ ...editForm, results: newResults });
1608
+ };
1609
+ const handleUpdateResult = (index2, updates) => {
1610
+ const newResults = [...editForm.results];
1611
+ newResults[index2] = { ...newResults[index2], ...updates };
1612
+ setEditForm({ ...editForm, results: newResults });
1613
+ };
1614
+ const handleResultImageUpload = async (index2, file) => {
1615
+ try {
1616
+ if (!onImageUpload) {
1617
+ const reader = new FileReader();
1618
+ reader.onload = (e) => {
1619
+ const base64 = e.target?.result;
1620
+ handleUpdateResult(index2, {
1621
+ image: base64,
1622
+ imageType: "url"
1623
+ });
1624
+ };
1625
+ reader.readAsDataURL(file);
1626
+ } else {
1627
+ const url = await onImageUpload(file);
1628
+ handleUpdateResult(index2, {
1629
+ image: url,
1630
+ imageType: "url"
1631
+ });
1632
+ }
1633
+ } catch (err) {
1634
+ setError("\u4E0A\u4F20\u56FE\u7247\u5931\u8D25: " + err.message);
1635
+ }
1636
+ };
1637
+ const handleUseDefaultResults = () => {
1638
+ if (confirm("\u786E\u5B9A\u8981\u4F7F\u7528\u9ED8\u8BA4\u768445\u4E2A\u7ED3\u679C\u5417\uFF1F\u8FD9\u5C06\u66FF\u6362\u5F53\u524D\u7684\u6240\u6709\u7ED3\u679C\u3002")) {
1639
+ setEditForm({ ...editForm, results: DEFAULT_RESULTS });
1640
+ }
1641
+ };
1642
+ const renderConfigList = () => /* @__PURE__ */ React2__default.default.createElement("div", { className: "space-y-4" }, configs.map((config) => /* @__PURE__ */ React2__default.default.createElement(
1643
+ "div",
1644
+ {
1645
+ key: config.id,
1646
+ className: "bg-white dark:bg-gray-800 rounded-lg shadow-sm p-4 border border-gray-200 dark:border-gray-700 hover:shadow-md transition-shadow"
1647
+ },
1648
+ /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-start justify-between" }, /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex-1" }, /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-center gap-2 mb-1" }, /* @__PURE__ */ React2__default.default.createElement("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white" }, config.name), config.isDefault && /* @__PURE__ */ React2__default.default.createElement("span", { className: "inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200" }, /* @__PURE__ */ React2__default.default.createElement(lucideReact.Star, { className: "w-3 h-3" }), "\u9ED8\u8BA4")), config.description && /* @__PURE__ */ React2__default.default.createElement("p", { className: "text-sm text-gray-600 dark:text-gray-400 mb-2" }, config.description), /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-center gap-4 text-xs text-gray-500 dark:text-gray-400" }, /* @__PURE__ */ React2__default.default.createElement("span", null, "\u7ED3\u679C\u6570: ", config.config.results.length), /* @__PURE__ */ React2__default.default.createElement("span", null, "\u521B\u5EFA: ", new Date(config.createdAt).toLocaleDateString()))), /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-center gap-2" }, /* @__PURE__ */ React2__default.default.createElement(
1649
+ "button",
1650
+ {
1651
+ onClick: () => handleSetDefault(config.id),
1652
+ disabled: config.isDefault,
1653
+ className: "p-2 text-gray-600 hover:text-yellow-600 disabled:opacity-50 disabled:cursor-not-allowed",
1654
+ title: "\u8BBE\u4E3A\u9ED8\u8BA4"
1655
+ },
1656
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Star, { className: "w-5 h-5" })
1657
+ ), /* @__PURE__ */ React2__default.default.createElement(
1658
+ "button",
1659
+ {
1660
+ onClick: () => handleStartEdit(config),
1661
+ className: "p-2 text-gray-600 hover:text-blue-600",
1662
+ title: "\u7F16\u8F91"
1663
+ },
1664
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Edit, { className: "w-5 h-5" })
1665
+ ), /* @__PURE__ */ React2__default.default.createElement(
1666
+ "button",
1667
+ {
1668
+ onClick: () => handleDuplicate(config.id),
1669
+ className: "p-2 text-gray-600 hover:text-green-600",
1670
+ title: "\u590D\u5236"
1671
+ },
1672
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Copy, { className: "w-5 h-5" })
1673
+ ), /* @__PURE__ */ React2__default.default.createElement(
1674
+ "button",
1675
+ {
1676
+ onClick: () => handleExport(config.id),
1677
+ className: "p-2 text-gray-600 hover:text-purple-600",
1678
+ title: "\u5BFC\u51FA"
1679
+ },
1680
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Download, { className: "w-5 h-5" })
1681
+ ), /* @__PURE__ */ React2__default.default.createElement(
1682
+ "button",
1683
+ {
1684
+ onClick: () => handleDelete(config.id),
1685
+ className: "p-2 text-gray-600 hover:text-red-600",
1686
+ title: "\u5220\u9664"
1687
+ },
1688
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Trash2, { className: "w-5 h-5" })
1689
+ )))
1690
+ )));
1691
+ const renderResultEditor = (result, index2) => /* @__PURE__ */ React2__default.default.createElement(
1692
+ "div",
1693
+ {
1694
+ key: result._tempId || result.id,
1695
+ className: "bg-gray-50 dark:bg-gray-700 rounded-lg p-4 space-y-3"
1696
+ },
1697
+ /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-start justify-between" }, /* @__PURE__ */ React2__default.default.createElement("h4", { className: "text-sm font-medium text-gray-700 dark:text-gray-300" }, "\u7ED3\u679C #", index2 + 1), /* @__PURE__ */ React2__default.default.createElement(
1698
+ "button",
1699
+ {
1700
+ onClick: () => handleDeleteResult(index2),
1701
+ className: "text-red-600 hover:text-red-700"
1702
+ },
1703
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Trash2, { className: "w-4 h-4" })
1704
+ )),
1705
+ /* @__PURE__ */ React2__default.default.createElement("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-3" }, /* @__PURE__ */ React2__default.default.createElement("div", null, /* @__PURE__ */ React2__default.default.createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1" }, "\u6807\u9898"), /* @__PURE__ */ React2__default.default.createElement(
1706
+ "input",
1707
+ {
1708
+ type: "text",
1709
+ value: result.title,
1710
+ onChange: (e) => handleUpdateResult(index2, { title: e.target.value }),
1711
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-800 dark:text-white",
1712
+ placeholder: "\u4F8B\u5982: \u53EF\u7231\u7684\u732B\u54AA"
1713
+ }
1714
+ )), /* @__PURE__ */ React2__default.default.createElement("div", null, /* @__PURE__ */ React2__default.default.createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1" }, "\u56FE\u7247/Emoji"), /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex gap-2" }, /* @__PURE__ */ React2__default.default.createElement(
1715
+ "input",
1716
+ {
1717
+ type: "text",
1718
+ value: result.image,
1719
+ onChange: (e) => handleUpdateResult(index2, { image: e.target.value }),
1720
+ className: "flex-1 px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-800 dark:text-white",
1721
+ placeholder: "\u{1F389} \u6216 URL"
1722
+ }
1723
+ ), /* @__PURE__ */ React2__default.default.createElement("label", { className: "cursor-pointer inline-flex items-center justify-center px-3 py-2 bg-blue-50 dark:bg-blue-900 text-blue-600 dark:text-blue-200 rounded-lg hover:bg-blue-100 dark:hover:bg-blue-800" }, /* @__PURE__ */ React2__default.default.createElement(lucideReact.Image, { className: "w-5 h-5" }), /* @__PURE__ */ React2__default.default.createElement(
1724
+ "input",
1725
+ {
1726
+ type: "file",
1727
+ accept: "image/*",
1728
+ className: "hidden",
1729
+ onChange: (e) => {
1730
+ const file = e.target.files?.[0];
1731
+ if (file) handleResultImageUpload(index2, file);
1732
+ }
1733
+ }
1734
+ ))))),
1735
+ /* @__PURE__ */ React2__default.default.createElement("div", null, /* @__PURE__ */ React2__default.default.createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1" }, "\u63CF\u8FF0"), /* @__PURE__ */ React2__default.default.createElement(
1736
+ "textarea",
1737
+ {
1738
+ value: result.description,
1739
+ onChange: (e) => handleUpdateResult(index2, { description: e.target.value }),
1740
+ rows: 2,
1741
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-800 dark:text-white",
1742
+ placeholder: "\u8FD9\u4E2A\u7ED3\u679C\u7684\u8BE6\u7EC6\u63CF\u8FF0..."
1743
+ }
1744
+ )),
1745
+ result.image && /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-center gap-2 p-2 bg-white dark:bg-gray-600 rounded border border-gray-200 dark:border-gray-500" }, /* @__PURE__ */ React2__default.default.createElement("span", { className: "text-sm text-gray-500 dark:text-gray-400" }, "\u9884\u89C8:"), result.imageType === "emoji" ? /* @__PURE__ */ React2__default.default.createElement("span", { className: "text-2xl" }, result.image) : /* @__PURE__ */ React2__default.default.createElement("img", { src: result.image, alt: result.title, className: "w-8 h-8 object-cover rounded" }), /* @__PURE__ */ React2__default.default.createElement("span", { className: "text-sm font-medium text-gray-700 dark:text-gray-300" }, result.title))
1746
+ );
1747
+ const renderEditForm = () => /* @__PURE__ */ React2__default.default.createElement("div", { className: "space-y-6" }, /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-center justify-between" }, /* @__PURE__ */ React2__default.default.createElement("h2", { className: "text-2xl font-bold text-gray-900 dark:text-white" }, isCreating ? "\u521B\u5EFA\u65B0\u914D\u7F6E" : "\u7F16\u8F91\u914D\u7F6E"), /* @__PURE__ */ React2__default.default.createElement(
1748
+ "button",
1749
+ {
1750
+ onClick: handleCancelEdit,
1751
+ className: "p-2 text-gray-600 hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-200"
1752
+ },
1753
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.X, { className: "w-6 h-6" })
1754
+ )), /* @__PURE__ */ React2__default.default.createElement("div", { className: "space-y-4 bg-white dark:bg-gray-800 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-gray-700" }, /* @__PURE__ */ React2__default.default.createElement("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white mb-4" }, "\u57FA\u672C\u4FE1\u606F"), /* @__PURE__ */ React2__default.default.createElement("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4" }, /* @__PURE__ */ React2__default.default.createElement("div", null, /* @__PURE__ */ React2__default.default.createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2" }, "\u914D\u7F6E\u540D\u79F0 *"), /* @__PURE__ */ React2__default.default.createElement(
1755
+ "input",
1756
+ {
1757
+ type: "text",
1758
+ value: editForm.name,
1759
+ onChange: (e) => setEditForm({ ...editForm, name: e.target.value }),
1760
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white",
1761
+ placeholder: "\u4F8B\u5982: \u52A8\u7269\u4E3B\u9898\u6D4B\u8BD5"
1762
+ }
1763
+ )), /* @__PURE__ */ React2__default.default.createElement("div", null, /* @__PURE__ */ React2__default.default.createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2" }, "\u6E38\u620F\u6807\u9898 *"), /* @__PURE__ */ React2__default.default.createElement(
1764
+ "input",
1765
+ {
1766
+ type: "text",
1767
+ value: editForm.gameTitle,
1768
+ onChange: (e) => setEditForm({ ...editForm, gameTitle: e.target.value }),
1769
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white",
1770
+ placeholder: "\u4F8B\u5982: \u6D4B\u6D4B\u4F60\u662F\u4EC0\u4E48\u52A8\u7269"
1771
+ }
1772
+ ))), /* @__PURE__ */ React2__default.default.createElement("div", null, /* @__PURE__ */ React2__default.default.createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2" }, "\u914D\u7F6E\u63CF\u8FF0"), /* @__PURE__ */ React2__default.default.createElement(
1773
+ "textarea",
1774
+ {
1775
+ value: editForm.description,
1776
+ onChange: (e) => setEditForm({ ...editForm, description: e.target.value }),
1777
+ rows: 2,
1778
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white",
1779
+ placeholder: "\u7B80\u8981\u63CF\u8FF0\u8FD9\u4E2A\u914D\u7F6E\u7684\u7528\u9014..."
1780
+ }
1781
+ )), /* @__PURE__ */ React2__default.default.createElement("div", null, /* @__PURE__ */ React2__default.default.createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2" }, "\u6E38\u620F\u63CF\u8FF0"), /* @__PURE__ */ React2__default.default.createElement(
1782
+ "input",
1783
+ {
1784
+ type: "text",
1785
+ value: editForm.gameDescription,
1786
+ onChange: (e) => setEditForm({ ...editForm, gameDescription: e.target.value }),
1787
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white",
1788
+ placeholder: "\u4F8B\u5982: \u957F\u6309\u6309\u94AE\uFF0C\u53D1\u73B0\u4F60\u7684\u4E13\u5C5E\u5C5E\u6027"
1789
+ }
1790
+ )), /* @__PURE__ */ React2__default.default.createElement("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4" }, /* @__PURE__ */ React2__default.default.createElement("div", null, /* @__PURE__ */ React2__default.default.createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2" }, "\u6309\u94AE\u6587\u672C"), /* @__PURE__ */ React2__default.default.createElement(
1791
+ "input",
1792
+ {
1793
+ type: "text",
1794
+ value: editForm.buttonText,
1795
+ onChange: (e) => setEditForm({ ...editForm, buttonText: e.target.value }),
1796
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white"
1797
+ }
1798
+ )), /* @__PURE__ */ React2__default.default.createElement("div", null, /* @__PURE__ */ React2__default.default.createElement("label", { className: "block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2" }, "\u957F\u6309\u65F6\u95F4 (\u6BEB\u79D2)"), /* @__PURE__ */ React2__default.default.createElement(
1799
+ "input",
1800
+ {
1801
+ type: "number",
1802
+ value: editForm.longPressDuration,
1803
+ onChange: (e) => setEditForm({ ...editForm, longPressDuration: parseInt(e.target.value) || 2e3 }),
1804
+ className: "w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-700 dark:text-white",
1805
+ min: "500",
1806
+ step: "100"
1807
+ }
1808
+ )))), /* @__PURE__ */ React2__default.default.createElement("div", { className: "bg-white dark:bg-gray-800 rounded-lg p-6 shadow-sm border border-gray-200 dark:border-gray-700" }, /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-center justify-between mb-4" }, /* @__PURE__ */ React2__default.default.createElement("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white" }, "\u7ED3\u679C\u5217\u8868 (", editForm.results.length, ")"), /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex gap-2" }, /* @__PURE__ */ React2__default.default.createElement(
1809
+ "button",
1810
+ {
1811
+ onClick: handleUseDefaultResults,
1812
+ className: "inline-flex items-center gap-2 px-3 py-1.5 text-sm bg-purple-50 dark:bg-purple-900 text-purple-600 dark:text-purple-200 rounded-lg hover:bg-purple-100 dark:hover:bg-purple-800"
1813
+ },
1814
+ "\u4F7F\u7528\u9ED8\u8BA4\u7ED3\u679C"
1815
+ ), /* @__PURE__ */ React2__default.default.createElement(
1816
+ "button",
1817
+ {
1818
+ onClick: handleAddResult,
1819
+ className: "inline-flex items-center gap-2 px-3 py-1.5 text-sm bg-blue-50 dark:bg-blue-900 text-blue-600 dark:text-blue-200 rounded-lg hover:bg-blue-100 dark:hover:bg-blue-800"
1820
+ },
1821
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Plus, { className: "w-4 h-4" }),
1822
+ "\u6DFB\u52A0\u7ED3\u679C"
1823
+ ))), /* @__PURE__ */ React2__default.default.createElement("div", { className: "space-y-3 max-h-[500px] overflow-y-auto" }, editForm.results.length === 0 ? /* @__PURE__ */ React2__default.default.createElement("div", { className: "text-center py-8 text-gray-500 dark:text-gray-400" }, /* @__PURE__ */ React2__default.default.createElement("p", null, "\u8FD8\u6CA1\u6709\u6DFB\u52A0\u4EFB\u4F55\u7ED3\u679C"), /* @__PURE__ */ React2__default.default.createElement("p", { className: "text-sm mt-2" }, '\u70B9\u51FB"\u6DFB\u52A0\u7ED3\u679C"\u6216"\u4F7F\u7528\u9ED8\u8BA4\u7ED3\u679C"\u5F00\u59CB')) : editForm.results.map((result, index2) => renderResultEditor(result, index2)))), /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-center justify-end gap-3" }, /* @__PURE__ */ React2__default.default.createElement(
1824
+ "button",
1825
+ {
1826
+ onClick: handleCancelEdit,
1827
+ className: "px-6 py-2 text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700"
1828
+ },
1829
+ "\u53D6\u6D88"
1830
+ ), /* @__PURE__ */ React2__default.default.createElement(
1831
+ "button",
1832
+ {
1833
+ onClick: handleSave,
1834
+ className: "inline-flex items-center gap-2 px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700"
1835
+ },
1836
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Save, { className: "w-5 h-5" }),
1837
+ "\u4FDD\u5B58\u914D\u7F6E"
1838
+ )));
1839
+ if (loading) {
1840
+ return /* @__PURE__ */ React2__default.default.createElement("div", { className: clsx.clsx("p-8", className) }, /* @__PURE__ */ React2__default.default.createElement("div", { className: "text-center" }, /* @__PURE__ */ React2__default.default.createElement("div", { className: "inline-block w-8 h-8 border-4 border-blue-600 border-t-transparent rounded-full animate-spin" }), /* @__PURE__ */ React2__default.default.createElement("p", { className: "mt-2 text-gray-600 dark:text-gray-400" }, "\u52A0\u8F7D\u4E2D...")));
1841
+ }
1842
+ return /* @__PURE__ */ React2__default.default.createElement("div", { className: clsx.clsx("p-6", className) }, error && /* @__PURE__ */ React2__default.default.createElement("div", { className: "mb-4 p-4 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg flex items-center gap-2 text-red-800 dark:text-red-200" }, /* @__PURE__ */ React2__default.default.createElement(lucideReact.AlertCircle, { className: "w-5 h-5 flex-shrink-0" }), /* @__PURE__ */ React2__default.default.createElement("span", null, error), /* @__PURE__ */ React2__default.default.createElement("button", { onClick: () => setError(null), className: "ml-auto" }, /* @__PURE__ */ React2__default.default.createElement(lucideReact.X, { className: "w-5 h-5" }))), success && /* @__PURE__ */ React2__default.default.createElement("div", { className: "mb-4 p-4 bg-green-50 dark:bg-green-900/20 border border-green-200 dark:border-green-800 rounded-lg flex items-center gap-2 text-green-800 dark:text-green-200" }, /* @__PURE__ */ React2__default.default.createElement(lucideReact.CheckCircle2, { className: "w-5 h-5 flex-shrink-0" }), /* @__PURE__ */ React2__default.default.createElement("span", null, success), /* @__PURE__ */ React2__default.default.createElement("button", { onClick: () => setSuccess(null), className: "ml-auto" }, /* @__PURE__ */ React2__default.default.createElement(lucideReact.X, { className: "w-5 h-5" }))), isEditing ? renderEditForm() : /* @__PURE__ */ React2__default.default.createElement(React2__default.default.Fragment, null, /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-center justify-between mb-6" }, /* @__PURE__ */ React2__default.default.createElement("h1", { className: "text-3xl font-bold text-gray-900 dark:text-white" }, "\u914D\u7F6E\u7BA1\u7406"), /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex gap-2" }, /* @__PURE__ */ React2__default.default.createElement(
1843
+ "button",
1844
+ {
1845
+ onClick: handleImport,
1846
+ className: "inline-flex items-center gap-2 px-4 py-2 text-gray-700 dark:text-gray-300 border border-gray-300 dark:border-gray-600 rounded-lg hover:bg-gray-50 dark:hover:bg-gray-700"
1847
+ },
1848
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Upload, { className: "w-5 h-5" }),
1849
+ "\u5BFC\u5165"
1850
+ ), /* @__PURE__ */ React2__default.default.createElement(
1851
+ "button",
1852
+ {
1853
+ onClick: handleStartCreate,
1854
+ className: "inline-flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700"
1855
+ },
1856
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Plus, { className: "w-5 h-5" }),
1857
+ "\u521B\u5EFA\u914D\u7F6E"
1858
+ ))), configs.length === 0 ? /* @__PURE__ */ React2__default.default.createElement("div", { className: "text-center py-12 bg-white dark:bg-gray-800 rounded-lg border-2 border-dashed border-gray-300 dark:border-gray-700" }, /* @__PURE__ */ React2__default.default.createElement("p", { className: "text-gray-600 dark:text-gray-400 mb-4" }, "\u8FD8\u6CA1\u6709\u4EFB\u4F55\u914D\u7F6E"), /* @__PURE__ */ React2__default.default.createElement(
1859
+ "button",
1860
+ {
1861
+ onClick: handleStartCreate,
1862
+ className: "inline-flex items-center gap-2 px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700"
1863
+ },
1864
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Plus, { className: "w-5 h-5" }),
1865
+ "\u521B\u5EFA\u7B2C\u4E00\u4E2A\u914D\u7F6E"
1866
+ )) : renderConfigList()));
1867
+ };
1868
+ var ConfigList = ({
1869
+ configService,
1870
+ onSelect,
1871
+ onEdit,
1872
+ onDelete,
1873
+ showActions = true,
1874
+ showPreviewLink = false,
1875
+ previewBaseUrl = "/test-yourself",
1876
+ className = "",
1877
+ pageSize = 10
1878
+ }) => {
1879
+ const [configs, setConfigs] = React2.useState([]);
1880
+ const [loading, setLoading] = React2.useState(true);
1881
+ const [currentPage, setCurrentPage] = React2.useState(1);
1882
+ const [searchTerm, setSearchTerm] = React2.useState("");
1883
+ const loadConfigs = React2.useCallback(async () => {
1884
+ try {
1885
+ setLoading(true);
1886
+ const list = await configService.getConfigList();
1887
+ setConfigs(list);
1888
+ } catch (error) {
1889
+ console.error("\u52A0\u8F7D\u914D\u7F6E\u5217\u8868\u5931\u8D25:", error);
1890
+ } finally {
1891
+ setLoading(false);
1892
+ }
1893
+ }, [configService]);
1894
+ React2.useEffect(() => {
1895
+ loadConfigs();
1896
+ }, [loadConfigs]);
1897
+ const handleRefresh = () => {
1898
+ loadConfigs();
1899
+ };
1900
+ const handleSelect = (id) => {
1901
+ onSelect?.(id);
1902
+ };
1903
+ const handleEdit = (id) => {
1904
+ onEdit?.(id);
1905
+ };
1906
+ const handleDelete = async (id) => {
1907
+ if (!confirm("\u786E\u5B9A\u8981\u5220\u9664\u8FD9\u4E2A\u914D\u7F6E\u5417\uFF1F")) return;
1908
+ try {
1909
+ await configService.deleteConfig(id);
1910
+ await loadConfigs();
1911
+ onDelete?.(id);
1912
+ } catch (error) {
1913
+ console.error("\u5220\u9664\u914D\u7F6E\u5931\u8D25:", error);
1914
+ alert("\u5220\u9664\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5");
1915
+ }
1916
+ };
1917
+ const handleDuplicate = async (id) => {
1918
+ try {
1919
+ await configService.duplicateConfig(id);
1920
+ await loadConfigs();
1921
+ } catch (error) {
1922
+ console.error("\u590D\u5236\u914D\u7F6E\u5931\u8D25:", error);
1923
+ alert("\u590D\u5236\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5");
1924
+ }
1925
+ };
1926
+ const handleSetDefault = async (id) => {
1927
+ try {
1928
+ await configService.setDefaultConfig(id);
1929
+ await loadConfigs();
1930
+ } catch (error) {
1931
+ console.error("\u8BBE\u7F6E\u9ED8\u8BA4\u914D\u7F6E\u5931\u8D25:", error);
1932
+ alert("\u8BBE\u7F6E\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5");
1933
+ }
1934
+ };
1935
+ const handleExport = async (id) => {
1936
+ try {
1937
+ const jsonString = await configService.exportConfig(id);
1938
+ const blob = new Blob([jsonString], { type: "application/json" });
1939
+ const url = URL.createObjectURL(blob);
1940
+ const a = document.createElement("a");
1941
+ a.href = url;
1942
+ a.download = "config_" + id + ".json";
1943
+ document.body.appendChild(a);
1944
+ a.click();
1945
+ document.body.removeChild(a);
1946
+ URL.revokeObjectURL(url);
1947
+ } catch (error) {
1948
+ console.error("\u5BFC\u51FA\u914D\u7F6E\u5931\u8D25:", error);
1949
+ alert("\u5BFC\u51FA\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5");
1950
+ }
1951
+ };
1952
+ const getPreviewUrl = (id) => {
1953
+ return previewBaseUrl + "?configId=" + id;
1954
+ };
1955
+ const filteredConfigs = configs.filter((config) => {
1956
+ if (!searchTerm) return true;
1957
+ const term = searchTerm.toLowerCase();
1958
+ return config.name.toLowerCase().includes(term) || config.description?.toLowerCase().includes(term);
1959
+ });
1960
+ const totalPages = Math.ceil(filteredConfigs.length / pageSize);
1961
+ const startIndex = (currentPage - 1) * pageSize;
1962
+ const endIndex = startIndex + pageSize;
1963
+ const currentConfigs = filteredConfigs.slice(startIndex, endIndex);
1964
+ if (loading) {
1965
+ return /* @__PURE__ */ React2__default.default.createElement("div", { className: clsx.clsx("p-8", className) }, /* @__PURE__ */ React2__default.default.createElement("div", { className: "text-center" }, /* @__PURE__ */ React2__default.default.createElement("div", { className: "inline-block w-8 h-8 border-4 border-blue-600 border-t-transparent rounded-full animate-spin" }), /* @__PURE__ */ React2__default.default.createElement("p", { className: "mt-2 text-gray-600 dark:text-gray-400" }, "\u52A0\u8F7D\u4E2D...")));
1966
+ }
1967
+ return /* @__PURE__ */ React2__default.default.createElement("div", { className }, /* @__PURE__ */ React2__default.default.createElement("div", { className: "mb-4 flex items-center justify-between gap-4" }, /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex-1" }, /* @__PURE__ */ React2__default.default.createElement(
1968
+ "input",
1969
+ {
1970
+ type: "text",
1971
+ placeholder: "\u641C\u7D22\u914D\u7F6E...",
1972
+ value: searchTerm,
1973
+ onChange: (e) => {
1974
+ setSearchTerm(e.target.value);
1975
+ setCurrentPage(1);
1976
+ },
1977
+ className: "w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 dark:bg-gray-800 dark:text-white"
1978
+ }
1979
+ )), /* @__PURE__ */ React2__default.default.createElement(
1980
+ "button",
1981
+ {
1982
+ onClick: handleRefresh,
1983
+ className: "p-2 text-gray-600 hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-200",
1984
+ title: "\u5237\u65B0"
1985
+ },
1986
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.RefreshCw, { className: "w-5 h-5" })
1987
+ )), currentConfigs.length === 0 ? /* @__PURE__ */ React2__default.default.createElement("div", { className: "text-center py-12 bg-gray-50 dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700" }, /* @__PURE__ */ React2__default.default.createElement("p", { className: "text-gray-600 dark:text-gray-400" }, searchTerm ? "\u6CA1\u6709\u627E\u5230\u5339\u914D\u7684\u914D\u7F6E" : "\u8FD8\u6CA1\u6709\u4EFB\u4F55\u914D\u7F6E")) : /* @__PURE__ */ React2__default.default.createElement("div", { className: "space-y-3" }, currentConfigs.map((config) => /* @__PURE__ */ React2__default.default.createElement(
1988
+ "div",
1989
+ {
1990
+ key: config.id,
1991
+ className: "bg-white dark:bg-gray-800 rounded-lg shadow-sm p-4 border border-gray-200 dark:border-gray-700 hover:shadow-md transition-shadow"
1992
+ },
1993
+ /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-start justify-between gap-4" }, /* @__PURE__ */ React2__default.default.createElement(
1994
+ "div",
1995
+ {
1996
+ className: "flex-1 cursor-pointer",
1997
+ onClick: () => handleSelect(config.id)
1998
+ },
1999
+ /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-center gap-2 mb-1" }, /* @__PURE__ */ React2__default.default.createElement("h3", { className: "text-lg font-semibold text-gray-900 dark:text-white" }, config.name), config.isDefault && /* @__PURE__ */ React2__default.default.createElement("span", { className: "inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs font-medium bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200" }, /* @__PURE__ */ React2__default.default.createElement(lucideReact.Star, { className: "w-3 h-3" }), "\u9ED8\u8BA4")),
2000
+ config.description && /* @__PURE__ */ React2__default.default.createElement("p", { className: "text-sm text-gray-600 dark:text-gray-400 mb-2" }, config.description),
2001
+ /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-center gap-4 text-xs text-gray-500 dark:text-gray-400" }, /* @__PURE__ */ React2__default.default.createElement("span", null, "\u7ED3\u679C\u6570: ", config.resultCount), /* @__PURE__ */ React2__default.default.createElement("span", null, "\u521B\u5EFA: ", new Date(config.createdAt).toLocaleDateString()), config.updatedAt !== config.createdAt && /* @__PURE__ */ React2__default.default.createElement("span", null, "\u66F4\u65B0: ", new Date(config.updatedAt).toLocaleDateString()))
2002
+ ), showActions && /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-center gap-1" }, showPreviewLink && /* @__PURE__ */ React2__default.default.createElement(
2003
+ "a",
2004
+ {
2005
+ href: getPreviewUrl(config.id),
2006
+ target: "_blank",
2007
+ rel: "noopener noreferrer",
2008
+ className: "p-2 text-gray-600 hover:text-blue-600 dark:text-gray-400 dark:hover:text-blue-400",
2009
+ title: "\u9884\u89C8"
2010
+ },
2011
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.ExternalLink, { className: "w-4 h-4" })
2012
+ ), /* @__PURE__ */ React2__default.default.createElement(
2013
+ "button",
2014
+ {
2015
+ onClick: () => handleSetDefault(config.id),
2016
+ disabled: config.isDefault,
2017
+ className: "p-2 text-gray-600 hover:text-yellow-600 disabled:opacity-50 disabled:cursor-not-allowed",
2018
+ title: "\u8BBE\u4E3A\u9ED8\u8BA4"
2019
+ },
2020
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Star, { className: "w-4 h-4" })
2021
+ ), /* @__PURE__ */ React2__default.default.createElement(
2022
+ "button",
2023
+ {
2024
+ onClick: () => handleEdit(config.id),
2025
+ className: "p-2 text-gray-600 hover:text-blue-600",
2026
+ title: "\u7F16\u8F91"
2027
+ },
2028
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Edit, { className: "w-4 h-4" })
2029
+ ), /* @__PURE__ */ React2__default.default.createElement(
2030
+ "button",
2031
+ {
2032
+ onClick: () => handleDuplicate(config.id),
2033
+ className: "p-2 text-gray-600 hover:text-green-600",
2034
+ title: "\u590D\u5236"
2035
+ },
2036
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Copy, { className: "w-4 h-4" })
2037
+ ), /* @__PURE__ */ React2__default.default.createElement(
2038
+ "button",
2039
+ {
2040
+ onClick: () => handleExport(config.id),
2041
+ className: "p-2 text-gray-600 hover:text-purple-600",
2042
+ title: "\u5BFC\u51FA"
2043
+ },
2044
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Download, { className: "w-4 h-4" })
2045
+ ), /* @__PURE__ */ React2__default.default.createElement(
2046
+ "button",
2047
+ {
2048
+ onClick: () => handleDelete(config.id),
2049
+ className: "p-2 text-gray-600 hover:text-red-600",
2050
+ title: "\u5220\u9664"
2051
+ },
2052
+ /* @__PURE__ */ React2__default.default.createElement(lucideReact.Trash2, { className: "w-4 h-4" })
2053
+ )))
2054
+ ))), totalPages > 1 && /* @__PURE__ */ React2__default.default.createElement("div", { className: "mt-4 flex items-center justify-between" }, /* @__PURE__ */ React2__default.default.createElement("p", { className: "text-sm text-gray-600 dark:text-gray-400" }, "\u663E\u793A ", startIndex + 1, " - ", Math.min(endIndex, filteredConfigs.length), " \u5171", " ", filteredConfigs.length, " \u4E2A\u914D\u7F6E"), /* @__PURE__ */ React2__default.default.createElement("div", { className: "flex items-center gap-2" }, /* @__PURE__ */ React2__default.default.createElement(
2055
+ "button",
2056
+ {
2057
+ onClick: () => setCurrentPage((p) => Math.max(1, p - 1)),
2058
+ disabled: currentPage === 1,
2059
+ className: "px-3 py-1 border border-gray-300 dark:border-gray-600 rounded-lg disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-50 dark:hover:bg-gray-700"
2060
+ },
2061
+ "\u4E0A\u4E00\u9875"
2062
+ ), /* @__PURE__ */ React2__default.default.createElement("span", { className: "text-sm text-gray-600 dark:text-gray-400" }, currentPage, " / ", totalPages), /* @__PURE__ */ React2__default.default.createElement(
2063
+ "button",
2064
+ {
2065
+ onClick: () => setCurrentPage((p) => Math.min(totalPages, p + 1)),
2066
+ disabled: currentPage === totalPages,
2067
+ className: "px-3 py-1 border border-gray-300 dark:border-gray-600 rounded-lg disabled:opacity-50 disabled:cursor-not-allowed hover:bg-gray-50 dark:hover:bg-gray-700"
2068
+ },
2069
+ "\u4E0B\u4E00\u9875"
2070
+ ))));
2071
+ };
2072
+
2073
+ // src/testYourself/server/index.ts
2074
+ init_ConfigService();
2075
+ var testYourselfConfigs = pgCore.pgTable(
2076
+ "test_yourself_configs",
2077
+ {
2078
+ // ========== 主键 ==========
2079
+ /** 配置唯一ID */
2080
+ id: pgCore.uuid("id").primaryKey().defaultRandom(),
2081
+ // ========== 基本信息 ==========
2082
+ /** 配置名称 */
2083
+ name: pgCore.varchar("name", { length: 255 }).notNull(),
2084
+ /** 配置描述 */
2085
+ description: pgCore.text("description"),
2086
+ /** 配置标签(用于分类和搜索) */
2087
+ tags: pgCore.json("tags").$type().default([]),
2088
+ // ========== 配置数据 ==========
2089
+ /** 测试配置内容(JSON格式) */
2090
+ config: pgCore.json("config").$type().notNull(),
2091
+ /** 结果数量(冗余字段,便于查询) */
2092
+ resultCount: pgCore.integer("result_count").notNull().default(0),
2093
+ // ========== 状态字段 ==========
2094
+ /** 是否为默认配置 */
2095
+ isDefault: pgCore.boolean("is_default").notNull().default(false),
2096
+ /** 是否已发布(草稿/发布) */
2097
+ isPublished: pgCore.boolean("is_published").notNull().default(true),
2098
+ /** 是否已归档 */
2099
+ isArchived: pgCore.boolean("is_archived").notNull().default(false),
2100
+ /** 是否已删除(软删除) */
2101
+ isDeleted: pgCore.boolean("is_deleted").notNull().default(false),
2102
+ // ========== 权限和所有权 ==========
2103
+ /** 创建者ID */
2104
+ createdBy: pgCore.varchar("created_by", { length: 255 }).notNull(),
2105
+ /** 最后更新者ID */
2106
+ updatedBy: pgCore.varchar("updated_by", { length: 255 }),
2107
+ /** 所属组织/租户ID(多租户支持) */
2108
+ organizationId: pgCore.varchar("organization_id", { length: 255 }),
2109
+ // ========== 统计信息 ==========
2110
+ /** 使用次数 */
2111
+ usageCount: pgCore.integer("usage_count").notNull().default(0),
2112
+ /** 最后使用时间 */
2113
+ lastUsedAt: pgCore.timestamp("last_used_at"),
2114
+ /** 浏览次数 */
2115
+ viewCount: pgCore.integer("view_count").notNull().default(0),
2116
+ // ========== 版本控制 ==========
2117
+ /** 配置版本号 */
2118
+ version: pgCore.integer("version").notNull().default(1),
2119
+ /** 父配置ID(用于版本追踪) */
2120
+ parentId: pgCore.uuid("parent_id"),
2121
+ // ========== 自定义字段 ==========
2122
+ /** 自定义元数据(扩展字段) */
2123
+ metadata: pgCore.json("metadata").$type(),
2124
+ /** 配置来源(web/api/import) */
2125
+ source: pgCore.varchar("source", { length: 50 }),
2126
+ // ========== 时间戳 ==========
2127
+ /** 创建时间 */
2128
+ createdAt: pgCore.timestamp("created_at").defaultNow().notNull(),
2129
+ /** 更新时间 */
2130
+ updatedAt: pgCore.timestamp("updated_at").defaultNow().notNull(),
2131
+ /** 发布时间 */
2132
+ publishedAt: pgCore.timestamp("published_at"),
2133
+ /** 归档时间 */
2134
+ archivedAt: pgCore.timestamp("archived_at"),
2135
+ /** 删除时间 */
2136
+ deletedAt: pgCore.timestamp("deleted_at")
2137
+ },
2138
+ (table) => ({
2139
+ // ========== 索引设计 ==========
2140
+ /** 名称搜索索引 */
2141
+ nameIndex: pgCore.index("test_configs_name_idx").on(table.name),
2142
+ /** 创建者索引 */
2143
+ createdByIndex: pgCore.index("test_configs_created_by_idx").on(table.createdBy),
2144
+ /** 组织索引(多租户) */
2145
+ organizationIndex: pgCore.index("test_configs_organization_idx").on(table.organizationId),
2146
+ /** 默认配置索引 */
2147
+ isDefaultIndex: pgCore.index("test_configs_is_default_idx").on(table.isDefault),
2148
+ /** 发布状态索引 */
2149
+ isPublishedIndex: pgCore.index("test_configs_is_published_idx").on(table.isPublished),
2150
+ /** 删除状态索引 */
2151
+ isDeletedIndex: pgCore.index("test_configs_is_deleted_idx").on(table.isDeleted),
2152
+ /** 创建时间索引 */
2153
+ createdAtIndex: pgCore.index("test_configs_created_at_idx").on(table.createdAt),
2154
+ /** 最后使用时间索引 */
2155
+ lastUsedAtIndex: pgCore.index("test_configs_last_used_at_idx").on(table.lastUsedAt),
2156
+ /** 组合索引:组织+删除状态+发布状态 */
2157
+ orgDeletedPublishedIndex: pgCore.index("test_configs_org_deleted_published_idx").on(
2158
+ table.organizationId,
2159
+ table.isDeleted,
2160
+ table.isPublished
2161
+ ),
2162
+ /** 组合索引:创建者+删除状态 */
2163
+ createdByDeletedIndex: pgCore.index("test_configs_created_by_deleted_idx").on(
2164
+ table.createdBy,
2165
+ table.isDeleted
2166
+ )
2167
+ })
2168
+ );
2169
+ var testYourselfConfigUsage = pgCore.pgTable(
2170
+ "test_yourself_config_usage",
2171
+ {
2172
+ /** 记录ID */
2173
+ id: pgCore.uuid("id").primaryKey().defaultRandom(),
2174
+ /** 配置ID */
2175
+ configId: pgCore.uuid("config_id").references(() => testYourselfConfigs.id, { onDelete: "cascade" }).notNull(),
2176
+ /** 用户ID */
2177
+ userId: pgCore.varchar("user_id", { length: 255 }),
2178
+ /** 设备指纹 */
2179
+ fingerprint: pgCore.text("fingerprint"),
2180
+ /** 测试结果ID */
2181
+ resultId: pgCore.varchar("result_id", { length: 255 }),
2182
+ /** IP地址 */
2183
+ ipAddress: pgCore.varchar("ip_address", { length: 45 }),
2184
+ /** User Agent */
2185
+ userAgent: pgCore.text("user_agent"),
2186
+ /** 来源页面 */
2187
+ referer: pgCore.text("referer"),
2188
+ /** 使用时间 */
2189
+ usedAt: pgCore.timestamp("used_at").defaultNow().notNull(),
2190
+ /** 完成时间(毫秒) */
2191
+ completionTime: pgCore.integer("completion_time"),
2192
+ /** 额外数据 */
2193
+ metadata: pgCore.json("metadata").$type()
2194
+ },
2195
+ (table) => ({
2196
+ /** 配置ID索引 */
2197
+ configIndex: pgCore.index("test_usage_config_idx").on(table.configId),
2198
+ /** 用户ID索引 */
2199
+ userIndex: pgCore.index("test_usage_user_idx").on(table.userId),
2200
+ /** 使用时间索引 */
2201
+ usedAtIndex: pgCore.index("test_usage_used_at_idx").on(table.usedAt),
2202
+ /** 指纹索引 */
2203
+ fingerprintIndex: pgCore.index("test_usage_fingerprint_idx").on(table.fingerprint)
2204
+ })
2205
+ );
2206
+ var testYourselfConfigShares = pgCore.pgTable(
2207
+ "test_yourself_config_shares",
2208
+ {
2209
+ /** 分享ID */
2210
+ id: pgCore.uuid("id").primaryKey().defaultRandom(),
2211
+ /** 分享代码(短链接标识) */
2212
+ shareCode: pgCore.varchar("share_code", { length: 20 }).notNull().unique(),
2213
+ /** 配置ID */
2214
+ configId: pgCore.uuid("config_id").references(() => testYourselfConfigs.id, { onDelete: "cascade" }).notNull(),
2215
+ /** 分享标题 */
2216
+ title: pgCore.varchar("title", { length: 255 }),
2217
+ /** 分享描述 */
2218
+ description: pgCore.text("description"),
2219
+ /** 访问密码 */
2220
+ password: pgCore.varchar("password", { length: 100 }),
2221
+ /** 最大访问次数 */
2222
+ maxAccess: pgCore.integer("max_access"),
2223
+ /** 当前访问次数 */
2224
+ accessCount: pgCore.integer("access_count").notNull().default(0),
2225
+ /** 是否启用 */
2226
+ isActive: pgCore.boolean("is_active").notNull().default(true),
2227
+ /** 过期时间 */
2228
+ expiresAt: pgCore.timestamp("expires_at"),
2229
+ /** 创建者ID */
2230
+ createdBy: pgCore.varchar("created_by", { length: 255 }).notNull(),
2231
+ /** 创建时间 */
2232
+ createdAt: pgCore.timestamp("created_at").defaultNow().notNull(),
2233
+ /** 更新时间 */
2234
+ updatedAt: pgCore.timestamp("updated_at").defaultNow().notNull()
2235
+ },
2236
+ (table) => ({
2237
+ /** 分享代码索引 */
2238
+ shareCodeIndex: pgCore.index("test_shares_share_code_idx").on(table.shareCode),
2239
+ /** 配置ID索引 */
2240
+ configIndex: pgCore.index("test_shares_config_idx").on(table.configId),
2241
+ /** 创建者索引 */
2242
+ createdByIndex: pgCore.index("test_shares_created_by_idx").on(table.createdBy),
2243
+ /** 活跃状态索引 */
2244
+ isActiveIndex: pgCore.index("test_shares_is_active_idx").on(table.isActive)
2245
+ })
2246
+ );
2247
+
2248
+ // src/testYourself/server/DatabaseConfigAdapter.ts
2249
+ var DatabaseConfigAdapter = class {
2250
+ constructor(options) {
2251
+ this.db = options.db;
2252
+ this.userId = options.userId || "system";
2253
+ this.organizationId = options.organizationId;
2254
+ this.softDelete = options.softDelete !== false;
2255
+ }
2256
+ /**
2257
+ * 设置当前用户ID
2258
+ */
2259
+ setUserId(userId) {
2260
+ this.userId = userId;
2261
+ }
2262
+ /**
2263
+ * 设置组织ID
2264
+ */
2265
+ setOrganizationId(organizationId) {
2266
+ this.organizationId = organizationId;
2267
+ }
2268
+ /**
2269
+ * 将数据库记录转换为 SavedConfig
2270
+ */
2271
+ toSavedConfig(dbConfig) {
2272
+ return {
2273
+ id: dbConfig.id,
2274
+ name: dbConfig.name,
2275
+ description: dbConfig.description || void 0,
2276
+ config: dbConfig.config,
2277
+ createdAt: dbConfig.createdAt.getTime(),
2278
+ updatedAt: dbConfig.updatedAt.getTime(),
2279
+ isDefault: dbConfig.isDefault
2280
+ };
2281
+ }
2282
+ /**
2283
+ * 保存配置
2284
+ */
2285
+ async saveConfig(config) {
2286
+ try {
2287
+ const existing = await this.db.select().from(testYourselfConfigs).where(drizzleOrm.eq(testYourselfConfigs.id, config.id)).limit(1);
2288
+ const resultCount = config.config.results?.length || 0;
2289
+ if (existing && existing.length > 0) {
2290
+ await this.db.update(testYourselfConfigs).set({
2291
+ name: config.name,
2292
+ description: config.description || null,
2293
+ config: config.config,
2294
+ resultCount,
2295
+ isDefault: config.isDefault || false,
2296
+ updatedBy: this.userId,
2297
+ updatedAt: /* @__PURE__ */ new Date(),
2298
+ version: drizzleOrm.sql`${testYourselfConfigs.version} + 1`
2299
+ // 版本号递增
2300
+ }).where(drizzleOrm.eq(testYourselfConfigs.id, config.id));
2301
+ console.log("\u2705 [DatabaseAdapter] \u914D\u7F6E\u5DF2\u66F4\u65B0:", config.id);
2302
+ } else {
2303
+ await this.db.insert(testYourselfConfigs).values({
2304
+ id: config.id,
2305
+ name: config.name,
2306
+ description: config.description || null,
2307
+ config: config.config,
2308
+ resultCount,
2309
+ isDefault: config.isDefault || false,
2310
+ createdBy: this.userId,
2311
+ organizationId: this.organizationId,
2312
+ createdAt: new Date(config.createdAt),
2313
+ updatedAt: new Date(config.updatedAt)
2314
+ });
2315
+ console.log("\u2705 [DatabaseAdapter] \u914D\u7F6E\u5DF2\u521B\u5EFA:", config.id);
2316
+ }
2317
+ } catch (error) {
2318
+ console.error("\u274C [DatabaseAdapter] \u4FDD\u5B58\u914D\u7F6E\u5931\u8D25:", error);
2319
+ throw error;
2320
+ }
2321
+ }
2322
+ /**
2323
+ * 获取配置
2324
+ */
2325
+ async getConfig(id) {
2326
+ try {
2327
+ const conditions = [drizzleOrm.eq(testYourselfConfigs.id, id)];
2328
+ if (this.softDelete) {
2329
+ conditions.push(drizzleOrm.eq(testYourselfConfigs.isDeleted, false));
2330
+ }
2331
+ const result = await this.db.select().from(testYourselfConfigs).where(drizzleOrm.and(...conditions)).limit(1);
2332
+ if (!result || result.length === 0) {
2333
+ return null;
2334
+ }
2335
+ return this.toSavedConfig(result[0]);
2336
+ } catch (error) {
2337
+ console.error("\u274C [DatabaseAdapter] \u83B7\u53D6\u914D\u7F6E\u5931\u8D25:", error);
2338
+ throw error;
2339
+ }
2340
+ }
2341
+ /**
2342
+ * 获取所有配置列表
2343
+ */
2344
+ async getAllConfigs() {
2345
+ try {
2346
+ const conditions = [];
2347
+ if (this.softDelete) {
2348
+ conditions.push(drizzleOrm.eq(testYourselfConfigs.isDeleted, false));
2349
+ }
2350
+ if (this.organizationId) {
2351
+ conditions.push(
2352
+ drizzleOrm.or(
2353
+ drizzleOrm.eq(testYourselfConfigs.organizationId, this.organizationId),
2354
+ drizzleOrm.sql`${testYourselfConfigs.organizationId} IS NULL`
2355
+ // 包含全局配置
2356
+ )
2357
+ );
2358
+ }
2359
+ const result = await this.db.select().from(testYourselfConfigs).where(conditions.length > 0 ? drizzleOrm.and(...conditions) : void 0).orderBy(drizzleOrm.desc(testYourselfConfigs.createdAt));
2360
+ return result.map((config) => this.toSavedConfig(config));
2361
+ } catch (error) {
2362
+ console.error("\u274C [DatabaseAdapter] \u83B7\u53D6\u914D\u7F6E\u5217\u8868\u5931\u8D25:", error);
2363
+ throw error;
2364
+ }
2365
+ }
2366
+ /**
2367
+ * 删除配置
2368
+ */
2369
+ async deleteConfig(id) {
2370
+ try {
2371
+ if (this.softDelete) {
2372
+ await this.db.update(testYourselfConfigs).set({
2373
+ isDeleted: true,
2374
+ deletedAt: /* @__PURE__ */ new Date(),
2375
+ updatedBy: this.userId,
2376
+ updatedAt: /* @__PURE__ */ new Date()
2377
+ }).where(drizzleOrm.eq(testYourselfConfigs.id, id));
2378
+ console.log("\u{1F5D1}\uFE0F [DatabaseAdapter] \u914D\u7F6E\u5DF2\u8F6F\u5220\u9664:", id);
2379
+ } else {
2380
+ await this.db.delete(testYourselfConfigs).where(drizzleOrm.eq(testYourselfConfigs.id, id));
2381
+ console.log("\u{1F5D1}\uFE0F [DatabaseAdapter] \u914D\u7F6E\u5DF2\u786C\u5220\u9664:", id);
2382
+ }
2383
+ } catch (error) {
2384
+ console.error("\u274C [DatabaseAdapter] \u5220\u9664\u914D\u7F6E\u5931\u8D25:", error);
2385
+ throw error;
2386
+ }
2387
+ }
2388
+ /**
2389
+ * 更新配置
2390
+ */
2391
+ async updateConfig(id, config) {
2392
+ try {
2393
+ const resultCount = config.config.results?.length || 0;
2394
+ await this.db.update(testYourselfConfigs).set({
2395
+ name: config.name,
2396
+ description: config.description || null,
2397
+ config: config.config,
2398
+ resultCount,
2399
+ isDefault: config.isDefault || false,
2400
+ updatedBy: this.userId,
2401
+ updatedAt: new Date(config.updatedAt),
2402
+ version: drizzleOrm.sql`${testYourselfConfigs.version} + 1`
2403
+ }).where(drizzleOrm.eq(testYourselfConfigs.id, id));
2404
+ console.log("\u2705 [DatabaseAdapter] \u914D\u7F6E\u5DF2\u66F4\u65B0:", id);
2405
+ } catch (error) {
2406
+ console.error("\u274C [DatabaseAdapter] \u66F4\u65B0\u914D\u7F6E\u5931\u8D25:", error);
2407
+ throw error;
2408
+ }
2409
+ }
2410
+ /**
2411
+ * 设置默认配置
2412
+ */
2413
+ async setDefaultConfig(id) {
2414
+ try {
2415
+ await this.db.transaction(async (tx) => {
2416
+ const conditions = [drizzleOrm.eq(testYourselfConfigs.isDefault, true)];
2417
+ if (this.organizationId) {
2418
+ conditions.push(
2419
+ drizzleOrm.eq(testYourselfConfigs.organizationId, this.organizationId)
2420
+ );
2421
+ }
2422
+ await tx.update(testYourselfConfigs).set({
2423
+ isDefault: false,
2424
+ updatedBy: this.userId,
2425
+ updatedAt: /* @__PURE__ */ new Date()
2426
+ }).where(drizzleOrm.and(...conditions));
2427
+ await tx.update(testYourselfConfigs).set({
2428
+ isDefault: true,
2429
+ updatedBy: this.userId,
2430
+ updatedAt: /* @__PURE__ */ new Date()
2431
+ }).where(drizzleOrm.eq(testYourselfConfigs.id, id));
2432
+ });
2433
+ console.log("\u2705 [DatabaseAdapter] \u9ED8\u8BA4\u914D\u7F6E\u5DF2\u8BBE\u7F6E:", id);
2434
+ } catch (error) {
2435
+ console.error("\u274C [DatabaseAdapter] \u8BBE\u7F6E\u9ED8\u8BA4\u914D\u7F6E\u5931\u8D25:", error);
2436
+ throw error;
2437
+ }
2438
+ }
2439
+ /**
2440
+ * 获取默认配置
2441
+ */
2442
+ async getDefaultConfig() {
2443
+ try {
2444
+ const conditions = [drizzleOrm.eq(testYourselfConfigs.isDefault, true)];
2445
+ if (this.softDelete) {
2446
+ conditions.push(drizzleOrm.eq(testYourselfConfigs.isDeleted, false));
2447
+ }
2448
+ if (this.organizationId) {
2449
+ conditions.push(
2450
+ drizzleOrm.eq(testYourselfConfigs.organizationId, this.organizationId)
2451
+ );
2452
+ }
2453
+ const result = await this.db.select().from(testYourselfConfigs).where(drizzleOrm.and(...conditions)).limit(1);
2454
+ if (!result || result.length === 0) {
2455
+ return null;
2456
+ }
2457
+ return this.toSavedConfig(result[0]);
2458
+ } catch (error) {
2459
+ console.error("\u274C [DatabaseAdapter] \u83B7\u53D6\u9ED8\u8BA4\u914D\u7F6E\u5931\u8D25:", error);
2460
+ throw error;
2461
+ }
2462
+ }
2463
+ /**
2464
+ * 恢复已删除的配置(软删除时可用)
2465
+ */
2466
+ async restoreConfig(id) {
2467
+ if (!this.softDelete) {
2468
+ throw new Error("\u6062\u590D\u529F\u80FD\u4EC5\u5728\u542F\u7528\u8F6F\u5220\u9664\u65F6\u53EF\u7528");
2469
+ }
2470
+ try {
2471
+ await this.db.update(testYourselfConfigs).set({
2472
+ isDeleted: false,
2473
+ deletedAt: null,
2474
+ updatedBy: this.userId,
2475
+ updatedAt: /* @__PURE__ */ new Date()
2476
+ }).where(drizzleOrm.eq(testYourselfConfigs.id, id));
2477
+ console.log("\u267B\uFE0F [DatabaseAdapter] \u914D\u7F6E\u5DF2\u6062\u590D:", id);
2478
+ } catch (error) {
2479
+ console.error("\u274C [DatabaseAdapter] \u6062\u590D\u914D\u7F6E\u5931\u8D25:", error);
2480
+ throw error;
2481
+ }
2482
+ }
2483
+ /**
2484
+ * 归档配置
2485
+ */
2486
+ async archiveConfig(id) {
2487
+ try {
2488
+ await this.db.update(testYourselfConfigs).set({
2489
+ isArchived: true,
2490
+ archivedAt: /* @__PURE__ */ new Date(),
2491
+ updatedBy: this.userId,
2492
+ updatedAt: /* @__PURE__ */ new Date()
2493
+ }).where(drizzleOrm.eq(testYourselfConfigs.id, id));
2494
+ console.log("\u{1F4E6} [DatabaseAdapter] \u914D\u7F6E\u5DF2\u5F52\u6863:", id);
2495
+ } catch (error) {
2496
+ console.error("\u274C [DatabaseAdapter] \u5F52\u6863\u914D\u7F6E\u5931\u8D25:", error);
2497
+ throw error;
2498
+ }
2499
+ }
2500
+ /**
2501
+ * 取消归档
2502
+ */
2503
+ async unarchiveConfig(id) {
2504
+ try {
2505
+ await this.db.update(testYourselfConfigs).set({
2506
+ isArchived: false,
2507
+ archivedAt: null,
2508
+ updatedBy: this.userId,
2509
+ updatedAt: /* @__PURE__ */ new Date()
2510
+ }).where(drizzleOrm.eq(testYourselfConfigs.id, id));
2511
+ console.log("\u{1F4C2} [DatabaseAdapter] \u914D\u7F6E\u5DF2\u53D6\u6D88\u5F52\u6863:", id);
2512
+ } catch (error) {
2513
+ console.error("\u274C [DatabaseAdapter] \u53D6\u6D88\u5F52\u6863\u5931\u8D25:", error);
2514
+ throw error;
2515
+ }
2516
+ }
2517
+ /**
2518
+ * 记录使用次数
2519
+ */
2520
+ async incrementUsageCount(id) {
2521
+ try {
2522
+ await this.db.update(testYourselfConfigs).set({
2523
+ usageCount: drizzleOrm.sql`${testYourselfConfigs.usageCount} + 1`,
2524
+ lastUsedAt: /* @__PURE__ */ new Date()
2525
+ }).where(drizzleOrm.eq(testYourselfConfigs.id, id));
2526
+ } catch (error) {
2527
+ console.error("\u274C [DatabaseAdapter] \u66F4\u65B0\u4F7F\u7528\u6B21\u6570\u5931\u8D25:", error);
2528
+ }
2529
+ }
2530
+ };
2531
+ function createDatabaseConfigAdapter(options) {
2532
+ return new DatabaseConfigAdapter(options);
2533
+ }
2534
+
2535
+ exports.ConfigList = ConfigList;
2536
+ exports.ConfigManager = ConfigManager;
2537
+ exports.DEFAULT_RESULTS = DEFAULT_RESULTS;
2538
+ exports.DatabaseConfigAdapter = DatabaseConfigAdapter;
2539
+ exports.TestYourself = TestYourself;
2540
+ exports.createConfigService = createConfigService;
2541
+ exports.createDatabaseConfigAdapter = createDatabaseConfigAdapter;
2542
+ exports.generateDeviceHash = generateDeviceHash;
2543
+ exports.getDefaultConfigService = getDefaultConfigService;
2544
+ exports.getDeviceFingerprint = getDeviceFingerprint;
2545
+ exports.selectResultIndex = selectResultIndex;
2546
+ exports.testYourselfConfigShares = testYourselfConfigShares;
2547
+ exports.testYourselfConfigUsage = testYourselfConfigUsage;
2548
+ exports.testYourselfConfigs = testYourselfConfigs;
2549
+ exports.tryGetIPAddress = tryGetIPAddress;
2550
+ //# sourceMappingURL=index.js.map
2551
+ //# sourceMappingURL=index.js.map