@talex-touch/utils 1.0.31 → 1.0.32

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 (112) hide show
  1. package/animation/window-node.ts +15 -12
  2. package/animation/window.ts +19 -15
  3. package/auth/clerk-types.ts +1 -1
  4. package/auth/index.ts +1 -1
  5. package/auth/useAuthState.ts +6 -5
  6. package/auth/useClerkConfig.ts +4 -4
  7. package/auth/useClerkProvider.ts +3 -2
  8. package/channel/index.ts +23 -22
  9. package/common/file-scan-constants.ts +137 -121
  10. package/common/file-scan-utils.ts +48 -27
  11. package/common/index.ts +3 -3
  12. package/common/search/gather.ts +1 -1
  13. package/common/search/index.ts +5 -6
  14. package/common/storage/constants.ts +3 -2
  15. package/common/storage/entity/app-settings.ts +5 -3
  16. package/common/storage/entity/shortcut-settings.ts +10 -10
  17. package/common/storage/shortcut-storage.ts +6 -4
  18. package/common/utils/file.ts +14 -6
  19. package/common/utils/index.ts +62 -52
  20. package/common/utils/polling.ts +87 -84
  21. package/common/utils/task-queue.ts +11 -10
  22. package/common/utils/time.ts +50 -47
  23. package/common/utils/timing.ts +41 -37
  24. package/core-box/builder/index.ts +1 -1
  25. package/core-box/builder/tuff-builder.ts +254 -229
  26. package/core-box/index.ts +3 -6
  27. package/core-box/preview/index.ts +1 -0
  28. package/core-box/preview/types.ts +43 -0
  29. package/core-box/tuff/index.ts +1 -1
  30. package/core-box/tuff/tuff-dsl.ts +328 -266
  31. package/electron/clipboard-helper.ts +20 -12
  32. package/electron/download-manager.ts +43 -42
  33. package/electron/env-tool.ts +19 -18
  34. package/electron/file-parsers/index.ts +2 -2
  35. package/electron/file-parsers/parsers/text-parser.ts +15 -14
  36. package/electron/file-parsers/registry.ts +9 -7
  37. package/electron/file-parsers/types.ts +4 -4
  38. package/electron/index.ts +1 -1
  39. package/eventbus/index.ts +11 -11
  40. package/index.ts +5 -4
  41. package/intelligence/client.ts +87 -0
  42. package/intelligence/index.ts +1 -0
  43. package/package.json +14 -14
  44. package/permission/index.ts +8 -8
  45. package/plugin/channel.ts +77 -68
  46. package/plugin/index.ts +96 -82
  47. package/plugin/install.ts +8 -8
  48. package/plugin/log/types.ts +5 -5
  49. package/plugin/node/index.ts +1 -1
  50. package/plugin/node/logger-manager.ts +14 -11
  51. package/plugin/node/logger.ts +8 -8
  52. package/plugin/plugin-source.ts +11 -11
  53. package/plugin/preload.ts +1 -1
  54. package/plugin/providers/registry.ts +8 -7
  55. package/plugin/providers/types.ts +6 -6
  56. package/plugin/sdk/channel.ts +20 -20
  57. package/plugin/sdk/clipboard.ts +8 -6
  58. package/plugin/sdk/common.ts +10 -6
  59. package/plugin/sdk/core-box.ts +2 -3
  60. package/plugin/sdk/division-box.ts +266 -0
  61. package/plugin/sdk/enum/bridge-event.ts +1 -1
  62. package/plugin/sdk/examples/storage-onDidChange-example.js +1 -1
  63. package/plugin/sdk/features.ts +34 -26
  64. package/plugin/sdk/hooks/bridge.ts +3 -6
  65. package/plugin/sdk/hooks/index.ts +1 -1
  66. package/plugin/sdk/hooks/life-cycle.ts +4 -10
  67. package/plugin/sdk/index.ts +8 -7
  68. package/plugin/sdk/service/index.ts +3 -3
  69. package/plugin/sdk/storage.ts +4 -4
  70. package/plugin/sdk/system.ts +1 -1
  71. package/plugin/sdk/types.ts +147 -141
  72. package/plugin/sdk/window/index.ts +8 -5
  73. package/preload/loading.ts +6 -6
  74. package/preload/renderer.ts +4 -2
  75. package/renderer/hooks/arg-mapper.ts +1 -2
  76. package/renderer/hooks/index.ts +2 -0
  77. package/renderer/hooks/initialize.ts +10 -8
  78. package/renderer/hooks/performance.ts +4 -4
  79. package/renderer/hooks/use-channel.ts +150 -0
  80. package/renderer/hooks/use-intelligence.ts +236 -0
  81. package/renderer/index.ts +6 -2
  82. package/renderer/ref.ts +32 -36
  83. package/renderer/slots.ts +29 -26
  84. package/renderer/storage/app-settings.ts +16 -6
  85. package/renderer/storage/base-storage.ts +222 -114
  86. package/renderer/storage/index.ts +3 -0
  87. package/renderer/storage/intelligence-storage.ts +215 -0
  88. package/renderer/storage/openers.ts +13 -3
  89. package/renderer/touch-sdk/env.ts +41 -41
  90. package/renderer/touch-sdk/index.ts +1 -1
  91. package/renderer/touch-sdk/terminal.ts +5 -5
  92. package/renderer/touch-sdk/utils.ts +4 -3
  93. package/search/levenshtein-utils.ts +11 -11
  94. package/search/types.ts +102 -102
  95. package/service/index.ts +11 -11
  96. package/service/protocol/index.ts +217 -14
  97. package/types/division-box.ts +248 -0
  98. package/types/download.ts +72 -34
  99. package/types/index.ts +3 -1
  100. package/types/intelligence.ts +413 -0
  101. package/types/modules/base.ts +16 -16
  102. package/types/modules/index.ts +1 -1
  103. package/types/modules/module-lifecycle.ts +21 -21
  104. package/types/modules/module-manager.ts +11 -11
  105. package/types/modules/module.ts +16 -16
  106. package/types/storage.ts +0 -1
  107. package/types/touch-app-core.ts +32 -32
  108. package/types/update.ts +79 -21
  109. package/core-box/README.md +0 -218
  110. package/core-box/builder/tuff-builder.example.ts.bak +0 -258
  111. package/core-box/run-tests.sh +0 -7
  112. package/core-box/search.ts +0 -1
@@ -17,27 +17,27 @@
17
17
  */
18
18
 
19
19
  import type {
20
- TuffItem,
21
- TuffSource,
22
- TuffSourceType,
23
- TuffItemKind,
24
- TuffRender,
25
- TuffRenderMode,
20
+ IProviderActivate,
21
+ TuffAction,
22
+ TuffActionType,
26
23
  TuffBasicRender,
24
+ TuffContext,
27
25
  TuffCustomRender,
28
26
  TuffIcon,
29
- TuffTag,
27
+ TuffItem,
28
+ TuffItemKind,
30
29
  TuffLayout,
31
- TuffPreview,
32
- TuffAction,
33
- TuffActionType,
34
- TuffScoring,
35
- TuffContext,
36
30
  TuffMeta,
37
31
  TuffPermissionLevel,
38
- TuffSearchResult,
32
+ TuffPreview,
39
33
  TuffQuery,
40
- IProviderActivate
34
+ TuffRender,
35
+ TuffRenderMode,
36
+ TuffScoring,
37
+ TuffSearchResult,
38
+ TuffSource,
39
+ TuffSourceType,
40
+ TuffTag,
41
41
  } from '../tuff/tuff-dsl'
42
42
 
43
43
  // ==================== Builder 类 ====================
@@ -60,15 +60,15 @@ import type {
60
60
  * ```
61
61
  */
62
62
  class TuffItemBuilder {
63
- private item: Partial<TuffItem> = {};
64
- private basicRender: Partial<TuffBasicRender> = {};
65
- private customRender: Partial<TuffCustomRender> | null = null;
66
- private renderMode: TuffRenderMode = 'default';
67
- private layout: Partial<TuffLayout> | null = null;
68
- private preview: Partial<TuffPreview> | null = null;
69
- private renderStyle: Record<string, string> | null = null;
70
- private renderClassName: string | null = null;
71
- private scoring: Partial<TuffScoring> = {};
63
+ private item: Partial<TuffItem> = {}
64
+ private basicRender: Partial<TuffBasicRender> = {}
65
+ private customRender: Partial<TuffCustomRender> | null = null
66
+ private renderMode: TuffRenderMode = 'default'
67
+ private layout: Partial<TuffLayout> | null = null
68
+ private preview: Partial<TuffPreview> | null = null
69
+ private renderStyle: Record<string, string> | null = null
70
+ private renderClassName: string | null = null
71
+ private scoring: Partial<TuffScoring> = {}
72
72
 
73
73
  /**
74
74
  * 创建一个新的 TuffItemBuilder 实例
@@ -82,8 +82,8 @@ class TuffItemBuilder {
82
82
  if (sourceType && sourceId) {
83
83
  this.item.source = {
84
84
  type: sourceType,
85
- id: sourceId
86
- };
85
+ id: sourceId,
86
+ }
87
87
  }
88
88
  }
89
89
 
@@ -94,8 +94,8 @@ class TuffItemBuilder {
94
94
  * @returns 当前构建器实例,用于链式调用
95
95
  */
96
96
  setId(id: string): TuffItemBuilder {
97
- this.item.id = id;
98
- return this;
97
+ this.item.id = id
98
+ return this
99
99
  }
100
100
 
101
101
  /**
@@ -113,15 +113,18 @@ class TuffItemBuilder {
113
113
  id: string,
114
114
  name?: string,
115
115
  version?: string,
116
- permission?: TuffPermissionLevel
116
+ permission?: TuffPermissionLevel,
117
117
  ): TuffItemBuilder {
118
- this.item.source = { type, id };
118
+ this.item.source = { type, id }
119
119
 
120
- if (name) this.item.source.name = name;
121
- if (version) this.item.source.version = version;
122
- if (permission) this.item.source.permission = permission;
120
+ if (name)
121
+ this.item.source.name = name
122
+ if (version)
123
+ this.item.source.version = version
124
+ if (permission)
125
+ this.item.source.permission = permission
123
126
 
124
- return this;
127
+ return this
125
128
  }
126
129
 
127
130
  /**
@@ -131,8 +134,8 @@ class TuffItemBuilder {
131
134
  * @returns 当前构建器实例,用于链式调用
132
135
  */
133
136
  setKind(kind: TuffItemKind): TuffItemBuilder {
134
- this.item.kind = kind;
135
- return this;
137
+ this.item.kind = kind
138
+ return this
136
139
  }
137
140
 
138
141
  /**
@@ -142,8 +145,8 @@ class TuffItemBuilder {
142
145
  * @returns 当前构建器实例,用于链式调用
143
146
  */
144
147
  setTitle(title: string): TuffItemBuilder {
145
- this.basicRender.title = title;
146
- return this;
148
+ this.basicRender.title = title
149
+ return this
147
150
  }
148
151
 
149
152
  /**
@@ -153,8 +156,8 @@ class TuffItemBuilder {
153
156
  * @returns 当前构建器实例,用于链式调用
154
157
  */
155
158
  setSubtitle(subtitle: string): this {
156
- this.basicRender.subtitle = subtitle;
157
- return this;
159
+ this.basicRender.subtitle = subtitle
160
+ return this
158
161
  }
159
162
 
160
163
  /**
@@ -164,8 +167,8 @@ class TuffItemBuilder {
164
167
  * @returns 当前构建器实例,用于链式调用
165
168
  */
166
169
  setDescription(description: string): this {
167
- this.basicRender.description = description;
168
- return this;
170
+ this.basicRender.description = description
171
+ return this
169
172
  }
170
173
 
171
174
  /**
@@ -175,8 +178,8 @@ class TuffItemBuilder {
175
178
  * @returns 当前构建器实例,用于链式调用
176
179
  */
177
180
  setIcon(icon: TuffIcon): this {
178
- this.basicRender.icon = icon;
179
- return this;
181
+ this.basicRender.icon = icon
182
+ return this
180
183
  }
181
184
 
182
185
  /**
@@ -187,10 +190,10 @@ class TuffItemBuilder {
187
190
  */
188
191
  addTag(tag: TuffTag): this {
189
192
  if (!this.basicRender.tags) {
190
- this.basicRender.tags = [];
193
+ this.basicRender.tags = []
191
194
  }
192
- this.basicRender.tags.push(tag);
193
- return this;
195
+ this.basicRender.tags.push(tag)
196
+ return this
194
197
  }
195
198
 
196
199
  /**
@@ -200,8 +203,8 @@ class TuffItemBuilder {
200
203
  * @returns 当前构建器实例,用于链式调用
201
204
  */
202
205
  setTags(tags: TuffTag[]): this {
203
- this.basicRender.tags = tags;
204
- return this;
206
+ this.basicRender.tags = tags
207
+ return this
205
208
  }
206
209
 
207
210
  /**
@@ -211,8 +214,8 @@ class TuffItemBuilder {
211
214
  * @returns 当前构建器实例,用于链式调用
212
215
  */
213
216
  setAccessory(accessory: string): this {
214
- this.basicRender.accessory = accessory;
215
- return this;
217
+ this.basicRender.accessory = accessory
218
+ return this
216
219
  }
217
220
 
218
221
  /**
@@ -222,8 +225,8 @@ class TuffItemBuilder {
222
225
  * @returns 当前构建器实例,用于链式调用
223
226
  */
224
227
  setRenderMode(mode: TuffRenderMode): this {
225
- this.renderMode = mode;
226
- return this;
228
+ this.renderMode = mode
229
+ return this
227
230
  }
228
231
 
229
232
  /**
@@ -241,16 +244,19 @@ class TuffItemBuilder {
241
244
  content: string,
242
245
  data?: Record<string, any>,
243
246
  styles?: string[],
244
- scripts?: string[]
247
+ scripts?: string[],
245
248
  ): this {
246
- this.renderMode = 'custom';
247
- this.customRender = { type, content };
249
+ this.renderMode = 'custom'
250
+ this.customRender = { type, content }
248
251
 
249
- if (data) this.customRender.data = data;
250
- if (styles) this.customRender.styles = styles;
251
- if (scripts) this.customRender.scripts = scripts;
252
+ if (data)
253
+ this.customRender.data = data
254
+ if (styles)
255
+ this.customRender.styles = styles
256
+ if (scripts)
257
+ this.customRender.scripts = scripts
252
258
 
253
- return this;
259
+ return this
254
260
  }
255
261
 
256
262
  /**
@@ -264,14 +270,16 @@ class TuffItemBuilder {
264
270
  setLayout(
265
271
  display: 'list' | 'card' | 'grid' | 'compact' | 'detailed',
266
272
  size?: 'small' | 'medium' | 'large',
267
- align?: 'left' | 'center' | 'right'
273
+ align?: 'left' | 'center' | 'right',
268
274
  ): this {
269
- this.layout = { display };
275
+ this.layout = { display }
270
276
 
271
- if (size) this.layout.size = size;
272
- if (align) this.layout.align = align;
277
+ if (size)
278
+ this.layout.size = size
279
+ if (align)
280
+ this.layout.align = align
273
281
 
274
- return this;
282
+ return this
275
283
  }
276
284
 
277
285
  /**
@@ -283,19 +291,21 @@ class TuffItemBuilder {
283
291
  */
284
292
  setGridLayout(columns: number, gap?: number): this {
285
293
  if (!this.layout) {
286
- this.layout = { display: 'grid' };
287
- } else {
288
- this.layout.display = 'grid';
294
+ this.layout = { display: 'grid' }
295
+ }
296
+ else {
297
+ this.layout.display = 'grid'
289
298
  }
290
299
 
291
300
  if (!this.layout.grid) {
292
- this.layout.grid = {};
301
+ this.layout.grid = {}
293
302
  }
294
303
 
295
- this.layout.grid.columns = columns;
296
- if (gap !== undefined) this.layout.grid.gap = gap;
304
+ this.layout.grid.columns = columns
305
+ if (gap !== undefined)
306
+ this.layout.grid.gap = gap
297
307
 
298
- return this;
308
+ return this
299
309
  }
300
310
 
301
311
  /**
@@ -313,16 +323,20 @@ class TuffItemBuilder {
313
323
  title?: string,
314
324
  content?: string,
315
325
  image?: string,
316
- lazy?: boolean
326
+ lazy?: boolean,
317
327
  ): this {
318
- this.preview = { type };
328
+ this.preview = { type }
319
329
 
320
- if (title) this.preview.title = title;
321
- if (content) this.preview.content = content;
322
- if (image) this.preview.image = image;
323
- if (lazy !== undefined) this.preview.lazy = lazy;
330
+ if (title)
331
+ this.preview.title = title
332
+ if (content)
333
+ this.preview.content = content
334
+ if (image)
335
+ this.preview.image = image
336
+ if (lazy !== undefined)
337
+ this.preview.lazy = lazy
324
338
 
325
- return this;
339
+ return this
326
340
  }
327
341
 
328
342
  /**
@@ -333,11 +347,11 @@ class TuffItemBuilder {
333
347
  */
334
348
  setPreviewComponent(customRender: TuffCustomRender): this {
335
349
  if (!this.preview) {
336
- this.preview = { type: 'panel' };
350
+ this.preview = { type: 'panel' }
337
351
  }
338
352
 
339
- this.preview.component = customRender;
340
- return this;
353
+ this.preview.component = customRender
354
+ return this
341
355
  }
342
356
 
343
357
  /**
@@ -347,8 +361,8 @@ class TuffItemBuilder {
347
361
  * @returns 当前构建器实例,用于链式调用
348
362
  */
349
363
  setClassName(className: string): this {
350
- this.renderClassName = className;
351
- return this;
364
+ this.renderClassName = className
365
+ return this
352
366
  }
353
367
 
354
368
  /**
@@ -358,8 +372,8 @@ class TuffItemBuilder {
358
372
  * @returns 当前构建器实例,用于链式调用
359
373
  */
360
374
  setStyle(style: Record<string, string>): this {
361
- this.renderStyle = style;
362
- return this;
375
+ this.renderStyle = style
376
+ return this
363
377
  }
364
378
 
365
379
  /**
@@ -370,10 +384,10 @@ class TuffItemBuilder {
370
384
  */
371
385
  addAction(action: TuffAction): this {
372
386
  if (!this.item.actions) {
373
- this.item.actions = [];
387
+ this.item.actions = []
374
388
  }
375
- this.item.actions.push(action);
376
- return this;
389
+ this.item.actions.push(action)
390
+ return this
377
391
  }
378
392
 
379
393
  /**
@@ -383,8 +397,8 @@ class TuffItemBuilder {
383
397
  * @returns 当前构建器实例,用于链式调用
384
398
  */
385
399
  setActions(actions: TuffAction[]): this {
386
- this.item.actions = actions;
387
- return this;
400
+ this.item.actions = actions
401
+ return this
388
402
  }
389
403
 
390
404
  /**
@@ -403,19 +417,19 @@ class TuffItemBuilder {
403
417
  id: string,
404
418
  type: TuffActionType,
405
419
  label: string,
406
- payload?: any
420
+ payload?: any,
407
421
  ): this {
408
- const isFirstAction = !this.item.actions || this.item.actions.length === 0;
422
+ const isFirstAction = !this.item.actions || this.item.actions.length === 0
409
423
 
410
424
  const action = TuffUtils.createAction(
411
425
  id,
412
426
  type,
413
427
  label,
414
428
  isFirstAction, // Set primary to true if it's the first action
415
- payload
416
- );
429
+ payload,
430
+ )
417
431
 
418
- return this.addAction(action);
432
+ return this.addAction(action)
419
433
  }
420
434
 
421
435
  /**
@@ -425,8 +439,8 @@ class TuffItemBuilder {
425
439
  * @returns 当前构建器实例,用于链式调用
426
440
  */
427
441
  setScoring(scoring: TuffScoring): this {
428
- this.item.scoring = scoring;
429
- return this;
442
+ this.item.scoring = scoring
443
+ return this
430
444
  }
431
445
 
432
446
  /**
@@ -437,10 +451,10 @@ class TuffItemBuilder {
437
451
  */
438
452
  setFinalScore(score: number): this {
439
453
  if (score < 0 || score > 1) {
440
- throw new Error('Score must be between 0 and 1');
454
+ throw new Error('Score must be between 0 and 1')
441
455
  }
442
- this.scoring.final = score;
443
- return this;
456
+ this.scoring.final = score
457
+ return this
444
458
  }
445
459
 
446
460
  /**
@@ -450,8 +464,8 @@ class TuffItemBuilder {
450
464
  * @returns 当前构建器实例,用于链式调用
451
465
  */
452
466
  setContext(context: TuffContext): this {
453
- this.item.context = context;
454
- return this;
467
+ this.item.context = context
468
+ return this
455
469
  }
456
470
 
457
471
  /**
@@ -461,8 +475,8 @@ class TuffItemBuilder {
461
475
  * @returns 当前构建器实例,用于链式调用
462
476
  */
463
477
  setMeta(meta: TuffMeta): this {
464
- this.item.meta = { ...this.item.meta, ...meta };
465
- return this;
478
+ this.item.meta = { ...this.item.meta, ...meta }
479
+ return this
466
480
  }
467
481
 
468
482
  /**
@@ -475,48 +489,53 @@ class TuffItemBuilder {
475
489
  // 检查并自动生成 ID
476
490
  if (!this.item.id) {
477
491
  // this.item.id = TuffUtils.generateId();
478
- throw new Error('TuffItem 必须设置 id 属性');
492
+ throw new Error('TuffItem 必须设置 id 属性')
479
493
  }
480
494
 
481
495
  // 检查必要属性
482
496
  if (!this.item.source) {
483
- throw new Error('TuffItem 必须设置 source 属性');
497
+ throw new Error('TuffItem 必须设置 source 属性')
484
498
  }
485
499
 
486
500
  // 构建渲染配置
487
501
  const render: TuffRender = {
488
- mode: this.renderMode
489
- };
502
+ mode: this.renderMode,
503
+ }
490
504
 
491
505
  // 根据渲染模式设置相应的渲染配置
492
506
  if (this.renderMode === 'default' || this.renderMode === 'rich' || this.renderMode === 'card') {
493
507
  if (!this.basicRender.title) {
494
- throw new Error('默认渲染模式下 TuffItem 必须设置 title 属性');
508
+ throw new Error('默认渲染模式下 TuffItem 必须设置 title 属性')
495
509
  }
496
- render.basic = this.basicRender as TuffBasicRender;
497
- } else if (this.renderMode === 'custom') {
510
+ render.basic = this.basicRender as TuffBasicRender
511
+ }
512
+ else if (this.renderMode === 'custom') {
498
513
  if (!this.customRender) {
499
- throw new Error('自定义渲染模式下必须设置 customRender 属性');
514
+ throw new Error('自定义渲染模式下必须设置 customRender 属性')
500
515
  }
501
- render.custom = this.customRender as TuffCustomRender;
516
+ render.custom = this.customRender as TuffCustomRender
502
517
  }
503
518
 
504
519
  // 设置其他渲染属性
505
- if (this.layout) render.layout = this.layout as TuffLayout;
506
- if (this.preview) render.preview = this.preview as TuffPreview;
507
- if (this.renderClassName) render.className = this.renderClassName;
508
- if (this.renderStyle) render.style = this.renderStyle;
520
+ if (this.layout)
521
+ render.layout = this.layout as TuffLayout
522
+ if (this.preview)
523
+ render.preview = this.preview as TuffPreview
524
+ if (this.renderClassName)
525
+ render.className = this.renderClassName
526
+ if (this.renderStyle)
527
+ render.style = this.renderStyle
509
528
 
510
529
  // 设置渲染配置
511
- this.item.render = render;
530
+ this.item.render = render
512
531
 
513
532
  // 设置评分信息
514
533
  if (Object.keys(this.scoring).length > 0) {
515
- this.item.scoring = this.scoring as TuffScoring;
534
+ this.item.scoring = this.scoring as TuffScoring
516
535
  }
517
536
 
518
537
  // 返回完整的 TuffItem
519
- return this.item as TuffItem;
538
+ return this.item as TuffItem
520
539
  }
521
540
  }
522
541
 
@@ -526,7 +545,7 @@ class TuffItemBuilder {
526
545
  * A fluent builder for creating TuffSearchResult objects.
527
546
  */
528
547
  class TuffSearchResultBuilder {
529
- private readonly result: TuffSearchResult;
548
+ private readonly result: TuffSearchResult
530
549
 
531
550
  constructor(query: TuffQuery) {
532
551
  this.result = {
@@ -534,42 +553,41 @@ class TuffSearchResultBuilder {
534
553
  items: [],
535
554
  duration: 0,
536
555
  sources: [],
537
- activate: []
538
- };
556
+ activate: [],
557
+ }
539
558
  }
540
559
 
541
560
  public setItems(items: TuffItem[]): this {
542
- this.result.items = items;
543
- return this;
561
+ this.result.items = items
562
+ return this
544
563
  }
545
564
 
546
565
  public setDuration(duration: number): this {
547
- this.result.duration = duration;
548
- return this;
566
+ this.result.duration = duration
567
+ return this
549
568
  }
550
569
 
551
570
  public setActivate(activate: IProviderActivate[]): this {
552
- this.result.activate = activate;
553
- return this;
571
+ this.result.activate = activate
572
+ return this
554
573
  }
555
574
 
556
575
  public setSources(sources: TuffSearchResult['sources']): this {
557
- this.result.sources = sources;
558
- return this;
576
+ this.result.sources = sources
577
+ return this
559
578
  }
560
579
 
561
580
  public setSortStats(stats: any[]): this {
562
581
  // @ts-ignore
563
- this.result.sort_stats = stats;
564
- return this;
582
+ this.result.sort_stats = stats
583
+ return this
565
584
  }
566
585
 
567
586
  public build(): TuffSearchResult {
568
- return this.result;
587
+ return this.result
569
588
  }
570
589
  }
571
590
 
572
-
573
591
  // ==================== 工厂方法 ====================
574
592
 
575
593
  /**
@@ -589,15 +607,16 @@ class TuffFactory {
589
607
  title: string,
590
608
  sourceType: TuffSourceType,
591
609
  sourceId: string,
592
- kind?: TuffItemKind
610
+ kind?: TuffItemKind,
593
611
  ): TuffItem {
594
612
  const builder = new TuffItemBuilder(TuffUtils.generateId())
595
613
  .setSource(sourceType, sourceId)
596
614
  .setTitle(title)
597
615
 
598
- if (kind) builder.setKind(kind);
616
+ if (kind)
617
+ builder.setKind(kind)
599
618
 
600
- return builder.build();
619
+ return builder.build()
601
620
  }
602
621
 
603
622
  /**
@@ -611,9 +630,9 @@ class TuffFactory {
611
630
  static createSystemItem(
612
631
  title: string,
613
632
  id: string,
614
- kind?: TuffItemKind
633
+ kind?: TuffItemKind,
615
634
  ): TuffItem {
616
- return TuffFactory.createBasicItem(title, 'system', id, kind);
635
+ return TuffFactory.createBasicItem(title, 'system', id, kind)
617
636
  }
618
637
 
619
638
  /**
@@ -627,9 +646,9 @@ class TuffFactory {
627
646
  static createPluginItem(
628
647
  title: string,
629
648
  pluginId: string,
630
- kind?: TuffItemKind
649
+ kind?: TuffItemKind,
631
650
  ): TuffItem {
632
- return TuffFactory.createBasicItem(title, 'plugin', pluginId, kind);
651
+ return TuffFactory.createBasicItem(title, 'plugin', pluginId, kind)
633
652
  }
634
653
 
635
654
  /**
@@ -643,9 +662,9 @@ class TuffFactory {
643
662
  static createAIItem(
644
663
  title: string,
645
664
  aiSourceId: string,
646
- kind?: TuffItemKind
665
+ kind?: TuffItemKind,
647
666
  ): TuffItem {
648
- return TuffFactory.createBasicItem(title, 'ai', aiSourceId, kind);
667
+ return TuffFactory.createBasicItem(title, 'ai', aiSourceId, kind)
649
668
  }
650
669
 
651
670
  /**
@@ -661,7 +680,7 @@ class TuffFactory {
661
680
  title: string,
662
681
  path: string,
663
682
  sourceType: TuffSourceType,
664
- sourceId: string
683
+ sourceId: string,
665
684
  ): TuffItem {
666
685
  return new TuffItemBuilder(TuffUtils.generateId())
667
686
  .setSource(sourceType, sourceId)
@@ -669,11 +688,11 @@ class TuffFactory {
669
688
  .setKind('file')
670
689
  .setMeta({
671
690
  file: {
672
- path: path
673
- }
691
+ path,
692
+ },
674
693
  })
675
694
  .createAndAddAction('open', 'open', '打开')
676
- .build();
695
+ .build()
677
696
  }
678
697
 
679
698
  /**
@@ -689,7 +708,7 @@ class TuffFactory {
689
708
  title: string,
690
709
  path: string,
691
710
  sourceType: TuffSourceType,
692
- sourceId: string
711
+ sourceId: string,
693
712
  ): TuffItem {
694
713
  return new TuffItemBuilder(TuffUtils.generateId())
695
714
  .setSource(sourceType, sourceId)
@@ -697,11 +716,11 @@ class TuffFactory {
697
716
  .setKind('folder')
698
717
  .setMeta({
699
718
  file: {
700
- path: path
701
- }
719
+ path,
720
+ },
702
721
  })
703
722
  .createAndAddAction('open', 'open', '打开')
704
- .build();
723
+ .build()
705
724
  }
706
725
 
707
726
  /**
@@ -717,7 +736,7 @@ class TuffFactory {
717
736
  title: string,
718
737
  url: string,
719
738
  sourceType: TuffSourceType,
720
- sourceId: string
739
+ sourceId: string,
721
740
  ): TuffItem {
722
741
  return new TuffItemBuilder(TuffUtils.generateId())
723
742
  .setSource(sourceType, sourceId)
@@ -725,11 +744,11 @@ class TuffFactory {
725
744
  .setKind('url')
726
745
  .setMeta({
727
746
  web: {
728
- url: url
729
- }
747
+ url,
748
+ },
730
749
  })
731
750
  .createAndAddAction('open', 'open', '打开')
732
- .build();
751
+ .build()
733
752
  }
734
753
 
735
754
  /**
@@ -747,7 +766,7 @@ class TuffFactory {
747
766
  path: string,
748
767
  bundleId: string,
749
768
  sourceType: TuffSourceType,
750
- sourceId: string
769
+ sourceId: string,
751
770
  ): TuffItem {
752
771
  return new TuffItemBuilder(TuffUtils.generateId())
753
772
  .setSource(sourceType, sourceId)
@@ -755,12 +774,12 @@ class TuffFactory {
755
774
  .setKind('app')
756
775
  .setMeta({
757
776
  app: {
758
- path: path,
759
- bundle_id: bundleId
760
- }
777
+ path,
778
+ bundle_id: bundleId,
779
+ },
761
780
  })
762
781
  .createAndAddAction('execute', 'execute', '启动')
763
- .build();
782
+ .build()
764
783
  }
765
784
 
766
785
  /**
@@ -776,14 +795,14 @@ class TuffFactory {
776
795
  title: string,
777
796
  command: string,
778
797
  sourceType: TuffSourceType,
779
- sourceId: string
798
+ sourceId: string,
780
799
  ): TuffItem {
781
800
  return new TuffItemBuilder(TuffUtils.generateId())
782
801
  .setSource(sourceType, sourceId)
783
802
  .setTitle(title)
784
803
  .setKind('command')
785
804
  .createAndAddAction('execute', 'execute', '执行', { command })
786
- .build();
805
+ .build()
787
806
  }
788
807
 
789
808
  /**
@@ -799,18 +818,18 @@ class TuffFactory {
799
818
  title: string,
800
819
  action: TuffAction,
801
820
  sourceType: TuffSourceType,
802
- sourceId: string
821
+ sourceId: string,
803
822
  ): TuffItem {
804
823
  return new TuffItemBuilder(TuffUtils.generateId())
805
824
  .setSource(sourceType, sourceId)
806
825
  .setTitle(title)
807
826
  .setKind('action')
808
827
  .addAction(action)
809
- .build();
828
+ .build()
810
829
  }
811
830
 
812
831
  public static createSearchResult(query: TuffQuery): TuffSearchResultBuilder {
813
- return new TuffSearchResultBuilder(query);
832
+ return new TuffSearchResultBuilder(query)
814
833
  }
815
834
  }
816
835
 
@@ -838,10 +857,10 @@ class TuffFactory {
838
857
  * ```
839
858
  */
840
859
  class TuffListBuilder {
841
- private items: TuffItem[] = [];
842
- private sharedSource: TuffSource;
843
- private sharedKind?: TuffItemKind;
844
- private sharedActions: TuffAction[] = [];
860
+ private items: TuffItem[] = []
861
+ private sharedSource: TuffSource
862
+ private sharedKind?: TuffItemKind
863
+ private sharedActions: TuffAction[] = []
845
864
 
846
865
  /**
847
866
  * 创建一个新的列表构建器
@@ -850,7 +869,7 @@ class TuffListBuilder {
850
869
  * @param sourceId - 共享的来源标识符
851
870
  */
852
871
  constructor(sourceType: TuffSourceType, sourceId: string) {
853
- this.sharedSource = { type: sourceType, id: sourceId };
872
+ this.sharedSource = { type: sourceType, id: sourceId }
854
873
  }
855
874
 
856
875
  /**
@@ -860,8 +879,8 @@ class TuffListBuilder {
860
879
  * @returns 当前列表构建器实例,用于链式调用
861
880
  */
862
881
  setSharedKind(kind: TuffItemKind): TuffListBuilder {
863
- this.sharedKind = kind;
864
- return this;
882
+ this.sharedKind = kind
883
+ return this
865
884
  }
866
885
 
867
886
  /**
@@ -871,8 +890,8 @@ class TuffListBuilder {
871
890
  * @returns 当前列表构建器实例,用于链式调用
872
891
  */
873
892
  addSharedAction(action: TuffAction): TuffListBuilder {
874
- this.sharedActions.push(action);
875
- return this;
893
+ this.sharedActions.push(action)
894
+ return this
876
895
  }
877
896
 
878
897
  /**
@@ -887,23 +906,24 @@ class TuffListBuilder {
887
906
 
888
907
  // 应用共享配置
889
908
  if (this.sharedKind) {
890
- builder.setKind(this.sharedKind);
909
+ builder.setKind(this.sharedKind)
891
910
  }
892
911
  if (this.sharedActions.length > 0) {
893
912
  // 克隆共享操作以避免交叉污染
894
- builder.setActions(JSON.parse(JSON.stringify(this.sharedActions)));
913
+ builder.setActions(JSON.parse(JSON.stringify(this.sharedActions)))
895
914
  }
896
915
 
897
916
  // 应用自定义配置
898
- customize(builder);
917
+ customize(builder)
899
918
 
900
919
  try {
901
- this.items.push(builder.build());
902
- } catch (error) {
903
- console.error('构建 TuffItem 失败:', error);
920
+ this.items.push(builder.build())
921
+ }
922
+ catch (error) {
923
+ console.error('构建 TuffItem 失败:', error)
904
924
  }
905
925
 
906
- return this;
926
+ return this
907
927
  }
908
928
 
909
929
  /**
@@ -915,12 +935,12 @@ class TuffListBuilder {
915
935
  */
916
936
  addItemsFromData<T>(
917
937
  dataItems: T[],
918
- customize: (builder: TuffItemBuilder, dataItem: T) => void
938
+ customize: (builder: TuffItemBuilder, dataItem: T) => void,
919
939
  ): TuffListBuilder {
920
940
  for (const dataItem of dataItems) {
921
- this.addItem(builder => customize(builder, dataItem));
941
+ this.addItem(builder => customize(builder, dataItem))
922
942
  }
923
- return this;
943
+ return this
924
944
  }
925
945
 
926
946
  /**
@@ -929,7 +949,7 @@ class TuffListBuilder {
929
949
  * @returns 创建的 TuffItem 对象数组
930
950
  */
931
951
  build(): TuffItem[] {
932
- return this.items;
952
+ return this.items
933
953
  }
934
954
 
935
955
  /**
@@ -938,8 +958,8 @@ class TuffListBuilder {
938
958
  * @returns 当前列表构建器实例,用于链式调用
939
959
  */
940
960
  clear(): TuffListBuilder {
941
- this.items = [];
942
- return this;
961
+ this.items = []
962
+ return this
943
963
  }
944
964
  }
945
965
 
@@ -962,7 +982,7 @@ class TuffUtils {
962
982
  * @returns {string} 生成的唯一 ID
963
983
  */
964
984
  static generateId(): string {
965
- return `tuff_${Date.now()}_${Math.random().toString(36).substring(2, 9)}_${Math.random().toString(36).substring(2, 5)}`;
985
+ return `tuff_${Date.now()}_${Math.random().toString(36).substring(2, 9)}_${Math.random().toString(36).substring(2, 5)}`
966
986
  }
967
987
 
968
988
  /**
@@ -975,8 +995,8 @@ class TuffUtils {
975
995
  static createIcon(value: string, type: 'emoji' | 'url' | 'file' = 'emoji'): TuffIcon {
976
996
  return {
977
997
  type,
978
- value
979
- };
998
+ value,
999
+ }
980
1000
  }
981
1001
 
982
1002
  /**
@@ -988,10 +1008,12 @@ class TuffUtils {
988
1008
  * @returns 创建的标签对象
989
1009
  */
990
1010
  static createTag(text: string, color?: string, variant?: 'filled' | 'outlined' | 'ghost'): TuffTag {
991
- const tag: TuffTag = { text };
992
- if (color) tag.color = color;
993
- if (variant) tag.variant = variant;
994
- return tag;
1011
+ const tag: TuffTag = { text }
1012
+ if (color)
1013
+ tag.color = color
1014
+ if (variant)
1015
+ tag.variant = variant
1016
+ return tag
995
1017
  }
996
1018
 
997
1019
  /**
@@ -1009,11 +1031,12 @@ class TuffUtils {
1009
1031
  type: TuffActionType,
1010
1032
  label: string,
1011
1033
  primary: boolean = false,
1012
- payload?: any
1034
+ payload?: any,
1013
1035
  ): TuffAction {
1014
- const action: TuffAction = { id, type, label, primary };
1015
- if (payload) action.payload = payload;
1016
- return action;
1036
+ const action: TuffAction = { id, type, label, primary }
1037
+ if (payload)
1038
+ action.payload = payload
1039
+ return action
1017
1040
  }
1018
1041
 
1019
1042
  /**
@@ -1024,7 +1047,7 @@ class TuffUtils {
1024
1047
  * @returns 过滤后的项目列表
1025
1048
  */
1026
1049
  static filterItems(items: TuffItem[], predicate: (item: TuffItem) => boolean): TuffItem[] {
1027
- return items.filter(predicate);
1050
+ return items.filter(predicate)
1028
1051
  }
1029
1052
 
1030
1053
  /**
@@ -1035,7 +1058,7 @@ class TuffUtils {
1035
1058
  * @returns 过滤后的项目列表
1036
1059
  */
1037
1060
  static filterByKind(items: TuffItem[], kind: TuffItemKind): TuffItem[] {
1038
- return TuffUtils.filterItems(items, item => item.kind === kind);
1061
+ return TuffUtils.filterItems(items, item => item.kind === kind)
1039
1062
  }
1040
1063
 
1041
1064
  /**
@@ -1046,7 +1069,7 @@ class TuffUtils {
1046
1069
  * @returns 过滤后的项目列表
1047
1070
  */
1048
1071
  static filterBySourceType(items: TuffItem[], sourceType: TuffSourceType): TuffItem[] {
1049
- return TuffUtils.filterItems(items, item => item.source.type === sourceType);
1072
+ return TuffUtils.filterItems(items, item => item.source.type === sourceType)
1050
1073
  }
1051
1074
 
1052
1075
  /**
@@ -1058,13 +1081,14 @@ class TuffUtils {
1058
1081
  * @returns 匹配的项目列表
1059
1082
  */
1060
1083
  static searchByTitle(items: TuffItem[], query: string, caseSensitive: boolean = false): TuffItem[] {
1061
- const normalizedQuery = caseSensitive ? query : query.toLowerCase();
1062
- return TuffUtils.filterItems(items, item => {
1063
- const title = item.render.basic?.title;
1064
- if (!title) return false;
1065
- const normalizedTitle = caseSensitive ? title : title.toLowerCase();
1066
- return normalizedTitle.includes(normalizedQuery);
1067
- });
1084
+ const normalizedQuery = caseSensitive ? query : query.toLowerCase()
1085
+ return TuffUtils.filterItems(items, (item) => {
1086
+ const title = item.render.basic?.title
1087
+ if (!title)
1088
+ return false
1089
+ const normalizedTitle = caseSensitive ? title : title.toLowerCase()
1090
+ return normalizedTitle.includes(normalizedQuery)
1091
+ })
1068
1092
  }
1069
1093
 
1070
1094
  /**
@@ -1076,10 +1100,10 @@ class TuffUtils {
1076
1100
  */
1077
1101
  static sortByScore(items: TuffItem[], ascending: boolean = false): TuffItem[] {
1078
1102
  return [...items].sort((a, b) => {
1079
- const scoreA = a.scoring?.final ?? a.scoring?.base ?? 0;
1080
- const scoreB = b.scoring?.final ?? b.scoring?.base ?? 0;
1081
- return ascending ? scoreA - scoreB : scoreB - scoreA;
1082
- });
1103
+ const scoreA = a.scoring?.final ?? a.scoring?.base ?? 0
1104
+ const scoreB = b.scoring?.final ?? b.scoring?.base ?? 0
1105
+ return ascending ? scoreA - scoreB : scoreB - scoreA
1106
+ })
1083
1107
  }
1084
1108
 
1085
1109
  /**
@@ -1091,12 +1115,12 @@ class TuffUtils {
1091
1115
  */
1092
1116
  static sortByTitle(items: TuffItem[], ascending: boolean = true): TuffItem[] {
1093
1117
  return [...items].sort((a, b) => {
1094
- const titleA = a.render.basic?.title ?? '';
1095
- const titleB = b.render.basic?.title ?? '';
1118
+ const titleA = a.render.basic?.title ?? ''
1119
+ const titleB = b.render.basic?.title ?? ''
1096
1120
  return ascending
1097
1121
  ? titleA.localeCompare(titleB)
1098
- : titleB.localeCompare(titleA);
1099
- });
1122
+ : titleB.localeCompare(titleA)
1123
+ })
1100
1124
  }
1101
1125
 
1102
1126
  /**
@@ -1113,36 +1137,37 @@ class TuffUtils {
1113
1137
 
1114
1138
  // 尝试提取标题
1115
1139
  if (obj.title || obj.name || obj.label) {
1116
- builder.setTitle(obj.title || obj.name || obj.label);
1117
- } else {
1118
- builder.setTitle(String(obj));
1140
+ builder.setTitle(obj.title || obj.name || obj.label)
1141
+ }
1142
+ else {
1143
+ builder.setTitle(String(obj))
1119
1144
  }
1120
1145
 
1121
1146
  // 尝试提取描述
1122
1147
  if (obj.description || obj.desc) {
1123
- builder.setDescription(obj.description || obj.desc);
1148
+ builder.setDescription(obj.description || obj.desc)
1124
1149
  }
1125
1150
 
1126
1151
  // 尝试提取图标
1127
1152
  if (obj.icon) {
1128
- builder.setIcon(obj.icon);
1153
+ builder.setIcon(obj.icon)
1129
1154
  }
1130
1155
 
1131
1156
  // 尝试提取类型
1132
1157
  if (obj.kind || obj.type) {
1133
- const kind = obj.kind || obj.type;
1134
- builder.setKind(kind as TuffItemKind);
1158
+ const kind = obj.kind || obj.type
1159
+ builder.setKind(kind as TuffItemKind)
1135
1160
  }
1136
1161
 
1137
1162
  // 尝试提取分数
1138
1163
  if (obj.score !== undefined) {
1139
- builder.setFinalScore(obj.score);
1164
+ builder.setFinalScore(obj.score)
1140
1165
  }
1141
1166
 
1142
1167
  // 保存原始数据
1143
- builder.setMeta({ raw: obj });
1168
+ builder.setMeta({ raw: obj })
1144
1169
 
1145
- return builder.build();
1170
+ return builder.build()
1146
1171
  }
1147
1172
 
1148
1173
  /**
@@ -1154,9 +1179,9 @@ class TuffUtils {
1154
1179
  * @returns 创建的 TuffItem 对象数组
1155
1180
  */
1156
1181
  static fromObjects(objects: any[], sourceType: TuffSourceType, sourceId: string): TuffItem[] {
1157
- return objects.map(obj => TuffUtils.fromObject(obj, sourceType, sourceId));
1182
+ return objects.map(obj => TuffUtils.fromObject(obj, sourceType, sourceId))
1158
1183
  }
1159
1184
  }
1160
1185
 
1161
1186
  // 导出所有工具
1162
- export { TuffItemBuilder, TuffSearchResultBuilder, TuffFactory, TuffListBuilder, TuffUtils };
1187
+ export { TuffFactory, TuffItemBuilder, TuffListBuilder, TuffSearchResultBuilder, TuffUtils }