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