@snowcone-app/canvas 0.40.8 → 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-CBl27o5h.js → EditorCanvasImpl-C8tvgEh8.js} +6 -6
- package/dist/{EditorCanvasImpl-CBl27o5h.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 +10 -10
- package/dist/components/embed-realtime/usePieceGuideBundle.d.ts +1 -1
- 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-BY6gMPTK.js → embed-DO1jibk2.js} +8 -8
- package/dist/{embed-BY6gMPTK.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/{usePieceGuideBundle-Cab2gRnn.js → usePieceGuideBundle-BpIz4qow.js} +10 -9
- package/dist/usePieceGuideBundle-BpIz4qow.js.map +1 -0
- 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 +3 -3
- package/dist/ExportManager-BbBfO22S.js.map +0 -1
- package/dist/usePieceGuideBundle-Cab2gRnn.js.map +0 -1
|
@@ -1,2493 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
let ke = null;
|
|
3
|
-
function dt(e) {
|
|
4
|
-
ke = e;
|
|
5
|
-
}
|
|
6
|
-
function Ua() {
|
|
7
|
-
return ke;
|
|
8
|
-
}
|
|
9
|
-
const ft = U("TextureManager"), ln = class ln {
|
|
10
|
-
/**
|
|
11
|
-
* Load a texture by ID or URL
|
|
12
|
-
*/
|
|
13
|
-
static async loadTexture(n) {
|
|
14
|
-
if (this.cache.has(n))
|
|
15
|
-
return this.cache.get(n);
|
|
16
|
-
if (this.loading.has(n))
|
|
17
|
-
return this.loading.get(n);
|
|
18
|
-
const t = this.resolveTextureUrl(n), a = new Promise((r, o) => {
|
|
19
|
-
const s = new Image();
|
|
20
|
-
s.crossOrigin = "anonymous", s.onload = () => {
|
|
21
|
-
this.cache.set(n, s), this.cache.set(t, s), this.loading.delete(n), this.loading.delete(t), r(s);
|
|
22
|
-
}, s.onerror = () => {
|
|
23
|
-
ft.error("Failed to load texture:", t), this.loading.delete(n), this.loading.delete(t), o(new Error(`Failed to load texture: ${t}`));
|
|
24
|
-
}, s.src = t;
|
|
25
|
-
});
|
|
26
|
-
return this.loading.set(n, a), t !== n && this.loading.set(t, a), a;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Get a texture synchronously (returns null if not loaded)
|
|
30
|
-
*/
|
|
31
|
-
static getTexture(n) {
|
|
32
|
-
const t = this.resolveTextureUrl(n);
|
|
33
|
-
return this.cache.get(n) || this.cache.get(t) || null;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Preload multiple textures
|
|
37
|
-
*/
|
|
38
|
-
static async preloadTextures(n) {
|
|
39
|
-
await Promise.all(n.map((t) => this.loadTexture(t)));
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Preload all built-in textures
|
|
43
|
-
*/
|
|
44
|
-
static async preloadAllTextures() {
|
|
45
|
-
await this.preloadTextures(this.TEXTURES.map((n) => n.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(n) {
|
|
57
|
-
if (n.startsWith("http://") || n.startsWith("https://") || n.startsWith("/") || n.startsWith("data:"))
|
|
58
|
-
return n;
|
|
59
|
-
const t = this.TEXTURES.find((a) => a.id === n);
|
|
60
|
-
return t ? t.url : `/textures/${n}`;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Get texture info by ID
|
|
64
|
-
*/
|
|
65
|
-
static getTextureInfo(n) {
|
|
66
|
-
return this.TEXTURES.find((t) => t.id === n);
|
|
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(n) {
|
|
78
|
-
return this.TEXTURES.filter((t) => t.category === n);
|
|
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(n) {
|
|
85
|
-
const t = this.TEXTURES.find((a) => a.id === n);
|
|
86
|
-
return (t == null ? void 0 : t.presetColor) || "#ffffff";
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
ln.cache = /* @__PURE__ */ new Map(), ln.loading = /* @__PURE__ */ new Map(), ln.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 Z = ln;
|
|
100
|
-
const ut = U("ElementPreviewRenderer"), pt = {
|
|
101
|
-
width: 40,
|
|
102
|
-
height: 40,
|
|
103
|
-
padding: 4,
|
|
104
|
-
backgroundColor: "transparent"
|
|
105
|
-
};
|
|
106
|
-
function ht(e, n = {}) {
|
|
107
|
-
jn();
|
|
108
|
-
const t = { ...pt, ...n }, a = document.createElement("canvas");
|
|
109
|
-
a.width = t.width, a.height = t.height;
|
|
110
|
-
const r = a.getContext("2d");
|
|
111
|
-
if (!r)
|
|
112
|
-
return "";
|
|
113
|
-
t.backgroundColor !== "transparent" && (r.fillStyle = t.backgroundColor, r.fillRect(0, 0, t.width, t.height)), r.save();
|
|
114
|
-
try {
|
|
115
|
-
e instanceof ve ? gt(r, e, t) : bt(r, e, t);
|
|
116
|
-
} catch (o) {
|
|
117
|
-
ut.warn("Failed to generate preview:", o);
|
|
118
|
-
}
|
|
119
|
-
return r.restore(), a.toDataURL("image/png");
|
|
120
|
-
}
|
|
121
|
-
function bt(e, n, t) {
|
|
122
|
-
var f;
|
|
123
|
-
const a = ((f = n.getBoundingBox) == null ? void 0 : f.call(n)) || { x: 0, y: 0, width: 100, height: 100 }, r = a.width, o = a.height;
|
|
124
|
-
if (r === 0 || o === 0) {
|
|
125
|
-
Qn(e, n, t);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const s = t.width - t.padding * 2, c = t.height - t.padding * 2, i = Math.min(
|
|
129
|
-
s / r,
|
|
130
|
-
c / o,
|
|
131
|
-
1
|
|
132
|
-
// Don't scale up, only down
|
|
133
|
-
), l = r * i, d = o * i, u = t.padding + (s - l) / 2, p = t.padding + (c - d) / 2;
|
|
134
|
-
e.save(), e.translate(u - a.x * i, p - a.y * i), e.scale(i, i), typeof n.render == "function" ? n.render(e, !1, !1) : Qn(e, n, t), e.restore();
|
|
135
|
-
}
|
|
136
|
-
function Qn(e, n, t) {
|
|
137
|
-
e.fillStyle = "#888888", e.font = "10px Arial", e.textAlign = "center", e.textBaseline = "middle";
|
|
138
|
-
const a = n.transformType || "Element";
|
|
139
|
-
e.fillText(a, t.width / 2, t.height / 2);
|
|
140
|
-
}
|
|
141
|
-
function gt(e, n, t) {
|
|
142
|
-
const a = t.width - t.padding * 2, r = t.height - t.padding * 2, o = t.padding, s = t.padding;
|
|
143
|
-
e.fillStyle = "#888888", e.strokeStyle = "#666666", e.lineWidth = 1;
|
|
144
|
-
const c = r * 0.7, i = s + r * 0.3, l = a * 0.4, d = r * 0.2;
|
|
145
|
-
e.fillRect(o, i, a, c), e.fillRect(o, i - d, l, d), n.children && n.children.length > 0 && (e.fillStyle = "#FFFFFF", e.font = "bold 10px Arial", e.textAlign = "center", e.textBaseline = "middle", e.fillText(
|
|
146
|
-
n.children.length.toString(),
|
|
147
|
-
o + a / 2,
|
|
148
|
-
i + c / 2
|
|
149
|
-
));
|
|
150
|
-
}
|
|
151
|
-
function Wa(e, n, t) {
|
|
152
|
-
var l;
|
|
153
|
-
e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180);
|
|
154
|
-
const a = n, r = a.fontSize || 24, o = a.fontFamily || "Arial", s = a.bold || !1, c = a.italic || !1;
|
|
155
|
-
e.font = He(r, o, s, c);
|
|
156
|
-
const i = a.text || "";
|
|
157
|
-
if (n.transformType === "custom") {
|
|
158
|
-
const u = ((l = n.transformData) == null ? void 0 : l.width) || 200, p = Ve(i, r, o, s, c), f = Math.min(p, u), $ = r * 1.2;
|
|
159
|
-
e.rect(-f / 2, -$ / 2, f, $);
|
|
160
|
-
} else {
|
|
161
|
-
const d = e.measureText(i).width;
|
|
162
|
-
e.beginPath(), e.moveTo(-d / 2, 0), e.lineTo(d / 2, 0), e.moveTo(-d / 2, -r), e.lineTo(d / 2, -r), e.moveTo(-d / 2, r * 0.2), e.lineTo(d / 2, r * 0.2);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
function mt(e, n) {
|
|
166
|
-
if (!n.transformData) return;
|
|
167
|
-
const { borderRadius: t = 0 } = n.transformData, a = n.transformData.width ?? 100, r = n.transformData.height ?? 100;
|
|
168
|
-
if (e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180), e.beginPath(), t > 0) {
|
|
169
|
-
const o = Math.min(a, r) / 2, s = Math.min(t, o), c = -a / 2, i = -r / 2;
|
|
170
|
-
e.moveTo(c + s, i), e.lineTo(c + a - s, i), e.arcTo(c + a, i, c + a, i + s, s), e.lineTo(c + a, i + r - s), e.arcTo(c + a, i + r, c + a - s, i + r, s), e.lineTo(c + s, i + r), e.arcTo(c, i + r, c, i + r - s, s), e.lineTo(c, i + s), e.arcTo(c, i, c + s, i, s), e.closePath();
|
|
171
|
-
} else
|
|
172
|
-
e.rect(-a / 2, -r / 2, a, r);
|
|
173
|
-
}
|
|
174
|
-
function za(e, n, t, a) {
|
|
175
|
-
e.beginPath(), e.arc(n, t, a, 0, Math.PI * 2), e.closePath();
|
|
176
|
-
}
|
|
177
|
-
function Ga(e, n, t, a, r) {
|
|
178
|
-
e.beginPath(), e.rect(n, t, a, r), e.closePath();
|
|
179
|
-
}
|
|
180
|
-
function Te(e, n) {
|
|
181
|
-
e.strokeStyle = n.color, e.lineWidth = n.width, e.lineCap = n.lineCap || "butt", e.lineJoin = n.lineJoin || "miter", n.miterLimit !== void 0 && (e.miterLimit = n.miterLimit), n.dashArray && n.dashArray.length > 0 ? e.setLineDash(n.dashArray) : e.setLineDash([]), n.opacity !== void 0 && (e.globalAlpha = n.opacity);
|
|
182
|
-
}
|
|
183
|
-
function yt(e, n) {
|
|
184
|
-
if (typeof OffscreenCanvas < "u")
|
|
185
|
-
return new OffscreenCanvas(e, n);
|
|
186
|
-
const t = document.createElement("canvas");
|
|
187
|
-
return t.width = e, t.height = n, t;
|
|
188
|
-
}
|
|
189
|
-
function _e(e, n, t) {
|
|
190
|
-
var i;
|
|
191
|
-
if (!((i = n.stroke) != null && i.enabled)) return;
|
|
192
|
-
const a = n;
|
|
193
|
-
if (!(a.text || "")) return;
|
|
194
|
-
const o = (t == null ? void 0 : t.isKnockout) === !0, s = n.stroke.opacity ?? 1;
|
|
195
|
-
if (!o && s < 1)
|
|
196
|
-
try {
|
|
197
|
-
$t(e, n, a, t, s);
|
|
198
|
-
} catch {
|
|
199
|
-
cn(e, n, a, t, !1);
|
|
200
|
-
}
|
|
201
|
-
else
|
|
202
|
-
cn(e, n, a, t, o);
|
|
203
|
-
}
|
|
204
|
-
function $t(e, n, t, a, r) {
|
|
205
|
-
var k, _;
|
|
206
|
-
const o = t.text || "", s = t.fontSize || 24, c = n.stroke.width, i = n.stroke.feather || 0, l = n.transformType === "custom" && ((k = n.transformData) == null ? void 0 : k.width), d = l ? ((_ = n.transformData) == null ? void 0 : _.width) ?? 200 : 0, u = l ? d + c * 2 + i * 2 + 40 : s * o.length * 0.7 + c * 2 + i * 2 + 40, p = s * 3 + c * 2 + i * 2 + 40, f = e.getTransform(), $ = Math.max(Math.abs(f.a), Math.abs(f.d), 1), h = Math.ceil(u * $ / 2) * 2, g = Math.ceil(p * $ / 2) * 2;
|
|
207
|
-
if (h <= 0 || g <= 0) {
|
|
208
|
-
cn(e, n, t, a, !1);
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
const v = yt(h, g), y = v.getContext("2d");
|
|
212
|
-
if (!y) {
|
|
213
|
-
cn(e, n, t, a, !1);
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
const x = n.x || 0, m = n.y || 0, b = f.a * x + f.c * m + f.e, C = f.b * x + f.d * m + f.f;
|
|
217
|
-
y.setTransform(
|
|
218
|
-
f.a,
|
|
219
|
-
f.b,
|
|
220
|
-
f.c,
|
|
221
|
-
f.d,
|
|
222
|
-
h / 2 - b + f.e,
|
|
223
|
-
g / 2 - C + f.f
|
|
224
|
-
);
|
|
225
|
-
const T = n.stroke.opacity;
|
|
226
|
-
n.stroke.opacity = 1, cn(y, n, t, a, !1), n.stroke.opacity = T, e.save(), e.resetTransform(), e.globalAlpha = r, e.drawImage(
|
|
227
|
-
v,
|
|
228
|
-
Math.round(b - h / 2),
|
|
229
|
-
Math.round(C - g / 2)
|
|
230
|
-
), e.restore();
|
|
231
|
-
}
|
|
232
|
-
function cn(e, n, t, a, r) {
|
|
233
|
-
var f;
|
|
234
|
-
const o = t.text || "";
|
|
235
|
-
e.save(), a != null && a.positionApplied || (e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180));
|
|
236
|
-
const s = t.fontSize || 24, c = t.fontFamily || "Arial", i = t.bold || !1, l = t.italic || !1, d = t.textAlign || "center";
|
|
237
|
-
e.font = `${l ? "italic " : ""}${i ? "bold " : ""}${s}px ${c}`, e.textAlign = d, e.textBaseline = "alphabetic", r ? (e.strokeStyle = "#000000", e.globalAlpha = 1) : (e.strokeStyle = n.stroke.color, n.stroke.opacity !== void 0 && (e.globalAlpha = n.stroke.opacity)), e.lineWidth = n.stroke.width, e.lineCap = n.stroke.lineCap || "round", e.lineJoin = n.stroke.lineJoin || "round", n.stroke.miterLimit !== void 0 && (e.miterLimit = n.stroke.miterLimit), !r && n.stroke.feather && n.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${n.stroke.feather}px)`);
|
|
238
|
-
const u = je(s, c, i, l);
|
|
239
|
-
if (n.transformType === "custom" && ((f = n.transformData) == null ? void 0 : f.width)) {
|
|
240
|
-
const $ = n.transformData, h = ($ == null ? void 0 : $.width) ?? 200, g = h - Q * 2, v = t.letterSpacing ?? 0, { lines: y, height: x } = we(
|
|
241
|
-
o,
|
|
242
|
-
g,
|
|
243
|
-
s,
|
|
244
|
-
c,
|
|
245
|
-
i,
|
|
246
|
-
l,
|
|
247
|
-
void 0,
|
|
248
|
-
// No locked line count for stroke
|
|
249
|
-
!0,
|
|
250
|
-
// strict: wrap exactly at maxWidth
|
|
251
|
-
{ letterSpacing: v, lineHeight: t.lineHeight }
|
|
252
|
-
), m = -h / 2, b = -x / 2, C = s * (t.lineHeight ?? Gn);
|
|
253
|
-
y.forEach((T, k) => {
|
|
254
|
-
const _ = k === 0, w = k === y.length - 1;
|
|
255
|
-
let A = T;
|
|
256
|
-
if (!_) {
|
|
257
|
-
const P = T.match(/^ +/), I = P ? P[0].length : 0;
|
|
258
|
-
I > 0 && (A = A.substring(I));
|
|
259
|
-
}
|
|
260
|
-
if (!w) {
|
|
261
|
-
const P = A.match(/ +$/), I = P ? P[0].length : 0;
|
|
262
|
-
I > 0 && (A = A.substring(0, A.length - I));
|
|
263
|
-
}
|
|
264
|
-
let E = m + Q;
|
|
265
|
-
d === "center" ? E = m + h / 2 : d === "right" && (E = m + h - Q);
|
|
266
|
-
const S = b + u.ascent + k * C;
|
|
267
|
-
qe(e, A, E, S, v);
|
|
268
|
-
});
|
|
269
|
-
} else {
|
|
270
|
-
const g = -u.height / 2 + u.ascent;
|
|
271
|
-
e.strokeText(o, 0, g);
|
|
272
|
-
}
|
|
273
|
-
e.restore();
|
|
274
|
-
}
|
|
275
|
-
function xt(e, n, t) {
|
|
276
|
-
var r;
|
|
277
|
-
if (!((r = n.stroke) != null && r.enabled) || !n.transformData) return;
|
|
278
|
-
const a = (t == null ? void 0 : t.isKnockout) === !0;
|
|
279
|
-
e.save(), a ? (e.strokeStyle = "#000000", e.lineWidth = n.stroke.width, e.lineCap = n.stroke.lineCap || "butt", e.lineJoin = n.stroke.lineJoin || "miter", e.globalAlpha = 1, n.stroke.miterLimit !== void 0 && (e.miterLimit = n.stroke.miterLimit)) : Te(e, n.stroke), !a && n.stroke.feather && n.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${n.stroke.feather}px)`), mt(e, n), e.stroke(), e.restore();
|
|
280
|
-
}
|
|
281
|
-
function Ha(e, n, t) {
|
|
282
|
-
n.enabled && (e.save(), Te(e, n), n.feather && n.feather > 0 && "filter" in e && (e.filter = `blur(${n.feather}px)`), e.beginPath(), t(), e.stroke(), e.restore());
|
|
283
|
-
}
|
|
284
|
-
const ne = U("GlyphRenderer");
|
|
285
|
-
function vt(e, n, t, a, r, o, s, c = {}) {
|
|
286
|
-
try {
|
|
287
|
-
const i = [];
|
|
288
|
-
Object.entries(s).forEach(([g, v]) => {
|
|
289
|
-
v && i.push(g);
|
|
290
|
-
});
|
|
291
|
-
const l = [];
|
|
292
|
-
n.GSUB && n.GSUB.featureList && n.GSUB.featureList.forEach((g) => {
|
|
293
|
-
l.push(g.tag);
|
|
294
|
-
});
|
|
295
|
-
const d = {};
|
|
296
|
-
d.ccmp = !0, d.locl = !0, d.kern = !0, i.forEach((g) => {
|
|
297
|
-
d[g] = !0;
|
|
298
|
-
}), d.calt && (d.liga = !0, d.init = !0, d.fina = !0);
|
|
299
|
-
const u = n.layout(t, d, "latn"), p = o / n.unitsPerEm;
|
|
300
|
-
let f = 0;
|
|
301
|
-
u.glyphs.forEach((g) => {
|
|
302
|
-
f += g.advanceWidth * p;
|
|
303
|
-
});
|
|
304
|
-
let $ = a;
|
|
305
|
-
c.align === "center" ? $ = a - f / 2 : c.align === "right" && ($ = a - f), e.save(), e.fillStyle = c.color || "#000000";
|
|
306
|
-
let h = $;
|
|
307
|
-
u.glyphs.forEach((g, v) => {
|
|
308
|
-
const y = u.positions[v];
|
|
309
|
-
let x = null;
|
|
310
|
-
try {
|
|
311
|
-
if (g.path && typeof g.path.toPath == "function")
|
|
312
|
-
x = g.path.toPath();
|
|
313
|
-
else if (g.path && typeof g.path.toSVG == "function") {
|
|
314
|
-
const m = g.path.toSVG();
|
|
315
|
-
if (m && /^[MmLlHhVvCcSsQqTtAaZz]/.test(m))
|
|
316
|
-
x = m;
|
|
317
|
-
else {
|
|
318
|
-
const b = m == null ? void 0 : m.match(/\bd=["']([^"']+)["']/);
|
|
319
|
-
x = b ? b[1] : null;
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
} catch (m) {
|
|
323
|
-
ne.warn("Error getting path for glyph:", g.name, m);
|
|
324
|
-
}
|
|
325
|
-
if (x) {
|
|
326
|
-
const m = new Path2D(x);
|
|
327
|
-
e.save(), e.translate(h + y.xOffset * p, r + y.yOffset * p), e.scale(p, -p), e.fill(m), e.restore();
|
|
328
|
-
}
|
|
329
|
-
h += g.advanceWidth * p;
|
|
330
|
-
}), e.restore();
|
|
331
|
-
} catch (i) {
|
|
332
|
-
ne.error("Error rendering with fontkit:", i), e.fillStyle = c.color || "#000000", e.textAlign = c.align || "left", e.fillText(t, a, r);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
function wt(e, n, t, a, r, o, s, c = {}) {
|
|
336
|
-
const l = ((g) => {
|
|
337
|
-
for (const v of g) {
|
|
338
|
-
const y = v.codePointAt(0);
|
|
339
|
-
if (y && y >= 983040 && y <= 1048573) return !0;
|
|
340
|
-
}
|
|
341
|
-
return !1;
|
|
342
|
-
})(t);
|
|
343
|
-
if ((!s || s.length === 0) && !l) {
|
|
344
|
-
e.fillStyle = c.color || "#000000", e.textAlign = c.align || "left", e.fillText(t, a, r);
|
|
345
|
-
return;
|
|
346
|
-
}
|
|
347
|
-
const d = /* @__PURE__ */ new Map();
|
|
348
|
-
s && s.forEach((g) => {
|
|
349
|
-
d.set(g.charIndex, g.glyphIndex);
|
|
350
|
-
});
|
|
351
|
-
const u = o / n.unitsPerEm, p = Array.from(t);
|
|
352
|
-
let f = 0;
|
|
353
|
-
p.forEach((g, v) => {
|
|
354
|
-
const y = g.codePointAt(0) || 0;
|
|
355
|
-
let x;
|
|
356
|
-
if (y >= 983040 && y <= 1048573)
|
|
357
|
-
x = y - 983040;
|
|
358
|
-
else if (x = d.get(v), x === void 0) {
|
|
359
|
-
const b = n.glyphForCodePoint(y);
|
|
360
|
-
x = b ? b.id : 0;
|
|
361
|
-
}
|
|
362
|
-
const m = n.getGlyph(x);
|
|
363
|
-
m && (f += m.advanceWidth * u);
|
|
364
|
-
});
|
|
365
|
-
let $ = a;
|
|
366
|
-
c.align === "center" ? $ = a - f / 2 : c.align === "right" && ($ = a - f), e.save(), e.fillStyle = c.color || "#000000";
|
|
367
|
-
let h = $;
|
|
368
|
-
p.forEach((g, v) => {
|
|
369
|
-
const y = g.codePointAt(0) || 0;
|
|
370
|
-
let x;
|
|
371
|
-
if (y >= 983040 && y <= 1048573)
|
|
372
|
-
x = y - 983040;
|
|
373
|
-
else if (x = d.get(v), x === void 0) {
|
|
374
|
-
const b = n.glyphForCodePoint(y);
|
|
375
|
-
x = b ? b.id : 0;
|
|
376
|
-
}
|
|
377
|
-
const m = n.getGlyph(x);
|
|
378
|
-
if (m) {
|
|
379
|
-
const b = m.path.toSVG();
|
|
380
|
-
if (b) {
|
|
381
|
-
const C = new Path2D(b);
|
|
382
|
-
e.save(), e.translate(h, r), e.scale(u, -u), e.fill(C), e.restore();
|
|
383
|
-
}
|
|
384
|
-
h += m.advanceWidth * u;
|
|
385
|
-
}
|
|
386
|
-
}), e.restore();
|
|
387
|
-
}
|
|
388
|
-
function St(e, n, t, a, r) {
|
|
389
|
-
e.fillStyle = t.color;
|
|
390
|
-
const o = t.textAlign || "center", s = (h) => h.letterSpacing !== void 0 ? h.letterSpacing : t.letterSpacing ?? 0, c = Xe(n);
|
|
391
|
-
let i, l;
|
|
392
|
-
a !== void 0 && a > 0 && !r ? (i = [], l = [], c.forEach((h) => {
|
|
393
|
-
const g = Ye(h, a, t);
|
|
394
|
-
g.forEach((v, y) => {
|
|
395
|
-
i.push(v), l.push({
|
|
396
|
-
isParagraphStart: y === 0,
|
|
397
|
-
isParagraphEnd: y === g.length - 1
|
|
398
|
-
});
|
|
399
|
-
});
|
|
400
|
-
})) : (i = c, l = c.map(() => ({
|
|
401
|
-
isParagraphStart: !0,
|
|
402
|
-
isParagraphEnd: !0
|
|
403
|
-
})));
|
|
404
|
-
const d = [];
|
|
405
|
-
i.forEach((h, g) => {
|
|
406
|
-
const v = [];
|
|
407
|
-
let y = 0, x = 0;
|
|
408
|
-
const m = l[g].isParagraphStart, b = l[g].isParagraphEnd;
|
|
409
|
-
h.forEach((S) => {
|
|
410
|
-
const P = S.style.fontSize !== void 0 ? S.style.fontSize : t.fontSize, I = S.style.fontFamily !== void 0 ? S.style.fontFamily : t.fontFamily, F = S.style.bold !== void 0 ? S.style.bold : t.bold || !1, D = S.style.italic !== void 0 ? S.style.italic : t.italic || !1;
|
|
411
|
-
e.font = B(P, I, F, D);
|
|
412
|
-
const M = on(e.measureText(S.text).width, S.text, s(S.style));
|
|
413
|
-
v.push(M);
|
|
414
|
-
const L = fn(P, I, F, D);
|
|
415
|
-
y = Math.max(y, L.height), x = Math.max(x, L.ascent);
|
|
416
|
-
});
|
|
417
|
-
const C = h.map((S) => S.text).join(""), T = C.match(/^ +/), k = C.match(/ +$/), _ = T ? T[0].length : 0, w = k ? k[0].length : 0;
|
|
418
|
-
let A = 0, E = 0;
|
|
419
|
-
h.forEach((S) => {
|
|
420
|
-
const P = S.style.fontSize !== void 0 ? S.style.fontSize : t.fontSize, I = S.style.fontFamily !== void 0 ? S.style.fontFamily : t.fontFamily, F = S.style.bold !== void 0 ? S.style.bold : t.bold || !1, D = S.style.italic !== void 0 ? S.style.italic : t.italic || !1;
|
|
421
|
-
let M = S.text;
|
|
422
|
-
const L = E, kn = E + S.text.length;
|
|
423
|
-
if (!m && _ > 0 && L < _) {
|
|
424
|
-
const R = Math.min(_ - L, S.text.length);
|
|
425
|
-
M = M.substring(R);
|
|
426
|
-
}
|
|
427
|
-
if (!b && w > 0) {
|
|
428
|
-
const R = C.length - w;
|
|
429
|
-
if (kn > R) {
|
|
430
|
-
const H = !m && _ > 0 && L < _ ? Math.min(_ - L, S.text.length) : 0, Tn = Math.max(0, R - L - H);
|
|
431
|
-
M = M.substring(0, Tn);
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
E += S.text.length, M.length > 0 && (e.save(), e.font = B(P, I, F, D), A += on(
|
|
435
|
-
e.measureText(M).width,
|
|
436
|
-
M,
|
|
437
|
-
s(S.style)
|
|
438
|
-
), e.restore());
|
|
439
|
-
}), d.push({
|
|
440
|
-
spans: h,
|
|
441
|
-
width: A,
|
|
442
|
-
// Use adjusted width for alignment (may be 0 for empty lines)
|
|
443
|
-
height: y,
|
|
444
|
-
ascent: x,
|
|
445
|
-
spanWidths: v,
|
|
446
|
-
isParagraphStart: m,
|
|
447
|
-
// Store metadata with line
|
|
448
|
-
isParagraphEnd: b
|
|
449
|
-
});
|
|
450
|
-
});
|
|
451
|
-
const u = fn(t.fontSize, t.fontFamily, t.bold, t.italic), p = t.fontSize * (t.lineHeight ?? Gn);
|
|
452
|
-
let f;
|
|
453
|
-
d.length === 0 ? f = 0 : d.length === 1 ? f = u.height : f = (d.length - 1) * p + u.height;
|
|
454
|
-
const $ = -f / 2;
|
|
455
|
-
d.forEach((h, g) => {
|
|
456
|
-
const { spans: v, width: y, isParagraphStart: x, isParagraphEnd: m } = h;
|
|
457
|
-
let b;
|
|
458
|
-
o === "center" ? b = -y / 2 : o === "right" ? b = a !== void 0 ? a / 2 - y : -y : b = a !== void 0 ? -a / 2 : 0;
|
|
459
|
-
const C = $ + u.ascent + g * p, T = v.map((S) => S.text).join(""), k = T.match(/^ +/), _ = T.match(/ +$/), w = k ? k[0].length : 0, A = _ ? _[0].length : 0;
|
|
460
|
-
let E = 0;
|
|
461
|
-
v.forEach((S) => {
|
|
462
|
-
const P = S.style.fontSize !== void 0 ? S.style.fontSize : t.fontSize, I = S.style.fontFamily !== void 0 ? S.style.fontFamily : t.fontFamily, F = S.style.color !== void 0 ? S.style.color : t.color, D = S.style.bold !== void 0 ? S.style.bold : t.bold || !1, M = S.style.italic !== void 0 ? S.style.italic : t.italic || !1, L = S.style.underline !== void 0 ? S.style.underline : t.underline || !1, kn = S.style.strikethrough !== void 0 ? S.style.strikethrough : t.strikethrough || !1;
|
|
463
|
-
let R = S.text, H = E, Tn = E + S.text.length;
|
|
464
|
-
if (!x && w > 0 && H < w) {
|
|
465
|
-
const V = Math.min(w - H, S.text.length);
|
|
466
|
-
R = R.substring(V);
|
|
467
|
-
}
|
|
468
|
-
if (!m && A > 0) {
|
|
469
|
-
const V = T.length - A;
|
|
470
|
-
if (Tn > V) {
|
|
471
|
-
const an = !x && w > 0 && H < w ? Math.min(w - H, S.text.length) : 0, j = Math.max(0, V - H - an);
|
|
472
|
-
R = R.substring(0, j);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
if (E += S.text.length, R.length > 0) {
|
|
476
|
-
const V = s(S.style);
|
|
477
|
-
e.font = B(P, I, D, M), e.fillStyle = F, e.textBaseline = "alphabetic", e.textAlign = "left", Hn(e, R, b, C, V);
|
|
478
|
-
const an = on(e.measureText(R).width, R, V);
|
|
479
|
-
if (L) {
|
|
480
|
-
const j = C + P * 0.1;
|
|
481
|
-
e.beginPath(), e.moveTo(b, j), e.lineTo(b + an, j), e.lineWidth = Math.max(1, P * 0.05), e.strokeStyle = F, e.stroke();
|
|
482
|
-
}
|
|
483
|
-
if (kn) {
|
|
484
|
-
const j = C - P * 0.25;
|
|
485
|
-
e.beginPath(), e.moveTo(b, j), e.lineTo(b + an, j), e.lineWidth = Math.max(1, P * 0.05), e.strokeStyle = F, e.stroke();
|
|
486
|
-
}
|
|
487
|
-
b += an;
|
|
488
|
-
}
|
|
489
|
-
});
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
const Pn = U("canvas-renderer");
|
|
493
|
-
let hn = null;
|
|
494
|
-
function Vn() {
|
|
495
|
-
if (!hn)
|
|
496
|
-
if (typeof OffscreenCanvas < "u")
|
|
497
|
-
hn = new OffscreenCanvas(1, 1).getContext("2d");
|
|
498
|
-
else if (typeof document < "u")
|
|
499
|
-
hn = document.createElement("canvas").getContext("2d");
|
|
500
|
-
else
|
|
501
|
-
throw new Error("No canvas context available");
|
|
502
|
-
return hn;
|
|
503
|
-
}
|
|
504
|
-
function B(e, n, t = !1, a = !1) {
|
|
505
|
-
const r = [];
|
|
506
|
-
return a && r.push("italic"), t && r.push("bold"), r.push(`${e}px`), r.push(n), r.join(" ");
|
|
507
|
-
}
|
|
508
|
-
function ee(e, n, t, a = !1, r = !1, o = 0) {
|
|
509
|
-
const s = Vn();
|
|
510
|
-
return s.font = B(n, t, a, r), on(s.measureText(e).width, e, o);
|
|
511
|
-
}
|
|
512
|
-
function fn(e, n, t = !1, a = !1) {
|
|
513
|
-
const r = Vn();
|
|
514
|
-
r.font = B(e, n, t, a);
|
|
515
|
-
const s = r.measureText("ÁÉÍgjpqy"), c = s.actualBoundingBoxAscent || e * 0.8, i = s.actualBoundingBoxDescent || e * 0.2, l = c + i;
|
|
516
|
-
return { ascent: c, descent: i, height: l };
|
|
517
|
-
}
|
|
518
|
-
function Va(e, n) {
|
|
519
|
-
const t = e.map((r, o) => ({
|
|
520
|
-
isParagraphStart: !n && o === 0,
|
|
521
|
-
isParagraphEnd: !n && o === e.length - 1
|
|
522
|
-
}));
|
|
523
|
-
return e.map((r, o) => {
|
|
524
|
-
if (r.trim().length === 0)
|
|
525
|
-
return "";
|
|
526
|
-
const s = t[o].isParagraphStart, c = t[o].isParagraphEnd;
|
|
527
|
-
let i = r;
|
|
528
|
-
return s || (i = i.replace(/^ +/, "")), c || (i = i.replace(/ +$/, "")), i;
|
|
529
|
-
}).filter((r) => r.length > 0);
|
|
530
|
-
}
|
|
531
|
-
function Ct(e, n) {
|
|
532
|
-
const t = n.fontSize, a = n.fontFamily, r = n.bold || !1, o = n.italic || !1, s = n.textAlign || "center", c = n.text;
|
|
533
|
-
e.font = B(t, a, r, o), e.textAlign = s, e.textBaseline = "alphabetic", e.fillStyle = n.color;
|
|
534
|
-
const i = fn(t, a, r, o), u = -i.height / 2 + i.ascent;
|
|
535
|
-
Hn(e, c, 0, u, n.letterSpacing);
|
|
536
|
-
}
|
|
537
|
-
function kt(e, n, t, a, r = !1, o = !1, s) {
|
|
538
|
-
const c = Vn();
|
|
539
|
-
if (c.font = B(t, a, r, o), e.trim().length === 0)
|
|
540
|
-
return [e];
|
|
541
|
-
if (e.includes(`
|
|
542
|
-
`)) {
|
|
543
|
-
const k = e.split(`
|
|
544
|
-
`), _ = [];
|
|
545
|
-
for (let w = 0; w < k.length; w++) {
|
|
546
|
-
const A = k[w], E = kt(A, n, t, a, r, o);
|
|
547
|
-
_.push(...E);
|
|
548
|
-
}
|
|
549
|
-
return _;
|
|
550
|
-
}
|
|
551
|
-
const i = e.match(/^\s*/), l = e.match(/\s*$/), d = i ? i[0] : "", u = l ? l[0] : "", f = e.substring(d.length, e.length - u.length).split(" ");
|
|
552
|
-
if (s !== void 0 && s > 0) {
|
|
553
|
-
if (s === 1)
|
|
554
|
-
return [d + f.join(" ") + u];
|
|
555
|
-
const k = [], _ = Math.ceil(f.length / s);
|
|
556
|
-
for (let w = 0; w < f.length; w += _) {
|
|
557
|
-
const E = f.slice(w, w + _).join(" ");
|
|
558
|
-
w === 0 && w + _ >= f.length ? k.push(d + E + u) : w === 0 ? k.push(d + E) : w + _ >= f.length ? k.push(E + u) : k.push(E);
|
|
559
|
-
}
|
|
560
|
-
return k;
|
|
561
|
-
}
|
|
562
|
-
const $ = f.join(" "), h = d + $ + u, g = c.measureText(h).width, v = n < 200, x = Math.max(20, n * (v ? 0.08 : 0.05));
|
|
563
|
-
if (g <= n + x)
|
|
564
|
-
return [h];
|
|
565
|
-
const m = [];
|
|
566
|
-
let b = f[0];
|
|
567
|
-
const T = Math.max(15, n * (v ? 0.05 : 0.03));
|
|
568
|
-
for (let k = 1; k < f.length; k++) {
|
|
569
|
-
const _ = f[k], w = b + " " + _;
|
|
570
|
-
c.measureText(w).width > n + T ? (m.push(b), b = _) : b = w;
|
|
571
|
-
}
|
|
572
|
-
return m.push(b), m.length > 0 && (m[0] = d + m[0], m[m.length - 1] = m[m.length - 1] + u), m;
|
|
573
|
-
}
|
|
574
|
-
function ja(e, n, t, a, r, o, s = "left", c = 0, i = 0, l = 1.2, d = !1, u = !1, p = !1, f = !1, $, h) {
|
|
575
|
-
e.font = B(r, o, d, u), e.textBaseline = "alphabetic", e.textAlign = s;
|
|
576
|
-
const g = (w) => {
|
|
577
|
-
for (const A of w) {
|
|
578
|
-
const E = A.codePointAt(0);
|
|
579
|
-
if (E && E >= 983040 && E <= 1048573)
|
|
580
|
-
return !0;
|
|
581
|
-
}
|
|
582
|
-
return !1;
|
|
583
|
-
}, v = $ && Object.values($).some((w) => w), y = h && h.length > 0, x = n.join(" "), m = g(x), b = v || y || m, C = b ? Jn.getFontSync(o, d ? 700 : 400) : null;
|
|
584
|
-
b && !C && (Pn.warn(
|
|
585
|
-
`[renderMultilineText] Font ${o} not loaded for fontkit rendering. Text may not render correctly. Has PUA: ${m}, Text: "${x}"`
|
|
586
|
-
), Jn.loadFont(o, d ? 700 : 400).catch((w) => {
|
|
587
|
-
Pn.error("[renderMultilineText] Error loading font:", w);
|
|
588
|
-
}));
|
|
589
|
-
const T = fn(r, o, d, u), k = r * l;
|
|
590
|
-
let _ = 0;
|
|
591
|
-
n.forEach((w, A) => {
|
|
592
|
-
let E = t + i;
|
|
593
|
-
s === "center" ? E = t + c / 2 : s === "right" && (E = t + c - i);
|
|
594
|
-
const S = a + T.ascent + A * k, P = Array.from(w).length, I = y ? h.filter((F) => {
|
|
595
|
-
const D = F.charIndex - _;
|
|
596
|
-
return D >= 0 && D < P;
|
|
597
|
-
}).map((F) => ({
|
|
598
|
-
...F,
|
|
599
|
-
charIndex: F.charIndex - _
|
|
600
|
-
// Adjust to line-relative index
|
|
601
|
-
})) : [];
|
|
602
|
-
if (C && (v || I.length > 0 || m) ? I.length > 0 || g(w) ? wt(e, C, w, E, S, r, I, {
|
|
603
|
-
color: e.fillStyle,
|
|
604
|
-
align: s === "start" || s === "end" ? "left" : s
|
|
605
|
-
}) : $ && vt(e, C, w, E, S, r, $, {
|
|
606
|
-
color: e.fillStyle,
|
|
607
|
-
align: s === "start" || s === "end" ? "left" : s
|
|
608
|
-
}) : e.fillText(w, E, S), _ += P + 1, p) {
|
|
609
|
-
const F = ee(w, r, o, d, u);
|
|
610
|
-
let D = E;
|
|
611
|
-
s === "center" ? D = E - F / 2 : s === "right" && (D = E - F);
|
|
612
|
-
const M = S + r * 0.1;
|
|
613
|
-
e.beginPath(), e.moveTo(D, M), e.lineTo(D + F, M), e.lineWidth = Math.max(1, r * 0.05), e.strokeStyle = e.fillStyle, e.stroke();
|
|
614
|
-
}
|
|
615
|
-
if (f) {
|
|
616
|
-
const F = ee(w, r, o, d, u);
|
|
617
|
-
let D = E;
|
|
618
|
-
s === "center" ? D = E - F / 2 : s === "right" && (D = E - F);
|
|
619
|
-
const M = S - r * 0.25;
|
|
620
|
-
e.beginPath(), e.moveTo(D, M), e.lineTo(D + F, M), e.lineWidth = Math.max(1, r * 0.05), e.strokeStyle = e.fillStyle, e.stroke();
|
|
621
|
-
}
|
|
622
|
-
});
|
|
623
|
-
}
|
|
624
|
-
function In(e, n) {
|
|
625
|
-
Tt(e, n);
|
|
626
|
-
}
|
|
627
|
-
function Tt(e, n) {
|
|
628
|
-
var r;
|
|
629
|
-
(r = n.stroke) != null && r.enabled && _e(e, n), e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180);
|
|
630
|
-
const t = n.transformData, a = ((t == null ? void 0 : t.width) ?? 100) - Q * 2;
|
|
631
|
-
if (n.richText) {
|
|
632
|
-
const o = Ke.fromJSON(n.richText);
|
|
633
|
-
e.save(), e.translate(0, 0);
|
|
634
|
-
const s = n._lockedLineCount;
|
|
635
|
-
St(
|
|
636
|
-
e,
|
|
637
|
-
o,
|
|
638
|
-
{
|
|
639
|
-
fontSize: n.fontSize,
|
|
640
|
-
fontFamily: n.fontFamily,
|
|
641
|
-
color: n.color,
|
|
642
|
-
bold: n.bold,
|
|
643
|
-
italic: n.italic,
|
|
644
|
-
underline: n.underline,
|
|
645
|
-
strikethrough: n.strikethrough,
|
|
646
|
-
textAlign: n.textAlign,
|
|
647
|
-
letterSpacing: n.letterSpacing,
|
|
648
|
-
lineHeight: n.lineHeight
|
|
649
|
-
},
|
|
650
|
-
a,
|
|
651
|
-
s
|
|
652
|
-
), e.restore();
|
|
653
|
-
} else if (n.text) {
|
|
654
|
-
e.fillStyle = n.color;
|
|
655
|
-
const o = n._lockedLineCount, s = n.letterSpacing ?? 0, { lines: c, height: i } = we(
|
|
656
|
-
n.text,
|
|
657
|
-
a,
|
|
658
|
-
n.fontSize,
|
|
659
|
-
n.fontFamily,
|
|
660
|
-
n.bold,
|
|
661
|
-
n.italic,
|
|
662
|
-
o,
|
|
663
|
-
!0,
|
|
664
|
-
// strict: true
|
|
665
|
-
{ letterSpacing: s, lineHeight: n.lineHeight }
|
|
666
|
-
), l = fn(
|
|
667
|
-
n.fontSize,
|
|
668
|
-
n.fontFamily,
|
|
669
|
-
n.bold,
|
|
670
|
-
n.italic
|
|
671
|
-
), d = -((t == null ? void 0 : t.width) ?? 100) / 2, u = -i / 2, p = n.fontSize * (n.lineHeight ?? Gn);
|
|
672
|
-
e.font = `${n.italic ? "italic " : ""}${n.bold ? "bold " : ""}${n.fontSize}px ${n.fontFamily}`, e.textBaseline = "alphabetic", e.textAlign = n.textAlign, c.forEach((f, $) => {
|
|
673
|
-
const h = $ === 0, g = $ === c.length - 1;
|
|
674
|
-
let v = f;
|
|
675
|
-
if (!h) {
|
|
676
|
-
const m = f.match(/^ +/), b = m ? m[0].length : 0;
|
|
677
|
-
b > 0 && (v = v.substring(b));
|
|
678
|
-
}
|
|
679
|
-
if (!g) {
|
|
680
|
-
const m = v.match(/ +$/), b = m ? m[0].length : 0;
|
|
681
|
-
b > 0 && (v = v.substring(0, v.length - b));
|
|
682
|
-
}
|
|
683
|
-
let y = d + Q;
|
|
684
|
-
n.textAlign === "center" ? y = d + ((t == null ? void 0 : t.width) ?? 100) / 2 : n.textAlign === "right" && (y = d + ((t == null ? void 0 : t.width) ?? 100) - Q);
|
|
685
|
-
const x = u + l.ascent + $ * p;
|
|
686
|
-
if (Hn(e, v, y, x, s), v.length > 0) {
|
|
687
|
-
const m = on(e.measureText(v).width, v, s);
|
|
688
|
-
let b = y;
|
|
689
|
-
if (n.textAlign === "center" ? b -= m / 2 : n.textAlign === "right" && (b -= m), n.underline) {
|
|
690
|
-
const C = x + n.fontSize * 0.1;
|
|
691
|
-
e.fillRect(b, C, m, Math.max(1, n.fontSize * 0.05));
|
|
692
|
-
}
|
|
693
|
-
if (n.strikethrough) {
|
|
694
|
-
const C = x - l.ascent * 0.4;
|
|
695
|
-
e.fillRect(b, C, m, Math.max(1, n.fontSize * 0.05));
|
|
696
|
-
}
|
|
697
|
-
}
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
e.restore();
|
|
701
|
-
}
|
|
702
|
-
function qa(e, n) {
|
|
703
|
-
var s;
|
|
704
|
-
const t = n.opacity ?? 1, a = !!((s = n.stroke) != null && s.enabled), r = n.type === "custom";
|
|
705
|
-
if (t < 1 && a && r) {
|
|
706
|
-
_t(e, n, t);
|
|
707
|
-
return;
|
|
708
|
-
}
|
|
709
|
-
const o = e.globalAlpha;
|
|
710
|
-
t !== 1 && (e.globalAlpha = t), Fn(e, n), e.globalAlpha = o;
|
|
711
|
-
}
|
|
712
|
-
function _t(e, n, t) {
|
|
713
|
-
var g;
|
|
714
|
-
const a = n.transformData, r = n.fontSize || 24, o = ((g = n.stroke) == null ? void 0 : g.width) || 0, s = ((a == null ? void 0 : a.width) ?? r * n.text.length * 0.7) + o * 2 + 40, c = r * 3 + o * 2 + 40, i = e.getTransform(), l = Math.max(Math.abs(i.a), Math.abs(i.d), 1), d = Math.ceil(s * l), u = Math.ceil(c * l);
|
|
715
|
-
let p;
|
|
716
|
-
typeof OffscreenCanvas < "u" ? p = new OffscreenCanvas(d, u) : (p = document.createElement("canvas"), p.width = d, p.height = u);
|
|
717
|
-
const f = p.getContext("2d");
|
|
718
|
-
if (!f) {
|
|
719
|
-
const v = e.globalAlpha;
|
|
720
|
-
e.globalAlpha = t, Fn(e, n), e.globalAlpha = v;
|
|
721
|
-
return;
|
|
722
|
-
}
|
|
723
|
-
const $ = i.a * n.x + i.e, h = i.d * n.y + i.f;
|
|
724
|
-
f.setTransform(
|
|
725
|
-
i.a,
|
|
726
|
-
i.b,
|
|
727
|
-
i.c,
|
|
728
|
-
i.d,
|
|
729
|
-
i.e - $ + d / 2,
|
|
730
|
-
i.f - h + u / 2
|
|
731
|
-
), Fn(f, n), e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.globalAlpha = t, e.drawImage(p, $ - d / 2, h - u / 2), e.restore();
|
|
732
|
-
}
|
|
733
|
-
function Fn(e, n) {
|
|
734
|
-
switch (n.type) {
|
|
735
|
-
case "custom":
|
|
736
|
-
In(e, n);
|
|
737
|
-
break;
|
|
738
|
-
case "circle":
|
|
739
|
-
Ee(e, n);
|
|
740
|
-
break;
|
|
741
|
-
case "wave":
|
|
742
|
-
Ae(e, n);
|
|
743
|
-
break;
|
|
744
|
-
case "arch":
|
|
745
|
-
Pe(e, n);
|
|
746
|
-
break;
|
|
747
|
-
case "ascend":
|
|
748
|
-
Ie(e, n);
|
|
749
|
-
break;
|
|
750
|
-
case "lean":
|
|
751
|
-
Fe(e, n);
|
|
752
|
-
break;
|
|
753
|
-
case "flag":
|
|
754
|
-
De(e, n);
|
|
755
|
-
break;
|
|
756
|
-
default:
|
|
757
|
-
Pn.warn(`[canvas-renderer] Unsupported transform type: ${n.type}`), In(e, n);
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
function Et(e, n) {
|
|
761
|
-
if (typeof OffscreenCanvas < "u")
|
|
762
|
-
return new OffscreenCanvas(e, n);
|
|
763
|
-
const t = document.createElement("canvas");
|
|
764
|
-
return t.width = e, t.height = n, t;
|
|
765
|
-
}
|
|
766
|
-
function en(e, n, t) {
|
|
767
|
-
if (t != null && t.enabled)
|
|
768
|
-
if (e.strokeStyle = t.color, e.lineWidth = t.width, e.lineCap = t.lineCap || "round", e.lineJoin = t.lineJoin || "round", t.miterLimit !== void 0 && (e.miterLimit = t.miterLimit), t.opacity !== void 0) {
|
|
769
|
-
const a = e.globalAlpha;
|
|
770
|
-
e.globalAlpha = t.opacity, e.strokeText(n, 0, 0), e.globalAlpha = a;
|
|
771
|
-
} else
|
|
772
|
-
e.strokeText(n, 0, 0);
|
|
773
|
-
}
|
|
774
|
-
function tn(e, n, t) {
|
|
775
|
-
const a = n.stroke, r = (a == null ? void 0 : a.opacity) ?? 1, o = e.globalAlpha, s = (a == null ? void 0 : a.enabled) && r < 1, c = (a == null ? void 0 : a.enabled) && o < 1;
|
|
776
|
-
if (!(s || c)) {
|
|
777
|
-
t(e, n);
|
|
778
|
-
return;
|
|
779
|
-
}
|
|
780
|
-
const l = n.fontSize || 24, d = a.width || 0, u = n.transformData, p = l * n.text.length * 0.7, f = u.width ?? (u.radius ? u.radius * 2 : 0), $ = Math.max(f, p), h = (a.feather || 0) * 2, g = d * 4 + h + l + 40, v = $ + g, y = u.archHeight ? Math.abs(u.archHeight) * l * 2 : 0, x = u.radius ? u.radius : 0, m = l * 3 + g + y + x, b = e.getTransform(), C = Math.max(Math.abs(b.a), Math.abs(b.d), 1), T = Math.ceil(v * C / 2) * 2, k = Math.ceil(m * C / 2) * 2;
|
|
781
|
-
if (T <= 0 || k <= 0) {
|
|
782
|
-
t(e, n);
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
|
-
const _ = Et(T, k), w = _.getContext("2d");
|
|
786
|
-
if (!w) {
|
|
787
|
-
t(e, n);
|
|
788
|
-
return;
|
|
789
|
-
}
|
|
790
|
-
const A = n.x || 0, E = n.y || 0, S = b.a * A + b.c * E + b.e, P = b.b * A + b.d * E + b.f, I = Math.round(S - T / 2), F = Math.round(P - k / 2);
|
|
791
|
-
if (w.setTransform(
|
|
792
|
-
b.a,
|
|
793
|
-
b.b,
|
|
794
|
-
b.c,
|
|
795
|
-
b.d,
|
|
796
|
-
T / 2 - S + b.e,
|
|
797
|
-
k / 2 - P + b.f
|
|
798
|
-
), c) {
|
|
799
|
-
w.globalAlpha = 1;
|
|
800
|
-
const L = a.opacity;
|
|
801
|
-
s && (a.opacity = 1), t(w, n), s && (a.opacity = L), e.save(), e.resetTransform(), e.globalAlpha = o, e.drawImage(_, I, F), e.restore();
|
|
802
|
-
return;
|
|
803
|
-
}
|
|
804
|
-
const D = a.opacity;
|
|
805
|
-
a.opacity = 1, t(w, n), a.opacity = D;
|
|
806
|
-
const M = a.enabled;
|
|
807
|
-
a.enabled = !1, t(e, n), a.enabled = M, e.save(), e.resetTransform(), e.globalAlpha = r, e.drawImage(
|
|
808
|
-
_,
|
|
809
|
-
I,
|
|
810
|
-
F
|
|
811
|
-
), e.restore();
|
|
812
|
-
}
|
|
813
|
-
function Ee(e, n) {
|
|
814
|
-
tn(e, n, At);
|
|
815
|
-
}
|
|
816
|
-
function At(e, n) {
|
|
817
|
-
const t = n.transformData;
|
|
818
|
-
e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.scale(t.scale, t.scale);
|
|
819
|
-
const a = n.bold ? "bold" : "normal", r = n.italic ? "italic" : "normal";
|
|
820
|
-
e.font = `${r} ${a} ${n.fontSize}px ${n.fontFamily}`, e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
821
|
-
const o = n.text.split(""), s = o.map((i) => e.measureText(i).width), c = s.reduce((i, l) => i + l, 0);
|
|
822
|
-
if (t.reverse) {
|
|
823
|
-
let i = Math.PI / 2 + c / (2 * t.radius);
|
|
824
|
-
o.forEach((l, d) => {
|
|
825
|
-
const p = s[d] / t.radius, f = Math.cos(i - p / 2) * t.radius, $ = Math.sin(i - p / 2) * t.radius;
|
|
826
|
-
e.save(), e.translate(f, $), e.rotate(i - p / 2 - Math.PI / 2), en(e, l, n.stroke), e.fillText(l, 0, 0), e.restore(), i -= p;
|
|
827
|
-
});
|
|
828
|
-
} else {
|
|
829
|
-
let i = -Math.PI / 2 - c / (2 * t.radius);
|
|
830
|
-
o.forEach((l, d) => {
|
|
831
|
-
const p = s[d] / t.radius, f = Math.cos(i + p / 2) * t.radius, $ = Math.sin(i + p / 2) * t.radius;
|
|
832
|
-
e.save(), e.translate(f, $), e.rotate(i + p / 2 + Math.PI / 2), en(e, l, n.stroke), e.fillText(l, 0, 0), e.restore(), i += p;
|
|
833
|
-
});
|
|
834
|
-
}
|
|
835
|
-
e.restore();
|
|
836
|
-
}
|
|
837
|
-
function Ae(e, n) {
|
|
838
|
-
tn(e, n, Pt);
|
|
839
|
-
}
|
|
840
|
-
function Pt(e, n) {
|
|
841
|
-
const t = n.transformData;
|
|
842
|
-
e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = B(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
843
|
-
const a = n.text.split("");
|
|
844
|
-
let o = -a.reduce((s, c) => s + e.measureText(c).width, 0) / 2;
|
|
845
|
-
a.forEach((s) => {
|
|
846
|
-
const c = e.measureText(s).width, i = o + c / 2, l = i / (t.width / 2), d = t.amplitude * n.fontSize * Math.sin(t.frequency * Math.PI * l), u = t.amplitude * t.frequency * Math.PI * Math.cos(t.frequency * Math.PI * l);
|
|
847
|
-
e.save(), e.translate(i, d), e.transform(1, u * Je, 0, 1, 0, 0), en(e, s, n.stroke), e.fillText(s, 0, 0), e.restore(), o += c;
|
|
848
|
-
}), e.restore();
|
|
849
|
-
}
|
|
850
|
-
function Pe(e, n) {
|
|
851
|
-
tn(e, n, It);
|
|
852
|
-
}
|
|
853
|
-
function It(e, n) {
|
|
854
|
-
const t = n.transformData;
|
|
855
|
-
e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = B(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
856
|
-
const a = n.text.split(""), r = a.reduce((c, i) => c + e.measureText(i).width, 0), o = t.width / 2;
|
|
857
|
-
let s = -r / 2;
|
|
858
|
-
a.forEach((c) => {
|
|
859
|
-
const i = e.measureText(c).width, l = s + i / 2, d = l / o, u = (Math.pow(d, 2) - 1) * t.archHeight * n.fontSize, p = 2 * d * t.archHeight;
|
|
860
|
-
e.save(), e.translate(l, u), e.transform(1, p * 0.3, 0, 1, 0, 0), en(e, c, n.stroke), e.fillText(c, 0, 0), e.restore(), s += i;
|
|
861
|
-
}), e.restore();
|
|
862
|
-
}
|
|
863
|
-
function Ie(e, n) {
|
|
864
|
-
tn(e, n, Ft);
|
|
865
|
-
}
|
|
866
|
-
function Ft(e, n) {
|
|
867
|
-
const t = n.transformData;
|
|
868
|
-
e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = B(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
869
|
-
const a = n.text.split(""), r = a.reduce((c, i) => c + e.measureText(i).width, 0), o = t.ascendAngle * Math.PI / 180;
|
|
870
|
-
let s = -r / 2;
|
|
871
|
-
a.forEach((c) => {
|
|
872
|
-
const i = e.measureText(c).width, l = s + i / 2, d = l * Math.tan(o), u = Math.tan(o);
|
|
873
|
-
e.save(), e.translate(l, d), e.transform(1, u * 1, 0, 1, 0, 0), en(e, c, n.stroke), e.fillText(c, 0, 0), e.restore(), s += i;
|
|
874
|
-
}), e.restore();
|
|
875
|
-
}
|
|
876
|
-
function Fe(e, n) {
|
|
877
|
-
tn(e, n, Dt);
|
|
878
|
-
}
|
|
879
|
-
function Dt(e, n) {
|
|
880
|
-
var r;
|
|
881
|
-
const t = n.transformData;
|
|
882
|
-
e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180);
|
|
883
|
-
const a = -t.leanAmount * Math.PI / 4;
|
|
884
|
-
e.transform(1, 0, Math.tan(a), 1, 0, 0), e.font = B(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle", (r = n.stroke) != null && r.enabled && (e.save(), e.strokeStyle = n.stroke.color, e.lineWidth = n.stroke.width, e.lineCap = n.stroke.lineCap || "round", e.lineJoin = n.stroke.lineJoin || "round", n.stroke.opacity !== void 0 && (e.globalAlpha = n.stroke.opacity), e.strokeText(n.text, 0, 0), e.restore()), e.fillText(n.text, 0, 0), e.restore();
|
|
885
|
-
}
|
|
886
|
-
function De(e, n) {
|
|
887
|
-
tn(e, n, Mt);
|
|
888
|
-
}
|
|
889
|
-
function Mt(e, n) {
|
|
890
|
-
const t = n.transformData;
|
|
891
|
-
e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = B(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
892
|
-
const a = n.text.split("");
|
|
893
|
-
let o = -a.reduce((s, c) => s + e.measureText(c).width, 0) / 2;
|
|
894
|
-
a.forEach((s) => {
|
|
895
|
-
const c = e.measureText(s).width, i = o + c / 2, l = i / (t.width / 2), d = Math.abs(l), u = t.amplitude * d, p = u * n.fontSize * Math.sin(t.frequency * Math.PI * l), f = u * t.frequency * Math.PI * Math.cos(t.frequency * Math.PI * l), $ = t.amplitude * Math.sign(l) * Math.sin(t.frequency * Math.PI * l), h = f + $;
|
|
896
|
-
e.save(), e.translate(i, p), e.transform(1, h * 0.3, 0, 1, 0, 0), en(e, s, n.stroke), e.fillText(s, 0, 0), e.restore(), o += c;
|
|
897
|
-
}), e.restore();
|
|
898
|
-
}
|
|
899
|
-
function Y(e) {
|
|
900
|
-
return (n, t) => e(n, t);
|
|
901
|
-
}
|
|
902
|
-
function Ot(e, n) {
|
|
903
|
-
e.save();
|
|
904
|
-
const t = e.canvas, a = t.width, r = t.height, o = e.getTransform(), s = [];
|
|
905
|
-
let c = [];
|
|
906
|
-
for (const i of n)
|
|
907
|
-
i.isClipping ? c.length > 0 ? (s.push({ content: c, mask: i }), c = []) : s.push({ content: [i] }) : c.push(i);
|
|
908
|
-
c.length > 0 && s.push({ content: c });
|
|
909
|
-
for (const i of s)
|
|
910
|
-
if (!i.mask)
|
|
911
|
-
i.content.forEach((l) => l.render(e, !1, !1));
|
|
912
|
-
else {
|
|
913
|
-
const l = document.createElement("canvas");
|
|
914
|
-
l.width = a, l.height = r;
|
|
915
|
-
const d = l.getContext("2d");
|
|
916
|
-
if (!d) continue;
|
|
917
|
-
d.setTransform(o), i.content.forEach((f) => {
|
|
918
|
-
f.render(d, !1, !1);
|
|
919
|
-
});
|
|
920
|
-
const u = document.createElement("canvas");
|
|
921
|
-
u.width = a, u.height = r;
|
|
922
|
-
const p = u.getContext("2d");
|
|
923
|
-
if (!p) continue;
|
|
924
|
-
if (p.setTransform(o), i.mask.render(p, !1, !1), i.mask.transformType !== "image" && i.mask.transformType !== "shape") {
|
|
925
|
-
const f = i.mask.getBoundingBox();
|
|
926
|
-
p.save(), p.fillStyle = "#FFFFFF", p.fillRect(f.x, f.y, f.width, f.height), p.restore();
|
|
927
|
-
}
|
|
928
|
-
d.globalCompositeOperation = "destination-in", d.setTransform(1, 0, 0, 1, 0, 0), d.drawImage(u, 0, 0), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(l, 0, 0), e.setTransform(o);
|
|
929
|
-
}
|
|
930
|
-
e.restore();
|
|
931
|
-
}
|
|
932
|
-
var te = !1;
|
|
933
|
-
function jn() {
|
|
934
|
-
te || (te = !0, q("arch", Y(Pe)), q("ascend", Y(Ie)), q("circle", Y(Ee)), q("flag", Y(De)), q("lean", Y(Fe)), q("wave", Y(Ae)), q(
|
|
935
|
-
"custom",
|
|
936
|
-
(e, n) => In(e, n)
|
|
937
|
-
), Ze(Ot), dt(
|
|
938
|
-
(e, n) => ht(e, n)
|
|
939
|
-
), globalThis.__scElementPaintersInstalled = !0);
|
|
940
|
-
}
|
|
941
|
-
jn();
|
|
942
|
-
function qn(e, n, t = {}) {
|
|
943
|
-
const a = t.mode || "both";
|
|
944
|
-
switch (e.save(), e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180), n.transformType) {
|
|
945
|
-
case "image":
|
|
946
|
-
Bt(e, n, a, t);
|
|
947
|
-
break;
|
|
948
|
-
case "shape":
|
|
949
|
-
Lt(e, n, a, t);
|
|
950
|
-
break;
|
|
951
|
-
case "group":
|
|
952
|
-
break;
|
|
953
|
-
default:
|
|
954
|
-
Rt(e, n, a, t);
|
|
955
|
-
break;
|
|
956
|
-
}
|
|
957
|
-
e.restore();
|
|
958
|
-
}
|
|
959
|
-
function Rt(e, n, t, a) {
|
|
960
|
-
var s;
|
|
961
|
-
const r = n, o = r.text || "";
|
|
962
|
-
o && ((t === "stroke" || t === "both") && ((s = n.stroke) != null && s.enabled) && (e.save(), _e(e, n, { ...a.renderingContext, positionApplied: !0 }), e.restore()), (t === "fill" || t === "both") && (e.save(), Ct(e, {
|
|
963
|
-
text: o,
|
|
964
|
-
fontSize: r.fontSize || 24,
|
|
965
|
-
fontFamily: r.fontFamily || "Arial",
|
|
966
|
-
bold: r.bold || !1,
|
|
967
|
-
italic: r.italic || !1,
|
|
968
|
-
textAlign: r.textAlign || "center",
|
|
969
|
-
color: r.color || "#000000",
|
|
970
|
-
letterSpacing: r.letterSpacing
|
|
971
|
-
}), e.restore()));
|
|
972
|
-
}
|
|
973
|
-
function Bt(e, n, t, a) {
|
|
974
|
-
var o;
|
|
975
|
-
if (!n.transformData) return;
|
|
976
|
-
const r = n.transformData;
|
|
977
|
-
if (t === "fill" || t === "both")
|
|
978
|
-
if (Gt(e, n), a.loadedImage) {
|
|
979
|
-
e.save(), e.clip();
|
|
980
|
-
const s = r.flipHorizontal ? -1 : 1, c = r.flipVertical ? -1 : 1;
|
|
981
|
-
e.scale(s, c);
|
|
982
|
-
const i = r.width ?? 100, l = r.height ?? 100;
|
|
983
|
-
e.drawImage(a.loadedImage, -i / 2, -l / 2, i, l), e.restore();
|
|
984
|
-
} else
|
|
985
|
-
e.fillStyle = "#cccccc", e.fill();
|
|
986
|
-
(t === "stroke" || t === "both") && ((o = n.stroke) != null && o.enabled) && (e.save(), xt(e, n, a.renderingContext), e.restore());
|
|
987
|
-
}
|
|
988
|
-
function Lt(e, n, t, a) {
|
|
989
|
-
var s, c;
|
|
990
|
-
if (!n.transformData) return;
|
|
991
|
-
const r = n.transformData, o = ((s = a.renderingContext) == null ? void 0 : s.isKnockout) === !0;
|
|
992
|
-
e.beginPath(), Me(e, r), (t === "fill" || t === "both") && (e.fillStyle = o ? "#000000" : Qe(e, r), e.globalAlpha = o ? 1 : r.fillOpacity ?? 1, e.fill()), (t === "stroke" || t === "both") && ((c = n.stroke) != null && c.enabled) && (e.save(), zt(e, n, a.renderingContext), e.restore());
|
|
993
|
-
}
|
|
994
|
-
function Me(e, n) {
|
|
995
|
-
const { shapeType: t } = n, a = n.width ?? 100, r = n.height ?? 100;
|
|
996
|
-
switch (t) {
|
|
997
|
-
case "rectangle":
|
|
998
|
-
ae(e, n, a, r);
|
|
999
|
-
break;
|
|
1000
|
-
case "circle":
|
|
1001
|
-
Nt(e, Math.min(a, r) / 2);
|
|
1002
|
-
break;
|
|
1003
|
-
case "ellipse":
|
|
1004
|
-
Ut(e, a / 2, r / 2);
|
|
1005
|
-
break;
|
|
1006
|
-
case "star":
|
|
1007
|
-
Wt(e, n, Math.min(a, r) / 2);
|
|
1008
|
-
break;
|
|
1009
|
-
default:
|
|
1010
|
-
ae(e, n, a, r);
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
function ae(e, n, t, a) {
|
|
1014
|
-
const r = n.borderRadius || 0, o = -t / 2, s = -a / 2;
|
|
1015
|
-
if (r > 0) {
|
|
1016
|
-
const c = Math.min(r / 100 * Math.min(t, a), t / 2, a / 2);
|
|
1017
|
-
e.roundRect(o, s, t, a, c);
|
|
1018
|
-
} else
|
|
1019
|
-
e.rect(o, s, t, a);
|
|
1020
|
-
}
|
|
1021
|
-
function Nt(e, n) {
|
|
1022
|
-
e.arc(0, 0, n, 0, Math.PI * 2);
|
|
1023
|
-
}
|
|
1024
|
-
function Ut(e, n, t) {
|
|
1025
|
-
e.ellipse(0, 0, n, t, 0, 0, Math.PI * 2);
|
|
1026
|
-
}
|
|
1027
|
-
function Wt(e, n, t) {
|
|
1028
|
-
const a = Math.max(3, Math.min(20, n.points || 5)), r = Math.max(0.1, Math.min(0.9, n.innerRadius || 0.4)), o = t * r, s = Math.PI / a, c = -Math.PI / 2;
|
|
1029
|
-
for (let i = 0; i < a * 2; i++) {
|
|
1030
|
-
const l = c + s * i, d = i % 2 === 0 ? t : o, u = Math.cos(l) * d, p = Math.sin(l) * d;
|
|
1031
|
-
i === 0 ? e.moveTo(u, p) : e.lineTo(u, p);
|
|
1032
|
-
}
|
|
1033
|
-
e.closePath();
|
|
1034
|
-
}
|
|
1035
|
-
function zt(e, n, t) {
|
|
1036
|
-
var r;
|
|
1037
|
-
if (!((r = n.stroke) != null && r.enabled) || !n.transformData) return;
|
|
1038
|
-
const a = (t == null ? void 0 : t.isKnockout) === !0;
|
|
1039
|
-
e.save(), a ? (e.strokeStyle = "#000000", e.lineWidth = n.stroke.width, e.lineCap = n.stroke.lineCap || "butt", e.lineJoin = n.stroke.lineJoin || "miter", e.globalAlpha = 1) : (e.strokeStyle = n.stroke.color, e.lineWidth = n.stroke.width, e.lineCap = n.stroke.lineCap || "butt", e.lineJoin = n.stroke.lineJoin || "miter", n.stroke.opacity !== void 0 && (e.globalAlpha = n.stroke.opacity)), n.stroke.miterLimit !== void 0 && (e.miterLimit = n.stroke.miterLimit), n.stroke.dashArray && n.stroke.dashArray.length > 0 && e.setLineDash(n.stroke.dashArray), !a && n.stroke.feather && n.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${n.stroke.feather}px)`), e.beginPath(), Me(e, n.transformData), e.stroke(), e.restore();
|
|
1040
|
-
}
|
|
1041
|
-
function Gt(e, n) {
|
|
1042
|
-
if (!n.transformData) return;
|
|
1043
|
-
const { borderRadius: t } = n.transformData, a = n.transformData.width ?? 100, r = n.transformData.height ?? 100, o = -a / 2, s = -r / 2;
|
|
1044
|
-
if (e.beginPath(), t && t > 0) {
|
|
1045
|
-
const c = Math.min(t / 100 * Math.min(a, r), a / 2, r / 2);
|
|
1046
|
-
e.roundRect(o, s, a, r, c);
|
|
1047
|
-
} else
|
|
1048
|
-
e.rect(o, s, a, r);
|
|
1049
|
-
}
|
|
1050
|
-
function Dn(e, n, t, a, r, o, s = "destination-out") {
|
|
1051
|
-
var x;
|
|
1052
|
-
if (!n.knockoutParts) return;
|
|
1053
|
-
if (!(n.knockoutParts.fill || n.knockoutParts.stroke)) {
|
|
1054
|
-
a(e, n);
|
|
1055
|
-
return;
|
|
1056
|
-
}
|
|
1057
|
-
const i = e.getTransform();
|
|
1058
|
-
e.save();
|
|
1059
|
-
const l = n.knockoutParts.scope || "group", d = Ht(n, l, t);
|
|
1060
|
-
if (d.length === 0 && l === "artboard") {
|
|
1061
|
-
jt(e, n, a), e.restore();
|
|
1062
|
-
return;
|
|
1063
|
-
}
|
|
1064
|
-
if (d.length === 0) {
|
|
1065
|
-
a(e, n), e.restore();
|
|
1066
|
-
return;
|
|
1067
|
-
}
|
|
1068
|
-
const u = e.canvas, f = e.getTransform().a, $ = qt(u.width, u.height), h = $.getContext("2d");
|
|
1069
|
-
if (!h) return;
|
|
1070
|
-
h.scale(f, f), r && o && (h.fillStyle = r, h.fillRect(o.x, o.y, o.width, o.height));
|
|
1071
|
-
for (const m of d)
|
|
1072
|
-
a(h, m);
|
|
1073
|
-
n.knockoutParts.fill && !n.knockoutParts.stroke && ((x = n.stroke) != null && x.enabled) && (h.save(), On(h, n), h.restore()), h.save(), h.globalCompositeOperation = s, n.knockoutParts.fill && Mn(h, n), n.knockoutParts.stroke && On(h, n), h.restore(), n.knockoutParts.fill || (h.save(), Mn(h, n), h.restore());
|
|
1074
|
-
const g = u.width / f, v = u.height / f;
|
|
1075
|
-
e.drawImage($, 0, 0, g, v), e.restore();
|
|
1076
|
-
const y = e.getTransform();
|
|
1077
|
-
(Math.abs(y.a - i.a) > 1e-3 || Math.abs(y.d - i.d) > 1e-3 || Math.abs(y.e - i.e) > 1e-3 || Math.abs(y.f - i.f) > 1e-3) && e.setTransform(
|
|
1078
|
-
i.a,
|
|
1079
|
-
i.b,
|
|
1080
|
-
i.c,
|
|
1081
|
-
i.d,
|
|
1082
|
-
i.e,
|
|
1083
|
-
i.f
|
|
1084
|
-
);
|
|
1085
|
-
}
|
|
1086
|
-
function Xa(e, n, t, a, r, o) {
|
|
1087
|
-
Dn(e, n, t, a, r, o, "destination-out");
|
|
1088
|
-
}
|
|
1089
|
-
function Ht(e, n, t) {
|
|
1090
|
-
return n === "artboard" ? Oe(e, t) : Vt(e, t);
|
|
1091
|
-
}
|
|
1092
|
-
function Oe(e, n) {
|
|
1093
|
-
const t = n.findIndex((a) => a.id === e.id);
|
|
1094
|
-
return t === -1 ? [] : n.slice(0, t);
|
|
1095
|
-
}
|
|
1096
|
-
function Vt(e, n) {
|
|
1097
|
-
const t = Re(e, n);
|
|
1098
|
-
if (!t)
|
|
1099
|
-
return Oe(e, n);
|
|
1100
|
-
if (t.transformType !== "group" || !t.children)
|
|
1101
|
-
return [];
|
|
1102
|
-
const a = t.children.findIndex((r) => r.id === e.id);
|
|
1103
|
-
return a === -1 ? [] : t.children.slice(0, a);
|
|
1104
|
-
}
|
|
1105
|
-
function Re(e, n) {
|
|
1106
|
-
for (const t of n)
|
|
1107
|
-
if (t.transformType === "group" && t.children) {
|
|
1108
|
-
if (t.children.some((r) => r.id === e.id))
|
|
1109
|
-
return t;
|
|
1110
|
-
const a = Re(e, t.children);
|
|
1111
|
-
if (a)
|
|
1112
|
-
return a;
|
|
1113
|
-
}
|
|
1114
|
-
return null;
|
|
1115
|
-
}
|
|
1116
|
-
function Mn(e, n, t) {
|
|
1117
|
-
qn(e, n, {
|
|
1118
|
-
mode: "fill",
|
|
1119
|
-
renderingContext: { isKnockout: !0 }
|
|
1120
|
-
});
|
|
1121
|
-
}
|
|
1122
|
-
function On(e, n) {
|
|
1123
|
-
var t;
|
|
1124
|
-
(t = n.stroke) != null && t.enabled && qn(e, n, {
|
|
1125
|
-
mode: "stroke",
|
|
1126
|
-
renderingContext: { isKnockout: !0 }
|
|
1127
|
-
});
|
|
1128
|
-
}
|
|
1129
|
-
function jt(e, n, t) {
|
|
1130
|
-
var r;
|
|
1131
|
-
const a = n.knockoutParts;
|
|
1132
|
-
if (!a) {
|
|
1133
|
-
t(e, n);
|
|
1134
|
-
return;
|
|
1135
|
-
}
|
|
1136
|
-
a.fill || (e.save(), Mn(e, n), e.restore()), !a.stroke && ((r = n.stroke) != null && r.enabled) && (e.save(), On(e, n), e.restore());
|
|
1137
|
-
}
|
|
1138
|
-
function qt(e, n) {
|
|
1139
|
-
if (typeof OffscreenCanvas < "u")
|
|
1140
|
-
return new OffscreenCanvas(e, n);
|
|
1141
|
-
if (typeof document < "u") {
|
|
1142
|
-
const t = document.createElement("canvas");
|
|
1143
|
-
return t.width = e, t.height = n, t;
|
|
1144
|
-
}
|
|
1145
|
-
throw new Error("No canvas context available");
|
|
1146
|
-
}
|
|
1147
|
-
function re(e, n, t, a, r = 0) {
|
|
1148
|
-
if (t <= 0 || a <= 0 || e <= 0 || n <= 0)
|
|
1149
|
-
return { width: e + r, height: n + r };
|
|
1150
|
-
const o = t / a, s = e / n;
|
|
1151
|
-
let c, i;
|
|
1152
|
-
return s > o ? (i = n, c = n * o) : (c = e, i = e / o), {
|
|
1153
|
-
width: c + r,
|
|
1154
|
-
height: i + r
|
|
1155
|
-
};
|
|
1156
|
-
}
|
|
1157
|
-
const rn = 64, _n = 512;
|
|
1158
|
-
function Xt(e, n) {
|
|
1159
|
-
e.beginPath(), e.arc(n / 2, n / 2, n * 0.45, 0, Math.PI * 2), e.fill();
|
|
1160
|
-
}
|
|
1161
|
-
function Yt(e, n) {
|
|
1162
|
-
const t = n / 2, a = n / 2, r = n * 0.45, o = r * 0.4, s = 5;
|
|
1163
|
-
e.beginPath();
|
|
1164
|
-
for (let c = 0; c < s * 2; c++) {
|
|
1165
|
-
const i = -Math.PI / 2 + Math.PI / s * c, l = c % 2 === 0 ? r : o, d = t + Math.cos(i) * l, u = a + Math.sin(i) * l;
|
|
1166
|
-
c === 0 ? e.moveTo(d, u) : e.lineTo(d, u);
|
|
1167
|
-
}
|
|
1168
|
-
e.closePath(), e.fill();
|
|
1169
|
-
}
|
|
1170
|
-
function Kt(e, n) {
|
|
1171
|
-
const t = n / 2, a = n * 0.42;
|
|
1172
|
-
e.beginPath(), e.moveTo(t, n * 0.82), e.bezierCurveTo(t - a * 1.1, n * 0.6, t - a * 1.3, n * 0.2, t, n * 0.35), e.bezierCurveTo(t + a * 1.3, n * 0.2, t + a * 1.1, n * 0.6, t, n * 0.82), e.closePath(), e.fill();
|
|
1173
|
-
}
|
|
1174
|
-
function Jt(e, n) {
|
|
1175
|
-
const t = n / 2, a = n / 2, r = n * 0.4, o = n * 0.48;
|
|
1176
|
-
e.beginPath(), e.moveTo(t, a - o), e.lineTo(t + r, a), e.lineTo(t, a + o), e.lineTo(t - r, a), e.closePath(), e.fill();
|
|
1177
|
-
}
|
|
1178
|
-
function Zt(e, n) {
|
|
1179
|
-
const t = n / 2, a = n / 2, r = n * 0.44;
|
|
1180
|
-
e.beginPath();
|
|
1181
|
-
for (let o = 0; o < 6; o++) {
|
|
1182
|
-
const s = -Math.PI / 2 + Math.PI / 3 * o, c = t + Math.cos(s) * r, i = a + Math.sin(s) * r;
|
|
1183
|
-
o === 0 ? e.moveTo(c, i) : e.lineTo(c, i);
|
|
1184
|
-
}
|
|
1185
|
-
e.closePath(), e.fill();
|
|
1186
|
-
}
|
|
1187
|
-
function Qt(e, n) {
|
|
1188
|
-
const t = n / 2, a = n * 0.4, r = n * 0.12;
|
|
1189
|
-
e.beginPath(), e.moveTo(t, r), e.lineTo(t + a, n * 0.25), e.lineTo(t + a, n * 0.55), e.quadraticCurveTo(t + a * 0.3, n * 0.8, t, n * 0.9), e.quadraticCurveTo(t - a * 0.3, n * 0.8, t - a, n * 0.55), e.lineTo(t - a, n * 0.25), e.closePath(), e.fill();
|
|
1190
|
-
}
|
|
1191
|
-
function na(e, n) {
|
|
1192
|
-
const t = n / 2, a = n / 2;
|
|
1193
|
-
let r = 42;
|
|
1194
|
-
const o = () => (r = (r * 16807 + 0) % 2147483647, r / 2147483647);
|
|
1195
|
-
e.beginPath(), e.arc(t, a, n * 0.28, 0, Math.PI * 2), e.fill();
|
|
1196
|
-
for (let s = 0; s < 30; s++) {
|
|
1197
|
-
const c = o() * Math.PI * 2, i = n * 0.15 + o() * n * 0.3, l = n * 0.02 + o() * n * 0.06;
|
|
1198
|
-
e.beginPath(), e.arc(t + Math.cos(c) * i, a + Math.sin(c) * i, l, 0, Math.PI * 2), e.fill();
|
|
1199
|
-
}
|
|
1200
|
-
}
|
|
1201
|
-
function ea(e, n) {
|
|
1202
|
-
let t = 123;
|
|
1203
|
-
const a = () => (t = (t * 16807 + 0) % 2147483647, t / 2147483647), r = n * 0.08, o = 40;
|
|
1204
|
-
e.beginPath(), e.moveTo(r, r);
|
|
1205
|
-
for (let s = 1; s <= o; s++) {
|
|
1206
|
-
const c = r + (n - 2 * r) * (s / o), i = r + (a() - 0.5) * n * 0.08;
|
|
1207
|
-
e.lineTo(c, i);
|
|
1208
|
-
}
|
|
1209
|
-
for (let s = 1; s <= o; s++) {
|
|
1210
|
-
const c = n - r + (a() - 0.5) * n * 0.08, i = r + (n - 2 * r) * (s / o);
|
|
1211
|
-
e.lineTo(c, i);
|
|
1212
|
-
}
|
|
1213
|
-
for (let s = o; s >= 0; s--) {
|
|
1214
|
-
const c = r + (n - 2 * r) * (s / o), i = n - r + (a() - 0.5) * n * 0.08;
|
|
1215
|
-
e.lineTo(c, i);
|
|
1216
|
-
}
|
|
1217
|
-
for (let s = o; s >= 0; s--) {
|
|
1218
|
-
const c = r + (a() - 0.5) * n * 0.08, i = r + (n - 2 * r) * (s / o);
|
|
1219
|
-
e.lineTo(c, i);
|
|
1220
|
-
}
|
|
1221
|
-
e.closePath(), e.fill();
|
|
1222
|
-
}
|
|
1223
|
-
function ta(e, n) {
|
|
1224
|
-
let t = 77;
|
|
1225
|
-
const a = () => (t = (t * 16807 + 0) % 2147483647, t / 2147483647), r = n * 0.25, o = n * 0.75, s = n * 0.1;
|
|
1226
|
-
e.beginPath(), e.moveTo(s, r + a() * n * 0.05);
|
|
1227
|
-
for (let c = 1; c <= 10; c++) {
|
|
1228
|
-
const i = s + (n - 2 * s) * (c / 10), l = r + (a() - 0.5) * n * 0.1;
|
|
1229
|
-
e.lineTo(i, l);
|
|
1230
|
-
}
|
|
1231
|
-
for (let c = 10; c >= 0; c--) {
|
|
1232
|
-
const i = s + (n - 2 * s) * (c / 10), l = o + (a() - 0.5) * n * 0.1;
|
|
1233
|
-
e.lineTo(i, l);
|
|
1234
|
-
}
|
|
1235
|
-
e.closePath(), e.fill();
|
|
1236
|
-
}
|
|
1237
|
-
function aa(e, n) {
|
|
1238
|
-
const t = n / 2, a = n * 0.55;
|
|
1239
|
-
e.beginPath(), e.arc(t, a, n * 0.2, 0, Math.PI * 2), e.fill(), e.beginPath(), e.arc(t - n * 0.18, a + n * 0.02, n * 0.15, 0, Math.PI * 2), e.fill(), e.beginPath(), e.arc(t + n * 0.18, a + n * 0.02, n * 0.16, 0, Math.PI * 2), e.fill(), e.beginPath(), e.arc(t - n * 0.06, a - n * 0.14, n * 0.14, 0, Math.PI * 2), e.fill(), e.beginPath(), e.arc(t + n * 0.1, a - n * 0.12, n * 0.12, 0, Math.PI * 2), e.fill();
|
|
1240
|
-
}
|
|
1241
|
-
const ra = [
|
|
1242
|
-
// Geometric
|
|
1243
|
-
{ id: "circle", name: "Circle", description: "Perfect circle", imageUrl: "builtin-mask:circle", thumbnailUrl: "", category: "geometric", draw: Xt },
|
|
1244
|
-
{ id: "star", name: "Star", description: "5-pointed star", imageUrl: "builtin-mask:star", thumbnailUrl: "", category: "geometric", draw: Yt },
|
|
1245
|
-
{ id: "heart", name: "Heart", description: "Heart shape", imageUrl: "builtin-mask:heart", thumbnailUrl: "", category: "geometric", draw: Kt },
|
|
1246
|
-
{ id: "diamond", name: "Diamond", description: "Diamond/rhombus", imageUrl: "builtin-mask:diamond", thumbnailUrl: "", category: "geometric", draw: Jt },
|
|
1247
|
-
{ id: "hexagon", name: "Hexagon", description: "Regular hexagon", imageUrl: "builtin-mask:hexagon", thumbnailUrl: "", category: "geometric", draw: Zt },
|
|
1248
|
-
{ id: "shield", name: "Shield", description: "Shield/crest shape", imageUrl: "builtin-mask:shield", thumbnailUrl: "", category: "geometric", draw: Qt },
|
|
1249
|
-
// Organic
|
|
1250
|
-
{ id: "splatter", name: "Splatter", description: "Ink splatter", imageUrl: "builtin-mask:splatter", thumbnailUrl: "", category: "organic", draw: na },
|
|
1251
|
-
{ id: "torn-edge", name: "Torn Edge", description: "Rough torn paper edge", imageUrl: "builtin-mask:torn-edge", thumbnailUrl: "", category: "organic", draw: ea },
|
|
1252
|
-
{ id: "paint-stroke", name: "Paint Stroke", description: "Horizontal brush stroke", imageUrl: "builtin-mask:paint-stroke", thumbnailUrl: "", category: "organic", draw: ta },
|
|
1253
|
-
{ id: "cloud", name: "Cloud", description: "Soft cloud shape", imageUrl: "builtin-mask:cloud", thumbnailUrl: "", category: "organic", draw: aa }
|
|
1254
|
-
];
|
|
1255
|
-
let se = !1;
|
|
1256
|
-
function ie(e, n) {
|
|
1257
|
-
if (typeof document > "u") return null;
|
|
1258
|
-
const t = document.createElement("canvas");
|
|
1259
|
-
return t.width = e, t.height = n, t;
|
|
1260
|
-
}
|
|
1261
|
-
function sa() {
|
|
1262
|
-
if (typeof document > "u" || se) return;
|
|
1263
|
-
se = !0;
|
|
1264
|
-
const e = wn.getInstance();
|
|
1265
|
-
for (const n of ra) {
|
|
1266
|
-
const t = ie(_n, _n);
|
|
1267
|
-
if (!t) continue;
|
|
1268
|
-
const a = t.getContext("2d");
|
|
1269
|
-
if (!a) continue;
|
|
1270
|
-
a.fillStyle = "white", n.draw(a, _n);
|
|
1271
|
-
const r = t.toDataURL("image/png"), o = e.acquire(n.imageUrl);
|
|
1272
|
-
o.crossOrigin = "anonymous", o.src = r;
|
|
1273
|
-
const s = ie(rn, rn);
|
|
1274
|
-
if (s) {
|
|
1275
|
-
const c = s.getContext("2d");
|
|
1276
|
-
c && (c.fillStyle = "#1a1a2e", c.fillRect(0, 0, rn, rn), c.fillStyle = "white", n.draw(c, rn), n.thumbnailUrl = s.toDataURL("image/png"));
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
}
|
|
1280
|
-
const ia = U("MaskRenderer"), Rn = /* @__PURE__ */ new Map(), oa = /* @__PURE__ */ new Map();
|
|
1281
|
-
function Ya(e) {
|
|
1282
|
-
const n = [];
|
|
1283
|
-
Rn.forEach((t, a) => {
|
|
1284
|
-
a.startsWith(e) && n.push(a);
|
|
1285
|
-
}), n.forEach((t) => Rn.delete(t));
|
|
1286
|
-
}
|
|
1287
|
-
function Ka() {
|
|
1288
|
-
Rn.clear();
|
|
1289
|
-
}
|
|
1290
|
-
function oe(e, n, t) {
|
|
1291
|
-
if (!n.masks || n.masks.length === 0) {
|
|
1292
|
-
t(e);
|
|
1293
|
-
return;
|
|
1294
|
-
}
|
|
1295
|
-
const a = e.canvas, r = gn(a.width, a.height), o = r.getContext("2d");
|
|
1296
|
-
if (!o) {
|
|
1297
|
-
ia.error("[renderWithMasks] Failed to get offscreen context");
|
|
1298
|
-
return;
|
|
1299
|
-
}
|
|
1300
|
-
const s = e.getTransform();
|
|
1301
|
-
o.setTransform(s), t(o);
|
|
1302
|
-
for (const c of n.masks)
|
|
1303
|
-
ca(o, c, n);
|
|
1304
|
-
e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(r, 0, 0), e.restore();
|
|
1305
|
-
}
|
|
1306
|
-
function ca(e, n, t) {
|
|
1307
|
-
switch (n.type) {
|
|
1308
|
-
case "clip":
|
|
1309
|
-
la(e, n, t);
|
|
1310
|
-
break;
|
|
1311
|
-
case "alpha":
|
|
1312
|
-
da(e, n, t);
|
|
1313
|
-
break;
|
|
1314
|
-
case "luma":
|
|
1315
|
-
fa(e, n, t);
|
|
1316
|
-
break;
|
|
1317
|
-
case "distress":
|
|
1318
|
-
ua(e, n, t);
|
|
1319
|
-
break;
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
function la(e, n, t) {
|
|
1323
|
-
e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), Sn(e, n.maskElement, t), e.restore();
|
|
1324
|
-
}
|
|
1325
|
-
function da(e, n, t) {
|
|
1326
|
-
e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), Sn(e, n.maskElement, t), n.feather && n.feather > 0 && Be(e, n.feather), e.restore();
|
|
1327
|
-
}
|
|
1328
|
-
function fa(e, n, t) {
|
|
1329
|
-
const a = gn(e.canvas.width, e.canvas.height), r = a.getContext("2d");
|
|
1330
|
-
if (!r) return;
|
|
1331
|
-
Sn(r, n.maskElement, t);
|
|
1332
|
-
const o = r.getImageData(0, 0, a.width, a.height), s = o.data;
|
|
1333
|
-
for (let c = 0; c < s.length; c += 4) {
|
|
1334
|
-
const i = s[c], l = s[c + 1], d = s[c + 2], u = 0.299 * i + 0.587 * l + 0.114 * d;
|
|
1335
|
-
s[c + 3] = n.inverted ? 255 - u : u;
|
|
1336
|
-
}
|
|
1337
|
-
r.putImageData(o, 0, 0), e.save(), e.globalCompositeOperation = "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), e.drawImage(a, 0, 0), e.restore();
|
|
1338
|
-
}
|
|
1339
|
-
function ua(e, n, t) {
|
|
1340
|
-
e.save(), e.globalCompositeOperation = n.inverted ? "destination-in" : "destination-out", n.opacity !== void 0 && (e.globalAlpha = n.opacity), Sn(e, n.maskElement, t), n.feather && n.feather > 0 && Be(e, n.feather), e.restore();
|
|
1341
|
-
}
|
|
1342
|
-
function Sn(e, n, t) {
|
|
1343
|
-
const a = t.x || 0, r = t.y || 0, o = n.x || 0, s = n.y || 0, c = {
|
|
1344
|
-
...n,
|
|
1345
|
-
x: a + o,
|
|
1346
|
-
y: r + s,
|
|
1347
|
-
// Inherit parent rotation so mask rotates with the element
|
|
1348
|
-
rotation: (n.rotation || 0) + (t.rotation || 0)
|
|
1349
|
-
}, i = 4, l = t.transformData, d = t, u = (l == null ? void 0 : l.width) || d.width || 0, p = (l == null ? void 0 : l.height) || d.height || 0, f = n.transformData;
|
|
1350
|
-
u && p && f && (c.transformData = {
|
|
1351
|
-
...f,
|
|
1352
|
-
width: u + i,
|
|
1353
|
-
height: p + i
|
|
1354
|
-
});
|
|
1355
|
-
let $, h;
|
|
1356
|
-
if (n.transformType === "image") {
|
|
1357
|
-
const m = n;
|
|
1358
|
-
if (m.imageUrl)
|
|
1359
|
-
if (typeof document < "u") {
|
|
1360
|
-
m.imageUrl.startsWith("builtin-mask:") && sa();
|
|
1361
|
-
const b = wn.getInstance(), C = b.acquire(m.imageUrl);
|
|
1362
|
-
C.complete && C.naturalWidth > 0 && ($ = C), b.release(m.imageUrl);
|
|
1363
|
-
} else
|
|
1364
|
-
h = oa.get(m.imageUrl);
|
|
1365
|
-
}
|
|
1366
|
-
const g = c.transformData, v = (f == null ? void 0 : f.width) || 0, y = (f == null ? void 0 : f.height) || 0, x = v > 0 && y > 0 && u > 0 && p > 0 && Math.abs(v / y - u / p) > 1e-3;
|
|
1367
|
-
if (h) {
|
|
1368
|
-
e.save();
|
|
1369
|
-
const m = (g == null ? void 0 : g.width) || h.width, b = (g == null ? void 0 : g.height) || h.height;
|
|
1370
|
-
if (e.translate(c.x || 0, c.y || 0), e.rotate(-(c.rotation || 0) * Math.PI / 180), x) {
|
|
1371
|
-
const C = re(
|
|
1372
|
-
m,
|
|
1373
|
-
b,
|
|
1374
|
-
v,
|
|
1375
|
-
y,
|
|
1376
|
-
0
|
|
1377
|
-
);
|
|
1378
|
-
e.drawImage(h, -C.width / 2, -C.height / 2, C.width, C.height);
|
|
1379
|
-
} else
|
|
1380
|
-
e.drawImage(h, -m / 2, -b / 2, m, b);
|
|
1381
|
-
e.restore();
|
|
1382
|
-
} else if (x && $) {
|
|
1383
|
-
const m = (g == null ? void 0 : g.width) || u, b = (g == null ? void 0 : g.height) || p, C = re(
|
|
1384
|
-
m,
|
|
1385
|
-
b,
|
|
1386
|
-
v,
|
|
1387
|
-
y,
|
|
1388
|
-
0
|
|
1389
|
-
);
|
|
1390
|
-
e.save(), e.translate(c.x || 0, c.y || 0), e.rotate(-(c.rotation || 0) * Math.PI / 180), e.drawImage($, -C.width / 2, -C.height / 2, C.width, C.height), e.restore();
|
|
1391
|
-
} else
|
|
1392
|
-
qn(e, c, { mode: "both", loadedImage: $ });
|
|
1393
|
-
}
|
|
1394
|
-
function Be(e, n) {
|
|
1395
|
-
"filter" in e && (e.filter = `blur(${n}px)`);
|
|
1396
|
-
}
|
|
1397
|
-
function gn(e, n) {
|
|
1398
|
-
if (typeof OffscreenCanvas < "u")
|
|
1399
|
-
return new OffscreenCanvas(e, n);
|
|
1400
|
-
if (typeof document < "u") {
|
|
1401
|
-
const t = document.createElement("canvas");
|
|
1402
|
-
return t.width = e, t.height = n, t;
|
|
1403
|
-
}
|
|
1404
|
-
throw new Error("No canvas context available");
|
|
1405
|
-
}
|
|
1406
|
-
function pa(e, n, t, a) {
|
|
1407
|
-
if (!n.enabled || !n.imageUrl || n.opacity <= 0) return;
|
|
1408
|
-
const r = wn.getInstance(), o = r.acquire(n.imageUrl);
|
|
1409
|
-
if (!o.complete || o.naturalWidth === 0) {
|
|
1410
|
-
r.release(n.imageUrl);
|
|
1411
|
-
return;
|
|
1412
|
-
}
|
|
1413
|
-
const { x: s, y: c, width: i, height: l } = t, d = e.getTransform(), u = d.a * s + d.e, p = d.d * c + d.f, f = d.a * i, $ = d.d * l, h = Math.ceil(f), g = Math.ceil($);
|
|
1414
|
-
if (h <= 0 || g <= 0) {
|
|
1415
|
-
r.release(n.imageUrl);
|
|
1416
|
-
return;
|
|
1417
|
-
}
|
|
1418
|
-
const v = gn(h, g), y = v.getContext("2d");
|
|
1419
|
-
if (!y) {
|
|
1420
|
-
r.release(n.imageUrl);
|
|
1421
|
-
return;
|
|
1422
|
-
}
|
|
1423
|
-
y.drawImage(
|
|
1424
|
-
e.canvas,
|
|
1425
|
-
u,
|
|
1426
|
-
p,
|
|
1427
|
-
f,
|
|
1428
|
-
$,
|
|
1429
|
-
0,
|
|
1430
|
-
0,
|
|
1431
|
-
h,
|
|
1432
|
-
g
|
|
1433
|
-
);
|
|
1434
|
-
let x;
|
|
1435
|
-
if (n.maskType === "luma" ? x = "destination-in" : x = n.inverted ? "destination-out" : "destination-in", n.maskType === "luma") {
|
|
1436
|
-
const m = gn(h, g), b = m.getContext("2d");
|
|
1437
|
-
if (b) {
|
|
1438
|
-
b.drawImage(o, 0, 0, h, g);
|
|
1439
|
-
const C = b.getImageData(0, 0, h, g), T = C.data;
|
|
1440
|
-
for (let k = 0; k < T.length; k += 4) {
|
|
1441
|
-
const _ = 0.299 * T[k] + 0.587 * T[k + 1] + 0.114 * T[k + 2];
|
|
1442
|
-
T[k + 3] = n.inverted ? 255 - _ : _;
|
|
1443
|
-
}
|
|
1444
|
-
b.putImageData(C, 0, 0), y.globalCompositeOperation = "destination-in", y.globalAlpha = n.opacity / 100, y.drawImage(m, 0, 0);
|
|
1445
|
-
}
|
|
1446
|
-
} else
|
|
1447
|
-
y.globalCompositeOperation = x, y.globalAlpha = n.opacity / 100, y.drawImage(o, 0, 0, h, g);
|
|
1448
|
-
y.globalCompositeOperation = "source-over", y.globalAlpha = 1, e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.clearRect(u, p, f, $), a && (e.fillStyle = a, e.fillRect(u, p, f, $)), e.drawImage(v, u, p), e.restore(), r.release(n.imageUrl);
|
|
1449
|
-
}
|
|
1450
|
-
function ha(e) {
|
|
1451
|
-
var n;
|
|
1452
|
-
return e ? ((n = e.shadow) == null ? void 0 : n.enabled) === !0 || Se(e.blendMode) : !1;
|
|
1453
|
-
}
|
|
1454
|
-
function ce(e, n, t) {
|
|
1455
|
-
var l;
|
|
1456
|
-
if (!ha(n)) {
|
|
1457
|
-
t(e);
|
|
1458
|
-
return;
|
|
1459
|
-
}
|
|
1460
|
-
const a = (l = n.shadow) != null && l.enabled ? n.shadow : void 0, r = Se(n.blendMode) ? n.blendMode : void 0, o = e.canvas, s = e.getTransform(), c = ga(o.width, o.height), i = c.getContext("2d");
|
|
1461
|
-
if (!i)
|
|
1462
|
-
throw new Error(
|
|
1463
|
-
"[canvas] renderWithLayerEffects: could not acquire a 2D context for the layer-effects raster"
|
|
1464
|
-
);
|
|
1465
|
-
if (i.setTransform(s), t(i), e.save(), e.setTransform(1, 0, 0, 1, 0, 0), r && (e.globalCompositeOperation = r), a) {
|
|
1466
|
-
const d = Math.hypot(s.a, s.b) || 1, u = o.width + 1;
|
|
1467
|
-
e.save(), e.globalAlpha = e.globalAlpha * ba(a.opacity ?? 1), e.shadowColor = a.color, e.shadowBlur = a.blur * d, e.shadowOffsetX = a.offsetX * d + u, e.shadowOffsetY = a.offsetY * d, e.drawImage(c, -u, 0), e.restore();
|
|
1468
|
-
}
|
|
1469
|
-
e.drawImage(c, 0, 0), e.restore();
|
|
1470
|
-
}
|
|
1471
|
-
function ba(e) {
|
|
1472
|
-
return Math.min(1, Math.max(0, e));
|
|
1473
|
-
}
|
|
1474
|
-
function ga(e, n) {
|
|
1475
|
-
if (typeof OffscreenCanvas < "u")
|
|
1476
|
-
return new OffscreenCanvas(e, n);
|
|
1477
|
-
if (typeof document < "u") {
|
|
1478
|
-
const t = document.createElement("canvas");
|
|
1479
|
-
return t.width = e, t.height = n, t;
|
|
1480
|
-
}
|
|
1481
|
-
throw new Error("No canvas context available");
|
|
1482
|
-
}
|
|
1483
|
-
class ma {
|
|
1484
|
-
constructor(n = Math.random()) {
|
|
1485
|
-
this.perm = [];
|
|
1486
|
-
for (let a = 0; a < 256; a++)
|
|
1487
|
-
this.perm[a] = a;
|
|
1488
|
-
const t = this.seededRandom(n);
|
|
1489
|
-
for (let a = 255; a > 0; a--) {
|
|
1490
|
-
const r = Math.floor(t() * (a + 1));
|
|
1491
|
-
[this.perm[a], this.perm[r]] = [this.perm[r], this.perm[a]];
|
|
1492
|
-
}
|
|
1493
|
-
for (let a = 0; a < 256; a++)
|
|
1494
|
-
this.perm[256 + a] = this.perm[a];
|
|
1495
|
-
}
|
|
1496
|
-
seededRandom(n) {
|
|
1497
|
-
let t = Math.sin(n++) * 1e4;
|
|
1498
|
-
return () => (t = Math.sin(n++) * 1e4, t - Math.floor(t));
|
|
1499
|
-
}
|
|
1500
|
-
fade(n) {
|
|
1501
|
-
return n * n * n * (n * (n * 6 - 15) + 10);
|
|
1502
|
-
}
|
|
1503
|
-
lerp(n, t, a) {
|
|
1504
|
-
return t + n * (a - t);
|
|
1505
|
-
}
|
|
1506
|
-
grad(n, t, a) {
|
|
1507
|
-
const r = n & 15, o = r < 8 ? t : a, s = r < 4 ? a : r === 12 || r === 14 ? t : 0;
|
|
1508
|
-
return ((r & 1) === 0 ? o : -o) + ((r & 2) === 0 ? s : -s);
|
|
1509
|
-
}
|
|
1510
|
-
noise(n, t) {
|
|
1511
|
-
const a = Math.floor(n) & 255, r = Math.floor(t) & 255;
|
|
1512
|
-
n -= Math.floor(n), t -= Math.floor(t);
|
|
1513
|
-
const o = this.fade(n), s = this.fade(t), c = this.perm[a] + r, i = this.perm[a + 1] + r;
|
|
1514
|
-
return this.lerp(
|
|
1515
|
-
s,
|
|
1516
|
-
this.lerp(o, this.grad(this.perm[c], n, t), this.grad(this.perm[i], n - 1, t)),
|
|
1517
|
-
this.lerp(o, this.grad(this.perm[c + 1], n, t - 1), this.grad(this.perm[i + 1], n - 1, t - 1))
|
|
1518
|
-
);
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
function En(e, n, t, a = Date.now()) {
|
|
1522
|
-
const s = Cn(e, n).getContext("2d").createImageData(e, n), c = s.data, i = new ma(a), l = 0.02, d = 1 - t / 100;
|
|
1523
|
-
for (let u = 0; u < n; u++)
|
|
1524
|
-
for (let p = 0; p < e; p++) {
|
|
1525
|
-
const f = (u * e + p) * 4;
|
|
1526
|
-
let $ = 0;
|
|
1527
|
-
$ += i.noise(p * l, u * l) * 0.5, $ += i.noise(p * l * 2, u * l * 2) * 0.25, $ += i.noise(p * l * 4, u * l * 4) * 0.125, $ = ($ + 1) / 2;
|
|
1528
|
-
const h = Math.min(p / e, (e - p) / e) * 2, g = Math.min(u / n, (n - u) / n) * 2, v = Math.min(h, g);
|
|
1529
|
-
$ *= 0.7 + v * 0.3;
|
|
1530
|
-
const y = $ > d ? 255 : 0;
|
|
1531
|
-
c[f] = 255, c[f + 1] = 255, c[f + 2] = 255, c[f + 3] = y;
|
|
1532
|
-
}
|
|
1533
|
-
return s;
|
|
1534
|
-
}
|
|
1535
|
-
function ya(e, n, t, a = Date.now()) {
|
|
1536
|
-
const o = Cn(e, n).getContext("2d");
|
|
1537
|
-
o.clearRect(0, 0, e, n), o.strokeStyle = "#000000", o.lineWidth = 1 + t / 50, o.lineCap = "round";
|
|
1538
|
-
const s = Xn(a), c = Math.floor(t / 100 * 30 + 5);
|
|
1539
|
-
for (let i = 0; i < c; i++) {
|
|
1540
|
-
const l = s() * e, d = s() * n;
|
|
1541
|
-
Bn(o, l, d, s() * Math.PI * 2, 50 + s() * 100, s, 0);
|
|
1542
|
-
}
|
|
1543
|
-
return o.getImageData(0, 0, e, n);
|
|
1544
|
-
}
|
|
1545
|
-
function Bn(e, n, t, a, r, o, s) {
|
|
1546
|
-
if (s > 3 || r < 10) return;
|
|
1547
|
-
const c = n + Math.cos(a) * r, i = t + Math.sin(a) * r;
|
|
1548
|
-
if (e.beginPath(), e.moveTo(n, t), e.lineTo(c, i), e.stroke(), o() > 0.5) {
|
|
1549
|
-
const l = a + (o() - 0.5) * Math.PI / 2;
|
|
1550
|
-
Bn(e, c, i, l, r * 0.6, o, s + 1);
|
|
1551
|
-
}
|
|
1552
|
-
if (o() > 0.7) {
|
|
1553
|
-
const l = a - (o() - 0.5) * Math.PI / 2;
|
|
1554
|
-
Bn(e, c, i, l, r * 0.6, o, s + 1);
|
|
1555
|
-
}
|
|
1556
|
-
}
|
|
1557
|
-
function bn(e, n, t, a = Date.now()) {
|
|
1558
|
-
const s = Cn(e, n).getContext("2d").createImageData(e, n), c = s.data, i = Xn(a), l = t / 100 * 0.5;
|
|
1559
|
-
for (let d = 0; d < n; d++)
|
|
1560
|
-
for (let u = 0; u < e; u++) {
|
|
1561
|
-
const p = (d * e + u) * 4, $ = i() < l ? 255 : 0;
|
|
1562
|
-
c[p] = 0, c[p + 1] = 0, c[p + 2] = 0, c[p + 3] = $;
|
|
1563
|
-
}
|
|
1564
|
-
return s;
|
|
1565
|
-
}
|
|
1566
|
-
function $a(e, n, t, a = Date.now()) {
|
|
1567
|
-
const o = Cn(e, n).getContext("2d");
|
|
1568
|
-
o.fillStyle = "#000000";
|
|
1569
|
-
const s = Xn(a), c = 4 + t / 100 * 6, i = c * 2;
|
|
1570
|
-
for (let l = 0; l < n; l += i)
|
|
1571
|
-
for (let d = 0; d < e; d += i)
|
|
1572
|
-
if (s() < t / 100) {
|
|
1573
|
-
const u = c * (0.5 + s() * 0.5);
|
|
1574
|
-
o.beginPath(), o.arc(d, l, u / 2, 0, Math.PI * 2), o.fill();
|
|
1575
|
-
}
|
|
1576
|
-
return o.getImageData(0, 0, e, n);
|
|
1577
|
-
}
|
|
1578
|
-
function Cn(e, n) {
|
|
1579
|
-
if (typeof OffscreenCanvas < "u")
|
|
1580
|
-
return new OffscreenCanvas(e, n);
|
|
1581
|
-
if (typeof document < "u") {
|
|
1582
|
-
const t = document.createElement("canvas");
|
|
1583
|
-
return t.width = e, t.height = n, t;
|
|
1584
|
-
}
|
|
1585
|
-
throw new Error("No canvas context available");
|
|
1586
|
-
}
|
|
1587
|
-
function Xn(e) {
|
|
1588
|
-
let n = Math.sin(e++) * 1e4;
|
|
1589
|
-
return () => (n = Math.sin(e++) * 1e4, n - Math.floor(n));
|
|
1590
|
-
}
|
|
1591
|
-
const N = 42, K = 512, J = 64;
|
|
1592
|
-
function Ln(e) {
|
|
1593
|
-
const n = e.data;
|
|
1594
|
-
for (let t = 0; t < n.length; t += 4)
|
|
1595
|
-
n[t] = 255, n[t + 1] = 255, n[t + 2] = 255;
|
|
1596
|
-
return e;
|
|
1597
|
-
}
|
|
1598
|
-
function xa(e, n) {
|
|
1599
|
-
const t = e.data, a = n.data;
|
|
1600
|
-
for (let r = 0; r < t.length; r += 4)
|
|
1601
|
-
t[r] = 255, t[r + 1] = 255, t[r + 2] = 255, t[r + 3] = Math.min(255, t[r + 3] + a[r + 3]);
|
|
1602
|
-
return e;
|
|
1603
|
-
}
|
|
1604
|
-
const va = [
|
|
1605
|
-
{
|
|
1606
|
-
id: "grunge-heavy",
|
|
1607
|
-
name: "Heavy Grunge",
|
|
1608
|
-
textureUrl: "builtin:grunge-heavy",
|
|
1609
|
-
thumbnailUrl: "",
|
|
1610
|
-
description: "Dense random splatters",
|
|
1611
|
-
generate: (e, n) => bn(e, n, 80, N)
|
|
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, n) => bn(e, n, 25, N + 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, n) => En(e, n, 55, N + 2)
|
|
1628
|
-
},
|
|
1629
|
-
{
|
|
1630
|
-
id: "paper",
|
|
1631
|
-
name: "Old Paper",
|
|
1632
|
-
textureUrl: "builtin:paper",
|
|
1633
|
-
thumbnailUrl: "",
|
|
1634
|
-
description: "Subtle aging",
|
|
1635
|
-
generate: (e, n) => En(e, n, 20, N + 3)
|
|
1636
|
-
},
|
|
1637
|
-
{
|
|
1638
|
-
id: "rust",
|
|
1639
|
-
name: "Rust",
|
|
1640
|
-
textureUrl: "builtin:rust",
|
|
1641
|
-
thumbnailUrl: "",
|
|
1642
|
-
description: "Noise + splatter combined",
|
|
1643
|
-
generate: (e, n) => {
|
|
1644
|
-
const t = En(e, n, 45, N + 4), a = bn(e, n, 35, N + 5);
|
|
1645
|
-
return xa(Ln(t), Ln(a));
|
|
1646
|
-
}
|
|
1647
|
-
},
|
|
1648
|
-
{
|
|
1649
|
-
id: "scratches",
|
|
1650
|
-
name: "Scratches",
|
|
1651
|
-
textureUrl: "builtin:scratches",
|
|
1652
|
-
thumbnailUrl: "",
|
|
1653
|
-
description: "Branching crack lines",
|
|
1654
|
-
generate: (e, n) => ya(e, n, 55, N + 6)
|
|
1655
|
-
},
|
|
1656
|
-
{
|
|
1657
|
-
id: "halftone",
|
|
1658
|
-
name: "Halftone",
|
|
1659
|
-
textureUrl: "builtin:halftone",
|
|
1660
|
-
thumbnailUrl: "",
|
|
1661
|
-
description: "Dot grid pattern",
|
|
1662
|
-
generate: (e, n) => $a(e, n, 55, N + 7)
|
|
1663
|
-
},
|
|
1664
|
-
{
|
|
1665
|
-
id: "spray",
|
|
1666
|
-
name: "Spray Paint",
|
|
1667
|
-
textureUrl: "builtin:spray",
|
|
1668
|
-
thumbnailUrl: "",
|
|
1669
|
-
description: "Medium random splatter",
|
|
1670
|
-
generate: (e, n) => bn(e, n, 55, N + 8)
|
|
1671
|
-
}
|
|
1672
|
-
];
|
|
1673
|
-
let le = !1;
|
|
1674
|
-
function wa(e, n) {
|
|
1675
|
-
if (typeof OffscreenCanvas < "u")
|
|
1676
|
-
return new OffscreenCanvas(e, n);
|
|
1677
|
-
const t = document.createElement("canvas");
|
|
1678
|
-
return t.width = e, t.height = n, t;
|
|
1679
|
-
}
|
|
1680
|
-
function de(e, n) {
|
|
1681
|
-
if (typeof document > "u") return null;
|
|
1682
|
-
const t = document.createElement("canvas");
|
|
1683
|
-
return t.width = e, t.height = n, t;
|
|
1684
|
-
}
|
|
1685
|
-
function Sa(e) {
|
|
1686
|
-
const n = de(e.width, e.height);
|
|
1687
|
-
if (!n) return "";
|
|
1688
|
-
const t = n.getContext("2d");
|
|
1689
|
-
if (!t) return "";
|
|
1690
|
-
t.putImageData(e, 0, 0);
|
|
1691
|
-
const a = de(J, J);
|
|
1692
|
-
if (!a) return "";
|
|
1693
|
-
const r = a.getContext("2d");
|
|
1694
|
-
if (!r) return "";
|
|
1695
|
-
r.drawImage(n, 0, 0, e.width, e.height, 0, 0, J, J);
|
|
1696
|
-
const o = r.getImageData(0, 0, J, J), s = o.data;
|
|
1697
|
-
for (let c = 0; c < s.length; c += 4) {
|
|
1698
|
-
const i = s[c + 3], l = 255 - Math.round(i / 255 * 195);
|
|
1699
|
-
s[c] = l, s[c + 1] = l, s[c + 2] = l, s[c + 3] = 255;
|
|
1700
|
-
}
|
|
1701
|
-
return r.putImageData(o, 0, 0), a.toDataURL("image/png");
|
|
1702
|
-
}
|
|
1703
|
-
function Ca() {
|
|
1704
|
-
if (!le) {
|
|
1705
|
-
le = !0;
|
|
1706
|
-
for (const e of va) {
|
|
1707
|
-
const n = e.generate(K, K);
|
|
1708
|
-
Ln(n);
|
|
1709
|
-
const t = wa(K, K), a = t.getContext("2d");
|
|
1710
|
-
a && (a.putImageData(n, 0, 0), ka(e.textureUrl, t, K, K)), typeof document < "u" && (e.thumbnailUrl = Sa(n));
|
|
1711
|
-
}
|
|
1712
|
-
}
|
|
1713
|
-
}
|
|
1714
|
-
const z = /* @__PURE__ */ new Set(), G = /* @__PURE__ */ new Map(), mn = /* @__PURE__ */ new Map();
|
|
1715
|
-
function fe(e, n) {
|
|
1716
|
-
if (typeof OffscreenCanvas < "u")
|
|
1717
|
-
return new OffscreenCanvas(e, n);
|
|
1718
|
-
const t = document.createElement("canvas");
|
|
1719
|
-
return t.width = e, t.height = n, t;
|
|
1720
|
-
}
|
|
1721
|
-
function ue(e) {
|
|
1722
|
-
return e.getContext("2d");
|
|
1723
|
-
}
|
|
1724
|
-
function pe(e) {
|
|
1725
|
-
const { width: n, height: t } = e, a = fe(n, t), r = ue(a);
|
|
1726
|
-
if (!r) throw new Error("Failed to get 2d context for temp canvas");
|
|
1727
|
-
r.drawImage(e, 0, 0);
|
|
1728
|
-
const o = r.getImageData(0, 0, n, t), s = o.data;
|
|
1729
|
-
for (let l = 0; l < s.length; l += 4) {
|
|
1730
|
-
const d = s[l], u = s[l + 1], p = s[l + 2], $ = 255 - (0.299 * d + 0.587 * u + 0.114 * p);
|
|
1731
|
-
s[l] = 255, s[l + 1] = 255, s[l + 2] = 255, s[l + 3] = $;
|
|
1732
|
-
}
|
|
1733
|
-
const c = fe(n, t), i = ue(c);
|
|
1734
|
-
if (!i) throw new Error("Failed to get 2d context for mask canvas");
|
|
1735
|
-
return i.putImageData(o, 0, 0), { alphaMask: c, width: n, height: t };
|
|
1736
|
-
}
|
|
1737
|
-
function Le(e) {
|
|
1738
|
-
const n = G.get(e);
|
|
1739
|
-
if (n) return n;
|
|
1740
|
-
if (e.startsWith("builtin:")) {
|
|
1741
|
-
Ca();
|
|
1742
|
-
const t = G.get(e);
|
|
1743
|
-
return t || null;
|
|
1744
|
-
}
|
|
1745
|
-
return z.has(e) || (z.add(e), Ne(e)), null;
|
|
1746
|
-
}
|
|
1747
|
-
function Ja(e) {
|
|
1748
|
-
return G.has(e) ? Promise.resolve() : new Promise((n) => {
|
|
1749
|
-
if (G.has(e)) {
|
|
1750
|
-
n();
|
|
1751
|
-
return;
|
|
1752
|
-
}
|
|
1753
|
-
const t = mn.get(e) || [];
|
|
1754
|
-
t.push(n), mn.set(e, t), z.has(e) || (z.add(e), Ne(e));
|
|
1755
|
-
});
|
|
1756
|
-
}
|
|
1757
|
-
function ka(e, n, t, a) {
|
|
1758
|
-
G.has(e) || (G.set(e, { alphaMask: n, width: t, height: a }), sn(e));
|
|
1759
|
-
}
|
|
1760
|
-
function sn(e) {
|
|
1761
|
-
const n = mn.get(e);
|
|
1762
|
-
n && (n.forEach((t) => t()), mn.delete(e));
|
|
1763
|
-
}
|
|
1764
|
-
function Ne(e) {
|
|
1765
|
-
if (typeof document < "u") {
|
|
1766
|
-
const n = new Image();
|
|
1767
|
-
n.crossOrigin = "anonymous", n.onload = () => {
|
|
1768
|
-
const t = pe(n);
|
|
1769
|
-
G.set(e, t), z.delete(e), sn(e);
|
|
1770
|
-
}, n.onerror = () => {
|
|
1771
|
-
z.delete(e), sn(e);
|
|
1772
|
-
}, n.src = e;
|
|
1773
|
-
} else
|
|
1774
|
-
fetch(e).then((n) => n.blob()).then((n) => createImageBitmap(n)).then((n) => {
|
|
1775
|
-
const t = pe(n);
|
|
1776
|
-
G.set(e, t), z.delete(e), sn(e);
|
|
1777
|
-
}).catch(() => {
|
|
1778
|
-
z.delete(e), sn(e);
|
|
1779
|
-
});
|
|
1780
|
-
}
|
|
1781
|
-
function Ue(e, n) {
|
|
1782
|
-
if (typeof OffscreenCanvas < "u")
|
|
1783
|
-
return new OffscreenCanvas(e, n);
|
|
1784
|
-
const t = document.createElement("canvas");
|
|
1785
|
-
return t.width = e, t.height = n, t;
|
|
1786
|
-
}
|
|
1787
|
-
function Ta(e, n, t, a) {
|
|
1788
|
-
if (!n.enabled || !n.textureUrl || n.intensity <= 0) return;
|
|
1789
|
-
const r = Le(n.textureUrl);
|
|
1790
|
-
if (!r) return;
|
|
1791
|
-
const { x: o, y: s, width: c, height: i } = t, l = e.getTransform(), d = l.a * o + l.e, u = l.d * s + l.f, p = l.a * c, f = l.d * i, $ = Math.ceil(p), h = Math.ceil(f);
|
|
1792
|
-
if ($ <= 0 || h <= 0) return;
|
|
1793
|
-
const g = Ue($, h), v = g.getContext("2d");
|
|
1794
|
-
if (!v) return;
|
|
1795
|
-
v.drawImage(
|
|
1796
|
-
e.canvas,
|
|
1797
|
-
d,
|
|
1798
|
-
u,
|
|
1799
|
-
p,
|
|
1800
|
-
f,
|
|
1801
|
-
0,
|
|
1802
|
-
0,
|
|
1803
|
-
$,
|
|
1804
|
-
h
|
|
1805
|
-
);
|
|
1806
|
-
const y = r.alphaMask.getContext("2d");
|
|
1807
|
-
if (y) {
|
|
1808
|
-
const x = n.intensity / 100, m = y.getImageData(0, 0, r.width, r.height).data, b = r.width, C = r.height, T = v.getImageData(0, 0, $, h), k = T.data;
|
|
1809
|
-
for (let _ = 0; _ < h; _++) {
|
|
1810
|
-
const w = Math.floor(_ / h * C);
|
|
1811
|
-
for (let A = 0; A < $; A++) {
|
|
1812
|
-
const E = Math.floor(A / $ * b), S = m[(w * b + E) * 4 + 3] / 255, P = (_ * $ + A) * 4;
|
|
1813
|
-
k[P + 3] = Math.round(k[P + 3] * (1 - S * x));
|
|
1814
|
-
}
|
|
1815
|
-
}
|
|
1816
|
-
v.putImageData(T, 0, 0);
|
|
1817
|
-
} else
|
|
1818
|
-
v.globalCompositeOperation = "destination-out", v.globalAlpha = n.intensity / 100, v.drawImage(r.alphaMask, 0, 0, $, h), v.globalCompositeOperation = "source-over";
|
|
1819
|
-
v.globalAlpha = 1, e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.clearRect(d, u, p, f), a && (e.fillStyle = a, e.fillRect(d, u, p, f)), e.drawImage(g, d, u), e.restore();
|
|
1820
|
-
}
|
|
1821
|
-
function he(e, n, t, a) {
|
|
1822
|
-
if (!n.enabled || n.style !== "custom" || !n.textureUrl) return;
|
|
1823
|
-
const r = Le(n.textureUrl);
|
|
1824
|
-
if (!r) {
|
|
1825
|
-
a(e);
|
|
1826
|
-
return;
|
|
1827
|
-
}
|
|
1828
|
-
const o = n.textureOpacity ?? n.intensity / 100, s = e.getTransform(), c = Math.sqrt(t.width ** 2 + t.height ** 2), i = (c - t.width) / 2, l = (c - t.height) / 2, d = 20, u = i + d, p = l + d, f = {
|
|
1829
|
-
x: t.x - u,
|
|
1830
|
-
y: t.y - p,
|
|
1831
|
-
width: t.width + u * 2,
|
|
1832
|
-
height: t.height + p * 2
|
|
1833
|
-
}, $ = s.a * f.x + s.e, h = s.d * f.y + s.f, g = s.a * f.width, v = s.d * f.height, y = Math.ceil(g), x = Math.ceil(v);
|
|
1834
|
-
if (y <= 0 || x <= 0) {
|
|
1835
|
-
a(e);
|
|
1836
|
-
return;
|
|
1837
|
-
}
|
|
1838
|
-
const m = Ue(y, x), b = m.getContext("2d");
|
|
1839
|
-
if (!b) {
|
|
1840
|
-
a(e);
|
|
1841
|
-
return;
|
|
1842
|
-
}
|
|
1843
|
-
b.setTransform(
|
|
1844
|
-
s.a,
|
|
1845
|
-
s.b,
|
|
1846
|
-
s.c,
|
|
1847
|
-
s.d,
|
|
1848
|
-
s.e - $,
|
|
1849
|
-
s.f - h
|
|
1850
|
-
), a(b), b.setTransform(1, 0, 0, 1, 0, 0);
|
|
1851
|
-
const C = r.alphaMask.getContext("2d");
|
|
1852
|
-
if (C) {
|
|
1853
|
-
const T = C.getImageData(0, 0, r.width, r.height).data, k = r.width, _ = r.height, w = b.getImageData(0, 0, y, x), A = w.data;
|
|
1854
|
-
for (let E = 0; E < x; E++) {
|
|
1855
|
-
const S = Math.floor(E / x * _);
|
|
1856
|
-
for (let P = 0; P < y; P++) {
|
|
1857
|
-
const I = Math.floor(P / y * k), F = T[(S * k + I) * 4 + 3] / 255, D = (E * y + P) * 4;
|
|
1858
|
-
A[D + 3] = Math.round(A[D + 3] * (1 - F * o));
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
b.putImageData(w, 0, 0);
|
|
1862
|
-
} else
|
|
1863
|
-
b.globalCompositeOperation = "destination-out", b.globalAlpha = o, b.drawImage(r.alphaMask, 0, 0, y, x), b.globalCompositeOperation = "source-over", b.globalAlpha = 1;
|
|
1864
|
-
e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(m, $, h), e.restore();
|
|
1865
|
-
}
|
|
1866
|
-
class yn {
|
|
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(n) {
|
|
1876
|
-
const { transformType: t } = n;
|
|
1877
|
-
switch (t) {
|
|
1878
|
-
case "custom":
|
|
1879
|
-
return new ct(n);
|
|
1880
|
-
case "distort":
|
|
1881
|
-
throw new Error("DistortTransform is not yet implemented");
|
|
1882
|
-
case "circle":
|
|
1883
|
-
return new ot(n);
|
|
1884
|
-
case "lean":
|
|
1885
|
-
return new it(n);
|
|
1886
|
-
case "arch":
|
|
1887
|
-
return new st(n);
|
|
1888
|
-
case "ascend":
|
|
1889
|
-
return new rt(n);
|
|
1890
|
-
case "wave":
|
|
1891
|
-
return new at(n);
|
|
1892
|
-
case "flag":
|
|
1893
|
-
return new tt(n);
|
|
1894
|
-
case "image":
|
|
1895
|
-
return new An(n);
|
|
1896
|
-
case "group": {
|
|
1897
|
-
const r = (n.children || []).map(
|
|
1898
|
-
(i) => yn.createFromJSON(i)
|
|
1899
|
-
), { children: o, ...s } = n, c = new ve(s);
|
|
1900
|
-
return r.forEach((i) => c.addChild(i)), c;
|
|
1901
|
-
}
|
|
1902
|
-
case "shape":
|
|
1903
|
-
return new et(n);
|
|
1904
|
-
case "path":
|
|
1905
|
-
return new nt(n);
|
|
1906
|
-
default:
|
|
1907
|
-
const a = t;
|
|
1908
|
-
throw new Error(`Unknown transform type: ${a}`);
|
|
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(n) {
|
|
1919
|
-
return n.map((t) => this.createFromJSON(t));
|
|
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(n) {
|
|
1929
|
-
const t = n;
|
|
1930
|
-
return !!n && typeof n == "object" && typeof t.id == "string" && typeof t.transformType == "string" && typeof t.getBoundingBox == "function" && typeof t.getVisualBoundingBox == "function" && typeof t.hitTest == "function" && typeof t.render == "function" && typeof t.toJSON == "function" && typeof t.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(n) {
|
|
1940
|
-
const t = n;
|
|
1941
|
-
return !!n && typeof n == "object" && typeof t.transformType == "string" && (t.id === void 0 || typeof t.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(n) {
|
|
1951
|
-
const t = {
|
|
1952
|
-
id: `${n}-${Date.now()}`,
|
|
1953
|
-
x: window.innerWidth / 2,
|
|
1954
|
-
y: window.innerHeight / 2,
|
|
1955
|
-
rotation: 0
|
|
1956
|
-
};
|
|
1957
|
-
switch (n) {
|
|
1958
|
-
case "custom":
|
|
1959
|
-
return {
|
|
1960
|
-
...t,
|
|
1961
|
-
transformType: "custom",
|
|
1962
|
-
text: "Custom Text",
|
|
1963
|
-
transformData: {
|
|
1964
|
-
type: "custom",
|
|
1965
|
-
controlPoints: []
|
|
1966
|
-
}
|
|
1967
|
-
};
|
|
1968
|
-
case "distort":
|
|
1969
|
-
return {
|
|
1970
|
-
...t,
|
|
1971
|
-
transformType: "distort",
|
|
1972
|
-
text: "Distorted Text",
|
|
1973
|
-
transformData: {
|
|
1974
|
-
type: "distort"
|
|
1975
|
-
}
|
|
1976
|
-
};
|
|
1977
|
-
case "circle":
|
|
1978
|
-
return {
|
|
1979
|
-
...t,
|
|
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
|
-
...t,
|
|
1992
|
-
transformType: "lean",
|
|
1993
|
-
text: "Leaning Text",
|
|
1994
|
-
transformData: {
|
|
1995
|
-
type: "lean",
|
|
1996
|
-
leanAmount: 0
|
|
1997
|
-
}
|
|
1998
|
-
};
|
|
1999
|
-
case "arch":
|
|
2000
|
-
return {
|
|
2001
|
-
...t,
|
|
2002
|
-
transformType: "arch",
|
|
2003
|
-
text: "Arched Text",
|
|
2004
|
-
transformData: {
|
|
2005
|
-
type: "arch",
|
|
2006
|
-
archHeight: 0.5
|
|
2007
|
-
}
|
|
2008
|
-
};
|
|
2009
|
-
case "ascend":
|
|
2010
|
-
return {
|
|
2011
|
-
...t,
|
|
2012
|
-
transformType: "ascend",
|
|
2013
|
-
text: "Ascending Text",
|
|
2014
|
-
transformData: {
|
|
2015
|
-
type: "ascend",
|
|
2016
|
-
ascendAngle: -15
|
|
2017
|
-
}
|
|
2018
|
-
};
|
|
2019
|
-
case "wave":
|
|
2020
|
-
return {
|
|
2021
|
-
...t,
|
|
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
|
-
...t,
|
|
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
|
-
...t,
|
|
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
|
-
...t,
|
|
2062
|
-
transformType: "group",
|
|
2063
|
-
children: [],
|
|
2064
|
-
transformData: {
|
|
2065
|
-
type: "group"
|
|
2066
|
-
}
|
|
2067
|
-
};
|
|
2068
|
-
case "shape":
|
|
2069
|
-
return {
|
|
2070
|
-
...t,
|
|
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
|
-
...t,
|
|
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 a = n;
|
|
2104
|
-
throw new Error(`Unknown transform type: ${a}`);
|
|
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(n) {
|
|
2115
|
-
const t = n.toJSON();
|
|
2116
|
-
return this.createFromJSON(t);
|
|
2117
|
-
}
|
|
2118
|
-
}
|
|
2119
|
-
const be = U("ImportManager"), Kn = class Kn {
|
|
2120
|
-
/**
|
|
2121
|
-
* Import workspace from JSON file
|
|
2122
|
-
*/
|
|
2123
|
-
static async importFromJSON(n) {
|
|
2124
|
-
try {
|
|
2125
|
-
const t = await this.readFileAsText(n), a = JSON.parse(t);
|
|
2126
|
-
if (this.validateDocument(a), !this.SUPPORTED_VERSIONS.includes(a.metadata.version))
|
|
2127
|
-
throw new Error(
|
|
2128
|
-
`Unsupported version: ${a.metadata.version}. Supported versions: ${this.SUPPORTED_VERSIONS.join(", ")}`
|
|
2129
|
-
);
|
|
2130
|
-
if (a.metadata.version === "1.0.0")
|
|
2131
|
-
return this.migrateV1Document(a);
|
|
2132
|
-
const r = [], o = [];
|
|
2133
|
-
return a.artboards.forEach((s) => {
|
|
2134
|
-
const c = Zn.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((l) => l.id || "")
|
|
2143
|
-
}), i = s.elements.map((l) => {
|
|
2144
|
-
try {
|
|
2145
|
-
return yn.createFromJSON(l);
|
|
2146
|
-
} catch (d) {
|
|
2147
|
-
return be.error("Failed to create element:", l, d), null;
|
|
2148
|
-
}
|
|
2149
|
-
}).filter((l) => l !== null);
|
|
2150
|
-
r.push(c), o.push(...i);
|
|
2151
|
-
}), await this.preloadAllImages(o), {
|
|
2152
|
-
success: !0,
|
|
2153
|
-
artboards: r,
|
|
2154
|
-
elements: o,
|
|
2155
|
-
activeArtboardId: a.activeArtboardId
|
|
2156
|
-
};
|
|
2157
|
-
} catch (t) {
|
|
2158
|
-
return {
|
|
2159
|
-
success: !1,
|
|
2160
|
-
error: t instanceof Error ? t.message : "Unknown error"
|
|
2161
|
-
};
|
|
2162
|
-
}
|
|
2163
|
-
}
|
|
2164
|
-
/**
|
|
2165
|
-
* Migrate v1 document (no artboards) to v2 (with artboards)
|
|
2166
|
-
*/
|
|
2167
|
-
static async migrateV1Document(n) {
|
|
2168
|
-
var t, a, r;
|
|
2169
|
-
try {
|
|
2170
|
-
const o = n.elements || [], s = new Zn({
|
|
2171
|
-
id: "artboard-migrated",
|
|
2172
|
-
name: "Artboard 1",
|
|
2173
|
-
x: 0,
|
|
2174
|
-
y: 0,
|
|
2175
|
-
width: ((t = n.canvas) == null ? void 0 : t.width) || 1920,
|
|
2176
|
-
height: ((a = n.canvas) == null ? void 0 : a.height) || 1080,
|
|
2177
|
-
backgroundColor: ((r = n.canvas) == null ? void 0 : r.backgroundColor) || "#ffffff"
|
|
2178
|
-
}), c = o.map((i) => {
|
|
2179
|
-
try {
|
|
2180
|
-
return yn.createFromJSON(i);
|
|
2181
|
-
} catch (l) {
|
|
2182
|
-
return be.error("Failed to create element:", i, l), null;
|
|
2183
|
-
}
|
|
2184
|
-
}).filter((i) => i !== null);
|
|
2185
|
-
return c.forEach((i) => {
|
|
2186
|
-
s.addElementId(i.id);
|
|
2187
|
-
}), await this.preloadAllImages(c), {
|
|
2188
|
-
success: !0,
|
|
2189
|
-
artboards: [s],
|
|
2190
|
-
elements: c,
|
|
2191
|
-
activeArtboardId: s.id
|
|
2192
|
-
};
|
|
2193
|
-
} catch (o) {
|
|
2194
|
-
return {
|
|
2195
|
-
success: !1,
|
|
2196
|
-
error: o instanceof Error ? o.message : "Migration failed"
|
|
2197
|
-
};
|
|
2198
|
-
}
|
|
2199
|
-
}
|
|
2200
|
-
/**
|
|
2201
|
-
* Import image file
|
|
2202
|
-
*/
|
|
2203
|
-
static async importImage(n) {
|
|
2204
|
-
try {
|
|
2205
|
-
if (!n.type.startsWith("image/"))
|
|
2206
|
-
throw new Error("File is not an image");
|
|
2207
|
-
const t = 10 * 1024 * 1024;
|
|
2208
|
-
if (n.size > t)
|
|
2209
|
-
throw new Error("Image file is too large (max 10MB)");
|
|
2210
|
-
const a = await this.readFileAsDataURL(n), { width: r, height: o } = await this.getImageDimensions(a);
|
|
2211
|
-
return {
|
|
2212
|
-
success: !0,
|
|
2213
|
-
dataUrl: a,
|
|
2214
|
-
filename: n.name,
|
|
2215
|
-
width: r,
|
|
2216
|
-
height: o
|
|
2217
|
-
};
|
|
2218
|
-
} catch (t) {
|
|
2219
|
-
return {
|
|
2220
|
-
success: !1,
|
|
2221
|
-
error: t instanceof Error ? t.message : "Unknown error"
|
|
2222
|
-
};
|
|
2223
|
-
}
|
|
2224
|
-
}
|
|
2225
|
-
/**
|
|
2226
|
-
* Validate document structure
|
|
2227
|
-
*/
|
|
2228
|
-
static validateDocument(n) {
|
|
2229
|
-
if (!n || typeof n != "object")
|
|
2230
|
-
throw new Error("Invalid document");
|
|
2231
|
-
const t = n;
|
|
2232
|
-
if (!t.metadata)
|
|
2233
|
-
throw new Error("Missing metadata");
|
|
2234
|
-
if (!t.metadata.version)
|
|
2235
|
-
throw new Error("Missing version in metadata");
|
|
2236
|
-
if (!t.artboards && !t.elements)
|
|
2237
|
-
throw new Error("Missing artboards or elements array");
|
|
2238
|
-
if (t.artboards && !Array.isArray(t.artboards))
|
|
2239
|
-
throw new Error("Invalid artboards array");
|
|
2240
|
-
}
|
|
2241
|
-
/**
|
|
2242
|
-
* Read file as text
|
|
2243
|
-
*/
|
|
2244
|
-
static readFileAsText(n) {
|
|
2245
|
-
return new Promise((t, a) => {
|
|
2246
|
-
const r = new FileReader();
|
|
2247
|
-
r.onload = (o) => {
|
|
2248
|
-
var s;
|
|
2249
|
-
return t((s = o.target) == null ? void 0 : s.result);
|
|
2250
|
-
}, r.onerror = () => a(new Error("Failed to read file")), r.readAsText(n);
|
|
2251
|
-
});
|
|
2252
|
-
}
|
|
2253
|
-
/**
|
|
2254
|
-
* Read file as data URL
|
|
2255
|
-
*/
|
|
2256
|
-
static readFileAsDataURL(n) {
|
|
2257
|
-
return new Promise((t, a) => {
|
|
2258
|
-
const r = new FileReader();
|
|
2259
|
-
r.onload = (o) => {
|
|
2260
|
-
var s;
|
|
2261
|
-
return t((s = o.target) == null ? void 0 : s.result);
|
|
2262
|
-
}, r.onerror = () => a(new Error("Failed to read file")), r.readAsDataURL(n);
|
|
2263
|
-
});
|
|
2264
|
-
}
|
|
2265
|
-
/**
|
|
2266
|
-
* Get image dimensions from data URL
|
|
2267
|
-
*/
|
|
2268
|
-
static getImageDimensions(n) {
|
|
2269
|
-
return new Promise((t, a) => {
|
|
2270
|
-
const r = new Image();
|
|
2271
|
-
r.onload = () => {
|
|
2272
|
-
t({ width: r.width, height: r.height });
|
|
2273
|
-
}, r.onerror = () => a(new Error("Failed to load image")), r.src = n;
|
|
2274
|
-
});
|
|
2275
|
-
}
|
|
2276
|
-
/**
|
|
2277
|
-
* Validate imported data before applying to state
|
|
2278
|
-
*/
|
|
2279
|
-
static validateImportedData(n, t) {
|
|
2280
|
-
const a = [], r = /* @__PURE__ */ new Set();
|
|
2281
|
-
n.forEach((s) => {
|
|
2282
|
-
r.has(s.id) && a.push(`Duplicate artboard ID: ${s.id}`), r.add(s.id);
|
|
2283
|
-
});
|
|
2284
|
-
const o = /* @__PURE__ */ new Set();
|
|
2285
|
-
return t.forEach((s) => {
|
|
2286
|
-
o.has(s.id) && a.push(`Duplicate element ID: ${s.id}`), o.add(s.id);
|
|
2287
|
-
}), n.forEach((s) => {
|
|
2288
|
-
s.getElementIds().forEach((c) => {
|
|
2289
|
-
o.has(c) || a.push(`Artboard "${s.name}" references missing element: ${c}`);
|
|
2290
|
-
});
|
|
2291
|
-
}), {
|
|
2292
|
-
valid: a.length === 0,
|
|
2293
|
-
errors: a
|
|
2294
|
-
};
|
|
2295
|
-
}
|
|
2296
|
-
/**
|
|
2297
|
-
* Get import summary (for UI display before confirming)
|
|
2298
|
-
*/
|
|
2299
|
-
static getImportSummary(n, t) {
|
|
2300
|
-
const a = this.validateImportedData(n, t);
|
|
2301
|
-
return {
|
|
2302
|
-
artboardCount: n.length,
|
|
2303
|
-
elementCount: t.length,
|
|
2304
|
-
artboardNames: n.map((r) => r.name),
|
|
2305
|
-
warnings: a.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(n) {
|
|
2313
|
-
const t = [], a = (o) => {
|
|
2314
|
-
o.transformType === "image" ? t.push(o) : o.transformType === "group" && "children" in o && o.children.forEach((s) => a(s));
|
|
2315
|
-
};
|
|
2316
|
-
n.forEach(a);
|
|
2317
|
-
const r = t.map((o) => new Promise((s) => {
|
|
2318
|
-
if (o.imageLoaded)
|
|
2319
|
-
s();
|
|
2320
|
-
else if (o.imageElement) {
|
|
2321
|
-
const c = o.imageElement, i = () => {
|
|
2322
|
-
c.removeEventListener("load", i), c.removeEventListener("error", l), s();
|
|
2323
|
-
}, l = () => {
|
|
2324
|
-
c.removeEventListener("load", i), c.removeEventListener("error", l), s();
|
|
2325
|
-
};
|
|
2326
|
-
c.addEventListener("load", i), c.addEventListener("error", l);
|
|
2327
|
-
} else
|
|
2328
|
-
s();
|
|
2329
|
-
}));
|
|
2330
|
-
await Promise.all(r);
|
|
2331
|
-
}
|
|
2332
|
-
};
|
|
2333
|
-
Kn.SUPPORTED_VERSIONS = ["1.0.0", "2.0.0"];
|
|
2334
|
-
let ge = Kn;
|
|
2335
|
-
const me = U("element-serializer"), We = 4e3, un = /* @__PURE__ */ new Set();
|
|
2336
|
-
function _a(e, n) {
|
|
2337
|
-
const t = n ? Ea(n) : "no-src";
|
|
2338
|
-
return `${e}:${t}`;
|
|
2339
|
-
}
|
|
2340
|
-
function Ea(e) {
|
|
2341
|
-
let n = 0;
|
|
2342
|
-
for (let t = 0; t < e.length; t++) {
|
|
2343
|
-
const a = e.charCodeAt(t);
|
|
2344
|
-
n = (n << 5) - n + a, n = n & n;
|
|
2345
|
-
}
|
|
2346
|
-
return n.toString(36);
|
|
2347
|
-
}
|
|
2348
|
-
function Nn() {
|
|
2349
|
-
un.clear();
|
|
2350
|
-
}
|
|
2351
|
-
function ze(e) {
|
|
2352
|
-
for (const n of un)
|
|
2353
|
-
n.startsWith(`${e}:`) && un.delete(n);
|
|
2354
|
-
}
|
|
2355
|
-
function Aa(e) {
|
|
2356
|
-
un.add(e);
|
|
2357
|
-
}
|
|
2358
|
-
function Pa(e) {
|
|
2359
|
-
return un.has(e);
|
|
2360
|
-
}
|
|
2361
|
-
async function Ia(e, n = We) {
|
|
2362
|
-
const { naturalWidth: t, naturalHeight: a } = e;
|
|
2363
|
-
if (t <= n && a <= n)
|
|
2364
|
-
return createImageBitmap(e);
|
|
2365
|
-
const r = n / Math.max(t, a), o = Math.round(t * r), s = Math.round(a * r);
|
|
2366
|
-
return createImageBitmap(e, {
|
|
2367
|
-
resizeWidth: o,
|
|
2368
|
-
resizeHeight: s,
|
|
2369
|
-
resizeQuality: "high"
|
|
2370
|
-
});
|
|
2371
|
-
}
|
|
2372
|
-
let $n = null, xn = null;
|
|
2373
|
-
function Fa(e, n) {
|
|
2374
|
-
$n = e, xn = n;
|
|
2375
|
-
}
|
|
2376
|
-
function Da() {
|
|
2377
|
-
$n = null, xn = null;
|
|
2378
|
-
}
|
|
2379
|
-
function Za() {
|
|
2380
|
-
Nn(), $n && $n();
|
|
2381
|
-
}
|
|
2382
|
-
function Qa(e) {
|
|
2383
|
-
ze(e), xn && xn(e);
|
|
2384
|
-
}
|
|
2385
|
-
function Un(e, n) {
|
|
2386
|
-
const t = e;
|
|
2387
|
-
if (typeof t.fontFamily == "string" && n.add(t.fontFamily), t.richText && typeof t.richText == "object") {
|
|
2388
|
-
const a = t.richText;
|
|
2389
|
-
if (a.spans && Array.isArray(a.spans))
|
|
2390
|
-
for (const r of a.spans) {
|
|
2391
|
-
const o = r;
|
|
2392
|
-
if (o.style && typeof o.style == "object") {
|
|
2393
|
-
const s = o.style;
|
|
2394
|
-
typeof s.fontFamily == "string" && n.add(s.fontFamily);
|
|
2395
|
-
}
|
|
2396
|
-
}
|
|
2397
|
-
}
|
|
2398
|
-
if (t.children && Array.isArray(t.children))
|
|
2399
|
-
for (const a of t.children)
|
|
2400
|
-
Un(a, n);
|
|
2401
|
-
if (e.masks && Array.isArray(e.masks))
|
|
2402
|
-
for (const a of e.masks)
|
|
2403
|
-
a.maskElement && Un(a.maskElement, n);
|
|
2404
|
-
}
|
|
2405
|
-
function ye(e) {
|
|
2406
|
-
if (typeof document > "u") return e;
|
|
2407
|
-
const n = wn.getInstance();
|
|
2408
|
-
return e.map((t) => {
|
|
2409
|
-
if (!(t != null && t.maskElement) || t.maskElement.transformType !== "image") return t;
|
|
2410
|
-
const a = t.maskElement.imageUrl;
|
|
2411
|
-
if (!a || !a.startsWith("builtin-mask:")) return t;
|
|
2412
|
-
const r = n.get(a);
|
|
2413
|
-
return r != null && r.src && r.src.startsWith("data:") ? {
|
|
2414
|
-
...t,
|
|
2415
|
-
maskElement: {
|
|
2416
|
-
...t.maskElement,
|
|
2417
|
-
imageUrl: r.src
|
|
2418
|
-
// Replace with data URL
|
|
2419
|
-
}
|
|
2420
|
-
} : t;
|
|
2421
|
-
});
|
|
2422
|
-
}
|
|
2423
|
-
async function $e(e, n, t = We) {
|
|
2424
|
-
const a = n.filter((i) => e.hasElementId(i.id)), r = [], o = [], s = /* @__PURE__ */ new Set();
|
|
2425
|
-
for (const i of a) {
|
|
2426
|
-
const l = i.toJSON();
|
|
2427
|
-
if (Un(l, s), i instanceof An && !i.imageElement) {
|
|
2428
|
-
me.warn(`[element-serializer] Skipping image ${i.id}: image not loaded (state: ${i.imageLoadState})`);
|
|
2429
|
-
continue;
|
|
2430
|
-
}
|
|
2431
|
-
if (i instanceof An && i.imageElement)
|
|
2432
|
-
try {
|
|
2433
|
-
const d = _a(i.id, i.imageUrl);
|
|
2434
|
-
if (!Pa(d)) {
|
|
2435
|
-
const x = await Ia(i.imageElement, t);
|
|
2436
|
-
o.push({ cacheKey: d, bitmap: x }), Aa(d);
|
|
2437
|
-
}
|
|
2438
|
-
const p = i.transformData || {}, f = l.masks && l.masks.length > 0, $ = f ? p.width : p.width * (p.cropWidth ?? 1), h = f ? p.height : p.height * (p.cropHeight ?? 1), g = {
|
|
2439
|
-
id: i.id,
|
|
2440
|
-
type: "image",
|
|
2441
|
-
x: i.x,
|
|
2442
|
-
y: i.y,
|
|
2443
|
-
width: $,
|
|
2444
|
-
height: h,
|
|
2445
|
-
rotation: i.rotation || 0,
|
|
2446
|
-
bitmapCacheKey: d
|
|
2447
|
-
};
|
|
2448
|
-
if (!f && (p.cropX !== 0 || p.cropY !== 0 || p.cropWidth !== 1 || p.cropHeight !== 1)) {
|
|
2449
|
-
const x = i.imageElement.naturalWidth, m = i.imageElement.naturalHeight;
|
|
2450
|
-
let b = 1;
|
|
2451
|
-
(x > t || m > t) && (b = t / Math.max(x, m)), g.cropX = p.cropX * x * b, g.cropY = p.cropY * m * b, g.cropWidth = p.cropWidth * x * b, g.cropHeight = p.cropHeight * m * b;
|
|
2452
|
-
}
|
|
2453
|
-
p.flipHorizontal && (g.flipHorizontal = p.flipHorizontal), p.flipVertical && (g.flipVertical = p.flipVertical), p.borderRadius && (g.borderRadius = p.borderRadius), lt(p.adjustments) || (g.adjustments = { ...p.adjustments }), i.opacity !== void 0 && (g.opacity = i.opacity);
|
|
2454
|
-
const y = g;
|
|
2455
|
-
i.distressEffect && (y.distressEffect = { ...i.distressEffect }), l.masks && l.masks.length > 0 && (y.masks = ye(l.masks)), l.blendMode && (y.blendMode = l.blendMode), l.knockoutParts && (y.knockoutParts = l.knockoutParts), l.shadow && (y.shadow = { ...l.shadow }), "getVisualBoundingBox" in i && typeof i.getVisualBoundingBox == "function" ? y._boundingBox = i.getVisualBoundingBox() : "getBoundingBox" in i && typeof i.getBoundingBox == "function" && (y._boundingBox = i.getBoundingBox()), r.push(y);
|
|
2456
|
-
} catch (d) {
|
|
2457
|
-
me.error(`[element-serializer] Failed to create ImageBitmap for ${l.id}:`, d);
|
|
2458
|
-
}
|
|
2459
|
-
else {
|
|
2460
|
-
const d = {
|
|
2461
|
-
...l,
|
|
2462
|
-
type: l.transformType
|
|
2463
|
-
// Map transformType to type for worker compatibility
|
|
2464
|
-
};
|
|
2465
|
-
d.masks && Array.isArray(d.masks) && d.masks.length > 0 && (d.masks = ye(d.masks)), "getVisualBoundingBox" in i && typeof i.getVisualBoundingBox == "function" ? d._boundingBox = i.getVisualBoundingBox() : "getBoundingBox" in i && typeof i.getBoundingBox == "function" && (d._boundingBox = i.getBoundingBox()), r.push(d);
|
|
2466
|
-
}
|
|
2467
|
-
}
|
|
2468
|
-
const c = 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: r,
|
|
2485
|
-
fonts: c
|
|
2486
|
-
},
|
|
2487
|
-
newBitmaps: o
|
|
2488
|
-
};
|
|
2489
|
-
}
|
|
2490
|
-
const Ma = `"use strict";
|
|
1
|
+
const n = `"use strict";
|
|
2491
2
|
(() => {
|
|
2492
3
|
var __create = Object.create;
|
|
2493
4
|
var __defProp = Object.defineProperty;
|
|
@@ -26840,1133 +24351,7 @@ const Ma = `"use strict";
|
|
|
26840
24351
|
};
|
|
26841
24352
|
})();
|
|
26842
24353
|
`;
|
|
26843
|
-
async function Oa(e, n, t = fetch) {
|
|
26844
|
-
try {
|
|
26845
|
-
const a = await t(n.fontFileUrl, { mode: "cors" });
|
|
26846
|
-
if (!a.ok) return null;
|
|
26847
|
-
const r = await a.arrayBuffer(), o = new FontFace(e, r, n.descriptors);
|
|
26848
|
-
return await o.load(), o;
|
|
26849
|
-
} catch {
|
|
26850
|
-
return null;
|
|
26851
|
-
}
|
|
26852
|
-
}
|
|
26853
|
-
function X(e) {
|
|
26854
|
-
return e.trim().toLowerCase();
|
|
26855
|
-
}
|
|
26856
|
-
function Yn(e) {
|
|
26857
|
-
return `${X(e.family)}|${e.weight ?? 400}|${e.style ?? "normal"}`;
|
|
26858
|
-
}
|
|
26859
|
-
class Ra {
|
|
26860
|
-
constructor() {
|
|
26861
|
-
this.fonts = /* @__PURE__ */ new Map(), this.listeners = /* @__PURE__ */ new Set(), this.snapshot = [], this.list = () => this.snapshot, this.subscribe = (n) => (this.listeners.add(n), () => {
|
|
26862
|
-
this.listeners.delete(n);
|
|
26863
|
-
});
|
|
26864
|
-
}
|
|
26865
|
-
/**
|
|
26866
|
-
* Register fonts (idempotent; re-registering the same family/weight/style
|
|
26867
|
-
* replaces the URL). Returns true when anything changed.
|
|
26868
|
-
*/
|
|
26869
|
-
register(n) {
|
|
26870
|
-
let t = !1;
|
|
26871
|
-
for (const a of n) {
|
|
26872
|
-
const r = Yn(a), o = this.fonts.get(r);
|
|
26873
|
-
o && o.url === a.url && o.family === a.family || (this.fonts.set(r, { ...a }), t = !0);
|
|
26874
|
-
}
|
|
26875
|
-
if (t) {
|
|
26876
|
-
this.snapshot = Object.freeze([...this.fonts.values()]);
|
|
26877
|
-
for (const a of this.listeners) a();
|
|
26878
|
-
}
|
|
26879
|
-
return t;
|
|
26880
|
-
}
|
|
26881
|
-
/** Is this family registered as a custom font? (Shadowing check.) */
|
|
26882
|
-
has(n) {
|
|
26883
|
-
const t = X(n);
|
|
26884
|
-
for (const a of this.fonts.values())
|
|
26885
|
-
if (X(a.family) === t) return !0;
|
|
26886
|
-
return !1;
|
|
26887
|
-
}
|
|
26888
|
-
/** All registered faces of one family (possibly several weights/styles). */
|
|
26889
|
-
facesOf(n) {
|
|
26890
|
-
const t = X(n);
|
|
26891
|
-
return [...this.fonts.values()].filter((a) => X(a.family) === t);
|
|
26892
|
-
}
|
|
26893
|
-
/** Registered faces whose family appears in `families` — what the export
|
|
26894
|
-
* path sends to the worker alongside the used-font list. */
|
|
26895
|
-
forFamilies(n) {
|
|
26896
|
-
const t = new Set(n.map(X));
|
|
26897
|
-
return [...this.fonts.values()].filter((a) => t.has(X(a.family)));
|
|
26898
|
-
}
|
|
26899
|
-
/** @internal Test helper — wipe registry state between tests. */
|
|
26900
|
-
clear() {
|
|
26901
|
-
this.fonts.clear(), this.snapshot = Object.freeze([]);
|
|
26902
|
-
for (const n of this.listeners) n();
|
|
26903
|
-
}
|
|
26904
|
-
}
|
|
26905
|
-
const Wn = new Ra();
|
|
26906
|
-
function Ba(e) {
|
|
26907
|
-
Wn.register(e);
|
|
26908
|
-
}
|
|
26909
|
-
const Ge = /* @__PURE__ */ new Set();
|
|
26910
|
-
async function La(e, n = {}) {
|
|
26911
|
-
const t = await Oa(
|
|
26912
|
-
e.family,
|
|
26913
|
-
{
|
|
26914
|
-
fontFileUrl: e.url,
|
|
26915
|
-
descriptors: {
|
|
26916
|
-
weight: String(e.weight ?? 400),
|
|
26917
|
-
style: e.style ?? "normal"
|
|
26918
|
-
}
|
|
26919
|
-
},
|
|
26920
|
-
n.fetchImpl ?? fetch
|
|
26921
|
-
);
|
|
26922
|
-
if (!t)
|
|
26923
|
-
throw new Ce(
|
|
26924
|
-
"E_FONT_LOAD_FAILED",
|
|
26925
|
-
`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.`,
|
|
26926
|
-
{
|
|
26927
|
-
family: e.family,
|
|
26928
|
-
url: e.url,
|
|
26929
|
-
weight: e.weight ?? 400,
|
|
26930
|
-
style: e.style ?? "normal"
|
|
26931
|
-
}
|
|
26932
|
-
);
|
|
26933
|
-
const a = n.fonts ?? (typeof document < "u" ? document.fonts : void 0);
|
|
26934
|
-
return a == null || a.add(t), Ge.add(Yn(e)), t;
|
|
26935
|
-
}
|
|
26936
|
-
async function nr(e, n = {}) {
|
|
26937
|
-
Ba(e);
|
|
26938
|
-
const { onLoadError: t, ...a } = n;
|
|
26939
|
-
await Promise.all(
|
|
26940
|
-
e.map(async (r) => {
|
|
26941
|
-
if (!Ge.has(Yn(r)))
|
|
26942
|
-
try {
|
|
26943
|
-
await La(r, a);
|
|
26944
|
-
} catch (o) {
|
|
26945
|
-
if (t && o instanceof Ce) {
|
|
26946
|
-
t(o, r);
|
|
26947
|
-
return;
|
|
26948
|
-
}
|
|
26949
|
-
throw o;
|
|
26950
|
-
}
|
|
26951
|
-
})
|
|
26952
|
-
);
|
|
26953
|
-
}
|
|
26954
|
-
const O = U("WorkerExport");
|
|
26955
|
-
class pn {
|
|
26956
|
-
constructor() {
|
|
26957
|
-
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.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;
|
|
26958
|
-
}
|
|
26959
|
-
// 30 seconds
|
|
26960
|
-
/**
|
|
26961
|
-
* Add progress listener
|
|
26962
|
-
*/
|
|
26963
|
-
onProgress(n) {
|
|
26964
|
-
return this.progressListeners.add(n), () => {
|
|
26965
|
-
this.progressListeners.delete(n);
|
|
26966
|
-
};
|
|
26967
|
-
}
|
|
26968
|
-
/**
|
|
26969
|
-
* Remove progress listener
|
|
26970
|
-
*/
|
|
26971
|
-
offProgress(n) {
|
|
26972
|
-
this.progressListeners.delete(n);
|
|
26973
|
-
}
|
|
26974
|
-
/**
|
|
26975
|
-
* Emit progress event to all listeners
|
|
26976
|
-
*/
|
|
26977
|
-
emitProgress(n) {
|
|
26978
|
-
for (const t of this.progressListeners)
|
|
26979
|
-
try {
|
|
26980
|
-
t(n);
|
|
26981
|
-
} catch (a) {
|
|
26982
|
-
O.error("Error in progress listener:", a);
|
|
26983
|
-
}
|
|
26984
|
-
}
|
|
26985
|
-
/**
|
|
26986
|
-
* Reset idle timer
|
|
26987
|
-
*/
|
|
26988
|
-
resetIdleTimer() {
|
|
26989
|
-
this.idleTimeout && clearTimeout(this.idleTimeout), this.idleTimeout = window.setTimeout(() => {
|
|
26990
|
-
this.terminate();
|
|
26991
|
-
}, this.IDLE_TIMEOUT_MS);
|
|
26992
|
-
}
|
|
26993
|
-
// ============================================================================
|
|
26994
|
-
// Worker Bitmap Cache Management
|
|
26995
|
-
// ============================================================================
|
|
26996
|
-
/**
|
|
26997
|
-
* Register bitmaps with the worker's cache.
|
|
26998
|
-
* This transfers the bitmaps to the worker (zero-copy) where they are cached.
|
|
26999
|
-
*/
|
|
27000
|
-
registerBitmapsWithWorker(n) {
|
|
27001
|
-
if (!(!this.worker || n.length === 0))
|
|
27002
|
-
for (const { cacheKey: t, bitmap: a } of n) {
|
|
27003
|
-
const r = {
|
|
27004
|
-
type: "register-bitmap",
|
|
27005
|
-
cacheKey: t,
|
|
27006
|
-
bitmap: a
|
|
27007
|
-
};
|
|
27008
|
-
this.worker.postMessage(r, [a]);
|
|
27009
|
-
}
|
|
27010
|
-
}
|
|
27011
|
-
/**
|
|
27012
|
-
* Clear all bitmaps from the worker's cache.
|
|
27013
|
-
* Also clears the main thread's registration tracking.
|
|
27014
|
-
* Call this when exiting editor mode to free memory.
|
|
27015
|
-
*/
|
|
27016
|
-
clearWorkerBitmapCache() {
|
|
27017
|
-
if (Nn(), this.worker && this.isReady) {
|
|
27018
|
-
const n = {
|
|
27019
|
-
type: "clear-all-bitmaps"
|
|
27020
|
-
};
|
|
27021
|
-
this.worker.postMessage(n);
|
|
27022
|
-
}
|
|
27023
|
-
}
|
|
27024
|
-
/**
|
|
27025
|
-
* Clear a specific element's bitmaps from the worker's cache.
|
|
27026
|
-
* Call this when an element is removed or its image source changes.
|
|
27027
|
-
*/
|
|
27028
|
-
clearWorkerBitmap(n) {
|
|
27029
|
-
if (ze(n), this.worker && this.isReady) {
|
|
27030
|
-
const t = {
|
|
27031
|
-
type: "clear-bitmap",
|
|
27032
|
-
elementId: n
|
|
27033
|
-
};
|
|
27034
|
-
this.worker.postMessage(t);
|
|
27035
|
-
}
|
|
27036
|
-
}
|
|
27037
|
-
/**
|
|
27038
|
-
* Check if browser supports OffscreenCanvas and Web Workers
|
|
27039
|
-
*/
|
|
27040
|
-
static supportsWorkerExport() {
|
|
27041
|
-
try {
|
|
27042
|
-
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);
|
|
27043
|
-
} catch (n) {
|
|
27044
|
-
return O.warn("Feature detection failed:", n), !1;
|
|
27045
|
-
}
|
|
27046
|
-
}
|
|
27047
|
-
/**
|
|
27048
|
-
* Initialize the worker
|
|
27049
|
-
*/
|
|
27050
|
-
async initialize() {
|
|
27051
|
-
if (this.worker)
|
|
27052
|
-
return this.readyPromise || Promise.resolve();
|
|
27053
|
-
if (!pn.supportsWorkerExport())
|
|
27054
|
-
throw new Error("Browser does not support OffscreenCanvas or Web Workers");
|
|
27055
|
-
return this.readyPromise = new Promise((n, t) => {
|
|
27056
|
-
try {
|
|
27057
|
-
let a;
|
|
27058
|
-
try {
|
|
27059
|
-
const s = new Blob([Ma], { type: "application/javascript" });
|
|
27060
|
-
a = URL.createObjectURL(s), this.workerBlobUrl = a;
|
|
27061
|
-
} catch (s) {
|
|
27062
|
-
O.error("Failed to create worker blob:", s), t(new Error(`Worker creation failed: ${s instanceof Error ? s.message : String(s)}`));
|
|
27063
|
-
return;
|
|
27064
|
-
}
|
|
27065
|
-
this.worker = new Worker(a, { type: "classic" }), this.worker.onmessage = (s) => {
|
|
27066
|
-
this.handleWorkerMessage(s.data);
|
|
27067
|
-
}, this.worker.onerror = (s) => {
|
|
27068
|
-
O.error("Worker error:", s), this.handleWorkerError(s);
|
|
27069
|
-
};
|
|
27070
|
-
const r = setTimeout(() => {
|
|
27071
|
-
t(new Error("Worker initialization timeout"));
|
|
27072
|
-
}, 15e3), o = (s) => {
|
|
27073
|
-
s.data.type === "ready" && (clearTimeout(r), this.isReady = !0, Fa(
|
|
27074
|
-
() => this.clearWorkerBitmapCache(),
|
|
27075
|
-
(c) => this.clearWorkerBitmap(c)
|
|
27076
|
-
), n());
|
|
27077
|
-
};
|
|
27078
|
-
this.worker.addEventListener("message", o, { once: !0 });
|
|
27079
|
-
} catch (a) {
|
|
27080
|
-
O.error("Failed to create worker:", a), t(a);
|
|
27081
|
-
}
|
|
27082
|
-
}), this.readyPromise;
|
|
27083
|
-
}
|
|
27084
|
-
/**
|
|
27085
|
-
* Restart worker after crash
|
|
27086
|
-
*/
|
|
27087
|
-
async restartWorker() {
|
|
27088
|
-
const n = Date.now();
|
|
27089
|
-
if (n - this.lastCrashTime > this.CRASH_RESET_TIMEOUT && (this.workerCrashCount = 0), this.workerCrashCount++, this.lastCrashTime = n, O.warn(`Worker crashed (${this.workerCrashCount}/${this.MAX_CRASHES_BEFORE_FALLBACK})`), this.workerCrashCount >= this.MAX_CRASHES_BEFORE_FALLBACK)
|
|
27090
|
-
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.");
|
|
27091
|
-
this.worker && (this.worker.terminate(), this.worker = null, this.isReady = !1, this.readyPromise = null, this.workerBlobUrl && (URL.revokeObjectURL(this.workerBlobUrl), this.workerBlobUrl = null));
|
|
27092
|
-
const t = Math.min(1e3 * Math.pow(2, this.workerCrashCount - 1), 5e3);
|
|
27093
|
-
await new Promise((a) => setTimeout(a, t)), await this.initialize();
|
|
27094
|
-
}
|
|
27095
|
-
/**
|
|
27096
|
-
* Export artboard to data URL using worker
|
|
27097
|
-
* Uses request queue for concurrent exports
|
|
27098
|
-
*/
|
|
27099
|
-
async exportArtboardToDataURL(n, t, a = {}) {
|
|
27100
|
-
return this.resetIdleTimer(), new Promise((r, o) => {
|
|
27101
|
-
this.requestQueue.push({
|
|
27102
|
-
artboard: n,
|
|
27103
|
-
elements: t,
|
|
27104
|
-
config: { ...a, returnFormat: "dataUrl" },
|
|
27105
|
-
resolve: r,
|
|
27106
|
-
reject: o
|
|
27107
|
-
}), this.processQueue();
|
|
27108
|
-
});
|
|
27109
|
-
}
|
|
27110
|
-
/**
|
|
27111
|
-
* Export artboard to Blob using worker
|
|
27112
|
-
* Returns a Blob directly - more efficient for API uploads
|
|
27113
|
-
* Uses request queue for concurrent exports
|
|
27114
|
-
*/
|
|
27115
|
-
async exportArtboardToBlob(n, t, a = {}) {
|
|
27116
|
-
return this.resetIdleTimer(), new Promise((r, o) => {
|
|
27117
|
-
this.blobRequestQueue.push({
|
|
27118
|
-
artboard: n,
|
|
27119
|
-
elements: t,
|
|
27120
|
-
config: { ...a, returnFormat: "blob" },
|
|
27121
|
-
resolve: r,
|
|
27122
|
-
reject: o
|
|
27123
|
-
}), this.processBlobQueue();
|
|
27124
|
-
});
|
|
27125
|
-
}
|
|
27126
|
-
/**
|
|
27127
|
-
* Process the request queue
|
|
27128
|
-
*/
|
|
27129
|
-
async processQueue() {
|
|
27130
|
-
if (!(this.isProcessingQueue || this.requestQueue.length === 0)) {
|
|
27131
|
-
for (this.isProcessingQueue = !0; this.requestQueue.length > 0; ) {
|
|
27132
|
-
const n = this.requestQueue.shift();
|
|
27133
|
-
try {
|
|
27134
|
-
const t = await this.executeExportRequest(n);
|
|
27135
|
-
n.resolve(t);
|
|
27136
|
-
} catch (t) {
|
|
27137
|
-
n.reject(t instanceof Error ? t : new Error(String(t)));
|
|
27138
|
-
}
|
|
27139
|
-
}
|
|
27140
|
-
this.isProcessingQueue = !1;
|
|
27141
|
-
}
|
|
27142
|
-
}
|
|
27143
|
-
/**
|
|
27144
|
-
* Execute a single export request
|
|
27145
|
-
*/
|
|
27146
|
-
async executeExportRequest(n) {
|
|
27147
|
-
const { artboard: t, elements: a, config: r } = n;
|
|
27148
|
-
if ((!this.worker || !this.isReady) && await this.initialize(), !this.worker)
|
|
27149
|
-
throw new Error("Worker is not initialized");
|
|
27150
|
-
const o = `export-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: c, newBitmaps: i } = await $e(t, a);
|
|
27151
|
-
i.length > 0 && this.registerBitmapsWithWorker(i);
|
|
27152
|
-
const l = {
|
|
27153
|
-
type: "export",
|
|
27154
|
-
requestId: o,
|
|
27155
|
-
artboardData: c.artboard,
|
|
27156
|
-
elements: c.elements,
|
|
27157
|
-
fonts: c.fonts,
|
|
27158
|
-
// Custom (brand) fonts among the used families — the worker loads
|
|
27159
|
-
// these from their hosted URL instead of Google Fonts (deterministic
|
|
27160
|
-
// shadowing; see utils/custom-fonts.ts).
|
|
27161
|
-
customFonts: Wn.forFamilies(c.fonts ?? []),
|
|
27162
|
-
scale: r.scale || 1,
|
|
27163
|
-
format: r.format || "png",
|
|
27164
|
-
quality: r.quality || 0.95
|
|
27165
|
-
}, d = new Promise(($, h) => {
|
|
27166
|
-
this.pendingRequests.set(o, {
|
|
27167
|
-
requestId: o,
|
|
27168
|
-
resolve: $,
|
|
27169
|
-
reject: h,
|
|
27170
|
-
startTime: s,
|
|
27171
|
-
returnFormat: "dataUrl"
|
|
27172
|
-
}), setTimeout(() => {
|
|
27173
|
-
this.pendingRequests.has(o) && (this.pendingRequests.delete(o), h(new Error("Export request timeout")));
|
|
27174
|
-
}, 3e4);
|
|
27175
|
-
});
|
|
27176
|
-
this.worker.postMessage(l);
|
|
27177
|
-
const u = await d, f = performance.now() - s;
|
|
27178
|
-
return {
|
|
27179
|
-
dataUrl: u.dataUrl,
|
|
27180
|
-
artboardId: u.artboardId,
|
|
27181
|
-
artboardName: u.artboardName,
|
|
27182
|
-
renderTime: u.renderTime,
|
|
27183
|
-
totalTime: u.totalTime,
|
|
27184
|
-
mainThreadBlockTime: f
|
|
27185
|
-
};
|
|
27186
|
-
}
|
|
27187
|
-
/**
|
|
27188
|
-
* Process the blob request queue
|
|
27189
|
-
*/
|
|
27190
|
-
async processBlobQueue() {
|
|
27191
|
-
if (!(this.isProcessingQueue || this.blobRequestQueue.length === 0)) {
|
|
27192
|
-
for (this.isProcessingQueue = !0; this.blobRequestQueue.length > 0; ) {
|
|
27193
|
-
const n = this.blobRequestQueue.shift();
|
|
27194
|
-
try {
|
|
27195
|
-
const t = await this.executeBlobExportRequest(n);
|
|
27196
|
-
n.resolve(t);
|
|
27197
|
-
} catch (t) {
|
|
27198
|
-
n.reject(t instanceof Error ? t : new Error(String(t)));
|
|
27199
|
-
}
|
|
27200
|
-
}
|
|
27201
|
-
this.isProcessingQueue = !1;
|
|
27202
|
-
}
|
|
27203
|
-
}
|
|
27204
|
-
/**
|
|
27205
|
-
* Execute a single blob export request
|
|
27206
|
-
*/
|
|
27207
|
-
async executeBlobExportRequest(n) {
|
|
27208
|
-
const { artboard: t, elements: a, config: r } = n;
|
|
27209
|
-
if ((!this.worker || !this.isReady) && await this.initialize(), !this.worker)
|
|
27210
|
-
throw new Error("Worker is not initialized");
|
|
27211
|
-
const o = `export-blob-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: c, newBitmaps: i } = await $e(t, a);
|
|
27212
|
-
i.length > 0 && this.registerBitmapsWithWorker(i);
|
|
27213
|
-
const l = {
|
|
27214
|
-
type: "export",
|
|
27215
|
-
requestId: o,
|
|
27216
|
-
artboardData: c.artboard,
|
|
27217
|
-
elements: c.elements,
|
|
27218
|
-
fonts: c.fonts,
|
|
27219
|
-
// Same custom-font threading as the dataUrl path above.
|
|
27220
|
-
customFonts: Wn.forFamilies(c.fonts ?? []),
|
|
27221
|
-
scale: r.scale || 1,
|
|
27222
|
-
format: r.format || "png",
|
|
27223
|
-
quality: r.quality || 0.95,
|
|
27224
|
-
returnFormat: "blob"
|
|
27225
|
-
}, d = new Promise((h, g) => {
|
|
27226
|
-
this.pendingRequests.set(o, {
|
|
27227
|
-
requestId: o,
|
|
27228
|
-
resolve: h,
|
|
27229
|
-
reject: g,
|
|
27230
|
-
startTime: s,
|
|
27231
|
-
returnFormat: "blob"
|
|
27232
|
-
}), setTimeout(() => {
|
|
27233
|
-
this.pendingRequests.has(o) && (this.pendingRequests.delete(o), g(new Error("Export request timeout")));
|
|
27234
|
-
}, 3e4);
|
|
27235
|
-
});
|
|
27236
|
-
this.worker.postMessage(l);
|
|
27237
|
-
const u = await d, f = performance.now() - s;
|
|
27238
|
-
return {
|
|
27239
|
-
blob: new Blob([u.blobData], { type: u.mimeType }),
|
|
27240
|
-
artboardId: u.artboardId,
|
|
27241
|
-
artboardName: u.artboardName,
|
|
27242
|
-
renderTime: u.renderTime,
|
|
27243
|
-
totalTime: u.totalTime,
|
|
27244
|
-
mainThreadBlockTime: f
|
|
27245
|
-
};
|
|
27246
|
-
}
|
|
27247
|
-
/**
|
|
27248
|
-
* Handle messages from worker
|
|
27249
|
-
*/
|
|
27250
|
-
handleWorkerMessage(n) {
|
|
27251
|
-
switch (n.type) {
|
|
27252
|
-
case "exportComplete":
|
|
27253
|
-
this.handleExportComplete(n);
|
|
27254
|
-
break;
|
|
27255
|
-
case "exportBlobComplete":
|
|
27256
|
-
this.handleBlobExportComplete(n);
|
|
27257
|
-
break;
|
|
27258
|
-
case "exportError":
|
|
27259
|
-
this.handleExportError(n);
|
|
27260
|
-
break;
|
|
27261
|
-
case "exportProgress":
|
|
27262
|
-
this.emitProgress({
|
|
27263
|
-
requestId: n.requestId,
|
|
27264
|
-
progress: n.progress,
|
|
27265
|
-
message: n.message
|
|
27266
|
-
});
|
|
27267
|
-
break;
|
|
27268
|
-
case "ready":
|
|
27269
|
-
break;
|
|
27270
|
-
default:
|
|
27271
|
-
O.warn("Unknown message type:", n);
|
|
27272
|
-
}
|
|
27273
|
-
}
|
|
27274
|
-
/**
|
|
27275
|
-
* Handle successful export completion (dataUrl)
|
|
27276
|
-
*/
|
|
27277
|
-
handleExportComplete(n) {
|
|
27278
|
-
const t = this.pendingRequests.get(n.requestId);
|
|
27279
|
-
t && t.returnFormat === "dataUrl" ? (t.resolve(n), this.pendingRequests.delete(n.requestId)) : t ? (O.warn("Received dataUrl response for blob request:", n.requestId), t.reject(new Error("Received dataUrl response when expecting blob")), this.pendingRequests.delete(n.requestId)) : O.warn("Received response for unknown request:", n.requestId);
|
|
27280
|
-
}
|
|
27281
|
-
/**
|
|
27282
|
-
* Handle successful blob export completion
|
|
27283
|
-
*/
|
|
27284
|
-
handleBlobExportComplete(n) {
|
|
27285
|
-
const t = this.pendingRequests.get(n.requestId);
|
|
27286
|
-
t && t.returnFormat === "blob" ? (t.resolve(n), this.pendingRequests.delete(n.requestId)) : t ? (O.warn("Received blob response for dataUrl request:", n.requestId), t.reject(new Error("Received blob response when expecting dataUrl")), this.pendingRequests.delete(n.requestId)) : O.warn("Received blob response for unknown request:", n.requestId);
|
|
27287
|
-
}
|
|
27288
|
-
/**
|
|
27289
|
-
* Handle export error
|
|
27290
|
-
*/
|
|
27291
|
-
handleExportError(n) {
|
|
27292
|
-
const t = this.pendingRequests.get(n.requestId);
|
|
27293
|
-
if (t) {
|
|
27294
|
-
const a = new Error(n.error);
|
|
27295
|
-
n.stack && (a.stack = n.stack), t.reject(a), this.pendingRequests.delete(n.requestId);
|
|
27296
|
-
} else
|
|
27297
|
-
O.warn("Received error for unknown request:", n.requestId);
|
|
27298
|
-
}
|
|
27299
|
-
/**
|
|
27300
|
-
* Handle worker errors
|
|
27301
|
-
*/
|
|
27302
|
-
async handleWorkerError(n) {
|
|
27303
|
-
O.error("Worker error:", n);
|
|
27304
|
-
const t = Array.from(this.pendingRequests.values());
|
|
27305
|
-
for (const [a, r] of this.pendingRequests.entries())
|
|
27306
|
-
this.pendingRequests.delete(a);
|
|
27307
|
-
this.isReady = !1;
|
|
27308
|
-
try {
|
|
27309
|
-
await this.restartWorker();
|
|
27310
|
-
} catch (a) {
|
|
27311
|
-
O.error("Failed to restart worker:", a);
|
|
27312
|
-
for (const r of t)
|
|
27313
|
-
r.reject(new Error(`Worker crashed and could not be restarted: ${n.message}`));
|
|
27314
|
-
for (; this.requestQueue.length > 0; )
|
|
27315
|
-
this.requestQueue.shift().reject(new Error("Worker crashed and could not be restarted"));
|
|
27316
|
-
}
|
|
27317
|
-
}
|
|
27318
|
-
/**
|
|
27319
|
-
* Terminate the worker
|
|
27320
|
-
*/
|
|
27321
|
-
terminate() {
|
|
27322
|
-
if (this.idleTimeout && (clearTimeout(this.idleTimeout), this.idleTimeout = null), this.worker) {
|
|
27323
|
-
for (const [n, t] of this.pendingRequests.entries())
|
|
27324
|
-
t.reject(new Error("Worker terminated")), this.pendingRequests.delete(n);
|
|
27325
|
-
for (; this.requestQueue.length > 0; )
|
|
27326
|
-
this.requestQueue.shift().reject(new Error("Worker terminated"));
|
|
27327
|
-
this.worker.terminate(), this.worker = null, this.isReady = !1, this.readyPromise = null, Nn(), Da(), this.workerBlobUrl && (URL.revokeObjectURL(this.workerBlobUrl), this.workerBlobUrl = null);
|
|
27328
|
-
}
|
|
27329
|
-
}
|
|
27330
|
-
/**
|
|
27331
|
-
* Get worker status
|
|
27332
|
-
*/
|
|
27333
|
-
getStatus() {
|
|
27334
|
-
return {
|
|
27335
|
-
isReady: this.isReady,
|
|
27336
|
-
pendingRequests: this.pendingRequests.size,
|
|
27337
|
-
queuedRequests: this.requestQueue.length,
|
|
27338
|
-
crashCount: this.workerCrashCount
|
|
27339
|
-
};
|
|
27340
|
-
}
|
|
27341
|
-
}
|
|
27342
|
-
let nn = null;
|
|
27343
|
-
function er() {
|
|
27344
|
-
return nn || (nn = new pn()), nn;
|
|
27345
|
-
}
|
|
27346
|
-
function tr() {
|
|
27347
|
-
nn && (nn.terminate(), nn = null);
|
|
27348
|
-
}
|
|
27349
|
-
jn();
|
|
27350
|
-
const W = U("Export");
|
|
27351
|
-
function zn(e, n) {
|
|
27352
|
-
var t;
|
|
27353
|
-
if (!(!e || typeof e != "object")) {
|
|
27354
|
-
if (typeof e.fontFamily == "string" && e.fontFamily.trim() && n.add(e.fontFamily), e.richText && Array.isArray(e.richText.spans))
|
|
27355
|
-
for (const a of e.richText.spans)
|
|
27356
|
-
(t = a == null ? void 0 : a.style) != null && t.fontFamily && typeof a.style.fontFamily == "string" && n.add(a.style.fontFamily);
|
|
27357
|
-
if (Array.isArray(e.children))
|
|
27358
|
-
for (const a of e.children) zn(a, n);
|
|
27359
|
-
if (Array.isArray(e.masks))
|
|
27360
|
-
for (const a of e.masks)
|
|
27361
|
-
a != null && a.maskElement && zn(a.maskElement, n);
|
|
27362
|
-
}
|
|
27363
|
-
}
|
|
27364
|
-
async function xe(e) {
|
|
27365
|
-
if (typeof document > "u" || !document.fonts) return;
|
|
27366
|
-
const n = /* @__PURE__ */ new Set();
|
|
27367
|
-
for (const a of e) zn(a, n);
|
|
27368
|
-
if (n.size === 0) return;
|
|
27369
|
-
const t = [];
|
|
27370
|
-
for (const a of n)
|
|
27371
|
-
t.push(document.fonts.load(`16px "${a}"`).catch(() => {
|
|
27372
|
-
}));
|
|
27373
|
-
await Promise.all(t), document.fonts.ready && await document.fonts.ready;
|
|
27374
|
-
}
|
|
27375
|
-
const dn = class dn {
|
|
27376
|
-
/**
|
|
27377
|
-
* Check if worker export is supported in this browser
|
|
27378
|
-
*/
|
|
27379
|
-
static supportsWorkerExport() {
|
|
27380
|
-
return pn.supportsWorkerExport();
|
|
27381
|
-
}
|
|
27382
|
-
/**
|
|
27383
|
-
* Get or initialize the worker manager
|
|
27384
|
-
*/
|
|
27385
|
-
static async getWorkerManager() {
|
|
27386
|
-
return this.supportsWorkerExport() ? this.workerManager ? this.workerManager : this.workerInitPromise ? (await this.workerInitPromise, this.workerManager) : (this.workerInitPromise = (async () => {
|
|
27387
|
-
try {
|
|
27388
|
-
this.workerManager = new pn(), await this.workerManager.initialize();
|
|
27389
|
-
} catch (n) {
|
|
27390
|
-
W.error("Failed to initialize worker:", n), this.workerManager = null;
|
|
27391
|
-
}
|
|
27392
|
-
})(), await this.workerInitPromise, this.workerInitPromise = null, this.workerManager) : null;
|
|
27393
|
-
}
|
|
27394
|
-
/**
|
|
27395
|
-
* Terminate the worker (for cleanup)
|
|
27396
|
-
*/
|
|
27397
|
-
static terminateWorker() {
|
|
27398
|
-
this.workerManager && (this.workerManager.terminate(), this.workerManager = null);
|
|
27399
|
-
}
|
|
27400
|
-
/**
|
|
27401
|
-
* Export entire workspace to JSON
|
|
27402
|
-
*/
|
|
27403
|
-
static exportToJSON(n, t, a, r) {
|
|
27404
|
-
const o = {
|
|
27405
|
-
metadata: {
|
|
27406
|
-
version: this.CURRENT_VERSION,
|
|
27407
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
27408
|
-
appVersion: "1.0.0"
|
|
27409
|
-
},
|
|
27410
|
-
artboards: n.map((d) => {
|
|
27411
|
-
const u = new Set(d.getElementIds()), p = t.filter((f) => u.has(f.id));
|
|
27412
|
-
return {
|
|
27413
|
-
id: d.id,
|
|
27414
|
-
name: d.name,
|
|
27415
|
-
x: d.x,
|
|
27416
|
-
y: d.y,
|
|
27417
|
-
width: d.width,
|
|
27418
|
-
height: d.height,
|
|
27419
|
-
backgroundColor: d.backgroundColor,
|
|
27420
|
-
elements: p.map((f) => f.toJSON())
|
|
27421
|
-
};
|
|
27422
|
-
}),
|
|
27423
|
-
activeArtboardId: a.getActiveArtboardId()
|
|
27424
|
-
}, s = JSON.stringify(o, null, 2), c = new Blob([s], { type: "application/json" }), i = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").split("T")[0], l = r || `canvas-${i}.json`;
|
|
27425
|
-
this.downloadBlob(c, l);
|
|
27426
|
-
}
|
|
27427
|
-
/**
|
|
27428
|
-
* Export artboard to image
|
|
27429
|
-
* Uses worker if supported, falls back to main thread
|
|
27430
|
-
*/
|
|
27431
|
-
static async exportArtboardToImage(n, t, a, r = {}) {
|
|
27432
|
-
const {
|
|
27433
|
-
format: o = "png",
|
|
27434
|
-
quality: s = 0.95,
|
|
27435
|
-
scale: c = 1,
|
|
27436
|
-
transparentBackground: i = !1,
|
|
27437
|
-
backgroundColor: l = n.backgroundColor,
|
|
27438
|
-
filename: d,
|
|
27439
|
-
forceMainThread: u = !1
|
|
27440
|
-
} = r, p = await this.exportArtboardToDataURL(n, t, a, {
|
|
27441
|
-
format: o,
|
|
27442
|
-
quality: s,
|
|
27443
|
-
scale: c,
|
|
27444
|
-
transparentBackground: i,
|
|
27445
|
-
backgroundColor: l,
|
|
27446
|
-
forceMainThread: u
|
|
27447
|
-
}), f = await this.dataUrlToBlob(p), $ = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").split("T")[0], h = d || `${n.name}-${$}.${o}`;
|
|
27448
|
-
this.downloadBlob(f, h);
|
|
27449
|
-
}
|
|
27450
|
-
/**
|
|
27451
|
-
* Export artboard to data URL (for preview/testing)
|
|
27452
|
-
* Uses worker if supported, falls back to main thread
|
|
27453
|
-
*/
|
|
27454
|
-
static async exportArtboardToDataURL(n, t, a, r = {}) {
|
|
27455
|
-
const {
|
|
27456
|
-
format: o = "png",
|
|
27457
|
-
quality: s = 0.95,
|
|
27458
|
-
scale: c = 1,
|
|
27459
|
-
transparentBackground: i = !1,
|
|
27460
|
-
backgroundColor: l = n.backgroundColor,
|
|
27461
|
-
forceMainThread: d = !1
|
|
27462
|
-
} = r;
|
|
27463
|
-
if (!d && this.supportsWorkerExport())
|
|
27464
|
-
try {
|
|
27465
|
-
const u = await this.getWorkerManager();
|
|
27466
|
-
if (u) {
|
|
27467
|
-
const p = new Set(n.getElementIds()), f = t.filter((h) => p.has(h.id));
|
|
27468
|
-
return (await u.exportArtboardToDataURL(n, f, {
|
|
27469
|
-
scale: c,
|
|
27470
|
-
format: o === "jpg" ? "jpeg" : o,
|
|
27471
|
-
quality: s
|
|
27472
|
-
})).dataUrl;
|
|
27473
|
-
}
|
|
27474
|
-
} catch (u) {
|
|
27475
|
-
W.warn("Worker export failed, falling back to main thread:", u);
|
|
27476
|
-
}
|
|
27477
|
-
return this.mainThreadExportToDataURL(n, t, a, {
|
|
27478
|
-
format: o,
|
|
27479
|
-
quality: s,
|
|
27480
|
-
scale: c,
|
|
27481
|
-
transparentBackground: i,
|
|
27482
|
-
backgroundColor: l
|
|
27483
|
-
});
|
|
27484
|
-
}
|
|
27485
|
-
/**
|
|
27486
|
-
* Export artboard as Blob (more efficient for API uploads)
|
|
27487
|
-
* Returns a Blob instead of data URL - smaller payload, faster for network operations
|
|
27488
|
-
* Uses worker if supported, falls back to main thread
|
|
27489
|
-
*/
|
|
27490
|
-
static async exportArtboardToBlob(n, t, a, r = {}) {
|
|
27491
|
-
const {
|
|
27492
|
-
format: o = "png",
|
|
27493
|
-
quality: s = 0.95,
|
|
27494
|
-
scale: c = 1,
|
|
27495
|
-
transparentBackground: i = !1,
|
|
27496
|
-
backgroundColor: l = n.backgroundColor,
|
|
27497
|
-
forceMainThread: d = !1
|
|
27498
|
-
} = r;
|
|
27499
|
-
if (!d && this.supportsWorkerExport())
|
|
27500
|
-
try {
|
|
27501
|
-
const u = await this.getWorkerManager();
|
|
27502
|
-
if (u) {
|
|
27503
|
-
const p = new Set(n.getElementIds()), f = t.filter((h) => p.has(h.id));
|
|
27504
|
-
return (await u.exportArtboardToBlob(n, f, {
|
|
27505
|
-
scale: c,
|
|
27506
|
-
format: o === "jpg" ? "jpeg" : o,
|
|
27507
|
-
quality: s
|
|
27508
|
-
})).blob;
|
|
27509
|
-
}
|
|
27510
|
-
} catch (u) {
|
|
27511
|
-
W.warn("Worker blob export failed, falling back to main thread:", u);
|
|
27512
|
-
}
|
|
27513
|
-
return this.mainThreadExportToBlob(n, t, a, {
|
|
27514
|
-
format: o,
|
|
27515
|
-
quality: s,
|
|
27516
|
-
scale: c,
|
|
27517
|
-
transparentBackground: i,
|
|
27518
|
-
backgroundColor: l
|
|
27519
|
-
});
|
|
27520
|
-
}
|
|
27521
|
-
/**
|
|
27522
|
-
* Main thread export to Blob (fallback/legacy method).
|
|
27523
|
-
*
|
|
27524
|
-
* On iOS WebKit this is also the *primary* path (`isIOSWebKit()` skips the
|
|
27525
|
-
* worker), so font readiness matters here even when no fallback occurred.
|
|
27526
|
-
*/
|
|
27527
|
-
static async mainThreadExportToBlob(n, t, a, r = {}) {
|
|
27528
|
-
const {
|
|
27529
|
-
format: o = "png",
|
|
27530
|
-
quality: s = 0.95,
|
|
27531
|
-
scale: c = 1,
|
|
27532
|
-
transparentBackground: i = !1,
|
|
27533
|
-
backgroundColor: l = n.backgroundColor
|
|
27534
|
-
} = r;
|
|
27535
|
-
await xe(t);
|
|
27536
|
-
const d = document.createElement("canvas"), u = n.width * c, p = n.height * c;
|
|
27537
|
-
d.width = u, d.height = p;
|
|
27538
|
-
const f = d.getContext("2d");
|
|
27539
|
-
if (f.scale(c, c), !i && n.exportBackground) {
|
|
27540
|
-
if (f.save(), this.applyExportBackgroundClipPath(f, n), n.backgroundType === "texture" && n.backgroundTexture) {
|
|
27541
|
-
const m = Z.getTexturePresetColor(n.backgroundTexture);
|
|
27542
|
-
f.fillStyle = m, f.fillRect(0, 0, n.width, n.height);
|
|
27543
|
-
const b = Z.getTexture(n.backgroundTexture);
|
|
27544
|
-
b && b.complete && f.drawImage(b, 0, 0, n.width, n.height);
|
|
27545
|
-
} else
|
|
27546
|
-
f.fillStyle = l || n.backgroundColor, f.fillRect(0, 0, n.width, n.height);
|
|
27547
|
-
f.restore();
|
|
27548
|
-
}
|
|
27549
|
-
f.save(), f.translate(-n.x, -n.y), this.applyExportClipPath(f, n);
|
|
27550
|
-
const $ = new Set(n.getElementIds()), h = t.filter((m) => $.has(m.id)), g = /* @__PURE__ */ new Map();
|
|
27551
|
-
h.forEach((m) => g.set(m.id, m));
|
|
27552
|
-
const v = (m, b) => {
|
|
27553
|
-
if (!b.id) return;
|
|
27554
|
-
const C = g.get(b.id);
|
|
27555
|
-
C && C.render(m, !1);
|
|
27556
|
-
}, y = h.map((m) => m.toJSON()), x = /* @__PURE__ */ new Set();
|
|
27557
|
-
return h.forEach((m, b) => {
|
|
27558
|
-
var C;
|
|
27559
|
-
if (m.blendMode === "knockout" || m.blendMode === "clip") {
|
|
27560
|
-
const T = y[b], k = m.blendMode === "knockout" ? "destination-out" : "destination-in", _ = ((C = T.knockoutParts) == null ? void 0 : C.scope) || "group", w = y.findIndex((A) => A.id === T.id);
|
|
27561
|
-
if (w !== -1 && _ === "artboard")
|
|
27562
|
-
for (let A = 0; A < w; A++) {
|
|
27563
|
-
const E = y[A].id;
|
|
27564
|
-
E && x.add(E);
|
|
27565
|
-
}
|
|
27566
|
-
Dn(
|
|
27567
|
-
f,
|
|
27568
|
-
T,
|
|
27569
|
-
y,
|
|
27570
|
-
v,
|
|
27571
|
-
i || !n.exportBackground ? void 0 : l,
|
|
27572
|
-
n,
|
|
27573
|
-
k
|
|
27574
|
-
), x.add(m.id);
|
|
27575
|
-
}
|
|
27576
|
-
}), h.forEach((m, b) => {
|
|
27577
|
-
x.has(m.id) || ce(f, y[b], (C) => {
|
|
27578
|
-
m.render(C, !1);
|
|
27579
|
-
});
|
|
27580
|
-
}), f.restore(), new Promise((m, b) => {
|
|
27581
|
-
d.toBlob(
|
|
27582
|
-
(C) => {
|
|
27583
|
-
C ? m(C) : b(new Error("Failed to create blob from canvas"));
|
|
27584
|
-
},
|
|
27585
|
-
o === "jpg" || o === "jpeg" ? "image/jpeg" : o === "webp" ? "image/webp" : "image/png",
|
|
27586
|
-
s
|
|
27587
|
-
);
|
|
27588
|
-
});
|
|
27589
|
-
}
|
|
27590
|
-
/**
|
|
27591
|
-
* Main thread export to data URL (fallback/legacy method).
|
|
27592
|
-
*
|
|
27593
|
-
* On iOS WebKit this is also the *primary* path (`isIOSWebKit()` skips the
|
|
27594
|
-
* worker), so font readiness matters here even when no fallback occurred.
|
|
27595
|
-
*/
|
|
27596
|
-
static async mainThreadExportToDataURL(n, t, a, r = {}) {
|
|
27597
|
-
var b, C;
|
|
27598
|
-
const {
|
|
27599
|
-
format: o = "png",
|
|
27600
|
-
quality: s = 0.95,
|
|
27601
|
-
scale: c = 1,
|
|
27602
|
-
transparentBackground: i = !1,
|
|
27603
|
-
backgroundColor: l = n.backgroundColor
|
|
27604
|
-
} = r;
|
|
27605
|
-
await xe(t);
|
|
27606
|
-
const d = document.createElement("canvas"), u = n.width * c, p = n.height * c;
|
|
27607
|
-
d.width = u, d.height = p;
|
|
27608
|
-
const f = d.getContext("2d");
|
|
27609
|
-
if (f.scale(c, c), !i && n.exportBackground) {
|
|
27610
|
-
if (f.save(), this.applyExportBackgroundClipPath(f, n), n.backgroundType === "texture" && n.backgroundTexture) {
|
|
27611
|
-
const T = Z.getTexturePresetColor(n.backgroundTexture);
|
|
27612
|
-
f.fillStyle = T, f.fillRect(0, 0, n.width, n.height);
|
|
27613
|
-
const k = Z.getTexture(n.backgroundTexture);
|
|
27614
|
-
k && k.complete ? f.drawImage(k, 0, 0, n.width, n.height) : W.warn("Texture not loaded for export:", n.backgroundTexture);
|
|
27615
|
-
} else
|
|
27616
|
-
f.fillStyle = l, f.fillRect(0, 0, n.width, n.height);
|
|
27617
|
-
f.restore();
|
|
27618
|
-
}
|
|
27619
|
-
f.save(), f.translate(-n.x, -n.y), this.applyExportClipPath(f, n);
|
|
27620
|
-
const $ = new Set(n.getElementIds()), h = t.filter((T) => $.has(T.id)), g = /* @__PURE__ */ new Map();
|
|
27621
|
-
h.forEach((T) => g.set(T.id, T));
|
|
27622
|
-
const v = (T, k) => {
|
|
27623
|
-
if (!k.id) return;
|
|
27624
|
-
const _ = g.get(k.id);
|
|
27625
|
-
_ ? _.render(T, !1) : W.warn("Element not found in map:", k.id);
|
|
27626
|
-
}, y = h.map((T) => T.toJSON()), x = /* @__PURE__ */ new Set();
|
|
27627
|
-
h.forEach((T, k) => {
|
|
27628
|
-
var _;
|
|
27629
|
-
if (T.blendMode === "knockout" || T.blendMode === "clip") {
|
|
27630
|
-
const w = y[k], A = T.blendMode === "knockout" ? "destination-out" : "destination-in", E = ((_ = w.knockoutParts) == null ? void 0 : _.scope) || "group", S = y.findIndex((P) => P.id === w.id);
|
|
27631
|
-
if (S !== -1 && E === "artboard")
|
|
27632
|
-
for (let P = 0; P < S; P++) {
|
|
27633
|
-
const I = y[P].id;
|
|
27634
|
-
I && x.add(I);
|
|
27635
|
-
}
|
|
27636
|
-
Dn(
|
|
27637
|
-
f,
|
|
27638
|
-
w,
|
|
27639
|
-
y,
|
|
27640
|
-
v,
|
|
27641
|
-
i || !n.exportBackground ? void 0 : l,
|
|
27642
|
-
n,
|
|
27643
|
-
A
|
|
27644
|
-
), x.add(T.id);
|
|
27645
|
-
}
|
|
27646
|
-
}), h.forEach((T, k) => {
|
|
27647
|
-
var _;
|
|
27648
|
-
if (!x.has(T.id)) {
|
|
27649
|
-
const w = y[k], A = ((_ = w == null ? void 0 : w.distressEffect) == null ? void 0 : _.enabled) && w.distressEffect.style === "custom" && w.distressEffect.textureUrl, E = (w == null ? void 0 : w.masks) && w.masks.length > 0, S = (P) => {
|
|
27650
|
-
T.render(P, !1);
|
|
27651
|
-
};
|
|
27652
|
-
ce(f, w, (P) => {
|
|
27653
|
-
if (E && A)
|
|
27654
|
-
oe(P, w, (I) => {
|
|
27655
|
-
const F = T.getVisualBoundingBox();
|
|
27656
|
-
he(I, w.distressEffect, F, S);
|
|
27657
|
-
});
|
|
27658
|
-
else if (E)
|
|
27659
|
-
oe(P, w, S);
|
|
27660
|
-
else if (A) {
|
|
27661
|
-
const I = T.getVisualBoundingBox();
|
|
27662
|
-
he(P, w.distressEffect, I, S);
|
|
27663
|
-
} else
|
|
27664
|
-
T.render(P, !1);
|
|
27665
|
-
});
|
|
27666
|
-
}
|
|
27667
|
-
}), (b = n.distressTexture) != null && b.enabled && Ta(f, n.distressTexture, {
|
|
27668
|
-
x: n.x,
|
|
27669
|
-
y: n.y,
|
|
27670
|
-
width: n.width,
|
|
27671
|
-
height: n.height
|
|
27672
|
-
}), (C = n.imageMask) != null && C.enabled && pa(f, n.imageMask, {
|
|
27673
|
-
x: n.x,
|
|
27674
|
-
y: n.y,
|
|
27675
|
-
width: n.width,
|
|
27676
|
-
height: n.height
|
|
27677
|
-
}), f.restore();
|
|
27678
|
-
const m = o === "png" ? "image/png" : o === "webp" ? "image/webp" : "image/jpeg";
|
|
27679
|
-
return d.toDataURL(m, s);
|
|
27680
|
-
}
|
|
27681
|
-
/**
|
|
27682
|
-
* Apply clip path for export background (uses 0,0 as origin since background is drawn before translate)
|
|
27683
|
-
*/
|
|
27684
|
-
static applyExportBackgroundClipPath(n, t) {
|
|
27685
|
-
const { width: a, height: r, clipShape: o } = t, s = 0, c = 0;
|
|
27686
|
-
if (n.beginPath(), !o || o === "rectangle")
|
|
27687
|
-
n.rect(s, c, a, r);
|
|
27688
|
-
else if (o === "circle") {
|
|
27689
|
-
const i = s + a / 2, l = c + r / 2, d = Math.min(a, r) / 2;
|
|
27690
|
-
n.arc(i, l, d, 0, Math.PI * 2);
|
|
27691
|
-
} else if (typeof o == "object" && o.type === "rounded") {
|
|
27692
|
-
const i = Math.min(o.radius, Math.min(a, r) / 2);
|
|
27693
|
-
typeof n.roundRect == "function" ? n.roundRect(s, c, a, r, i) : (n.moveTo(s + i, c), n.lineTo(s + a - i, c), n.arcTo(s + a, c, s + a, c + i, i), n.lineTo(s + a, c + r - i), n.arcTo(s + a, c + r, s + a - i, c + r, i), n.lineTo(s + i, c + r), n.arcTo(s, c + r, s, c + r - i, i), n.lineTo(s, c + i), n.arcTo(s, c, s + i, c, i));
|
|
27694
|
-
} else if (typeof o == "object" && o.type === "path")
|
|
27695
|
-
try {
|
|
27696
|
-
const i = new Path2D(o.d);
|
|
27697
|
-
n.clip(i);
|
|
27698
|
-
return;
|
|
27699
|
-
} catch (i) {
|
|
27700
|
-
W.warn("Invalid SVG path, falling back to rectangle:", i), n.rect(s, c, a, r);
|
|
27701
|
-
}
|
|
27702
|
-
n.clip();
|
|
27703
|
-
}
|
|
27704
|
-
/**
|
|
27705
|
-
* Apply clip path for export based on artboard's clipShape
|
|
27706
|
-
* This creates the clip region for the given artboard during export
|
|
27707
|
-
*/
|
|
27708
|
-
static applyExportClipPath(n, t) {
|
|
27709
|
-
const { x: a, y: r, width: o, height: s, clipShape: c } = t;
|
|
27710
|
-
if (n.beginPath(), !c || c === "rectangle")
|
|
27711
|
-
n.rect(a, r, o, s);
|
|
27712
|
-
else if (c === "circle") {
|
|
27713
|
-
const i = a + o / 2, l = r + s / 2, d = Math.min(o, s) / 2;
|
|
27714
|
-
n.arc(i, l, d, 0, Math.PI * 2);
|
|
27715
|
-
} else if (typeof c == "object" && c.type === "rounded") {
|
|
27716
|
-
const i = Math.min(c.radius, Math.min(o, s) / 2);
|
|
27717
|
-
typeof n.roundRect == "function" ? n.roundRect(a, r, o, s, i) : (n.moveTo(a + i, r), n.lineTo(a + o - i, r), n.arcTo(a + o, r, a + o, r + i, i), n.lineTo(a + o, r + s - i), n.arcTo(a + o, r + s, a + o - i, r + s, i), n.lineTo(a + i, r + s), n.arcTo(a, r + s, a, r + s - i, i), n.lineTo(a, r + i), n.arcTo(a, r, a + i, r, i));
|
|
27718
|
-
} else if (typeof c == "object" && c.type === "path")
|
|
27719
|
-
try {
|
|
27720
|
-
const i = new Path2D(c.d);
|
|
27721
|
-
n.translate(a, r), n.clip(i), n.translate(-a, -r);
|
|
27722
|
-
return;
|
|
27723
|
-
} catch (i) {
|
|
27724
|
-
W.warn("Invalid SVG path, falling back to rectangle:", i), n.rect(a, r, o, s);
|
|
27725
|
-
}
|
|
27726
|
-
n.clip();
|
|
27727
|
-
}
|
|
27728
|
-
/**
|
|
27729
|
-
* Export all artboards as separate images (HIGH PERFORMANCE - parallel rendering)
|
|
27730
|
-
*/
|
|
27731
|
-
static async exportAllArtboardsToImages(n, t, a, r = {}) {
|
|
27732
|
-
const o = n.map(
|
|
27733
|
-
(s) => this.exportArtboardToImage(s, t, a, {
|
|
27734
|
-
...r,
|
|
27735
|
-
filename: r.filename ? `${r.filename}-${s.name}.${r.format || "png"}` : void 0
|
|
27736
|
-
})
|
|
27737
|
-
);
|
|
27738
|
-
await Promise.all(o);
|
|
27739
|
-
}
|
|
27740
|
-
/**
|
|
27741
|
-
* Download a blob as a file
|
|
27742
|
-
*/
|
|
27743
|
-
static downloadBlob(n, t) {
|
|
27744
|
-
const a = URL.createObjectURL(n), r = document.createElement("a");
|
|
27745
|
-
r.href = a, r.download = t, document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(a);
|
|
27746
|
-
}
|
|
27747
|
-
/**
|
|
27748
|
-
* Convert data URL to blob
|
|
27749
|
-
*/
|
|
27750
|
-
static async dataUrlToBlob(n) {
|
|
27751
|
-
return (await fetch(n)).blob();
|
|
27752
|
-
}
|
|
27753
|
-
/**
|
|
27754
|
-
* Get export summary (for UI display)
|
|
27755
|
-
*/
|
|
27756
|
-
static getExportSummary(n, t) {
|
|
27757
|
-
const a = n.length, r = t.length, c = a * 200 + r * 500, i = Math.ceil(c / 1024);
|
|
27758
|
-
return {
|
|
27759
|
-
artboardCount: a,
|
|
27760
|
-
totalElementCount: r,
|
|
27761
|
-
estimatedFileSize: i < 1024 ? `${i} KB` : `${(i / 1024).toFixed(1)} MB`
|
|
27762
|
-
};
|
|
27763
|
-
}
|
|
27764
|
-
/**
|
|
27765
|
-
* Performance benchmark: Compare worker vs main thread export
|
|
27766
|
-
* Returns timing data for both methods
|
|
27767
|
-
*/
|
|
27768
|
-
static async benchmarkExport(n, t, a, r = {}) {
|
|
27769
|
-
const o = performance.now(), s = await this.exportArtboardToDataURL(n, t, a, {
|
|
27770
|
-
...r,
|
|
27771
|
-
forceMainThread: !0
|
|
27772
|
-
}), c = performance.now() - o, i = {
|
|
27773
|
-
workerSupported: this.supportsWorkerExport(),
|
|
27774
|
-
mainThread: {
|
|
27775
|
-
time: c,
|
|
27776
|
-
dataUrl: s
|
|
27777
|
-
},
|
|
27778
|
-
recommendation: ""
|
|
27779
|
-
};
|
|
27780
|
-
if (this.supportsWorkerExport())
|
|
27781
|
-
try {
|
|
27782
|
-
const l = performance.now(), d = await this.getWorkerManager();
|
|
27783
|
-
if (d) {
|
|
27784
|
-
const u = new Set(n.getElementIds()), p = t.filter((g) => u.has(g.id)), f = await d.exportArtboardToDataURL(n, p, {
|
|
27785
|
-
scale: r.scale || 1,
|
|
27786
|
-
format: (r.format === "jpg" ? "jpeg" : r.format) || "png",
|
|
27787
|
-
quality: r.quality || 0.95
|
|
27788
|
-
}), $ = performance.now() - l, h = c / $;
|
|
27789
|
-
return {
|
|
27790
|
-
...i,
|
|
27791
|
-
worker: {
|
|
27792
|
-
time: $,
|
|
27793
|
-
dataUrl: f.dataUrl,
|
|
27794
|
-
mainThreadBlockTime: f.mainThreadBlockTime
|
|
27795
|
-
},
|
|
27796
|
-
speedup: h,
|
|
27797
|
-
recommendation: h > 1.2 ? `Worker export is ${h.toFixed(2)}x faster - recommended for continuous export` : h < 0.8 ? `Main thread export is ${(1 / h).toFixed(2)}x faster - worker overhead not worth it for single exports` : "Performance is similar, but worker keeps UI responsive during export"
|
|
27798
|
-
};
|
|
27799
|
-
}
|
|
27800
|
-
} catch (l) {
|
|
27801
|
-
W.error("Worker benchmark failed:", l), i.recommendation = "Worker export not available - using main thread export";
|
|
27802
|
-
}
|
|
27803
|
-
else
|
|
27804
|
-
i.recommendation = "Worker export not supported in this browser - using main thread export";
|
|
27805
|
-
return i;
|
|
27806
|
-
}
|
|
27807
|
-
/**
|
|
27808
|
-
* Performance benchmark: Test continuous exports to measure UI impact
|
|
27809
|
-
* Returns statistics about export performance over time
|
|
27810
|
-
*/
|
|
27811
|
-
static async benchmarkContinuousExport(n, t, a, r = {}) {
|
|
27812
|
-
const {
|
|
27813
|
-
duration: o = 5e3,
|
|
27814
|
-
// 5 seconds
|
|
27815
|
-
interval: s = 500,
|
|
27816
|
-
// Every 500ms
|
|
27817
|
-
useWorker: c = this.supportsWorkerExport()
|
|
27818
|
-
} = r, i = [];
|
|
27819
|
-
let l = 0, d = !0;
|
|
27820
|
-
for (setTimeout(() => {
|
|
27821
|
-
d = !1;
|
|
27822
|
-
}, o); d; ) {
|
|
27823
|
-
const y = performance.now();
|
|
27824
|
-
await this.exportArtboardToDataURL(n, t, a, {
|
|
27825
|
-
forceMainThread: !c
|
|
27826
|
-
});
|
|
27827
|
-
const x = performance.now() - y;
|
|
27828
|
-
i.push(x), c || (l += x), await new Promise((m) => setTimeout(m, Math.max(0, s - x)));
|
|
27829
|
-
}
|
|
27830
|
-
const u = i.length, p = i.reduce((y, x) => y + x, 0) / u, f = Math.min(...i), $ = Math.max(...i), h = u / o * 1e3, g = l / o * 100, v = g > 20 ? `Main thread blocked ${g.toFixed(1)}% of the time - STRONGLY recommend worker export` : g > 10 ? `Main thread blocked ${g.toFixed(1)}% of the time - consider worker export` : `Main thread blocked ${g.toFixed(1)}% of the time - performance is acceptable`;
|
|
27831
|
-
return {
|
|
27832
|
-
totalExports: u,
|
|
27833
|
-
duration: o,
|
|
27834
|
-
averageTime: p,
|
|
27835
|
-
minTime: f,
|
|
27836
|
-
maxTime: $,
|
|
27837
|
-
totalMainThreadBlockTime: l,
|
|
27838
|
-
exportsPerSecond: h,
|
|
27839
|
-
recommendation: v
|
|
27840
|
-
};
|
|
27841
|
-
}
|
|
27842
|
-
/**
|
|
27843
|
-
* Get performance statistics for the worker (if initialized)
|
|
27844
|
-
*/
|
|
27845
|
-
static getWorkerStats() {
|
|
27846
|
-
var n;
|
|
27847
|
-
return {
|
|
27848
|
-
workerSupported: this.supportsWorkerExport(),
|
|
27849
|
-
workerInitialized: this.workerManager !== null,
|
|
27850
|
-
workerStatus: (n = this.workerManager) == null ? void 0 : n.getStatus()
|
|
27851
|
-
};
|
|
27852
|
-
}
|
|
27853
|
-
/**
|
|
27854
|
-
* Get recommended export options for t-shirt designs
|
|
27855
|
-
* T-shirt designs should ALWAYS use transparent backgrounds with knockout effects
|
|
27856
|
-
*/
|
|
27857
|
-
static getTShirtExportOptions(n = {}) {
|
|
27858
|
-
return {
|
|
27859
|
-
format: "png",
|
|
27860
|
-
// PNG for transparency support
|
|
27861
|
-
scale: 2,
|
|
27862
|
-
// 2x for print quality
|
|
27863
|
-
quality: 1,
|
|
27864
|
-
// Maximum quality
|
|
27865
|
-
...n,
|
|
27866
|
-
// Force transparent background - critical for knockout effects
|
|
27867
|
-
transparentBackground: !0
|
|
27868
|
-
};
|
|
27869
|
-
}
|
|
27870
|
-
/**
|
|
27871
|
-
* Get recommended export options for pillow/pattern designs
|
|
27872
|
-
* These may use group-scoped knockout with pattern backgrounds
|
|
27873
|
-
*/
|
|
27874
|
-
static getPatternExportOptions(n = {}) {
|
|
27875
|
-
return {
|
|
27876
|
-
format: "png",
|
|
27877
|
-
scale: 2,
|
|
27878
|
-
transparentBackground: !1,
|
|
27879
|
-
// Patterns often include background
|
|
27880
|
-
quality: 1,
|
|
27881
|
-
...n
|
|
27882
|
-
};
|
|
27883
|
-
}
|
|
27884
|
-
/**
|
|
27885
|
-
* Validate export options for common issues
|
|
27886
|
-
* Returns warnings if options might cause problems
|
|
27887
|
-
*/
|
|
27888
|
-
static validateExportOptions(n, t) {
|
|
27889
|
-
const a = [];
|
|
27890
|
-
return t && !n.transparentBackground && a.push(
|
|
27891
|
-
"WARNING: Document has knockout effects but transparentBackground is false. Knockout effects work best with transparent backgrounds for t-shirt designs."
|
|
27892
|
-
), n.transparentBackground && (n.format === "jpg" || n.format === "jpeg") && a.push("WARNING: JPEG format does not support transparency. Use PNG format for transparent backgrounds."), n.quality && n.quality < 0.9 && a.push("NOTE: Using quality < 0.9 may reduce the appearance of distress and other effects."), n.scale && n.scale < 2 && a.push("NOTE: For print-ready designs, recommend scale of 2x or higher."), a;
|
|
27893
|
-
}
|
|
27894
|
-
/**
|
|
27895
|
-
* Check if any elements in the list have knockout effects
|
|
27896
|
-
*/
|
|
27897
|
-
static hasKnockoutEffects(n) {
|
|
27898
|
-
const t = (a) => (a.blendMode === "knockout" || a.blendMode === "clip") && a.knockoutParts ? !0 : "children" in a && Array.isArray(a.children) ? a.children.some((r) => t(r)) : !1;
|
|
27899
|
-
return n.some((a) => t(a));
|
|
27900
|
-
}
|
|
27901
|
-
/**
|
|
27902
|
-
* CRITICAL: Ensure artboard is export-safe
|
|
27903
|
-
* Strips preview background color to prevent accidental export
|
|
27904
|
-
* Returns a copy of the artboard safe for export
|
|
27905
|
-
*/
|
|
27906
|
-
static makeArtboardExportSafe(n) {
|
|
27907
|
-
const t = Object.assign(Object.create(Object.getPrototypeOf(n)), n);
|
|
27908
|
-
return "previewBackgroundColor" in t && delete t.previewBackgroundColor, t;
|
|
27909
|
-
}
|
|
27910
|
-
};
|
|
27911
|
-
dn.CURRENT_VERSION = "2.0.0", dn.workerManager = null, dn.workerInitPromise = null;
|
|
27912
|
-
let vn = dn;
|
|
27913
|
-
const ar = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
27914
|
-
__proto__: null,
|
|
27915
|
-
ExportManager: vn,
|
|
27916
|
-
default: vn
|
|
27917
|
-
}, Symbol.toStringTag, { value: "Module" }));
|
|
27918
24354
|
export {
|
|
27919
|
-
|
|
27920
|
-
ze as B,
|
|
27921
|
-
kt as C,
|
|
27922
|
-
We as D,
|
|
27923
|
-
yn as E,
|
|
27924
|
-
Wn as F,
|
|
27925
|
-
nr as G,
|
|
27926
|
-
La as H,
|
|
27927
|
-
ge as I,
|
|
27928
|
-
Ba as J,
|
|
27929
|
-
Dn as K,
|
|
27930
|
-
ce as L,
|
|
27931
|
-
Ta as M,
|
|
27932
|
-
pa as N,
|
|
27933
|
-
jn as O,
|
|
27934
|
-
he as P,
|
|
27935
|
-
Ua as Q,
|
|
27936
|
-
Ca as R,
|
|
27937
|
-
va as S,
|
|
27938
|
-
Z as T,
|
|
27939
|
-
Ja as U,
|
|
27940
|
-
sa as V,
|
|
27941
|
-
pn as W,
|
|
27942
|
-
ra as X,
|
|
27943
|
-
ht as Y,
|
|
27944
|
-
ar as Z,
|
|
27945
|
-
vn as a,
|
|
27946
|
-
Va as b,
|
|
27947
|
-
Te as c,
|
|
27948
|
-
B as d,
|
|
27949
|
-
Za as e,
|
|
27950
|
-
Ka as f,
|
|
27951
|
-
Nn as g,
|
|
27952
|
-
za as h,
|
|
27953
|
-
mt as i,
|
|
27954
|
-
Ga as j,
|
|
27955
|
-
Wa as k,
|
|
27956
|
-
fn as l,
|
|
27957
|
-
er as m,
|
|
27958
|
-
Ya as n,
|
|
27959
|
-
ee as o,
|
|
27960
|
-
Qa as p,
|
|
27961
|
-
In as q,
|
|
27962
|
-
xt as r,
|
|
27963
|
-
ja as s,
|
|
27964
|
-
Ha as t,
|
|
27965
|
-
St as u,
|
|
27966
|
-
qa as v,
|
|
27967
|
-
Ct as w,
|
|
27968
|
-
_e as x,
|
|
27969
|
-
Xa as y,
|
|
27970
|
-
oe as z
|
|
24355
|
+
n as default
|
|
27971
24356
|
};
|
|
27972
|
-
//# sourceMappingURL=
|
|
24357
|
+
//# sourceMappingURL=export-worker.bundle.string-DXciOLDt.js.map
|