@snowcone-app/canvas 0.17.1 → 0.17.3
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/{CanvasStateV1-C6i6vU6p.js → CanvasStateV1-BG2hEc3-.js} +3 -3
- package/dist/{CanvasStateV1-C6i6vU6p.js.map → CanvasStateV1-BG2hEc3-.js.map} +1 -1
- package/dist/EditorCanvasImpl-DQxqdgpq.js +70 -0
- package/dist/EditorCanvasImpl-DQxqdgpq.js.map +1 -0
- package/dist/EditorContext-CGkfmbgo.js +1178 -0
- package/dist/EditorContext-CGkfmbgo.js.map +1 -0
- package/dist/{ElementFactory-C05JJkRp.js → ElementFactory-CuHSAPfg.js} +1469 -710
- package/dist/ElementFactory-CuHSAPfg.js.map +1 -0
- package/dist/{HybridHistoryManager-Bht98XRv.js → FontAnalyzer-CLv7_msL.js} +2104 -2903
- package/dist/FontAnalyzer-CLv7_msL.js.map +1 -0
- package/dist/{ImportManager-kRYfIX-D.js → ImportManager-C_wBjWaV.js} +147 -147
- package/dist/{ImportManager-kRYfIX-D.js.map → ImportManager-C_wBjWaV.js.map} +1 -1
- package/dist/SnowconeCanvas-DBbmx9qW.js +1187 -0
- package/dist/SnowconeCanvas-DBbmx9qW.js.map +1 -0
- package/dist/{UnifiedFontService-BAtqqkU4.js → UnifiedFontService-Dsu5cwfT.js} +141 -141
- package/dist/UnifiedFontService-Dsu5cwfT.js.map +1 -0
- package/dist/advanced.mjs +10 -10
- package/dist/components/editor/RootInternals.d.ts +7 -0
- package/dist/components/embed/EmbedRoot.d.ts +23 -0
- package/dist/components/embed/SnowconeCanvas.d.ts +13 -0
- package/dist/components/embed/kernel.d.ts +114 -0
- package/dist/contexts/BoundLayerGuardContext.d.ts +36 -0
- package/dist/core/GroupElement.d.ts +0 -5
- package/dist/core/TextElement.d.ts +8 -3
- package/dist/core/paint-registry.d.ts +42 -0
- package/dist/core/rich-text-layout.d.ts +28 -0
- package/dist/{editorErrors-DbIEtCTt.js → editorErrors-BY4Pdg7a.js} +2 -2
- package/dist/{editorErrors-DbIEtCTt.js.map → editorErrors-BY4Pdg7a.js.map} +1 -1
- package/dist/{embed-B5kewSQY.js → embed--B8ot6Lj.js} +207 -199
- package/dist/embed--B8ot6Lj.js.map +1 -0
- package/dist/embed.mjs +21 -22
- package/dist/embed.mjs.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/internals.mjs +93 -93
- package/dist/rendering/element-painters.d.ts +16 -0
- package/dist/rendering/rich-text-renderer.d.ts +3 -28
- package/dist/{template-fields-GOM4MNfq.js → template-fields-Z9x13sjM.js} +32 -33
- package/dist/{template-fields-GOM4MNfq.js.map → template-fields-Z9x13sjM.js.map} +1 -1
- package/dist/testing.mjs +7 -7
- package/dist/transforms/ArchTransform.d.ts +0 -1
- package/dist/transforms/AscendTransform.d.ts +0 -1
- package/dist/transforms/CircleTransform.d.ts +0 -1
- package/dist/transforms/FlagTransform.d.ts +0 -1
- package/dist/transforms/LeanTransform.d.ts +0 -1
- package/dist/transforms/WaveTransform.d.ts +0 -1
- package/dist/{usePieceGuideBundle-CGERAQJl.js → usePieceGuideBundle-C1ipFnZd.js} +2 -2
- package/dist/{usePieceGuideBundle-CGERAQJl.js.map → usePieceGuideBundle-C1ipFnZd.js.map} +1 -1
- package/dist/{validation-DEd6EOCP.js → validation-C795COGQ.js} +4803 -4791
- package/dist/validation-C795COGQ.js.map +1 -0
- package/dist/vendor/ui/primitives/kbd.d.ts +1 -1
- package/dist/workers/export-worker.bundle.string.d.ts +1 -1
- package/package.json +1 -1
- package/dist/EditorCanvasImpl-C8SsT3C2.js +0 -68
- package/dist/EditorCanvasImpl-C8SsT3C2.js.map +0 -1
- package/dist/EditorContext-CyanYzo2.js +0 -1131
- package/dist/EditorContext-CyanYzo2.js.map +0 -1
- package/dist/ElementFactory-C05JJkRp.js.map +0 -1
- package/dist/HybridHistoryManager-Bht98XRv.js.map +0 -1
- package/dist/SnowconeCanvas-C3eZ9PP8.js +0 -1047
- package/dist/SnowconeCanvas-C3eZ9PP8.js.map +0 -1
- package/dist/UnifiedFontService-BAtqqkU4.js.map +0 -1
- package/dist/editorError-DMENTZ-3.js +0 -19
- package/dist/editorError-DMENTZ-3.js.map +0 -1
- package/dist/embed-B5kewSQY.js.map +0 -1
- package/dist/validation-DEd6EOCP.js.map +0 -1
|
@@ -1,5 +1,744 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { a1 as me, a2 as ye, a3 as $e, a4 as ae, a5 as Y, a6 as Fn, c as V, $ as xe, a0 as ve, z as Bn, R as we, a7 as Se, a8 as bn, I as vn, P as Ce, S as ke, G as Te, M as _e, W as Ee, H as Ae, D as Pe, O as Ie, J as De, K as Fe } from "./FontAnalyzer-CLv7_msL.js";
|
|
2
|
+
function ta(e, n, t) {
|
|
3
|
+
var l;
|
|
4
|
+
e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180);
|
|
5
|
+
const a = n, r = a.fontSize || 24, o = a.fontFamily || "Arial", s = a.bold || !1, c = a.italic || !1;
|
|
6
|
+
e.font = me(r, o, s, c);
|
|
7
|
+
const i = a.text || "";
|
|
8
|
+
if (n.transformType === "custom") {
|
|
9
|
+
const u = ((l = n.transformData) == null ? void 0 : l.width) || 200, p = ye(i, r, o, s, c), f = Math.min(p, u), m = r * 1.2;
|
|
10
|
+
e.rect(-f / 2, -m / 2, f, m);
|
|
11
|
+
} else {
|
|
12
|
+
const d = e.measureText(i).width;
|
|
13
|
+
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);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function Me(e, n) {
|
|
17
|
+
if (!n.transformData) return;
|
|
18
|
+
const { borderRadius: t = 0 } = n.transformData, a = n.transformData.width ?? 100, r = n.transformData.height ?? 100;
|
|
19
|
+
if (e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180), e.beginPath(), t > 0) {
|
|
20
|
+
const o = Math.min(a, r) / 2, s = Math.min(t, o), c = -a / 2, i = -r / 2;
|
|
21
|
+
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();
|
|
22
|
+
} else
|
|
23
|
+
e.rect(-a / 2, -r / 2, a, r);
|
|
24
|
+
}
|
|
25
|
+
function aa(e, n, t, a) {
|
|
26
|
+
e.beginPath(), e.arc(n, t, a, 0, Math.PI * 2), e.closePath();
|
|
27
|
+
}
|
|
28
|
+
function ra(e, n, t, a, r) {
|
|
29
|
+
e.beginPath(), e.rect(n, t, a, r), e.closePath();
|
|
30
|
+
}
|
|
31
|
+
function re(e, n) {
|
|
32
|
+
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);
|
|
33
|
+
}
|
|
34
|
+
function Oe(e, n) {
|
|
35
|
+
if (typeof OffscreenCanvas < "u")
|
|
36
|
+
return new OffscreenCanvas(e, n);
|
|
37
|
+
const t = document.createElement("canvas");
|
|
38
|
+
return t.width = e, t.height = n, t;
|
|
39
|
+
}
|
|
40
|
+
function se(e, n, t) {
|
|
41
|
+
var i;
|
|
42
|
+
if (!((i = n.stroke) != null && i.enabled)) return;
|
|
43
|
+
const a = n;
|
|
44
|
+
if (!(a.text || "")) return;
|
|
45
|
+
const o = (t == null ? void 0 : t.isKnockout) === !0, s = n.stroke.opacity ?? 1;
|
|
46
|
+
if (!o && s < 1)
|
|
47
|
+
try {
|
|
48
|
+
Re(e, n, a, t, s);
|
|
49
|
+
} catch {
|
|
50
|
+
tn(e, n, a, t, !1);
|
|
51
|
+
}
|
|
52
|
+
else
|
|
53
|
+
tn(e, n, a, t, o);
|
|
54
|
+
}
|
|
55
|
+
function Re(e, n, t, a, r) {
|
|
56
|
+
var C, _;
|
|
57
|
+
const o = t.text || "", s = t.fontSize || 24, c = n.stroke.width, i = n.stroke.feather || 0, l = n.transformType === "custom" && ((C = n.transformData) == null ? void 0 : C.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(), m = Math.max(Math.abs(f.a), Math.abs(f.d), 1), b = Math.ceil(u * m / 2) * 2, h = Math.ceil(p * m / 2) * 2;
|
|
58
|
+
if (b <= 0 || h <= 0) {
|
|
59
|
+
tn(e, n, t, a, !1);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const S = Oe(b, h), $ = S.getContext("2d");
|
|
63
|
+
if (!$) {
|
|
64
|
+
tn(e, n, t, a, !1);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const v = n.x || 0, g = n.y || 0, y = f.a * v + f.c * g + f.e, k = f.b * v + f.d * g + f.f;
|
|
68
|
+
$.setTransform(
|
|
69
|
+
f.a,
|
|
70
|
+
f.b,
|
|
71
|
+
f.c,
|
|
72
|
+
f.d,
|
|
73
|
+
b / 2 - y + f.e,
|
|
74
|
+
h / 2 - k + f.f
|
|
75
|
+
);
|
|
76
|
+
const T = n.stroke.opacity;
|
|
77
|
+
n.stroke.opacity = 1, tn($, n, t, a, !1), n.stroke.opacity = T, e.save(), e.resetTransform(), e.globalAlpha = r, e.drawImage(
|
|
78
|
+
S,
|
|
79
|
+
Math.round(y - b / 2),
|
|
80
|
+
Math.round(k - h / 2)
|
|
81
|
+
), e.restore();
|
|
82
|
+
}
|
|
83
|
+
function tn(e, n, t, a, r) {
|
|
84
|
+
var f;
|
|
85
|
+
const o = t.text || "";
|
|
86
|
+
e.save(), a != null && a.positionApplied || (e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180));
|
|
87
|
+
const s = t.fontSize || 24, c = t.fontFamily || "Arial", i = t.bold || !1, l = t.italic || !1, d = t.textAlign || "center";
|
|
88
|
+
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)`);
|
|
89
|
+
const u = $e(s, c, i, l);
|
|
90
|
+
if (n.transformType === "custom" && ((f = n.transformData) == null ? void 0 : f.width)) {
|
|
91
|
+
const m = n.transformData, b = (m == null ? void 0 : m.width) ?? 200, h = b - Y * 2, { lines: S, height: $ } = ae(
|
|
92
|
+
o,
|
|
93
|
+
h,
|
|
94
|
+
s,
|
|
95
|
+
c,
|
|
96
|
+
i,
|
|
97
|
+
l,
|
|
98
|
+
void 0,
|
|
99
|
+
// No locked line count for stroke
|
|
100
|
+
!0
|
|
101
|
+
// strict: wrap exactly at maxWidth
|
|
102
|
+
), v = -b / 2, g = -$ / 2, y = s * Fn;
|
|
103
|
+
S.forEach((k, T) => {
|
|
104
|
+
const C = T === 0, _ = T === S.length - 1;
|
|
105
|
+
let w = k;
|
|
106
|
+
if (!C) {
|
|
107
|
+
const P = k.match(/^ +/), A = P ? P[0].length : 0;
|
|
108
|
+
A > 0 && (w = w.substring(A));
|
|
109
|
+
}
|
|
110
|
+
if (!_) {
|
|
111
|
+
const P = w.match(/ +$/), A = P ? P[0].length : 0;
|
|
112
|
+
A > 0 && (w = w.substring(0, w.length - A));
|
|
113
|
+
}
|
|
114
|
+
let E = v + Y;
|
|
115
|
+
d === "center" ? E = v + b / 2 : d === "right" && (E = v + b - Y);
|
|
116
|
+
const x = g + u.ascent + T * y;
|
|
117
|
+
e.strokeText(w, E, x);
|
|
118
|
+
});
|
|
119
|
+
} else {
|
|
120
|
+
const h = -u.height / 2 + u.ascent;
|
|
121
|
+
e.strokeText(o, 0, h);
|
|
122
|
+
}
|
|
123
|
+
e.restore();
|
|
124
|
+
}
|
|
125
|
+
function Be(e, n, t) {
|
|
126
|
+
var r;
|
|
127
|
+
if (!((r = n.stroke) != null && r.enabled) || !n.transformData) return;
|
|
128
|
+
const a = (t == null ? void 0 : t.isKnockout) === !0;
|
|
129
|
+
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)) : re(e, n.stroke), !a && n.stroke.feather && n.stroke.feather > 0 && "filter" in e && (e.filter = `blur(${n.stroke.feather}px)`), Me(e, n), e.stroke(), e.restore();
|
|
130
|
+
}
|
|
131
|
+
function sa(e, n, t) {
|
|
132
|
+
n.enabled && (e.save(), re(e, n), n.feather && n.feather > 0 && "filter" in e && (e.filter = `blur(${n.feather}px)`), e.beginPath(), t(), e.stroke(), e.restore());
|
|
133
|
+
}
|
|
134
|
+
const Ln = V("GlyphRenderer");
|
|
135
|
+
function Le(e, n, t, a, r, o, s, c = {}) {
|
|
136
|
+
try {
|
|
137
|
+
const i = [];
|
|
138
|
+
Object.entries(s).forEach(([h, S]) => {
|
|
139
|
+
S && i.push(h);
|
|
140
|
+
});
|
|
141
|
+
const l = [];
|
|
142
|
+
n.GSUB && n.GSUB.featureList && n.GSUB.featureList.forEach((h) => {
|
|
143
|
+
l.push(h.tag);
|
|
144
|
+
});
|
|
145
|
+
const d = {};
|
|
146
|
+
d.ccmp = !0, d.locl = !0, d.kern = !0, i.forEach((h) => {
|
|
147
|
+
d[h] = !0;
|
|
148
|
+
}), d.calt && (d.liga = !0, d.init = !0, d.fina = !0);
|
|
149
|
+
const u = n.layout(t, d, "latn"), p = o / n.unitsPerEm;
|
|
150
|
+
let f = 0;
|
|
151
|
+
u.glyphs.forEach((h) => {
|
|
152
|
+
f += h.advanceWidth * p;
|
|
153
|
+
});
|
|
154
|
+
let m = a;
|
|
155
|
+
c.align === "center" ? m = a - f / 2 : c.align === "right" && (m = a - f), e.save(), e.fillStyle = c.color || "#000000";
|
|
156
|
+
let b = m;
|
|
157
|
+
u.glyphs.forEach((h, S) => {
|
|
158
|
+
const $ = u.positions[S];
|
|
159
|
+
let v = null;
|
|
160
|
+
try {
|
|
161
|
+
if (h.path && typeof h.path.toPath == "function")
|
|
162
|
+
v = h.path.toPath();
|
|
163
|
+
else if (h.path && typeof h.path.toSVG == "function") {
|
|
164
|
+
const g = h.path.toSVG();
|
|
165
|
+
if (g && /^[MmLlHhVvCcSsQqTtAaZz]/.test(g))
|
|
166
|
+
v = g;
|
|
167
|
+
else {
|
|
168
|
+
const y = g == null ? void 0 : g.match(/\bd=["']([^"']+)["']/);
|
|
169
|
+
v = y ? y[1] : null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
} catch (g) {
|
|
173
|
+
Ln.warn("Error getting path for glyph:", h.name, g);
|
|
174
|
+
}
|
|
175
|
+
if (v) {
|
|
176
|
+
const g = new Path2D(v);
|
|
177
|
+
e.save(), e.translate(b + $.xOffset * p, r + $.yOffset * p), e.scale(p, -p), e.fill(g), e.restore();
|
|
178
|
+
}
|
|
179
|
+
b += h.advanceWidth * p;
|
|
180
|
+
}), e.restore();
|
|
181
|
+
} catch (i) {
|
|
182
|
+
Ln.error("Error rendering with fontkit:", i), e.fillStyle = c.color || "#000000", e.textAlign = c.align || "left", e.fillText(t, a, r);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function Ne(e, n, t, a, r, o, s, c = {}) {
|
|
186
|
+
const l = ((h) => {
|
|
187
|
+
for (const S of h) {
|
|
188
|
+
const $ = S.codePointAt(0);
|
|
189
|
+
if ($ && $ >= 983040 && $ <= 1048573) return !0;
|
|
190
|
+
}
|
|
191
|
+
return !1;
|
|
192
|
+
})(t);
|
|
193
|
+
if ((!s || s.length === 0) && !l) {
|
|
194
|
+
e.fillStyle = c.color || "#000000", e.textAlign = c.align || "left", e.fillText(t, a, r);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
const d = /* @__PURE__ */ new Map();
|
|
198
|
+
s && s.forEach((h) => {
|
|
199
|
+
d.set(h.charIndex, h.glyphIndex);
|
|
200
|
+
});
|
|
201
|
+
const u = o / n.unitsPerEm, p = Array.from(t);
|
|
202
|
+
let f = 0;
|
|
203
|
+
p.forEach((h, S) => {
|
|
204
|
+
const $ = h.codePointAt(0) || 0;
|
|
205
|
+
let v;
|
|
206
|
+
if ($ >= 983040 && $ <= 1048573)
|
|
207
|
+
v = $ - 983040;
|
|
208
|
+
else if (v = d.get(S), v === void 0) {
|
|
209
|
+
const y = n.glyphForCodePoint($);
|
|
210
|
+
v = y ? y.id : 0;
|
|
211
|
+
}
|
|
212
|
+
const g = n.getGlyph(v);
|
|
213
|
+
g && (f += g.advanceWidth * u);
|
|
214
|
+
});
|
|
215
|
+
let m = a;
|
|
216
|
+
c.align === "center" ? m = a - f / 2 : c.align === "right" && (m = a - f), e.save(), e.fillStyle = c.color || "#000000";
|
|
217
|
+
let b = m;
|
|
218
|
+
p.forEach((h, S) => {
|
|
219
|
+
const $ = h.codePointAt(0) || 0;
|
|
220
|
+
let v;
|
|
221
|
+
if ($ >= 983040 && $ <= 1048573)
|
|
222
|
+
v = $ - 983040;
|
|
223
|
+
else if (v = d.get(S), v === void 0) {
|
|
224
|
+
const y = n.glyphForCodePoint($);
|
|
225
|
+
v = y ? y.id : 0;
|
|
226
|
+
}
|
|
227
|
+
const g = n.getGlyph(v);
|
|
228
|
+
if (g) {
|
|
229
|
+
const y = g.path.toSVG();
|
|
230
|
+
if (y) {
|
|
231
|
+
const k = new Path2D(y);
|
|
232
|
+
e.save(), e.translate(b, r), e.scale(u, -u), e.fill(k), e.restore();
|
|
233
|
+
}
|
|
234
|
+
b += g.advanceWidth * u;
|
|
235
|
+
}
|
|
236
|
+
}), e.restore();
|
|
237
|
+
}
|
|
238
|
+
function Ue(e, n, t, a, r) {
|
|
239
|
+
e.fillStyle = t.color;
|
|
240
|
+
const o = t.textAlign || "center", s = xe(n);
|
|
241
|
+
let c, i;
|
|
242
|
+
a !== void 0 && a > 0 && !r ? (c = [], i = [], s.forEach((m) => {
|
|
243
|
+
const b = ve(m, a, t);
|
|
244
|
+
b.forEach((h, S) => {
|
|
245
|
+
c.push(h), i.push({
|
|
246
|
+
isParagraphStart: S === 0,
|
|
247
|
+
isParagraphEnd: S === b.length - 1
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
})) : (c = s, i = s.map(() => ({
|
|
251
|
+
isParagraphStart: !0,
|
|
252
|
+
isParagraphEnd: !0
|
|
253
|
+
})));
|
|
254
|
+
const l = [];
|
|
255
|
+
c.forEach((m, b) => {
|
|
256
|
+
const h = [];
|
|
257
|
+
let S = 0, $ = 0;
|
|
258
|
+
const v = i[b].isParagraphStart, g = i[b].isParagraphEnd;
|
|
259
|
+
m.forEach((x) => {
|
|
260
|
+
const P = x.style.fontSize !== void 0 ? x.style.fontSize : t.fontSize, A = x.style.fontFamily !== void 0 ? x.style.fontFamily : t.fontFamily, F = x.style.bold !== void 0 ? x.style.bold : t.bold || !1, D = x.style.italic !== void 0 ? x.style.italic : t.italic || !1;
|
|
261
|
+
e.font = R(P, A, F, D);
|
|
262
|
+
const I = e.measureText(x.text).width;
|
|
263
|
+
h.push(I);
|
|
264
|
+
const M = sn(P, A, F, D);
|
|
265
|
+
S = Math.max(S, M.height), $ = Math.max($, M.ascent);
|
|
266
|
+
});
|
|
267
|
+
const y = m.map((x) => x.text).join(""), k = y.match(/^ +/), T = y.match(/ +$/), C = k ? k[0].length : 0, _ = T ? T[0].length : 0;
|
|
268
|
+
let w = 0, E = 0;
|
|
269
|
+
m.forEach((x) => {
|
|
270
|
+
const P = x.style.fontSize !== void 0 ? x.style.fontSize : t.fontSize, A = x.style.fontFamily !== void 0 ? x.style.fontFamily : t.fontFamily, F = x.style.bold !== void 0 ? x.style.bold : t.bold || !1, D = x.style.italic !== void 0 ? x.style.italic : t.italic || !1;
|
|
271
|
+
let I = x.text;
|
|
272
|
+
const M = E, Q = E + x.text.length;
|
|
273
|
+
if (!v && C > 0 && M < C) {
|
|
274
|
+
const B = Math.min(C - M, x.text.length);
|
|
275
|
+
I = I.substring(B);
|
|
276
|
+
}
|
|
277
|
+
if (!g && _ > 0) {
|
|
278
|
+
const B = y.length - _;
|
|
279
|
+
if (Q > B) {
|
|
280
|
+
const G = !v && C > 0 && M < C ? Math.min(C - M, x.text.length) : 0, yn = Math.max(0, B - M - G);
|
|
281
|
+
I = I.substring(0, yn);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
E += x.text.length, I.length > 0 && (e.save(), e.font = R(P, A, F, D), w += e.measureText(I).width, e.restore());
|
|
285
|
+
}), l.push({
|
|
286
|
+
spans: m,
|
|
287
|
+
width: w,
|
|
288
|
+
// Use adjusted width for alignment (may be 0 for empty lines)
|
|
289
|
+
height: S,
|
|
290
|
+
ascent: $,
|
|
291
|
+
spanWidths: h,
|
|
292
|
+
isParagraphStart: v,
|
|
293
|
+
// Store metadata with line
|
|
294
|
+
isParagraphEnd: g
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
const d = sn(t.fontSize, t.fontFamily, t.bold, t.italic), u = t.fontSize * Fn;
|
|
298
|
+
let p;
|
|
299
|
+
l.length === 0 ? p = 0 : l.length === 1 ? p = d.height : p = (l.length - 1) * u + d.height;
|
|
300
|
+
const f = -p / 2;
|
|
301
|
+
l.forEach((m, b) => {
|
|
302
|
+
const { spans: h, width: S, isParagraphStart: $, isParagraphEnd: v } = m;
|
|
303
|
+
let g;
|
|
304
|
+
o === "center" ? g = -S / 2 : o === "right" ? g = a !== void 0 ? a / 2 - S : -S : g = a !== void 0 ? -a / 2 : 0;
|
|
305
|
+
const y = f + d.ascent + b * u, k = h.map((x) => x.text).join(""), T = k.match(/^ +/), C = k.match(/ +$/), _ = T ? T[0].length : 0, w = C ? C[0].length : 0;
|
|
306
|
+
let E = 0;
|
|
307
|
+
h.forEach((x) => {
|
|
308
|
+
const P = x.style.fontSize !== void 0 ? x.style.fontSize : t.fontSize, A = x.style.fontFamily !== void 0 ? x.style.fontFamily : t.fontFamily, F = x.style.color !== void 0 ? x.style.color : t.color, D = x.style.bold !== void 0 ? x.style.bold : t.bold || !1, I = x.style.italic !== void 0 ? x.style.italic : t.italic || !1, M = x.style.underline !== void 0 ? x.style.underline : t.underline || !1, Q = x.style.strikethrough !== void 0 ? x.style.strikethrough : t.strikethrough || !1;
|
|
309
|
+
let B = x.text, G = E, yn = E + x.text.length;
|
|
310
|
+
if (!$ && _ > 0 && G < _) {
|
|
311
|
+
const N = Math.min(_ - G, x.text.length);
|
|
312
|
+
B = B.substring(N);
|
|
313
|
+
}
|
|
314
|
+
if (!v && w > 0) {
|
|
315
|
+
const N = k.length - w;
|
|
316
|
+
if (yn > N) {
|
|
317
|
+
const H = !$ && _ > 0 && G < _ ? Math.min(_ - G, x.text.length) : 0, ge = Math.max(0, N - G - H);
|
|
318
|
+
B = B.substring(0, ge);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (E += x.text.length, B.length > 0) {
|
|
322
|
+
e.font = R(P, A, D, I), e.fillStyle = F, e.textBaseline = "alphabetic", e.textAlign = "left", e.fillText(B, g, y);
|
|
323
|
+
const N = e.measureText(B).width;
|
|
324
|
+
if (M) {
|
|
325
|
+
const H = y + P * 0.1;
|
|
326
|
+
e.beginPath(), e.moveTo(g, H), e.lineTo(g + N, H), e.lineWidth = Math.max(1, P * 0.05), e.strokeStyle = F, e.stroke();
|
|
327
|
+
}
|
|
328
|
+
if (Q) {
|
|
329
|
+
const H = y - P * 0.25;
|
|
330
|
+
e.beginPath(), e.moveTo(g, H), e.lineTo(g + N, H), e.lineWidth = Math.max(1, P * 0.05), e.strokeStyle = F, e.stroke();
|
|
331
|
+
}
|
|
332
|
+
g += N;
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
const wn = V("canvas-renderer");
|
|
338
|
+
let ln = null;
|
|
339
|
+
function Mn() {
|
|
340
|
+
if (!ln)
|
|
341
|
+
if (typeof OffscreenCanvas < "u")
|
|
342
|
+
ln = new OffscreenCanvas(1, 1).getContext("2d");
|
|
343
|
+
else if (typeof document < "u")
|
|
344
|
+
ln = document.createElement("canvas").getContext("2d");
|
|
345
|
+
else
|
|
346
|
+
throw new Error("No canvas context available");
|
|
347
|
+
return ln;
|
|
348
|
+
}
|
|
349
|
+
function R(e, n, t = !1, a = !1) {
|
|
350
|
+
const r = [];
|
|
351
|
+
return a && r.push("italic"), t && r.push("bold"), r.push(`${e}px`), r.push(n), r.join(" ");
|
|
352
|
+
}
|
|
353
|
+
function Nn(e, n, t, a = !1, r = !1) {
|
|
354
|
+
const o = Mn();
|
|
355
|
+
return o.font = R(n, t, a, r), o.measureText(e).width;
|
|
356
|
+
}
|
|
357
|
+
function sn(e, n, t = !1, a = !1) {
|
|
358
|
+
const r = Mn();
|
|
359
|
+
r.font = R(e, n, t, a);
|
|
360
|
+
const s = r.measureText("ÁÉÍgjpqy"), c = s.actualBoundingBoxAscent || e * 0.8, i = s.actualBoundingBoxDescent || e * 0.2, l = c + i;
|
|
361
|
+
return { ascent: c, descent: i, height: l };
|
|
362
|
+
}
|
|
363
|
+
function ia(e, n) {
|
|
364
|
+
const t = e.map((r, o) => ({
|
|
365
|
+
isParagraphStart: !n && o === 0,
|
|
366
|
+
isParagraphEnd: !n && o === e.length - 1
|
|
367
|
+
}));
|
|
368
|
+
return e.map((r, o) => {
|
|
369
|
+
if (r.trim().length === 0)
|
|
370
|
+
return "";
|
|
371
|
+
const s = t[o].isParagraphStart, c = t[o].isParagraphEnd;
|
|
372
|
+
let i = r;
|
|
373
|
+
return s || (i = i.replace(/^ +/, "")), c || (i = i.replace(/ +$/, "")), i;
|
|
374
|
+
}).filter((r) => r.length > 0);
|
|
375
|
+
}
|
|
376
|
+
function ze(e, n) {
|
|
377
|
+
const t = n.fontSize, a = n.fontFamily, r = n.bold || !1, o = n.italic || !1, s = n.textAlign || "center", c = n.text;
|
|
378
|
+
e.font = R(t, a, r, o), e.textAlign = s, e.textBaseline = "alphabetic", e.fillStyle = n.color;
|
|
379
|
+
const i = sn(t, a, r, o), u = -i.height / 2 + i.ascent;
|
|
380
|
+
e.fillText(c, 0, u);
|
|
381
|
+
}
|
|
382
|
+
function We(e, n, t, a, r = !1, o = !1, s) {
|
|
383
|
+
const c = Mn();
|
|
384
|
+
if (c.font = R(t, a, r, o), e.trim().length === 0)
|
|
385
|
+
return [e];
|
|
386
|
+
if (e.includes(`
|
|
387
|
+
`)) {
|
|
388
|
+
const C = e.split(`
|
|
389
|
+
`), _ = [];
|
|
390
|
+
for (let w = 0; w < C.length; w++) {
|
|
391
|
+
const E = C[w], x = We(E, n, t, a, r, o);
|
|
392
|
+
_.push(...x);
|
|
393
|
+
}
|
|
394
|
+
return _;
|
|
395
|
+
}
|
|
396
|
+
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(" ");
|
|
397
|
+
if (s !== void 0 && s > 0) {
|
|
398
|
+
if (s === 1)
|
|
399
|
+
return [d + f.join(" ") + u];
|
|
400
|
+
const C = [], _ = Math.ceil(f.length / s);
|
|
401
|
+
for (let w = 0; w < f.length; w += _) {
|
|
402
|
+
const x = f.slice(w, w + _).join(" ");
|
|
403
|
+
w === 0 && w + _ >= f.length ? C.push(d + x + u) : w === 0 ? C.push(d + x) : w + _ >= f.length ? C.push(x + u) : C.push(x);
|
|
404
|
+
}
|
|
405
|
+
return C;
|
|
406
|
+
}
|
|
407
|
+
const m = f.join(" "), b = d + m + u, h = c.measureText(b).width, S = n < 200, v = Math.max(20, n * (S ? 0.08 : 0.05));
|
|
408
|
+
if (h <= n + v)
|
|
409
|
+
return [b];
|
|
410
|
+
const g = [];
|
|
411
|
+
let y = f[0];
|
|
412
|
+
const T = Math.max(15, n * (S ? 0.05 : 0.03));
|
|
413
|
+
for (let C = 1; C < f.length; C++) {
|
|
414
|
+
const _ = f[C], w = y + " " + _;
|
|
415
|
+
c.measureText(w).width > n + T ? (g.push(y), y = _) : y = w;
|
|
416
|
+
}
|
|
417
|
+
return g.push(y), g.length > 0 && (g[0] = d + g[0], g[g.length - 1] = g[g.length - 1] + u), g;
|
|
418
|
+
}
|
|
419
|
+
function oa(e, n, t, a, r, o, s = "left", c = 0, i = 0, l = 1.2, d = !1, u = !1, p = !1, f = !1, m, b) {
|
|
420
|
+
e.font = R(r, o, d, u), e.textBaseline = "alphabetic", e.textAlign = s;
|
|
421
|
+
const h = (w) => {
|
|
422
|
+
for (const E of w) {
|
|
423
|
+
const x = E.codePointAt(0);
|
|
424
|
+
if (x && x >= 983040 && x <= 1048573)
|
|
425
|
+
return !0;
|
|
426
|
+
}
|
|
427
|
+
return !1;
|
|
428
|
+
}, S = m && Object.values(m).some((w) => w), $ = b && b.length > 0, v = n.join(" "), g = h(v), y = S || $ || g, k = y ? Bn.getFontSync(o, d ? 700 : 400) : null;
|
|
429
|
+
y && !k && (wn.warn(
|
|
430
|
+
`[renderMultilineText] Font ${o} not loaded for fontkit rendering. Text may not render correctly. Has PUA: ${g}, Text: "${v}"`
|
|
431
|
+
), Bn.loadFont(o, d ? 700 : 400).catch((w) => {
|
|
432
|
+
wn.error("[renderMultilineText] Error loading font:", w);
|
|
433
|
+
}));
|
|
434
|
+
const T = sn(r, o, d, u), C = r * l;
|
|
435
|
+
let _ = 0;
|
|
436
|
+
n.forEach((w, E) => {
|
|
437
|
+
let x = t + i;
|
|
438
|
+
s === "center" ? x = t + c / 2 : s === "right" && (x = t + c - i);
|
|
439
|
+
const P = a + T.ascent + E * C, A = Array.from(w).length, F = $ ? b.filter((D) => {
|
|
440
|
+
const I = D.charIndex - _;
|
|
441
|
+
return I >= 0 && I < A;
|
|
442
|
+
}).map((D) => ({
|
|
443
|
+
...D,
|
|
444
|
+
charIndex: D.charIndex - _
|
|
445
|
+
// Adjust to line-relative index
|
|
446
|
+
})) : [];
|
|
447
|
+
if (k && (S || F.length > 0 || g) ? F.length > 0 || h(w) ? Ne(e, k, w, x, P, r, F, {
|
|
448
|
+
color: e.fillStyle,
|
|
449
|
+
align: s === "start" || s === "end" ? "left" : s
|
|
450
|
+
}) : m && Le(e, k, w, x, P, r, m, {
|
|
451
|
+
color: e.fillStyle,
|
|
452
|
+
align: s === "start" || s === "end" ? "left" : s
|
|
453
|
+
}) : e.fillText(w, x, P), _ += A + 1, p) {
|
|
454
|
+
const D = Nn(w, r, o, d, u);
|
|
455
|
+
let I = x;
|
|
456
|
+
s === "center" ? I = x - D / 2 : s === "right" && (I = x - D);
|
|
457
|
+
const M = P + r * 0.1;
|
|
458
|
+
e.beginPath(), e.moveTo(I, M), e.lineTo(I + D, M), e.lineWidth = Math.max(1, r * 0.05), e.strokeStyle = e.fillStyle, e.stroke();
|
|
459
|
+
}
|
|
460
|
+
if (f) {
|
|
461
|
+
const D = Nn(w, r, o, d, u);
|
|
462
|
+
let I = x;
|
|
463
|
+
s === "center" ? I = x - D / 2 : s === "right" && (I = x - D);
|
|
464
|
+
const M = P - r * 0.25;
|
|
465
|
+
e.beginPath(), e.moveTo(I, M), e.lineTo(I + D, M), e.lineWidth = Math.max(1, r * 0.05), e.strokeStyle = e.fillStyle, e.stroke();
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
function Un(e, n) {
|
|
470
|
+
Ge(e, n);
|
|
471
|
+
}
|
|
472
|
+
function Ge(e, n) {
|
|
473
|
+
var r;
|
|
474
|
+
(r = n.stroke) != null && r.enabled && se(e, n), e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180);
|
|
475
|
+
const t = n.transformData, a = ((t == null ? void 0 : t.width) ?? 100) - Y * 2;
|
|
476
|
+
if (n.richText) {
|
|
477
|
+
const o = we.fromJSON(n.richText);
|
|
478
|
+
e.save(), e.translate(0, 0);
|
|
479
|
+
const s = n._lockedLineCount;
|
|
480
|
+
Ue(
|
|
481
|
+
e,
|
|
482
|
+
o,
|
|
483
|
+
{
|
|
484
|
+
fontSize: n.fontSize,
|
|
485
|
+
fontFamily: n.fontFamily,
|
|
486
|
+
color: n.color,
|
|
487
|
+
bold: n.bold,
|
|
488
|
+
italic: n.italic,
|
|
489
|
+
underline: n.underline,
|
|
490
|
+
strikethrough: n.strikethrough,
|
|
491
|
+
textAlign: n.textAlign
|
|
492
|
+
},
|
|
493
|
+
a,
|
|
494
|
+
s
|
|
495
|
+
), e.restore();
|
|
496
|
+
} else if (n.text) {
|
|
497
|
+
e.fillStyle = n.color;
|
|
498
|
+
const o = n._lockedLineCount, { lines: s, height: c } = ae(
|
|
499
|
+
n.text,
|
|
500
|
+
a,
|
|
501
|
+
n.fontSize,
|
|
502
|
+
n.fontFamily,
|
|
503
|
+
n.bold,
|
|
504
|
+
n.italic,
|
|
505
|
+
o,
|
|
506
|
+
!0
|
|
507
|
+
// strict: true
|
|
508
|
+
), i = sn(
|
|
509
|
+
n.fontSize,
|
|
510
|
+
n.fontFamily,
|
|
511
|
+
n.bold,
|
|
512
|
+
n.italic
|
|
513
|
+
), l = -((t == null ? void 0 : t.width) ?? 100) / 2, d = -c / 2, u = n.fontSize * Fn;
|
|
514
|
+
e.font = `${n.italic ? "italic " : ""}${n.bold ? "bold " : ""}${n.fontSize}px ${n.fontFamily}`, e.textBaseline = "alphabetic", e.textAlign = n.textAlign, s.forEach((p, f) => {
|
|
515
|
+
const m = f === 0, b = f === s.length - 1;
|
|
516
|
+
let h = p;
|
|
517
|
+
if (!m) {
|
|
518
|
+
const v = p.match(/^ +/), g = v ? v[0].length : 0;
|
|
519
|
+
g > 0 && (h = h.substring(g));
|
|
520
|
+
}
|
|
521
|
+
if (!b) {
|
|
522
|
+
const v = h.match(/ +$/), g = v ? v[0].length : 0;
|
|
523
|
+
g > 0 && (h = h.substring(0, h.length - g));
|
|
524
|
+
}
|
|
525
|
+
let S = l + Y;
|
|
526
|
+
n.textAlign === "center" ? S = l + ((t == null ? void 0 : t.width) ?? 100) / 2 : n.textAlign === "right" && (S = l + ((t == null ? void 0 : t.width) ?? 100) - Y);
|
|
527
|
+
const $ = d + i.ascent + f * u;
|
|
528
|
+
if (e.fillText(h, S, $), h.length > 0) {
|
|
529
|
+
const v = e.measureText(h).width;
|
|
530
|
+
let g = S;
|
|
531
|
+
if (n.textAlign === "center" ? g -= v / 2 : n.textAlign === "right" && (g -= v), n.underline) {
|
|
532
|
+
const y = $ + n.fontSize * 0.1;
|
|
533
|
+
e.fillRect(g, y, v, Math.max(1, n.fontSize * 0.05));
|
|
534
|
+
}
|
|
535
|
+
if (n.strikethrough) {
|
|
536
|
+
const y = $ - i.ascent * 0.4;
|
|
537
|
+
e.fillRect(g, y, v, Math.max(1, n.fontSize * 0.05));
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
e.restore();
|
|
543
|
+
}
|
|
544
|
+
function ca(e, n) {
|
|
545
|
+
var s;
|
|
546
|
+
const t = n.opacity ?? 1, a = !!((s = n.stroke) != null && s.enabled), r = n.type === "custom";
|
|
547
|
+
if (t < 1 && a && r) {
|
|
548
|
+
He(e, n, t);
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
const o = e.globalAlpha;
|
|
552
|
+
t !== 1 && (e.globalAlpha = t), Sn(e, n), e.globalAlpha = o;
|
|
553
|
+
}
|
|
554
|
+
function He(e, n, t) {
|
|
555
|
+
var h;
|
|
556
|
+
const a = n.transformData, r = n.fontSize || 24, o = ((h = n.stroke) == null ? void 0 : h.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);
|
|
557
|
+
let p;
|
|
558
|
+
typeof OffscreenCanvas < "u" ? p = new OffscreenCanvas(d, u) : (p = document.createElement("canvas"), p.width = d, p.height = u);
|
|
559
|
+
const f = p.getContext("2d");
|
|
560
|
+
if (!f) {
|
|
561
|
+
const S = e.globalAlpha;
|
|
562
|
+
e.globalAlpha = t, Sn(e, n), e.globalAlpha = S;
|
|
563
|
+
return;
|
|
564
|
+
}
|
|
565
|
+
const m = i.a * n.x + i.e, b = i.d * n.y + i.f;
|
|
566
|
+
f.setTransform(
|
|
567
|
+
i.a,
|
|
568
|
+
i.b,
|
|
569
|
+
i.c,
|
|
570
|
+
i.d,
|
|
571
|
+
i.e - m + d / 2,
|
|
572
|
+
i.f - b + u / 2
|
|
573
|
+
), Sn(f, n), e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.globalAlpha = t, e.drawImage(p, m - d / 2, b - u / 2), e.restore();
|
|
574
|
+
}
|
|
575
|
+
function Sn(e, n) {
|
|
576
|
+
switch (n.type) {
|
|
577
|
+
case "custom":
|
|
578
|
+
Un(e, n);
|
|
579
|
+
break;
|
|
580
|
+
case "circle":
|
|
581
|
+
je(e, n);
|
|
582
|
+
break;
|
|
583
|
+
case "wave":
|
|
584
|
+
Xe(e, n);
|
|
585
|
+
break;
|
|
586
|
+
case "arch":
|
|
587
|
+
Ke(e, n);
|
|
588
|
+
break;
|
|
589
|
+
case "ascend":
|
|
590
|
+
Ze(e, n);
|
|
591
|
+
break;
|
|
592
|
+
case "lean":
|
|
593
|
+
nt(e, n);
|
|
594
|
+
break;
|
|
595
|
+
case "flag":
|
|
596
|
+
tt(e, n);
|
|
597
|
+
break;
|
|
598
|
+
default:
|
|
599
|
+
wn.warn(`[canvas-renderer] Unsupported transform type: ${n.type}`), Un(e, n);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
function Ve(e, n) {
|
|
603
|
+
if (typeof OffscreenCanvas < "u")
|
|
604
|
+
return new OffscreenCanvas(e, n);
|
|
605
|
+
const t = document.createElement("canvas");
|
|
606
|
+
return t.width = e, t.height = n, t;
|
|
607
|
+
}
|
|
608
|
+
function J(e, n, t) {
|
|
609
|
+
if (t != null && t.enabled)
|
|
610
|
+
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) {
|
|
611
|
+
const a = e.globalAlpha;
|
|
612
|
+
e.globalAlpha = t.opacity, e.strokeText(n, 0, 0), e.globalAlpha = a;
|
|
613
|
+
} else
|
|
614
|
+
e.strokeText(n, 0, 0);
|
|
615
|
+
}
|
|
616
|
+
function Z(e, n, t) {
|
|
617
|
+
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;
|
|
618
|
+
if (!(s || c)) {
|
|
619
|
+
t(e, n);
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
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), m = Math.max(f, p), b = (a.feather || 0) * 2, h = d * 4 + b + l + 40, S = m + h, $ = u.archHeight ? Math.abs(u.archHeight) * l * 2 : 0, v = u.radius ? u.radius : 0, g = l * 3 + h + $ + v, y = e.getTransform(), k = Math.max(Math.abs(y.a), Math.abs(y.d), 1), T = Math.ceil(S * k / 2) * 2, C = Math.ceil(g * k / 2) * 2;
|
|
623
|
+
if (T <= 0 || C <= 0) {
|
|
624
|
+
t(e, n);
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
const _ = Ve(T, C), w = _.getContext("2d");
|
|
628
|
+
if (!w) {
|
|
629
|
+
t(e, n);
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
const E = n.x || 0, x = n.y || 0, P = y.a * E + y.c * x + y.e, A = y.b * E + y.d * x + y.f, F = Math.round(P - T / 2), D = Math.round(A - C / 2);
|
|
633
|
+
if (w.setTransform(
|
|
634
|
+
y.a,
|
|
635
|
+
y.b,
|
|
636
|
+
y.c,
|
|
637
|
+
y.d,
|
|
638
|
+
T / 2 - P + y.e,
|
|
639
|
+
C / 2 - A + y.f
|
|
640
|
+
), c) {
|
|
641
|
+
w.globalAlpha = 1;
|
|
642
|
+
const Q = a.opacity;
|
|
643
|
+
s && (a.opacity = 1), t(w, n), s && (a.opacity = Q), e.save(), e.resetTransform(), e.globalAlpha = o, e.drawImage(_, F, D), e.restore();
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
const I = a.opacity;
|
|
647
|
+
a.opacity = 1, t(w, n), a.opacity = I;
|
|
648
|
+
const M = a.enabled;
|
|
649
|
+
a.enabled = !1, t(e, n), a.enabled = M, e.save(), e.resetTransform(), e.globalAlpha = r, e.drawImage(
|
|
650
|
+
_,
|
|
651
|
+
F,
|
|
652
|
+
D
|
|
653
|
+
), e.restore();
|
|
654
|
+
}
|
|
655
|
+
function je(e, n) {
|
|
656
|
+
Z(e, n, qe);
|
|
657
|
+
}
|
|
658
|
+
function qe(e, n) {
|
|
659
|
+
const t = n.transformData;
|
|
660
|
+
e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.scale(t.scale, t.scale);
|
|
661
|
+
const a = n.bold ? "bold" : "normal", r = n.italic ? "italic" : "normal";
|
|
662
|
+
e.font = `${r} ${a} ${n.fontSize}px ${n.fontFamily}`, e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
663
|
+
const o = n.text.split(""), s = o.map((i) => e.measureText(i).width), c = s.reduce((i, l) => i + l, 0);
|
|
664
|
+
if (t.reverse) {
|
|
665
|
+
let i = Math.PI / 2 + c / (2 * t.radius);
|
|
666
|
+
o.forEach((l, d) => {
|
|
667
|
+
const p = s[d] / t.radius, f = Math.cos(i - p / 2) * t.radius, m = Math.sin(i - p / 2) * t.radius;
|
|
668
|
+
e.save(), e.translate(f, m), e.rotate(i - p / 2 - Math.PI / 2), J(e, l, n.stroke), e.fillText(l, 0, 0), e.restore(), i -= p;
|
|
669
|
+
});
|
|
670
|
+
} else {
|
|
671
|
+
let i = -Math.PI / 2 - c / (2 * t.radius);
|
|
672
|
+
o.forEach((l, d) => {
|
|
673
|
+
const p = s[d] / t.radius, f = Math.cos(i + p / 2) * t.radius, m = Math.sin(i + p / 2) * t.radius;
|
|
674
|
+
e.save(), e.translate(f, m), e.rotate(i + p / 2 + Math.PI / 2), J(e, l, n.stroke), e.fillText(l, 0, 0), e.restore(), i += p;
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
e.restore();
|
|
678
|
+
}
|
|
679
|
+
function Xe(e, n) {
|
|
680
|
+
Z(e, n, Ye);
|
|
681
|
+
}
|
|
682
|
+
function Ye(e, n) {
|
|
683
|
+
const t = n.transformData;
|
|
684
|
+
e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = R(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
685
|
+
const a = n.text.split("");
|
|
686
|
+
let o = -a.reduce((s, c) => s + e.measureText(c).width, 0) / 2;
|
|
687
|
+
a.forEach((s) => {
|
|
688
|
+
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);
|
|
689
|
+
e.save(), e.translate(i, d), e.transform(1, u * Se, 0, 1, 0, 0), J(e, s, n.stroke), e.fillText(s, 0, 0), e.restore(), o += c;
|
|
690
|
+
}), e.restore();
|
|
691
|
+
}
|
|
692
|
+
function Ke(e, n) {
|
|
693
|
+
Z(e, n, Je);
|
|
694
|
+
}
|
|
695
|
+
function Je(e, n) {
|
|
696
|
+
const t = n.transformData;
|
|
697
|
+
e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = R(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
698
|
+
const a = n.text.split(""), r = a.reduce((c, i) => c + e.measureText(i).width, 0), o = t.width / 2;
|
|
699
|
+
let s = -r / 2;
|
|
700
|
+
a.forEach((c) => {
|
|
701
|
+
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;
|
|
702
|
+
e.save(), e.translate(l, u), e.transform(1, p * 0.3, 0, 1, 0, 0), J(e, c, n.stroke), e.fillText(c, 0, 0), e.restore(), s += i;
|
|
703
|
+
}), e.restore();
|
|
704
|
+
}
|
|
705
|
+
function Ze(e, n) {
|
|
706
|
+
Z(e, n, Qe);
|
|
707
|
+
}
|
|
708
|
+
function Qe(e, n) {
|
|
709
|
+
const t = n.transformData;
|
|
710
|
+
e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = R(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
711
|
+
const a = n.text.split(""), r = a.reduce((c, i) => c + e.measureText(i).width, 0), o = t.ascendAngle * Math.PI / 180;
|
|
712
|
+
let s = -r / 2;
|
|
713
|
+
a.forEach((c) => {
|
|
714
|
+
const i = e.measureText(c).width, l = s + i / 2, d = l * Math.tan(o), u = Math.tan(o);
|
|
715
|
+
e.save(), e.translate(l, d), e.transform(1, u * 1, 0, 1, 0, 0), J(e, c, n.stroke), e.fillText(c, 0, 0), e.restore(), s += i;
|
|
716
|
+
}), e.restore();
|
|
717
|
+
}
|
|
718
|
+
function nt(e, n) {
|
|
719
|
+
Z(e, n, et);
|
|
720
|
+
}
|
|
721
|
+
function et(e, n) {
|
|
722
|
+
var r;
|
|
723
|
+
const t = n.transformData;
|
|
724
|
+
e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180);
|
|
725
|
+
const a = -t.leanAmount * Math.PI / 4;
|
|
726
|
+
e.transform(1, 0, Math.tan(a), 1, 0, 0), e.font = R(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();
|
|
727
|
+
}
|
|
728
|
+
function tt(e, n) {
|
|
729
|
+
Z(e, n, at);
|
|
730
|
+
}
|
|
731
|
+
function at(e, n) {
|
|
732
|
+
const t = n.transformData;
|
|
733
|
+
e.save(), e.translate(n.x, n.y), e.rotate(-n.rotation * Math.PI / 180), e.font = R(n.fontSize, n.fontFamily, n.bold, n.italic), e.fillStyle = n.color, e.textAlign = "center", e.textBaseline = "middle";
|
|
734
|
+
const a = n.text.split("");
|
|
735
|
+
let o = -a.reduce((s, c) => s + e.measureText(c).width, 0) / 2;
|
|
736
|
+
a.forEach((s) => {
|
|
737
|
+
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), m = t.amplitude * Math.sign(l) * Math.sin(t.frequency * Math.PI * l), b = f + m;
|
|
738
|
+
e.save(), e.translate(i, p), e.transform(1, b * 0.3, 0, 1, 0, 0), J(e, s, n.stroke), e.fillText(s, 0, 0), e.restore(), o += c;
|
|
739
|
+
}), e.restore();
|
|
740
|
+
}
|
|
741
|
+
const rt = V("TextureManager"), an = class an {
|
|
3
742
|
/**
|
|
4
743
|
* Load a texture by ID or URL
|
|
5
744
|
*/
|
|
@@ -8,12 +747,12 @@ const re = q("TextureManager"), W = class W {
|
|
|
8
747
|
return this.cache.get(n);
|
|
9
748
|
if (this.loading.has(n))
|
|
10
749
|
return this.loading.get(n);
|
|
11
|
-
const t = this.resolveTextureUrl(n), a = new Promise((r,
|
|
750
|
+
const t = this.resolveTextureUrl(n), a = new Promise((r, o) => {
|
|
12
751
|
const s = new Image();
|
|
13
752
|
s.crossOrigin = "anonymous", s.onload = () => {
|
|
14
753
|
this.cache.set(n, s), this.cache.set(t, s), this.loading.delete(n), this.loading.delete(t), r(s);
|
|
15
754
|
}, s.onerror = () => {
|
|
16
|
-
|
|
755
|
+
rt.error("Failed to load texture:", t), this.loading.delete(n), this.loading.delete(t), o(new Error(`Failed to load texture: ${t}`));
|
|
17
756
|
}, s.src = t;
|
|
18
757
|
});
|
|
19
758
|
return this.loading.set(n, a), t !== n && this.loading.set(t, a), a;
|
|
@@ -79,7 +818,7 @@ const re = q("TextureManager"), W = class W {
|
|
|
79
818
|
return (t == null ? void 0 : t.presetColor) || "#ffffff";
|
|
80
819
|
}
|
|
81
820
|
};
|
|
82
|
-
|
|
821
|
+
an.cache = /* @__PURE__ */ new Map(), an.loading = /* @__PURE__ */ new Map(), an.TEXTURES = [
|
|
83
822
|
{
|
|
84
823
|
id: "glass-frame",
|
|
85
824
|
name: "Glass Frame",
|
|
@@ -89,29 +828,29 @@ W.cache = /* @__PURE__ */ new Map(), W.loading = /* @__PURE__ */ new Map(), W.TE
|
|
|
89
828
|
// Light gray
|
|
90
829
|
}
|
|
91
830
|
];
|
|
92
|
-
let
|
|
93
|
-
function
|
|
831
|
+
let X = an;
|
|
832
|
+
function On(e, n, t = {}) {
|
|
94
833
|
const a = t.mode || "both";
|
|
95
834
|
switch (e.save(), e.translate(n.x || 0, n.y || 0), e.rotate(-(n.rotation || 0) * Math.PI / 180), n.transformType) {
|
|
96
835
|
case "image":
|
|
97
|
-
|
|
836
|
+
it(e, n, a, t);
|
|
98
837
|
break;
|
|
99
838
|
case "shape":
|
|
100
|
-
|
|
839
|
+
ot(e, n, a, t);
|
|
101
840
|
break;
|
|
102
841
|
case "group":
|
|
103
842
|
break;
|
|
104
843
|
default:
|
|
105
|
-
|
|
844
|
+
st(e, n, a, t);
|
|
106
845
|
break;
|
|
107
846
|
}
|
|
108
847
|
e.restore();
|
|
109
848
|
}
|
|
110
|
-
function
|
|
849
|
+
function st(e, n, t, a) {
|
|
111
850
|
var s;
|
|
112
|
-
const r = n,
|
|
113
|
-
|
|
114
|
-
text:
|
|
851
|
+
const r = n, o = r.text || "";
|
|
852
|
+
o && ((t === "stroke" || t === "both") && ((s = n.stroke) != null && s.enabled) && (e.save(), se(e, n, { ...a.renderingContext, positionApplied: !0 }), e.restore()), (t === "fill" || t === "both") && (e.save(), ze(e, {
|
|
853
|
+
text: o,
|
|
115
854
|
fontSize: r.fontSize || 24,
|
|
116
855
|
fontFamily: r.fontFamily || "Arial",
|
|
117
856
|
bold: r.bold || !1,
|
|
@@ -120,172 +859,172 @@ function se(e, n, t, a) {
|
|
|
120
859
|
color: r.color || "#000000"
|
|
121
860
|
}), e.restore()));
|
|
122
861
|
}
|
|
123
|
-
function
|
|
124
|
-
var
|
|
862
|
+
function it(e, n, t, a) {
|
|
863
|
+
var o;
|
|
125
864
|
if (!n.transformData) return;
|
|
126
865
|
const r = n.transformData;
|
|
127
866
|
if (t === "fill" || t === "both")
|
|
128
|
-
if (
|
|
867
|
+
if (ut(e, n), a.loadedImage) {
|
|
129
868
|
e.save(), e.clip();
|
|
130
869
|
const s = r.flipHorizontal ? -1 : 1, c = r.flipVertical ? -1 : 1;
|
|
131
870
|
e.scale(s, c);
|
|
132
|
-
const
|
|
133
|
-
e.drawImage(a.loadedImage, -
|
|
871
|
+
const i = r.width ?? 100, l = r.height ?? 100;
|
|
872
|
+
e.drawImage(a.loadedImage, -i / 2, -l / 2, i, l), e.restore();
|
|
134
873
|
} else
|
|
135
874
|
e.fillStyle = "#cccccc", e.fill();
|
|
136
|
-
(t === "stroke" || t === "both") && ((
|
|
875
|
+
(t === "stroke" || t === "both") && ((o = n.stroke) != null && o.enabled) && (e.save(), Be(e, n, a.renderingContext), e.restore());
|
|
137
876
|
}
|
|
138
|
-
function
|
|
877
|
+
function ot(e, n, t, a) {
|
|
139
878
|
var s, c;
|
|
140
879
|
if (!n.transformData) return;
|
|
141
|
-
const r = n.transformData,
|
|
142
|
-
e.beginPath(),
|
|
880
|
+
const r = n.transformData, o = ((s = a.renderingContext) == null ? void 0 : s.isKnockout) === !0;
|
|
881
|
+
e.beginPath(), ie(e, r), (t === "fill" || t === "both") && (e.fillStyle = o ? "#000000" : r.fillColor || "#3b82f6", e.globalAlpha = o ? 1 : r.fillOpacity ?? 1, e.fill()), (t === "stroke" || t === "both") && ((c = n.stroke) != null && c.enabled) && (e.save(), ft(e, n, a.renderingContext), e.restore());
|
|
143
882
|
}
|
|
144
|
-
function
|
|
883
|
+
function ie(e, n) {
|
|
145
884
|
const { shapeType: t } = n, a = n.width ?? 100, r = n.height ?? 100;
|
|
146
885
|
switch (t) {
|
|
147
886
|
case "rectangle":
|
|
148
|
-
|
|
887
|
+
zn(e, n, a, r);
|
|
149
888
|
break;
|
|
150
889
|
case "circle":
|
|
151
|
-
|
|
890
|
+
ct(e, Math.min(a, r) / 2);
|
|
152
891
|
break;
|
|
153
892
|
case "ellipse":
|
|
154
|
-
|
|
893
|
+
lt(e, a / 2, r / 2);
|
|
155
894
|
break;
|
|
156
895
|
case "star":
|
|
157
|
-
|
|
896
|
+
dt(e, n, Math.min(a, r) / 2);
|
|
158
897
|
break;
|
|
159
898
|
default:
|
|
160
|
-
|
|
899
|
+
zn(e, n, a, r);
|
|
161
900
|
}
|
|
162
901
|
}
|
|
163
|
-
function
|
|
164
|
-
const r = n.borderRadius || 0,
|
|
902
|
+
function zn(e, n, t, a) {
|
|
903
|
+
const r = n.borderRadius || 0, o = -t / 2, s = -a / 2;
|
|
165
904
|
if (r > 0) {
|
|
166
905
|
const c = Math.min(r / 100 * Math.min(t, a), t / 2, a / 2);
|
|
167
|
-
e.roundRect(
|
|
906
|
+
e.roundRect(o, s, t, a, c);
|
|
168
907
|
} else
|
|
169
|
-
e.rect(
|
|
908
|
+
e.rect(o, s, t, a);
|
|
170
909
|
}
|
|
171
|
-
function
|
|
910
|
+
function ct(e, n) {
|
|
172
911
|
e.arc(0, 0, n, 0, Math.PI * 2);
|
|
173
912
|
}
|
|
174
|
-
function
|
|
913
|
+
function lt(e, n, t) {
|
|
175
914
|
e.ellipse(0, 0, n, t, 0, 0, Math.PI * 2);
|
|
176
915
|
}
|
|
177
|
-
function
|
|
178
|
-
const a = Math.max(3, Math.min(20, n.points || 5)), r = Math.max(0.1, Math.min(0.9, n.innerRadius || 0.4)),
|
|
179
|
-
for (let
|
|
180
|
-
const l = c + s *
|
|
181
|
-
|
|
916
|
+
function dt(e, n, t) {
|
|
917
|
+
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;
|
|
918
|
+
for (let i = 0; i < a * 2; i++) {
|
|
919
|
+
const l = c + s * i, d = i % 2 === 0 ? t : o, u = Math.cos(l) * d, p = Math.sin(l) * d;
|
|
920
|
+
i === 0 ? e.moveTo(u, p) : e.lineTo(u, p);
|
|
182
921
|
}
|
|
183
922
|
e.closePath();
|
|
184
923
|
}
|
|
185
|
-
function
|
|
924
|
+
function ft(e, n, t) {
|
|
186
925
|
var r;
|
|
187
926
|
if (!((r = n.stroke) != null && r.enabled) || !n.transformData) return;
|
|
188
927
|
const a = (t == null ? void 0 : t.isKnockout) === !0;
|
|
189
|
-
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(),
|
|
928
|
+
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(), ie(e, n.transformData), e.stroke(), e.restore();
|
|
190
929
|
}
|
|
191
|
-
function
|
|
930
|
+
function ut(e, n) {
|
|
192
931
|
if (!n.transformData) return;
|
|
193
|
-
const { borderRadius: t } = n.transformData, a = n.transformData.width ?? 100, r = n.transformData.height ?? 100,
|
|
932
|
+
const { borderRadius: t } = n.transformData, a = n.transformData.width ?? 100, r = n.transformData.height ?? 100, o = -a / 2, s = -r / 2;
|
|
194
933
|
if (e.beginPath(), t && t > 0) {
|
|
195
934
|
const c = Math.min(t / 100 * Math.min(a, r), a / 2, r / 2);
|
|
196
|
-
e.roundRect(
|
|
935
|
+
e.roundRect(o, s, a, r, c);
|
|
197
936
|
} else
|
|
198
|
-
e.rect(
|
|
937
|
+
e.rect(o, s, a, r);
|
|
199
938
|
}
|
|
200
|
-
function
|
|
201
|
-
var
|
|
939
|
+
function Cn(e, n, t, a, r, o, s = "destination-out") {
|
|
940
|
+
var v;
|
|
202
941
|
if (!n.knockoutParts) return;
|
|
203
942
|
if (!(n.knockoutParts.fill || n.knockoutParts.stroke)) {
|
|
204
943
|
a(e, n);
|
|
205
944
|
return;
|
|
206
945
|
}
|
|
207
|
-
const
|
|
946
|
+
const i = e.getTransform();
|
|
208
947
|
e.save();
|
|
209
|
-
const l = n.knockoutParts.scope || "group", d =
|
|
948
|
+
const l = n.knockoutParts.scope || "group", d = pt(n, l, t);
|
|
210
949
|
if (d.length === 0 && l === "artboard") {
|
|
211
|
-
|
|
950
|
+
bt(e, n, a), e.restore();
|
|
212
951
|
return;
|
|
213
952
|
}
|
|
214
953
|
if (d.length === 0) {
|
|
215
954
|
a(e, n), e.restore();
|
|
216
955
|
return;
|
|
217
956
|
}
|
|
218
|
-
const u = e.canvas, f = e.getTransform().a, m =
|
|
219
|
-
if (!
|
|
220
|
-
|
|
221
|
-
for (const
|
|
222
|
-
a(
|
|
223
|
-
n.knockoutParts.fill && !n.knockoutParts.stroke && ((
|
|
224
|
-
const
|
|
225
|
-
e.drawImage(m, 0, 0,
|
|
226
|
-
const
|
|
227
|
-
(Math.abs(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
957
|
+
const u = e.canvas, f = e.getTransform().a, m = gt(u.width, u.height), b = m.getContext("2d");
|
|
958
|
+
if (!b) return;
|
|
959
|
+
b.scale(f, f), r && o && (b.fillStyle = r, b.fillRect(o.x, o.y, o.width, o.height));
|
|
960
|
+
for (const g of d)
|
|
961
|
+
a(b, g);
|
|
962
|
+
n.knockoutParts.fill && !n.knockoutParts.stroke && ((v = n.stroke) != null && v.enabled) && (b.save(), Tn(b, n), b.restore()), b.save(), b.globalCompositeOperation = s, n.knockoutParts.fill && kn(b, n), n.knockoutParts.stroke && Tn(b, n), b.restore(), n.knockoutParts.fill || (b.save(), kn(b, n), b.restore());
|
|
963
|
+
const h = u.width / f, S = u.height / f;
|
|
964
|
+
e.drawImage(m, 0, 0, h, S), e.restore();
|
|
965
|
+
const $ = e.getTransform();
|
|
966
|
+
(Math.abs($.a - i.a) > 1e-3 || Math.abs($.d - i.d) > 1e-3 || Math.abs($.e - i.e) > 1e-3 || Math.abs($.f - i.f) > 1e-3) && e.setTransform(
|
|
967
|
+
i.a,
|
|
968
|
+
i.b,
|
|
969
|
+
i.c,
|
|
970
|
+
i.d,
|
|
971
|
+
i.e,
|
|
972
|
+
i.f
|
|
234
973
|
);
|
|
235
974
|
}
|
|
236
|
-
function
|
|
237
|
-
|
|
975
|
+
function la(e, n, t, a, r, o) {
|
|
976
|
+
Cn(e, n, t, a, r, o, "destination-out");
|
|
238
977
|
}
|
|
239
|
-
function
|
|
240
|
-
return n === "artboard" ?
|
|
978
|
+
function pt(e, n, t) {
|
|
979
|
+
return n === "artboard" ? oe(e, t) : ht(e, t);
|
|
241
980
|
}
|
|
242
|
-
function
|
|
981
|
+
function oe(e, n) {
|
|
243
982
|
const t = n.findIndex((a) => a.id === e.id);
|
|
244
983
|
return t === -1 ? [] : n.slice(0, t);
|
|
245
984
|
}
|
|
246
|
-
function
|
|
247
|
-
const t =
|
|
985
|
+
function ht(e, n) {
|
|
986
|
+
const t = ce(e, n);
|
|
248
987
|
if (!t)
|
|
249
|
-
return
|
|
988
|
+
return oe(e, n);
|
|
250
989
|
if (t.transformType !== "group" || !t.children)
|
|
251
990
|
return [];
|
|
252
991
|
const a = t.children.findIndex((r) => r.id === e.id);
|
|
253
992
|
return a === -1 ? [] : t.children.slice(0, a);
|
|
254
993
|
}
|
|
255
|
-
function
|
|
994
|
+
function ce(e, n) {
|
|
256
995
|
for (const t of n)
|
|
257
996
|
if (t.transformType === "group" && t.children) {
|
|
258
997
|
if (t.children.some((r) => r.id === e.id))
|
|
259
998
|
return t;
|
|
260
|
-
const a =
|
|
999
|
+
const a = ce(e, t.children);
|
|
261
1000
|
if (a)
|
|
262
1001
|
return a;
|
|
263
1002
|
}
|
|
264
1003
|
return null;
|
|
265
1004
|
}
|
|
266
|
-
function
|
|
267
|
-
|
|
1005
|
+
function kn(e, n, t) {
|
|
1006
|
+
On(e, n, {
|
|
268
1007
|
mode: "fill",
|
|
269
1008
|
renderingContext: { isKnockout: !0 }
|
|
270
1009
|
});
|
|
271
1010
|
}
|
|
272
|
-
function
|
|
1011
|
+
function Tn(e, n) {
|
|
273
1012
|
var t;
|
|
274
|
-
(t = n.stroke) != null && t.enabled &&
|
|
1013
|
+
(t = n.stroke) != null && t.enabled && On(e, n, {
|
|
275
1014
|
mode: "stroke",
|
|
276
1015
|
renderingContext: { isKnockout: !0 }
|
|
277
1016
|
});
|
|
278
1017
|
}
|
|
279
|
-
function
|
|
1018
|
+
function bt(e, n, t) {
|
|
280
1019
|
var r;
|
|
281
1020
|
const a = n.knockoutParts;
|
|
282
1021
|
if (!a) {
|
|
283
1022
|
t(e, n);
|
|
284
1023
|
return;
|
|
285
1024
|
}
|
|
286
|
-
a.fill || (e.save(),
|
|
1025
|
+
a.fill || (e.save(), kn(e, n), e.restore()), !a.stroke && ((r = n.stroke) != null && r.enabled) && (e.save(), Tn(e, n), e.restore());
|
|
287
1026
|
}
|
|
288
|
-
function
|
|
1027
|
+
function gt(e, n) {
|
|
289
1028
|
if (typeof OffscreenCanvas < "u")
|
|
290
1029
|
return new OffscreenCanvas(e, n);
|
|
291
1030
|
if (typeof document < "u") {
|
|
@@ -294,257 +1033,257 @@ function ge(e, n) {
|
|
|
294
1033
|
}
|
|
295
1034
|
throw new Error("No canvas context available");
|
|
296
1035
|
}
|
|
297
|
-
function
|
|
1036
|
+
function Wn(e, n, t, a, r = 0) {
|
|
298
1037
|
if (t <= 0 || a <= 0 || e <= 0 || n <= 0)
|
|
299
1038
|
return { width: e + r, height: n + r };
|
|
300
|
-
const
|
|
301
|
-
let c,
|
|
302
|
-
return s >
|
|
1039
|
+
const o = t / a, s = e / n;
|
|
1040
|
+
let c, i;
|
|
1041
|
+
return s > o ? (i = n, c = n * o) : (c = e, i = e / o), {
|
|
303
1042
|
width: c + r,
|
|
304
|
-
height:
|
|
1043
|
+
height: i + r
|
|
305
1044
|
};
|
|
306
1045
|
}
|
|
307
|
-
const
|
|
308
|
-
function
|
|
1046
|
+
const nn = 64, $n = 512;
|
|
1047
|
+
function mt(e, n) {
|
|
309
1048
|
e.beginPath(), e.arc(n / 2, n / 2, n * 0.45, 0, Math.PI * 2), e.fill();
|
|
310
1049
|
}
|
|
311
|
-
function
|
|
312
|
-
const t = n / 2, a = n / 2, r = n * 0.45,
|
|
1050
|
+
function yt(e, n) {
|
|
1051
|
+
const t = n / 2, a = n / 2, r = n * 0.45, o = r * 0.4, s = 5;
|
|
313
1052
|
e.beginPath();
|
|
314
1053
|
for (let c = 0; c < s * 2; c++) {
|
|
315
|
-
const
|
|
1054
|
+
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;
|
|
316
1055
|
c === 0 ? e.moveTo(d, u) : e.lineTo(d, u);
|
|
317
1056
|
}
|
|
318
1057
|
e.closePath(), e.fill();
|
|
319
1058
|
}
|
|
320
|
-
function $
|
|
1059
|
+
function $t(e, n) {
|
|
321
1060
|
const t = n / 2, a = n * 0.42;
|
|
322
1061
|
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();
|
|
323
1062
|
}
|
|
324
|
-
function
|
|
325
|
-
const t = n / 2, a = n / 2, r = n * 0.4,
|
|
326
|
-
e.beginPath(), e.moveTo(t, a -
|
|
1063
|
+
function xt(e, n) {
|
|
1064
|
+
const t = n / 2, a = n / 2, r = n * 0.4, o = n * 0.48;
|
|
1065
|
+
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();
|
|
327
1066
|
}
|
|
328
|
-
function
|
|
1067
|
+
function vt(e, n) {
|
|
329
1068
|
const t = n / 2, a = n / 2, r = n * 0.44;
|
|
330
1069
|
e.beginPath();
|
|
331
|
-
for (let
|
|
332
|
-
const s = -Math.PI / 2 + Math.PI / 3 *
|
|
333
|
-
|
|
1070
|
+
for (let o = 0; o < 6; o++) {
|
|
1071
|
+
const s = -Math.PI / 2 + Math.PI / 3 * o, c = t + Math.cos(s) * r, i = a + Math.sin(s) * r;
|
|
1072
|
+
o === 0 ? e.moveTo(c, i) : e.lineTo(c, i);
|
|
334
1073
|
}
|
|
335
1074
|
e.closePath(), e.fill();
|
|
336
1075
|
}
|
|
337
|
-
function
|
|
1076
|
+
function wt(e, n) {
|
|
338
1077
|
const t = n / 2, a = n * 0.4, r = n * 0.12;
|
|
339
1078
|
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();
|
|
340
1079
|
}
|
|
341
|
-
function
|
|
1080
|
+
function St(e, n) {
|
|
342
1081
|
const t = n / 2, a = n / 2;
|
|
343
1082
|
let r = 42;
|
|
344
|
-
const
|
|
1083
|
+
const o = () => (r = (r * 16807 + 0) % 2147483647, r / 2147483647);
|
|
345
1084
|
e.beginPath(), e.arc(t, a, n * 0.28, 0, Math.PI * 2), e.fill();
|
|
346
1085
|
for (let s = 0; s < 30; s++) {
|
|
347
|
-
const c =
|
|
348
|
-
e.beginPath(), e.arc(t + Math.cos(c) *
|
|
1086
|
+
const c = o() * Math.PI * 2, i = n * 0.15 + o() * n * 0.3, l = n * 0.02 + o() * n * 0.06;
|
|
1087
|
+
e.beginPath(), e.arc(t + Math.cos(c) * i, a + Math.sin(c) * i, l, 0, Math.PI * 2), e.fill();
|
|
349
1088
|
}
|
|
350
1089
|
}
|
|
351
|
-
function
|
|
1090
|
+
function Ct(e, n) {
|
|
352
1091
|
let t = 123;
|
|
353
|
-
const a = () => (t = (t * 16807 + 0) % 2147483647, t / 2147483647), r = n * 0.08,
|
|
1092
|
+
const a = () => (t = (t * 16807 + 0) % 2147483647, t / 2147483647), r = n * 0.08, o = 40;
|
|
354
1093
|
e.beginPath(), e.moveTo(r, r);
|
|
355
|
-
for (let s = 1; s <=
|
|
356
|
-
const c = r + (n - 2 * r) * (s /
|
|
357
|
-
e.lineTo(c,
|
|
1094
|
+
for (let s = 1; s <= o; s++) {
|
|
1095
|
+
const c = r + (n - 2 * r) * (s / o), i = r + (a() - 0.5) * n * 0.08;
|
|
1096
|
+
e.lineTo(c, i);
|
|
358
1097
|
}
|
|
359
|
-
for (let s = 1; s <=
|
|
360
|
-
const c = n - r + (a() - 0.5) * n * 0.08,
|
|
361
|
-
e.lineTo(c,
|
|
1098
|
+
for (let s = 1; s <= o; s++) {
|
|
1099
|
+
const c = n - r + (a() - 0.5) * n * 0.08, i = r + (n - 2 * r) * (s / o);
|
|
1100
|
+
e.lineTo(c, i);
|
|
362
1101
|
}
|
|
363
|
-
for (let s =
|
|
364
|
-
const c = r + (n - 2 * r) * (s /
|
|
365
|
-
e.lineTo(c,
|
|
1102
|
+
for (let s = o; s >= 0; s--) {
|
|
1103
|
+
const c = r + (n - 2 * r) * (s / o), i = n - r + (a() - 0.5) * n * 0.08;
|
|
1104
|
+
e.lineTo(c, i);
|
|
366
1105
|
}
|
|
367
|
-
for (let s =
|
|
368
|
-
const c = r + (a() - 0.5) * n * 0.08,
|
|
369
|
-
e.lineTo(c,
|
|
1106
|
+
for (let s = o; s >= 0; s--) {
|
|
1107
|
+
const c = r + (a() - 0.5) * n * 0.08, i = r + (n - 2 * r) * (s / o);
|
|
1108
|
+
e.lineTo(c, i);
|
|
370
1109
|
}
|
|
371
1110
|
e.closePath(), e.fill();
|
|
372
1111
|
}
|
|
373
|
-
function
|
|
1112
|
+
function kt(e, n) {
|
|
374
1113
|
let t = 77;
|
|
375
|
-
const a = () => (t = (t * 16807 + 0) % 2147483647, t / 2147483647), r = n * 0.25,
|
|
1114
|
+
const a = () => (t = (t * 16807 + 0) % 2147483647, t / 2147483647), r = n * 0.25, o = n * 0.75, s = n * 0.1;
|
|
376
1115
|
e.beginPath(), e.moveTo(s, r + a() * n * 0.05);
|
|
377
1116
|
for (let c = 1; c <= 10; c++) {
|
|
378
|
-
const
|
|
379
|
-
e.lineTo(
|
|
1117
|
+
const i = s + (n - 2 * s) * (c / 10), l = r + (a() - 0.5) * n * 0.1;
|
|
1118
|
+
e.lineTo(i, l);
|
|
380
1119
|
}
|
|
381
1120
|
for (let c = 10; c >= 0; c--) {
|
|
382
|
-
const
|
|
383
|
-
e.lineTo(
|
|
1121
|
+
const i = s + (n - 2 * s) * (c / 10), l = o + (a() - 0.5) * n * 0.1;
|
|
1122
|
+
e.lineTo(i, l);
|
|
384
1123
|
}
|
|
385
1124
|
e.closePath(), e.fill();
|
|
386
1125
|
}
|
|
387
|
-
function
|
|
1126
|
+
function Tt(e, n) {
|
|
388
1127
|
const t = n / 2, a = n * 0.55;
|
|
389
1128
|
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();
|
|
390
1129
|
}
|
|
391
|
-
const
|
|
1130
|
+
const _t = [
|
|
392
1131
|
// Geometric
|
|
393
|
-
{ id: "circle", name: "Circle", description: "Perfect circle", imageUrl: "builtin-mask:circle", thumbnailUrl: "", category: "geometric", draw:
|
|
394
|
-
{ id: "star", name: "Star", description: "5-pointed star", imageUrl: "builtin-mask:star", thumbnailUrl: "", category: "geometric", draw:
|
|
395
|
-
{ id: "heart", name: "Heart", description: "Heart shape", imageUrl: "builtin-mask:heart", thumbnailUrl: "", category: "geometric", draw: $
|
|
396
|
-
{ id: "diamond", name: "Diamond", description: "Diamond/rhombus", imageUrl: "builtin-mask:diamond", thumbnailUrl: "", category: "geometric", draw:
|
|
397
|
-
{ id: "hexagon", name: "Hexagon", description: "Regular hexagon", imageUrl: "builtin-mask:hexagon", thumbnailUrl: "", category: "geometric", draw:
|
|
398
|
-
{ id: "shield", name: "Shield", description: "Shield/crest shape", imageUrl: "builtin-mask:shield", thumbnailUrl: "", category: "geometric", draw:
|
|
1132
|
+
{ id: "circle", name: "Circle", description: "Perfect circle", imageUrl: "builtin-mask:circle", thumbnailUrl: "", category: "geometric", draw: mt },
|
|
1133
|
+
{ id: "star", name: "Star", description: "5-pointed star", imageUrl: "builtin-mask:star", thumbnailUrl: "", category: "geometric", draw: yt },
|
|
1134
|
+
{ id: "heart", name: "Heart", description: "Heart shape", imageUrl: "builtin-mask:heart", thumbnailUrl: "", category: "geometric", draw: $t },
|
|
1135
|
+
{ id: "diamond", name: "Diamond", description: "Diamond/rhombus", imageUrl: "builtin-mask:diamond", thumbnailUrl: "", category: "geometric", draw: xt },
|
|
1136
|
+
{ id: "hexagon", name: "Hexagon", description: "Regular hexagon", imageUrl: "builtin-mask:hexagon", thumbnailUrl: "", category: "geometric", draw: vt },
|
|
1137
|
+
{ id: "shield", name: "Shield", description: "Shield/crest shape", imageUrl: "builtin-mask:shield", thumbnailUrl: "", category: "geometric", draw: wt },
|
|
399
1138
|
// Organic
|
|
400
|
-
{ id: "splatter", name: "Splatter", description: "Ink splatter", imageUrl: "builtin-mask:splatter", thumbnailUrl: "", category: "organic", draw:
|
|
401
|
-
{ id: "torn-edge", name: "Torn Edge", description: "Rough torn paper edge", imageUrl: "builtin-mask:torn-edge", thumbnailUrl: "", category: "organic", draw:
|
|
402
|
-
{ id: "paint-stroke", name: "Paint Stroke", description: "Horizontal brush stroke", imageUrl: "builtin-mask:paint-stroke", thumbnailUrl: "", category: "organic", draw:
|
|
403
|
-
{ id: "cloud", name: "Cloud", description: "Soft cloud shape", imageUrl: "builtin-mask:cloud", thumbnailUrl: "", category: "organic", draw:
|
|
1139
|
+
{ id: "splatter", name: "Splatter", description: "Ink splatter", imageUrl: "builtin-mask:splatter", thumbnailUrl: "", category: "organic", draw: St },
|
|
1140
|
+
{ id: "torn-edge", name: "Torn Edge", description: "Rough torn paper edge", imageUrl: "builtin-mask:torn-edge", thumbnailUrl: "", category: "organic", draw: Ct },
|
|
1141
|
+
{ id: "paint-stroke", name: "Paint Stroke", description: "Horizontal brush stroke", imageUrl: "builtin-mask:paint-stroke", thumbnailUrl: "", category: "organic", draw: kt },
|
|
1142
|
+
{ id: "cloud", name: "Cloud", description: "Soft cloud shape", imageUrl: "builtin-mask:cloud", thumbnailUrl: "", category: "organic", draw: Tt }
|
|
404
1143
|
];
|
|
405
|
-
let
|
|
406
|
-
function
|
|
1144
|
+
let Gn = !1;
|
|
1145
|
+
function Hn(e, n) {
|
|
407
1146
|
if (typeof document > "u") return null;
|
|
408
1147
|
const t = document.createElement("canvas");
|
|
409
1148
|
return t.width = e, t.height = n, t;
|
|
410
1149
|
}
|
|
411
|
-
function
|
|
412
|
-
if (typeof document > "u" ||
|
|
413
|
-
|
|
414
|
-
const e =
|
|
415
|
-
for (const n of
|
|
416
|
-
const t =
|
|
1150
|
+
function Et() {
|
|
1151
|
+
if (typeof document > "u" || Gn) return;
|
|
1152
|
+
Gn = !0;
|
|
1153
|
+
const e = bn.getInstance();
|
|
1154
|
+
for (const n of _t) {
|
|
1155
|
+
const t = Hn($n, $n);
|
|
417
1156
|
if (!t) continue;
|
|
418
1157
|
const a = t.getContext("2d");
|
|
419
1158
|
if (!a) continue;
|
|
420
|
-
a.fillStyle = "white", n.draw(a,
|
|
421
|
-
const r = t.toDataURL("image/png"),
|
|
422
|
-
|
|
423
|
-
const s =
|
|
1159
|
+
a.fillStyle = "white", n.draw(a, $n);
|
|
1160
|
+
const r = t.toDataURL("image/png"), o = e.acquire(n.imageUrl);
|
|
1161
|
+
o.crossOrigin = "anonymous", o.src = r;
|
|
1162
|
+
const s = Hn(nn, nn);
|
|
424
1163
|
if (s) {
|
|
425
1164
|
const c = s.getContext("2d");
|
|
426
|
-
c && (c.fillStyle = "#1a1a2e", c.fillRect(0, 0,
|
|
1165
|
+
c && (c.fillStyle = "#1a1a2e", c.fillRect(0, 0, nn, nn), c.fillStyle = "white", n.draw(c, nn), n.thumbnailUrl = s.toDataURL("image/png"));
|
|
427
1166
|
}
|
|
428
1167
|
}
|
|
429
1168
|
}
|
|
430
|
-
const
|
|
431
|
-
function
|
|
1169
|
+
const At = V("MaskRenderer"), _n = /* @__PURE__ */ new Map(), Pt = /* @__PURE__ */ new Map();
|
|
1170
|
+
function da(e) {
|
|
432
1171
|
const n = [];
|
|
433
|
-
|
|
1172
|
+
_n.forEach((t, a) => {
|
|
434
1173
|
a.startsWith(e) && n.push(a);
|
|
435
|
-
}), n.forEach((t) =>
|
|
1174
|
+
}), n.forEach((t) => _n.delete(t));
|
|
436
1175
|
}
|
|
437
|
-
function
|
|
438
|
-
|
|
1176
|
+
function fa() {
|
|
1177
|
+
_n.clear();
|
|
439
1178
|
}
|
|
440
|
-
function
|
|
1179
|
+
function Vn(e, n, t) {
|
|
441
1180
|
if (!n.masks || n.masks.length === 0) {
|
|
442
1181
|
t(e);
|
|
443
1182
|
return;
|
|
444
1183
|
}
|
|
445
|
-
const a = e.canvas, r =
|
|
446
|
-
if (!
|
|
447
|
-
|
|
1184
|
+
const a = e.canvas, r = fn(a.width, a.height), o = r.getContext("2d");
|
|
1185
|
+
if (!o) {
|
|
1186
|
+
At.error("[renderWithMasks] Failed to get offscreen context");
|
|
448
1187
|
return;
|
|
449
1188
|
}
|
|
450
1189
|
const s = e.getTransform();
|
|
451
|
-
|
|
1190
|
+
o.setTransform(s), t(o);
|
|
452
1191
|
for (const c of n.masks)
|
|
453
|
-
|
|
1192
|
+
It(o, c, n);
|
|
454
1193
|
e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(r, 0, 0), e.restore();
|
|
455
1194
|
}
|
|
456
|
-
function
|
|
1195
|
+
function It(e, n, t) {
|
|
457
1196
|
switch (n.type) {
|
|
458
1197
|
case "clip":
|
|
459
|
-
|
|
1198
|
+
Dt(e, n, t);
|
|
460
1199
|
break;
|
|
461
1200
|
case "alpha":
|
|
462
|
-
|
|
1201
|
+
Ft(e, n, t);
|
|
463
1202
|
break;
|
|
464
1203
|
case "luma":
|
|
465
|
-
|
|
1204
|
+
Mt(e, n, t);
|
|
466
1205
|
break;
|
|
467
1206
|
case "distress":
|
|
468
|
-
|
|
1207
|
+
Ot(e, n, t);
|
|
469
1208
|
break;
|
|
470
1209
|
}
|
|
471
1210
|
}
|
|
472
|
-
function
|
|
473
|
-
e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity),
|
|
1211
|
+
function Dt(e, n, t) {
|
|
1212
|
+
e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), gn(e, n.maskElement, t), e.restore();
|
|
474
1213
|
}
|
|
475
|
-
function
|
|
476
|
-
e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity),
|
|
1214
|
+
function Ft(e, n, t) {
|
|
1215
|
+
e.save(), e.globalCompositeOperation = n.inverted ? "destination-out" : "destination-in", n.opacity !== void 0 && (e.globalAlpha = n.opacity), gn(e, n.maskElement, t), n.feather && n.feather > 0 && le(e, n.feather), e.restore();
|
|
477
1216
|
}
|
|
478
|
-
function
|
|
479
|
-
const a =
|
|
1217
|
+
function Mt(e, n, t) {
|
|
1218
|
+
const a = fn(e.canvas.width, e.canvas.height), r = a.getContext("2d");
|
|
480
1219
|
if (!r) return;
|
|
481
|
-
|
|
482
|
-
const
|
|
1220
|
+
gn(r, n.maskElement, t);
|
|
1221
|
+
const o = r.getImageData(0, 0, a.width, a.height), s = o.data;
|
|
483
1222
|
for (let c = 0; c < s.length; c += 4) {
|
|
484
|
-
const
|
|
1223
|
+
const i = s[c], l = s[c + 1], d = s[c + 2], u = 0.299 * i + 0.587 * l + 0.114 * d;
|
|
485
1224
|
s[c + 3] = n.inverted ? 255 - u : u;
|
|
486
1225
|
}
|
|
487
|
-
r.putImageData(
|
|
1226
|
+
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();
|
|
488
1227
|
}
|
|
489
|
-
function
|
|
490
|
-
e.save(), e.globalCompositeOperation = n.inverted ? "destination-in" : "destination-out", n.opacity !== void 0 && (e.globalAlpha = n.opacity),
|
|
1228
|
+
function Ot(e, n, t) {
|
|
1229
|
+
e.save(), e.globalCompositeOperation = n.inverted ? "destination-in" : "destination-out", n.opacity !== void 0 && (e.globalAlpha = n.opacity), gn(e, n.maskElement, t), n.feather && n.feather > 0 && le(e, n.feather), e.restore();
|
|
491
1230
|
}
|
|
492
|
-
function
|
|
493
|
-
const a = t.x || 0, r = t.y || 0,
|
|
1231
|
+
function gn(e, n, t) {
|
|
1232
|
+
const a = t.x || 0, r = t.y || 0, o = n.x || 0, s = n.y || 0, c = {
|
|
494
1233
|
...n,
|
|
495
|
-
x: a +
|
|
1234
|
+
x: a + o,
|
|
496
1235
|
y: r + s,
|
|
497
1236
|
// Inherit parent rotation so mask rotates with the element
|
|
498
1237
|
rotation: (n.rotation || 0) + (t.rotation || 0)
|
|
499
|
-
},
|
|
1238
|
+
}, 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;
|
|
500
1239
|
u && p && f && (c.transformData = {
|
|
501
1240
|
...f,
|
|
502
|
-
width: u +
|
|
503
|
-
height: p +
|
|
1241
|
+
width: u + i,
|
|
1242
|
+
height: p + i
|
|
504
1243
|
});
|
|
505
|
-
let m,
|
|
1244
|
+
let m, b;
|
|
506
1245
|
if (n.transformType === "image") {
|
|
507
|
-
const
|
|
508
|
-
if (
|
|
1246
|
+
const g = n;
|
|
1247
|
+
if (g.imageUrl)
|
|
509
1248
|
if (typeof document < "u") {
|
|
510
|
-
|
|
511
|
-
const
|
|
512
|
-
|
|
1249
|
+
g.imageUrl.startsWith("builtin-mask:") && Et();
|
|
1250
|
+
const y = bn.getInstance(), k = y.acquire(g.imageUrl);
|
|
1251
|
+
k.complete && k.naturalWidth > 0 && (m = k), y.release(g.imageUrl);
|
|
513
1252
|
} else
|
|
514
|
-
|
|
1253
|
+
b = Pt.get(g.imageUrl);
|
|
515
1254
|
}
|
|
516
|
-
const
|
|
517
|
-
if (
|
|
1255
|
+
const h = c.transformData, S = (f == null ? void 0 : f.width) || 0, $ = (f == null ? void 0 : f.height) || 0, v = S > 0 && $ > 0 && u > 0 && p > 0 && Math.abs(S / $ - u / p) > 1e-3;
|
|
1256
|
+
if (b) {
|
|
518
1257
|
e.save();
|
|
519
|
-
const
|
|
520
|
-
if (e.translate(c.x || 0, c.y || 0), e.rotate(-(c.rotation || 0) * Math.PI / 180),
|
|
521
|
-
const
|
|
1258
|
+
const g = (h == null ? void 0 : h.width) || b.width, y = (h == null ? void 0 : h.height) || b.height;
|
|
1259
|
+
if (e.translate(c.x || 0, c.y || 0), e.rotate(-(c.rotation || 0) * Math.PI / 180), v) {
|
|
1260
|
+
const k = Wn(
|
|
1261
|
+
g,
|
|
522
1262
|
y,
|
|
1263
|
+
S,
|
|
523
1264
|
$,
|
|
524
|
-
C,
|
|
525
|
-
g,
|
|
526
1265
|
0
|
|
527
1266
|
);
|
|
528
|
-
e.drawImage(
|
|
1267
|
+
e.drawImage(b, -k.width / 2, -k.height / 2, k.width, k.height);
|
|
529
1268
|
} else
|
|
530
|
-
e.drawImage(
|
|
1269
|
+
e.drawImage(b, -g / 2, -y / 2, g, y);
|
|
531
1270
|
e.restore();
|
|
532
|
-
} else if (
|
|
533
|
-
const
|
|
1271
|
+
} else if (v && m) {
|
|
1272
|
+
const g = (h == null ? void 0 : h.width) || u, y = (h == null ? void 0 : h.height) || p, k = Wn(
|
|
1273
|
+
g,
|
|
534
1274
|
y,
|
|
1275
|
+
S,
|
|
535
1276
|
$,
|
|
536
|
-
C,
|
|
537
|
-
g,
|
|
538
1277
|
0
|
|
539
1278
|
);
|
|
540
|
-
e.save(), e.translate(c.x || 0, c.y || 0), e.rotate(-(c.rotation || 0) * Math.PI / 180), e.drawImage(m, -
|
|
1279
|
+
e.save(), e.translate(c.x || 0, c.y || 0), e.rotate(-(c.rotation || 0) * Math.PI / 180), e.drawImage(m, -k.width / 2, -k.height / 2, k.width, k.height), e.restore();
|
|
541
1280
|
} else
|
|
542
|
-
|
|
1281
|
+
On(e, c, { mode: "both", loadedImage: m });
|
|
543
1282
|
}
|
|
544
|
-
function
|
|
1283
|
+
function le(e, n) {
|
|
545
1284
|
"filter" in e && (e.filter = `blur(${n}px)`);
|
|
546
1285
|
}
|
|
547
|
-
function
|
|
1286
|
+
function fn(e, n) {
|
|
548
1287
|
if (typeof OffscreenCanvas < "u")
|
|
549
1288
|
return new OffscreenCanvas(e, n);
|
|
550
1289
|
if (typeof document < "u") {
|
|
@@ -553,24 +1292,24 @@ function Y(e, n) {
|
|
|
553
1292
|
}
|
|
554
1293
|
throw new Error("No canvas context available");
|
|
555
1294
|
}
|
|
556
|
-
function
|
|
1295
|
+
function Rt(e, n, t, a) {
|
|
557
1296
|
if (!n.enabled || !n.imageUrl || n.opacity <= 0) return;
|
|
558
|
-
const r =
|
|
559
|
-
if (!
|
|
1297
|
+
const r = bn.getInstance(), o = r.acquire(n.imageUrl);
|
|
1298
|
+
if (!o.complete || o.naturalWidth === 0) {
|
|
560
1299
|
r.release(n.imageUrl);
|
|
561
1300
|
return;
|
|
562
1301
|
}
|
|
563
|
-
const { x: s, y: c, width:
|
|
564
|
-
if (
|
|
1302
|
+
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, m = d.d * l, b = Math.ceil(f), h = Math.ceil(m);
|
|
1303
|
+
if (b <= 0 || h <= 0) {
|
|
565
1304
|
r.release(n.imageUrl);
|
|
566
1305
|
return;
|
|
567
1306
|
}
|
|
568
|
-
const
|
|
569
|
-
if (
|
|
1307
|
+
const S = fn(b, h), $ = S.getContext("2d");
|
|
1308
|
+
if (!$) {
|
|
570
1309
|
r.release(n.imageUrl);
|
|
571
1310
|
return;
|
|
572
1311
|
}
|
|
573
|
-
|
|
1312
|
+
$.drawImage(
|
|
574
1313
|
e.canvas,
|
|
575
1314
|
u,
|
|
576
1315
|
p,
|
|
@@ -578,26 +1317,26 @@ function Me(e, n, t, a) {
|
|
|
578
1317
|
m,
|
|
579
1318
|
0,
|
|
580
1319
|
0,
|
|
581
|
-
|
|
582
|
-
|
|
1320
|
+
b,
|
|
1321
|
+
h
|
|
583
1322
|
);
|
|
584
|
-
let
|
|
585
|
-
if (n.maskType === "luma" ?
|
|
586
|
-
const
|
|
587
|
-
if (
|
|
588
|
-
|
|
589
|
-
const
|
|
590
|
-
for (let
|
|
591
|
-
const
|
|
592
|
-
|
|
1323
|
+
let v;
|
|
1324
|
+
if (n.maskType === "luma" ? v = "destination-in" : v = n.inverted ? "destination-out" : "destination-in", n.maskType === "luma") {
|
|
1325
|
+
const g = fn(b, h), y = g.getContext("2d");
|
|
1326
|
+
if (y) {
|
|
1327
|
+
y.drawImage(o, 0, 0, b, h);
|
|
1328
|
+
const k = y.getImageData(0, 0, b, h), T = k.data;
|
|
1329
|
+
for (let C = 0; C < T.length; C += 4) {
|
|
1330
|
+
const _ = 0.299 * T[C] + 0.587 * T[C + 1] + 0.114 * T[C + 2];
|
|
1331
|
+
T[C + 3] = n.inverted ? 255 - _ : _;
|
|
593
1332
|
}
|
|
594
|
-
|
|
1333
|
+
y.putImageData(k, 0, 0), $.globalCompositeOperation = "destination-in", $.globalAlpha = n.opacity / 100, $.drawImage(g, 0, 0);
|
|
595
1334
|
}
|
|
596
1335
|
} else
|
|
597
|
-
|
|
598
|
-
|
|
1336
|
+
$.globalCompositeOperation = v, $.globalAlpha = n.opacity / 100, $.drawImage(o, 0, 0, b, h);
|
|
1337
|
+
$.globalCompositeOperation = "source-over", $.globalAlpha = 1, e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.clearRect(u, p, f, m), a && (e.fillStyle = a, e.fillRect(u, p, f, m)), e.drawImage(S, u, p), e.restore(), r.release(n.imageUrl);
|
|
599
1338
|
}
|
|
600
|
-
class
|
|
1339
|
+
class Bt {
|
|
601
1340
|
constructor(n = Math.random()) {
|
|
602
1341
|
this.perm = [];
|
|
603
1342
|
for (let a = 0; a < 256; a++)
|
|
@@ -621,78 +1360,78 @@ class Be {
|
|
|
621
1360
|
return t + n * (a - t);
|
|
622
1361
|
}
|
|
623
1362
|
grad(n, t, a) {
|
|
624
|
-
const r = n & 15,
|
|
625
|
-
return ((r & 1) === 0 ?
|
|
1363
|
+
const r = n & 15, o = r < 8 ? t : a, s = r < 4 ? a : r === 12 || r === 14 ? t : 0;
|
|
1364
|
+
return ((r & 1) === 0 ? o : -o) + ((r & 2) === 0 ? s : -s);
|
|
626
1365
|
}
|
|
627
1366
|
noise(n, t) {
|
|
628
1367
|
const a = Math.floor(n) & 255, r = Math.floor(t) & 255;
|
|
629
1368
|
n -= Math.floor(n), t -= Math.floor(t);
|
|
630
|
-
const
|
|
1369
|
+
const o = this.fade(n), s = this.fade(t), c = this.perm[a] + r, i = this.perm[a + 1] + r;
|
|
631
1370
|
return this.lerp(
|
|
632
1371
|
s,
|
|
633
|
-
this.lerp(
|
|
634
|
-
this.lerp(
|
|
1372
|
+
this.lerp(o, this.grad(this.perm[c], n, t), this.grad(this.perm[i], n - 1, t)),
|
|
1373
|
+
this.lerp(o, this.grad(this.perm[c + 1], n, t - 1), this.grad(this.perm[i + 1], n - 1, t - 1))
|
|
635
1374
|
);
|
|
636
1375
|
}
|
|
637
1376
|
}
|
|
638
|
-
function
|
|
639
|
-
const s =
|
|
1377
|
+
function xn(e, n, t, a = Date.now()) {
|
|
1378
|
+
const s = mn(e, n).getContext("2d").createImageData(e, n), c = s.data, i = new Bt(a), l = 0.02, d = 1 - t / 100;
|
|
640
1379
|
for (let u = 0; u < n; u++)
|
|
641
1380
|
for (let p = 0; p < e; p++) {
|
|
642
1381
|
const f = (u * e + p) * 4;
|
|
643
1382
|
let m = 0;
|
|
644
|
-
m +=
|
|
645
|
-
const
|
|
646
|
-
m *= 0.7 +
|
|
647
|
-
const
|
|
648
|
-
c[f] = 255, c[f + 1] = 255, c[f + 2] = 255, c[f + 3] =
|
|
1383
|
+
m += i.noise(p * l, u * l) * 0.5, m += i.noise(p * l * 2, u * l * 2) * 0.25, m += i.noise(p * l * 4, u * l * 4) * 0.125, m = (m + 1) / 2;
|
|
1384
|
+
const b = Math.min(p / e, (e - p) / e) * 2, h = Math.min(u / n, (n - u) / n) * 2, S = Math.min(b, h);
|
|
1385
|
+
m *= 0.7 + S * 0.3;
|
|
1386
|
+
const $ = m > d ? 255 : 0;
|
|
1387
|
+
c[f] = 255, c[f + 1] = 255, c[f + 2] = 255, c[f + 3] = $;
|
|
649
1388
|
}
|
|
650
1389
|
return s;
|
|
651
1390
|
}
|
|
652
|
-
function
|
|
653
|
-
const
|
|
654
|
-
|
|
655
|
-
const s =
|
|
656
|
-
for (let
|
|
1391
|
+
function Lt(e, n, t, a = Date.now()) {
|
|
1392
|
+
const o = mn(e, n).getContext("2d");
|
|
1393
|
+
o.clearRect(0, 0, e, n), o.strokeStyle = "#000000", o.lineWidth = 1 + t / 50, o.lineCap = "round";
|
|
1394
|
+
const s = Rn(a), c = Math.floor(t / 100 * 30 + 5);
|
|
1395
|
+
for (let i = 0; i < c; i++) {
|
|
657
1396
|
const l = s() * e, d = s() * n;
|
|
658
|
-
|
|
1397
|
+
En(o, l, d, s() * Math.PI * 2, 50 + s() * 100, s, 0);
|
|
659
1398
|
}
|
|
660
|
-
return
|
|
1399
|
+
return o.getImageData(0, 0, e, n);
|
|
661
1400
|
}
|
|
662
|
-
function
|
|
1401
|
+
function En(e, n, t, a, r, o, s) {
|
|
663
1402
|
if (s > 3 || r < 10) return;
|
|
664
|
-
const c = n + Math.cos(a) * r,
|
|
665
|
-
if (e.beginPath(), e.moveTo(n, t), e.lineTo(c,
|
|
666
|
-
const l = a + (
|
|
667
|
-
|
|
1403
|
+
const c = n + Math.cos(a) * r, i = t + Math.sin(a) * r;
|
|
1404
|
+
if (e.beginPath(), e.moveTo(n, t), e.lineTo(c, i), e.stroke(), o() > 0.5) {
|
|
1405
|
+
const l = a + (o() - 0.5) * Math.PI / 2;
|
|
1406
|
+
En(e, c, i, l, r * 0.6, o, s + 1);
|
|
668
1407
|
}
|
|
669
|
-
if (
|
|
670
|
-
const l = a - (
|
|
671
|
-
|
|
1408
|
+
if (o() > 0.7) {
|
|
1409
|
+
const l = a - (o() - 0.5) * Math.PI / 2;
|
|
1410
|
+
En(e, c, i, l, r * 0.6, o, s + 1);
|
|
672
1411
|
}
|
|
673
1412
|
}
|
|
674
|
-
function
|
|
675
|
-
const s =
|
|
1413
|
+
function dn(e, n, t, a = Date.now()) {
|
|
1414
|
+
const s = mn(e, n).getContext("2d").createImageData(e, n), c = s.data, i = Rn(a), l = t / 100 * 0.5;
|
|
676
1415
|
for (let d = 0; d < n; d++)
|
|
677
1416
|
for (let u = 0; u < e; u++) {
|
|
678
|
-
const p = (d * e + u) * 4, m =
|
|
1417
|
+
const p = (d * e + u) * 4, m = i() < l ? 255 : 0;
|
|
679
1418
|
c[p] = 0, c[p + 1] = 0, c[p + 2] = 0, c[p + 3] = m;
|
|
680
1419
|
}
|
|
681
1420
|
return s;
|
|
682
1421
|
}
|
|
683
|
-
function
|
|
684
|
-
const
|
|
685
|
-
|
|
686
|
-
const s =
|
|
687
|
-
for (let l = 0; l < n; l +=
|
|
688
|
-
for (let d = 0; d < e; d +=
|
|
1422
|
+
function Nt(e, n, t, a = Date.now()) {
|
|
1423
|
+
const o = mn(e, n).getContext("2d");
|
|
1424
|
+
o.fillStyle = "#000000";
|
|
1425
|
+
const s = Rn(a), c = 4 + t / 100 * 6, i = c * 2;
|
|
1426
|
+
for (let l = 0; l < n; l += i)
|
|
1427
|
+
for (let d = 0; d < e; d += i)
|
|
689
1428
|
if (s() < t / 100) {
|
|
690
1429
|
const u = c * (0.5 + s() * 0.5);
|
|
691
|
-
|
|
1430
|
+
o.beginPath(), o.arc(d, l, u / 2, 0, Math.PI * 2), o.fill();
|
|
692
1431
|
}
|
|
693
|
-
return
|
|
1432
|
+
return o.getImageData(0, 0, e, n);
|
|
694
1433
|
}
|
|
695
|
-
function
|
|
1434
|
+
function mn(e, n) {
|
|
696
1435
|
if (typeof OffscreenCanvas < "u")
|
|
697
1436
|
return new OffscreenCanvas(e, n);
|
|
698
1437
|
if (typeof document < "u") {
|
|
@@ -701,31 +1440,31 @@ function en(e, n) {
|
|
|
701
1440
|
}
|
|
702
1441
|
throw new Error("No canvas context available");
|
|
703
1442
|
}
|
|
704
|
-
function
|
|
1443
|
+
function Rn(e) {
|
|
705
1444
|
let n = Math.sin(e++) * 1e4;
|
|
706
1445
|
return () => (n = Math.sin(e++) * 1e4, n - Math.floor(n));
|
|
707
1446
|
}
|
|
708
|
-
const
|
|
709
|
-
function
|
|
1447
|
+
const L = 42, j = 512, q = 64;
|
|
1448
|
+
function An(e) {
|
|
710
1449
|
const n = e.data;
|
|
711
1450
|
for (let t = 0; t < n.length; t += 4)
|
|
712
1451
|
n[t] = 255, n[t + 1] = 255, n[t + 2] = 255;
|
|
713
1452
|
return e;
|
|
714
1453
|
}
|
|
715
|
-
function
|
|
1454
|
+
function Ut(e, n) {
|
|
716
1455
|
const t = e.data, a = n.data;
|
|
717
1456
|
for (let r = 0; r < t.length; r += 4)
|
|
718
1457
|
t[r] = 255, t[r + 1] = 255, t[r + 2] = 255, t[r + 3] = Math.min(255, t[r + 3] + a[r + 3]);
|
|
719
1458
|
return e;
|
|
720
1459
|
}
|
|
721
|
-
const
|
|
1460
|
+
const zt = [
|
|
722
1461
|
{
|
|
723
1462
|
id: "grunge-heavy",
|
|
724
1463
|
name: "Heavy Grunge",
|
|
725
1464
|
textureUrl: "builtin:grunge-heavy",
|
|
726
1465
|
thumbnailUrl: "",
|
|
727
1466
|
description: "Dense random splatters",
|
|
728
|
-
generate: (e, n) =>
|
|
1467
|
+
generate: (e, n) => dn(e, n, 80, L)
|
|
729
1468
|
},
|
|
730
1469
|
{
|
|
731
1470
|
id: "grunge-fine",
|
|
@@ -733,7 +1472,7 @@ const ze = [
|
|
|
733
1472
|
textureUrl: "builtin:grunge-fine",
|
|
734
1473
|
thumbnailUrl: "",
|
|
735
1474
|
description: "Sparse fine grain",
|
|
736
|
-
generate: (e, n) =>
|
|
1475
|
+
generate: (e, n) => dn(e, n, 25, L + 1)
|
|
737
1476
|
},
|
|
738
1477
|
{
|
|
739
1478
|
id: "concrete",
|
|
@@ -741,7 +1480,7 @@ const ze = [
|
|
|
741
1480
|
textureUrl: "builtin:concrete",
|
|
742
1481
|
thumbnailUrl: "",
|
|
743
1482
|
description: "Rough surface via Perlin noise",
|
|
744
|
-
generate: (e, n) =>
|
|
1483
|
+
generate: (e, n) => xn(e, n, 55, L + 2)
|
|
745
1484
|
},
|
|
746
1485
|
{
|
|
747
1486
|
id: "paper",
|
|
@@ -749,7 +1488,7 @@ const ze = [
|
|
|
749
1488
|
textureUrl: "builtin:paper",
|
|
750
1489
|
thumbnailUrl: "",
|
|
751
1490
|
description: "Subtle aging",
|
|
752
|
-
generate: (e, n) =>
|
|
1491
|
+
generate: (e, n) => xn(e, n, 20, L + 3)
|
|
753
1492
|
},
|
|
754
1493
|
{
|
|
755
1494
|
id: "rust",
|
|
@@ -758,8 +1497,8 @@ const ze = [
|
|
|
758
1497
|
thumbnailUrl: "",
|
|
759
1498
|
description: "Noise + splatter combined",
|
|
760
1499
|
generate: (e, n) => {
|
|
761
|
-
const t =
|
|
762
|
-
return
|
|
1500
|
+
const t = xn(e, n, 45, L + 4), a = dn(e, n, 35, L + 5);
|
|
1501
|
+
return Ut(An(t), An(a));
|
|
763
1502
|
}
|
|
764
1503
|
},
|
|
765
1504
|
{
|
|
@@ -768,7 +1507,7 @@ const ze = [
|
|
|
768
1507
|
textureUrl: "builtin:scratches",
|
|
769
1508
|
thumbnailUrl: "",
|
|
770
1509
|
description: "Branching crack lines",
|
|
771
|
-
generate: (e, n) =>
|
|
1510
|
+
generate: (e, n) => Lt(e, n, 55, L + 6)
|
|
772
1511
|
},
|
|
773
1512
|
{
|
|
774
1513
|
id: "halftone",
|
|
@@ -776,7 +1515,7 @@ const ze = [
|
|
|
776
1515
|
textureUrl: "builtin:halftone",
|
|
777
1516
|
thumbnailUrl: "",
|
|
778
1517
|
description: "Dot grid pattern",
|
|
779
|
-
generate: (e, n) =>
|
|
1518
|
+
generate: (e, n) => Nt(e, n, 55, L + 7)
|
|
780
1519
|
},
|
|
781
1520
|
{
|
|
782
1521
|
id: "spray",
|
|
@@ -784,132 +1523,132 @@ const ze = [
|
|
|
784
1523
|
textureUrl: "builtin:spray",
|
|
785
1524
|
thumbnailUrl: "",
|
|
786
1525
|
description: "Medium random splatter",
|
|
787
|
-
generate: (e, n) =>
|
|
1526
|
+
generate: (e, n) => dn(e, n, 55, L + 8)
|
|
788
1527
|
}
|
|
789
1528
|
];
|
|
790
|
-
let
|
|
791
|
-
function
|
|
1529
|
+
let jn = !1;
|
|
1530
|
+
function Wt(e, n) {
|
|
792
1531
|
if (typeof OffscreenCanvas < "u")
|
|
793
1532
|
return new OffscreenCanvas(e, n);
|
|
794
1533
|
const t = document.createElement("canvas");
|
|
795
1534
|
return t.width = e, t.height = n, t;
|
|
796
1535
|
}
|
|
797
|
-
function
|
|
1536
|
+
function qn(e, n) {
|
|
798
1537
|
if (typeof document > "u") return null;
|
|
799
1538
|
const t = document.createElement("canvas");
|
|
800
1539
|
return t.width = e, t.height = n, t;
|
|
801
1540
|
}
|
|
802
|
-
function
|
|
803
|
-
const n =
|
|
1541
|
+
function Gt(e) {
|
|
1542
|
+
const n = qn(e.width, e.height);
|
|
804
1543
|
if (!n) return "";
|
|
805
1544
|
const t = n.getContext("2d");
|
|
806
1545
|
if (!t) return "";
|
|
807
1546
|
t.putImageData(e, 0, 0);
|
|
808
|
-
const a =
|
|
1547
|
+
const a = qn(q, q);
|
|
809
1548
|
if (!a) return "";
|
|
810
1549
|
const r = a.getContext("2d");
|
|
811
1550
|
if (!r) return "";
|
|
812
|
-
r.drawImage(n, 0, 0, e.width, e.height, 0, 0,
|
|
813
|
-
const
|
|
1551
|
+
r.drawImage(n, 0, 0, e.width, e.height, 0, 0, q, q);
|
|
1552
|
+
const o = r.getImageData(0, 0, q, q), s = o.data;
|
|
814
1553
|
for (let c = 0; c < s.length; c += 4) {
|
|
815
|
-
const
|
|
1554
|
+
const i = s[c + 3], l = 255 - Math.round(i / 255 * 195);
|
|
816
1555
|
s[c] = l, s[c + 1] = l, s[c + 2] = l, s[c + 3] = 255;
|
|
817
1556
|
}
|
|
818
|
-
return r.putImageData(
|
|
1557
|
+
return r.putImageData(o, 0, 0), a.toDataURL("image/png");
|
|
819
1558
|
}
|
|
820
|
-
function
|
|
821
|
-
if (!
|
|
822
|
-
|
|
823
|
-
for (const e of
|
|
824
|
-
const n = e.generate(
|
|
825
|
-
|
|
826
|
-
const t =
|
|
827
|
-
a && (a.putImageData(n, 0, 0),
|
|
1559
|
+
function Ht() {
|
|
1560
|
+
if (!jn) {
|
|
1561
|
+
jn = !0;
|
|
1562
|
+
for (const e of zt) {
|
|
1563
|
+
const n = e.generate(j, j);
|
|
1564
|
+
An(n);
|
|
1565
|
+
const t = Wt(j, j), a = t.getContext("2d");
|
|
1566
|
+
a && (a.putImageData(n, 0, 0), Vt(e.textureUrl, t, j, j)), typeof document < "u" && (e.thumbnailUrl = Gt(n));
|
|
828
1567
|
}
|
|
829
1568
|
}
|
|
830
1569
|
}
|
|
831
|
-
const
|
|
832
|
-
function
|
|
1570
|
+
const z = /* @__PURE__ */ new Set(), W = /* @__PURE__ */ new Map(), un = /* @__PURE__ */ new Map();
|
|
1571
|
+
function Xn(e, n) {
|
|
833
1572
|
if (typeof OffscreenCanvas < "u")
|
|
834
1573
|
return new OffscreenCanvas(e, n);
|
|
835
1574
|
const t = document.createElement("canvas");
|
|
836
1575
|
return t.width = e, t.height = n, t;
|
|
837
1576
|
}
|
|
838
|
-
function
|
|
1577
|
+
function Yn(e) {
|
|
839
1578
|
return e.getContext("2d");
|
|
840
1579
|
}
|
|
841
|
-
function
|
|
842
|
-
const { width: n, height: t } = e, a =
|
|
1580
|
+
function Kn(e) {
|
|
1581
|
+
const { width: n, height: t } = e, a = Xn(n, t), r = Yn(a);
|
|
843
1582
|
if (!r) throw new Error("Failed to get 2d context for temp canvas");
|
|
844
1583
|
r.drawImage(e, 0, 0);
|
|
845
|
-
const
|
|
1584
|
+
const o = r.getImageData(0, 0, n, t), s = o.data;
|
|
846
1585
|
for (let l = 0; l < s.length; l += 4) {
|
|
847
1586
|
const d = s[l], u = s[l + 1], p = s[l + 2], m = 255 - (0.299 * d + 0.587 * u + 0.114 * p);
|
|
848
1587
|
s[l] = 255, s[l + 1] = 255, s[l + 2] = 255, s[l + 3] = m;
|
|
849
1588
|
}
|
|
850
|
-
const c =
|
|
851
|
-
if (!
|
|
852
|
-
return
|
|
1589
|
+
const c = Xn(n, t), i = Yn(c);
|
|
1590
|
+
if (!i) throw new Error("Failed to get 2d context for mask canvas");
|
|
1591
|
+
return i.putImageData(o, 0, 0), { alphaMask: c, width: n, height: t };
|
|
853
1592
|
}
|
|
854
|
-
function
|
|
855
|
-
const n =
|
|
1593
|
+
function de(e) {
|
|
1594
|
+
const n = W.get(e);
|
|
856
1595
|
if (n) return n;
|
|
857
1596
|
if (e.startsWith("builtin:")) {
|
|
858
|
-
|
|
859
|
-
const t =
|
|
1597
|
+
Ht();
|
|
1598
|
+
const t = W.get(e);
|
|
860
1599
|
return t || null;
|
|
861
1600
|
}
|
|
862
|
-
return
|
|
1601
|
+
return z.has(e) || (z.add(e), fe(e)), null;
|
|
863
1602
|
}
|
|
864
|
-
function
|
|
865
|
-
return
|
|
866
|
-
if (
|
|
1603
|
+
function ua(e) {
|
|
1604
|
+
return W.has(e) ? Promise.resolve() : new Promise((n) => {
|
|
1605
|
+
if (W.has(e)) {
|
|
867
1606
|
n();
|
|
868
1607
|
return;
|
|
869
1608
|
}
|
|
870
|
-
const t =
|
|
871
|
-
t.push(n),
|
|
1609
|
+
const t = un.get(e) || [];
|
|
1610
|
+
t.push(n), un.set(e, t), z.has(e) || (z.add(e), fe(e));
|
|
872
1611
|
});
|
|
873
1612
|
}
|
|
874
|
-
function
|
|
875
|
-
|
|
1613
|
+
function Vt(e, n, t, a) {
|
|
1614
|
+
W.has(e) || (W.set(e, { alphaMask: n, width: t, height: a }), en(e));
|
|
876
1615
|
}
|
|
877
|
-
function
|
|
878
|
-
const n =
|
|
879
|
-
n && (n.forEach((t) => t()),
|
|
1616
|
+
function en(e) {
|
|
1617
|
+
const n = un.get(e);
|
|
1618
|
+
n && (n.forEach((t) => t()), un.delete(e));
|
|
880
1619
|
}
|
|
881
|
-
function
|
|
1620
|
+
function fe(e) {
|
|
882
1621
|
if (typeof document < "u") {
|
|
883
1622
|
const n = new Image();
|
|
884
1623
|
n.crossOrigin = "anonymous", n.onload = () => {
|
|
885
|
-
const t =
|
|
886
|
-
|
|
1624
|
+
const t = Kn(n);
|
|
1625
|
+
W.set(e, t), z.delete(e), en(e);
|
|
887
1626
|
}, n.onerror = () => {
|
|
888
|
-
|
|
1627
|
+
z.delete(e), en(e);
|
|
889
1628
|
}, n.src = e;
|
|
890
1629
|
} else
|
|
891
1630
|
fetch(e).then((n) => n.blob()).then((n) => createImageBitmap(n)).then((n) => {
|
|
892
|
-
const t =
|
|
893
|
-
|
|
1631
|
+
const t = Kn(n);
|
|
1632
|
+
W.set(e, t), z.delete(e), en(e);
|
|
894
1633
|
}).catch(() => {
|
|
895
|
-
|
|
1634
|
+
z.delete(e), en(e);
|
|
896
1635
|
});
|
|
897
1636
|
}
|
|
898
|
-
function
|
|
1637
|
+
function ue(e, n) {
|
|
899
1638
|
if (typeof OffscreenCanvas < "u")
|
|
900
1639
|
return new OffscreenCanvas(e, n);
|
|
901
1640
|
const t = document.createElement("canvas");
|
|
902
1641
|
return t.width = e, t.height = n, t;
|
|
903
1642
|
}
|
|
904
|
-
function
|
|
1643
|
+
function jt(e, n, t, a) {
|
|
905
1644
|
if (!n.enabled || !n.textureUrl || n.intensity <= 0) return;
|
|
906
|
-
const r =
|
|
1645
|
+
const r = de(n.textureUrl);
|
|
907
1646
|
if (!r) return;
|
|
908
|
-
const { x:
|
|
909
|
-
if (m <= 0 ||
|
|
910
|
-
const
|
|
911
|
-
if (!
|
|
912
|
-
|
|
1647
|
+
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, m = Math.ceil(p), b = Math.ceil(f);
|
|
1648
|
+
if (m <= 0 || b <= 0) return;
|
|
1649
|
+
const h = ue(m, b), S = h.getContext("2d");
|
|
1650
|
+
if (!S) return;
|
|
1651
|
+
S.drawImage(
|
|
913
1652
|
e.canvas,
|
|
914
1653
|
d,
|
|
915
1654
|
u,
|
|
@@ -918,74 +1657,74 @@ function je(e, n, t, a) {
|
|
|
918
1657
|
0,
|
|
919
1658
|
0,
|
|
920
1659
|
m,
|
|
921
|
-
|
|
1660
|
+
b
|
|
922
1661
|
);
|
|
923
|
-
const
|
|
924
|
-
if (
|
|
925
|
-
const
|
|
926
|
-
for (let
|
|
927
|
-
const
|
|
1662
|
+
const $ = r.alphaMask.getContext("2d");
|
|
1663
|
+
if ($) {
|
|
1664
|
+
const v = n.intensity / 100, g = $.getImageData(0, 0, r.width, r.height).data, y = r.width, k = r.height, T = S.getImageData(0, 0, m, b), C = T.data;
|
|
1665
|
+
for (let _ = 0; _ < b; _++) {
|
|
1666
|
+
const w = Math.floor(_ / b * k);
|
|
928
1667
|
for (let E = 0; E < m; E++) {
|
|
929
|
-
const
|
|
930
|
-
|
|
1668
|
+
const x = Math.floor(E / m * y), P = g[(w * y + x) * 4 + 3] / 255, A = (_ * m + E) * 4;
|
|
1669
|
+
C[A + 3] = Math.round(C[A + 3] * (1 - P * v));
|
|
931
1670
|
}
|
|
932
1671
|
}
|
|
933
|
-
|
|
1672
|
+
S.putImageData(T, 0, 0);
|
|
934
1673
|
} else
|
|
935
|
-
|
|
936
|
-
|
|
1674
|
+
S.globalCompositeOperation = "destination-out", S.globalAlpha = n.intensity / 100, S.drawImage(r.alphaMask, 0, 0, m, b), S.globalCompositeOperation = "source-over";
|
|
1675
|
+
S.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(h, d, u), e.restore();
|
|
937
1676
|
}
|
|
938
|
-
function
|
|
1677
|
+
function Jn(e, n, t, a) {
|
|
939
1678
|
if (!n.enabled || n.style !== "custom" || !n.textureUrl) return;
|
|
940
|
-
const r =
|
|
1679
|
+
const r = de(n.textureUrl);
|
|
941
1680
|
if (!r) {
|
|
942
1681
|
a(e);
|
|
943
1682
|
return;
|
|
944
1683
|
}
|
|
945
|
-
const
|
|
1684
|
+
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 = {
|
|
946
1685
|
x: t.x - u,
|
|
947
1686
|
y: t.y - p,
|
|
948
1687
|
width: t.width + u * 2,
|
|
949
1688
|
height: t.height + p * 2
|
|
950
|
-
}, m = s.a * f.x + s.e,
|
|
951
|
-
if (
|
|
1689
|
+
}, m = s.a * f.x + s.e, b = s.d * f.y + s.f, h = s.a * f.width, S = s.d * f.height, $ = Math.ceil(h), v = Math.ceil(S);
|
|
1690
|
+
if ($ <= 0 || v <= 0) {
|
|
952
1691
|
a(e);
|
|
953
1692
|
return;
|
|
954
1693
|
}
|
|
955
|
-
const
|
|
956
|
-
if (
|
|
1694
|
+
const g = ue($, v), y = g.getContext("2d");
|
|
1695
|
+
if (!y) {
|
|
957
1696
|
a(e);
|
|
958
1697
|
return;
|
|
959
1698
|
}
|
|
960
|
-
|
|
1699
|
+
y.setTransform(
|
|
961
1700
|
s.a,
|
|
962
1701
|
s.b,
|
|
963
1702
|
s.c,
|
|
964
1703
|
s.d,
|
|
965
1704
|
s.e - m,
|
|
966
|
-
s.f -
|
|
967
|
-
), a(
|
|
968
|
-
const
|
|
969
|
-
if (
|
|
970
|
-
const
|
|
971
|
-
for (let
|
|
972
|
-
const
|
|
973
|
-
for (let
|
|
974
|
-
const
|
|
975
|
-
E[
|
|
1705
|
+
s.f - b
|
|
1706
|
+
), a(y), y.setTransform(1, 0, 0, 1, 0, 0);
|
|
1707
|
+
const k = r.alphaMask.getContext("2d");
|
|
1708
|
+
if (k) {
|
|
1709
|
+
const T = k.getImageData(0, 0, r.width, r.height).data, C = r.width, _ = r.height, w = y.getImageData(0, 0, $, v), E = w.data;
|
|
1710
|
+
for (let x = 0; x < v; x++) {
|
|
1711
|
+
const P = Math.floor(x / v * _);
|
|
1712
|
+
for (let A = 0; A < $; A++) {
|
|
1713
|
+
const F = Math.floor(A / $ * C), D = T[(P * C + F) * 4 + 3] / 255, I = (x * $ + A) * 4;
|
|
1714
|
+
E[I + 3] = Math.round(E[I + 3] * (1 - D * o));
|
|
976
1715
|
}
|
|
977
1716
|
}
|
|
978
|
-
|
|
1717
|
+
y.putImageData(w, 0, 0);
|
|
979
1718
|
} else
|
|
980
|
-
|
|
981
|
-
e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(
|
|
1719
|
+
y.globalCompositeOperation = "destination-out", y.globalAlpha = o, y.drawImage(r.alphaMask, 0, 0, $, v), y.globalCompositeOperation = "source-over", y.globalAlpha = 1;
|
|
1720
|
+
e.save(), e.setTransform(1, 0, 0, 1, 0, 0), e.drawImage(g, m, b), e.restore();
|
|
982
1721
|
}
|
|
983
|
-
const
|
|
984
|
-
function
|
|
985
|
-
const t = n ?
|
|
1722
|
+
const Zn = V("element-serializer"), pe = 4e3, on = /* @__PURE__ */ new Set();
|
|
1723
|
+
function qt(e, n) {
|
|
1724
|
+
const t = n ? Xt(n) : "no-src";
|
|
986
1725
|
return `${e}:${t}`;
|
|
987
1726
|
}
|
|
988
|
-
function
|
|
1727
|
+
function Xt(e) {
|
|
989
1728
|
let n = 0;
|
|
990
1729
|
for (let t = 0; t < e.length; t++) {
|
|
991
1730
|
const a = e.charCodeAt(t);
|
|
@@ -993,66 +1732,66 @@ function Xe(e) {
|
|
|
993
1732
|
}
|
|
994
1733
|
return n.toString(36);
|
|
995
1734
|
}
|
|
996
|
-
function
|
|
997
|
-
|
|
1735
|
+
function Pn() {
|
|
1736
|
+
on.clear();
|
|
998
1737
|
}
|
|
999
|
-
function
|
|
1000
|
-
for (const n of
|
|
1001
|
-
n.startsWith(`${e}:`) &&
|
|
1738
|
+
function he(e) {
|
|
1739
|
+
for (const n of on)
|
|
1740
|
+
n.startsWith(`${e}:`) && on.delete(n);
|
|
1002
1741
|
}
|
|
1003
|
-
function
|
|
1004
|
-
|
|
1742
|
+
function Yt(e) {
|
|
1743
|
+
on.add(e);
|
|
1005
1744
|
}
|
|
1006
|
-
function
|
|
1007
|
-
return
|
|
1745
|
+
function Kt(e) {
|
|
1746
|
+
return on.has(e);
|
|
1008
1747
|
}
|
|
1009
|
-
async function
|
|
1748
|
+
async function Jt(e, n = pe) {
|
|
1010
1749
|
const { naturalWidth: t, naturalHeight: a } = e;
|
|
1011
1750
|
if (t <= n && a <= n)
|
|
1012
1751
|
return createImageBitmap(e);
|
|
1013
|
-
const r = n / Math.max(t, a),
|
|
1752
|
+
const r = n / Math.max(t, a), o = Math.round(t * r), s = Math.round(a * r);
|
|
1014
1753
|
return createImageBitmap(e, {
|
|
1015
|
-
resizeWidth:
|
|
1754
|
+
resizeWidth: o,
|
|
1016
1755
|
resizeHeight: s,
|
|
1017
1756
|
resizeQuality: "high"
|
|
1018
1757
|
});
|
|
1019
1758
|
}
|
|
1020
|
-
let
|
|
1021
|
-
function
|
|
1022
|
-
|
|
1759
|
+
let pn = null, hn = null;
|
|
1760
|
+
function Zt(e, n) {
|
|
1761
|
+
pn = e, hn = n;
|
|
1023
1762
|
}
|
|
1024
|
-
function
|
|
1025
|
-
|
|
1763
|
+
function Qt() {
|
|
1764
|
+
pn = null, hn = null;
|
|
1026
1765
|
}
|
|
1027
|
-
function
|
|
1028
|
-
|
|
1766
|
+
function pa() {
|
|
1767
|
+
Pn(), pn && pn();
|
|
1029
1768
|
}
|
|
1030
|
-
function
|
|
1031
|
-
|
|
1769
|
+
function ha(e) {
|
|
1770
|
+
he(e), hn && hn(e);
|
|
1032
1771
|
}
|
|
1033
|
-
function
|
|
1772
|
+
function In(e, n) {
|
|
1034
1773
|
const t = e;
|
|
1035
1774
|
if (typeof t.fontFamily == "string" && n.add(t.fontFamily), t.richText && typeof t.richText == "object") {
|
|
1036
1775
|
const a = t.richText;
|
|
1037
1776
|
if (a.spans && Array.isArray(a.spans))
|
|
1038
1777
|
for (const r of a.spans) {
|
|
1039
|
-
const
|
|
1040
|
-
if (
|
|
1041
|
-
const s =
|
|
1778
|
+
const o = r;
|
|
1779
|
+
if (o.style && typeof o.style == "object") {
|
|
1780
|
+
const s = o.style;
|
|
1042
1781
|
typeof s.fontFamily == "string" && n.add(s.fontFamily);
|
|
1043
1782
|
}
|
|
1044
1783
|
}
|
|
1045
1784
|
}
|
|
1046
1785
|
if (t.children && Array.isArray(t.children))
|
|
1047
1786
|
for (const a of t.children)
|
|
1048
|
-
|
|
1787
|
+
In(a, n);
|
|
1049
1788
|
if (e.masks && Array.isArray(e.masks))
|
|
1050
1789
|
for (const a of e.masks)
|
|
1051
|
-
a.maskElement &&
|
|
1790
|
+
a.maskElement && In(a.maskElement, n);
|
|
1052
1791
|
}
|
|
1053
|
-
function
|
|
1792
|
+
function Qn(e) {
|
|
1054
1793
|
if (typeof document > "u") return e;
|
|
1055
|
-
const n =
|
|
1794
|
+
const n = bn.getInstance();
|
|
1056
1795
|
return e.map((t) => {
|
|
1057
1796
|
if (!(t != null && t.maskElement) || t.maskElement.transformType !== "image") return t;
|
|
1058
1797
|
const a = t.maskElement.imageUrl;
|
|
@@ -1068,41 +1807,41 @@ function Pn(e) {
|
|
|
1068
1807
|
} : t;
|
|
1069
1808
|
});
|
|
1070
1809
|
}
|
|
1071
|
-
async function
|
|
1072
|
-
const a = n.filter((
|
|
1073
|
-
for (const
|
|
1074
|
-
const l =
|
|
1075
|
-
if (
|
|
1076
|
-
|
|
1810
|
+
async function ne(e, n, t = pe) {
|
|
1811
|
+
const a = n.filter((i) => e.hasElementId(i.id)), r = [], o = [], s = /* @__PURE__ */ new Set();
|
|
1812
|
+
for (const i of a) {
|
|
1813
|
+
const l = i.toJSON();
|
|
1814
|
+
if (In(l, s), i instanceof vn && !i.imageElement) {
|
|
1815
|
+
Zn.warn(`[element-serializer] Skipping image ${i.id}: image not loaded (state: ${i.imageLoadState})`);
|
|
1077
1816
|
continue;
|
|
1078
1817
|
}
|
|
1079
|
-
if (
|
|
1818
|
+
if (i instanceof vn && i.imageElement)
|
|
1080
1819
|
try {
|
|
1081
|
-
const d =
|
|
1082
|
-
if (!
|
|
1083
|
-
const
|
|
1084
|
-
|
|
1820
|
+
const d = qt(i.id, i.imageUrl);
|
|
1821
|
+
if (!Kt(d)) {
|
|
1822
|
+
const v = await Jt(i.imageElement, t);
|
|
1823
|
+
o.push({ cacheKey: d, bitmap: v }), Yt(d);
|
|
1085
1824
|
}
|
|
1086
|
-
const p =
|
|
1087
|
-
id:
|
|
1825
|
+
const p = i.transformData || {}, f = l.masks && l.masks.length > 0, m = f ? p.width : p.width * (p.cropWidth ?? 1), b = f ? p.height : p.height * (p.cropHeight ?? 1), h = {
|
|
1826
|
+
id: i.id,
|
|
1088
1827
|
type: "image",
|
|
1089
|
-
x:
|
|
1090
|
-
y:
|
|
1828
|
+
x: i.x,
|
|
1829
|
+
y: i.y,
|
|
1091
1830
|
width: m,
|
|
1092
|
-
height:
|
|
1093
|
-
rotation:
|
|
1831
|
+
height: b,
|
|
1832
|
+
rotation: i.rotation || 0,
|
|
1094
1833
|
bitmapCacheKey: d
|
|
1095
1834
|
};
|
|
1096
1835
|
if (!f && (p.cropX !== 0 || p.cropY !== 0 || p.cropWidth !== 1 || p.cropHeight !== 1)) {
|
|
1097
|
-
const
|
|
1098
|
-
let
|
|
1099
|
-
(
|
|
1836
|
+
const v = i.imageElement.naturalWidth, g = i.imageElement.naturalHeight;
|
|
1837
|
+
let y = 1;
|
|
1838
|
+
(v > t || g > t) && (y = t / Math.max(v, g)), h.cropX = p.cropX * v * y, h.cropY = p.cropY * g * y, h.cropWidth = p.cropWidth * v * y, h.cropHeight = p.cropHeight * g * y;
|
|
1100
1839
|
}
|
|
1101
|
-
p.flipHorizontal && (
|
|
1102
|
-
const
|
|
1103
|
-
|
|
1840
|
+
p.flipHorizontal && (h.flipHorizontal = p.flipHorizontal), p.flipVertical && (h.flipVertical = p.flipVertical), p.borderRadius && (h.borderRadius = p.borderRadius), i.opacity !== void 0 && (h.opacity = i.opacity);
|
|
1841
|
+
const $ = h;
|
|
1842
|
+
i.distressEffect && ($.distressEffect = { ...i.distressEffect }), l.masks && l.masks.length > 0 && ($.masks = Qn(l.masks)), l.blendMode && ($.blendMode = l.blendMode), l.knockoutParts && ($.knockoutParts = l.knockoutParts), "getVisualBoundingBox" in i && typeof i.getVisualBoundingBox == "function" ? $._boundingBox = i.getVisualBoundingBox() : "getBoundingBox" in i && typeof i.getBoundingBox == "function" && ($._boundingBox = i.getBoundingBox()), r.push($);
|
|
1104
1843
|
} catch (d) {
|
|
1105
|
-
|
|
1844
|
+
Zn.error(`[element-serializer] Failed to create ImageBitmap for ${l.id}:`, d);
|
|
1106
1845
|
}
|
|
1107
1846
|
else {
|
|
1108
1847
|
const d = {
|
|
@@ -1110,7 +1849,7 @@ async function In(e, n, t = zn) {
|
|
|
1110
1849
|
type: l.transformType
|
|
1111
1850
|
// Map transformType to type for worker compatibility
|
|
1112
1851
|
};
|
|
1113
|
-
d.masks && Array.isArray(d.masks) && d.masks.length > 0 && (d.masks =
|
|
1852
|
+
d.masks && Array.isArray(d.masks) && d.masks.length > 0 && (d.masks = Qn(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);
|
|
1114
1853
|
}
|
|
1115
1854
|
}
|
|
1116
1855
|
const c = Array.from(s);
|
|
@@ -1132,10 +1871,10 @@ async function In(e, n, t = zn) {
|
|
|
1132
1871
|
elements: r,
|
|
1133
1872
|
fonts: c
|
|
1134
1873
|
},
|
|
1135
|
-
newBitmaps:
|
|
1874
|
+
newBitmaps: o
|
|
1136
1875
|
};
|
|
1137
1876
|
}
|
|
1138
|
-
const
|
|
1877
|
+
const na = `"use strict";
|
|
1139
1878
|
(() => {
|
|
1140
1879
|
var __create = Object.create;
|
|
1141
1880
|
var __defProp = Object.defineProperty;
|
|
@@ -22012,7 +22751,22 @@ const nt = `"use strict";
|
|
|
22012
22751
|
};
|
|
22013
22752
|
var FontAnalyzer = new FontAnalyzerService();
|
|
22014
22753
|
|
|
22015
|
-
// src/
|
|
22754
|
+
// src/core/rich-text-layout.ts
|
|
22755
|
+
var _measureCtx = null;
|
|
22756
|
+
function getMeasureContext() {
|
|
22757
|
+
if (!_measureCtx) {
|
|
22758
|
+
if (typeof OffscreenCanvas !== "undefined") {
|
|
22759
|
+
const canvas = new OffscreenCanvas(1, 1);
|
|
22760
|
+
_measureCtx = canvas.getContext("2d");
|
|
22761
|
+
} else if (typeof document !== "undefined") {
|
|
22762
|
+
const canvas = document.createElement("canvas");
|
|
22763
|
+
_measureCtx = canvas.getContext("2d");
|
|
22764
|
+
} else {
|
|
22765
|
+
throw new Error("No canvas context available");
|
|
22766
|
+
}
|
|
22767
|
+
}
|
|
22768
|
+
return _measureCtx;
|
|
22769
|
+
}
|
|
22016
22770
|
function wrapRichTextSpans(spans, maxWidth, element) {
|
|
22017
22771
|
const ctx = getMeasureContext();
|
|
22018
22772
|
const lines = [];
|
|
@@ -22021,7 +22775,7 @@ const nt = `"use strict";
|
|
|
22021
22775
|
const fontFamily = style.fontFamily || element.fontFamily;
|
|
22022
22776
|
const bold = style.bold !== void 0 ? style.bold : element.bold || false;
|
|
22023
22777
|
const italic = style.italic !== void 0 ? style.italic : element.italic || false;
|
|
22024
|
-
ctx.font =
|
|
22778
|
+
ctx.font = buildFontString2(fontSize, fontFamily, bold, italic);
|
|
22025
22779
|
return ctx.measureText(text).width;
|
|
22026
22780
|
};
|
|
22027
22781
|
const stylesMatch = (s1, s2) => {
|
|
@@ -22194,6 +22948,8 @@ const nt = `"use strict";
|
|
|
22194
22948
|
}
|
|
22195
22949
|
return lines;
|
|
22196
22950
|
}
|
|
22951
|
+
|
|
22952
|
+
// src/rendering/rich-text-renderer.ts
|
|
22197
22953
|
function renderRichTextFillOnly(ctx, richText, element, maxWidth, lockedLineCount) {
|
|
22198
22954
|
ctx.fillStyle = element.color;
|
|
22199
22955
|
const textAlign = element.textAlign || "center";
|
|
@@ -22372,21 +23128,6 @@ const nt = `"use strict";
|
|
|
22372
23128
|
});
|
|
22373
23129
|
});
|
|
22374
23130
|
}
|
|
22375
|
-
var _measureCtx = null;
|
|
22376
|
-
function getMeasureContext() {
|
|
22377
|
-
if (!_measureCtx) {
|
|
22378
|
-
if (typeof OffscreenCanvas !== "undefined") {
|
|
22379
|
-
const canvas = new OffscreenCanvas(1, 1);
|
|
22380
|
-
_measureCtx = canvas.getContext("2d");
|
|
22381
|
-
} else if (typeof document !== "undefined") {
|
|
22382
|
-
const canvas = document.createElement("canvas");
|
|
22383
|
-
_measureCtx = canvas.getContext("2d");
|
|
22384
|
-
} else {
|
|
22385
|
-
throw new Error("No canvas context available");
|
|
22386
|
-
}
|
|
22387
|
-
}
|
|
22388
|
-
return _measureCtx;
|
|
22389
|
-
}
|
|
22390
23131
|
|
|
22391
23132
|
// src/rendering/text-renderer.ts
|
|
22392
23133
|
var logger2 = createLogger("canvas-renderer");
|
|
@@ -25003,8 +25744,8 @@ const nt = `"use strict";
|
|
|
25003
25744
|
console.error("[Export Worker] Unhandled promise rejection:", event.reason);
|
|
25004
25745
|
};
|
|
25005
25746
|
})();
|
|
25006
|
-
`,
|
|
25007
|
-
class
|
|
25747
|
+
`, O = V("WorkerExport");
|
|
25748
|
+
class cn {
|
|
25008
25749
|
constructor() {
|
|
25009
25750
|
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;
|
|
25010
25751
|
}
|
|
@@ -25031,7 +25772,7 @@ class j {
|
|
|
25031
25772
|
try {
|
|
25032
25773
|
t(n);
|
|
25033
25774
|
} catch (a) {
|
|
25034
|
-
|
|
25775
|
+
O.error("Error in progress listener:", a);
|
|
25035
25776
|
}
|
|
25036
25777
|
}
|
|
25037
25778
|
/**
|
|
@@ -25066,7 +25807,7 @@ class j {
|
|
|
25066
25807
|
* Call this when exiting editor mode to free memory.
|
|
25067
25808
|
*/
|
|
25068
25809
|
clearWorkerBitmapCache() {
|
|
25069
|
-
if (
|
|
25810
|
+
if (Pn(), this.worker && this.isReady) {
|
|
25070
25811
|
const n = {
|
|
25071
25812
|
type: "clear-all-bitmaps"
|
|
25072
25813
|
};
|
|
@@ -25078,7 +25819,7 @@ class j {
|
|
|
25078
25819
|
* Call this when an element is removed or its image source changes.
|
|
25079
25820
|
*/
|
|
25080
25821
|
clearWorkerBitmap(n) {
|
|
25081
|
-
if (
|
|
25822
|
+
if (he(n), this.worker && this.isReady) {
|
|
25082
25823
|
const t = {
|
|
25083
25824
|
type: "clear-bitmap",
|
|
25084
25825
|
elementId: n
|
|
@@ -25091,9 +25832,9 @@ class j {
|
|
|
25091
25832
|
*/
|
|
25092
25833
|
static supportsWorkerExport() {
|
|
25093
25834
|
try {
|
|
25094
|
-
return typeof OffscreenCanvas > "u" ? (
|
|
25835
|
+
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);
|
|
25095
25836
|
} catch (n) {
|
|
25096
|
-
return
|
|
25837
|
+
return O.warn("Feature detection failed:", n), !1;
|
|
25097
25838
|
}
|
|
25098
25839
|
}
|
|
25099
25840
|
/**
|
|
@@ -25102,34 +25843,34 @@ class j {
|
|
|
25102
25843
|
async initialize() {
|
|
25103
25844
|
if (this.worker)
|
|
25104
25845
|
return this.readyPromise || Promise.resolve();
|
|
25105
|
-
if (!
|
|
25846
|
+
if (!cn.supportsWorkerExport())
|
|
25106
25847
|
throw new Error("Browser does not support OffscreenCanvas or Web Workers");
|
|
25107
25848
|
return this.readyPromise = new Promise((n, t) => {
|
|
25108
25849
|
try {
|
|
25109
25850
|
let a;
|
|
25110
25851
|
try {
|
|
25111
|
-
const s = new Blob([
|
|
25852
|
+
const s = new Blob([na], { type: "application/javascript" });
|
|
25112
25853
|
a = URL.createObjectURL(s), this.workerBlobUrl = a;
|
|
25113
25854
|
} catch (s) {
|
|
25114
|
-
|
|
25855
|
+
O.error("Failed to create worker blob:", s), t(new Error(`Worker creation failed: ${s instanceof Error ? s.message : String(s)}`));
|
|
25115
25856
|
return;
|
|
25116
25857
|
}
|
|
25117
25858
|
this.worker = new Worker(a, { type: "classic" }), this.worker.onmessage = (s) => {
|
|
25118
25859
|
this.handleWorkerMessage(s.data);
|
|
25119
25860
|
}, this.worker.onerror = (s) => {
|
|
25120
|
-
|
|
25861
|
+
O.error("Worker error:", s), this.handleWorkerError(s);
|
|
25121
25862
|
};
|
|
25122
25863
|
const r = setTimeout(() => {
|
|
25123
25864
|
t(new Error("Worker initialization timeout"));
|
|
25124
|
-
}, 15e3),
|
|
25125
|
-
s.data.type === "ready" && (clearTimeout(r), this.isReady = !0,
|
|
25865
|
+
}, 15e3), o = (s) => {
|
|
25866
|
+
s.data.type === "ready" && (clearTimeout(r), this.isReady = !0, Zt(
|
|
25126
25867
|
() => this.clearWorkerBitmapCache(),
|
|
25127
25868
|
(c) => this.clearWorkerBitmap(c)
|
|
25128
25869
|
), n());
|
|
25129
25870
|
};
|
|
25130
|
-
this.worker.addEventListener("message",
|
|
25871
|
+
this.worker.addEventListener("message", o, { once: !0 });
|
|
25131
25872
|
} catch (a) {
|
|
25132
|
-
|
|
25873
|
+
O.error("Failed to create worker:", a), t(a);
|
|
25133
25874
|
}
|
|
25134
25875
|
}), this.readyPromise;
|
|
25135
25876
|
}
|
|
@@ -25138,8 +25879,8 @@ class j {
|
|
|
25138
25879
|
*/
|
|
25139
25880
|
async restartWorker() {
|
|
25140
25881
|
const n = Date.now();
|
|
25141
|
-
if (n - this.lastCrashTime > this.CRASH_RESET_TIMEOUT && (this.workerCrashCount = 0), this.workerCrashCount++, this.lastCrashTime = n,
|
|
25142
|
-
throw
|
|
25882
|
+
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)
|
|
25883
|
+
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.");
|
|
25143
25884
|
this.worker && (this.worker.terminate(), this.worker = null, this.isReady = !1, this.readyPromise = null, this.workerBlobUrl && (URL.revokeObjectURL(this.workerBlobUrl), this.workerBlobUrl = null));
|
|
25144
25885
|
const t = Math.min(1e3 * Math.pow(2, this.workerCrashCount - 1), 5e3);
|
|
25145
25886
|
await new Promise((a) => setTimeout(a, t)), await this.initialize();
|
|
@@ -25149,13 +25890,13 @@ class j {
|
|
|
25149
25890
|
* Uses request queue for concurrent exports
|
|
25150
25891
|
*/
|
|
25151
25892
|
async exportArtboardToDataURL(n, t, a = {}) {
|
|
25152
|
-
return this.resetIdleTimer(), new Promise((r,
|
|
25893
|
+
return this.resetIdleTimer(), new Promise((r, o) => {
|
|
25153
25894
|
this.requestQueue.push({
|
|
25154
25895
|
artboard: n,
|
|
25155
25896
|
elements: t,
|
|
25156
25897
|
config: { ...a, returnFormat: "dataUrl" },
|
|
25157
25898
|
resolve: r,
|
|
25158
|
-
reject:
|
|
25899
|
+
reject: o
|
|
25159
25900
|
}), this.processQueue();
|
|
25160
25901
|
});
|
|
25161
25902
|
}
|
|
@@ -25165,13 +25906,13 @@ class j {
|
|
|
25165
25906
|
* Uses request queue for concurrent exports
|
|
25166
25907
|
*/
|
|
25167
25908
|
async exportArtboardToBlob(n, t, a = {}) {
|
|
25168
|
-
return this.resetIdleTimer(), new Promise((r,
|
|
25909
|
+
return this.resetIdleTimer(), new Promise((r, o) => {
|
|
25169
25910
|
this.blobRequestQueue.push({
|
|
25170
25911
|
artboard: n,
|
|
25171
25912
|
elements: t,
|
|
25172
25913
|
config: { ...a, returnFormat: "blob" },
|
|
25173
25914
|
resolve: r,
|
|
25174
|
-
reject:
|
|
25915
|
+
reject: o
|
|
25175
25916
|
}), this.processBlobQueue();
|
|
25176
25917
|
});
|
|
25177
25918
|
}
|
|
@@ -25199,26 +25940,26 @@ class j {
|
|
|
25199
25940
|
const { artboard: t, elements: a, config: r } = n;
|
|
25200
25941
|
if ((!this.worker || !this.isReady) && await this.initialize(), !this.worker)
|
|
25201
25942
|
throw new Error("Worker is not initialized");
|
|
25202
|
-
const
|
|
25203
|
-
|
|
25943
|
+
const o = `export-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: c, newBitmaps: i } = await ne(t, a);
|
|
25944
|
+
i.length > 0 && this.registerBitmapsWithWorker(i);
|
|
25204
25945
|
const l = {
|
|
25205
25946
|
type: "export",
|
|
25206
|
-
requestId:
|
|
25947
|
+
requestId: o,
|
|
25207
25948
|
artboardData: c.artboard,
|
|
25208
25949
|
elements: c.elements,
|
|
25209
25950
|
fonts: c.fonts,
|
|
25210
25951
|
scale: r.scale || 1,
|
|
25211
25952
|
format: r.format || "png",
|
|
25212
25953
|
quality: r.quality || 0.95
|
|
25213
|
-
}, d = new Promise((m,
|
|
25214
|
-
this.pendingRequests.set(
|
|
25215
|
-
requestId:
|
|
25954
|
+
}, d = new Promise((m, b) => {
|
|
25955
|
+
this.pendingRequests.set(o, {
|
|
25956
|
+
requestId: o,
|
|
25216
25957
|
resolve: m,
|
|
25217
|
-
reject:
|
|
25958
|
+
reject: b,
|
|
25218
25959
|
startTime: s,
|
|
25219
25960
|
returnFormat: "dataUrl"
|
|
25220
25961
|
}), setTimeout(() => {
|
|
25221
|
-
this.pendingRequests.has(
|
|
25962
|
+
this.pendingRequests.has(o) && (this.pendingRequests.delete(o), b(new Error("Export request timeout")));
|
|
25222
25963
|
}, 3e4);
|
|
25223
25964
|
});
|
|
25224
25965
|
this.worker.postMessage(l);
|
|
@@ -25256,11 +25997,11 @@ class j {
|
|
|
25256
25997
|
const { artboard: t, elements: a, config: r } = n;
|
|
25257
25998
|
if ((!this.worker || !this.isReady) && await this.initialize(), !this.worker)
|
|
25258
25999
|
throw new Error("Worker is not initialized");
|
|
25259
|
-
const
|
|
25260
|
-
|
|
26000
|
+
const o = `export-blob-${++this.requestIdCounter}-${Date.now()}`, s = performance.now(), { data: c, newBitmaps: i } = await ne(t, a);
|
|
26001
|
+
i.length > 0 && this.registerBitmapsWithWorker(i);
|
|
25261
26002
|
const l = {
|
|
25262
26003
|
type: "export",
|
|
25263
|
-
requestId:
|
|
26004
|
+
requestId: o,
|
|
25264
26005
|
artboardData: c.artboard,
|
|
25265
26006
|
elements: c.elements,
|
|
25266
26007
|
fonts: c.fonts,
|
|
@@ -25268,15 +26009,15 @@ class j {
|
|
|
25268
26009
|
format: r.format || "png",
|
|
25269
26010
|
quality: r.quality || 0.95,
|
|
25270
26011
|
returnFormat: "blob"
|
|
25271
|
-
}, d = new Promise((
|
|
25272
|
-
this.pendingRequests.set(
|
|
25273
|
-
requestId:
|
|
25274
|
-
resolve:
|
|
25275
|
-
reject:
|
|
26012
|
+
}, d = new Promise((b, h) => {
|
|
26013
|
+
this.pendingRequests.set(o, {
|
|
26014
|
+
requestId: o,
|
|
26015
|
+
resolve: b,
|
|
26016
|
+
reject: h,
|
|
25276
26017
|
startTime: s,
|
|
25277
26018
|
returnFormat: "blob"
|
|
25278
26019
|
}), setTimeout(() => {
|
|
25279
|
-
this.pendingRequests.has(
|
|
26020
|
+
this.pendingRequests.has(o) && (this.pendingRequests.delete(o), h(new Error("Export request timeout")));
|
|
25280
26021
|
}, 3e4);
|
|
25281
26022
|
});
|
|
25282
26023
|
this.worker.postMessage(l);
|
|
@@ -25314,7 +26055,7 @@ class j {
|
|
|
25314
26055
|
case "ready":
|
|
25315
26056
|
break;
|
|
25316
26057
|
default:
|
|
25317
|
-
|
|
26058
|
+
O.warn("Unknown message type:", n);
|
|
25318
26059
|
}
|
|
25319
26060
|
}
|
|
25320
26061
|
/**
|
|
@@ -25322,14 +26063,14 @@ class j {
|
|
|
25322
26063
|
*/
|
|
25323
26064
|
handleExportComplete(n) {
|
|
25324
26065
|
const t = this.pendingRequests.get(n.requestId);
|
|
25325
|
-
t && t.returnFormat === "dataUrl" ? (t.resolve(n), this.pendingRequests.delete(n.requestId)) : t ? (
|
|
26066
|
+
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);
|
|
25326
26067
|
}
|
|
25327
26068
|
/**
|
|
25328
26069
|
* Handle successful blob export completion
|
|
25329
26070
|
*/
|
|
25330
26071
|
handleBlobExportComplete(n) {
|
|
25331
26072
|
const t = this.pendingRequests.get(n.requestId);
|
|
25332
|
-
t && t.returnFormat === "blob" ? (t.resolve(n), this.pendingRequests.delete(n.requestId)) : t ? (
|
|
26073
|
+
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);
|
|
25333
26074
|
}
|
|
25334
26075
|
/**
|
|
25335
26076
|
* Handle export error
|
|
@@ -25340,13 +26081,13 @@ class j {
|
|
|
25340
26081
|
const a = new Error(n.error);
|
|
25341
26082
|
n.stack && (a.stack = n.stack), t.reject(a), this.pendingRequests.delete(n.requestId);
|
|
25342
26083
|
} else
|
|
25343
|
-
|
|
26084
|
+
O.warn("Received error for unknown request:", n.requestId);
|
|
25344
26085
|
}
|
|
25345
26086
|
/**
|
|
25346
26087
|
* Handle worker errors
|
|
25347
26088
|
*/
|
|
25348
26089
|
async handleWorkerError(n) {
|
|
25349
|
-
|
|
26090
|
+
O.error("Worker error:", n);
|
|
25350
26091
|
const t = Array.from(this.pendingRequests.values());
|
|
25351
26092
|
for (const [a, r] of this.pendingRequests.entries())
|
|
25352
26093
|
this.pendingRequests.delete(a);
|
|
@@ -25354,7 +26095,7 @@ class j {
|
|
|
25354
26095
|
try {
|
|
25355
26096
|
await this.restartWorker();
|
|
25356
26097
|
} catch (a) {
|
|
25357
|
-
|
|
26098
|
+
O.error("Failed to restart worker:", a);
|
|
25358
26099
|
for (const r of t)
|
|
25359
26100
|
r.reject(new Error(`Worker crashed and could not be restarted: ${n.message}`));
|
|
25360
26101
|
for (; this.requestQueue.length > 0; )
|
|
@@ -25370,7 +26111,7 @@ class j {
|
|
|
25370
26111
|
t.reject(new Error("Worker terminated")), this.pendingRequests.delete(n);
|
|
25371
26112
|
for (; this.requestQueue.length > 0; )
|
|
25372
26113
|
this.requestQueue.shift().reject(new Error("Worker terminated"));
|
|
25373
|
-
this.worker.terminate(), this.worker = null, this.isReady = !1, this.readyPromise = null,
|
|
26114
|
+
this.worker.terminate(), this.worker = null, this.isReady = !1, this.readyPromise = null, Pn(), Qt(), this.workerBlobUrl && (URL.revokeObjectURL(this.workerBlobUrl), this.workerBlobUrl = null);
|
|
25374
26115
|
}
|
|
25375
26116
|
}
|
|
25376
26117
|
/**
|
|
@@ -25385,31 +26126,31 @@ class j {
|
|
|
25385
26126
|
};
|
|
25386
26127
|
}
|
|
25387
26128
|
}
|
|
25388
|
-
let
|
|
25389
|
-
function
|
|
25390
|
-
return
|
|
26129
|
+
let K = null;
|
|
26130
|
+
function ba() {
|
|
26131
|
+
return K || (K = new cn()), K;
|
|
25391
26132
|
}
|
|
25392
|
-
function
|
|
25393
|
-
|
|
26133
|
+
function ga() {
|
|
26134
|
+
K && (K.terminate(), K = null);
|
|
25394
26135
|
}
|
|
25395
|
-
const
|
|
25396
|
-
function
|
|
26136
|
+
const U = V("Export");
|
|
26137
|
+
function Dn(e, n) {
|
|
25397
26138
|
var t;
|
|
25398
26139
|
if (!(!e || typeof e != "object")) {
|
|
25399
26140
|
if (typeof e.fontFamily == "string" && e.fontFamily.trim() && n.add(e.fontFamily), e.richText && Array.isArray(e.richText.spans))
|
|
25400
26141
|
for (const a of e.richText.spans)
|
|
25401
26142
|
(t = a == null ? void 0 : a.style) != null && t.fontFamily && typeof a.style.fontFamily == "string" && n.add(a.style.fontFamily);
|
|
25402
26143
|
if (Array.isArray(e.children))
|
|
25403
|
-
for (const a of e.children)
|
|
26144
|
+
for (const a of e.children) Dn(a, n);
|
|
25404
26145
|
if (Array.isArray(e.masks))
|
|
25405
26146
|
for (const a of e.masks)
|
|
25406
|
-
a != null && a.maskElement &&
|
|
26147
|
+
a != null && a.maskElement && Dn(a.maskElement, n);
|
|
25407
26148
|
}
|
|
25408
26149
|
}
|
|
25409
|
-
async function
|
|
26150
|
+
async function ee(e) {
|
|
25410
26151
|
if (typeof document > "u" || !document.fonts) return;
|
|
25411
26152
|
const n = /* @__PURE__ */ new Set();
|
|
25412
|
-
for (const a of e)
|
|
26153
|
+
for (const a of e) Dn(a, n);
|
|
25413
26154
|
if (n.size === 0) return;
|
|
25414
26155
|
const t = [];
|
|
25415
26156
|
for (const a of n)
|
|
@@ -25417,12 +26158,12 @@ async function Dn(e) {
|
|
|
25417
26158
|
}));
|
|
25418
26159
|
await Promise.all(t), document.fonts.ready && await document.fonts.ready;
|
|
25419
26160
|
}
|
|
25420
|
-
const
|
|
26161
|
+
const rn = class rn {
|
|
25421
26162
|
/**
|
|
25422
26163
|
* Check if worker export is supported in this browser
|
|
25423
26164
|
*/
|
|
25424
26165
|
static supportsWorkerExport() {
|
|
25425
|
-
return
|
|
26166
|
+
return cn.supportsWorkerExport();
|
|
25426
26167
|
}
|
|
25427
26168
|
/**
|
|
25428
26169
|
* Get or initialize the worker manager
|
|
@@ -25430,9 +26171,9 @@ const H = class H {
|
|
|
25430
26171
|
static async getWorkerManager() {
|
|
25431
26172
|
return this.supportsWorkerExport() ? this.workerManager ? this.workerManager : this.workerInitPromise ? (await this.workerInitPromise, this.workerManager) : (this.workerInitPromise = (async () => {
|
|
25432
26173
|
try {
|
|
25433
|
-
this.workerManager = new
|
|
26174
|
+
this.workerManager = new cn(), await this.workerManager.initialize();
|
|
25434
26175
|
} catch (n) {
|
|
25435
|
-
|
|
26176
|
+
U.error("Failed to initialize worker:", n), this.workerManager = null;
|
|
25436
26177
|
}
|
|
25437
26178
|
})(), await this.workerInitPromise, this.workerInitPromise = null, this.workerManager) : null;
|
|
25438
26179
|
}
|
|
@@ -25446,7 +26187,7 @@ const H = class H {
|
|
|
25446
26187
|
* Export entire workspace to JSON
|
|
25447
26188
|
*/
|
|
25448
26189
|
static exportToJSON(n, t, a, r) {
|
|
25449
|
-
const
|
|
26190
|
+
const o = {
|
|
25450
26191
|
metadata: {
|
|
25451
26192
|
version: this.CURRENT_VERSION,
|
|
25452
26193
|
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -25466,7 +26207,7 @@ const H = class H {
|
|
|
25466
26207
|
};
|
|
25467
26208
|
}),
|
|
25468
26209
|
activeArtboardId: a.getActiveArtboardId()
|
|
25469
|
-
}, s = JSON.stringify(
|
|
26210
|
+
}, 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`;
|
|
25470
26211
|
this.downloadBlob(c, l);
|
|
25471
26212
|
}
|
|
25472
26213
|
/**
|
|
@@ -25475,22 +26216,22 @@ const H = class H {
|
|
|
25475
26216
|
*/
|
|
25476
26217
|
static async exportArtboardToImage(n, t, a, r = {}) {
|
|
25477
26218
|
const {
|
|
25478
|
-
format:
|
|
26219
|
+
format: o = "png",
|
|
25479
26220
|
quality: s = 0.95,
|
|
25480
26221
|
scale: c = 1,
|
|
25481
|
-
transparentBackground:
|
|
26222
|
+
transparentBackground: i = !1,
|
|
25482
26223
|
backgroundColor: l = n.backgroundColor,
|
|
25483
26224
|
filename: d,
|
|
25484
26225
|
forceMainThread: u = !1
|
|
25485
26226
|
} = r, p = await this.exportArtboardToDataURL(n, t, a, {
|
|
25486
|
-
format:
|
|
26227
|
+
format: o,
|
|
25487
26228
|
quality: s,
|
|
25488
26229
|
scale: c,
|
|
25489
|
-
transparentBackground:
|
|
26230
|
+
transparentBackground: i,
|
|
25490
26231
|
backgroundColor: l,
|
|
25491
26232
|
forceMainThread: u
|
|
25492
|
-
}), f = await this.dataUrlToBlob(p), m = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").split("T")[0],
|
|
25493
|
-
this.downloadBlob(f,
|
|
26233
|
+
}), f = await this.dataUrlToBlob(p), m = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-").split("T")[0], b = d || `${n.name}-${m}.${o}`;
|
|
26234
|
+
this.downloadBlob(f, b);
|
|
25494
26235
|
}
|
|
25495
26236
|
/**
|
|
25496
26237
|
* Export artboard to data URL (for preview/testing)
|
|
@@ -25498,10 +26239,10 @@ const H = class H {
|
|
|
25498
26239
|
*/
|
|
25499
26240
|
static async exportArtboardToDataURL(n, t, a, r = {}) {
|
|
25500
26241
|
const {
|
|
25501
|
-
format:
|
|
26242
|
+
format: o = "png",
|
|
25502
26243
|
quality: s = 0.95,
|
|
25503
26244
|
scale: c = 1,
|
|
25504
|
-
transparentBackground:
|
|
26245
|
+
transparentBackground: i = !1,
|
|
25505
26246
|
backgroundColor: l = n.backgroundColor,
|
|
25506
26247
|
forceMainThread: d = !1
|
|
25507
26248
|
} = r;
|
|
@@ -25509,21 +26250,21 @@ const H = class H {
|
|
|
25509
26250
|
try {
|
|
25510
26251
|
const u = await this.getWorkerManager();
|
|
25511
26252
|
if (u) {
|
|
25512
|
-
const p = new Set(n.getElementIds()), f = t.filter((
|
|
26253
|
+
const p = new Set(n.getElementIds()), f = t.filter((b) => p.has(b.id));
|
|
25513
26254
|
return (await u.exportArtboardToDataURL(n, f, {
|
|
25514
26255
|
scale: c,
|
|
25515
|
-
format:
|
|
26256
|
+
format: o === "jpg" ? "jpeg" : o,
|
|
25516
26257
|
quality: s
|
|
25517
26258
|
})).dataUrl;
|
|
25518
26259
|
}
|
|
25519
26260
|
} catch (u) {
|
|
25520
|
-
|
|
26261
|
+
U.warn("Worker export failed, falling back to main thread:", u);
|
|
25521
26262
|
}
|
|
25522
26263
|
return this.mainThreadExportToDataURL(n, t, a, {
|
|
25523
|
-
format:
|
|
26264
|
+
format: o,
|
|
25524
26265
|
quality: s,
|
|
25525
26266
|
scale: c,
|
|
25526
|
-
transparentBackground:
|
|
26267
|
+
transparentBackground: i,
|
|
25527
26268
|
backgroundColor: l
|
|
25528
26269
|
});
|
|
25529
26270
|
}
|
|
@@ -25534,10 +26275,10 @@ const H = class H {
|
|
|
25534
26275
|
*/
|
|
25535
26276
|
static async exportArtboardToBlob(n, t, a, r = {}) {
|
|
25536
26277
|
const {
|
|
25537
|
-
format:
|
|
26278
|
+
format: o = "png",
|
|
25538
26279
|
quality: s = 0.95,
|
|
25539
26280
|
scale: c = 1,
|
|
25540
|
-
transparentBackground:
|
|
26281
|
+
transparentBackground: i = !1,
|
|
25541
26282
|
backgroundColor: l = n.backgroundColor,
|
|
25542
26283
|
forceMainThread: d = !1
|
|
25543
26284
|
} = r;
|
|
@@ -25545,21 +26286,21 @@ const H = class H {
|
|
|
25545
26286
|
try {
|
|
25546
26287
|
const u = await this.getWorkerManager();
|
|
25547
26288
|
if (u) {
|
|
25548
|
-
const p = new Set(n.getElementIds()), f = t.filter((
|
|
26289
|
+
const p = new Set(n.getElementIds()), f = t.filter((b) => p.has(b.id));
|
|
25549
26290
|
return (await u.exportArtboardToBlob(n, f, {
|
|
25550
26291
|
scale: c,
|
|
25551
|
-
format:
|
|
26292
|
+
format: o === "jpg" ? "jpeg" : o,
|
|
25552
26293
|
quality: s
|
|
25553
26294
|
})).blob;
|
|
25554
26295
|
}
|
|
25555
26296
|
} catch (u) {
|
|
25556
|
-
|
|
26297
|
+
U.warn("Worker blob export failed, falling back to main thread:", u);
|
|
25557
26298
|
}
|
|
25558
26299
|
return this.mainThreadExportToBlob(n, t, a, {
|
|
25559
|
-
format:
|
|
26300
|
+
format: o,
|
|
25560
26301
|
quality: s,
|
|
25561
26302
|
scale: c,
|
|
25562
|
-
transparentBackground:
|
|
26303
|
+
transparentBackground: i,
|
|
25563
26304
|
backgroundColor: l
|
|
25564
26305
|
});
|
|
25565
26306
|
}
|
|
@@ -25571,61 +26312,61 @@ const H = class H {
|
|
|
25571
26312
|
*/
|
|
25572
26313
|
static async mainThreadExportToBlob(n, t, a, r = {}) {
|
|
25573
26314
|
const {
|
|
25574
|
-
format:
|
|
26315
|
+
format: o = "png",
|
|
25575
26316
|
quality: s = 0.95,
|
|
25576
26317
|
scale: c = 1,
|
|
25577
|
-
transparentBackground:
|
|
26318
|
+
transparentBackground: i = !1,
|
|
25578
26319
|
backgroundColor: l = n.backgroundColor
|
|
25579
26320
|
} = r;
|
|
25580
|
-
await
|
|
26321
|
+
await ee(t);
|
|
25581
26322
|
const d = document.createElement("canvas"), u = n.width * c, p = n.height * c;
|
|
25582
26323
|
d.width = u, d.height = p;
|
|
25583
26324
|
const f = d.getContext("2d");
|
|
25584
|
-
if (f.scale(c, c), !
|
|
26325
|
+
if (f.scale(c, c), !i && n.exportBackground) {
|
|
25585
26326
|
if (f.save(), this.applyExportBackgroundClipPath(f, n), n.backgroundType === "texture" && n.backgroundTexture) {
|
|
25586
|
-
const
|
|
25587
|
-
f.fillStyle =
|
|
25588
|
-
const
|
|
25589
|
-
|
|
26327
|
+
const g = X.getTexturePresetColor(n.backgroundTexture);
|
|
26328
|
+
f.fillStyle = g, f.fillRect(0, 0, n.width, n.height);
|
|
26329
|
+
const y = X.getTexture(n.backgroundTexture);
|
|
26330
|
+
y && y.complete && f.drawImage(y, 0, 0, n.width, n.height);
|
|
25590
26331
|
} else
|
|
25591
26332
|
f.fillStyle = l || n.backgroundColor, f.fillRect(0, 0, n.width, n.height);
|
|
25592
26333
|
f.restore();
|
|
25593
26334
|
}
|
|
25594
26335
|
f.save(), f.translate(-n.x, -n.y), this.applyExportClipPath(f, n);
|
|
25595
|
-
const m = new Set(n.getElementIds()),
|
|
25596
|
-
|
|
25597
|
-
const
|
|
25598
|
-
if (
|
|
25599
|
-
const
|
|
25600
|
-
|
|
25601
|
-
},
|
|
25602
|
-
return
|
|
25603
|
-
var
|
|
25604
|
-
if (
|
|
25605
|
-
const
|
|
25606
|
-
if (
|
|
25607
|
-
for (let E = 0; E <
|
|
25608
|
-
const
|
|
25609
|
-
|
|
25610
|
-
}
|
|
25611
|
-
|
|
26336
|
+
const m = new Set(n.getElementIds()), b = t.filter((g) => m.has(g.id)), h = /* @__PURE__ */ new Map();
|
|
26337
|
+
b.forEach((g) => h.set(g.id, g));
|
|
26338
|
+
const S = (g, y) => {
|
|
26339
|
+
if (!y.id) return;
|
|
26340
|
+
const k = h.get(y.id);
|
|
26341
|
+
k && k.render(g, !1);
|
|
26342
|
+
}, $ = b.map((g) => g.toJSON()), v = /* @__PURE__ */ new Set();
|
|
26343
|
+
return b.forEach((g, y) => {
|
|
26344
|
+
var k;
|
|
26345
|
+
if (g.blendMode === "knockout" || g.blendMode === "clip") {
|
|
26346
|
+
const T = $[y], C = g.blendMode === "knockout" ? "destination-out" : "destination-in", _ = ((k = T.knockoutParts) == null ? void 0 : k.scope) || "group", w = $.findIndex((E) => E.id === T.id);
|
|
26347
|
+
if (w !== -1 && _ === "artboard")
|
|
26348
|
+
for (let E = 0; E < w; E++) {
|
|
26349
|
+
const x = $[E].id;
|
|
26350
|
+
x && v.add(x);
|
|
26351
|
+
}
|
|
26352
|
+
Cn(
|
|
25612
26353
|
f,
|
|
25613
|
-
|
|
25614
|
-
|
|
25615
|
-
|
|
25616
|
-
|
|
26354
|
+
T,
|
|
26355
|
+
$,
|
|
26356
|
+
S,
|
|
26357
|
+
i || !n.exportBackground ? void 0 : l,
|
|
25617
26358
|
n,
|
|
25618
|
-
|
|
25619
|
-
),
|
|
26359
|
+
C
|
|
26360
|
+
), v.add(g.id);
|
|
25620
26361
|
}
|
|
25621
|
-
}),
|
|
25622
|
-
|
|
25623
|
-
}), f.restore(), new Promise((
|
|
26362
|
+
}), b.forEach((g) => {
|
|
26363
|
+
v.has(g.id) || g.render(f, !1);
|
|
26364
|
+
}), f.restore(), new Promise((g, y) => {
|
|
25624
26365
|
d.toBlob(
|
|
25625
|
-
(
|
|
25626
|
-
|
|
26366
|
+
(k) => {
|
|
26367
|
+
k ? g(k) : y(new Error("Failed to create blob from canvas"));
|
|
25627
26368
|
},
|
|
25628
|
-
|
|
26369
|
+
o === "jpg" || o === "jpeg" ? "image/jpeg" : o === "webp" ? "image/webp" : "image/png",
|
|
25629
26370
|
s
|
|
25630
26371
|
);
|
|
25631
26372
|
});
|
|
@@ -25637,108 +26378,108 @@ const H = class H {
|
|
|
25637
26378
|
* worker), so font readiness matters here even when no fallback occurred.
|
|
25638
26379
|
*/
|
|
25639
26380
|
static async mainThreadExportToDataURL(n, t, a, r = {}) {
|
|
25640
|
-
var
|
|
26381
|
+
var y, k;
|
|
25641
26382
|
const {
|
|
25642
|
-
format:
|
|
26383
|
+
format: o = "png",
|
|
25643
26384
|
quality: s = 0.95,
|
|
25644
26385
|
scale: c = 1,
|
|
25645
|
-
transparentBackground:
|
|
26386
|
+
transparentBackground: i = !1,
|
|
25646
26387
|
backgroundColor: l = n.backgroundColor
|
|
25647
26388
|
} = r;
|
|
25648
|
-
await
|
|
26389
|
+
await ee(t);
|
|
25649
26390
|
const d = document.createElement("canvas"), u = n.width * c, p = n.height * c;
|
|
25650
26391
|
d.width = u, d.height = p;
|
|
25651
26392
|
const f = d.getContext("2d");
|
|
25652
|
-
if (f.scale(c, c), !
|
|
26393
|
+
if (f.scale(c, c), !i && n.exportBackground) {
|
|
25653
26394
|
if (f.save(), this.applyExportBackgroundClipPath(f, n), n.backgroundType === "texture" && n.backgroundTexture) {
|
|
25654
|
-
const
|
|
25655
|
-
f.fillStyle =
|
|
25656
|
-
const
|
|
25657
|
-
|
|
26395
|
+
const T = X.getTexturePresetColor(n.backgroundTexture);
|
|
26396
|
+
f.fillStyle = T, f.fillRect(0, 0, n.width, n.height);
|
|
26397
|
+
const C = X.getTexture(n.backgroundTexture);
|
|
26398
|
+
C && C.complete ? f.drawImage(C, 0, 0, n.width, n.height) : U.warn("Texture not loaded for export:", n.backgroundTexture);
|
|
25658
26399
|
} else
|
|
25659
26400
|
f.fillStyle = l, f.fillRect(0, 0, n.width, n.height);
|
|
25660
26401
|
f.restore();
|
|
25661
26402
|
}
|
|
25662
26403
|
f.save(), f.translate(-n.x, -n.y), this.applyExportClipPath(f, n);
|
|
25663
|
-
const m = new Set(n.getElementIds()),
|
|
25664
|
-
|
|
25665
|
-
const
|
|
25666
|
-
if (!
|
|
25667
|
-
const
|
|
25668
|
-
|
|
25669
|
-
},
|
|
25670
|
-
|
|
25671
|
-
var
|
|
25672
|
-
if (
|
|
25673
|
-
const
|
|
25674
|
-
if (
|
|
25675
|
-
for (let
|
|
25676
|
-
const
|
|
25677
|
-
|
|
25678
|
-
}
|
|
25679
|
-
|
|
26404
|
+
const m = new Set(n.getElementIds()), b = t.filter((T) => m.has(T.id)), h = /* @__PURE__ */ new Map();
|
|
26405
|
+
b.forEach((T) => h.set(T.id, T));
|
|
26406
|
+
const S = (T, C) => {
|
|
26407
|
+
if (!C.id) return;
|
|
26408
|
+
const _ = h.get(C.id);
|
|
26409
|
+
_ ? _.render(T, !1) : U.warn("Element not found in map:", C.id);
|
|
26410
|
+
}, $ = b.map((T) => T.toJSON()), v = /* @__PURE__ */ new Set();
|
|
26411
|
+
b.forEach((T, C) => {
|
|
26412
|
+
var _;
|
|
26413
|
+
if (T.blendMode === "knockout" || T.blendMode === "clip") {
|
|
26414
|
+
const w = $[C], E = T.blendMode === "knockout" ? "destination-out" : "destination-in", x = ((_ = w.knockoutParts) == null ? void 0 : _.scope) || "group", P = $.findIndex((A) => A.id === w.id);
|
|
26415
|
+
if (P !== -1 && x === "artboard")
|
|
26416
|
+
for (let A = 0; A < P; A++) {
|
|
26417
|
+
const F = $[A].id;
|
|
26418
|
+
F && v.add(F);
|
|
26419
|
+
}
|
|
26420
|
+
Cn(
|
|
25680
26421
|
f,
|
|
25681
|
-
|
|
25682
|
-
|
|
25683
|
-
|
|
25684
|
-
|
|
26422
|
+
w,
|
|
26423
|
+
$,
|
|
26424
|
+
S,
|
|
26425
|
+
i || !n.exportBackground ? void 0 : l,
|
|
25685
26426
|
n,
|
|
25686
26427
|
E
|
|
25687
|
-
),
|
|
26428
|
+
), v.add(T.id);
|
|
25688
26429
|
}
|
|
25689
|
-
}),
|
|
25690
|
-
var
|
|
25691
|
-
if (!
|
|
25692
|
-
const
|
|
25693
|
-
|
|
26430
|
+
}), b.forEach((T, C) => {
|
|
26431
|
+
var _;
|
|
26432
|
+
if (!v.has(T.id)) {
|
|
26433
|
+
const w = $[C], E = ((_ = w == null ? void 0 : w.distressEffect) == null ? void 0 : _.enabled) && w.distressEffect.style === "custom" && w.distressEffect.textureUrl, x = (w == null ? void 0 : w.masks) && w.masks.length > 0, P = (A) => {
|
|
26434
|
+
T.render(A, !1);
|
|
25694
26435
|
};
|
|
25695
|
-
if (
|
|
25696
|
-
|
|
25697
|
-
const
|
|
25698
|
-
|
|
26436
|
+
if (x && E)
|
|
26437
|
+
Vn(f, w, (A) => {
|
|
26438
|
+
const F = T.getVisualBoundingBox();
|
|
26439
|
+
Jn(A, w.distressEffect, F, P);
|
|
25699
26440
|
});
|
|
25700
|
-
else if (
|
|
25701
|
-
|
|
26441
|
+
else if (x)
|
|
26442
|
+
Vn(f, w, P);
|
|
25702
26443
|
else if (E) {
|
|
25703
|
-
const
|
|
25704
|
-
|
|
26444
|
+
const A = T.getVisualBoundingBox();
|
|
26445
|
+
Jn(f, w.distressEffect, A, P);
|
|
25705
26446
|
} else
|
|
25706
|
-
|
|
26447
|
+
T.render(f, !1);
|
|
25707
26448
|
}
|
|
25708
|
-
}), (
|
|
26449
|
+
}), (y = n.distressTexture) != null && y.enabled && jt(f, n.distressTexture, {
|
|
25709
26450
|
x: n.x,
|
|
25710
26451
|
y: n.y,
|
|
25711
26452
|
width: n.width,
|
|
25712
26453
|
height: n.height
|
|
25713
|
-
}), (
|
|
26454
|
+
}), (k = n.imageMask) != null && k.enabled && Rt(f, n.imageMask, {
|
|
25714
26455
|
x: n.x,
|
|
25715
26456
|
y: n.y,
|
|
25716
26457
|
width: n.width,
|
|
25717
26458
|
height: n.height
|
|
25718
26459
|
}), f.restore();
|
|
25719
|
-
const
|
|
25720
|
-
return d.toDataURL(
|
|
26460
|
+
const g = o === "png" ? "image/png" : o === "webp" ? "image/webp" : "image/jpeg";
|
|
26461
|
+
return d.toDataURL(g, s);
|
|
25721
26462
|
}
|
|
25722
26463
|
/**
|
|
25723
26464
|
* Apply clip path for export background (uses 0,0 as origin since background is drawn before translate)
|
|
25724
26465
|
*/
|
|
25725
26466
|
static applyExportBackgroundClipPath(n, t) {
|
|
25726
|
-
const { width: a, height: r, clipShape:
|
|
25727
|
-
if (n.beginPath(), !
|
|
26467
|
+
const { width: a, height: r, clipShape: o } = t, s = 0, c = 0;
|
|
26468
|
+
if (n.beginPath(), !o || o === "rectangle")
|
|
25728
26469
|
n.rect(s, c, a, r);
|
|
25729
|
-
else if (
|
|
25730
|
-
const
|
|
25731
|
-
n.arc(
|
|
25732
|
-
} else if (typeof
|
|
25733
|
-
const
|
|
25734
|
-
typeof n.roundRect == "function" ? n.roundRect(s, c, a, r,
|
|
25735
|
-
} else if (typeof
|
|
26470
|
+
else if (o === "circle") {
|
|
26471
|
+
const i = s + a / 2, l = c + r / 2, d = Math.min(a, r) / 2;
|
|
26472
|
+
n.arc(i, l, d, 0, Math.PI * 2);
|
|
26473
|
+
} else if (typeof o == "object" && o.type === "rounded") {
|
|
26474
|
+
const i = Math.min(o.radius, Math.min(a, r) / 2);
|
|
26475
|
+
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));
|
|
26476
|
+
} else if (typeof o == "object" && o.type === "path")
|
|
25736
26477
|
try {
|
|
25737
|
-
const
|
|
25738
|
-
n.clip(
|
|
26478
|
+
const i = new Path2D(o.d);
|
|
26479
|
+
n.clip(i);
|
|
25739
26480
|
return;
|
|
25740
|
-
} catch (
|
|
25741
|
-
|
|
26481
|
+
} catch (i) {
|
|
26482
|
+
U.warn("Invalid SVG path, falling back to rectangle:", i), n.rect(s, c, a, r);
|
|
25742
26483
|
}
|
|
25743
26484
|
n.clip();
|
|
25744
26485
|
}
|
|
@@ -25747,22 +26488,22 @@ const H = class H {
|
|
|
25747
26488
|
* This creates the clip region for the given artboard during export
|
|
25748
26489
|
*/
|
|
25749
26490
|
static applyExportClipPath(n, t) {
|
|
25750
|
-
const { x: a, y: r, width:
|
|
26491
|
+
const { x: a, y: r, width: o, height: s, clipShape: c } = t;
|
|
25751
26492
|
if (n.beginPath(), !c || c === "rectangle")
|
|
25752
|
-
n.rect(a, r,
|
|
26493
|
+
n.rect(a, r, o, s);
|
|
25753
26494
|
else if (c === "circle") {
|
|
25754
|
-
const
|
|
25755
|
-
n.arc(
|
|
26495
|
+
const i = a + o / 2, l = r + s / 2, d = Math.min(o, s) / 2;
|
|
26496
|
+
n.arc(i, l, d, 0, Math.PI * 2);
|
|
25756
26497
|
} else if (typeof c == "object" && c.type === "rounded") {
|
|
25757
|
-
const
|
|
25758
|
-
typeof n.roundRect == "function" ? n.roundRect(a, r,
|
|
26498
|
+
const i = Math.min(c.radius, Math.min(o, s) / 2);
|
|
26499
|
+
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));
|
|
25759
26500
|
} else if (typeof c == "object" && c.type === "path")
|
|
25760
26501
|
try {
|
|
25761
|
-
const
|
|
25762
|
-
n.translate(a, r), n.clip(
|
|
26502
|
+
const i = new Path2D(c.d);
|
|
26503
|
+
n.translate(a, r), n.clip(i), n.translate(-a, -r);
|
|
25763
26504
|
return;
|
|
25764
|
-
} catch (
|
|
25765
|
-
|
|
26505
|
+
} catch (i) {
|
|
26506
|
+
U.warn("Invalid SVG path, falling back to rectangle:", i), n.rect(a, r, o, s);
|
|
25766
26507
|
}
|
|
25767
26508
|
n.clip();
|
|
25768
26509
|
}
|
|
@@ -25770,13 +26511,13 @@ const H = class H {
|
|
|
25770
26511
|
* Export all artboards as separate images (HIGH PERFORMANCE - parallel rendering)
|
|
25771
26512
|
*/
|
|
25772
26513
|
static async exportAllArtboardsToImages(n, t, a, r = {}) {
|
|
25773
|
-
const
|
|
26514
|
+
const o = n.map(
|
|
25774
26515
|
(s) => this.exportArtboardToImage(s, t, a, {
|
|
25775
26516
|
...r,
|
|
25776
26517
|
filename: r.filename ? `${r.filename}-${s.name}.${r.format || "png"}` : void 0
|
|
25777
26518
|
})
|
|
25778
26519
|
);
|
|
25779
|
-
await Promise.all(
|
|
26520
|
+
await Promise.all(o);
|
|
25780
26521
|
}
|
|
25781
26522
|
/**
|
|
25782
26523
|
* Download a blob as a file
|
|
@@ -25795,11 +26536,11 @@ const H = class H {
|
|
|
25795
26536
|
* Get export summary (for UI display)
|
|
25796
26537
|
*/
|
|
25797
26538
|
static getExportSummary(n, t) {
|
|
25798
|
-
const a = n.length, r = t.length, c = a * 200 + r * 500,
|
|
26539
|
+
const a = n.length, r = t.length, c = a * 200 + r * 500, i = Math.ceil(c / 1024);
|
|
25799
26540
|
return {
|
|
25800
26541
|
artboardCount: a,
|
|
25801
26542
|
totalElementCount: r,
|
|
25802
|
-
estimatedFileSize:
|
|
26543
|
+
estimatedFileSize: i < 1024 ? `${i} KB` : `${(i / 1024).toFixed(1)} MB`
|
|
25803
26544
|
};
|
|
25804
26545
|
}
|
|
25805
26546
|
/**
|
|
@@ -25807,10 +26548,10 @@ const H = class H {
|
|
|
25807
26548
|
* Returns timing data for both methods
|
|
25808
26549
|
*/
|
|
25809
26550
|
static async benchmarkExport(n, t, a, r = {}) {
|
|
25810
|
-
const
|
|
26551
|
+
const o = performance.now(), s = await this.exportArtboardToDataURL(n, t, a, {
|
|
25811
26552
|
...r,
|
|
25812
26553
|
forceMainThread: !0
|
|
25813
|
-
}), c = performance.now() -
|
|
26554
|
+
}), c = performance.now() - o, i = {
|
|
25814
26555
|
workerSupported: this.supportsWorkerExport(),
|
|
25815
26556
|
mainThread: {
|
|
25816
26557
|
time: c,
|
|
@@ -25822,28 +26563,28 @@ const H = class H {
|
|
|
25822
26563
|
try {
|
|
25823
26564
|
const l = performance.now(), d = await this.getWorkerManager();
|
|
25824
26565
|
if (d) {
|
|
25825
|
-
const u = new Set(n.getElementIds()), p = t.filter((
|
|
26566
|
+
const u = new Set(n.getElementIds()), p = t.filter((h) => u.has(h.id)), f = await d.exportArtboardToDataURL(n, p, {
|
|
25826
26567
|
scale: r.scale || 1,
|
|
25827
26568
|
format: (r.format === "jpg" ? "jpeg" : r.format) || "png",
|
|
25828
26569
|
quality: r.quality || 0.95
|
|
25829
|
-
}), m = performance.now() - l,
|
|
26570
|
+
}), m = performance.now() - l, b = c / m;
|
|
25830
26571
|
return {
|
|
25831
|
-
...
|
|
26572
|
+
...i,
|
|
25832
26573
|
worker: {
|
|
25833
26574
|
time: m,
|
|
25834
26575
|
dataUrl: f.dataUrl,
|
|
25835
26576
|
mainThreadBlockTime: f.mainThreadBlockTime
|
|
25836
26577
|
},
|
|
25837
|
-
speedup:
|
|
25838
|
-
recommendation:
|
|
26578
|
+
speedup: b,
|
|
26579
|
+
recommendation: b > 1.2 ? `Worker export is ${b.toFixed(2)}x faster - recommended for continuous export` : b < 0.8 ? `Main thread export is ${(1 / b).toFixed(2)}x faster - worker overhead not worth it for single exports` : "Performance is similar, but worker keeps UI responsive during export"
|
|
25839
26580
|
};
|
|
25840
26581
|
}
|
|
25841
26582
|
} catch (l) {
|
|
25842
|
-
|
|
26583
|
+
U.error("Worker benchmark failed:", l), i.recommendation = "Worker export not available - using main thread export";
|
|
25843
26584
|
}
|
|
25844
26585
|
else
|
|
25845
|
-
|
|
25846
|
-
return
|
|
26586
|
+
i.recommendation = "Worker export not supported in this browser - using main thread export";
|
|
26587
|
+
return i;
|
|
25847
26588
|
}
|
|
25848
26589
|
/**
|
|
25849
26590
|
* Performance benchmark: Test continuous exports to measure UI impact
|
|
@@ -25851,33 +26592,33 @@ const H = class H {
|
|
|
25851
26592
|
*/
|
|
25852
26593
|
static async benchmarkContinuousExport(n, t, a, r = {}) {
|
|
25853
26594
|
const {
|
|
25854
|
-
duration:
|
|
26595
|
+
duration: o = 5e3,
|
|
25855
26596
|
// 5 seconds
|
|
25856
26597
|
interval: s = 500,
|
|
25857
26598
|
// Every 500ms
|
|
25858
26599
|
useWorker: c = this.supportsWorkerExport()
|
|
25859
|
-
} = r,
|
|
26600
|
+
} = r, i = [];
|
|
25860
26601
|
let l = 0, d = !0;
|
|
25861
26602
|
for (setTimeout(() => {
|
|
25862
26603
|
d = !1;
|
|
25863
|
-
},
|
|
25864
|
-
const
|
|
26604
|
+
}, o); d; ) {
|
|
26605
|
+
const $ = performance.now();
|
|
25865
26606
|
await this.exportArtboardToDataURL(n, t, a, {
|
|
25866
26607
|
forceMainThread: !c
|
|
25867
26608
|
});
|
|
25868
|
-
const
|
|
25869
|
-
|
|
26609
|
+
const v = performance.now() - $;
|
|
26610
|
+
i.push(v), c || (l += v), await new Promise((g) => setTimeout(g, Math.max(0, s - v)));
|
|
25870
26611
|
}
|
|
25871
|
-
const u =
|
|
26612
|
+
const u = i.length, p = i.reduce(($, v) => $ + v, 0) / u, f = Math.min(...i), m = Math.max(...i), b = u / o * 1e3, h = l / o * 100, S = h > 20 ? `Main thread blocked ${h.toFixed(1)}% of the time - STRONGLY recommend worker export` : h > 10 ? `Main thread blocked ${h.toFixed(1)}% of the time - consider worker export` : `Main thread blocked ${h.toFixed(1)}% of the time - performance is acceptable`;
|
|
25872
26613
|
return {
|
|
25873
26614
|
totalExports: u,
|
|
25874
|
-
duration:
|
|
26615
|
+
duration: o,
|
|
25875
26616
|
averageTime: p,
|
|
25876
26617
|
minTime: f,
|
|
25877
26618
|
maxTime: m,
|
|
25878
26619
|
totalMainThreadBlockTime: l,
|
|
25879
|
-
exportsPerSecond:
|
|
25880
|
-
recommendation:
|
|
26620
|
+
exportsPerSecond: b,
|
|
26621
|
+
recommendation: S
|
|
25881
26622
|
};
|
|
25882
26623
|
}
|
|
25883
26624
|
/**
|
|
@@ -25949,9 +26690,9 @@ const H = class H {
|
|
|
25949
26690
|
return "previewBackgroundColor" in t && delete t.previewBackgroundColor, t;
|
|
25950
26691
|
}
|
|
25951
26692
|
};
|
|
25952
|
-
|
|
25953
|
-
let
|
|
25954
|
-
class
|
|
26693
|
+
rn.CURRENT_VERSION = "2.0.0", rn.workerManager = null, rn.workerInitPromise = null;
|
|
26694
|
+
let te = rn;
|
|
26695
|
+
class be {
|
|
25955
26696
|
/**
|
|
25956
26697
|
* Create an element instance from a JSON configuration
|
|
25957
26698
|
* TypeScript ensures all transform types are handled
|
|
@@ -25964,27 +26705,27 @@ class Wn {
|
|
|
25964
26705
|
const { transformType: t } = n;
|
|
25965
26706
|
switch (t) {
|
|
25966
26707
|
case "custom":
|
|
25967
|
-
return new
|
|
26708
|
+
return new Fe(n);
|
|
25968
26709
|
case "distort":
|
|
25969
26710
|
throw new Error("DistortTransform is not yet implemented");
|
|
25970
26711
|
case "circle":
|
|
25971
|
-
return new
|
|
26712
|
+
return new De(n);
|
|
25972
26713
|
case "lean":
|
|
25973
|
-
return new
|
|
26714
|
+
return new Ie(n);
|
|
25974
26715
|
case "arch":
|
|
25975
|
-
return new
|
|
26716
|
+
return new Pe(n);
|
|
25976
26717
|
case "ascend":
|
|
25977
|
-
return new
|
|
26718
|
+
return new Ae(n);
|
|
25978
26719
|
case "wave":
|
|
25979
|
-
return new
|
|
26720
|
+
return new Ee(n);
|
|
25980
26721
|
case "flag":
|
|
25981
|
-
return new
|
|
26722
|
+
return new _e(n);
|
|
25982
26723
|
case "image":
|
|
25983
|
-
return new
|
|
26724
|
+
return new vn(n);
|
|
25984
26725
|
case "group":
|
|
25985
26726
|
const a = (n.children || []).map(
|
|
25986
|
-
(s) =>
|
|
25987
|
-
), r = new
|
|
26727
|
+
(s) => be.createFromJSON(s)
|
|
26728
|
+
), r = new Te({
|
|
25988
26729
|
id: n.id,
|
|
25989
26730
|
x: n.x,
|
|
25990
26731
|
y: n.y,
|
|
@@ -25992,12 +26733,12 @@ class Wn {
|
|
|
25992
26733
|
});
|
|
25993
26734
|
return a.forEach((s) => r.addChild(s)), r;
|
|
25994
26735
|
case "shape":
|
|
25995
|
-
return new
|
|
26736
|
+
return new ke(n);
|
|
25996
26737
|
case "path":
|
|
25997
|
-
return new
|
|
26738
|
+
return new Ce(n);
|
|
25998
26739
|
default:
|
|
25999
|
-
const
|
|
26000
|
-
throw new Error(`Unknown transform type: ${
|
|
26740
|
+
const o = t;
|
|
26741
|
+
throw new Error(`Unknown transform type: ${o}`);
|
|
26001
26742
|
}
|
|
26002
26743
|
}
|
|
26003
26744
|
/**
|
|
@@ -26209,29 +26950,47 @@ class Wn {
|
|
|
26209
26950
|
}
|
|
26210
26951
|
}
|
|
26211
26952
|
export {
|
|
26212
|
-
|
|
26213
|
-
|
|
26214
|
-
|
|
26215
|
-
|
|
26216
|
-
|
|
26217
|
-
|
|
26218
|
-
|
|
26219
|
-
|
|
26220
|
-
|
|
26221
|
-
|
|
26222
|
-
|
|
26223
|
-
|
|
26224
|
-
|
|
26225
|
-
|
|
26226
|
-
|
|
26227
|
-
|
|
26228
|
-
|
|
26229
|
-
|
|
26230
|
-
|
|
26231
|
-
|
|
26232
|
-
|
|
26233
|
-
|
|
26234
|
-
|
|
26235
|
-
|
|
26953
|
+
he as A,
|
|
26954
|
+
We as B,
|
|
26955
|
+
be as C,
|
|
26956
|
+
pe as D,
|
|
26957
|
+
te as E,
|
|
26958
|
+
Ht as F,
|
|
26959
|
+
zt as G,
|
|
26960
|
+
ua as H,
|
|
26961
|
+
Et as I,
|
|
26962
|
+
Cn as J,
|
|
26963
|
+
Jn as K,
|
|
26964
|
+
jt as L,
|
|
26965
|
+
_t as M,
|
|
26966
|
+
Rt as N,
|
|
26967
|
+
X as T,
|
|
26968
|
+
cn as W,
|
|
26969
|
+
ia as a,
|
|
26970
|
+
re as b,
|
|
26971
|
+
R as c,
|
|
26972
|
+
pa as d,
|
|
26973
|
+
fa as e,
|
|
26974
|
+
Pn as f,
|
|
26975
|
+
aa as g,
|
|
26976
|
+
Me as h,
|
|
26977
|
+
ra as i,
|
|
26978
|
+
ta as j,
|
|
26979
|
+
sn as k,
|
|
26980
|
+
ba as l,
|
|
26981
|
+
da as m,
|
|
26982
|
+
Nn as n,
|
|
26983
|
+
ha as o,
|
|
26984
|
+
Un as p,
|
|
26985
|
+
oa as q,
|
|
26986
|
+
Be as r,
|
|
26987
|
+
sa as s,
|
|
26988
|
+
Ue as t,
|
|
26989
|
+
ca as u,
|
|
26990
|
+
ze as v,
|
|
26991
|
+
se as w,
|
|
26992
|
+
la as x,
|
|
26993
|
+
Vn as y,
|
|
26994
|
+
ga as z
|
|
26236
26995
|
};
|
|
26237
|
-
//# sourceMappingURL=ElementFactory-
|
|
26996
|
+
//# sourceMappingURL=ElementFactory-CuHSAPfg.js.map
|