ftdsy-attr 2.1.1 → 2.1.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 (81) hide show
  1. package/dist/ftdsy-attr.cjs.js +17878 -1
  2. package/dist/ftdsy-attr.cjs.js.map +1 -1
  3. package/dist/ftdsy-attr.d.ts +15 -11
  4. package/dist/ftdsy-attr.esm.mjs +17858 -0
  5. package/dist/ftdsy-attr.esm.mjs.map +1 -0
  6. package/package.json +13 -9
  7. package/dist/ftdsy-attr.esm.js +0 -2
  8. package/dist/ftdsy-attr.esm.js.map +0 -1
  9. package/dist/index.html +0 -845
  10. package/dist/types/api/tb/index.d.ts +0 -3
  11. package/dist/types/category/bags/bags_leather.d.ts +0 -16
  12. package/dist/types/category/bags/bags_motion.d.ts +0 -16
  13. package/dist/types/category/clothing/clothing_accessory.d.ts +0 -16
  14. package/dist/types/category/clothing/clothing_children.d.ts +0 -16
  15. package/dist/types/category/clothing/clothing_jewelry.d.ts +0 -16
  16. package/dist/types/category/clothing/clothing_men.d.ts +0 -16
  17. package/dist/types/category/clothing/clothing_motion.d.ts +0 -16
  18. package/dist/types/category/clothing/clothing_underwear.d.ts +0 -16
  19. package/dist/types/category/clothing/clothing_women.d.ts +0 -16
  20. package/dist/types/category/departmentStore/departmentStore_bedding.d.ts +0 -16
  21. package/dist/types/category/departmentStore/departmentStore_commodity.d.ts +0 -17
  22. package/dist/types/category/departmentStore/departmentStore_flower.d.ts +0 -16
  23. package/dist/types/category/departmentStore/departmentStore_holidaysupplies.d.ts +0 -17
  24. package/dist/types/category/departmentStore/departmentStore_homefabric.d.ts +0 -16
  25. package/dist/types/category/departmentStore/departmentStore_petanimal.d.ts +0 -16
  26. package/dist/types/category/departmentStore/departmentStore_storage.d.ts +0 -16
  27. package/dist/types/category/departmentStore/departmentStore_tableware.d.ts +0 -17
  28. package/dist/types/category/index.d.ts +0 -7
  29. package/dist/types/category/motherBaby/motherBaby_bady.d.ts +0 -16
  30. package/dist/types/category/motherBaby/motherBaby_gravida.d.ts +0 -16
  31. package/dist/types/category/numeral/numeral_accessory.d.ts +0 -16
  32. package/dist/types/category/numeral/numeral_camera.d.ts +0 -16
  33. package/dist/types/category/numeral/numeral_computer.d.ts +0 -16
  34. package/dist/types/category/numeral/numeral_game.d.ts +0 -17
  35. package/dist/types/category/numeral/numeral_smart.d.ts +0 -17
  36. package/dist/types/category/shoes/shoes_children.d.ts +0 -16
  37. package/dist/types/category/shoes/shoes_men.d.ts +0 -16
  38. package/dist/types/category/shoes/shoes_motion.d.ts +0 -16
  39. package/dist/types/category/shoes/shoes_women.d.ts +0 -16
  40. package/dist/types/category/sportsOutdoor/sportsOutdoor_outdoors.d.ts +0 -16
  41. package/dist/types/category/sportsOutdoor/sportsOutdoor_sports.d.ts +0 -16
  42. package/dist/types/category/type.d.ts +0 -18
  43. package/dist/types/category/vehicle/vehicle_cycling.d.ts +0 -16
  44. package/dist/types/category/vehicle/vehicle_electricvehicle.d.ts +0 -16
  45. package/dist/types/category/vehicle/vehicle_motorcycle.d.ts +0 -16
  46. package/dist/types/main.d.ts +0 -42
  47. package/dist/types/models/defaultModel.d.ts +0 -16
  48. package/dist/types/models/index.d.ts +0 -4
  49. package/dist/types/models/modal.d.ts +0 -11
  50. package/dist/types/platform/albb.d.ts +0 -6
  51. package/dist/types/platform/albb.type.d.ts +0 -27
  52. package/dist/types/platform/dy.d.ts +0 -3
  53. package/dist/types/platform/dy.type.d.ts +0 -48
  54. package/dist/types/platform/jd.d.ts +0 -3
  55. package/dist/types/platform/jd.type.d.ts +0 -30
  56. package/dist/types/platform/ks.d.ts +0 -3
  57. package/dist/types/platform/ks.type.d.ts +0 -41
  58. package/dist/types/platform/pdd.d.ts +0 -6
  59. package/dist/types/platform/pdd.type.d.ts +0 -28
  60. package/dist/types/platform/shopee.d.ts +0 -6
  61. package/dist/types/platform/shopee.type.d.ts +0 -28
  62. package/dist/types/platform/tb.d.ts +0 -7
  63. package/dist/types/platform/tb.type.d.ts +0 -63
  64. package/dist/types/platform/tiktok.d.ts +0 -6
  65. package/dist/types/platform/tiktok.type.d.ts +0 -1
  66. package/dist/types/platform/tm.d.ts +0 -5
  67. package/dist/types/platform/tm.type.d.ts +0 -1
  68. package/dist/types/platform/wxsph.d.ts +0 -6
  69. package/dist/types/platform/wxsph.type.d.ts +0 -9
  70. package/dist/types/platform/xhs.d.ts +0 -6
  71. package/dist/types/platform/xhs.type.d.ts +0 -16
  72. package/dist/types/property/index.d.ts +0 -10
  73. package/dist/types/property/matchProperty.d.ts +0 -6
  74. package/dist/types/property/perpareProperty.d.ts +0 -9
  75. package/dist/types/property/predictionProperty.d.ts +0 -8
  76. package/dist/types/property/type.d.ts +0 -69
  77. package/dist/types/type.d.ts +0 -67
  78. package/dist/types/utils/axios.d.ts +0 -15
  79. package/dist/types/utils/error.d.ts +0 -12
  80. package/dist/types/utils/is/index.d.ts +0 -23
  81. package/dist/types/utils/utils.d.ts +0 -34
package/dist/index.html DELETED
@@ -1,845 +0,0 @@
1
- <!DOCTYPE html>
2
- <html lang="zh-CN">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>TypeScript 打包模块测试工具</title>
7
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
8
- <style>
9
- * {
10
- box-sizing: border-box;
11
- margin: 0;
12
- padding: 0;
13
- font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
14
- }
15
-
16
- :root {
17
- --primary: #3498db;
18
- --secondary: #2c3e50;
19
- --success: #2ecc71;
20
- --warning: #f39c12;
21
- --danger: #e74c3c;
22
- --light: #ecf0f1;
23
- --dark: #34495e;
24
- --cjs: #9b59b6;
25
- --esm: #e74c3c;
26
- --json-key: #9b59b6;
27
- --json-string: #2ecc71;
28
- --json-number: #e67e22;
29
- --json-boolean: #3498db;
30
- }
31
-
32
- body {
33
- background: linear-gradient(135deg, #1a2a6c, #b21f1f, #1a2a6c);
34
- min-height: 100vh;
35
- padding: 20px;
36
- color: #333;
37
- display: flex;
38
- justify-content: center;
39
- align-items: center;
40
- }
41
-
42
- .container {
43
- width: 100%;
44
- max-width: 1000px;
45
- background: rgba(255, 255, 255, 0.95);
46
- border-radius: 15px;
47
- box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
48
- overflow: hidden;
49
- position: relative;
50
- }
51
-
52
- header {
53
- background: linear-gradient(to right, var(--secondary), var(--primary));
54
- color: white;
55
- padding: 25px 40px;
56
- text-align: center;
57
- position: relative;
58
- }
59
-
60
- h1 {
61
- font-size: 2.5rem;
62
- margin-bottom: 10px;
63
- display: flex;
64
- align-items: center;
65
- justify-content: center;
66
- gap: 15px;
67
- }
68
-
69
- .logo {
70
- font-size: 2rem;
71
- animation: spin 8s linear infinite;
72
- }
73
-
74
- @keyframes spin {
75
- 100% { transform: rotate(360deg); }
76
- }
77
-
78
- .subtitle {
79
- font-size: 1.1rem;
80
- opacity: 0.9;
81
- margin-top: 5px;
82
- }
83
-
84
- .content {
85
- display: grid;
86
- grid-template-columns: 1fr;
87
- gap: 25px;
88
- padding: 30px;
89
- }
90
-
91
- .card {
92
- background: white;
93
- border-radius: 10px;
94
- box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
95
- padding: 25px;
96
- position: relative;
97
- overflow: hidden;
98
- }
99
-
100
- .card-header {
101
- display: flex;
102
- align-items: center;
103
- margin-bottom: 20px;
104
- padding-bottom: 15px;
105
- border-bottom: 2px solid #f0f0f0;
106
- color: var(--secondary);
107
- }
108
-
109
- .card-header i {
110
- font-size: 24px;
111
- margin-right: 10px;
112
- background: var(--primary);
113
- color: white;
114
- width: 40px;
115
- height: 40px;
116
- border-radius: 50%;
117
- display: flex;
118
- align-items: center;
119
- justify-content: center;
120
- }
121
-
122
- .module-selector {
123
- display: flex;
124
- gap: 15px;
125
- margin-bottom: 25px;
126
- }
127
-
128
- .module-btn {
129
- flex: 1;
130
- padding: 15px;
131
- border: none;
132
- border-radius: 8px;
133
- font-size: 16px;
134
- font-weight: 600;
135
- cursor: pointer;
136
- transition: all 0.3s;
137
- display: flex;
138
- align-items: center;
139
- justify-content: center;
140
- gap: 10px;
141
- }
142
-
143
- .module-btn.cjs {
144
- background: var(--cjs);
145
- color: white;
146
- box-shadow: 0 4px 10px rgba(155, 89, 182, 0.3);
147
- }
148
-
149
- .module-btn.esm {
150
- background: var(--esm);
151
- color: white;
152
- box-shadow: 0 4px 10px rgba(231, 76, 60, 0.3);
153
- }
154
-
155
- .module-btn:hover {
156
- transform: translateY(-3px);
157
- box-shadow: 0 6px 15px rgba(0, 0, 0, 0.2);
158
- }
159
-
160
- .module-btn.active {
161
- transform: translateY(-2px);
162
- box-shadow: 0 6px 15px rgba(0, 0, 0, 0.3), 0 0 0 3px rgba(255, 255, 255, 0.7);
163
- }
164
-
165
- .input-group {
166
- margin-bottom: 20px;
167
- }
168
-
169
- label {
170
- display: block;
171
- margin-bottom: 8px;
172
- font-weight: 600;
173
- color: var(--dark);
174
- }
175
-
176
- textarea {
177
- width: 100%;
178
- height: 150px;
179
- padding: 15px;
180
- border: 2px solid #ddd;
181
- border-radius: 8px;
182
- font-family: 'Courier New', monospace;
183
- font-size: 14px;
184
- resize: vertical;
185
- transition: border-color 0.3s;
186
- }
187
-
188
- textarea:focus {
189
- border-color: var(--primary);
190
- outline: none;
191
- box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
192
- }
193
-
194
- .function-selector {
195
- margin-bottom: 25px;
196
- }
197
-
198
- select {
199
- width: 100%;
200
- padding: 12px 15px;
201
- border: 2px solid #ddd;
202
- border-radius: 8px;
203
- font-size: 16px;
204
- background: white;
205
- transition: all 0.3s;
206
- }
207
-
208
- select:focus {
209
- border-color: var(--primary);
210
- outline: none;
211
- box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.2);
212
- }
213
-
214
- .btn-test {
215
- display: block;
216
- width: 100%;
217
- padding: 16px;
218
- background: linear-gradient(to right, var(--success), #27ae60);
219
- color: white;
220
- border: none;
221
- border-radius: 8px;
222
- font-size: 18px;
223
- font-weight: 600;
224
- cursor: pointer;
225
- transition: all 0.3s;
226
- box-shadow: 0 4px 10px rgba(46, 204, 113, 0.3);
227
- margin-top: 20px;
228
- }
229
-
230
- .btn-test:hover {
231
- transform: translateY(-3px);
232
- box-shadow: 0 6px 15px rgba(46, 204, 113, 0.4);
233
- }
234
-
235
- .btn-test:active {
236
- transform: translateY(0);
237
- }
238
-
239
- .result-container {
240
- min-height: 200px;
241
- padding: 20px;
242
- border: 2px solid #ddd;
243
- border-radius: 8px;
244
- background: #f8f9fa;
245
- font-family: 'Courier New', monospace;
246
- font-size: 14px;
247
- white-space: pre-wrap;
248
- overflow-x: auto;
249
- margin-top: 20px;
250
- }
251
-
252
- .result-success {
253
- color: #27ae60;
254
- border-color: var(--success);
255
- background: rgba(46, 204, 113, 0.05);
256
- }
257
-
258
- .result-error {
259
- color: var(--danger);
260
- border-color: var(--danger);
261
- background: rgba(231, 76, 60, 0.05);
262
- }
263
-
264
- .result-info {
265
- color: var(--primary);
266
- border-color: var(--primary);
267
- background: rgba(52, 152, 219, 0.05);
268
- }
269
-
270
- .module-info {
271
- padding: 15px;
272
- background: #f0f7ff;
273
- border-radius: 8px;
274
- border-left: 4px solid var(--primary);
275
- margin-top: 20px;
276
- }
277
-
278
- .info-title {
279
- font-weight: 600;
280
- margin-bottom: 10px;
281
- color: var(--secondary);
282
- }
283
-
284
- .info-content {
285
- font-size: 0.9rem;
286
- line-height: 1.6;
287
- }
288
-
289
- .status-bar {
290
- display: flex;
291
- align-items: center;
292
- gap: 10px;
293
- padding: 10px 15px;
294
- background: #f8f9fa;
295
- border-radius: 8px;
296
- margin-top: 20px;
297
- }
298
-
299
- .status-indicator {
300
- width: 12px;
301
- height: 12px;
302
- border-radius: 50%;
303
- background: #95a5a6;
304
- }
305
-
306
- .status-indicator.active {
307
- background: var(--success);
308
- box-shadow: 0 0 8px rgba(46, 204, 113, 0.6);
309
- }
310
-
311
- footer {
312
- text-align: center;
313
- padding: 20px;
314
- color: #7f8c8d;
315
- font-size: 0.9rem;
316
- background: #f8f9fa;
317
- border-top: 1px solid #eee;
318
- }
319
-
320
- .loader {
321
- display: none;
322
- text-align: center;
323
- margin: 10px 0;
324
- }
325
-
326
- .loader-dot {
327
- display: inline-block;
328
- width: 12px;
329
- height: 12px;
330
- border-radius: 50%;
331
- background: var(--primary);
332
- margin: 0 4px;
333
- animation: bounce 1.5s infinite ease-in-out;
334
- }
335
-
336
- .loader-dot:nth-child(2) {
337
- animation-delay: 0.2s;
338
- }
339
-
340
- .loader-dot:nth-child(3) {
341
- animation-delay: 0.4s;
342
- }
343
-
344
- @keyframes bounce {
345
- 0%, 80%, 100% { transform: scale(0); }
346
- 40% { transform: scale(1); }
347
- }
348
-
349
- .function-info {
350
- margin-top: 15px;
351
- padding: 10px;
352
- background: #f8f9fa;
353
- border-radius: 8px;
354
- font-size: 0.9rem;
355
- }
356
-
357
- .function-info strong {
358
- color: var(--secondary);
359
- }
360
-
361
- .json-key {
362
- color: var(--json-key);
363
- }
364
-
365
- .json-string {
366
- color: var(--json-string);
367
- }
368
-
369
- .json-number {
370
- color: var(--json-number);
371
- }
372
-
373
- .json-boolean {
374
- color: var(--json-boolean);
375
- }
376
-
377
- .json-null {
378
- color: #7f8c8d;
379
- }
380
-
381
- .example-container {
382
- background: #f8f9fa;
383
- border-radius: 8px;
384
- padding: 15px;
385
- margin-top: 15px;
386
- border-left: 3px solid var(--warning);
387
- }
388
-
389
- .example-title {
390
- font-weight: 600;
391
- margin-bottom: 8px;
392
- color: var(--dark);
393
- display: flex;
394
- align-items: center;
395
- gap: 8px;
396
- }
397
-
398
- .example-content {
399
- font-family: 'Courier New', monospace;
400
- font-size: 0.9rem;
401
- white-space: pre;
402
- overflow-x: auto;
403
- }
404
-
405
- .function-tag {
406
- display: inline-block;
407
- padding: 3px 8px;
408
- border-radius: 4px;
409
- font-size: 0.8rem;
410
- font-weight: 600;
411
- margin-right: 8px;
412
- }
413
-
414
- .tag-cjs {
415
- background: var(--cjs);
416
- color: white;
417
- }
418
-
419
- .tag-esm {
420
- background: var(--esm);
421
- color: white;
422
- }
423
-
424
- .tag-common {
425
- background: var(--primary);
426
- color: white;
427
- }
428
- </style>
429
- </head>
430
- <body>
431
- <div class="container">
432
- <header>
433
- <h1><i class="fas fa-code logo"></i> TypeScript 模块测试工具</h1>
434
- <p class="subtitle">测试打包后的 cjs.js 和 esm.js 模块</p>
435
- </header>
436
-
437
- <div class="content">
438
- <div class="card">
439
- <div class="card-header">
440
- <i class="fas fa-plug"></i>
441
- <h2>模块加载</h2>
442
- </div>
443
-
444
- <div class="module-selector">
445
- <button class="module-btn cjs" id="loadCJS">
446
- <i class="fab fa-node-js"></i> 加载 CommonJS 模块 (cjs.js)
447
- </button>
448
- <button class="module-btn esm" id="loadESM">
449
- <i class="fab fa-js"></i> 加载 ES 模块 (esm.js)
450
- </button>
451
- </div>
452
-
453
- <div class="status-bar" id="moduleStatus">
454
- <div class="status-indicator" id="statusIndicator"></div>
455
- <span id="statusText">未加载任何模块</span>
456
- </div>
457
-
458
- <div class="module-info">
459
- <div class="info-title">模块信息</div>
460
- <div class="info-content" id="moduleInfo">
461
- 请选择要加载的模块类型。加载后,模块中的函数将出现在下方选择框中。
462
- </div>
463
- </div>
464
- </div>
465
-
466
- <div class="card">
467
- <div class="card-header">
468
- <i class="fas fa-vial"></i>
469
- <h2>函数测试</h2>
470
- </div>
471
-
472
- <div class="input-group">
473
- <label for="functionSelect">选择要测试的函数:</label>
474
- <select id="functionSelect" disabled>
475
- <option value="">-- 请先加载模块 --</option>
476
- </select>
477
- </div>
478
-
479
- <div class="function-info" id="functionInfo">
480
- 函数信息将在此显示
481
- </div>
482
-
483
- <div class="input-group">
484
- <label for="jsonInput">输入 JSON 参数:</label>
485
- <textarea id="jsonInput" placeholder='输入 JSON 参数,例如:
486
- {
487
- "name": "测试数据",
488
- "value": 42,
489
- "items": ["A", "B", "C"]
490
- }'></textarea>
491
-
492
- <div class="example-container">
493
- <div class="example-title">
494
- <i class="fas fa-lightbulb"></i> 函数使用示例
495
- </div>
496
- <div class="example-content">
497
- // 示例 1: 带单个对象参数的函数
498
- {
499
- "user": {
500
- "name": "张三",
501
- "age": 30,
502
- "isActive": true
503
- }
504
- }
505
-
506
- // 示例 2: 带多个参数的函数
507
- [
508
- "参数1",
509
- 42,
510
- {"key": "value"}
511
- ]
512
-
513
- // 示例 3: 不带参数的函数
514
- null
515
- </div>
516
- </div>
517
- </div>
518
-
519
- <div class="loader" id="loader">
520
- <div class="loader-dot"></div>
521
- <div class="loader-dot"></div>
522
- <div class="loader-dot"></div>
523
- </div>
524
-
525
- <button class="btn-test" id="testBtn" disabled>
526
- <i class="fas fa-play-circle"></i> 执行测试
527
- </button>
528
-
529
- <div class="result-container result-info" id="resultContainer">
530
- 测试结果将显示在这里
531
- </div>
532
- </div>
533
- </div>
534
-
535
- <footer>
536
- <p>© 2023 TypeScript 模块测试工具 | 设计用于测试打包后的 cjs.js 和 esm.js 模块</p>
537
- </footer>
538
- </div>
539
-
540
- <script>
541
- import('ftdsy-attr.cjs.js')
542
-
543
- // 模块加载状态
544
- let currentModule = null;
545
- let moduleFunctions = [];
546
-
547
- // DOM元素
548
- const loadCJS = document.getElementById('loadCJS');
549
- const loadESM = document.getElementById('loadESM');
550
- const functionSelect = document.getElementById('functionSelect');
551
- const jsonInput = document.getElementById('jsonInput');
552
- const testBtn = document.getElementById('testBtn');
553
- const resultContainer = document.getElementById('resultContainer');
554
- const loader = document.getElementById('loader');
555
- const statusIndicator = document.getElementById('statusIndicator');
556
- const statusText = document.getElementById('statusText');
557
- const moduleInfo = document.getElementById('moduleInfo');
558
- const functionInfo = document.getElementById('functionInfo');
559
-
560
- // 加载CommonJS模块
561
- loadCJS.addEventListener('click', async function() {
562
- resetModuleState();
563
- setModuleLoading('正在加载 CommonJS 模块...');
564
-
565
- try {
566
- // 动态加载CommonJS模块
567
- const module = await import('./ftdsy-attr.cjs.js');
568
- currentModule = module;
569
-
570
- // 获取模块中的所有函数
571
- moduleFunctions = Object.entries(module)
572
- .filter(([key, value]) => typeof value === 'function')
573
- .map(([key]) => key);
574
-
575
- if (moduleFunctions.length === 0) {
576
- setModuleError('ftdsy-attr.cjs.js', '模块中没有找到可用的函数');
577
- return;
578
- }
579
-
580
- // 更新UI
581
- updateFunctionSelect(moduleFunctions);
582
- setModuleSuccess('ftdsy-attr.cjs.js', moduleFunctions);
583
- testBtn.disabled = false;
584
- } catch (error) {
585
- setModuleError('ftdsy-attr.cjs.js', error.message);
586
- console.error('加载 cjs.js 失败:', error);
587
- }
588
- });
589
-
590
- // 加载ESM模块
591
- loadESM.addEventListener('click', async function() {
592
- resetModuleState();
593
- setModuleLoading('正在加载 ES 模块...');
594
-
595
- try {
596
- // 动态加载ES模块
597
- const module = await import('./ftdsy-attr.esm.js');
598
- currentModule = module;
599
-
600
- // 获取模块中的所有函数
601
- moduleFunctions = Object.entries(module)
602
- .filter(([key, value]) => typeof value === 'function')
603
- .map(([key]) => key);
604
-
605
- if (moduleFunctions.length === 0) {
606
- setModuleError('ftdsy-attr.esm.js', '模块中没有找到可用的函数');
607
- return;
608
- }
609
-
610
- // 更新UI
611
- updateFunctionSelect(moduleFunctions);
612
- setModuleSuccess('ftdsy-attr.esm.js', moduleFunctions);
613
- testBtn.disabled = false;
614
- } catch (error) {
615
- setModuleError('ftdsy-attr.esm.js', error.message);
616
- console.error('加载 esm.js 失败:', error);
617
- }
618
- });
619
-
620
- // 函数选择变化
621
- functionSelect.addEventListener('change', function() {
622
- const selectedFunction = this.value;
623
- if (!selectedFunction) {
624
- functionInfo.textContent = "请选择一个函数";
625
- return;
626
- }
627
-
628
- if (currentModule && currentModule[selectedFunction]) {
629
- functionInfo.innerHTML = `
630
- <strong>函数名称:</strong> ${selectedFunction}<br>
631
- <strong>函数参数:</strong> ${getFunctionParams(currentModule[selectedFunction])}<br>
632
- <strong>函数长度:</strong> ${currentModule[selectedFunction].length} 个参数
633
- `;
634
- } else {
635
- functionInfo.textContent = "无法获取函数信息";
636
- }
637
- });
638
-
639
- // 执行测试
640
- testBtn.addEventListener('click', function() {
641
- const selectedFunction = functionSelect.value;
642
- if (!selectedFunction) {
643
- showResult("错误:请选择一个函数", "error");
644
- return;
645
- }
646
-
647
- const jsonString = jsonInput.value.trim();
648
- if (!jsonString) {
649
- showResult("错误:请输入JSON参数", "error");
650
- return;
651
- }
652
-
653
- let params;
654
- try {
655
- params = JSON.parse(jsonString);
656
- } catch (error) {
657
- showResult("JSON解析错误: " + error.message, "error");
658
- return;
659
- }
660
-
661
- // 显示加载动画
662
- loader.style.display = 'block';
663
- showResult("执行中...", "info");
664
-
665
- // 模拟执行延迟
666
- setTimeout(() => {
667
-
668
- try {
669
- // 获取选中的函数
670
- const func = currentModule[selectedFunction];
671
-
672
- // 执行函数
673
- let result;
674
- if (Array.isArray(params)) {
675
- // 如果参数是数组,使用展开运算符
676
- result = func(...params);
677
- } else if (typeof params === 'object' && params !== null) {
678
- // 如果参数是对象,尝试作为单个参数传递
679
- result = func(params);
680
- } else {
681
- // 其他情况直接传递
682
- result = func(params);
683
- }
684
-
685
- // 显示结果
686
- showResult(formatResult(result), "success");
687
- } catch (error) {
688
- showResult("执行错误: " + error.message, "error");
689
- } finally {
690
- loader.style.display = 'none';
691
- }
692
- }, 800);
693
- });
694
-
695
- // 辅助函数:重置模块状态
696
- function resetModuleState() {
697
- currentModule = null;
698
- moduleFunctions = [];
699
- functionSelect.innerHTML = '<option value="">-- 请先加载模块 --</option>';
700
- functionSelect.disabled = true;
701
- testBtn.disabled = true;
702
- functionInfo.textContent = "函数信息将在此显示";
703
- showResult("测试结果将显示在这里", "info");
704
- }
705
-
706
- // 辅助函数:设置模块加载状态
707
- function setModuleLoading(message) {
708
- statusIndicator.className = "status-indicator";
709
- statusText.textContent = message;
710
- statusText.style.color = "";
711
- loader.style.display = 'block';
712
- }
713
-
714
- // 辅助函数:设置模块加载成功
715
- function setModuleSuccess(moduleName, functions) {
716
- statusIndicator.className = "status-indicator active";
717
- statusText.textContent = `${moduleName} 加载成功!`;
718
- statusText.style.color = "var(--success)";
719
- loader.style.display = 'none';
720
-
721
- moduleInfo.innerHTML = `
722
- <strong>模块名称:</strong> ${moduleName}<br>
723
- <strong>加载时间:</strong> ${new Date().toLocaleTimeString()}<br>
724
- <strong>可用函数:</strong> ${functions.join(', ')}
725
- `;
726
- }
727
-
728
- // 辅助函数:设置模块加载错误
729
- function setModuleError(moduleName, error) {
730
- statusIndicator.className = "status-indicator";
731
- statusText.textContent = `${moduleName} 加载失败`;
732
- statusText.style.color = "var(--danger)";
733
- loader.style.display = 'none';
734
-
735
- moduleInfo.innerHTML = `
736
- <strong>模块名称:</strong> ${moduleName}<br>
737
- <strong>错误信息:</strong> ${error}<br>
738
- <strong>建议:</strong> 请确保模块文件存在于dist目录中
739
- `;
740
- }
741
-
742
- // 辅助函数:更新函数选择框
743
- function updateFunctionSelect(functions) {
744
- functionSelect.innerHTML = '<option value="">-- 选择函数 --</option>';
745
- functions.forEach(func => {
746
- const option = document.createElement('option');
747
- option.value = func;
748
- option.textContent = func;
749
- functionSelect.appendChild(option);
750
- });
751
- functionSelect.disabled = false;
752
- }
753
-
754
- // 辅助函数:获取函数参数信息
755
- function getFunctionParams(func) {
756
- const funcString = func.toString();
757
- const paramsMatch = funcString.match(/\(([^)]*)\)/);
758
- if (paramsMatch && paramsMatch[1]) {
759
- return paramsMatch[1].split(',').map(p => p.trim()).join(', ');
760
- }
761
- return "无法获取参数信息";
762
- }
763
-
764
- // 辅助函数:格式化结果
765
- function formatResult(result) {
766
- if (result === null) return '<span class="json-null">null</span>';
767
- if (result === undefined) return '<span class="json-null">undefined</span>';
768
-
769
- if (typeof result === 'object') {
770
- try {
771
- return syntaxHighlight(JSON.stringify(result, null, 2));
772
- } catch (e) {
773
- return result.toString();
774
- }
775
- }
776
-
777
- return result.toString();
778
- }
779
-
780
- // 辅助函数:显示结果
781
- function showResult(message, type) {
782
- resultContainer.innerHTML = message;
783
- resultContainer.className = "result-container";
784
-
785
- switch (type) {
786
- case "success":
787
- resultContainer.classList.add("result-success");
788
- break;
789
- case "error":
790
- resultContainer.classList.add("result-error");
791
- break;
792
- case "info":
793
- resultContainer.classList.add("result-info");
794
- break;
795
- }
796
- }
797
-
798
- // 辅助函数:JSON语法高亮
799
- function syntaxHighlight(json) {
800
- if (typeof json != 'string') {
801
- json = JSON.stringify(json, undefined, 2);
802
- }
803
-
804
- json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
805
- return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
806
- let cls = 'json-number';
807
- if (/^"/.test(match)) {
808
- if (/:$/.test(match)) {
809
- cls = 'json-key';
810
- } else {
811
- cls = 'json-string';
812
- }
813
- } else if (/true|false/.test(match)) {
814
- cls = 'json-boolean';
815
- } else if (/null/.test(match)) {
816
- cls = 'json-null';
817
- }
818
- return '<span class="' + cls + '">' + match + '</span>';
819
- });
820
- }
821
-
822
- // 页面加载完成后初始化
823
- document.addEventListener('DOMContentLoaded', function() {
824
- // 设置示例模块函数信息
825
- functionInfo.innerHTML = `
826
- <div class="function-info">
827
- <strong>示例函数信息</strong>
828
- <div class="function-tag tag-common">通用</div>
829
- <div class="function-tag tag-cjs">CJS</div>
830
- <div class="function-tag tag-esm">ESM</div>
831
- <br><br>
832
- <strong>parseData(data: object)</strong><br>
833
- 解析数据对象并添加元数据
834
- <br><br>
835
- <strong>calculateSum(...numbers: number[])</strong><br>
836
- 计算所有数字参数的总和
837
- <br><br>
838
- <strong>formatText(text: string, options?: object)</strong><br>
839
- 格式化文本字符串
840
- </div>
841
- `;
842
- });
843
- </script>
844
- </body>
845
- </html>