@charisol/plexo-sdk 2.0.28 → 2.0.29

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.
Files changed (47) hide show
  1. package/README.md +301 -0
  2. package/dist/{InlineColorPicker-BYcOgLVc.js → InlineColorPicker-XesBzRsU.js} +362 -114
  3. package/dist/{v1-Cz7qypQd.js → blank-BEl6CY5C.js} +4656 -10906
  4. package/dist/brandGuide-Dd4fqVjS.js +33 -0
  5. package/dist/{client-DUSU8g5z.js → client-CWui0-3q.js} +1 -1
  6. package/dist/codeEditor-Cux0ud2j.js +205 -0
  7. package/dist/files-Df6FY0HK.js +2182 -0
  8. package/dist/id-CR6Y8qD6.js +8 -0
  9. package/dist/index.js +12786 -13034
  10. package/dist/{brandGuide-DgoZ7spo.js → lint-CV3DmM0X.js} +78 -109
  11. package/dist/pdfImport-BOev0Pc1.js +262 -0
  12. package/dist/plexo-sdk.css +1 -1
  13. package/dist/v1-Cn7SGvZk.js +6253 -0
  14. package/dist/v2/CanvasEditor.d.ts +25 -0
  15. package/dist/v2/V2Editor.d.ts +15 -20
  16. package/dist/v2/compile/build.d.ts +5 -0
  17. package/dist/v2/components/properties/PropertiesPanel.d.ts +1 -0
  18. package/dist/v2/files/aiPicture.d.ts +85 -0
  19. package/dist/v2/files/build.d.ts +49 -0
  20. package/dist/v2/files/capture.d.ts +52 -0
  21. package/dist/v2/files/convert.d.ts +24 -0
  22. package/dist/v2/files/docx.d.ts +1 -0
  23. package/dist/v2/files/engine.d.ts +2 -0
  24. package/dist/v2/files/export.d.ts +97 -0
  25. package/dist/v2/files/import.d.ts +34 -0
  26. package/dist/v2/files/index.d.ts +16 -0
  27. package/dist/v2/files/pdf.d.ts +15 -0
  28. package/dist/v2/files/pdfImport.d.ts +28 -0
  29. package/dist/v2/files/sheet.d.ts +16 -0
  30. package/dist/v2/files/text.d.ts +8 -0
  31. package/dist/v2/files/types.d.ts +96 -0
  32. package/dist/v2/files/ui/ExportDock.d.ts +11 -0
  33. package/dist/v2/files/ui/ExportMenu.d.ts +5 -0
  34. package/dist/v2/files/ui/ExportPanel.d.ts +17 -0
  35. package/dist/v2/files/ui/FileEditor.d.ts +14 -0
  36. package/dist/v2/files/ui/HtmlWorkbench.d.ts +15 -0
  37. package/dist/v2/files/ui/codeEditor.d.ts +12 -0
  38. package/dist/v2/files/ui/editors.d.ts +28 -0
  39. package/dist/v2/files/vector.d.ts +19 -0
  40. package/dist/v2/files/zip.d.ts +10 -0
  41. package/dist/v2/host/HostContext.d.ts +6 -3
  42. package/dist/v2/index.d.ts +5 -1
  43. package/dist/v2-compile.js +17 -16
  44. package/dist/v2-files.js +3 -0
  45. package/dist/v2-strata.js +2 -2
  46. package/dist/v2.js +5805 -4038
  47. package/package.json +18 -3
@@ -0,0 +1,2182 @@
1
+ import { t as e } from "./id-CR6Y8qD6.js";
2
+ import { H as t, Jt as n, Qt as r, o as i, r as a, t as o } from "./blank-BEl6CY5C.js";
3
+ import { a as s, i as c, o as l, s as u } from "./pdfImport-BOev0Pc1.js";
4
+ //#region src/v2/files/vector.ts
5
+ var d = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"), f = (e) => String(Math.round(e * 100) / 100), p = (e) => !e || e === "transparent" || /^rgba?\([^)]*[,/]\s*0(\.0+)?\s*\)$/.test(e.trim());
6
+ function m(e) {
7
+ let t = [], n = 0, r = "";
8
+ for (let i of e) i === "(" && n++, i === ")" && n--, i === "," && n === 0 ? (t.push(r.trim()), r = "") : r += i;
9
+ return r.trim() && t.push(r.trim()), t;
10
+ }
11
+ function h(e) {
12
+ let t = /^rgba?\(\s*([\d.]+)[\s,]+([\d.]+)[\s,]+([\d.]+)(?:[\s,/]+([\d.]+%?))?\s*\)$/.exec(e.trim());
13
+ if (!t) return null;
14
+ let n = t[4] === void 0 ? 1 : t[4].endsWith("%") ? parseFloat(t[4]) / 100 : parseFloat(t[4]);
15
+ return [
16
+ Number(t[1]),
17
+ Number(t[2]),
18
+ Number(t[3]),
19
+ n
20
+ ];
21
+ }
22
+ var g = (e) => `rgba(${Math.round(e[0])},${Math.round(e[1])},${Math.round(e[2])},${Math.round(e[3] * 1e3) / 1e3})`, _ = (e, t, n) => [
23
+ e[0] + (t[0] - e[0]) * n,
24
+ e[1] + (t[1] - e[1]) * n,
25
+ e[2] + (t[2] - e[2]) * n,
26
+ e[3] + (t[3] - e[3]) * n
27
+ ];
28
+ function v(e, t, n, r, i) {
29
+ let a = Math.min(n, r) / 2, [o, s, c, l] = i.map((e) => Math.max(0, Math.min(e, a)));
30
+ return `M${f(e + o)} ${f(t)}H${f(e + n - s)}${s ? `A${f(s)} ${f(s)} 0 0 1 ${f(e + n)} ${f(t + s)}` : ""}V${f(t + r - c)}${c ? `A${f(c)} ${f(c)} 0 0 1 ${f(e + n - c)} ${f(t + r)}` : ""}H${f(e + l)}${l ? `A${f(l)} ${f(l)} 0 0 1 ${f(e)} ${f(t + r - l)}` : ""}V${f(t + o)}${o ? `A${f(o)} ${f(o)} 0 0 1 ${f(e + o)} ${f(t)}` : ""}Z`;
31
+ }
32
+ function y(e, t) {
33
+ let n = (e) => {
34
+ let n = e.split(" ")[0];
35
+ return n.endsWith("%") ? parseFloat(n) / 100 * t : parseFloat(n) || 0;
36
+ };
37
+ return [
38
+ n(e.borderTopLeftRadius),
39
+ n(e.borderTopRightRadius),
40
+ n(e.borderBottomRightRadius),
41
+ n(e.borderBottomLeftRadius)
42
+ ];
43
+ }
44
+ function b(e, t) {
45
+ return e.map((e) => {
46
+ let n = t === "%" ? /\s+(-?[\d.]+)%$/.exec(e) : /\s+(-?[\d.]+)(deg|turn|%)$/.exec(e);
47
+ if (!n) return {
48
+ color: e.trim(),
49
+ pos: null
50
+ };
51
+ let r = parseFloat(n[1]);
52
+ return t === "deg" ? r = n[2] === "deg" ? r / 360 : n[2] === "turn" ? r : r / 100 : r /= 100, {
53
+ color: e.slice(0, n.index).trim(),
54
+ pos: r
55
+ };
56
+ });
57
+ }
58
+ function x(e) {
59
+ let t = e.map((e) => ({ ...e }));
60
+ t[0].pos === null && (t[0].pos = 0), t[t.length - 1].pos === null && (t[t.length - 1].pos = 1);
61
+ let n = 0;
62
+ for (; n < t.length;) if (t[n].pos === null) {
63
+ let e = n;
64
+ for (; t[e].pos === null;) e++;
65
+ let r = t[n - 1].pos, i = t[e].pos;
66
+ for (let a = n; a < e; a++) t[a].pos = r + (i - r) * (a - n + 1) / (e - n + 1);
67
+ n = e;
68
+ } else n++;
69
+ let r = 0;
70
+ for (let e of t) e.pos = Math.max(r, e.pos), r = e.pos;
71
+ return t;
72
+ }
73
+ function S(e, t, n) {
74
+ let r = e.trim().split(/\s+/).filter(Boolean), i = {
75
+ left: 0,
76
+ top: 0,
77
+ center: .5,
78
+ right: 1,
79
+ bottom: 1
80
+ }, a = (e, t) => {
81
+ if (e === void 0) return .5 * t;
82
+ if (e in i) return i[e] * t;
83
+ if (e.endsWith("%")) return parseFloat(e) / 100 * t;
84
+ let n = parseFloat(e);
85
+ return Number.isFinite(n) ? n : .5 * t;
86
+ }, o = r[0], s = r[1];
87
+ return (o === "top" || o === "bottom") && ([o, s] = [s, o]), (s === "left" || s === "right") && ([o, s] = [s, o]), {
88
+ x: a(o, t),
89
+ y: a(s, n)
90
+ };
91
+ }
92
+ function C(e, t, n, r, i = !1) {
93
+ let a = e.defaultView, o = /* @__PURE__ */ new Set(), s = [], c = [], l = 0, u = a.scrollX || 0, C = a.scrollY || 0, w = /* @__PURE__ */ new Map();
94
+ for (let t of Array.from(e.querySelectorAll("*"))) {
95
+ let e = a.getComputedStyle(t);
96
+ if (e.transform && e.transform !== "none") try {
97
+ w.set(t, {
98
+ m: new DOMMatrixReadOnly(e.transform),
99
+ origin: e.transformOrigin
100
+ });
101
+ } catch {}
102
+ }
103
+ let T = e.createElement("style");
104
+ T.textContent = "*,*::before,*::after{transform:none!important;translate:none!important;rotate:none!important;scale:none!important}", w.size && (e.head.appendChild(T), e.body.offsetHeight);
105
+ let E = 0, D = (e) => E > 0 || e.right + u > t.x && e.left + u < t.x + t.width && e.bottom + C > t.y && e.top + C < t.y + t.height, O = /* @__PURE__ */ new Map(), k = (e) => {
106
+ let t = Math.round(e * 10) / 10, n = O.get(t);
107
+ return n || (n = `f${++l}`, O.set(t, n), s.push(`<filter id="${n}" x="-60%" y="-60%" width="220%" height="220%"><feGaussianBlur stdDeviation="${f(t)}"/></filter>`)), n;
108
+ }, ee = (e) => e.map((e) => `<stop offset="${f(e.pos * 100)}%" stop-color="${d(e.color)}"/>`).join(""), te = (e, t) => {
109
+ let n = e.trim();
110
+ if (/^repeating-/.test(n)) return null;
111
+ let r = /^linear-gradient\((.*)\)$/s.exec(n);
112
+ if (r) {
113
+ let e = m(r[1]), n = 180, i = e[0];
114
+ if (/^-?[\d.]+(deg|turn|rad|grad)$/.test(i)) {
115
+ let t = parseFloat(i);
116
+ n = i.endsWith("turn") ? t * 360 : i.endsWith("rad") ? t * 180 / Math.PI : i.endsWith("grad") ? t * .9 : t, e.shift();
117
+ } else i.startsWith("to ") && (n = {
118
+ top: 0,
119
+ right: 90,
120
+ bottom: 180,
121
+ left: 270,
122
+ "top right": 45,
123
+ "right top": 45,
124
+ "bottom right": 135,
125
+ "right bottom": 135,
126
+ "bottom left": 225,
127
+ "left bottom": 225,
128
+ "top left": 315,
129
+ "left top": 315
130
+ }[i.slice(3).trim()] ?? 180, e.shift());
131
+ if (e.length < 2) return null;
132
+ let a = x(b(e, "%")), o = n * Math.PI / 180, c = Math.sin(o), u = -Math.cos(o), d = Math.abs(t.width * c) + Math.abs(t.height * u), p = t.x + t.width / 2, h = t.y + t.height / 2, g = `g${++l}`;
133
+ return s.push(`<linearGradient id="${g}" gradientUnits="userSpaceOnUse" x1="${f(p - c * d / 2)}" y1="${f(h - u * d / 2)}" x2="${f(p + c * d / 2)}" y2="${f(h + u * d / 2)}">${ee(a)}</linearGradient>`), `url(#${g})`;
134
+ }
135
+ let i = /^radial-gradient\((.*)\)$/s.exec(n);
136
+ if (i) {
137
+ let e = m(i[1]), n = !1, r = !1, a = "center";
138
+ if (/(circle|ellipse|closest|farthest|\bat\b)/.test(e[0]) && !/^(rgb|#)/.test(e[0])) {
139
+ let t = e.shift();
140
+ n = /\bcircle\b/.test(t), r = /closest-side|closest-corner/.test(t);
141
+ let i = /\bat\s+(.+)$/.exec(t);
142
+ i && (a = i[1]);
143
+ }
144
+ if (e.length < 2) return null;
145
+ let o = x(b(e, "%")), c = S(a, t.width, t.height), u = t.x + c.x, d = t.y + c.y, p = c.x, h = t.width - c.x, g = c.y, _ = t.height - c.y, v, y;
146
+ r ? (v = Math.min(p, h), y = Math.min(g, _)) : (v = Math.max(p, h) * (n ? 1 : Math.SQRT2), y = Math.max(g, _) * (n ? 1 : Math.SQRT2)), n && (v = y = r ? Math.min(p, h, g, _) : Math.hypot(Math.max(p, h), Math.max(g, _)));
147
+ let C = v ? y / v : 1, w = `g${++l}`;
148
+ return s.push(`<radialGradient id="${w}" gradientUnits="userSpaceOnUse" cx="${f(u)}" cy="${f(d)}" r="${f(Math.max(1, v))}" gradientTransform="translate(${f(u)} ${f(d)}) scale(1 ${f(C)}) translate(${f(-u)} ${f(-d)})">${ee(o)}</radialGradient>`), `url(#${w})`;
149
+ }
150
+ return null;
151
+ }, A = (e, t, n) => {
152
+ let r = /^conic-gradient\((.*)\)$/s.exec(e.trim());
153
+ if (!r) return "";
154
+ let i = m(r[1]), a = 0, o = "center";
155
+ if (/^(from|at)\b/.test(i[0])) {
156
+ let e = i.shift(), t = /from\s+(-?[\d.]+)deg/.exec(e);
157
+ t && (a = parseFloat(t[1]));
158
+ let n = /\bat\s+(.+)$/.exec(e);
159
+ n && (o = n[1]);
160
+ }
161
+ if (i.length < 2) return "";
162
+ let c = x(b(i, "deg")), u = c.map((e) => h(e.color));
163
+ if (u.some((e) => !e)) return "";
164
+ let d = S(o, t.width, t.height), p = t.x + d.x, v = t.y + d.y, y = Math.hypot(t.width, t.height), C = (e) => {
165
+ for (let t = 1; t < c.length; t++) if (e <= c[t].pos || t === c.length - 1) {
166
+ let n = c[t - 1].pos, r = c[t].pos;
167
+ return _(u[t - 1], u[t], r === n ? 1 : Math.min(1, Math.max(0, (e - n) / (r - n))));
168
+ }
169
+ return u[0];
170
+ }, w = `c${++l}`;
171
+ s.push(`<clipPath id="${w}"><path d="${n}"/></clipPath>`);
172
+ let T = (e) => {
173
+ let t = (e + a - 90) * Math.PI / 180;
174
+ return `${f(p + y * Math.cos(t))} ${f(v + y * Math.sin(t))}`;
175
+ }, E = [];
176
+ for (let e = 0; e < 120; e++) E.push(`<path d="M${f(p)} ${f(v)}L${T(e / 120 * 360)}L${T((e + 1) / 120 * 360 + .6)}Z" fill="${g(C((e + .5) / 120))}"/>`);
177
+ return `<g clip-path="url(#${w})">${E.join("")}</g>`;
178
+ }, j = (t, n, r, i, a, c) => {
179
+ if (!t || t === "none") return "";
180
+ let u = te(t, n);
181
+ if (u) return `<path d="${r}" fill="${u}"/>`;
182
+ if (/^conic-gradient/.test(t.trim())) return A(t, n, r);
183
+ if (/^repeating-/.test(t.trim())) return o.add("Repeating gradient stripes are drawn as one smooth gradient in an SVG."), "";
184
+ let p = /^url\(\s*["']?(.*?)["']?\s*\)$/s.exec(t.trim());
185
+ if (!p) return "";
186
+ let m = p[1], h = 0, g = 0, _ = Array.from(e.querySelectorAll("img")).find((e) => e.getAttribute("src") === m);
187
+ if (_?.naturalWidth) h = _.naturalWidth, g = _.naturalHeight;
188
+ else {
189
+ let e = m.startsWith("data:") ? (() => {
190
+ try {
191
+ return decodeURIComponent(m.slice(0, 1200));
192
+ } catch {
193
+ return "";
194
+ }
195
+ })() : "", t = /viewBox=['"]?\s*[\d.]+\s+[\d.]+\s+([\d.]+)\s+([\d.]+)/.exec(e), n = /<svg[^>]*\swidth=['"]?([\d.]+)(?:px)?['"]?[^>]*\sheight=['"]?([\d.]+)(?:px)?/.exec(e) ?? t;
196
+ n && (h = parseFloat(n[1]), g = parseFloat(n[2]));
197
+ }
198
+ let v = n.width, y = n.height;
199
+ if (i === "cover" && h) {
200
+ let e = Math.max(n.width / h, n.height / g);
201
+ v = h * e, y = g * e;
202
+ } else if (i === "contain" && h) {
203
+ let e = Math.min(n.width / h, n.height / g);
204
+ v = h * e, y = g * e;
205
+ } else if (i && i !== "auto" && i !== "cover" && i !== "contain") {
206
+ let [e, t] = i.split(/\s+/), r = (e, t) => !e || e === "auto" ? null : e.endsWith("%") ? parseFloat(e) / 100 * t : parseFloat(e), a = r(e, n.width), o = r(t, n.height);
207
+ v = a ?? (o && h ? o * h / g : h || n.width), y = o ?? (a && h ? a * g / h : g || n.height);
208
+ } else h && (v = h, y = g);
209
+ let b = S(a || "0% 0%", n.width - v, n.height - y), x = `c${++l}`;
210
+ if (s.push(`<clipPath id="${x}"><path d="${r}"/></clipPath>`), c && c !== "no-repeat") {
211
+ let e = `p${++l}`;
212
+ return s.push(`<pattern id="${e}" patternUnits="userSpaceOnUse" x="${f(n.x + b.x)}" y="${f(n.y + b.y)}" width="${f(c === "repeat-y" ? n.width + v : v)}" height="${f(c === "repeat-x" ? n.height + y : y)}"><image href="${d(m)}" width="${f(v)}" height="${f(y)}" preserveAspectRatio="none"/></pattern>`), `<path d="${r}" fill="url(#${e})"/>`;
213
+ }
214
+ return `<image href="${d(m)}" x="${f(n.x + b.x)}" y="${f(n.y + b.y)}" width="${f(v)}" height="${f(y)}" preserveAspectRatio="none" clip-path="url(#${x})"/>`;
215
+ }, M = (t) => {
216
+ let n = t.data, r = e.createRange(), i = [], a = /\S+/g, o;
217
+ for (; o = a.exec(n);) {
218
+ r.setStart(t, o.index), r.setEnd(t, o.index + o[0].length);
219
+ let e = Array.from(r.getClientRects()).filter((e) => e.width > 0 || e.height > 0);
220
+ if (e.length) if (e.length === 1) {
221
+ let t = e[0];
222
+ i.push({
223
+ text: o[0],
224
+ l: t.left,
225
+ r: t.right,
226
+ t: t.top,
227
+ b: t.bottom,
228
+ glue: !1
229
+ });
230
+ } else for (let e = 0; e < o[0].length; e++) {
231
+ r.setStart(t, o.index + e), r.setEnd(t, o.index + e + 1);
232
+ let n = r.getClientRects()[0];
233
+ n && i.push({
234
+ text: o[0][e],
235
+ l: n.left,
236
+ r: n.right,
237
+ t: n.top,
238
+ b: n.bottom,
239
+ glue: e > 0
240
+ });
241
+ }
242
+ }
243
+ let s = [];
244
+ for (let e of i) {
245
+ let t = s[s.length - 1], n = t?.[t.length - 1];
246
+ n && Math.abs(e.t - n.t) < (n.b - n.t) * .5 ? t.push(e) : s.push([e]);
247
+ }
248
+ return s.map((e) => ({
249
+ text: e.map((e, t) => (t === 0 || e.glue ? "" : " ") + e.text).join(""),
250
+ l: Math.min(...e.map((e) => e.l)),
251
+ r: Math.max(...e.map((e) => e.r)),
252
+ t: Math.min(...e.map((e) => e.t)),
253
+ b: Math.max(...e.map((e) => e.b))
254
+ }));
255
+ }, ne = (e, t) => [
256
+ `font-family="${d(e.fontFamily)}"`,
257
+ `font-size="${f(parseFloat(e.fontSize))}"`,
258
+ `font-weight="${d(e.fontWeight)}"`,
259
+ e.fontStyle === "normal" ? "" : `font-style="${d(e.fontStyle)}"`,
260
+ `fill="${d(t)}"`,
261
+ e.letterSpacing === "normal" ? "" : `letter-spacing="${f(parseFloat(e.letterSpacing) || 0)}"`,
262
+ e.textDecorationLine && e.textDecorationLine !== "none" ? `text-decoration="${d(e.textDecorationLine)}"` : ""
263
+ ].filter(Boolean).join(" "), N = (e, t, n, r, i, a, o) => {
264
+ let s = i.textTransform, l = s === "uppercase" ? e.toUpperCase() : s === "lowercase" ? e.toLowerCase() : s === "capitalize" ? e.replace(/\b\p{L}/gu, (e) => e.toUpperCase()) : e, u = ne(i, a), h = o ? "text-anchor=\"end\"" : r > 0 ? `textLength="${f(r)}" lengthAdjust="spacing"` : "";
265
+ if (i.textShadow && i.textShadow !== "none") for (let e of m(i.textShadow).reverse()) {
266
+ let r = /(rgba?\([^)]*\)|#[0-9a-f]{3,8})/i.exec(e), [i = 0, a = 0, o = 0] = e.replace(r?.[0] ?? "", "").match(/-?[\d.]+px/g)?.map((e) => parseFloat(e)) ?? [];
267
+ r && !p(r[1]) && c.push(`<text x="${f(t + i)}" y="${f(n + a)}" dominant-baseline="central" xml:space="preserve" ${h} ${u.replace(/fill="[^"]*"/, `fill="${d(r[1])}"`)}${o ? ` filter="url(#${k(o / 2)})"` : ""}>${d(l)}</text>`);
268
+ }
269
+ c.push(`<text x="${f(t)}" y="${f(n)}" dominant-baseline="central" xml:space="preserve" ${h} ${u}>${d(l)}</text>`);
270
+ }, re = (e, n, r) => {
271
+ if (!e.data.trim()) return;
272
+ let i = r ?? n.color;
273
+ for (let r of M(e)) (E > 0 || r.r + u > t.x && r.l + u < t.x + t.width && r.b + C > t.y && r.t + C < t.y + t.height) && N(r.text, r.l + u, (r.t + r.b) / 2 + C, r.r - r.l, n, i);
274
+ }, ie = (e, t, n, r, i) => {
275
+ if (!e.boxShadow || e.boxShadow === "none") return;
276
+ let a = m(e.boxShadow).filter((e) => /\binset\b/.test(e) === i);
277
+ for (let e of i ? a : a.reverse()) {
278
+ let a = /(rgba?\([^)]*\)|#[0-9a-f]{3,8})/i.exec(e), [o = 0, u = 0, m = 0, h = 0] = e.replace(a?.[0] ?? "", "").match(/-?[\d.]+px/g)?.map((e) => parseFloat(e)) ?? [];
279
+ if (!(!a || p(a[1]))) if (i) {
280
+ let e = Math.abs(o) + Math.abs(u) + m * 3 + Math.abs(h) + 20, i = v(t.x + o + h, t.y + u + h, t.width - h * 2, t.height - h * 2, n.map((e) => Math.max(0, e - h))), p = `c${++l}`;
281
+ s.push(`<clipPath id="${p}"><path d="${r}"/></clipPath>`), c.push(`<g clip-path="url(#${p})"><path d="M${f(t.x - e)} ${f(t.y - e)}H${f(t.x + t.width + e)}V${f(t.y + t.height + e)}H${f(t.x - e)}Z${i}" fill-rule="evenodd" fill="${d(a[1])}"${m ? ` filter="url(#${k(m / 2)})"` : ""}/></g>`);
282
+ } else {
283
+ let e = v(t.x + o - h, t.y + u - h, t.width + h * 2, t.height + h * 2, n.map((e) => Math.max(0, e + h)));
284
+ c.push(`<path d="${e}" fill="${d(a[1])}"${m ? ` filter="url(#${k(m / 2)})"` : ""}/>`);
285
+ }
286
+ }
287
+ }, P = (e) => {
288
+ c.push(`<rect x="${f(e.x)}" y="${f(e.y)}" width="${f(e.width)}" height="${f(e.height)}" fill="#e5e7eb"/>`);
289
+ let t = Math.min(e.width, e.height) * .22, n = e.x + e.width / 2, r = e.y + e.height / 2;
290
+ c.push(`<path d="M${f(n - t * .4)} ${f(r - t * .55)}L${f(n + t * .6)} ${f(r)}L${f(n - t * .4)} ${f(r + t * .55)}Z" fill="#9ca3af"/>`);
291
+ }, ae = (e, t, n, r) => {
292
+ let i = (e.getAttribute("type") || "text").toLowerCase();
293
+ if (i === "checkbox" || i === "radio") {
294
+ let t = Math.min(n.width, n.height), r = n.x + n.width / 2, a = n.y + n.height / 2, o = i === "radio";
295
+ c.push(o ? `<circle cx="${f(r)}" cy="${f(a)}" r="${f(t / 2 - .5)}" fill="#fff" stroke="#6b7280"/>` : `<rect x="${f(r - t / 2 + .5)}" y="${f(a - t / 2 + .5)}" width="${f(t - 1)}" height="${f(t - 1)}" rx="3" fill="#fff" stroke="#6b7280"/>`), e.checked && c.push(o ? `<circle cx="${f(r)}" cy="${f(a)}" r="${f(t / 4)}" fill="#2563eb"/>` : `<path d="M${f(r - t * .28)} ${f(a)}L${f(r - t * .08)} ${f(a + t * .22)}L${f(r + t * .3)} ${f(a - t * .2)}" fill="none" stroke="#2563eb" stroke-width="${f(Math.max(1.5, t / 8))}" stroke-linecap="round" stroke-linejoin="round"/>`);
296
+ return;
297
+ }
298
+ if (i === "hidden" || i === "submit" || i === "button" || i === "file") return;
299
+ let a = "", o = !1;
300
+ if (e.tagName === "SELECT" ? a = e.selectedOptions[0]?.textContent ?? "" : (a = i === "password" ? "•".repeat(e.value.length) : e.value, a || (a = e.getAttribute("placeholder") ?? "", o = !0)), !a) return;
301
+ let u = parseFloat(t.paddingLeft) + parseFloat(t.borderLeftWidth), d = parseFloat(t.paddingTop) + parseFloat(t.borderTopWidth), p = parseFloat(t.lineHeight) || parseFloat(t.fontSize) * 1.25, m = `c${++l}`;
302
+ if (s.push(`<clipPath id="${m}"><path d="${r}"/></clipPath>`), c.push(`<g clip-path="url(#${m})">`), (e.tagName === "TEXTAREA" ? a.split("\n") : [a]).slice(0, 40).forEach((r, i) => {
303
+ let a = e.tagName === "TEXTAREA" ? n.y + d + p * (i + .5) : n.y + n.height / 2;
304
+ N(r, n.x + u, a, 0, t, o ? "#6b7280" : t.color);
305
+ }), c.push("</g>"), e.tagName === "SELECT") {
306
+ let e = n.x + n.width - 14, t = n.y + n.height / 2;
307
+ c.push(`<path d="M${f(e - 4)} ${f(t - 2)}L${f(e)} ${f(t + 2)}L${f(e + 4)} ${f(t - 2)}" fill="none" stroke="#6b7280" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>`);
308
+ }
309
+ }, oe = (t, n, r, i) => {
310
+ let a = {
311
+ x: r.left + u,
312
+ y: r.top + C,
313
+ width: r.width,
314
+ height: r.height
315
+ };
316
+ if (a.width <= 0 || a.height <= 0) return;
317
+ let h = y(n, a.width), g = v(a.x, a.y, a.width, a.height, h);
318
+ if (ie(n, a, h, g, !1), !i && !p(n.backgroundColor) && c.push(`<path d="${g}" fill="${d(n.backgroundColor)}"/>`), !i && n.backgroundImage && n.backgroundImage !== "none") {
319
+ let e = m(n.backgroundImage), t = m(n.backgroundSize || "auto"), r = m(n.backgroundPosition || "0% 0%"), i = m(n.backgroundRepeat || "repeat");
320
+ for (let n = e.length - 1; n >= 0; n--) {
321
+ let o = j(e[n], a, g, t[n % t.length], r[n % r.length], i[n % i.length]);
322
+ o && c.push(o);
323
+ }
324
+ }
325
+ ie(n, a, h, g, !0);
326
+ let _ = [
327
+ {
328
+ w: parseFloat(n.borderTopWidth),
329
+ c: n.borderTopColor,
330
+ s: n.borderTopStyle
331
+ },
332
+ {
333
+ w: parseFloat(n.borderRightWidth),
334
+ c: n.borderRightColor,
335
+ s: n.borderRightStyle
336
+ },
337
+ {
338
+ w: parseFloat(n.borderBottomWidth),
339
+ c: n.borderBottomColor,
340
+ s: n.borderBottomStyle
341
+ },
342
+ {
343
+ w: parseFloat(n.borderLeftWidth),
344
+ c: n.borderLeftColor,
345
+ s: n.borderLeftStyle
346
+ }
347
+ ], b = _.filter((e) => e.w > 0 && e.s !== "none" && e.s !== "hidden" && !p(e.c));
348
+ if (b.length === 4 && _.every((e) => e.w === _[0].w && e.c === _[0].c && e.s === _[0].s)) {
349
+ let e = _[0].w, t = v(a.x + e / 2, a.y + e / 2, a.width - e, a.height - e, h.map((t) => Math.max(0, t - e / 2))), n = _[0].s === "dashed" ? ` stroke-dasharray="${f(e * 3)} ${f(e * 2)}"` : _[0].s === "dotted" ? ` stroke-dasharray="0 ${f(e * 2)}" stroke-linecap="round"` : "";
350
+ c.push(`<path d="${t}" fill="none" stroke="${d(_[0].c)}" stroke-width="${f(e)}"${n}/>`);
351
+ } else if (b.length) {
352
+ let [e, t, n, r] = _, i = [
353
+ [
354
+ e,
355
+ a.x,
356
+ a.y,
357
+ a.width,
358
+ e.w
359
+ ],
360
+ [
361
+ t,
362
+ a.x + a.width - t.w,
363
+ a.y,
364
+ t.w,
365
+ a.height
366
+ ],
367
+ [
368
+ n,
369
+ a.x,
370
+ a.y + a.height - n.w,
371
+ a.width,
372
+ n.w
373
+ ],
374
+ [
375
+ r,
376
+ a.x,
377
+ a.y,
378
+ r.w,
379
+ a.height
380
+ ]
381
+ ], o = `c${++l}`;
382
+ s.push(`<clipPath id="${o}"><path d="${g}"/></clipPath>`), c.push(`<g clip-path="url(#${o})">`);
383
+ for (let [e, t, n, r, a] of i) e.w > 0 && e.s !== "none" && !p(e.c) && c.push(`<rect x="${f(t)}" y="${f(n)}" width="${f(r)}" height="${f(a)}" fill="${d(e.c)}"/>`);
384
+ c.push("</g>");
385
+ }
386
+ let x = t.tagName.toLowerCase(), S = () => {
387
+ let e = `c${++l}`;
388
+ return s.push(`<clipPath id="${e}"><path d="${g}"/></clipPath>`), e;
389
+ }, w = () => {
390
+ let e = n.objectFit;
391
+ if (e === "fill") return "none";
392
+ let [t = "50%", r = "50%"] = n.objectPosition.split(/\s+/), i = (e, t, n, r) => {
393
+ let i = e.endsWith("%") ? parseFloat(e) : e === "left" || e === "top" ? 0 : e === "right" || e === "bottom" ? 100 : 50;
394
+ return i <= 25 ? t : i >= 75 ? r : n;
395
+ };
396
+ return `x${i(t, "Min", "Mid", "Max")}Y${i(r, "Min", "Mid", "Max")} ${e === "contain" || e === "scale-down" ? "meet" : "slice"}`;
397
+ };
398
+ if (x === "img") {
399
+ let e = t.getAttribute("src");
400
+ e && c.push(`<image href="${d(e)}" x="${f(a.x)}" y="${f(a.y)}" width="${f(a.width)}" height="${f(a.height)}" preserveAspectRatio="${w()}" clip-path="url(#${S()})"/>`);
401
+ } else if (x === "video") {
402
+ let n = null;
403
+ try {
404
+ let r = t;
405
+ if (r.videoWidth) {
406
+ let t = e.createElement("canvas");
407
+ t.width = r.videoWidth, t.height = r.videoHeight, t.getContext("2d").drawImage(r, 0, 0), n = t.toDataURL("image/jpeg", .85);
408
+ }
409
+ } catch {}
410
+ n ? c.push(`<image href="${n}" x="${f(a.x)}" y="${f(a.y)}" width="${f(a.width)}" height="${f(a.height)}" preserveAspectRatio="${w()}" clip-path="url(#${S()})"/>`) : P(a);
411
+ } else x === "iframe" || x === "object" || x === "embed" || x === "canvas" ? (P(a), o.add("Videos and maps embedded from other sites cannot be copied into an SVG, so they appear as a grey box with a play mark.")) : (x === "input" || x === "textarea" || x === "select") && ae(t, n, a, g);
412
+ }, se = (t, n) => {
413
+ let r = n.listStyleType;
414
+ if (!r || r === "none") return;
415
+ let i = e.createTreeWalker(t, NodeFilter.SHOW_TEXT, { acceptNode: (e) => (e.nodeValue ?? "").trim() ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT }).nextNode();
416
+ if (!i) return;
417
+ let a = M(i)[0];
418
+ if (!a) return;
419
+ let o = parseFloat(n.fontSize), s = (a.t + a.b) / 2 + C, l = a.l + u;
420
+ if (r === "disc" || r === "circle" || r === "square") {
421
+ let e = o * .28, t = l - o * .85;
422
+ c.push(r === "square" ? `<rect x="${f(t - e / 2)}" y="${f(s - e / 2)}" width="${f(e)}" height="${f(e)}" fill="${d(n.color)}"/>` : `<circle cx="${f(t)}" cy="${f(s)}" r="${f(e / 2)}" ${r === "circle" ? `fill="none" stroke="${d(n.color)}"` : `fill="${d(n.color)}"`}/>`);
423
+ return;
424
+ }
425
+ let p = t.parentElement, m = p ? Array.from(p.children).filter((e) => e.tagName === "LI").indexOf(t) + (parseInt(p.getAttribute("start") ?? "1", 10) || 1) : 1, h = r.startsWith("lower-alpha") || r === "lower-latin" ? String.fromCharCode(96 + m) : r.startsWith("upper-alpha") || r === "upper-latin" ? String.fromCharCode(64 + m) : String(m);
426
+ N(`${h}.`, l - o * .4, s, 0, n, n.color, "end");
427
+ }, ce = (e) => {
428
+ let t = e.tagName.toLowerCase();
429
+ if (t === "script" || t === "style" || t === "link" || t === "meta" || t === "noscript" || t === "template") return;
430
+ let n = a.getComputedStyle(e);
431
+ if (n.display === "none" || n.visibility === "hidden") return;
432
+ let r = e.getBoundingClientRect(), i = 0, p = (e) => {
433
+ c.push(`<g ${e}>`), i++;
434
+ }, h = w.get(e);
435
+ if (h) {
436
+ let [e, t] = h.origin.split(/\s+/).map((e) => parseFloat(e) || 0), n = r.left + u + e, i = r.top + C + t, a = h.m;
437
+ p(`transform="translate(${f(n)} ${f(i)}) matrix(${[
438
+ a.a,
439
+ a.b,
440
+ a.c,
441
+ a.d,
442
+ a.e,
443
+ a.f
444
+ ].map(f).join(" ")}) translate(${f(-n)} ${f(-i)})"`), E++;
445
+ }
446
+ let g = parseFloat(n.opacity), _ = [];
447
+ if (n.filter && n.filter !== "none" && _.push(`filter:${n.filter}`), n.mixBlendMode && n.mixBlendMode !== "normal" && _.push(`mix-blend-mode:${n.mixBlendMode}`), n.clipPath && n.clipPath !== "none" && _.push(`clip-path:${n.clipPath}`), (g < 1 || _.length) && p(`${g < 1 ? `opacity="${f(g)}" ` : ""}${_.length ? `style="${d(_.join(";"))}"` : ""}`.trim()), n.backdropFilter && n.backdropFilter !== "none" && !/^blur\(0/.test(n.backdropFilter) && o.add("Frosted-glass blur behind a box cannot be drawn in an SVG, so those boxes show without the blur."), t === "svg") {
448
+ if (D(r)) {
449
+ let t = e.cloneNode(!0);
450
+ t.setAttribute("x", f(r.left + u)), t.setAttribute("y", f(r.top + C)), t.setAttribute("width", f(r.width)), t.setAttribute("height", f(r.height)), t.getAttribute("xmlns") || t.setAttribute("xmlns", "http://www.w3.org/2000/svg"), c.push(`<g color="${d(n.color)}">${new XMLSerializer().serializeToString(t)}</g>`);
451
+ }
452
+ } else {
453
+ let i = /text/.test(n.webkitBackgroundClip || n.backgroundClip || "") && n.backgroundImage !== "none", a = null;
454
+ i && (a = te(m(n.backgroundImage)[0], {
455
+ x: r.left + u,
456
+ y: r.top + C,
457
+ width: r.width,
458
+ height: r.height
459
+ })), D(r) && oe(e, n, r, !!a || e === F);
460
+ let o = n.overflowX !== "visible" || n.overflowY !== "visible";
461
+ if (o && r.width > 0 && r.height > 0) {
462
+ let e = `c${++l}`;
463
+ s.push(`<clipPath id="${e}"><path d="${v(r.left + u, r.top + C, r.width, r.height, y(n, r.width))}"/></clipPath>`), c.push(`<g clip-path="url(#${e})">`);
464
+ }
465
+ if (n.display === "list-item" && se(e, n), t !== "img" && t !== "input" && t !== "textarea" && t !== "select" && t !== "video" && t !== "iframe") for (let t of Array.from(e.childNodes)) t.nodeType === 3 ? re(t, n, a) : t.nodeType === 1 && ce(t);
466
+ o && r.width > 0 && r.height > 0 && c.push("</g>");
467
+ }
468
+ h && E--;
469
+ for (let e = 0; e < i; e++) c.push("</g>");
470
+ }, F = null;
471
+ if (i && (F = [e.documentElement, e.body].find((e) => {
472
+ let t = a.getComputedStyle(e);
473
+ return !p(t.backgroundColor) || t.backgroundImage && t.backgroundImage !== "none";
474
+ }) ?? null, F)) {
475
+ let e = a.getComputedStyle(F), n = {
476
+ x: t.x,
477
+ y: t.y,
478
+ width: t.width,
479
+ height: t.height
480
+ }, r = v(n.x, n.y, n.width, n.height, [
481
+ 0,
482
+ 0,
483
+ 0,
484
+ 0
485
+ ]);
486
+ if (p(e.backgroundColor) || c.push(`<path d="${r}" fill="${d(e.backgroundColor)}"/>`), e.backgroundImage && e.backgroundImage !== "none") {
487
+ let t = m(e.backgroundImage), i = m(e.backgroundSize || "auto"), a = m(e.backgroundPosition || "0% 0%"), o = m(e.backgroundRepeat || "repeat");
488
+ for (let e = t.length - 1; e >= 0; e--) {
489
+ let s = j(t[e], n, r, i[e % i.length], a[e % a.length], o[e % o.length]);
490
+ s && c.push(s);
491
+ }
492
+ }
493
+ }
494
+ for (let e of n) ce(e);
495
+ T.remove();
496
+ let le = (r.match(/@font-face\s*\{[^}]*\}/g) ?? []).join("\n"), I = t.width, ue = t.height;
497
+ return {
498
+ svg: `<svg xmlns="http://www.w3.org/2000/svg" width="${I}" height="${ue}" viewBox="0 0 ${I} ${ue}">${le ? `<style>${le.replace(/</g, "\\3c ")}</style>` : ""}<defs>${s.join("")}</defs><g transform="translate(${f(-t.x)} ${f(-t.y)})">${c.join("")}</g></svg>`,
499
+ warnings: [...o]
500
+ };
501
+ }
502
+ //#endregion
503
+ //#region src/v2/files/capture.ts
504
+ var w = (e) => new Promise((t) => setTimeout(t, e)), T = () => new Promise((e) => requestAnimationFrame(() => e())), E = /* @__PURE__ */ new Map();
505
+ async function D(e) {
506
+ if (e.startsWith("data:")) return e;
507
+ let t = E.get(e);
508
+ return t || (t = (async () => {
509
+ try {
510
+ let t = await fetch(e, {
511
+ mode: "cors",
512
+ credentials: "omit"
513
+ });
514
+ if (!t.ok) return null;
515
+ let n = await t.blob();
516
+ return await new Promise((e) => {
517
+ let t = new FileReader();
518
+ t.onload = () => e(typeof t.result == "string" ? t.result : null), t.onerror = () => e(null), t.readAsDataURL(n);
519
+ });
520
+ } catch {
521
+ return null;
522
+ }
523
+ })(), E.set(e, t)), t;
524
+ }
525
+ var O = (e) => {
526
+ try {
527
+ return new URL(e, window.location.href).href;
528
+ } catch {
529
+ return e;
530
+ }
531
+ };
532
+ async function k(e, t) {
533
+ let n = /url\(\s*(['"]?)([^'")]+)\1\s*\)/g, r = /* @__PURE__ */ new Set();
534
+ for (let t of e.matchAll(n)) !t[2].startsWith("data:") && !t[2].startsWith("#") && r.add(t[2]);
535
+ let i = /* @__PURE__ */ new Map();
536
+ return await Promise.all([...r].map(async (e) => i.set(e, await D(O(e))))), e.replace(n, (e, n, r) => {
537
+ if (r.startsWith("data:") || r.startsWith("#")) return e;
538
+ let a = i.get(r);
539
+ return a ? `url("${a}")` : (t.add(r), "none");
540
+ });
541
+ }
542
+ function ee(e, t) {
543
+ let n = /* @__PURE__ */ new Set();
544
+ for (let e of t) n.add(e.codePointAt(0));
545
+ let r = (e) => e.split(",").some((e) => {
546
+ let t = /U\+([0-9A-F?]+)(?:-([0-9A-F]+))?/i.exec(e.trim());
547
+ if (!t) return !1;
548
+ let r = parseInt(t[1].replace(/\?/g, "0"), 16), i = t[2] ? parseInt(t[2], 16) : t[1].includes("?") ? parseInt(t[1].replace(/\?/g, "F"), 16) : r;
549
+ for (let e of n) if (e >= r && e <= i) return !0;
550
+ return !1;
551
+ });
552
+ return e.replace(/@font-face\s*\{[^}]*\}/g, (e) => {
553
+ let t = /unicode-range\s*:\s*([^;}]+)/i.exec(e);
554
+ return !t || r(t[1]) ? e : "";
555
+ });
556
+ }
557
+ async function te(e) {
558
+ let t = [], n = document.createElement("iframe");
559
+ n.setAttribute("sandbox", "allow-same-origin"), n.setAttribute("aria-hidden", "true"), n.tabIndex = -1, n.style.cssText = `position:fixed;left:-100000px;top:0;width:${Math.round(e.width)}px;height:900px;border:0;visibility:hidden;pointer-events:none`;
560
+ let r = () => n.remove();
561
+ try {
562
+ let i = e.document.replace(/loading="lazy"/g, "loading=\"eager\"").replace(/<\/head>/i, "<style>*,*::before,*::after{animation:none!important;transition:none!important}.plx-in{opacity:1!important;transform:none!important}</style></head>");
563
+ await new Promise((e) => {
564
+ n.onload = () => e(), n.srcdoc = i, document.body.appendChild(n);
565
+ });
566
+ let a = n.contentDocument, o = n.contentWindow;
567
+ if (!a || !o) throw Error("Could not prepare the page for export.");
568
+ let s = /* @__PURE__ */ new Set(), c = [];
569
+ for (let e of Array.from(a.querySelectorAll("link[rel~=\"stylesheet\"][href]"))) {
570
+ let t = O(e.getAttribute("href") ?? "");
571
+ try {
572
+ let e = await fetch(t, {
573
+ mode: "cors",
574
+ credentials: "omit"
575
+ });
576
+ e.ok ? c.push(await e.text()) : s.add(t);
577
+ } catch {
578
+ s.add(t);
579
+ }
580
+ e.remove();
581
+ }
582
+ for (let e of Array.from(a.querySelectorAll("style"))) c.push(e.textContent ?? ""), e.remove();
583
+ let l = a.body.textContent ?? "", u = await k(ee(c.join("\n"), l), s), d = a.createElement("style");
584
+ d.textContent = u, a.head.appendChild(d);
585
+ for (let e of Array.from(a.querySelectorAll("[style*=\"url(\"]"))) e.setAttribute("style", await k(e.getAttribute("style") ?? "", s));
586
+ let f = Array.from(a.images);
587
+ await Promise.all(f.map(async (e) => {
588
+ let t = e.getAttribute("src") ?? "";
589
+ if (e.removeAttribute("srcset"), !t || t.startsWith("data:")) return;
590
+ let n = await D(O(t));
591
+ n ? e.setAttribute("src", n) : s.add(t);
592
+ })), await Promise.race([Promise.all(f.map((e) => e.complete ? null : new Promise((t) => {
593
+ e.onload = e.onerror = () => t();
594
+ }))), w(8e3)]), await Promise.race([a.fonts?.ready ?? Promise.resolve(), w(5e3)]), s.size && t.push(`${s.size === 1 ? "1 picture or font" : `${s.size} pictures or fonts`} could not be included because the website hosting ${s.size === 1 ? "it" : "them"} doesn't allow copying, so ${s.size === 1 ? "it appears" : "they appear"} blank or in a standard font. Upload ${s.size === 1 ? "it" : "them"} to your own library to fix that.`);
595
+ let p = Math.max(a.documentElement.scrollHeight, a.body.scrollHeight, 1);
596
+ n.style.height = `${p}px`, await T(), await T();
597
+ let m = o.scrollX || 0, h = o.scrollY || 0, g, _;
598
+ if (e.nodeIds && e.nodeIds.length) {
599
+ let t = e.nodeIds.map((e) => a.querySelector(`[data-plx-node="${e.replace(/["\\]/g, "")}"]`)).filter((e) => !!e);
600
+ if (!t.length) throw Error("That part of the page isn't visible on this screen size, so there is nothing to export. Switch screen size or pick another element.");
601
+ g = t.filter((e) => !t.some((t) => t !== e && t.contains(e)));
602
+ let n = g.map((e) => e.getBoundingClientRect()), r = Math.min(...n.map((e) => e.left)) + m, i = Math.min(...n.map((e) => e.top)) + h, o = Math.max(...n.map((e) => e.right)) + m, s = Math.max(...n.map((e) => e.bottom)) + h;
603
+ _ = {
604
+ x: r,
605
+ y: i,
606
+ width: Math.max(1, o - r),
607
+ height: Math.max(1, s - i)
608
+ };
609
+ } else if (e.fullDocument) g = [a.body], _ = {
610
+ x: 0,
611
+ y: 0,
612
+ width: Math.max(1, Math.round(Math.max(e.width, a.documentElement.scrollWidth, a.body.scrollWidth))),
613
+ height: Math.max(1, Math.ceil(Math.max(a.documentElement.scrollHeight, a.body.scrollHeight)))
614
+ };
615
+ else {
616
+ let t = a.querySelector(".plx-page") ?? a.body, n = t.getBoundingClientRect();
617
+ g = [t], _ = {
618
+ x: 0,
619
+ y: 0,
620
+ width: Math.max(1, Math.round(Math.max(n.right + m, e.width))),
621
+ height: Math.max(1, Math.ceil(n.bottom + h))
622
+ };
623
+ }
624
+ return _ = {
625
+ x: Math.floor(_.x),
626
+ y: Math.floor(_.y),
627
+ width: Math.ceil(_.width),
628
+ height: Math.ceil(_.height)
629
+ }, {
630
+ doc: a,
631
+ crop: _,
632
+ roots: g,
633
+ css: u,
634
+ warnings: t,
635
+ release: r,
636
+ fullDocument: e.fullDocument
637
+ };
638
+ } catch (e) {
639
+ throw r(), e;
640
+ }
641
+ }
642
+ var A = "http://www.w3.org/1999/xhtml";
643
+ function j(e) {
644
+ let { doc: t, crop: n, css: r } = e, i = Math.max(t.documentElement.scrollWidth, n.x + n.width), a = Math.max(t.documentElement.scrollHeight, n.y + n.height), o = t.createElementNS(A, "style"), s;
645
+ if (e.fullDocument) {
646
+ let e = t.defaultView, n = e.getComputedStyle(t.documentElement), c = e.getComputedStyle(t.body);
647
+ o.textContent = `.plx-html{display:flow-root;position:relative}.plx-body{display:block;margin:8px}${((e) => e.replace(/:root/g, ".plx-html").replace(/(^|[^\w.#\-[\]"'=:@])(html|body)(?![\w-])/g, (e, t, n) => `${t}${n === "html" ? ".plx-html" : ".plx-body"}`))(r)}`, s = t.createElementNS(A, "div");
648
+ let l = t.documentElement.getAttribute("style") ?? "";
649
+ s.setAttribute("class", `plx-html ${t.documentElement.getAttribute("class") ?? ""}`.trim());
650
+ let u = M(n.backgroundColor) && n.backgroundImage === "none" && (!M(c.backgroundColor) || c.backgroundImage !== "none") ? `background-color:${c.backgroundColor};background-image:${c.backgroundImage};background-size:${c.backgroundSize};background-position:${c.backgroundPosition};background-repeat:${c.backgroundRepeat};` : "";
651
+ s.setAttribute("style", `${l};width:${i}px;min-height:${a}px;${u}`);
652
+ let d = t.createElementNS(A, "div");
653
+ for (let e of Array.from(t.body.attributes)) e.name !== "class" && !e.name.startsWith("on") && d.setAttribute(e.name, e.value);
654
+ d.setAttribute("class", `plx-body ${t.body.getAttribute("class") ?? ""}`.trim()), u && d.setAttribute("style", `${d.getAttribute("style") ?? ""};background:none`), d.appendChild(o);
655
+ for (let e of Array.from(t.body.childNodes)) {
656
+ if (e.nodeName === "SCRIPT") continue;
657
+ let t = e.cloneNode(!0);
658
+ t instanceof Element && t.querySelectorAll("script").forEach((e) => e.remove()), d.appendChild(t);
659
+ }
660
+ s.appendChild(d);
661
+ } else {
662
+ s = t.createElementNS(A, "div"), s.setAttribute("style", `margin:0;width:${i}px;height:${a}px;position:relative`), o.textContent = r, s.appendChild(o);
663
+ for (let e of Array.from(t.body.childNodes)) {
664
+ if (e.nodeName === "SCRIPT") continue;
665
+ let t = e.cloneNode(!0);
666
+ t instanceof Element && t.querySelectorAll("script").forEach((e) => e.remove()), s.appendChild(t);
667
+ }
668
+ }
669
+ let c = new XMLSerializer().serializeToString(s);
670
+ return `<svg xmlns="http://www.w3.org/2000/svg" width="${n.width}" height="${n.height}" viewBox="${n.x} ${n.y} ${n.width} ${n.height}"><foreignObject x="0" y="0" width="${i}" height="${a}">${c}</foreignObject></svg>`;
671
+ }
672
+ var M = (e) => !e || e === "transparent" || /^rgba?\([^)]*[,/]\s*0(\.0+)?\s*\)$/.test(e.trim());
673
+ function ne(e) {
674
+ return C(e.doc, e.crop, e.roots, e.css, e.fullDocument);
675
+ }
676
+ var N = 16384, re = 12e7;
677
+ async function ie(e, t, n, r, i) {
678
+ let a = [], o = Math.max(.1, r), s = Math.min(N / t, N / n, Math.sqrt(re / (t * n)));
679
+ o > s && (o = Math.max(.1, s), a.push(`This is too large to export at the size you chose, so it was exported at ${Math.round(o * 100) / 100}x instead.`));
680
+ let c = new Image();
681
+ c.decoding = "async";
682
+ let l = new Promise((e, t) => {
683
+ c.onload = () => e(), c.onerror = () => t(/* @__PURE__ */ Error("Your browser could not draw this page as a picture. Try a smaller selection, or export as SVG."));
684
+ });
685
+ c.src = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(e)}`, await l;
686
+ let u = document.createElement("canvas");
687
+ u.width = Math.max(1, Math.round(t * o)), u.height = Math.max(1, Math.round(n * o));
688
+ let d = u.getContext("2d");
689
+ if (!d) throw Error("Your browser could not make the picture.");
690
+ return i && (d.fillStyle = i, d.fillRect(0, 0, u.width, u.height)), d.drawImage(c, 0, 0, u.width, u.height), {
691
+ canvas: u,
692
+ scale: o,
693
+ warnings: a
694
+ };
695
+ }
696
+ function P(e, t, n = .92) {
697
+ return new Promise((r, i) => {
698
+ try {
699
+ e.toBlob((e) => e ? r(e) : i(/* @__PURE__ */ Error("The picture could not be saved.")), t, n);
700
+ } catch {
701
+ i(/* @__PURE__ */ Error("Your browser blocked saving this picture because it includes images from another website. Export as SVG, or upload those images to your library first."));
702
+ }
703
+ });
704
+ }
705
+ //#endregion
706
+ //#region src/v2/files/pdf.ts
707
+ var ae = new TextEncoder(), oe = .75;
708
+ function se(e, t = {}) {
709
+ let n = [], r = [], i = 0, a = (e) => {
710
+ let t = typeof e == "string" ? ae.encode(e) : e;
711
+ n.push(t), i += t.length;
712
+ }, o = (e) => {
713
+ r[e] = i, a(`${e} 0 obj\n`);
714
+ };
715
+ a("%PDF-1.4\n%âãÏÓ\n"), o(1), a("<< /Type /Catalog /Pages 2 0 R >>\nendobj\n");
716
+ let s = e.map((e, t) => `${4 + t * 3} 0 R`).join(" ");
717
+ o(2), a(`<< /Type /Pages /Kids [${s}] /Count ${e.length} >>\nendobj\n`), o(3), a(`<< /Title (${(t.title ?? "Document").replace(/[()\\]/g, "").slice(0, 120)}) /Producer (Plexo) >>\nendobj\n`), e.forEach((e, n) => {
718
+ let r = t.pagePx?.[n] ?? {
719
+ width: e.width,
720
+ height: e.height
721
+ }, i = +(r.width * oe).toFixed(2), s = +(r.height * oe).toFixed(2), c = 4 + n * 3;
722
+ o(c), a(`<< /Type /Page /Parent 2 0 R /MediaBox [0 0 ${i} ${s}] /Resources << /XObject << /Im0 ${c + 2} 0 R >> >> /Contents ${c + 1} 0 R >>\nendobj\n`);
723
+ let l = `q ${i} 0 0 ${s} 0 0 cm /Im0 Do Q`;
724
+ o(c + 1), a(`<< /Length ${l.length} >>\nstream\n${l}\nendstream\nendobj\n`), o(c + 2), a(`<< /Type /XObject /Subtype /Image /Width ${e.width} /Height ${e.height} /ColorSpace /DeviceRGB /BitsPerComponent 8 /Filter /DCTDecode /Length ${e.jpeg.length} >>\nstream\n`), a(e.jpeg), a("\nendstream\nendobj\n");
725
+ });
726
+ let c = 3 + e.length * 3, l = i, u = `xref\n0 ${c + 1}\n0000000000 65535 f \n`;
727
+ for (let e = 1; e <= c; e++) u += `${String(r[e]).padStart(10, "0")} 00000 n \n`;
728
+ a(u), a(`trailer\n<< /Size ${c + 1} /Root 1 0 R /Info 3 0 R >>\nstartxref\n${l}\n%%EOF\n`);
729
+ let d = new Uint8Array(i), f = 0;
730
+ for (let e of n) d.set(e, f), f += e.length;
731
+ return new Blob([d], { type: "application/pdf" });
732
+ }
733
+ //#endregion
734
+ //#region src/v2/files/zip.ts
735
+ var ce = (() => {
736
+ let e = /* @__PURE__ */ new Uint32Array(256);
737
+ for (let t = 0; t < 256; t++) {
738
+ let n = t;
739
+ for (let e = 0; e < 8; e++) n = n & 1 ? 3988292384 ^ n >>> 1 : n >>> 1;
740
+ e[t] = n >>> 0;
741
+ }
742
+ return e;
743
+ })();
744
+ function F(e) {
745
+ let t = 4294967295;
746
+ for (let n = 0; n < e.length; n++) t = ce[(t ^ e[n]) & 255] ^ t >>> 8;
747
+ return (t ^ 4294967295) >>> 0;
748
+ }
749
+ var le = new TextEncoder(), I = (e) => le.encode(e);
750
+ function ue(e) {
751
+ let t = [], n = [], r = 0;
752
+ for (let i of e) {
753
+ let e = I(i.name), a = typeof i.data == "string" ? I(i.data) : i.data, o = F(a), s = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(30));
754
+ s.setUint32(0, 67324752, !0), s.setUint16(4, 20, !0), s.setUint16(6, 2048, !0), s.setUint16(8, 0, !0), s.setUint16(10, 0, !0), s.setUint16(12, 33, !0), s.setUint32(14, o, !0), s.setUint32(18, a.length, !0), s.setUint32(22, a.length, !0), s.setUint16(26, e.length, !0), s.setUint16(28, 0, !0), t.push(new Uint8Array(s.buffer), e, a);
755
+ let c = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(46));
756
+ c.setUint32(0, 33639248, !0), c.setUint16(4, 20, !0), c.setUint16(6, 20, !0), c.setUint16(8, 2048, !0), c.setUint16(10, 0, !0), c.setUint16(12, 0, !0), c.setUint16(14, 33, !0), c.setUint32(16, o, !0), c.setUint32(20, a.length, !0), c.setUint32(24, a.length, !0), c.setUint16(28, e.length, !0), c.setUint32(42, r, !0), n.push(new Uint8Array(c.buffer), e), r += 30 + e.length + a.length;
757
+ }
758
+ let i = n.reduce((e, t) => e + t.length, 0), a = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer(22));
759
+ a.setUint32(0, 101010256, !0), a.setUint16(8, e.length, !0), a.setUint16(10, e.length, !0), a.setUint32(12, i, !0), a.setUint32(16, r, !0);
760
+ let o = [
761
+ ...t,
762
+ ...n,
763
+ new Uint8Array(a.buffer)
764
+ ], s = new Uint8Array(o.reduce((e, t) => e + t.length, 0)), c = 0;
765
+ for (let e of o) s.set(e, c), c += e.length;
766
+ return s;
767
+ }
768
+ var L = (e, t) => new Blob([ue(e)], { type: t }), de = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"), fe = /* @__PURE__ */ new Set([
769
+ "SCRIPT",
770
+ "STYLE",
771
+ "TEMPLATE",
772
+ "NOSCRIPT",
773
+ "HEAD"
774
+ ]), R = 9525;
775
+ function pe(e) {
776
+ let t = [
777
+ e.b ? "<w:b/>" : "",
778
+ e.i ? "<w:i/>" : "",
779
+ e.u || e.link ? "<w:u w:val=\"single\"/>" : "",
780
+ e.link ? "<w:color w:val=\"0563C1\"/>" : "",
781
+ e.mono ? "<w:rFonts w:ascii=\"Courier New\" w:hAnsi=\"Courier New\"/>" : "",
782
+ e.size ? `<w:sz w:val="${e.size * 2}"/>` : ""
783
+ ].join("");
784
+ return t ? `<w:rPr>${t}</w:rPr>` : "";
785
+ }
786
+ var z = (e, t) => e ? `<w:r>${pe(t)}<w:t xml:space="preserve">${de(e)}</w:t></w:r>` : "";
787
+ function me(e) {
788
+ let t = /^data:image\/(png|jpe?g);base64,(.+)$/i.exec(e);
789
+ if (!t) return null;
790
+ let n = atob(t[2]), r = new Uint8Array(n.length);
791
+ for (let e = 0; e < n.length; e++) r[e] = n.charCodeAt(e);
792
+ return {
793
+ bytes: r,
794
+ ext: t[1].toLowerCase() === "png" ? "png" : "jpeg"
795
+ };
796
+ }
797
+ var he = (e) => new Promise((t) => {
798
+ let n = new Image();
799
+ n.onload = () => t({
800
+ w: n.naturalWidth,
801
+ h: n.naturalHeight
802
+ }), n.onerror = () => t(null), n.src = e;
803
+ });
804
+ async function ge(e) {
805
+ try {
806
+ let t = e;
807
+ if (!e.startsWith("data:")) {
808
+ let n = await (await fetch(e, {
809
+ mode: "cors",
810
+ credentials: "omit"
811
+ })).blob();
812
+ t = await new Promise((e, t) => {
813
+ let r = new FileReader();
814
+ r.onload = () => e(String(r.result)), r.onerror = t, r.readAsDataURL(n);
815
+ });
816
+ }
817
+ let n = new Image();
818
+ await new Promise((e, r) => {
819
+ n.onload = () => e(), n.onerror = () => r(/* @__PURE__ */ Error("image")), n.src = t;
820
+ });
821
+ let r = n.naturalWidth || 800, i = n.naturalHeight || 600, a = Math.min(1, 1600 / r), o = document.createElement("canvas");
822
+ return o.width = Math.max(1, Math.round(r * a)), o.height = Math.max(1, Math.round(i * a)), o.getContext("2d").drawImage(n, 0, 0, o.width, o.height), {
823
+ url: o.toDataURL("image/png"),
824
+ w: o.width,
825
+ h: o.height
826
+ };
827
+ } catch {
828
+ return null;
829
+ }
830
+ }
831
+ async function _e(e, t = "Document") {
832
+ let n = new DOMParser().parseFromString(e, "text/html"), r = {
833
+ media: [],
834
+ sizes: /* @__PURE__ */ new Map()
835
+ };
836
+ for (let e of Array.from(n.querySelectorAll("img"))) {
837
+ let t = e.getAttribute("src") ?? "";
838
+ if (!t || r.sizes.has(t)) continue;
839
+ let n = t;
840
+ if (!/^data:image\/(png|jpe?g);base64,/i.test(t)) {
841
+ let i = await ge(t);
842
+ if (!i) continue;
843
+ e.setAttribute("src", i.url), n = i.url, r.sizes.set(n, {
844
+ w: i.w,
845
+ h: i.h
846
+ });
847
+ continue;
848
+ }
849
+ let i = await he(n);
850
+ i && r.sizes.set(t, i);
851
+ }
852
+ let i = 0, a = [], o = (e) => {
853
+ let t = e.getAttribute("src") ?? "", n = me(t), o = r.sizes.get(t);
854
+ if (!n || !o) return z(e.getAttribute("alt") ? `[${e.getAttribute("alt")}]` : "", {});
855
+ let s = ++i;
856
+ r.media.push({
857
+ name: `word/media/image${s}.${n.ext}`,
858
+ data: n.bytes
859
+ }), a.push(`<Relationship Id="rIdImg${s}" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" Target="media/image${s}.${n.ext}"/>`);
860
+ let c = Math.min(o.w, 600), l = Math.round(o.h * c / o.w);
861
+ return `<w:r><w:drawing><wp:inline distT="0" distB="0" distL="0" distR="0"><wp:extent cx="${c * R}" cy="${l * R}"/><wp:docPr id="${s}" name="Picture ${s}" descr="${de(e.getAttribute("alt") ?? "")}"/><a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"><a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:pic xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"><pic:nvPicPr><pic:cNvPr id="${s}" name="image${s}.${n.ext}"/><pic:cNvPicPr/></pic:nvPicPr><pic:blipFill><a:blip r:embed="rIdImg${s}"/><a:stretch><a:fillRect/></a:stretch></pic:blipFill><pic:spPr><a:xfrm><a:off x="0" y="0"/><a:ext cx="${c * R}" cy="${l * R}"/></a:xfrm><a:prstGeom prst="rect"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic></wp:inline></w:drawing></w:r>`;
862
+ }, s = (e, t) => {
863
+ if (e.nodeType === 3) return z((e.nodeValue ?? "").replace(/\s+/g, " "), t);
864
+ if (!(e instanceof Element) || fe.has(e.tagName)) return "";
865
+ let n = (t) => Array.from(e.childNodes).map((e) => s(e, t)).join("");
866
+ switch (e.tagName) {
867
+ case "STRONG":
868
+ case "B": return n({
869
+ ...t,
870
+ b: !0
871
+ });
872
+ case "EM":
873
+ case "I": return n({
874
+ ...t,
875
+ i: !0
876
+ });
877
+ case "U": return n({
878
+ ...t,
879
+ u: !0
880
+ });
881
+ case "CODE": return n({
882
+ ...t,
883
+ mono: !0
884
+ });
885
+ case "A": return n({
886
+ ...t,
887
+ link: !0
888
+ });
889
+ case "BR": return "<w:r><w:br/></w:r>";
890
+ case "IMG": return o(e);
891
+ default: return n(t);
892
+ }
893
+ }, c = (e, t = {}) => !e.trim() && !t.bullet ? "" : `<w:p>${`<w:pPr>${t.keepNext ? "<w:keepNext/>" : ""}<w:spacing w:after="${t.after ?? 160}"/>${t.indent ? `<w:ind w:left="${t.indent}" w:hanging="260"/>` : ""}</w:pPr>`}${t.bullet ? z(`${t.bullet}\t`, {}) : ""}${e}</w:p>`, l = [
894
+ 0,
895
+ 32,
896
+ 28,
897
+ 24,
898
+ 22,
899
+ 20,
900
+ 18
901
+ ], u = (e, t = 0) => {
902
+ if (e.nodeType === 3) return (e.nodeValue ?? "").trim() ? c(s(e, {})) : "";
903
+ if (!(e instanceof Element) || fe.has(e.tagName)) return "";
904
+ let n = e.tagName;
905
+ if (/^H[1-6]$/.test(n)) return c(s(e, {
906
+ b: !0,
907
+ size: l[Number(n[1])] / 2
908
+ }), {
909
+ keepNext: !0,
910
+ after: 120
911
+ });
912
+ if (n === "P" || n === "FIGCAPTION" || n === "BUTTON" || n === "A" || n === "SPAN" || n === "IMG" || n === "LABEL") return c(s(e, {}));
913
+ if (n === "BLOCKQUOTE") return Array.from(e.childNodes).map((e) => u(e, t + 720)).join("");
914
+ if (n === "PRE") return c(z(e.textContent ?? "", { mono: !0 }));
915
+ if (n === "HR") return "<w:p><w:pPr><w:pBdr><w:bottom w:val=\"single\" w:sz=\"6\" w:space=\"1\" w:color=\"999999\"/></w:pBdr></w:pPr></w:p>";
916
+ if (n === "UL" || n === "OL") return Array.from(e.children).filter((e) => e.tagName === "LI").map((e, r) => {
917
+ let i = Array.from(e.children).filter((e) => e.tagName === "UL" || e.tagName === "OL"), a = Array.from(e.childNodes).filter((e) => !i.includes(e)).map((e) => s(e, {})).join("");
918
+ return c(a, {
919
+ indent: t + 560,
920
+ bullet: n === "OL" ? `${r + 1}.` : "•",
921
+ after: 60
922
+ }) + i.map((e) => u(e, t + 360)).join("");
923
+ }).join("");
924
+ if (n === "TABLE") {
925
+ let t = Array.from(e.querySelectorAll("tr")), n = t.map((e) => `<w:tr>${Array.from(e.children).map((e) => `<w:tc><w:tcPr><w:tcW w:w="0" w:type="auto"/></w:tcPr>${c(s(e, e.tagName === "TH" ? { b: !0 } : {}), { after: 40 }) || "<w:p/>"}</w:tc>`).join("")}</w:tr>`).join(""), r = [
926
+ "top",
927
+ "left",
928
+ "bottom",
929
+ "right",
930
+ "insideH",
931
+ "insideV"
932
+ ].map((e) => `<w:${e} w:val="single" w:sz="4" w:space="0" w:color="BBBBBB"/>`).join("");
933
+ return t.length ? `<w:tbl><w:tblPr><w:tblW w:w="0" w:type="auto"/><w:tblBorders>${r}</w:tblBorders></w:tblPr>${n}</w:tbl><w:p/>` : "";
934
+ }
935
+ return Array.from(e.children).some((e) => /^(P|DIV|SECTION|ARTICLE|H[1-6]|UL|OL|TABLE|BLOCKQUOTE|PRE|HR|FIGURE|HEADER|FOOTER|MAIN|NAV|ASIDE|FORM)$/.test(e.tagName)) ? Array.from(e.childNodes).map((e) => u(e, t)).join("") : c(s(e, {}));
936
+ }, d = Array.from(n.body.childNodes).map((e) => u(e)).join("") || "<w:p/>", f = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
937
+ return L([
938
+ {
939
+ name: "[Content_Types].xml",
940
+ data: `${f}<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Default Extension="png" ContentType="image/png"/><Default Extension="jpeg" ContentType="image/jpeg"/><Override PartName="/word/document.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/><Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/></Types>`
941
+ },
942
+ {
943
+ name: "_rels/.rels",
944
+ data: `${f}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="word/document.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/></Relationships>`
945
+ },
946
+ {
947
+ name: "docProps/core.xml",
948
+ data: `${f}<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:title>${de(t)}</dc:title></cp:coreProperties>`
949
+ },
950
+ {
951
+ name: "word/document.xml",
952
+ data: `${f}<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"><w:body>${d}<w:sectPr><w:pgSz w:w="11906" w:h="16838"/><w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/></w:sectPr></w:body></w:document>`
953
+ },
954
+ {
955
+ name: "word/_rels/document.xml.rels",
956
+ data: `${f}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">${a.join("")}</Relationships>`
957
+ },
958
+ ...r.media
959
+ ], "application/vnd.openxmlformats-officedocument.wordprocessingml.document");
960
+ }
961
+ //#endregion
962
+ //#region src/v2/files/sheet.ts
963
+ var ve = (e) => {
964
+ let t = "";
965
+ for (let n = e + 1; n > 0; n = Math.floor((n - 1) / 26)) t = String.fromCharCode(65 + (n - 1) % 26) + t;
966
+ return t;
967
+ }, ye = (e) => e.split("").reduce((e, t) => e * 26 + t.charCodeAt(0) - 64, 0) - 1;
968
+ function be(e, t) {
969
+ let n = e.split("\n", 1)[0] ?? "", r = t ?? ([
970
+ ",",
971
+ " ",
972
+ ";"
973
+ ].sort((e, t) => n.split(t).length - n.split(e).length)[0] || ","), i = [], a = [], o = "", s = !1;
974
+ for (let t = 0; t < e.length; t++) {
975
+ let n = e[t];
976
+ s ? n === "\"" ? e[t + 1] === "\"" ? (o += "\"", t++) : s = !1 : o += n : n === "\"" ? s = !0 : n === r ? (a.push(o), o = "") : n === "\n" || n === "\r" ? (n === "\r" && e[t + 1] === "\n" && t++, a.push(o), o = "", i.push(a), a = []) : o += n;
977
+ }
978
+ return (o !== "" || a.length) && (a.push(o), i.push(a)), i;
979
+ }
980
+ function xe(e, t = ",") {
981
+ return e.map((e) => e.map((e) => /["\n\r]/.test(e) || e.includes(t) ? `"${e.replace(/"/g, "\"\"")}"` : e).join(t)).join("\r\n");
982
+ }
983
+ function Se(e) {
984
+ let t = e.length;
985
+ for (; t > 1 && e[t - 1].every((e) => e === "");) t--;
986
+ let n = e.slice(0, t), r = Math.max(1, ...n.map((e) => e.length));
987
+ for (; r > 1 && n.every((e) => (e[r - 1] ?? "") === "");) r--;
988
+ return n.map((e) => Array.from({ length: r }, (t, n) => e[n] ?? ""));
989
+ }
990
+ var Ce = {
991
+ SUM: (...e) => e.reduce((e, t) => e + t, 0),
992
+ AVERAGE: (...e) => e.length ? e.reduce((e, t) => e + t, 0) / e.length : 0,
993
+ MIN: (...e) => e.length ? Math.min(...e) : 0,
994
+ MAX: (...e) => e.length ? Math.max(...e) : 0,
995
+ COUNT: (...e) => e.length,
996
+ ROUND: (e, t = 0) => Math.round(e * 10 ** t) / 10 ** t,
997
+ ABS: (e) => Math.abs(e),
998
+ SQRT: (e) => Math.sqrt(e)
999
+ };
1000
+ function B(e) {
1001
+ let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), r = (t, n) => e[n]?.[t] ?? "", i = (e, a) => {
1002
+ let o = `${e},${a}`, s = r(e, a);
1003
+ if (!s.startsWith("=")) return s;
1004
+ if (t.has(o)) return t.get(o);
1005
+ if (n.has(o)) return "#LOOP";
1006
+ n.add(o);
1007
+ let c;
1008
+ try {
1009
+ c = String(we(s.slice(1), (e, t) => i(e, t)));
1010
+ } catch (e) {
1011
+ c = e instanceof Error && e.message.startsWith("#") ? e.message : "#ERROR";
1012
+ }
1013
+ return n.delete(o), t.set(o, c), c;
1014
+ };
1015
+ return e.map((e, t) => e.map((e, n) => i(n, t)));
1016
+ }
1017
+ function we(e, t) {
1018
+ let n = (e) => {
1019
+ if (e.startsWith("#")) throw Error(e);
1020
+ return e.trim() !== "" && !Number.isNaN(Number(e)) ? Number(e) : null;
1021
+ }, r = (e, r) => {
1022
+ let i = /^([A-Z]+)(\d+)$/.exec(e), a = /^([A-Z]+)(\d+)$/.exec(r), [o, s] = [ye(i[1]), ye(a[1])].sort((e, t) => e - t), [c, l] = [Number(i[2]) - 1, Number(a[2]) - 1].sort((e, t) => e - t), u = [];
1023
+ for (let e = c; e <= l; e++) for (let r = o; r <= s; r++) {
1024
+ let i = n(t(r, e));
1025
+ i !== null && u.push(i);
1026
+ }
1027
+ return u;
1028
+ }, i = [], a = e.toUpperCase().replace(/\s+/g, "");
1029
+ a = a.replace(/([A-Z]+\d+):([A-Z]+\d+)/g, (e, t, n) => (i.push(r(t, n)), `__R(${i.length - 1})`)), a = a.replace(/\b([A-Z]+)(\d+)\b(?!\()/g, (e, r, i) => `(${n(t(ye(r), Number(i) - 1)) ?? 0})`);
1030
+ let o = a.replace(/__R\(\d+\)/g, "").replace(/\b(SUM|AVERAGE|MIN|MAX|COUNT|ROUND|ABS|SQRT)\(/g, "(");
1031
+ if (!/^[\d+\-*/().,%^\s]*$/.test(o)) throw Error("bad formula");
1032
+ let s = a.replace(/\^/g, "**").replace(/(\d+(?:\.\d+)?)%/g, "($1/100)").replace(/__R\((\d+)\)/g, "...__A[$1]"), c = Function("__A", ...Object.keys(Ce), `"use strict";return (${s});`)(i, ...Object.values(Ce));
1033
+ if (typeof c != "number" || !Number.isFinite(c)) throw Error("bad result");
1034
+ return Math.round(c * 1e10) / 1e10;
1035
+ }
1036
+ var V = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
1037
+ function Te(e, t = {}) {
1038
+ return `<table>${B(e).map((e, n) => `<tr>${e.map((e) => n === 0 && t.header !== !1 ? `<th>${V(e)}</th>` : `<td>${V(e)}</td>`).join("")}</tr>`).join("")}</table>`;
1039
+ }
1040
+ function Ee(e) {
1041
+ let t = B(e);
1042
+ if (!t.length) return "";
1043
+ let n = Math.max(...t.map((e) => e.length)), r = (e) => `| ${Array.from({ length: n }, (t, n) => (e[n] ?? "").replace(/\|/g, "\\|")).join(" | ")} |`;
1044
+ return `${r(t[0])}\n| ${Array.from({ length: n }, () => "---").join(" | ")} |\n${t.slice(1).map(r).join("\n")}\n`;
1045
+ }
1046
+ function De(e, t = "Sheet1") {
1047
+ let n = B(e), r = e.map((e, t) => {
1048
+ let r = e.map((e, r) => {
1049
+ if (e === "") return "";
1050
+ let i = `${ve(r)}${t + 1}`;
1051
+ if (e.startsWith("=")) {
1052
+ let a = n[t][r], o = Number(a);
1053
+ return Number.isNaN(o) || a === "" ? `<c r="${i}" t="str"><f>${V(e.slice(1))}</f><v>${V(a)}</v></c>` : `<c r="${i}"><f>${V(e.slice(1))}</f><v>${o}</v></c>`;
1054
+ }
1055
+ return e.trim() !== "" && !Number.isNaN(Number(e)) && !/^0\d/.test(e) ? `<c r="${i}"><v>${Number(e)}</v></c>` : `<c r="${i}" t="inlineStr"><is><t xml:space="preserve">${V(e)}</t></is></c>`;
1056
+ }).join("");
1057
+ return `<row r="${t + 1}">${r}</row>`;
1058
+ }).join(""), i = V(t.replace(/[\\/?*[\]:]/g, " ").slice(0, 31) || "Sheet1"), a = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n";
1059
+ return L([
1060
+ {
1061
+ name: "[Content_Types].xml",
1062
+ data: `${a}<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/></Types>`
1063
+ },
1064
+ {
1065
+ name: "_rels/.rels",
1066
+ data: `${a}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/></Relationships>`
1067
+ },
1068
+ {
1069
+ name: "xl/workbook.xml",
1070
+ data: `${a}<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><sheets><sheet name="${i}" sheetId="1" r:id="rId1"/></sheets></workbook>`
1071
+ },
1072
+ {
1073
+ name: "xl/_rels/workbook.xml.rels",
1074
+ data: `${a}<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/></Relationships>`
1075
+ },
1076
+ {
1077
+ name: "xl/worksheets/sheet1.xml",
1078
+ data: `${a}<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><sheetData>${r}</sheetData></worksheet>`
1079
+ }
1080
+ ], "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
1081
+ }
1082
+ //#endregion
1083
+ //#region src/v2/files/text.ts
1084
+ var H = (e) => e.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;"), Oe = /* @__PURE__ */ new Set([
1085
+ "SCRIPT",
1086
+ "STYLE",
1087
+ "TEMPLATE",
1088
+ "NOSCRIPT",
1089
+ "HEAD"
1090
+ ]), ke = /* @__PURE__ */ new Set([
1091
+ "P",
1092
+ "DIV",
1093
+ "SECTION",
1094
+ "ARTICLE",
1095
+ "HEADER",
1096
+ "FOOTER",
1097
+ "MAIN",
1098
+ "NAV",
1099
+ "ASIDE",
1100
+ "H1",
1101
+ "H2",
1102
+ "H3",
1103
+ "H4",
1104
+ "H5",
1105
+ "H6",
1106
+ "UL",
1107
+ "OL",
1108
+ "LI",
1109
+ "BLOCKQUOTE",
1110
+ "PRE",
1111
+ "TABLE",
1112
+ "TR",
1113
+ "FIGURE",
1114
+ "FORM",
1115
+ "HR"
1116
+ ]), Ae = (e) => new DOMParser().parseFromString(e, "text/html"), je = (e) => e.replace(/[ \t]+\n/g, "\n").replace(/\n{3,}/g, "\n\n").trim() + "\n";
1117
+ function U(e) {
1118
+ let t = Ae(e), n = "", r = (e) => {
1119
+ if (!n) return;
1120
+ let t = 0;
1121
+ for (; t < e && n[n.length - 1 - t] === "\n";) t++;
1122
+ n += "\n".repeat(e - t);
1123
+ }, i = (e) => {
1124
+ if (e.nodeType === 3) {
1125
+ n += (e.nodeValue ?? "").replace(/\s+/g, " ");
1126
+ return;
1127
+ }
1128
+ if (!(e instanceof Element) || Oe.has(e.tagName)) return;
1129
+ if (e.tagName === "BR") {
1130
+ n += "\n";
1131
+ return;
1132
+ }
1133
+ let t = ke.has(e.tagName), a = e.tagName === "LI" || e.tagName === "TR";
1134
+ t && r(a ? 1 : 2), e.tagName === "LI" && (n += e.parentElement?.tagName === "OL" ? `${Array.from(e.parentElement.children).indexOf(e) + 1}. ` : "- "), e.childNodes.forEach(i), (e.tagName === "TD" || e.tagName === "TH") && (n += " "), t && r(a ? 1 : 2);
1135
+ };
1136
+ return i(t.body), je(n.replace(/\n[ \t]+/g, "\n").replace(/\t\n/g, "\n"));
1137
+ }
1138
+ function Me(e) {
1139
+ let t = Ae(e), n = (e) => {
1140
+ if (e.nodeType === 3) return (e.nodeValue ?? "").replace(/\s+/g, " ");
1141
+ if (!(e instanceof Element) || Oe.has(e.tagName)) return "";
1142
+ let t = () => Array.from(e.childNodes).map(n).join("");
1143
+ switch (e.tagName) {
1144
+ case "STRONG":
1145
+ case "B": return `**${t().trim()}**`;
1146
+ case "EM":
1147
+ case "I": return `*${t().trim()}*`;
1148
+ case "CODE": return `\`${e.textContent ?? ""}\``;
1149
+ case "DEL":
1150
+ case "S": return `~~${t().trim()}~~`;
1151
+ case "BR": return " \n";
1152
+ case "A": {
1153
+ let n = e.getAttribute("href") ?? "", r = t().trim();
1154
+ return n && r ? `[${r}](${n})` : r;
1155
+ }
1156
+ case "IMG": {
1157
+ let t = e.getAttribute("src") ?? "";
1158
+ return t ? `![${e.getAttribute("alt") ?? ""}](${t.startsWith("data:") ? "image" : t})` : "";
1159
+ }
1160
+ default: return t();
1161
+ }
1162
+ }, r = (e, t = "") => {
1163
+ if (e.nodeType === 3) return (e.nodeValue ?? "").trim() ? n(e) : "";
1164
+ if (!(e instanceof Element) || Oe.has(e.tagName)) return "";
1165
+ let a = e.tagName;
1166
+ if (/^H[1-6]$/.test(a)) return `\n\n${"#".repeat(Number(a[1]))} ${n(e).trim()}\n\n`;
1167
+ if (a === "P") return `\n\n${n(e).trim()}\n\n`;
1168
+ if (a === "HR") return "\n\n---\n\n";
1169
+ if (a === "BLOCKQUOTE") return `\n\n${i(e).trim().split("\n").map((e) => `> ${e}`).join("\n")}\n\n`;
1170
+ if (a === "PRE") return `\n\n\`\`\`\n${e.textContent ?? ""}\n\`\`\`\n\n`;
1171
+ if (a === "UL" || a === "OL") return `\n${Array.from(e.children).filter((e) => e.tagName === "LI").map((e, i) => {
1172
+ let o = Array.from(e.children).filter((e) => e.tagName === "UL" || e.tagName === "OL"), s = Array.from(e.childNodes).filter((e) => !o.includes(e)).map(n).join("").trim();
1173
+ return `${t}${a === "OL" ? `${i + 1}.` : "-"} ${s}${o.map((e) => r(e, `${t} `)).join("")}`;
1174
+ }).join("\n")}\n\n`;
1175
+ if (a === "TABLE") {
1176
+ let t = Array.from(e.querySelectorAll("tr")).map((e) => Array.from(e.children).map((e) => n(e).trim().replace(/\|/g, "\\|")));
1177
+ if (!t.length) return "";
1178
+ let r = Math.max(...t.map((e) => e.length)), i = (e) => `| ${Array.from({ length: r }, (t, n) => e[n] ?? "").join(" | ")} |`;
1179
+ return `\n\n${i(t[0])}\n| ${Array.from({ length: r }, () => "---").join(" | ")} |\n${t.slice(1).map(i).join("\n")}\n\n`;
1180
+ }
1181
+ return ke.has(a) ? i(e, t) : n(e);
1182
+ }, i = (e, t = "") => Array.from(e.childNodes).map((e) => r(e, t)).join("");
1183
+ return je(i(t.body));
1184
+ }
1185
+ function W(e) {
1186
+ let t = (e) => {
1187
+ let t = H(e);
1188
+ return t = t.replace(/!\[([^\]]*)\]\(([^)\s]+)\)/g, (e, t, n) => `<img src="${Ne(n)}" alt="${t}">`), t = t.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, (e, t, n) => `<a href="${Ne(n)}">${t}</a>`), t = t.replace(/`([^`]+)`/g, "<code>$1</code>"), t = t.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>").replace(/__([^_]+)__/g, "<strong>$1</strong>"), t = t.replace(/(^|[^*])\*([^*\s][^*]*)\*/g, "$1<em>$2</em>").replace(/~~([^~]+)~~/g, "<del>$1</del>"), t.replace(/ {2}\n/g, "<br>");
1189
+ }, n = e.replace(/\r\n?/g, "\n").split("\n"), r = [], i = 0;
1190
+ for (; i < n.length;) {
1191
+ let e = n[i];
1192
+ if (!e.trim()) {
1193
+ i++;
1194
+ continue;
1195
+ }
1196
+ if (/^```/.exec(e)) {
1197
+ let e = [];
1198
+ for (i++; i < n.length && !/^```/.test(n[i]);) e.push(n[i++]);
1199
+ i++, r.push(`<pre><code>${H(e.join("\n"))}</code></pre>`);
1200
+ continue;
1201
+ }
1202
+ let a = /^(#{1,6})\s+(.*)$/.exec(e);
1203
+ if (a) {
1204
+ r.push(`<h${a[1].length}>${t(a[2].trim())}</h${a[1].length}>`), i++;
1205
+ continue;
1206
+ }
1207
+ if (/^\s*([-*_])(\s*\1){2,}\s*$/.test(e)) {
1208
+ r.push("<hr>"), i++;
1209
+ continue;
1210
+ }
1211
+ if (/^>\s?/.test(e)) {
1212
+ let e = [];
1213
+ for (; i < n.length && /^>\s?/.test(n[i]);) e.push(n[i++].replace(/^>\s?/, ""));
1214
+ r.push(`<blockquote>${W(e.join("\n"))}</blockquote>`);
1215
+ continue;
1216
+ }
1217
+ if (e.includes("|") && /^\s*\|?\s*:?-{3,}/.test(n[i + 1] ?? "")) {
1218
+ let a = (e) => e.trim().replace(/^\||\|$/g, "").split("|").map((e) => e.trim()), o = a(e);
1219
+ i += 2;
1220
+ let s = [];
1221
+ for (; i < n.length && n[i].includes("|") && n[i].trim();) s.push(a(n[i++]));
1222
+ r.push(`<table><thead><tr>${o.map((e) => `<th>${t(e)}</th>`).join("")}</tr></thead><tbody>${s.map((e) => `<tr>${e.map((e) => `<td>${t(e)}</td>`).join("")}</tr>`).join("")}</tbody></table>`);
1223
+ continue;
1224
+ }
1225
+ let o = /^(\s*)([-*+]|\d+\.)\s+/.exec(e);
1226
+ if (o) {
1227
+ let e = /\d/.test(o[2]), a = [];
1228
+ for (; i < n.length && /^(\s*)([-*+]|\d+\.)\s+/.test(n[i]);) a.push(n[i++].replace(/^(\s*)([-*+]|\d+\.)\s+/, ""));
1229
+ r.push(`<${e ? "ol" : "ul"}>${a.map((e) => `<li>${t(e)}</li>`).join("")}</${e ? "ol" : "ul"}>`);
1230
+ continue;
1231
+ }
1232
+ let s = [];
1233
+ for (; i < n.length && n[i].trim() && !/^(#{1,6}\s|```|>\s?|\s*([-*+]|\d+\.)\s+)/.test(n[i]);) s.push(n[i++]);
1234
+ r.push(`<p>${t(s.join("\n"))}</p>`);
1235
+ }
1236
+ return r.join("\n");
1237
+ }
1238
+ function Ne(e) {
1239
+ let t = e.replace(/&amp;/g, "&").trim();
1240
+ return /^(https?:|mailto:|tel:|\/|#|data:image\/(png|jpe?g|gif|webp);)/i.test(t) ? H(t) : "#";
1241
+ }
1242
+ function Pe(e) {
1243
+ return e.replace(/\r\n?/g, "\n").split(/\n{2,}/).map((e) => `<p>${H(e).replace(/\n/g, "<br>")}</p>`).join("\n");
1244
+ }
1245
+ var Fe = H, Ie = [
1246
+ {
1247
+ id: "png",
1248
+ label: "PNG",
1249
+ ext: "png",
1250
+ mime: "image/png",
1251
+ hint: "A sharp picture with a see-through background."
1252
+ },
1253
+ {
1254
+ id: "jpeg",
1255
+ label: "JPG",
1256
+ ext: "jpg",
1257
+ mime: "image/jpeg",
1258
+ hint: "A smaller picture, good for photos and sharing."
1259
+ },
1260
+ {
1261
+ id: "pdf",
1262
+ label: "PDF",
1263
+ ext: "pdf",
1264
+ mime: "application/pdf",
1265
+ hint: "A document you can print or send."
1266
+ },
1267
+ {
1268
+ id: "svg",
1269
+ label: "SVG",
1270
+ ext: "svg",
1271
+ mime: "image/svg+xml",
1272
+ hint: "A scalable vector that opens in design tools."
1273
+ },
1274
+ {
1275
+ id: "html",
1276
+ label: "HTML",
1277
+ ext: "html",
1278
+ mime: "text/html",
1279
+ hint: "A web page file."
1280
+ },
1281
+ {
1282
+ id: "txt",
1283
+ label: "Text",
1284
+ ext: "txt",
1285
+ mime: "text/plain",
1286
+ hint: "Just the words."
1287
+ },
1288
+ {
1289
+ id: "md",
1290
+ label: "Markdown",
1291
+ ext: "md",
1292
+ mime: "text/markdown",
1293
+ hint: "Words with simple formatting."
1294
+ },
1295
+ {
1296
+ id: "docx",
1297
+ label: "Word",
1298
+ ext: "docx",
1299
+ mime: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1300
+ hint: "A Word document (text and pictures, not the layout)."
1301
+ },
1302
+ {
1303
+ id: "csv",
1304
+ label: "CSV",
1305
+ ext: "csv",
1306
+ mime: "text/csv",
1307
+ hint: "A plain table any spreadsheet app opens."
1308
+ },
1309
+ {
1310
+ id: "xlsx",
1311
+ label: "Excel",
1312
+ ext: "xlsx",
1313
+ mime: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
1314
+ hint: "An Excel spreadsheet."
1315
+ }
1316
+ ], Le = [
1317
+ "png",
1318
+ "jpeg",
1319
+ "pdf",
1320
+ "svg"
1321
+ ], Re = (e, t) => `
1322
+ html,body{margin:0;background:#fff}
1323
+ .plx-doc{box-sizing:border-box;${t ? "padding:56px 64px;" : ""}color:#111827;font:${e ? "14px/1.6 ui-monospace,SFMono-Regular,Menlo,Consolas,monospace" : "16px/1.65 -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif"};${e ? "white-space:pre-wrap;" : ""}overflow-wrap:anywhere}
1324
+ .plx-doc h1{font-size:2em;line-height:1.2;margin:0 0 .6em}.plx-doc h2{font-size:1.55em;line-height:1.25;margin:1.2em 0 .5em}.plx-doc h3{font-size:1.25em;margin:1.1em 0 .4em}.plx-doc h4,.plx-doc h5,.plx-doc h6{font-size:1em;margin:1em 0 .3em}
1325
+ .plx-doc p{margin:0 0 1em}.plx-doc ul,.plx-doc ol{margin:0 0 1em;padding-left:1.6em}.plx-doc li{margin:.2em 0}
1326
+ .plx-doc a{color:#2563eb}.plx-doc img{max-width:100%;height:auto}.plx-doc blockquote{margin:0 0 1em;padding-left:1em;border-left:3px solid #d1d5db;color:#4b5563}
1327
+ .plx-doc code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:.92em;background:#f3f4f6;padding:.1em .3em;border-radius:4px}
1328
+ .plx-doc pre{background:#f3f4f6;padding:12px 14px;border-radius:8px;overflow:auto;white-space:pre-wrap}.plx-doc pre code{background:none;padding:0}
1329
+ .plx-doc table{border-collapse:collapse;margin:0 0 1em}.plx-doc th,.plx-doc td{border:1px solid #d1d5db;padding:6px 10px;text-align:left;font-size:.95em}.plx-doc th{background:#f3f4f6;font-weight:600}
1330
+ .plx-doc hr{border:0;border-top:1px solid #d1d5db;margin:1.4em 0}`;
1331
+ function G(e, t, n = {}) {
1332
+ return `<!doctype html>\n<html lang="en">\n<head>\n<meta charset="utf-8">\n<meta name="viewport" content="width=device-width, initial-scale=1">\n<title>${Fe(e)}</title>\n<style>${Re(!!n.mono, n.paper !== !1)}${n.css ?? ""}</style>\n</head>\n<body>\n<div class="plx-doc">${t}</div>\n</body>\n</html>`;
1333
+ }
1334
+ var ze = ".plx-doc table{font-size:14px}.plx-doc td,.plx-doc th{min-width:64px}";
1335
+ function Be(e) {
1336
+ if (e.kind === "design") {
1337
+ let t = {
1338
+ designSystem: e.designSystem,
1339
+ title: e.page.name,
1340
+ ...e.compile
1341
+ };
1342
+ if (e.mode === "email") {
1343
+ let t = a(e.page, {
1344
+ designSystem: e.designSystem,
1345
+ title: e.page.name
1346
+ });
1347
+ return {
1348
+ document: t.html,
1349
+ width: 640,
1350
+ body: () => t.html,
1351
+ name: e.page.name
1352
+ };
1353
+ }
1354
+ let n = i(e.page, {
1355
+ ...t,
1356
+ runtime: "none",
1357
+ nodeIds: !0
1358
+ }), o = e.viewport ?? "desktop", s = e.nodeIds?.length ? void 0 : Ve(e.page);
1359
+ return {
1360
+ document: n.document,
1361
+ width: r[o],
1362
+ nodeIds: e.nodeIds?.length ? e.nodeIds : s ? [s] : void 0,
1363
+ body: () => n.html,
1364
+ name: e.page.name
1365
+ };
1366
+ }
1367
+ if (e.kind === "html") {
1368
+ let t = e.width ?? 816;
1369
+ return {
1370
+ document: G(e.name, e.body, {
1371
+ css: e.css,
1372
+ mono: e.mono,
1373
+ paper: e.paper
1374
+ }),
1375
+ width: t,
1376
+ body: () => e.body,
1377
+ name: e.name
1378
+ };
1379
+ }
1380
+ if (e.kind === "rawhtml") {
1381
+ let t = /<html[\s>]|<body[\s>]|<!doctype/i.test(e.html) ? e.html : `<!doctype html>\n<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"></head><body>${e.html}</body></html>`;
1382
+ return {
1383
+ document: t,
1384
+ width: e.width ?? 1200,
1385
+ fullDocument: !0,
1386
+ body: () => new DOMParser().parseFromString(t, "text/html").body.innerHTML,
1387
+ name: e.name
1388
+ };
1389
+ }
1390
+ let t = Te(e.grid);
1391
+ return {
1392
+ document: G(e.name, t, {
1393
+ css: ze,
1394
+ paper: !0
1395
+ }),
1396
+ width: Math.max(816, Math.min(2400, 140 + Math.max(0, ...e.grid.map((e) => e.length)) * 140)),
1397
+ body: () => t,
1398
+ name: e.name
1399
+ };
1400
+ }
1401
+ function Ve(e) {
1402
+ let t = (e.rootNode.children ?? []).filter((e) => !e.hidden && !n(e)), r = t.length === 1 ? t[0] : void 0;
1403
+ return r && r.type === "section" && /^\d+(\.\d+)?px$/.test(r.styles.width ?? "") && /^\d+(\.\d+)?px$/.test(r.styles.height ?? "") ? r.id : void 0;
1404
+ }
1405
+ var He = (e) => e.replace(/[\\/:*?"<>|\u0000-\u001f]+/g, " ").replace(/\s+/g, " ").trim().slice(0, 80) || "Untitled", K = (e, t) => new Blob([e], { type: `${t};charset=utf-8` });
1406
+ async function Ue(e, t) {
1407
+ let n = await P(e, "image/jpeg", t);
1408
+ return new Uint8Array(await n.arrayBuffer());
1409
+ }
1410
+ async function We(e, t, n, r, i) {
1411
+ if (r === "single") return {
1412
+ pages: [{
1413
+ jpeg: await Ue(e, i),
1414
+ width: e.width,
1415
+ height: e.height
1416
+ }],
1417
+ sizes: [t]
1418
+ };
1419
+ let a = Math.round(t.width * 297 / 210), o = Math.round(a * n), s = [], c = [];
1420
+ for (let n = 0; n < e.height; n += o) {
1421
+ let r = Math.min(o, e.height - n), l = document.createElement("canvas");
1422
+ l.width = e.width, l.height = o;
1423
+ let u = l.getContext("2d");
1424
+ u.fillStyle = "#ffffff", u.fillRect(0, 0, l.width, l.height), u.drawImage(e, 0, n, e.width, r, 0, 0, e.width, r), s.push({
1425
+ jpeg: await Ue(l, i),
1426
+ width: l.width,
1427
+ height: l.height
1428
+ }), c.push({
1429
+ width: t.width,
1430
+ height: a
1431
+ });
1432
+ }
1433
+ return {
1434
+ pages: s,
1435
+ sizes: c
1436
+ };
1437
+ }
1438
+ async function Ge(e, t, n) {
1439
+ let r = e.kind === "sheet" ? {
1440
+ ...e,
1441
+ grid: Se(e.grid)
1442
+ } : e, i = Ie.find((e) => e.id === t.format);
1443
+ if (!i) throw Error(`"${t.format}" isn't a format Plexo can export.`);
1444
+ let a = Math.max(1, Math.min(4, t.scale ?? 2)), o = [], s = r.kind === "design" && !!r.nodeIds?.length && r.mode !== "email", c = He(t.filename ?? (r.kind === "design" ? r.page.name : r.name)), l = (e, t = "") => ({
1445
+ blob: e,
1446
+ filename: `${c}${t}.${i.ext}`,
1447
+ mime: i.mime,
1448
+ warnings: o
1449
+ });
1450
+ r.kind === "design" && r.mode === "email" && r.nodeIds?.length && o.push("An email is exported as a whole, so the whole email was exported.");
1451
+ let u = r.kind === "sheet";
1452
+ if (t.format === "csv" || t.format === "xlsx") {
1453
+ if (!u) throw Error("Only spreadsheets can be saved as CSV or Excel. Choose another format for this file.");
1454
+ return l(t.format === "csv" ? K(xe(B(r.grid)), "text/csv") : De(r.grid, r.name));
1455
+ }
1456
+ let d = Be(r);
1457
+ if (t.format === "txt" || t.format === "md" || t.format === "docx" || t.format === "html") {
1458
+ let e = d.body(), n = d.document;
1459
+ if (s) {
1460
+ let t = await te({
1461
+ document: d.document,
1462
+ width: d.width,
1463
+ nodeIds: d.nodeIds,
1464
+ fullDocument: d.fullDocument
1465
+ });
1466
+ try {
1467
+ o.push(...t.warnings), e = t.roots.map((e) => e.outerHTML).join("\n"), n = G(c, e, {
1468
+ css: t.css,
1469
+ paper: !1
1470
+ });
1471
+ } finally {
1472
+ t.release();
1473
+ }
1474
+ }
1475
+ return t.format === "html" ? l(K(r.kind === "design" && !s ? n.replace(/\sdata-plx-node="[^"]*"/g, "") : n, "text/html")) : t.format === "txt" ? l(K(u ? xe(B(r.grid), " ") : (r.kind === "html" && r.mono, U(e)), "text/plain")) : t.format === "md" ? l(K(u ? Ee(r.grid) : Me(e), "text/markdown")) : l(await _e(e, c));
1476
+ }
1477
+ let f = await te({
1478
+ document: d.document,
1479
+ width: d.width,
1480
+ nodeIds: d.nodeIds,
1481
+ fullDocument: d.fullDocument
1482
+ });
1483
+ try {
1484
+ o.push(...f.warnings);
1485
+ let { crop: e } = f;
1486
+ if (t.format === "svg") {
1487
+ if ((t.svgMode ?? "vector") === "exact") return l(K(j(f), "image/svg+xml"));
1488
+ let e = ne(f);
1489
+ return o.push(...e.warnings), l(K(e.svg, "image/svg+xml"));
1490
+ }
1491
+ let r = t.background === void 0 ? t.format === "png" ? null : "#ffffff" : t.background, i = await ie(j(f), e.width, e.height, a, r);
1492
+ o.push(...i.warnings);
1493
+ let s = t.scaleSuffix !== !1 && a !== 1 && t.format !== "pdf" ? `@${i.scale === a ? a : Math.round(i.scale * 100) / 100}x` : "";
1494
+ if (t.format === "png") return l(await P(i.canvas, "image/png"), s);
1495
+ if (t.format === "jpeg") return l(await P(i.canvas, "image/jpeg", t.quality ?? .92), s);
1496
+ let u = await We(i.canvas, e, i.scale, t.pdfPaging ?? "single", t.quality ?? .92);
1497
+ return n ? (n.pages.push(...u.pages), n.sizes.push(...u.sizes), l(new Blob([]))) : l(se(u.pages, {
1498
+ title: c,
1499
+ pagePx: u.sizes
1500
+ }));
1501
+ } finally {
1502
+ f.release();
1503
+ }
1504
+ }
1505
+ function Ke(e) {
1506
+ let t = URL.createObjectURL(e.blob), n = document.createElement("a");
1507
+ n.href = t, n.download = e.filename, n.style.display = "none", document.body.appendChild(n), n.click(), n.remove(), setTimeout(() => URL.revokeObjectURL(t), 1e4);
1508
+ }
1509
+ async function qe(e, t) {
1510
+ let n = e.kind === "design" && e.mode !== "email" && !e.nodeIds?.length && e.pages && e.pages.length > 1 ? e.pages : null, r = t.format === "png" || t.format === "jpeg" || t.format === "svg";
1511
+ if (!n || !(t.format === "pdf" || r)) return Ge(e, t);
1512
+ let i = e, a = Ie.find((e) => e.id === t.format), o = He(t.filename ?? i.page.name), s = [];
1513
+ if (t.format === "pdf") {
1514
+ let e = {
1515
+ pages: [],
1516
+ sizes: []
1517
+ };
1518
+ for (let r of n) s.push(...(await Ge({
1519
+ ...i,
1520
+ page: r,
1521
+ pages: void 0
1522
+ }, t, e)).warnings);
1523
+ return {
1524
+ blob: se(e.pages, {
1525
+ title: o,
1526
+ pagePx: e.sizes
1527
+ }),
1528
+ filename: `${o}.pdf`,
1529
+ mime: a.mime,
1530
+ warnings: [...new Set(s)]
1531
+ };
1532
+ }
1533
+ let c = [];
1534
+ for (let e = 0; e < n.length; e++) {
1535
+ let r = await Ge({
1536
+ ...i,
1537
+ page: n[e],
1538
+ pages: void 0
1539
+ }, {
1540
+ ...t,
1541
+ filename: `${o}-${e + 1}`
1542
+ });
1543
+ s.push(...r.warnings), c.push({
1544
+ name: r.filename,
1545
+ data: new Uint8Array(await r.blob.arrayBuffer())
1546
+ });
1547
+ }
1548
+ return {
1549
+ blob: L(c, "application/zip"),
1550
+ filename: `${o}.zip`,
1551
+ mime: "application/zip",
1552
+ warnings: [...new Set(s)]
1553
+ };
1554
+ }
1555
+ //#endregion
1556
+ //#region src/v2/files/import.ts
1557
+ async function Je(e) {
1558
+ if (typeof DecompressionStream > "u") throw Error("This browser can't open compressed files. Please update it, or export the file as HTML or CSV first.");
1559
+ let t = new Blob([e]).stream().pipeThrough(new DecompressionStream("deflate-raw"));
1560
+ return new Uint8Array(await new Response(t).arrayBuffer());
1561
+ }
1562
+ async function Ye(e) {
1563
+ let t = new Uint8Array(e), n = new DataView(e), r = -1;
1564
+ for (let e = t.length - 22; e >= Math.max(0, t.length - 65557); e--) if (n.getUint32(e, !0) === 101010256) {
1565
+ r = e;
1566
+ break;
1567
+ }
1568
+ if (r < 0) throw Error("This doesn't look like a valid Word or Excel file.");
1569
+ let i = n.getUint16(r + 10, !0), a = n.getUint32(r + 16, !0), o = /* @__PURE__ */ new Map(), s = new TextDecoder();
1570
+ for (let e = 0; e < i && n.getUint32(a, !0) === 33639248; e++) {
1571
+ let e = n.getUint16(a + 10, !0), r = n.getUint32(a + 20, !0), i = n.getUint16(a + 28, !0), c = n.getUint16(a + 30, !0), l = n.getUint16(a + 32, !0), u = n.getUint32(a + 42, !0), d = s.decode(t.subarray(a + 46, a + 46 + i));
1572
+ if (a += 46 + i + c + l, d.endsWith("/")) continue;
1573
+ let f = u + 30 + n.getUint16(u + 26, !0) + n.getUint16(u + 28, !0), p = t.subarray(f, f + r);
1574
+ o.set(d, e === 0 ? p : e === 8 ? await Je(p) : /* @__PURE__ */ new Uint8Array());
1575
+ }
1576
+ return o;
1577
+ }
1578
+ var q = (e) => e ? new TextDecoder().decode(e) : "", J = (e) => new DOMParser().parseFromString(e, "application/xml"), Xe = (e) => {
1579
+ let t = "";
1580
+ for (let n = 0; n < e.length; n += 32768) t += String.fromCharCode(...e.subarray(n, n + 32768));
1581
+ return btoa(t);
1582
+ };
1583
+ async function Ze(e) {
1584
+ let t = await Ye(e), n = q(t.get("word/document.xml"));
1585
+ if (!n) throw Error("This Word file couldn't be read. Try saving it again from Word as a .docx.");
1586
+ let r = J(n), i = J(q(t.get("word/_rels/document.xml.rels"))), a = /* @__PURE__ */ new Map();
1587
+ for (let e of Array.from(i.getElementsByTagName("Relationship"))) a.set(e.getAttribute("Id") ?? "", e.getAttribute("Target") ?? "");
1588
+ let o = (e, t) => Array.from(e.children).filter((e) => e.tagName === t), s = (e, t) => o(e, t)[0] ?? null, c = (e) => !!e && e.getAttribute("w:val") !== "0" && e.getAttribute("w:val") !== "false", l = (e) => {
1589
+ let n = s(e, "w:rPr"), r = "";
1590
+ for (let n of Array.from(e.children)) if (n.tagName === "w:t") r += Fe(n.textContent ?? "");
1591
+ else if (n.tagName === "w:tab") r += "&emsp;";
1592
+ else if (n.tagName === "w:br") r += "<br>";
1593
+ else if (n.tagName === "w:drawing" || n.tagName === "w:pict") {
1594
+ let e = n.getElementsByTagName("a:blip")[0]?.getAttribute("r:embed"), i = e ? a.get(e) : void 0, o = i ? t.get(`word/${i.replace(/^\//, "").replace(/^word\//, "")}`) : void 0;
1595
+ if (o) {
1596
+ let e = (i ?? "").split(".").pop()?.toLowerCase(), t = e === "png" ? "image/png" : e === "gif" ? "image/gif" : e === "jpg" || e === "jpeg" ? "image/jpeg" : "";
1597
+ t && (r += `<img src="data:${t};base64,${Xe(o)}" alt="">`);
1598
+ }
1599
+ }
1600
+ if (!r) return "";
1601
+ if (n) {
1602
+ c(s(n, "w:b")) && (r = `<strong>${r}</strong>`), c(s(n, "w:i")) && (r = `<em>${r}</em>`);
1603
+ let e = s(n, "w:u");
1604
+ e && e.getAttribute("w:val") !== "none" && (r = `<u>${r}</u>`);
1605
+ }
1606
+ return r;
1607
+ }, u = (e) => Array.from(e.children).map((e) => {
1608
+ if (e.tagName === "w:r") return l(e);
1609
+ if (e.tagName === "w:hyperlink") {
1610
+ let t = a.get(e.getAttribute("r:id") ?? "") ?? "", n = o(e, "w:r").map(l).join("");
1611
+ return /^https?:|^mailto:/i.test(t) ? `<a href="${Fe(t)}">${n}</a>` : n;
1612
+ }
1613
+ return "";
1614
+ }).join(""), d = r.getElementsByTagName("w:body")[0], f = [], p = null, m = () => {
1615
+ p && f.push(`<${p.tag}>${p.items.map((e) => `<li>${e}</li>`).join("")}</${p.tag}>`), p = null;
1616
+ }, h = (e) => {
1617
+ let t = s(e, "w:pPr"), n = s(t ?? e, "w:pStyle")?.getAttribute("w:val") ?? "", r = u(e);
1618
+ if (t && s(t, "w:numPr") && r.trim()) {
1619
+ let e = /number|decimal/i.test(n) ? "ol" : "ul";
1620
+ (!p || p.tag !== e) && (m(), p = {
1621
+ tag: e,
1622
+ items: []
1623
+ }), p.items.push(r);
1624
+ return;
1625
+ }
1626
+ m();
1627
+ let i = /^Heading(\d)$/i.exec(n) ?? (/^Title$/i.test(n) ? [0, "1"] : null);
1628
+ i ? f.push(`<h${Math.min(6, Number(i[1]))}>${r}</h${Math.min(6, Number(i[1]))}>`) : r.trim() && f.push(`<p>${r}</p>`);
1629
+ };
1630
+ for (let e of Array.from(d?.children ?? [])) if (e.tagName === "w:p") h(e);
1631
+ else if (e.tagName === "w:tbl") {
1632
+ m();
1633
+ let t = o(e, "w:tr").map((e, t) => `<tr>${o(e, "w:tc").map((e) => `<${t === 0 ? "th" : "td"}>${o(e, "w:p").map(u).join("<br>")}</${t === 0 ? "th" : "td"}>`).join("")}</tr>`);
1634
+ f.push(`<table>${t.join("")}</table>`);
1635
+ }
1636
+ return m(), f.join("\n");
1637
+ }
1638
+ async function Qe(e) {
1639
+ let t = await Ye(e), n = t.has("xl/worksheets/sheet1.xml") ? "xl/worksheets/sheet1.xml" : [...t.keys()].filter((e) => /^xl\/worksheets\/[^/]+\.xml$/.test(e)).sort()[0];
1640
+ if (!n) throw Error("This Excel file couldn't be read. Try saving it again from Excel as .xlsx, or as CSV.");
1641
+ let r = [], i = t.get("xl/sharedStrings.xml");
1642
+ if (i) for (let e of Array.from(J(q(i)).getElementsByTagName("si"))) r.push(Array.from(e.getElementsByTagName("t")).map((e) => e.textContent ?? "").join(""));
1643
+ let a = J(q(t.get(n))), o = [], s = (e) => e.split("").reduce((e, t) => e * 26 + t.charCodeAt(0) - 64, 0) - 1;
1644
+ for (let e of Array.from(a.getElementsByTagName("c"))) {
1645
+ let t = /^([A-Z]+)(\d+)$/.exec(e.getAttribute("r") ?? "");
1646
+ if (!t) continue;
1647
+ let n = s(t[1]), i = Number(t[2]) - 1;
1648
+ if (i > 5e3 || n > 200) continue;
1649
+ let a = e.getAttribute("t"), c = e.getElementsByTagName("v")[0]?.textContent ?? "", l = e.getElementsByTagName("f")[0]?.textContent, u;
1650
+ for (u = l ? `=${l}` : a === "s" ? r[Number(c)] ?? "" : a === "inlineStr" ? Array.from(e.getElementsByTagName("t")).map((e) => e.textContent ?? "").join("") : a === "b" ? c === "1" ? "TRUE" : "FALSE" : c; o.length <= i;) o.push([]);
1651
+ for (; o[i].length <= n;) o[i].push("");
1652
+ o[i][n] = u;
1653
+ }
1654
+ let c = Math.max(0, ...o.map((e) => e.length));
1655
+ return o.map((e) => Array.from({ length: c }, (t, n) => e[n] ?? ""));
1656
+ }
1657
+ var Y = (t, n, r, i, a) => ({
1658
+ id: e(t),
1659
+ type: t,
1660
+ name: n,
1661
+ content: r,
1662
+ ...a ? { props: { level: a } } : {},
1663
+ styles: i
1664
+ }), $e = {
1665
+ 1: "44px",
1666
+ 2: "32px",
1667
+ 3: "24px",
1668
+ 4: "20px",
1669
+ 5: "18px",
1670
+ 6: "16px"
1671
+ }, et = (t, n, r = "#ffffff") => [{
1672
+ id: e("page"),
1673
+ name: t,
1674
+ slug: "home",
1675
+ isHome: !0,
1676
+ rootNode: {
1677
+ id: e("page"),
1678
+ type: "page",
1679
+ name: "Page",
1680
+ styles: {
1681
+ backgroundColor: r,
1682
+ textColor: "#111827",
1683
+ fontFamily: "Inter"
1684
+ },
1685
+ children: n
1686
+ }
1687
+ }];
1688
+ function X(t, n = "Untitled") {
1689
+ let r = new DOMParser().parseFromString(t, "text/html"), i = [], a = (e, t = "") => {
1690
+ let n = (e.textContent ?? "").replace(/\s+/g, " ").trim();
1691
+ n && i.push(Y("paragraph", "Text", `${t}${n}`, {
1692
+ fontSize: "18px",
1693
+ lineHeight: "1.6",
1694
+ textColor: "#374151"
1695
+ }));
1696
+ }, o = (t) => {
1697
+ let n = t.getAttribute("src");
1698
+ n && i.push({
1699
+ id: e("image"),
1700
+ type: "image",
1701
+ name: "Image",
1702
+ props: {
1703
+ src: n,
1704
+ alt: t.getAttribute("alt") ?? "",
1705
+ fit: "contain"
1706
+ },
1707
+ styles: {
1708
+ width: "100%",
1709
+ borderRadius: "8px"
1710
+ }
1711
+ });
1712
+ }, s = (e) => {
1713
+ let t = e.tagName;
1714
+ if (/^H[1-6]$/.test(t)) {
1715
+ let n = Number(t[1]), r = (e.textContent ?? "").replace(/\s+/g, " ").trim();
1716
+ r && i.push(Y("heading", "Heading", r, {
1717
+ fontSize: $e[n],
1718
+ fontWeight: "700",
1719
+ lineHeight: "1.2",
1720
+ textColor: "#111827"
1721
+ }, n));
1722
+ } else if (t === "P" || t === "BLOCKQUOTE" || t === "PRE") e.querySelectorAll("img").forEach(o), a(e);
1723
+ else if (t === "UL" || t === "OL") Array.from(e.children).forEach((e, n) => a(e, t === "OL" ? `${n + 1}. ` : "• "));
1724
+ else if (t === "IMG") o(e);
1725
+ else if (t === "TABLE") for (let t of Array.from(e.querySelectorAll("tr"))) {
1726
+ let e = Array.from(t.children).map((e) => (e.textContent ?? "").replace(/\s+/g, " ").trim()).filter(Boolean);
1727
+ e.length && i.push(Y("paragraph", "Row", e.join(" | "), {
1728
+ fontSize: "16px",
1729
+ lineHeight: "1.6",
1730
+ textColor: "#374151"
1731
+ }));
1732
+ }
1733
+ else if (t === "SCRIPT" || t === "STYLE") return;
1734
+ else Array.from(e.children).some((e) => /^(P|DIV|SECTION|ARTICLE|H[1-6]|UL|OL|TABLE|IMG|FIGURE|HEADER|FOOTER|MAIN|BLOCKQUOTE|PRE)$/.test(e.tagName)) ? Array.from(e.children).forEach(s) : a(e);
1735
+ };
1736
+ return Array.from(r.body.children).forEach(s), i.length || i.push(Y("paragraph", "Text", "Start writing…", {
1737
+ fontSize: "18px",
1738
+ textColor: "#9ca3af"
1739
+ })), et(n, [{
1740
+ id: e("section"),
1741
+ type: "section",
1742
+ name: "Content",
1743
+ styles: {
1744
+ display: "flex",
1745
+ flexDirection: "column",
1746
+ gap: "16px",
1747
+ paddingTop: "64px",
1748
+ paddingBottom: "64px",
1749
+ paddingLeft: "48px",
1750
+ paddingRight: "48px",
1751
+ maxWidth: "880px",
1752
+ margin: "0 auto"
1753
+ },
1754
+ children: i
1755
+ }]);
1756
+ }
1757
+ var tt = (e, t) => X(W(e), t), nt = (e, t) => X(Pe(e), t);
1758
+ function rt(t, n, r, i = "Image") {
1759
+ let a = Math.max(1, Math.round(n)), o = Math.max(1, Math.round(r)), s = {
1760
+ id: e("image"),
1761
+ type: "image",
1762
+ name: "Picture",
1763
+ props: {
1764
+ src: t,
1765
+ alt: i,
1766
+ fit: "cover"
1767
+ },
1768
+ styles: {
1769
+ width: "100%",
1770
+ aspectRatio: `${a} / ${o}`
1771
+ }
1772
+ };
1773
+ return et(i, [{
1774
+ id: e("section"),
1775
+ type: "section",
1776
+ name: "Picture",
1777
+ styles: {
1778
+ paddingTop: "0px",
1779
+ paddingBottom: "0px",
1780
+ paddingLeft: "0px",
1781
+ paddingRight: "0px",
1782
+ maxWidth: `${Math.min(a, 1200)}px`,
1783
+ margin: "0 auto"
1784
+ },
1785
+ children: [s]
1786
+ }], "#ffffff");
1787
+ }
1788
+ var it = (e) => new Promise((t, n) => {
1789
+ let r = new FileReader();
1790
+ r.onload = () => t(String(r.result)), r.onerror = () => n(/* @__PURE__ */ Error("That file couldn't be read.")), r.readAsDataURL(e);
1791
+ }), at = (e) => new Promise((t, n) => {
1792
+ let r = new Image();
1793
+ r.onload = () => t({
1794
+ width: r.naturalWidth || 800,
1795
+ height: r.naturalHeight || 600
1796
+ }), r.onerror = () => n(/* @__PURE__ */ Error("That picture couldn't be opened.")), r.src = e;
1797
+ }), ot = (e) => e.replace(/\.[^.]+$/, "") || "Untitled";
1798
+ async function st(e, t = "Untitled") {
1799
+ let n = e.name || t, r = ot(n), i = (n.split(".").pop() ?? "").toLowerCase(), a = e.type;
1800
+ if (a.startsWith("image/") || [
1801
+ "png",
1802
+ "jpg",
1803
+ "jpeg",
1804
+ "gif",
1805
+ "webp",
1806
+ "avif"
1807
+ ].includes(i)) {
1808
+ let t = await it(e), { width: n, height: i } = await at(t);
1809
+ return {
1810
+ type: "image",
1811
+ name: r,
1812
+ dataUrl: t,
1813
+ width: n,
1814
+ height: i
1815
+ };
1816
+ }
1817
+ if (i === "svg") {
1818
+ let t = await it(e), { width: n, height: i } = await at(t);
1819
+ return {
1820
+ type: "image",
1821
+ name: r,
1822
+ dataUrl: t,
1823
+ width: n,
1824
+ height: i
1825
+ };
1826
+ }
1827
+ if (i === "docx") return {
1828
+ type: "source",
1829
+ source: {
1830
+ kind: "document",
1831
+ name: r,
1832
+ content: await Ze(await e.arrayBuffer())
1833
+ }
1834
+ };
1835
+ if (i === "xlsx") return {
1836
+ type: "source",
1837
+ source: {
1838
+ kind: "sheet",
1839
+ name: r,
1840
+ content: await Qe(await e.arrayBuffer())
1841
+ }
1842
+ };
1843
+ if (i === "csv" || i === "tsv" || a === "text/csv") return {
1844
+ type: "source",
1845
+ source: {
1846
+ kind: "sheet",
1847
+ name: r,
1848
+ content: be(await e.text(), i === "tsv" ? " " : void 0)
1849
+ }
1850
+ };
1851
+ if (i === "md" || i === "markdown" || a === "text/markdown") return {
1852
+ type: "source",
1853
+ source: {
1854
+ kind: "markdown",
1855
+ name: r,
1856
+ content: await e.text()
1857
+ }
1858
+ };
1859
+ if (i === "html" || i === "htm" || a === "text/html") return {
1860
+ type: "source",
1861
+ source: {
1862
+ kind: "html",
1863
+ name: r,
1864
+ content: await e.text()
1865
+ }
1866
+ };
1867
+ if (i === "txt" || a === "text/plain" || !i && a === "") return {
1868
+ type: "source",
1869
+ source: {
1870
+ kind: "text",
1871
+ name: r,
1872
+ content: await e.text()
1873
+ }
1874
+ };
1875
+ if (i === "json") try {
1876
+ let t = JSON.parse(await e.text());
1877
+ if (t && typeof t == "object" && t.kind && "content" in t) return {
1878
+ type: "source",
1879
+ source: {
1880
+ ...t,
1881
+ name: t.name ?? r
1882
+ }
1883
+ };
1884
+ } catch {}
1885
+ if (i === "pdf" || a === "application/pdf") {
1886
+ let { readPdf: t } = await import("./pdfImport-BOev0Pc1.js").then((e) => e.t);
1887
+ return {
1888
+ type: "pdf",
1889
+ name: r,
1890
+ read: await t(await e.arrayBuffer())
1891
+ };
1892
+ }
1893
+ throw Error(`Plexo can't open .${i || "this type of"} files yet. It opens pictures, HTML, Word (.docx), Excel (.xlsx), CSV, Markdown and text.`);
1894
+ }
1895
+ //#endregion
1896
+ //#region src/v2/files/convert.ts
1897
+ var ct = (e) => e === "design" || e === "email", lt = {
1898
+ design: "Design",
1899
+ email: "Email",
1900
+ html: "HTML",
1901
+ document: "Document",
1902
+ text: "Text",
1903
+ markdown: "Markdown",
1904
+ sheet: "Sheet"
1905
+ }, ut = {
1906
+ design: "A web page built on the visual canvas. Saves as HTML.",
1907
+ email: "An email, built to look right in every inbox.",
1908
+ html: "Paste or write a web page as code. See it live and save it as PNG, PDF, SVG and more.",
1909
+ document: "Written pages with headings, lists and pictures, like Word.",
1910
+ text: "Just words. No formatting, nothing else.",
1911
+ markdown: "Words with simple formatting, shown styled as you type.",
1912
+ sheet: "Rows and columns with formulas, like Excel."
1913
+ }, dt = "<!doctype html>\n<html lang=\"en\">\n<head>\n <meta charset=\"utf-8\">\n <title>My page</title>\n <style>\n body { font-family: system-ui, sans-serif; margin: 0; padding: 48px; background: #f8fafc; color: #0f172a; }\n h1 { margin: 0 0 8px; font-size: 40px; }\n p { margin: 0; color: #475569; font-size: 18px; }\n </style>\n</head>\n<body>\n <h1>Hello</h1>\n <p>Paste your own HTML here, or start typing.</p>\n</body>\n</html>\n", ft = (e) => {
1914
+ switch (e) {
1915
+ case "design": return t();
1916
+ case "email": return o();
1917
+ case "sheet": return Array.from({ length: 30 }, () => Array(12).fill(""));
1918
+ case "html": return dt;
1919
+ default: return "";
1920
+ }
1921
+ }, pt = (e, t, n) => ({
1922
+ kind: e,
1923
+ name: t,
1924
+ content: n
1925
+ });
1926
+ function Z(e, t, n) {
1927
+ switch (e) {
1928
+ case "design":
1929
+ case "email": {
1930
+ let e = t[0];
1931
+ return e ? i(e, {
1932
+ designSystem: n,
1933
+ runtime: "none"
1934
+ }).html : "";
1935
+ }
1936
+ case "html": return new DOMParser().parseFromString(t, "text/html").body.innerHTML;
1937
+ case "document": return t;
1938
+ case "text": return Pe(t);
1939
+ case "markdown": return W(t);
1940
+ case "sheet": return Te(t);
1941
+ }
1942
+ }
1943
+ function mt(e) {
1944
+ let t = new DOMParser().parseFromString(e, "text/html"), n = /* @__PURE__ */ new Set([
1945
+ "href",
1946
+ "src",
1947
+ "alt"
1948
+ ]), r = /^(P|DIV|SECTION|ARTICLE|HEADER|FOOTER|MAIN|NAV|ASIDE|H[1-6]|UL|OL|LI|TABLE|BLOCKQUOTE|PRE|HR|FIGURE|FORM)$/, i = (e) => {
1949
+ Array.from(e.children).forEach(i);
1950
+ for (let t of Array.from(e.attributes)) n.has(t.name) || e.removeAttribute(t.name);
1951
+ let a = e.tagName;
1952
+ if (a === "DIV" || a === "SECTION" || a === "ARTICLE" || a === "HEADER" || a === "FOOTER" || a === "MAIN" || a === "NAV" || a === "ASIDE" || a === "FIGURE") {
1953
+ if (!(e.textContent ?? "").trim() && !e.querySelector("img,hr,table")) {
1954
+ e.remove();
1955
+ return;
1956
+ }
1957
+ if (Array.from(e.children).some((e) => r.test(e.tagName) || e.tagName === "IMG")) e.replaceWith(...Array.from(e.childNodes));
1958
+ else {
1959
+ let n = t.createElement("p");
1960
+ n.append(...Array.from(e.childNodes)), e.replaceWith(n);
1961
+ }
1962
+ } else (a === "P" || a === "SPAN") && !(e.textContent ?? "").trim() && !e.querySelector("img") && e.remove();
1963
+ };
1964
+ return Array.from(t.body.children).forEach(i), t.body.innerHTML.replace(/\n{2,}/g, "\n");
1965
+ }
1966
+ var ht = (e) => {
1967
+ let t = new DOMParser().parseFromString(e, "text/html").querySelector("table");
1968
+ if (!t) return null;
1969
+ let n = Array.from(t.querySelectorAll("tr")).map((e) => Array.from(e.children).map((e) => (e.textContent ?? "").trim())), r = Math.max(0, ...n.map((e) => e.length));
1970
+ return n.length ? n.map((e) => Array.from({ length: r }, (t, n) => e[n] ?? "")) : null;
1971
+ };
1972
+ function gt(e, t, n, r, a) {
1973
+ if (e === t) return n;
1974
+ if (t === "html") {
1975
+ if (ct(e)) {
1976
+ let e = n[0];
1977
+ return e ? i(e, {
1978
+ designSystem: a,
1979
+ title: r,
1980
+ runtime: "none"
1981
+ }).document : dt;
1982
+ }
1983
+ return G(r, Z(e, n, a), { mono: e === "text" });
1984
+ }
1985
+ if (t === "sheet") {
1986
+ let t = Z(e, n, a);
1987
+ return ht(t) ?? be(e === "text" ? n : U(t), " ");
1988
+ }
1989
+ if (e === "sheet") {
1990
+ let e = n;
1991
+ if (t === "text") return _t(e);
1992
+ if (t === "markdown") return Ee(e);
1993
+ }
1994
+ let o = Z(e, n, a);
1995
+ switch (t) {
1996
+ case "document": return ct(e) || e === "html" ? mt(o) : o;
1997
+ case "text": return U(e === "markdown" ? W(n) : o);
1998
+ case "markdown": return e === "text" ? n : Me(o);
1999
+ case "design":
2000
+ case "email": return X(o, r);
2001
+ default: return n;
2002
+ }
2003
+ }
2004
+ var _t = (e) => e.map((e) => e.join(" ").replace(/\s+$/, "")).join("\n").trim(), vt = (e, t) => e !== t && t !== "html" && e !== "text" && !(e === "markdown" && t === "document"), yt = 250, bt = 12, Q = (e, t, n, r) => {
2005
+ let i = typeof e == "number" ? e : typeof e == "string" ? parseFloat(e) : NaN;
2006
+ return Number.isFinite(i) ? Math.min(n, Math.max(t, i)) : r;
2007
+ }, $ = (e, t) => typeof e == "string" && /^(#[0-9a-f]{3,8}|rgba?\(\s*[\d.\s,%/]+\)|[a-z]{3,20})$/i.test(e.trim()) ? e.trim() : t;
2008
+ function xt(e) {
2009
+ let t = e;
2010
+ if (typeof t == "string") try {
2011
+ t = JSON.parse(t.trim().replace(/^```(?:json)?/i, "").replace(/```$/, "").trim());
2012
+ } catch {
2013
+ return null;
2014
+ }
2015
+ if (!t || typeof t != "object") return null;
2016
+ let n = t, r = Q(n.width, 16, 8e3, 0), i = Q(n.height, 16, 8e3, 0);
2017
+ if (!r || !i || !Array.isArray(n.elements)) return null;
2018
+ let a = [], o = 0;
2019
+ for (let e of n.elements.slice(0, yt)) {
2020
+ if (!e || typeof e != "object") continue;
2021
+ let t = e, n = Q(t.x, -r, r * 2, 0), s = Q(t.y, -i, i * 2, 0), c = Q(t.w, 1, r * 2, 0), l = Q(t.h, 1, i * 2, 0);
2022
+ if (t.type === "text") {
2023
+ let e = typeof t.text == "string" ? t.text.slice(0, 2e3) : "";
2024
+ if (!e.trim() || !c) continue;
2025
+ a.push({
2026
+ type: "text",
2027
+ text: e,
2028
+ x: n,
2029
+ y: s,
2030
+ w: c,
2031
+ h: l || void 0,
2032
+ fontSize: Q(t.fontSize, 6, 400, 16),
2033
+ color: $(t.color, "#111827"),
2034
+ bold: t.bold === !0 || typeof t.fontWeight == "number" && t.fontWeight >= 600,
2035
+ italic: t.italic === !0,
2036
+ uppercase: t.uppercase === !0,
2037
+ align: t.align === "center" || t.align === "right" ? t.align : "left",
2038
+ letterSpacing: Q(t.letterSpacing, -5, 40, 0),
2039
+ lineHeight: Q(t.lineHeight, .8, 3, 1.25)
2040
+ });
2041
+ } else if (t.type === "shape") {
2042
+ if (!c || !l) continue;
2043
+ a.push({
2044
+ type: "shape",
2045
+ x: n,
2046
+ y: s,
2047
+ w: c,
2048
+ h: l,
2049
+ fill: t.fill ? $(t.fill, "transparent") : void 0,
2050
+ radius: Q(t.radius, 0, 5e3, 0),
2051
+ borderWidth: Q(t.borderWidth, 0, 40, 0),
2052
+ borderColor: t.borderColor ? $(t.borderColor, "#000000") : void 0,
2053
+ shadow: t.shadow === !0,
2054
+ opacity: Q(t.opacity, 0, 1, 1)
2055
+ });
2056
+ } else if (t.type === "picture") {
2057
+ if (!c || !l || c < 24 || l < 24 || o >= bt) continue;
2058
+ o++, a.push({
2059
+ type: "picture",
2060
+ x: n,
2061
+ y: s,
2062
+ w: c,
2063
+ h: l,
2064
+ radius: Q(t.radius, 0, 5e3, 0),
2065
+ label: typeof t.label == "string" ? t.label.slice(0, 120) : void 0
2066
+ });
2067
+ }
2068
+ }
2069
+ return a.length ? {
2070
+ width: r,
2071
+ height: i,
2072
+ background: $(n.background, "#ffffff"),
2073
+ elements: a
2074
+ } : null;
2075
+ }
2076
+ var St = (e) => new Promise((t, n) => {
2077
+ let r = new Image();
2078
+ r.onload = () => t(r), r.onerror = () => n(/* @__PURE__ */ Error("The picture could not be opened.")), r.src = e;
2079
+ });
2080
+ async function Ct(e, t, n) {
2081
+ let r = t.width / e.width, i = Math.min(1, 1200 / t.width), a = r * i, o = Math.round(t.width * i), d = Math.round(t.height * i), f = e.elements.some((e) => e.type === "picture") ? await St(t.dataUrl) : null, p = [], m = 0;
2082
+ for (let i of e.elements) if (i.type === "shape") {
2083
+ let e = {
2084
+ x: i.x * a,
2085
+ y: i.y * a,
2086
+ w: i.w * a,
2087
+ h: i.h * a,
2088
+ fill: i.fill,
2089
+ radius: (i.radius ?? 0) * a,
2090
+ borderWidth: i.borderWidth ? Math.max(1, i.borderWidth * a) : void 0,
2091
+ borderColor: i.borderColor,
2092
+ shadow: i.shadow ? "0 8px 24px rgba(0,0,0,0.18)" : void 0,
2093
+ opacity: i.opacity
2094
+ };
2095
+ p.push(c(e));
2096
+ } else if (i.type === "picture" && f) {
2097
+ let e = Math.max(0, i.x * r), o = Math.max(0, i.y * r), s = Math.min(t.width - e, i.w * r), c = Math.min(t.height - o, i.h * r);
2098
+ if (s < 8 || c < 8) continue;
2099
+ let u = Math.min(1, 1400 / Math.max(s, c)), d = document.createElement("canvas");
2100
+ d.width = Math.max(1, Math.round(s * u)), d.height = Math.max(1, Math.round(c * u)), d.getContext("2d").drawImage(f, e, o, s, c, 0, 0, d.width, d.height);
2101
+ let h = await new Promise((e) => d.toBlob(e, "image/jpeg", .88));
2102
+ if (!h) continue;
2103
+ let g = await n(new File([h], `${t.name}-photo-${++m}.jpg`, { type: "image/jpeg" }));
2104
+ p.push(l(g, {
2105
+ x: i.x * a,
2106
+ y: i.y * a,
2107
+ w: i.w * a,
2108
+ h: i.h * a,
2109
+ radius: (i.radius ?? 0) * a
2110
+ }, {
2111
+ name: i.label || "Photo",
2112
+ alt: i.label
2113
+ }));
2114
+ } else if (i.type === "text") {
2115
+ let e = {
2116
+ text: i.text,
2117
+ x: i.x * a,
2118
+ y: i.y * a,
2119
+ w: i.w * a + 2,
2120
+ fontSize: i.fontSize * a,
2121
+ color: i.color ?? "#111827",
2122
+ bold: i.bold,
2123
+ italic: i.italic,
2124
+ align: i.align,
2125
+ wrap: !0,
2126
+ uppercase: i.uppercase,
2127
+ letterSpacing: (i.letterSpacing ?? 0) * a,
2128
+ lineHeight: i.lineHeight
2129
+ };
2130
+ p.push(u(e));
2131
+ }
2132
+ return s(t.name, o, d, p, e.background);
2133
+ }
2134
+ async function wt(e) {
2135
+ let t = await St(e), n = Math.min(1, 1600 / Math.max(t.naturalWidth, t.naturalHeight)), r = document.createElement("canvas");
2136
+ r.width = Math.max(1, Math.round(t.naturalWidth * n)), r.height = Math.max(1, Math.round(t.naturalHeight * n));
2137
+ let i = r.getContext("2d");
2138
+ return i.fillStyle = "#ffffff", i.fillRect(0, 0, r.width, r.height), i.drawImage(t, 0, 0, r.width, r.height), {
2139
+ dataUrl: r.toDataURL("image/jpeg", .85),
2140
+ width: r.width,
2141
+ height: r.height
2142
+ };
2143
+ }
2144
+ var Tt = async ({ image: e, width: t, height: n, name: r, signal: i }) => {
2145
+ let a;
2146
+ try {
2147
+ a = await fetch("/api/v1/ai/image-to-design", {
2148
+ method: "POST",
2149
+ headers: { "Content-Type": "application/json" },
2150
+ body: JSON.stringify({
2151
+ image: e,
2152
+ width: t,
2153
+ height: n,
2154
+ name: r
2155
+ }),
2156
+ signal: i
2157
+ });
2158
+ } catch (e) {
2159
+ throw i?.aborted ? e : Error("We couldn't reach Plexo to rebuild the picture. Check your connection and try again.");
2160
+ }
2161
+ let o = await a.json().catch(() => null);
2162
+ if (!a.ok) throw Error(o?.error || (a.status === 402 ? "You're out of AI credits. Top up, or add your own key in Settings." : "The AI couldn't rebuild this picture. Try again in a moment."));
2163
+ return o?.spec;
2164
+ };
2165
+ async function Et(e, t, n, r) {
2166
+ let i = await wt(e.dataUrl), a = xt(await t({
2167
+ image: i.dataUrl,
2168
+ width: i.width,
2169
+ height: i.height,
2170
+ name: e.name,
2171
+ signal: r
2172
+ }));
2173
+ if (!a) throw Error("The AI couldn't make out what's in this picture. Try a clearer or larger one.");
2174
+ return [await Ct({
2175
+ ...a,
2176
+ width: i.width,
2177
+ height: i.height
2178
+ }, e, n)];
2179
+ }
2180
+ var Dt = "You turn a picture of a design (a poster, flyer, web page, social post, slide, screenshot, document page) into a description of its parts, so each part can be rebuilt as an editable element. You are shown ONE picture of exactly {width}x{height} pixels. Measure everything in those pixels, origin at the top-left.\n\nReply with ONLY one JSON object, no markdown, no commentary:\n{\"width\":{width},\"height\":{height},\"background\":\"#rrggbb\",\"elements\":[ ... ]}\n\nElements, listed from the back to the front (things drawn underneath come first):\n- {\"type\":\"shape\",\"x\":0,\"y\":0,\"w\":0,\"h\":0,\"fill\":\"#rrggbb\",\"radius\":0,\"borderWidth\":0,\"borderColor\":\"#rrggbb\",\"shadow\":false,\"opacity\":1} for every plain coloured area: cards, buttons, bars, banners, dividers, circles (radius = half the size), panels. Leave fill out for outline-only boxes.\n- {\"type\":\"text\",\"text\":\"exact words\",\"x\":0,\"y\":0,\"w\":0,\"fontSize\":0,\"color\":\"#rrggbb\",\"bold\":false,\"italic\":false,\"align\":\"left\",\"uppercase\":false,\"lineHeight\":1.25,\"letterSpacing\":0} for every piece of writing. x,y is the top-left of the text block, w its width, fontSize the height of a capital letter times 1.4 (in pixels). Keep a paragraph as ONE element with its own line breaks removed; give a separate element to each heading, label and button caption. Copy the words exactly as written; do not translate or fix them.\n- {\"type\":\"picture\",\"x\":0,\"y\":0,\"w\":0,\"h\":0,\"radius\":0,\"label\":\"what it shows\"} for every photo or illustration or logo, anything that is an image rather than flat colour or writing. It will be cut out of the original, so only give its box.\n\nRules: be exact about positions and sizes; use the real colours you see; do not invent anything that is not in the picture; do not describe text that is inside a \"picture\" box separately; at most 250 elements (group tiny repeated details into one picture); the numbers are plain numbers, never strings.";
2181
+ //#endregion
2182
+ export { Pe as A, Le as C, Me as D, G as E, L as F, B as M, be as N, U as O, xe as P, Ie as S, qe as T, tt as _, Ct as a, Qe as b, ft as c, ct as d, vt as f, rt as g, X as h, Tt as i, ve as j, W as k, Z as l, Ze as m, Et as n, ut as o, pt as p, xt as r, lt as s, Dt as t, gt as u, st as v, Ke as w, Re as x, nt as y };