utools-api-types 7.1.0 → 7.5.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "utools-api-types",
3
- "version": "7.1.0",
3
+ "version": "7.5.0",
4
4
  "description": "TypeScript definitions for uTools API",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,5 +20,8 @@
20
20
  "default": {
21
21
  "types": "./utools.api.d.ts"
22
22
  }
23
+ },
24
+ "dependencies": {
25
+ "@types/sharp": "^0.31.1"
23
26
  }
24
27
  }
@@ -60,6 +60,10 @@
60
60
  "mainPush": {
61
61
  "type": "boolean"
62
62
  },
63
+ "mainHide": {
64
+ "type": "boolean",
65
+ "description": "设置为 `true` 时,打开对应的 `feature` 不主动弹出搜索框窗口"
66
+ },
63
67
  "cmds": {
64
68
  "type": "array",
65
69
  "description": "该功能下可响应的命令集,支持 6 种类型,由 cmds 的类型或 cmds.type 决定。",
@@ -120,13 +124,16 @@
120
124
  "file",
121
125
  "directory"
122
126
  ]
127
+ },
128
+ "extensions": {
129
+ "type": "array",
130
+ "description": "文件扩展名",
131
+ "items": {
132
+ "type": "string"
133
+ }
123
134
  }
124
135
  }
125
136
  }
126
- },
127
- "mainHide": {
128
- "type": "boolean",
129
- "description": "设置为 `true` 时,打开对应的 `feature` 不主动弹出搜索框面板"
130
137
  }
131
138
  }
132
139
  }
package/utools.api.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  /// <reference path="ubw.d.ts"/>
2
2
  /// <reference path="electron.d.ts"/>
3
3
 
4
+ import type { Sharp, SharpOptions } from 'sharp';
5
+
4
6
  interface UtoolsAiModel {
5
7
  id: string;
6
8
  label: string;
@@ -92,7 +94,7 @@ interface UBrowser {
92
94
  screenshot(arg: string | { x: number, y: number, width: number, height: number }, savePath?: string): this;
93
95
  /**
94
96
  * 转为 markdown 文本
95
- * @param selector css 选择器或者XPATH
97
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
96
98
  */
97
99
  markdown(selector?: string): this;
98
100
  /**
@@ -106,30 +108,34 @@ interface UBrowser {
106
108
  */
107
109
  device(arg: { size: { width: number, height: number }, useragent: string }): this;
108
110
  /**
109
- * 在当前 url 根据名称获取 cookie
110
- * @param name 为空获取当前 url 全部 cookie
111
+ * 获取当前 URL 的 Cookie。
112
+ * @param name 可选,指定 Cookie 名称。如果未传入,则返回当前 URL 的所有 Cookie。
111
113
  */
112
114
  cookies(name?: string): this;
113
115
  /**
114
- * 根据条件获取 ubrowser cookies
115
- * @param filter 条件过滤对象
116
+ * 根据条件获取 Cookie。
117
+ * @param filter 条件过滤对象,例如 { name: string, domain?: string }。
116
118
  */
117
119
  cookies(filter: CookieFilter): this;
118
120
  /**
119
- * 设置Cookie
121
+ * 设置单个 Cookie。
122
+ * @param name Cookie 名称
123
+ * @param value Cookie 值
120
124
  */
121
125
  setCookies(name: string, value: string): this;
122
126
  /**
123
- * 设置Cookie
127
+ * 批量设置 Cookie。
128
+ * @param cookies Cookie 数组,每个元素包含 name 和 value。
124
129
  */
125
- setCookies(cookies: { name: string, value: string }[]): this;
130
+ setCookies(cookies: { name: string; value: string }[]): this;
126
131
  /**
127
- * 删除 cookie
132
+ * 删除指定 Cookie。
133
+ * @param name Cookie 名称
128
134
  */
129
135
  removeCookies(name: string): this;
130
136
  /**
131
- * 清空cookie
132
- * @param url 在执行"goto"前执行 url参数必需
137
+ * 清空 Cookie。
138
+ * @param url 可选,指定 URL。若在执行 "goto" 前调用,url 参数必填。
133
139
  */
134
140
  clearCookies(url?: string): this;
135
141
  /**
@@ -143,30 +149,66 @@ interface UBrowser {
143
149
  */
144
150
  evaluate<T extends any[]>(func: (...params: T) => any, ...params: T): this;
145
151
  /**
146
- * 等待时间
147
- * @param ms 毫秒
152
+ * 等待指定的时间。
153
+ * @param ms 等待时长(毫秒)
148
154
  */
149
155
  wait(ms: number): this;
150
156
  /**
151
- * 等待元素出现
152
- * @param selector DOM元素
153
- * @param timeout 超时 默认60000 ms(60秒)
157
+ * 等待元素满足条件。
158
+ *
159
+ * 默认行为:等待元素出现。
160
+ *
161
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
162
+ * @param options 等待选项
163
+ * - result: true 等待出现,false 等待消失(默认 true)
164
+ * - timeout: 超时时间,默认 60000 ms
165
+ * - interval: 轮询间隔(毫秒),默认 500 ms
166
+ */
167
+ wait(selector: string, options?: { result?: boolean; timeout?: number; interval?: number; }): this;
168
+ /**
169
+ * 等待元素满足条件(简写形式)。
170
+ *
171
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
172
+ * @param result 为 true 等待出现,为 false 等待消失(默认 true)
173
+ */
174
+ wait(selector: string, result?: boolean): this;
175
+ /**
176
+ * 等待元素出现,指定超时时间(简写形式)。
177
+ *
178
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
179
+ * @param timeout 超时时间(毫秒)
154
180
  */
155
181
  wait(selector: string, timeout?: number): this;
156
182
  /**
157
- * 等待 JS函数 执行返回 true
158
- * @param func 执行的JS函数
159
- * @param timeout 超时 默认60000 ms(60秒)
160
- * @param params 传到 func 中的参数
183
+ * 等待 JS 函数执行结果为 true。
184
+ *
185
+ * 该函数将被周期性执行,直到返回 true 或超时。
186
+ *
187
+ * @param func 判定函数,返回 true 表示条件满足
188
+ * @param timeout 超时时间,默认 60000 ms
189
+ * @param params 传递给 func 的参数
161
190
  */
162
191
  wait<T extends any[]>(func: (...params: T) => boolean, timeout?: number, ...params: T): this;
192
+ /**
193
+ * 等待 JS 函数执行结果为 true。
194
+ *
195
+ * 该函数将被周期性执行,直到返回 true 或超时。
196
+ *
197
+ * @param func 判定函数,返回 true 表示条件满足
198
+ * @param options 等待选项
199
+ * - timeout: 超时时间,默认 60000 ms
200
+ * - interval: 轮询间隔(毫秒),默认 500 ms
201
+ * @param params 传递给 func 的参数
202
+ */
203
+ wait<T extends any[]>(func: (...params: T) => boolean, options?: { timeout?: number; interval?: number; }, ...params: T): this;
163
204
  /**
164
- * 当元素存在时执行,直到碰到 end
165
- * @param selector DOM元素
205
+ * 当元素满足条件时,直到碰到 end
206
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
207
+ * @param result 可选,为 true 表示当元素存在时,为 false 表示当元素不存在时(默认 true)
166
208
  */
167
- when(selector: string): this;
209
+ when(selector: string, result?: boolean): this;
168
210
  /**
169
- * 当 JS函数执行返回 true 时执行直到碰到 end
211
+ * 当 JS 函数执行返回 true 时,直到碰到 end
170
212
  * @param func 执行的JS函数
171
213
  * @param params 传到 func 中的参数
172
214
  */
@@ -176,39 +218,136 @@ interface UBrowser {
176
218
  */
177
219
  end(): this;
178
220
  /**
179
- * 单击元素
221
+ * 单击指定元素
222
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
223
+ * @param button 可选,鼠标按键;当设置该参数时,将以物理方式执行操作
224
+ */
225
+ click(selector: string, button?: 'left' | 'middle' | 'right'): this;
226
+ /**
227
+ * 单击坐标位置
228
+ * @param x 窗口 X 坐标
229
+ * @param y 窗口 Y 坐标
230
+ * @param button 可选,鼠标按键,默认为 'left'
231
+ */
232
+ click(x: number, y: number, button?: 'left' | 'middle' | 'right'): this;
233
+ /**
234
+ * 双击指定元素
235
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
236
+ * @param button 可选,鼠标按键;当设置该参数时,将以物理方式执行操作
237
+ */
238
+ dblclick(selector: string, button?: 'left' | 'middle' | 'right'): this;
239
+ /**
240
+ * 双击坐标位置
241
+ * @param x 窗口 X 坐标
242
+ * @param y 窗口 Y 坐标
243
+ * @param button 可选,鼠标按键,默认为 'left'
244
+ */
245
+ dblclick(x: number, y: number, button?: 'left' | 'middle' | 'right'): this;
246
+ /**
247
+ * 在指定元素按下鼠标键(mousedown)
248
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
249
+ * @param button 可选,鼠标按键;当设置该参数时,将以物理方式执行操作
250
+ */
251
+ mousedown(selector: string, button?: 'left' | 'middle' | 'right'): this;
252
+ /**
253
+ * 在坐标位置按下鼠标键
254
+ * @param x 窗口 X 坐标
255
+ * @param y 窗口 Y 坐标
256
+ * @param button 可选,鼠标按键,默认为 'left'
257
+ */
258
+ mousedown(x: number, y: number, button?: 'left' | 'middle' | 'right'): this;
259
+ /**
260
+ * 在指定元素释放鼠标键(mouseup)
261
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
262
+ * @param button 可选,鼠标按键;当设置该参数时,将以物理方式执行操作
263
+ */
264
+ mouseup(selector: string, button?: 'left' | 'middle' | 'right'): this;
265
+ /**
266
+ * 在坐标位置释放鼠标键
267
+ * @param x 窗口 X 坐标
268
+ * @param y 窗口 Y 坐标
269
+ * @param button 可选,鼠标按键,默认为 'left'
180
270
  */
181
- click(selector: string): this;
271
+ mouseup(x: number, y: number, button?: 'left' | 'middle' | 'right'): this;
182
272
  /**
183
- * 元素触发按下鼠标左键
273
+ * 移动鼠标到元素
274
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
184
275
  */
185
- mousedown(selector: string): this;
276
+ hover(selector: string): this;
186
277
  /**
187
- * 元素触发释放鼠标左键
278
+ * 移动鼠标到坐标。
279
+ * @param x 窗口 X 坐标
280
+ * @param y 窗口 Y 坐标
188
281
  */
189
- mouseup(selector: string): this;
282
+ hover(x: number, y: number): this;
190
283
  /**
191
- * 赋值 file input
192
- * @param selector <input type='file' /> 元素
193
- * @param payload 1. string - 文件路径 或 图片的base64编码,2. string[] - 文件路径集合,3. Uint8Array[]
284
+ * 上传文件(必须为 input[type=file])
285
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
286
+ * @param payload 文件内容,可为以下类型:
287
+ * - string:文件路径或图像的 base64 Data URL
288
+ * - string[]:多个文件路径
289
+ * - Uint8Array[]:文件 Buffer
194
290
  */
195
291
  file(selector: string, payload: string | string[] | Uint8Array): this;
196
292
  /**
197
- * input textarea select 等元素赋值并触发 input 或 change事件
293
+ * 拖放文件到指定元素
294
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
295
+ * @param payload 文件内容,可为以下类型:
296
+ * - string:文件路径或图像的 base64 Data URL
297
+ * - string[]:多个文件路径
298
+ * - Uint8Array[]:文件 Buffer
299
+ */
300
+ drop(selector: string, payload: string | string[] | Uint8Array): this;
301
+ /**
302
+ * 拖放文件到指定坐标
303
+ * @param x 窗口 X 坐标
304
+ * @param y 窗口 Y 坐标
305
+ * @param payload 文件内容,可为以下类型:
306
+ * - string:文件路径或图像的 base64 Data URL
307
+ * - string[]:多个文件路径
308
+ * - Uint8Array[]:多个文件的二进制数据
309
+ */
310
+ drop(x: number, y: number, payload: string | string[] | Uint8Array): this;
311
+ /**
312
+ * 输入文本,模拟输入法输入,不触发键盘按键事件
313
+ * @param text 字符串文本
314
+ */
315
+ input(text: string): this;
316
+ /**
317
+ * 元素获得焦点后,输入文本,模拟输入法输入,不触发键盘按键事件
318
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
319
+ * @param text 字符串文本
320
+ */
321
+ input(selector: string, text: string): this;
322
+ /**
323
+ * input、textarea、select 等元素赋值
324
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
325
+ * @param value 元素的值
198
326
  */
199
327
  value(selector: string, value: string): this;
200
328
  /**
201
329
  * checkbox radio 元素选中或取消选中
330
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
202
331
  */
203
332
  check(selector: string, checked: boolean): this;
204
333
  /**
205
334
  * 元素获得焦点
335
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
206
336
  */
207
337
  focus(selector: string): this;
208
338
  /**
209
- * 滚动到元素位置
339
+ * 滚动到指定元素位置
340
+ *
341
+ * @param selector CSS 或 XPath 选择器,支持使用 `>>` 进行 iframe 嵌套
342
+ * @param options 可选参数:
343
+ * - boolean:是否执行滚动(默认 true)
344
+ * - object:滚动行为与条件配置
210
345
  */
211
- scroll(selector: string): this;
346
+ scroll(selector: string, optional?: boolean | {
347
+ behavior?: 'auto' | 'smooth';
348
+ block?: 'start' | 'center' | 'end' | 'nearest';
349
+ inline?: 'start' | 'center' | 'end' | 'nearest';
350
+ }): this;
212
351
  /**
213
352
  * Y轴滚动
214
353
  */
@@ -219,52 +358,115 @@ interface UBrowser {
219
358
  scroll(x: number, y: number): this;
220
359
  /**
221
360
  * 下载文件
361
+ *
362
+ * @param url 需要下载的文件地址。
363
+ * @param savePath 可选,文件保存路径或保存目录,未传时将保存到下载目录
222
364
  */
223
365
  download(url: string, savePath?: string): this;
224
366
  /**
225
- * 下载文件
367
+ * 下载文件(动态生成的下载地址)
368
+ *
369
+ * @param func 返回下载地址的函数。该函数将在 ubrowser 运行环境中执行。
370
+ * @param savePath 可选,文件保存路径或保存目录,未传时将保存到下载目录
371
+ * @param params 传递给 func 的参数列表
226
372
  */
227
373
  download(func: (...params: any[]) => string, savePath: string | null, ...params: any[]): this;
228
374
  /**
229
- * 启动一个 ubrowser 运行
230
- * 当运行结束后,窗口如果为隐藏状态将自动销毁窗口
231
- * @param options
375
+ * 启动一个新的 ubrowser 实例运行。
376
+ *
377
+ * 当执行结束后:
378
+ * - 若窗口为隐藏状态(show = false),将自动销毁该窗口
379
+ * - 若窗口仍处于显示状态,则保留实例并返回其 ID
380
+ *
381
+ * @param options 窗口及运行配置项
232
382
  */
233
383
  run<T extends any = any[]>(options: {
384
+ /** 是否显示窗口,默认 false */
234
385
  show?: boolean;
386
+
387
+ /** 窗口宽度 */
235
388
  width?: number;
389
+ /** 窗口高度 */
236
390
  height?: number;
391
+
392
+ /** 窗口 X 坐标 */
237
393
  x?: number;
394
+ /** 窗口 Y 坐标 */
238
395
  y?: number;
396
+
397
+ /** 是否居中显示 */
239
398
  center?: boolean;
399
+
400
+ /** 最小宽度 */
240
401
  minWidth?: number;
402
+ /** 最小高度 */
241
403
  minHeight?: number;
404
+
405
+ /** 最大宽度 */
242
406
  maxWidth?: number;
407
+ /** 最大高度 */
243
408
  maxHeight?: number;
409
+
410
+ /** 是否允许调整大小 */
244
411
  resizable?: boolean;
412
+ /** 是否允许移动 */
245
413
  movable?: boolean;
414
+
415
+ /** 是否允许最小化 */
246
416
  minimizable?: boolean;
417
+ /** 是否允许最大化 */
247
418
  maximizable?: boolean;
419
+
420
+ /** 是否置顶 */
248
421
  alwaysOnTop?: boolean;
422
+
423
+ /** 是否全屏 */
249
424
  fullscreen?: boolean;
425
+ /** 是否允许进入全屏 */
250
426
  fullscreenable?: boolean;
427
+
428
+ /** 是否允许窗口尺寸大于屏幕 */
251
429
  enableLargerThanScreen?: boolean;
430
+
431
+ /** 窗口透明度(0 ~ 1) */
252
432
  opacity?: number;
433
+
434
+ /** 是否显示窗口边框 */
253
435
  frame?: boolean;
436
+
437
+ /** 是否允许关闭 */
254
438
  closable?: boolean;
439
+ /** 是否可获取焦点 */
255
440
  focusable?: boolean;
441
+
442
+ /** 是否在任务栏显示 */
256
443
  skipTaskbar?: boolean;
444
+
445
+ /** 窗口背景色 */
257
446
  backgroundColor?: string;
447
+
448
+ /** 是否显示阴影 */
258
449
  hasShadow?: boolean;
450
+
451
+ /** 是否透明窗口 */
259
452
  transparent?: boolean;
453
+
454
+ /** 标题栏样式(平台相关) */
260
455
  titleBarStyle?: string;
456
+
457
+ /** 是否使用系统厚边框(Windows) */
261
458
  thickFrame?: boolean;
262
459
  }): Promise<T>;
460
+
263
461
  /**
264
- * 运行在闲置的 ubrowser 上
265
- * @param ubrowserId 1. run(options) 运行结束后, 当 ubrowser 实例窗口仍然显示时返回 2. utools.getIdleUBrowsers() 中获得
462
+ * 在一个闲置的 ubrowser 实例上运行。
463
+ *
464
+ * @param ubrowserId ubrowser 实例 ID:
465
+ * - 可由 `run(options)` 在窗口未销毁时返回
466
+ * - 或通过 `utools.getIdleUBrowsers()` 获取
266
467
  */
267
468
  run<T extends any = any[]>(ubrowserId: number): Promise<T>;
469
+
268
470
  }
269
471
 
270
472
  interface Display {
@@ -499,6 +701,10 @@ interface UToolsApi {
499
701
  * @param autocopy 是否自动复制,默认为 false
500
702
  */
501
703
  redirectHotKeySetting(cmdLabel: string, autocopy?: boolean): void;
704
+ /**
705
+ * 跳转(前往) uTools 自定义 AI 模型设置界面,引导用户配置自定义 AI 模型
706
+ */
707
+ redirectAiModelsSetting(): void;
502
708
  /**
503
709
  * 获取闲置的 ubrowser
504
710
  */
@@ -856,30 +1062,10 @@ interface UToolsApi {
856
1062
  removeItem(key: string): void;
857
1063
  };
858
1064
 
859
- team: {
860
- /**
861
- * 获取团队信息
862
- */
863
- info(): {
864
- teamId: string,
865
- teamName: string,
866
- teamLogo: string,
867
- userId: string,
868
- userName: string,
869
- userAvatar: string
870
- };
871
- /**
872
- * 获取团队版预设键名对应的值
873
- */
874
- preset<T = any>(key: string): T;
875
- /**
876
- * 获取团队版预设的所有数据
877
- */
878
- allPresets(): Promise<{ key: string, value: any }[]>;
879
- }
880
-
881
1065
  ubrowser: UBrowser;
882
1066
 
1067
+ sharp: (input?: Buffer | Uint8Array | Uint8ClampedArray | Int8Array | Uint16Array | Int16Array | Uint32Array | Int32Array | Float32Array | Float64Array | string, options?: SharpOptions) => Sharp;
1068
+
883
1069
  /**
884
1070
  * 运行 ffmpeg
885
1071
  * @param args ffmpeg 命令行参数