@jieyin/editor-sdk-test 1.1.179 → 1.1.187
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 +1111 -367
- package/dist/editor-sdk.es.js +13692 -10345
- package/dist/encodeWorker.js +20 -0
- package/dist/maskWorker.js +28 -28
- package/dist/renderWorker.js +3526 -3527
- package/dist/style.css +1 -1
- package/package.json +50 -51
package/dist/deform.worker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
var
|
|
2
|
-
const
|
|
1
|
+
var Zt = Object.defineProperty, zt = (t, n, e) => n in t ? Zt(t, n, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[n] = e, It = (t, n, e) => zt(t, typeof n != "symbol" ? n + "" : n, e);
|
|
2
|
+
const Gt = class ct {
|
|
3
3
|
constructor() {
|
|
4
|
-
|
|
4
|
+
It(this, "wasmReady", !1), It(this, "go", null), It(this, "wasmModule", null);
|
|
5
5
|
}
|
|
6
6
|
isDebugEnabled() {
|
|
7
7
|
try {
|
|
@@ -10,61 +10,61 @@ const Z = class P {
|
|
|
10
10
|
}
|
|
11
11
|
return !1;
|
|
12
12
|
}
|
|
13
|
-
debugLog(...
|
|
13
|
+
debugLog(...n) {
|
|
14
14
|
this.isDebugEnabled();
|
|
15
15
|
}
|
|
16
|
-
debugWarn(...
|
|
16
|
+
debugWarn(...n) {
|
|
17
17
|
this.isDebugEnabled();
|
|
18
18
|
}
|
|
19
19
|
static getInstance() {
|
|
20
|
-
return
|
|
20
|
+
return ct.instance || (ct.instance = new ct()), ct.instance;
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
23
|
* 在 Worker 环境中加载 WASM 模块
|
|
24
24
|
* @param wasmUrl WASM 文件路径
|
|
25
25
|
* @param wasmExecUrl wasm_exec.js 路径
|
|
26
26
|
*/
|
|
27
|
-
async load(
|
|
27
|
+
async load(n, e) {
|
|
28
28
|
if (this.wasmReady) {
|
|
29
29
|
this.debugLog("✅ WASM 已加载,跳过重复加载");
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
try {
|
|
33
33
|
this.debugLog("🚀 Worker: 加载透视变换 WASM...");
|
|
34
|
-
const r = (
|
|
35
|
-
if (e &&
|
|
34
|
+
const r = (d) => {
|
|
35
|
+
if (e && d === "wasm_exec.js")
|
|
36
36
|
return e;
|
|
37
|
-
if (
|
|
38
|
-
return
|
|
37
|
+
if (n && d === "perspective.wasm")
|
|
38
|
+
return n;
|
|
39
39
|
try {
|
|
40
40
|
let h = null;
|
|
41
41
|
if (typeof import.meta < "u" && import.meta.url ? h = import.meta.url : typeof self < "u" && self.location && (h = self.location.href), h) {
|
|
42
|
-
const
|
|
43
|
-
if (
|
|
44
|
-
const
|
|
45
|
-
return this.debugLog(`🔍 [WASM] 计算路径: ${
|
|
46
|
-
} else if (
|
|
47
|
-
const
|
|
48
|
-
return this.debugLog(`🔍 [WASM] 计算路径: ${
|
|
42
|
+
const p = new URL(h), A = p.pathname;
|
|
43
|
+
if (A.includes("/js/")) {
|
|
44
|
+
const g = "../assets/" + d, a = new URL(g, p);
|
|
45
|
+
return this.debugLog(`🔍 [WASM] 计算路径: ${d} -> ${a.pathname} (Worker: ${A})`), a.pathname;
|
|
46
|
+
} else if (A.includes("/assets/")) {
|
|
47
|
+
const g = "./" + d, a = new URL(g, p);
|
|
48
|
+
return this.debugLog(`🔍 [WASM] 计算路径: ${d} -> ${a.pathname} (Worker: ${A})`), a.pathname;
|
|
49
49
|
} else
|
|
50
|
-
return this.debugLog(`🔍 [WASM] 使用默认绝对路径: /assets/${
|
|
50
|
+
return this.debugLog(`🔍 [WASM] 使用默认绝对路径: /assets/${d}`), "/assets/" + d;
|
|
51
51
|
}
|
|
52
52
|
} catch (h) {
|
|
53
53
|
this.debugWarn("⚠️ 无法计算 WASM 相对路径,使用默认路径:", h);
|
|
54
54
|
}
|
|
55
|
-
return "/assets/" +
|
|
56
|
-
},
|
|
57
|
-
this.debugLog("🔍 [WASM] 最终使用的路径:", { execUrl:
|
|
58
|
-
const
|
|
59
|
-
this.go = new
|
|
60
|
-
const
|
|
61
|
-
if (!
|
|
62
|
-
throw new Error(`无法加载 WASM 文件: ${
|
|
63
|
-
const
|
|
64
|
-
this.wasmModule =
|
|
65
|
-
const
|
|
66
|
-
if (
|
|
67
|
-
this.debugLog("✅ Worker WASM 加载成功:",
|
|
55
|
+
return "/assets/" + d;
|
|
56
|
+
}, s = e || r("wasm_exec.js"), o = n || r("perspective.wasm");
|
|
57
|
+
this.debugLog("🔍 [WASM] 最终使用的路径:", { execUrl: s, moduleUrl: o }), await this.loadWasmExec(s);
|
|
58
|
+
const i = typeof self < "u" ? self : globalThis;
|
|
59
|
+
this.go = new i.Go();
|
|
60
|
+
const u = await fetch(o);
|
|
61
|
+
if (!u.ok)
|
|
62
|
+
throw new Error(`无法加载 WASM 文件: ${u.status}`);
|
|
63
|
+
const c = await u.arrayBuffer(), l = await WebAssembly.instantiate(c, this.go.importObject);
|
|
64
|
+
this.wasmModule = l.instance, this.go.run(this.wasmModule), this.wasmReady = !0;
|
|
65
|
+
const f = this.call("wasmInit");
|
|
66
|
+
if (f && f.success)
|
|
67
|
+
this.debugLog("✅ Worker WASM 加载成功:", f);
|
|
68
68
|
else
|
|
69
69
|
throw new Error("WASM 初始化失败");
|
|
70
70
|
} catch (r) {
|
|
@@ -75,59 +75,59 @@ const Z = class P {
|
|
|
75
75
|
* 在 Worker 中加载 wasm_exec.js
|
|
76
76
|
* Module Worker 不支持 importScripts(),仅 Classic Worker 可尝试 importScripts,否则用 fetch + eval
|
|
77
77
|
*/
|
|
78
|
-
async loadWasmExec(
|
|
78
|
+
async loadWasmExec(n) {
|
|
79
79
|
return new Promise((e, r) => {
|
|
80
80
|
if (!(typeof import.meta < "u" && import.meta.url) && typeof self.importScripts == "function")
|
|
81
81
|
try {
|
|
82
|
-
self.importScripts(
|
|
82
|
+
self.importScripts(n), e();
|
|
83
83
|
return;
|
|
84
|
-
} catch (
|
|
85
|
-
this.debugWarn("⚠️ importScripts 失败,使用 fetch:",
|
|
84
|
+
} catch (o) {
|
|
85
|
+
this.debugWarn("⚠️ importScripts 失败,使用 fetch:", o);
|
|
86
86
|
}
|
|
87
|
-
fetch(
|
|
88
|
-
if (!
|
|
89
|
-
throw new Error(`HTTP ${
|
|
90
|
-
const
|
|
91
|
-
return !
|
|
92
|
-
}).then((
|
|
93
|
-
if (
|
|
94
|
-
throw new Error(`返回的是 HTML 而不是 JavaScript,可能是 404 错误。URL: ${
|
|
87
|
+
fetch(n).then((o) => {
|
|
88
|
+
if (!o.ok)
|
|
89
|
+
throw new Error(`HTTP ${o.status}: ${o.statusText} - URL: ${n}`);
|
|
90
|
+
const i = o.headers.get("content-type") || "";
|
|
91
|
+
return !i.includes("javascript") && !i.includes("text/plain") && this.debugWarn("⚠️ [WASM] 响应 Content-Type 不是 JavaScript:", i), o.text();
|
|
92
|
+
}).then((o) => {
|
|
93
|
+
if (o.trim().startsWith("<!DOCTYPE") || o.trim().startsWith("<html"))
|
|
94
|
+
throw new Error(`返回的是 HTML 而不是 JavaScript,可能是 404 错误。URL: ${n}`);
|
|
95
95
|
try {
|
|
96
|
-
const
|
|
97
|
-
new Function("self",
|
|
98
|
-
} catch (
|
|
99
|
-
r(new Error(`执行 wasm_exec.js 失败: ${
|
|
96
|
+
const i = typeof self < "u" ? self : globalThis;
|
|
97
|
+
new Function("self", o)(i), e();
|
|
98
|
+
} catch (i) {
|
|
99
|
+
r(new Error(`执行 wasm_exec.js 失败: ${i}`));
|
|
100
100
|
}
|
|
101
|
-
}).catch((
|
|
102
|
-
r(
|
|
101
|
+
}).catch((o) => {
|
|
102
|
+
r(o);
|
|
103
103
|
});
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
* 验证授权(通过 API)
|
|
108
108
|
*/
|
|
109
|
-
async verifyLicense(
|
|
109
|
+
async verifyLicense(n, e) {
|
|
110
110
|
if (!this.wasmReady)
|
|
111
111
|
return !1;
|
|
112
112
|
if (e)
|
|
113
113
|
try {
|
|
114
|
-
const r = this.getDeviceID(),
|
|
114
|
+
const r = this.getDeviceID(), s = this.getDomain(), i = await (await fetch(`${e}/jet_license/interface/license/verify`, {
|
|
115
115
|
method: "POST",
|
|
116
116
|
headers: {
|
|
117
117
|
"Content-Type": "application/json"
|
|
118
118
|
},
|
|
119
119
|
body: JSON.stringify({
|
|
120
|
-
token:
|
|
120
|
+
token: n,
|
|
121
121
|
deviceId: r,
|
|
122
|
-
domain:
|
|
122
|
+
domain: s
|
|
123
123
|
})
|
|
124
124
|
})).json();
|
|
125
|
-
if (!
|
|
126
|
-
const
|
|
127
|
-
throw new Error(
|
|
125
|
+
if (!i.success || !i.valid) {
|
|
126
|
+
const c = i.error || "License 验证失败";
|
|
127
|
+
throw new Error(c);
|
|
128
128
|
}
|
|
129
|
-
const
|
|
130
|
-
if (!
|
|
129
|
+
const u = this.call("wasmVerifyLicense", n);
|
|
130
|
+
if (!u.success || u.valid !== !0)
|
|
131
131
|
throw new Error("WASM 验证失败");
|
|
132
132
|
return !0;
|
|
133
133
|
} catch (r) {
|
|
@@ -135,7 +135,7 @@ const Z = class P {
|
|
|
135
135
|
}
|
|
136
136
|
else
|
|
137
137
|
try {
|
|
138
|
-
const r = this.call("wasmVerifyLicense",
|
|
138
|
+
const r = this.call("wasmVerifyLicense", n);
|
|
139
139
|
return r.success && r.valid === !0;
|
|
140
140
|
} catch {
|
|
141
141
|
return !1;
|
|
@@ -156,13 +156,13 @@ const Z = class P {
|
|
|
156
156
|
/**
|
|
157
157
|
* 计算透视变换矩阵
|
|
158
158
|
*/
|
|
159
|
-
calcPerspectiveMatrix(
|
|
159
|
+
calcPerspectiveMatrix(n) {
|
|
160
160
|
if (!this.wasmReady)
|
|
161
161
|
throw new Error("WASM 未加载");
|
|
162
|
-
if (
|
|
162
|
+
if (n.length !== 4)
|
|
163
163
|
throw new Error("需要恰好 4 个点");
|
|
164
164
|
try {
|
|
165
|
-
const e = this.call("wasmCalcPerspectiveMatrix", JSON.stringify(
|
|
165
|
+
const e = this.call("wasmCalcPerspectiveMatrix", JSON.stringify(n));
|
|
166
166
|
if (!e.success)
|
|
167
167
|
throw new Error(e.error || "计算失败");
|
|
168
168
|
return e.matrix;
|
|
@@ -173,11 +173,11 @@ const Z = class P {
|
|
|
173
173
|
/**
|
|
174
174
|
* 矩阵求逆
|
|
175
175
|
*/
|
|
176
|
-
invertMatrix(
|
|
176
|
+
invertMatrix(n) {
|
|
177
177
|
if (!this.wasmReady)
|
|
178
178
|
throw new Error("WASM 未加载");
|
|
179
179
|
try {
|
|
180
|
-
const e = this.call("wasmInvertMatrix", JSON.stringify(
|
|
180
|
+
const e = this.call("wasmInvertMatrix", JSON.stringify(n));
|
|
181
181
|
if (!e.success)
|
|
182
182
|
throw new Error(e.error || "矩阵求逆失败");
|
|
183
183
|
return e.matrix;
|
|
@@ -188,51 +188,51 @@ const Z = class P {
|
|
|
188
188
|
/**
|
|
189
189
|
* 应用透视变换到单个点
|
|
190
190
|
*/
|
|
191
|
-
applyPerspective(
|
|
191
|
+
applyPerspective(n, e, r) {
|
|
192
192
|
if (!this.wasmReady)
|
|
193
193
|
throw new Error("WASM 未加载");
|
|
194
194
|
try {
|
|
195
|
-
const
|
|
196
|
-
if (!
|
|
197
|
-
throw new Error(
|
|
198
|
-
return { x:
|
|
199
|
-
} catch (
|
|
200
|
-
throw
|
|
195
|
+
const s = this.call("wasmApplyPerspective", n, e, JSON.stringify(r));
|
|
196
|
+
if (!s.success)
|
|
197
|
+
throw new Error(s.error || "变换失败");
|
|
198
|
+
return { x: s.x, y: s.y };
|
|
199
|
+
} catch (s) {
|
|
200
|
+
throw s;
|
|
201
201
|
}
|
|
202
202
|
}
|
|
203
203
|
/**
|
|
204
204
|
* 应用逆透视变换到单个点
|
|
205
205
|
*/
|
|
206
|
-
applyInversePerspective(
|
|
206
|
+
applyInversePerspective(n, e, r) {
|
|
207
207
|
if (!this.wasmReady)
|
|
208
208
|
throw new Error("WASM 未加载");
|
|
209
209
|
try {
|
|
210
|
-
const
|
|
211
|
-
if (!
|
|
212
|
-
throw new Error(
|
|
213
|
-
return { x:
|
|
214
|
-
} catch (
|
|
215
|
-
throw
|
|
210
|
+
const s = this.call("wasmApplyInversePerspective", n, e, JSON.stringify(r));
|
|
211
|
+
if (!s.success)
|
|
212
|
+
throw new Error(s.error || "逆变换失败");
|
|
213
|
+
return { x: s.x, y: s.y };
|
|
214
|
+
} catch (s) {
|
|
215
|
+
throw s;
|
|
216
216
|
}
|
|
217
217
|
}
|
|
218
218
|
/**
|
|
219
219
|
* 批量变换点(高性能)
|
|
220
220
|
*/
|
|
221
|
-
transformPoints(
|
|
221
|
+
transformPoints(n, e, r = !1) {
|
|
222
222
|
if (!this.wasmReady)
|
|
223
223
|
throw new Error("WASM 未加载");
|
|
224
224
|
try {
|
|
225
|
-
const
|
|
225
|
+
const s = this.call(
|
|
226
226
|
"wasmTransformPoints",
|
|
227
|
-
JSON.stringify(
|
|
227
|
+
JSON.stringify(n),
|
|
228
228
|
JSON.stringify(e),
|
|
229
229
|
r
|
|
230
230
|
);
|
|
231
|
-
if (!
|
|
232
|
-
throw new Error(
|
|
233
|
-
return JSON.parse(
|
|
234
|
-
} catch (
|
|
235
|
-
throw
|
|
231
|
+
if (!s.success)
|
|
232
|
+
throw new Error(s.error || "批量变换失败");
|
|
233
|
+
return JSON.parse(s.points);
|
|
234
|
+
} catch (s) {
|
|
235
|
+
throw s;
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
238
|
/**
|
|
@@ -244,57 +244,57 @@ const Z = class P {
|
|
|
244
244
|
/**
|
|
245
245
|
* 双三次插值点计算
|
|
246
246
|
*/
|
|
247
|
-
getBicubicPoint(
|
|
247
|
+
getBicubicPoint(n, e, r) {
|
|
248
248
|
if (!this.wasmReady)
|
|
249
249
|
throw new Error("WASM 未加载");
|
|
250
250
|
if (r.length !== 16)
|
|
251
251
|
throw new Error("需要恰好 16 个点");
|
|
252
252
|
try {
|
|
253
|
-
const
|
|
254
|
-
if (!
|
|
255
|
-
throw new Error(
|
|
256
|
-
return { x:
|
|
257
|
-
} catch (
|
|
258
|
-
throw
|
|
253
|
+
const s = this.call("wasmGetBicubicPoint", n, e, JSON.stringify(r));
|
|
254
|
+
if (!s.success)
|
|
255
|
+
throw new Error(s.error || "计算失败");
|
|
256
|
+
return { x: s.x, y: s.y };
|
|
257
|
+
} catch (s) {
|
|
258
|
+
throw s;
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
/**
|
|
262
262
|
* 双线性插值点计算
|
|
263
263
|
*/
|
|
264
|
-
getBilinearPoint(
|
|
264
|
+
getBilinearPoint(n, e, r) {
|
|
265
265
|
if (!this.wasmReady)
|
|
266
266
|
throw new Error("WASM 未加载");
|
|
267
267
|
if (r.length !== 4)
|
|
268
268
|
throw new Error("需要恰好 4 个点");
|
|
269
269
|
try {
|
|
270
|
-
const
|
|
271
|
-
if (!
|
|
272
|
-
throw new Error(
|
|
273
|
-
return { x:
|
|
274
|
-
} catch (
|
|
275
|
-
throw
|
|
270
|
+
const s = this.call("wasmGetBilinearPoint", n, e, JSON.stringify(r));
|
|
271
|
+
if (!s.success)
|
|
272
|
+
throw new Error(s.error || "计算失败");
|
|
273
|
+
return { x: s.x, y: s.y };
|
|
274
|
+
} catch (s) {
|
|
275
|
+
throw s;
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
278
|
/**
|
|
279
279
|
* 任意网格点插值计算
|
|
280
280
|
*/
|
|
281
|
-
getArbitraryMeshPoint(
|
|
281
|
+
getArbitraryMeshPoint(n, e, r, s) {
|
|
282
282
|
if (!this.wasmReady)
|
|
283
283
|
throw new Error("WASM 未加载");
|
|
284
284
|
try {
|
|
285
|
-
const
|
|
286
|
-
if (!
|
|
287
|
-
throw new Error(
|
|
288
|
-
return { x:
|
|
289
|
-
} catch (
|
|
290
|
-
throw
|
|
285
|
+
const o = this.call("wasmGetArbitraryMeshPoint", n, e, JSON.stringify(r), s);
|
|
286
|
+
if (!o.success)
|
|
287
|
+
throw new Error(o.error || "计算失败");
|
|
288
|
+
return { x: o.x, y: o.y };
|
|
289
|
+
} catch (o) {
|
|
290
|
+
throw o;
|
|
291
291
|
}
|
|
292
292
|
}
|
|
293
293
|
/**
|
|
294
294
|
* 批量双三次插值(高性能优化)
|
|
295
295
|
* 一次性处理多个坐标,避免频繁的 JS/WASM 边界调用
|
|
296
296
|
*/
|
|
297
|
-
batchBicubicInterpolation(
|
|
297
|
+
batchBicubicInterpolation(n, e) {
|
|
298
298
|
if (!this.wasmReady)
|
|
299
299
|
throw new Error("WASM 未加载");
|
|
300
300
|
if (e.length !== 16)
|
|
@@ -302,7 +302,7 @@ const Z = class P {
|
|
|
302
302
|
try {
|
|
303
303
|
const r = this.call(
|
|
304
304
|
"wasmBatchBicubicInterpolation",
|
|
305
|
-
JSON.stringify(
|
|
305
|
+
JSON.stringify(n),
|
|
306
306
|
JSON.stringify(e)
|
|
307
307
|
);
|
|
308
308
|
if (!r.success)
|
|
@@ -315,7 +315,7 @@ const Z = class P {
|
|
|
315
315
|
/**
|
|
316
316
|
* 批量双线性插值(高性能优化)
|
|
317
317
|
*/
|
|
318
|
-
batchBilinearInterpolation(
|
|
318
|
+
batchBilinearInterpolation(n, e) {
|
|
319
319
|
if (!this.wasmReady)
|
|
320
320
|
throw new Error("WASM 未加载");
|
|
321
321
|
if (e.length !== 4)
|
|
@@ -323,7 +323,7 @@ const Z = class P {
|
|
|
323
323
|
try {
|
|
324
324
|
const r = this.call(
|
|
325
325
|
"wasmBatchBilinearInterpolation",
|
|
326
|
-
JSON.stringify(
|
|
326
|
+
JSON.stringify(n),
|
|
327
327
|
JSON.stringify(e)
|
|
328
328
|
);
|
|
329
329
|
if (!r.success)
|
|
@@ -336,313 +336,1055 @@ const Z = class P {
|
|
|
336
336
|
/**
|
|
337
337
|
* 批量任意网格插值(高性能优化)
|
|
338
338
|
*/
|
|
339
|
-
batchArbitraryMeshInterpolation(
|
|
339
|
+
batchArbitraryMeshInterpolation(n, e, r) {
|
|
340
340
|
if (!this.wasmReady)
|
|
341
341
|
throw new Error("WASM 未加载");
|
|
342
342
|
try {
|
|
343
|
-
const
|
|
343
|
+
const s = this.call(
|
|
344
344
|
"wasmBatchArbitraryMeshInterpolation",
|
|
345
|
-
JSON.stringify(
|
|
345
|
+
JSON.stringify(n),
|
|
346
346
|
JSON.stringify(e),
|
|
347
347
|
r
|
|
348
348
|
);
|
|
349
|
-
if (!
|
|
350
|
-
throw new Error(
|
|
351
|
-
return
|
|
352
|
-
} catch (
|
|
353
|
-
throw
|
|
349
|
+
if (!s.success)
|
|
350
|
+
throw new Error(s.error || "批量网格插值失败");
|
|
351
|
+
return s.points;
|
|
352
|
+
} catch (s) {
|
|
353
|
+
throw s;
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
/**
|
|
357
357
|
* 调用 WASM 函数
|
|
358
358
|
*/
|
|
359
|
-
call(
|
|
359
|
+
call(n, ...e) {
|
|
360
360
|
if (!this.wasmReady)
|
|
361
361
|
throw new Error("WASM 未加载");
|
|
362
|
-
const
|
|
363
|
-
if (!
|
|
364
|
-
throw new Error(`函数不存在: ${
|
|
362
|
+
const s = (typeof self < "u" ? self : globalThis)[n];
|
|
363
|
+
if (!s)
|
|
364
|
+
throw new Error(`函数不存在: ${n}`);
|
|
365
365
|
try {
|
|
366
|
-
return
|
|
367
|
-
} catch (
|
|
368
|
-
throw
|
|
366
|
+
return s(...e);
|
|
367
|
+
} catch (o) {
|
|
368
|
+
throw o;
|
|
369
369
|
}
|
|
370
370
|
}
|
|
371
371
|
};
|
|
372
|
-
|
|
373
|
-
let
|
|
374
|
-
|
|
375
|
-
|
|
372
|
+
It(Gt, "instance");
|
|
373
|
+
let te = Gt;
|
|
374
|
+
function _t(t, n, e, r) {
|
|
375
|
+
t || (t = 0), n || (n = 0), e || (e = 0), r || (r = 0), this.x = t, this.y = n, this.r = e, this.B = r;
|
|
376
|
+
}
|
|
377
|
+
_t.prototype.C = function() {
|
|
378
|
+
return this.r * this.B;
|
|
379
|
+
};
|
|
380
|
+
_t.prototype.P = function() {
|
|
381
|
+
return new _t(this.x, this.y, this.r, this.B);
|
|
382
|
+
};
|
|
383
|
+
function $(t, n, e, r, s, o) {
|
|
384
|
+
typeof t > "u" && (t = 1, n = 0, e = 0, r = 1, s = 0, o = 0), this.zh = t, this.X = n, this.Fm = e, this.Yd = r, this.uV = s, this.QJ = o;
|
|
385
|
+
}
|
|
386
|
+
$.prototype.TX = function(t) {
|
|
387
|
+
return { x: t.x * this.zh + t.y * this.Fm + this.uV, y: t.x * this.X + t.y * this.Yd + this.QJ };
|
|
388
|
+
};
|
|
389
|
+
$.prototype.translate = function(t, n) {
|
|
390
|
+
this.uV += t, this.QJ += n;
|
|
391
|
+
};
|
|
392
|
+
$.prototype.rotate = function(t) {
|
|
393
|
+
const n = new $(Math.cos(t), -Math.sin(t), Math.sin(t), Math.cos(t), 0, 0);
|
|
394
|
+
this.concat(n);
|
|
395
|
+
};
|
|
396
|
+
$.prototype.scale = function(t, n) {
|
|
397
|
+
const e = new $(t, 0, 0, n, 0, 0);
|
|
398
|
+
this.concat(e);
|
|
399
|
+
};
|
|
400
|
+
$.prototype.concat = function(t) {
|
|
401
|
+
this.yd(new $(
|
|
402
|
+
this.zh * t.zh + this.X * t.Fm,
|
|
403
|
+
this.zh * t.X + this.X * t.Yd,
|
|
404
|
+
this.Fm * t.zh + this.Yd * t.Fm,
|
|
405
|
+
this.Fm * t.X + this.Yd * t.Yd,
|
|
406
|
+
this.uV * t.zh + this.QJ * t.Fm + t.uV,
|
|
407
|
+
this.uV * t.X + this.QJ * t.Yd + t.QJ
|
|
408
|
+
));
|
|
409
|
+
};
|
|
410
|
+
$.prototype.Ql = function() {
|
|
411
|
+
const t = this.zh * this.Yd - this.X * this.Fm;
|
|
412
|
+
this.yd(new $(
|
|
413
|
+
this.Yd / t,
|
|
414
|
+
-this.X / t,
|
|
415
|
+
-this.Fm / t,
|
|
416
|
+
this.zh / t,
|
|
417
|
+
(this.Fm * this.QJ - this.Yd * this.uV) / t,
|
|
418
|
+
(this.X * this.uV - this.zh * this.QJ) / t
|
|
419
|
+
));
|
|
420
|
+
};
|
|
421
|
+
$.prototype.P = function() {
|
|
422
|
+
return new $(this.zh, this.X, this.Fm, this.Yd, this.uV, this.QJ);
|
|
423
|
+
};
|
|
424
|
+
$.prototype.yd = function(t) {
|
|
425
|
+
this.zh = t.zh, this.X = t.X, this.Fm = t.Fm, this.Yd = t.Yd, this.uV = t.uV, this.QJ = t.QJ;
|
|
426
|
+
};
|
|
427
|
+
const U = { b: {}, ml: {}, n3: {} };
|
|
428
|
+
U.b.u = function(t, n, e) {
|
|
429
|
+
for (let r = 0; r < t.length; r += 2) {
|
|
430
|
+
const s = t[r], o = t[r + 1];
|
|
431
|
+
e[r] = s * n.zh + o * n.Fm + n.uV, e[r + 1] = s * n.X + o * n.Yd + n.QJ;
|
|
432
|
+
}
|
|
433
|
+
};
|
|
434
|
+
U.b.aGX = function(t, n, e, r) {
|
|
435
|
+
for (let s = 0; s < t.length; s += 2) {
|
|
436
|
+
const o = t[s], i = t[s + 1], u = n[s], c = n[s + 1];
|
|
437
|
+
e[s] = o + (u - o) * r, e[s + 1] = i + (c - i) * r;
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
U.ml.J = function(t, n, e, r) {
|
|
441
|
+
const s = [];
|
|
442
|
+
for (let o = 0; o < 4; o++) for (let i = 0; i < 4; i++) s.push(t + e * i / 3, n + r * o / 3);
|
|
443
|
+
return s;
|
|
444
|
+
};
|
|
445
|
+
U.n3.abG = function(t) {
|
|
446
|
+
return (4 - t) * (1 / 3);
|
|
447
|
+
};
|
|
448
|
+
U.n3.azW = function(t, n) {
|
|
449
|
+
return (1 - t) * (3 - t) / (3 * n);
|
|
450
|
+
};
|
|
451
|
+
U.n3.aK6 = function(t) {
|
|
452
|
+
const n = Math.sin(t * Math.PI / 2), e = Math.pow(t, 1 / 3.5);
|
|
453
|
+
let r = (1 - t) * n + t * e;
|
|
454
|
+
r = Math.pow(r, 1.045);
|
|
455
|
+
const s = 0.1725 + 0.0573 * r;
|
|
456
|
+
let o = 1 - (0.96 * n + 0.04 * e);
|
|
457
|
+
o = Math.pow(o, 1.27);
|
|
458
|
+
const i = 1 / 129 + (0.167684 - 1 / 129) * o;
|
|
459
|
+
return [s, i];
|
|
460
|
+
};
|
|
461
|
+
U.n3.atL = function(t, n) {
|
|
462
|
+
for (let e = 0; e < t.length; e += 2)
|
|
463
|
+
t[e] = n.x + t[e] * n.r, t[e + 1] = n.y + t[e + 1] * n.B;
|
|
464
|
+
};
|
|
465
|
+
U.n3.ac5 = function(t, n, e) {
|
|
466
|
+
for (let r = 0; r < t.length; r += 2) {
|
|
467
|
+
let s = t[r], o = t[r + 1];
|
|
468
|
+
const i = (1 - n) / 2, u = 1 - i, c = i + s * (u - i);
|
|
469
|
+
o = 0.5 + (o - 0.5) * c * 2;
|
|
470
|
+
const l = (1 - e) / 2, f = 1 - l, d = l + o * (f - l);
|
|
471
|
+
s = 0.5 + (s - 0.5) * d * 2, t[r] = s, t[r + 1] = o;
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
U.n3.n3 = function(t, n, e, r, s, o) {
|
|
475
|
+
if (t === "warpCylinder") {
|
|
476
|
+
const u = n, c = u[0], l = u[1], f = u[2], d = u[3], h = u[4], p = u[5], A = u[6], g = [];
|
|
477
|
+
for (let F = 0; F < 4; F++) for (let S = 0; S < 13; S++) g.push(S / 12, F / 3);
|
|
478
|
+
const a = f - c, y = l - d, m = h * 0.5 * (a / y), x = p * 0.5 * (a / y), E = U.n3.aK6(A), w = [0, 0, 0, 0, 0, E[0], 0.5], M = [0, 0, 0, 0, m * 0.42, m, m], D = [0, 0, 0, 0, x * 0.42, x, x];
|
|
479
|
+
for (let F = 0; F < 4; F++) for (let S = 0; S < 7; S++) {
|
|
480
|
+
const I = F * 13 + S;
|
|
481
|
+
g[I * 2] = w[S];
|
|
482
|
+
const v = M[S], T = 1 + D[S], W = F / 3;
|
|
483
|
+
g[I * 2 + 1] = v * (1 - W) + T * W;
|
|
484
|
+
}
|
|
485
|
+
for (let F = 0; F < 4; F++) for (let S = 0; S < 6; S++) {
|
|
486
|
+
const I = F * 13 + S, v = F * 13 + 12 - S;
|
|
487
|
+
g[v * 2] = 1 - g[I * 2], g[v * 2 + 1] = g[I * 2 + 1];
|
|
488
|
+
}
|
|
489
|
+
const C = E[1];
|
|
490
|
+
return [13, 4, [[0, C, 0.5, 1 - C, 1], [0, 1]], g];
|
|
491
|
+
}
|
|
492
|
+
const i = U.ml.J(0, 0, 1, 1);
|
|
493
|
+
if (t !== "warpNone") {
|
|
494
|
+
e || (o = 1 / o), U.n3.asq(i, t, n, r, s, o);
|
|
495
|
+
const u = i.slice(0);
|
|
496
|
+
if (!e) for (let c = 0; c < 4; c++) for (let l = 0; l < 4; l++)
|
|
497
|
+
i[(c * 4 + l) * 2] = u[(l * 4 + c) * 2 + 1], i[(c * 4 + l) * 2 + 1] = u[(l * 4 + c) * 2];
|
|
498
|
+
if (n === 0)
|
|
499
|
+
U.n3.ac5(i, r, s);
|
|
500
|
+
else {
|
|
501
|
+
const c = new $(void 0, void 0, void 0, void 0, void 0, void 0);
|
|
502
|
+
c.translate(-0.5, -0.5), U.b.u(i, c, i), U.n3.aLy(i, s, r), c.Ql(), U.b.u(i, c, i);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return [4, 4, [[0, 1], [0, 1]], i];
|
|
376
506
|
};
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
507
|
+
U.n3.asq = function(t, n, e, r, s, o) {
|
|
508
|
+
const i = new _t(0, 0, o, 1);
|
|
509
|
+
for (let u = 0; u < t.length; u += 2) t[u] *= o;
|
|
510
|
+
for (let u = 0; u < 4; u++)
|
|
511
|
+
for (let c = 0; c < 4; c++) {
|
|
512
|
+
const l = 2 * (4 * u + c);
|
|
513
|
+
let f = t[l] - i.x, d = t[l + 1] - i.y, h = f, p = d;
|
|
514
|
+
if (e !== 0) {
|
|
515
|
+
const A = i.r / 2, g = i.B / 2;
|
|
516
|
+
h -= A, p -= g;
|
|
517
|
+
let a = h, y = h, m = -g, x = g;
|
|
518
|
+
const E = Math.abs(e), w = Math.tan((1 - E) * Math.PI / 2), M = Math.sqrt(w * w + 1), D = Math.atan2(1, w), C = h / A * D, F = A * M, S = A * M + i.B, I = Math.cos(D), v = Math.sin(D), T = U.n3.abG(I, v), W = U.n3.azW(I, v), L = -w * A + T * F;
|
|
519
|
+
if (n === "warpArc" && (a = Math.sin(C) * S, m = w * A - Math.cos(D) * S + g, y = Math.sin(C) * F, x = w * A - Math.cos(D) * F + g, (c === 1 || c === 2) && (a = c === 1 ? -W * S : W * S, y = c === 1 ? -W * F : W * F, m = w * A + g - T * S, x = w * A + g - T * F), e < 0)) {
|
|
520
|
+
const b = a;
|
|
521
|
+
a = y, y = b;
|
|
522
|
+
const P = m;
|
|
523
|
+
m = -x, x = -P;
|
|
524
|
+
}
|
|
525
|
+
if (n === "warpArcLower" && (c === 1 || c === 2) && (y = c === 1 ? -W * F : W * F, x = e < 0 ? g - L : g + L), (n === "warpArcUpper" || n === "warpArch" || n === "warpBulge") && ((c === 1 || c === 2) && (a = c === 1 ? -W * F : W * F, m = e < 0 ? -g + L : -g - L), n === "warpArch" && (y = a, x = m + 2 * g), n === "warpBulge" && (y = a, x = -m)), n === "warpFish" || n === "warpFlag" || n === "warpWave") {
|
|
526
|
+
let b = c;
|
|
527
|
+
n === "warpFlag" && (b = 3 - c), b === 1 && (m -= e * 4 * g, x += e * 4 * g), b === 2 && (m += e * 4 * g, x -= e * 4 * g), (n === "warpFlag" || n === "warpWave") && (m = x - 2 * g);
|
|
528
|
+
}
|
|
529
|
+
n === "warpRise" && (c < 2 && (m = -g + e * g * 4), x = m + 2 * g);
|
|
530
|
+
const B = (p + g) / i.B;
|
|
531
|
+
if (h = a + B * (y - a), p = m + B * (x - m), n === "warpWave" && (u === 0 && (p = -g), u === 3 && (p = g), (u === 1 || u === 2) && (p = 2 * g * (u / 3 - 0.5) * (1 / 3) + p * (2 / 3))), n === "warpFisheye" && (u === 1 || u === 2) && (c === 1 || c === 2) && (h = h + 4 * h * e, p = p + 4 * p * e), n === "warpInflate") {
|
|
532
|
+
const b = 0.6666666666666666;
|
|
533
|
+
(u === 1 || u === 2) && (c === 1 || c === 2) ? (h = h + 0.5 * h * e, p = p + 0.5 * p * e) : u === 1 || u === 2 ? h = h + b * h * e : (c === 1 || c === 2) && (p = p + b * p * e);
|
|
534
|
+
}
|
|
535
|
+
if (n === "warpSqueeze") {
|
|
536
|
+
const b = 0.6666666666666666;
|
|
537
|
+
(u === 1 || u === 2) && (c === 1 || c === 2) ? e > 0 ? h = h - b * h * e : p = p + b * p * e : u === 1 || u === 2 ? h = h - b * h * e : (c === 1 || c === 2) && (p = p + b * p * e);
|
|
538
|
+
}
|
|
539
|
+
if (n === "warpTwist" && (u === 1 || u === 2) && (c === 1 || c === 2)) {
|
|
540
|
+
const b = e * Math.PI / 2, P = 1 + Math.abs(e) * 2, X = h * Math.cos(b) - p * Math.sin(b), O = h * Math.sin(b) + p * Math.cos(b);
|
|
541
|
+
h = X * P, p = O * P;
|
|
542
|
+
}
|
|
543
|
+
if (n === "warpShellLower" || n === "warpShellUpper") {
|
|
544
|
+
let b = u;
|
|
545
|
+
if (n === "warpShellUpper" && (b = 3 - b, p = -p), b > 2 || b === 2 && (c === 0 || c === 3))
|
|
546
|
+
if (e > 0) {
|
|
547
|
+
const P = F + b / 3 * 2 * g;
|
|
548
|
+
h = Math.sin(C) * P, p = -w * A - g + Math.cos(C) * P, (c === 1 || c === 2) && (h = c === 1 ? -W * P : W * P, p = -w * A - g + T * P);
|
|
549
|
+
} else
|
|
550
|
+
(c === 1 || c === 2) && b === 3 ? (h = c === 1 ? -W * F : W * F, p = w * A - T * F + g) : b === 2 && (p = g - g * (2 / 3) * Math.cos(C), h = h + g * (2 / 3) * Math.sin(C));
|
|
551
|
+
n === "warpShellUpper" && (b = 3 - b, p = -p);
|
|
552
|
+
}
|
|
553
|
+
h += A, p += g;
|
|
554
|
+
}
|
|
555
|
+
f = h, d = p, t[l] = f + i.x, t[l + 1] = d + i.y;
|
|
556
|
+
}
|
|
557
|
+
for (let u = 0; u < t.length; u += 2) t[u] /= o;
|
|
558
|
+
};
|
|
559
|
+
U.n3.aLy = function(t, n, e) {
|
|
560
|
+
const r = [];
|
|
561
|
+
for (let x = 0; x < 4; x++) r.push(1 - e + x / 3 * 2 * e);
|
|
562
|
+
const s = [0, 0, 0, 0], o = [0, 0, 0, 0];
|
|
563
|
+
for (let x = 0; x < 4; x++) for (let E = 0; E < 4; E++) {
|
|
564
|
+
const w = 2 * (4 * x + E);
|
|
565
|
+
s[E] += t[w] / 4, o[E] += t[w + 1] / 4;
|
|
566
|
+
}
|
|
567
|
+
for (let x = 0; x < 4; x++) for (let E = 0; E < 4; E++) {
|
|
568
|
+
const w = r[E], M = 2 * (4 * x + E), D = s[E], C = o[E];
|
|
569
|
+
t[M] = D + w * (t[M] - D), t[M + 1] = C + w * (t[M + 1] - C);
|
|
570
|
+
}
|
|
571
|
+
const i = t.slice(0);
|
|
572
|
+
for (let x = 0; x < 4; x++) for (let E = 1; E < 3; E++) {
|
|
573
|
+
const w = 2 * (4 * x + E), M = w + (E === 1 ? -2 : 2);
|
|
574
|
+
t[w] = t[w] - t[M], t[w + 1] = t[w + 1] - t[M + 1];
|
|
575
|
+
}
|
|
576
|
+
const u = t[0], c = t[1], l = t[6], f = t[7], d = t[24], h = t[25], p = t[30], A = t[31], g = l - u, a = f - c, y = p - d, m = A - h;
|
|
577
|
+
for (let x = 0; x < 4; x++) {
|
|
578
|
+
const E = 2 * x * 4;
|
|
579
|
+
let w = 0, M = 0;
|
|
580
|
+
const D = x === 1 ? 0.33 : 0.66, C = 1 - D;
|
|
581
|
+
x === 0 && (w = g, M = a), x === 1 && (w = C * g + D * -y, M = C * a + D * -m), x === 2 && (w = C * g + D * -y, M = C * a + D * -m), x === 3 && (w = -y, M = -m), t[E] = t[E] + w / 2, t[E + 1] = t[E + 1] + M / 2, t[E + 6] = t[E + 6] - w / 2, t[E + 7] = t[E + 7] - M / 2;
|
|
582
|
+
}
|
|
583
|
+
for (let x = 0; x < 4; x++) for (let E = 1; E < 3; E++) {
|
|
584
|
+
const w = 2 * (4 * x + E), M = w + (E === 1 ? -2 : 2), D = 2 * x / 3;
|
|
585
|
+
t[w] = t[M] + D * t[w], t[w + 1] = t[M + 1] + D * t[w + 1];
|
|
586
|
+
}
|
|
587
|
+
for (let x = 1; x < 3; x++) for (let E = 1; E < 3; E++) {
|
|
588
|
+
const w = 2 * (4 * x + E), M = x === 1 ? -8 : -16, D = x === 1 ? 16 : 8, C = t[w + M], F = t[w + M + 1], S = t[w + D], I = t[w + D + 1], v = x / 3;
|
|
589
|
+
t[w] = (1 - v) * C + v * S, t[w + 1] = (1 - v) * F + v * I;
|
|
590
|
+
}
|
|
591
|
+
U.b.aGX(i, t, t, n);
|
|
592
|
+
};
|
|
593
|
+
function ee(t) {
|
|
594
|
+
const [n, e, r, s] = U.n3.n3(
|
|
595
|
+
t.preset,
|
|
596
|
+
t.value,
|
|
597
|
+
t.rotateHorizontal,
|
|
598
|
+
t.perspective,
|
|
599
|
+
t.perspectiveOther,
|
|
600
|
+
t.aspect
|
|
601
|
+
);
|
|
602
|
+
return { cols: n, rows: e, slices: r, points: s };
|
|
603
|
+
}
|
|
604
|
+
function ne(t, n) {
|
|
605
|
+
U.n3.atL(t, { x: n.x, y: n.y, r: n.width, B: n.height });
|
|
606
|
+
}
|
|
607
|
+
const re = (function() {
|
|
608
|
+
function t(r, s) {
|
|
609
|
+
this.data = new Array(r.length);
|
|
610
|
+
for (let o = 0, i = r[0].length; o < r.length; o++) {
|
|
611
|
+
this.data[o] = new Array(i);
|
|
612
|
+
for (let u = 0; u < i; u++)
|
|
613
|
+
this.data[o][u] = r[o][u];
|
|
614
|
+
}
|
|
615
|
+
if (s) {
|
|
616
|
+
if (typeof s[0] != "object")
|
|
617
|
+
for (let o = 0; o < s.length; o++)
|
|
618
|
+
s[o] = [s[o]];
|
|
619
|
+
this.mirror = new t(s);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
t.prototype.swap = function(r, s) {
|
|
623
|
+
this.mirror && this.mirror.swap(r, s);
|
|
624
|
+
const o = this.data[r];
|
|
625
|
+
this.data[r] = this.data[s], this.data[s] = o;
|
|
626
|
+
}, t.prototype.multline = function(r, s) {
|
|
627
|
+
this.mirror && this.mirror.multline(r, s);
|
|
628
|
+
const o = this.data[r];
|
|
629
|
+
for (let i = o.length - 1; i >= 0; i--)
|
|
630
|
+
o[i] *= s;
|
|
631
|
+
}, t.prototype.addmul = function(r, s, o) {
|
|
632
|
+
this.mirror && this.mirror.addmul(r, s, o);
|
|
633
|
+
const i = this.data[r], u = this.data[s];
|
|
634
|
+
for (let c = i.length - 1; c >= 0; c--)
|
|
635
|
+
i[c] = i[c] + o * u[c];
|
|
636
|
+
}, t.prototype.hasNullLine = function(r) {
|
|
637
|
+
for (let s = 0; s < this.data[r].length; s++)
|
|
638
|
+
if (this.data[r][s] !== 0) return !1;
|
|
639
|
+
return !0;
|
|
640
|
+
}, t.prototype.gauss = function() {
|
|
641
|
+
let r = 0;
|
|
642
|
+
const s = this.data.length, o = this.data[0].length, i = [];
|
|
643
|
+
for (let u = 0; u < o; u++) {
|
|
644
|
+
let c = 0, l = 0;
|
|
645
|
+
for (let f = r; f < s; f++) {
|
|
646
|
+
const d = this.data[f][u];
|
|
647
|
+
Math.abs(d) > Math.abs(c) && (l = f, c = d);
|
|
648
|
+
}
|
|
649
|
+
if (c === 0)
|
|
650
|
+
i.push(r);
|
|
651
|
+
else {
|
|
652
|
+
this.multline(l, 1 / c), this.swap(l, r);
|
|
653
|
+
for (let f = 0; f < s; f++)
|
|
654
|
+
f !== r && this.addmul(f, r, -this.data[f][u]);
|
|
655
|
+
}
|
|
656
|
+
r++;
|
|
657
|
+
}
|
|
658
|
+
for (let u = 0; u < i.length; u++)
|
|
659
|
+
if (!this.mirror.hasNullLine(i[u]))
|
|
660
|
+
throw new Error("singular matrix");
|
|
661
|
+
return this.mirror.data;
|
|
662
|
+
};
|
|
663
|
+
const n = {};
|
|
664
|
+
n.solve = function(r, s) {
|
|
665
|
+
const o = new t(r, s).gauss();
|
|
666
|
+
if (o.length > 0 && o[0].length === 1)
|
|
667
|
+
for (let i = 0; i < o.length; i++) o[i] = o[i][0];
|
|
668
|
+
return o;
|
|
669
|
+
};
|
|
670
|
+
function e(r) {
|
|
671
|
+
const s = new Array(r);
|
|
672
|
+
for (let o = 0; o < r; o++) {
|
|
673
|
+
s[o] = new Array(r);
|
|
674
|
+
for (let i = 0; i < r; i++)
|
|
675
|
+
s[o][i] = o === i ? 1 : 0;
|
|
676
|
+
}
|
|
677
|
+
return s;
|
|
678
|
+
}
|
|
679
|
+
return n.invert = function(r) {
|
|
680
|
+
return new t(r, e(r.length)).gauss();
|
|
681
|
+
}, n;
|
|
682
|
+
})(), _ = { avu: {}, es: {}, XF: {}, uZ: {} };
|
|
683
|
+
_.avu.GE = function(t, n) {
|
|
684
|
+
t.push(n);
|
|
685
|
+
let e = t.length - 1, r = e >>> 1;
|
|
686
|
+
for (; r !== 0 && t[e][0] < t[r][0]; ) {
|
|
687
|
+
const s = t[e];
|
|
688
|
+
t[e] = t[r], t[r] = s, e = r, r = e >>> 1;
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
_.avu.Ng = function(t) {
|
|
692
|
+
if (t.length === 2) return t.pop();
|
|
693
|
+
const n = t[1];
|
|
694
|
+
let e = 1;
|
|
695
|
+
t[1] = t.pop();
|
|
696
|
+
const r = t.length;
|
|
697
|
+
for (; ; ) {
|
|
698
|
+
const s = e << 1, o = s + 1;
|
|
699
|
+
let i = e;
|
|
700
|
+
if (s < r && t[s][0] < t[i][0] && (i = s), o < r && t[o][0] < t[i][0] && (i = o), i === e) break;
|
|
701
|
+
const u = t[e];
|
|
702
|
+
t[e] = t[i], t[i] = u, e = i;
|
|
703
|
+
}
|
|
704
|
+
return n;
|
|
705
|
+
};
|
|
706
|
+
_.es.MG = function(t) {
|
|
707
|
+
const n = t.length, e = t[0].length, r = new Array(e);
|
|
708
|
+
for (let s = 0; s < e; s++) r[s] = new Array(n);
|
|
709
|
+
for (let s = 0; s < e; s++) for (let o = 0; o < n; o++) r[s][o] = t[o][s];
|
|
710
|
+
return r;
|
|
711
|
+
};
|
|
712
|
+
_.es.y8 = function(t, n) {
|
|
713
|
+
const e = t.length, r = t[0].length, s = new Array(e);
|
|
714
|
+
for (let o = 0; o < e; o++) s[o] = new Array(r);
|
|
715
|
+
for (let o = 0; o < e; o++) for (let i = 0; i < r; i++) s[o][i] = t[o][i] - n[o][i];
|
|
716
|
+
return s;
|
|
717
|
+
};
|
|
718
|
+
_.es.multiply = function(t, n) {
|
|
719
|
+
const e = t.length, r = t[0].length, s = n[0].length;
|
|
720
|
+
if (r !== n.length) throw new Error("es.multiply dim mismatch");
|
|
721
|
+
const o = new Array(e);
|
|
722
|
+
for (let i = 0; i < e; i++) o[i] = new Array(s);
|
|
723
|
+
for (let i = 0; i < e; i++) {
|
|
724
|
+
const u = t[i], c = o[i];
|
|
725
|
+
for (let l = 0; l < s; l++) {
|
|
726
|
+
let f = 0;
|
|
727
|
+
for (let d = 0; d < r; d++) f += u[d] * n[d][l];
|
|
728
|
+
c[l] = f;
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
return o;
|
|
732
|
+
};
|
|
733
|
+
_.es.Jj = function(t, n) {
|
|
734
|
+
const e = t.length, r = t[0].length, s = new Array(e);
|
|
735
|
+
for (let o = 0; o < e; o++) {
|
|
736
|
+
let i = 0;
|
|
737
|
+
for (let u = 0; u < r; u++) i += t[o][u] * n[u];
|
|
738
|
+
s[o] = i;
|
|
739
|
+
}
|
|
740
|
+
return s;
|
|
741
|
+
};
|
|
742
|
+
_.W9 = function(t, n) {
|
|
743
|
+
this.Y = [], this.ia = [0], this.Am = [], this.yr = [], this.qq = [0], this.t8 = [], this.oN = [], this.rows = t, this.cols = n;
|
|
744
|
+
};
|
|
745
|
+
_.W9.prototype.Hk = function(t, n, e) {
|
|
746
|
+
const r = this.ia.length - 1;
|
|
747
|
+
for (let s = 0; s < e; s++) {
|
|
748
|
+
const o = t[s], i = n[s];
|
|
749
|
+
this.Y.push(o), this.Am.push(i), i === r ? this.oN.push(o === 0 ? 0 : 1 / o) : (this.yr.push(o), this.t8.push(i));
|
|
750
|
+
}
|
|
751
|
+
this.ia.push(this.Y.length), this.qq.push(this.yr.length);
|
|
752
|
+
};
|
|
753
|
+
_.W9.prototype.Jj = function(t, n) {
|
|
754
|
+
const e = this, r = e.rows, s = e.Y, o = e.Am;
|
|
755
|
+
n == null && (n = new Array(r));
|
|
756
|
+
for (let i = 0; i < r; i++) {
|
|
757
|
+
let u = e.ia[i];
|
|
758
|
+
const c = e.ia[i + 1];
|
|
759
|
+
let l = 0;
|
|
760
|
+
for (; (c - u & 3) !== 0; )
|
|
761
|
+
l += s[u] * t[o[u]], u++;
|
|
762
|
+
for (let f = u; f < c; f += 4)
|
|
763
|
+
l += s[f] * t[o[f]] + s[f + 1] * t[o[f + 1]] + s[f + 2] * t[o[f + 2]] + s[f + 3] * t[o[f + 3]];
|
|
764
|
+
n[i] = l;
|
|
765
|
+
}
|
|
766
|
+
return n;
|
|
767
|
+
};
|
|
768
|
+
_.W9.prototype.multiply = function(t) {
|
|
769
|
+
return this._g(t.MG());
|
|
770
|
+
};
|
|
771
|
+
_.W9.prototype._g = function(t) {
|
|
772
|
+
const n = this, e = n.rows, r = t.rows, s = new _.W9(e, r), o = n.Am, i = t.Am;
|
|
773
|
+
for (let u = 0; u < e; u++) {
|
|
774
|
+
const c = [], l = [], f = n.ia[u], d = n.ia[u + 1];
|
|
775
|
+
for (let h = 0; h < r; h++) {
|
|
776
|
+
const p = t.ia[h], A = t.ia[h + 1];
|
|
777
|
+
let g = 0, a = f, y = p;
|
|
778
|
+
for (; a < d && y < A; ) {
|
|
779
|
+
const m = Math.max(o[a], i[y]);
|
|
780
|
+
for (; a < d && o[a] < m; ) a++;
|
|
781
|
+
for (; y < A && i[y] < m; ) y++;
|
|
782
|
+
a < d && y < A && o[a] === i[y] && (g += n.Y[a++] * t.Y[y++]);
|
|
783
|
+
}
|
|
784
|
+
g !== 0 && (c.push(g), l.push(h));
|
|
785
|
+
}
|
|
786
|
+
s.Hk(c, l, c.length);
|
|
787
|
+
}
|
|
788
|
+
return s;
|
|
789
|
+
};
|
|
790
|
+
_.W9.prototype.MG = function() {
|
|
791
|
+
const t = this.rows, n = this.cols, e = [];
|
|
792
|
+
for (let u = 0; u < n; u++) e.push([[], []]);
|
|
793
|
+
const r = this.Y, s = this.ia, o = this.Am;
|
|
794
|
+
for (let u = 0; u < t; u++) {
|
|
795
|
+
const c = s[u], l = s[u + 1];
|
|
796
|
+
for (let f = c; f < l; f++) {
|
|
797
|
+
const d = e[o[f]];
|
|
798
|
+
d[0].push(r[f]), d[1].push(u);
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
const i = new _.W9(n, t);
|
|
802
|
+
for (let u = 0; u < n; u++) i.Hk(e[u][0], e[u][1], e[u][1].length);
|
|
803
|
+
return i;
|
|
804
|
+
};
|
|
805
|
+
_.W9.prototype.e0 = function(t, n, e) {
|
|
806
|
+
function r(g, a, y, m) {
|
|
807
|
+
const x = g.length;
|
|
808
|
+
for (let E = 0; E < x; E++) m[E] = g[E] - a[E] * y;
|
|
809
|
+
}
|
|
810
|
+
function s(g, a, y, m) {
|
|
811
|
+
const x = g.length;
|
|
812
|
+
let E = 0;
|
|
813
|
+
for (; (x - E & 3) !== 0; )
|
|
814
|
+
m[E] = g[E] + a[E] * y, E++;
|
|
815
|
+
for (let w = E; w < x; w += 4)
|
|
816
|
+
m[w] = g[w] + a[w] * y, m[w + 1] = g[w + 1] + a[w + 1] * y, m[w + 2] = g[w + 2] + a[w + 2] * y, m[w + 3] = g[w + 3] + a[w + 3] * y;
|
|
817
|
+
}
|
|
818
|
+
function o(g, a, y) {
|
|
819
|
+
const m = g.length;
|
|
820
|
+
for (let x = 0; x < m; x++) y[x] = g[x] * a[x];
|
|
821
|
+
}
|
|
822
|
+
function i(g, a) {
|
|
823
|
+
const y = g.length;
|
|
824
|
+
let m = 0, x = 0;
|
|
825
|
+
for (; (y - m & 3) !== 0; )
|
|
826
|
+
x += g[m] * a[m], m++;
|
|
827
|
+
for (let E = m; E < y; E += 4)
|
|
828
|
+
x += g[E] * a[E] + g[E + 1] * a[E + 1] + g[E + 2] * a[E + 2] + g[E + 3] * a[E + 3];
|
|
829
|
+
return x;
|
|
830
|
+
}
|
|
831
|
+
let u = 0;
|
|
832
|
+
const c = this, l = t.slice(0), f = t.slice(0);
|
|
833
|
+
c.Jj(t, f), r(n, f, 1, l);
|
|
834
|
+
const d = this.oN, h = l.slice(0);
|
|
835
|
+
o(d, l, h);
|
|
836
|
+
const p = h.slice(0);
|
|
837
|
+
let A = i(l, h);
|
|
838
|
+
for (; ; ) {
|
|
839
|
+
c.Jj(p, f);
|
|
840
|
+
const g = A / i(p, f);
|
|
841
|
+
if (s(t, p, g, t), r(l, f, g, l), (u & 7) === 0 && Math.sqrt(i(l, l)) < e) break;
|
|
842
|
+
o(d, l, h);
|
|
843
|
+
const a = i(l, h), y = a / A;
|
|
844
|
+
if (s(h, p, y, p), A = a, u++, u > 1e4) break;
|
|
845
|
+
}
|
|
846
|
+
};
|
|
847
|
+
_.XF.h6 = function(t, n, e, r) {
|
|
848
|
+
const s = t[n * 2], o = t[n * 2 + 1], i = t[e * 2], u = t[e * 2 + 1], c = t[r * 2], l = t[r * 2 + 1];
|
|
849
|
+
return s * u + i * l + c * o - c * u - i * o - s * l;
|
|
850
|
+
};
|
|
851
|
+
_.XF.a9o = function(t, n) {
|
|
852
|
+
const e = [], r = [], s = [], o = {};
|
|
853
|
+
for (let i = 0; i < n.length; i += 3) {
|
|
854
|
+
const u = ~~(i * 0.3333333333333333);
|
|
855
|
+
let c = n[i + 0], l = n[i + 1], f = n[i + 2];
|
|
856
|
+
if (_.XF.h6(t, c, l, f) > 0) {
|
|
857
|
+
const m = l;
|
|
858
|
+
l = f, f = m;
|
|
859
|
+
}
|
|
860
|
+
const h = o[f + "-" + l], p = o[l + "-" + c], A = o[c + "-" + f], g = [f, h, u, null], a = [l, p, u, g], y = [c, A, u, a];
|
|
861
|
+
g[3] = y, h && (h[1] = g), p && (p[1] = a), A && (A[1] = y), o[f + "-" + c] = y, o[c + "-" + l] = a, o[l + "-" + f] = g, e[c] = a, s[i] = a, e[l] = g, s[i + 1] = g, e[f] = y, s[i + 2] = y, r[u] = a;
|
|
862
|
+
}
|
|
863
|
+
return { fD: e, EE: r, pK: s };
|
|
864
|
+
};
|
|
865
|
+
_.uZ.aI9 = function(t) {
|
|
866
|
+
const n = t.UC, e = t.B_, r = t.w$, s = _.es.multiply, o = _.XF.a9o(n, e), i = n.length >>> 1;
|
|
867
|
+
let u = 0;
|
|
868
|
+
const c = 1e3;
|
|
869
|
+
for (let E = 0; E < o.pK.length; E++) u += o.pK[E][1] ? 0.5 : 1;
|
|
870
|
+
const l = u + r.length, f = new _.W9(l * 2, i * 2), d = new _.W9(l, i), h = [[[-1, 0, 1, 0, 0, 0], [0, -1, 0, 1, 0, 0]], [[-1, 0, 1, 0, 0, 0, 0, 0], [0, -1, 0, 1, 0, 0, 0, 0]]], p = [], A = [], g = [];
|
|
871
|
+
for (let E = 0; E < o.pK.length; E++) {
|
|
872
|
+
const w = o.pK[E], M = w[3][3][0], D = w[0], C = w[3][0], F = w[1] ? w[1][3][0] : C;
|
|
873
|
+
if (w[1] && M > D) continue;
|
|
874
|
+
const S = n[M * 2], I = n[M * 2 + 1], v = n[D * 2], T = n[D * 2 + 1], W = n[C * 2], L = n[C * 2 + 1], B = n[F * 2], b = n[F * 2 + 1], P = [[S, I, 1, 0], [I, -S, 0, 1], [v, T, 1, 0], [T, -v, 0, 1], [W, L, 1, 0], [L, -W, 0, 1]];
|
|
875
|
+
w[1] && P.push([B, b, 1, 0], [b, -B, 0, 1]);
|
|
876
|
+
const X = _.es.MG(P), O = s(re.invert(s(X, P)), X);
|
|
877
|
+
O.pop(), O.pop(), p.push(O);
|
|
878
|
+
const k = v - S, j = T - I;
|
|
879
|
+
let Y = h[w[1] ? 1 : 0];
|
|
880
|
+
Y = _.es.y8(Y, s([[k, j], [j, -k]], O));
|
|
881
|
+
const J = [M * 2, M * 2 + 1, D * 2, D * 2 + 1, C * 2, C * 2 + 1, F * 2, F * 2 + 1], z = w[1] ? 8 : 6, K = [];
|
|
882
|
+
for (let N = 0; N < z; N++) K.push([J[N], Y[0][N], Y[1][N]]);
|
|
883
|
+
K.sort(function(N, V) {
|
|
884
|
+
return N[0] - V[0];
|
|
885
|
+
});
|
|
886
|
+
for (let N = 0; N < 2; N++) {
|
|
887
|
+
for (let V = 0; V < z; V++)
|
|
888
|
+
A[V] = K[V][0], g[V] = K[V][1 + N];
|
|
889
|
+
f.Hk(g, A, z);
|
|
890
|
+
}
|
|
891
|
+
M < D ? d.Hk([-1, 1], [M, D], 2) : d.Hk([1, -1], [D, M], 2);
|
|
892
|
+
}
|
|
893
|
+
for (let E = 0; E < r.length; E++) {
|
|
894
|
+
const w = r[E];
|
|
895
|
+
f.Hk([c], [w * 2], 1), f.Hk([c], [w * 2 + 1], 1), d.Hk([c], [w], 1);
|
|
896
|
+
}
|
|
897
|
+
const a = f.MG(), y = a._g(a), m = d.MG(), x = m._g(m);
|
|
898
|
+
return { aI8: u, ah: l, abf: a, aCL: y, aug: m, ahD: x, azO: o, afj: p, mE: c };
|
|
899
|
+
};
|
|
900
|
+
_.uZ.aH0 = function(t) {
|
|
901
|
+
const n = t.nt, e = t.UC, r = t.iE, s = t.M3, o = t.oP, i = t.k3, u = _.es.Jj;
|
|
902
|
+
let c = 0;
|
|
903
|
+
function l(a) {
|
|
904
|
+
const y = new Array(a);
|
|
905
|
+
for (let m = 0; m < a; m++) y[m] = 0;
|
|
906
|
+
return y;
|
|
907
|
+
}
|
|
908
|
+
const f = e.length >>> 1, d = l(n.ah * 2), h = l(n.ah), p = l(n.ah);
|
|
909
|
+
for (let a = 0; a < t.w$.length; a++) {
|
|
910
|
+
const y = n.aI8 + a, m = n.mE * (o[a * 2] + i[a * 2]), x = n.mE * (o[a * 2 + 1] + i[a * 2 + 1]);
|
|
911
|
+
d[y * 2] = m, d[y * 2 + 1] = x, h[y] = m, p[y] = x;
|
|
912
|
+
}
|
|
913
|
+
n.aCL.e0(r, n.abf.Jj(d), 0.01);
|
|
914
|
+
for (let a = 0; a < n.azO.pK.length; a++) {
|
|
915
|
+
const y = n.azO.pK[a], m = y[3][3][0], x = y[0], E = y[3][0], w = y[1] ? y[1][3][0] : E;
|
|
916
|
+
if (y[1] && m > x) continue;
|
|
917
|
+
const M = e[m * 2], D = e[m * 2 + 1], C = e[x * 2], F = e[x * 2 + 1], S = r[m * 2], I = r[m * 2 + 1], v = r[x * 2], T = r[x * 2 + 1], W = r[E * 2], L = r[E * 2 + 1], B = r[w * 2], b = r[w * 2 + 1], P = [S, I, v, T, W, L];
|
|
918
|
+
y[1] && P.push(B, b);
|
|
919
|
+
const X = u(n.afj[c], P);
|
|
920
|
+
let O = X[0], k = X[1];
|
|
921
|
+
const j = 1 / Math.sqrt(O * O + k * k);
|
|
922
|
+
O *= j, k *= j;
|
|
923
|
+
const Y = C - M, J = F - D;
|
|
924
|
+
h[c] = O * Y + k * J, p[c] = -k * Y + O * J, c++;
|
|
925
|
+
}
|
|
926
|
+
const A = new Array(f), g = new Array(f);
|
|
927
|
+
for (let a = 0; a < f; a++)
|
|
928
|
+
A[a] = s[a * 2], g[a] = s[a * 2 + 1];
|
|
929
|
+
n.ahD.e0(A, n.aug.Jj(h), 0.5), n.ahD.e0(g, n.aug.Jj(p), 0.5);
|
|
930
|
+
for (let a = 0; a < f; a++)
|
|
931
|
+
s[a * 2] = A[a], s[a * 2 + 1] = g[a];
|
|
932
|
+
};
|
|
933
|
+
const it = /* @__PURE__ */ new Map(), se = 32;
|
|
934
|
+
function oe(t) {
|
|
935
|
+
const n = t.UC, e = t.B_, r = t.w$, s = n.length, o = [], i = [0, 1, 2, 3, s >> 2 | 0, s >> 1 | 0, 3 * s >> 2 | 0, s - 2, s - 1];
|
|
936
|
+
for (const u of i)
|
|
937
|
+
u >= 0 && u < s && o.push(Math.round(n[u] * 1e3));
|
|
938
|
+
return `${n.length}|${e.length}|${r.length}|${r.join(",")}|${o.join(",")}`;
|
|
939
|
+
}
|
|
940
|
+
function Qt(t) {
|
|
941
|
+
const n = oe(t), e = it.get(n);
|
|
942
|
+
if (e)
|
|
943
|
+
return e.lastUsed = Date.now(), t.nt = e.nt, t.nt;
|
|
944
|
+
if (it.size >= se) {
|
|
945
|
+
let s = null, o = 1 / 0;
|
|
946
|
+
for (const [i, u] of it)
|
|
947
|
+
u.lastUsed < o && (o = u.lastUsed, s = i);
|
|
948
|
+
s !== null && it.delete(s);
|
|
949
|
+
}
|
|
950
|
+
const r = _.uZ.aI9(t);
|
|
951
|
+
return t.nt = r, it.set(n, { nt: r, lastUsed: Date.now() }), r;
|
|
952
|
+
}
|
|
953
|
+
function ie(t) {
|
|
954
|
+
t.nt || Qt(t), _.uZ.aH0(t);
|
|
955
|
+
}
|
|
956
|
+
function ue(t) {
|
|
957
|
+
const n = [];
|
|
958
|
+
for (const i of t.originalVertices)
|
|
959
|
+
n.push(i.x, i.y);
|
|
960
|
+
const e = n.slice(), r = n.slice(), s = [];
|
|
961
|
+
for (const i of t.pinTargets)
|
|
962
|
+
s.push(i.x, i.y);
|
|
963
|
+
const o = [];
|
|
964
|
+
if (t.pinOffsets)
|
|
965
|
+
for (const i of t.pinOffsets)
|
|
966
|
+
o.push(i.x, i.y);
|
|
967
|
+
else
|
|
968
|
+
for (let i = 0; i < t.pinIndices.length; i++) o.push(0, 0);
|
|
969
|
+
return {
|
|
970
|
+
UC: n,
|
|
971
|
+
B_: t.triangles.slice(),
|
|
972
|
+
w$: t.pinIndices.slice(),
|
|
973
|
+
iE: e,
|
|
974
|
+
M3: r,
|
|
975
|
+
oP: s,
|
|
976
|
+
k3: o
|
|
977
|
+
};
|
|
978
|
+
}
|
|
979
|
+
let Bt = !1;
|
|
980
|
+
const rt = (...t) => {
|
|
981
|
+
}, ce = (...t) => {
|
|
982
|
+
};
|
|
983
|
+
let R = null, st = !1, H = null, q = null, lt = null, ht = null, ft = null, Tt = null, jt = 0, Kt = 0, Pt = null, ut = null, Rt = 0, Xt = 0, Z = [], Ot = null, nt = null, G = null, Ct = null, bt = null, vt = null;
|
|
984
|
+
function ae(t) {
|
|
985
|
+
q = t.licenseToken, lt = t.licenseApiUrl, ht = t.deviceId, ft = t.domain, self.LICENSE_TOKEN = q, self.LICENSE_API_URL = lt, self.DEVICE_ID = ht, self.DOMAIN = ft, R || (H && !st && (H = null), Nt().then(() => {
|
|
986
|
+
}).catch((n) => {
|
|
381
987
|
}));
|
|
382
988
|
}
|
|
383
|
-
async function
|
|
384
|
-
return
|
|
989
|
+
async function Nt() {
|
|
990
|
+
return R ? void 0 : st ? H || Promise.resolve() : q || self.LICENSE_TOKEN ? (st = !0, H = (async () => {
|
|
385
991
|
try {
|
|
386
|
-
|
|
387
|
-
const
|
|
388
|
-
const
|
|
389
|
-
if (
|
|
390
|
-
return
|
|
391
|
-
if (
|
|
392
|
-
return
|
|
992
|
+
R = te.getInstance();
|
|
993
|
+
const n = (l) => {
|
|
994
|
+
const f = self.WASM_URL, d = self.WASM_EXEC_URL;
|
|
995
|
+
if (l === "perspective.wasm" && f)
|
|
996
|
+
return f;
|
|
997
|
+
if (l === "wasm_exec.js" && d)
|
|
998
|
+
return d;
|
|
393
999
|
try {
|
|
394
1000
|
let h = null;
|
|
395
1001
|
if (typeof import.meta < "u" && import.meta.url ? h = import.meta.url : typeof self < "u" && self.location && (h = self.location.href), h) {
|
|
396
|
-
const
|
|
397
|
-
if (
|
|
398
|
-
const
|
|
399
|
-
return
|
|
400
|
-
} else if (
|
|
401
|
-
const
|
|
402
|
-
return
|
|
1002
|
+
const p = new URL(h), A = p.pathname;
|
|
1003
|
+
if (A.includes("/js/")) {
|
|
1004
|
+
const g = "../assets/" + l, a = new URL(g, p);
|
|
1005
|
+
return rt(`🔍 [deform.worker] 计算路径: ${l} -> ${a.pathname} (Worker: ${A})`), a.pathname;
|
|
1006
|
+
} else if (A.includes("/assets/")) {
|
|
1007
|
+
const g = "./" + l, a = new URL(g, p);
|
|
1008
|
+
return rt(`🔍 [deform.worker] 计算路径: ${l} -> ${a.pathname} (Worker: ${A})`), a.pathname;
|
|
403
1009
|
} else
|
|
404
|
-
return
|
|
1010
|
+
return rt(`🔍 [deform.worker] 使用默认绝对路径: /assets/${l}`), "/assets/" + l;
|
|
405
1011
|
}
|
|
406
1012
|
} catch (h) {
|
|
407
|
-
|
|
1013
|
+
ce("⚠️ [deform.worker] 无法计算 WASM 相对路径,使用默认路径:", h);
|
|
408
1014
|
}
|
|
409
|
-
return "/assets/" +
|
|
410
|
-
}, e = self.WASM_URL ||
|
|
411
|
-
|
|
412
|
-
const
|
|
413
|
-
if (!
|
|
1015
|
+
return "/assets/" + l;
|
|
1016
|
+
}, e = self.WASM_URL || n("perspective.wasm"), r = self.WASM_EXEC_URL || n("wasm_exec.js");
|
|
1017
|
+
rt("🔍 [deform.worker] 最终使用的 WASM 路径:", { wasmUrl: e, wasmExecUrl: r }), await R.load(e, r);
|
|
1018
|
+
const s = q || self.LICENSE_TOKEN, o = lt || self.LICENSE_API_URL, i = ht || self.DEVICE_ID, u = ft || self.DOMAIN;
|
|
1019
|
+
if (!s)
|
|
414
1020
|
throw new Error("LICENSE_TOKEN 未设置,无法使用 WASM 功能");
|
|
415
|
-
if (!await
|
|
1021
|
+
if (!await R.verifyLicense(s, o))
|
|
416
1022
|
throw new Error("WASM License 验证失败,无法使用 WASM 功能");
|
|
417
|
-
} catch (
|
|
418
|
-
throw
|
|
1023
|
+
} catch (n) {
|
|
1024
|
+
throw R = null, H = null, n;
|
|
419
1025
|
} finally {
|
|
420
|
-
|
|
1026
|
+
st = !1;
|
|
421
1027
|
}
|
|
422
|
-
})(),
|
|
1028
|
+
})(), H) : Promise.resolve();
|
|
423
1029
|
}
|
|
424
|
-
function
|
|
425
|
-
return "naturalWidth" in
|
|
1030
|
+
function Ut(t) {
|
|
1031
|
+
return "naturalWidth" in t && t.naturalWidth ? { width: t.naturalWidth, height: t.naturalHeight } : "width" in t ? { width: t.width, height: t.height } : { width: 0, height: 0 };
|
|
426
1032
|
}
|
|
427
|
-
function
|
|
428
|
-
if (!
|
|
1033
|
+
function le(t, n) {
|
|
1034
|
+
if (!t || !t.bounds)
|
|
429
1035
|
throw new Error("Invalid layer data: missing bounds");
|
|
430
|
-
const e =
|
|
431
|
-
if (
|
|
432
|
-
return { ...
|
|
433
|
-
const r =
|
|
1036
|
+
const e = t.bounds;
|
|
1037
|
+
if (n && n.width > 0 && n.height > 0)
|
|
1038
|
+
return { ...t };
|
|
1039
|
+
const r = t.size || t.placedLayer || {
|
|
434
1040
|
width: e.width,
|
|
435
1041
|
height: e.height
|
|
436
|
-
},
|
|
437
|
-
return
|
|
438
|
-
(
|
|
439
|
-
(
|
|
440
|
-
(
|
|
441
|
-
(
|
|
442
|
-
(
|
|
443
|
-
(
|
|
444
|
-
(
|
|
445
|
-
(
|
|
446
|
-
]),
|
|
447
|
-
}
|
|
448
|
-
function
|
|
449
|
-
return
|
|
450
|
-
}
|
|
451
|
-
function
|
|
452
|
-
if (!
|
|
1042
|
+
}, s = r.width / e.width, o = r.height / e.height, i = { ...t };
|
|
1043
|
+
return t.transform && t.transform.length === 8 && (i.transform = [
|
|
1044
|
+
(t.transform[0] - e.left) * s,
|
|
1045
|
+
(t.transform[1] - e.top) * o,
|
|
1046
|
+
(t.transform[2] - e.left) * s,
|
|
1047
|
+
(t.transform[3] - e.top) * o,
|
|
1048
|
+
(t.transform[4] - e.left) * s,
|
|
1049
|
+
(t.transform[5] - e.top) * o,
|
|
1050
|
+
(t.transform[6] - e.left) * s,
|
|
1051
|
+
(t.transform[7] - e.top) * o
|
|
1052
|
+
]), i;
|
|
1053
|
+
}
|
|
1054
|
+
function he(t) {
|
|
1055
|
+
return t.error, t;
|
|
1056
|
+
}
|
|
1057
|
+
function fe(t, n, e) {
|
|
1058
|
+
if (!t || !n || !e)
|
|
453
1059
|
return "Invalid Parameters";
|
|
454
|
-
const r = "naturalWidth" in
|
|
455
|
-
if (!r || !
|
|
1060
|
+
const r = "naturalWidth" in n ? n.naturalWidth : "width" in n ? n.width : 0, s = "naturalHeight" in n ? n.naturalHeight : "height" in n ? n.height : 0;
|
|
1061
|
+
if (!r || !s)
|
|
456
1062
|
return "Image Not Loaded";
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
{ x:
|
|
464
|
-
{ x:
|
|
465
|
-
{ x:
|
|
1063
|
+
t.imageSmoothingEnabled = !0, t.imageSmoothingQuality = "high", Z = [];
|
|
1064
|
+
const o = t.canvas.width, i = t.canvas.height;
|
|
1065
|
+
let u = null, c = null, l = null, f = null, d = 0, h = 0, p = null, A = "Unknown";
|
|
1066
|
+
if (e.size && e.size.width ? (d = e.size.width, h = e.size.height) : e.placedLayer && e.placedLayer.width ? (d = e.placedLayer.width, h = e.placedLayer.height) : e.originalWidth && (d = e.originalWidth, h = e.originalHeight), e.meshPoints && e.meshPoints.length > 0 && (u = e.meshPoints), e.transform && e.transform.length === 8) {
|
|
1067
|
+
const a = e.transform;
|
|
1068
|
+
c = [
|
|
1069
|
+
{ x: a[0], y: a[1] },
|
|
1070
|
+
{ x: a[2], y: a[3] },
|
|
1071
|
+
{ x: a[4], y: a[5] },
|
|
1072
|
+
{ x: a[6], y: a[7] }
|
|
466
1073
|
];
|
|
467
1074
|
}
|
|
468
|
-
|
|
1075
|
+
if (e.quiltSliceX && (l = e.quiltSliceX), e.quiltSliceY && (f = e.quiltSliceY), e.filterList && (p = e.filterList.find((a) => a.type === "puppet" && a.enabled)), d === 0 && l && l.length > 0 && (d = l[l.length - 1]), d === 0 && (d = 1e3), h === 0 && (h = 1e3), e.presetPuppet && e.presetPuppet.triangles && e.presetPuppet.triangles.length > 0)
|
|
1076
|
+
try {
|
|
1077
|
+
const a = e.presetPuppet, y = (D) => {
|
|
1078
|
+
if (!D) return [];
|
|
1079
|
+
if (D.length > 0 && typeof D[0] == "number") {
|
|
1080
|
+
const C = [], F = D;
|
|
1081
|
+
for (let S = 0; S < F.length; S += 2) C.push({ x: F[S], y: F[S + 1] });
|
|
1082
|
+
return C;
|
|
1083
|
+
}
|
|
1084
|
+
return D;
|
|
1085
|
+
}, m = y(a.originalVertices), x = y(a.pinTargets), E = a.pinOffsets ? y(a.pinOffsets) : void 0, w = ue({
|
|
1086
|
+
originalVertices: m,
|
|
1087
|
+
triangles: a.triangles,
|
|
1088
|
+
pinIndices: a.pinIndices,
|
|
1089
|
+
pinTargets: x,
|
|
1090
|
+
pinOffsets: E
|
|
1091
|
+
});
|
|
1092
|
+
Qt(w), ie(w);
|
|
1093
|
+
const M = Ut(n);
|
|
1094
|
+
for (let D = 0; D < a.triangles.length; D += 3) {
|
|
1095
|
+
const C = a.triangles[D], F = a.triangles[D + 1], S = a.triangles[D + 2], I = { x: w.UC[C * 2], y: w.UC[C * 2 + 1] }, v = { x: w.UC[F * 2], y: w.UC[F * 2 + 1] }, T = { x: w.UC[S * 2], y: w.UC[S * 2 + 1] }, W = { x: w.M3[C * 2], y: w.M3[C * 2 + 1] }, L = { x: w.M3[F * 2], y: w.M3[F * 2 + 1] }, B = { x: w.M3[S * 2], y: w.M3[S * 2 + 1] };
|
|
1096
|
+
let b = I, P = v, X = T;
|
|
1097
|
+
m.length > 0 && Math.max(
|
|
1098
|
+
...m.map((k) => Math.max(k.x, k.y))
|
|
1099
|
+
) <= 1.5 && (b = { x: I.x * M.width, y: I.y * M.height }, P = { x: v.x * M.width, y: v.y * M.height }, X = { x: T.x * M.width, y: T.y * M.height }), ot(t, n, b, P, X, W, L, B);
|
|
1100
|
+
}
|
|
1101
|
+
A = "Photopea ARAP Puppet";
|
|
1102
|
+
} catch {
|
|
1103
|
+
}
|
|
1104
|
+
if (A === "Unknown" && e.presetWarp && e.presetWarp.preset)
|
|
1105
|
+
try {
|
|
1106
|
+
const a = e.presetWarp, y = d / h, m = ee({
|
|
1107
|
+
preset: a.preset,
|
|
1108
|
+
value: a.value,
|
|
1109
|
+
rotateHorizontal: a.horizontal !== !1,
|
|
1110
|
+
perspective: a.perspective ?? 0,
|
|
1111
|
+
perspectiveOther: a.perspectiveOther ?? 0,
|
|
1112
|
+
aspect: y
|
|
1113
|
+
});
|
|
1114
|
+
ne(m.points, {
|
|
1115
|
+
x: e.bounds.left,
|
|
1116
|
+
y: e.bounds.top,
|
|
1117
|
+
width: e.bounds.width,
|
|
1118
|
+
height: e.bounds.height
|
|
1119
|
+
});
|
|
1120
|
+
const x = [];
|
|
1121
|
+
for (let E = 0; E < m.points.length; E += 2)
|
|
1122
|
+
x.push({ x: m.points[E], y: m.points[E + 1] });
|
|
1123
|
+
m.cols === 4 && m.rows === 4 ? Jt(t, n, x) : yt(t, n, x, "grid", m.cols, 20), A = `Preset:${a.preset}`;
|
|
1124
|
+
} catch {
|
|
1125
|
+
}
|
|
1126
|
+
A === "Unknown" && p && p.filter && p.filter.puppetShapeList && p.filter.puppetShapeList.length > 0 && c ? (ye(t, n, c, p.filter.puppetShapeList[0]), A = "Puppet Warp") : A === "Unknown" && u && c ? l && f ? (we(t, n, c, u, l, f, d, h), A = "Quilt Mesh") : u.length === 16 ? (de(t, n, c, u), A = "Std Mesh (16pt)") : (pe(t, n, c, u), A = "Auto-Fit Mesh") : A === "Unknown" && u ? (Jt(t, n, u), A = "Direct Mesh") : A === "Unknown" && c && ($t(t, n, c), A = "Transform Only");
|
|
1127
|
+
const g = Ee(n, o, i);
|
|
1128
|
+
if (g)
|
|
1129
|
+
Ot = g;
|
|
1130
|
+
else if (Z.length > 0) {
|
|
1131
|
+
const y = new OffscreenCanvas(r, s).getContext("2d");
|
|
1132
|
+
y.drawImage(n, 0, 0), Tt = y.getImageData(0, 0, r, s).data, jt = r, Kt = s, Rt = o, Xt = i, ut = new ImageData(Rt, Xt), Pt = ut.data;
|
|
1133
|
+
for (const m of Z)
|
|
1134
|
+
xe(
|
|
1135
|
+
{ x: m.t0x, y: m.t0y },
|
|
1136
|
+
{ x: m.t1x, y: m.t1y },
|
|
1137
|
+
{ x: m.t2x, y: m.t2y },
|
|
1138
|
+
{ x: m.p0x, y: m.p0y },
|
|
1139
|
+
{ x: m.p1x, y: m.p1y },
|
|
1140
|
+
{ x: m.p2x, y: m.p2y }
|
|
1141
|
+
);
|
|
1142
|
+
ut && t.putImageData(ut, 0, 0), Tt = null, Pt = null, ut = null;
|
|
1143
|
+
}
|
|
1144
|
+
return A;
|
|
469
1145
|
}
|
|
470
|
-
function
|
|
1146
|
+
function ye(t, n, e, r, s, o) {
|
|
471
1147
|
if (!r.originalVertexArray || !r.deformedVertexArray || !r.indexArray)
|
|
472
1148
|
return;
|
|
473
|
-
const
|
|
474
|
-
if (!
|
|
475
|
-
|
|
1149
|
+
const i = kt(e), u = me(i);
|
|
1150
|
+
if (!u) {
|
|
1151
|
+
$t(t, n, e);
|
|
476
1152
|
return;
|
|
477
1153
|
}
|
|
478
|
-
const
|
|
479
|
-
for (let
|
|
480
|
-
const h =
|
|
481
|
-
if (!
|
|
482
|
-
const
|
|
483
|
-
|
|
1154
|
+
const c = r.originalVertexArray, l = r.deformedVertexArray, f = r.indexArray;
|
|
1155
|
+
for (let d = 0; d < f.length; d += 3) {
|
|
1156
|
+
const h = f[d], p = f[d + 1], A = f[d + 2];
|
|
1157
|
+
if (!c[h] || !c[p] || !c[A]) continue;
|
|
1158
|
+
const g = c[h], a = c[p], y = c[A], m = Lt(g.x, g.y, u), x = Lt(a.x, a.y, u), E = Lt(y.x, y.y, u), w = Ut(n), M = { x: m.x * w.width, y: m.y * w.height }, D = { x: x.x * w.width, y: x.y * w.height }, C = { x: E.x * w.width, y: E.y * w.height }, F = l[h], S = l[p], I = l[A];
|
|
1159
|
+
ot(t, n, M, D, C, F, S, I);
|
|
484
1160
|
}
|
|
485
1161
|
}
|
|
486
|
-
function
|
|
487
|
-
let
|
|
488
|
-
r.forEach((
|
|
489
|
-
|
|
1162
|
+
function de(t, n, e, r) {
|
|
1163
|
+
let s = 1 / 0, o = -1 / 0, i = 1 / 0, u = -1 / 0;
|
|
1164
|
+
r.forEach((d) => {
|
|
1165
|
+
s = Math.min(s, d.x), o = Math.max(o, d.x), i = Math.min(i, d.y), u = Math.max(u, d.y);
|
|
490
1166
|
});
|
|
491
|
-
const
|
|
492
|
-
if (
|
|
493
|
-
|
|
1167
|
+
const c = o - s, l = u - i;
|
|
1168
|
+
if (c < 1 || l < 1) {
|
|
1169
|
+
$t(t, n, e);
|
|
494
1170
|
return;
|
|
495
1171
|
}
|
|
496
|
-
const
|
|
497
|
-
const h = (
|
|
498
|
-
return
|
|
1172
|
+
const f = r.map((d) => {
|
|
1173
|
+
const h = (d.x - s) / c, p = (d.y - i) / l;
|
|
1174
|
+
return at(h, p, e);
|
|
499
1175
|
});
|
|
500
|
-
|
|
1176
|
+
yt(t, n, f, "bicubic", 4, 40);
|
|
501
1177
|
}
|
|
502
|
-
function
|
|
503
|
-
const
|
|
504
|
-
let
|
|
505
|
-
r.forEach((
|
|
506
|
-
|
|
1178
|
+
function we(t, n, e, r, s, o, i, u) {
|
|
1179
|
+
const c = kt(e);
|
|
1180
|
+
let l = 1 / 0, f = -1 / 0, d = 1 / 0, h = -1 / 0;
|
|
1181
|
+
r.forEach((y) => {
|
|
1182
|
+
l = Math.min(l, y.x), f = Math.max(f, y.x), d = Math.min(d, y.y), h = Math.max(h, y.y);
|
|
507
1183
|
});
|
|
508
|
-
const
|
|
509
|
-
for (let
|
|
510
|
-
for (let
|
|
511
|
-
const
|
|
1184
|
+
const p = f - l || 1, A = h - d || 1, g = s.length - 1, a = o.length - 1;
|
|
1185
|
+
for (let y = 0; y < a; y++)
|
|
1186
|
+
for (let m = 0; m < g; m++) {
|
|
1187
|
+
const x = y * 3, E = m * 3, w = [], M = g * 3 + 1;
|
|
512
1188
|
try {
|
|
513
|
-
for (let
|
|
1189
|
+
for (let v = 0; v < 4; v++)
|
|
514
1190
|
for (let T = 0; T < 4; T++) {
|
|
515
|
-
const
|
|
516
|
-
r[
|
|
1191
|
+
const W = (x + v) * M + (E + T);
|
|
1192
|
+
r[W] && w.push(r[W]);
|
|
517
1193
|
}
|
|
518
1194
|
} catch {
|
|
519
1195
|
continue;
|
|
520
1196
|
}
|
|
521
|
-
if (
|
|
522
|
-
const
|
|
523
|
-
const T = (
|
|
524
|
-
return
|
|
525
|
-
}),
|
|
526
|
-
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
|
-
function
|
|
530
|
-
const
|
|
531
|
-
let
|
|
532
|
-
r.forEach((
|
|
533
|
-
|
|
1197
|
+
if (w.length < 16) continue;
|
|
1198
|
+
const D = w.map((v) => {
|
|
1199
|
+
const T = (v.x - l) / p, W = (v.y - d) / A;
|
|
1200
|
+
return qt(T, W, c);
|
|
1201
|
+
}), C = s[m] / i, F = s[m + 1] / i, S = o[y] / u, I = o[y + 1] / u;
|
|
1202
|
+
ge(t, n, D, C, F, S, I);
|
|
1203
|
+
}
|
|
1204
|
+
}
|
|
1205
|
+
function pe(t, n, e, r) {
|
|
1206
|
+
const s = kt(e);
|
|
1207
|
+
let o = 1 / 0, i = -1 / 0, u = 1 / 0, c = -1 / 0;
|
|
1208
|
+
r.forEach((p) => {
|
|
1209
|
+
o = Math.min(o, p.x), i = Math.max(i, p.x), u = Math.min(u, p.y), c = Math.max(c, p.y);
|
|
534
1210
|
});
|
|
535
|
-
const
|
|
536
|
-
const
|
|
537
|
-
return
|
|
1211
|
+
const l = i - o || 1, f = c - u || 1, d = r.map((p) => {
|
|
1212
|
+
const A = (p.x - o) / l, g = (p.y - u) / f;
|
|
1213
|
+
return qt(A, g, s);
|
|
538
1214
|
}), h = Math.floor(Math.sqrt(r.length)) || 4;
|
|
539
|
-
|
|
1215
|
+
yt(t, n, d, "grid", h, 40);
|
|
540
1216
|
}
|
|
541
|
-
function
|
|
542
|
-
const
|
|
543
|
-
for (let
|
|
1217
|
+
function ge(t, n, e, r, s, o, i) {
|
|
1218
|
+
const c = Ut(n), l = c.width, f = c.height;
|
|
1219
|
+
for (let d = 0; d < 20; d++)
|
|
544
1220
|
for (let h = 0; h < 20; h++) {
|
|
545
|
-
const
|
|
546
|
-
|
|
1221
|
+
const p = h / 20, A = d / 20, g = (h + 1) / 20, a = (d + 1) / 20, y = r + p * (s - r), m = r + g * (s - r), x = o + A * (i - o), E = o + a * (i - o), w = { x: y * l, y: x * f }, M = { x: m * l, y: x * f }, D = { x: y * l, y: E * f }, C = { x: m * l, y: E * f }, F = Q(p, A, e), S = Q(g, A, e), I = Q(p, a, e), v = Q(g, a, e);
|
|
1222
|
+
ot(t, n, w, M, D, F, S, I), ot(t, n, M, C, D, S, v, I);
|
|
547
1223
|
}
|
|
548
1224
|
}
|
|
549
|
-
function
|
|
550
|
-
|
|
1225
|
+
function $t(t, n, e) {
|
|
1226
|
+
yt(t, n, e, "bilinear", 0, 10);
|
|
551
1227
|
}
|
|
552
|
-
function
|
|
553
|
-
|
|
1228
|
+
function Jt(t, n, e) {
|
|
1229
|
+
yt(t, n, e, "bicubic", 4, 40);
|
|
554
1230
|
}
|
|
555
|
-
function
|
|
556
|
-
const
|
|
557
|
-
for (let
|
|
558
|
-
for (let
|
|
559
|
-
const
|
|
560
|
-
let
|
|
561
|
-
r === "bicubic" ? (
|
|
1231
|
+
function yt(t, n, e, r, s, o) {
|
|
1232
|
+
const i = Ut(n), u = i.width, c = i.height;
|
|
1233
|
+
for (let l = 0; l < o; l++)
|
|
1234
|
+
for (let f = 0; f < o; f++) {
|
|
1235
|
+
const d = f / o, h = l / o, p = (f + 1) / o, A = (l + 1) / o, g = { x: d * u, y: h * c }, a = { x: p * u, y: h * c }, y = { x: d * u, y: A * c }, m = { x: p * u, y: A * c };
|
|
1236
|
+
let x, E, w, M;
|
|
1237
|
+
r === "bicubic" ? (x = Q(d, h, e), E = Q(p, h, e), w = Q(d, A, e), M = Q(p, A, e)) : r === "grid" ? (x = Wt(d, h, e, s), E = Wt(p, h, e, s), w = Wt(d, A, e, s), M = Wt(p, A, e, s)) : (x = at(d, h, e), E = at(p, h, e), w = at(d, A, e), M = at(p, A, e)), ot(t, n, g, a, y, x, E, w), ot(t, n, a, m, y, E, M, w);
|
|
562
1238
|
}
|
|
563
1239
|
}
|
|
564
|
-
function
|
|
565
|
-
const e = 1 -
|
|
566
|
-
return
|
|
1240
|
+
function Ht(t, n) {
|
|
1241
|
+
const e = 1 - n;
|
|
1242
|
+
return t === 0 ? e * e * e : t === 1 ? 3 * e * e * n : t === 2 ? 3 * e * n * n : n * n * n;
|
|
567
1243
|
}
|
|
568
|
-
function
|
|
569
|
-
let r = 0,
|
|
570
|
-
for (let
|
|
571
|
-
for (let
|
|
572
|
-
const
|
|
573
|
-
r += e[
|
|
1244
|
+
function Q(t, n, e) {
|
|
1245
|
+
let r = 0, s = 0;
|
|
1246
|
+
for (let o = 0; o < 4; o++)
|
|
1247
|
+
for (let i = 0; i < 4; i++) {
|
|
1248
|
+
const u = Ht(o, n) * Ht(i, t);
|
|
1249
|
+
r += e[o * 4 + i].x * u, s += e[o * 4 + i].y * u;
|
|
574
1250
|
}
|
|
575
|
-
return { x: r, y:
|
|
1251
|
+
return { x: r, y: s };
|
|
576
1252
|
}
|
|
577
|
-
function
|
|
578
|
-
const r = (1 -
|
|
579
|
-
return { x: r, y:
|
|
1253
|
+
function at(t, n, e) {
|
|
1254
|
+
const r = (1 - t) * (1 - n) * e[0].x + t * (1 - n) * e[1].x + t * n * e[2].x + (1 - t) * n * e[3].x, s = (1 - t) * (1 - n) * e[0].y + t * (1 - n) * e[1].y + t * n * e[2].y + (1 - t) * n * e[3].y;
|
|
1255
|
+
return { x: r, y: s };
|
|
580
1256
|
}
|
|
581
|
-
function
|
|
582
|
-
const
|
|
583
|
-
let
|
|
584
|
-
|
|
585
|
-
const
|
|
586
|
-
return { x:
|
|
1257
|
+
function Wt(t, n, e, r) {
|
|
1258
|
+
const s = r - 1, o = t * s, i = n * s;
|
|
1259
|
+
let u = Math.floor(o), c = Math.floor(i);
|
|
1260
|
+
u >= s && (u = s - 1), c >= s && (c = s - 1), u < 0 && (u = 0), c < 0 && (c = 0);
|
|
1261
|
+
const l = o - u, f = i - c, d = e[c * r + u], h = e[c * r + (u + 1)], p = e[(c + 1) * r + u], A = e[(c + 1) * r + (u + 1)], g = (1 - l) * (1 - f) * d.x + l * (1 - f) * h.x + l * f * A.x + (1 - l) * f * p.x, a = (1 - l) * (1 - f) * d.y + l * (1 - f) * h.y + l * f * A.y + (1 - l) * f * p.y;
|
|
1262
|
+
return { x: g, y: a };
|
|
587
1263
|
}
|
|
588
|
-
function
|
|
589
|
-
if (!
|
|
1264
|
+
function kt(t) {
|
|
1265
|
+
if (!R || !R.isReady())
|
|
590
1266
|
throw new Error("WASM 模块未加载,无法计算透视变换矩阵");
|
|
591
1267
|
try {
|
|
592
|
-
return
|
|
593
|
-
} catch (
|
|
594
|
-
throw new Error(`WASM 计算透视矩阵失败: ${
|
|
1268
|
+
return R.calcPerspectiveMatrix(t);
|
|
1269
|
+
} catch (n) {
|
|
1270
|
+
throw new Error(`WASM 计算透视矩阵失败: ${n}`);
|
|
595
1271
|
}
|
|
596
1272
|
}
|
|
597
|
-
function
|
|
598
|
-
if (!
|
|
1273
|
+
function me(t) {
|
|
1274
|
+
if (!R || !R.isReady())
|
|
599
1275
|
throw new Error("WASM 模块未加载,无法求逆矩阵");
|
|
600
1276
|
try {
|
|
601
|
-
return
|
|
602
|
-
} catch (
|
|
603
|
-
throw new Error(`WASM 求逆矩阵失败: ${
|
|
1277
|
+
return R.invertMatrix(t);
|
|
1278
|
+
} catch (n) {
|
|
1279
|
+
throw new Error(`WASM 求逆矩阵失败: ${n}`);
|
|
604
1280
|
}
|
|
605
1281
|
}
|
|
606
|
-
function
|
|
607
|
-
if (!
|
|
1282
|
+
function Lt(t, n, e) {
|
|
1283
|
+
if (!R || !R.isReady())
|
|
608
1284
|
throw new Error("WASM 模块未加载,无法应用逆透视变换");
|
|
609
1285
|
try {
|
|
610
|
-
return
|
|
1286
|
+
return R.applyInversePerspective(t, n, e);
|
|
611
1287
|
} catch (r) {
|
|
612
1288
|
throw new Error(`WASM 应用逆透视变换失败: ${r}`);
|
|
613
1289
|
}
|
|
614
1290
|
}
|
|
615
|
-
function
|
|
616
|
-
if (!
|
|
1291
|
+
function qt(t, n, e) {
|
|
1292
|
+
if (!R || !R.isReady())
|
|
617
1293
|
throw new Error("WASM 模块未加载,无法应用透视变换");
|
|
618
1294
|
try {
|
|
619
|
-
return
|
|
1295
|
+
return R.applyPerspective(t, n, e);
|
|
620
1296
|
} catch (r) {
|
|
621
1297
|
throw new Error(`WASM 应用透视变换失败: ${r}`);
|
|
622
1298
|
}
|
|
623
1299
|
}
|
|
624
|
-
function
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
s.
|
|
631
|
-
|
|
1300
|
+
function ot(t, n, e, r, s, o, i, u) {
|
|
1301
|
+
Z.push({
|
|
1302
|
+
t0x: e.x,
|
|
1303
|
+
t0y: e.y,
|
|
1304
|
+
t1x: r.x,
|
|
1305
|
+
t1y: r.y,
|
|
1306
|
+
t2x: s.x,
|
|
1307
|
+
t2y: s.y,
|
|
1308
|
+
p0x: o.x,
|
|
1309
|
+
p0y: o.y,
|
|
1310
|
+
p1x: i.x,
|
|
1311
|
+
p1y: i.y,
|
|
1312
|
+
p2x: u.x,
|
|
1313
|
+
p2y: u.y
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
function xe(t, n, e, r, s, o) {
|
|
1317
|
+
if (!Tt || !Pt) return;
|
|
1318
|
+
const i = t.x * (e.y - n.y) - n.x * e.y + e.x * n.y + (n.x - e.x) * t.y;
|
|
1319
|
+
if (Math.abs(i) < 1e-3) return;
|
|
1320
|
+
const u = -(t.y * (o.x - s.x) - n.y * o.x + e.y * s.x + (n.y - e.y) * r.x) / i, c = (n.y * o.y + t.y * (s.y - o.y) - e.y * s.y + (e.y - n.y) * r.y) / i, l = (t.x * (o.x - s.x) - n.x * o.x + e.x * s.x + (n.x - e.x) * r.x) / i, f = -(n.x * o.y + t.x * (s.y - o.y) - e.x * s.y + (e.x - n.x) * r.y) / i, d = (t.x * (e.y * s.x - n.y * o.x) + t.y * (n.x * o.x - e.x * s.x) + (e.x * n.y - n.x * e.y) * r.x) / i, h = (t.x * (e.y * s.y - n.y * o.y) + t.y * (n.x * o.y - e.x * s.y) + (e.x * n.y - n.x * e.y) * r.y) / i, p = u * f - c * l;
|
|
1321
|
+
if (Math.abs(p) < 1e-9) return;
|
|
1322
|
+
const A = f / p, g = -c / p, a = -l / p, y = u / p, m = (-f * d + l * h) / p, x = (c * d - u * h) / p, E = Math.max(0, Math.floor(Math.min(r.x, s.x, o.x))), w = Math.min(Rt - 1, Math.ceil(Math.max(r.x, s.x, o.x))), M = Math.max(0, Math.floor(Math.min(r.y, s.y, o.y))), D = Math.min(Xt - 1, Math.ceil(Math.max(r.y, s.y, o.y))), C = s.x - r.x, F = s.y - r.y, S = o.x - s.x, I = o.y - s.y, v = r.x - o.x, T = r.y - o.y, W = jt, L = Kt, B = Tt, b = Pt;
|
|
1323
|
+
for (let P = M; P <= D; P++) {
|
|
1324
|
+
const X = P + 0.5, O = C * (X - r.y), k = S * (X - s.y), j = v * (X - o.y);
|
|
1325
|
+
for (let Y = E; Y <= w; Y++) {
|
|
1326
|
+
const J = Y + 0.5, z = O - F * (J - r.x), K = k - I * (J - s.x), N = j - T * (J - o.x);
|
|
1327
|
+
if (!(z >= 0 && K >= 0 && N >= 0 || z <= 0 && K <= 0 && N <= 0)) continue;
|
|
1328
|
+
const V = A * J + a * X + m, dt = g * J + y * X + x;
|
|
1329
|
+
if (V < 0 || V >= W || dt < 0 || dt >= L) continue;
|
|
1330
|
+
const tt = V | 0, et = dt | 0, Vt = tt < W - 1 ? tt + 1 : tt, Yt = et < L - 1 ? et + 1 : et, wt = V - tt, pt = dt - et, gt = (1 - wt) * (1 - pt), mt = wt * (1 - pt), xt = (1 - wt) * pt, Et = wt * pt, At = (et * W + tt) * 4, Mt = (et * W + Vt) * 4, Ft = (Yt * W + tt) * 4, Dt = (Yt * W + Vt) * 4, St = (P * Rt + Y) * 4;
|
|
1331
|
+
b[St] = gt * B[At] + mt * B[Mt] + xt * B[Ft] + Et * B[Dt], b[St + 1] = gt * B[At + 1] + mt * B[Mt + 1] + xt * B[Ft + 1] + Et * B[Dt + 1], b[St + 2] = gt * B[At + 2] + mt * B[Mt + 2] + xt * B[Ft + 2] + Et * B[Dt + 2], b[St + 3] = gt * B[At + 3] + mt * B[Mt + 3] + xt * B[Ft + 3] + Et * B[Dt + 3];
|
|
1332
|
+
}
|
|
632
1333
|
}
|
|
633
|
-
const p = -(e.y * (c.x - o.x) - r.y * c.x + n.y * o.x + (r.y - n.y) * u.x) / g, x = (r.y * c.y + e.y * (o.y - c.y) - n.y * o.y + (n.y - r.y) * u.y) / g, A = (e.x * (c.x - o.x) - r.x * c.x + n.x * o.x + (r.x - n.x) * u.x) / g, D = -(r.x * c.y + e.x * (o.y - c.y) - n.x * o.y + (n.x - r.x) * u.y) / g, W = (e.x * (n.y * o.x - r.y * c.x) + e.y * (r.x * c.x - n.x * o.x) + (n.x * r.y - r.x * n.y) * u.x) / g, B = (e.x * (n.y * o.y - r.y * c.y) + e.y * (r.x * c.y - n.x * o.y) + (n.x * r.y - r.x * n.y) * u.y) / g;
|
|
634
|
-
s.transform(p, x, A, D, W, B), s.drawImage(t, 0, 0), s.restore();
|
|
635
1334
|
}
|
|
636
|
-
|
|
637
|
-
if (
|
|
638
|
-
|
|
1335
|
+
function Ee(t, n, e) {
|
|
1336
|
+
if (Z.length === 0) return null;
|
|
1337
|
+
try {
|
|
1338
|
+
if ((!nt || nt.width !== n || nt.height !== e) && (nt = new OffscreenCanvas(n, e), G = null, Ct = null, bt = null, vt = null), !G) {
|
|
1339
|
+
if (G = nt.getContext("webgl", {
|
|
1340
|
+
alpha: !0,
|
|
1341
|
+
premultipliedAlpha: !1,
|
|
1342
|
+
// 启用 MSAA:硬件抗锯齿,对三角形边缘、硬边图案(如网格/文字)显著改善
|
|
1343
|
+
// 现代 GPU 上开销可忽略;OffscreenCanvas + WebGL 1 默认 4x MSAA
|
|
1344
|
+
antialias: !0
|
|
1345
|
+
}), !G) return null;
|
|
1346
|
+
const a = G, y = "attribute vec2 aPos;attribute vec2 aUV;varying vec2 vUV;void main(){gl_Position=vec4(aPos,0.0,1.0);vUV=aUV;}", m = "precision highp float;uniform sampler2D uTex;varying vec2 vUV;void main(){if(vUV.x<0.0||vUV.x>1.0||vUV.y<0.0||vUV.y>1.0){gl_FragColor=vec4(0.0);return;}gl_FragColor=texture2D(uTex,vUV);}", x = (D, C) => {
|
|
1347
|
+
const F = a.createShader(D);
|
|
1348
|
+
return F ? (a.shaderSource(F, C), a.compileShader(F), a.getShaderParameter(F, a.COMPILE_STATUS) ? F : null) : null;
|
|
1349
|
+
}, E = x(a.VERTEX_SHADER, y), w = x(a.FRAGMENT_SHADER, m);
|
|
1350
|
+
if (!E || !w)
|
|
1351
|
+
return G = null, null;
|
|
1352
|
+
const M = a.createProgram();
|
|
1353
|
+
if (a.attachShader(M, E), a.attachShader(M, w), a.linkProgram(M), !a.getProgramParameter(M, a.LINK_STATUS))
|
|
1354
|
+
return G = null, null;
|
|
1355
|
+
Ct = M, bt = a.createBuffer(), vt = a.createTexture();
|
|
1356
|
+
}
|
|
1357
|
+
const r = G, s = Ct, o = "naturalWidth" in t ? t.naturalWidth : t.width, i = "naturalWidth" in t ? t.naturalHeight : t.height, u = r.getParameter(r.MAX_TEXTURE_SIZE), c = Math.min(u, Math.max(n * 2, e * 2));
|
|
1358
|
+
let l = t;
|
|
1359
|
+
if (o > c || i > c) {
|
|
1360
|
+
const a = Math.min(c / o, c / i), y = Math.max(1, Math.floor(o * a)), m = Math.max(1, Math.floor(i * a)), x = new OffscreenCanvas(y, m);
|
|
1361
|
+
x.getContext("2d").drawImage(t, 0, 0, y, m), l = x;
|
|
1362
|
+
}
|
|
1363
|
+
r.bindTexture(r.TEXTURE_2D, vt), r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL, !1), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MIN_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_MAG_FILTER, r.LINEAR), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_S, r.CLAMP_TO_EDGE), r.texParameteri(r.TEXTURE_2D, r.TEXTURE_WRAP_T, r.CLAMP_TO_EDGE), r.texImage2D(r.TEXTURE_2D, 0, r.RGBA, r.RGBA, r.UNSIGNED_BYTE, l);
|
|
1364
|
+
const f = Z.length, d = new Float32Array(f * 12), h = 1.65;
|
|
1365
|
+
for (let a = 0; a < f; a++) {
|
|
1366
|
+
const y = Z[a], m = a * 12, x = (y.p0x + y.p1x + y.p2x) / 3, E = (y.p0y + y.p1y + y.p2y) / 3, w = (y.t0x + y.t1x + y.t2x) / 3, M = (y.t0y + y.t1y + y.t2y) / 3, D = x + (y.p0x - x) * h, C = E + (y.p0y - E) * h, F = x + (y.p1x - x) * h, S = E + (y.p1y - E) * h, I = x + (y.p2x - x) * h, v = E + (y.p2y - E) * h, T = w + (y.t0x - w) * h, W = M + (y.t0y - M) * h, L = w + (y.t1x - w) * h, B = M + (y.t1y - M) * h, b = w + (y.t2x - w) * h, P = M + (y.t2y - M) * h;
|
|
1367
|
+
d[m] = D / n * 2 - 1, d[m + 1] = -(C / e * 2 - 1), d[m + 2] = T / o, d[m + 3] = W / i, d[m + 4] = F / n * 2 - 1, d[m + 5] = -(S / e * 2 - 1), d[m + 6] = L / o, d[m + 7] = B / i, d[m + 8] = I / n * 2 - 1, d[m + 9] = -(v / e * 2 - 1), d[m + 10] = b / o, d[m + 11] = P / i;
|
|
1368
|
+
}
|
|
1369
|
+
r.useProgram(s), r.bindBuffer(r.ARRAY_BUFFER, bt), r.bufferData(r.ARRAY_BUFFER, d, r.DYNAMIC_DRAW);
|
|
1370
|
+
const p = 16, A = r.getAttribLocation(s, "aPos");
|
|
1371
|
+
r.enableVertexAttribArray(A), r.vertexAttribPointer(A, 2, r.FLOAT, !1, p, 0);
|
|
1372
|
+
const g = r.getAttribLocation(s, "aUV");
|
|
1373
|
+
return r.enableVertexAttribArray(g), r.vertexAttribPointer(g, 2, r.FLOAT, !1, p, 8), r.viewport(0, 0, n, e), r.clearColor(0, 0, 0, 0), r.clear(r.COLOR_BUFFER_BIT), r.enable(r.BLEND), r.blendFuncSeparate(r.SRC_ALPHA, r.ONE_MINUS_SRC_ALPHA, r.ONE, r.ONE_MINUS_SRC_ALPHA), r.drawArrays(r.TRIANGLES, 0, f * 3), r.flush(), nt.transferToImageBitmap();
|
|
1374
|
+
} catch {
|
|
1375
|
+
return G = null, Ct = null, bt = null, vt = null, null;
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
self.onmessage = async (t) => {
|
|
1379
|
+
if (t.data?.type === "SET_DEBUG") {
|
|
1380
|
+
Bt = !!t.data?.debugRender, self.__DEBUG_RENDER__ = Bt;
|
|
639
1381
|
return;
|
|
640
1382
|
}
|
|
641
|
-
if (
|
|
642
|
-
|
|
1383
|
+
if (t.data?.type === "SET_LICENSE") {
|
|
1384
|
+
ae(t.data);
|
|
643
1385
|
return;
|
|
644
1386
|
}
|
|
645
|
-
const
|
|
1387
|
+
const n = t.data, { id: e, designBitmap: r, layerData: s, canvasSize: o } = n;
|
|
646
1388
|
if (!r) {
|
|
647
1389
|
self.postMessage({
|
|
648
1390
|
id: e,
|
|
@@ -652,7 +1394,7 @@ self.onmessage = async (s) => {
|
|
|
652
1394
|
});
|
|
653
1395
|
return;
|
|
654
1396
|
}
|
|
655
|
-
if (!
|
|
1397
|
+
if (!s) {
|
|
656
1398
|
self.postMessage({
|
|
657
1399
|
id: e,
|
|
658
1400
|
imageBitmap: null,
|
|
@@ -661,58 +1403,58 @@ self.onmessage = async (s) => {
|
|
|
661
1403
|
});
|
|
662
1404
|
return;
|
|
663
1405
|
}
|
|
664
|
-
const
|
|
665
|
-
if (
|
|
1406
|
+
const i = performance.now(), u = (/* @__PURE__ */ new Date()).toISOString();
|
|
1407
|
+
if (rt(`[deform worker] ⏰ 开始 id=${e} 时间=${u}`, {
|
|
666
1408
|
designBitmap: { width: r.width, height: r.height },
|
|
667
|
-
size:
|
|
668
|
-
bounds:
|
|
669
|
-
canvasSize:
|
|
670
|
-
}), !
|
|
671
|
-
if (
|
|
1409
|
+
size: s.size,
|
|
1410
|
+
bounds: s.bounds,
|
|
1411
|
+
canvasSize: o
|
|
1412
|
+
}), !R || !R.isReady())
|
|
1413
|
+
if (q || self.LICENSE_TOKEN)
|
|
672
1414
|
try {
|
|
673
|
-
if (
|
|
1415
|
+
if (st && H && await H, (!R || !R.isReady()) && await Nt(), !R || !R.isReady())
|
|
674
1416
|
throw new Error("WASM 模块仍未就绪");
|
|
675
|
-
} catch (
|
|
676
|
-
const
|
|
1417
|
+
} catch (l) {
|
|
1418
|
+
const d = performance.now() - i;
|
|
677
1419
|
self.postMessage({
|
|
678
1420
|
id: e,
|
|
679
|
-
error: `WASM 初始化失败: ${
|
|
680
|
-
duration:
|
|
1421
|
+
error: `WASM 初始化失败: ${l.message}`,
|
|
1422
|
+
duration: d
|
|
681
1423
|
});
|
|
682
1424
|
return;
|
|
683
1425
|
}
|
|
684
1426
|
else {
|
|
685
|
-
let
|
|
686
|
-
const
|
|
1427
|
+
let l = 0;
|
|
1428
|
+
const f = 500, d = 50;
|
|
687
1429
|
let h = null;
|
|
688
|
-
for (;
|
|
689
|
-
await new Promise((
|
|
1430
|
+
for (; l < f && !h; )
|
|
1431
|
+
await new Promise((p) => setTimeout(p, d)), l += d, h = q || self.LICENSE_TOKEN;
|
|
690
1432
|
if (h)
|
|
691
1433
|
try {
|
|
692
|
-
if (
|
|
1434
|
+
if (q = h, lt = lt || self.LICENSE_API_URL, ht = ht || self.DEVICE_ID, ft = ft || self.DOMAIN, st && H ? await H : R || await Nt(), !R || !R.isReady())
|
|
693
1435
|
throw new Error("WASM 模块未就绪");
|
|
694
|
-
} catch (
|
|
695
|
-
const
|
|
1436
|
+
} catch (p) {
|
|
1437
|
+
const g = performance.now() - i;
|
|
696
1438
|
self.postMessage({
|
|
697
1439
|
id: e,
|
|
698
|
-
error: `WASM 初始化失败: ${
|
|
699
|
-
duration:
|
|
1440
|
+
error: `WASM 初始化失败: ${p.message}`,
|
|
1441
|
+
duration: g
|
|
700
1442
|
});
|
|
701
1443
|
return;
|
|
702
1444
|
}
|
|
703
1445
|
else if (!h) {
|
|
704
|
-
const
|
|
1446
|
+
const A = performance.now() - i;
|
|
705
1447
|
self.postMessage({
|
|
706
1448
|
id: e,
|
|
707
1449
|
error: "LICENSE_TOKEN 未设置,无法使用 WASM 功能",
|
|
708
|
-
duration:
|
|
1450
|
+
duration: A
|
|
709
1451
|
});
|
|
710
1452
|
return;
|
|
711
1453
|
}
|
|
712
1454
|
}
|
|
713
1455
|
try {
|
|
714
|
-
const
|
|
715
|
-
if (!
|
|
1456
|
+
const c = s.bounds;
|
|
1457
|
+
if (!c || !c.width || !c.height) {
|
|
716
1458
|
self.postMessage({
|
|
717
1459
|
id: e,
|
|
718
1460
|
imageBitmap: null,
|
|
@@ -721,40 +1463,42 @@ self.onmessage = async (s) => {
|
|
|
721
1463
|
});
|
|
722
1464
|
return;
|
|
723
1465
|
}
|
|
724
|
-
const
|
|
725
|
-
let
|
|
726
|
-
if (
|
|
727
|
-
|
|
1466
|
+
const l = le(s, o);
|
|
1467
|
+
let f, d;
|
|
1468
|
+
if (o && o.width > 0 && o.height > 0)
|
|
1469
|
+
f = o.width, d = o.height;
|
|
728
1470
|
else {
|
|
729
|
-
const
|
|
730
|
-
width:
|
|
731
|
-
height:
|
|
1471
|
+
const E = s.size || s.placedLayer || {
|
|
1472
|
+
width: c.width,
|
|
1473
|
+
height: c.height
|
|
732
1474
|
};
|
|
733
|
-
|
|
1475
|
+
f = E.width, d = E.height;
|
|
734
1476
|
}
|
|
735
|
-
const h = new OffscreenCanvas(
|
|
736
|
-
if (!
|
|
737
|
-
const
|
|
738
|
-
self.postMessage({ id: e, error: "Canvas context unavailable", duration:
|
|
1477
|
+
const h = new OffscreenCanvas(f, d), p = h.getContext("2d");
|
|
1478
|
+
if (!p) {
|
|
1479
|
+
const w = performance.now() - i;
|
|
1480
|
+
self.postMessage({ id: e, error: "Canvas context unavailable", duration: w });
|
|
739
1481
|
return;
|
|
740
1482
|
}
|
|
741
|
-
const
|
|
742
|
-
|
|
743
|
-
|
|
1483
|
+
const A = fe(p, r, l), g = Ot ?? h.transferToImageBitmap();
|
|
1484
|
+
Ot = null;
|
|
1485
|
+
const y = performance.now() - i, m = (/* @__PURE__ */ new Date()).toISOString();
|
|
1486
|
+
rt(
|
|
1487
|
+
`[deform worker] ✅ 结束 id=${e} 时间=${m} 耗时=${Math.round(y)}ms 变形方法=${A}`,
|
|
744
1488
|
{
|
|
745
|
-
width:
|
|
746
|
-
height:
|
|
1489
|
+
width: g.width,
|
|
1490
|
+
height: g.height
|
|
747
1491
|
}
|
|
748
1492
|
), r.close();
|
|
749
|
-
const
|
|
750
|
-
{ id: e, imageBitmap:
|
|
1493
|
+
const x = he(
|
|
1494
|
+
{ id: e, imageBitmap: g, duration: y }
|
|
751
1495
|
);
|
|
752
1496
|
self.postMessage(
|
|
753
|
-
|
|
754
|
-
|
|
1497
|
+
x,
|
|
1498
|
+
x.imageBitmap ? [x.imageBitmap] : []
|
|
755
1499
|
);
|
|
756
|
-
} catch (
|
|
757
|
-
const
|
|
758
|
-
(/* @__PURE__ */ new Date()).toISOString(), self.postMessage({ id: e, error:
|
|
1500
|
+
} catch (c) {
|
|
1501
|
+
const f = performance.now() - i, d = c instanceof Error ? c.message : String(c);
|
|
1502
|
+
(/* @__PURE__ */ new Date()).toISOString(), self.postMessage({ id: e, error: d, duration: f });
|
|
759
1503
|
}
|
|
760
1504
|
};
|