@jieyin/editor-sdk 1.1.136 → 1.1.137

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,10 +1,23 @@
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
+ var te = Object.defineProperty, re = (s, t, e) => t in s ? te(s, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[t] = e, z = (s, t, e) => re(s, typeof t != "symbol" ? t + "" : t, e);
2
+ const Z = class P {
3
3
  constructor() {
4
- $(this, "wasmReady", !1), $(this, "go", null), $(this, "wasmModule", null);
4
+ z(this, "wasmReady", !1), z(this, "go", null), z(this, "wasmModule", null);
5
+ }
6
+ isDebugEnabled() {
7
+ try {
8
+ return globalThis.__DEBUG_RENDER__ === !0;
9
+ } catch {
10
+ }
11
+ return !1;
12
+ }
13
+ debugLog(...t) {
14
+ this.isDebugEnabled();
15
+ }
16
+ debugWarn(...t) {
17
+ this.isDebugEnabled();
5
18
  }
6
19
  static getInstance() {
7
- return T.instance || (T.instance = new T()), T.instance;
20
+ return P.instance || (P.instance = new P()), P.instance;
8
21
  }
9
22
  /**
10
23
  * 在 Worker 环境中加载 WASM 模块
@@ -12,44 +25,51 @@ const q = class T {
12
25
  * @param wasmExecUrl wasm_exec.js 路径
13
26
  */
14
27
  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 {
28
+ if (this.wasmReady) {
29
+ this.debugLog("✅ WASM 已加载,跳过重复加载");
30
+ return;
31
+ }
32
+ try {
33
+ this.debugLog("🚀 Worker: 加载透视变换 WASM...");
34
+ const r = (c) => {
35
+ if (e && c === "wasm_exec.js")
36
+ return e;
37
+ if (t && c === "perspective.wasm")
38
+ return t;
39
+ try {
40
+ let f = null;
41
+ if (typeof import.meta < "u" && import.meta.url ? f = import.meta.url : typeof self < "u" && self.location && (f = self.location.href), f) {
42
+ const l = new URL(f), d = l.pathname;
43
+ if (d.includes("/js/")) {
44
+ const y = "../assets/" + c, m = new URL(y, l);
45
+ return this.debugLog(`🔍 [WASM] 计算路径: ${c} -> ${m.pathname} (Worker: ${d})`), m.pathname;
46
+ } else if (d.includes("/assets/")) {
47
+ const y = "./" + c, m = new URL(y, l);
48
+ return this.debugLog(`🔍 [WASM] 计算路径: ${c} -> ${m.pathname} (Worker: ${d})`), m.pathname;
49
+ } else
50
+ return this.debugLog(`🔍 [WASM] 使用默认绝对路径: /assets/${c}`), "/assets/" + c;
36
51
  }
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
- }
52
+ } catch (f) {
53
+ this.debugWarn("⚠️ 无法计算 WASM 相对路径,使用默认路径:", f);
54
+ }
55
+ return "/assets/" + c;
56
+ }, n = e || r("wasm_exec.js"), u = t || r("perspective.wasm");
57
+ this.debugLog("🔍 [WASM] 最终使用的路径:", { execUrl: n, moduleUrl: u }), await this.loadWasmExec(n);
58
+ const o = typeof self < "u" ? self : globalThis;
59
+ this.go = new o.Go();
60
+ const i = await fetch(u);
61
+ if (!i.ok)
62
+ throw new Error(`无法加载 WASM 文件: ${i.status}`);
63
+ const w = await i.arrayBuffer(), a = await WebAssembly.instantiate(w, this.go.importObject);
64
+ this.wasmModule = a.instance, this.go.run(this.wasmModule), this.wasmReady = !0;
65
+ const h = this.call("wasmInit");
66
+ if (h && h.success)
67
+ this.debugLog("✅ Worker WASM 加载成功:", h);
68
+ else
69
+ throw new Error("WASM 初始化失败");
70
+ } catch (r) {
71
+ throw this.wasmReady = !1, r;
72
+ }
53
73
  }
54
74
  /**
55
75
  * 在 Worker 中加载 wasm_exec.js
@@ -61,24 +81,25 @@ const q = class T {
61
81
  try {
62
82
  self.importScripts(t), e();
63
83
  return;
64
- } catch {
84
+ } catch (u) {
85
+ this.debugWarn("⚠️ importScripts 失败,使用 fetch:", u);
65
86
  }
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"))
87
+ fetch(t).then((u) => {
88
+ if (!u.ok)
89
+ throw new Error(`HTTP ${u.status}: ${u.statusText} - URL: ${t}`);
90
+ const o = u.headers.get("content-type") || "";
91
+ return !o.includes("javascript") && !o.includes("text/plain") && this.debugWarn("⚠️ [WASM] 响应 Content-Type 不是 JavaScript:", o), u.text();
92
+ }).then((u) => {
93
+ if (u.trim().startsWith("<!DOCTYPE") || u.trim().startsWith("<html"))
73
94
  throw new Error(`返回的是 HTML 而不是 JavaScript,可能是 404 错误。URL: ${t}`);
74
95
  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}`));
96
+ const o = typeof self < "u" ? self : globalThis;
97
+ new Function("self", u)(o), e();
98
+ } catch (o) {
99
+ r(new Error(`执行 wasm_exec.js 失败: ${o}`));
79
100
  }
80
- }).catch((o) => {
81
- r(o);
101
+ }).catch((u) => {
102
+ r(u);
82
103
  });
83
104
  });
84
105
  }
@@ -90,7 +111,7 @@ const q = class T {
90
111
  return !1;
91
112
  if (e)
92
113
  try {
93
- const r = this.getDeviceID(), n = this.getDomain(), u = await (await fetch(`${e}/jet_license/interface/license/verify`, {
114
+ const r = this.getDeviceID(), n = this.getDomain(), o = await (await fetch(`${e}/jet_license/interface/license/verify`, {
94
115
  method: "POST",
95
116
  headers: {
96
117
  "Content-Type": "application/json"
@@ -101,8 +122,8 @@ const q = class T {
101
122
  domain: n
102
123
  })
103
124
  })).json();
104
- if (!u.success || !u.valid) {
105
- const w = u.error || "License 验证失败";
125
+ if (!o.success || !o.valid) {
126
+ const w = o.error || "License 验证失败";
106
127
  throw new Error(w);
107
128
  }
108
129
  const i = this.call("wasmVerifyLicense", t);
@@ -261,12 +282,12 @@ const q = class T {
261
282
  if (!this.wasmReady)
262
283
  throw new Error("WASM 未加载");
263
284
  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;
285
+ const u = this.call("wasmGetArbitraryMeshPoint", t, e, JSON.stringify(r), n);
286
+ if (!u.success)
287
+ throw new Error(u.error || "计算失败");
288
+ return { x: u.x, y: u.y };
289
+ } catch (u) {
290
+ throw u;
270
291
  }
271
292
  }
272
293
  /**
@@ -343,62 +364,67 @@ const q = class T {
343
364
  throw new Error(`函数不存在: ${t}`);
344
365
  try {
345
366
  return n(...e);
346
- } catch (o) {
347
- throw o;
367
+ } catch (u) {
368
+ throw u;
348
369
  }
349
370
  }
350
371
  };
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(() => {
372
+ z(Z, "instance");
373
+ let ne = Z, H = !1;
374
+ const R = (...s) => {
375
+ }, se = (...s) => {
376
+ };
377
+ let E = null, _ = !1, M = null, v = null, O = null, $ = null, U = null;
378
+ function ue(s) {
379
+ v = s.licenseToken, O = s.licenseApiUrl, $ = s.deviceId, U = s.domain, self.LICENSE_TOKEN = v, self.LICENSE_API_URL = O, self.DEVICE_ID = $, self.DOMAIN = U, E || (M && !_ && (M = null), G().then(() => {
355
380
  }).catch((t) => {
356
381
  }));
357
382
  }
358
- async function z() {
359
- return d ? void 0 : L ? C || Promise.resolve() : b || self.LICENSE_TOKEN ? (L = !0, C = (async () => {
383
+ async function G() {
384
+ return E ? void 0 : _ ? M || Promise.resolve() : v || self.LICENSE_TOKEN ? (_ = !0, M = (async () => {
360
385
  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)
365
- return l;
366
- if (c === "wasm_exec.js" && a)
367
- return a;
386
+ E = ne.getInstance();
387
+ const t = (a) => {
388
+ const h = self.WASM_URL, c = self.WASM_EXEC_URL;
389
+ if (a === "perspective.wasm" && h)
390
+ return h;
391
+ if (a === "wasm_exec.js" && c)
392
+ return c;
368
393
  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;
394
+ let f = null;
395
+ if (typeof import.meta < "u" && import.meta.url ? f = import.meta.url : typeof self < "u" && self.location && (f = self.location.href), f) {
396
+ const l = new URL(f), d = l.pathname;
397
+ if (d.includes("/js/")) {
398
+ const y = "../assets/" + a, m = new URL(y, l);
399
+ return R(`🔍 [deform.worker] 计算路径: ${a} -> ${m.pathname} (Worker: ${d})`), m.pathname;
400
+ } else if (d.includes("/assets/")) {
401
+ const y = "./" + a, m = new URL(y, l);
402
+ return R(`🔍 [deform.worker] 计算路径: ${a} -> ${m.pathname} (Worker: ${d})`), m.pathname;
378
403
  } else
379
- return "/assets/" + c;
404
+ return R(`🔍 [deform.worker] 使用默认绝对路径: /assets/${a}`), "/assets/" + a;
380
405
  }
381
- } catch {
406
+ } catch (f) {
407
+ se("⚠️ [deform.worker] 无法计算 WASM 相对路径,使用默认路径:", f);
382
408
  }
383
- return "/assets/" + c;
409
+ return "/assets/" + a;
384
410
  }, 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;
411
+ R("🔍 [deform.worker] 最终使用的 WASM 路径:", { wasmUrl: e, wasmExecUrl: r }), await E.load(e, r);
412
+ const n = v || self.LICENSE_TOKEN, u = O || self.LICENSE_API_URL, o = $ || self.DEVICE_ID, i = U || self.DOMAIN;
387
413
  if (!n)
388
414
  throw new Error("LICENSE_TOKEN 未设置,无法使用 WASM 功能");
389
- if (!await d.verifyLicense(n, o))
415
+ if (!await E.verifyLicense(n, u))
390
416
  throw new Error("WASM License 验证失败,无法使用 WASM 功能");
391
417
  } catch (t) {
392
- throw d = null, C = null, t;
418
+ throw E = null, M = null, t;
393
419
  } finally {
394
- L = !1;
420
+ _ = !1;
395
421
  }
396
- })(), C) : Promise.resolve();
422
+ })(), M) : Promise.resolve();
397
423
  }
398
- function X(s) {
424
+ function Y(s) {
399
425
  return "naturalWidth" in s && s.naturalWidth ? { width: s.naturalWidth, height: s.naturalHeight } : "width" in s ? { width: s.width, height: s.height } : { width: 0, height: 0 };
400
426
  }
401
- function ne(s, t) {
427
+ function oe(s, t) {
402
428
  if (!s || !s.bounds)
403
429
  throw new Error("Invalid layer data: missing bounds");
404
430
  const e = s.bounds;
@@ -407,144 +433,144 @@ function ne(s, t) {
407
433
  const r = s.size || s.placedLayer || {
408
434
  width: e.width,
409
435
  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 = [
436
+ }, n = r.width / e.width, u = r.height / e.height, o = { ...s };
437
+ return s.transform && s.transform.length === 8 && (o.transform = [
412
438
  (s.transform[0] - e.left) * n,
413
- (s.transform[1] - e.top) * o,
439
+ (s.transform[1] - e.top) * u,
414
440
  (s.transform[2] - e.left) * n,
415
- (s.transform[3] - e.top) * o,
441
+ (s.transform[3] - e.top) * u,
416
442
  (s.transform[4] - e.left) * n,
417
- (s.transform[5] - e.top) * o,
443
+ (s.transform[5] - e.top) * u,
418
444
  (s.transform[6] - e.left) * n,
419
- (s.transform[7] - e.top) * o
420
- ]), u;
445
+ (s.transform[7] - e.top) * u
446
+ ]), o;
421
447
  }
422
- function se(s) {
448
+ function ie(s) {
423
449
  return s.error, s;
424
450
  }
425
- function oe(s, t, e) {
451
+ function ce(s, t, e) {
426
452
  if (!s || !t || !e)
427
453
  return "Invalid Parameters";
428
454
  const r = "naturalWidth" in t ? t.naturalWidth : "width" in t ? t.width : 0, n = "naturalHeight" in t ? t.naturalHeight : "height" in t ? t.height : 0;
429
455
  if (!r || !n)
430
456
  return "Image Not Loaded";
431
457
  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) {
434
- const f = e.transform;
435
- u = [
436
- { x: f[0], y: f[1] },
437
- { x: f[2], y: f[3] },
438
- { x: f[4], y: f[5] },
439
- { x: f[6], y: f[7] }
458
+ let u = null, o = null, i = null, w = null, a = 0, h = 0, c = null, f = "Unknown";
459
+ 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 && (u = e.meshPoints), e.transform && e.transform.length === 8) {
460
+ const l = e.transform;
461
+ o = [
462
+ { x: l[0], y: l[1] },
463
+ { x: l[2], y: l[3] },
464
+ { x: l[4], y: l[5] },
465
+ { x: l[6], y: l[7] }
440
466
  ];
441
467
  }
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;
468
+ return e.quiltSliceX && (i = e.quiltSliceX), e.quiltSliceY && (w = e.quiltSliceY), e.filterList && (c = e.filterList.find((l) => l.type === "puppet" && l.enabled)), a === 0 && i && i.length > 0 && (a = i[i.length - 1]), a === 0 && (a = 1e3), h === 0 && (h = 1e3), c && c.filter && c.filter.puppetShapeList && c.filter.puppetShapeList.length > 0 && o ? (ae(s, t, o, c.filter.puppetShapeList[0]), f = "Puppet Warp") : u && o ? i && w ? (he(s, t, o, u, i, w, a, h), f = "Quilt Mesh") : u.length === 16 ? (le(s, t, o, u), f = "Std Mesh (16pt)") : (fe(s, t, o, u), f = "Auto-Fit Mesh") : u ? (de(s, t, u), f = "Direct Mesh") : o && (K(s, t, o), f = "Transform Only"), f;
443
469
  }
444
- function ie(s, t, e, r, n, o) {
470
+ function ae(s, t, e, r, n, u) {
445
471
  if (!r.originalVertexArray || !r.deformedVertexArray || !r.indexArray)
446
472
  return;
447
- const u = G(e), i = he(u);
473
+ const o = q(e), i = ye(o);
448
474
  if (!i) {
449
- Y(s, t, e);
475
+ K(s, t, e);
450
476
  return;
451
477
  }
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);
478
+ const w = r.originalVertexArray, a = r.deformedVertexArray, h = r.indexArray;
479
+ for (let c = 0; c < h.length; c += 3) {
480
+ const f = h[c], l = h[c + 1], d = h[c + 2];
481
+ if (!w[f] || !w[l] || !w[d]) continue;
482
+ const y = w[f], m = w[l], g = w[d], p = X(y.x, y.y, i), x = X(m.x, m.y, i), F = X(g.x, g.y, i), A = Y(t), D = { x: p.x * A.width, y: p.y * A.height }, W = { x: x.x * A.width, y: x.y * A.height }, b = { x: F.x * A.width, y: F.y * A.height }, I = a[f], C = a[l], L = a[d];
483
+ k(s, t, D, W, b, I, C, L);
458
484
  }
459
485
  }
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);
486
+ function le(s, t, e, r) {
487
+ let n = 1 / 0, u = -1 / 0, o = 1 / 0, i = -1 / 0;
488
+ r.forEach((c) => {
489
+ n = Math.min(n, c.x), u = Math.max(u, c.x), o = Math.min(o, c.y), i = Math.max(i, c.y);
464
490
  });
465
- const w = o - n, c = i - u;
466
- if (w < 1 || c < 1) {
467
- Y(s, t, e);
491
+ const w = u - n, a = i - o;
492
+ if (w < 1 || a < 1) {
493
+ K(s, t, e);
468
494
  return;
469
495
  }
470
- const l = r.map((a) => {
471
- const h = (a.x - n) / w, f = (a.y - u) / c;
472
- return N(h, f, e);
496
+ const h = r.map((c) => {
497
+ const f = (c.x - n) / w, l = (c.y - o) / a;
498
+ return N(f, l, e);
473
499
  });
474
- H(s, t, l, "bicubic", 4, 40);
500
+ V(s, t, h, "bicubic", 4, 40);
475
501
  }
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);
502
+ function he(s, t, e, r, n, u, o, i) {
503
+ const w = q(e);
504
+ let a = 1 / 0, h = -1 / 0, c = 1 / 0, f = -1 / 0;
505
+ r.forEach((g) => {
506
+ a = Math.min(a, g.x), h = Math.max(h, g.x), c = Math.min(c, g.y), f = Math.max(f, g.y);
481
507
  });
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;
508
+ const l = h - a || 1, d = f - c || 1, y = n.length - 1, m = u.length - 1;
509
+ for (let g = 0; g < m; g++)
510
+ for (let p = 0; p < y; p++) {
511
+ const x = g * 3, F = p * 3, A = [], D = y * 3 + 1;
486
512
  try {
487
- 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]);
513
+ for (let S = 0; S < 4; S++)
514
+ for (let T = 0; T < 4; T++) {
515
+ const J = (x + S) * D + (F + T);
516
+ r[J] && A.push(r[J]);
491
517
  }
492
518
  } catch {
493
519
  continue;
494
520
  }
495
- 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);
521
+ if (A.length < 16) continue;
522
+ const W = A.map((S) => {
523
+ const T = (S.x - a) / l, J = (S.y - c) / d;
524
+ return ee(T, J, w);
525
+ }), b = n[p] / o, I = n[p + 1] / o, C = u[g] / i, L = u[g + 1] / i;
526
+ we(s, t, W, b, I, C, L);
501
527
  }
502
528
  }
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);
529
+ function fe(s, t, e, r) {
530
+ const n = q(e);
531
+ let u = 1 / 0, o = -1 / 0, i = 1 / 0, w = -1 / 0;
532
+ r.forEach((l) => {
533
+ u = Math.min(u, l.x), o = Math.max(o, l.x), i = Math.min(i, l.y), w = Math.max(w, l.y);
508
534
  });
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);
535
+ const a = o - u || 1, h = w - i || 1, c = r.map((l) => {
536
+ const d = (l.x - u) / a, y = (l.y - i) / h;
537
+ return ee(d, y, n);
538
+ }), f = Math.floor(Math.sqrt(r.length)) || 4;
539
+ V(s, t, c, "grid", f, 40);
514
540
  }
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);
541
+ function we(s, t, e, r, n, u, o) {
542
+ const w = Y(t), a = w.width, h = w.height;
543
+ for (let c = 0; c < 20; c++)
544
+ for (let f = 0; f < 20; f++) {
545
+ const l = f / 20, d = c / 20, y = (f + 1) / 20, m = (c + 1) / 20, g = r + l * (n - r), p = r + y * (n - r), x = u + d * (o - u), F = u + m * (o - u), A = { x: g * a, y: x * h }, D = { x: p * a, y: x * h }, W = { x: g * a, y: F * h }, b = { x: p * a, y: F * h }, I = B(l, d, e), C = B(y, d, e), L = B(l, m, e), S = B(y, m, e);
546
+ k(s, t, A, D, W, I, C, L), k(s, t, D, b, W, C, S, L);
521
547
  }
522
548
  }
523
- function Y(s, t, e) {
524
- H(s, t, e, "bilinear", 0, 10);
549
+ function K(s, t, e) {
550
+ V(s, t, e, "bilinear", 0, 10);
525
551
  }
526
- function fe(s, t, e) {
527
- H(s, t, e, "bicubic", 4, 40);
552
+ function de(s, t, e) {
553
+ V(s, t, e, "bicubic", 4, 40);
528
554
  }
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);
555
+ function V(s, t, e, r, n, u) {
556
+ const o = Y(t), i = o.width, w = o.height;
557
+ for (let a = 0; a < u; a++)
558
+ for (let h = 0; h < u; h++) {
559
+ const c = h / u, f = a / u, l = (h + 1) / u, d = (a + 1) / u, y = { x: c * i, y: f * w }, m = { x: l * i, y: f * w }, g = { x: c * i, y: d * w }, p = { x: l * i, y: d * w };
560
+ let x, F, A, D;
561
+ r === "bicubic" ? (x = B(c, f, e), F = B(l, f, e), A = B(c, d, e), D = B(l, d, e)) : r === "grid" ? (x = j(c, f, e, n), F = j(l, f, e, n), A = j(c, d, e, n), D = j(l, d, e, n)) : (x = N(c, f, e), F = N(l, f, e), A = N(c, d, e), D = N(l, d, e)), k(s, t, y, m, g, x, F, A), k(s, t, m, p, g, F, D, A);
536
562
  }
537
563
  }
538
- function K(s, t) {
564
+ function Q(s, t) {
539
565
  const e = 1 - t;
540
566
  return s === 0 ? e * e * e : s === 1 ? 3 * e * e * t : s === 2 ? 3 * e * t * t : t * t * t;
541
567
  }
542
- function v(s, t, e) {
568
+ function B(s, t, e) {
543
569
  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;
570
+ for (let u = 0; u < 4; u++)
571
+ for (let o = 0; o < 4; o++) {
572
+ const i = Q(u, t) * Q(o, s);
573
+ r += e[u * 4 + o].x * i, n += e[u * 4 + o].y * i;
548
574
  }
549
575
  return { x: r, y: n };
550
576
  }
@@ -552,67 +578,71 @@ function N(s, t, e) {
552
578
  const r = (1 - s) * (1 - t) * e[0].x + s * (1 - t) * e[1].x + s * t * e[2].x + (1 - s) * t * e[3].x, n = (1 - s) * (1 - t) * e[0].y + s * (1 - t) * e[1].y + s * t * e[2].y + (1 - s) * t * e[3].y;
553
579
  return { x: r, y: n };
554
580
  }
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);
581
+ function j(s, t, e, r) {
582
+ const n = r - 1, u = s * n, o = t * n;
583
+ let i = Math.floor(u), w = Math.floor(o);
558
584
  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 };
585
+ const a = u - i, h = o - w, c = e[w * r + i], f = e[w * r + (i + 1)], l = e[(w + 1) * r + i], d = e[(w + 1) * r + (i + 1)], y = (1 - a) * (1 - h) * c.x + a * (1 - h) * f.x + a * h * d.x + (1 - a) * h * l.x, m = (1 - a) * (1 - h) * c.y + a * (1 - h) * f.y + a * h * d.y + (1 - a) * h * l.y;
586
+ return { x: y, y: m };
561
587
  }
562
- function G(s) {
563
- if (!d || !d.isReady())
588
+ function q(s) {
589
+ if (!E || !E.isReady())
564
590
  throw new Error("WASM 模块未加载,无法计算透视变换矩阵");
565
591
  try {
566
- return d.calcPerspectiveMatrix(s);
592
+ return E.calcPerspectiveMatrix(s);
567
593
  } catch (t) {
568
594
  throw new Error(`WASM 计算透视矩阵失败: ${t}`);
569
595
  }
570
596
  }
571
- function he(s) {
572
- if (!d || !d.isReady())
597
+ function ye(s) {
598
+ if (!E || !E.isReady())
573
599
  throw new Error("WASM 模块未加载,无法求逆矩阵");
574
600
  try {
575
- return d.invertMatrix(s);
601
+ return E.invertMatrix(s);
576
602
  } catch (t) {
577
603
  throw new Error(`WASM 求逆矩阵失败: ${t}`);
578
604
  }
579
605
  }
580
- function V(s, t, e) {
581
- if (!d || !d.isReady())
606
+ function X(s, t, e) {
607
+ if (!E || !E.isReady())
582
608
  throw new Error("WASM 模块未加载,无法应用逆透视变换");
583
609
  try {
584
- return d.applyInversePerspective(s, t, e);
610
+ return E.applyInversePerspective(s, t, e);
585
611
  } catch (r) {
586
612
  throw new Error(`WASM 应用逆透视变换失败: ${r}`);
587
613
  }
588
614
  }
589
- function Q(s, t, e) {
590
- if (!d || !d.isReady())
615
+ function ee(s, t, e) {
616
+ if (!E || !E.isReady())
591
617
  throw new Error("WASM 模块未加载,无法应用透视变换");
592
618
  try {
593
- return d.applyPerspective(s, t, e);
619
+ return E.applyPerspective(s, t, e);
594
620
  } catch (r) {
595
621
  throw new Error(`WASM 应用透视变换失败: ${r}`);
596
622
  }
597
623
  }
598
- function j(s, t, e, r, n, o, u, i) {
624
+ function k(s, t, e, r, n, u, o, i) {
599
625
  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;
603
- if (Math.abs(x) < 1e-3) {
626
+ const a = (u.x + o.x + i.x) / 3, h = (u.y + o.y + i.y) / 3, c = (Math.hypot(u.x - a, u.y - h) + Math.hypot(o.x - a, o.y - h) + Math.hypot(i.x - a, i.y - h)) / 3, l = c > 1 ? (c + 1.65) / c : 1.5, d = a + (u.x - a) * l, y = h + (u.y - h) * l, m = a + (o.x - a) * l, g = h + (o.y - h) * l, p = a + (i.x - a) * l, x = h + (i.y - h) * l;
627
+ s.save(), s.beginPath(), s.moveTo(d, y), s.lineTo(m, g), s.lineTo(p, x), s.closePath(), s.clip();
628
+ const F = e.x * (n.y - r.y) - r.x * n.y + n.x * r.y + (r.x - n.x) * e.y;
629
+ if (Math.abs(F) < 1e-3) {
604
630
  s.restore();
605
631
  return;
606
632
  }
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();
633
+ const A = -(e.y * (i.x - o.x) - r.y * i.x + n.y * o.x + (r.y - n.y) * u.x) / F, D = (r.y * i.y + e.y * (o.y - i.y) - n.y * o.y + (n.y - r.y) * u.y) / F, W = (e.x * (i.x - o.x) - r.x * i.x + n.x * o.x + (r.x - n.x) * u.x) / F, b = -(r.x * i.y + e.x * (o.y - i.y) - n.x * o.y + (n.x - r.x) * u.y) / F, I = (e.x * (n.y * o.x - r.y * i.x) + e.y * (r.x * i.x - n.x * o.x) + (n.x * r.y - r.x * n.y) * u.x) / F, C = (e.x * (n.y * o.y - r.y * i.y) + e.y * (r.x * i.y - n.x * o.y) + (n.x * r.y - r.x * n.y) * u.y) / F;
634
+ s.transform(A, D, W, b, I, C), s.drawImage(t, 0, 0), s.restore();
609
635
  }
610
636
  self.onmessage = async (s) => {
637
+ if (s.data?.type === "SET_DEBUG") {
638
+ H = !!s.data?.debugRender, self.__DEBUG_RENDER__ = H;
639
+ return;
640
+ }
611
641
  if (s.data?.type === "SET_LICENSE") {
612
- re(s.data);
642
+ ue(s.data);
613
643
  return;
614
644
  }
615
- const t = s.data, { id: e, designBitmap: r, layerData: n, canvasSize: o } = t;
645
+ const t = s.data, { id: e, designBitmap: r, layerData: n, canvasSize: u } = t;
616
646
  if (!r) {
617
647
  self.postMessage({
618
648
  id: e,
@@ -631,53 +661,58 @@ self.onmessage = async (s) => {
631
661
  });
632
662
  return;
633
663
  }
634
- const u = performance.now();
635
- if ((/* @__PURE__ */ new Date()).toISOString(), !d || !d.isReady())
636
- if (b || self.LICENSE_TOKEN)
664
+ const o = performance.now(), i = (/* @__PURE__ */ new Date()).toISOString();
665
+ if (R(`[deform worker] 开始 id=${e} 时间=${i}`, {
666
+ designBitmap: { width: r.width, height: r.height },
667
+ size: n.size,
668
+ bounds: n.bounds,
669
+ canvasSize: u
670
+ }), !E || !E.isReady())
671
+ if (v || self.LICENSE_TOKEN)
637
672
  try {
638
- if (L && C && await C, (!d || !d.isReady()) && await z(), !d || !d.isReady())
673
+ if (_ && M && await M, (!E || !E.isReady()) && await G(), !E || !E.isReady())
639
674
  throw new Error("WASM 模块仍未就绪");
640
- } catch (w) {
641
- const l = performance.now() - u;
675
+ } catch (a) {
676
+ const c = performance.now() - o;
642
677
  self.postMessage({
643
678
  id: e,
644
- error: `WASM 初始化失败: ${w.message}`,
645
- duration: l
679
+ error: `WASM 初始化失败: ${a.message}`,
680
+ duration: c
646
681
  });
647
682
  return;
648
683
  }
649
684
  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)
685
+ let a = 0;
686
+ const h = 500, c = 50;
687
+ let f = null;
688
+ for (; a < h && !f; )
689
+ await new Promise((l) => setTimeout(l, c)), a += c, f = v || self.LICENSE_TOKEN;
690
+ if (f)
656
691
  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())
692
+ if (v = f, O = O || self.LICENSE_API_URL, $ = $ || self.DEVICE_ID, U = U || self.DOMAIN, _ && M ? await M : E || await G(), !E || !E.isReady())
658
693
  throw new Error("WASM 模块未就绪");
659
- } catch (h) {
660
- const y = performance.now() - u;
694
+ } catch (l) {
695
+ const y = performance.now() - o;
661
696
  self.postMessage({
662
697
  id: e,
663
- error: `WASM 初始化失败: ${h.message}`,
698
+ error: `WASM 初始化失败: ${l.message}`,
664
699
  duration: y
665
700
  });
666
701
  return;
667
702
  }
668
- else if (!a) {
669
- const f = performance.now() - u;
703
+ else if (!f) {
704
+ const d = performance.now() - o;
670
705
  self.postMessage({
671
706
  id: e,
672
707
  error: "LICENSE_TOKEN 未设置,无法使用 WASM 功能",
673
- duration: f
708
+ duration: d
674
709
  });
675
710
  return;
676
711
  }
677
712
  }
678
713
  try {
679
- const i = n.bounds;
680
- if (!i || !i.width || !i.height) {
714
+ const w = n.bounds;
715
+ if (!w || !w.width || !w.height) {
681
716
  self.postMessage({
682
717
  id: e,
683
718
  imageBitmap: null,
@@ -686,34 +721,40 @@ self.onmessage = async (s) => {
686
721
  });
687
722
  return;
688
723
  }
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;
724
+ const a = oe(n, u);
725
+ let h, c;
726
+ if (u && u.width > 0 && u.height > 0)
727
+ h = u.width, c = u.height;
693
728
  else {
694
- const M = n.size || n.placedLayer || {
695
- width: i.width,
696
- height: i.height
729
+ const F = n.size || n.placedLayer || {
730
+ width: w.width,
731
+ height: w.height
697
732
  };
698
- c = M.width, l = M.height;
733
+ h = F.width, c = F.height;
699
734
  }
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 });
735
+ const f = new OffscreenCanvas(h, c), l = f.getContext("2d");
736
+ if (!l) {
737
+ const A = performance.now() - o;
738
+ self.postMessage({ id: e, error: "Canvas context unavailable", duration: A });
704
739
  return;
705
740
  }
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 }
741
+ const d = ce(l, r, a), y = f.transferToImageBitmap(), g = performance.now() - o, p = (/* @__PURE__ */ new Date()).toISOString();
742
+ R(
743
+ `[deform worker] 结束 id=${e} 时间=${p} 耗时=${Math.round(g)}ms 变形方法=${d}`,
744
+ {
745
+ width: y.width,
746
+ height: y.height
747
+ }
748
+ ), r.close();
749
+ const x = ie(
750
+ { id: e, imageBitmap: y, duration: g }
710
751
  );
711
752
  self.postMessage(
712
- g,
713
- g.imageBitmap ? [g.imageBitmap] : []
753
+ x,
754
+ x.imageBitmap ? [x.imageBitmap] : []
714
755
  );
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 });
756
+ } catch (w) {
757
+ const h = performance.now() - o, c = w instanceof Error ? w.message : String(w);
758
+ (/* @__PURE__ */ new Date()).toISOString(), self.postMessage({ id: e, error: c, duration: h });
718
759
  }
719
760
  };