assistsx-js 0.1.41 → 0.2.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/README.md +32 -0
- package/dist/index.cjs +7957 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.mts +4231 -0
- package/dist/index.d.ts +4231 -30
- package/dist/index.global.js +46 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +7879 -30
- package/dist/index.js.map +1 -0
- package/package.json +11 -5
- package/src/{AssistsXAsync.ts → assistsx-async.ts} +8 -8
- package/src/{AssistsX.ts → assistsx.ts} +8 -8
- package/src/barutils/bar-utils.ts +3 -3
- package/src/filesystem/fileio/file-io.ts +2 -2
- package/src/filesystem/fileutils/file-utils.ts +2 -2
- package/src/filesystem/path.ts +2 -2
- package/src/floatingwindow/float.ts +4 -4
- package/src/gallery/gallery.ts +2 -2
- package/src/global.d.ts +6 -1
- package/src/imageutils/image-utils.ts +2 -2
- package/src/ime/ime.ts +2 -2
- package/src/index.ts +21 -20
- package/src/log/log-call-method.ts +28 -0
- package/src/log/log.ts +445 -0
- package/src/mlkit/mlkit.ts +3 -3
- package/src/network/http.ts +2 -2
- package/src/{NodeAsync.ts → node-async.ts} +5 -5
- package/src/{Node.ts → node.ts} +5 -5
- package/src/{StepAsync.ts → step-async.ts} +8 -8
- package/src/{Step.ts → step.ts} +7 -7
- package/dist/AccessibilityEventFilter.d.ts +0 -105
- package/dist/AccessibilityEventFilter.js +0 -89
- package/dist/AppInfo.d.ts +0 -45
- package/dist/AppInfo.js +0 -38
- package/dist/AssistsX.d.ts +0 -484
- package/dist/AssistsX.js +0 -828
- package/dist/AssistsXAsync.d.ts +0 -532
- package/dist/AssistsXAsync.js +0 -874
- package/dist/Bounds.d.ts +0 -48
- package/dist/Bounds.js +0 -68
- package/dist/CallMethod.d.ts +0 -69
- package/dist/CallMethod.js +0 -71
- package/dist/CallResponse.d.ts +0 -10
- package/dist/CallResponse.js +0 -28
- package/dist/DeviceInfo.d.ts +0 -69
- package/dist/DeviceInfo.js +0 -50
- package/dist/Node.d.ts +0 -334
- package/dist/Node.js +0 -369
- package/dist/NodeAsync.d.ts +0 -213
- package/dist/NodeAsync.js +0 -313
- package/dist/NodeClassValue.d.ts +0 -15
- package/dist/NodeClassValue.js +0 -15
- package/dist/Step.d.ts +0 -355
- package/dist/Step.js +0 -689
- package/dist/StepAsync.d.ts +0 -162
- package/dist/StepAsync.js +0 -264
- package/dist/StepError.d.ts +0 -35
- package/dist/StepError.js +0 -26
- package/dist/StepStateStore.d.ts +0 -14
- package/dist/StepStateStore.js +0 -37
- package/dist/Utils.d.ts +0 -3
- package/dist/Utils.js +0 -20
- package/dist/WindowFlags.d.ts +0 -75
- package/dist/WindowFlags.js +0 -97
- package/dist/barutils/BarUtilsCallMethod.d.ts +0 -24
- package/dist/barutils/BarUtilsCallMethod.js +0 -26
- package/dist/barutils/bar-utils.d.ts +0 -41
- package/dist/barutils/bar-utils.js +0 -205
- package/dist/filesystem/fileio/file-io.d.ts +0 -101
- package/dist/filesystem/fileio/file-io.js +0 -235
- package/dist/filesystem/fileutils/file-utils.d.ts +0 -242
- package/dist/filesystem/fileutils/file-utils.js +0 -493
- package/dist/filesystem/path.d.ts +0 -252
- package/dist/filesystem/path.js +0 -589
- package/dist/floatingwindow/FloatCallMethod.d.ts +0 -19
- package/dist/floatingwindow/FloatCallMethod.js +0 -18
- package/dist/floatingwindow/float.d.ts +0 -29
- package/dist/floatingwindow/float.js +0 -149
- package/dist/gallery/gallery.d.ts +0 -60
- package/dist/gallery/gallery.js +0 -142
- package/dist/imageutils/image-utils.d.ts +0 -442
- package/dist/imageutils/image-utils.js +0 -543
- package/dist/ime/ime.d.ts +0 -80
- package/dist/ime/ime.js +0 -141
- package/dist/mlkit/MlkitCallMethod.d.ts +0 -27
- package/dist/mlkit/MlkitCallMethod.js +0 -26
- package/dist/mlkit/mlkit.d.ts +0 -86
- package/dist/mlkit/mlkit.js +0 -169
- package/dist/network/http.d.ts +0 -127
- package/dist/network/http.js +0 -202
- /package/src/{AccessibilityEventFilter.ts → accessibility-event-filter.ts} +0 -0
- /package/src/{AppInfo.ts → app-info.ts} +0 -0
- /package/src/barutils/{BarUtilsCallMethod.ts → bar-utils-call-method.ts} +0 -0
- /package/src/{Bounds.ts → bounds.ts} +0 -0
- /package/src/{CallMethod.ts → call-method.ts} +0 -0
- /package/src/{CallResponse.ts → call-response.ts} +0 -0
- /package/src/{DeviceInfo.ts → device-info.ts} +0 -0
- /package/src/floatingwindow/{FloatCallMethod.ts → float-call-method.ts} +0 -0
- /package/src/mlkit/{MlkitCallMethod.ts → mlkit-call-method.ts} +0 -0
- /package/src/{NodeClassValue.ts → node-class-value.ts} +0 -0
- /package/src/{StepError.ts → step-error.ts} +0 -0
- /package/src/{StepStateStore.ts → step-state-store.ts} +0 -0
- /package/src/{Utils.ts → utils.ts} +0 -0
- /package/src/{WindowFlags.ts → window-flags.ts} +0 -0
|
@@ -1,543 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 图片工具相关功能
|
|
3
|
-
* 提供图片处理相关的功能,包括转换、处理、压缩、保存等
|
|
4
|
-
*/
|
|
5
|
-
import { CallResponse } from "../CallResponse";
|
|
6
|
-
import { decodeBase64UTF8, generateUUID } from "../Utils";
|
|
7
|
-
// 回调函数存储对象
|
|
8
|
-
const callbacks = new Map();
|
|
9
|
-
// 初始化全局回调函数
|
|
10
|
-
if (typeof window !== "undefined" && !window.assistsxImageUtilsCallback) {
|
|
11
|
-
window.assistsxImageUtilsCallback = (data) => {
|
|
12
|
-
let callbackId;
|
|
13
|
-
try {
|
|
14
|
-
const json = decodeBase64UTF8(data);
|
|
15
|
-
const response = JSON.parse(json);
|
|
16
|
-
callbackId = response.callbackId;
|
|
17
|
-
if (callbackId) {
|
|
18
|
-
const callback = callbacks.get(callbackId);
|
|
19
|
-
if (callback) {
|
|
20
|
-
callback(json);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
catch (e) {
|
|
25
|
-
console.error("ImageUtils callback error:", e);
|
|
26
|
-
}
|
|
27
|
-
finally {
|
|
28
|
-
if (callbackId) {
|
|
29
|
-
callbacks.delete(callbackId);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
export class ImageUtils {
|
|
35
|
-
/**
|
|
36
|
-
* 执行异步调用
|
|
37
|
-
* @param method 方法名
|
|
38
|
-
* @param args 参数对象
|
|
39
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
40
|
-
* @returns Promise<调用响应>
|
|
41
|
-
*/
|
|
42
|
-
async asyncCall(method, args, timeout = 30) {
|
|
43
|
-
const uuid = generateUUID();
|
|
44
|
-
const params = {
|
|
45
|
-
method,
|
|
46
|
-
arguments: args ? args : undefined,
|
|
47
|
-
callbackId: uuid,
|
|
48
|
-
};
|
|
49
|
-
const promise = new Promise((resolve) => {
|
|
50
|
-
callbacks.set(uuid, (data) => {
|
|
51
|
-
resolve(data);
|
|
52
|
-
});
|
|
53
|
-
setTimeout(() => {
|
|
54
|
-
callbacks.delete(uuid);
|
|
55
|
-
resolve(JSON.stringify(new CallResponse(0, null, uuid)));
|
|
56
|
-
}, timeout * 1000);
|
|
57
|
-
});
|
|
58
|
-
const result = window.assistsxImageUtils.call(JSON.stringify(params));
|
|
59
|
-
const promiseResult = await promise;
|
|
60
|
-
if (typeof promiseResult === "string") {
|
|
61
|
-
const responseData = JSON.parse(promiseResult);
|
|
62
|
-
return new CallResponse(responseData.code, responseData.data, responseData.callbackId);
|
|
63
|
-
}
|
|
64
|
-
throw new Error("Call failed");
|
|
65
|
-
}
|
|
66
|
-
// ==================== 获取相关 ====================
|
|
67
|
-
/**
|
|
68
|
-
* 获取图片尺寸
|
|
69
|
-
* @param imagePath 图片路径
|
|
70
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
71
|
-
* @returns Promise<图片尺寸信息>
|
|
72
|
-
*/
|
|
73
|
-
async getSize(imagePath, timeout) {
|
|
74
|
-
var _a;
|
|
75
|
-
const response = await this.asyncCall("getSize", { imagePath }, timeout);
|
|
76
|
-
if (!response.isSuccess()) {
|
|
77
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "获取图片尺寸失败");
|
|
78
|
-
}
|
|
79
|
-
return response.data;
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* 获取图片类型
|
|
83
|
-
* @param imagePath 图片路径
|
|
84
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
85
|
-
* @returns Promise<图片类型信息>
|
|
86
|
-
*/
|
|
87
|
-
async getImageType(imagePath, timeout) {
|
|
88
|
-
var _a;
|
|
89
|
-
const response = await this.asyncCall("getImageType", { imagePath }, timeout);
|
|
90
|
-
if (!response.isSuccess()) {
|
|
91
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "获取图片类型失败");
|
|
92
|
-
}
|
|
93
|
-
return response.data;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* 判断是否为图片
|
|
97
|
-
* @param fileName 文件名
|
|
98
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
99
|
-
* @returns Promise<是否为图片>
|
|
100
|
-
*/
|
|
101
|
-
async isImage(fileName, timeout) {
|
|
102
|
-
var _a;
|
|
103
|
-
const response = await this.asyncCall("isImage", { fileName }, timeout);
|
|
104
|
-
if (!response.isSuccess()) {
|
|
105
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "判断是否为图片失败");
|
|
106
|
-
}
|
|
107
|
-
return response.data.isImage;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* 获取图片旋转角度
|
|
111
|
-
* @param imagePath 图片路径
|
|
112
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
113
|
-
* @returns Promise<图片旋转角度信息>
|
|
114
|
-
*/
|
|
115
|
-
async getRotateDegree(imagePath, timeout) {
|
|
116
|
-
var _a;
|
|
117
|
-
const response = await this.asyncCall("getRotateDegree", { imagePath }, timeout);
|
|
118
|
-
if (!response.isSuccess()) {
|
|
119
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "获取图片旋转角度失败");
|
|
120
|
-
}
|
|
121
|
-
return response.data;
|
|
122
|
-
}
|
|
123
|
-
// ==================== 图片处理相关 ====================
|
|
124
|
-
/**
|
|
125
|
-
* 缩放图片
|
|
126
|
-
* @param imagePath 图片路径
|
|
127
|
-
* @param options 缩放选项
|
|
128
|
-
* @param options.scaleWidth 缩放宽度(可选)
|
|
129
|
-
* @param options.scaleHeight 缩放高度(可选)
|
|
130
|
-
* @param options.savePath 保存路径(可选)
|
|
131
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
132
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
133
|
-
* @returns Promise<处理后的图片路径>
|
|
134
|
-
*/
|
|
135
|
-
async scale(imagePath, options = {}) {
|
|
136
|
-
var _a;
|
|
137
|
-
const { scaleWidth, scaleHeight, savePath, format, timeout } = options;
|
|
138
|
-
const response = await this.asyncCall("scale", { imagePath, scaleWidth, scaleHeight, savePath, format }, timeout);
|
|
139
|
-
if (!response.isSuccess()) {
|
|
140
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "缩放图片失败");
|
|
141
|
-
}
|
|
142
|
-
return response.data.filePath;
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* 裁剪图片
|
|
146
|
-
* @param imagePath 图片路径
|
|
147
|
-
* @param options 裁剪选项
|
|
148
|
-
* @param options.x 起始X坐标,默认0
|
|
149
|
-
* @param options.y 起始Y坐标,默认0
|
|
150
|
-
* @param options.width 裁剪宽度(可选,不提供则裁剪到图片右边界)
|
|
151
|
-
* @param options.height 裁剪高度(可选,不提供则裁剪到图片下边界)
|
|
152
|
-
* @param options.savePath 保存路径(可选)
|
|
153
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
154
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
155
|
-
* @returns Promise<处理后的图片路径>
|
|
156
|
-
*/
|
|
157
|
-
async clip(imagePath, options = {}) {
|
|
158
|
-
var _a;
|
|
159
|
-
const { x = 0, y = 0, width, height, savePath, format, timeout } = options;
|
|
160
|
-
const response = await this.asyncCall("clip", { imagePath, x, y, width, height, savePath, format }, timeout);
|
|
161
|
-
if (!response.isSuccess()) {
|
|
162
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "裁剪图片失败");
|
|
163
|
-
}
|
|
164
|
-
return response.data.filePath;
|
|
165
|
-
}
|
|
166
|
-
/**
|
|
167
|
-
* 倾斜图片
|
|
168
|
-
* @param imagePath 图片路径
|
|
169
|
-
* @param options 倾斜选项
|
|
170
|
-
* @param options.kx X轴倾斜系数,默认0
|
|
171
|
-
* @param options.ky Y轴倾斜系数,默认0
|
|
172
|
-
* @param options.px X轴倾斜点(可选)
|
|
173
|
-
* @param options.py Y轴倾斜点(可选)
|
|
174
|
-
* @param options.savePath 保存路径(可选)
|
|
175
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
176
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
177
|
-
* @returns Promise<处理后的图片路径>
|
|
178
|
-
*/
|
|
179
|
-
async skew(imagePath, options = {}) {
|
|
180
|
-
var _a;
|
|
181
|
-
const { kx = 0, ky = 0, px, py, savePath, format, timeout } = options;
|
|
182
|
-
const response = await this.asyncCall("skew", { imagePath, kx, ky, px, py, savePath, format }, timeout);
|
|
183
|
-
if (!response.isSuccess()) {
|
|
184
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "倾斜图片失败");
|
|
185
|
-
}
|
|
186
|
-
return response.data.filePath;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* 旋转图片
|
|
190
|
-
* @param imagePath 图片路径
|
|
191
|
-
* @param options 旋转选项
|
|
192
|
-
* @param options.degree 旋转角度,默认0
|
|
193
|
-
* @param options.px 旋转中心X坐标(可选)
|
|
194
|
-
* @param options.py 旋转中心Y坐标(可选)
|
|
195
|
-
* @param options.savePath 保存路径(可选)
|
|
196
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
197
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
198
|
-
* @returns Promise<处理后的图片路径>
|
|
199
|
-
*/
|
|
200
|
-
async rotate(imagePath, options = {}) {
|
|
201
|
-
var _a;
|
|
202
|
-
const { degree = 0, px, py, savePath, format, timeout } = options;
|
|
203
|
-
const response = await this.asyncCall("rotate", { imagePath, degree, px, py, savePath, format }, timeout);
|
|
204
|
-
if (!response.isSuccess()) {
|
|
205
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "旋转图片失败");
|
|
206
|
-
}
|
|
207
|
-
return response.data.filePath;
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* 转为圆形图片
|
|
211
|
-
* @param imagePath 图片路径
|
|
212
|
-
* @param options 选项
|
|
213
|
-
* @param options.savePath 保存路径(可选)
|
|
214
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
215
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
216
|
-
* @returns Promise<处理后的图片路径>
|
|
217
|
-
*/
|
|
218
|
-
async toRound(imagePath, options = {}) {
|
|
219
|
-
var _a;
|
|
220
|
-
const { savePath, format, timeout } = options;
|
|
221
|
-
const response = await this.asyncCall("toRound", { imagePath, savePath, format }, timeout);
|
|
222
|
-
if (!response.isSuccess()) {
|
|
223
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "转为圆形图片失败");
|
|
224
|
-
}
|
|
225
|
-
return response.data.filePath;
|
|
226
|
-
}
|
|
227
|
-
/**
|
|
228
|
-
* 转为圆角图片
|
|
229
|
-
* @param imagePath 图片路径
|
|
230
|
-
* @param options 选项
|
|
231
|
-
* @param options.radius 圆角半径,默认0
|
|
232
|
-
* @param options.savePath 保存路径(可选)
|
|
233
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
234
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
235
|
-
* @returns Promise<处理后的图片路径>
|
|
236
|
-
*/
|
|
237
|
-
async toRoundCorner(imagePath, options = {}) {
|
|
238
|
-
var _a;
|
|
239
|
-
const { radius = 0, savePath, format, timeout } = options;
|
|
240
|
-
const response = await this.asyncCall("toRoundCorner", { imagePath, radius, savePath, format }, timeout);
|
|
241
|
-
if (!response.isSuccess()) {
|
|
242
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "转为圆角图片失败");
|
|
243
|
-
}
|
|
244
|
-
return response.data.filePath;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* 添加圆角边框
|
|
248
|
-
* @param imagePath 图片路径
|
|
249
|
-
* @param options 选项
|
|
250
|
-
* @param options.borderSize 边框大小,默认0
|
|
251
|
-
* @param options.color 边框颜色,默认"#000000"
|
|
252
|
-
* @param options.cornerRadius 圆角半径,默认0
|
|
253
|
-
* @param options.savePath 保存路径(可选)
|
|
254
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
255
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
256
|
-
* @returns Promise<处理后的图片路径>
|
|
257
|
-
*/
|
|
258
|
-
async addCornerBorder(imagePath, options = {}) {
|
|
259
|
-
var _a;
|
|
260
|
-
const { borderSize = 0, color = "#000000", cornerRadius = 0, savePath, format, timeout } = options;
|
|
261
|
-
const response = await this.asyncCall("addCornerBorder", { imagePath, borderSize, color, cornerRadius, savePath, format }, timeout);
|
|
262
|
-
if (!response.isSuccess()) {
|
|
263
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "添加圆角边框失败");
|
|
264
|
-
}
|
|
265
|
-
return response.data.filePath;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* 添加圆形边框
|
|
269
|
-
* @param imagePath 图片路径
|
|
270
|
-
* @param options 选项
|
|
271
|
-
* @param options.borderSize 边框大小,默认0
|
|
272
|
-
* @param options.color 边框颜色,默认"#000000"
|
|
273
|
-
* @param options.savePath 保存路径(可选)
|
|
274
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
275
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
276
|
-
* @returns Promise<处理后的图片路径>
|
|
277
|
-
*/
|
|
278
|
-
async addCircleBorder(imagePath, options = {}) {
|
|
279
|
-
var _a;
|
|
280
|
-
const { borderSize = 0, color = "#000000", savePath, format, timeout } = options;
|
|
281
|
-
const response = await this.asyncCall("addCircleBorder", { imagePath, borderSize, color, savePath, format }, timeout);
|
|
282
|
-
if (!response.isSuccess()) {
|
|
283
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "添加圆形边框失败");
|
|
284
|
-
}
|
|
285
|
-
return response.data.filePath;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* 添加倒影
|
|
289
|
-
* @param imagePath 图片路径
|
|
290
|
-
* @param options 选项
|
|
291
|
-
* @param options.reflectionHeight 倒影高度,默认0
|
|
292
|
-
* @param options.savePath 保存路径(可选)
|
|
293
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
294
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
295
|
-
* @returns Promise<处理后的图片路径>
|
|
296
|
-
*/
|
|
297
|
-
async addReflection(imagePath, options = {}) {
|
|
298
|
-
var _a;
|
|
299
|
-
const { reflectionHeight = 0, savePath, format, timeout } = options;
|
|
300
|
-
const response = await this.asyncCall("addReflection", { imagePath, reflectionHeight, savePath, format }, timeout);
|
|
301
|
-
if (!response.isSuccess()) {
|
|
302
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "添加倒影失败");
|
|
303
|
-
}
|
|
304
|
-
return response.data.filePath;
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* 添加文字水印
|
|
308
|
-
* @param imagePath 图片路径
|
|
309
|
-
* @param options 选项
|
|
310
|
-
* @param options.text 水印文字,默认""
|
|
311
|
-
* @param options.x 文字X坐标,默认0
|
|
312
|
-
* @param options.y 文字Y坐标,默认0
|
|
313
|
-
* @param options.color 文字颜色,默认"#000000"
|
|
314
|
-
* @param options.size 文字大小,默认16
|
|
315
|
-
* @param options.savePath 保存路径(可选)
|
|
316
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
317
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
318
|
-
* @returns Promise<处理后的图片路径>
|
|
319
|
-
*/
|
|
320
|
-
async addTextWatermark(imagePath, options = {}) {
|
|
321
|
-
var _a;
|
|
322
|
-
const { text = "", x = 0, y = 0, color = "#000000", size = 16, savePath, format, timeout } = options;
|
|
323
|
-
const response = await this.asyncCall("addTextWatermark", { imagePath, text, x, y, color, size, savePath, format }, timeout);
|
|
324
|
-
if (!response.isSuccess()) {
|
|
325
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "添加文字水印失败");
|
|
326
|
-
}
|
|
327
|
-
return response.data.filePath;
|
|
328
|
-
}
|
|
329
|
-
/**
|
|
330
|
-
* 添加图片水印
|
|
331
|
-
* @param imagePath 图片路径
|
|
332
|
-
* @param options 选项
|
|
333
|
-
* @param options.watermarkPath 水印图片路径(必需)
|
|
334
|
-
* @param options.x 水印X坐标,默认0
|
|
335
|
-
* @param options.y 水印Y坐标,默认0
|
|
336
|
-
* @param options.alpha 透明度,默认255
|
|
337
|
-
* @param options.savePath 保存路径(可选)
|
|
338
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
339
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
340
|
-
* @returns Promise<处理后的图片路径>
|
|
341
|
-
*/
|
|
342
|
-
async addImageWatermark(imagePath, options) {
|
|
343
|
-
var _a;
|
|
344
|
-
const { watermarkPath, x = 0, y = 0, alpha = 255, savePath, format, timeout } = options;
|
|
345
|
-
const response = await this.asyncCall("addImageWatermark", { imagePath, watermarkPath, x, y, alpha, savePath, format }, timeout);
|
|
346
|
-
if (!response.isSuccess()) {
|
|
347
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "添加图片水印失败");
|
|
348
|
-
}
|
|
349
|
-
return response.data.filePath;
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* 转为 alpha 位图
|
|
353
|
-
* @param imagePath 图片路径
|
|
354
|
-
* @param options 选项
|
|
355
|
-
* @param options.savePath 保存路径(可选)
|
|
356
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
357
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
358
|
-
* @returns Promise<处理后的图片路径>
|
|
359
|
-
*/
|
|
360
|
-
async toAlpha(imagePath, options = {}) {
|
|
361
|
-
var _a;
|
|
362
|
-
const { savePath, format, timeout } = options;
|
|
363
|
-
const response = await this.asyncCall("toAlpha", { imagePath, savePath, format }, timeout);
|
|
364
|
-
if (!response.isSuccess()) {
|
|
365
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "转为 alpha 位图失败");
|
|
366
|
-
}
|
|
367
|
-
return response.data.filePath;
|
|
368
|
-
}
|
|
369
|
-
/**
|
|
370
|
-
* 转为灰度图片
|
|
371
|
-
* @param imagePath 图片路径
|
|
372
|
-
* @param options 选项
|
|
373
|
-
* @param options.savePath 保存路径(可选)
|
|
374
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
375
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
376
|
-
* @returns Promise<处理后的图片路径>
|
|
377
|
-
*/
|
|
378
|
-
async toGray(imagePath, options = {}) {
|
|
379
|
-
var _a;
|
|
380
|
-
const { savePath, format, timeout } = options;
|
|
381
|
-
const response = await this.asyncCall("toGray", { imagePath, savePath, format }, timeout);
|
|
382
|
-
if (!response.isSuccess()) {
|
|
383
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "转为灰度图片失败");
|
|
384
|
-
}
|
|
385
|
-
return response.data.filePath;
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* 快速模糊
|
|
389
|
-
* @param imagePath 图片路径
|
|
390
|
-
* @param options 选项
|
|
391
|
-
* @param options.radius 模糊半径,默认0
|
|
392
|
-
* @param options.scale 缩放比例,默认1
|
|
393
|
-
* @param options.savePath 保存路径(可选)
|
|
394
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
395
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
396
|
-
* @returns Promise<处理后的图片路径>
|
|
397
|
-
*/
|
|
398
|
-
async fastBlur(imagePath, options = {}) {
|
|
399
|
-
var _a;
|
|
400
|
-
const { radius = 0, scale = 1, savePath, format, timeout } = options;
|
|
401
|
-
const response = await this.asyncCall("fastBlur", { imagePath, radius, scale, savePath, format }, timeout);
|
|
402
|
-
if (!response.isSuccess()) {
|
|
403
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "快速模糊失败");
|
|
404
|
-
}
|
|
405
|
-
return response.data.filePath;
|
|
406
|
-
}
|
|
407
|
-
/**
|
|
408
|
-
* RenderScript 模糊
|
|
409
|
-
* @param imagePath 图片路径
|
|
410
|
-
* @param options 选项
|
|
411
|
-
* @param options.radius 模糊半径,默认0
|
|
412
|
-
* @param options.savePath 保存路径(可选)
|
|
413
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
414
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
415
|
-
* @returns Promise<处理后的图片路径>
|
|
416
|
-
*/
|
|
417
|
-
async renderScriptBlur(imagePath, options = {}) {
|
|
418
|
-
var _a;
|
|
419
|
-
const { radius = 0, savePath, format, timeout } = options;
|
|
420
|
-
const response = await this.asyncCall("renderScriptBlur", { imagePath, radius, savePath, format }, timeout);
|
|
421
|
-
if (!response.isSuccess()) {
|
|
422
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "RenderScript 模糊失败");
|
|
423
|
-
}
|
|
424
|
-
return response.data.filePath;
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* Stack 模糊
|
|
428
|
-
* @param imagePath 图片路径
|
|
429
|
-
* @param options 选项
|
|
430
|
-
* @param options.radius 模糊半径,默认0
|
|
431
|
-
* @param options.savePath 保存路径(可选)
|
|
432
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
433
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
434
|
-
* @returns Promise<处理后的图片路径>
|
|
435
|
-
*/
|
|
436
|
-
async stackBlur(imagePath, options = {}) {
|
|
437
|
-
var _a;
|
|
438
|
-
const { radius = 0, savePath, format, timeout } = options;
|
|
439
|
-
const response = await this.asyncCall("stackBlur", { imagePath, radius, savePath, format }, timeout);
|
|
440
|
-
if (!response.isSuccess()) {
|
|
441
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "Stack 模糊失败");
|
|
442
|
-
}
|
|
443
|
-
return response.data.filePath;
|
|
444
|
-
}
|
|
445
|
-
// ==================== 压缩相关 ====================
|
|
446
|
-
/**
|
|
447
|
-
* 按缩放压缩
|
|
448
|
-
* @param imagePath 图片路径
|
|
449
|
-
* @param options 选项
|
|
450
|
-
* @param options.scaleWidth 缩放宽度(可选)
|
|
451
|
-
* @param options.scaleHeight 缩放高度(可选)
|
|
452
|
-
* @param options.savePath 保存路径(可选)
|
|
453
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
454
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
455
|
-
* @returns Promise<压缩后的图片路径>
|
|
456
|
-
*/
|
|
457
|
-
async compressByScale(imagePath, options = {}) {
|
|
458
|
-
var _a;
|
|
459
|
-
const { scaleWidth, scaleHeight, savePath, format, timeout } = options;
|
|
460
|
-
const response = await this.asyncCall("compressByScale", { imagePath, scaleWidth, scaleHeight, savePath, format }, timeout);
|
|
461
|
-
if (!response.isSuccess()) {
|
|
462
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "按缩放压缩失败");
|
|
463
|
-
}
|
|
464
|
-
return response.data.filePath;
|
|
465
|
-
}
|
|
466
|
-
/**
|
|
467
|
-
* 按质量压缩
|
|
468
|
-
* @param imagePath 图片路径
|
|
469
|
-
* @param options 选项
|
|
470
|
-
* @param options.quality 压缩质量,0-100,默认100
|
|
471
|
-
* @param options.format 图片格式,支持 "JPEG"、"PNG"、"WEBP",默认"JPEG"
|
|
472
|
-
* @param options.savePath 保存路径(可选)
|
|
473
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
474
|
-
* @returns Promise<压缩后的图片路径>
|
|
475
|
-
*/
|
|
476
|
-
async compressByQuality(imagePath, options = {}) {
|
|
477
|
-
var _a;
|
|
478
|
-
const { quality = 100, format = "JPEG", savePath, timeout } = options;
|
|
479
|
-
const response = await this.asyncCall("compressByQuality", { imagePath, quality, format, savePath }, timeout);
|
|
480
|
-
if (!response.isSuccess()) {
|
|
481
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "按质量压缩失败");
|
|
482
|
-
}
|
|
483
|
-
return response.data.filePath;
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* 按采样大小压缩
|
|
487
|
-
* @param imagePath 图片路径
|
|
488
|
-
* @param options 选项
|
|
489
|
-
* @param options.sampleSize 采样大小,默认1
|
|
490
|
-
* @param options.savePath 保存路径(可选)
|
|
491
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
492
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
493
|
-
* @returns Promise<压缩后的图片路径>
|
|
494
|
-
*/
|
|
495
|
-
async compressBySampleSize(imagePath, options = {}) {
|
|
496
|
-
var _a;
|
|
497
|
-
const { sampleSize = 1, savePath, format, timeout } = options;
|
|
498
|
-
const response = await this.asyncCall("compressBySampleSize", { imagePath, sampleSize, savePath, format }, timeout);
|
|
499
|
-
if (!response.isSuccess()) {
|
|
500
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "按采样大小压缩失败");
|
|
501
|
-
}
|
|
502
|
-
return response.data.filePath;
|
|
503
|
-
}
|
|
504
|
-
// ==================== 保存相关 ====================
|
|
505
|
-
/**
|
|
506
|
-
* 保存图片
|
|
507
|
-
* @param imagePath 图片路径
|
|
508
|
-
* @param options 选项
|
|
509
|
-
* @param options.savePath 保存路径(可选,不提供则自动生成)
|
|
510
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
511
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
512
|
-
* @returns Promise<保存结果>
|
|
513
|
-
*/
|
|
514
|
-
async save(imagePath, options = {}) {
|
|
515
|
-
var _a;
|
|
516
|
-
const { savePath, format = "PNG", timeout } = options;
|
|
517
|
-
const response = await this.asyncCall("save", { imagePath, savePath, format }, timeout);
|
|
518
|
-
if (!response.isSuccess()) {
|
|
519
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "保存图片失败");
|
|
520
|
-
}
|
|
521
|
-
return response.data;
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* 保存图片到相册
|
|
525
|
-
* @param imagePath 图片路径
|
|
526
|
-
* @param options 选项
|
|
527
|
-
* @param options.fileName 文件名(可选,不提供则自动生成)
|
|
528
|
-
* @param options.format 图片格式,支持 "PNG"、"JPEG"、"JPG"、"WEBP",默认"PNG"
|
|
529
|
-
* @param options.timeout 超时时间(秒),默认30秒
|
|
530
|
-
* @returns Promise<保存结果>
|
|
531
|
-
*/
|
|
532
|
-
async save2Album(imagePath, options = {}) {
|
|
533
|
-
var _a;
|
|
534
|
-
const { fileName, format = "PNG", timeout } = options;
|
|
535
|
-
const response = await this.asyncCall("save2Album", { imagePath, fileName, format }, timeout);
|
|
536
|
-
if (!response.isSuccess()) {
|
|
537
|
-
throw new Error(((_a = response.data) === null || _a === void 0 ? void 0 : _a.message) || "保存图片到相册失败");
|
|
538
|
-
}
|
|
539
|
-
return response.data;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
// 导出常量实例
|
|
543
|
-
export const imageUtils = new ImageUtils();
|
package/dist/ime/ime.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* IME 动作 ID 常量
|
|
3
|
-
*/
|
|
4
|
-
export declare enum ImeAction {
|
|
5
|
-
/** 无动作 */
|
|
6
|
-
NONE = 0,
|
|
7
|
-
/** 前往 */
|
|
8
|
-
GO = 2,
|
|
9
|
-
/** 搜索 */
|
|
10
|
-
SEARCH = 3,
|
|
11
|
-
/** 发送 */
|
|
12
|
-
SEND = 4,
|
|
13
|
-
/** 下一步 */
|
|
14
|
-
NEXT = 5,
|
|
15
|
-
/** 完成 */
|
|
16
|
-
DONE = 6,
|
|
17
|
-
/** 上一个 */
|
|
18
|
-
PREVIOUS = 7
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* 执行编辑器动作响应接口定义
|
|
22
|
-
*/
|
|
23
|
-
export interface PerformEditorActionResponse {
|
|
24
|
-
success: boolean;
|
|
25
|
-
actionId: number;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* 打开输入法设置响应接口定义
|
|
29
|
-
*/
|
|
30
|
-
export interface OpenInputMethodSettingsResponse {
|
|
31
|
-
success: boolean;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* 检查输入法是否启用响应接口定义
|
|
35
|
-
*/
|
|
36
|
-
export interface IsInputMethodEnabledResponse {
|
|
37
|
-
enabled: boolean;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 检查当前选中的输入法是否是当前输入法响应接口定义
|
|
41
|
-
*/
|
|
42
|
-
export interface IsCurrentInputMethodResponse {
|
|
43
|
-
isCurrent: boolean;
|
|
44
|
-
}
|
|
45
|
-
export declare class Ime {
|
|
46
|
-
/**
|
|
47
|
-
* 执行异步调用
|
|
48
|
-
* @param method 方法名
|
|
49
|
-
* @param args 参数对象
|
|
50
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
51
|
-
* @returns Promise<调用响应>
|
|
52
|
-
*/
|
|
53
|
-
private asyncCall;
|
|
54
|
-
/**
|
|
55
|
-
* 执行编辑器动作(如搜索)
|
|
56
|
-
* @param actionId 动作 ID,默认为 ImeAction.SEARCH
|
|
57
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
58
|
-
* @returns Promise<执行结果>
|
|
59
|
-
*/
|
|
60
|
-
performEditorAction(actionId?: number, timeout?: number): Promise<PerformEditorActionResponse>;
|
|
61
|
-
/**
|
|
62
|
-
* 跳转到输入法管理页面
|
|
63
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
64
|
-
* @returns Promise<执行结果>
|
|
65
|
-
*/
|
|
66
|
-
openInputMethodSettings(timeout?: number): Promise<OpenInputMethodSettingsResponse>;
|
|
67
|
-
/**
|
|
68
|
-
* 检查输入法是否启用
|
|
69
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
70
|
-
* @returns Promise<检查结果>
|
|
71
|
-
*/
|
|
72
|
-
isInputMethodEnabled(timeout?: number): Promise<IsInputMethodEnabledResponse>;
|
|
73
|
-
/**
|
|
74
|
-
* 检查当前选中的输入法是否是当前输入法
|
|
75
|
-
* @param timeout 超时时间(秒),默认30秒
|
|
76
|
-
* @returns Promise<检查结果>
|
|
77
|
-
*/
|
|
78
|
-
isCurrentInputMethod(timeout?: number): Promise<IsCurrentInputMethodResponse>;
|
|
79
|
-
}
|
|
80
|
-
export declare const ime: Ime;
|