@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.
@@ -1,123 +1,133 @@
1
- var Z = Object.defineProperty, ee = (s, t, e) => t in s ? Z(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e, $ = (s, t, e) => ee(s, typeof t != "symbol" ? t + "" : t, e);
2
- const q = class T {
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 T.instance || (T.instance = new T()), T.instance;
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(t, e) {
15
- if (!this.wasmReady)
16
- try {
17
- const r = (a) => {
18
- if (e && a === "wasm_exec.js")
19
- return e;
20
- if (t && a === "perspective.wasm")
21
- return t;
22
- try {
23
- let h = null;
24
- if (typeof import.meta < "u" && import.meta.url ? h = import.meta.url : typeof self < "u" && self.location && (h = self.location.href), h) {
25
- const f = new URL(h), y = f.pathname;
26
- if (y.includes("/js/")) {
27
- const m = "../assets/" + a;
28
- return new URL(m, f).pathname;
29
- } else if (y.includes("/assets/")) {
30
- const m = "./" + a;
31
- return new URL(m, f).pathname;
32
- } else
33
- return "/assets/" + a;
34
- }
35
- } catch {
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
- return "/assets/" + a;
38
- }, n = e || r("wasm_exec.js"), o = t || r("perspective.wasm");
39
- await this.loadWasmExec(n);
40
- const u = typeof self < "u" ? self : globalThis;
41
- this.go = new u.Go();
42
- const i = await fetch(o);
43
- if (!i.ok)
44
- throw new Error(`无法加载 WASM 文件: ${i.status}`);
45
- const w = await i.arrayBuffer(), c = await WebAssembly.instantiate(w, this.go.importObject);
46
- this.wasmModule = c.instance, this.go.run(this.wasmModule), this.wasmReady = !0;
47
- const l = this.call("wasmInit");
48
- if (!(l && l.success))
49
- throw new Error("WASM 初始化失败");
50
- } catch (r) {
51
- throw this.wasmReady = !1, r;
52
- }
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(t) {
59
- return new Promise((e, r) => {
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(t), e();
71
+ self.importScripts(r), e();
63
72
  return;
64
- } catch {
73
+ } catch (s) {
74
+ console.warn("⚠️ importScripts 失败,使用 fetch:", s);
65
75
  }
66
- fetch(t).then((o) => {
67
- if (!o.ok)
68
- throw new Error(`HTTP ${o.status}: ${o.statusText} - URL: ${t}`);
69
- const u = o.headers.get("content-type") || "";
70
- return !u.includes("javascript") && u.includes("text/plain"), o.text();
71
- }).then((o) => {
72
- if (o.trim().startsWith("<!DOCTYPE") || o.trim().startsWith("<html"))
73
- throw new Error(`返回的是 HTML 而不是 JavaScript,可能是 404 错误。URL: ${t}`);
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 u = typeof self < "u" ? self : globalThis;
76
- new Function("self", o)(u), e();
77
- } catch (u) {
78
- r(new Error(`执行 wasm_exec.js 失败: ${u}`));
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((o) => {
81
- r(o);
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(t, e) {
98
+ async verifyLicense(r, e) {
89
99
  if (!this.wasmReady)
90
100
  return !1;
91
101
  if (e)
92
102
  try {
93
- const r = this.getDeviceID(), n = this.getDomain(), u = await (await fetch(`${e}/jet_license/interface/license/verify`, {
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: t,
100
- deviceId: r,
101
- domain: n
109
+ token: r,
110
+ deviceId: t,
111
+ domain: o
102
112
  })
103
113
  })).json();
104
- if (!u.success || !u.valid) {
105
- const w = u.error || "License 验证失败";
106
- throw new Error(w);
114
+ if (!i.success || !i.valid) {
115
+ const u = i.error || "License 验证失败";
116
+ throw new Error(u);
107
117
  }
108
- const i = this.call("wasmVerifyLicense", t);
109
- if (!i.success || i.valid !== !0)
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 (r) {
113
- throw r;
122
+ } catch (t) {
123
+ throw console.error("License API 验证失败:", t), t;
114
124
  }
115
125
  else
116
126
  try {
117
- const r = this.call("wasmVerifyLicense", t);
118
- return r.success && r.valid === !0;
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(t) {
148
+ calcPerspectiveMatrix(r) {
139
149
  if (!this.wasmReady)
140
150
  throw new Error("WASM 未加载");
141
- if (t.length !== 4)
151
+ if (r.length !== 4)
142
152
  throw new Error("需要恰好 4 个点");
143
153
  try {
144
- const e = this.call("wasmCalcPerspectiveMatrix", JSON.stringify(t));
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(t) {
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(t));
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(t, e, r) {
180
+ applyPerspective(r, e, t) {
171
181
  if (!this.wasmReady)
172
182
  throw new Error("WASM 未加载");
173
183
  try {
174
- const n = this.call("wasmApplyPerspective", t, e, JSON.stringify(r));
175
- if (!n.success)
176
- throw new Error(n.error || "变换失败");
177
- return { x: n.x, y: n.y };
178
- } catch (n) {
179
- throw n;
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(t, e, r) {
195
+ applyInversePerspective(r, e, t) {
186
196
  if (!this.wasmReady)
187
197
  throw new Error("WASM 未加载");
188
198
  try {
189
- const n = this.call("wasmApplyInversePerspective", t, e, JSON.stringify(r));
190
- if (!n.success)
191
- throw new Error(n.error || "逆变换失败");
192
- return { x: n.x, y: n.y };
193
- } catch (n) {
194
- throw n;
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(t, e, r = !1) {
210
+ transformPoints(r, e, t = !1) {
201
211
  if (!this.wasmReady)
202
212
  throw new Error("WASM 未加载");
203
213
  try {
204
- const n = this.call(
214
+ const o = this.call(
205
215
  "wasmTransformPoints",
206
- JSON.stringify(t),
216
+ JSON.stringify(r),
207
217
  JSON.stringify(e),
208
- r
218
+ t
209
219
  );
210
- if (!n.success)
211
- throw new Error(n.error || "批量变换失败");
212
- return JSON.parse(n.points);
213
- } catch (n) {
214
- throw n;
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(t, e, r) {
236
+ getBicubicPoint(r, e, t) {
227
237
  if (!this.wasmReady)
228
238
  throw new Error("WASM 未加载");
229
- if (r.length !== 16)
239
+ if (t.length !== 16)
230
240
  throw new Error("需要恰好 16 个点");
231
241
  try {
232
- const n = this.call("wasmGetBicubicPoint", t, e, JSON.stringify(r));
233
- if (!n.success)
234
- throw new Error(n.error || "计算失败");
235
- return { x: n.x, y: n.y };
236
- } catch (n) {
237
- throw n;
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(t, e, r) {
253
+ getBilinearPoint(r, e, t) {
244
254
  if (!this.wasmReady)
245
255
  throw new Error("WASM 未加载");
246
- if (r.length !== 4)
256
+ if (t.length !== 4)
247
257
  throw new Error("需要恰好 4 个点");
248
258
  try {
249
- const n = this.call("wasmGetBilinearPoint", t, e, JSON.stringify(r));
250
- if (!n.success)
251
- throw new Error(n.error || "计算失败");
252
- return { x: n.x, y: n.y };
253
- } catch (n) {
254
- throw n;
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(t, e, r, n) {
270
+ getArbitraryMeshPoint(r, e, t, o) {
261
271
  if (!this.wasmReady)
262
272
  throw new Error("WASM 未加载");
263
273
  try {
264
- const o = this.call("wasmGetArbitraryMeshPoint", t, e, JSON.stringify(r), n);
265
- if (!o.success)
266
- throw new Error(o.error || "计算失败");
267
- return { x: o.x, y: o.y };
268
- } catch (o) {
269
- throw o;
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(t, e) {
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 r = this.call(
292
+ const t = this.call(
283
293
  "wasmBatchBicubicInterpolation",
284
- JSON.stringify(t),
294
+ JSON.stringify(r),
285
295
  JSON.stringify(e)
286
296
  );
287
- if (!r.success)
288
- throw new Error(r.error || "批量双三次插值失败");
289
- return r.points;
290
- } catch (r) {
291
- throw r;
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(t, e) {
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 r = this.call(
313
+ const t = this.call(
304
314
  "wasmBatchBilinearInterpolation",
305
- JSON.stringify(t),
315
+ JSON.stringify(r),
306
316
  JSON.stringify(e)
307
317
  );
308
- if (!r.success)
309
- throw new Error(r.error || "批量双线性插值失败");
310
- return r.points;
311
- } catch (r) {
312
- throw r;
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(t, e, r) {
328
+ batchArbitraryMeshInterpolation(r, e, t) {
319
329
  if (!this.wasmReady)
320
330
  throw new Error("WASM 未加载");
321
331
  try {
322
- const n = this.call(
332
+ const o = this.call(
323
333
  "wasmBatchArbitraryMeshInterpolation",
324
- JSON.stringify(t),
334
+ JSON.stringify(r),
325
335
  JSON.stringify(e),
326
- r
336
+ t
327
337
  );
328
- if (!n.success)
329
- throw new Error(n.error || "批量网格插值失败");
330
- return n.points;
331
- } catch (n) {
332
- throw n;
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(t, ...e) {
348
+ call(r, ...e) {
339
349
  if (!this.wasmReady)
340
350
  throw new Error("WASM 未加载");
341
- const n = (typeof self < "u" ? self : globalThis)[t];
342
- if (!n)
343
- throw new Error(`函数不存在: ${t}`);
351
+ const o = (typeof self < "u" ? self : globalThis)[r];
352
+ if (!o)
353
+ throw new Error(`函数不存在: ${r}`);
344
354
  try {
345
- return n(...e);
346
- } catch (o) {
347
- throw o;
355
+ return o(...e);
356
+ } catch (s) {
357
+ throw console.error(`调用 ${r} 失败:`, s), s;
348
358
  }
349
359
  }
350
- };
351
- $(q, "instance");
352
- let te = q, d = null, L = !1, C = null, b = null, _ = null, O = null, U = null;
353
- function re(s) {
354
- b = s.licenseToken, _ = s.licenseApiUrl, O = s.deviceId, U = s.domain, self.LICENSE_TOKEN = b, self.LICENSE_API_URL = _, self.DEVICE_ID = O, self.DOMAIN = U, d || (C && !L && (C = null), z().then(() => {
355
- }).catch((t) => {
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 z() {
359
- return d ? void 0 : L ? C || Promise.resolve() : b || self.LICENSE_TOKEN ? (L = !0, C = (async () => {
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
- d = te.getInstance();
362
- const t = (c) => {
363
- const l = self.WASM_URL, a = self.WASM_EXEC_URL;
364
- if (c === "perspective.wasm" && l)
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 h = null;
370
- if (typeof import.meta < "u" && import.meta.url ? h = import.meta.url : typeof self < "u" && self.location && (h = self.location.href), h) {
371
- const f = new URL(h), y = f.pathname;
372
- if (y.includes("/js/")) {
373
- const m = "../assets/" + c;
374
- return new URL(m, f).pathname;
375
- } else if (y.includes("/assets/")) {
376
- const m = "./" + c;
377
- return new URL(m, f).pathname;
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/" + c;
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/" + c;
384
- }, e = self.WASM_URL || t("perspective.wasm"), r = self.WASM_EXEC_URL || t("wasm_exec.js");
385
- await d.load(e, r);
386
- const n = b || self.LICENSE_TOKEN, o = _ || self.LICENSE_API_URL, u = O || self.DEVICE_ID, i = U || self.DOMAIN;
387
- if (!n)
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 d.verifyLicense(n, o))
401
+ if (!await g.verifyLicense(o, s))
390
402
  throw new Error("WASM License 验证失败,无法使用 WASM 功能");
391
- } catch (t) {
392
- throw d = null, C = null, t;
403
+ console.log("✅ Worker WASM 模块加载并验证成功");
404
+ } catch (r) {
405
+ throw console.error("❌ WASM 加载或验证失败:", r), g = null, A = null, r;
393
406
  } finally {
394
- L = !1;
407
+ P = !1;
395
408
  }
396
- })(), C) : Promise.resolve();
409
+ })(), A) : (console.log("⏳ [deform.worker] 等待 License Token..."), Promise.resolve());
397
410
  }
398
- function X(s) {
399
- return "naturalWidth" in s && s.naturalWidth ? { width: s.naturalWidth, height: s.naturalHeight } : "width" in s ? { width: s.width, height: s.height } : { width: 0, height: 0 };
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 ne(s, t) {
402
- if (!s || !s.bounds)
414
+ function Z(n, r) {
415
+ if (!n || !n.bounds)
403
416
  throw new Error("Invalid layer data: missing bounds");
404
- const e = s.bounds;
405
- if (t && t.width > 0 && t.height > 0)
406
- return { ...s };
407
- const r = s.size || s.placedLayer || {
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
- }, n = r.width / e.width, o = r.height / e.height, u = { ...s };
411
- return s.transform && s.transform.length === 8 && (u.transform = [
412
- (s.transform[0] - e.left) * n,
413
- (s.transform[1] - e.top) * o,
414
- (s.transform[2] - e.left) * n,
415
- (s.transform[3] - e.top) * o,
416
- (s.transform[4] - e.left) * n,
417
- (s.transform[5] - e.top) * o,
418
- (s.transform[6] - e.left) * n,
419
- (s.transform[7] - e.top) * o
420
- ]), u;
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 se(s) {
423
- return s.error, s;
435
+ function D(n) {
436
+ return n.error, n;
424
437
  }
425
- function oe(s, t, e) {
426
- if (!s || !t || !e)
438
+ function ee(n, r, e) {
439
+ if (!n || !r || !e)
427
440
  return "Invalid Parameters";
428
- const r = "naturalWidth" in t ? t.naturalWidth : "width" in t ? t.width : 0, n = "naturalHeight" in t ? t.naturalHeight : "height" in t ? t.height : 0;
429
- if (!r || !n)
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
- s.imageSmoothingEnabled = !0, s.imageSmoothingQuality = "high";
432
- let o = null, u = null, i = null, w = null, c = 0, l = 0, a = null, h = "Unknown";
433
- if (e.size && e.size.width ? (c = e.size.width, l = e.size.height) : e.placedLayer && e.placedLayer.width ? (c = e.placedLayer.width, l = e.placedLayer.height) : e.originalWidth && (c = e.originalWidth, l = e.originalHeight), e.meshPoints && e.meshPoints.length > 0 && (o = e.meshPoints), e.transform && e.transform.length === 8) {
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
- u = [
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 && (i = e.quiltSliceX), e.quiltSliceY && (w = e.quiltSliceY), e.filterList && (a = e.filterList.find((f) => f.type === "puppet" && f.enabled)), c === 0 && i && i.length > 0 && (c = i[i.length - 1]), c === 0 && (c = 1e3), l === 0 && (l = 1e3), a && a.filter && a.filter.puppetShapeList && a.filter.puppetShapeList.length > 0 && u ? (ie(s, t, u, a.filter.puppetShapeList[0]), h = "Puppet Warp") : o && u ? i && w ? (ce(s, t, u, o, i, w, c, l), h = "Quilt Mesh") : o.length === 16 ? (ue(s, t, u, o), h = "Std Mesh (16pt)") : (ae(s, t, u, o), h = "Auto-Fit Mesh") : o ? (fe(s, t, o), h = "Direct Mesh") : u && (Y(s, t, u), h = "Transform Only"), h;
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 ie(s, t, e, r, n, o) {
445
- if (!r.originalVertexArray || !r.deformedVertexArray || !r.indexArray)
457
+ function re(n, r, e, t, o, s) {
458
+ if (!t.originalVertexArray || !t.deformedVertexArray || !t.indexArray)
446
459
  return;
447
- const u = G(e), i = he(u);
448
- if (!i) {
449
- Y(s, t, e);
460
+ const i = K(e), c = ce(i);
461
+ if (!c) {
462
+ G(n, r, e);
450
463
  return;
451
464
  }
452
- const w = r.originalVertexArray, c = r.deformedVertexArray, l = r.indexArray;
453
- for (let a = 0; a < l.length; a += 3) {
454
- const h = l[a], f = l[a + 1], y = l[a + 2];
455
- if (!w[h] || !w[f] || !w[y]) continue;
456
- const m = w[h], A = w[f], E = w[y], g = V(m.x, m.y, i), M = V(A.x, A.y, i), x = V(E.x, E.y, i), p = X(t), S = { x: g.x * p.width, y: g.y * p.height }, W = { x: M.x * p.width, y: M.y * p.height }, D = { x: x.x * p.width, y: x.y * p.height }, B = c[h], F = c[f], P = c[y];
457
- j(s, t, S, W, D, B, F, P);
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 ue(s, t, e, r) {
461
- let n = 1 / 0, o = -1 / 0, u = 1 / 0, i = -1 / 0;
462
- r.forEach((a) => {
463
- n = Math.min(n, a.x), o = Math.max(o, a.x), u = Math.min(u, a.y), i = Math.max(i, a.y);
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 w = o - n, c = i - u;
466
- if (w < 1 || c < 1) {
467
- Y(s, t, e);
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 l = r.map((a) => {
471
- const h = (a.x - n) / w, f = (a.y - u) / c;
472
- return N(h, f, e);
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
- H(s, t, l, "bicubic", 4, 40);
487
+ z(n, r, h, "bicubic", 4, 40);
475
488
  }
476
- function ce(s, t, e, r, n, o, u, i) {
477
- const w = G(e);
478
- let c = 1 / 0, l = -1 / 0, a = 1 / 0, h = -1 / 0;
479
- r.forEach((E) => {
480
- c = Math.min(c, E.x), l = Math.max(l, E.x), a = Math.min(a, E.y), h = Math.max(h, E.y);
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 = l - c || 1, y = h - a || 1, m = n.length - 1, A = o.length - 1;
483
- for (let E = 0; E < A; E++)
484
- for (let g = 0; g < m; g++) {
485
- const M = E * 3, x = g * 3, p = [], S = m * 3 + 1;
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 R = 0; R < 4; R++) {
489
- const J = (M + I) * S + (x + R);
490
- r[J] && p.push(r[J]);
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 W = p.map((I) => {
497
- const R = (I.x - c) / f, J = (I.y - a) / y;
498
- return Q(R, J, w);
499
- }), D = n[g] / u, B = n[g + 1] / u, F = o[E] / i, P = o[E + 1] / i;
500
- le(s, t, W, D, B, F, P);
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 ae(s, t, e, r) {
504
- const n = G(e);
505
- let o = 1 / 0, u = -1 / 0, i = 1 / 0, w = -1 / 0;
506
- r.forEach((f) => {
507
- o = Math.min(o, f.x), u = Math.max(u, f.x), i = Math.min(i, f.y), w = Math.max(w, f.y);
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 c = u - o || 1, l = w - i || 1, a = r.map((f) => {
510
- const y = (f.x - o) / c, m = (f.y - i) / l;
511
- return Q(y, m, n);
512
- }), h = Math.floor(Math.sqrt(r.length)) || 4;
513
- H(s, t, a, "grid", h, 40);
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 le(s, t, e, r, n, o, u) {
516
- const w = X(t), c = w.width, l = w.height;
517
- for (let a = 0; a < 20; a++)
518
- for (let h = 0; h < 20; h++) {
519
- const f = h / 20, y = a / 20, m = (h + 1) / 20, A = (a + 1) / 20, E = r + f * (n - r), g = r + m * (n - r), M = o + y * (u - o), x = o + A * (u - o), p = { x: E * c, y: M * l }, S = { x: g * c, y: M * l }, W = { x: E * c, y: x * l }, D = { x: g * c, y: x * l }, B = v(f, y, e), F = v(m, y, e), P = v(f, A, e), I = v(m, A, e);
520
- j(s, t, p, S, W, B, F, P), j(s, t, S, D, W, F, I, P);
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 Y(s, t, e) {
524
- H(s, t, e, "bilinear", 0, 10);
536
+ function G(n, r, e) {
537
+ z(n, r, e, "bilinear", 0, 10);
525
538
  }
526
- function fe(s, t, e) {
527
- H(s, t, e, "bicubic", 4, 40);
539
+ function ie(n, r, e) {
540
+ z(n, r, e, "bicubic", 4, 40);
528
541
  }
529
- function H(s, t, e, r, n, o) {
530
- const u = X(t), i = u.width, w = u.height;
531
- for (let c = 0; c < o; c++)
532
- for (let l = 0; l < o; l++) {
533
- const a = l / o, h = c / o, f = (l + 1) / o, y = (c + 1) / o, m = { x: a * i, y: h * w }, A = { x: f * i, y: h * w }, E = { x: a * i, y: y * w }, g = { x: f * i, y: y * w };
534
- let M, x, p, S;
535
- r === "bicubic" ? (M = v(a, h, e), x = v(f, h, e), p = v(a, y, e), S = v(f, y, e)) : r === "grid" ? (M = k(a, h, e, n), x = k(f, h, e, n), p = k(a, y, e, n), S = k(f, y, e, n)) : (M = N(a, h, e), x = N(f, h, e), p = N(a, y, e), S = N(f, y, e)), j(s, t, m, A, E, M, x, p), j(s, t, A, g, E, x, S, p);
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 K(s, t) {
539
- const e = 1 - t;
540
- return s === 0 ? e * e * e : s === 1 ? 3 * e * e * t : s === 2 ? 3 * e * t * t : t * t * t;
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 v(s, t, e) {
543
- let r = 0, n = 0;
544
- for (let o = 0; o < 4; o++)
545
- for (let u = 0; u < 4; u++) {
546
- const i = K(o, t) * K(u, s);
547
- r += e[o * 4 + u].x * i, n += e[o * 4 + u].y * i;
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: r, y: n };
562
+ return { x: t, y: o };
550
563
  }
551
- function N(s, t, e) {
552
- const r = (1 - s) * (1 - t) * e[0].x + s * (1 - t) * e[1].x + s * t * e[2].x + (1 - s) * t * e[3].x, n = (1 - s) * (1 - t) * e[0].y + s * (1 - t) * e[1].y + s * t * e[2].y + (1 - s) * t * e[3].y;
553
- return { x: r, y: n };
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 k(s, t, e, r) {
556
- const n = r - 1, o = s * n, u = t * n;
557
- let i = Math.floor(o), w = Math.floor(u);
558
- i >= n && (i = n - 1), w >= n && (w = n - 1), i < 0 && (i = 0), w < 0 && (w = 0);
559
- const c = o - i, l = u - w, a = e[w * r + i], h = e[w * r + (i + 1)], f = e[(w + 1) * r + i], y = e[(w + 1) * r + (i + 1)], m = (1 - c) * (1 - l) * a.x + c * (1 - l) * h.x + c * l * y.x + (1 - c) * l * f.x, A = (1 - c) * (1 - l) * a.y + c * (1 - l) * h.y + c * l * y.y + (1 - c) * l * f.y;
560
- return { x: m, y: A };
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 G(s) {
563
- if (!d || !d.isReady())
575
+ function K(n) {
576
+ if (!g || !g.isReady())
564
577
  throw new Error("WASM 模块未加载,无法计算透视变换矩阵");
565
578
  try {
566
- return d.calcPerspectiveMatrix(s);
567
- } catch (t) {
568
- throw new Error(`WASM 计算透视矩阵失败: ${t}`);
579
+ return g.calcPerspectiveMatrix(n);
580
+ } catch (r) {
581
+ throw new Error(`WASM 计算透视矩阵失败: ${r}`);
569
582
  }
570
583
  }
571
- function he(s) {
572
- if (!d || !d.isReady())
584
+ function ce(n) {
585
+ if (!g || !g.isReady())
573
586
  throw new Error("WASM 模块未加载,无法求逆矩阵");
574
587
  try {
575
- return d.invertMatrix(s);
576
- } catch (t) {
577
- throw new Error(`WASM 求逆矩阵失败: ${t}`);
588
+ return g.invertMatrix(n);
589
+ } catch (r) {
590
+ throw new Error(`WASM 求逆矩阵失败: ${r}`);
578
591
  }
579
592
  }
580
- function V(s, t, e) {
581
- if (!d || !d.isReady())
593
+ function V(n, r, e) {
594
+ if (!g || !g.isReady())
582
595
  throw new Error("WASM 模块未加载,无法应用逆透视变换");
583
596
  try {
584
- return d.applyInversePerspective(s, t, e);
585
- } catch (r) {
586
- throw new Error(`WASM 应用逆透视变换失败: ${r}`);
597
+ return g.applyInversePerspective(n, r, e);
598
+ } catch (t) {
599
+ throw new Error(`WASM 应用逆透视变换失败: ${t}`);
587
600
  }
588
601
  }
589
- function Q(s, t, e) {
590
- if (!d || !d.isReady())
602
+ function F(n, r, e) {
603
+ if (!g || !g.isReady())
591
604
  throw new Error("WASM 模块未加载,无法应用透视变换");
592
605
  try {
593
- return d.applyPerspective(s, t, e);
594
- } catch (r) {
595
- throw new Error(`WASM 应用透视变换失败: ${r}`);
606
+ return g.applyPerspective(n, r, e);
607
+ } catch (t) {
608
+ throw new Error(`WASM 应用透视变换失败: ${t}`);
596
609
  }
597
610
  }
598
- function j(s, t, e, r, n, o, u, i) {
599
- if (!t || "complete" in t && !t.complete || !("naturalWidth" in t ? t.naturalWidth : t.width)) return;
600
- const c = (o.x + u.x + i.x) / 3, l = (o.y + u.y + i.y) / 3, a = (Math.hypot(o.x - c, o.y - l) + Math.hypot(u.x - c, u.y - l) + Math.hypot(i.x - c, i.y - l)) / 3, f = a > 1 ? (a + 1.65) / a : 1.5, y = c + (o.x - c) * f, m = l + (o.y - l) * f, A = c + (u.x - c) * f, E = l + (u.y - l) * f, g = c + (i.x - c) * f, M = l + (i.y - l) * f;
601
- s.save(), s.beginPath(), s.moveTo(y, m), s.lineTo(A, E), s.lineTo(g, M), s.closePath(), s.clip();
602
- const x = e.x * (n.y - r.y) - r.x * n.y + n.x * r.y + (r.x - n.x) * e.y;
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
- s.restore();
617
+ n.restore();
605
618
  return;
606
619
  }
607
- const p = -(e.y * (i.x - u.x) - r.y * i.x + n.y * u.x + (r.y - n.y) * o.x) / x, S = (r.y * i.y + e.y * (u.y - i.y) - n.y * u.y + (n.y - r.y) * o.y) / x, W = (e.x * (i.x - u.x) - r.x * i.x + n.x * u.x + (r.x - n.x) * o.x) / x, D = -(r.x * i.y + e.x * (u.y - i.y) - n.x * u.y + (n.x - r.x) * o.y) / x, B = (e.x * (n.y * u.x - r.y * i.x) + e.y * (r.x * i.x - n.x * u.x) + (n.x * r.y - r.x * n.y) * o.x) / x, F = (e.x * (n.y * u.y - r.y * i.y) + e.y * (r.x * i.y - n.x * u.y) + (n.x * r.y - r.x * n.y) * o.y) / x;
608
- s.transform(p, S, W, D, B, F), s.drawImage(t, 0, 0), s.restore();
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
- self.onmessage = async (s) => {
611
- if (s.data?.type === "SET_LICENSE") {
612
- re(s.data);
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 t = s.data, { id: e, designBitmap: r, layerData: n, canvasSize: o } = t;
616
- if (!r) {
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 (!n) {
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 u = performance.now();
635
- if ((/* @__PURE__ */ new Date()).toISOString(), !d || !d.isReady())
636
- if (b || self.LICENSE_TOKEN)
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 (L && C && await C, (!d || !d.isReady()) && await z(), !d || !d.isReady())
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
- } catch (w) {
641
- const l = performance.now() - u;
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 初始化失败: ${w.message}`,
666
+ error: `WASM 初始化失败: ${a.message}`,
645
667
  duration: l
646
668
  });
647
669
  return;
648
670
  }
649
- else {
650
- let w = 0;
651
- const c = 500, l = 50;
652
- let a = null;
653
- for (; w < c && !a; )
654
- await new Promise((h) => setTimeout(h, l)), w += l, a = b || self.LICENSE_TOKEN;
655
- if (a)
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 (b = a, _ = _ || self.LICENSE_API_URL, O = O || self.DEVICE_ID, U = U || self.DOMAIN, L && C ? await C : d || await z(), !d || !d.isReady())
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
- } catch (h) {
660
- const y = performance.now() - u;
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 初始化失败: ${h.message}`,
664
- duration: y
688
+ error: `WASM 初始化失败: ${f.message}`,
689
+ duration: m
665
690
  });
666
691
  return;
667
692
  }
668
- else if (!a) {
669
- const f = performance.now() - u;
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: f
699
+ duration: d
674
700
  });
675
701
  return;
676
702
  }
677
703
  }
678
704
  try {
679
- const i = n.bounds;
680
- if (!i || !i.width || !i.height) {
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 w = ne(n, o);
690
- let c, l;
691
- if (o && o.width > 0 && o.height > 0)
692
- c = o.width, l = o.height;
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 M = n.size || n.placedLayer || {
695
- width: i.width,
696
- height: i.height
720
+ const x = o.size || o.placedLayer || {
721
+ width: u.width,
722
+ height: u.height
697
723
  };
698
- c = M.width, l = M.height;
724
+ h = x.width, l = x.height;
699
725
  }
700
- const a = new OffscreenCanvas(c, l), h = a.getContext("2d");
701
- if (!h) {
702
- const x = performance.now() - u;
703
- self.postMessage({ id: e, error: "Canvas context unavailable", duration: x });
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 f = oe(h, r, w), y = a.transferToImageBitmap(), A = performance.now() - u, E = (/* @__PURE__ */ new Date()).toISOString();
707
- r.close();
708
- const g = se(
709
- { id: e, imageBitmap: y, duration: A }
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
- g,
713
- g.imageBitmap ? [g.imageBitmap] : []
744
+ S,
745
+ S.imageBitmap ? [S.imageBitmap] : []
714
746
  );
715
- } catch (i) {
716
- const c = performance.now() - u, l = i instanceof Error ? i.message : String(i);
717
- (/* @__PURE__ */ new Date()).toISOString(), self.postMessage({ id: e, error: l, duration: c });
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
  };