@snowcone-app/canvas 0.40.9 → 0.40.10
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/{CanvasRenderer-COO5UXtZ.js → CanvasRenderer-BuZVwUch.js} +2 -2
- package/dist/{CanvasRenderer-COO5UXtZ.js.map → CanvasRenderer-BuZVwUch.js.map} +1 -1
- package/dist/{CanvasStateV1-V8l7-6PC.js → CanvasStateV1-D-ki3MtP.js} +2 -2
- package/dist/{CanvasStateV1-V8l7-6PC.js.map → CanvasStateV1-D-ki3MtP.js.map} +1 -1
- package/dist/{ContextualToolbars-_5zqlcSw.js → ContextualToolbars-Cy91bYY9.js} +4 -4
- package/dist/{ContextualToolbars-_5zqlcSw.js.map → ContextualToolbars-Cy91bYY9.js.map} +1 -1
- package/dist/{EditorCanvasImpl-EZu_ZNRj.js → EditorCanvasImpl-C8tvgEh8.js} +6 -6
- package/dist/{EditorCanvasImpl-EZu_ZNRj.js.map → EditorCanvasImpl-C8tvgEh8.js.map} +1 -1
- package/dist/ExportManager-B_7SG-Ox.js +3640 -0
- package/dist/ExportManager-B_7SG-Ox.js.map +1 -0
- package/dist/{ImagePanel-BaX0UE-L.js → ImagePanel-CJJzUQWY.js} +3 -3
- package/dist/{ImagePanel-BaX0UE-L.js.map → ImagePanel-CJJzUQWY.js.map} +1 -1
- package/dist/{SnowconeCanvas-uUJy5mxC.js → SnowconeCanvas-BfxMwXO9.js} +8 -8
- package/dist/{SnowconeCanvas-uUJy5mxC.js.map → SnowconeCanvas-BfxMwXO9.js.map} +1 -1
- package/dist/advanced.mjs +9 -9
- package/dist/{custom-icons-o1U13Vcg.js → custom-icons-sebOL9Xd.js} +2 -2
- package/dist/{custom-icons-o1U13Vcg.js.map → custom-icons-sebOL9Xd.js.map} +1 -1
- package/dist/{embed-BkKsYOQt.js → embed-DO1jibk2.js} +7 -7
- package/dist/{embed-BkKsYOQt.js.map → embed-DO1jibk2.js.map} +1 -1
- package/dist/embed.mjs +5 -5
- package/dist/{ExportManager-BbBfO22S.js → export-worker.bundle.string-DXciOLDt.js} +3 -3618
- package/dist/export-worker.bundle.string-DXciOLDt.js.map +1 -0
- package/dist/index.mjs +7 -7
- package/dist/internals.mjs +4 -4
- package/dist/{template-fields-DaLRAR5W.js → template-fields-DwmObbeX.js} +3 -3
- package/dist/{template-fields-DaLRAR5W.js.map → template-fields-DwmObbeX.js.map} +1 -1
- package/dist/{useCommands-x8J7_Mzy.js → useCommands-f-UTuBI1.js} +5 -5
- package/dist/{useCommands-x8J7_Mzy.js.map → useCommands-f-UTuBI1.js.map} +1 -1
- package/dist/utils/WorkerExportManager.d.ts +9 -0
- package/dist/{validation-BMB6_hp4.js → validation-B5eH5mzI.js} +9 -9
- package/dist/{validation-BMB6_hp4.js.map → validation-B5eH5mzI.js.map} +1 -1
- package/example/package.json +1 -1
- package/package.json +2 -2
- package/dist/ExportManager-BbBfO22S.js.map +0 -1
|
@@ -0,0 +1,3640 @@
|
|
|
1
|
+
import { c as j, G as ve, ac as Ye, aO as Ve, aa as Je, ag as Ee, aP as Gt, ae as Ke, ab as x, s as Qe, w as ze, ad as at, af as Yt, x as Dt, at as Ze, ah as De, aQ as J, aR as xe, b as tr, aS as Tt, aT as Se, P as er, S as rr, I as At, F as nr, W as or, f as sr, d as ar, L as ir, C as lr, g as cr, A as xt, i as hr, t as Me } from "./FontAnalyzer-DWHS41ba.js";
|
|
2
|
+
let Ce = null;
|
|
3
|
+
function fr(e) {
|
|
4
|
+
Ce = e;
|
|
5
|
+
}
|
|
6
|
+
function Xn() {
|
|
7
|
+
return Ce;
|
|
8
|
+
}
|
|
9
|
+
const dr = j("TextureManager"), lt = class lt {
|
|
10
|
+
/**
|
|
11
|
+
* Load a texture by ID or URL
|
|
12
|
+
*/
|
|
13
|
+
static async loadTexture(t) {
|
|
14
|
+
if (this.cache.has(t))
|
|
15
|
+
return this.cache.get(t);
|
|
16
|
+
if (this.loading.has(t))
|
|
17
|
+
return this.loading.get(t);
|
|
18
|
+
const r = this.resolveTextureUrl(t), n = new Promise((o, i) => {
|
|
19
|
+
const s = new Image();
|
|
20
|
+
s.crossOrigin = "anonymous", s.onload = () => {
|
|
21
|
+
this.cache.set(t, s), this.cache.set(r, s), this.loading.delete(t), this.loading.delete(r), o(s);
|
|
22
|
+
}, s.onerror = () => {
|
|
23
|
+
dr.error("Failed to load texture:", r), this.loading.delete(t), this.loading.delete(r), i(new Error(`Failed to load texture: ${r}`));
|
|
24
|
+
}, s.src = r;
|
|
25
|
+
});
|
|
26
|
+
return this.loading.set(t, n), r !== t && this.loading.set(r, n), n;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get a texture synchronously (returns null if not loaded)
|
|
30
|
+
*/
|
|
31
|
+
static getTexture(t) {
|
|
32
|
+
const r = this.resolveTextureUrl(t);
|
|
33
|
+
return this.cache.get(t) || this.cache.get(r) || null;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Preload multiple textures
|
|
37
|
+
*/
|
|
38
|
+
static async preloadTextures(t) {
|
|
39
|
+
await Promise.all(t.map((r) => this.loadTexture(r)));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Preload all built-in textures
|
|
43
|
+
*/
|
|
44
|
+
static async preloadAllTextures() {
|
|
45
|
+
await this.preloadTextures(this.TEXTURES.map((t) => t.id));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Clear cache
|
|
49
|
+
*/
|
|
50
|
+
static clearCache() {
|
|
51
|
+
this.cache.clear(), this.loading.clear();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Resolve texture URL from ID
|
|
55
|
+
*/
|
|
56
|
+
static resolveTextureUrl(t) {
|
|
57
|
+
if (t.startsWith("http://") || t.startsWith("https://") || t.startsWith("/") || t.startsWith("data:"))
|
|
58
|
+
return t;
|
|
59
|
+
const r = this.TEXTURES.find((n) => n.id === t);
|
|
60
|
+
return r ? r.url : `/textures/${t}`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Get texture info by ID
|
|
64
|
+
*/
|
|
65
|
+
static getTextureInfo(t) {
|
|
66
|
+
return this.TEXTURES.find((r) => r.id === t);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get all available textures
|
|
70
|
+
*/
|
|
71
|
+
static getAllTextures() {
|
|
72
|
+
return [...this.TEXTURES];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get textures by category
|
|
76
|
+
*/
|
|
77
|
+
static getTexturesByCategory(t) {
|
|
78
|
+
return this.TEXTURES.filter((r) => r.category === t);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get preset color for a texture
|
|
82
|
+
* Each texture has a fixed color that's part of its preset
|
|
83
|
+
*/
|
|
84
|
+
static getTexturePresetColor(t) {
|
|
85
|
+
const r = this.TEXTURES.find((n) => n.id === t);
|
|
86
|
+
return (r == null ? void 0 : r.presetColor) || "#ffffff";
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
lt.cache = /* @__PURE__ */ new Map(), lt.loading = /* @__PURE__ */ new Map(), lt.TEXTURES = [
|
|
90
|
+
{
|
|
91
|
+
id: "glass-frame",
|
|
92
|
+
name: "Glass Frame",
|
|
93
|
+
url: "/textures/glass-frame.svg",
|
|
94
|
+
category: "glass",
|
|
95
|
+
presetColor: "#ccc"
|
|
96
|
+
// Light gray
|
|
97
|
+
}
|
|
98
|
+
];
|
|
99
|
+
let D = lt;
|
|
100
|
+
const ur = j("ElementPreviewRenderer"), gr = {
|
|
101
|
+
width: 40,
|
|
102
|
+
height: 40,
|
|
103
|
+
padding: 4,
|
|
104
|
+
backgroundColor: "transparent"
|
|
105
|
+
};
|
|
106
|
+
function pr(e, t = {}) {
|
|
107
|
+
Jt();
|
|
108
|
+
const r = { ...gr, ...t }, n = document.createElement("canvas");
|
|
109
|
+
n.width = r.width, n.height = r.height;
|
|
110
|
+
const o = n.getContext("2d");
|
|
111
|
+
if (!o)
|
|
112
|
+
return "";
|
|
113
|
+
r.backgroundColor !== "transparent" && (o.fillStyle = r.backgroundColor, o.fillRect(0, 0, r.width, r.height)), o.save();
|
|
114
|
+
try {
|
|
115
|
+
e instanceof ve ? yr(o, e, r) : mr(o, e, r);
|
|
116
|
+
} catch (i) {
|
|
117
|
+
ur.warn("Failed to generate preview:", i);
|
|
118
|
+
}
|
|
119
|
+
return o.restore(), n.toDataURL("image/png");
|
|
120
|
+
}
|
|
121
|
+
function mr(e, t, r) {
|
|
122
|
+
var f;
|
|
123
|
+
const n = ((f = t.getBoundingBox) == null ? void 0 : f.call(t)) || { x: 0, y: 0, width: 100, height: 100 }, o = n.width, i = n.height;
|
|
124
|
+
if (o === 0 || i === 0) {
|
|
125
|
+
te(e, t, r);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const s = r.width - r.padding * 2, l = r.height - r.padding * 2, a = Math.min(
|
|
129
|
+
s / o,
|
|
130
|
+
l / i,
|
|
131
|
+
1
|
|
132
|
+
// Don't scale up, only down
|
|
133
|
+
), c = o * a, h = i * a, d = r.padding + (s - c) / 2, u = r.padding + (l - h) / 2;
|
|
134
|
+
e.save(), e.translate(d - n.x * a, u - n.y * a), e.scale(a, a), typeof t.render == "function" ? t.render(e, !1, !1) : te(e, t, r), e.restore();
|
|
135
|
+
}
|
|
136
|
+
function te(e, t, r) {
|
|
137
|
+
e.fillStyle = "#888888", e.font = "10px Arial", e.textAlign = "center", e.textBaseline = "middle";
|
|
138
|
+
const n = t.transformType || "Element";
|
|
139
|
+
e.fillText(n, r.width / 2, r.height / 2);
|
|
140
|
+
}
|
|
141
|
+
function yr(e, t, r) {
|
|
142
|
+
const n = r.width - r.padding * 2, o = r.height - r.padding * 2, i = r.padding, s = r.padding;
|
|
143
|
+
e.fillStyle = "#888888", e.strokeStyle = "#666666", e.lineWidth = 1;
|
|
144
|
+
const l = o * 0.7, a = s + o * 0.3, c = n * 0.4, h = o * 0.2;
|
|
145
|
+
e.fillRect(i, a, n, l), e.fillRect(i, a - h, c, h), t.children && t.children.length > 0 && (e.fillStyle = "#FFFFFF", e.font = "bold 10px Arial", e.textAlign = "center", e.textBaseline = "middle", e.fillText(
|
|
146
|
+
t.children.length.toString(),
|
|
147
|
+
i + n / 2,
|
|
148
|
+
a + l / 2
|
|
149
|
+
));
|
|
150
|
+
}
|
|
151
|
+
function _n(e, t, r) {
|
|
152
|
+
var c;
|
|
153
|
+
e.translate(t.x || 0, t.y || 0), e.rotate(-(t.rotation || 0) * Math.PI / 180);
|
|
154
|
+
const n = t, o = n.fontSize || 24, i = n.fontFamily || "Arial", s = n.bold || !1, l = n.italic || !1;
|
|
155
|
+
e.font = Ye(o, i, s, l);
|
|
156
|
+
const a = n.text || "";
|
|
157
|
+
if (t.transformType === "custom") {
|
|
158
|
+
const d = ((c = t.transformData) == null ? void 0 : c.width) || 200, u = Ve(a, o, i, s, l), f = Math.min(u, d), k = o * 1.2;
|
|
159
|
+
e.rect(-f / 2, -k / 2, f, k);
|
|
160
|
+
} else {
|
|
161
|
+
const h = e.measureText(a).width;
|
|
162
|
+
e.beginPath(), e.moveTo(-h / 2, 0), e.lineTo(h / 2, 0), e.moveTo(-h / 2, -o), e.lineTo(h / 2, -o), e.moveTo(-h / 2, o * 0.2), e.lineTo(h / 2, o * 0.2);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function wr(e, t) {
|
|
166
|
+
if (!t.transformData) return;
|
|
167
|
+
const { borderRadius: r = 0 } = t.transformData, n = t.transformData.width ?? 100, o = t.transformData.height ?? 100;
|
|
168
|
+
if (e.translate(t.x || 0, t.y || 0), e.rotate(-(t.rotation || 0) * Math.PI / 180), e.beginPath(), r > 0) {
|
|
169
|
+
const i = Math.min(n, o) / 2, s = Math.min(r, i), l = -n / 2, a = -o / 2;
|
|
170
|
+
e.moveTo(l + s, a), e.lineTo(l + n - s, a), e.arcTo(l + n, a, l + n, a + s, s), e.lineTo(l + n, a + o - s), e.arcTo(l + n, a + o, l + n - s, a + o, s), e.lineTo(l + s, a + o), e.arcTo(l, a + o, l, a + o - s, s), e.lineTo(l, a + s), e.arcTo(l, a, l + s, a, s), e.closePath();
|
|
171
|
+
} else
|
|
172
|
+
e.rect(-n / 2, -o / 2, n, o);
|
|
173
|
+
}
|
|
174
|
+
function Gn(e, t, r, n) {
|
|
175
|
+
e.beginPath(), e.arc(t, r, n, 0, Math.PI * 2), e.closePath();
|
|
176
|
+
}
|
|
177
|
+
function Yn(e, t, r, n, o) {
|
|
178
|
+
e.beginPath(), e.rect(t, r, n, o), e.closePath();
|
|
179
|
+
}
|
|
180
|
+
function Pe(e, t) {
|
|
181
|
+
e.strokeStyle = t.color, e.lineWidth = t.width, e.lineCap = t.lineCap || "butt", e.lineJoin = t.lineJoin || "miter", t.miterLimit !== void 0 && (e.miterLimit = t.miterLimit), t.dashArray && t.dashArray.length > 0 ? e.setLineDash(t.dashArray) : e.setLineDash([]), t.opacity !== void 0 && (e.globalAlpha = t.opacity);
|
|
182
|
+
}
|
|
183
|
+
function kr(e, t) {
|
|
184
|
+
if (typeof OffscreenCanvas < "u")
|
|
185
|
+
return new OffscreenCanvas(e, t);
|
|
186
|
+
const r = document.createElement("canvas");
|
|
187
|
+
return r.width = e, r.height = t, r;
|
|
188
|
+
}
|
|
189
|
+
function Ie(e, t, r) {
|
|
190
|
+
var a;
|
|
191
|
+
if (!((a = t.stroke) != null && a.enabled)) return;
|
|
192
|
+
const n = t;
|
|
193
|
+
if (!(n.text || "")) return;
|
|
194
|
+
const i = (r == null ? void 0 : r.isKnockout) === !0, s = t.stroke.opacity ?? 1;
|
|
195
|
+
if (!i && s < 1)
|
|
196
|
+
try {
|
|
197
|
+
br(e, t, n, r, s);
|
|
198
|
+
} catch {
|
|
199
|
+
it(e, t, n, r, !1);
|
|
200
|
+
}
|
|
201
|
+
else
|
|
202
|
+
it(e, t, n, r, i);
|
|
203
|
+
}
|
|
204
|
+
function br(e, t, r, n, o) {
|
|
205
|
+
var M, P;
|
|
206
|
+
const i = r.text || "", s = r.fontSize || 24, l = t.stroke.width, a = t.stroke.feather || 0, c = t.transformType === "custom" && ((M = t.transformData) == null ? void 0 : M.width), h = c ? ((P = t.transformData) == null ? void 0 : P.width) ?? 200 : 0, d = c ? h + l * 2 + a * 2 + 40 : s * i.length * 0.7 + l * 2 + a * 2 + 40, u = s * 3 + l * 2 + a * 2 + 40, f = e.getTransform(), k = Math.max(Math.abs(f.a), Math.abs(f.d), 1), g = Math.ceil(d * k / 2) * 2, m = Math.ceil(u * k / 2) * 2;
|
|
207
|
+
if (g <= 0 || m <= 0) {
|
|
208
|
+
it(e, t, r, n, !1);
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const T = kr(g, m), w = T.getContext("2d");
|
|
212
|
+
if (!w) {
|
|
213
|
+
it(e, t, r, n, !1);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const b = t.x || 0, y = t.y || 0, p = f.a * b + f.c * y + f.e, S = f.b * b + f.d * y + f.f;
|
|
217
|
+
w.setTransform(
|
|
218
|
+
f.a,
|
|
219
|
+
f.b,
|
|
220
|
+
f.c,
|
|
221
|
+
f.d,
|
|
222
|
+
g / 2 - p + f.e,
|
|
223
|
+
m / 2 - S + f.f
|
|
224
|
+
);
|
|
225
|
+
const C = t.stroke.opacity;
|
|
226
|
+
t.stroke.opacity = 1, it(w, t, r, n, !1), t.stroke.opacity = C, e.save(), e.resetTransform(), e.globalAlpha = o, e.drawImage(
|
|
227
|
+
T,
|
|
228
|
+
Math.round(p - g / 2),
|
|
229
|
+
Math.round(S - m / 2)
|
|
230
|
+
), e.restore();
|
|
231
|
+
}
|
|
232
|
+
function it(e, t, r, n, o) {
|
|
233
|
+
var f;
|
|
234
|
+
const i = r.text || "";
|
|
235
|
+
e.save(), n != null && n.positionApplied || (e.translate(t.x || 0, t.y || 0), e.rotate(-(t.rotation || 0) * Math.PI / 180));
|
|
236
|
+
const s = r.fontSize || 24, l = r.fontFamily || "Arial", a = r.bold || !1, c = r.italic || !1, h = r.textAlign || "center";
|
|
237
|
+
e.font = `${c ? "italic " : ""}${a ? "bold " : ""}${s}px ${l}`, e.textAlign = h, e.textBaseline = "alphabetic", o ? (e.strokeStyle = "#000000", e.globalAlpha = 1) : (e.strokeStyle = t.stroke.color, t.stroke.opacity !== void 0 && (e.globalAlpha = t.stroke.opacity)), e.lineWidth = t.stroke.width, e.lineCap = t.stroke.lineCap || "round", e.lineJoin = t.stroke.lineJoin || "round", t.stroke.miterLimit !== void 0 && (e.miterLimit = t.stroke.miterLimit), !o && t.stroke.feather && t.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${t.stroke.feather}px)`);
|
|
238
|
+
const d = Je(s, l, a, c);
|
|
239
|
+
if (t.transformType === "custom" && ((f = t.transformData) == null ? void 0 : f.width)) {
|
|
240
|
+
const k = t.transformData, g = (k == null ? void 0 : k.width) ?? 200, m = g - x * 2, T = r.letterSpacing ?? 0, { lines: w, height: b } = Ee(
|
|
241
|
+
i,
|
|
242
|
+
m,
|
|
243
|
+
s,
|
|
244
|
+
l,
|
|
245
|
+
a,
|
|
246
|
+
c,
|
|
247
|
+
void 0,
|
|
248
|
+
// No locked line count for stroke
|
|
249
|
+
!0,
|
|
250
|
+
// strict: wrap exactly at maxWidth
|
|
251
|
+
{ letterSpacing: T, lineHeight: r.lineHeight }
|
|
252
|
+
), y = -g / 2, p = -b / 2, S = s * (r.lineHeight ?? Gt);
|
|
253
|
+
w.forEach((C, M) => {
|
|
254
|
+
const P = M === 0, v = M === w.length - 1;
|
|
255
|
+
let A = C;
|
|
256
|
+
if (!P) {
|
|
257
|
+
const R = C.match(/^ +/), W = R ? R[0].length : 0;
|
|
258
|
+
W > 0 && (A = A.substring(W));
|
|
259
|
+
}
|
|
260
|
+
if (!v) {
|
|
261
|
+
const R = A.match(/ +$/), W = R ? R[0].length : 0;
|
|
262
|
+
W > 0 && (A = A.substring(0, A.length - W));
|
|
263
|
+
}
|
|
264
|
+
let I = y + x;
|
|
265
|
+
h === "center" ? I = y + g / 2 : h === "right" && (I = y + g - x);
|
|
266
|
+
const E = p + d.ascent + M * S;
|
|
267
|
+
Ke(e, A, I, E, T);
|
|
268
|
+
});
|
|
269
|
+
} else {
|
|
270
|
+
const m = -d.height / 2 + d.ascent;
|
|
271
|
+
e.strokeText(i, 0, m);
|
|
272
|
+
}
|
|
273
|
+
e.restore();
|
|
274
|
+
}
|
|
275
|
+
function Tr(e, t, r) {
|
|
276
|
+
var o;
|
|
277
|
+
if (!((o = t.stroke) != null && o.enabled) || !t.transformData) return;
|
|
278
|
+
const n = (r == null ? void 0 : r.isKnockout) === !0;
|
|
279
|
+
e.save(), n ? (e.strokeStyle = "#000000", e.lineWidth = t.stroke.width, e.lineCap = t.stroke.lineCap || "butt", e.lineJoin = t.stroke.lineJoin || "miter", e.globalAlpha = 1, t.stroke.miterLimit !== void 0 && (e.miterLimit = t.stroke.miterLimit)) : Pe(e, t.stroke), !n && t.stroke.feather && t.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${t.stroke.feather}px)`), wr(e, t), e.stroke(), e.restore();
|
|
280
|
+
}
|
|
281
|
+
function Vn(e, t, r) {
|
|
282
|
+
t.enabled && (e.save(), Pe(e, t), t.feather && t.feather > 0 && "filter" in e && (e.filter = `blur(${t.feather}px)`), e.beginPath(), r(), e.stroke(), e.restore());
|
|
283
|
+
}
|
|
284
|
+
const ee = j("GlyphRenderer");
|
|
285
|
+
function vr(e, t, r, n, o, i, s, l = {}) {
|
|
286
|
+
try {
|
|
287
|
+
const a = [];
|
|
288
|
+
Object.entries(s).forEach(([m, T]) => {
|
|
289
|
+
T && a.push(m);
|
|
290
|
+
});
|
|
291
|
+
const c = [];
|
|
292
|
+
t.GSUB && t.GSUB.featureList && t.GSUB.featureList.forEach((m) => {
|
|
293
|
+
c.push(m.tag);
|
|
294
|
+
});
|
|
295
|
+
const h = {};
|
|
296
|
+
h.ccmp = !0, h.locl = !0, h.kern = !0, a.forEach((m) => {
|
|
297
|
+
h[m] = !0;
|
|
298
|
+
}), h.calt && (h.liga = !0, h.init = !0, h.fina = !0);
|
|
299
|
+
const d = t.layout(r, h, "latn"), u = i / t.unitsPerEm;
|
|
300
|
+
let f = 0;
|
|
301
|
+
d.glyphs.forEach((m) => {
|
|
302
|
+
f += m.advanceWidth * u;
|
|
303
|
+
});
|
|
304
|
+
let k = n;
|
|
305
|
+
l.align === "center" ? k = n - f / 2 : l.align === "right" && (k = n - f), e.save(), e.fillStyle = l.color || "#000000";
|
|
306
|
+
let g = k;
|
|
307
|
+
d.glyphs.forEach((m, T) => {
|
|
308
|
+
const w = d.positions[T];
|
|
309
|
+
let b = null;
|
|
310
|
+
try {
|
|
311
|
+
if (m.path && typeof m.path.toPath == "function")
|
|
312
|
+
b = m.path.toPath();
|
|
313
|
+
else if (m.path && typeof m.path.toSVG == "function") {
|
|
314
|
+
const y = m.path.toSVG();
|
|
315
|
+
if (y && /^[MmLlHhVvCcSsQqTtAaZz]/.test(y))
|
|
316
|
+
b = y;
|
|
317
|
+
else {
|
|
318
|
+
const p = y == null ? void 0 : y.match(/\bd=["']([^"']+)["']/);
|
|
319
|
+
b = p ? p[1] : null;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
} catch (y) {
|
|
323
|
+
ee.warn("Error getting path for glyph:", m.name, y);
|
|
324
|
+
}
|
|
325
|
+
if (b) {
|
|
326
|
+
const y = new Path2D(b);
|
|
327
|
+
e.save(), e.translate(g + w.xOffset * u, o + w.yOffset * u), e.scale(u, -u), e.fill(y), e.restore();
|
|
328
|
+
}
|
|
329
|
+
g += m.advanceWidth * u;
|
|
330
|
+
}), e.restore();
|
|
331
|
+
} catch (a) {
|
|
332
|
+
ee.error("Error rendering with fontkit:", a), e.fillStyle = l.color || "#000000", e.textAlign = l.align || "left", e.fillText(r, n, o);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
function Er(e, t, r, n, o, i, s, l = {}) {
|
|
336
|
+
const c = ((m) => {
|
|
337
|
+
for (const T of m) {
|
|
338
|
+
const w = T.codePointAt(0);
|
|
339
|
+
if (w && w >= 983040 && w <= 1048573) return !0;
|
|
340
|
+
}
|
|
341
|
+
return !1;
|
|
342
|
+
})(r);
|
|
343
|
+
if ((!s || s.length === 0) && !c) {
|
|
344
|
+
e.fillStyle = l.color || "#000000", e.textAlign = l.align || "left", e.fillText(r, n, o);
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const h = /* @__PURE__ */ new Map();
|
|
348
|
+
s && s.forEach((m) => {
|
|
349
|
+
h.set(m.charIndex, m.glyphIndex);
|
|
350
|
+
});
|
|
351
|
+
const d = i / t.unitsPerEm, u = Array.from(r);
|
|
352
|
+
let f = 0;
|
|
353
|
+
u.forEach((m, T) => {
|
|
354
|
+
const w = m.codePointAt(0) || 0;
|
|
355
|
+
let b;
|
|
356
|
+
if (w >= 983040 && w <= 1048573)
|
|
357
|
+
b = w - 983040;
|
|
358
|
+
else if (b = h.get(T), b === void 0) {
|
|
359
|
+
const p = t.glyphForCodePoint(w);
|
|
360
|
+
b = p ? p.id : 0;
|
|
361
|
+
}
|
|
362
|
+
const y = t.getGlyph(b);
|
|
363
|
+
y && (f += y.advanceWidth * d);
|
|
364
|
+
});
|
|
365
|
+
let k = n;
|
|
366
|
+
l.align === "center" ? k = n - f / 2 : l.align === "right" && (k = n - f), e.save(), e.fillStyle = l.color || "#000000";
|
|
367
|
+
let g = k;
|
|
368
|
+
u.forEach((m, T) => {
|
|
369
|
+
const w = m.codePointAt(0) || 0;
|
|
370
|
+
let b;
|
|
371
|
+
if (w >= 983040 && w <= 1048573)
|
|
372
|
+
b = w - 983040;
|
|
373
|
+
else if (b = h.get(T), b === void 0) {
|
|
374
|
+
const p = t.glyphForCodePoint(w);
|
|
375
|
+
b = p ? p.id : 0;
|
|
376
|
+
}
|
|
377
|
+
const y = t.getGlyph(b);
|
|
378
|
+
if (y) {
|
|
379
|
+
const p = y.path.toSVG();
|
|
380
|
+
if (p) {
|
|
381
|
+
const S = new Path2D(p);
|
|
382
|
+
e.save(), e.translate(g, o), e.scale(d, -d), e.fill(S), e.restore();
|
|
383
|
+
}
|
|
384
|
+
g += y.advanceWidth * d;
|
|
385
|
+
}
|
|
386
|
+
}), e.restore();
|
|
387
|
+
}
|
|
388
|
+
function Sr(e, t, r, n, o) {
|
|
389
|
+
e.fillStyle = r.color;
|
|
390
|
+
const i = r.textAlign || "center", s = (g) => g.letterSpacing !== void 0 ? g.letterSpacing : r.letterSpacing ?? 0, l = Qe(t);
|
|
391
|
+
let a, c;
|
|
392
|
+
n !== void 0 && n > 0 && !o ? (a = [], c = [], l.forEach((g) => {
|
|
393
|
+
const m = ze(g, n, r);
|
|
394
|
+
m.forEach((T, w) => {
|
|
395
|
+
a.push(T), c.push({
|
|
396
|
+
isParagraphStart: w === 0,
|
|
397
|
+
isParagraphEnd: w === m.length - 1
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
})) : (a = l, c = l.map(() => ({
|
|
401
|
+
isParagraphStart: !0,
|
|
402
|
+
isParagraphEnd: !0
|
|
403
|
+
})));
|
|
404
|
+
const h = [];
|
|
405
|
+
a.forEach((g, m) => {
|
|
406
|
+
const T = [];
|
|
407
|
+
let w = 0, b = 0;
|
|
408
|
+
const y = c[m].isParagraphStart, p = c[m].isParagraphEnd;
|
|
409
|
+
g.forEach((E) => {
|
|
410
|
+
const R = E.style.fontSize !== void 0 ? E.style.fontSize : r.fontSize, W = E.style.fontFamily !== void 0 ? E.style.fontFamily : r.fontFamily, F = E.style.bold !== void 0 ? E.style.bold : r.bold || !1, B = E.style.italic !== void 0 ? E.style.italic : r.italic || !1;
|
|
411
|
+
e.font = q(R, W, F, B);
|
|
412
|
+
const U = at(e.measureText(E.text).width, E.text, s(E.style));
|
|
413
|
+
T.push(U);
|
|
414
|
+
const $ = ht(R, W, F, B);
|
|
415
|
+
w = Math.max(w, $.height), b = Math.max(b, $.ascent);
|
|
416
|
+
});
|
|
417
|
+
const S = g.map((E) => E.text).join(""), C = S.match(/^ +/), M = S.match(/ +$/), P = C ? C[0].length : 0, v = M ? M[0].length : 0;
|
|
418
|
+
let A = 0, I = 0;
|
|
419
|
+
g.forEach((E) => {
|
|
420
|
+
const R = E.style.fontSize !== void 0 ? E.style.fontSize : r.fontSize, W = E.style.fontFamily !== void 0 ? E.style.fontFamily : r.fontFamily, F = E.style.bold !== void 0 ? E.style.bold : r.bold || !1, B = E.style.italic !== void 0 ? E.style.italic : r.italic || !1;
|
|
421
|
+
let U = E.text;
|
|
422
|
+
const $ = I, St = I + E.text.length;
|
|
423
|
+
if (!y && P > 0 && $ < P) {
|
|
424
|
+
const L = Math.min(P - $, E.text.length);
|
|
425
|
+
U = U.substring(L);
|
|
426
|
+
}
|
|
427
|
+
if (!p && v > 0) {
|
|
428
|
+
const L = S.length - v;
|
|
429
|
+
if (St > L) {
|
|
430
|
+
const G = !y && P > 0 && $ < P ? Math.min(P - $, E.text.length) : 0, Mt = Math.max(0, L - $ - G);
|
|
431
|
+
U = U.substring(0, Mt);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
I += E.text.length, U.length > 0 && (e.save(), e.font = q(R, W, F, B), A += at(
|
|
435
|
+
e.measureText(U).width,
|
|
436
|
+
U,
|
|
437
|
+
s(E.style)
|
|
438
|
+
), e.restore());
|
|
439
|
+
}), h.push({
|
|
440
|
+
spans: g,
|
|
441
|
+
width: A,
|
|
442
|
+
// Use adjusted width for alignment (may be 0 for empty lines)
|
|
443
|
+
height: w,
|
|
444
|
+
ascent: b,
|
|
445
|
+
spanWidths: T,
|
|
446
|
+
isParagraphStart: y,
|
|
447
|
+
// Store metadata with line
|
|
448
|
+
isParagraphEnd: p
|
|
449
|
+
});
|
|
450
|
+
});
|
|
451
|
+
const d = ht(r.fontSize, r.fontFamily, r.bold, r.italic), u = r.fontSize * (r.lineHeight ?? Gt);
|
|
452
|
+
let f;
|
|
453
|
+
h.length === 0 ? f = 0 : h.length === 1 ? f = d.height : f = (h.length - 1) * u + d.height;
|
|
454
|
+
const k = -f / 2;
|
|
455
|
+
h.forEach((g, m) => {
|
|
456
|
+
const { spans: T, width: w, isParagraphStart: b, isParagraphEnd: y } = g;
|
|
457
|
+
let p;
|
|
458
|
+
i === "center" ? p = -w / 2 : i === "right" ? p = n !== void 0 ? n / 2 - w : -w : p = n !== void 0 ? -n / 2 : 0;
|
|
459
|
+
const S = k + d.ascent + m * u, C = T.map((E) => E.text).join(""), M = C.match(/^ +/), P = C.match(/ +$/), v = M ? M[0].length : 0, A = P ? P[0].length : 0;
|
|
460
|
+
let I = 0;
|
|
461
|
+
T.forEach((E) => {
|
|
462
|
+
const R = E.style.fontSize !== void 0 ? E.style.fontSize : r.fontSize, W = E.style.fontFamily !== void 0 ? E.style.fontFamily : r.fontFamily, F = E.style.color !== void 0 ? E.style.color : r.color, B = E.style.bold !== void 0 ? E.style.bold : r.bold || !1, U = E.style.italic !== void 0 ? E.style.italic : r.italic || !1, $ = E.style.underline !== void 0 ? E.style.underline : r.underline || !1, St = E.style.strikethrough !== void 0 ? E.style.strikethrough : r.strikethrough || !1;
|
|
463
|
+
let L = E.text, G = I, Mt = I + E.text.length;
|
|
464
|
+
if (!b && v > 0 && G < v) {
|
|
465
|
+
const Y = Math.min(v - G, E.text.length);
|
|
466
|
+
L = L.substring(Y);
|
|
467
|
+
}
|
|
468
|
+
if (!y && A > 0) {
|
|
469
|
+
const Y = C.length - A;
|
|
470
|
+
if (Mt > Y) {
|
|
471
|
+
const nt = !b && v > 0 && G < v ? Math.min(v - G, E.text.length) : 0, V = Math.max(0, Y - G - nt);
|
|
472
|
+
L = L.substring(0, V);
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
if (I += E.text.length, L.length > 0) {
|
|
476
|
+
const Y = s(E.style);
|
|
477
|
+
e.font = q(R, W, B, U), e.fillStyle = F, e.textBaseline = "alphabetic", e.textAlign = "left", Yt(e, L, p, S, Y);
|
|
478
|
+
const nt = at(e.measureText(L).width, L, Y);
|
|
479
|
+
if ($) {
|
|
480
|
+
const V = S + R * 0.1;
|
|
481
|
+
e.beginPath(), e.moveTo(p, V), e.lineTo(p + nt, V), e.lineWidth = Math.max(1, R * 0.05), e.strokeStyle = F, e.stroke();
|
|
482
|
+
}
|
|
483
|
+
if (St) {
|
|
484
|
+
const V = S - R * 0.25;
|
|
485
|
+
e.beginPath(), e.moveTo(p, V), e.lineTo(p + nt, V), e.lineWidth = Math.max(1, R * 0.05), e.strokeStyle = F, e.stroke();
|
|
486
|
+
}
|
|
487
|
+
p += nt;
|
|
488
|
+
}
|
|
489
|
+
});
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
const Rt = j("canvas-renderer");
|
|
493
|
+
let ut = null;
|
|
494
|
+
function Vt() {
|
|
495
|
+
if (!ut)
|
|
496
|
+
if (typeof OffscreenCanvas < "u")
|
|
497
|
+
ut = new OffscreenCanvas(1, 1).getContext("2d");
|
|
498
|
+
else if (typeof document < "u")
|
|
499
|
+
ut = document.createElement("canvas").getContext("2d");
|
|
500
|
+
else
|
|
501
|
+
throw new Error("No canvas context available");
|
|
502
|
+
return ut;
|
|
503
|
+
}
|
|
504
|
+
function q(e, t, r = !1, n = !1) {
|
|
505
|
+
const o = [];
|
|
506
|
+
return n && o.push("italic"), r && o.push("bold"), o.push(`${e}px`), o.push(t), o.join(" ");
|
|
507
|
+
}
|
|
508
|
+
function re(e, t, r, n = !1, o = !1, i = 0) {
|
|
509
|
+
const s = Vt();
|
|
510
|
+
return s.font = q(t, r, n, o), at(s.measureText(e).width, e, i);
|
|
511
|
+
}
|
|
512
|
+
function ht(e, t, r = !1, n = !1) {
|
|
513
|
+
const o = Vt();
|
|
514
|
+
o.font = q(e, t, r, n);
|
|
515
|
+
const s = o.measureText("ÁÉÍgjpqy"), l = s.actualBoundingBoxAscent || e * 0.8, a = s.actualBoundingBoxDescent || e * 0.2, c = l + a;
|
|
516
|
+
return { ascent: l, descent: a, height: c };
|
|
517
|
+
}
|
|
518
|
+
function Jn(e, t) {
|
|
519
|
+
const r = e.map((o, i) => ({
|
|
520
|
+
isParagraphStart: !t && i === 0,
|
|
521
|
+
isParagraphEnd: !t && i === e.length - 1
|
|
522
|
+
}));
|
|
523
|
+
return e.map((o, i) => {
|
|
524
|
+
if (o.trim().length === 0)
|
|
525
|
+
return "";
|
|
526
|
+
const s = r[i].isParagraphStart, l = r[i].isParagraphEnd;
|
|
527
|
+
let a = o;
|
|
528
|
+
return s || (a = a.replace(/^ +/, "")), l || (a = a.replace(/ +$/, "")), a;
|
|
529
|
+
}).filter((o) => o.length > 0);
|
|
530
|
+
}
|
|
531
|
+
function Mr(e, t) {
|
|
532
|
+
const r = t.fontSize, n = t.fontFamily, o = t.bold || !1, i = t.italic || !1, s = t.textAlign || "center", l = t.text;
|
|
533
|
+
e.font = q(r, n, o, i), e.textAlign = s, e.textBaseline = "alphabetic", e.fillStyle = t.color;
|
|
534
|
+
const a = ht(r, n, o, i), d = -a.height / 2 + a.ascent;
|
|
535
|
+
Yt(e, l, 0, d, t.letterSpacing);
|
|
536
|
+
}
|
|
537
|
+
function Cr(e, t, r, n, o = !1, i = !1, s) {
|
|
538
|
+
const l = Vt();
|
|
539
|
+
if (l.font = q(r, n, o, i), e.trim().length === 0)
|
|
540
|
+
return [e];
|
|
541
|
+
if (e.includes(`
|
|
542
|
+
`)) {
|
|
543
|
+
const M = e.split(`
|
|
544
|
+
`), P = [];
|
|
545
|
+
for (let v = 0; v < M.length; v++) {
|
|
546
|
+
const A = M[v], I = Cr(A, t, r, n, o, i);
|
|
547
|
+
P.push(...I);
|
|
548
|
+
}
|
|
549
|
+
return P;
|
|
550
|
+
}
|
|
551
|
+
const a = e.match(/^\s*/), c = e.match(/\s*$/), h = a ? a[0] : "", d = c ? c[0] : "", f = e.substring(h.length, e.length - d.length).split(" ");
|
|
552
|
+
if (s !== void 0 && s > 0) {
|
|
553
|
+
if (s === 1)
|
|
554
|
+
return [h + f.join(" ") + d];
|
|
555
|
+
const M = [], P = Math.ceil(f.length / s);
|
|
556
|
+
for (let v = 0; v < f.length; v += P) {
|
|
557
|
+
const I = f.slice(v, v + P).join(" ");
|
|
558
|
+
v === 0 && v + P >= f.length ? M.push(h + I + d) : v === 0 ? M.push(h + I) : v + P >= f.length ? M.push(I + d) : M.push(I);
|
|
559
|
+
}
|
|
560
|
+
return M;
|
|
561
|
+
}
|
|
562
|
+
const k = f.join(" "), g = h + k + d, m = l.measureText(g).width, T = t < 200, b = Math.max(20, t * (T ? 0.08 : 0.05));
|
|
563
|
+
if (m <= t + b)
|
|
564
|
+
return [g];
|
|
565
|
+
const y = [];
|
|
566
|
+
let p = f[0];
|
|
567
|
+
const C = Math.max(15, t * (T ? 0.05 : 0.03));
|
|
568
|
+
for (let M = 1; M < f.length; M++) {
|
|
569
|
+
const P = f[M], v = p + " " + P;
|
|
570
|
+
l.measureText(v).width > t + C ? (y.push(p), p = P) : p = v;
|
|
571
|
+
}
|
|
572
|
+
return y.push(p), y.length > 0 && (y[0] = h + y[0], y[y.length - 1] = y[y.length - 1] + d), y;
|
|
573
|
+
}
|
|
574
|
+
function Kn(e, t, r, n, o, i, s = "left", l = 0, a = 0, c = 1.2, h = !1, d = !1, u = !1, f = !1, k, g) {
|
|
575
|
+
e.font = q(o, i, h, d), e.textBaseline = "alphabetic", e.textAlign = s;
|
|
576
|
+
const m = (v) => {
|
|
577
|
+
for (const A of v) {
|
|
578
|
+
const I = A.codePointAt(0);
|
|
579
|
+
if (I && I >= 983040 && I <= 1048573)
|
|
580
|
+
return !0;
|
|
581
|
+
}
|
|
582
|
+
return !1;
|
|
583
|
+
}, T = k && Object.values(k).some((v) => v), w = g && g.length > 0, b = t.join(" "), y = m(b), p = T || w || y, S = p ? Dt.getFontSync(i, h ? 700 : 400) : null;
|
|
584
|
+
p && !S && (Rt.warn(
|
|
585
|
+
`[renderMultilineText] Font ${i} not loaded for fontkit rendering. Text may not render correctly. Has PUA: ${y}, Text: "${b}"`
|
|
586
|
+
), Dt.loadFont(i, h ? 700 : 400).catch((v) => {
|
|
587
|
+
Rt.error("[renderMultilineText] Error loading font:", v);
|
|
588
|
+
}));
|
|
589
|
+
const C = ht(o, i, h, d), M = o * c;
|
|
590
|
+
let P = 0;
|
|
591
|
+
t.forEach((v, A) => {
|
|
592
|
+
let I = r + a;
|
|
593
|
+
s === "center" ? I = r + l / 2 : s === "right" && (I = r + l - a);
|
|
594
|
+
const E = n + C.ascent + A * M, R = Array.from(v).length, W = w ? g.filter((F) => {
|
|
595
|
+
const B = F.charIndex - P;
|
|
596
|
+
return B >= 0 && B < R;
|
|
597
|
+
}).map((F) => ({
|
|
598
|
+
...F,
|
|
599
|
+
charIndex: F.charIndex - P
|
|
600
|
+
// Adjust to line-relative index
|
|
601
|
+
})) : [];
|
|
602
|
+
if (S && (T || W.length > 0 || y) ? W.length > 0 || m(v) ? Er(e, S, v, I, E, o, W, {
|
|
603
|
+
color: e.fillStyle,
|
|
604
|
+
align: s === "start" || s === "end" ? "left" : s
|
|
605
|
+
}) : k && vr(e, S, v, I, E, o, k, {
|
|
606
|
+
color: e.fillStyle,
|
|
607
|
+
align: s === "start" || s === "end" ? "left" : s
|
|
608
|
+
}) : e.fillText(v, I, E), P += R + 1, u) {
|
|
609
|
+
const F = re(v, o, i, h, d);
|
|
610
|
+
let B = I;
|
|
611
|
+
s === "center" ? B = I - F / 2 : s === "right" && (B = I - F);
|
|
612
|
+
const U = E + o * 0.1;
|
|
613
|
+
e.beginPath(), e.moveTo(B, U), e.lineTo(B + F, U), e.lineWidth = Math.max(1, o * 0.05), e.strokeStyle = e.fillStyle, e.stroke();
|
|
614
|
+
}
|
|
615
|
+
if (f) {
|
|
616
|
+
const F = re(v, o, i, h, d);
|
|
617
|
+
let B = I;
|
|
618
|
+
s === "center" ? B = I - F / 2 : s === "right" && (B = I - F);
|
|
619
|
+
const U = E - o * 0.25;
|
|
620
|
+
e.beginPath(), e.moveTo(B, U), e.lineTo(B + F, U), e.lineWidth = Math.max(1, o * 0.05), e.strokeStyle = e.fillStyle, e.stroke();
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
function Wt(e, t) {
|
|
625
|
+
Pr(e, t);
|
|
626
|
+
}
|
|
627
|
+
function Pr(e, t) {
|
|
628
|
+
var o;
|
|
629
|
+
(o = t.stroke) != null && o.enabled && Ie(e, t), e.save(), e.translate(t.x, t.y), e.rotate(-t.rotation * Math.PI / 180);
|
|
630
|
+
const r = t.transformData, n = ((r == null ? void 0 : r.width) ?? 100) - x * 2;
|
|
631
|
+
if (t.richText) {
|
|
632
|
+
const i = Ze.fromJSON(t.richText);
|
|
633
|
+
e.save(), e.translate(0, 0);
|
|
634
|
+
const s = t._lockedLineCount;
|
|
635
|
+
Sr(
|
|
636
|
+
e,
|
|
637
|
+
i,
|
|
638
|
+
{
|
|
639
|
+
fontSize: t.fontSize,
|
|
640
|
+
fontFamily: t.fontFamily,
|
|
641
|
+
color: t.color,
|
|
642
|
+
bold: t.bold,
|
|
643
|
+
italic: t.italic,
|
|
644
|
+
underline: t.underline,
|
|
645
|
+
strikethrough: t.strikethrough,
|
|
646
|
+
textAlign: t.textAlign,
|
|
647
|
+
letterSpacing: t.letterSpacing,
|
|
648
|
+
lineHeight: t.lineHeight
|
|
649
|
+
},
|
|
650
|
+
n,
|
|
651
|
+
s
|
|
652
|
+
), e.restore();
|
|
653
|
+
} else if (t.text) {
|
|
654
|
+
e.fillStyle = t.color;
|
|
655
|
+
const i = t._lockedLineCount, s = t.letterSpacing ?? 0, { lines: l, height: a } = Ee(
|
|
656
|
+
t.text,
|
|
657
|
+
n,
|
|
658
|
+
t.fontSize,
|
|
659
|
+
t.fontFamily,
|
|
660
|
+
t.bold,
|
|
661
|
+
t.italic,
|
|
662
|
+
i,
|
|
663
|
+
!0,
|
|
664
|
+
// strict: true
|
|
665
|
+
{ letterSpacing: s, lineHeight: t.lineHeight }
|
|
666
|
+
), c = ht(
|
|
667
|
+
t.fontSize,
|
|
668
|
+
t.fontFamily,
|
|
669
|
+
t.bold,
|
|
670
|
+
t.italic
|
|
671
|
+
), h = -((r == null ? void 0 : r.width) ?? 100) / 2, d = -a / 2, u = t.fontSize * (t.lineHeight ?? Gt);
|
|
672
|
+
e.font = `${t.italic ? "italic " : ""}${t.bold ? "bold " : ""}${t.fontSize}px ${t.fontFamily}`, e.textBaseline = "alphabetic", e.textAlign = t.textAlign, l.forEach((f, k) => {
|
|
673
|
+
const g = k === 0, m = k === l.length - 1;
|
|
674
|
+
let T = f;
|
|
675
|
+
if (!g) {
|
|
676
|
+
const y = f.match(/^ +/), p = y ? y[0].length : 0;
|
|
677
|
+
p > 0 && (T = T.substring(p));
|
|
678
|
+
}
|
|
679
|
+
if (!m) {
|
|
680
|
+
const y = T.match(/ +$/), p = y ? y[0].length : 0;
|
|
681
|
+
p > 0 && (T = T.substring(0, T.length - p));
|
|
682
|
+
}
|
|
683
|
+
let w = h + x;
|
|
684
|
+
t.textAlign === "center" ? w = h + ((r == null ? void 0 : r.width) ?? 100) / 2 : t.textAlign === "right" && (w = h + ((r == null ? void 0 : r.width) ?? 100) - x);
|
|
685
|
+
const b = d + c.ascent + k * u;
|
|
686
|
+
if (Yt(e, T, w, b, s), T.length > 0) {
|
|
687
|
+
const y = at(e.measureText(T).width, T, s);
|
|
688
|
+
let p = w;
|
|
689
|
+
if (t.textAlign === "center" ? p -= y / 2 : t.textAlign === "right" && (p -= y), t.underline) {
|
|
690
|
+
const S = b + t.fontSize * 0.1;
|
|
691
|
+
e.fillRect(p, S, y, Math.max(1, t.fontSize * 0.05));
|
|
692
|
+
}
|
|
693
|
+
if (t.strikethrough) {
|
|
694
|
+
const S = b - c.ascent * 0.4;
|
|
695
|
+
e.fillRect(p, S, y, Math.max(1, t.fontSize * 0.05));
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
}
|
|
700
|
+
e.restore();
|
|
701
|
+
}
|
|
702
|
+
function Qn(e, t) {
|
|
703
|
+
var s;
|
|
704
|
+
const r = t.opacity ?? 1, n = !!((s = t.stroke) != null && s.enabled), o = t.type === "custom";
|
|
705
|
+
if (r < 1 && n && o) {
|
|
706
|
+
Ir(e, t, r);
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
const i = e.globalAlpha;
|
|
710
|
+
r !== 1 && (e.globalAlpha = r), Ft(e, t), e.globalAlpha = i;
|
|
711
|
+
}
|
|
712
|
+
function Ir(e, t, r) {
|
|
713
|
+
var m;
|
|
714
|
+
const n = t.transformData, o = t.fontSize || 24, i = ((m = t.stroke) == null ? void 0 : m.width) || 0, s = ((n == null ? void 0 : n.width) ?? o * t.text.length * 0.7) + i * 2 + 40, l = o * 3 + i * 2 + 40, a = e.getTransform(), c = Math.max(Math.abs(a.a), Math.abs(a.d), 1), h = Math.ceil(s * c), d = Math.ceil(l * c);
|
|
715
|
+
let u;
|
|
716
|
+
typeof OffscreenCanvas < "u" ? u = new OffscreenCanvas(h, d) : (u = document.createElement("canvas"), u.width = h, u.height = d);
|
|
717
|
+
const f = u.getContext("2d");
|
|
718
|
+
if (!f) {
|
|
719
|
+
const T = e.globalAlpha;
|
|
720
|
+
e.globalAlpha = r, Ft(e, t), e.globalAlpha = T;
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
const k = a.a * t.x + a.e, g = a.d * t.y + a.f;
|
|
724
|
+
f.setTransform(
|
|
725
|
+
a.a,
|
|
726
|
+
a.b,
|
|
727
|
+
a.c,
|
|
728
|
+
a.d,
|
|
729
|
+
a.e - k + h / 2,
|
|
730
|
+
a.f - g + d / 2
|
|
731
|
+
), Ft(f, t), e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.globalAlpha = r, e.drawImage(u, k - h / 2, g - d / 2), e.restore();
|
|
732
|
+
}
|
|
733
|
+
function Ft(e, t) {
|
|
734
|
+
switch (t.type) {
|
|
735
|
+
case "custom":
|
|
736
|
+
Wt(e, t);
|
|
737
|
+
break;
|
|
738
|
+
case "circle":
|
|
739
|
+
Ae(e, t);
|
|
740
|
+
break;
|
|
741
|
+
case "wave":
|
|
742
|
+
Re(e, t);
|
|
743
|
+
break;
|
|
744
|
+
case "arch":
|
|
745
|
+
We(e, t);
|
|
746
|
+
break;
|
|
747
|
+
case "ascend":
|
|
748
|
+
Fe(e, t);
|
|
749
|
+
break;
|
|
750
|
+
case "lean":
|
|
751
|
+
Be(e, t);
|
|
752
|
+
break;
|
|
753
|
+
case "flag":
|
|
754
|
+
Ue(e, t);
|
|
755
|
+
break;
|
|
756
|
+
default:
|
|
757
|
+
Rt.warn(`[canvas-renderer] Unsupported transform type: ${t.type}`), Wt(e, t);
|
|
758
|
+
}
|
|
759
|
+
}
|
|
760
|
+
function Ar(e, t) {
|
|
761
|
+
if (typeof OffscreenCanvas < "u")
|
|
762
|
+
return new OffscreenCanvas(e, t);
|
|
763
|
+
const r = document.createElement("canvas");
|
|
764
|
+
return r.width = e, r.height = t, r;
|
|
765
|
+
}
|
|
766
|
+
function et(e, t, r) {
|
|
767
|
+
if (r != null && r.enabled)
|
|
768
|
+
if (e.strokeStyle = r.color, e.lineWidth = r.width, e.lineCap = r.lineCap || "round", e.lineJoin = r.lineJoin || "round", r.miterLimit !== void 0 && (e.miterLimit = r.miterLimit), r.opacity !== void 0) {
|
|
769
|
+
const n = e.globalAlpha;
|
|
770
|
+
e.globalAlpha = r.opacity, e.strokeText(t, 0, 0), e.globalAlpha = n;
|
|
771
|
+
} else
|
|
772
|
+
e.strokeText(t, 0, 0);
|
|
773
|
+
}
|
|
774
|
+
function rt(e, t, r) {
|
|
775
|
+
const n = t.stroke, o = (n == null ? void 0 : n.opacity) ?? 1, i = e.globalAlpha, s = (n == null ? void 0 : n.enabled) && o < 1, l = (n == null ? void 0 : n.enabled) && i < 1;
|
|
776
|
+
if (!(s || l)) {
|
|
777
|
+
r(e, t);
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
const c = t.fontSize || 24, h = n.width || 0, d = t.transformData, u = c * t.text.length * 0.7, f = d.width ?? (d.radius ? d.radius * 2 : 0), k = Math.max(f, u), g = (n.feather || 0) * 2, m = h * 4 + g + c + 40, T = k + m, w = d.archHeight ? Math.abs(d.archHeight) * c * 2 : 0, b = d.radius ? d.radius : 0, y = c * 3 + m + w + b, p = e.getTransform(), S = Math.max(Math.abs(p.a), Math.abs(p.d), 1), C = Math.ceil(T * S / 2) * 2, M = Math.ceil(y * S / 2) * 2;
|
|
781
|
+
if (C <= 0 || M <= 0) {
|
|
782
|
+
r(e, t);
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
const P = Ar(C, M), v = P.getContext("2d");
|
|
786
|
+
if (!v) {
|
|
787
|
+
r(e, t);
|
|
788
|
+
return;
|
|
789
|
+
}
|
|
790
|
+
const A = t.x || 0, I = t.y || 0, E = p.a * A + p.c * I + p.e, R = p.b * A + p.d * I + p.f, W = Math.round(E - C / 2), F = Math.round(R - M / 2);
|
|
791
|
+
if (v.setTransform(
|
|
792
|
+
p.a,
|
|
793
|
+
p.b,
|
|
794
|
+
p.c,
|
|
795
|
+
p.d,
|
|
796
|
+
C / 2 - E + p.e,
|
|
797
|
+
M / 2 - R + p.f
|
|
798
|
+
), l) {
|
|
799
|
+
v.globalAlpha = 1;
|
|
800
|
+
const $ = n.opacity;
|
|
801
|
+
s && (n.opacity = 1), r(v, t), s && (n.opacity = $), e.save(), e.resetTransform(), e.globalAlpha = i, e.drawImage(P, W, F), e.restore();
|
|
802
|
+
return;
|
|
803
|
+
}
|
|
804
|
+
const B = n.opacity;
|
|
805
|
+
n.opacity = 1, r(v, t), n.opacity = B;
|
|
806
|
+
const U = n.enabled;
|
|
807
|
+
n.enabled = !1, r(e, t), n.enabled = U, e.save(), e.resetTransform(), e.globalAlpha = o, e.drawImage(
|
|
808
|
+
P,
|
|
809
|
+
W,
|
|
810
|
+
F
|
|
811
|
+
), e.restore();
|
|
812
|
+
}
|
|
813
|
+
function Ae(e, t) {
|
|
814
|
+
rt(e, t, Rr);
|
|
815
|
+
}
|
|
816
|
+
function Rr(e, t) {
|
|
817
|
+
const r = t.transformData;
|
|
818
|
+
e.save(), e.translate(t.x, t.y), e.rotate(-t.rotation * Math.PI / 180), e.scale(r.scale, r.scale);
|
|
819
|
+
const n = t.bold ? "bold" : "normal", o = t.italic ? "italic" : "normal";
|
|
820
|
+
e.font = `${o} ${n} ${t.fontSize}px ${t.fontFamily}`, e.fillStyle = t.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
821
|
+
const i = t.text.split(""), s = i.map((a) => e.measureText(a).width), l = s.reduce((a, c) => a + c, 0);
|
|
822
|
+
if (r.reverse) {
|
|
823
|
+
let a = Math.PI / 2 + l / (2 * r.radius);
|
|
824
|
+
i.forEach((c, h) => {
|
|
825
|
+
const u = s[h] / r.radius, f = Math.cos(a - u / 2) * r.radius, k = Math.sin(a - u / 2) * r.radius;
|
|
826
|
+
e.save(), e.translate(f, k), e.rotate(a - u / 2 - Math.PI / 2), et(e, c, t.stroke), e.fillText(c, 0, 0), e.restore(), a -= u;
|
|
827
|
+
});
|
|
828
|
+
} else {
|
|
829
|
+
let a = -Math.PI / 2 - l / (2 * r.radius);
|
|
830
|
+
i.forEach((c, h) => {
|
|
831
|
+
const u = s[h] / r.radius, f = Math.cos(a + u / 2) * r.radius, k = Math.sin(a + u / 2) * r.radius;
|
|
832
|
+
e.save(), e.translate(f, k), e.rotate(a + u / 2 + Math.PI / 2), et(e, c, t.stroke), e.fillText(c, 0, 0), e.restore(), a += u;
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
e.restore();
|
|
836
|
+
}
|
|
837
|
+
function Re(e, t) {
|
|
838
|
+
rt(e, t, Wr);
|
|
839
|
+
}
|
|
840
|
+
function Wr(e, t) {
|
|
841
|
+
const r = t.transformData;
|
|
842
|
+
e.save(), e.translate(t.x, t.y), e.rotate(-t.rotation * Math.PI / 180), e.font = q(t.fontSize, t.fontFamily, t.bold, t.italic), e.fillStyle = t.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
843
|
+
const n = t.text.split("");
|
|
844
|
+
let i = -n.reduce((s, l) => s + e.measureText(l).width, 0) / 2;
|
|
845
|
+
n.forEach((s) => {
|
|
846
|
+
const l = e.measureText(s).width, a = i + l / 2, c = a / (r.width / 2), h = r.amplitude * t.fontSize * Math.sin(r.frequency * Math.PI * c), d = r.amplitude * r.frequency * Math.PI * Math.cos(r.frequency * Math.PI * c);
|
|
847
|
+
e.save(), e.translate(a, h), e.transform(1, d * De, 0, 1, 0, 0), et(e, s, t.stroke), e.fillText(s, 0, 0), e.restore(), i += l;
|
|
848
|
+
}), e.restore();
|
|
849
|
+
}
|
|
850
|
+
function We(e, t) {
|
|
851
|
+
rt(e, t, Fr);
|
|
852
|
+
}
|
|
853
|
+
function Fr(e, t) {
|
|
854
|
+
const r = t.transformData;
|
|
855
|
+
e.save(), e.translate(t.x, t.y), e.rotate(-t.rotation * Math.PI / 180), e.font = q(t.fontSize, t.fontFamily, t.bold, t.italic), e.fillStyle = t.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
856
|
+
const n = t.text.split(""), o = n.reduce((l, a) => l + e.measureText(a).width, 0), i = r.width / 2;
|
|
857
|
+
let s = -o / 2;
|
|
858
|
+
n.forEach((l) => {
|
|
859
|
+
const a = e.measureText(l).width, c = s + a / 2, h = c / i, d = (Math.pow(h, 2) - 1) * r.archHeight * t.fontSize, u = 2 * h * r.archHeight;
|
|
860
|
+
e.save(), e.translate(c, d), e.transform(1, u * 0.3, 0, 1, 0, 0), et(e, l, t.stroke), e.fillText(l, 0, 0), e.restore(), s += a;
|
|
861
|
+
}), e.restore();
|
|
862
|
+
}
|
|
863
|
+
function Fe(e, t) {
|
|
864
|
+
rt(e, t, Br);
|
|
865
|
+
}
|
|
866
|
+
function Br(e, t) {
|
|
867
|
+
const r = t.transformData;
|
|
868
|
+
e.save(), e.translate(t.x, t.y), e.rotate(-t.rotation * Math.PI / 180), e.font = q(t.fontSize, t.fontFamily, t.bold, t.italic), e.fillStyle = t.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
869
|
+
const n = t.text.split(""), o = n.reduce((l, a) => l + e.measureText(a).width, 0), i = r.ascendAngle * Math.PI / 180;
|
|
870
|
+
let s = -o / 2;
|
|
871
|
+
n.forEach((l) => {
|
|
872
|
+
const a = e.measureText(l).width, c = s + a / 2, h = c * Math.tan(i), d = Math.tan(i);
|
|
873
|
+
e.save(), e.translate(c, h), e.transform(1, d * 1, 0, 1, 0, 0), et(e, l, t.stroke), e.fillText(l, 0, 0), e.restore(), s += a;
|
|
874
|
+
}), e.restore();
|
|
875
|
+
}
|
|
876
|
+
function Be(e, t) {
|
|
877
|
+
rt(e, t, Ur);
|
|
878
|
+
}
|
|
879
|
+
function Ur(e, t) {
|
|
880
|
+
var o;
|
|
881
|
+
const r = t.transformData;
|
|
882
|
+
e.save(), e.translate(t.x, t.y), e.rotate(-t.rotation * Math.PI / 180);
|
|
883
|
+
const n = -r.leanAmount * Math.PI / 4;
|
|
884
|
+
e.transform(1, 0, Math.tan(n), 1, 0, 0), e.font = q(t.fontSize, t.fontFamily, t.bold, t.italic), e.fillStyle = t.color, e.textAlign = "center", e.textBaseline = "middle", (o = t.stroke) != null && o.enabled && (e.save(), e.strokeStyle = t.stroke.color, e.lineWidth = t.stroke.width, e.lineCap = t.stroke.lineCap || "round", e.lineJoin = t.stroke.lineJoin || "round", t.stroke.opacity !== void 0 && (e.globalAlpha = t.stroke.opacity), e.strokeText(t.text, 0, 0), e.restore()), e.fillText(t.text, 0, 0), e.restore();
|
|
885
|
+
}
|
|
886
|
+
function Ue(e, t) {
|
|
887
|
+
rt(e, t, Or);
|
|
888
|
+
}
|
|
889
|
+
function Or(e, t) {
|
|
890
|
+
const r = t.transformData;
|
|
891
|
+
e.save(), e.translate(t.x, t.y), e.rotate(-t.rotation * Math.PI / 180), e.font = q(t.fontSize, t.fontFamily, t.bold, t.italic), e.fillStyle = t.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
892
|
+
const n = t.text.split("");
|
|
893
|
+
let i = -n.reduce((s, l) => s + e.measureText(l).width, 0) / 2;
|
|
894
|
+
n.forEach((s) => {
|
|
895
|
+
const l = e.measureText(s).width, a = i + l / 2, c = a / (r.width / 2), h = Math.abs(c), d = r.amplitude * h, u = d * t.fontSize * Math.sin(r.frequency * Math.PI * c), f = d * r.frequency * Math.PI * Math.cos(r.frequency * Math.PI * c), k = r.amplitude * Math.sign(c) * Math.sin(r.frequency * Math.PI * c), g = f + k;
|
|
896
|
+
e.save(), e.translate(a, u), e.transform(1, g * 0.3, 0, 1, 0, 0), et(e, s, t.stroke), e.fillText(s, 0, 0), e.restore(), i += l;
|
|
897
|
+
}), e.restore();
|
|
898
|
+
}
|
|
899
|
+
function Q(e) {
|
|
900
|
+
return (t, r) => e(t, r);
|
|
901
|
+
}
|
|
902
|
+
function Lr(e, t) {
|
|
903
|
+
e.save();
|
|
904
|
+
const r = e.canvas, n = r.width, o = r.height, i = e.getTransform(), s = [];
|
|
905
|
+
let l = [];
|
|
906
|
+
for (const a of t)
|
|
907
|
+
a.isClipping ? l.length > 0 ? (s.push({ content: l, mask: a }), l = []) : s.push({ content: [a] }) : l.push(a);
|
|
908
|
+
l.length > 0 && s.push({ content: l });
|
|
909
|
+
for (const a of s)
|
|
910
|
+
if (!a.mask)
|
|
911
|
+
a.content.forEach((c) => c.render(e, !1, !1));
|
|
912
|
+
else {
|
|
913
|
+
const c = document.createElement("canvas");
|
|
914
|
+
c.width = n, c.height = o;
|
|
915
|
+
const h = c.getContext("2d");
|
|
916
|
+
if (!h) continue;
|
|
917
|
+
h.setTransform(i), a.content.forEach((f) => {
|
|
918
|
+
f.render(h, !1, !1);
|
|
919
|
+
});
|
|
920
|
+
const d = document.createElement("canvas");
|
|
921
|
+
d.width = n, d.height = o;
|
|
922
|
+
const u = d.getContext("2d");
|
|
923
|
+
if (!u) continue;
|
|
924
|
+
if (u.setTransform(i), a.mask.render(u, !1, !1), a.mask.transformType !== "image" && a.mask.transformType !== "shape") {
|
|
925
|
+
const f = a.mask.getBoundingBox();
|
|
926
|
+
u.save(), u.fillStyle = "#FFFFFF", u.fillRect(f.x, f.y, f.width, f.height), u.restore();
|
|
927
|
+
}
|
|
928
|
+
h.globalCompositeOperation = "destination-in", h.setTransform(1, 0, 0, 1, 0, 0), h.drawImage(d, 0, 0), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(c, 0, 0), e.setTransform(i);
|
|
929
|
+
}
|
|
930
|
+
e.restore();
|
|
931
|
+
}
|
|
932
|
+
var ne = !1;
|
|
933
|
+
function Jt() {
|
|
934
|
+
ne || (ne = !0, J("arch", Q(We)), J("ascend", Q(Fe)), J("circle", Q(Ae)), J("flag", Q(Ue)), J("lean", Q(Be)), J("wave", Q(Re)), J(
|
|
935
|
+
"custom",
|
|
936
|
+
(e, t) => Wt(e, t)
|
|
937
|
+
), xe(Lr), fr(
|
|
938
|
+
(e, t) => pr(e, t)
|
|
939
|
+
), globalThis.__scElementPaintersInstalled = !0);
|
|
940
|
+
}
|
|
941
|
+
Jt();
|
|
942
|
+
function Kt(e, t, r = {}) {
|
|
943
|
+
const n = r.mode || "both";
|
|
944
|
+
switch (e.save(), e.translate(t.x || 0, t.y || 0), e.rotate(-(t.rotation || 0) * Math.PI / 180), t.transformType) {
|
|
945
|
+
case "image":
|
|
946
|
+
$r(e, t, n, r);
|
|
947
|
+
break;
|
|
948
|
+
case "shape":
|
|
949
|
+
Hr(e, t, n, r);
|
|
950
|
+
break;
|
|
951
|
+
case "group":
|
|
952
|
+
break;
|
|
953
|
+
default:
|
|
954
|
+
qr(e, t, n, r);
|
|
955
|
+
break;
|
|
956
|
+
}
|
|
957
|
+
e.restore();
|
|
958
|
+
}
|
|
959
|
+
function qr(e, t, r, n) {
|
|
960
|
+
var s;
|
|
961
|
+
const o = t, i = o.text || "";
|
|
962
|
+
i && ((r === "stroke" || r === "both") && ((s = t.stroke) != null && s.enabled) && (e.save(), Ie(e, t, { ...n.renderingContext, positionApplied: !0 }), e.restore()), (r === "fill" || r === "both") && (e.save(), Mr(e, {
|
|
963
|
+
text: i,
|
|
964
|
+
fontSize: o.fontSize || 24,
|
|
965
|
+
fontFamily: o.fontFamily || "Arial",
|
|
966
|
+
bold: o.bold || !1,
|
|
967
|
+
italic: o.italic || !1,
|
|
968
|
+
textAlign: o.textAlign || "center",
|
|
969
|
+
color: o.color || "#000000",
|
|
970
|
+
letterSpacing: o.letterSpacing
|
|
971
|
+
}), e.restore()));
|
|
972
|
+
}
|
|
973
|
+
function $r(e, t, r, n) {
|
|
974
|
+
var i;
|
|
975
|
+
if (!t.transformData) return;
|
|
976
|
+
const o = t.transformData;
|
|
977
|
+
if (r === "fill" || r === "both")
|
|
978
|
+
if (Gr(e, t), n.loadedImage) {
|
|
979
|
+
e.save(), e.clip();
|
|
980
|
+
const s = o.flipHorizontal ? -1 : 1, l = o.flipVertical ? -1 : 1;
|
|
981
|
+
e.scale(s, l);
|
|
982
|
+
const a = o.width ?? 100, c = o.height ?? 100;
|
|
983
|
+
e.drawImage(n.loadedImage, -a / 2, -c / 2, a, c), e.restore();
|
|
984
|
+
} else
|
|
985
|
+
e.fillStyle = "#cccccc", e.fill();
|
|
986
|
+
(r === "stroke" || r === "both") && ((i = t.stroke) != null && i.enabled) && (e.save(), Tr(e, t, n.renderingContext), e.restore());
|
|
987
|
+
}
|
|
988
|
+
function Hr(e, t, r, n) {
|
|
989
|
+
var s, l;
|
|
990
|
+
if (!t.transformData) return;
|
|
991
|
+
const o = t.transformData, i = ((s = n.renderingContext) == null ? void 0 : s.isKnockout) === !0;
|
|
992
|
+
e.beginPath(), Oe(e, o), (r === "fill" || r === "both") && (e.fillStyle = i ? "#000000" : tr(e, o), e.globalAlpha = i ? 1 : o.fillOpacity ?? 1, e.fill()), (r === "stroke" || r === "both") && ((l = t.stroke) != null && l.enabled) && (e.save(), _r(e, t, n.renderingContext), e.restore());
|
|
993
|
+
}
|
|
994
|
+
function Oe(e, t) {
|
|
995
|
+
const { shapeType: r } = t, n = t.width ?? 100, o = t.height ?? 100;
|
|
996
|
+
switch (r) {
|
|
997
|
+
case "rectangle":
|
|
998
|
+
oe(e, t, n, o);
|
|
999
|
+
break;
|
|
1000
|
+
case "circle":
|
|
1001
|
+
jr(e, Math.min(n, o) / 2);
|
|
1002
|
+
break;
|
|
1003
|
+
case "ellipse":
|
|
1004
|
+
Nr(e, n / 2, o / 2);
|
|
1005
|
+
break;
|
|
1006
|
+
case "star":
|
|
1007
|
+
Xr(e, t, Math.min(n, o) / 2);
|
|
1008
|
+
break;
|
|
1009
|
+
default:
|
|
1010
|
+
oe(e, t, n, o);
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
function oe(e, t, r, n) {
|
|
1014
|
+
const o = t.borderRadius || 0, i = -r / 2, s = -n / 2;
|
|
1015
|
+
if (o > 0) {
|
|
1016
|
+
const l = Math.min(o / 100 * Math.min(r, n), r / 2, n / 2);
|
|
1017
|
+
e.roundRect(i, s, r, n, l);
|
|
1018
|
+
} else
|
|
1019
|
+
e.rect(i, s, r, n);
|
|
1020
|
+
}
|
|
1021
|
+
function jr(e, t) {
|
|
1022
|
+
e.arc(0, 0, t, 0, Math.PI * 2);
|
|
1023
|
+
}
|
|
1024
|
+
function Nr(e, t, r) {
|
|
1025
|
+
e.ellipse(0, 0, t, r, 0, 0, Math.PI * 2);
|
|
1026
|
+
}
|
|
1027
|
+
function Xr(e, t, r) {
|
|
1028
|
+
const n = Math.max(3, Math.min(20, t.points || 5)), o = Math.max(0.1, Math.min(0.9, t.innerRadius || 0.4)), i = r * o, s = Math.PI / n, l = -Math.PI / 2;
|
|
1029
|
+
for (let a = 0; a < n * 2; a++) {
|
|
1030
|
+
const c = l + s * a, h = a % 2 === 0 ? r : i, d = Math.cos(c) * h, u = Math.sin(c) * h;
|
|
1031
|
+
a === 0 ? e.moveTo(d, u) : e.lineTo(d, u);
|
|
1032
|
+
}
|
|
1033
|
+
e.closePath();
|
|
1034
|
+
}
|
|
1035
|
+
function _r(e, t, r) {
|
|
1036
|
+
var o;
|
|
1037
|
+
if (!((o = t.stroke) != null && o.enabled) || !t.transformData) return;
|
|
1038
|
+
const n = (r == null ? void 0 : r.isKnockout) === !0;
|
|
1039
|
+
e.save(), n ? (e.strokeStyle = "#000000", e.lineWidth = t.stroke.width, e.lineCap = t.stroke.lineCap || "butt", e.lineJoin = t.stroke.lineJoin || "miter", e.globalAlpha = 1) : (e.strokeStyle = t.stroke.color, e.lineWidth = t.stroke.width, e.lineCap = t.stroke.lineCap || "butt", e.lineJoin = t.stroke.lineJoin || "miter", t.stroke.opacity !== void 0 && (e.globalAlpha = t.stroke.opacity)), t.stroke.miterLimit !== void 0 && (e.miterLimit = t.stroke.miterLimit), t.stroke.dashArray && t.stroke.dashArray.length > 0 && e.setLineDash(t.stroke.dashArray), !n && t.stroke.feather && t.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${t.stroke.feather}px)`), e.beginPath(), Oe(e, t.transformData), e.stroke(), e.restore();
|
|
1040
|
+
}
|
|
1041
|
+
function Gr(e, t) {
|
|
1042
|
+
if (!t.transformData) return;
|
|
1043
|
+
const { borderRadius: r } = t.transformData, n = t.transformData.width ?? 100, o = t.transformData.height ?? 100, i = -n / 2, s = -o / 2;
|
|
1044
|
+
if (e.beginPath(), r && r > 0) {
|
|
1045
|
+
const l = Math.min(r / 100 * Math.min(n, o), n / 2, o / 2);
|
|
1046
|
+
e.roundRect(i, s, n, o, l);
|
|
1047
|
+
} else
|
|
1048
|
+
e.rect(i, s, n, o);
|
|
1049
|
+
}
|
|
1050
|
+
function Bt(e, t, r, n, o, i, s = "destination-out") {
|
|
1051
|
+
var b;
|
|
1052
|
+
if (!t.knockoutParts) return;
|
|
1053
|
+
if (!(t.knockoutParts.fill || t.knockoutParts.stroke)) {
|
|
1054
|
+
n(e, t);
|
|
1055
|
+
return;
|
|
1056
|
+
}
|
|
1057
|
+
const a = e.getTransform();
|
|
1058
|
+
e.save();
|
|
1059
|
+
const c = t.knockoutParts.scope || "group", h = Yr(t, c, r);
|
|
1060
|
+
if (h.length === 0 && c === "artboard") {
|
|
1061
|
+
Jr(e, t, n), e.restore();
|
|
1062
|
+
return;
|
|
1063
|
+
}
|
|
1064
|
+
if (h.length === 0) {
|
|
1065
|
+
n(e, t), e.restore();
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
const d = e.canvas, f = e.getTransform().a, k = Kr(d.width, d.height), g = k.getContext("2d");
|
|
1069
|
+
if (!g) return;
|
|
1070
|
+
g.scale(f, f), o && i && (g.fillStyle = o, g.fillRect(i.x, i.y, i.width, i.height));
|
|
1071
|
+
for (const y of h)
|
|
1072
|
+
n(g, y);
|
|
1073
|
+
t.knockoutParts.fill && !t.knockoutParts.stroke && ((b = t.stroke) != null && b.enabled) && (g.save(), Ot(g, t), g.restore()), g.save(), g.globalCompositeOperation = s, t.knockoutParts.fill && Ut(g, t), t.knockoutParts.stroke && Ot(g, t), g.restore(), t.knockoutParts.fill || (g.save(), Ut(g, t), g.restore());
|
|
1074
|
+
const m = d.width / f, T = d.height / f;
|
|
1075
|
+
e.drawImage(k, 0, 0, m, T), e.restore();
|
|
1076
|
+
const w = e.getTransform();
|
|
1077
|
+
(Math.abs(w.a - a.a) > 1e-3 || Math.abs(w.d - a.d) > 1e-3 || Math.abs(w.e - a.e) > 1e-3 || Math.abs(w.f - a.f) > 1e-3) && e.setTransform(
|
|
1078
|
+
a.a,
|
|
1079
|
+
a.b,
|
|
1080
|
+
a.c,
|
|
1081
|
+
a.d,
|
|
1082
|
+
a.e,
|
|
1083
|
+
a.f
|
|
1084
|
+
);
|
|
1085
|
+
}
|
|
1086
|
+
function zn(e, t, r, n, o, i) {
|
|
1087
|
+
Bt(e, t, r, n, o, i, "destination-out");
|
|
1088
|
+
}
|
|
1089
|
+
function Yr(e, t, r) {
|
|
1090
|
+
return t === "artboard" ? Le(e, r) : Vr(e, r);
|
|
1091
|
+
}
|
|
1092
|
+
function Le(e, t) {
|
|
1093
|
+
const r = t.findIndex((n) => n.id === e.id);
|
|
1094
|
+
return r === -1 ? [] : t.slice(0, r);
|
|
1095
|
+
}
|
|
1096
|
+
function Vr(e, t) {
|
|
1097
|
+
const r = qe(e, t);
|
|
1098
|
+
if (!r)
|
|
1099
|
+
return Le(e, t);
|
|
1100
|
+
if (r.transformType !== "group" || !r.children)
|
|
1101
|
+
return [];
|
|
1102
|
+
const n = r.children.findIndex((o) => o.id === e.id);
|
|
1103
|
+
return n === -1 ? [] : r.children.slice(0, n);
|
|
1104
|
+
}
|
|
1105
|
+
function qe(e, t) {
|
|
1106
|
+
for (const r of t)
|
|
1107
|
+
if (r.transformType === "group" && r.children) {
|
|
1108
|
+
if (r.children.some((o) => o.id === e.id))
|
|
1109
|
+
return r;
|
|
1110
|
+
const n = qe(e, r.children);
|
|
1111
|
+
if (n)
|
|
1112
|
+
return n;
|
|
1113
|
+
}
|
|
1114
|
+
return null;
|
|
1115
|
+
}
|
|
1116
|
+
function Ut(e, t, r) {
|
|
1117
|
+
Kt(e, t, {
|
|
1118
|
+
mode: "fill",
|
|
1119
|
+
renderingContext: { isKnockout: !0 }
|
|
1120
|
+
});
|
|
1121
|
+
}
|
|
1122
|
+
function Ot(e, t) {
|
|
1123
|
+
var r;
|
|
1124
|
+
(r = t.stroke) != null && r.enabled && Kt(e, t, {
|
|
1125
|
+
mode: "stroke",
|
|
1126
|
+
renderingContext: { isKnockout: !0 }
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
function Jr(e, t, r) {
|
|
1130
|
+
var o;
|
|
1131
|
+
const n = t.knockoutParts;
|
|
1132
|
+
if (!n) {
|
|
1133
|
+
r(e, t);
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
n.fill || (e.save(), Ut(e, t), e.restore()), !n.stroke && ((o = t.stroke) != null && o.enabled) && (e.save(), Ot(e, t), e.restore());
|
|
1137
|
+
}
|
|
1138
|
+
function Kr(e, t) {
|
|
1139
|
+
if (typeof OffscreenCanvas < "u")
|
|
1140
|
+
return new OffscreenCanvas(e, t);
|
|
1141
|
+
if (typeof document < "u") {
|
|
1142
|
+
const r = document.createElement("canvas");
|
|
1143
|
+
return r.width = e, r.height = t, r;
|
|
1144
|
+
}
|
|
1145
|
+
throw new Error("No canvas context available");
|
|
1146
|
+
}
|
|
1147
|
+
function se(e, t, r, n, o = 0) {
|
|
1148
|
+
if (r <= 0 || n <= 0 || e <= 0 || t <= 0)
|
|
1149
|
+
return { width: e + o, height: t + o };
|
|
1150
|
+
const i = r / n, s = e / t;
|
|
1151
|
+
let l, a;
|
|
1152
|
+
return s > i ? (a = t, l = t * i) : (l = e, a = e / i), {
|
|
1153
|
+
width: l + o,
|
|
1154
|
+
height: a + o
|
|
1155
|
+
};
|
|
1156
|
+
}
|
|
1157
|
+
const ot = 64, Ct = 512;
|
|
1158
|
+
function Qr(e, t) {
|
|
1159
|
+
e.beginPath(), e.arc(t / 2, t / 2, t * 0.45, 0, Math.PI * 2), e.fill();
|
|
1160
|
+
}
|
|
1161
|
+
function zr(e, t) {
|
|
1162
|
+
const r = t / 2, n = t / 2, o = t * 0.45, i = o * 0.4, s = 5;
|
|
1163
|
+
e.beginPath();
|
|
1164
|
+
for (let l = 0; l < s * 2; l++) {
|
|
1165
|
+
const a = -Math.PI / 2 + Math.PI / s * l, c = l % 2 === 0 ? o : i, h = r + Math.cos(a) * c, d = n + Math.sin(a) * c;
|
|
1166
|
+
l === 0 ? e.moveTo(h, d) : e.lineTo(h, d);
|
|
1167
|
+
}
|
|
1168
|
+
e.closePath(), e.fill();
|
|
1169
|
+
}
|
|
1170
|
+
function Zr(e, t) {
|
|
1171
|
+
const r = t / 2, n = t * 0.42;
|
|
1172
|
+
e.beginPath(), e.moveTo(r, t * 0.82), e.bezierCurveTo(r - n * 1.1, t * 0.6, r - n * 1.3, t * 0.2, r, t * 0.35), e.bezierCurveTo(r + n * 1.3, t * 0.2, r + n * 1.1, t * 0.6, r, t * 0.82), e.closePath(), e.fill();
|
|
1173
|
+
}
|
|
1174
|
+
function Dr(e, t) {
|
|
1175
|
+
const r = t / 2, n = t / 2, o = t * 0.4, i = t * 0.48;
|
|
1176
|
+
e.beginPath(), e.moveTo(r, n - i), e.lineTo(r + o, n), e.lineTo(r, n + i), e.lineTo(r - o, n), e.closePath(), e.fill();
|
|
1177
|
+
}
|
|
1178
|
+
function xr(e, t) {
|
|
1179
|
+
const r = t / 2, n = t / 2, o = t * 0.44;
|
|
1180
|
+
e.beginPath();
|
|
1181
|
+
for (let i = 0; i < 6; i++) {
|
|
1182
|
+
const s = -Math.PI / 2 + Math.PI / 3 * i, l = r + Math.cos(s) * o, a = n + Math.sin(s) * o;
|
|
1183
|
+
i === 0 ? e.moveTo(l, a) : e.lineTo(l, a);
|
|
1184
|
+
}
|
|
1185
|
+
e.closePath(), e.fill();
|
|
1186
|
+
}
|
|
1187
|
+
function tn(e, t) {
|
|
1188
|
+
const r = t / 2, n = t * 0.4, o = t * 0.12;
|
|
1189
|
+
e.beginPath(), e.moveTo(r, o), e.lineTo(r + n, t * 0.25), e.lineTo(r + n, t * 0.55), e.quadraticCurveTo(r + n * 0.3, t * 0.8, r, t * 0.9), e.quadraticCurveTo(r - n * 0.3, t * 0.8, r - n, t * 0.55), e.lineTo(r - n, t * 0.25), e.closePath(), e.fill();
|
|
1190
|
+
}
|
|
1191
|
+
function en(e, t) {
|
|
1192
|
+
const r = t / 2, n = t / 2;
|
|
1193
|
+
let o = 42;
|
|
1194
|
+
const i = () => (o = (o * 16807 + 0) % 2147483647, o / 2147483647);
|
|
1195
|
+
e.beginPath(), e.arc(r, n, t * 0.28, 0, Math.PI * 2), e.fill();
|
|
1196
|
+
for (let s = 0; s < 30; s++) {
|
|
1197
|
+
const l = i() * Math.PI * 2, a = t * 0.15 + i() * t * 0.3, c = t * 0.02 + i() * t * 0.06;
|
|
1198
|
+
e.beginPath(), e.arc(r + Math.cos(l) * a, n + Math.sin(l) * a, c, 0, Math.PI * 2), e.fill();
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
function rn(e, t) {
|
|
1202
|
+
let r = 123;
|
|
1203
|
+
const n = () => (r = (r * 16807 + 0) % 2147483647, r / 2147483647), o = t * 0.08, i = 40;
|
|
1204
|
+
e.beginPath(), e.moveTo(o, o);
|
|
1205
|
+
for (let s = 1; s <= i; s++) {
|
|
1206
|
+
const l = o + (t - 2 * o) * (s / i), a = o + (n() - 0.5) * t * 0.08;
|
|
1207
|
+
e.lineTo(l, a);
|
|
1208
|
+
}
|
|
1209
|
+
for (let s = 1; s <= i; s++) {
|
|
1210
|
+
const l = t - o + (n() - 0.5) * t * 0.08, a = o + (t - 2 * o) * (s / i);
|
|
1211
|
+
e.lineTo(l, a);
|
|
1212
|
+
}
|
|
1213
|
+
for (let s = i; s >= 0; s--) {
|
|
1214
|
+
const l = o + (t - 2 * o) * (s / i), a = t - o + (n() - 0.5) * t * 0.08;
|
|
1215
|
+
e.lineTo(l, a);
|
|
1216
|
+
}
|
|
1217
|
+
for (let s = i; s >= 0; s--) {
|
|
1218
|
+
const l = o + (n() - 0.5) * t * 0.08, a = o + (t - 2 * o) * (s / i);
|
|
1219
|
+
e.lineTo(l, a);
|
|
1220
|
+
}
|
|
1221
|
+
e.closePath(), e.fill();
|
|
1222
|
+
}
|
|
1223
|
+
function nn(e, t) {
|
|
1224
|
+
let r = 77;
|
|
1225
|
+
const n = () => (r = (r * 16807 + 0) % 2147483647, r / 2147483647), o = t * 0.25, i = t * 0.75, s = t * 0.1;
|
|
1226
|
+
e.beginPath(), e.moveTo(s, o + n() * t * 0.05);
|
|
1227
|
+
for (let l = 1; l <= 10; l++) {
|
|
1228
|
+
const a = s + (t - 2 * s) * (l / 10), c = o + (n() - 0.5) * t * 0.1;
|
|
1229
|
+
e.lineTo(a, c);
|
|
1230
|
+
}
|
|
1231
|
+
for (let l = 10; l >= 0; l--) {
|
|
1232
|
+
const a = s + (t - 2 * s) * (l / 10), c = i + (n() - 0.5) * t * 0.1;
|
|
1233
|
+
e.lineTo(a, c);
|
|
1234
|
+
}
|
|
1235
|
+
e.closePath(), e.fill();
|
|
1236
|
+
}
|
|
1237
|
+
function on(e, t) {
|
|
1238
|
+
const r = t / 2, n = t * 0.55;
|
|
1239
|
+
e.beginPath(), e.arc(r, n, t * 0.2, 0, Math.PI * 2), e.fill(), e.beginPath(), e.arc(r - t * 0.18, n + t * 0.02, t * 0.15, 0, Math.PI * 2), e.fill(), e.beginPath(), e.arc(r + t * 0.18, n + t * 0.02, t * 0.16, 0, Math.PI * 2), e.fill(), e.beginPath(), e.arc(r - t * 0.06, n - t * 0.14, t * 0.14, 0, Math.PI * 2), e.fill(), e.beginPath(), e.arc(r + t * 0.1, n - t * 0.12, t * 0.12, 0, Math.PI * 2), e.fill();
|
|
1240
|
+
}
|
|
1241
|
+
const sn = [
|
|
1242
|
+
// Geometric
|
|
1243
|
+
{ id: "circle", name: "Circle", description: "Perfect circle", imageUrl: "builtin-mask:circle", thumbnailUrl: "", category: "geometric", draw: Qr },
|
|
1244
|
+
{ id: "star", name: "Star", description: "5-pointed star", imageUrl: "builtin-mask:star", thumbnailUrl: "", category: "geometric", draw: zr },
|
|
1245
|
+
{ id: "heart", name: "Heart", description: "Heart shape", imageUrl: "builtin-mask:heart", thumbnailUrl: "", category: "geometric", draw: Zr },
|
|
1246
|
+
{ id: "diamond", name: "Diamond", description: "Diamond/rhombus", imageUrl: "builtin-mask:diamond", thumbnailUrl: "", category: "geometric", draw: Dr },
|
|
1247
|
+
{ id: "hexagon", name: "Hexagon", description: "Regular hexagon", imageUrl: "builtin-mask:hexagon", thumbnailUrl: "", category: "geometric", draw: xr },
|
|
1248
|
+
{ id: "shield", name: "Shield", description: "Shield/crest shape", imageUrl: "builtin-mask:shield", thumbnailUrl: "", category: "geometric", draw: tn },
|
|
1249
|
+
// Organic
|
|
1250
|
+
{ id: "splatter", name: "Splatter", description: "Ink splatter", imageUrl: "builtin-mask:splatter", thumbnailUrl: "", category: "organic", draw: en },
|
|
1251
|
+
{ id: "torn-edge", name: "Torn Edge", description: "Rough torn paper edge", imageUrl: "builtin-mask:torn-edge", thumbnailUrl: "", category: "organic", draw: rn },
|
|
1252
|
+
{ id: "paint-stroke", name: "Paint Stroke", description: "Horizontal brush stroke", imageUrl: "builtin-mask:paint-stroke", thumbnailUrl: "", category: "organic", draw: nn },
|
|
1253
|
+
{ id: "cloud", name: "Cloud", description: "Soft cloud shape", imageUrl: "builtin-mask:cloud", thumbnailUrl: "", category: "organic", draw: on }
|
|
1254
|
+
];
|
|
1255
|
+
let ae = !1;
|
|
1256
|
+
function ie(e, t) {
|
|
1257
|
+
if (typeof document > "u") return null;
|
|
1258
|
+
const r = document.createElement("canvas");
|
|
1259
|
+
return r.width = e, r.height = t, r;
|
|
1260
|
+
}
|
|
1261
|
+
function an() {
|
|
1262
|
+
if (typeof document > "u" || ae) return;
|
|
1263
|
+
ae = !0;
|
|
1264
|
+
const e = Tt.getInstance();
|
|
1265
|
+
for (const t of sn) {
|
|
1266
|
+
const r = ie(Ct, Ct);
|
|
1267
|
+
if (!r) continue;
|
|
1268
|
+
const n = r.getContext("2d");
|
|
1269
|
+
if (!n) continue;
|
|
1270
|
+
n.fillStyle = "white", t.draw(n, Ct);
|
|
1271
|
+
const o = r.toDataURL("image/png"), i = e.acquire(t.imageUrl);
|
|
1272
|
+
i.crossOrigin = "anonymous", i.src = o;
|
|
1273
|
+
const s = ie(ot, ot);
|
|
1274
|
+
if (s) {
|
|
1275
|
+
const l = s.getContext("2d");
|
|
1276
|
+
l && (l.fillStyle = "#1a1a2e", l.fillRect(0, 0, ot, ot), l.fillStyle = "white", t.draw(l, ot), t.thumbnailUrl = s.toDataURL("image/png"));
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
}
|
|
1280
|
+
const ln = j("MaskRenderer"), Lt = /* @__PURE__ */ new Map(), cn = /* @__PURE__ */ new Map();
|
|
1281
|
+
function Zn(e) {
|
|
1282
|
+
const t = [];
|
|
1283
|
+
Lt.forEach((r, n) => {
|
|
1284
|
+
n.startsWith(e) && t.push(n);
|
|
1285
|
+
}), t.forEach((r) => Lt.delete(r));
|
|
1286
|
+
}
|
|
1287
|
+
function Dn() {
|
|
1288
|
+
Lt.clear();
|
|
1289
|
+
}
|
|
1290
|
+
function le(e, t, r) {
|
|
1291
|
+
if (!t.masks || t.masks.length === 0) {
|
|
1292
|
+
r(e);
|
|
1293
|
+
return;
|
|
1294
|
+
}
|
|
1295
|
+
const n = e.canvas, o = pt(n.width, n.height), i = o.getContext("2d");
|
|
1296
|
+
if (!i) {
|
|
1297
|
+
ln.error("[renderWithMasks] Failed to get offscreen context");
|
|
1298
|
+
return;
|
|
1299
|
+
}
|
|
1300
|
+
const s = e.getTransform();
|
|
1301
|
+
i.setTransform(s), r(i);
|
|
1302
|
+
for (const l of t.masks)
|
|
1303
|
+
hn(i, l, t);
|
|
1304
|
+
e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(o, 0, 0), e.restore();
|
|
1305
|
+
}
|
|
1306
|
+
function hn(e, t, r) {
|
|
1307
|
+
switch (t.type) {
|
|
1308
|
+
case "clip":
|
|
1309
|
+
fn(e, t, r);
|
|
1310
|
+
break;
|
|
1311
|
+
case "alpha":
|
|
1312
|
+
dn(e, t, r);
|
|
1313
|
+
break;
|
|
1314
|
+
case "luma":
|
|
1315
|
+
un(e, t, r);
|
|
1316
|
+
break;
|
|
1317
|
+
case "distress":
|
|
1318
|
+
gn(e, t, r);
|
|
1319
|
+
break;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
function fn(e, t, r) {
|
|
1323
|
+
e.save(), e.globalCompositeOperation = t.inverted ? "destination-out" : "destination-in", t.opacity !== void 0 && (e.globalAlpha = t.opacity), vt(e, t.maskElement, r), e.restore();
|
|
1324
|
+
}
|
|
1325
|
+
function dn(e, t, r) {
|
|
1326
|
+
e.save(), e.globalCompositeOperation = t.inverted ? "destination-out" : "destination-in", t.opacity !== void 0 && (e.globalAlpha = t.opacity), vt(e, t.maskElement, r), t.feather && t.feather > 0 && $e(e, t.feather), e.restore();
|
|
1327
|
+
}
|
|
1328
|
+
function un(e, t, r) {
|
|
1329
|
+
const n = pt(e.canvas.width, e.canvas.height), o = n.getContext("2d");
|
|
1330
|
+
if (!o) return;
|
|
1331
|
+
vt(o, t.maskElement, r);
|
|
1332
|
+
const i = o.getImageData(0, 0, n.width, n.height), s = i.data;
|
|
1333
|
+
for (let l = 0; l < s.length; l += 4) {
|
|
1334
|
+
const a = s[l], c = s[l + 1], h = s[l + 2], d = 0.299 * a + 0.587 * c + 0.114 * h;
|
|
1335
|
+
s[l + 3] = t.inverted ? 255 - d : d;
|
|
1336
|
+
}
|
|
1337
|
+
o.putImageData(i, 0, 0), e.save(), e.globalCompositeOperation = "destination-in", t.opacity !== void 0 && (e.globalAlpha = t.opacity), e.drawImage(n, 0, 0), e.restore();
|
|
1338
|
+
}
|
|
1339
|
+
function gn(e, t, r) {
|
|
1340
|
+
e.save(), e.globalCompositeOperation = t.inverted ? "destination-in" : "destination-out", t.opacity !== void 0 && (e.globalAlpha = t.opacity), vt(e, t.maskElement, r), t.feather && t.feather > 0 && $e(e, t.feather), e.restore();
|
|
1341
|
+
}
|
|
1342
|
+
function vt(e, t, r) {
|
|
1343
|
+
const n = r.x || 0, o = r.y || 0, i = t.x || 0, s = t.y || 0, l = {
|
|
1344
|
+
...t,
|
|
1345
|
+
x: n + i,
|
|
1346
|
+
y: o + s,
|
|
1347
|
+
// Inherit parent rotation so mask rotates with the element
|
|
1348
|
+
rotation: (t.rotation || 0) + (r.rotation || 0)
|
|
1349
|
+
}, a = 4, c = r.transformData, h = r, d = (c == null ? void 0 : c.width) || h.width || 0, u = (c == null ? void 0 : c.height) || h.height || 0, f = t.transformData;
|
|
1350
|
+
d && u && f && (l.transformData = {
|
|
1351
|
+
...f,
|
|
1352
|
+
width: d + a,
|
|
1353
|
+
height: u + a
|
|
1354
|
+
});
|
|
1355
|
+
let k, g;
|
|
1356
|
+
if (t.transformType === "image") {
|
|
1357
|
+
const y = t;
|
|
1358
|
+
if (y.imageUrl)
|
|
1359
|
+
if (typeof document < "u") {
|
|
1360
|
+
y.imageUrl.startsWith("builtin-mask:") && an();
|
|
1361
|
+
const p = Tt.getInstance(), S = p.acquire(y.imageUrl);
|
|
1362
|
+
S.complete && S.naturalWidth > 0 && (k = S), p.release(y.imageUrl);
|
|
1363
|
+
} else
|
|
1364
|
+
g = cn.get(y.imageUrl);
|
|
1365
|
+
}
|
|
1366
|
+
const m = l.transformData, T = (f == null ? void 0 : f.width) || 0, w = (f == null ? void 0 : f.height) || 0, b = T > 0 && w > 0 && d > 0 && u > 0 && Math.abs(T / w - d / u) > 1e-3;
|
|
1367
|
+
if (g) {
|
|
1368
|
+
e.save();
|
|
1369
|
+
const y = (m == null ? void 0 : m.width) || g.width, p = (m == null ? void 0 : m.height) || g.height;
|
|
1370
|
+
if (e.translate(l.x || 0, l.y || 0), e.rotate(-(l.rotation || 0) * Math.PI / 180), b) {
|
|
1371
|
+
const S = se(
|
|
1372
|
+
y,
|
|
1373
|
+
p,
|
|
1374
|
+
T,
|
|
1375
|
+
w,
|
|
1376
|
+
0
|
|
1377
|
+
);
|
|
1378
|
+
e.drawImage(g, -S.width / 2, -S.height / 2, S.width, S.height);
|
|
1379
|
+
} else
|
|
1380
|
+
e.drawImage(g, -y / 2, -p / 2, y, p);
|
|
1381
|
+
e.restore();
|
|
1382
|
+
} else if (b && k) {
|
|
1383
|
+
const y = (m == null ? void 0 : m.width) || d, p = (m == null ? void 0 : m.height) || u, S = se(
|
|
1384
|
+
y,
|
|
1385
|
+
p,
|
|
1386
|
+
T,
|
|
1387
|
+
w,
|
|
1388
|
+
0
|
|
1389
|
+
);
|
|
1390
|
+
e.save(), e.translate(l.x || 0, l.y || 0), e.rotate(-(l.rotation || 0) * Math.PI / 180), e.drawImage(k, -S.width / 2, -S.height / 2, S.width, S.height), e.restore();
|
|
1391
|
+
} else
|
|
1392
|
+
Kt(e, l, { mode: "both", loadedImage: k });
|
|
1393
|
+
}
|
|
1394
|
+
function $e(e, t) {
|
|
1395
|
+
"filter" in e && (e.filter = `blur(${t}px)`);
|
|
1396
|
+
}
|
|
1397
|
+
function pt(e, t) {
|
|
1398
|
+
if (typeof OffscreenCanvas < "u")
|
|
1399
|
+
return new OffscreenCanvas(e, t);
|
|
1400
|
+
if (typeof document < "u") {
|
|
1401
|
+
const r = document.createElement("canvas");
|
|
1402
|
+
return r.width = e, r.height = t, r;
|
|
1403
|
+
}
|
|
1404
|
+
throw new Error("No canvas context available");
|
|
1405
|
+
}
|
|
1406
|
+
function pn(e, t, r, n) {
|
|
1407
|
+
if (!t.enabled || !t.imageUrl || t.opacity <= 0) return;
|
|
1408
|
+
const o = Tt.getInstance(), i = o.acquire(t.imageUrl);
|
|
1409
|
+
if (!i.complete || i.naturalWidth === 0) {
|
|
1410
|
+
o.release(t.imageUrl);
|
|
1411
|
+
return;
|
|
1412
|
+
}
|
|
1413
|
+
const { x: s, y: l, width: a, height: c } = r, h = e.getTransform(), d = h.a * s + h.e, u = h.d * l + h.f, f = h.a * a, k = h.d * c, g = Math.ceil(f), m = Math.ceil(k);
|
|
1414
|
+
if (g <= 0 || m <= 0) {
|
|
1415
|
+
o.release(t.imageUrl);
|
|
1416
|
+
return;
|
|
1417
|
+
}
|
|
1418
|
+
const T = pt(g, m), w = T.getContext("2d");
|
|
1419
|
+
if (!w) {
|
|
1420
|
+
o.release(t.imageUrl);
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1423
|
+
w.drawImage(
|
|
1424
|
+
e.canvas,
|
|
1425
|
+
d,
|
|
1426
|
+
u,
|
|
1427
|
+
f,
|
|
1428
|
+
k,
|
|
1429
|
+
0,
|
|
1430
|
+
0,
|
|
1431
|
+
g,
|
|
1432
|
+
m
|
|
1433
|
+
);
|
|
1434
|
+
let b;
|
|
1435
|
+
if (t.maskType === "luma" ? b = "destination-in" : b = t.inverted ? "destination-out" : "destination-in", t.maskType === "luma") {
|
|
1436
|
+
const y = pt(g, m), p = y.getContext("2d");
|
|
1437
|
+
if (p) {
|
|
1438
|
+
p.drawImage(i, 0, 0, g, m);
|
|
1439
|
+
const S = p.getImageData(0, 0, g, m), C = S.data;
|
|
1440
|
+
for (let M = 0; M < C.length; M += 4) {
|
|
1441
|
+
const P = 0.299 * C[M] + 0.587 * C[M + 1] + 0.114 * C[M + 2];
|
|
1442
|
+
C[M + 3] = t.inverted ? 255 - P : P;
|
|
1443
|
+
}
|
|
1444
|
+
p.putImageData(S, 0, 0), w.globalCompositeOperation = "destination-in", w.globalAlpha = t.opacity / 100, w.drawImage(y, 0, 0);
|
|
1445
|
+
}
|
|
1446
|
+
} else
|
|
1447
|
+
w.globalCompositeOperation = b, w.globalAlpha = t.opacity / 100, w.drawImage(i, 0, 0, g, m);
|
|
1448
|
+
w.globalCompositeOperation = "source-over", w.globalAlpha = 1, e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.clearRect(d, u, f, k), n && (e.fillStyle = n, e.fillRect(d, u, f, k)), e.drawImage(T, d, u), e.restore(), o.release(t.imageUrl);
|
|
1449
|
+
}
|
|
1450
|
+
function mn(e) {
|
|
1451
|
+
var t;
|
|
1452
|
+
return e ? ((t = e.shadow) == null ? void 0 : t.enabled) === !0 || Se(e.blendMode) : !1;
|
|
1453
|
+
}
|
|
1454
|
+
function ce(e, t, r) {
|
|
1455
|
+
var c;
|
|
1456
|
+
if (!mn(t)) {
|
|
1457
|
+
r(e);
|
|
1458
|
+
return;
|
|
1459
|
+
}
|
|
1460
|
+
const n = (c = t.shadow) != null && c.enabled ? t.shadow : void 0, o = Se(t.blendMode) ? t.blendMode : void 0, i = e.canvas, s = e.getTransform(), l = wn(i.width, i.height), a = l.getContext("2d");
|
|
1461
|
+
if (!a)
|
|
1462
|
+
throw new Error(
|
|
1463
|
+
"[canvas] renderWithLayerEffects: could not acquire a 2D context for the layer-effects raster"
|
|
1464
|
+
);
|
|
1465
|
+
if (a.setTransform(s), r(a), e.save(), e.setTransform(1, 0, 0, 1, 0, 0), o && (e.globalCompositeOperation = o), n) {
|
|
1466
|
+
const h = Math.hypot(s.a, s.b) || 1, d = i.width + 1;
|
|
1467
|
+
e.save(), e.globalAlpha = e.globalAlpha * yn(n.opacity ?? 1), e.shadowColor = n.color, e.shadowBlur = n.blur * h, e.shadowOffsetX = n.offsetX * h + d, e.shadowOffsetY = n.offsetY * h, e.drawImage(l, -d, 0), e.restore();
|
|
1468
|
+
}
|
|
1469
|
+
e.drawImage(l, 0, 0), e.restore();
|
|
1470
|
+
}
|
|
1471
|
+
function yn(e) {
|
|
1472
|
+
return Math.min(1, Math.max(0, e));
|
|
1473
|
+
}
|
|
1474
|
+
function wn(e, t) {
|
|
1475
|
+
if (typeof OffscreenCanvas < "u")
|
|
1476
|
+
return new OffscreenCanvas(e, t);
|
|
1477
|
+
if (typeof document < "u") {
|
|
1478
|
+
const r = document.createElement("canvas");
|
|
1479
|
+
return r.width = e, r.height = t, r;
|
|
1480
|
+
}
|
|
1481
|
+
throw new Error("No canvas context available");
|
|
1482
|
+
}
|
|
1483
|
+
class kn {
|
|
1484
|
+
constructor(t = Math.random()) {
|
|
1485
|
+
this.perm = [];
|
|
1486
|
+
for (let n = 0; n < 256; n++)
|
|
1487
|
+
this.perm[n] = n;
|
|
1488
|
+
const r = this.seededRandom(t);
|
|
1489
|
+
for (let n = 255; n > 0; n--) {
|
|
1490
|
+
const o = Math.floor(r() * (n + 1));
|
|
1491
|
+
[this.perm[n], this.perm[o]] = [this.perm[o], this.perm[n]];
|
|
1492
|
+
}
|
|
1493
|
+
for (let n = 0; n < 256; n++)
|
|
1494
|
+
this.perm[256 + n] = this.perm[n];
|
|
1495
|
+
}
|
|
1496
|
+
seededRandom(t) {
|
|
1497
|
+
let r = Math.sin(t++) * 1e4;
|
|
1498
|
+
return () => (r = Math.sin(t++) * 1e4, r - Math.floor(r));
|
|
1499
|
+
}
|
|
1500
|
+
fade(t) {
|
|
1501
|
+
return t * t * t * (t * (t * 6 - 15) + 10);
|
|
1502
|
+
}
|
|
1503
|
+
lerp(t, r, n) {
|
|
1504
|
+
return r + t * (n - r);
|
|
1505
|
+
}
|
|
1506
|
+
grad(t, r, n) {
|
|
1507
|
+
const o = t & 15, i = o < 8 ? r : n, s = o < 4 ? n : o === 12 || o === 14 ? r : 0;
|
|
1508
|
+
return ((o & 1) === 0 ? i : -i) + ((o & 2) === 0 ? s : -s);
|
|
1509
|
+
}
|
|
1510
|
+
noise(t, r) {
|
|
1511
|
+
const n = Math.floor(t) & 255, o = Math.floor(r) & 255;
|
|
1512
|
+
t -= Math.floor(t), r -= Math.floor(r);
|
|
1513
|
+
const i = this.fade(t), s = this.fade(r), l = this.perm[n] + o, a = this.perm[n + 1] + o;
|
|
1514
|
+
return this.lerp(
|
|
1515
|
+
s,
|
|
1516
|
+
this.lerp(i, this.grad(this.perm[l], t, r), this.grad(this.perm[a], t - 1, r)),
|
|
1517
|
+
this.lerp(i, this.grad(this.perm[l + 1], t, r - 1), this.grad(this.perm[a + 1], t - 1, r - 1))
|
|
1518
|
+
);
|
|
1519
|
+
}
|
|
1520
|
+
}
|
|
1521
|
+
function Pt(e, t, r, n = Date.now()) {
|
|
1522
|
+
const s = Et(e, t).getContext("2d").createImageData(e, t), l = s.data, a = new kn(n), c = 0.02, h = 1 - r / 100;
|
|
1523
|
+
for (let d = 0; d < t; d++)
|
|
1524
|
+
for (let u = 0; u < e; u++) {
|
|
1525
|
+
const f = (d * e + u) * 4;
|
|
1526
|
+
let k = 0;
|
|
1527
|
+
k += a.noise(u * c, d * c) * 0.5, k += a.noise(u * c * 2, d * c * 2) * 0.25, k += a.noise(u * c * 4, d * c * 4) * 0.125, k = (k + 1) / 2;
|
|
1528
|
+
const g = Math.min(u / e, (e - u) / e) * 2, m = Math.min(d / t, (t - d) / t) * 2, T = Math.min(g, m);
|
|
1529
|
+
k *= 0.7 + T * 0.3;
|
|
1530
|
+
const w = k > h ? 255 : 0;
|
|
1531
|
+
l[f] = 255, l[f + 1] = 255, l[f + 2] = 255, l[f + 3] = w;
|
|
1532
|
+
}
|
|
1533
|
+
return s;
|
|
1534
|
+
}
|
|
1535
|
+
function bn(e, t, r, n = Date.now()) {
|
|
1536
|
+
const i = Et(e, t).getContext("2d");
|
|
1537
|
+
i.clearRect(0, 0, e, t), i.strokeStyle = "#000000", i.lineWidth = 1 + r / 50, i.lineCap = "round";
|
|
1538
|
+
const s = Qt(n), l = Math.floor(r / 100 * 30 + 5);
|
|
1539
|
+
for (let a = 0; a < l; a++) {
|
|
1540
|
+
const c = s() * e, h = s() * t;
|
|
1541
|
+
qt(i, c, h, s() * Math.PI * 2, 50 + s() * 100, s, 0);
|
|
1542
|
+
}
|
|
1543
|
+
return i.getImageData(0, 0, e, t);
|
|
1544
|
+
}
|
|
1545
|
+
function qt(e, t, r, n, o, i, s) {
|
|
1546
|
+
if (s > 3 || o < 10) return;
|
|
1547
|
+
const l = t + Math.cos(n) * o, a = r + Math.sin(n) * o;
|
|
1548
|
+
if (e.beginPath(), e.moveTo(t, r), e.lineTo(l, a), e.stroke(), i() > 0.5) {
|
|
1549
|
+
const c = n + (i() - 0.5) * Math.PI / 2;
|
|
1550
|
+
qt(e, l, a, c, o * 0.6, i, s + 1);
|
|
1551
|
+
}
|
|
1552
|
+
if (i() > 0.7) {
|
|
1553
|
+
const c = n - (i() - 0.5) * Math.PI / 2;
|
|
1554
|
+
qt(e, l, a, c, o * 0.6, i, s + 1);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
function gt(e, t, r, n = Date.now()) {
|
|
1558
|
+
const s = Et(e, t).getContext("2d").createImageData(e, t), l = s.data, a = Qt(n), c = r / 100 * 0.5;
|
|
1559
|
+
for (let h = 0; h < t; h++)
|
|
1560
|
+
for (let d = 0; d < e; d++) {
|
|
1561
|
+
const u = (h * e + d) * 4, k = a() < c ? 255 : 0;
|
|
1562
|
+
l[u] = 0, l[u + 1] = 0, l[u + 2] = 0, l[u + 3] = k;
|
|
1563
|
+
}
|
|
1564
|
+
return s;
|
|
1565
|
+
}
|
|
1566
|
+
function Tn(e, t, r, n = Date.now()) {
|
|
1567
|
+
const i = Et(e, t).getContext("2d");
|
|
1568
|
+
i.fillStyle = "#000000";
|
|
1569
|
+
const s = Qt(n), l = 4 + r / 100 * 6, a = l * 2;
|
|
1570
|
+
for (let c = 0; c < t; c += a)
|
|
1571
|
+
for (let h = 0; h < e; h += a)
|
|
1572
|
+
if (s() < r / 100) {
|
|
1573
|
+
const d = l * (0.5 + s() * 0.5);
|
|
1574
|
+
i.beginPath(), i.arc(h, c, d / 2, 0, Math.PI * 2), i.fill();
|
|
1575
|
+
}
|
|
1576
|
+
return i.getImageData(0, 0, e, t);
|
|
1577
|
+
}
|
|
1578
|
+
function Et(e, t) {
|
|
1579
|
+
if (typeof OffscreenCanvas < "u")
|
|
1580
|
+
return new OffscreenCanvas(e, t);
|
|
1581
|
+
if (typeof document < "u") {
|
|
1582
|
+
const r = document.createElement("canvas");
|
|
1583
|
+
return r.width = e, r.height = t, r;
|
|
1584
|
+
}
|
|
1585
|
+
throw new Error("No canvas context available");
|
|
1586
|
+
}
|
|
1587
|
+
function Qt(e) {
|
|
1588
|
+
let t = Math.sin(e++) * 1e4;
|
|
1589
|
+
return () => (t = Math.sin(e++) * 1e4, t - Math.floor(t));
|
|
1590
|
+
}
|
|
1591
|
+
const H = 42, z = 512, Z = 64;
|
|
1592
|
+
function $t(e) {
|
|
1593
|
+
const t = e.data;
|
|
1594
|
+
for (let r = 0; r < t.length; r += 4)
|
|
1595
|
+
t[r] = 255, t[r + 1] = 255, t[r + 2] = 255;
|
|
1596
|
+
return e;
|
|
1597
|
+
}
|
|
1598
|
+
function vn(e, t) {
|
|
1599
|
+
const r = e.data, n = t.data;
|
|
1600
|
+
for (let o = 0; o < r.length; o += 4)
|
|
1601
|
+
r[o] = 255, r[o + 1] = 255, r[o + 2] = 255, r[o + 3] = Math.min(255, r[o + 3] + n[o + 3]);
|
|
1602
|
+
return e;
|
|
1603
|
+
}
|
|
1604
|
+
const En = [
|
|
1605
|
+
{
|
|
1606
|
+
id: "grunge-heavy",
|
|
1607
|
+
name: "Heavy Grunge",
|
|
1608
|
+
textureUrl: "builtin:grunge-heavy",
|
|
1609
|
+
thumbnailUrl: "",
|
|
1610
|
+
description: "Dense random splatters",
|
|
1611
|
+
generate: (e, t) => gt(e, t, 80, H)
|
|
1612
|
+
},
|
|
1613
|
+
{
|
|
1614
|
+
id: "grunge-fine",
|
|
1615
|
+
name: "Fine Grunge",
|
|
1616
|
+
textureUrl: "builtin:grunge-fine",
|
|
1617
|
+
thumbnailUrl: "",
|
|
1618
|
+
description: "Sparse fine grain",
|
|
1619
|
+
generate: (e, t) => gt(e, t, 25, H + 1)
|
|
1620
|
+
},
|
|
1621
|
+
{
|
|
1622
|
+
id: "concrete",
|
|
1623
|
+
name: "Concrete",
|
|
1624
|
+
textureUrl: "builtin:concrete",
|
|
1625
|
+
thumbnailUrl: "",
|
|
1626
|
+
description: "Rough surface via Perlin noise",
|
|
1627
|
+
generate: (e, t) => Pt(e, t, 55, H + 2)
|
|
1628
|
+
},
|
|
1629
|
+
{
|
|
1630
|
+
id: "paper",
|
|
1631
|
+
name: "Old Paper",
|
|
1632
|
+
textureUrl: "builtin:paper",
|
|
1633
|
+
thumbnailUrl: "",
|
|
1634
|
+
description: "Subtle aging",
|
|
1635
|
+
generate: (e, t) => Pt(e, t, 20, H + 3)
|
|
1636
|
+
},
|
|
1637
|
+
{
|
|
1638
|
+
id: "rust",
|
|
1639
|
+
name: "Rust",
|
|
1640
|
+
textureUrl: "builtin:rust",
|
|
1641
|
+
thumbnailUrl: "",
|
|
1642
|
+
description: "Noise + splatter combined",
|
|
1643
|
+
generate: (e, t) => {
|
|
1644
|
+
const r = Pt(e, t, 45, H + 4), n = gt(e, t, 35, H + 5);
|
|
1645
|
+
return vn($t(r), $t(n));
|
|
1646
|
+
}
|
|
1647
|
+
},
|
|
1648
|
+
{
|
|
1649
|
+
id: "scratches",
|
|
1650
|
+
name: "Scratches",
|
|
1651
|
+
textureUrl: "builtin:scratches",
|
|
1652
|
+
thumbnailUrl: "",
|
|
1653
|
+
description: "Branching crack lines",
|
|
1654
|
+
generate: (e, t) => bn(e, t, 55, H + 6)
|
|
1655
|
+
},
|
|
1656
|
+
{
|
|
1657
|
+
id: "halftone",
|
|
1658
|
+
name: "Halftone",
|
|
1659
|
+
textureUrl: "builtin:halftone",
|
|
1660
|
+
thumbnailUrl: "",
|
|
1661
|
+
description: "Dot grid pattern",
|
|
1662
|
+
generate: (e, t) => Tn(e, t, 55, H + 7)
|
|
1663
|
+
},
|
|
1664
|
+
{
|
|
1665
|
+
id: "spray",
|
|
1666
|
+
name: "Spray Paint",
|
|
1667
|
+
textureUrl: "builtin:spray",
|
|
1668
|
+
thumbnailUrl: "",
|
|
1669
|
+
description: "Medium random splatter",
|
|
1670
|
+
generate: (e, t) => gt(e, t, 55, H + 8)
|
|
1671
|
+
}
|
|
1672
|
+
];
|
|
1673
|
+
let he = !1;
|
|
1674
|
+
function Sn(e, t) {
|
|
1675
|
+
if (typeof OffscreenCanvas < "u")
|
|
1676
|
+
return new OffscreenCanvas(e, t);
|
|
1677
|
+
const r = document.createElement("canvas");
|
|
1678
|
+
return r.width = e, r.height = t, r;
|
|
1679
|
+
}
|
|
1680
|
+
function fe(e, t) {
|
|
1681
|
+
if (typeof document > "u") return null;
|
|
1682
|
+
const r = document.createElement("canvas");
|
|
1683
|
+
return r.width = e, r.height = t, r;
|
|
1684
|
+
}
|
|
1685
|
+
function Mn(e) {
|
|
1686
|
+
const t = fe(e.width, e.height);
|
|
1687
|
+
if (!t) return "";
|
|
1688
|
+
const r = t.getContext("2d");
|
|
1689
|
+
if (!r) return "";
|
|
1690
|
+
r.putImageData(e, 0, 0);
|
|
1691
|
+
const n = fe(Z, Z);
|
|
1692
|
+
if (!n) return "";
|
|
1693
|
+
const o = n.getContext("2d");
|
|
1694
|
+
if (!o) return "";
|
|
1695
|
+
o.drawImage(t, 0, 0, e.width, e.height, 0, 0, Z, Z);
|
|
1696
|
+
const i = o.getImageData(0, 0, Z, Z), s = i.data;
|
|
1697
|
+
for (let l = 0; l < s.length; l += 4) {
|
|
1698
|
+
const a = s[l + 3], c = 255 - Math.round(a / 255 * 195);
|
|
1699
|
+
s[l] = c, s[l + 1] = c, s[l + 2] = c, s[l + 3] = 255;
|
|
1700
|
+
}
|
|
1701
|
+
return o.putImageData(i, 0, 0), n.toDataURL("image/png");
|
|
1702
|
+
}
|
|
1703
|
+
function Cn() {
|
|
1704
|
+
if (!he) {
|
|
1705
|
+
he = !0;
|
|
1706
|
+
for (const e of En) {
|
|
1707
|
+
const t = e.generate(z, z);
|
|
1708
|
+
$t(t);
|
|
1709
|
+
const r = Sn(z, z), n = r.getContext("2d");
|
|
1710
|
+
n && (n.putImageData(t, 0, 0), Pn(e.textureUrl, r, z, z)), typeof document < "u" && (e.thumbnailUrl = Mn(t));
|
|
1711
|
+
}
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
const X = /* @__PURE__ */ new Set(), _ = /* @__PURE__ */ new Map(), mt = /* @__PURE__ */ new Map();
|
|
1715
|
+
function de(e, t) {
|
|
1716
|
+
if (typeof OffscreenCanvas < "u")
|
|
1717
|
+
return new OffscreenCanvas(e, t);
|
|
1718
|
+
const r = document.createElement("canvas");
|
|
1719
|
+
return r.width = e, r.height = t, r;
|
|
1720
|
+
}
|
|
1721
|
+
function ue(e) {
|
|
1722
|
+
return e.getContext("2d");
|
|
1723
|
+
}
|
|
1724
|
+
function ge(e) {
|
|
1725
|
+
const { width: t, height: r } = e, n = de(t, r), o = ue(n);
|
|
1726
|
+
if (!o) throw new Error("Failed to get 2d context for temp canvas");
|
|
1727
|
+
o.drawImage(e, 0, 0);
|
|
1728
|
+
const i = o.getImageData(0, 0, t, r), s = i.data;
|
|
1729
|
+
for (let c = 0; c < s.length; c += 4) {
|
|
1730
|
+
const h = s[c], d = s[c + 1], u = s[c + 2], k = 255 - (0.299 * h + 0.587 * d + 0.114 * u);
|
|
1731
|
+
s[c] = 255, s[c + 1] = 255, s[c + 2] = 255, s[c + 3] = k;
|
|
1732
|
+
}
|
|
1733
|
+
const l = de(t, r), a = ue(l);
|
|
1734
|
+
if (!a) throw new Error("Failed to get 2d context for mask canvas");
|
|
1735
|
+
return a.putImageData(i, 0, 0), { alphaMask: l, width: t, height: r };
|
|
1736
|
+
}
|
|
1737
|
+
function He(e) {
|
|
1738
|
+
const t = _.get(e);
|
|
1739
|
+
if (t) return t;
|
|
1740
|
+
if (e.startsWith("builtin:")) {
|
|
1741
|
+
Cn();
|
|
1742
|
+
const r = _.get(e);
|
|
1743
|
+
return r || null;
|
|
1744
|
+
}
|
|
1745
|
+
return X.has(e) || (X.add(e), je(e)), null;
|
|
1746
|
+
}
|
|
1747
|
+
function xn(e) {
|
|
1748
|
+
return _.has(e) ? Promise.resolve() : new Promise((t) => {
|
|
1749
|
+
if (_.has(e)) {
|
|
1750
|
+
t();
|
|
1751
|
+
return;
|
|
1752
|
+
}
|
|
1753
|
+
const r = mt.get(e) || [];
|
|
1754
|
+
r.push(t), mt.set(e, r), X.has(e) || (X.add(e), je(e));
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
function Pn(e, t, r, n) {
|
|
1758
|
+
_.has(e) || (_.set(e, { alphaMask: t, width: r, height: n }), st(e));
|
|
1759
|
+
}
|
|
1760
|
+
function st(e) {
|
|
1761
|
+
const t = mt.get(e);
|
|
1762
|
+
t && (t.forEach((r) => r()), mt.delete(e));
|
|
1763
|
+
}
|
|
1764
|
+
function je(e) {
|
|
1765
|
+
if (typeof document < "u") {
|
|
1766
|
+
const t = new Image();
|
|
1767
|
+
t.crossOrigin = "anonymous", t.onload = () => {
|
|
1768
|
+
const r = ge(t);
|
|
1769
|
+
_.set(e, r), X.delete(e), st(e);
|
|
1770
|
+
}, t.onerror = () => {
|
|
1771
|
+
X.delete(e), st(e);
|
|
1772
|
+
}, t.src = e;
|
|
1773
|
+
} else
|
|
1774
|
+
fetch(e).then((t) => t.blob()).then((t) => createImageBitmap(t)).then((t) => {
|
|
1775
|
+
const r = ge(t);
|
|
1776
|
+
_.set(e, r), X.delete(e), st(e);
|
|
1777
|
+
}).catch(() => {
|
|
1778
|
+
X.delete(e), st(e);
|
|
1779
|
+
});
|
|
1780
|
+
}
|
|
1781
|
+
function Ne(e, t) {
|
|
1782
|
+
if (typeof OffscreenCanvas < "u")
|
|
1783
|
+
return new OffscreenCanvas(e, t);
|
|
1784
|
+
const r = document.createElement("canvas");
|
|
1785
|
+
return r.width = e, r.height = t, r;
|
|
1786
|
+
}
|
|
1787
|
+
function In(e, t, r, n) {
|
|
1788
|
+
if (!t.enabled || !t.textureUrl || t.intensity <= 0) return;
|
|
1789
|
+
const o = He(t.textureUrl);
|
|
1790
|
+
if (!o) return;
|
|
1791
|
+
const { x: i, y: s, width: l, height: a } = r, c = e.getTransform(), h = c.a * i + c.e, d = c.d * s + c.f, u = c.a * l, f = c.d * a, k = Math.ceil(u), g = Math.ceil(f);
|
|
1792
|
+
if (k <= 0 || g <= 0) return;
|
|
1793
|
+
const m = Ne(k, g), T = m.getContext("2d");
|
|
1794
|
+
if (!T) return;
|
|
1795
|
+
T.drawImage(
|
|
1796
|
+
e.canvas,
|
|
1797
|
+
h,
|
|
1798
|
+
d,
|
|
1799
|
+
u,
|
|
1800
|
+
f,
|
|
1801
|
+
0,
|
|
1802
|
+
0,
|
|
1803
|
+
k,
|
|
1804
|
+
g
|
|
1805
|
+
);
|
|
1806
|
+
const w = o.alphaMask.getContext("2d");
|
|
1807
|
+
if (w) {
|
|
1808
|
+
const b = t.intensity / 100, y = w.getImageData(0, 0, o.width, o.height).data, p = o.width, S = o.height, C = T.getImageData(0, 0, k, g), M = C.data;
|
|
1809
|
+
for (let P = 0; P < g; P++) {
|
|
1810
|
+
const v = Math.floor(P / g * S);
|
|
1811
|
+
for (let A = 0; A < k; A++) {
|
|
1812
|
+
const I = Math.floor(A / k * p), E = y[(v * p + I) * 4 + 3] / 255, R = (P * k + A) * 4;
|
|
1813
|
+
M[R + 3] = Math.round(M[R + 3] * (1 - E * b));
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
T.putImageData(C, 0, 0);
|
|
1817
|
+
} else
|
|
1818
|
+
T.globalCompositeOperation = "destination-out", T.globalAlpha = t.intensity / 100, T.drawImage(o.alphaMask, 0, 0, k, g), T.globalCompositeOperation = "source-over";
|
|
1819
|
+
T.globalAlpha = 1, e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.clearRect(h, d, u, f), n && (e.fillStyle = n, e.fillRect(h, d, u, f)), e.drawImage(m, h, d), e.restore();
|
|
1820
|
+
}
|
|
1821
|
+
function pe(e, t, r, n) {
|
|
1822
|
+
if (!t.enabled || t.style !== "custom" || !t.textureUrl) return;
|
|
1823
|
+
const o = He(t.textureUrl);
|
|
1824
|
+
if (!o) {
|
|
1825
|
+
n(e);
|
|
1826
|
+
return;
|
|
1827
|
+
}
|
|
1828
|
+
const i = t.textureOpacity ?? t.intensity / 100, s = e.getTransform(), l = Math.sqrt(r.width ** 2 + r.height ** 2), a = (l - r.width) / 2, c = (l - r.height) / 2, h = 20, d = a + h, u = c + h, f = {
|
|
1829
|
+
x: r.x - d,
|
|
1830
|
+
y: r.y - u,
|
|
1831
|
+
width: r.width + d * 2,
|
|
1832
|
+
height: r.height + u * 2
|
|
1833
|
+
}, k = s.a * f.x + s.e, g = s.d * f.y + s.f, m = s.a * f.width, T = s.d * f.height, w = Math.ceil(m), b = Math.ceil(T);
|
|
1834
|
+
if (w <= 0 || b <= 0) {
|
|
1835
|
+
n(e);
|
|
1836
|
+
return;
|
|
1837
|
+
}
|
|
1838
|
+
const y = Ne(w, b), p = y.getContext("2d");
|
|
1839
|
+
if (!p) {
|
|
1840
|
+
n(e);
|
|
1841
|
+
return;
|
|
1842
|
+
}
|
|
1843
|
+
p.setTransform(
|
|
1844
|
+
s.a,
|
|
1845
|
+
s.b,
|
|
1846
|
+
s.c,
|
|
1847
|
+
s.d,
|
|
1848
|
+
s.e - k,
|
|
1849
|
+
s.f - g
|
|
1850
|
+
), n(p), p.setTransform(1, 0, 0, 1, 0, 0);
|
|
1851
|
+
const S = o.alphaMask.getContext("2d");
|
|
1852
|
+
if (S) {
|
|
1853
|
+
const C = S.getImageData(0, 0, o.width, o.height).data, M = o.width, P = o.height, v = p.getImageData(0, 0, w, b), A = v.data;
|
|
1854
|
+
for (let I = 0; I < b; I++) {
|
|
1855
|
+
const E = Math.floor(I / b * P);
|
|
1856
|
+
for (let R = 0; R < w; R++) {
|
|
1857
|
+
const W = Math.floor(R / w * M), F = C[(E * M + W) * 4 + 3] / 255, B = (I * w + R) * 4;
|
|
1858
|
+
A[B + 3] = Math.round(A[B + 3] * (1 - F * i));
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1861
|
+
p.putImageData(v, 0, 0);
|
|
1862
|
+
} else
|
|
1863
|
+
p.globalCompositeOperation = "destination-out", p.globalAlpha = i, p.drawImage(o.alphaMask, 0, 0, w, b), p.globalCompositeOperation = "source-over", p.globalAlpha = 1;
|
|
1864
|
+
e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(y, k, g), e.restore();
|
|
1865
|
+
}
|
|
1866
|
+
class yt {
|
|
1867
|
+
/**
|
|
1868
|
+
* Create an element instance from a JSON configuration
|
|
1869
|
+
* TypeScript ensures all transform types are handled
|
|
1870
|
+
*
|
|
1871
|
+
* @param config - Element configuration object
|
|
1872
|
+
* @returns BaseElement instance (TextElement, ImageElement, GroupElement, ShapeElement, or PathElement)
|
|
1873
|
+
* @throws Error if transform type is unknown
|
|
1874
|
+
*/
|
|
1875
|
+
static createFromJSON(t) {
|
|
1876
|
+
const { transformType: r } = t;
|
|
1877
|
+
switch (r) {
|
|
1878
|
+
case "custom":
|
|
1879
|
+
return new cr(t);
|
|
1880
|
+
case "distort":
|
|
1881
|
+
throw new Error("DistortTransform is not yet implemented");
|
|
1882
|
+
case "circle":
|
|
1883
|
+
return new lr(t);
|
|
1884
|
+
case "lean":
|
|
1885
|
+
return new ir(t);
|
|
1886
|
+
case "arch":
|
|
1887
|
+
return new ar(t);
|
|
1888
|
+
case "ascend":
|
|
1889
|
+
return new sr(t);
|
|
1890
|
+
case "wave":
|
|
1891
|
+
return new or(t);
|
|
1892
|
+
case "flag":
|
|
1893
|
+
return new nr(t);
|
|
1894
|
+
case "image":
|
|
1895
|
+
return new At(t);
|
|
1896
|
+
case "group": {
|
|
1897
|
+
const o = (t.children || []).map(
|
|
1898
|
+
(a) => yt.createFromJSON(a)
|
|
1899
|
+
), { children: i, ...s } = t, l = new ve(s);
|
|
1900
|
+
return o.forEach((a) => l.addChild(a)), l;
|
|
1901
|
+
}
|
|
1902
|
+
case "shape":
|
|
1903
|
+
return new rr(t);
|
|
1904
|
+
case "path":
|
|
1905
|
+
return new er(t);
|
|
1906
|
+
default:
|
|
1907
|
+
const n = r;
|
|
1908
|
+
throw new Error(`Unknown transform type: ${n}`);
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
/**
|
|
1912
|
+
* Create multiple elements from an array of JSON configurations
|
|
1913
|
+
* Useful for bulk deserialization (e.g., loading a document from DB)
|
|
1914
|
+
*
|
|
1915
|
+
* @param configs - Array of element configurations
|
|
1916
|
+
* @returns Array of BaseElement instances
|
|
1917
|
+
*/
|
|
1918
|
+
static createManyFromJSON(t) {
|
|
1919
|
+
return t.map((r) => this.createFromJSON(r));
|
|
1920
|
+
}
|
|
1921
|
+
/**
|
|
1922
|
+
* Type guard to check if an object is a valid TextElement instance
|
|
1923
|
+
* Useful for runtime validation
|
|
1924
|
+
*
|
|
1925
|
+
* @param obj - Object to check
|
|
1926
|
+
* @returns true if obj is a TextElement
|
|
1927
|
+
*/
|
|
1928
|
+
static isTextElement(t) {
|
|
1929
|
+
const r = t;
|
|
1930
|
+
return !!t && typeof t == "object" && typeof r.id == "string" && typeof r.transformType == "string" && typeof r.getBoundingBox == "function" && typeof r.getVisualBoundingBox == "function" && typeof r.hitTest == "function" && typeof r.render == "function" && typeof r.toJSON == "function" && typeof r.clone == "function";
|
|
1931
|
+
}
|
|
1932
|
+
/**
|
|
1933
|
+
* Validate an element configuration object
|
|
1934
|
+
* Returns true if the config has all required properties
|
|
1935
|
+
*
|
|
1936
|
+
* @param config - Configuration to validate
|
|
1937
|
+
* @returns true if valid
|
|
1938
|
+
*/
|
|
1939
|
+
static isValidConfig(t) {
|
|
1940
|
+
const r = t;
|
|
1941
|
+
return !!t && typeof t == "object" && typeof r.transformType == "string" && (r.id === void 0 || typeof r.id == "string");
|
|
1942
|
+
}
|
|
1943
|
+
/**
|
|
1944
|
+
* Create a default element of a given type
|
|
1945
|
+
* Useful for UI "Add Element" buttons
|
|
1946
|
+
*
|
|
1947
|
+
* @param transformType - Type of transform to create
|
|
1948
|
+
* @returns Default element configuration
|
|
1949
|
+
*/
|
|
1950
|
+
static createDefaultConfig(t) {
|
|
1951
|
+
const r = {
|
|
1952
|
+
id: `${t}-${Date.now()}`,
|
|
1953
|
+
x: window.innerWidth / 2,
|
|
1954
|
+
y: window.innerHeight / 2,
|
|
1955
|
+
rotation: 0
|
|
1956
|
+
};
|
|
1957
|
+
switch (t) {
|
|
1958
|
+
case "custom":
|
|
1959
|
+
return {
|
|
1960
|
+
...r,
|
|
1961
|
+
transformType: "custom",
|
|
1962
|
+
text: "Custom Text",
|
|
1963
|
+
transformData: {
|
|
1964
|
+
type: "custom",
|
|
1965
|
+
controlPoints: []
|
|
1966
|
+
}
|
|
1967
|
+
};
|
|
1968
|
+
case "distort":
|
|
1969
|
+
return {
|
|
1970
|
+
...r,
|
|
1971
|
+
transformType: "distort",
|
|
1972
|
+
text: "Distorted Text",
|
|
1973
|
+
transformData: {
|
|
1974
|
+
type: "distort"
|
|
1975
|
+
}
|
|
1976
|
+
};
|
|
1977
|
+
case "circle":
|
|
1978
|
+
return {
|
|
1979
|
+
...r,
|
|
1980
|
+
transformType: "circle",
|
|
1981
|
+
text: "Circular Text",
|
|
1982
|
+
transformData: {
|
|
1983
|
+
type: "circle",
|
|
1984
|
+
radius: 100,
|
|
1985
|
+
scale: 1,
|
|
1986
|
+
reverse: !1
|
|
1987
|
+
}
|
|
1988
|
+
};
|
|
1989
|
+
case "lean":
|
|
1990
|
+
return {
|
|
1991
|
+
...r,
|
|
1992
|
+
transformType: "lean",
|
|
1993
|
+
text: "Leaning Text",
|
|
1994
|
+
transformData: {
|
|
1995
|
+
type: "lean",
|
|
1996
|
+
leanAmount: 0
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1999
|
+
case "arch":
|
|
2000
|
+
return {
|
|
2001
|
+
...r,
|
|
2002
|
+
transformType: "arch",
|
|
2003
|
+
text: "Arched Text",
|
|
2004
|
+
transformData: {
|
|
2005
|
+
type: "arch",
|
|
2006
|
+
archHeight: 0.5
|
|
2007
|
+
}
|
|
2008
|
+
};
|
|
2009
|
+
case "ascend":
|
|
2010
|
+
return {
|
|
2011
|
+
...r,
|
|
2012
|
+
transformType: "ascend",
|
|
2013
|
+
text: "Ascending Text",
|
|
2014
|
+
transformData: {
|
|
2015
|
+
type: "ascend",
|
|
2016
|
+
ascendAngle: -15
|
|
2017
|
+
}
|
|
2018
|
+
};
|
|
2019
|
+
case "wave":
|
|
2020
|
+
return {
|
|
2021
|
+
...r,
|
|
2022
|
+
transformType: "wave",
|
|
2023
|
+
text: "Wavy Text",
|
|
2024
|
+
transformData: {
|
|
2025
|
+
type: "wave",
|
|
2026
|
+
amplitude: 0.5,
|
|
2027
|
+
frequency: 2
|
|
2028
|
+
}
|
|
2029
|
+
};
|
|
2030
|
+
case "flag":
|
|
2031
|
+
return {
|
|
2032
|
+
...r,
|
|
2033
|
+
transformType: "flag",
|
|
2034
|
+
text: "Flag Text",
|
|
2035
|
+
transformData: {
|
|
2036
|
+
type: "flag",
|
|
2037
|
+
amplitude: 0.5,
|
|
2038
|
+
frequency: 2
|
|
2039
|
+
}
|
|
2040
|
+
};
|
|
2041
|
+
case "image":
|
|
2042
|
+
return {
|
|
2043
|
+
...r,
|
|
2044
|
+
transformType: "image",
|
|
2045
|
+
imageUrl: "",
|
|
2046
|
+
transformData: {
|
|
2047
|
+
type: "image",
|
|
2048
|
+
width: 200,
|
|
2049
|
+
height: 200,
|
|
2050
|
+
cropX: 0,
|
|
2051
|
+
cropY: 0,
|
|
2052
|
+
cropWidth: 1,
|
|
2053
|
+
cropHeight: 1,
|
|
2054
|
+
flipHorizontal: !1,
|
|
2055
|
+
flipVertical: !1,
|
|
2056
|
+
borderRadius: 0
|
|
2057
|
+
}
|
|
2058
|
+
};
|
|
2059
|
+
case "group":
|
|
2060
|
+
return {
|
|
2061
|
+
...r,
|
|
2062
|
+
transformType: "group",
|
|
2063
|
+
children: [],
|
|
2064
|
+
transformData: {
|
|
2065
|
+
type: "group"
|
|
2066
|
+
}
|
|
2067
|
+
};
|
|
2068
|
+
case "shape":
|
|
2069
|
+
return {
|
|
2070
|
+
...r,
|
|
2071
|
+
transformType: "shape",
|
|
2072
|
+
transformData: {
|
|
2073
|
+
type: "shape",
|
|
2074
|
+
shapeType: "rectangle",
|
|
2075
|
+
width: 200,
|
|
2076
|
+
height: 200,
|
|
2077
|
+
borderRadius: 0,
|
|
2078
|
+
fillColor: "#3b82f6",
|
|
2079
|
+
fillOpacity: 1
|
|
2080
|
+
}
|
|
2081
|
+
};
|
|
2082
|
+
case "path":
|
|
2083
|
+
return {
|
|
2084
|
+
...r,
|
|
2085
|
+
transformType: "path",
|
|
2086
|
+
transformData: {
|
|
2087
|
+
type: "path",
|
|
2088
|
+
points: [],
|
|
2089
|
+
closed: !1,
|
|
2090
|
+
width: 200,
|
|
2091
|
+
height: 200,
|
|
2092
|
+
fillEnabled: !1,
|
|
2093
|
+
fillColor: "#3b82f6",
|
|
2094
|
+
fillOpacity: 1,
|
|
2095
|
+
strokeEnabled: !0,
|
|
2096
|
+
strokeColor: "#000000",
|
|
2097
|
+
strokeWidth: 2
|
|
2098
|
+
}
|
|
2099
|
+
};
|
|
2100
|
+
case "artboard":
|
|
2101
|
+
throw new Error("Artboards cannot be created via ElementFactory");
|
|
2102
|
+
default:
|
|
2103
|
+
const n = t;
|
|
2104
|
+
throw new Error(`Unknown transform type: ${n}`);
|
|
2105
|
+
}
|
|
2106
|
+
}
|
|
2107
|
+
/**
|
|
2108
|
+
* Clone an element by serializing and deserializing
|
|
2109
|
+
* Ensures a deep copy with proper class instance
|
|
2110
|
+
*
|
|
2111
|
+
* @param element - Element to clone
|
|
2112
|
+
* @returns Cloned element instance
|
|
2113
|
+
*/
|
|
2114
|
+
static clone(t) {
|
|
2115
|
+
const r = t.toJSON();
|
|
2116
|
+
return this.createFromJSON(r);
|
|
2117
|
+
}
|
|
2118
|
+
}
|
|
2119
|
+
const me = j("ImportManager"), Zt = class Zt {
|
|
2120
|
+
/**
|
|
2121
|
+
* Import workspace from JSON file
|
|
2122
|
+
*/
|
|
2123
|
+
static async importFromJSON(t) {
|
|
2124
|
+
try {
|
|
2125
|
+
const r = await this.readFileAsText(t), n = JSON.parse(r);
|
|
2126
|
+
if (this.validateDocument(n), !this.SUPPORTED_VERSIONS.includes(n.metadata.version))
|
|
2127
|
+
throw new Error(
|
|
2128
|
+
`Unsupported version: ${n.metadata.version}. Supported versions: ${this.SUPPORTED_VERSIONS.join(", ")}`
|
|
2129
|
+
);
|
|
2130
|
+
if (n.metadata.version === "1.0.0")
|
|
2131
|
+
return this.migrateV1Document(n);
|
|
2132
|
+
const o = [], i = [];
|
|
2133
|
+
return n.artboards.forEach((s) => {
|
|
2134
|
+
const l = xt.fromJSON({
|
|
2135
|
+
id: s.id,
|
|
2136
|
+
name: s.name,
|
|
2137
|
+
x: s.x,
|
|
2138
|
+
y: s.y,
|
|
2139
|
+
width: s.width,
|
|
2140
|
+
height: s.height,
|
|
2141
|
+
backgroundColor: s.backgroundColor,
|
|
2142
|
+
elementIds: s.elements.map((c) => c.id || "")
|
|
2143
|
+
}), a = s.elements.map((c) => {
|
|
2144
|
+
try {
|
|
2145
|
+
return yt.createFromJSON(c);
|
|
2146
|
+
} catch (h) {
|
|
2147
|
+
return me.error("Failed to create element:", c, h), null;
|
|
2148
|
+
}
|
|
2149
|
+
}).filter((c) => c !== null);
|
|
2150
|
+
o.push(l), i.push(...a);
|
|
2151
|
+
}), await this.preloadAllImages(i), {
|
|
2152
|
+
success: !0,
|
|
2153
|
+
artboards: o,
|
|
2154
|
+
elements: i,
|
|
2155
|
+
activeArtboardId: n.activeArtboardId
|
|
2156
|
+
};
|
|
2157
|
+
} catch (r) {
|
|
2158
|
+
return {
|
|
2159
|
+
success: !1,
|
|
2160
|
+
error: r instanceof Error ? r.message : "Unknown error"
|
|
2161
|
+
};
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
/**
|
|
2165
|
+
* Migrate v1 document (no artboards) to v2 (with artboards)
|
|
2166
|
+
*/
|
|
2167
|
+
static async migrateV1Document(t) {
|
|
2168
|
+
var r, n, o;
|
|
2169
|
+
try {
|
|
2170
|
+
const i = t.elements || [], s = new xt({
|
|
2171
|
+
id: "artboard-migrated",
|
|
2172
|
+
name: "Artboard 1",
|
|
2173
|
+
x: 0,
|
|
2174
|
+
y: 0,
|
|
2175
|
+
width: ((r = t.canvas) == null ? void 0 : r.width) || 1920,
|
|
2176
|
+
height: ((n = t.canvas) == null ? void 0 : n.height) || 1080,
|
|
2177
|
+
backgroundColor: ((o = t.canvas) == null ? void 0 : o.backgroundColor) || "#ffffff"
|
|
2178
|
+
}), l = i.map((a) => {
|
|
2179
|
+
try {
|
|
2180
|
+
return yt.createFromJSON(a);
|
|
2181
|
+
} catch (c) {
|
|
2182
|
+
return me.error("Failed to create element:", a, c), null;
|
|
2183
|
+
}
|
|
2184
|
+
}).filter((a) => a !== null);
|
|
2185
|
+
return l.forEach((a) => {
|
|
2186
|
+
s.addElementId(a.id);
|
|
2187
|
+
}), await this.preloadAllImages(l), {
|
|
2188
|
+
success: !0,
|
|
2189
|
+
artboards: [s],
|
|
2190
|
+
elements: l,
|
|
2191
|
+
activeArtboardId: s.id
|
|
2192
|
+
};
|
|
2193
|
+
} catch (i) {
|
|
2194
|
+
return {
|
|
2195
|
+
success: !1,
|
|
2196
|
+
error: i instanceof Error ? i.message : "Migration failed"
|
|
2197
|
+
};
|
|
2198
|
+
}
|
|
2199
|
+
}
|
|
2200
|
+
/**
|
|
2201
|
+
* Import image file
|
|
2202
|
+
*/
|
|
2203
|
+
static async importImage(t) {
|
|
2204
|
+
try {
|
|
2205
|
+
if (!t.type.startsWith("image/"))
|
|
2206
|
+
throw new Error("File is not an image");
|
|
2207
|
+
const r = 10 * 1024 * 1024;
|
|
2208
|
+
if (t.size > r)
|
|
2209
|
+
throw new Error("Image file is too large (max 10MB)");
|
|
2210
|
+
const n = await this.readFileAsDataURL(t), { width: o, height: i } = await this.getImageDimensions(n);
|
|
2211
|
+
return {
|
|
2212
|
+
success: !0,
|
|
2213
|
+
dataUrl: n,
|
|
2214
|
+
filename: t.name,
|
|
2215
|
+
width: o,
|
|
2216
|
+
height: i
|
|
2217
|
+
};
|
|
2218
|
+
} catch (r) {
|
|
2219
|
+
return {
|
|
2220
|
+
success: !1,
|
|
2221
|
+
error: r instanceof Error ? r.message : "Unknown error"
|
|
2222
|
+
};
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
/**
|
|
2226
|
+
* Validate document structure
|
|
2227
|
+
*/
|
|
2228
|
+
static validateDocument(t) {
|
|
2229
|
+
if (!t || typeof t != "object")
|
|
2230
|
+
throw new Error("Invalid document");
|
|
2231
|
+
const r = t;
|
|
2232
|
+
if (!r.metadata)
|
|
2233
|
+
throw new Error("Missing metadata");
|
|
2234
|
+
if (!r.metadata.version)
|
|
2235
|
+
throw new Error("Missing version in metadata");
|
|
2236
|
+
if (!r.artboards && !r.elements)
|
|
2237
|
+
throw new Error("Missing artboards or elements array");
|
|
2238
|
+
if (r.artboards && !Array.isArray(r.artboards))
|
|
2239
|
+
throw new Error("Invalid artboards array");
|
|
2240
|
+
}
|
|
2241
|
+
/**
|
|
2242
|
+
* Read file as text
|
|
2243
|
+
*/
|
|
2244
|
+
static readFileAsText(t) {
|
|
2245
|
+
return new Promise((r, n) => {
|
|
2246
|
+
const o = new FileReader();
|
|
2247
|
+
o.onload = (i) => {
|
|
2248
|
+
var s;
|
|
2249
|
+
return r((s = i.target) == null ? void 0 : s.result);
|
|
2250
|
+
}, o.onerror = () => n(new Error("Failed to read file")), o.readAsText(t);
|
|
2251
|
+
});
|
|
2252
|
+
}
|
|
2253
|
+
/**
|
|
2254
|
+
* Read file as data URL
|
|
2255
|
+
*/
|
|
2256
|
+
static readFileAsDataURL(t) {
|
|
2257
|
+
return new Promise((r, n) => {
|
|
2258
|
+
const o = new FileReader();
|
|
2259
|
+
o.onload = (i) => {
|
|
2260
|
+
var s;
|
|
2261
|
+
return r((s = i.target) == null ? void 0 : s.result);
|
|
2262
|
+
}, o.onerror = () => n(new Error("Failed to read file")), o.readAsDataURL(t);
|
|
2263
|
+
});
|
|
2264
|
+
}
|
|
2265
|
+
/**
|
|
2266
|
+
* Get image dimensions from data URL
|
|
2267
|
+
*/
|
|
2268
|
+
static getImageDimensions(t) {
|
|
2269
|
+
return new Promise((r, n) => {
|
|
2270
|
+
const o = new Image();
|
|
2271
|
+
o.onload = () => {
|
|
2272
|
+
r({ width: o.width, height: o.height });
|
|
2273
|
+
}, o.onerror = () => n(new Error("Failed to load image")), o.src = t;
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2276
|
+
/**
|
|
2277
|
+
* Validate imported data before applying to state
|
|
2278
|
+
*/
|
|
2279
|
+
static validateImportedData(t, r) {
|
|
2280
|
+
const n = [], o = /* @__PURE__ */ new Set();
|
|
2281
|
+
t.forEach((s) => {
|
|
2282
|
+
o.has(s.id) && n.push(`Duplicate artboard ID: ${s.id}`), o.add(s.id);
|
|
2283
|
+
});
|
|
2284
|
+
const i = /* @__PURE__ */ new Set();
|
|
2285
|
+
return r.forEach((s) => {
|
|
2286
|
+
i.has(s.id) && n.push(`Duplicate element ID: ${s.id}`), i.add(s.id);
|
|
2287
|
+
}), t.forEach((s) => {
|
|
2288
|
+
s.getElementIds().forEach((l) => {
|
|
2289
|
+
i.has(l) || n.push(`Artboard "${s.name}" references missing element: ${l}`);
|
|
2290
|
+
});
|
|
2291
|
+
}), {
|
|
2292
|
+
valid: n.length === 0,
|
|
2293
|
+
errors: n
|
|
2294
|
+
};
|
|
2295
|
+
}
|
|
2296
|
+
/**
|
|
2297
|
+
* Get import summary (for UI display before confirming)
|
|
2298
|
+
*/
|
|
2299
|
+
static getImportSummary(t, r) {
|
|
2300
|
+
const n = this.validateImportedData(t, r);
|
|
2301
|
+
return {
|
|
2302
|
+
artboardCount: t.length,
|
|
2303
|
+
elementCount: r.length,
|
|
2304
|
+
artboardNames: t.map((o) => o.name),
|
|
2305
|
+
warnings: n.errors
|
|
2306
|
+
};
|
|
2307
|
+
}
|
|
2308
|
+
/**
|
|
2309
|
+
* Preload all images in parallel for fast artboard switching
|
|
2310
|
+
* Recursively finds all ImageElements (including those in groups)
|
|
2311
|
+
*/
|
|
2312
|
+
static async preloadAllImages(t) {
|
|
2313
|
+
const r = [], n = (i) => {
|
|
2314
|
+
i.transformType === "image" ? r.push(i) : i.transformType === "group" && "children" in i && i.children.forEach((s) => n(s));
|
|
2315
|
+
};
|
|
2316
|
+
t.forEach(n);
|
|
2317
|
+
const o = r.map((i) => new Promise((s) => {
|
|
2318
|
+
if (i.imageLoaded)
|
|
2319
|
+
s();
|
|
2320
|
+
else if (i.imageElement) {
|
|
2321
|
+
const l = i.imageElement, a = () => {
|
|
2322
|
+
l.removeEventListener("load", a), l.removeEventListener("error", c), s();
|
|
2323
|
+
}, c = () => {
|
|
2324
|
+
l.removeEventListener("load", a), l.removeEventListener("error", c), s();
|
|
2325
|
+
};
|
|
2326
|
+
l.addEventListener("load", a), l.addEventListener("error", c);
|
|
2327
|
+
} else
|
|
2328
|
+
s();
|
|
2329
|
+
}));
|
|
2330
|
+
await Promise.all(o);
|
|
2331
|
+
}
|
|
2332
|
+
};
|
|
2333
|
+
Zt.SUPPORTED_VERSIONS = ["1.0.0", "2.0.0"];
|
|
2334
|
+
let ye = Zt;
|
|
2335
|
+
const we = j("element-serializer"), Xe = 4e3, ft = /* @__PURE__ */ new Set();
|
|
2336
|
+
function An(e, t) {
|
|
2337
|
+
const r = t ? Rn(t) : "no-src";
|
|
2338
|
+
return `${e}:${r}`;
|
|
2339
|
+
}
|
|
2340
|
+
function Rn(e) {
|
|
2341
|
+
let t = 0;
|
|
2342
|
+
for (let r = 0; r < e.length; r++) {
|
|
2343
|
+
const n = e.charCodeAt(r);
|
|
2344
|
+
t = (t << 5) - t + n, t = t & t;
|
|
2345
|
+
}
|
|
2346
|
+
return t.toString(36);
|
|
2347
|
+
}
|
|
2348
|
+
function Ht() {
|
|
2349
|
+
ft.clear();
|
|
2350
|
+
}
|
|
2351
|
+
function _e(e) {
|
|
2352
|
+
for (const t of ft)
|
|
2353
|
+
t.startsWith(`${e}:`) && ft.delete(t);
|
|
2354
|
+
}
|
|
2355
|
+
function Wn(e) {
|
|
2356
|
+
ft.add(e);
|
|
2357
|
+
}
|
|
2358
|
+
function Fn(e) {
|
|
2359
|
+
return ft.has(e);
|
|
2360
|
+
}
|
|
2361
|
+
async function Bn(e, t = Xe) {
|
|
2362
|
+
const { naturalWidth: r, naturalHeight: n } = e;
|
|
2363
|
+
if (r <= t && n <= t)
|
|
2364
|
+
return createImageBitmap(e);
|
|
2365
|
+
const o = t / Math.max(r, n), i = Math.round(r * o), s = Math.round(n * o);
|
|
2366
|
+
return createImageBitmap(e, {
|
|
2367
|
+
resizeWidth: i,
|
|
2368
|
+
resizeHeight: s,
|
|
2369
|
+
resizeQuality: "high"
|
|
2370
|
+
});
|
|
2371
|
+
}
|
|
2372
|
+
let wt = null, kt = null;
|
|
2373
|
+
function Un(e, t) {
|
|
2374
|
+
wt = e, kt = t;
|
|
2375
|
+
}
|
|
2376
|
+
function On() {
|
|
2377
|
+
wt = null, kt = null;
|
|
2378
|
+
}
|
|
2379
|
+
function to() {
|
|
2380
|
+
Ht(), wt && wt();
|
|
2381
|
+
}
|
|
2382
|
+
function eo(e) {
|
|
2383
|
+
_e(e), kt && kt(e);
|
|
2384
|
+
}
|
|
2385
|
+
function jt(e, t) {
|
|
2386
|
+
const r = e;
|
|
2387
|
+
if (typeof r.fontFamily == "string" && t.add(r.fontFamily), r.richText && typeof r.richText == "object") {
|
|
2388
|
+
const n = r.richText;
|
|
2389
|
+
if (n.spans && Array.isArray(n.spans))
|
|
2390
|
+
for (const o of n.spans) {
|
|
2391
|
+
const i = o;
|
|
2392
|
+
if (i.style && typeof i.style == "object") {
|
|
2393
|
+
const s = i.style;
|
|
2394
|
+
typeof s.fontFamily == "string" && t.add(s.fontFamily);
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
if (r.children && Array.isArray(r.children))
|
|
2399
|
+
for (const n of r.children)
|
|
2400
|
+
jt(n, t);
|
|
2401
|
+
if (e.masks && Array.isArray(e.masks))
|
|
2402
|
+
for (const n of e.masks)
|
|
2403
|
+
n.maskElement && jt(n.maskElement, t);
|
|
2404
|
+
}
|
|
2405
|
+
function ke(e) {
|
|
2406
|
+
if (typeof document > "u") return e;
|
|
2407
|
+
const t = Tt.getInstance();
|
|
2408
|
+
return e.map((r) => {
|
|
2409
|
+
if (!(r != null && r.maskElement) || r.maskElement.transformType !== "image") return r;
|
|
2410
|
+
const n = r.maskElement.imageUrl;
|
|
2411
|
+
if (!n || !n.startsWith("builtin-mask:")) return r;
|
|
2412
|
+
const o = t.get(n);
|
|
2413
|
+
return o != null && o.src && o.src.startsWith("data:") ? {
|
|
2414
|
+
...r,
|
|
2415
|
+
maskElement: {
|
|
2416
|
+
...r.maskElement,
|
|
2417
|
+
imageUrl: o.src
|
|
2418
|
+
// Replace with data URL
|
|
2419
|
+
}
|
|
2420
|
+
} : r;
|
|
2421
|
+
});
|
|
2422
|
+
}
|
|
2423
|
+
async function be(e, t, r = Xe) {
|
|
2424
|
+
const n = t.filter((a) => e.hasElementId(a.id)), o = [], i = [], s = /* @__PURE__ */ new Set();
|
|
2425
|
+
for (const a of n) {
|
|
2426
|
+
const c = a.toJSON();
|
|
2427
|
+
if (jt(c, s), a instanceof At && !a.imageElement) {
|
|
2428
|
+
we.warn(`[element-serializer] Skipping image ${a.id}: image not loaded (state: ${a.imageLoadState})`);
|
|
2429
|
+
continue;
|
|
2430
|
+
}
|
|
2431
|
+
if (a instanceof At && a.imageElement)
|
|
2432
|
+
try {
|
|
2433
|
+
const h = An(a.id, a.imageUrl);
|
|
2434
|
+
if (!Fn(h)) {
|
|
2435
|
+
const b = await Bn(a.imageElement, r);
|
|
2436
|
+
i.push({ cacheKey: h, bitmap: b }), Wn(h);
|
|
2437
|
+
}
|
|
2438
|
+
const u = a.transformData || {}, f = c.masks && c.masks.length > 0, k = f ? u.width : u.width * (u.cropWidth ?? 1), g = f ? u.height : u.height * (u.cropHeight ?? 1), m = {
|
|
2439
|
+
id: a.id,
|
|
2440
|
+
type: "image",
|
|
2441
|
+
x: a.x,
|
|
2442
|
+
y: a.y,
|
|
2443
|
+
width: k,
|
|
2444
|
+
height: g,
|
|
2445
|
+
rotation: a.rotation || 0,
|
|
2446
|
+
bitmapCacheKey: h
|
|
2447
|
+
};
|
|
2448
|
+
if (!f && (u.cropX !== 0 || u.cropY !== 0 || u.cropWidth !== 1 || u.cropHeight !== 1)) {
|
|
2449
|
+
const b = a.imageElement.naturalWidth, y = a.imageElement.naturalHeight;
|
|
2450
|
+
let p = 1;
|
|
2451
|
+
(b > r || y > r) && (p = r / Math.max(b, y)), m.cropX = u.cropX * b * p, m.cropY = u.cropY * y * p, m.cropWidth = u.cropWidth * b * p, m.cropHeight = u.cropHeight * y * p;
|
|
2452
|
+
}
|
|
2453
|
+
u.flipHorizontal && (m.flipHorizontal = u.flipHorizontal), u.flipVertical && (m.flipVertical = u.flipVertical), u.borderRadius && (m.borderRadius = u.borderRadius), hr(u.adjustments) || (m.adjustments = { ...u.adjustments }), a.opacity !== void 0 && (m.opacity = a.opacity);
|
|
2454
|
+
const w = m;
|
|
2455
|
+
a.distressEffect && (w.distressEffect = { ...a.distressEffect }), c.masks && c.masks.length > 0 && (w.masks = ke(c.masks)), c.blendMode && (w.blendMode = c.blendMode), c.knockoutParts && (w.knockoutParts = c.knockoutParts), c.shadow && (w.shadow = { ...c.shadow }), "getVisualBoundingBox" in a && typeof a.getVisualBoundingBox == "function" ? w._boundingBox = a.getVisualBoundingBox() : "getBoundingBox" in a && typeof a.getBoundingBox == "function" && (w._boundingBox = a.getBoundingBox()), o.push(w);
|
|
2456
|
+
} catch (h) {
|
|
2457
|
+
we.error(`[element-serializer] Failed to create ImageBitmap for ${c.id}:`, h);
|
|
2458
|
+
}
|
|
2459
|
+
else {
|
|
2460
|
+
const h = {
|
|
2461
|
+
...c,
|
|
2462
|
+
type: c.transformType
|
|
2463
|
+
// Map transformType to type for worker compatibility
|
|
2464
|
+
};
|
|
2465
|
+
h.masks && Array.isArray(h.masks) && h.masks.length > 0 && (h.masks = ke(h.masks)), "getVisualBoundingBox" in a && typeof a.getVisualBoundingBox == "function" ? h._boundingBox = a.getVisualBoundingBox() : "getBoundingBox" in a && typeof a.getBoundingBox == "function" && (h._boundingBox = a.getBoundingBox()), o.push(h);
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
const l = Array.from(s);
|
|
2469
|
+
return {
|
|
2470
|
+
data: {
|
|
2471
|
+
version: "1.0.0",
|
|
2472
|
+
artboard: {
|
|
2473
|
+
id: e.id,
|
|
2474
|
+
name: e.name,
|
|
2475
|
+
width: e.width,
|
|
2476
|
+
height: e.height,
|
|
2477
|
+
backgroundColor: e.backgroundColor,
|
|
2478
|
+
exportBackground: e.exportBackground,
|
|
2479
|
+
x: e.x,
|
|
2480
|
+
y: e.y,
|
|
2481
|
+
...e.distressTexture && { distressTexture: { ...e.distressTexture } },
|
|
2482
|
+
...e.imageMask && { imageMask: { ...e.imageMask } }
|
|
2483
|
+
},
|
|
2484
|
+
elements: o,
|
|
2485
|
+
fonts: l
|
|
2486
|
+
},
|
|
2487
|
+
newBitmaps: i
|
|
2488
|
+
};
|
|
2489
|
+
}
|
|
2490
|
+
async function Ln(e, t, r = fetch) {
|
|
2491
|
+
try {
|
|
2492
|
+
const n = await r(t.fontFileUrl, { mode: "cors" });
|
|
2493
|
+
if (!n.ok) return null;
|
|
2494
|
+
const o = await n.arrayBuffer(), i = new FontFace(e, o, t.descriptors);
|
|
2495
|
+
return await i.load(), i;
|
|
2496
|
+
} catch {
|
|
2497
|
+
return null;
|
|
2498
|
+
}
|
|
2499
|
+
}
|
|
2500
|
+
function K(e) {
|
|
2501
|
+
return e.trim().toLowerCase();
|
|
2502
|
+
}
|
|
2503
|
+
function zt(e) {
|
|
2504
|
+
return `${K(e.family)}|${e.weight ?? 400}|${e.style ?? "normal"}`;
|
|
2505
|
+
}
|
|
2506
|
+
class qn {
|
|
2507
|
+
constructor() {
|
|
2508
|
+
this.fonts = /* @__PURE__ */ new Map(), this.listeners = /* @__PURE__ */ new Set(), this.snapshot = [], this.list = () => this.snapshot, this.subscribe = (t) => (this.listeners.add(t), () => {
|
|
2509
|
+
this.listeners.delete(t);
|
|
2510
|
+
});
|
|
2511
|
+
}
|
|
2512
|
+
/**
|
|
2513
|
+
* Register fonts (idempotent; re-registering the same family/weight/style
|
|
2514
|
+
* replaces the URL). Returns true when anything changed.
|
|
2515
|
+
*/
|
|
2516
|
+
register(t) {
|
|
2517
|
+
let r = !1;
|
|
2518
|
+
for (const n of t) {
|
|
2519
|
+
const o = zt(n), i = this.fonts.get(o);
|
|
2520
|
+
i && i.url === n.url && i.family === n.family || (this.fonts.set(o, { ...n }), r = !0);
|
|
2521
|
+
}
|
|
2522
|
+
if (r) {
|
|
2523
|
+
this.snapshot = Object.freeze([...this.fonts.values()]);
|
|
2524
|
+
for (const n of this.listeners) n();
|
|
2525
|
+
}
|
|
2526
|
+
return r;
|
|
2527
|
+
}
|
|
2528
|
+
/** Is this family registered as a custom font? (Shadowing check.) */
|
|
2529
|
+
has(t) {
|
|
2530
|
+
const r = K(t);
|
|
2531
|
+
for (const n of this.fonts.values())
|
|
2532
|
+
if (K(n.family) === r) return !0;
|
|
2533
|
+
return !1;
|
|
2534
|
+
}
|
|
2535
|
+
/** All registered faces of one family (possibly several weights/styles). */
|
|
2536
|
+
facesOf(t) {
|
|
2537
|
+
const r = K(t);
|
|
2538
|
+
return [...this.fonts.values()].filter((n) => K(n.family) === r);
|
|
2539
|
+
}
|
|
2540
|
+
/** Registered faces whose family appears in `families` — what the export
|
|
2541
|
+
* path sends to the worker alongside the used-font list. */
|
|
2542
|
+
forFamilies(t) {
|
|
2543
|
+
const r = new Set(t.map(K));
|
|
2544
|
+
return [...this.fonts.values()].filter((n) => r.has(K(n.family)));
|
|
2545
|
+
}
|
|
2546
|
+
/** @internal Test helper — wipe registry state between tests. */
|
|
2547
|
+
clear() {
|
|
2548
|
+
this.fonts.clear(), this.snapshot = Object.freeze([]);
|
|
2549
|
+
for (const t of this.listeners) t();
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
const Nt = new qn();
|
|
2553
|
+
function $n(e) {
|
|
2554
|
+
Nt.register(e);
|
|
2555
|
+
}
|
|
2556
|
+
const Ge = /* @__PURE__ */ new Set();
|
|
2557
|
+
async function Hn(e, t = {}) {
|
|
2558
|
+
const r = await Ln(
|
|
2559
|
+
e.family,
|
|
2560
|
+
{
|
|
2561
|
+
fontFileUrl: e.url,
|
|
2562
|
+
descriptors: {
|
|
2563
|
+
weight: String(e.weight ?? 400),
|
|
2564
|
+
style: e.style ?? "normal"
|
|
2565
|
+
}
|
|
2566
|
+
},
|
|
2567
|
+
t.fetchImpl ?? fetch
|
|
2568
|
+
);
|
|
2569
|
+
if (!r)
|
|
2570
|
+
throw new Me(
|
|
2571
|
+
"E_FONT_LOAD_FAILED",
|
|
2572
|
+
`Custom font "${e.family}" failed to load from ${e.url}. The URL must serve the font binary over a plain cross-origin GET (CORS). Verify the URL is reachable and sends Access-Control-Allow-Origin, then re-register the font. Custom fonts never fall back silently — the design would render with the wrong typeface.`,
|
|
2573
|
+
{
|
|
2574
|
+
family: e.family,
|
|
2575
|
+
url: e.url,
|
|
2576
|
+
weight: e.weight ?? 400,
|
|
2577
|
+
style: e.style ?? "normal"
|
|
2578
|
+
}
|
|
2579
|
+
);
|
|
2580
|
+
const n = t.fonts ?? (typeof document < "u" ? document.fonts : void 0);
|
|
2581
|
+
return n == null || n.add(r), Ge.add(zt(e)), r;
|
|
2582
|
+
}
|
|
2583
|
+
async function ro(e, t = {}) {
|
|
2584
|
+
$n(e);
|
|
2585
|
+
const { onLoadError: r, ...n } = t;
|
|
2586
|
+
await Promise.all(
|
|
2587
|
+
e.map(async (o) => {
|
|
2588
|
+
if (!Ge.has(zt(o)))
|
|
2589
|
+
try {
|
|
2590
|
+
await Hn(o, n);
|
|
2591
|
+
} catch (i) {
|
|
2592
|
+
if (r && i instanceof Me) {
|
|
2593
|
+
r(i, o);
|
|
2594
|
+
return;
|
|
2595
|
+
}
|
|
2596
|
+
throw i;
|
|
2597
|
+
}
|
|
2598
|
+
})
|
|
2599
|
+
);
|
|
2600
|
+
}
|
|
2601
|
+
const O = j("WorkerExport");
|
|
2602
|
+
let Xt = null, It = null;
|
|
2603
|
+
function jn() {
|
|
2604
|
+
return It ?? (It = import("./export-worker.bundle.string-DXciOLDt.js").then((e) => Xt = e.default).catch((e) => {
|
|
2605
|
+
throw It = null, e;
|
|
2606
|
+
})), It;
|
|
2607
|
+
}
|
|
2608
|
+
class dt {
|
|
2609
|
+
constructor() {
|
|
2610
|
+
this.worker = null, this.workerBlobUrl = null, this.pendingRequests = /* @__PURE__ */ new Map(), this.requestQueue = [], this.blobRequestQueue = [], this.isProcessingQueue = !1, this.isReady = !1, this.readyPromise = null, this.initGeneration = 0, this.requestIdCounter = 0, this.workerCrashCount = 0, this.MAX_CRASHES_BEFORE_FALLBACK = 3, this.lastCrashTime = 0, this.CRASH_RESET_TIMEOUT = 6e4, this.progressListeners = /* @__PURE__ */ new Set(), this.idleTimeout = null, this.IDLE_TIMEOUT_MS = 3e4;
|
|
2611
|
+
}
|
|
2612
|
+
// 30 seconds
|
|
2613
|
+
/**
|
|
2614
|
+
* Add progress listener
|
|
2615
|
+
*/
|
|
2616
|
+
onProgress(t) {
|
|
2617
|
+
return this.progressListeners.add(t), () => {
|
|
2618
|
+
this.progressListeners.delete(t);
|
|
2619
|
+
};
|
|
2620
|
+
}
|
|
2621
|
+
/**
|
|
2622
|
+
* Remove progress listener
|
|
2623
|
+
*/
|
|
2624
|
+
offProgress(t) {
|
|
2625
|
+
this.progressListeners.delete(t);
|
|
2626
|
+
}
|
|
2627
|
+
/**
|
|
2628
|
+
* Emit progress event to all listeners
|
|
2629
|
+
*/
|
|
2630
|
+
emitProgress(t) {
|
|
2631
|
+
for (const r of this.progressListeners)
|
|
2632
|
+
try {
|
|
2633
|
+
r(t);
|
|
2634
|
+
} catch (n) {
|
|
2635
|
+
O.error("Error in progress listener:", n);
|
|
2636
|
+
}
|
|
2637
|
+
}
|
|
2638
|
+
/**
|
|
2639
|
+
* Reset idle timer
|
|
2640
|
+
*/
|
|
2641
|
+
resetIdleTimer() {
|
|
2642
|
+
this.idleTimeout && clearTimeout(this.idleTimeout), this.idleTimeout = window.setTimeout(() => {
|
|
2643
|
+
this.terminate();
|
|
2644
|
+
}, this.IDLE_TIMEOUT_MS);
|
|
2645
|
+
}
|
|
2646
|
+
// ============================================================================
|
|
2647
|
+
// Worker Bitmap Cache Management
|
|
2648
|
+
// ============================================================================
|
|
2649
|
+
/**
|
|
2650
|
+
* Register bitmaps with the worker's cache.
|
|
2651
|
+
* This transfers the bitmaps to the worker (zero-copy) where they are cached.
|
|
2652
|
+
*/
|
|
2653
|
+
registerBitmapsWithWorker(t) {
|
|
2654
|
+
if (!(!this.worker || t.length === 0))
|
|
2655
|
+
for (const { cacheKey: r, bitmap: n } of t) {
|
|
2656
|
+
const o = {
|
|
2657
|
+
type: "register-bitmap",
|
|
2658
|
+
cacheKey: r,
|
|
2659
|
+
bitmap: n
|
|
2660
|
+
};
|
|
2661
|
+
this.worker.postMessage(o, [n]);
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
/**
|
|
2665
|
+
* Clear all bitmaps from the worker's cache.
|
|
2666
|
+
* Also clears the main thread's registration tracking.
|
|
2667
|
+
* Call this when exiting editor mode to free memory.
|
|
2668
|
+
*/
|
|
2669
|
+
clearWorkerBitmapCache() {
|
|
2670
|
+
if (Ht(), this.worker && this.isReady) {
|
|
2671
|
+
const t = {
|
|
2672
|
+
type: "clear-all-bitmaps"
|
|
2673
|
+
};
|
|
2674
|
+
this.worker.postMessage(t);
|
|
2675
|
+
}
|
|
2676
|
+
}
|
|
2677
|
+
/**
|
|
2678
|
+
* Clear a specific element's bitmaps from the worker's cache.
|
|
2679
|
+
* Call this when an element is removed or its image source changes.
|
|
2680
|
+
*/
|
|
2681
|
+
clearWorkerBitmap(t) {
|
|
2682
|
+
if (_e(t), this.worker && this.isReady) {
|
|
2683
|
+
const r = {
|
|
2684
|
+
type: "clear-bitmap",
|
|
2685
|
+
elementId: t
|
|
2686
|
+
};
|
|
2687
|
+
this.worker.postMessage(r);
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
/**
|
|
2691
|
+
* Check if browser supports OffscreenCanvas and Web Workers
|
|
2692
|
+
*/
|
|
2693
|
+
static supportsWorkerExport() {
|
|
2694
|
+
try {
|
|
2695
|
+
return typeof OffscreenCanvas > "u" ? (O.warn("OffscreenCanvas not supported"), !1) : typeof Worker > "u" ? (O.warn("Web Workers not supported"), !1) : new OffscreenCanvas(1, 1).getContext("2d") ? !0 : (O.warn("OffscreenCanvas 2D context not supported"), !1);
|
|
2696
|
+
} catch (t) {
|
|
2697
|
+
return O.warn("Feature detection failed:", t), !1;
|
|
2698
|
+
}
|
|
2699
|
+
}
|
|
2700
|
+
/**
|
|
2701
|
+
* Initialize the worker
|
|
2702
|
+
*/
|
|
2703
|
+
async initialize() {
|
|
2704
|
+
if (this.worker)
|
|
2705
|
+
return this.readyPromise || Promise.resolve();
|
|
2706
|
+
if (this.readyPromise)
|
|
2707
|
+
return this.readyPromise;
|
|
2708
|
+
if (!dt.supportsWorkerExport())
|
|
2709
|
+
throw new Error("Browser does not support OffscreenCanvas or Web Workers");
|
|
2710
|
+
if (Xt !== null)
|
|
2711
|
+
return this.readyPromise = this.startWorker(Xt), this.readyPromise;
|
|
2712
|
+
const t = this.initGeneration, r = jn().then((n) => {
|
|
2713
|
+
if (t !== this.initGeneration)
|
|
2714
|
+
throw new Error("Worker terminated");
|
|
2715
|
+
return this.startWorker(n);
|
|
2716
|
+
});
|
|
2717
|
+
return this.readyPromise = r, r.catch(() => {
|
|
2718
|
+
this.readyPromise === r && !this.worker && (this.readyPromise = null);
|
|
2719
|
+
}), r;
|
|
2720
|
+
}
|
|
2721
|
+
/** Spawn the worker from its code and resolve once it reports `ready`. */
|
|
2722
|
+
startWorker(t) {
|
|
2723
|
+
return new Promise((r, n) => {
|
|
2724
|
+
try {
|
|
2725
|
+
let o;
|
|
2726
|
+
try {
|
|
2727
|
+
const l = new Blob([t], { type: "application/javascript" });
|
|
2728
|
+
o = URL.createObjectURL(l), this.workerBlobUrl = o;
|
|
2729
|
+
} catch (l) {
|
|
2730
|
+
O.error("Failed to create worker blob:", l), n(new Error(`Worker creation failed: ${l instanceof Error ? l.message : String(l)}`));
|
|
2731
|
+
return;
|
|
2732
|
+
}
|
|
2733
|
+
this.worker = new Worker(o, { type: "classic" }), this.worker.onmessage = (l) => {
|
|
2734
|
+
this.handleWorkerMessage(l.data);
|
|
2735
|
+
}, this.worker.onerror = (l) => {
|
|
2736
|
+
O.error("Worker error:", l), this.handleWorkerError(l);
|
|
2737
|
+
};
|
|
2738
|
+
const i = setTimeout(() => {
|
|
2739
|
+
n(new Error("Worker initialization timeout"));
|
|
2740
|
+
}, 15e3), s = (l) => {
|
|
2741
|
+
l.data.type === "ready" && (clearTimeout(i), this.isReady = !0, Un(
|
|
2742
|
+
() => this.clearWorkerBitmapCache(),
|
|
2743
|
+
(a) => this.clearWorkerBitmap(a)
|
|
2744
|
+
), r());
|
|
2745
|
+
};
|
|
2746
|
+
this.worker.addEventListener("message", s, { once: !0 });
|
|
2747
|
+
} catch (o) {
|
|
2748
|
+
O.error("Failed to create worker:", o), n(o);
|
|
2749
|
+
}
|
|
2750
|
+
});
|
|
2751
|
+
}
|
|
2752
|
+
/**
|
|
2753
|
+
* Restart worker after crash
|
|
2754
|
+
*/
|
|
2755
|
+
async restartWorker() {
|
|
2756
|
+
const t = Date.now();
|
|
2757
|
+
if (t - this.lastCrashTime > this.CRASH_RESET_TIMEOUT && (this.workerCrashCount = 0), this.workerCrashCount++, this.lastCrashTime = t, O.warn(`Worker crashed (${this.workerCrashCount}/${this.MAX_CRASHES_BEFORE_FALLBACK})`), this.workerCrashCount >= this.MAX_CRASHES_BEFORE_FALLBACK)
|
|
2758
|
+
throw O.error("Worker crashed too many times, giving up"), new Error("Worker has crashed too many times. Please refresh the page or use main thread export.");
|
|
2759
|
+
this.worker && (this.worker.terminate(), this.worker = null, this.isReady = !1, this.readyPromise = null, this.workerBlobUrl && (URL.revokeObjectURL(this.workerBlobUrl), this.workerBlobUrl = null));
|
|
2760
|
+
const r = Math.min(1e3 * Math.pow(2, this.workerCrashCount - 1), 5e3);
|
|
2761
|
+
await new Promise((n) => setTimeout(n, r)), await this.initialize();
|
|
2762
|
+
}
|
|
2763
|
+
/**
|
|
2764
|
+
* Export artboard to data URL using worker
|
|
2765
|
+
* Uses request queue for concurrent exports
|
|
2766
|
+
*/
|
|
2767
|
+
async exportArtboardToDataURL(t, r, n = {}) {
|
|
2768
|
+
return this.resetIdleTimer(), new Promise((o, i) => {
|
|
2769
|
+
this.requestQueue.push({
|
|
2770
|
+
artboard: t,
|
|
2771
|
+
elements: r,
|
|
2772
|
+
config: { ...n, returnFormat: "dataUrl" },
|
|
2773
|
+
resolve: o,
|
|
2774
|
+
reject: i
|
|
2775
|
+
}), this.processQueue();
|
|
2776
|
+
});
|
|
2777
|
+
}
|
|
2778
|
+
/**
|
|
2779
|
+
* Export artboard to Blob using worker
|
|
2780
|
+
* Returns a Blob directly - more efficient for API uploads
|
|
2781
|
+
* Uses request queue for concurrent exports
|
|
2782
|
+
*/
|
|
2783
|
+
async exportArtboardToBlob(t, r, n = {}) {
|
|
2784
|
+
return this.resetIdleTimer(), new Promise((o, i) => {
|
|
2785
|
+
this.blobRequestQueue.push({
|
|
2786
|
+
artboard: t,
|
|
2787
|
+
elements: r,
|
|
2788
|
+
config: { ...n, returnFormat: "blob" },
|
|
2789
|
+
resolve: o,
|
|
2790
|
+
reject: i
|
|
2791
|
+
}), this.processBlobQueue();
|
|
2792
|
+
});
|
|
2793
|
+
}
|
|
2794
|
+
/**
|
|
2795
|
+
* Process the request queue
|
|
2796
|
+
*/
|
|
2797
|
+
async processQueue() {
|
|
2798
|
+
if (!(this.isProcessingQueue || this.requestQueue.length === 0)) {
|
|
2799
|
+
for (this.isProcessingQueue = !0; this.requestQueue.length > 0; ) {
|
|
2800
|
+
const t = this.requestQueue.shift();
|
|
2801
|
+
try {
|
|
2802
|
+
const r = await this.executeExportRequest(t);
|
|
2803
|
+
t.resolve(r);
|
|
2804
|
+
} catch (r) {
|
|
2805
|
+
t.reject(r instanceof Error ? r : new Error(String(r)));
|
|
2806
|
+
}
|
|
2807
|
+
}
|
|
2808
|
+
this.isProcessingQueue = !1;
|
|
2809
|
+
}
|
|
2810
|
+
}
|
|
2811
|
+
/**
|
|
2812
|
+
* Execute a single export request
|
|
2813
|
+
*/
|
|
2814
|
+
async executeExportRequest(t) {
|
|
2815
|
+
const { artboard: r, elements: n, config: o } = t;
|
|
2816
|
+
if ((!this.worker || !this.isReady) && await this.initialize(), !this.worker)
|
|
2817
|
+
throw new Error("Worker is not initialized");
|
|
2818
|
+
const i = `export-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: l, newBitmaps: a } = await be(r, n);
|
|
2819
|
+
a.length > 0 && this.registerBitmapsWithWorker(a);
|
|
2820
|
+
const c = {
|
|
2821
|
+
type: "export",
|
|
2822
|
+
requestId: i,
|
|
2823
|
+
artboardData: l.artboard,
|
|
2824
|
+
elements: l.elements,
|
|
2825
|
+
fonts: l.fonts,
|
|
2826
|
+
// Custom (brand) fonts among the used families — the worker loads
|
|
2827
|
+
// these from their hosted URL instead of Google Fonts (deterministic
|
|
2828
|
+
// shadowing; see utils/custom-fonts.ts).
|
|
2829
|
+
customFonts: Nt.forFamilies(l.fonts ?? []),
|
|
2830
|
+
scale: o.scale || 1,
|
|
2831
|
+
format: o.format || "png",
|
|
2832
|
+
quality: o.quality || 0.95
|
|
2833
|
+
}, h = new Promise((k, g) => {
|
|
2834
|
+
this.pendingRequests.set(i, {
|
|
2835
|
+
requestId: i,
|
|
2836
|
+
resolve: k,
|
|
2837
|
+
reject: g,
|
|
2838
|
+
startTime: s,
|
|
2839
|
+
returnFormat: "dataUrl"
|
|
2840
|
+
}), setTimeout(() => {
|
|
2841
|
+
this.pendingRequests.has(i) && (this.pendingRequests.delete(i), g(new Error("Export request timeout")));
|
|
2842
|
+
}, 3e4);
|
|
2843
|
+
});
|
|
2844
|
+
this.worker.postMessage(c);
|
|
2845
|
+
const d = await h, f = performance.now() - s;
|
|
2846
|
+
return {
|
|
2847
|
+
dataUrl: d.dataUrl,
|
|
2848
|
+
artboardId: d.artboardId,
|
|
2849
|
+
artboardName: d.artboardName,
|
|
2850
|
+
renderTime: d.renderTime,
|
|
2851
|
+
totalTime: d.totalTime,
|
|
2852
|
+
mainThreadBlockTime: f
|
|
2853
|
+
};
|
|
2854
|
+
}
|
|
2855
|
+
/**
|
|
2856
|
+
* Process the blob request queue
|
|
2857
|
+
*/
|
|
2858
|
+
async processBlobQueue() {
|
|
2859
|
+
if (!(this.isProcessingQueue || this.blobRequestQueue.length === 0)) {
|
|
2860
|
+
for (this.isProcessingQueue = !0; this.blobRequestQueue.length > 0; ) {
|
|
2861
|
+
const t = this.blobRequestQueue.shift();
|
|
2862
|
+
try {
|
|
2863
|
+
const r = await this.executeBlobExportRequest(t);
|
|
2864
|
+
t.resolve(r);
|
|
2865
|
+
} catch (r) {
|
|
2866
|
+
t.reject(r instanceof Error ? r : new Error(String(r)));
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
this.isProcessingQueue = !1;
|
|
2870
|
+
}
|
|
2871
|
+
}
|
|
2872
|
+
/**
|
|
2873
|
+
* Execute a single blob export request
|
|
2874
|
+
*/
|
|
2875
|
+
async executeBlobExportRequest(t) {
|
|
2876
|
+
const { artboard: r, elements: n, config: o } = t;
|
|
2877
|
+
if ((!this.worker || !this.isReady) && await this.initialize(), !this.worker)
|
|
2878
|
+
throw new Error("Worker is not initialized");
|
|
2879
|
+
const i = `export-blob-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: l, newBitmaps: a } = await be(r, n);
|
|
2880
|
+
a.length > 0 && this.registerBitmapsWithWorker(a);
|
|
2881
|
+
const c = {
|
|
2882
|
+
type: "export",
|
|
2883
|
+
requestId: i,
|
|
2884
|
+
artboardData: l.artboard,
|
|
2885
|
+
elements: l.elements,
|
|
2886
|
+
fonts: l.fonts,
|
|
2887
|
+
// Same custom-font threading as the dataUrl path above.
|
|
2888
|
+
customFonts: Nt.forFamilies(l.fonts ?? []),
|
|
2889
|
+
scale: o.scale || 1,
|
|
2890
|
+
format: o.format || "png",
|
|
2891
|
+
quality: o.quality || 0.95,
|
|
2892
|
+
returnFormat: "blob"
|
|
2893
|
+
}, h = new Promise((g, m) => {
|
|
2894
|
+
this.pendingRequests.set(i, {
|
|
2895
|
+
requestId: i,
|
|
2896
|
+
resolve: g,
|
|
2897
|
+
reject: m,
|
|
2898
|
+
startTime: s,
|
|
2899
|
+
returnFormat: "blob"
|
|
2900
|
+
}), setTimeout(() => {
|
|
2901
|
+
this.pendingRequests.has(i) && (this.pendingRequests.delete(i), m(new Error("Export request timeout")));
|
|
2902
|
+
}, 3e4);
|
|
2903
|
+
});
|
|
2904
|
+
this.worker.postMessage(c);
|
|
2905
|
+
const d = await h, f = performance.now() - s;
|
|
2906
|
+
return {
|
|
2907
|
+
blob: new Blob([d.blobData], { type: d.mimeType }),
|
|
2908
|
+
artboardId: d.artboardId,
|
|
2909
|
+
artboardName: d.artboardName,
|
|
2910
|
+
renderTime: d.renderTime,
|
|
2911
|
+
totalTime: d.totalTime,
|
|
2912
|
+
mainThreadBlockTime: f
|
|
2913
|
+
};
|
|
2914
|
+
}
|
|
2915
|
+
/**
|
|
2916
|
+
* Handle messages from worker
|
|
2917
|
+
*/
|
|
2918
|
+
handleWorkerMessage(t) {
|
|
2919
|
+
switch (t.type) {
|
|
2920
|
+
case "exportComplete":
|
|
2921
|
+
this.handleExportComplete(t);
|
|
2922
|
+
break;
|
|
2923
|
+
case "exportBlobComplete":
|
|
2924
|
+
this.handleBlobExportComplete(t);
|
|
2925
|
+
break;
|
|
2926
|
+
case "exportError":
|
|
2927
|
+
this.handleExportError(t);
|
|
2928
|
+
break;
|
|
2929
|
+
case "exportProgress":
|
|
2930
|
+
this.emitProgress({
|
|
2931
|
+
requestId: t.requestId,
|
|
2932
|
+
progress: t.progress,
|
|
2933
|
+
message: t.message
|
|
2934
|
+
});
|
|
2935
|
+
break;
|
|
2936
|
+
case "ready":
|
|
2937
|
+
break;
|
|
2938
|
+
default:
|
|
2939
|
+
O.warn("Unknown message type:", t);
|
|
2940
|
+
}
|
|
2941
|
+
}
|
|
2942
|
+
/**
|
|
2943
|
+
* Handle successful export completion (dataUrl)
|
|
2944
|
+
*/
|
|
2945
|
+
handleExportComplete(t) {
|
|
2946
|
+
const r = this.pendingRequests.get(t.requestId);
|
|
2947
|
+
r && r.returnFormat === "dataUrl" ? (r.resolve(t), this.pendingRequests.delete(t.requestId)) : r ? (O.warn("Received dataUrl response for blob request:", t.requestId), r.reject(new Error("Received dataUrl response when expecting blob")), this.pendingRequests.delete(t.requestId)) : O.warn("Received response for unknown request:", t.requestId);
|
|
2948
|
+
}
|
|
2949
|
+
/**
|
|
2950
|
+
* Handle successful blob export completion
|
|
2951
|
+
*/
|
|
2952
|
+
handleBlobExportComplete(t) {
|
|
2953
|
+
const r = this.pendingRequests.get(t.requestId);
|
|
2954
|
+
r && r.returnFormat === "blob" ? (r.resolve(t), this.pendingRequests.delete(t.requestId)) : r ? (O.warn("Received blob response for dataUrl request:", t.requestId), r.reject(new Error("Received blob response when expecting dataUrl")), this.pendingRequests.delete(t.requestId)) : O.warn("Received blob response for unknown request:", t.requestId);
|
|
2955
|
+
}
|
|
2956
|
+
/**
|
|
2957
|
+
* Handle export error
|
|
2958
|
+
*/
|
|
2959
|
+
handleExportError(t) {
|
|
2960
|
+
const r = this.pendingRequests.get(t.requestId);
|
|
2961
|
+
if (r) {
|
|
2962
|
+
const n = new Error(t.error);
|
|
2963
|
+
t.stack && (n.stack = t.stack), r.reject(n), this.pendingRequests.delete(t.requestId);
|
|
2964
|
+
} else
|
|
2965
|
+
O.warn("Received error for unknown request:", t.requestId);
|
|
2966
|
+
}
|
|
2967
|
+
/**
|
|
2968
|
+
* Handle worker errors
|
|
2969
|
+
*/
|
|
2970
|
+
async handleWorkerError(t) {
|
|
2971
|
+
O.error("Worker error:", t);
|
|
2972
|
+
const r = Array.from(this.pendingRequests.values());
|
|
2973
|
+
for (const [n, o] of this.pendingRequests.entries())
|
|
2974
|
+
this.pendingRequests.delete(n);
|
|
2975
|
+
this.isReady = !1;
|
|
2976
|
+
try {
|
|
2977
|
+
await this.restartWorker();
|
|
2978
|
+
} catch (n) {
|
|
2979
|
+
O.error("Failed to restart worker:", n);
|
|
2980
|
+
for (const o of r)
|
|
2981
|
+
o.reject(new Error(`Worker crashed and could not be restarted: ${t.message}`));
|
|
2982
|
+
for (; this.requestQueue.length > 0; )
|
|
2983
|
+
this.requestQueue.shift().reject(new Error("Worker crashed and could not be restarted"));
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
/**
|
|
2987
|
+
* Terminate the worker
|
|
2988
|
+
*/
|
|
2989
|
+
terminate() {
|
|
2990
|
+
if (this.idleTimeout && (clearTimeout(this.idleTimeout), this.idleTimeout = null), this.initGeneration++, this.worker || (this.readyPromise = null), this.worker) {
|
|
2991
|
+
for (const [t, r] of this.pendingRequests.entries())
|
|
2992
|
+
r.reject(new Error("Worker terminated")), this.pendingRequests.delete(t);
|
|
2993
|
+
for (; this.requestQueue.length > 0; )
|
|
2994
|
+
this.requestQueue.shift().reject(new Error("Worker terminated"));
|
|
2995
|
+
this.worker.terminate(), this.worker = null, this.isReady = !1, this.readyPromise = null, Ht(), On(), this.workerBlobUrl && (URL.revokeObjectURL(this.workerBlobUrl), this.workerBlobUrl = null);
|
|
2996
|
+
}
|
|
2997
|
+
}
|
|
2998
|
+
/**
|
|
2999
|
+
* Get worker status
|
|
3000
|
+
*/
|
|
3001
|
+
getStatus() {
|
|
3002
|
+
return {
|
|
3003
|
+
isReady: this.isReady,
|
|
3004
|
+
pendingRequests: this.pendingRequests.size,
|
|
3005
|
+
queuedRequests: this.requestQueue.length,
|
|
3006
|
+
crashCount: this.workerCrashCount
|
|
3007
|
+
};
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
let tt = null;
|
|
3011
|
+
function no() {
|
|
3012
|
+
return tt || (tt = new dt()), tt;
|
|
3013
|
+
}
|
|
3014
|
+
function oo() {
|
|
3015
|
+
tt && (tt.terminate(), tt = null);
|
|
3016
|
+
}
|
|
3017
|
+
Jt();
|
|
3018
|
+
const N = j("Export");
|
|
3019
|
+
function _t(e, t) {
|
|
3020
|
+
var r;
|
|
3021
|
+
if (!(!e || typeof e != "object")) {
|
|
3022
|
+
if (typeof e.fontFamily == "string" && e.fontFamily.trim() && t.add(e.fontFamily), e.richText && Array.isArray(e.richText.spans))
|
|
3023
|
+
for (const n of e.richText.spans)
|
|
3024
|
+
(r = n == null ? void 0 : n.style) != null && r.fontFamily && typeof n.style.fontFamily == "string" && t.add(n.style.fontFamily);
|
|
3025
|
+
if (Array.isArray(e.children))
|
|
3026
|
+
for (const n of e.children) _t(n, t);
|
|
3027
|
+
if (Array.isArray(e.masks))
|
|
3028
|
+
for (const n of e.masks)
|
|
3029
|
+
n != null && n.maskElement && _t(n.maskElement, t);
|
|
3030
|
+
}
|
|
3031
|
+
}
|
|
3032
|
+
async function Te(e) {
|
|
3033
|
+
if (typeof document > "u" || !document.fonts) return;
|
|
3034
|
+
const t = /* @__PURE__ */ new Set();
|
|
3035
|
+
for (const n of e) _t(n, t);
|
|
3036
|
+
if (t.size === 0) return;
|
|
3037
|
+
const r = [];
|
|
3038
|
+
for (const n of t)
|
|
3039
|
+
r.push(document.fonts.load(`16px "${n}"`).catch(() => {
|
|
3040
|
+
}));
|
|
3041
|
+
await Promise.all(r), document.fonts.ready && await document.fonts.ready;
|
|
3042
|
+
}
|
|
3043
|
+
const ct = class ct {
|
|
3044
|
+
/**
|
|
3045
|
+
* Check if worker export is supported in this browser
|
|
3046
|
+
*/
|
|
3047
|
+
static supportsWorkerExport() {
|
|
3048
|
+
return dt.supportsWorkerExport();
|
|
3049
|
+
}
|
|
3050
|
+
/**
|
|
3051
|
+
* Get or initialize the worker manager
|
|
3052
|
+
*/
|
|
3053
|
+
static async getWorkerManager() {
|
|
3054
|
+
return this.supportsWorkerExport() ? this.workerManager ? this.workerManager : this.workerInitPromise ? (await this.workerInitPromise, this.workerManager) : (this.workerInitPromise = (async () => {
|
|
3055
|
+
try {
|
|
3056
|
+
this.workerManager = new dt(), await this.workerManager.initialize();
|
|
3057
|
+
} catch (t) {
|
|
3058
|
+
N.error("Failed to initialize worker:", t), this.workerManager = null;
|
|
3059
|
+
}
|
|
3060
|
+
})(), await this.workerInitPromise, this.workerInitPromise = null, this.workerManager) : null;
|
|
3061
|
+
}
|
|
3062
|
+
/**
|
|
3063
|
+
* Terminate the worker (for cleanup)
|
|
3064
|
+
*/
|
|
3065
|
+
static terminateWorker() {
|
|
3066
|
+
this.workerManager && (this.workerManager.terminate(), this.workerManager = null);
|
|
3067
|
+
}
|
|
3068
|
+
/**
|
|
3069
|
+
* Export entire workspace to JSON
|
|
3070
|
+
*/
|
|
3071
|
+
static exportToJSON(t, r, n, o) {
|
|
3072
|
+
const i = {
|
|
3073
|
+
metadata: {
|
|
3074
|
+
version: this.CURRENT_VERSION,
|
|
3075
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
3076
|
+
appVersion: "1.0.0"
|
|
3077
|
+
},
|
|
3078
|
+
artboards: t.map((h) => {
|
|
3079
|
+
const d = new Set(h.getElementIds()), u = r.filter((f) => d.has(f.id));
|
|
3080
|
+
return {
|
|
3081
|
+
id: h.id,
|
|
3082
|
+
name: h.name,
|
|
3083
|
+
x: h.x,
|
|
3084
|
+
y: h.y,
|
|
3085
|
+
width: h.width,
|
|
3086
|
+
height: h.height,
|
|
3087
|
+
backgroundColor: h.backgroundColor,
|
|
3088
|
+
elements: u.map((f) => f.toJSON())
|
|
3089
|
+
};
|
|
3090
|
+
}),
|
|
3091
|
+
activeArtboardId: n.getActiveArtboardId()
|
|
3092
|
+
}, s = JSON.stringify(i, null, 2), l = new Blob([s], { type: "application/json" }), a = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").split("T")[0], c = o || `canvas-${a}.json`;
|
|
3093
|
+
this.downloadBlob(l, c);
|
|
3094
|
+
}
|
|
3095
|
+
/**
|
|
3096
|
+
* Export artboard to image
|
|
3097
|
+
* Uses worker if supported, falls back to main thread
|
|
3098
|
+
*/
|
|
3099
|
+
static async exportArtboardToImage(t, r, n, o = {}) {
|
|
3100
|
+
const {
|
|
3101
|
+
format: i = "png",
|
|
3102
|
+
quality: s = 0.95,
|
|
3103
|
+
scale: l = 1,
|
|
3104
|
+
transparentBackground: a = !1,
|
|
3105
|
+
backgroundColor: c = t.backgroundColor,
|
|
3106
|
+
filename: h,
|
|
3107
|
+
forceMainThread: d = !1
|
|
3108
|
+
} = o, u = await this.exportArtboardToDataURL(t, r, n, {
|
|
3109
|
+
format: i,
|
|
3110
|
+
quality: s,
|
|
3111
|
+
scale: l,
|
|
3112
|
+
transparentBackground: a,
|
|
3113
|
+
backgroundColor: c,
|
|
3114
|
+
forceMainThread: d
|
|
3115
|
+
}), f = await this.dataUrlToBlob(u), k = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").split("T")[0], g = h || `${t.name}-${k}.${i}`;
|
|
3116
|
+
this.downloadBlob(f, g);
|
|
3117
|
+
}
|
|
3118
|
+
/**
|
|
3119
|
+
* Export artboard to data URL (for preview/testing)
|
|
3120
|
+
* Uses worker if supported, falls back to main thread
|
|
3121
|
+
*/
|
|
3122
|
+
static async exportArtboardToDataURL(t, r, n, o = {}) {
|
|
3123
|
+
const {
|
|
3124
|
+
format: i = "png",
|
|
3125
|
+
quality: s = 0.95,
|
|
3126
|
+
scale: l = 1,
|
|
3127
|
+
transparentBackground: a = !1,
|
|
3128
|
+
backgroundColor: c = t.backgroundColor,
|
|
3129
|
+
forceMainThread: h = !1
|
|
3130
|
+
} = o;
|
|
3131
|
+
if (!h && this.supportsWorkerExport())
|
|
3132
|
+
try {
|
|
3133
|
+
const d = await this.getWorkerManager();
|
|
3134
|
+
if (d) {
|
|
3135
|
+
const u = new Set(t.getElementIds()), f = r.filter((g) => u.has(g.id));
|
|
3136
|
+
return (await d.exportArtboardToDataURL(t, f, {
|
|
3137
|
+
scale: l,
|
|
3138
|
+
format: i === "jpg" ? "jpeg" : i,
|
|
3139
|
+
quality: s
|
|
3140
|
+
})).dataUrl;
|
|
3141
|
+
}
|
|
3142
|
+
} catch (d) {
|
|
3143
|
+
N.warn("Worker export failed, falling back to main thread:", d);
|
|
3144
|
+
}
|
|
3145
|
+
return this.mainThreadExportToDataURL(t, r, n, {
|
|
3146
|
+
format: i,
|
|
3147
|
+
quality: s,
|
|
3148
|
+
scale: l,
|
|
3149
|
+
transparentBackground: a,
|
|
3150
|
+
backgroundColor: c
|
|
3151
|
+
});
|
|
3152
|
+
}
|
|
3153
|
+
/**
|
|
3154
|
+
* Export artboard as Blob (more efficient for API uploads)
|
|
3155
|
+
* Returns a Blob instead of data URL - smaller payload, faster for network operations
|
|
3156
|
+
* Uses worker if supported, falls back to main thread
|
|
3157
|
+
*/
|
|
3158
|
+
static async exportArtboardToBlob(t, r, n, o = {}) {
|
|
3159
|
+
const {
|
|
3160
|
+
format: i = "png",
|
|
3161
|
+
quality: s = 0.95,
|
|
3162
|
+
scale: l = 1,
|
|
3163
|
+
transparentBackground: a = !1,
|
|
3164
|
+
backgroundColor: c = t.backgroundColor,
|
|
3165
|
+
forceMainThread: h = !1
|
|
3166
|
+
} = o;
|
|
3167
|
+
if (!h && this.supportsWorkerExport())
|
|
3168
|
+
try {
|
|
3169
|
+
const d = await this.getWorkerManager();
|
|
3170
|
+
if (d) {
|
|
3171
|
+
const u = new Set(t.getElementIds()), f = r.filter((g) => u.has(g.id));
|
|
3172
|
+
return (await d.exportArtboardToBlob(t, f, {
|
|
3173
|
+
scale: l,
|
|
3174
|
+
format: i === "jpg" ? "jpeg" : i,
|
|
3175
|
+
quality: s
|
|
3176
|
+
})).blob;
|
|
3177
|
+
}
|
|
3178
|
+
} catch (d) {
|
|
3179
|
+
N.warn("Worker blob export failed, falling back to main thread:", d);
|
|
3180
|
+
}
|
|
3181
|
+
return this.mainThreadExportToBlob(t, r, n, {
|
|
3182
|
+
format: i,
|
|
3183
|
+
quality: s,
|
|
3184
|
+
scale: l,
|
|
3185
|
+
transparentBackground: a,
|
|
3186
|
+
backgroundColor: c
|
|
3187
|
+
});
|
|
3188
|
+
}
|
|
3189
|
+
/**
|
|
3190
|
+
* Main thread export to Blob (fallback/legacy method).
|
|
3191
|
+
*
|
|
3192
|
+
* On iOS WebKit this is also the *primary* path (`isIOSWebKit()` skips the
|
|
3193
|
+
* worker), so font readiness matters here even when no fallback occurred.
|
|
3194
|
+
*/
|
|
3195
|
+
static async mainThreadExportToBlob(t, r, n, o = {}) {
|
|
3196
|
+
const {
|
|
3197
|
+
format: i = "png",
|
|
3198
|
+
quality: s = 0.95,
|
|
3199
|
+
scale: l = 1,
|
|
3200
|
+
transparentBackground: a = !1,
|
|
3201
|
+
backgroundColor: c = t.backgroundColor
|
|
3202
|
+
} = o;
|
|
3203
|
+
await Te(r);
|
|
3204
|
+
const h = document.createElement("canvas"), d = t.width * l, u = t.height * l;
|
|
3205
|
+
h.width = d, h.height = u;
|
|
3206
|
+
const f = h.getContext("2d");
|
|
3207
|
+
if (f.scale(l, l), !a && t.exportBackground) {
|
|
3208
|
+
if (f.save(), this.applyExportBackgroundClipPath(f, t), t.backgroundType === "texture" && t.backgroundTexture) {
|
|
3209
|
+
const y = D.getTexturePresetColor(t.backgroundTexture);
|
|
3210
|
+
f.fillStyle = y, f.fillRect(0, 0, t.width, t.height);
|
|
3211
|
+
const p = D.getTexture(t.backgroundTexture);
|
|
3212
|
+
p && p.complete && f.drawImage(p, 0, 0, t.width, t.height);
|
|
3213
|
+
} else
|
|
3214
|
+
f.fillStyle = c || t.backgroundColor, f.fillRect(0, 0, t.width, t.height);
|
|
3215
|
+
f.restore();
|
|
3216
|
+
}
|
|
3217
|
+
f.save(), f.translate(-t.x, -t.y), this.applyExportClipPath(f, t);
|
|
3218
|
+
const k = new Set(t.getElementIds()), g = r.filter((y) => k.has(y.id)), m = /* @__PURE__ */ new Map();
|
|
3219
|
+
g.forEach((y) => m.set(y.id, y));
|
|
3220
|
+
const T = (y, p) => {
|
|
3221
|
+
if (!p.id) return;
|
|
3222
|
+
const S = m.get(p.id);
|
|
3223
|
+
S && S.render(y, !1);
|
|
3224
|
+
}, w = g.map((y) => y.toJSON()), b = /* @__PURE__ */ new Set();
|
|
3225
|
+
return g.forEach((y, p) => {
|
|
3226
|
+
var S;
|
|
3227
|
+
if (y.blendMode === "knockout" || y.blendMode === "clip") {
|
|
3228
|
+
const C = w[p], M = y.blendMode === "knockout" ? "destination-out" : "destination-in", P = ((S = C.knockoutParts) == null ? void 0 : S.scope) || "group", v = w.findIndex((A) => A.id === C.id);
|
|
3229
|
+
if (v !== -1 && P === "artboard")
|
|
3230
|
+
for (let A = 0; A < v; A++) {
|
|
3231
|
+
const I = w[A].id;
|
|
3232
|
+
I && b.add(I);
|
|
3233
|
+
}
|
|
3234
|
+
Bt(
|
|
3235
|
+
f,
|
|
3236
|
+
C,
|
|
3237
|
+
w,
|
|
3238
|
+
T,
|
|
3239
|
+
a || !t.exportBackground ? void 0 : c,
|
|
3240
|
+
t,
|
|
3241
|
+
M
|
|
3242
|
+
), b.add(y.id);
|
|
3243
|
+
}
|
|
3244
|
+
}), g.forEach((y, p) => {
|
|
3245
|
+
b.has(y.id) || ce(f, w[p], (S) => {
|
|
3246
|
+
y.render(S, !1);
|
|
3247
|
+
});
|
|
3248
|
+
}), f.restore(), new Promise((y, p) => {
|
|
3249
|
+
h.toBlob(
|
|
3250
|
+
(S) => {
|
|
3251
|
+
S ? y(S) : p(new Error("Failed to create blob from canvas"));
|
|
3252
|
+
},
|
|
3253
|
+
i === "jpg" || i === "jpeg" ? "image/jpeg" : i === "webp" ? "image/webp" : "image/png",
|
|
3254
|
+
s
|
|
3255
|
+
);
|
|
3256
|
+
});
|
|
3257
|
+
}
|
|
3258
|
+
/**
|
|
3259
|
+
* Main thread export to data URL (fallback/legacy method).
|
|
3260
|
+
*
|
|
3261
|
+
* On iOS WebKit this is also the *primary* path (`isIOSWebKit()` skips the
|
|
3262
|
+
* worker), so font readiness matters here even when no fallback occurred.
|
|
3263
|
+
*/
|
|
3264
|
+
static async mainThreadExportToDataURL(t, r, n, o = {}) {
|
|
3265
|
+
var p, S;
|
|
3266
|
+
const {
|
|
3267
|
+
format: i = "png",
|
|
3268
|
+
quality: s = 0.95,
|
|
3269
|
+
scale: l = 1,
|
|
3270
|
+
transparentBackground: a = !1,
|
|
3271
|
+
backgroundColor: c = t.backgroundColor
|
|
3272
|
+
} = o;
|
|
3273
|
+
await Te(r);
|
|
3274
|
+
const h = document.createElement("canvas"), d = t.width * l, u = t.height * l;
|
|
3275
|
+
h.width = d, h.height = u;
|
|
3276
|
+
const f = h.getContext("2d");
|
|
3277
|
+
if (f.scale(l, l), !a && t.exportBackground) {
|
|
3278
|
+
if (f.save(), this.applyExportBackgroundClipPath(f, t), t.backgroundType === "texture" && t.backgroundTexture) {
|
|
3279
|
+
const C = D.getTexturePresetColor(t.backgroundTexture);
|
|
3280
|
+
f.fillStyle = C, f.fillRect(0, 0, t.width, t.height);
|
|
3281
|
+
const M = D.getTexture(t.backgroundTexture);
|
|
3282
|
+
M && M.complete ? f.drawImage(M, 0, 0, t.width, t.height) : N.warn("Texture not loaded for export:", t.backgroundTexture);
|
|
3283
|
+
} else
|
|
3284
|
+
f.fillStyle = c, f.fillRect(0, 0, t.width, t.height);
|
|
3285
|
+
f.restore();
|
|
3286
|
+
}
|
|
3287
|
+
f.save(), f.translate(-t.x, -t.y), this.applyExportClipPath(f, t);
|
|
3288
|
+
const k = new Set(t.getElementIds()), g = r.filter((C) => k.has(C.id)), m = /* @__PURE__ */ new Map();
|
|
3289
|
+
g.forEach((C) => m.set(C.id, C));
|
|
3290
|
+
const T = (C, M) => {
|
|
3291
|
+
if (!M.id) return;
|
|
3292
|
+
const P = m.get(M.id);
|
|
3293
|
+
P ? P.render(C, !1) : N.warn("Element not found in map:", M.id);
|
|
3294
|
+
}, w = g.map((C) => C.toJSON()), b = /* @__PURE__ */ new Set();
|
|
3295
|
+
g.forEach((C, M) => {
|
|
3296
|
+
var P;
|
|
3297
|
+
if (C.blendMode === "knockout" || C.blendMode === "clip") {
|
|
3298
|
+
const v = w[M], A = C.blendMode === "knockout" ? "destination-out" : "destination-in", I = ((P = v.knockoutParts) == null ? void 0 : P.scope) || "group", E = w.findIndex((R) => R.id === v.id);
|
|
3299
|
+
if (E !== -1 && I === "artboard")
|
|
3300
|
+
for (let R = 0; R < E; R++) {
|
|
3301
|
+
const W = w[R].id;
|
|
3302
|
+
W && b.add(W);
|
|
3303
|
+
}
|
|
3304
|
+
Bt(
|
|
3305
|
+
f,
|
|
3306
|
+
v,
|
|
3307
|
+
w,
|
|
3308
|
+
T,
|
|
3309
|
+
a || !t.exportBackground ? void 0 : c,
|
|
3310
|
+
t,
|
|
3311
|
+
A
|
|
3312
|
+
), b.add(C.id);
|
|
3313
|
+
}
|
|
3314
|
+
}), g.forEach((C, M) => {
|
|
3315
|
+
var P;
|
|
3316
|
+
if (!b.has(C.id)) {
|
|
3317
|
+
const v = w[M], A = ((P = v == null ? void 0 : v.distressEffect) == null ? void 0 : P.enabled) && v.distressEffect.style === "custom" && v.distressEffect.textureUrl, I = (v == null ? void 0 : v.masks) && v.masks.length > 0, E = (R) => {
|
|
3318
|
+
C.render(R, !1);
|
|
3319
|
+
};
|
|
3320
|
+
ce(f, v, (R) => {
|
|
3321
|
+
if (I && A)
|
|
3322
|
+
le(R, v, (W) => {
|
|
3323
|
+
const F = C.getVisualBoundingBox();
|
|
3324
|
+
pe(W, v.distressEffect, F, E);
|
|
3325
|
+
});
|
|
3326
|
+
else if (I)
|
|
3327
|
+
le(R, v, E);
|
|
3328
|
+
else if (A) {
|
|
3329
|
+
const W = C.getVisualBoundingBox();
|
|
3330
|
+
pe(R, v.distressEffect, W, E);
|
|
3331
|
+
} else
|
|
3332
|
+
C.render(R, !1);
|
|
3333
|
+
});
|
|
3334
|
+
}
|
|
3335
|
+
}), (p = t.distressTexture) != null && p.enabled && In(f, t.distressTexture, {
|
|
3336
|
+
x: t.x,
|
|
3337
|
+
y: t.y,
|
|
3338
|
+
width: t.width,
|
|
3339
|
+
height: t.height
|
|
3340
|
+
}), (S = t.imageMask) != null && S.enabled && pn(f, t.imageMask, {
|
|
3341
|
+
x: t.x,
|
|
3342
|
+
y: t.y,
|
|
3343
|
+
width: t.width,
|
|
3344
|
+
height: t.height
|
|
3345
|
+
}), f.restore();
|
|
3346
|
+
const y = i === "png" ? "image/png" : i === "webp" ? "image/webp" : "image/jpeg";
|
|
3347
|
+
return h.toDataURL(y, s);
|
|
3348
|
+
}
|
|
3349
|
+
/**
|
|
3350
|
+
* Apply clip path for export background (uses 0,0 as origin since background is drawn before translate)
|
|
3351
|
+
*/
|
|
3352
|
+
static applyExportBackgroundClipPath(t, r) {
|
|
3353
|
+
const { width: n, height: o, clipShape: i } = r, s = 0, l = 0;
|
|
3354
|
+
if (t.beginPath(), !i || i === "rectangle")
|
|
3355
|
+
t.rect(s, l, n, o);
|
|
3356
|
+
else if (i === "circle") {
|
|
3357
|
+
const a = s + n / 2, c = l + o / 2, h = Math.min(n, o) / 2;
|
|
3358
|
+
t.arc(a, c, h, 0, Math.PI * 2);
|
|
3359
|
+
} else if (typeof i == "object" && i.type === "rounded") {
|
|
3360
|
+
const a = Math.min(i.radius, Math.min(n, o) / 2);
|
|
3361
|
+
typeof t.roundRect == "function" ? t.roundRect(s, l, n, o, a) : (t.moveTo(s + a, l), t.lineTo(s + n - a, l), t.arcTo(s + n, l, s + n, l + a, a), t.lineTo(s + n, l + o - a), t.arcTo(s + n, l + o, s + n - a, l + o, a), t.lineTo(s + a, l + o), t.arcTo(s, l + o, s, l + o - a, a), t.lineTo(s, l + a), t.arcTo(s, l, s + a, l, a));
|
|
3362
|
+
} else if (typeof i == "object" && i.type === "path")
|
|
3363
|
+
try {
|
|
3364
|
+
const a = new Path2D(i.d);
|
|
3365
|
+
t.clip(a);
|
|
3366
|
+
return;
|
|
3367
|
+
} catch (a) {
|
|
3368
|
+
N.warn("Invalid SVG path, falling back to rectangle:", a), t.rect(s, l, n, o);
|
|
3369
|
+
}
|
|
3370
|
+
t.clip();
|
|
3371
|
+
}
|
|
3372
|
+
/**
|
|
3373
|
+
* Apply clip path for export based on artboard's clipShape
|
|
3374
|
+
* This creates the clip region for the given artboard during export
|
|
3375
|
+
*/
|
|
3376
|
+
static applyExportClipPath(t, r) {
|
|
3377
|
+
const { x: n, y: o, width: i, height: s, clipShape: l } = r;
|
|
3378
|
+
if (t.beginPath(), !l || l === "rectangle")
|
|
3379
|
+
t.rect(n, o, i, s);
|
|
3380
|
+
else if (l === "circle") {
|
|
3381
|
+
const a = n + i / 2, c = o + s / 2, h = Math.min(i, s) / 2;
|
|
3382
|
+
t.arc(a, c, h, 0, Math.PI * 2);
|
|
3383
|
+
} else if (typeof l == "object" && l.type === "rounded") {
|
|
3384
|
+
const a = Math.min(l.radius, Math.min(i, s) / 2);
|
|
3385
|
+
typeof t.roundRect == "function" ? t.roundRect(n, o, i, s, a) : (t.moveTo(n + a, o), t.lineTo(n + i - a, o), t.arcTo(n + i, o, n + i, o + a, a), t.lineTo(n + i, o + s - a), t.arcTo(n + i, o + s, n + i - a, o + s, a), t.lineTo(n + a, o + s), t.arcTo(n, o + s, n, o + s - a, a), t.lineTo(n, o + a), t.arcTo(n, o, n + a, o, a));
|
|
3386
|
+
} else if (typeof l == "object" && l.type === "path")
|
|
3387
|
+
try {
|
|
3388
|
+
const a = new Path2D(l.d);
|
|
3389
|
+
t.translate(n, o), t.clip(a), t.translate(-n, -o);
|
|
3390
|
+
return;
|
|
3391
|
+
} catch (a) {
|
|
3392
|
+
N.warn("Invalid SVG path, falling back to rectangle:", a), t.rect(n, o, i, s);
|
|
3393
|
+
}
|
|
3394
|
+
t.clip();
|
|
3395
|
+
}
|
|
3396
|
+
/**
|
|
3397
|
+
* Export all artboards as separate images (HIGH PERFORMANCE - parallel rendering)
|
|
3398
|
+
*/
|
|
3399
|
+
static async exportAllArtboardsToImages(t, r, n, o = {}) {
|
|
3400
|
+
const i = t.map(
|
|
3401
|
+
(s) => this.exportArtboardToImage(s, r, n, {
|
|
3402
|
+
...o,
|
|
3403
|
+
filename: o.filename ? `${o.filename}-${s.name}.${o.format || "png"}` : void 0
|
|
3404
|
+
})
|
|
3405
|
+
);
|
|
3406
|
+
await Promise.all(i);
|
|
3407
|
+
}
|
|
3408
|
+
/**
|
|
3409
|
+
* Download a blob as a file
|
|
3410
|
+
*/
|
|
3411
|
+
static downloadBlob(t, r) {
|
|
3412
|
+
const n = URL.createObjectURL(t), o = document.createElement("a");
|
|
3413
|
+
o.href = n, o.download = r, document.body.appendChild(o), o.click(), document.body.removeChild(o), URL.revokeObjectURL(n);
|
|
3414
|
+
}
|
|
3415
|
+
/**
|
|
3416
|
+
* Convert data URL to blob
|
|
3417
|
+
*/
|
|
3418
|
+
static async dataUrlToBlob(t) {
|
|
3419
|
+
return (await fetch(t)).blob();
|
|
3420
|
+
}
|
|
3421
|
+
/**
|
|
3422
|
+
* Get export summary (for UI display)
|
|
3423
|
+
*/
|
|
3424
|
+
static getExportSummary(t, r) {
|
|
3425
|
+
const n = t.length, o = r.length, l = n * 200 + o * 500, a = Math.ceil(l / 1024);
|
|
3426
|
+
return {
|
|
3427
|
+
artboardCount: n,
|
|
3428
|
+
totalElementCount: o,
|
|
3429
|
+
estimatedFileSize: a < 1024 ? `${a} KB` : `${(a / 1024).toFixed(1)} MB`
|
|
3430
|
+
};
|
|
3431
|
+
}
|
|
3432
|
+
/**
|
|
3433
|
+
* Performance benchmark: Compare worker vs main thread export
|
|
3434
|
+
* Returns timing data for both methods
|
|
3435
|
+
*/
|
|
3436
|
+
static async benchmarkExport(t, r, n, o = {}) {
|
|
3437
|
+
const i = performance.now(), s = await this.exportArtboardToDataURL(t, r, n, {
|
|
3438
|
+
...o,
|
|
3439
|
+
forceMainThread: !0
|
|
3440
|
+
}), l = performance.now() - i, a = {
|
|
3441
|
+
workerSupported: this.supportsWorkerExport(),
|
|
3442
|
+
mainThread: {
|
|
3443
|
+
time: l,
|
|
3444
|
+
dataUrl: s
|
|
3445
|
+
},
|
|
3446
|
+
recommendation: ""
|
|
3447
|
+
};
|
|
3448
|
+
if (this.supportsWorkerExport())
|
|
3449
|
+
try {
|
|
3450
|
+
const c = performance.now(), h = await this.getWorkerManager();
|
|
3451
|
+
if (h) {
|
|
3452
|
+
const d = new Set(t.getElementIds()), u = r.filter((m) => d.has(m.id)), f = await h.exportArtboardToDataURL(t, u, {
|
|
3453
|
+
scale: o.scale || 1,
|
|
3454
|
+
format: (o.format === "jpg" ? "jpeg" : o.format) || "png",
|
|
3455
|
+
quality: o.quality || 0.95
|
|
3456
|
+
}), k = performance.now() - c, g = l / k;
|
|
3457
|
+
return {
|
|
3458
|
+
...a,
|
|
3459
|
+
worker: {
|
|
3460
|
+
time: k,
|
|
3461
|
+
dataUrl: f.dataUrl,
|
|
3462
|
+
mainThreadBlockTime: f.mainThreadBlockTime
|
|
3463
|
+
},
|
|
3464
|
+
speedup: g,
|
|
3465
|
+
recommendation: g > 1.2 ? `Worker export is ${g.toFixed(2)}x faster - recommended for continuous export` : g < 0.8 ? `Main thread export is ${(1 / g).toFixed(2)}x faster - worker overhead not worth it for single exports` : "Performance is similar, but worker keeps UI responsive during export"
|
|
3466
|
+
};
|
|
3467
|
+
}
|
|
3468
|
+
} catch (c) {
|
|
3469
|
+
N.error("Worker benchmark failed:", c), a.recommendation = "Worker export not available - using main thread export";
|
|
3470
|
+
}
|
|
3471
|
+
else
|
|
3472
|
+
a.recommendation = "Worker export not supported in this browser - using main thread export";
|
|
3473
|
+
return a;
|
|
3474
|
+
}
|
|
3475
|
+
/**
|
|
3476
|
+
* Performance benchmark: Test continuous exports to measure UI impact
|
|
3477
|
+
* Returns statistics about export performance over time
|
|
3478
|
+
*/
|
|
3479
|
+
static async benchmarkContinuousExport(t, r, n, o = {}) {
|
|
3480
|
+
const {
|
|
3481
|
+
duration: i = 5e3,
|
|
3482
|
+
// 5 seconds
|
|
3483
|
+
interval: s = 500,
|
|
3484
|
+
// Every 500ms
|
|
3485
|
+
useWorker: l = this.supportsWorkerExport()
|
|
3486
|
+
} = o, a = [];
|
|
3487
|
+
let c = 0, h = !0;
|
|
3488
|
+
for (setTimeout(() => {
|
|
3489
|
+
h = !1;
|
|
3490
|
+
}, i); h; ) {
|
|
3491
|
+
const w = performance.now();
|
|
3492
|
+
await this.exportArtboardToDataURL(t, r, n, {
|
|
3493
|
+
forceMainThread: !l
|
|
3494
|
+
});
|
|
3495
|
+
const b = performance.now() - w;
|
|
3496
|
+
a.push(b), l || (c += b), await new Promise((y) => setTimeout(y, Math.max(0, s - b)));
|
|
3497
|
+
}
|
|
3498
|
+
const d = a.length, u = a.reduce((w, b) => w + b, 0) / d, f = Math.min(...a), k = Math.max(...a), g = d / i * 1e3, m = c / i * 100, T = m > 20 ? `Main thread blocked ${m.toFixed(1)}% of the time - STRONGLY recommend worker export` : m > 10 ? `Main thread blocked ${m.toFixed(1)}% of the time - consider worker export` : `Main thread blocked ${m.toFixed(1)}% of the time - performance is acceptable`;
|
|
3499
|
+
return {
|
|
3500
|
+
totalExports: d,
|
|
3501
|
+
duration: i,
|
|
3502
|
+
averageTime: u,
|
|
3503
|
+
minTime: f,
|
|
3504
|
+
maxTime: k,
|
|
3505
|
+
totalMainThreadBlockTime: c,
|
|
3506
|
+
exportsPerSecond: g,
|
|
3507
|
+
recommendation: T
|
|
3508
|
+
};
|
|
3509
|
+
}
|
|
3510
|
+
/**
|
|
3511
|
+
* Get performance statistics for the worker (if initialized)
|
|
3512
|
+
*/
|
|
3513
|
+
static getWorkerStats() {
|
|
3514
|
+
var t;
|
|
3515
|
+
return {
|
|
3516
|
+
workerSupported: this.supportsWorkerExport(),
|
|
3517
|
+
workerInitialized: this.workerManager !== null,
|
|
3518
|
+
workerStatus: (t = this.workerManager) == null ? void 0 : t.getStatus()
|
|
3519
|
+
};
|
|
3520
|
+
}
|
|
3521
|
+
/**
|
|
3522
|
+
* Get recommended export options for t-shirt designs
|
|
3523
|
+
* T-shirt designs should ALWAYS use transparent backgrounds with knockout effects
|
|
3524
|
+
*/
|
|
3525
|
+
static getTShirtExportOptions(t = {}) {
|
|
3526
|
+
return {
|
|
3527
|
+
format: "png",
|
|
3528
|
+
// PNG for transparency support
|
|
3529
|
+
scale: 2,
|
|
3530
|
+
// 2x for print quality
|
|
3531
|
+
quality: 1,
|
|
3532
|
+
// Maximum quality
|
|
3533
|
+
...t,
|
|
3534
|
+
// Force transparent background - critical for knockout effects
|
|
3535
|
+
transparentBackground: !0
|
|
3536
|
+
};
|
|
3537
|
+
}
|
|
3538
|
+
/**
|
|
3539
|
+
* Get recommended export options for pillow/pattern designs
|
|
3540
|
+
* These may use group-scoped knockout with pattern backgrounds
|
|
3541
|
+
*/
|
|
3542
|
+
static getPatternExportOptions(t = {}) {
|
|
3543
|
+
return {
|
|
3544
|
+
format: "png",
|
|
3545
|
+
scale: 2,
|
|
3546
|
+
transparentBackground: !1,
|
|
3547
|
+
// Patterns often include background
|
|
3548
|
+
quality: 1,
|
|
3549
|
+
...t
|
|
3550
|
+
};
|
|
3551
|
+
}
|
|
3552
|
+
/**
|
|
3553
|
+
* Validate export options for common issues
|
|
3554
|
+
* Returns warnings if options might cause problems
|
|
3555
|
+
*/
|
|
3556
|
+
static validateExportOptions(t, r) {
|
|
3557
|
+
const n = [];
|
|
3558
|
+
return r && !t.transparentBackground && n.push(
|
|
3559
|
+
"WARNING: Document has knockout effects but transparentBackground is false. Knockout effects work best with transparent backgrounds for t-shirt designs."
|
|
3560
|
+
), t.transparentBackground && (t.format === "jpg" || t.format === "jpeg") && n.push("WARNING: JPEG format does not support transparency. Use PNG format for transparent backgrounds."), t.quality && t.quality < 0.9 && n.push("NOTE: Using quality < 0.9 may reduce the appearance of distress and other effects."), t.scale && t.scale < 2 && n.push("NOTE: For print-ready designs, recommend scale of 2x or higher."), n;
|
|
3561
|
+
}
|
|
3562
|
+
/**
|
|
3563
|
+
* Check if any elements in the list have knockout effects
|
|
3564
|
+
*/
|
|
3565
|
+
static hasKnockoutEffects(t) {
|
|
3566
|
+
const r = (n) => (n.blendMode === "knockout" || n.blendMode === "clip") && n.knockoutParts ? !0 : "children" in n && Array.isArray(n.children) ? n.children.some((o) => r(o)) : !1;
|
|
3567
|
+
return t.some((n) => r(n));
|
|
3568
|
+
}
|
|
3569
|
+
/**
|
|
3570
|
+
* CRITICAL: Ensure artboard is export-safe
|
|
3571
|
+
* Strips preview background color to prevent accidental export
|
|
3572
|
+
* Returns a copy of the artboard safe for export
|
|
3573
|
+
*/
|
|
3574
|
+
static makeArtboardExportSafe(t) {
|
|
3575
|
+
const r = Object.assign(Object.create(Object.getPrototypeOf(t)), t);
|
|
3576
|
+
return "previewBackgroundColor" in r && delete r.previewBackgroundColor, r;
|
|
3577
|
+
}
|
|
3578
|
+
};
|
|
3579
|
+
ct.CURRENT_VERSION = "2.0.0", ct.workerManager = null, ct.workerInitPromise = null;
|
|
3580
|
+
let bt = ct;
|
|
3581
|
+
const so = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
3582
|
+
__proto__: null,
|
|
3583
|
+
ExportManager: bt,
|
|
3584
|
+
default: bt
|
|
3585
|
+
}, Symbol.toStringTag, { value: "Module" }));
|
|
3586
|
+
export {
|
|
3587
|
+
oo as A,
|
|
3588
|
+
_e as B,
|
|
3589
|
+
Cr as C,
|
|
3590
|
+
Xe as D,
|
|
3591
|
+
yt as E,
|
|
3592
|
+
Nt as F,
|
|
3593
|
+
ro as G,
|
|
3594
|
+
Hn as H,
|
|
3595
|
+
ye as I,
|
|
3596
|
+
$n as J,
|
|
3597
|
+
Bt as K,
|
|
3598
|
+
ce as L,
|
|
3599
|
+
In as M,
|
|
3600
|
+
pn as N,
|
|
3601
|
+
Jt as O,
|
|
3602
|
+
pe as P,
|
|
3603
|
+
Xn as Q,
|
|
3604
|
+
Cn as R,
|
|
3605
|
+
En as S,
|
|
3606
|
+
D as T,
|
|
3607
|
+
xn as U,
|
|
3608
|
+
an as V,
|
|
3609
|
+
dt as W,
|
|
3610
|
+
sn as X,
|
|
3611
|
+
pr as Y,
|
|
3612
|
+
so as Z,
|
|
3613
|
+
bt as a,
|
|
3614
|
+
Jn as b,
|
|
3615
|
+
Pe as c,
|
|
3616
|
+
q as d,
|
|
3617
|
+
to as e,
|
|
3618
|
+
Dn as f,
|
|
3619
|
+
Ht as g,
|
|
3620
|
+
Gn as h,
|
|
3621
|
+
wr as i,
|
|
3622
|
+
Yn as j,
|
|
3623
|
+
_n as k,
|
|
3624
|
+
ht as l,
|
|
3625
|
+
no as m,
|
|
3626
|
+
Zn as n,
|
|
3627
|
+
re as o,
|
|
3628
|
+
eo as p,
|
|
3629
|
+
Wt as q,
|
|
3630
|
+
Tr as r,
|
|
3631
|
+
Kn as s,
|
|
3632
|
+
Vn as t,
|
|
3633
|
+
Sr as u,
|
|
3634
|
+
Qn as v,
|
|
3635
|
+
Mr as w,
|
|
3636
|
+
Ie as x,
|
|
3637
|
+
zn as y,
|
|
3638
|
+
le as z
|
|
3639
|
+
};
|
|
3640
|
+
//# sourceMappingURL=ExportManager-B_7SG-Ox.js.map
|