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