@jieyin/editor-sdk 1.1.127 → 1.1.128
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/dist/deform.worker.js +393 -428
- package/dist/editor-sdk.es.js +7009 -7071
- package/dist/renderWorker.js +1605 -1669
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/deform.worker.js
CHANGED
|
@@ -1,133 +1,123 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
wasmReady = !1;
|
|
4
|
-
go = null;
|
|
5
|
-
wasmModule = null;
|
|
1
|
+
var Z = Object.defineProperty, ee = (s, t, e) => t in s ? Z(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e, $ = (s, t, e) => ee(s, typeof t != "symbol" ? t + "" : t, e);
|
|
2
|
+
const q = class T {
|
|
6
3
|
constructor() {
|
|
4
|
+
$(this, "wasmReady", !1), $(this, "go", null), $(this, "wasmModule", null);
|
|
7
5
|
}
|
|
8
6
|
static getInstance() {
|
|
9
|
-
return
|
|
7
|
+
return T.instance || (T.instance = new T()), T.instance;
|
|
10
8
|
}
|
|
11
9
|
/**
|
|
12
10
|
* 在 Worker 环境中加载 WASM 模块
|
|
13
11
|
* @param wasmUrl WASM 文件路径
|
|
14
12
|
* @param wasmExecUrl wasm_exec.js 路径
|
|
15
13
|
*/
|
|
16
|
-
async load(
|
|
17
|
-
if (this.wasmReady)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} else
|
|
39
|
-
return console.log(`🔍 [WASM] 使用默认绝对路径: /assets/${l}`), "/assets/" + l;
|
|
14
|
+
async load(t, e) {
|
|
15
|
+
if (!this.wasmReady)
|
|
16
|
+
try {
|
|
17
|
+
const r = (a) => {
|
|
18
|
+
if (e && a === "wasm_exec.js")
|
|
19
|
+
return e;
|
|
20
|
+
if (t && a === "perspective.wasm")
|
|
21
|
+
return t;
|
|
22
|
+
try {
|
|
23
|
+
let h = null;
|
|
24
|
+
if (typeof import.meta < "u" && import.meta.url ? h = import.meta.url : typeof self < "u" && self.location && (h = self.location.href), h) {
|
|
25
|
+
const f = new URL(h), y = f.pathname;
|
|
26
|
+
if (y.includes("/js/")) {
|
|
27
|
+
const m = "../assets/" + a;
|
|
28
|
+
return new URL(m, f).pathname;
|
|
29
|
+
} else if (y.includes("/assets/")) {
|
|
30
|
+
const m = "./" + a;
|
|
31
|
+
return new URL(m, f).pathname;
|
|
32
|
+
} else
|
|
33
|
+
return "/assets/" + a;
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
40
36
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
else
|
|
58
|
-
throw new Error("WASM 初始化失败");
|
|
59
|
-
} catch (t) {
|
|
60
|
-
throw console.error("❌ Worker WASM 加载失败:", t), this.wasmReady = !1, t;
|
|
61
|
-
}
|
|
37
|
+
return "/assets/" + a;
|
|
38
|
+
}, n = e || r("wasm_exec.js"), o = t || r("perspective.wasm");
|
|
39
|
+
await this.loadWasmExec(n);
|
|
40
|
+
const u = typeof self < "u" ? self : globalThis;
|
|
41
|
+
this.go = new u.Go();
|
|
42
|
+
const i = await fetch(o);
|
|
43
|
+
if (!i.ok)
|
|
44
|
+
throw new Error(`无法加载 WASM 文件: ${i.status}`);
|
|
45
|
+
const w = await i.arrayBuffer(), c = await WebAssembly.instantiate(w, this.go.importObject);
|
|
46
|
+
this.wasmModule = c.instance, this.go.run(this.wasmModule), this.wasmReady = !0;
|
|
47
|
+
const l = this.call("wasmInit");
|
|
48
|
+
if (!(l && l.success))
|
|
49
|
+
throw new Error("WASM 初始化失败");
|
|
50
|
+
} catch (r) {
|
|
51
|
+
throw this.wasmReady = !1, r;
|
|
52
|
+
}
|
|
62
53
|
}
|
|
63
54
|
/**
|
|
64
55
|
* 在 Worker 中加载 wasm_exec.js
|
|
65
56
|
* Module Worker 不支持 importScripts(),仅 Classic Worker 可尝试 importScripts,否则用 fetch + eval
|
|
66
57
|
*/
|
|
67
|
-
async loadWasmExec(
|
|
68
|
-
return new Promise((e,
|
|
58
|
+
async loadWasmExec(t) {
|
|
59
|
+
return new Promise((e, r) => {
|
|
69
60
|
if (!(typeof import.meta < "u" && import.meta.url) && typeof self.importScripts == "function")
|
|
70
61
|
try {
|
|
71
|
-
self.importScripts(
|
|
62
|
+
self.importScripts(t), e();
|
|
72
63
|
return;
|
|
73
|
-
} catch
|
|
74
|
-
console.warn("⚠️ importScripts 失败,使用 fetch:", s);
|
|
64
|
+
} catch {
|
|
75
65
|
}
|
|
76
|
-
fetch(
|
|
77
|
-
if (!
|
|
78
|
-
throw new Error(`HTTP ${
|
|
79
|
-
const
|
|
80
|
-
return !
|
|
81
|
-
}).then((
|
|
82
|
-
if (
|
|
83
|
-
throw
|
|
66
|
+
fetch(t).then((o) => {
|
|
67
|
+
if (!o.ok)
|
|
68
|
+
throw new Error(`HTTP ${o.status}: ${o.statusText} - URL: ${t}`);
|
|
69
|
+
const u = o.headers.get("content-type") || "";
|
|
70
|
+
return !u.includes("javascript") && u.includes("text/plain"), o.text();
|
|
71
|
+
}).then((o) => {
|
|
72
|
+
if (o.trim().startsWith("<!DOCTYPE") || o.trim().startsWith("<html"))
|
|
73
|
+
throw new Error(`返回的是 HTML 而不是 JavaScript,可能是 404 错误。URL: ${t}`);
|
|
84
74
|
try {
|
|
85
|
-
const
|
|
86
|
-
new Function("self",
|
|
87
|
-
} catch (
|
|
88
|
-
|
|
75
|
+
const u = typeof self < "u" ? self : globalThis;
|
|
76
|
+
new Function("self", o)(u), e();
|
|
77
|
+
} catch (u) {
|
|
78
|
+
r(new Error(`执行 wasm_exec.js 失败: ${u}`));
|
|
89
79
|
}
|
|
90
|
-
}).catch((
|
|
91
|
-
|
|
80
|
+
}).catch((o) => {
|
|
81
|
+
r(o);
|
|
92
82
|
});
|
|
93
83
|
});
|
|
94
84
|
}
|
|
95
85
|
/**
|
|
96
86
|
* 验证授权(通过 API)
|
|
97
87
|
*/
|
|
98
|
-
async verifyLicense(
|
|
88
|
+
async verifyLicense(t, e) {
|
|
99
89
|
if (!this.wasmReady)
|
|
100
90
|
return !1;
|
|
101
91
|
if (e)
|
|
102
92
|
try {
|
|
103
|
-
const
|
|
93
|
+
const r = this.getDeviceID(), n = this.getDomain(), u = await (await fetch(`${e}/jet_license/interface/license/verify`, {
|
|
104
94
|
method: "POST",
|
|
105
95
|
headers: {
|
|
106
96
|
"Content-Type": "application/json"
|
|
107
97
|
},
|
|
108
98
|
body: JSON.stringify({
|
|
109
|
-
token:
|
|
110
|
-
deviceId:
|
|
111
|
-
domain:
|
|
99
|
+
token: t,
|
|
100
|
+
deviceId: r,
|
|
101
|
+
domain: n
|
|
112
102
|
})
|
|
113
103
|
})).json();
|
|
114
|
-
if (!
|
|
115
|
-
const
|
|
116
|
-
throw new Error(
|
|
104
|
+
if (!u.success || !u.valid) {
|
|
105
|
+
const w = u.error || "License 验证失败";
|
|
106
|
+
throw new Error(w);
|
|
117
107
|
}
|
|
118
|
-
const
|
|
119
|
-
if (!
|
|
108
|
+
const i = this.call("wasmVerifyLicense", t);
|
|
109
|
+
if (!i.success || i.valid !== !0)
|
|
120
110
|
throw new Error("WASM 验证失败");
|
|
121
111
|
return !0;
|
|
122
|
-
} catch (
|
|
123
|
-
throw
|
|
112
|
+
} catch (r) {
|
|
113
|
+
throw r;
|
|
124
114
|
}
|
|
125
115
|
else
|
|
126
116
|
try {
|
|
127
|
-
const
|
|
128
|
-
return
|
|
129
|
-
} catch
|
|
130
|
-
return
|
|
117
|
+
const r = this.call("wasmVerifyLicense", t);
|
|
118
|
+
return r.success && r.valid === !0;
|
|
119
|
+
} catch {
|
|
120
|
+
return !1;
|
|
131
121
|
}
|
|
132
122
|
}
|
|
133
123
|
/**
|
|
@@ -145,83 +135,83 @@ class N {
|
|
|
145
135
|
/**
|
|
146
136
|
* 计算透视变换矩阵
|
|
147
137
|
*/
|
|
148
|
-
calcPerspectiveMatrix(
|
|
138
|
+
calcPerspectiveMatrix(t) {
|
|
149
139
|
if (!this.wasmReady)
|
|
150
140
|
throw new Error("WASM 未加载");
|
|
151
|
-
if (
|
|
141
|
+
if (t.length !== 4)
|
|
152
142
|
throw new Error("需要恰好 4 个点");
|
|
153
143
|
try {
|
|
154
|
-
const e = this.call("wasmCalcPerspectiveMatrix", JSON.stringify(
|
|
144
|
+
const e = this.call("wasmCalcPerspectiveMatrix", JSON.stringify(t));
|
|
155
145
|
if (!e.success)
|
|
156
146
|
throw new Error(e.error || "计算失败");
|
|
157
147
|
return e.matrix;
|
|
158
148
|
} catch (e) {
|
|
159
|
-
throw
|
|
149
|
+
throw e;
|
|
160
150
|
}
|
|
161
151
|
}
|
|
162
152
|
/**
|
|
163
153
|
* 矩阵求逆
|
|
164
154
|
*/
|
|
165
|
-
invertMatrix(
|
|
155
|
+
invertMatrix(t) {
|
|
166
156
|
if (!this.wasmReady)
|
|
167
157
|
throw new Error("WASM 未加载");
|
|
168
158
|
try {
|
|
169
|
-
const e = this.call("wasmInvertMatrix", JSON.stringify(
|
|
159
|
+
const e = this.call("wasmInvertMatrix", JSON.stringify(t));
|
|
170
160
|
if (!e.success)
|
|
171
161
|
throw new Error(e.error || "矩阵求逆失败");
|
|
172
162
|
return e.matrix;
|
|
173
163
|
} catch (e) {
|
|
174
|
-
throw
|
|
164
|
+
throw e;
|
|
175
165
|
}
|
|
176
166
|
}
|
|
177
167
|
/**
|
|
178
168
|
* 应用透视变换到单个点
|
|
179
169
|
*/
|
|
180
|
-
applyPerspective(
|
|
170
|
+
applyPerspective(t, e, r) {
|
|
181
171
|
if (!this.wasmReady)
|
|
182
172
|
throw new Error("WASM 未加载");
|
|
183
173
|
try {
|
|
184
|
-
const
|
|
185
|
-
if (!
|
|
186
|
-
throw new Error(
|
|
187
|
-
return { x:
|
|
188
|
-
} catch (
|
|
189
|
-
throw
|
|
174
|
+
const n = this.call("wasmApplyPerspective", t, e, JSON.stringify(r));
|
|
175
|
+
if (!n.success)
|
|
176
|
+
throw new Error(n.error || "变换失败");
|
|
177
|
+
return { x: n.x, y: n.y };
|
|
178
|
+
} catch (n) {
|
|
179
|
+
throw n;
|
|
190
180
|
}
|
|
191
181
|
}
|
|
192
182
|
/**
|
|
193
183
|
* 应用逆透视变换到单个点
|
|
194
184
|
*/
|
|
195
|
-
applyInversePerspective(
|
|
185
|
+
applyInversePerspective(t, e, r) {
|
|
196
186
|
if (!this.wasmReady)
|
|
197
187
|
throw new Error("WASM 未加载");
|
|
198
188
|
try {
|
|
199
|
-
const
|
|
200
|
-
if (!
|
|
201
|
-
throw new Error(
|
|
202
|
-
return { x:
|
|
203
|
-
} catch (
|
|
204
|
-
throw
|
|
189
|
+
const n = this.call("wasmApplyInversePerspective", t, e, JSON.stringify(r));
|
|
190
|
+
if (!n.success)
|
|
191
|
+
throw new Error(n.error || "逆变换失败");
|
|
192
|
+
return { x: n.x, y: n.y };
|
|
193
|
+
} catch (n) {
|
|
194
|
+
throw n;
|
|
205
195
|
}
|
|
206
196
|
}
|
|
207
197
|
/**
|
|
208
198
|
* 批量变换点(高性能)
|
|
209
199
|
*/
|
|
210
|
-
transformPoints(
|
|
200
|
+
transformPoints(t, e, r = !1) {
|
|
211
201
|
if (!this.wasmReady)
|
|
212
202
|
throw new Error("WASM 未加载");
|
|
213
203
|
try {
|
|
214
|
-
const
|
|
204
|
+
const n = this.call(
|
|
215
205
|
"wasmTransformPoints",
|
|
216
|
-
JSON.stringify(
|
|
206
|
+
JSON.stringify(t),
|
|
217
207
|
JSON.stringify(e),
|
|
218
|
-
|
|
208
|
+
r
|
|
219
209
|
);
|
|
220
|
-
if (!
|
|
221
|
-
throw new Error(
|
|
222
|
-
return JSON.parse(
|
|
223
|
-
} catch (
|
|
224
|
-
throw
|
|
210
|
+
if (!n.success)
|
|
211
|
+
throw new Error(n.error || "批量变换失败");
|
|
212
|
+
return JSON.parse(n.points);
|
|
213
|
+
} catch (n) {
|
|
214
|
+
throw n;
|
|
225
215
|
}
|
|
226
216
|
}
|
|
227
217
|
/**
|
|
@@ -233,402 +223,398 @@ class N {
|
|
|
233
223
|
/**
|
|
234
224
|
* 双三次插值点计算
|
|
235
225
|
*/
|
|
236
|
-
getBicubicPoint(
|
|
226
|
+
getBicubicPoint(t, e, r) {
|
|
237
227
|
if (!this.wasmReady)
|
|
238
228
|
throw new Error("WASM 未加载");
|
|
239
|
-
if (
|
|
229
|
+
if (r.length !== 16)
|
|
240
230
|
throw new Error("需要恰好 16 个点");
|
|
241
231
|
try {
|
|
242
|
-
const
|
|
243
|
-
if (!
|
|
244
|
-
throw new Error(
|
|
245
|
-
return { x:
|
|
246
|
-
} catch (
|
|
247
|
-
throw
|
|
232
|
+
const n = this.call("wasmGetBicubicPoint", t, e, JSON.stringify(r));
|
|
233
|
+
if (!n.success)
|
|
234
|
+
throw new Error(n.error || "计算失败");
|
|
235
|
+
return { x: n.x, y: n.y };
|
|
236
|
+
} catch (n) {
|
|
237
|
+
throw n;
|
|
248
238
|
}
|
|
249
239
|
}
|
|
250
240
|
/**
|
|
251
241
|
* 双线性插值点计算
|
|
252
242
|
*/
|
|
253
|
-
getBilinearPoint(
|
|
243
|
+
getBilinearPoint(t, e, r) {
|
|
254
244
|
if (!this.wasmReady)
|
|
255
245
|
throw new Error("WASM 未加载");
|
|
256
|
-
if (
|
|
246
|
+
if (r.length !== 4)
|
|
257
247
|
throw new Error("需要恰好 4 个点");
|
|
258
248
|
try {
|
|
259
|
-
const
|
|
260
|
-
if (!
|
|
261
|
-
throw new Error(
|
|
262
|
-
return { x:
|
|
263
|
-
} catch (
|
|
264
|
-
throw
|
|
249
|
+
const n = this.call("wasmGetBilinearPoint", t, e, JSON.stringify(r));
|
|
250
|
+
if (!n.success)
|
|
251
|
+
throw new Error(n.error || "计算失败");
|
|
252
|
+
return { x: n.x, y: n.y };
|
|
253
|
+
} catch (n) {
|
|
254
|
+
throw n;
|
|
265
255
|
}
|
|
266
256
|
}
|
|
267
257
|
/**
|
|
268
258
|
* 任意网格点插值计算
|
|
269
259
|
*/
|
|
270
|
-
getArbitraryMeshPoint(
|
|
260
|
+
getArbitraryMeshPoint(t, e, r, n) {
|
|
271
261
|
if (!this.wasmReady)
|
|
272
262
|
throw new Error("WASM 未加载");
|
|
273
263
|
try {
|
|
274
|
-
const
|
|
275
|
-
if (!
|
|
276
|
-
throw new Error(
|
|
277
|
-
return { x:
|
|
278
|
-
} catch (
|
|
279
|
-
throw
|
|
264
|
+
const o = this.call("wasmGetArbitraryMeshPoint", t, e, JSON.stringify(r), n);
|
|
265
|
+
if (!o.success)
|
|
266
|
+
throw new Error(o.error || "计算失败");
|
|
267
|
+
return { x: o.x, y: o.y };
|
|
268
|
+
} catch (o) {
|
|
269
|
+
throw o;
|
|
280
270
|
}
|
|
281
271
|
}
|
|
282
272
|
/**
|
|
283
273
|
* 批量双三次插值(高性能优化)
|
|
284
274
|
* 一次性处理多个坐标,避免频繁的 JS/WASM 边界调用
|
|
285
275
|
*/
|
|
286
|
-
batchBicubicInterpolation(
|
|
276
|
+
batchBicubicInterpolation(t, e) {
|
|
287
277
|
if (!this.wasmReady)
|
|
288
278
|
throw new Error("WASM 未加载");
|
|
289
279
|
if (e.length !== 16)
|
|
290
280
|
throw new Error("需要恰好 16 个控制点");
|
|
291
281
|
try {
|
|
292
|
-
const
|
|
282
|
+
const r = this.call(
|
|
293
283
|
"wasmBatchBicubicInterpolation",
|
|
294
|
-
JSON.stringify(
|
|
284
|
+
JSON.stringify(t),
|
|
295
285
|
JSON.stringify(e)
|
|
296
286
|
);
|
|
297
|
-
if (!
|
|
298
|
-
throw new Error(
|
|
299
|
-
return
|
|
300
|
-
} catch (
|
|
301
|
-
throw
|
|
287
|
+
if (!r.success)
|
|
288
|
+
throw new Error(r.error || "批量双三次插值失败");
|
|
289
|
+
return r.points;
|
|
290
|
+
} catch (r) {
|
|
291
|
+
throw r;
|
|
302
292
|
}
|
|
303
293
|
}
|
|
304
294
|
/**
|
|
305
295
|
* 批量双线性插值(高性能优化)
|
|
306
296
|
*/
|
|
307
|
-
batchBilinearInterpolation(
|
|
297
|
+
batchBilinearInterpolation(t, e) {
|
|
308
298
|
if (!this.wasmReady)
|
|
309
299
|
throw new Error("WASM 未加载");
|
|
310
300
|
if (e.length !== 4)
|
|
311
301
|
throw new Error("需要恰好 4 个控制点");
|
|
312
302
|
try {
|
|
313
|
-
const
|
|
303
|
+
const r = this.call(
|
|
314
304
|
"wasmBatchBilinearInterpolation",
|
|
315
|
-
JSON.stringify(
|
|
305
|
+
JSON.stringify(t),
|
|
316
306
|
JSON.stringify(e)
|
|
317
307
|
);
|
|
318
|
-
if (!
|
|
319
|
-
throw new Error(
|
|
320
|
-
return
|
|
321
|
-
} catch (
|
|
322
|
-
throw
|
|
308
|
+
if (!r.success)
|
|
309
|
+
throw new Error(r.error || "批量双线性插值失败");
|
|
310
|
+
return r.points;
|
|
311
|
+
} catch (r) {
|
|
312
|
+
throw r;
|
|
323
313
|
}
|
|
324
314
|
}
|
|
325
315
|
/**
|
|
326
316
|
* 批量任意网格插值(高性能优化)
|
|
327
317
|
*/
|
|
328
|
-
batchArbitraryMeshInterpolation(
|
|
318
|
+
batchArbitraryMeshInterpolation(t, e, r) {
|
|
329
319
|
if (!this.wasmReady)
|
|
330
320
|
throw new Error("WASM 未加载");
|
|
331
321
|
try {
|
|
332
|
-
const
|
|
322
|
+
const n = this.call(
|
|
333
323
|
"wasmBatchArbitraryMeshInterpolation",
|
|
334
|
-
JSON.stringify(
|
|
324
|
+
JSON.stringify(t),
|
|
335
325
|
JSON.stringify(e),
|
|
336
|
-
|
|
326
|
+
r
|
|
337
327
|
);
|
|
338
|
-
if (!
|
|
339
|
-
throw new Error(
|
|
340
|
-
return
|
|
341
|
-
} catch (
|
|
342
|
-
throw
|
|
328
|
+
if (!n.success)
|
|
329
|
+
throw new Error(n.error || "批量网格插值失败");
|
|
330
|
+
return n.points;
|
|
331
|
+
} catch (n) {
|
|
332
|
+
throw n;
|
|
343
333
|
}
|
|
344
334
|
}
|
|
345
335
|
/**
|
|
346
336
|
* 调用 WASM 函数
|
|
347
337
|
*/
|
|
348
|
-
call(
|
|
338
|
+
call(t, ...e) {
|
|
349
339
|
if (!this.wasmReady)
|
|
350
340
|
throw new Error("WASM 未加载");
|
|
351
|
-
const
|
|
352
|
-
if (!
|
|
353
|
-
throw new Error(`函数不存在: ${
|
|
341
|
+
const n = (typeof self < "u" ? self : globalThis)[t];
|
|
342
|
+
if (!n)
|
|
343
|
+
throw new Error(`函数不存在: ${t}`);
|
|
354
344
|
try {
|
|
355
|
-
return
|
|
356
|
-
} catch (
|
|
357
|
-
throw
|
|
345
|
+
return n(...e);
|
|
346
|
+
} catch (o) {
|
|
347
|
+
throw o;
|
|
358
348
|
}
|
|
359
349
|
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
}).catch((
|
|
366
|
-
console.warn("⚠️ [deform.worker] WASM 初始化失败:", r);
|
|
350
|
+
};
|
|
351
|
+
$(q, "instance");
|
|
352
|
+
let te = q, d = null, L = !1, C = null, b = null, _ = null, O = null, U = null;
|
|
353
|
+
function re(s) {
|
|
354
|
+
b = s.licenseToken, _ = s.licenseApiUrl, O = s.deviceId, U = s.domain, self.LICENSE_TOKEN = b, self.LICENSE_API_URL = _, self.DEVICE_ID = O, self.DOMAIN = U, d || (C && !L && (C = null), z().then(() => {
|
|
355
|
+
}).catch((t) => {
|
|
367
356
|
}));
|
|
368
357
|
}
|
|
369
|
-
async function
|
|
370
|
-
return
|
|
358
|
+
async function z() {
|
|
359
|
+
return d ? void 0 : L ? C || Promise.resolve() : b || self.LICENSE_TOKEN ? (L = !0, C = (async () => {
|
|
371
360
|
try {
|
|
372
|
-
|
|
373
|
-
const
|
|
374
|
-
const
|
|
375
|
-
if (
|
|
376
|
-
return h;
|
|
377
|
-
if (a === "wasm_exec.js" && l)
|
|
361
|
+
d = te.getInstance();
|
|
362
|
+
const t = (c) => {
|
|
363
|
+
const l = self.WASM_URL, a = self.WASM_EXEC_URL;
|
|
364
|
+
if (c === "perspective.wasm" && l)
|
|
378
365
|
return l;
|
|
366
|
+
if (c === "wasm_exec.js" && a)
|
|
367
|
+
return a;
|
|
379
368
|
try {
|
|
380
|
-
let
|
|
381
|
-
if (typeof import.meta < "u" && import.meta.url ?
|
|
382
|
-
const f = new URL(
|
|
383
|
-
if (
|
|
384
|
-
const m = "../assets/" +
|
|
385
|
-
return
|
|
386
|
-
} else if (
|
|
387
|
-
const m = "./" +
|
|
388
|
-
return
|
|
369
|
+
let h = null;
|
|
370
|
+
if (typeof import.meta < "u" && import.meta.url ? h = import.meta.url : typeof self < "u" && self.location && (h = self.location.href), h) {
|
|
371
|
+
const f = new URL(h), y = f.pathname;
|
|
372
|
+
if (y.includes("/js/")) {
|
|
373
|
+
const m = "../assets/" + c;
|
|
374
|
+
return new URL(m, f).pathname;
|
|
375
|
+
} else if (y.includes("/assets/")) {
|
|
376
|
+
const m = "./" + c;
|
|
377
|
+
return new URL(m, f).pathname;
|
|
389
378
|
} else
|
|
390
|
-
return
|
|
379
|
+
return "/assets/" + c;
|
|
391
380
|
}
|
|
392
|
-
} catch
|
|
393
|
-
console.warn("⚠️ [deform.worker] 无法计算 WASM 相对路径,使用默认路径:", w);
|
|
381
|
+
} catch {
|
|
394
382
|
}
|
|
395
|
-
return "/assets/" +
|
|
396
|
-
}, e = self.WASM_URL ||
|
|
397
|
-
|
|
398
|
-
const
|
|
399
|
-
if (!
|
|
383
|
+
return "/assets/" + c;
|
|
384
|
+
}, e = self.WASM_URL || t("perspective.wasm"), r = self.WASM_EXEC_URL || t("wasm_exec.js");
|
|
385
|
+
await d.load(e, r);
|
|
386
|
+
const n = b || self.LICENSE_TOKEN, o = _ || self.LICENSE_API_URL, u = O || self.DEVICE_ID, i = U || self.DOMAIN;
|
|
387
|
+
if (!n)
|
|
400
388
|
throw new Error("LICENSE_TOKEN 未设置,无法使用 WASM 功能");
|
|
401
|
-
if (!await
|
|
389
|
+
if (!await d.verifyLicense(n, o))
|
|
402
390
|
throw new Error("WASM License 验证失败,无法使用 WASM 功能");
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
throw console.error("❌ WASM 加载或验证失败:", r), g = null, A = null, r;
|
|
391
|
+
} catch (t) {
|
|
392
|
+
throw d = null, C = null, t;
|
|
406
393
|
} finally {
|
|
407
|
-
|
|
394
|
+
L = !1;
|
|
408
395
|
}
|
|
409
|
-
})(),
|
|
396
|
+
})(), C) : Promise.resolve();
|
|
410
397
|
}
|
|
411
|
-
function
|
|
412
|
-
return "naturalWidth" in
|
|
398
|
+
function X(s) {
|
|
399
|
+
return "naturalWidth" in s && s.naturalWidth ? { width: s.naturalWidth, height: s.naturalHeight } : "width" in s ? { width: s.width, height: s.height } : { width: 0, height: 0 };
|
|
413
400
|
}
|
|
414
|
-
function
|
|
415
|
-
if (!
|
|
401
|
+
function ne(s, t) {
|
|
402
|
+
if (!s || !s.bounds)
|
|
416
403
|
throw new Error("Invalid layer data: missing bounds");
|
|
417
|
-
const e =
|
|
418
|
-
if (
|
|
419
|
-
return { ...
|
|
420
|
-
const
|
|
404
|
+
const e = s.bounds;
|
|
405
|
+
if (t && t.width > 0 && t.height > 0)
|
|
406
|
+
return { ...s };
|
|
407
|
+
const r = s.size || s.placedLayer || {
|
|
421
408
|
width: e.width,
|
|
422
409
|
height: e.height
|
|
423
|
-
},
|
|
424
|
-
return
|
|
425
|
-
(
|
|
426
|
-
(
|
|
427
|
-
(
|
|
428
|
-
(
|
|
429
|
-
(
|
|
430
|
-
(
|
|
431
|
-
(
|
|
432
|
-
(
|
|
433
|
-
]),
|
|
410
|
+
}, n = r.width / e.width, o = r.height / e.height, u = { ...s };
|
|
411
|
+
return s.transform && s.transform.length === 8 && (u.transform = [
|
|
412
|
+
(s.transform[0] - e.left) * n,
|
|
413
|
+
(s.transform[1] - e.top) * o,
|
|
414
|
+
(s.transform[2] - e.left) * n,
|
|
415
|
+
(s.transform[3] - e.top) * o,
|
|
416
|
+
(s.transform[4] - e.left) * n,
|
|
417
|
+
(s.transform[5] - e.top) * o,
|
|
418
|
+
(s.transform[6] - e.left) * n,
|
|
419
|
+
(s.transform[7] - e.top) * o
|
|
420
|
+
]), u;
|
|
434
421
|
}
|
|
435
|
-
function
|
|
436
|
-
return
|
|
422
|
+
function se(s) {
|
|
423
|
+
return s.error, s;
|
|
437
424
|
}
|
|
438
|
-
function
|
|
439
|
-
if (!
|
|
425
|
+
function oe(s, t, e) {
|
|
426
|
+
if (!s || !t || !e)
|
|
440
427
|
return "Invalid Parameters";
|
|
441
|
-
const
|
|
442
|
-
if (!
|
|
428
|
+
const r = "naturalWidth" in t ? t.naturalWidth : "width" in t ? t.width : 0, n = "naturalHeight" in t ? t.naturalHeight : "height" in t ? t.height : 0;
|
|
429
|
+
if (!r || !n)
|
|
443
430
|
return "Image Not Loaded";
|
|
444
|
-
|
|
445
|
-
let
|
|
446
|
-
if (e.size && e.size.width ? (
|
|
431
|
+
s.imageSmoothingEnabled = !0, s.imageSmoothingQuality = "high";
|
|
432
|
+
let o = null, u = null, i = null, w = null, c = 0, l = 0, a = null, h = "Unknown";
|
|
433
|
+
if (e.size && e.size.width ? (c = e.size.width, l = e.size.height) : e.placedLayer && e.placedLayer.width ? (c = e.placedLayer.width, l = e.placedLayer.height) : e.originalWidth && (c = e.originalWidth, l = e.originalHeight), e.meshPoints && e.meshPoints.length > 0 && (o = e.meshPoints), e.transform && e.transform.length === 8) {
|
|
447
434
|
const f = e.transform;
|
|
448
|
-
|
|
435
|
+
u = [
|
|
449
436
|
{ x: f[0], y: f[1] },
|
|
450
437
|
{ x: f[2], y: f[3] },
|
|
451
438
|
{ x: f[4], y: f[5] },
|
|
452
439
|
{ x: f[6], y: f[7] }
|
|
453
440
|
];
|
|
454
441
|
}
|
|
455
|
-
return e.quiltSliceX && (
|
|
442
|
+
return e.quiltSliceX && (i = e.quiltSliceX), e.quiltSliceY && (w = e.quiltSliceY), e.filterList && (a = e.filterList.find((f) => f.type === "puppet" && f.enabled)), c === 0 && i && i.length > 0 && (c = i[i.length - 1]), c === 0 && (c = 1e3), l === 0 && (l = 1e3), a && a.filter && a.filter.puppetShapeList && a.filter.puppetShapeList.length > 0 && u ? (ie(s, t, u, a.filter.puppetShapeList[0]), h = "Puppet Warp") : o && u ? i && w ? (ce(s, t, u, o, i, w, c, l), h = "Quilt Mesh") : o.length === 16 ? (ue(s, t, u, o), h = "Std Mesh (16pt)") : (ae(s, t, u, o), h = "Auto-Fit Mesh") : o ? (fe(s, t, o), h = "Direct Mesh") : u && (Y(s, t, u), h = "Transform Only"), h;
|
|
456
443
|
}
|
|
457
|
-
function
|
|
458
|
-
if (!
|
|
444
|
+
function ie(s, t, e, r, n, o) {
|
|
445
|
+
if (!r.originalVertexArray || !r.deformedVertexArray || !r.indexArray)
|
|
459
446
|
return;
|
|
460
|
-
const
|
|
461
|
-
if (!
|
|
462
|
-
|
|
447
|
+
const u = G(e), i = he(u);
|
|
448
|
+
if (!i) {
|
|
449
|
+
Y(s, t, e);
|
|
463
450
|
return;
|
|
464
451
|
}
|
|
465
|
-
const
|
|
466
|
-
for (let
|
|
467
|
-
const
|
|
468
|
-
if (!
|
|
469
|
-
const m =
|
|
470
|
-
j(
|
|
452
|
+
const w = r.originalVertexArray, c = r.deformedVertexArray, l = r.indexArray;
|
|
453
|
+
for (let a = 0; a < l.length; a += 3) {
|
|
454
|
+
const h = l[a], f = l[a + 1], y = l[a + 2];
|
|
455
|
+
if (!w[h] || !w[f] || !w[y]) continue;
|
|
456
|
+
const m = w[h], A = w[f], E = w[y], g = V(m.x, m.y, i), M = V(A.x, A.y, i), x = V(E.x, E.y, i), p = X(t), S = { x: g.x * p.width, y: g.y * p.height }, W = { x: M.x * p.width, y: M.y * p.height }, D = { x: x.x * p.width, y: x.y * p.height }, B = c[h], F = c[f], P = c[y];
|
|
457
|
+
j(s, t, S, W, D, B, F, P);
|
|
471
458
|
}
|
|
472
459
|
}
|
|
473
|
-
function
|
|
474
|
-
let
|
|
475
|
-
|
|
476
|
-
|
|
460
|
+
function ue(s, t, e, r) {
|
|
461
|
+
let n = 1 / 0, o = -1 / 0, u = 1 / 0, i = -1 / 0;
|
|
462
|
+
r.forEach((a) => {
|
|
463
|
+
n = Math.min(n, a.x), o = Math.max(o, a.x), u = Math.min(u, a.y), i = Math.max(i, a.y);
|
|
477
464
|
});
|
|
478
|
-
const
|
|
479
|
-
if (
|
|
480
|
-
|
|
465
|
+
const w = o - n, c = i - u;
|
|
466
|
+
if (w < 1 || c < 1) {
|
|
467
|
+
Y(s, t, e);
|
|
481
468
|
return;
|
|
482
469
|
}
|
|
483
|
-
const
|
|
484
|
-
const
|
|
485
|
-
return
|
|
470
|
+
const l = r.map((a) => {
|
|
471
|
+
const h = (a.x - n) / w, f = (a.y - u) / c;
|
|
472
|
+
return N(h, f, e);
|
|
486
473
|
});
|
|
487
|
-
|
|
474
|
+
H(s, t, l, "bicubic", 4, 40);
|
|
488
475
|
}
|
|
489
|
-
function
|
|
490
|
-
const
|
|
491
|
-
let
|
|
492
|
-
|
|
493
|
-
|
|
476
|
+
function ce(s, t, e, r, n, o, u, i) {
|
|
477
|
+
const w = G(e);
|
|
478
|
+
let c = 1 / 0, l = -1 / 0, a = 1 / 0, h = -1 / 0;
|
|
479
|
+
r.forEach((E) => {
|
|
480
|
+
c = Math.min(c, E.x), l = Math.max(l, E.x), a = Math.min(a, E.y), h = Math.max(h, E.y);
|
|
494
481
|
});
|
|
495
|
-
const f =
|
|
496
|
-
for (let
|
|
497
|
-
for (let
|
|
498
|
-
const
|
|
482
|
+
const f = l - c || 1, y = h - a || 1, m = n.length - 1, A = o.length - 1;
|
|
483
|
+
for (let E = 0; E < A; E++)
|
|
484
|
+
for (let g = 0; g < m; g++) {
|
|
485
|
+
const M = E * 3, x = g * 3, p = [], S = m * 3 + 1;
|
|
499
486
|
try {
|
|
500
487
|
for (let I = 0; I < 4; I++)
|
|
501
|
-
for (let
|
|
502
|
-
const J = (
|
|
503
|
-
|
|
488
|
+
for (let R = 0; R < 4; R++) {
|
|
489
|
+
const J = (M + I) * S + (x + R);
|
|
490
|
+
r[J] && p.push(r[J]);
|
|
504
491
|
}
|
|
505
492
|
} catch {
|
|
506
493
|
continue;
|
|
507
494
|
}
|
|
508
495
|
if (p.length < 16) continue;
|
|
509
|
-
const
|
|
510
|
-
const
|
|
511
|
-
return
|
|
512
|
-
}),
|
|
513
|
-
|
|
496
|
+
const W = p.map((I) => {
|
|
497
|
+
const R = (I.x - c) / f, J = (I.y - a) / y;
|
|
498
|
+
return Q(R, J, w);
|
|
499
|
+
}), D = n[g] / u, B = n[g + 1] / u, F = o[E] / i, P = o[E + 1] / i;
|
|
500
|
+
le(s, t, W, D, B, F, P);
|
|
514
501
|
}
|
|
515
502
|
}
|
|
516
|
-
function
|
|
517
|
-
const
|
|
518
|
-
let
|
|
519
|
-
|
|
520
|
-
|
|
503
|
+
function ae(s, t, e, r) {
|
|
504
|
+
const n = G(e);
|
|
505
|
+
let o = 1 / 0, u = -1 / 0, i = 1 / 0, w = -1 / 0;
|
|
506
|
+
r.forEach((f) => {
|
|
507
|
+
o = Math.min(o, f.x), u = Math.max(u, f.x), i = Math.min(i, f.y), w = Math.max(w, f.y);
|
|
521
508
|
});
|
|
522
|
-
const
|
|
523
|
-
const
|
|
524
|
-
return
|
|
525
|
-
}),
|
|
526
|
-
|
|
509
|
+
const c = u - o || 1, l = w - i || 1, a = r.map((f) => {
|
|
510
|
+
const y = (f.x - o) / c, m = (f.y - i) / l;
|
|
511
|
+
return Q(y, m, n);
|
|
512
|
+
}), h = Math.floor(Math.sqrt(r.length)) || 4;
|
|
513
|
+
H(s, t, a, "grid", h, 40);
|
|
527
514
|
}
|
|
528
|
-
function
|
|
529
|
-
const
|
|
530
|
-
for (let
|
|
531
|
-
for (let
|
|
532
|
-
const f =
|
|
533
|
-
j(
|
|
515
|
+
function le(s, t, e, r, n, o, u) {
|
|
516
|
+
const w = X(t), c = w.width, l = w.height;
|
|
517
|
+
for (let a = 0; a < 20; a++)
|
|
518
|
+
for (let h = 0; h < 20; h++) {
|
|
519
|
+
const f = h / 20, y = a / 20, m = (h + 1) / 20, A = (a + 1) / 20, E = r + f * (n - r), g = r + m * (n - r), M = o + y * (u - o), x = o + A * (u - o), p = { x: E * c, y: M * l }, S = { x: g * c, y: M * l }, W = { x: E * c, y: x * l }, D = { x: g * c, y: x * l }, B = v(f, y, e), F = v(m, y, e), P = v(f, A, e), I = v(m, A, e);
|
|
520
|
+
j(s, t, p, S, W, B, F, P), j(s, t, S, D, W, F, I, P);
|
|
534
521
|
}
|
|
535
522
|
}
|
|
536
|
-
function
|
|
537
|
-
|
|
523
|
+
function Y(s, t, e) {
|
|
524
|
+
H(s, t, e, "bilinear", 0, 10);
|
|
538
525
|
}
|
|
539
|
-
function
|
|
540
|
-
|
|
526
|
+
function fe(s, t, e) {
|
|
527
|
+
H(s, t, e, "bicubic", 4, 40);
|
|
541
528
|
}
|
|
542
|
-
function
|
|
543
|
-
const
|
|
544
|
-
for (let
|
|
545
|
-
for (let
|
|
546
|
-
const
|
|
547
|
-
let
|
|
548
|
-
|
|
529
|
+
function H(s, t, e, r, n, o) {
|
|
530
|
+
const u = X(t), i = u.width, w = u.height;
|
|
531
|
+
for (let c = 0; c < o; c++)
|
|
532
|
+
for (let l = 0; l < o; l++) {
|
|
533
|
+
const a = l / o, h = c / o, f = (l + 1) / o, y = (c + 1) / o, m = { x: a * i, y: h * w }, A = { x: f * i, y: h * w }, E = { x: a * i, y: y * w }, g = { x: f * i, y: y * w };
|
|
534
|
+
let M, x, p, S;
|
|
535
|
+
r === "bicubic" ? (M = v(a, h, e), x = v(f, h, e), p = v(a, y, e), S = v(f, y, e)) : r === "grid" ? (M = k(a, h, e, n), x = k(f, h, e, n), p = k(a, y, e, n), S = k(f, y, e, n)) : (M = N(a, h, e), x = N(f, h, e), p = N(a, y, e), S = N(f, y, e)), j(s, t, m, A, E, M, x, p), j(s, t, A, g, E, x, S, p);
|
|
549
536
|
}
|
|
550
537
|
}
|
|
551
|
-
function
|
|
552
|
-
const e = 1 -
|
|
553
|
-
return
|
|
538
|
+
function K(s, t) {
|
|
539
|
+
const e = 1 - t;
|
|
540
|
+
return s === 0 ? e * e * e : s === 1 ? 3 * e * e * t : s === 2 ? 3 * e * t * t : t * t * t;
|
|
554
541
|
}
|
|
555
|
-
function
|
|
556
|
-
let
|
|
557
|
-
for (let
|
|
558
|
-
for (let
|
|
559
|
-
const
|
|
560
|
-
|
|
542
|
+
function v(s, t, e) {
|
|
543
|
+
let r = 0, n = 0;
|
|
544
|
+
for (let o = 0; o < 4; o++)
|
|
545
|
+
for (let u = 0; u < 4; u++) {
|
|
546
|
+
const i = K(o, t) * K(u, s);
|
|
547
|
+
r += e[o * 4 + u].x * i, n += e[o * 4 + u].y * i;
|
|
561
548
|
}
|
|
562
|
-
return { x:
|
|
549
|
+
return { x: r, y: n };
|
|
563
550
|
}
|
|
564
|
-
function
|
|
565
|
-
const
|
|
566
|
-
return { x:
|
|
551
|
+
function N(s, t, e) {
|
|
552
|
+
const r = (1 - s) * (1 - t) * e[0].x + s * (1 - t) * e[1].x + s * t * e[2].x + (1 - s) * t * e[3].x, n = (1 - s) * (1 - t) * e[0].y + s * (1 - t) * e[1].y + s * t * e[2].y + (1 - s) * t * e[3].y;
|
|
553
|
+
return { x: r, y: n };
|
|
567
554
|
}
|
|
568
|
-
function
|
|
569
|
-
const
|
|
570
|
-
let
|
|
571
|
-
|
|
572
|
-
const
|
|
573
|
-
return { x: m, y };
|
|
555
|
+
function k(s, t, e, r) {
|
|
556
|
+
const n = r - 1, o = s * n, u = t * n;
|
|
557
|
+
let i = Math.floor(o), w = Math.floor(u);
|
|
558
|
+
i >= n && (i = n - 1), w >= n && (w = n - 1), i < 0 && (i = 0), w < 0 && (w = 0);
|
|
559
|
+
const c = o - i, l = u - w, a = e[w * r + i], h = e[w * r + (i + 1)], f = e[(w + 1) * r + i], y = e[(w + 1) * r + (i + 1)], m = (1 - c) * (1 - l) * a.x + c * (1 - l) * h.x + c * l * y.x + (1 - c) * l * f.x, A = (1 - c) * (1 - l) * a.y + c * (1 - l) * h.y + c * l * y.y + (1 - c) * l * f.y;
|
|
560
|
+
return { x: m, y: A };
|
|
574
561
|
}
|
|
575
|
-
function
|
|
576
|
-
if (!
|
|
562
|
+
function G(s) {
|
|
563
|
+
if (!d || !d.isReady())
|
|
577
564
|
throw new Error("WASM 模块未加载,无法计算透视变换矩阵");
|
|
578
565
|
try {
|
|
579
|
-
return
|
|
580
|
-
} catch (
|
|
581
|
-
throw new Error(`WASM 计算透视矩阵失败: ${
|
|
566
|
+
return d.calcPerspectiveMatrix(s);
|
|
567
|
+
} catch (t) {
|
|
568
|
+
throw new Error(`WASM 计算透视矩阵失败: ${t}`);
|
|
582
569
|
}
|
|
583
570
|
}
|
|
584
|
-
function
|
|
585
|
-
if (!
|
|
571
|
+
function he(s) {
|
|
572
|
+
if (!d || !d.isReady())
|
|
586
573
|
throw new Error("WASM 模块未加载,无法求逆矩阵");
|
|
587
574
|
try {
|
|
588
|
-
return
|
|
589
|
-
} catch (
|
|
590
|
-
throw new Error(`WASM 求逆矩阵失败: ${
|
|
575
|
+
return d.invertMatrix(s);
|
|
576
|
+
} catch (t) {
|
|
577
|
+
throw new Error(`WASM 求逆矩阵失败: ${t}`);
|
|
591
578
|
}
|
|
592
579
|
}
|
|
593
|
-
function V(
|
|
594
|
-
if (!
|
|
580
|
+
function V(s, t, e) {
|
|
581
|
+
if (!d || !d.isReady())
|
|
595
582
|
throw new Error("WASM 模块未加载,无法应用逆透视变换");
|
|
596
583
|
try {
|
|
597
|
-
return
|
|
598
|
-
} catch (
|
|
599
|
-
throw new Error(`WASM 应用逆透视变换失败: ${
|
|
584
|
+
return d.applyInversePerspective(s, t, e);
|
|
585
|
+
} catch (r) {
|
|
586
|
+
throw new Error(`WASM 应用逆透视变换失败: ${r}`);
|
|
600
587
|
}
|
|
601
588
|
}
|
|
602
|
-
function
|
|
603
|
-
if (!
|
|
589
|
+
function Q(s, t, e) {
|
|
590
|
+
if (!d || !d.isReady())
|
|
604
591
|
throw new Error("WASM 模块未加载,无法应用透视变换");
|
|
605
592
|
try {
|
|
606
|
-
return
|
|
607
|
-
} catch (
|
|
608
|
-
throw new Error(`WASM 应用透视变换失败: ${
|
|
593
|
+
return d.applyPerspective(s, t, e);
|
|
594
|
+
} catch (r) {
|
|
595
|
+
throw new Error(`WASM 应用透视变换失败: ${r}`);
|
|
609
596
|
}
|
|
610
597
|
}
|
|
611
|
-
function j(
|
|
612
|
-
if (!
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
const x = e.x * (
|
|
598
|
+
function j(s, t, e, r, n, o, u, i) {
|
|
599
|
+
if (!t || "complete" in t && !t.complete || !("naturalWidth" in t ? t.naturalWidth : t.width)) return;
|
|
600
|
+
const c = (o.x + u.x + i.x) / 3, l = (o.y + u.y + i.y) / 3, a = (Math.hypot(o.x - c, o.y - l) + Math.hypot(u.x - c, u.y - l) + Math.hypot(i.x - c, i.y - l)) / 3, f = a > 1 ? (a + 1.65) / a : 1.5, y = c + (o.x - c) * f, m = l + (o.y - l) * f, A = c + (u.x - c) * f, E = l + (u.y - l) * f, g = c + (i.x - c) * f, M = l + (i.y - l) * f;
|
|
601
|
+
s.save(), s.beginPath(), s.moveTo(y, m), s.lineTo(A, E), s.lineTo(g, M), s.closePath(), s.clip();
|
|
602
|
+
const x = e.x * (n.y - r.y) - r.x * n.y + n.x * r.y + (r.x - n.x) * e.y;
|
|
616
603
|
if (Math.abs(x) < 1e-3) {
|
|
617
|
-
|
|
604
|
+
s.restore();
|
|
618
605
|
return;
|
|
619
606
|
}
|
|
620
|
-
const p = -(e.y * (
|
|
621
|
-
|
|
607
|
+
const p = -(e.y * (i.x - u.x) - r.y * i.x + n.y * u.x + (r.y - n.y) * o.x) / x, S = (r.y * i.y + e.y * (u.y - i.y) - n.y * u.y + (n.y - r.y) * o.y) / x, W = (e.x * (i.x - u.x) - r.x * i.x + n.x * u.x + (r.x - n.x) * o.x) / x, D = -(r.x * i.y + e.x * (u.y - i.y) - n.x * u.y + (n.x - r.x) * o.y) / x, B = (e.x * (n.y * u.x - r.y * i.x) + e.y * (r.x * i.x - n.x * u.x) + (n.x * r.y - r.x * n.y) * o.x) / x, F = (e.x * (n.y * u.y - r.y * i.y) + e.y * (r.x * i.y - n.x * u.y) + (n.x * r.y - r.x * n.y) * o.y) / x;
|
|
608
|
+
s.transform(p, S, W, D, B, F), s.drawImage(t, 0, 0), s.restore();
|
|
622
609
|
}
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
Q(n.data);
|
|
610
|
+
self.onmessage = async (s) => {
|
|
611
|
+
if (s.data?.type === "SET_LICENSE") {
|
|
612
|
+
re(s.data);
|
|
627
613
|
return;
|
|
628
614
|
}
|
|
629
|
-
const
|
|
630
|
-
if (!
|
|
631
|
-
|
|
615
|
+
const t = s.data, { id: e, designBitmap: r, layerData: n, canvasSize: o } = t;
|
|
616
|
+
if (!r) {
|
|
617
|
+
self.postMessage({
|
|
632
618
|
id: e,
|
|
633
619
|
imageBitmap: null,
|
|
634
620
|
error: "designBitmap 未定义",
|
|
@@ -636,8 +622,8 @@ self.onmessage = async (n) => {
|
|
|
636
622
|
});
|
|
637
623
|
return;
|
|
638
624
|
}
|
|
639
|
-
if (!
|
|
640
|
-
|
|
625
|
+
if (!n) {
|
|
626
|
+
self.postMessage({
|
|
641
627
|
id: e,
|
|
642
628
|
imageBitmap: null,
|
|
643
629
|
error: "layerData 未定义",
|
|
@@ -645,66 +631,54 @@ self.onmessage = async (n) => {
|
|
|
645
631
|
});
|
|
646
632
|
return;
|
|
647
633
|
}
|
|
648
|
-
const
|
|
649
|
-
if (
|
|
650
|
-
|
|
651
|
-
size: o.size,
|
|
652
|
-
bounds: o.bounds,
|
|
653
|
-
canvasSize: s
|
|
654
|
-
}), !g || !g.isReady())
|
|
655
|
-
if (R || self.LICENSE_TOKEN) {
|
|
656
|
-
console.log("🔄 [deform.worker] WASM 未就绪,尝试初始化...");
|
|
634
|
+
const u = performance.now();
|
|
635
|
+
if ((/* @__PURE__ */ new Date()).toISOString(), !d || !d.isReady())
|
|
636
|
+
if (b || self.LICENSE_TOKEN)
|
|
657
637
|
try {
|
|
658
|
-
if (
|
|
638
|
+
if (L && C && await C, (!d || !d.isReady()) && await z(), !d || !d.isReady())
|
|
659
639
|
throw new Error("WASM 模块仍未就绪");
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
console.error("❌ [deform.worker] WASM 初始化失败:", a);
|
|
663
|
-
const l = performance.now() - i;
|
|
640
|
+
} catch (w) {
|
|
641
|
+
const l = performance.now() - u;
|
|
664
642
|
self.postMessage({
|
|
665
643
|
id: e,
|
|
666
|
-
error: `WASM 初始化失败: ${
|
|
644
|
+
error: `WASM 初始化失败: ${w.message}`,
|
|
667
645
|
duration: l
|
|
668
646
|
});
|
|
669
647
|
return;
|
|
670
648
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
if (w)
|
|
649
|
+
else {
|
|
650
|
+
let w = 0;
|
|
651
|
+
const c = 500, l = 50;
|
|
652
|
+
let a = null;
|
|
653
|
+
for (; w < c && !a; )
|
|
654
|
+
await new Promise((h) => setTimeout(h, l)), w += l, a = b || self.LICENSE_TOKEN;
|
|
655
|
+
if (a)
|
|
679
656
|
try {
|
|
680
|
-
if (
|
|
657
|
+
if (b = a, _ = _ || self.LICENSE_API_URL, O = O || self.DEVICE_ID, U = U || self.DOMAIN, L && C ? await C : d || await z(), !d || !d.isReady())
|
|
681
658
|
throw new Error("WASM 模块未就绪");
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
console.error("❌ [deform.worker] WASM 初始化失败:", f);
|
|
685
|
-
const m = performance.now() - i;
|
|
659
|
+
} catch (h) {
|
|
660
|
+
const y = performance.now() - u;
|
|
686
661
|
self.postMessage({
|
|
687
662
|
id: e,
|
|
688
|
-
error: `WASM 初始化失败: ${
|
|
689
|
-
duration:
|
|
663
|
+
error: `WASM 初始化失败: ${h.message}`,
|
|
664
|
+
duration: y
|
|
690
665
|
});
|
|
691
666
|
return;
|
|
692
667
|
}
|
|
693
|
-
else if (!
|
|
694
|
-
|
|
695
|
-
const d = performance.now() - i;
|
|
668
|
+
else if (!a) {
|
|
669
|
+
const f = performance.now() - u;
|
|
696
670
|
self.postMessage({
|
|
697
671
|
id: e,
|
|
698
672
|
error: "LICENSE_TOKEN 未设置,无法使用 WASM 功能",
|
|
699
|
-
duration:
|
|
673
|
+
duration: f
|
|
700
674
|
});
|
|
701
675
|
return;
|
|
702
676
|
}
|
|
703
677
|
}
|
|
704
678
|
try {
|
|
705
|
-
const
|
|
706
|
-
if (!
|
|
707
|
-
|
|
679
|
+
const i = n.bounds;
|
|
680
|
+
if (!i || !i.width || !i.height) {
|
|
681
|
+
self.postMessage({
|
|
708
682
|
id: e,
|
|
709
683
|
imageBitmap: null,
|
|
710
684
|
error: "bounds 无效",
|
|
@@ -712,43 +686,34 @@ self.onmessage = async (n) => {
|
|
|
712
686
|
});
|
|
713
687
|
return;
|
|
714
688
|
}
|
|
715
|
-
const
|
|
716
|
-
let
|
|
717
|
-
if (
|
|
718
|
-
|
|
689
|
+
const w = ne(n, o);
|
|
690
|
+
let c, l;
|
|
691
|
+
if (o && o.width > 0 && o.height > 0)
|
|
692
|
+
c = o.width, l = o.height;
|
|
719
693
|
else {
|
|
720
|
-
const
|
|
721
|
-
width:
|
|
722
|
-
height:
|
|
694
|
+
const M = n.size || n.placedLayer || {
|
|
695
|
+
width: i.width,
|
|
696
|
+
height: i.height
|
|
723
697
|
};
|
|
724
|
-
|
|
698
|
+
c = M.width, l = M.height;
|
|
725
699
|
}
|
|
726
|
-
const
|
|
727
|
-
if (!
|
|
728
|
-
const
|
|
729
|
-
self.postMessage({ id: e, error: "Canvas context unavailable", duration:
|
|
700
|
+
const a = new OffscreenCanvas(c, l), h = a.getContext("2d");
|
|
701
|
+
if (!h) {
|
|
702
|
+
const x = performance.now() - u;
|
|
703
|
+
self.postMessage({ id: e, error: "Canvas context unavailable", duration: x });
|
|
730
704
|
return;
|
|
731
705
|
}
|
|
732
|
-
const
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
{
|
|
736
|
-
width: m.width,
|
|
737
|
-
height: m.height
|
|
738
|
-
}
|
|
739
|
-
), t.close();
|
|
740
|
-
const S = D(
|
|
741
|
-
{ id: e, imageBitmap: m, duration: M }
|
|
706
|
+
const f = oe(h, r, w), y = a.transferToImageBitmap(), A = performance.now() - u, E = (/* @__PURE__ */ new Date()).toISOString();
|
|
707
|
+
r.close();
|
|
708
|
+
const g = se(
|
|
709
|
+
{ id: e, imageBitmap: y, duration: A }
|
|
742
710
|
);
|
|
743
711
|
self.postMessage(
|
|
744
|
-
|
|
745
|
-
|
|
712
|
+
g,
|
|
713
|
+
g.imageBitmap ? [g.imageBitmap] : []
|
|
746
714
|
);
|
|
747
|
-
} catch (
|
|
748
|
-
const
|
|
749
|
-
|
|
750
|
-
`[deform worker] ❌ 错误 id=${e} 时间=${w} 耗时=${Math.round(h)}ms`,
|
|
751
|
-
l
|
|
752
|
-
), self.postMessage({ id: e, error: l, duration: h });
|
|
715
|
+
} catch (i) {
|
|
716
|
+
const c = performance.now() - u, l = i instanceof Error ? i.message : String(i);
|
|
717
|
+
(/* @__PURE__ */ new Date()).toISOString(), self.postMessage({ id: e, error: l, duration: c });
|
|
753
718
|
}
|
|
754
719
|
};
|