@jieyin/editor-sdk 1.1.127 → 1.1.129

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