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