@jieyin/editor-sdk 1.1.113

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