@jieyin/editor-sdk 1.1.136 → 1.1.138
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/deform.worker.js +300 -259
- package/dist/editor-sdk.es.js +7747 -7604
- package/dist/renderWorker.js +1796 -1714
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/deform.worker.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
var
|
|
2
|
-
const
|
|
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
|
-
|
|
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
|
|
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 (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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((
|
|
67
|
-
if (!
|
|
68
|
-
throw new Error(`HTTP ${
|
|
69
|
-
const
|
|
70
|
-
return !
|
|
71
|
-
}).then((
|
|
72
|
-
if (
|
|
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
|
|
76
|
-
new Function("self",
|
|
77
|
-
} catch (
|
|
78
|
-
r(new Error(`执行 wasm_exec.js 失败: ${
|
|
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((
|
|
81
|
-
r(
|
|
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(),
|
|
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 (!
|
|
105
|
-
const w =
|
|
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
|
|
265
|
-
if (!
|
|
266
|
-
throw new Error(
|
|
267
|
-
return { x:
|
|
268
|
-
} catch (
|
|
269
|
-
throw
|
|
285
|
+
const u = this.call("wasmGetArbitraryMeshPoint", t, e, JSON.stringify(r), n);
|
|
286
|
+
if (!u.success)
|
|
287
|
+
throw new Error(u.error || "计算失败");
|
|
288
|
+
return { x: u.x, y: u.y };
|
|
289
|
+
} catch (u) {
|
|
290
|
+
throw u;
|
|
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 (
|
|
347
|
-
throw
|
|
367
|
+
} catch (u) {
|
|
368
|
+
throw u;
|
|
348
369
|
}
|
|
349
370
|
}
|
|
350
371
|
};
|
|
351
|
-
|
|
352
|
-
let
|
|
353
|
-
|
|
354
|
-
|
|
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
|
|
359
|
-
return
|
|
383
|
+
async function G() {
|
|
384
|
+
return E ? void 0 : _ ? M || Promise.resolve() : v || self.LICENSE_TOKEN ? (_ = !0, M = (async () => {
|
|
360
385
|
try {
|
|
361
|
-
|
|
362
|
-
const t = (
|
|
363
|
-
const
|
|
364
|
-
if (
|
|
365
|
-
return
|
|
366
|
-
if (
|
|
367
|
-
return
|
|
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
|
|
370
|
-
if (typeof import.meta < "u" && import.meta.url ?
|
|
371
|
-
const
|
|
372
|
-
if (
|
|
373
|
-
const
|
|
374
|
-
return
|
|
375
|
-
} else if (
|
|
376
|
-
const
|
|
377
|
-
return
|
|
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/" +
|
|
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/" +
|
|
409
|
+
return "/assets/" + a;
|
|
384
410
|
}, e = self.WASM_URL || t("perspective.wasm"), r = self.WASM_EXEC_URL || t("wasm_exec.js");
|
|
385
|
-
await
|
|
386
|
-
const n =
|
|
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
|
|
415
|
+
if (!await E.verifyLicense(n, u))
|
|
390
416
|
throw new Error("WASM License 验证失败,无法使用 WASM 功能");
|
|
391
417
|
} catch (t) {
|
|
392
|
-
throw
|
|
418
|
+
throw E = null, M = null, t;
|
|
393
419
|
} finally {
|
|
394
|
-
|
|
420
|
+
_ = !1;
|
|
395
421
|
}
|
|
396
|
-
})(),
|
|
422
|
+
})(), M) : Promise.resolve();
|
|
397
423
|
}
|
|
398
|
-
function
|
|
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
|
|
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,
|
|
411
|
-
return s.transform && s.transform.length === 8 && (
|
|
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) *
|
|
439
|
+
(s.transform[1] - e.top) * u,
|
|
414
440
|
(s.transform[2] - e.left) * n,
|
|
415
|
-
(s.transform[3] - e.top) *
|
|
441
|
+
(s.transform[3] - e.top) * u,
|
|
416
442
|
(s.transform[4] - e.left) * n,
|
|
417
|
-
(s.transform[5] - e.top) *
|
|
443
|
+
(s.transform[5] - e.top) * u,
|
|
418
444
|
(s.transform[6] - e.left) * n,
|
|
419
|
-
(s.transform[7] - e.top) *
|
|
420
|
-
]),
|
|
445
|
+
(s.transform[7] - e.top) * u
|
|
446
|
+
]), o;
|
|
421
447
|
}
|
|
422
|
-
function
|
|
448
|
+
function ie(s) {
|
|
423
449
|
return s.error, s;
|
|
424
450
|
}
|
|
425
|
-
function
|
|
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
|
|
433
|
-
if (e.size && e.size.width ? (
|
|
434
|
-
const
|
|
435
|
-
|
|
436
|
-
{ x:
|
|
437
|
-
{ x:
|
|
438
|
-
{ x:
|
|
439
|
-
{ x:
|
|
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 && (
|
|
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
|
|
470
|
+
function ae(s, t, e, r, n, u) {
|
|
445
471
|
if (!r.originalVertexArray || !r.deformedVertexArray || !r.indexArray)
|
|
446
472
|
return;
|
|
447
|
-
const
|
|
473
|
+
const o = q(e), i = ye(o);
|
|
448
474
|
if (!i) {
|
|
449
|
-
|
|
475
|
+
K(s, t, e);
|
|
450
476
|
return;
|
|
451
477
|
}
|
|
452
|
-
const w = r.originalVertexArray,
|
|
453
|
-
for (let
|
|
454
|
-
const
|
|
455
|
-
if (!w[
|
|
456
|
-
const
|
|
457
|
-
|
|
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
|
|
461
|
-
let n = 1 / 0,
|
|
462
|
-
r.forEach((
|
|
463
|
-
n = Math.min(n,
|
|
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 =
|
|
466
|
-
if (w < 1 ||
|
|
467
|
-
|
|
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
|
|
471
|
-
const
|
|
472
|
-
return N(
|
|
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
|
-
|
|
500
|
+
V(s, t, h, "bicubic", 4, 40);
|
|
475
501
|
}
|
|
476
|
-
function
|
|
477
|
-
const w =
|
|
478
|
-
let
|
|
479
|
-
r.forEach((
|
|
480
|
-
|
|
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
|
|
483
|
-
for (let
|
|
484
|
-
for (let
|
|
485
|
-
const
|
|
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
|
|
488
|
-
for (let
|
|
489
|
-
const J = (
|
|
490
|
-
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 (
|
|
496
|
-
const W =
|
|
497
|
-
const
|
|
498
|
-
return
|
|
499
|
-
}),
|
|
500
|
-
|
|
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
|
|
504
|
-
const n =
|
|
505
|
-
let
|
|
506
|
-
r.forEach((
|
|
507
|
-
|
|
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
|
|
510
|
-
const
|
|
511
|
-
return
|
|
512
|
-
}),
|
|
513
|
-
|
|
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
|
|
516
|
-
const w =
|
|
517
|
-
for (let
|
|
518
|
-
for (let
|
|
519
|
-
const
|
|
520
|
-
|
|
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
|
|
524
|
-
|
|
549
|
+
function K(s, t, e) {
|
|
550
|
+
V(s, t, e, "bilinear", 0, 10);
|
|
525
551
|
}
|
|
526
|
-
function
|
|
527
|
-
|
|
552
|
+
function de(s, t, e) {
|
|
553
|
+
V(s, t, e, "bicubic", 4, 40);
|
|
528
554
|
}
|
|
529
|
-
function
|
|
530
|
-
const
|
|
531
|
-
for (let
|
|
532
|
-
for (let
|
|
533
|
-
const
|
|
534
|
-
let
|
|
535
|
-
r === "bicubic" ? (
|
|
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
|
|
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
|
|
568
|
+
function B(s, t, e) {
|
|
543
569
|
let r = 0, n = 0;
|
|
544
|
-
for (let
|
|
545
|
-
for (let
|
|
546
|
-
const i =
|
|
547
|
-
r += e[
|
|
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
|
|
556
|
-
const n = r - 1,
|
|
557
|
-
let i = Math.floor(
|
|
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
|
|
560
|
-
return { x:
|
|
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
|
|
563
|
-
if (!
|
|
588
|
+
function q(s) {
|
|
589
|
+
if (!E || !E.isReady())
|
|
564
590
|
throw new Error("WASM 模块未加载,无法计算透视变换矩阵");
|
|
565
591
|
try {
|
|
566
|
-
return
|
|
592
|
+
return E.calcPerspectiveMatrix(s);
|
|
567
593
|
} catch (t) {
|
|
568
594
|
throw new Error(`WASM 计算透视矩阵失败: ${t}`);
|
|
569
595
|
}
|
|
570
596
|
}
|
|
571
|
-
function
|
|
572
|
-
if (!
|
|
597
|
+
function ye(s) {
|
|
598
|
+
if (!E || !E.isReady())
|
|
573
599
|
throw new Error("WASM 模块未加载,无法求逆矩阵");
|
|
574
600
|
try {
|
|
575
|
-
return
|
|
601
|
+
return E.invertMatrix(s);
|
|
576
602
|
} catch (t) {
|
|
577
603
|
throw new Error(`WASM 求逆矩阵失败: ${t}`);
|
|
578
604
|
}
|
|
579
605
|
}
|
|
580
|
-
function
|
|
581
|
-
if (!
|
|
606
|
+
function X(s, t, e) {
|
|
607
|
+
if (!E || !E.isReady())
|
|
582
608
|
throw new Error("WASM 模块未加载,无法应用逆透视变换");
|
|
583
609
|
try {
|
|
584
|
-
return
|
|
610
|
+
return E.applyInversePerspective(s, t, e);
|
|
585
611
|
} catch (r) {
|
|
586
612
|
throw new Error(`WASM 应用逆透视变换失败: ${r}`);
|
|
587
613
|
}
|
|
588
614
|
}
|
|
589
|
-
function
|
|
590
|
-
if (!
|
|
615
|
+
function ee(s, t, e) {
|
|
616
|
+
if (!E || !E.isReady())
|
|
591
617
|
throw new Error("WASM 模块未加载,无法应用透视变换");
|
|
592
618
|
try {
|
|
593
|
-
return
|
|
619
|
+
return E.applyPerspective(s, t, e);
|
|
594
620
|
} catch (r) {
|
|
595
621
|
throw new Error(`WASM 应用透视变换失败: ${r}`);
|
|
596
622
|
}
|
|
597
623
|
}
|
|
598
|
-
function
|
|
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
|
|
601
|
-
s.save(), s.beginPath(), s.moveTo(
|
|
602
|
-
const
|
|
603
|
-
if (Math.abs(
|
|
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
|
|
608
|
-
s.transform(
|
|
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
|
-
|
|
642
|
+
ue(s.data);
|
|
613
643
|
return;
|
|
614
644
|
}
|
|
615
|
-
const t = s.data, { id: e, designBitmap: r, layerData: n, canvasSize:
|
|
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
|
|
635
|
-
if ((
|
|
636
|
-
|
|
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 (
|
|
673
|
+
if (_ && M && await M, (!E || !E.isReady()) && await G(), !E || !E.isReady())
|
|
639
674
|
throw new Error("WASM 模块仍未就绪");
|
|
640
|
-
} catch (
|
|
641
|
-
const
|
|
675
|
+
} catch (a) {
|
|
676
|
+
const c = performance.now() - o;
|
|
642
677
|
self.postMessage({
|
|
643
678
|
id: e,
|
|
644
|
-
error: `WASM 初始化失败: ${
|
|
645
|
-
duration:
|
|
679
|
+
error: `WASM 初始化失败: ${a.message}`,
|
|
680
|
+
duration: c
|
|
646
681
|
});
|
|
647
682
|
return;
|
|
648
683
|
}
|
|
649
684
|
else {
|
|
650
|
-
let
|
|
651
|
-
const
|
|
652
|
-
let
|
|
653
|
-
for (;
|
|
654
|
-
await new Promise((
|
|
655
|
-
if (
|
|
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 (
|
|
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 (
|
|
660
|
-
const y = performance.now() -
|
|
694
|
+
} catch (l) {
|
|
695
|
+
const y = performance.now() - o;
|
|
661
696
|
self.postMessage({
|
|
662
697
|
id: e,
|
|
663
|
-
error: `WASM 初始化失败: ${
|
|
698
|
+
error: `WASM 初始化失败: ${l.message}`,
|
|
664
699
|
duration: y
|
|
665
700
|
});
|
|
666
701
|
return;
|
|
667
702
|
}
|
|
668
|
-
else if (!
|
|
669
|
-
const
|
|
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:
|
|
708
|
+
duration: d
|
|
674
709
|
});
|
|
675
710
|
return;
|
|
676
711
|
}
|
|
677
712
|
}
|
|
678
713
|
try {
|
|
679
|
-
const
|
|
680
|
-
if (!
|
|
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
|
|
690
|
-
let
|
|
691
|
-
if (
|
|
692
|
-
|
|
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
|
|
695
|
-
width:
|
|
696
|
-
height:
|
|
729
|
+
const F = n.size || n.placedLayer || {
|
|
730
|
+
width: w.width,
|
|
731
|
+
height: w.height
|
|
697
732
|
};
|
|
698
|
-
|
|
733
|
+
h = F.width, c = F.height;
|
|
699
734
|
}
|
|
700
|
-
const
|
|
701
|
-
if (!
|
|
702
|
-
const
|
|
703
|
-
self.postMessage({ id: e, error: "Canvas context unavailable", duration:
|
|
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
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
{
|
|
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
|
-
|
|
713
|
-
|
|
753
|
+
x,
|
|
754
|
+
x.imageBitmap ? [x.imageBitmap] : []
|
|
714
755
|
);
|
|
715
|
-
} catch (
|
|
716
|
-
const
|
|
717
|
-
(/* @__PURE__ */ new Date()).toISOString(), self.postMessage({ id: e, error:
|
|
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
|
};
|