textmode.export.js 1.2.2 → 1.3.0

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 +1 -0
  2. package/dist/textmode.export.esm.js +1274 -1149
  3. package/dist/textmode.export.umd.js +2 -2
  4. package/dist/types/exporters/base/CharacterResolver.d.ts +29 -0
  5. package/dist/types/exporters/base/CharacterResolver.d.ts.map +1 -0
  6. package/dist/types/exporters/base/DataExtractor.d.ts +23 -2
  7. package/dist/types/exporters/base/DataExtractor.d.ts.map +1 -1
  8. package/dist/types/exporters/base/index.d.ts +1 -0
  9. package/dist/types/exporters/base/index.d.ts.map +1 -1
  10. package/dist/types/exporters/json/JSONDataExtractor.d.ts +16 -0
  11. package/dist/types/exporters/json/JSONDataExtractor.d.ts.map +1 -0
  12. package/dist/types/exporters/json/JSONExporter.d.ts +56 -0
  13. package/dist/types/exporters/json/JSONExporter.d.ts.map +1 -0
  14. package/dist/types/exporters/json/JSONExporter.test.d.ts +2 -0
  15. package/dist/types/exporters/json/JSONExporter.test.d.ts.map +1 -0
  16. package/dist/types/exporters/json/index.d.ts +4 -0
  17. package/dist/types/exporters/json/index.d.ts.map +1 -0
  18. package/dist/types/exporters/json/types.d.ts +135 -0
  19. package/dist/types/exporters/json/types.d.ts.map +1 -0
  20. package/dist/types/exporters/svg/SVGContentGenerator.d.ts.map +1 -1
  21. package/dist/types/exporters/svg/SVGDataExtractor.d.ts +0 -8
  22. package/dist/types/exporters/svg/SVGDataExtractor.d.ts.map +1 -1
  23. package/dist/types/exporters/svg/SVGExporter.test.d.ts +2 -0
  24. package/dist/types/exporters/svg/SVGExporter.test.d.ts.map +1 -0
  25. package/dist/types/exporters/svg/SVGPathGenerator.d.ts +6 -14
  26. package/dist/types/exporters/svg/SVGPathGenerator.d.ts.map +1 -1
  27. package/dist/types/exporters/svg/types.d.ts +1 -1
  28. package/dist/types/exporters/svg/types.d.ts.map +1 -1
  29. package/dist/types/exporters/txt/TXTExporter.d.ts.map +1 -1
  30. package/dist/types/index.d.ts +4 -2
  31. package/dist/types/index.d.ts.map +1 -1
  32. package/dist/types/overlay/blades/JSONBlade.d.ts +15 -0
  33. package/dist/types/overlay/blades/JSONBlade.d.ts.map +1 -0
  34. package/dist/types/overlay/blades/index.d.ts +1 -0
  35. package/dist/types/overlay/blades/index.d.ts.map +1 -1
  36. package/dist/types/overlay/core/OverlayController.d.ts.map +1 -1
  37. package/dist/types/overlay/formatRegistry.d.ts.map +1 -1
  38. package/dist/types/overlay/services/ClipboardService.d.ts +2 -1
  39. package/dist/types/overlay/services/ClipboardService.d.ts.map +1 -1
  40. package/dist/types/overlay/services/ExportService.d.ts.map +1 -1
  41. package/dist/types/overlay/types.d.ts +3 -1
  42. package/dist/types/overlay/types.d.ts.map +1 -1
  43. package/dist/types/types.d.ts +36 -0
  44. package/dist/types/types.d.ts.map +1 -1
  45. package/dist/types/version.d.ts +2 -0
  46. package/dist/types/version.d.ts.map +1 -0
  47. package/package.json +32 -29
@@ -1,957 +1,1019 @@
1
- class At {
2
- $extractFramebufferData(t) {
3
- return { characterPixels: t.readPixels(0), primaryColorPixels: t.readPixels(1), secondaryColorPixels: t.readPixels(2) };
1
+ var Yt = Object.defineProperty;
2
+ var Qt = (i, r, t) => r in i ? Yt(i, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[r] = t;
3
+ var p = (i, r, t) => Qt(i, typeof r != "symbol" ? r + "" : r, t);
4
+ class xt {
5
+ $extractFramebufferData(r) {
6
+ return { characterPixels: r.readPixels(0), primaryColorPixels: r.readPixels(1), secondaryColorPixels: r.readPixels(2) };
4
7
  }
5
- $getCharacterIndex(t, e) {
6
- return t[e] + (t[e + 1] << 8);
8
+ $getEncodedCharacterValue(r, t) {
9
+ return r[t] + (r[t + 1] << 8);
10
+ }
11
+ $getCharacterIndex(r, t) {
12
+ return this.$getEncodedCharacterValue(r, t);
13
+ }
14
+ $extractCellTransform(r, t) {
15
+ const e = r[t + 2], a = r[t + 3] / 255;
16
+ return { isInverted: !!(1 & e), flipHorizontal: !!(2 & e), flipVertical: !!(4 & e), rotation: Math.round(360 * a * 100) / 100 };
7
17
  }
8
18
  }
9
- class Q {
10
- $downloadFile(t, e) {
19
+ class H {
20
+ $downloadFile(r, t) {
11
21
  try {
12
- const r = this._sanitizeFilename(e), a = URL.createObjectURL(t), i = document.createElement("a");
13
- i.href = a, i.download = r, i.style.display = "none", i.rel = "noopener", document.body.appendChild(i), i.click(), document.body.removeChild(i), URL.revokeObjectURL(a);
14
- } catch (r) {
15
- console.error("[textmode-export] Failed to download file:", r);
22
+ const e = this._sanitizeFilename(t), a = URL.createObjectURL(r), o = document.createElement("a");
23
+ o.href = a, o.download = e, o.style.display = "none", o.rel = "noopener", document.body.appendChild(o), o.click(), document.body.removeChild(o), URL.revokeObjectURL(a);
24
+ } catch (e) {
25
+ console.error("[textmode-export] Failed to download file:", e);
16
26
  }
17
27
  }
18
- _sanitizeFilename(t) {
19
- if (!t) return this._generateDefaultFilename();
20
- const e = t.trim();
21
- return e ? e.replace(/[<>:"/\\|?*]/g, "_").replace(/\s+/g, "_").replace(/_{2,}/g, "_").replace(/^_+|_+$/g, "").substring(0, 255) || this._generateDefaultFilename() : this._generateDefaultFilename();
28
+ _sanitizeFilename(r) {
29
+ if (!r) return this._generateDefaultFilename();
30
+ const t = r.trim();
31
+ return t ? t.replace(/[<>:"/\\|?*]/g, "_").replace(/\s+/g, "_").replace(/_{2,}/g, "_").replace(/^_+|_+$/g, "").substring(0, 255) || this._generateDefaultFilename() : this._generateDefaultFilename();
22
32
  }
23
33
  _generateDefaultFilename() {
24
34
  return `textmode-export-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 19).replace(/:/g, "-")}`;
25
35
  }
26
36
  }
27
- function ft(n, t) {
28
- return { r: n[t], g: n[t + 1], b: n[t + 2], a: n[t + 3] };
37
+ const wt = /* @__PURE__ */ new WeakMap();
38
+ function Kt(i) {
39
+ return Math.round(255 * i[0]) + (Math.round(255 * i[1]) << 8);
29
40
  }
30
- class qt extends At {
31
- _extractTransformData(t, e) {
32
- const r = t[e + 2], a = !!(1 & r), i = !!(2 & r), s = !!(4 & r), l = t[e + 3] / 255;
33
- return { isInverted: a, flipHorizontal: i, flipVertical: s, rotation: Math.round(360 * l * 100) / 100 };
41
+ function yt(i, r) {
42
+ let t = wt.get(i);
43
+ if (!t) {
44
+ t = /* @__PURE__ */ new Map();
45
+ for (const e of i.characters) t.set(Kt(e.color), e);
46
+ wt.set(i, t);
34
47
  }
35
- _calculateCellPosition(t, e, r) {
36
- return { x: t, y: e, cellX: t * r.cellWidth, cellY: e * r.cellHeight };
48
+ return t.get(r);
49
+ }
50
+ function it(i, r) {
51
+ return { r: i[r], g: i[r + 1], b: i[r + 2], a: i[r + 3] };
52
+ }
53
+ class Zt extends xt {
54
+ _calculateCellPosition(r, t, e) {
55
+ return { x: r, y: t, cellX: r * e.cellWidth, cellY: t * e.cellHeight };
37
56
  }
38
- $extractSVGCellData(t, e) {
39
- const r = [];
57
+ $extractSVGCellData(r, t) {
58
+ const e = [];
40
59
  let a = 0;
41
- for (let i = 0; i < e.rows; i++) for (let s = 0; s < e.cols; s++) {
42
- const l = 4 * a, d = this.$getCharacterIndex(t.characterPixels, l);
43
- let p = ft(t.primaryColorPixels, l), o = ft(t.secondaryColorPixels, l);
44
- const c = this._extractTransformData(t.characterPixels, l);
60
+ for (let o = 0; o < t.rows; o++) for (let s = 0; s < t.cols; s++) {
61
+ const d = 4 * a, l = this.$getEncodedCharacterValue(r.characterPixels, d);
62
+ let h = it(r.primaryColorPixels, d), n = it(r.secondaryColorPixels, d);
63
+ const c = this.$extractCellTransform(r.characterPixels, d);
45
64
  if (c.isInverted) {
46
- const m = p;
47
- p = o, o = m;
65
+ const f = h;
66
+ h = n, n = f;
48
67
  }
49
- const u = this._calculateCellPosition(s, i, e);
50
- r.push({ charIndex: d, primaryColor: p, secondaryColor: o, transform: c, position: u }), a++;
68
+ const u = this._calculateCellPosition(s, o, t);
69
+ e.push({ encodedGlyphSlot: l, primaryColor: h, secondaryColor: n, transform: c, position: u }), a++;
51
70
  }
52
- return r;
53
- }
54
- }
55
- class Ht {
56
- _createGlyphPath(t, e, r, a, i) {
57
- const s = i / t.head.unitsPerEm;
58
- return { getBoundingBox: () => ({ x1: r + e.xMin * s, y1: a + -e.yMax * s, x2: r + e.xMax * s, y2: a + -e.yMin * s }), toSVG: () => this._glyphToSVGPath(e, r, a, s) };
59
- }
60
- _glyphToSVGPath(t, e, r, a) {
61
- if (!t || !t.xs) return "";
62
- const { xs: i, ys: s, endPts: l, flags: d } = t;
63
- if (!(i && s && l && d)) return "";
64
- let p = "", o = 0;
65
- for (let c = 0; c < l.length; c++) {
66
- const u = l[c];
67
- if (!(u < o)) {
68
- if (u >= o) {
69
- const m = e + i[o] * a, x = r - s[o] * a;
70
- p += `M${m.toFixed(2)},${x.toFixed(2)}`;
71
- let h = o + 1;
72
- for (; h <= u; )
73
- if (1 & d[h]) {
74
- const g = e + i[h] * a, _ = r - s[h] * a;
75
- p += `L${g.toFixed(2)},${_.toFixed(2)}`, h++;
71
+ return e;
72
+ }
73
+ }
74
+ class te {
75
+ _createGlyphPath(r, t, e, a, o) {
76
+ const s = o / r.head.unitsPerEm;
77
+ return { getBoundingBox: () => ({ x1: e + t.xMin * s, y1: a + -t.yMax * s, x2: e + t.xMax * s, y2: a + -t.yMin * s }), toSVG: () => this._glyphToSVGPath(t, e, a, s) };
78
+ }
79
+ _glyphToSVGPath(r, t, e, a) {
80
+ if (!r || !r.xs) return "";
81
+ const { xs: o, ys: s, endPts: d, flags: l } = r;
82
+ if (!(o && s && d && l)) return "";
83
+ let h = "", n = 0;
84
+ for (let c = 0; c < d.length; c++) {
85
+ const u = d[c];
86
+ if (!(u < n)) {
87
+ if (u >= n) {
88
+ const f = t + o[n] * a, y = e - s[n] * a;
89
+ h += `M${f.toFixed(2)},${y.toFixed(2)}`;
90
+ let m = n + 1;
91
+ for (; m <= u; )
92
+ if (1 & l[m]) {
93
+ const v = t + o[m] * a, w = e - s[m] * a;
94
+ h += `L${v.toFixed(2)},${w.toFixed(2)}`, m++;
76
95
  } else {
77
- const g = e + i[h] * a, _ = r - s[h] * a, v = h + 1 > u ? o : h + 1;
78
- if (1 & d[v]) {
79
- const f = e + i[v] * a, C = r - s[v] * a;
80
- p += `Q${g.toFixed(2)},${_.toFixed(2)} ${f.toFixed(2)},${C.toFixed(2)}`, h = v + 1;
96
+ const v = t + o[m] * a, w = e - s[m] * a, x = m + 1 > u ? n : m + 1;
97
+ if (1 & l[x]) {
98
+ const g = t + o[x] * a, E = e - s[x] * a;
99
+ h += `Q${v.toFixed(2)},${w.toFixed(2)} ${g.toFixed(2)},${E.toFixed(2)}`, m = x + 1;
81
100
  } else {
82
- const f = (g + (e + i[v] * a)) / 2, C = (_ + (r - s[v] * a)) / 2;
83
- p += `Q${g.toFixed(2)},${_.toFixed(2)} ${f.toFixed(2)},${C.toFixed(2)}`, h = v;
101
+ const g = (v + (t + o[x] * a)) / 2, E = (w + (e - s[x] * a)) / 2;
102
+ h += `Q${v.toFixed(2)},${w.toFixed(2)} ${g.toFixed(2)},${E.toFixed(2)}`, m = x;
84
103
  }
85
104
  }
86
- p += "Z";
105
+ h += "Z";
87
106
  }
88
- o = u + 1;
107
+ n = u + 1;
89
108
  }
90
109
  }
91
- return p;
92
- }
93
- _generateCharacterPath(t, e, r, a, i) {
94
- const s = e.characterMap.get(t)?.glyphData;
95
- return s ? this._createGlyphPath(e.font, s, r, a, i) : null;
110
+ return h;
96
111
  }
97
- $generatePositionedCharacterPath(t, e, r, a, i, s, l, d) {
98
- if (!d) return null;
99
- const p = l / e.font.head.unitsPerEm, o = r + (i - d.advanceWidth * p) / 2, c = a + (s + 0.7 * l) / 2, u = this._generateCharacterPath(t, e, o, c, l);
100
- return u && u.toSVG() || null;
112
+ $generatePositionedCharacterPath(r, t, e, a, o, s, d, l) {
113
+ if (!l) return null;
114
+ const h = t.font, n = d / h.head.unitsPerEm, c = e + (o - l.advanceWidth * n) / 2, u = a + h.hhea.ascender * n;
115
+ return this._createGlyphPath(h, l, c, u, d).toSVG() || null;
101
116
  }
102
117
  }
103
- class jt {
104
- _pathGenerator;
118
+ class ee {
105
119
  constructor() {
106
- this._pathGenerator = new Ht();
120
+ p(this, "_pathGenerator");
121
+ this._pathGenerator = new te();
107
122
  }
108
- $generateSVGHeader(t) {
109
- const { width: e, height: r } = t;
110
- return `<?xml version="1.0" encoding="UTF-8"?><svg width="${e}" height="${r}" viewBox="0 0 ${e} ${r}" xmlns="http://www.w3.org/2000/svg"><title>textmode.js sketch</title>`;
123
+ $generateSVGHeader(r) {
124
+ const { width: t, height: e } = r;
125
+ return `<?xml version="1.0" encoding="UTF-8"?><svg width="${t}" height="${e}" viewBox="0 0 ${t} ${e}" xmlns="http://www.w3.org/2000/svg"><title>textmode.js sketch</title>`;
111
126
  }
112
127
  $generateSVGFooter() {
113
128
  return "</g></svg>";
114
129
  }
115
- _generateTransformAttribute(t, e) {
116
- const { transform: r, position: a } = t;
117
- if (!r.flipHorizontal && !r.flipVertical && !r.rotation) return "";
118
- const i = a.cellX + e.cellWidth / 2, s = a.cellY + e.cellHeight / 2, l = [];
119
- if (r.flipHorizontal || r.flipVertical) {
120
- const d = r.flipHorizontal ? -1 : 1, p = r.flipVertical ? -1 : 1;
121
- l.push(`translate(${i} ${s})scale(${d} ${p})translate(${-i} ${-s})`);
130
+ _generateTransformAttribute(r, t) {
131
+ const { transform: e, position: a } = r;
132
+ if (!e.flipHorizontal && !e.flipVertical && !e.rotation) return "";
133
+ const o = a.cellX + t.cellWidth / 2, s = a.cellY + t.cellHeight / 2, d = [];
134
+ if (e.flipHorizontal || e.flipVertical) {
135
+ const l = e.flipHorizontal ? -1 : 1, h = e.flipVertical ? -1 : 1;
136
+ d.push(`translate(${o} ${s})scale(${l} ${h})translate(${-o} ${-s})`);
122
137
  }
123
- return r.rotation && l.push(`rotate(${r.rotation} ${i} ${s})`), ` transform="${l.join(" ")}"`;
138
+ return e.rotation && d.push(`rotate(${e.rotation} ${o} ${s})`), ` transform="${d.join(" ")}"`;
124
139
  }
125
- _generateCellBackground(t, e, r) {
126
- if (!r.includeBackgroundRectangles || t.secondaryColor.a === 0) return "";
127
- const { position: a } = t, { r: i, g: s, b: l, a: d } = t.secondaryColor, p = `rgba(${i},${s},${l},${d / 255})`;
128
- return r.drawMode === "stroke" ? `<rect x="${a.cellX}" y="${a.cellY}" width="${e.cellWidth}" height="${e.cellHeight}" stroke="${p}" fill="none" stroke-width="${r.strokeWidth}"/>` : `<rect x="${a.cellX}" y="${a.cellY}" width="${e.cellWidth}" height="${e.cellHeight}" fill="${p}"/>`;
140
+ _generateCellBackground(r, t, e) {
141
+ if (!e.includeBackgroundRectangles || r.secondaryColor.a === 0) return "";
142
+ const { position: a } = r, { r: o, g: s, b: d, a: l } = r.secondaryColor, h = `rgba(${o},${s},${d},${l / 255})`;
143
+ return e.drawMode === "stroke" ? `<rect x="${a.cellX}" y="${a.cellY}" width="${t.cellWidth}" height="${t.cellHeight}" stroke="${h}" fill="none" stroke-width="${e.strokeWidth}"/>` : `<rect x="${a.cellX}" y="${a.cellY}" width="${t.cellWidth}" height="${t.cellHeight}" fill="${h}"/>`;
129
144
  }
130
- _generateCharacterPath(t, e, r, a) {
131
- const i = r.characters[t.charIndex];
132
- if (!i) return "";
133
- const s = this._pathGenerator.$generatePositionedCharacterPath(i.character, r, t.position.cellX, t.position.cellY, e.cellWidth, e.cellHeight, r.fontSize, i.glyphData);
145
+ _generateCharacterPath(r, t, e, a) {
146
+ const o = yt(e, r.encodedGlyphSlot);
147
+ if (!o) return "";
148
+ const s = this._pathGenerator.$generatePositionedCharacterPath(o.character, e, r.position.cellX, r.position.cellY, t.cellWidth, t.cellHeight, e.fontSize, o.glyphData);
134
149
  if (!s) return "";
135
- const { r: l, g: d, b: p, a: o } = t.primaryColor, c = `rgba(${l},${d},${p},${o / 255})`;
150
+ const { r: d, g: l, b: h, a: n } = r.primaryColor, c = `rgba(${d},${l},${h},${n / 255})`;
136
151
  return a.drawMode === "stroke" ? `<path d="${s}" stroke="${c}" stroke-width="${a.strokeWidth}" fill="none"/>` : `<path d="${s}" fill="${c}"/>`;
137
152
  }
138
- $generateCellContent(t, e, r, a) {
139
- const i = [], s = this._generateCellBackground(t, e, a);
140
- s && i.push(s);
141
- const l = this._generateCharacterPath(t, e, r, a);
142
- if (l) {
143
- const d = this._generateTransformAttribute(t, e);
144
- i.push(d ? `<g${d}>${l}</g>` : l);
153
+ $generateCellContent(r, t, e, a) {
154
+ const o = [], s = this._generateCellBackground(r, t, a);
155
+ s && o.push(s);
156
+ const d = this._generateCharacterPath(r, t, e, a);
157
+ if (d) {
158
+ const l = this._generateTransformAttribute(r, t);
159
+ o.push(l ? `<g${l}>${d}</g>` : d);
145
160
  }
146
- return i.join("");
161
+ return o.join("");
147
162
  }
148
- $generateSVGContent(t, e, r, a) {
149
- const i = [this.$generateSVGHeader(e), '<g id="ascii-cells">'];
150
- for (const s of t) i.push(this.$generateCellContent(s, e, r, a));
151
- return i.push(this.$generateSVGFooter()), i.join("");
163
+ $generateSVGContent(r, t, e, a) {
164
+ const o = [this.$generateSVGHeader(t), '<g id="ascii-cells">'];
165
+ for (const s of r) o.push(this.$generateCellContent(s, t, e, a));
166
+ return o.push(this.$generateSVGFooter()), o.join("");
152
167
  }
153
- $optimizeSVGContent(t) {
154
- return t.replace(/\s+/g, " ").replace(/> </g, "><");
168
+ $optimizeSVGContent(r) {
169
+ return r.replace(/\s+/g, " ").replace(/> </g, "><");
155
170
  }
156
171
  }
157
- class gt {
158
- _applyDefaultOptions(t) {
159
- return { includeBackgroundRectangles: t.includeBackgroundRectangles ?? !0, drawMode: t.drawMode ?? "fill", strokeWidth: t.strokeWidth ?? 1, filename: t.filename };
172
+ class Ct {
173
+ _applyDefaultOptions(r) {
174
+ return { includeBackgroundRectangles: r.includeBackgroundRectangles ?? !0, drawMode: r.drawMode ?? "fill", strokeWidth: r.strokeWidth ?? 1, filename: r.filename };
160
175
  }
161
- $generateSVG(t, e = {}) {
162
- const r = new qt(), a = new jt(), i = r.$extractSVGCellData(r.$extractFramebufferData(t.layers.base.drawFramebuffer), t.grid), s = a.$generateSVGContent(i, t.grid, t.font, this._applyDefaultOptions(e));
176
+ $generateSVG(r, t = {}) {
177
+ const e = new Zt(), a = new ee(), o = e.$extractSVGCellData(e.$extractFramebufferData(r.layers.base.drawFramebuffer), r.grid), s = a.$generateSVGContent(o, r.grid, r.font, this._applyDefaultOptions(t));
163
178
  return a.$optimizeSVGContent(s);
164
179
  }
165
- $saveSVG(t, e = {}) {
166
- new Q().$downloadFile(new Blob([this.$generateSVG(t, e)], { type: "image/svg+xml;charset=utf-8" }), e.filename);
180
+ $saveSVG(r, t = {}) {
181
+ new H().$downloadFile(new Blob([this.$generateSVG(r, t)], { type: "image/svg+xml;charset=utf-8" }), t.filename);
167
182
  }
168
183
  }
169
- const st = { png: "image/png", jpg: "image/jpeg", webp: "image/webp" }, lt = { png: ".png", jpg: ".jpg", webp: ".webp" };
170
- class bt {
171
- _applyDefaultOptions(t) {
172
- return { format: t.format ?? "png", scale: Math.abs(t.scale ?? 1), filename: t.filename };
184
+ const ut = { png: "image/png", jpg: "image/jpeg", webp: "image/webp" }, pt = { png: ".png", jpg: ".jpg", webp: ".webp" };
185
+ class Et {
186
+ _applyDefaultOptions(r) {
187
+ return { format: r.format ?? "png", scale: Math.abs(r.scale ?? 1), filename: r.filename };
173
188
  }
174
- _validateOptions(t) {
175
- if (!(t.format in st)) throw new Error(`Saving '${t.format}' files is not supported`);
189
+ _validateOptions(r) {
190
+ if (!(r.format in ut)) throw new Error(`Saving '${r.format}' files is not supported`);
176
191
  }
177
- async $generateImageBlob(t, e) {
178
- const r = t, a = document.createElement("canvas"), i = a.getContext("2d"), s = Math.round(r.width * e.scale), l = Math.round(r.height * e.scale);
179
- return a.width = s, a.height = l, i.imageSmoothingEnabled = !1, i.clearRect(0, 0, s, l), i.drawImage(r, 0, 0, r.width, r.height, 0, 0, s, l), await new Promise((d, p) => {
180
- a.toBlob((o) => {
181
- o ? d(o) : p(new Error(`Failed to generate ${e.format.toUpperCase()} blob`));
182
- }, st[e.format]);
192
+ async $generateImageBlob(r, t) {
193
+ const e = r, a = document.createElement("canvas"), o = a.getContext("2d"), s = Math.round(e.width * t.scale), d = Math.round(e.height * t.scale);
194
+ return a.width = s, a.height = d, o.imageSmoothingEnabled = !1, o.clearRect(0, 0, s, d), o.drawImage(e, 0, 0, e.width, e.height, 0, 0, s, d), await new Promise((l, h) => {
195
+ a.toBlob((n) => {
196
+ n ? l(n) : h(new Error(`Failed to generate ${t.format.toUpperCase()} blob`));
197
+ }, ut[t.format]);
183
198
  });
184
199
  }
185
- async $saveImage(t, e = {}) {
186
- const r = this._applyDefaultOptions(e);
187
- this._validateOptions(r);
188
- const a = await this.$generateImageBlob(t, r);
189
- new Q().$downloadFile(a, r.filename);
200
+ async $saveImage(r, t = {}) {
201
+ const e = this._applyDefaultOptions(t);
202
+ this._validateOptions(e);
203
+ const a = await this.$generateImageBlob(r, e);
204
+ new H().$downloadFile(a, e.filename);
190
205
  }
191
- async $copyImageToClipboard(t, e = {}) {
206
+ async $copyImageToClipboard(r, t = {}) {
192
207
  if (typeof navigator > "u" || !navigator.clipboard || typeof navigator.clipboard.write != "function") throw new Error("Clipboard API is not available in this environment");
193
- const r = this._applyDefaultOptions(e);
194
- this._validateOptions(r);
195
- const a = await this.$generateImageBlob(t, r), i = new ClipboardItem({ [st[r.format]]: a });
196
- await navigator.clipboard.write([i]);
197
- }
198
- }
199
- class vt {
200
- _applyDefaultOptions(t) {
201
- return { preserveTrailingSpaces: t.preserveTrailingSpaces ?? !1, emptyCharacter: t.emptyCharacter ?? " ", filename: t.filename };
202
- }
203
- _createTXTContent(t, e) {
204
- const r = new At(), a = t.layers.base.drawFramebuffer, i = r.$extractFramebufferData(a), s = [];
205
- let l = 0;
206
- for (let d = 0; d < t.grid.rows; d++) {
207
- let p = "";
208
- for (let o = 0; o < t.grid.cols; o++) {
209
- const c = 4 * l, u = r.$getCharacterIndex(i.characterPixels, c);
210
- p += t.font.characters[u]?.character || e.emptyCharacter, l++;
208
+ const e = this._applyDefaultOptions(t);
209
+ this._validateOptions(e);
210
+ const a = await this.$generateImageBlob(r, e), o = new ClipboardItem({ [ut[e.format]]: a });
211
+ await navigator.clipboard.write([o]);
212
+ }
213
+ }
214
+ class kt {
215
+ _applyDefaultOptions(r) {
216
+ return { preserveTrailingSpaces: r.preserveTrailingSpaces ?? !1, emptyCharacter: r.emptyCharacter ?? " ", filename: r.filename };
217
+ }
218
+ _createTXTContent(r, t) {
219
+ var l;
220
+ const e = new xt(), a = r.layers.base.drawFramebuffer, o = e.$extractFramebufferData(a), s = [];
221
+ let d = 0;
222
+ for (let h = 0; h < r.grid.rows; h++) {
223
+ let n = "";
224
+ for (let c = 0; c < r.grid.cols; c++) {
225
+ const u = 4 * d, f = e.$getEncodedCharacterValue(o.characterPixels, u);
226
+ n += ((l = yt(r.font, f)) == null ? void 0 : l.character) || t.emptyCharacter, d++;
211
227
  }
212
- e.preserveTrailingSpaces || (p = p.trimEnd()), s.push(p);
228
+ t.preserveTrailingSpaces || (n = n.trimEnd()), s.push(n);
213
229
  }
214
230
  return s.join(`
215
231
  `);
216
232
  }
217
- $generateTXT(t, e = {}) {
218
- return this._createTXTContent(t, this._applyDefaultOptions(e));
233
+ $generateTXT(r, t = {}) {
234
+ return this._createTXTContent(r, this._applyDefaultOptions(t));
219
235
  }
220
- $saveTXT(t, e = {}) {
221
- const r = this._applyDefaultOptions(e), a = this._createTXTContent(t, r), i = new Blob([a], { type: "text/plain;charset=utf-8" });
222
- new Q().$downloadFile(i, r.filename);
236
+ $saveTXT(r, t = {}) {
237
+ const e = this._applyDefaultOptions(t), a = this._createTXTContent(r, e), o = new Blob([a], { type: "text/plain;charset=utf-8" });
238
+ new H().$downloadFile(o, e.filename);
223
239
  }
224
240
  }
225
- class Qt {
226
- _canvas;
227
- _ctx;
228
- async $record(t, e, r, a) {
229
- const i = Math.max(1, Math.round(e.frameRate)), s = Math.round(1e3 / i), l = Math.max(1, Math.round(e.frameCount));
230
- return await new Promise((d, p) => {
231
- const o = [];
232
- let c, u = 0, m = !1;
233
- const x = () => {
241
+ class re {
242
+ constructor() {
243
+ p(this, "_canvas");
244
+ p(this, "_ctx");
245
+ }
246
+ async $record(r, t, e, a) {
247
+ const o = Math.max(1, Math.round(t.frameRate)), s = Math.round(1e3 / o), d = Math.max(1, Math.round(t.frameCount));
248
+ return await new Promise((l, h) => {
249
+ const n = [];
250
+ let c, u = 0, f = !1;
251
+ const y = () => {
234
252
  c && (c(), c = void 0);
235
- }, h = (_) => {
236
- m || (m = !0, x(), d(_));
237
- }, g = () => {
238
- if (u >= l) h(o);
253
+ }, m = (w) => {
254
+ f || (f = !0, y(), l(w));
255
+ }, v = () => {
256
+ if (u >= d) m(n);
239
257
  else try {
240
- const _ = e.scale, v = Math.max(1, Math.round(t.width * _)), f = Math.max(1, Math.round(t.height * _));
241
- this._canvas || (this._canvas = document.createElement("canvas")), this._canvas.width === v && this._canvas.height === f || (this._canvas.width = v, this._canvas.height = f), this._ctx || (this._ctx = this._canvas.getContext("2d"));
242
- const C = this._ctx;
243
- C.imageSmoothingEnabled = !1, C.clearRect(0, 0, v, f), C.drawImage(t, 0, 0, t.width, t.height, 0, 0, v, f);
244
- const S = { imageData: C.getImageData(0, 0, v, f), width: v, height: f, delayMs: s };
245
- o.push(S), u += 1, a?.({ state: "recording", frameIndex: u, totalFrames: l }), u >= l && h(o);
246
- } catch (_) {
247
- ((v) => {
248
- if (m) return;
249
- m = !0, x();
250
- const f = v instanceof Error ? v.message : "GIF recording failed";
251
- a?.({ state: "error", message: f }), p(v instanceof Error ? v : new Error(String(v)));
252
- })(_);
258
+ const w = t.scale, x = Math.max(1, Math.round(r.width * w)), g = Math.max(1, Math.round(r.height * w));
259
+ this._canvas || (this._canvas = document.createElement("canvas")), this._canvas.width === x && this._canvas.height === g || (this._canvas.width = x, this._canvas.height = g), this._ctx || (this._ctx = this._canvas.getContext("2d"));
260
+ const E = this._ctx;
261
+ E.imageSmoothingEnabled = !1, E.clearRect(0, 0, x, g), E.drawImage(r, 0, 0, r.width, r.height, 0, 0, x, g);
262
+ const F = { imageData: E.getImageData(0, 0, x, g), width: x, height: g, delayMs: s };
263
+ n.push(F), u += 1, a == null || a({ state: "recording", frameIndex: u, totalFrames: d }), u >= d && m(n);
264
+ } catch (w) {
265
+ ((x) => {
266
+ if (f) return;
267
+ f = !0, y();
268
+ const g = x instanceof Error ? x.message : "GIF recording failed";
269
+ a == null || a({ state: "error", message: g }), h(x instanceof Error ? x : new Error(String(x)));
270
+ })(w);
253
271
  }
254
272
  };
255
- c = r(() => {
256
- g();
257
- }), a?.({ state: "recording", frameIndex: 0, totalFrames: l });
273
+ c = e(() => {
274
+ v();
275
+ }), a == null || a({ state: "recording", frameIndex: 0, totalFrames: d });
258
276
  });
259
277
  }
260
278
  }
261
- var Pt = Object.defineProperty, Xt = (n) => Pt(n, "__esModule", { value: !0 }), Yt = (n, t) => () => (t || n((t = { exports: {} }).exports, t), t.exports), Jt = (n, t) => {
262
- for (var e in t) Pt(n, e, { get: t[e], enumerable: !0 });
263
- }, Kt = Yt((n) => {
264
- function t(c, u, m) {
265
- return 0.29889531 * c + 0.58662247 * u + 0.11448223 * m;
279
+ var Nt = Object.defineProperty, ae = (i) => Nt(i, "__esModule", { value: !0 }), oe = (i, r) => () => (r || i((r = { exports: {} }).exports, r), r.exports), ie = (i, r) => {
280
+ for (var t in r) Nt(i, t, { get: r[t], enumerable: !0 });
281
+ }, ne = oe((i) => {
282
+ function r(c, u, f) {
283
+ return 0.29889531 * c + 0.58662247 * u + 0.11448223 * f;
266
284
  }
267
- function e(c, u, m) {
268
- return 0.59597799 * c - 0.2741761 * u - 0.32180189 * m;
285
+ function t(c, u, f) {
286
+ return 0.59597799 * c - 0.2741761 * u - 0.32180189 * f;
269
287
  }
270
- function r(c, u, m) {
271
- return 0.21147017 * c - 0.52261711 * u + 0.31114694 * m;
288
+ function e(c, u, f) {
289
+ return 0.21147017 * c - 0.52261711 * u + 0.31114694 * f;
272
290
  }
273
291
  function a(c, u) {
274
- let m = c[0] - u[0], x = c[1] - u[1], h = c[2] - u[2], g = i(c) - i(u);
275
- return m * m * 0.5053 + x * x * 0.299 + h * h * 0.1957 + g * g;
292
+ let f = c[0] - u[0], y = c[1] - u[1], m = c[2] - u[2], v = o(c) - o(u);
293
+ return f * f * 0.5053 + y * y * 0.299 + m * m * 0.1957 + v * v;
276
294
  }
277
- function i(c) {
295
+ function o(c) {
278
296
  return c[3] != null ? c[3] : 255;
279
297
  }
280
298
  function s(c, u) {
281
299
  return Math.sqrt(a(c, u));
282
300
  }
283
- function l(c, u) {
284
- let [m, x, h] = c, [g, _, v] = u, f = t(m, x, h) - t(g, _, v), C = e(m, x, h) - e(g, _, v), S = r(m, x, h) - r(g, _, v), E = i(c) - i(u);
285
- return f * f * 0.5053 + C * C * 0.299 + S * S * 0.1957 + E * E;
286
- }
287
301
  function d(c, u) {
288
- return Math.sqrt(l(c, u));
302
+ let [f, y, m] = c, [v, w, x] = u, g = r(f, y, m) - r(v, w, x), E = t(f, y, m) - t(v, w, x), F = e(f, y, m) - e(v, w, x), k = o(c) - o(u);
303
+ return g * g * 0.5053 + E * E * 0.299 + F * F * 0.1957 + k * k;
289
304
  }
290
- function p(c, u) {
291
- var m, x = 0;
292
- for (m = 0; m < c.length; m++) {
293
- let h = c[m] - u[m];
294
- x += h * h;
305
+ function l(c, u) {
306
+ return Math.sqrt(d(c, u));
307
+ }
308
+ function h(c, u) {
309
+ var f, y = 0;
310
+ for (f = 0; f < c.length; f++) {
311
+ let m = c[f] - u[f];
312
+ y += m * m;
295
313
  }
296
- return x;
314
+ return y;
297
315
  }
298
- function o(c, u) {
299
- return Math.sqrt(p(c, u));
316
+ function n(c, u) {
317
+ return Math.sqrt(h(c, u));
300
318
  }
301
- Xt(n), Jt(n, { colorDifferenceRGBToYIQ: () => d, colorDifferenceRGBToYIQSquared: () => l, colorDifferenceYIQ: () => s, colorDifferenceYIQSquared: () => a, euclideanDistance: () => o, euclideanDistanceSquared: () => p });
302
- }), Zt = { trailer: 59 };
303
- function Dt(n = 256) {
304
- let t = 0, e = new Uint8Array(n);
319
+ ae(i), ie(i, { colorDifferenceRGBToYIQ: () => l, colorDifferenceRGBToYIQSquared: () => d, colorDifferenceYIQ: () => s, colorDifferenceYIQSquared: () => a, euclideanDistance: () => n, euclideanDistanceSquared: () => h });
320
+ }), se = { trailer: 59 };
321
+ function Ut(i = 256) {
322
+ let r = 0, t = new Uint8Array(i);
305
323
  return { get buffer() {
306
- return e.buffer;
324
+ return t.buffer;
307
325
  }, reset() {
308
- t = 0;
309
- }, bytesView: () => e.subarray(0, t), bytes: () => e.slice(0, t), writeByte(a) {
310
- r(t + 1), e[t] = a, t++;
311
- }, writeBytes(a, i = 0, s = a.length) {
312
- r(t + s);
313
- for (let l = 0; l < s; l++) e[t++] = a[l + i];
314
- }, writeBytesView(a, i = 0, s = a.byteLength) {
315
- r(t + s), e.set(a.subarray(i, i + s), t), t += s;
326
+ r = 0;
327
+ }, bytesView: () => t.subarray(0, r), bytes: () => t.slice(0, r), writeByte(a) {
328
+ e(r + 1), t[r] = a, r++;
329
+ }, writeBytes(a, o = 0, s = a.length) {
330
+ e(r + s);
331
+ for (let d = 0; d < s; d++) t[r++] = a[d + o];
332
+ }, writeBytesView(a, o = 0, s = a.byteLength) {
333
+ e(r + s), t.set(a.subarray(o, o + s), r), r += s;
316
334
  } };
317
- function r(a) {
318
- var i = e.length;
319
- if (i >= a) return;
320
- a = Math.max(a, i * (i < 1048576 ? 2 : 1.125) >>> 0), i != 0 && (a = Math.max(a, 256));
321
- let s = e;
322
- e = new Uint8Array(a), t > 0 && e.set(s.subarray(0, t), 0);
323
- }
324
- }
325
- var Z = 12, xt = 5003, te = [0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535];
326
- function ee(n, t, e, r, a, i, s, l) {
327
- a = a || Dt(512), i = i || new Uint8Array(256), s = s || new Int32Array(xt), l = l || new Int32Array(xt);
328
- let d = s.length, p = Math.max(2, r);
329
- i.fill(0), l.fill(0), L();
330
- let o = 0, c = 0, u = p + 1, m = u, x = !1, h = m, g = D(h), _ = 1 << u - 1, v = _ + 1, f = _ + 2, C = 0, S = e[0], E = 0;
331
- for (let k = d; k < 65536; k *= 2) ++E;
332
- E = 8 - E, a.writeByte(p), T(_);
333
- for (let k = 1; k < e.length; k++) V(e[k]);
334
- return T(S), T(v), a.writeByte(0), a.bytesView();
335
- function A(k) {
336
- i[C++] = k, C >= 254 && B();
335
+ function e(a) {
336
+ var o = t.length;
337
+ if (o >= a) return;
338
+ a = Math.max(a, o * (o < 1048576 ? 2 : 1.125) >>> 0), o != 0 && (a = Math.max(a, 256));
339
+ let s = t;
340
+ t = new Uint8Array(a), r > 0 && t.set(s.subarray(0, r), 0);
341
+ }
342
+ }
343
+ var tt = 12, Bt = 5003, le = [0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535];
344
+ function de(i, r, t, e, a, o, s, d) {
345
+ a = a || Ut(512), o = o || new Uint8Array(256), s = s || new Int32Array(Bt), d = d || new Int32Array(Bt);
346
+ let l = s.length, h = Math.max(2, e);
347
+ o.fill(0), d.fill(0), L();
348
+ let n = 0, c = 0, u = h + 1, f = u, y = !1, m = f, v = D(m), w = 1 << u - 1, x = w + 1, g = w + 2, E = 0, F = t[0], k = 0;
349
+ for (let B = l; B < 65536; B *= 2) ++k;
350
+ k = 8 - k, a.writeByte(h), R(w);
351
+ for (let B = 1; B < t.length; B++) V(t[B]);
352
+ return R(F), R(x), a.writeByte(0), a.bytesView();
353
+ function A(B) {
354
+ o[E++] = B, E >= 254 && S();
337
355
  }
338
356
  function L() {
339
357
  s.fill(-1);
340
358
  }
341
- function V(k) {
342
- let R = (k << Z) + S, y = k << E ^ S;
343
- if (s[y] === R) S = l[y];
359
+ function V(B) {
360
+ let N = (B << tt) + F, _ = B << k ^ F;
361
+ if (s[_] === N) F = d[_];
344
362
  else {
345
- if (s[y] >= 0) {
346
- let w = y === 0 ? 1 : d - y;
363
+ if (s[_] >= 0) {
364
+ let C = _ === 0 ? 1 : l - _;
347
365
  do
348
- if (y -= w, y < 0 && (y += d), s[y] === R) return void (S = l[y]);
349
- while (s[y] >= 0);
366
+ if (_ -= C, _ < 0 && (_ += l), s[_] === N) return void (F = d[_]);
367
+ while (s[_] >= 0);
350
368
  }
351
- T(S), S = k, f < 1 << Z ? (l[y] = f++, s[y] = R) : (L(), f = _ + 2, x = !0, T(_));
369
+ R(F), F = B, g < 1 << tt ? (d[_] = g++, s[_] = N) : (L(), g = w + 2, y = !0, R(w));
352
370
  }
353
371
  }
354
- function B() {
355
- C > 0 && (a.writeByte(C), a.writeBytesView(i, 0, C), C = 0);
372
+ function S() {
373
+ E > 0 && (a.writeByte(E), a.writeBytesView(o, 0, E), E = 0);
356
374
  }
357
- function D(k) {
358
- return (1 << k) - 1;
375
+ function D(B) {
376
+ return (1 << B) - 1;
359
377
  }
360
- function T(k) {
361
- for (o &= te[c], c > 0 ? o |= k << c : o = k, c += h; c >= 8; ) A(255 & o), o >>= 8, c -= 8;
362
- if ((f > g || x) && (x ? (h = m, g = D(h), x = !1) : (++h, g = h == Z ? 1 << Z : D(h))), k == v) {
363
- for (; c > 0; ) A(255 & o), o >>= 8, c -= 8;
364
- B();
378
+ function R(B) {
379
+ for (n &= le[c], c > 0 ? n |= B << c : n = B, c += m; c >= 8; ) A(255 & n), n >>= 8, c -= 8;
380
+ if ((g > v || y) && (y ? (m = f, v = D(m), y = !1) : (++m, v = m == tt ? 1 << tt : D(m))), B == x) {
381
+ for (; c > 0; ) A(255 & n), n >>= 8, c -= 8;
382
+ S();
365
383
  }
366
384
  }
367
385
  }
368
- var re = ee;
369
- function Vt(n, t, e) {
370
- return n << 8 & 63488 | t << 2 & 992 | e >> 3 & 31;
386
+ var ce = de;
387
+ function Gt(i, r, t) {
388
+ return i << 8 & 63488 | r << 2 & 992 | t >> 3 & 31;
371
389
  }
372
- function Ot(n, t, e, r) {
373
- return n >> 4 | 240 & t | (240 & e) << 4 | (240 & r) << 8;
390
+ function zt(i, r, t, e) {
391
+ return i >> 4 | 240 & r | (240 & t) << 4 | (240 & e) << 8;
374
392
  }
375
- function Tt(n, t, e) {
376
- return n >> 4 << 8 | t >> 4 << 4 | e >> 4;
393
+ function Wt(i, r, t) {
394
+ return i >> 4 << 8 | r >> 4 << 4 | t >> 4;
377
395
  }
378
- function tt(n, t, e) {
379
- return n < t ? t : n > e ? e : n;
396
+ function et(i, r, t) {
397
+ return i < r ? r : i > t ? t : i;
380
398
  }
381
- function at(n) {
382
- return n * n;
399
+ function ot(i) {
400
+ return i * i;
383
401
  }
384
- function yt(n, t, e) {
385
- for (var r = 0, a = 1e100, i = n[t], s = i.cnt, l = (i.ac, i.rc), d = i.gc, p = i.bc, o = i.fw; o != 0; o = n[o].fw) {
386
- var c = n[o].cnt, u = s * c / (s + c);
402
+ function St(i, r, t) {
403
+ for (var e = 0, a = 1e100, o = i[r], s = o.cnt, d = (o.ac, o.rc), l = o.gc, h = o.bc, n = o.fw; n != 0; n = i[n].fw) {
404
+ var c = i[n].cnt, u = s * c / (s + c);
387
405
  if (!(u >= a)) {
388
- var m = 0;
389
- !((m += u * at(n[o].rc - l)) >= a) && !((m += u * at(n[o].gc - d)) >= a) && !((m += u * at(n[o].bc - p)) >= a) && (a = m, r = o);
406
+ var f = 0;
407
+ !((f += u * ot(i[n].rc - d)) >= a) && !((f += u * ot(i[n].gc - l)) >= a) && !((f += u * ot(i[n].bc - h)) >= a) && (a = f, e = n);
390
408
  }
391
409
  }
392
- i.err = a, i.nn = r;
410
+ o.err = a, o.nn = e;
393
411
  }
394
- function dt() {
412
+ function ht() {
395
413
  return { ac: 0, rc: 0, gc: 0, bc: 0, cnt: 0, nn: 0, fw: 0, bk: 0, tm: 0, mtm: 0, err: 0 };
396
414
  }
397
- function ae(n, t) {
398
- let e = new Array(t === "rgb444" ? 4096 : 65536), r = n.length;
399
- if (t === "rgba4444") for (let a = 0; a < r; ++a) {
400
- let i = n[a], s = i >> 24 & 255, l = i >> 16 & 255, d = i >> 8 & 255, p = 255 & i, o = Ot(p, d, l, s), c = o in e ? e[o] : e[o] = dt();
401
- c.rc += p, c.gc += d, c.bc += l, c.ac += s, c.cnt++;
402
- }
403
- else if (t === "rgb444") for (let a = 0; a < r; ++a) {
404
- let i = n[a], s = i >> 16 & 255, l = i >> 8 & 255, d = 255 & i, p = Tt(d, l, s), o = p in e ? e[p] : e[p] = dt();
405
- o.rc += d, o.gc += l, o.bc += s, o.cnt++;
406
- }
407
- else for (let a = 0; a < r; ++a) {
408
- let i = n[a], s = i >> 16 & 255, l = i >> 8 & 255, d = 255 & i, p = Vt(d, l, s), o = p in e ? e[p] : e[p] = dt();
409
- o.rc += d, o.gc += l, o.bc += s, o.cnt++;
410
- }
411
- return e;
412
- }
413
- function ie(n, t, e) {
414
- let { format: r = "rgb565", clearAlpha: a = !0, clearAlphaColor: i = 0, clearAlphaThreshold: s = 0, oneBitAlpha: l = !1 } = e || {}, d = e.useSqrt !== !1, p = r === "rgba4444", o = ae(n, r), c = o.length, u = c - 1, m = new Uint32Array(c + 1);
415
- for (var x = 0, h = 0; h < o.length; ++h) {
416
- let k = o[h];
417
- if (k != null) {
418
- var g = 1 / k.cnt;
419
- p && (k.ac *= g), k.rc *= g, k.gc *= g, k.bc *= g, o[x++] = k;
415
+ function ue(i, r) {
416
+ let t = new Array(r === "rgb444" ? 4096 : 65536), e = i.length;
417
+ if (r === "rgba4444") for (let a = 0; a < e; ++a) {
418
+ let o = i[a], s = o >> 24 & 255, d = o >> 16 & 255, l = o >> 8 & 255, h = 255 & o, n = zt(h, l, d, s), c = n in t ? t[n] : t[n] = ht();
419
+ c.rc += h, c.gc += l, c.bc += d, c.ac += s, c.cnt++;
420
+ }
421
+ else if (r === "rgb444") for (let a = 0; a < e; ++a) {
422
+ let o = i[a], s = o >> 16 & 255, d = o >> 8 & 255, l = 255 & o, h = Wt(l, d, s), n = h in t ? t[h] : t[h] = ht();
423
+ n.rc += l, n.gc += d, n.bc += s, n.cnt++;
424
+ }
425
+ else for (let a = 0; a < e; ++a) {
426
+ let o = i[a], s = o >> 16 & 255, d = o >> 8 & 255, l = 255 & o, h = Gt(l, d, s), n = h in t ? t[h] : t[h] = ht();
427
+ n.rc += l, n.gc += d, n.bc += s, n.cnt++;
428
+ }
429
+ return t;
430
+ }
431
+ function pe(i, r, t) {
432
+ let { format: e = "rgb565", clearAlpha: a = !0, clearAlphaColor: o = 0, clearAlphaThreshold: s = 0, oneBitAlpha: d = !1 } = t || {}, l = t.useSqrt !== !1, h = e === "rgba4444", n = ue(i, e), c = n.length, u = c - 1, f = new Uint32Array(c + 1);
433
+ for (var y = 0, m = 0; m < n.length; ++m) {
434
+ let B = n[m];
435
+ if (B != null) {
436
+ var v = 1 / B.cnt;
437
+ h && (B.ac *= v), B.rc *= v, B.gc *= v, B.bc *= v, n[y++] = B;
420
438
  }
421
439
  }
422
- for (at(t) / x < 0.022 && (d = !1), h = 0; h < x - 1; ++h) o[h].fw = h + 1, o[h + 1].bk = h, d && (o[h].cnt = Math.sqrt(o[h].cnt));
423
- var _, v, f;
424
- for (d && (o[h].cnt = Math.sqrt(o[h].cnt)), h = 0; h < x; ++h) {
425
- yt(o, h);
426
- var C = o[h].err;
427
- for (v = ++m[0]; v > 1 && !(o[_ = m[f = v >> 1]].err <= C); v = f) m[v] = _;
428
- m[v] = h;
429
- }
430
- var S = x - t;
431
- for (h = 0; h < S; ) {
432
- for (var E; ; ) {
433
- var A = m[1];
434
- if ((E = o[A]).tm >= E.mtm && o[E.nn].mtm <= E.tm) break;
435
- for (E.mtm == u ? A = m[1] = m[m[0]--] : (yt(o, A), E.tm = h), C = o[A].err, v = 1; (f = v + v) <= m[0] && (f < m[0] && o[m[f]].err > o[m[f + 1]].err && f++, !(C <= o[_ = m[f]].err)); v = f) m[v] = _;
436
- m[v] = A;
440
+ for (ot(r) / y < 0.022 && (l = !1), m = 0; m < y - 1; ++m) n[m].fw = m + 1, n[m + 1].bk = m, l && (n[m].cnt = Math.sqrt(n[m].cnt));
441
+ var w, x, g;
442
+ for (l && (n[m].cnt = Math.sqrt(n[m].cnt)), m = 0; m < y; ++m) {
443
+ St(n, m);
444
+ var E = n[m].err;
445
+ for (x = ++f[0]; x > 1 && !(n[w = f[g = x >> 1]].err <= E); x = g) f[x] = w;
446
+ f[x] = m;
447
+ }
448
+ var F = y - r;
449
+ for (m = 0; m < F; ) {
450
+ for (var k; ; ) {
451
+ var A = f[1];
452
+ if ((k = n[A]).tm >= k.mtm && n[k.nn].mtm <= k.tm) break;
453
+ for (k.mtm == u ? A = f[1] = f[f[0]--] : (St(n, A), k.tm = m), E = n[A].err, x = 1; (g = x + x) <= f[0] && (g < f[0] && n[f[g]].err > n[f[g + 1]].err && g++, !(E <= n[w = f[g]].err)); x = g) f[x] = w;
454
+ f[x] = A;
437
455
  }
438
- var L = o[E.nn], V = E.cnt, B = L.cnt;
439
- g = 1 / (V + B), p && (E.ac = g * (V * E.ac + B * L.ac)), E.rc = g * (V * E.rc + B * L.rc), E.gc = g * (V * E.gc + B * L.gc), E.bc = g * (V * E.bc + B * L.bc), E.cnt += L.cnt, E.mtm = ++h, o[L.bk].fw = L.fw, o[L.fw].bk = L.bk, L.mtm = u;
456
+ var L = n[k.nn], V = k.cnt, S = L.cnt;
457
+ v = 1 / (V + S), h && (k.ac = v * (V * k.ac + S * L.ac)), k.rc = v * (V * k.rc + S * L.rc), k.gc = v * (V * k.gc + S * L.gc), k.bc = v * (V * k.bc + S * L.bc), k.cnt += L.cnt, k.mtm = ++m, n[L.bk].fw = L.fw, n[L.fw].bk = L.bk, L.mtm = u;
440
458
  }
441
459
  let D = [];
442
- var T = 0;
443
- for (h = 0; ; ++T) {
444
- let k = tt(Math.round(o[h].rc), 0, 255), R = tt(Math.round(o[h].gc), 0, 255), y = tt(Math.round(o[h].bc), 0, 255), w = 255;
445
- p && (w = tt(Math.round(o[h].ac), 0, 255), l && (w = w <= (typeof l == "number" ? l : 127) ? 0 : 255), a && w <= s && (k = R = y = i, w = 0));
446
- let F = p ? [k, R, y, w] : [k, R, y];
447
- if (oe(D, F) || D.push(F), (h = o[h].fw) == 0) break;
460
+ var R = 0;
461
+ for (m = 0; ; ++R) {
462
+ let B = et(Math.round(n[m].rc), 0, 255), N = et(Math.round(n[m].gc), 0, 255), _ = et(Math.round(n[m].bc), 0, 255), C = 255;
463
+ h && (C = et(Math.round(n[m].ac), 0, 255), d && (C = C <= (typeof d == "number" ? d : 127) ? 0 : 255), a && C <= s && (B = N = _ = o, C = 0));
464
+ let M = h ? [B, N, _, C] : [B, N, _];
465
+ if (he(D, M) || D.push(M), (m = n[m].fw) == 0) break;
448
466
  }
449
467
  return D;
450
468
  }
451
- function oe(n, t) {
452
- for (let e = 0; e < n.length; e++) {
453
- let r = n[e], a = r[0] === t[0] && r[1] === t[1] && r[2] === t[2], i = !(r.length >= 4 && t.length >= 4) || r[3] === t[3];
454
- if (a && i) return !0;
469
+ function he(i, r) {
470
+ for (let t = 0; t < i.length; t++) {
471
+ let e = i[t], a = e[0] === r[0] && e[1] === r[1] && e[2] === r[2], o = !(e.length >= 4 && r.length >= 4) || e[3] === r[3];
472
+ if (a && o) return !0;
455
473
  }
456
474
  return !1;
457
475
  }
458
- function ne(n, t, e) {
459
- let r = (e = e || "rgb565") === "rgb444" ? 4096 : 65536, a = new Uint8Array(n.length), i = new Array(r);
460
- if (e === "rgba4444") for (let s = 0; s < n.length; s++) {
461
- let l, d = n[s], p = d >> 24 & 255, o = d >> 16 & 255, c = d >> 8 & 255, u = 255 & d, m = Ot(u, c, o, p);
462
- i[m] != null ? l = i[m] : (l = se(u, c, o, p, t), i[m] = l), a[s] = l;
476
+ function me(i, r, t) {
477
+ let e = (t = t || "rgb565") === "rgb444" ? 4096 : 65536, a = new Uint8Array(i.length), o = new Array(e);
478
+ if (t === "rgba4444") for (let s = 0; s < i.length; s++) {
479
+ let d, l = i[s], h = l >> 24 & 255, n = l >> 16 & 255, c = l >> 8 & 255, u = 255 & l, f = zt(u, c, n, h);
480
+ o[f] != null ? d = o[f] : (d = fe(u, c, n, h, r), o[f] = d), a[s] = d;
463
481
  }
464
- else for (let s = 0; s < n.length; s++) {
465
- let l, d = n[s], p = d >> 16 & 255, o = d >> 8 & 255, c = 255 & d, u = e === "rgb444" ? Tt(c, o, p) : Vt(c, o, p);
466
- i[u] != null ? l = i[u] : (l = le(c, o, p, t), i[u] = l), a[s] = l;
482
+ else for (let s = 0; s < i.length; s++) {
483
+ let d, l = i[s], h = l >> 16 & 255, n = l >> 8 & 255, c = 255 & l, u = t === "rgb444" ? Wt(c, n, h) : Gt(c, n, h);
484
+ o[u] != null ? d = o[u] : (d = ge(c, n, h, r), o[u] = d), a[s] = d;
467
485
  }
468
486
  return a;
469
487
  }
470
- function se(n, t, e, r, a) {
471
- let i = 0, s = 1e100;
472
- for (let l = 0; l < a.length; l++) {
473
- let d = a[l], p = d[0], o = d[1], c = d[2], u = W(d[3] - r);
474
- u > s || (u += W(p - n), !(u > s) && (u += W(o - t), !(u > s) && (u += W(c - e), !(u > s) && (s = u, i = l))));
488
+ function fe(i, r, t, e, a) {
489
+ let o = 0, s = 1e100;
490
+ for (let d = 0; d < a.length; d++) {
491
+ let l = a[d], h = l[0], n = l[1], c = l[2], u = j(l[3] - e);
492
+ u > s || (u += j(h - i), !(u > s) && (u += j(n - r), !(u > s) && (u += j(c - t), !(u > s) && (s = u, o = d))));
475
493
  }
476
- return i;
494
+ return o;
477
495
  }
478
- function le(n, t, e, r) {
479
- let a = 0, i = 1e100;
480
- for (let s = 0; s < r.length; s++) {
481
- let l = r[s], d = l[0], p = l[1], o = l[2], c = W(d - n);
482
- c > i || (c += W(p - t), !(c > i) && (c += W(o - e), !(c > i) && (i = c, a = s)));
496
+ function ge(i, r, t, e) {
497
+ let a = 0, o = 1e100;
498
+ for (let s = 0; s < e.length; s++) {
499
+ let d = e[s], l = d[0], h = d[1], n = d[2], c = j(l - i);
500
+ c > o || (c += j(h - r), !(c > o) && (c += j(n - t), !(c > o) && (o = c, a = s)));
483
501
  }
484
502
  return a;
485
503
  }
486
- function W(n) {
487
- return n * n;
504
+ function j(i) {
505
+ return i * i;
488
506
  }
489
- function de(n = {}) {
490
- let { initialCapacity: t = 4096, auto: e = !0 } = n, r = Dt(t), a = new Uint8Array(256), i = new Int32Array(5003), s = new Int32Array(5003), l = !1;
507
+ function be(i = {}) {
508
+ let { initialCapacity: r = 4096, auto: t = !0 } = i, e = Ut(r), a = new Uint8Array(256), o = new Int32Array(5003), s = new Int32Array(5003), d = !1;
491
509
  return { reset() {
492
- r.reset(), l = !1;
510
+ e.reset(), d = !1;
493
511
  }, finish() {
494
- r.writeByte(Zt.trailer);
495
- }, bytes: () => r.bytes(), bytesView: () => r.bytesView(), get buffer() {
496
- return r.buffer;
512
+ e.writeByte(se.trailer);
513
+ }, bytes: () => e.bytes(), bytesView: () => e.bytesView(), get buffer() {
514
+ return e.buffer;
497
515
  }, get stream() {
498
- return r;
499
- }, writeHeader: d, writeFrame(p, o, c, u = {}) {
500
- let { transparent: m = !1, transparentIndex: x = 0, delay: h = 0, palette: g = null, repeat: _ = 0, colorDepth: v = 8, dispose: f = -1 } = u, C = !1;
501
- if (e ? l || (C = !0, d(), l = !0) : C = !!u.first, o = Math.max(0, Math.floor(o)), c = Math.max(0, Math.floor(c)), C) {
502
- if (!g) throw new Error("First frame must include a { palette } option");
503
- ue(r, o, c, g, v), _t(r, g), _ >= 0 && pe(r, _);
516
+ return e;
517
+ }, writeHeader: l, writeFrame(h, n, c, u = {}) {
518
+ let { transparent: f = !1, transparentIndex: y = 0, delay: m = 0, palette: v = null, repeat: w = 0, colorDepth: x = 8, dispose: g = -1 } = u, E = !1;
519
+ if (t ? d || (E = !0, l(), d = !0) : E = !!u.first, n = Math.max(0, Math.floor(n)), c = Math.max(0, Math.floor(c)), E) {
520
+ if (!v) throw new Error("First frame must include a { palette } option");
521
+ xe(e, n, c, v, x), It(e, v), w >= 0 && ye(e, w);
504
522
  }
505
- let S = Math.round(h / 10);
506
- ce(r, f, S, m, x);
507
- let E = !!g && !C;
508
- he(r, o, c, E ? g : null), E && _t(r, g), me(r, p, o, c, v, a, i, s);
523
+ let F = Math.round(m / 10);
524
+ ve(e, g, F, f, y);
525
+ let k = !!v && !E;
526
+ _e(e, n, c, k ? v : null), k && It(e, v), we(e, h, n, c, x, a, o, s);
509
527
  } };
510
- function d() {
511
- Rt(r, "GIF89a");
528
+ function l() {
529
+ jt(e, "GIF89a");
512
530
  }
513
531
  }
514
- function ce(n, t, e, r, a) {
515
- var i, s;
516
- n.writeByte(33), n.writeByte(249), n.writeByte(4), a < 0 && (a = 0, r = !1), r ? (i = 1, s = 2) : (i = 0, s = 0), t >= 0 && (s = 7 & t), s <<= 2, n.writeByte(0 | s | i), N(n, e), n.writeByte(a || 0), n.writeByte(0);
532
+ function ve(i, r, t, e, a) {
533
+ var o, s;
534
+ i.writeByte(33), i.writeByte(249), i.writeByte(4), a < 0 && (a = 0, e = !1), e ? (o = 1, s = 2) : (o = 0, s = 0), r >= 0 && (s = 7 & r), s <<= 2, i.writeByte(0 | s | o), G(i, t), i.writeByte(a || 0), i.writeByte(0);
517
535
  }
518
- function ue(n, t, e, r, a = 8) {
519
- let i = 128 | a - 1 << 4 | ht(r.length) - 1;
520
- N(n, t), N(n, e), n.writeBytes([i, 0, 0]);
536
+ function xe(i, r, t, e, a = 8) {
537
+ let o = 128 | a - 1 << 4 | _t(e.length) - 1;
538
+ G(i, r), G(i, t), i.writeBytes([o, 0, 0]);
521
539
  }
522
- function pe(n, t) {
523
- n.writeByte(33), n.writeByte(255), n.writeByte(11), Rt(n, "NETSCAPE2.0"), n.writeByte(3), n.writeByte(1), N(n, t), n.writeByte(0);
540
+ function ye(i, r) {
541
+ i.writeByte(33), i.writeByte(255), i.writeByte(11), jt(i, "NETSCAPE2.0"), i.writeByte(3), i.writeByte(1), G(i, r), i.writeByte(0);
524
542
  }
525
- function _t(n, t) {
526
- let e = 1 << ht(t.length);
527
- for (let r = 0; r < e; r++) {
543
+ function It(i, r) {
544
+ let t = 1 << _t(r.length);
545
+ for (let e = 0; e < t; e++) {
528
546
  let a = [0, 0, 0];
529
- r < t.length && (a = t[r]), n.writeByte(a[0]), n.writeByte(a[1]), n.writeByte(a[2]);
547
+ e < r.length && (a = r[e]), i.writeByte(a[0]), i.writeByte(a[1]), i.writeByte(a[2]);
530
548
  }
531
549
  }
532
- function he(n, t, e, r) {
533
- if (n.writeByte(44), N(n, 0), N(n, 0), N(n, t), N(n, e), r) {
534
- let a = 0, i = 0, s = ht(r.length) - 1;
535
- n.writeByte(128 | a | i | s);
536
- } else n.writeByte(0);
550
+ function _e(i, r, t, e) {
551
+ if (i.writeByte(44), G(i, 0), G(i, 0), G(i, r), G(i, t), e) {
552
+ let a = 0, o = 0, s = _t(e.length) - 1;
553
+ i.writeByte(128 | a | o | s);
554
+ } else i.writeByte(0);
537
555
  }
538
- function me(n, t, e, r, a = 8, i, s, l) {
539
- re(e, r, t, a, n, i, s, l);
556
+ function we(i, r, t, e, a = 8, o, s, d) {
557
+ ce(t, e, r, a, i, o, s, d);
540
558
  }
541
- function N(n, t) {
542
- n.writeByte(255 & t), n.writeByte(t >> 8 & 255);
559
+ function G(i, r) {
560
+ i.writeByte(255 & r), i.writeByte(r >> 8 & 255);
543
561
  }
544
- function Rt(n, t) {
545
- for (var e = 0; e < t.length; e++) n.writeByte(t.charCodeAt(e));
562
+ function jt(i, r) {
563
+ for (var t = 0; t < r.length; t++) i.writeByte(r.charCodeAt(t));
546
564
  }
547
- function ht(n) {
548
- return Math.max(Math.ceil(Math.log2(n)), 1);
565
+ function _t(i) {
566
+ return Math.max(Math.ceil(Math.log2(i)), 1);
549
567
  }
550
- Kt();
551
- class fe {
552
- _recorder;
553
- _textmodifier;
554
- _registerPostDrawHook;
555
- constructor(t, e) {
556
- this._recorder = new Qt(), this._textmodifier = t, this._registerPostDrawHook = e;
557
- }
558
- async $saveGIF(t = {}) {
559
- const e = this._textmodifier.canvas, r = this._applyDefaultOptions(t), a = t.onProgress;
568
+ ne();
569
+ class Ce {
570
+ constructor(r, t) {
571
+ p(this, "_recorder");
572
+ p(this, "_textmodifier");
573
+ p(this, "_registerPostDrawHook");
574
+ this._recorder = new re(), this._textmodifier = r, this._registerPostDrawHook = t;
575
+ }
576
+ async $saveGIF(r = {}) {
577
+ const t = this._textmodifier.canvas, e = this._applyDefaultOptions(r), a = r.onProgress;
560
578
  try {
561
- const i = await this._recorder.$record(e, r, this._registerPostDrawHook, a), s = de(), { repeat: l } = t;
562
- for (let o = 0; o < i.length; o++) {
563
- const c = i[o], { width: u, height: m, imageData: x, delayMs: h } = c, g = new Uint32Array(x.data.buffer), _ = ie(g, 256, {}), v = ne(g, _);
564
- s.writeFrame(v, u, m, { palette: _, delay: h, repeat: o === 0 ? l : -1 }), o % 2 != 0 && o !== i.length - 1 || (a?.({ state: "encoding", frameIndex: o + 1, totalFrames: i.length }), await new Promise((f) => setTimeout(f, 0)));
579
+ const o = await this._recorder.$record(t, e, this._registerPostDrawHook, a), s = be(), { repeat: d } = r;
580
+ for (let n = 0; n < o.length; n++) {
581
+ const c = o[n], { width: u, height: f, imageData: y, delayMs: m } = c, v = new Uint32Array(y.data.buffer), w = pe(v, 256, {}), x = me(v, w);
582
+ s.writeFrame(x, u, f, { palette: w, delay: m, repeat: n === 0 ? d : -1 }), n % 2 != 0 && n !== o.length - 1 || (a == null || a({ state: "encoding", frameIndex: n + 1, totalFrames: o.length }), await new Promise((g) => setTimeout(g, 0)));
565
583
  }
566
584
  s.finish();
567
- const d = s.bytes(), p = d.buffer.slice(d.byteOffset, d.byteOffset + d.byteLength);
568
- new Q().$downloadFile(new Blob([p], { type: "image/gif" }), r.filename), a?.({ state: "completed", totalFrames: r.frameCount });
569
- } catch (i) {
570
- throw a?.({ state: "error", message: i instanceof Error ? i.message : "GIF export failed" }), i;
585
+ const l = s.bytes(), h = l.buffer.slice(l.byteOffset, l.byteOffset + l.byteLength);
586
+ new H().$downloadFile(new Blob([h], { type: "image/gif" }), e.filename), a == null || a({ state: "completed", totalFrames: e.frameCount });
587
+ } catch (o) {
588
+ throw a == null || a({ state: "error", message: o instanceof Error ? o.message : "GIF export failed" }), o;
571
589
  }
572
590
  }
573
- _applyDefaultOptions(t) {
574
- const e = Math.abs(Math.round(t.frameCount ?? 300)), r = Math.abs(t.frameRate ?? 60), a = Math.abs(t.scale ?? 1), i = Math.max(-1, Math.round(t.repeat ?? 0));
575
- return { filename: t.filename, frameCount: e, frameRate: r, scale: a, repeat: i };
591
+ _applyDefaultOptions(r) {
592
+ const t = Math.abs(Math.round(r.frameCount ?? 300)), e = Math.abs(r.frameRate ?? 60), a = Math.abs(r.scale ?? 1), o = Math.max(-1, Math.round(r.repeat ?? 0));
593
+ return { filename: r.filename, frameCount: t, frameRate: e, scale: a, repeat: o };
576
594
  }
577
595
  }
578
- function ge(n) {
579
- return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
596
+ function Ee(i) {
597
+ return i && i.__esModule && Object.prototype.hasOwnProperty.call(i, "default") ? i.default : i;
580
598
  }
581
- var wt, Ct = { exports: {} };
582
- function be() {
583
- return wt || (wt = 1, n = Ct, (function() {
584
- function t(d, p) {
585
- return (function(o) {
586
- if (typeof o != "string" || !o.match(/^data:image\/webp;base64,/i)) throw new Error("Failed to decode WebP Base64 URL");
587
- return window.atob(o.substring(23));
588
- })(typeof d == "string" && /^data:image\/webp/.test(d) ? d : d.toDataURL("image/webp", p));
599
+ var Ft, Mt = { exports: {} };
600
+ function ke() {
601
+ return Ft || (Ft = 1, i = Mt, (function() {
602
+ function r(l, h) {
603
+ return (function(n) {
604
+ if (typeof n != "string" || !n.match(/^data:image\/webp;base64,/i)) throw new Error("Failed to decode WebP Base64 URL");
605
+ return window.atob(n.substring(23));
606
+ })(typeof l == "string" && /^data:image\/webp/.test(l) ? l : l.toDataURL("image/webp", h));
589
607
  }
590
- function e(d) {
591
- return (d.charCodeAt(0) | d.charCodeAt(1) << 8 | d.charCodeAt(2) << 16 | d.charCodeAt(3) << 24) >>> 0;
608
+ function t(l) {
609
+ return (l.charCodeAt(0) | l.charCodeAt(1) << 8 | l.charCodeAt(2) << 16 | l.charCodeAt(3) << 24) >>> 0;
592
610
  }
593
- function r(d) {
594
- let p = d.indexOf("VP8", 12);
595
- if (p === -1) throw new Error("Bad image format, does this browser support WebP?");
596
- let o = !1;
597
- for (; p < d.length - 8; ) {
611
+ function e(l) {
612
+ let h = l.indexOf("VP8", 12);
613
+ if (h === -1) throw new Error("Bad image format, does this browser support WebP?");
614
+ let n = !1;
615
+ for (; h < l.length - 8; ) {
598
616
  let c, u;
599
- switch (u = d.substring(p, p + 4), p += 4, c = e(d.substring(p, p + 4)), p += 4, u) {
617
+ switch (u = l.substring(h, h + 4), h += 4, c = t(l.substring(h, h + 4)), h += 4, u) {
600
618
  case "VP8 ":
601
- return { frame: d.substring(p, p + c), hasAlpha: o };
619
+ return { frame: l.substring(h, h + c), hasAlpha: n };
602
620
  case "ALPH":
603
- o = !0;
621
+ n = !0;
604
622
  }
605
- p += c, 1 & c && p++;
623
+ h += c, 1 & c && h++;
606
624
  }
607
625
  throw new Error("Failed to find VP8 keyframe in WebP image, is this image mistakenly encoded in the Lossless WebP format?");
608
626
  }
609
- function a(d) {
610
- this.value = d;
627
+ function a(l) {
628
+ this.value = l;
611
629
  }
612
- function i(d) {
613
- this.value = d;
630
+ function o(l) {
631
+ this.value = l;
614
632
  }
615
- function s(d, p, o) {
616
- if (Array.isArray(o)) for (let c = 0; c < o.length; c++) s(d, p, o[c]);
617
- else if (typeof o == "string") d.writeString(o);
618
- else if (o instanceof Uint8Array) d.writeBytes(o);
633
+ function s(l, h, n) {
634
+ if (Array.isArray(n)) for (let c = 0; c < n.length; c++) s(l, h, n[c]);
635
+ else if (typeof n == "string") l.writeString(n);
636
+ else if (n instanceof Uint8Array) l.writeBytes(n);
619
637
  else {
620
- if (!o.id) throw new Error("Bad EBML datatype " + typeof o.data);
621
- if (o.offset = d.pos + p, d.writeUnsignedIntBE(o.id), Array.isArray(o.data)) {
622
- let c, u, m;
623
- o.size === -1 ? d.writeByte(255) : o.size === -2 ? (c = d.pos, d.writeBytes([15, 255, 255, 255, 255])) : (c = d.pos, d.writeBytes([0, 0, 0, 0])), u = d.pos, o.dataOffset = u + p, s(d, p, o.data), o.size !== -1 && o.size !== -2 && (m = d.pos, o.size = m - u, d.seek(c), d.writeEBMLVarIntWidth(o.size, 4), d.seek(m));
624
- } else if (typeof o.data == "string") d.writeEBMLVarInt(o.data.length), o.dataOffset = d.pos + p, d.writeString(o.data);
625
- else if (typeof o.data == "number") o.size || (o.size = d.measureUnsignedInt(o.data)), d.writeEBMLVarInt(o.size), o.dataOffset = d.pos + p, d.writeUnsignedIntBE(o.data, o.size);
626
- else if (o.data instanceof i) d.writeEBMLVarInt(8), o.dataOffset = d.pos + p, d.writeDoubleBE(o.data.value);
627
- else if (o.data instanceof a) d.writeEBMLVarInt(4), o.dataOffset = d.pos + p, d.writeFloatBE(o.data.value);
638
+ if (!n.id) throw new Error("Bad EBML datatype " + typeof n.data);
639
+ if (n.offset = l.pos + h, l.writeUnsignedIntBE(n.id), Array.isArray(n.data)) {
640
+ let c, u, f;
641
+ n.size === -1 ? l.writeByte(255) : n.size === -2 ? (c = l.pos, l.writeBytes([15, 255, 255, 255, 255])) : (c = l.pos, l.writeBytes([0, 0, 0, 0])), u = l.pos, n.dataOffset = u + h, s(l, h, n.data), n.size !== -1 && n.size !== -2 && (f = l.pos, n.size = f - u, l.seek(c), l.writeEBMLVarIntWidth(n.size, 4), l.seek(f));
642
+ } else if (typeof n.data == "string") l.writeEBMLVarInt(n.data.length), n.dataOffset = l.pos + h, l.writeString(n.data);
643
+ else if (typeof n.data == "number") n.size || (n.size = l.measureUnsignedInt(n.data)), l.writeEBMLVarInt(n.size), n.dataOffset = l.pos + h, l.writeUnsignedIntBE(n.data, n.size);
644
+ else if (n.data instanceof o) l.writeEBMLVarInt(8), n.dataOffset = l.pos + h, l.writeDoubleBE(n.data.value);
645
+ else if (n.data instanceof a) l.writeEBMLVarInt(4), n.dataOffset = l.pos + h, l.writeFloatBE(n.data.value);
628
646
  else {
629
- if (!(o.data instanceof Uint8Array)) throw new Error("Bad EBML datatype " + typeof o.data);
630
- d.writeEBMLVarInt(o.data.byteLength), o.dataOffset = d.pos + p, d.writeBytes(o.data);
647
+ if (!(n.data instanceof Uint8Array)) throw new Error("Bad EBML datatype " + typeof n.data);
648
+ l.writeEBMLVarInt(n.data.byteLength), n.dataOffset = l.pos + h, l.writeBytes(n.data);
631
649
  }
632
650
  }
633
651
  }
634
- let l = function(d, p) {
635
- return function(o) {
636
- let c, u, m = !1, x = 0, h = 0, g = null, _ = null, v = null, f = [], C = 0, S = 0, E = { quality: 0.95, transparent: !1, alphaQuality: void 0, fileWriter: null, fd: null, frameDuration: null, frameRate: null }, A = { Cues: { id: new Uint8Array([28, 83, 187, 107]), positionEBML: null }, SegmentInfo: { id: new Uint8Array([21, 73, 169, 102]), positionEBML: null }, Tracks: { id: new Uint8Array([22, 84, 174, 107]), positionEBML: null } }, L = { id: 17545, data: new i(0) }, V = [], B = new p(o.fileWriter || o.fd);
637
- function D(y) {
638
- return y - c.dataOffset;
652
+ let d = function(l, h) {
653
+ return function(n) {
654
+ let c, u, f = !1, y = 0, m = 0, v = null, w = null, x = null, g = [], E = 0, F = 0, k = { quality: 0.95, transparent: !1, alphaQuality: void 0, fileWriter: null, fd: null, frameDuration: null, frameRate: null }, A = { Cues: { id: new Uint8Array([28, 83, 187, 107]), positionEBML: null }, SegmentInfo: { id: new Uint8Array([21, 73, 169, 102]), positionEBML: null }, Tracks: { id: new Uint8Array([22, 84, 174, 107]), positionEBML: null } }, L = { id: 17545, data: new o(0) }, V = [], S = new h(n.fileWriter || n.fd);
655
+ function D(_) {
656
+ return _ - c.dataOffset;
639
657
  }
640
- function T() {
658
+ function R() {
641
659
  u = (function() {
642
- let M = { id: 21420, size: 5, data: 0 }, U = { id: 290298740, data: [] };
660
+ let $ = { id: 21420, size: 5, data: 0 }, U = { id: 290298740, data: [] };
643
661
  for (let I in A) {
644
- let q = A[I];
645
- q.positionEBML = Object.create(M), U.data.push({ id: 19899, data: [{ id: 21419, data: q.id }, q.positionEBML] });
662
+ let X = A[I];
663
+ X.positionEBML = Object.create($), U.data.push({ id: 19899, data: [{ id: 21419, data: X.id }, X.positionEBML] });
646
664
  }
647
665
  return U;
648
666
  })();
649
- let y = { id: 357149030, data: [{ id: 2807729, data: 1e6 }, { id: 19840, data: "webm-writer-js" }, { id: 22337, data: "webm-writer-js" }, L] }, w = [{ id: 176, data: x }, { id: 186, data: h }];
650
- o.transparent && w.push({ id: 21440, data: 1 });
651
- let F = { id: 374648427, data: [{ id: 174, data: [{ id: 215, data: 1 }, { id: 29637, data: 1 }, { id: 156, data: 0 }, { id: 2274716, data: "und" }, { id: 134, data: "V_VP8" }, { id: 2459272, data: "VP8" }, { id: 131, data: 1 }, { id: 224, data: w }] }] };
652
- c = { id: 408125543, size: -2, data: [u, y, F] };
653
- let $ = new d(256);
654
- s($, B.pos, [{ id: 440786851, data: [{ id: 17030, data: 1 }, { id: 17143, data: 1 }, { id: 17138, data: 4 }, { id: 17139, data: 8 }, { id: 17026, data: "webm" }, { id: 17031, data: 2 }, { id: 17029, data: 2 }] }, c]), B.write($.getAsDataArray()), A.SegmentInfo.positionEBML.data = D(y.offset), A.Tracks.positionEBML.data = D(F.offset), m = !0;
667
+ let _ = { id: 357149030, data: [{ id: 2807729, data: 1e6 }, { id: 19840, data: "webm-writer-js" }, { id: 22337, data: "webm-writer-js" }, L] }, C = [{ id: 176, data: y }, { id: 186, data: m }];
668
+ n.transparent && C.push({ id: 21440, data: 1 });
669
+ let M = { id: 374648427, data: [{ id: 174, data: [{ id: 215, data: 1 }, { id: 29637, data: 1 }, { id: 156, data: 0 }, { id: 2274716, data: "und" }, { id: 134, data: "V_VP8" }, { id: 2459272, data: "VP8" }, { id: 131, data: 1 }, { id: 224, data: C }] }] };
670
+ c = { id: 408125543, size: -2, data: [u, _, M] };
671
+ let P = new l(256);
672
+ s(P, S.pos, [{ id: 440786851, data: [{ id: 17030, data: 1 }, { id: 17143, data: 1 }, { id: 17138, data: 4 }, { id: 17139, data: 8 }, { id: 17026, data: "webm" }, { id: 17031, data: 2 }, { id: 17029, data: 2 }] }, c]), S.write(P.getAsDataArray()), A.SegmentInfo.positionEBML.data = D(_.offset), A.Tracks.positionEBML.data = D(M.offset), f = !0;
655
673
  }
656
- function k(y) {
657
- return y.alpha ? (function(w) {
658
- let F, $, M = new d(4);
659
- if (!(w.trackNumber > 0 && w.trackNumber < 127)) throw new Error("TrackNumber must be > 0 and < 127");
660
- return M.writeEBMLVarInt(w.trackNumber), M.writeU16BE(w.timecode), M.writeByte(0), F = { id: 161, data: [M.getAsDataArray(), w.frame] }, $ = { id: 30113, data: [{ id: 166, data: [{ id: 238, data: 1 }, { id: 165, data: w.alpha }] }] }, { id: 160, data: [F, $] };
661
- })(y) : (function(w) {
662
- let F = new d(4);
663
- if (!(w.trackNumber > 0 && w.trackNumber < 127)) throw new Error("TrackNumber must be > 0 and < 127");
664
- return F.writeEBMLVarInt(w.trackNumber), F.writeU16BE(w.timecode), F.writeByte(128), { id: 163, data: [F.getAsDataArray(), w.frame] };
665
- })(y);
674
+ function B(_) {
675
+ return _.alpha ? (function(C) {
676
+ let M, P, $ = new l(4);
677
+ if (!(C.trackNumber > 0 && C.trackNumber < 127)) throw new Error("TrackNumber must be > 0 and < 127");
678
+ return $.writeEBMLVarInt(C.trackNumber), $.writeU16BE(C.timecode), $.writeByte(0), M = { id: 161, data: [$.getAsDataArray(), C.frame] }, P = { id: 30113, data: [{ id: 166, data: [{ id: 238, data: 1 }, { id: 165, data: C.alpha }] }] }, { id: 160, data: [M, P] };
679
+ })(_) : (function(C) {
680
+ let M = new l(4);
681
+ if (!(C.trackNumber > 0 && C.trackNumber < 127)) throw new Error("TrackNumber must be > 0 and < 127");
682
+ return M.writeEBMLVarInt(C.trackNumber), M.writeU16BE(C.timecode), M.writeByte(128), { id: 163, data: [M.getAsDataArray(), C.frame] };
683
+ })(_);
666
684
  }
667
- function R() {
668
- if (f.length === 0) return;
669
- let y = 0;
670
- for (let I = 0; I < f.length; I++) y += f[I].frame.length + (f[I].alpha ? f[I].alpha.length : 0);
671
- let w = new d(y + 64 * f.length), F = (function(I) {
685
+ function N() {
686
+ if (g.length === 0) return;
687
+ let _ = 0;
688
+ for (let I = 0; I < g.length; I++) _ += g[I].frame.length + (g[I].alpha ? g[I].alpha.length : 0);
689
+ let C = new l(_ + 64 * g.length), M = (function(I) {
672
690
  return { id: 524531317, data: [{ id: 231, data: Math.round(I.timecode) }] };
673
- })({ timecode: Math.round(C) });
674
- for (let I = 0; I < f.length; I++) F.data.push(k(f[I]));
675
- var $, M, U;
676
- s(w, B.pos, F), B.write(w.getAsDataArray()), $ = 1, M = Math.round(C), U = F.offset, V.push({ id: 187, data: [{ id: 179, data: M }, { id: 183, data: [{ id: 247, data: $ }, { id: 241, data: D(U) }] }] }), f = [], C += S, S = 0;
691
+ })({ timecode: Math.round(E) });
692
+ for (let I = 0; I < g.length; I++) M.data.push(B(g[I]));
693
+ var P, $, U;
694
+ s(C, S.pos, M), S.write(C.getAsDataArray()), P = 1, $ = Math.round(E), U = M.offset, V.push({ id: 187, data: [{ id: 179, data: $ }, { id: 183, data: [{ id: 247, data: P }, { id: 241, data: D(U) }] }] }), g = [], E += F, F = 0;
677
695
  }
678
- this.addFrame = function(y, w, F) {
679
- m || (x = y.width || 0, h = y.height || 0, T());
680
- let $, M = r(t(y, o.quality)), U = null;
681
- $ = F || (typeof w == "number" ? w : o.frameDuration), o.transparent && (w instanceof HTMLCanvasElement || typeof w == "string" ? U = w : M.hasAlpha && (U = (function(I) {
682
- g !== null && g.width === I.width && g.height === I.height || (g = document.createElement("canvas"), g.width = I.width, g.height = I.height, _ = g.getContext("2d"), v = _.createImageData(g.width, g.height));
683
- let q = I.getContext("2d").getImageData(0, 0, I.width, I.height).data, J = v.data, K = 0, Wt = I.width * I.height * 4;
684
- for (let ot = 3; ot < Wt; ot += 4) {
685
- let nt = q[ot];
686
- J[K++] = nt, J[K++] = nt, J[K++] = nt, J[K++] = 255;
696
+ this.addFrame = function(_, C, M) {
697
+ f || (y = _.width || 0, m = _.height || 0, R());
698
+ let P, $ = e(r(_, n.quality)), U = null;
699
+ P = M || (typeof C == "number" ? C : n.frameDuration), n.transparent && (C instanceof HTMLCanvasElement || typeof C == "string" ? U = C : $.hasAlpha && (U = (function(I) {
700
+ v !== null && v.width === I.width && v.height === I.height || (v = document.createElement("canvas"), v.width = I.width, v.height = I.height, w = v.getContext("2d"), x = w.createImageData(v.width, v.height));
701
+ let X = I.getContext("2d").getImageData(0, 0, I.width, I.height).data, K = x.data, Z = 0, Xt = I.width * I.height * 4;
702
+ for (let dt = 3; dt < Xt; dt += 4) {
703
+ let ct = X[dt];
704
+ K[Z++] = ct, K[Z++] = ct, K[Z++] = ct, K[Z++] = 255;
687
705
  }
688
- return _.putImageData(v, 0, 0), g;
689
- })(y))), (function(I) {
690
- I.trackNumber = 1, I.timecode = Math.round(S), f.push(I), S += I.duration, S >= 5e3 && R();
691
- })({ frame: M.frame, duration: $, alpha: U ? r(t(U, o.alphaQuality)).frame : null });
706
+ return w.putImageData(x, 0, 0), v;
707
+ })(_))), (function(I) {
708
+ I.trackNumber = 1, I.timecode = Math.round(F), g.push(I), F += I.duration, F >= 5e3 && N();
709
+ })({ frame: $.frame, duration: P, alpha: U ? e(r(U, n.alphaQuality)).frame : null });
692
710
  }, this.complete = function() {
693
- return m || T(), R(), (function() {
694
- let y = { id: 475249515, data: V }, w = new d(16 + 32 * V.length);
695
- s(w, B.pos, y), B.write(w.getAsDataArray()), A.Cues.positionEBML.data = D(y.offset);
711
+ return f || R(), N(), (function() {
712
+ let _ = { id: 475249515, data: V }, C = new l(16 + 32 * V.length);
713
+ s(C, S.pos, _), S.write(C.getAsDataArray()), A.Cues.positionEBML.data = D(_.offset);
696
714
  })(), (function() {
697
- let y = new d(u.size), w = B.pos;
698
- s(y, u.dataOffset, u.data), B.seek(u.dataOffset), B.write(y.getAsDataArray()), B.seek(w);
715
+ let _ = new l(u.size), C = S.pos;
716
+ s(_, u.dataOffset, u.data), S.seek(u.dataOffset), S.write(_.getAsDataArray()), S.seek(C);
699
717
  })(), (function() {
700
- let y = new d(8), w = B.pos;
701
- y.writeDoubleBE(C), B.seek(L.dataOffset), B.write(y.getAsDataArray()), B.seek(w);
718
+ let _ = new l(8), C = S.pos;
719
+ _.writeDoubleBE(E), S.seek(L.dataOffset), S.write(_.getAsDataArray()), S.seek(C);
702
720
  })(), (function() {
703
- let y = new d(10), w = B.pos;
704
- y.writeUnsignedIntBE(c.id), y.writeEBMLVarIntWidth(B.pos - c.dataOffset, 5), B.seek(c.offset), B.write(y.getAsDataArray()), B.seek(w);
705
- })(), B.complete("video/webm");
721
+ let _ = new l(10), C = S.pos;
722
+ _.writeUnsignedIntBE(c.id), _.writeEBMLVarIntWidth(S.pos - c.dataOffset, 5), S.seek(c.offset), S.write(_.getAsDataArray()), S.seek(C);
723
+ })(), S.complete("video/webm");
706
724
  }, this.getWrittenSize = function() {
707
- return B.length;
708
- }, o = (function(y, w) {
709
- let F = {};
710
- return [y, w].forEach(function($) {
711
- for (let M in $) Object.prototype.hasOwnProperty.call($, M) && (F[M] = $[M]);
712
- }), F;
713
- })(E, o || {}), (function() {
714
- if (!o.frameDuration) {
715
- if (!o.frameRate) throw new Error("Missing required frameDuration or frameRate setting");
716
- o.frameDuration = 1e3 / o.frameRate;
725
+ return S.length;
726
+ }, n = (function(_, C) {
727
+ let M = {};
728
+ return [_, C].forEach(function(P) {
729
+ for (let $ in P) Object.prototype.hasOwnProperty.call(P, $) && (M[$] = P[$]);
730
+ }), M;
731
+ })(k, n || {}), (function() {
732
+ if (!n.frameDuration) {
733
+ if (!n.frameRate) throw new Error("Missing required frameDuration or frameRate setting");
734
+ n.frameDuration = 1e3 / n.frameRate;
717
735
  }
718
- o.quality = Math.max(Math.min(o.quality, 0.99999), 0), o.alphaQuality === void 0 ? o.alphaQuality = o.quality : o.alphaQuality = Math.max(Math.min(o.alphaQuality, 0.99999), 0);
736
+ n.quality = Math.max(Math.min(n.quality, 0.99999), 0), n.alphaQuality === void 0 ? n.alphaQuality = n.quality : n.alphaQuality = Math.max(Math.min(n.alphaQuality, 0.99999), 0);
719
737
  })();
720
738
  };
721
739
  };
722
- n.exports = l;
723
- })()), Ct.exports;
724
- var n;
725
- }
726
- var Et, kt = { exports: {} };
727
- function ve() {
728
- return Et || (Et = 1, n = kt, (function() {
729
- let t = function(e) {
730
- this.data = new Uint8Array(e), this.pos = 0;
740
+ i.exports = d;
741
+ })()), Mt.exports;
742
+ var i;
743
+ }
744
+ var Lt, $t = { exports: {} };
745
+ function Be() {
746
+ return Lt || (Lt = 1, i = $t, (function() {
747
+ let r = function(t) {
748
+ this.data = new Uint8Array(t), this.pos = 0;
731
749
  };
732
- t.prototype.seek = function(e) {
733
- this.pos = e;
734
- }, t.prototype.writeBytes = function(e) {
735
- for (let r = 0; r < e.length; r++) this.data[this.pos++] = e[r];
736
- }, t.prototype.writeByte = function(e) {
737
- this.data[this.pos++] = e;
738
- }, t.prototype.writeU8 = t.prototype.writeByte, t.prototype.writeU16BE = function(e) {
739
- this.data[this.pos++] = e >> 8, this.data[this.pos++] = e;
740
- }, t.prototype.writeDoubleBE = function(e) {
741
- let r = new Uint8Array(new Float64Array([e]).buffer);
742
- for (let a = r.length - 1; a >= 0; a--) this.writeByte(r[a]);
743
- }, t.prototype.writeFloatBE = function(e) {
744
- let r = new Uint8Array(new Float32Array([e]).buffer);
745
- for (let a = r.length - 1; a >= 0; a--) this.writeByte(r[a]);
746
- }, t.prototype.writeString = function(e) {
747
- for (let r = 0; r < e.length; r++) this.data[this.pos++] = e.charCodeAt(r);
748
- }, t.prototype.writeEBMLVarIntWidth = function(e, r) {
749
- switch (r) {
750
+ r.prototype.seek = function(t) {
751
+ this.pos = t;
752
+ }, r.prototype.writeBytes = function(t) {
753
+ for (let e = 0; e < t.length; e++) this.data[this.pos++] = t[e];
754
+ }, r.prototype.writeByte = function(t) {
755
+ this.data[this.pos++] = t;
756
+ }, r.prototype.writeU8 = r.prototype.writeByte, r.prototype.writeU16BE = function(t) {
757
+ this.data[this.pos++] = t >> 8, this.data[this.pos++] = t;
758
+ }, r.prototype.writeDoubleBE = function(t) {
759
+ let e = new Uint8Array(new Float64Array([t]).buffer);
760
+ for (let a = e.length - 1; a >= 0; a--) this.writeByte(e[a]);
761
+ }, r.prototype.writeFloatBE = function(t) {
762
+ let e = new Uint8Array(new Float32Array([t]).buffer);
763
+ for (let a = e.length - 1; a >= 0; a--) this.writeByte(e[a]);
764
+ }, r.prototype.writeString = function(t) {
765
+ for (let e = 0; e < t.length; e++) this.data[this.pos++] = t.charCodeAt(e);
766
+ }, r.prototype.writeEBMLVarIntWidth = function(t, e) {
767
+ switch (e) {
750
768
  case 1:
751
- this.writeU8(128 | e);
769
+ this.writeU8(128 | t);
752
770
  break;
753
771
  case 2:
754
- this.writeU8(64 | e >> 8), this.writeU8(e);
772
+ this.writeU8(64 | t >> 8), this.writeU8(t);
755
773
  break;
756
774
  case 3:
757
- this.writeU8(32 | e >> 16), this.writeU8(e >> 8), this.writeU8(e);
775
+ this.writeU8(32 | t >> 16), this.writeU8(t >> 8), this.writeU8(t);
758
776
  break;
759
777
  case 4:
760
- this.writeU8(16 | e >> 24), this.writeU8(e >> 16), this.writeU8(e >> 8), this.writeU8(e);
778
+ this.writeU8(16 | t >> 24), this.writeU8(t >> 16), this.writeU8(t >> 8), this.writeU8(t);
761
779
  break;
762
780
  case 5:
763
- this.writeU8(8 | e / 4294967296 & 7), this.writeU8(e >> 24), this.writeU8(e >> 16), this.writeU8(e >> 8), this.writeU8(e);
781
+ this.writeU8(8 | t / 4294967296 & 7), this.writeU8(t >> 24), this.writeU8(t >> 16), this.writeU8(t >> 8), this.writeU8(t);
764
782
  break;
765
783
  default:
766
- throw new Error("Bad EBML VINT size " + r);
784
+ throw new Error("Bad EBML VINT size " + e);
767
785
  }
768
- }, t.prototype.measureEBMLVarInt = function(e) {
769
- if (e < 127) return 1;
770
- if (e < 16383) return 2;
771
- if (e < 2097151) return 3;
772
- if (e < 268435455) return 4;
773
- if (e < 34359738367) return 5;
774
- throw new Error("EBML VINT size not supported " + e);
775
- }, t.prototype.writeEBMLVarInt = function(e) {
776
- this.writeEBMLVarIntWidth(e, this.measureEBMLVarInt(e));
777
- }, t.prototype.writeUnsignedIntBE = function(e, r) {
778
- switch (r === void 0 && (r = this.measureUnsignedInt(e)), r) {
786
+ }, r.prototype.measureEBMLVarInt = function(t) {
787
+ if (t < 127) return 1;
788
+ if (t < 16383) return 2;
789
+ if (t < 2097151) return 3;
790
+ if (t < 268435455) return 4;
791
+ if (t < 34359738367) return 5;
792
+ throw new Error("EBML VINT size not supported " + t);
793
+ }, r.prototype.writeEBMLVarInt = function(t) {
794
+ this.writeEBMLVarIntWidth(t, this.measureEBMLVarInt(t));
795
+ }, r.prototype.writeUnsignedIntBE = function(t, e) {
796
+ switch (e === void 0 && (e = this.measureUnsignedInt(t)), e) {
779
797
  case 5:
780
- this.writeU8(Math.floor(e / 4294967296));
798
+ this.writeU8(Math.floor(t / 4294967296));
781
799
  case 4:
782
- this.writeU8(e >> 24);
800
+ this.writeU8(t >> 24);
783
801
  case 3:
784
- this.writeU8(e >> 16);
802
+ this.writeU8(t >> 16);
785
803
  case 2:
786
- this.writeU8(e >> 8);
804
+ this.writeU8(t >> 8);
787
805
  case 1:
788
- this.writeU8(e);
806
+ this.writeU8(t);
789
807
  break;
790
808
  default:
791
- throw new Error("Bad UINT size " + r);
809
+ throw new Error("Bad UINT size " + e);
792
810
  }
793
- }, t.prototype.measureUnsignedInt = function(e) {
794
- return e < 256 ? 1 : e < 65536 ? 2 : e < 1 << 24 ? 3 : e < 4294967296 ? 4 : 5;
795
- }, t.prototype.getAsDataArray = function() {
811
+ }, r.prototype.measureUnsignedInt = function(t) {
812
+ return t < 256 ? 1 : t < 65536 ? 2 : t < 1 << 24 ? 3 : t < 4294967296 ? 4 : 5;
813
+ }, r.prototype.getAsDataArray = function() {
796
814
  if (this.pos < this.data.byteLength) return this.data.subarray(0, this.pos);
797
815
  if (this.pos == this.data.byteLength) return this.data;
798
816
  throw new Error("ArrayBufferDataStream's pos lies beyond end of buffer");
799
- }, n.exports = t;
800
- })()), kt.exports;
801
- var n;
802
- }
803
- var Bt, It, St, Ft = { exports: {} };
804
- function xe() {
805
- return Bt || (Bt = 1, n = Ft, (function() {
806
- let t = function(e) {
807
- return function(r) {
808
- let a = [], i = Promise.resolve(), s = null, l = null;
809
- function d(c) {
810
- return new Promise(function(u, m) {
811
- let x = new FileReader();
812
- x.addEventListener("loadend", function() {
813
- u(x.result);
814
- }), x.readAsArrayBuffer(c);
817
+ }, i.exports = r;
818
+ })()), $t.exports;
819
+ var i;
820
+ }
821
+ var Pt, At, Ot, Dt = { exports: {} };
822
+ function Se() {
823
+ return Pt || (Pt = 1, i = Dt, (function() {
824
+ let r = function(t) {
825
+ return function(e) {
826
+ let a = [], o = Promise.resolve(), s = null, d = null;
827
+ function l(c) {
828
+ return new Promise(function(u, f) {
829
+ let y = new FileReader();
830
+ y.addEventListener("loadend", function() {
831
+ u(y.result);
832
+ }), y.readAsArrayBuffer(c);
815
833
  });
816
834
  }
817
- function p(c) {
818
- return new Promise(function(u, m) {
819
- c instanceof Uint8Array ? u(c) : c instanceof ArrayBuffer || ArrayBuffer.isView(c) ? u(new Uint8Array(c)) : c instanceof Blob ? u(d(c).then(function(x) {
820
- return new Uint8Array(x);
821
- })) : u(d(new Blob([c])).then(function(x) {
822
- return new Uint8Array(x);
835
+ function h(c) {
836
+ return new Promise(function(u, f) {
837
+ c instanceof Uint8Array ? u(c) : c instanceof ArrayBuffer || ArrayBuffer.isView(c) ? u(new Uint8Array(c)) : c instanceof Blob ? u(l(c).then(function(y) {
838
+ return new Uint8Array(y);
839
+ })) : u(l(new Blob([c])).then(function(y) {
840
+ return new Uint8Array(y);
823
841
  }));
824
842
  });
825
843
  }
826
- function o(c) {
844
+ function n(c) {
827
845
  let u = c.byteLength || c.length || c.size;
828
846
  if (!Number.isInteger(u)) throw new Error("Failed to determine size of element");
829
847
  return u;
830
848
  }
831
- r && r.constructor.name === "FileWriter" ? s = r : e && r && (l = r), this.pos = 0, this.length = 0, this.seek = function(c) {
849
+ e && e.constructor.name === "FileWriter" ? s = e : t && e && (d = e), this.pos = 0, this.length = 0, this.seek = function(c) {
832
850
  if (c < 0) throw new Error("Offset may not be negative");
833
851
  if (isNaN(c)) throw new Error("Offset may not be NaN");
834
852
  if (c > this.length) throw new Error("Seeking beyond the end of file is not allowed");
835
853
  this.pos = c;
836
854
  }, this.write = function(c) {
837
- let u = { offset: this.pos, data: c, length: o(c) }, m = u.offset >= this.length;
838
- this.pos += u.length, this.length = Math.max(this.length, this.pos), i = i.then(function() {
839
- if (l) return new Promise(function(x, h) {
840
- p(u.data).then(function(g) {
841
- let _ = 0, v = Buffer.from(g.buffer), f = function(C, S, E) {
842
- _ += S, _ >= E.length ? x() : e.write(l, E, _, E.length - _, u.offset + _, f);
855
+ let u = { offset: this.pos, data: c, length: n(c) }, f = u.offset >= this.length;
856
+ this.pos += u.length, this.length = Math.max(this.length, this.pos), o = o.then(function() {
857
+ if (d) return new Promise(function(y, m) {
858
+ h(u.data).then(function(v) {
859
+ let w = 0, x = Buffer.from(v.buffer), g = function(E, F, k) {
860
+ w += F, w >= k.length ? y() : t.write(d, k, w, k.length - w, u.offset + w, g);
843
861
  };
844
- e.write(l, v, 0, v.length, u.offset, f);
862
+ t.write(d, x, 0, x.length, u.offset, g);
845
863
  });
846
864
  });
847
- if (s) return new Promise(function(x, h) {
848
- s.onwriteend = x, s.seek(u.offset), s.write(new Blob([u.data]));
865
+ if (s) return new Promise(function(y, m) {
866
+ s.onwriteend = y, s.seek(u.offset), s.write(new Blob([u.data]));
849
867
  });
850
- if (!m) for (let x = 0; x < a.length; x++) {
851
- let h = a[x];
852
- if (!(u.offset + u.length <= h.offset || u.offset >= h.offset + h.length)) {
853
- if (u.offset < h.offset || u.offset + u.length > h.offset + h.length) throw new Error("Overwrite crosses blob boundaries");
854
- return u.offset == h.offset && u.length == h.length ? void (h.data = u.data) : p(h.data).then(function(g) {
855
- return h.data = g, p(u.data);
856
- }).then(function(g) {
857
- u.data = g, h.data.set(u.data, u.offset - h.offset);
868
+ if (!f) for (let y = 0; y < a.length; y++) {
869
+ let m = a[y];
870
+ if (!(u.offset + u.length <= m.offset || u.offset >= m.offset + m.length)) {
871
+ if (u.offset < m.offset || u.offset + u.length > m.offset + m.length) throw new Error("Overwrite crosses blob boundaries");
872
+ return u.offset == m.offset && u.length == m.length ? void (m.data = u.data) : h(m.data).then(function(v) {
873
+ return m.data = v, h(u.data);
874
+ }).then(function(v) {
875
+ u.data = v, m.data.set(u.data, u.offset - m.offset);
858
876
  });
859
877
  }
860
878
  }
861
879
  a.push(u);
862
880
  });
863
881
  }, this.complete = function(c) {
864
- return i = l || s ? i.then(function() {
882
+ return o = d || s ? o.then(function() {
865
883
  return null;
866
- }) : i.then(function() {
884
+ }) : o.then(function() {
867
885
  let u = [];
868
- for (let m = 0; m < a.length; m++) u.push(a[m].data);
886
+ for (let f = 0; f < a.length; f++) u.push(a[f].data);
869
887
  return new Blob(u, { type: c });
870
- }), i;
888
+ }), o;
871
889
  };
872
890
  };
873
891
  };
874
- n.exports = t;
875
- })()), Ft.exports;
876
- var n;
877
- }
878
- function ye() {
879
- return St ? It : (St = 1, It = be()(ve(), xe()(null)));
880
- }
881
- var _e = ye();
882
- const we = ge(_e);
883
- class Ce {
884
- async $record(t, e, r, a) {
885
- const i = Math.max(1, Math.round(e.frameRate)), s = Math.max(1, Math.round(e.frameCount)), l = new we({ quality: e.quality, alphaQuality: e.transparent ? e.quality : void 0, transparent: e.transparent, frameRate: i }), d = this._createSnapshotSurface();
886
- return await new Promise((p, o) => {
887
- let c, u = "capturing", m = !1, x = 0;
888
- const h = () => {
892
+ i.exports = r;
893
+ })()), Dt.exports;
894
+ var i;
895
+ }
896
+ function Ie() {
897
+ return Ot ? At : (Ot = 1, At = ke()(Be(), Se()(null)));
898
+ }
899
+ var Fe = Ie();
900
+ const Me = Ee(Fe);
901
+ class Le {
902
+ async $record(r, t, e, a) {
903
+ const o = Math.max(1, Math.round(t.frameRate)), s = Math.max(1, Math.round(t.frameCount)), d = new Me({ quality: t.quality, alphaQuality: t.transparent ? t.quality : void 0, transparent: t.transparent, frameRate: o }), l = this._createSnapshotSurface();
904
+ return await new Promise((h, n) => {
905
+ let c, u = "capturing", f = !1, y = 0;
906
+ const m = () => {
889
907
  c && (c(), c = void 0);
890
- }, g = () => {
891
- a?.({ state: "recording", frameIndex: x, totalFrames: s });
892
- }, _ = (f) => {
893
- if (m) return;
894
- m = !0, h();
895
- const C = f instanceof Error ? f.message : "WEBM export failed";
896
- a?.({ state: "error", message: C }), o(f instanceof Error ? f : new Error(String(f)));
897
908
  }, v = () => {
898
- u !== "capturing" || m || (u = "encoding", h(), l.complete().then((f) => {
899
- ((C) => {
900
- m || (m = !0, a?.({ state: "completed", frameIndex: Math.min(s, x), totalFrames: s }), p(C));
901
- })(f);
902
- }).catch(_));
909
+ a == null || a({ state: "recording", frameIndex: y, totalFrames: s });
910
+ }, w = (g) => {
911
+ if (f) return;
912
+ f = !0, m();
913
+ const E = g instanceof Error ? g.message : "WEBM export failed";
914
+ a == null || a({ state: "error", message: E }), n(g instanceof Error ? g : new Error(String(g)));
915
+ }, x = () => {
916
+ u !== "capturing" || f || (u = "encoding", m(), d.complete().then((g) => {
917
+ ((E) => {
918
+ f || (f = !0, a == null || a({ state: "completed", frameIndex: Math.min(s, y), totalFrames: s }), h(E));
919
+ })(g);
920
+ }).catch(w));
903
921
  };
904
- c = r(() => {
922
+ c = e(() => {
905
923
  (() => {
906
- if (u === "capturing") if (x >= s) v();
924
+ if (u === "capturing") if (y >= s) x();
907
925
  else try {
908
- const f = d(t);
909
- l.addFrame(f), x += 1, g(), x >= s && v();
910
- } catch (f) {
911
- _(f);
926
+ const g = l(r);
927
+ d.addFrame(g), y += 1, v(), y >= s && x();
928
+ } catch (g) {
929
+ w(g);
912
930
  }
913
931
  })();
914
- }), g();
932
+ }), v();
915
933
  });
916
934
  }
917
935
  _createSnapshotSurface() {
918
- let t = null, e = null;
919
- return (r) => {
920
- const a = Math.max(1, r.width), i = Math.max(1, r.height), s = ((l, d) => (t || (t = document.createElement("canvas")), t.width !== l || t.height !== d ? (t.width = l, t.height = d, e = t.getContext("2d"), e && (e.imageSmoothingEnabled = !1)) : e || (e = t.getContext("2d"), e && (e.imageSmoothingEnabled = !1)), e ? t : null))(a, i);
921
- return s && e ? (e.clearRect(0, 0, a, i), e.drawImage(r, 0, 0, a, i), s) : r;
936
+ let r = null, t = null;
937
+ return (e) => {
938
+ const a = Math.max(1, e.width), o = Math.max(1, e.height), s = ((d, l) => (r || (r = document.createElement("canvas")), r.width !== d || r.height !== l ? (r.width = d, r.height = l, t = r.getContext("2d"), t && (t.imageSmoothingEnabled = !1)) : t || (t = r.getContext("2d"), t && (t.imageSmoothingEnabled = !1)), t ? r : null))(a, o);
939
+ return s && t ? (t.clearRect(0, 0, a, o), t.drawImage(e, 0, 0, a, o), s) : e;
922
940
  };
923
941
  }
924
942
  }
925
- class Ee {
926
- _recorder;
927
- _textmodifier;
928
- _registerPostDrawHook;
929
- constructor(t, e) {
930
- this._recorder = new Ce(), this._textmodifier = t, this._registerPostDrawHook = e;
943
+ class $e {
944
+ constructor(r, t) {
945
+ p(this, "_recorder");
946
+ p(this, "_textmodifier");
947
+ p(this, "_registerPostDrawHook");
948
+ this._recorder = new Le(), this._textmodifier = r, this._registerPostDrawHook = t;
931
949
  }
932
- async $saveWEBM(t = {}) {
933
- const e = this._textmodifier.canvas, r = this._applyDefaultOptions(t);
950
+ async $saveWEBM(r = {}) {
951
+ var a;
952
+ const t = this._textmodifier.canvas, e = this._applyDefaultOptions(r);
934
953
  try {
935
- const a = await this._recorder.$record(e, r, this._registerPostDrawHook, t.onProgress);
936
- new Q().$downloadFile(a, r.filename);
937
- } catch (a) {
938
- throw t.onProgress?.({ state: "error", message: a instanceof Error ? a.message : "WEBM export failed" }), a;
954
+ const o = await this._recorder.$record(t, e, this._registerPostDrawHook, r.onProgress);
955
+ new H().$downloadFile(o, e.filename);
956
+ } catch (o) {
957
+ throw (a = r.onProgress) == null || a.call(r, { state: "error", message: o instanceof Error ? o.message : "WEBM export failed" }), o;
958
+ }
959
+ }
960
+ _applyDefaultOptions(r) {
961
+ return { filename: r.filename, frameRate: Math.abs(Math.round(r.frameRate ?? 60)), frameCount: Math.abs(Math.round(r.frameCount ?? 300)), quality: Math.abs(Math.min(Math.max(r.quality ?? 1, 0), 1)), transparent: !!r.transparent, debugLogging: !!r.debugLogging };
962
+ }
963
+ }
964
+ class Pe extends xt {
965
+ $extractCellData(r) {
966
+ var s;
967
+ const t = r.layers.base.drawFramebuffer, e = this.$extractFramebufferData(t), a = [];
968
+ let o = 0;
969
+ for (let d = 0; d < r.grid.rows; d++) for (let l = 0; l < r.grid.cols; l++) {
970
+ const h = 4 * o, n = this.$getEncodedCharacterValue(e.characterPixels, h), c = this.$extractCellTransform(e.characterPixels, h), u = ((s = yt(r.font, n)) == null ? void 0 : s.character) ?? " ";
971
+ a.push({ x: l, y: d, character: u, foreground: it(e.primaryColorPixels, h), background: it(e.secondaryColorPixels, h), transform: { invert: c.isInverted, flipX: c.flipHorizontal, flipY: c.flipVertical, rotation: c.rotation } }), o++;
972
+ }
973
+ return a;
974
+ }
975
+ }
976
+ const Ae = "https://textmode.art/schemas/textmode-layer-1.0.schema.json";
977
+ class mt {
978
+ _applyDefaultOptions(r) {
979
+ return { pretty: r.pretty ?? !0, colorMode: r.colorMode ?? "hex", includeMetadata: r.includeMetadata ?? !0, filename: r.filename };
980
+ }
981
+ _formatColor(r, t) {
982
+ return t === "rgba" ? { ...r } : `#${[r.r, r.g, r.b, r.a].map((e) => e.toString(16).padStart(2, "0")).join("")}`;
983
+ }
984
+ _createObjectRowsCells(r, t, e) {
985
+ const a = [];
986
+ for (let o = 0; o < t.grid.rows; o++) {
987
+ const s = o * t.grid.cols, d = r.slice(s, s + t.grid.cols).map((l) => ({ x: l.x, y: l.y, character: l.character, foreground: this._formatColor(l.foreground, e), background: this._formatColor(l.background, e), transform: { ...l.transform } }));
988
+ a.push(d);
939
989
  }
990
+ return { encoding: "object-rows-v1", rows: a };
991
+ }
992
+ $generateJSONData(r, t = {}) {
993
+ const e = this._applyDefaultOptions(t), a = new Pe().$extractCellData(r), o = this._createObjectRowsCells(a, r, e.colorMode);
994
+ return { $schema: Ae, format: "textmode.layer", formatVersion: "1.0.0", ...e.includeMetadata ? { metadata: { createdAt: (/* @__PURE__ */ new Date()).toISOString(), generator: { name: "textmode.export.js", version: "1.2.1" } } } : {}, canvas: { width: r.grid.width, height: r.grid.height }, grid: { cols: r.grid.cols, rows: r.grid.rows, cellWidth: r.grid.cellWidth, cellHeight: r.grid.cellHeight }, layer: { id: "base", cells: o } };
940
995
  }
941
- _applyDefaultOptions(t) {
942
- return { filename: t.filename, frameRate: Math.abs(Math.round(t.frameRate ?? 60)), frameCount: Math.abs(Math.round(t.frameCount ?? 300)), quality: Math.abs(Math.min(Math.max(t.quality ?? 1, 0), 1)), transparent: !!t.transparent, debugLogging: !!t.debugLogging };
996
+ $generateJSONString(r, t = {}) {
997
+ const e = this._applyDefaultOptions(t), a = this.$generateJSONData(r, e), o = typeof e.pretty == "number" ? e.pretty : e.pretty ? 2 : 0;
998
+ return JSON.stringify(a, null, o);
999
+ }
1000
+ $saveJSON(r, t = {}) {
1001
+ const e = this._applyDefaultOptions(t);
1002
+ new H().$downloadFile(new Blob([this.$generateJSONString(r, e)], { type: "application/json;charset=utf-8" }), e.filename);
943
1003
  }
944
1004
  }
945
1005
  const b = { root: "textmode-export-overlay", stack: "textmode-export-overlay__stack", stackDense: "textmode-export-overlay__stack--dense", stackCompact: "textmode-export-overlay__stack--compact", section: "textmode-export-overlay__section", header: "textmode-export-overlay__header", headerTitleRow: "textmode-export-overlay__header-title-row", headerLinks: "textmode-export-overlay__header-links", row: "textmode-export-overlay__row", label: "textmode-export-overlay__label", field: "textmode-export-overlay__field", fieldCompact: "textmode-export-overlay__field--compact", fieldDense: "textmode-export-overlay__field--dense", fieldFull: "textmode-export-overlay__field--full", fieldChannel: "textmode-export-overlay__field--channel", input: "textmode-export-overlay__input", checkbox: "textmode-export-overlay__checkbox", muted: "textmode-export-overlay__muted", status: "textmode-export-overlay__status", statusGif: "textmode-export-overlay__status--gif", statusVideo: "textmode-export-overlay__status--video", statusTitle: "textmode-export-overlay__status-title", statusValue: "textmode-export-overlay__status-value", divider: "textmode-export-overlay__divider", title: "textmode-export-overlay__title", button: "textmode-export-overlay__button", buttonPrimary: "textmode-export-overlay__button--primary", buttonSecondary: "textmode-export-overlay__button--secondary", buttonFull: "textmode-export-overlay__button--full", supportLink: "textmode-export-overlay__support-link", supportIcon: "textmode-export-overlay__support-icon", linkIcon: "textmode-export-overlay__link-icon" };
946
- class O {
947
- element;
948
- mounted = !1;
949
- destroyed = !1;
950
- mount(t) {
1006
+ class T {
1007
+ constructor() {
1008
+ p(this, "element");
1009
+ p(this, "mounted", !1);
1010
+ p(this, "destroyed", !1);
1011
+ }
1012
+ mount(r) {
951
1013
  if (this.destroyed) throw new Error("Cannot mount a destroyed component");
952
1014
  if (this.mounted) return;
953
- const e = this.render();
954
- t.appendChild(e), this.element = e, this.onMount(), this.mounted = !0;
1015
+ const t = this.render();
1016
+ r.appendChild(t), this.element = t, this.onMount(), this.mounted = !0;
955
1017
  }
956
1018
  unmount() {
957
1019
  this.mounted && this.element && (this._onUnmount(), this.element.remove(), this.element = void 0, this.mounted = !1);
@@ -959,8 +1021,8 @@ class O {
959
1021
  destroy() {
960
1022
  this.destroyed || (this.unmount(), this._onDestroy(), this.destroyed = !0);
961
1023
  }
962
- update(t) {
963
- this.mounted && this.onUpdate(t);
1024
+ update(r) {
1025
+ this.mounted && this.onUpdate(r);
964
1026
  }
965
1027
  onMount() {
966
1028
  }
@@ -968,7 +1030,7 @@ class O {
968
1030
  }
969
1031
  _onDestroy() {
970
1032
  }
971
- onUpdate(t) {
1033
+ onUpdate(r) {
972
1034
  }
973
1035
  get root() {
974
1036
  if (!this.element) throw new Error("Component is not mounted yet");
@@ -978,49 +1040,51 @@ class O {
978
1040
  return this.mounted;
979
1041
  }
980
1042
  }
981
- class H extends O {
982
- static _iconNamespace = "http://www.w3.org/2000/svg";
1043
+ const q = class q extends T {
983
1044
  render() {
1045
+ const r = document.createElement("div");
1046
+ r.classList.add(b.stack, b.stackDense, b.header);
984
1047
  const t = document.createElement("div");
985
- t.classList.add(b.stack, b.stackDense, b.header);
986
- const e = document.createElement("div");
987
- e.classList.add(b.headerTitleRow);
988
- const r = document.createElement("strong");
989
- r.textContent = "textmode.export.js", r.classList.add(b.title);
1048
+ t.classList.add(b.headerTitleRow);
1049
+ const e = document.createElement("strong");
1050
+ e.textContent = "textmode.export.js", e.classList.add(b.title);
990
1051
  const a = document.createElement("div");
991
1052
  a.classList.add(b.headerLinks);
992
- const i = this._createLink("https://github.com/humanbydefinition/textmode.export.js", "View repository on GitHub", b.linkIcon, [{ d: "M0 0h24v24H0z", fill: "none", stroke: "none" }, { d: "M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5" }]), s = this._createLink("https://code.textmode.art/docs/support", "Support textmode.export.js", b.supportIcon, [{ d: "M0 0h24v24H0z", fill: "none", stroke: "none" }, { d: "M3 14c.83 .642 2.077 1.017 3.5 1c1.423 .017 2.67 -.358 3.5 -1c.83 -.642 2.077 -1.017 3.5 -1c1.423 -.017 2.67 .358 3.5 1" }, { d: "M8 3a2.4 2.4 0 0 0 -1 2a2.4 2.4 0 0 0 1 2" }, { d: "M12 3a2.4 2.4 0 0 0 -1 2a2.4 2.4 0 0 0 1 2" }, { d: "M3 10h14v5a6 6 0 0 1 -6 6h-2a6 6 0 0 1 -6 -6v-5z" }, { d: "M16.746 16.726a3 3 0 1 0 .252 -5.555" }]);
993
- a.appendChild(i), a.appendChild(s), e.appendChild(r), e.appendChild(a);
994
- const l = document.createElement("div");
995
- return l.classList.add(b.divider), t.appendChild(e), t.appendChild(l), t;
996
- }
997
- _createLink(t, e, r, a) {
998
- const i = document.createElement("a");
999
- return i.href = t, i.target = "_blank", i.rel = "noopener noreferrer", i.classList.add(b.supportLink), i.setAttribute("aria-label", e), i.appendChild(this._createIcon(r, a)), i;
1000
- }
1001
- _createIcon(t, e) {
1002
- const r = document.createElementNS(H._iconNamespace, "svg");
1003
- r.setAttribute("xmlns", H._iconNamespace), r.setAttribute("width", "18"), r.setAttribute("height", "18"), r.setAttribute("viewBox", "0 0 24 24"), r.setAttribute("fill", "none"), r.setAttribute("stroke", "currentColor"), r.setAttribute("stroke-width", "2"), r.setAttribute("stroke-linecap", "round"), r.setAttribute("stroke-linejoin", "round"), r.classList.add(t);
1004
- for (const a of e) {
1005
- const i = document.createElementNS(H._iconNamespace, "path");
1006
- for (const [s, l] of Object.entries(a)) i.setAttribute(s, l);
1007
- r.appendChild(i);
1053
+ const o = this._createLink("https://github.com/humanbydefinition/textmode.export.js", "View repository on GitHub", b.linkIcon, [{ d: "M0 0h24v24H0z", fill: "none", stroke: "none" }, { d: "M9 19c-4.3 1.4 -4.3 -2.5 -6 -3m12 5v-3.5c0 -1 .1 -1.4 -.5 -2c2.8 -.3 5.5 -1.4 5.5 -6a4.6 4.6 0 0 0 -1.3 -3.2a4.2 4.2 0 0 0 -.1 -3.2s-1.1 -.3 -3.5 1.3a12.3 12.3 0 0 0 -6.2 0c-2.4 -1.6 -3.5 -1.3 -3.5 -1.3a4.2 4.2 0 0 0 -.1 3.2a4.6 4.6 0 0 0 -1.3 3.2c0 4.6 2.7 5.7 5.5 6c-.6 .6 -.6 1.2 -.5 2v3.5" }]), s = this._createLink("https://code.textmode.art/docs/support", "Support textmode.export.js", b.supportIcon, [{ d: "M0 0h24v24H0z", fill: "none", stroke: "none" }, { d: "M3 14c.83 .642 2.077 1.017 3.5 1c1.423 .017 2.67 -.358 3.5 -1c.83 -.642 2.077 -1.017 3.5 -1c1.423 -.017 2.67 .358 3.5 1" }, { d: "M8 3a2.4 2.4 0 0 0 -1 2a2.4 2.4 0 0 0 1 2" }, { d: "M12 3a2.4 2.4 0 0 0 -1 2a2.4 2.4 0 0 0 1 2" }, { d: "M3 10h14v5a6 6 0 0 1 -6 6h-2a6 6 0 0 1 -6 -6v-5z" }, { d: "M16.746 16.726a3 3 0 1 0 .252 -5.555" }]);
1054
+ a.appendChild(o), a.appendChild(s), t.appendChild(e), t.appendChild(a);
1055
+ const d = document.createElement("div");
1056
+ return d.classList.add(b.divider), r.appendChild(t), r.appendChild(d), r;
1057
+ }
1058
+ _createLink(r, t, e, a) {
1059
+ const o = document.createElement("a");
1060
+ return o.href = r, o.target = "_blank", o.rel = "noopener noreferrer", o.classList.add(b.supportLink), o.setAttribute("aria-label", t), o.appendChild(this._createIcon(e, a)), o;
1061
+ }
1062
+ _createIcon(r, t) {
1063
+ const e = document.createElementNS(q._iconNamespace, "svg");
1064
+ e.setAttribute("xmlns", q._iconNamespace), e.setAttribute("width", "18"), e.setAttribute("height", "18"), e.setAttribute("viewBox", "0 0 24 24"), e.setAttribute("fill", "none"), e.setAttribute("stroke", "currentColor"), e.setAttribute("stroke-width", "2"), e.setAttribute("stroke-linecap", "round"), e.setAttribute("stroke-linejoin", "round"), e.classList.add(r);
1065
+ for (const a of t) {
1066
+ const o = document.createElementNS(q._iconNamespace, "path");
1067
+ for (const [s, d] of Object.entries(a)) o.setAttribute(s, d);
1068
+ e.appendChild(o);
1008
1069
  }
1009
- return r;
1070
+ return e;
1010
1071
  }
1011
- }
1012
- class P extends O {
1013
- props;
1072
+ };
1073
+ p(q, "_iconNamespace", "http://www.w3.org/2000/svg");
1074
+ let gt = q;
1075
+ class O extends T {
1014
1076
  constructor(t) {
1015
- super(), this.props = t;
1077
+ super();
1078
+ p(this, "props");
1079
+ this.props = t;
1016
1080
  }
1017
1081
  render() {
1018
1082
  const t = document.createElement("div");
1019
1083
  t.classList.add(b.field), this.applyVariant(t, this.props.variant);
1020
1084
  const e = document.createElement("label");
1021
1085
  if (e.classList.add(b.label), e.textContent = this.props.label, this.props.labelFor && (e.htmlFor = this.props.labelFor), t.appendChild(e), this.props.description) {
1022
- const r = document.createElement("span");
1023
- r.classList.add(b.muted), r.textContent = this.props.description, t.appendChild(r);
1086
+ const a = document.createElement("span");
1087
+ a.classList.add(b.muted), a.textContent = this.props.description, t.appendChild(a);
1024
1088
  }
1025
1089
  return t;
1026
1090
  }
@@ -1034,10 +1098,10 @@ class P extends O {
1034
1098
  const e = this.root;
1035
1099
  for (; e.firstChild; ) e.removeChild(e.firstChild);
1036
1100
  this.props = t, e.classList.add(b.field), this.applyVariant(e, t.variant);
1037
- const r = document.createElement("label");
1038
- if (r.classList.add(b.label), r.textContent = t.label, t.labelFor && (r.htmlFor = t.labelFor), e.appendChild(r), t.description) {
1039
- const a = document.createElement("span");
1040
- a.classList.add(b.muted), a.textContent = t.description, e.appendChild(a);
1101
+ const a = document.createElement("label");
1102
+ if (a.classList.add(b.label), a.textContent = t.label, t.labelFor && (a.htmlFor = t.labelFor), e.appendChild(a), t.description) {
1103
+ const o = document.createElement("span");
1104
+ o.classList.add(b.muted), o.textContent = t.description, e.appendChild(o);
1041
1105
  }
1042
1106
  }
1043
1107
  applyVariant(t, e) {
@@ -1056,14 +1120,15 @@ class P extends O {
1056
1120
  }
1057
1121
  }
1058
1122
  }
1059
- class mt extends O {
1060
- props;
1061
- select;
1062
- handleChange = () => {
1063
- this.props.defaultValue = this.select.value;
1064
- };
1123
+ class st extends T {
1065
1124
  constructor(t) {
1066
- super(), this.props = t;
1125
+ super();
1126
+ p(this, "props");
1127
+ p(this, "select");
1128
+ p(this, "handleChange", () => {
1129
+ this.props.defaultValue = this.select.value;
1130
+ });
1131
+ this.props = t;
1067
1132
  }
1068
1133
  render() {
1069
1134
  return this.select = document.createElement("select"), this.select.classList.add(b.input), this.props.id && (this.select.id = this.props.id), this.populateOptions(), this.select.addEventListener("change", this.handleChange), this.select;
@@ -1097,11 +1162,12 @@ class mt extends O {
1097
1162
  }
1098
1163
  }
1099
1164
  }
1100
- class Lt extends O {
1101
- props;
1102
- button;
1165
+ class Vt extends T {
1103
1166
  constructor(t) {
1104
- super(), this.props = t;
1167
+ super();
1168
+ p(this, "props");
1169
+ p(this, "button");
1170
+ this.props = t;
1105
1171
  }
1106
1172
  render() {
1107
1173
  return this.button = document.createElement("button"), this.button.type = "button", this.button.textContent = this.props.label, this.button.classList.add(b.button), this.props.variant === "secondary" ? this.button.classList.add(b.buttonSecondary) : this.button.classList.add(b.buttonPrimary), this.props.fullWidth && this.button.classList.add(b.buttonFull), this.button.disabled = !!this.props.disabled, this.button;
@@ -1119,77 +1185,86 @@ class Lt extends O {
1119
1185
  this.props = t, this.button.textContent = t.label, this.button.disabled = !!t.disabled, t.variant === "secondary" ? (this.button.classList.add(b.buttonSecondary), this.button.classList.remove(b.buttonPrimary)) : (this.button.classList.add(b.buttonPrimary), this.button.classList.remove(b.buttonSecondary)), this.button.classList.toggle(b.buttonFull, !!t.fullWidth);
1120
1186
  }
1121
1187
  }
1122
- class ke {
1123
- api;
1124
- constructor(t) {
1125
- this.api = t;
1188
+ class Oe {
1189
+ constructor(r) {
1190
+ p(this, "api");
1191
+ this.api = r;
1126
1192
  }
1127
- async $copy(t, e) {
1128
- switch (t) {
1193
+ async $copy(r, t) {
1194
+ switch (r) {
1129
1195
  case "txt": {
1130
- const r = this.api.toString(e);
1131
- await navigator.clipboard.writeText(r);
1196
+ const e = this.api.toString(t);
1197
+ await navigator.clipboard.writeText(e);
1198
+ break;
1199
+ }
1200
+ case "json": {
1201
+ const e = this.api.toJSONString(t);
1202
+ await navigator.clipboard.writeText(e);
1132
1203
  break;
1133
1204
  }
1134
1205
  case "svg": {
1135
- const r = this.api.toSVG(e);
1136
- await navigator.clipboard.writeText(r);
1206
+ const e = this.api.toSVG(t);
1207
+ await navigator.clipboard.writeText(e);
1137
1208
  break;
1138
1209
  }
1139
1210
  case "image":
1140
- await this.api.copyCanvas(e);
1211
+ await this.api.copyCanvas(t);
1141
1212
  break;
1142
1213
  default:
1143
- throw new Error(`Clipboard not supported for ${t}`);
1214
+ throw new Error(`Clipboard not supported for ${r}`);
1144
1215
  }
1145
1216
  }
1146
1217
  }
1147
- class Be {
1148
- api;
1149
- events;
1150
- constructor(t, e) {
1151
- this.api = t, this.events = e;
1218
+ class De {
1219
+ constructor(r, t) {
1220
+ p(this, "api");
1221
+ p(this, "events");
1222
+ this.api = r, this.events = t;
1152
1223
  }
1153
- async $requestExport(t, e, r = {}) {
1154
- this.events.$emit("export:request", { format: t });
1224
+ async $requestExport(r, t, e = {}) {
1225
+ this.events.$emit("export:request", { format: r });
1155
1226
  try {
1156
- const a = { onGIFProgress: r.onGIFProgress ? (i) => {
1157
- r.onGIFProgress?.(i), this.events.$emit("export:progress", { format: t, progress: i });
1158
- } : t === "gif" ? (i) => this.events.$emit("export:progress", { format: t, progress: i }) : void 0, onVideoProgress: r.onVideoProgress ? (i) => {
1159
- r.onVideoProgress?.(i), this.events.$emit("export:progress", { format: t, progress: i });
1160
- } : t === "video" ? (i) => this.events.$emit("export:progress", { format: t, progress: i }) : void 0 };
1161
- await this._execute(t, e, a), this.events.$emit("export:success", { format: t });
1227
+ const a = { onGIFProgress: e.onGIFProgress ? (o) => {
1228
+ var s;
1229
+ (s = e.onGIFProgress) == null || s.call(e, o), this.events.$emit("export:progress", { format: r, progress: o });
1230
+ } : r === "gif" ? (o) => this.events.$emit("export:progress", { format: r, progress: o }) : void 0, onVideoProgress: e.onVideoProgress ? (o) => {
1231
+ var s;
1232
+ (s = e.onVideoProgress) == null || s.call(e, o), this.events.$emit("export:progress", { format: r, progress: o });
1233
+ } : r === "video" ? (o) => this.events.$emit("export:progress", { format: r, progress: o }) : void 0 };
1234
+ await this._execute(r, t, a), this.events.$emit("export:success", { format: r });
1162
1235
  } catch (a) {
1163
- throw this.events.$emit("export:error", { format: t, error: a }), a;
1236
+ throw this.events.$emit("export:error", { format: r, error: a }), a;
1164
1237
  }
1165
1238
  }
1166
- _execute(t, e, r) {
1167
- switch (t) {
1239
+ _execute(r, t, e) {
1240
+ switch (r) {
1168
1241
  case "txt":
1169
- return Promise.resolve(this.api.saveStrings(e));
1242
+ return Promise.resolve(this.api.saveStrings(t));
1243
+ case "json":
1244
+ return Promise.resolve(this.api.saveJSON(t));
1170
1245
  case "image":
1171
- return this.api.saveCanvas(e);
1246
+ return this.api.saveCanvas(t);
1172
1247
  case "svg":
1173
- return Promise.resolve(this.api.saveSVG(e));
1248
+ return Promise.resolve(this.api.saveSVG(t));
1174
1249
  case "gif": {
1175
- const a = { ...e, onProgress: r.onGIFProgress };
1250
+ const a = { ...t, onProgress: e.onGIFProgress };
1176
1251
  return this.api.saveGIF(a);
1177
1252
  }
1178
1253
  case "video": {
1179
- const a = { ...e, onProgress: r.onVideoProgress };
1254
+ const a = { ...t, onProgress: e.onVideoProgress };
1180
1255
  return this.api.saveWEBM(a);
1181
1256
  }
1182
1257
  }
1183
1258
  }
1184
1259
  }
1185
- class Ie {
1186
- modifier;
1187
- overlay;
1188
- animationFrameId = null;
1189
- handleUpdate;
1190
- bound = !1;
1191
- constructor(t, e) {
1192
- this.modifier = t, this.overlay = e, this.handleUpdate = () => this.scheduleUpdate();
1260
+ class Ve {
1261
+ constructor(r, t) {
1262
+ p(this, "modifier");
1263
+ p(this, "overlay");
1264
+ p(this, "animationFrameId", null);
1265
+ p(this, "handleUpdate");
1266
+ p(this, "bound", !1);
1267
+ this.modifier = r, this.overlay = t, this.handleUpdate = () => this.scheduleUpdate();
1193
1268
  }
1194
1269
  scheduleUpdate() {
1195
1270
  this.animationFrameId !== null && cancelAnimationFrame(this.animationFrameId), this.animationFrameId = requestAnimationFrame(() => this.update());
@@ -1199,38 +1274,39 @@ class Ie {
1199
1274
  }
1200
1275
  update() {
1201
1276
  this.animationFrameId = null;
1202
- const t = this.modifier.canvas.getBoundingClientRect();
1203
- this.overlay.style.top = `${t.top + window.scrollY + 8}px`, this.overlay.style.left = `${t.left + window.scrollX + 8}px`;
1277
+ const r = this.modifier.canvas.getBoundingClientRect();
1278
+ this.overlay.style.top = `${r.top + window.scrollY + 8}px`, this.overlay.style.left = `${r.left + window.scrollX + 8}px`;
1204
1279
  }
1205
1280
  dispose() {
1206
1281
  this.animationFrameId !== null && (cancelAnimationFrame(this.animationFrameId), this.animationFrameId = null), this.bound && (window.removeEventListener("resize", this.handleUpdate), window.removeEventListener("scroll", this.handleUpdate, !0), this.bound = !1);
1207
1282
  }
1208
1283
  }
1209
- const X = "textmode-export-number-input", Se = `${X}__field`, Fe = `${X}__controls`, Le = `${X}__control`, Ut = `${X}__display`, et = `${Ut}--visible`, Me = (n) => {
1210
- n.dispatchEvent(new Event("input", { bubbles: !0 })), n.dispatchEvent(new Event("change", { bubbles: !0 }));
1211
- }, Mt = (n) => {
1212
- const t = document.createElement("button");
1213
- return t.type = "button", t.className = Le, t.textContent = n > 0 ? "▲" : "▼", t;
1284
+ const Q = "textmode-export-number-input", Te = `${Q}__field`, Re = `${Q}__controls`, Ne = `${Q}__control`, qt = `${Q}__display`, rt = `${qt}--visible`, Ue = (i) => {
1285
+ i.dispatchEvent(new Event("input", { bubbles: !0 })), i.dispatchEvent(new Event("change", { bubbles: !0 }));
1286
+ }, Tt = (i) => {
1287
+ const r = document.createElement("button");
1288
+ return r.type = "button", r.className = Ne, r.textContent = i > 0 ? "▲" : "▼", r;
1214
1289
  };
1215
- class G extends O {
1216
- props;
1217
- input;
1218
- display;
1219
- incrementButton;
1220
- decrementButton;
1221
- suppressClickAfterPointer = /* @__PURE__ */ new WeakMap();
1222
- holdTimeoutId;
1223
- holdIntervalId;
1224
- activePointerId;
1225
- disabledObserver;
1290
+ class z extends T {
1226
1291
  constructor(t) {
1227
- super(), this.props = t;
1292
+ super();
1293
+ p(this, "props");
1294
+ p(this, "input");
1295
+ p(this, "display");
1296
+ p(this, "incrementButton");
1297
+ p(this, "decrementButton");
1298
+ p(this, "suppressClickAfterPointer", /* @__PURE__ */ new WeakMap());
1299
+ p(this, "holdTimeoutId");
1300
+ p(this, "holdIntervalId");
1301
+ p(this, "activePointerId");
1302
+ p(this, "disabledObserver");
1303
+ this.props = t;
1228
1304
  }
1229
1305
  render() {
1230
1306
  const t = document.createElement("div");
1231
- t.className = X, this.input = document.createElement("input"), this.input.type = "number", this.input.value = this.props.defaultValue, Object.assign(this.input, this.props.attributes), this.input.className = Se, this.display = document.createElement("div"), this.display.className = Ut;
1307
+ t.className = Q, this.input = document.createElement("input"), this.input.type = "number", this.input.value = this.props.defaultValue, Object.assign(this.input, this.props.attributes), this.input.className = Te, this.display = document.createElement("div"), this.display.className = qt;
1232
1308
  const e = document.createElement("div");
1233
- return e.className = Fe, this.incrementButton = Mt(1), this.decrementButton = Mt(-1), e.appendChild(this.incrementButton), e.appendChild(this.decrementButton), t.appendChild(this.input), t.appendChild(this.display), t.appendChild(e), this.bindStepControls(), this.bindHoldBehavior(), this.bindInputListeners(), this.observeDisabledState(t), this.updateDisplay(), t;
1309
+ return e.className = Re, this.incrementButton = Tt(1), this.decrementButton = Tt(-1), e.appendChild(this.incrementButton), e.appendChild(this.decrementButton), t.appendChild(this.input), t.appendChild(this.display), t.appendChild(e), this.bindStepControls(), this.bindHoldBehavior(), this.bindInputListeners(), this.observeDisabledState(t), this.updateDisplay(), t;
1234
1310
  }
1235
1311
  get inputElement() {
1236
1312
  return this.input;
@@ -1245,27 +1321,28 @@ class G extends O {
1245
1321
  this.updateDisplay();
1246
1322
  }
1247
1323
  _onDestroy() {
1248
- this.clearHoldTimers(), this.disabledObserver?.disconnect();
1324
+ var t;
1325
+ this.clearHoldTimers(), (t = this.disabledObserver) == null || t.disconnect();
1249
1326
  }
1250
1327
  bindStepControls() {
1251
- const t = (i) => () => {
1328
+ const t = (s) => () => {
1252
1329
  if (this.input.disabled) return;
1253
- const s = this.input.value, l = this.input.getAttribute("step");
1254
- if (l && l !== "any") i > 0 ? this.input.stepUp() : this.input.stepDown();
1330
+ const d = this.input.value, l = this.input.getAttribute("step");
1331
+ if (l && l !== "any") s > 0 ? this.input.stepUp() : this.input.stepDown();
1255
1332
  else {
1256
- const d = i > 0 ? 1 : -1, p = Number.parseFloat(this.input.value || "0"), o = Number.isFinite(p) ? p + d : d;
1257
- this.input.value = String(o);
1333
+ const h = s > 0 ? 1 : -1, n = Number.parseFloat(this.input.value || "0"), c = Number.isFinite(n) ? n + h : h;
1334
+ this.input.value = String(c);
1258
1335
  }
1259
- this.input.value !== s && Me(this.input), this.updateDisplay(), this.input.focus({ preventScroll: !0 });
1260
- }, e = t(1), r = t(-1), a = (i, s) => (l) => {
1261
- if (this.suppressClickAfterPointer.get(i)) return this.suppressClickAfterPointer.set(i, !1), void l.preventDefault();
1262
- s();
1336
+ this.input.value !== d && Ue(this.input), this.updateDisplay(), this.input.focus({ preventScroll: !0 });
1337
+ }, e = t(1), a = t(-1), o = (s, d) => (l) => {
1338
+ if (this.suppressClickAfterPointer.get(s)) return this.suppressClickAfterPointer.set(s, !1), void l.preventDefault();
1339
+ d();
1263
1340
  };
1264
- this.incrementButton.addEventListener("click", a(this.incrementButton, e)), this.decrementButton.addEventListener("click", a(this.decrementButton, r));
1341
+ this.incrementButton.addEventListener("click", o(this.incrementButton, e)), this.decrementButton.addEventListener("click", o(this.decrementButton, a));
1265
1342
  }
1266
1343
  bindHoldBehavior() {
1267
- const t = (e, r) => {
1268
- const a = r > 0 ? () => this.incrementButton.click() : () => this.decrementButton.click();
1344
+ const t = (e, a) => {
1345
+ const o = a > 0 ? () => this.incrementButton.click() : () => this.decrementButton.click();
1269
1346
  e.addEventListener("pointerdown", (l) => {
1270
1347
  if (l.button === 0) {
1271
1348
  l.preventDefault(), this.suppressClickAfterPointer.set(e, !0), this.activePointerId = l.pointerId;
@@ -1273,12 +1350,12 @@ class G extends O {
1273
1350
  e.setPointerCapture(l.pointerId);
1274
1351
  } catch {
1275
1352
  }
1276
- a(), this.holdTimeoutId = window.setTimeout(() => {
1277
- this.holdIntervalId = window.setInterval(a, 80);
1353
+ o(), this.holdTimeoutId = window.setTimeout(() => {
1354
+ this.holdIntervalId = window.setInterval(o, 80);
1278
1355
  }, 380);
1279
1356
  }
1280
1357
  });
1281
- const i = () => {
1358
+ const s = () => {
1282
1359
  if (this.activePointerId !== void 0) {
1283
1360
  try {
1284
1361
  e.releasePointerCapture(this.activePointerId);
@@ -1286,10 +1363,10 @@ class G extends O {
1286
1363
  }
1287
1364
  this.activePointerId = void 0;
1288
1365
  }
1289
- }, s = () => {
1290
- this.clearHoldTimers(), i();
1366
+ }, d = () => {
1367
+ this.clearHoldTimers(), s();
1291
1368
  };
1292
- e.addEventListener("pointerup", s), e.addEventListener("pointerleave", s), e.addEventListener("pointercancel", s);
1369
+ e.addEventListener("pointerup", d), e.addEventListener("pointerleave", d), e.addEventListener("pointercancel", d);
1293
1370
  };
1294
1371
  t(this.incrementButton, 1), t(this.decrementButton, -1);
1295
1372
  }
@@ -1301,39 +1378,41 @@ class G extends O {
1301
1378
  }
1302
1379
  observeDisabledState(t) {
1303
1380
  const e = () => {
1304
- const r = this.input.disabled;
1305
- this.incrementButton.disabled = r, this.decrementButton.disabled = r, t.classList.toggle("is-disabled", r), r ? (this.display.classList.remove(et), this.input.style.removeProperty("color"), this.input.style.removeProperty("caretColor")) : this.updateDisplay();
1381
+ const a = this.input.disabled;
1382
+ this.incrementButton.disabled = a, this.decrementButton.disabled = a, t.classList.toggle("is-disabled", a), a ? (this.display.classList.remove(rt), this.input.style.removeProperty("color"), this.input.style.removeProperty("caretColor")) : this.updateDisplay();
1306
1383
  };
1307
1384
  typeof MutationObserver < "u" && (this.disabledObserver = new MutationObserver(e), this.disabledObserver.observe(this.input, { attributes: !0, attributeFilter: ["disabled"] })), e();
1308
1385
  }
1309
1386
  updateDisplay() {
1310
1387
  const t = this.props.formatDisplay;
1311
- if (!t) return this.display.textContent = "", this.display.classList.remove(et), this.input.style.removeProperty("color"), void this.input.style.removeProperty("caretColor");
1312
- const e = this.input.value, r = Number.parseFloat(e), a = t(Number.isFinite(r) ? r : Number.NaN, e, this.input);
1313
- a ? (this.display.textContent = a, this.display.classList.add(et), this.input.style.color = "transparent", this.input.style.caretColor = "#f8fafc") : (this.display.textContent = "", this.display.classList.remove(et), this.input.style.removeProperty("color"), this.input.style.removeProperty("caretColor"));
1388
+ if (!t) return this.display.textContent = "", this.display.classList.remove(rt), this.input.style.removeProperty("color"), void this.input.style.removeProperty("caretColor");
1389
+ const e = this.input.value, a = Number.parseFloat(e), o = t(Number.isFinite(a) ? a : Number.NaN, e, this.input);
1390
+ o ? (this.display.textContent = o, this.display.classList.add(rt), this.input.style.color = "transparent", this.input.style.caretColor = "#f8fafc") : (this.display.textContent = "", this.display.classList.remove(rt), this.input.style.removeProperty("color"), this.input.style.removeProperty("caretColor"));
1314
1391
  }
1315
1392
  clearHoldTimers() {
1316
1393
  this.holdTimeoutId !== void 0 && (window.clearTimeout(this.holdTimeoutId), this.holdTimeoutId = void 0), this.holdIntervalId !== void 0 && (window.clearInterval(this.holdIntervalId), this.holdIntervalId = void 0);
1317
1394
  }
1318
1395
  }
1319
- class j extends O {
1320
- variant;
1321
- additionalClasses;
1396
+ class Y extends T {
1322
1397
  constructor(t = "stack", e = []) {
1323
- super(), this.variant = t, this.additionalClasses = e;
1398
+ super();
1399
+ p(this, "variant");
1400
+ p(this, "additionalClasses");
1401
+ this.variant = t, this.additionalClasses = e;
1324
1402
  }
1325
1403
  render() {
1326
1404
  const t = document.createElement("div"), e = [this.variant === "stack" ? b.stack : void 0, this.variant === "stackDense" ? b.stackDense : void 0, this.variant === "stackCompact" ? b.stackCompact : void 0, this.variant === "row" ? b.row : void 0, this.variant === "section" ? b.section : void 0, ...this.additionalClasses].filter(Boolean);
1327
1405
  return t.classList.add(...e), t;
1328
1406
  }
1329
1407
  }
1330
- const $t = { neutral: "textmode-export-overlay__status-value--neutral", active: "textmode-export-overlay__status-value--active", alert: "textmode-export-overlay__status-value--alert" };
1331
- class Nt extends O {
1332
- props;
1333
- container;
1334
- messageElement;
1408
+ const Rt = { neutral: "textmode-export-overlay__status-value--neutral", active: "textmode-export-overlay__status-value--active", alert: "textmode-export-overlay__status-value--alert" };
1409
+ class Ht extends T {
1335
1410
  constructor(t) {
1336
- super(), this.props = t;
1411
+ super();
1412
+ p(this, "props");
1413
+ p(this, "container");
1414
+ p(this, "messageElement");
1415
+ this.props = t;
1337
1416
  }
1338
1417
  render() {
1339
1418
  this.container = document.createElement("div"), this.container.classList.add(b.status), this.props.context === "gif" ? this.container.classList.add(b.statusGif) : this.props.context === "video" && this.container.classList.add(b.statusVideo);
@@ -1347,14 +1426,15 @@ class Nt extends O {
1347
1426
  this.props = t, this.setMessage(t.message, t.variant ?? "neutral");
1348
1427
  }
1349
1428
  applyVariant(t) {
1350
- this.messageElement.classList.remove(...Object.values($t)), this.messageElement.classList.add($t[t]);
1429
+ this.messageElement.classList.remove(...Object.values(Rt)), this.messageElement.classList.add(Rt[t]);
1351
1430
  }
1352
1431
  }
1353
- class Y extends O {
1354
- _config;
1355
- _managedComponents = /* @__PURE__ */ new Set();
1432
+ class J extends T {
1356
1433
  constructor(t) {
1357
- super(), this._config = t;
1434
+ super();
1435
+ p(this, "_config");
1436
+ p(this, "_managedComponents", /* @__PURE__ */ new Set());
1437
+ this._config = t;
1358
1438
  }
1359
1439
  _manageComponent(t) {
1360
1440
  return this._managedComponents.add(t), t;
@@ -1367,32 +1447,32 @@ class Y extends O {
1367
1447
  this._managedComponents.clear();
1368
1448
  }
1369
1449
  }
1370
- const z = { frameCount: 300, frameRate: 60, scale: 1, repeat: 0 };
1371
- class ut extends Y {
1372
- frameCountInput = this._manageComponent(new G({ defaultValue: String(z.frameCount), attributes: { min: "1", max: "600", step: "1" } }));
1373
- frameRateInput = this._manageComponent(new G({ defaultValue: String(z.frameRate), attributes: { min: "1", max: "60", step: "1" } }));
1374
- scaleInput = this._manageComponent(new G({ defaultValue: String(z.scale), attributes: { min: "0.1", max: "8", step: "0.1" } }));
1375
- repeatInput = this._manageComponent(new G({ defaultValue: "0", attributes: { min: "0", max: "50", step: "1" }, formatDisplay: (t, e) => Number.isFinite(t) ? t === 0 ? "∞" : null : e.trim() === "" ? null : e }));
1376
- status = this._manageComponent(new Nt({ title: "status", message: "ready to record", variant: "neutral", context: "gif" }));
1377
- recordingState = "idle";
1450
+ const W = { frameCount: 300, frameRate: 60, scale: 1, repeat: 0 };
1451
+ class bt extends J {
1378
1452
  constructor(t) {
1379
1453
  super(t);
1454
+ p(this, "frameCountInput", this._manageComponent(new z({ defaultValue: String(W.frameCount), attributes: { min: "1", max: "600", step: "1" } })));
1455
+ p(this, "frameRateInput", this._manageComponent(new z({ defaultValue: String(W.frameRate), attributes: { min: "1", max: "60", step: "1" } })));
1456
+ p(this, "scaleInput", this._manageComponent(new z({ defaultValue: String(W.scale), attributes: { min: "0.1", max: "8", step: "0.1" } })));
1457
+ p(this, "repeatInput", this._manageComponent(new z({ defaultValue: "0", attributes: { min: "0", max: "50", step: "1" }, formatDisplay: (t, e) => Number.isFinite(t) ? t === 0 ? "∞" : null : e.trim() === "" ? null : e })));
1458
+ p(this, "status", this._manageComponent(new Ht({ title: "status", message: "ready to record", variant: "neutral", context: "gif" })));
1459
+ p(this, "recordingState", "idle");
1380
1460
  }
1381
1461
  render() {
1382
1462
  const t = document.createElement("div");
1383
1463
  t.classList.add(b.stack);
1384
- const e = new j("row");
1464
+ const e = new Y("row");
1385
1465
  e.mount(t);
1386
- const r = new P({ label: "number of frames", labelFor: "textmode-export-gif-frame-count", variant: "dense" });
1387
- r.mount(e.root), this.frameCountInput.mount(r.root), this.frameCountInput.inputElement.id = "textmode-export-gif-frame-count";
1388
- const a = new P({ label: "frame rate (fps)", labelFor: "textmode-export-gif-frame-rate", variant: "dense" });
1389
- a.mount(e.root), this.frameRateInput.mount(a.root), this.frameRateInput.inputElement.id = "textmode-export-gif-frame-rate";
1390
- const i = new j("row");
1391
- i.mount(t);
1392
- const s = new P({ label: "scale", labelFor: "textmode-export-gif-scale", variant: "dense" });
1393
- s.mount(i.root), this.scaleInput.mount(s.root), this.scaleInput.inputElement.id = "textmode-export-gif-scale";
1394
- const l = new P({ label: "loop count", labelFor: "textmode-export-gif-repeat", variant: "dense" });
1395
- return l.mount(i.root), this.repeatInput.mount(l.root), this.repeatInput.inputElement.id = "textmode-export-gif-repeat", this.status.mount(t), t;
1466
+ const a = new O({ label: "number of frames", labelFor: "textmode-export-gif-frame-count", variant: "dense" });
1467
+ a.mount(e.root), this.frameCountInput.mount(a.root), this.frameCountInput.inputElement.id = "textmode-export-gif-frame-count";
1468
+ const o = new O({ label: "frame rate (fps)", labelFor: "textmode-export-gif-frame-rate", variant: "dense" });
1469
+ o.mount(e.root), this.frameRateInput.mount(o.root), this.frameRateInput.inputElement.id = "textmode-export-gif-frame-rate";
1470
+ const s = new Y("row");
1471
+ s.mount(t);
1472
+ const d = new O({ label: "scale", labelFor: "textmode-export-gif-scale", variant: "dense" });
1473
+ d.mount(s.root), this.scaleInput.mount(d.root), this.scaleInput.inputElement.id = "textmode-export-gif-scale";
1474
+ const l = new O({ label: "loop count", labelFor: "textmode-export-gif-repeat", variant: "dense" });
1475
+ return l.mount(s.root), this.repeatInput.mount(l.root), this.repeatInput.inputElement.id = "textmode-export-gif-repeat", this.status.mount(t), t;
1396
1476
  }
1397
1477
  getOptions() {
1398
1478
  const t = this._config.defaultOptions ?? {};
@@ -1402,33 +1482,33 @@ class ut extends Y {
1402
1482
  this.recordingState = "idle", this.applyDefaults(), this.setRecordingState("idle");
1403
1483
  }
1404
1484
  validate() {
1405
- const t = Number.parseInt(this.frameCountInput.value, 10), e = Number.parseInt(this.frameRateInput.value, 10), r = Number.parseFloat(this.scaleInput.value);
1406
- return Number.isFinite(t) && t > 0 && Number.isFinite(e) && e > 0 && Number.isFinite(r) && r > 0;
1485
+ const t = Number.parseInt(this.frameCountInput.value, 10), e = Number.parseInt(this.frameRateInput.value, 10), a = Number.parseFloat(this.scaleInput.value);
1486
+ return Number.isFinite(t) && t > 0 && Number.isFinite(e) && e > 0 && Number.isFinite(a) && a > 0;
1407
1487
  }
1408
1488
  isRecording() {
1409
1489
  return this.recordingState === "recording" || this.recordingState === "encoding";
1410
1490
  }
1411
1491
  setRecordingState(t, e) {
1412
1492
  this.recordingState = t;
1413
- const r = t === "recording" || t === "encoding";
1414
- switch (this.frameCountInput.inputElement.disabled = r, this.frameRateInput.inputElement.disabled = r, this.scaleInput.inputElement.disabled = r, this.repeatInput.inputElement.disabled = r, t) {
1493
+ const a = t === "recording" || t === "encoding";
1494
+ switch (this.frameCountInput.inputElement.disabled = a, this.frameRateInput.inputElement.disabled = a, this.scaleInput.inputElement.disabled = a, this.repeatInput.inputElement.disabled = a, t) {
1415
1495
  case "recording":
1416
- if (e?.totalFrames) {
1417
- const a = e.frameIndex ?? 0;
1418
- this.status.setMessage(`recording ${a}/${e.totalFrames}`, "active");
1496
+ if (e != null && e.totalFrames) {
1497
+ const o = e.frameIndex ?? 0;
1498
+ this.status.setMessage(`recording ${o}/${e.totalFrames}`, "active");
1419
1499
  } else this.status.setMessage("recording…", "active");
1420
1500
  break;
1421
1501
  case "encoding":
1422
- if (e?.totalFrames) {
1423
- const a = e.frameIndex ?? 0;
1424
- this.status.setMessage(`encoding ${a}/${e.totalFrames}`, "active");
1502
+ if (e != null && e.totalFrames) {
1503
+ const o = e.frameIndex ?? 0;
1504
+ this.status.setMessage(`encoding ${o}/${e.totalFrames}`, "active");
1425
1505
  } else this.status.setMessage("encoding…", "active");
1426
1506
  break;
1427
1507
  case "completed":
1428
1508
  this.status.setMessage("GIF saved successfully", "active");
1429
1509
  break;
1430
1510
  case "error":
1431
- this.status.setMessage(e?.message ?? "failed to export GIF", "alert");
1511
+ this.status.setMessage((e == null ? void 0 : e.message) ?? "failed to export GIF", "alert");
1432
1512
  break;
1433
1513
  default:
1434
1514
  this.status.setMessage("ready to record", "neutral");
@@ -1442,40 +1522,41 @@ class ut extends Y {
1442
1522
  }
1443
1523
  }
1444
1524
  applyDefaults() {
1445
- const t = this._config.defaultOptions ?? {}, e = t.frameCount ?? z.frameCount, r = t.frameRate ?? z.frameRate, a = t.scale ?? z.scale, i = t.repeat ?? z.repeat;
1446
- this.frameCountInput.value = String(e), this.frameRateInput.value = String(r), this.scaleInput.value = String(a), this.repeatInput.value = String(i), this.frameCountInput.refresh(), this.frameRateInput.refresh(), this.scaleInput.refresh(), this.repeatInput.refresh();
1525
+ const t = this._config.defaultOptions ?? {}, e = t.frameCount ?? W.frameCount, a = t.frameRate ?? W.frameRate, o = t.scale ?? W.scale, s = t.repeat ?? W.repeat;
1526
+ this.frameCountInput.value = String(e), this.frameRateInput.value = String(a), this.scaleInput.value = String(o), this.repeatInput.value = String(s), this.frameCountInput.refresh(), this.frameRateInput.refresh(), this.scaleInput.refresh(), this.repeatInput.refresh();
1447
1527
  }
1448
1528
  safeParseInt(t, e) {
1449
- const r = Number.parseInt(t, 10);
1450
- return Number.isFinite(r) ? r : e;
1529
+ const a = Number.parseInt(t, 10);
1530
+ return Number.isFinite(a) ? a : e;
1451
1531
  }
1452
1532
  safeParseFloat(t, e) {
1453
- const r = Number.parseFloat(t);
1454
- return Number.isFinite(r) ? r : e;
1455
- }
1456
- }
1457
- const it = "textmode-export-range-input", $e = `${it}__field`, Ae = `${it}__tooltip`, ct = `${it}__tooltip--visible`, rt = (n, t) => {
1458
- if (typeof n != "string" || n.length === 0) return t;
1459
- const e = Number.parseFloat(n);
1460
- return Number.isFinite(e) ? e : t;
1461
- }, Pe = (n, t, e) => Math.min(e, Math.max(t, n));
1462
- class De extends O {
1463
- props;
1464
- input;
1465
- tooltip;
1466
- hoverActive = !1;
1467
- focusActive = !1;
1468
- pointerActive = !1;
1469
- suppressFocusFromPointer = !1;
1470
- activePointerId;
1471
- disabledObserver;
1472
- resizeObserver;
1533
+ const a = Number.parseFloat(t);
1534
+ return Number.isFinite(a) ? a : e;
1535
+ }
1536
+ }
1537
+ const lt = "textmode-export-range-input", Ge = `${lt}__field`, ze = `${lt}__tooltip`, ft = `${lt}__tooltip--visible`, at = (i, r) => {
1538
+ if (typeof i != "string" || i.length === 0) return r;
1539
+ const t = Number.parseFloat(i);
1540
+ return Number.isFinite(t) ? t : r;
1541
+ }, We = (i, r, t) => Math.min(t, Math.max(r, i));
1542
+ class je extends T {
1473
1543
  constructor(t) {
1474
- super(), this.props = t;
1544
+ super();
1545
+ p(this, "props");
1546
+ p(this, "input");
1547
+ p(this, "tooltip");
1548
+ p(this, "hoverActive", !1);
1549
+ p(this, "focusActive", !1);
1550
+ p(this, "pointerActive", !1);
1551
+ p(this, "suppressFocusFromPointer", !1);
1552
+ p(this, "activePointerId");
1553
+ p(this, "disabledObserver");
1554
+ p(this, "resizeObserver");
1555
+ this.props = t;
1475
1556
  }
1476
1557
  render() {
1477
1558
  const t = document.createElement("div");
1478
- return t.className = it, this.input = document.createElement("input"), this.input.type = "range", this.input.value = this.props.defaultValue, Object.assign(this.input, this.props.attributes), this.input.className = $e, this.tooltip = document.createElement("div"), this.tooltip.className = Ae, t.appendChild(this.input), t.appendChild(this.tooltip), this.bindEvents(t), this.updateTooltip(), this.syncDisabledState(t), t;
1559
+ return t.className = lt, this.input = document.createElement("input"), this.input.type = "range", this.input.value = this.props.defaultValue, Object.assign(this.input, this.props.attributes), this.input.className = Ge, this.tooltip = document.createElement("div"), this.tooltip.className = ze, t.appendChild(this.input), t.appendChild(this.tooltip), this.bindEvents(t), this.updateTooltip(), this.syncDisabledState(t), t;
1479
1560
  }
1480
1561
  get inputElement() {
1481
1562
  return this.input;
@@ -1487,7 +1568,8 @@ class De extends O {
1487
1568
  this.input.value = t, this.updateTooltip();
1488
1569
  }
1489
1570
  _onDestroy() {
1490
- this.disabledObserver?.disconnect(), this.resizeObserver?.disconnect();
1571
+ var t, e;
1572
+ (t = this.disabledObserver) == null || t.disconnect(), (e = this.resizeObserver) == null || e.disconnect();
1491
1573
  }
1492
1574
  bindEvents(t) {
1493
1575
  this.input.addEventListener("pointerenter", () => {
@@ -1495,19 +1577,19 @@ class De extends O {
1495
1577
  }), this.input.addEventListener("pointerleave", () => {
1496
1578
  this.hoverActive = !1, this.refreshTooltipVisibility();
1497
1579
  }), this.input.addEventListener("focus", () => {
1498
- let r = !1;
1580
+ let a = !1;
1499
1581
  try {
1500
- r = this.input.matches(":focus-visible");
1582
+ a = this.input.matches(":focus-visible");
1501
1583
  } catch {
1502
- r = !this.suppressFocusFromPointer;
1584
+ a = !this.suppressFocusFromPointer;
1503
1585
  }
1504
- this.suppressFocusFromPointer || !r || this.input.disabled ? this.focusActive = !1 : this.focusActive = !0, this.suppressFocusFromPointer = !1, this.refreshTooltipVisibility();
1586
+ this.suppressFocusFromPointer || !a || this.input.disabled ? this.focusActive = !1 : this.focusActive = !0, this.suppressFocusFromPointer = !1, this.refreshTooltipVisibility();
1505
1587
  }), this.input.addEventListener("blur", () => {
1506
1588
  this.focusActive = !1, this.refreshTooltipVisibility();
1507
- }), this.input.addEventListener("pointerdown", (r) => {
1589
+ }), this.input.addEventListener("pointerdown", (a) => {
1508
1590
  this.pointerActive = !0, this.suppressFocusFromPointer = !0, this.hoverActive = !0, this.refreshTooltipVisibility();
1509
1591
  try {
1510
- this.input.setPointerCapture(r.pointerId), this.activePointerId = r.pointerId;
1592
+ this.input.setPointerCapture(a.pointerId), this.activePointerId = a.pointerId;
1511
1593
  } catch {
1512
1594
  this.activePointerId = void 0;
1513
1595
  }
@@ -1520,17 +1602,17 @@ class De extends O {
1520
1602
  }), this.input.addEventListener("change", () => {
1521
1603
  this.pointerActive || this.updateTooltip(), this.props.defaultValue = this.input.value;
1522
1604
  }), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => {
1523
- this.tooltip.classList.contains(ct) && this.updateTooltipPosition();
1605
+ this.tooltip.classList.contains(ft) && this.updateTooltipPosition();
1524
1606
  }), this.resizeObserver.observe(t));
1525
1607
  }
1526
1608
  refreshTooltipVisibility() {
1527
1609
  const t = (this.hoverActive || this.focusActive || this.pointerActive) && !this.input.disabled;
1528
- t && this.updateTooltip(), this.tooltip.classList.toggle(ct, t);
1610
+ t && this.updateTooltip(), this.tooltip.classList.toggle(ft, t);
1529
1611
  }
1530
1612
  syncDisabledState(t) {
1531
1613
  const e = () => {
1532
- const r = this.input.disabled;
1533
- t.classList.toggle("is-disabled", r), r && (this.hoverActive = !1, this.focusActive = !1, this.pointerActive = !1, this.suppressFocusFromPointer = !1, this.releasePointerCapture(), this.tooltip.classList.remove(ct));
1614
+ const a = this.input.disabled;
1615
+ t.classList.toggle("is-disabled", a), a && (this.hoverActive = !1, this.focusActive = !1, this.pointerActive = !1, this.suppressFocusFromPointer = !1, this.releasePointerCapture(), this.tooltip.classList.remove(ft));
1534
1616
  };
1535
1617
  typeof MutationObserver < "u" && (this.disabledObserver = new MutationObserver(e), this.disabledObserver.observe(this.input, { attributes: !0, attributeFilter: ["disabled"] })), e();
1536
1618
  }
@@ -1547,55 +1629,55 @@ class De extends O {
1547
1629
  this.updateTooltipContent(), this.updateTooltipPosition();
1548
1630
  }
1549
1631
  updateTooltipContent() {
1550
- const t = this.props.formatValue ?? ((r) => `${r}`), e = this.getCurrentValue();
1632
+ const t = this.props.formatValue ?? ((a) => `${a}`), e = this.getCurrentValue();
1551
1633
  this.tooltip.textContent = t(e, this.input);
1552
1634
  }
1553
1635
  updateTooltipPosition() {
1554
- const t = this.getMin(), e = this.getMax(), r = Pe(this.getCurrentValue(), t, e), a = e - t, i = a === 0 ? 0 : (r - t) / a;
1555
- this.tooltip.style.left = 100 * i + "%";
1636
+ const t = this.getMin(), e = this.getMax(), a = We(this.getCurrentValue(), t, e), o = e - t, s = o === 0 ? 0 : (a - t) / o;
1637
+ this.tooltip.style.left = 100 * s + "%";
1556
1638
  }
1557
1639
  getMin() {
1558
- return rt(this.input.min, 0);
1640
+ return at(this.input.min, 0);
1559
1641
  }
1560
1642
  getMax() {
1561
- return rt(this.input.max, 100);
1643
+ return at(this.input.max, 100);
1562
1644
  }
1563
1645
  getCurrentValue() {
1564
- return rt(this.input.value, rt(this.props.defaultValue, 0));
1646
+ return at(this.input.value, at(this.props.defaultValue, 0));
1565
1647
  }
1566
1648
  }
1567
- function Ve(n) {
1568
- if (!Number.isFinite(n)) return "default quality";
1569
- const t = Math.max(0, Math.min(1, n));
1570
- return t >= 0.995 ? "near-lossless" : t >= 0.98 ? "maximum detail" : t >= 0.88 ? "ultra quality" : t >= 0.7 ? "high quality" : t >= 0.5 ? "balanced" : t >= 0.25 ? "compact" : t >= 0.1 ? "lightweight" : "draft";
1649
+ function qe(i) {
1650
+ if (!Number.isFinite(i)) return "default quality";
1651
+ const r = Math.max(0, Math.min(1, i));
1652
+ return r >= 0.995 ? "near-lossless" : r >= 0.98 ? "maximum detail" : r >= 0.88 ? "ultra quality" : r >= 0.7 ? "high quality" : r >= 0.5 ? "balanced" : r >= 0.25 ? "compact" : r >= 0.1 ? "lightweight" : "draft";
1571
1653
  }
1572
- function Oe(n) {
1573
- return `${Ve(n)} (quality ≈ ${n.toFixed(3)})`;
1654
+ function He(i) {
1655
+ return `${qe(i)} (quality ≈ ${i.toFixed(3)})`;
1574
1656
  }
1575
- class pt extends Y {
1576
- frameRateInput = this._manageComponent(new G({ defaultValue: String(60), attributes: { min: String(1), max: String(60), step: "1" }, formatDisplay: (t) => Number.isFinite(t) ? `${t} fps` : null }));
1577
- frameCountInput = this._manageComponent(new G({ defaultValue: String(480), attributes: { min: String(1), max: String(3600), step: "1" } }));
1578
- qualityInput = this._manageComponent(new De({ defaultValue: String(0.7), attributes: { min: String(0), max: String(1), step: "0.001" }, formatValue: (t) => Oe(t) }));
1579
- status = this._manageComponent(new Nt({ title: "status", message: "ready to record", variant: "neutral", context: "video" }));
1580
- recordingState = "idle";
1657
+ class vt extends J {
1581
1658
  constructor(t) {
1582
1659
  super(t);
1660
+ p(this, "frameRateInput", this._manageComponent(new z({ defaultValue: String(60), attributes: { min: String(1), max: String(60), step: "1" }, formatDisplay: (t) => Number.isFinite(t) ? `${t} fps` : null })));
1661
+ p(this, "frameCountInput", this._manageComponent(new z({ defaultValue: String(480), attributes: { min: String(1), max: String(3600), step: "1" } })));
1662
+ p(this, "qualityInput", this._manageComponent(new je({ defaultValue: String(0.7), attributes: { min: String(0), max: String(1), step: "0.001" }, formatValue: (t) => He(t) })));
1663
+ p(this, "status", this._manageComponent(new Ht({ title: "status", message: "ready to record", variant: "neutral", context: "video" })));
1664
+ p(this, "recordingState", "idle");
1583
1665
  }
1584
1666
  render() {
1585
1667
  const t = document.createElement("div");
1586
1668
  t.classList.add(b.stack);
1587
- const e = new j("row");
1669
+ const e = new Y("row");
1588
1670
  e.mount(t);
1589
- const r = new P({ label: "number of frames", labelFor: "textmode-export-video-frame-count", variant: "compact" });
1590
- r.mount(e.root), this.frameCountInput.mount(r.root), this.frameCountInput.inputElement.id = "textmode-export-video-frame-count";
1591
- const a = new P({ label: "frame rate (fps)", labelFor: "textmode-export-video-frame-rate", variant: "compact" });
1592
- a.mount(e.root), this.frameRateInput.mount(a.root), this.frameRateInput.inputElement.id = "textmode-export-video-frame-rate";
1593
- const i = new P({ label: "quality", labelFor: "textmode-export-video-quality", variant: "full" });
1594
- return i.mount(t), this.qualityInput.mount(i.root), this.qualityInput.inputElement.id = "textmode-export-video-quality", this.status.mount(t), t;
1671
+ const a = new O({ label: "number of frames", labelFor: "textmode-export-video-frame-count", variant: "compact" });
1672
+ a.mount(e.root), this.frameCountInput.mount(a.root), this.frameCountInput.inputElement.id = "textmode-export-video-frame-count";
1673
+ const o = new O({ label: "frame rate (fps)", labelFor: "textmode-export-video-frame-rate", variant: "compact" });
1674
+ o.mount(e.root), this.frameRateInput.mount(o.root), this.frameRateInput.inputElement.id = "textmode-export-video-frame-rate";
1675
+ const s = new O({ label: "quality", labelFor: "textmode-export-video-quality", variant: "full" });
1676
+ return s.mount(t), this.qualityInput.mount(s.root), this.qualityInput.inputElement.id = "textmode-export-video-quality", this.status.mount(t), t;
1595
1677
  }
1596
1678
  getOptions() {
1597
- const t = this._config.defaultOptions ?? {}, e = Number.parseInt(this.frameCountInput.value, 10), r = Number.parseFloat(this.frameRateInput.value), a = Number.parseFloat(this.qualityInput.value);
1598
- return { frameCount: Number.isFinite(e) ? e : t.frameCount ?? 480, frameRate: Number.isFinite(r) ? r : t.frameRate ?? 60, quality: Number.isFinite(a) ? a : t.quality ?? 0.7 };
1679
+ const t = this._config.defaultOptions ?? {}, e = Number.parseInt(this.frameCountInput.value, 10), a = Number.parseFloat(this.frameRateInput.value), o = Number.parseFloat(this.qualityInput.value);
1680
+ return { frameCount: Number.isFinite(e) ? e : t.frameCount ?? 480, frameRate: Number.isFinite(a) ? a : t.frameRate ?? 60, quality: Number.isFinite(o) ? o : t.quality ?? 0.7 };
1599
1681
  }
1600
1682
  reset() {
1601
1683
  this.recordingState = "idle", this.applyDefaults(), this.status.setMessage("ready to record", "neutral");
@@ -1609,8 +1691,8 @@ class pt extends Y {
1609
1691
  }
1610
1692
  setRecordingState(t, e) {
1611
1693
  this.recordingState = t;
1612
- const r = t === "recording";
1613
- this.frameCountInput.inputElement.disabled = r, this.frameRateInput.inputElement.disabled = r, this.qualityInput.inputElement.disabled = r, this.syncStatus(t, e);
1694
+ const a = t === "recording";
1695
+ this.frameCountInput.inputElement.disabled = a, this.frameRateInput.inputElement.disabled = a, this.qualityInput.inputElement.disabled = a, this.syncStatus(t, e);
1614
1696
  }
1615
1697
  handleProgress(t) {
1616
1698
  this.syncStatus(t.state, t);
@@ -1618,18 +1700,18 @@ class pt extends Y {
1618
1700
  syncStatus(t, e) {
1619
1701
  switch (t) {
1620
1702
  case "recording": {
1621
- const r = e?.frameIndex ?? 0, a = e?.totalFrames ?? this.resolvePlannedFrameCount();
1622
- if (a) {
1623
- const i = Math.min(Math.max(0, Math.round(r)), a);
1624
- this.status.setMessage(`recording ${i}/${a} frames`, "active");
1625
- } else this.status.setMessage(`recording ${Math.max(0, Math.round(r))} frames`, "active");
1703
+ const a = (e == null ? void 0 : e.frameIndex) ?? 0, o = (e == null ? void 0 : e.totalFrames) ?? this.resolvePlannedFrameCount();
1704
+ if (o) {
1705
+ const s = Math.min(Math.max(0, Math.round(a)), o);
1706
+ this.status.setMessage(`recording ${s}/${o} frames`, "active");
1707
+ } else this.status.setMessage(`recording ${Math.max(0, Math.round(a))} frames`, "active");
1626
1708
  break;
1627
1709
  }
1628
1710
  case "completed":
1629
1711
  this.status.setMessage("saved to disk", "active");
1630
1712
  break;
1631
1713
  case "error":
1632
- this.status.setMessage(e?.message ? `error: ${e.message}` : "recording failed", "alert");
1714
+ this.status.setMessage(e != null && e.message ? `error: ${e.message}` : "recording failed", "alert");
1633
1715
  break;
1634
1716
  default:
1635
1717
  this.status.setMessage("ready to record", "neutral");
@@ -1640,51 +1722,51 @@ class pt extends Y {
1640
1722
  return Number.isFinite(t) && t > 0 ? Math.round(t) : void 0;
1641
1723
  }
1642
1724
  applyDefaults() {
1643
- const t = this._config.defaultOptions ?? {}, e = t.frameCount ?? 480, r = t.frameRate ?? 60, a = t.quality ?? 0.7;
1644
- this.frameCountInput.value = String(e), this.frameRateInput.value = String(r), this.qualityInput.value = String(a), this.frameCountInput.refresh(), this.frameRateInput.refresh();
1645
- }
1646
- }
1647
- const Te = `@layer textmode-export-overlay{.textmode-export-overlay{--overlay-bg: rgba(20, 20, 20, .8);--overlay-surface: rgba(40, 40, 40, .9);--overlay-border: rgba(255, 255, 255, .14);--overlay-border-strong: rgba(255, 255, 255, .2);--overlay-border-focus: rgba(160, 160, 160, .6);--overlay-focus-shadow: 0 0 0 1px rgba(140, 140, 140, .28);--overlay-text: #ffffff;--overlay-muted: rgba(200, 200, 200, .74);--overlay-radius: .75rem;--overlay-stack-gap: .55rem;position:absolute;top:0;left:0;display:flex;flex-direction:column;gap:var(--overlay-stack-gap);min-width:236px;max-width:236px;padding:.65rem .8rem;background:var(--overlay-bg);color:var(--overlay-text);border-radius:var(--overlay-radius);border:1px solid var(--overlay-border);box-shadow:0 12px 28px #0000004d;-webkit-backdrop-filter:blur(12px);backdrop-filter:blur(12px);font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:.82rem;line-height:1.35;pointer-events:auto;z-index:2147483647}.textmode-export-overlay *{box-sizing:border-box}.textmode-export-overlay__header{display:flex;flex-direction:column;gap:.4rem}.textmode-export-overlay__header-title-row{display:flex;align-items:center;justify-content:space-between;gap:.4rem}.textmode-export-overlay__header-links{display:inline-flex;align-items:center;gap:.3rem}.textmode-export-overlay__support-link{display:inline-flex;align-items:center;justify-content:center;padding:.2rem;border-radius:.45rem;border:1px solid transparent;color:#d7d7d7d1;background:transparent;text-decoration:none;line-height:0;transition:background .18s ease,color .18s ease,transform .18s ease,border-color .18s ease}.textmode-export-overlay__support-link:hover{color:#fff;background:#5a5a5a4d;border-color:#c8c8c824}.textmode-export-overlay__support-link:focus-visible{outline:none;border-color:var(--overlay-border-focus);box-shadow:var(--overlay-focus-shadow)}.textmode-export-overlay__support-icon,.textmode-export-overlay__link-icon{display:block;width:1rem;height:1rem}.textmode-export-overlay__stack{display:flex;flex-direction:column;gap:var(--overlay-stack-gap)}.textmode-export-overlay__stack--dense{gap:.3rem}.textmode-export-overlay__stack--compact{gap:.45rem}.textmode-export-overlay__section{display:flex;flex-direction:column;gap:.4rem}.textmode-export-overlay__title{font-size:.92rem;font-weight:600}.textmode-export-overlay__divider{width:100%;height:1px;background:#ffffff29;margin-top:.25rem}.textmode-export-overlay__label{font-weight:500;opacity:.9}.textmode-export-overlay__checkbox{display:flex;align-items:center;gap:.5rem}.textmode-export-overlay__checkbox input[type=checkbox]{width:1rem;height:1rem;accent-color:rgba(100,100,100,.9)}.textmode-export-overlay__row{display:flex;gap:.6rem;flex-wrap:wrap;align-items:flex-start;width:100%}.textmode-export-overlay__field{display:flex;flex-direction:column;gap:.3rem;flex:1 1 120px;min-width:120px}.textmode-export-overlay__field--compact{flex:1 1 100px;min-width:100px}.textmode-export-overlay__field--dense{flex:1 1 90px;min-width:90px}.textmode-export-overlay__field--channel{flex:1 1 0;min-width:0}.textmode-export-overlay__field--full{width:100%;flex:1 1 100%}.textmode-export-overlay__input,.textmode-export-overlay select.textmode-export-overlay__input,.textmode-export-overlay input.textmode-export-overlay__input{width:100%;padding:.35rem .5rem;border-radius:.4rem;border:1px solid var(--overlay-border-strong);background:var(--overlay-surface);color:var(--overlay-text);font:inherit;line-height:1.35;transition:border-color .18s ease,box-shadow .18s ease,background .18s ease}.textmode-export-overlay select.textmode-export-overlay__input{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-image:url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='rgba(200, 200, 200, 0.74)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");background-repeat:no-repeat;background-position:right .5rem center;background-size:1rem;padding-right:2rem}.textmode-export-overlay__input:focus{outline:none;border-color:var(--overlay-border-focus);box-shadow:var(--overlay-focus-shadow);background:#2d2f42eb}.textmode-export-overlay__input::placeholder{color:var(--overlay-muted);opacity:.7}.textmode-export-overlay__muted{font-size:.75rem;opacity:.7;display:block}.textmode-export-overlay__button{display:inline-flex;align-items:center;justify-content:center;gap:.35rem;border-radius:.45rem;border:none;font-weight:600;padding:.45rem .7rem;cursor:pointer;transition:background .2s ease,transform .2s ease,box-shadow .2s ease}.textmode-export-overlay__button--primary{background:#505050;color:#fff}.textmode-export-overlay__button--secondary{background:#606060;color:#fff}.textmode-export-overlay__button--full{width:100%}.textmode-export-overlay__button:hover:not(:disabled){transform:translateY(-1px);box-shadow:0 7px 18px #00000073}.textmode-export-overlay__button--primary:hover:not(:disabled){background:#404040}.textmode-export-overlay__button--secondary:hover:not(:disabled){background:#4a4a4a}.textmode-export-overlay__button:disabled{cursor:default;opacity:.55;transform:none;box-shadow:none}.textmode-export-overlay__status{display:flex;flex-direction:column;gap:.25rem;padding:.45rem .55rem;border-radius:.45rem;border:1px solid rgba(110,110,110,.22);background:#4646462e}.textmode-export-overlay__status--gif{background:#5050501f;border-color:#78787840}.textmode-export-overlay__status--video{background:#4646461f;border-color:#6e6e6e40}.textmode-export-overlay__status-title{font-weight:600;font-size:.75rem;opacity:.85;text-transform:uppercase;letter-spacing:.04em}.textmode-export-overlay__status-value{font-size:.82rem;color:#dedede;transition:color .18s ease}.textmode-export-overlay__status-value--neutral{color:#cfcfcf}.textmode-export-overlay__status-value--active{color:#f5f5f5}.textmode-export-overlay__status-value--alert{color:#b8b8b8}.textmode-export-number-input,.textmode-export-overlay .textmode-export-number-input{display:flex;align-items:stretch;width:100%;background:var(--overlay-surface);border:1px solid var(--overlay-border-strong);border-radius:.4rem;overflow:hidden;transition:border-color .18s ease,box-shadow .18s ease,background .18s ease;position:relative}.textmode-export-number-input:focus-within{border-color:var(--overlay-border-focus);box-shadow:var(--overlay-focus-shadow)}.textmode-export-number-input.is-disabled{opacity:.55}.textmode-export-number-input__field{flex:1 1 auto;min-width:0;border:none;background:transparent;color:var(--overlay-text);font:inherit;padding:.35rem .5rem;appearance:textfield}.textmode-export-number-input__field::-webkit-outer-spin-button,.textmode-export-number-input__field::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}.textmode-export-number-input__field:focus{outline:none}.textmode-export-number-input__controls{display:flex;flex-direction:column;border-left:1px solid rgba(255,255,255,.12);min-width:1.6rem}.textmode-export-number-input__control{display:flex;align-items:center;justify-content:center;width:100%;flex:1;border:none;background:#32323299;color:#d0d0d0;font-size:.68rem;line-height:1;cursor:pointer;transition:background .15s ease,color .15s ease;padding:0}.textmode-export-number-input__control:hover:not(:disabled){background:#5a5a5ad9;color:#fff}.textmode-export-number-input__control:disabled{cursor:default;opacity:.4;background:#28282880;color:#c8c8c866}.textmode-export-number-input:focus-within .textmode-export-number-input__control{background:#3c3c3cbf;color:#e8e8e8}.textmode-export-number-input__display{position:absolute;inset:0;display:flex;align-items:center;padding:.4rem .55rem;pointer-events:none;color:#f8fafc;opacity:0;transition:opacity .14s ease}.textmode-export-number-input__display--visible{opacity:1}.textmode-export-range-input{position:relative;width:100%}.textmode-export-range-input.is-disabled{opacity:.55}.textmode-export-range-input__field{width:100%;height:1.4rem;padding:0;margin:0;background:transparent;cursor:pointer;appearance:none;-webkit-appearance:none}.textmode-export-range-input__field::-webkit-slider-thumb{width:12px;height:12px;margin-top:-3.5px;-webkit-appearance:none;border-radius:50%;background:#a0a0a0;border:2px solid #303030;box-shadow:0 0 0 2px #00000059}.textmode-export-range-input__field::-webkit-slider-runnable-track{height:5px;border-radius:999px;background:linear-gradient(90deg,#8c8c8cd9,#646464a6)}.textmode-export-range-input__field::-moz-range-thumb{width:12px;height:12px;border-radius:50%;background:#a0a0a0;border:2px solid #303030;margin-top:-3.5px}.textmode-export-range-input__field::-moz-range-track{height:5px;border-radius:999px;background:linear-gradient(90deg,#8c8c8cd9,#646464a6)}.textmode-export-range-input__tooltip{position:absolute;top:-1.5rem;left:0;transform:translate(-50%);padding:.2rem .35rem;border-radius:.35rem;background:#1e1e1ee0;color:#f8fafc;font-size:.68rem;line-height:1;white-space:nowrap;pointer-events:none;opacity:0;transition:opacity .15s ease}.textmode-export-range-input__tooltip--visible{opacity:1}}`;
1648
- class Re {
1649
- _textmodifier;
1650
- _state;
1651
- _events;
1652
- _exportService;
1653
- _clipboardService;
1654
- _definitions;
1655
- _formats = /* @__PURE__ */ new Map();
1656
- _eventUnsubscribers = [];
1657
- _shadowHost;
1658
- _shadowRoot;
1659
- _overlayElement;
1660
- _optionsContainer;
1661
- _copyButtonContainer;
1662
- _positionService;
1663
- _header = new H();
1664
- _formatField = new P({ label: "export format", labelFor: "textmode-export-format", variant: "full" });
1665
- _formatSelect = new mt({ id: "textmode-export-format", options: [] });
1666
- _exportButton = new Lt({ label: "download file", fullWidth: !0, variant: "primary" });
1667
- _copyButton = new Lt({ label: "copy to clipboard", fullWidth: !0, variant: "primary" });
1668
- _currentFormat;
1669
- _currentBlade;
1670
- _handleFormatSelectChange = () => {
1671
- this._handleFormatChange(this._formatSelect.value);
1672
- };
1673
- _handleExportClickSafe = () => {
1674
- this._handleExportClick().catch((t) => {
1675
- console.error("[textmode-export] Export failed", t);
1725
+ const t = this._config.defaultOptions ?? {}, e = t.frameCount ?? 480, a = t.frameRate ?? 60, o = t.quality ?? 0.7;
1726
+ this.frameCountInput.value = String(e), this.frameRateInput.value = String(a), this.qualityInput.value = String(o), this.frameCountInput.refresh(), this.frameRateInput.refresh();
1727
+ }
1728
+ }
1729
+ const Je = `@layer textmode-export-overlay{.textmode-export-overlay{--overlay-bg: rgba(20, 20, 20, .8);--overlay-surface: rgba(40, 40, 40, .9);--overlay-border: rgba(255, 255, 255, .14);--overlay-border-strong: rgba(255, 255, 255, .2);--overlay-border-focus: rgba(160, 160, 160, .6);--overlay-focus-shadow: 0 0 0 1px rgba(140, 140, 140, .28);--overlay-text: #ffffff;--overlay-muted: rgba(200, 200, 200, .74);--overlay-radius: .75rem;--overlay-stack-gap: .55rem;position:absolute;top:0;left:0;display:flex;flex-direction:column;gap:var(--overlay-stack-gap);min-width:236px;max-width:236px;padding:.65rem .8rem;background:var(--overlay-bg);color:var(--overlay-text);border-radius:var(--overlay-radius);border:1px solid var(--overlay-border);box-shadow:0 12px 28px #0000004d;-webkit-backdrop-filter:blur(12px);backdrop-filter:blur(12px);font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,sans-serif;font-size:.82rem;line-height:1.35;pointer-events:auto;z-index:2147483647}.textmode-export-overlay *{box-sizing:border-box}.textmode-export-overlay__header{display:flex;flex-direction:column;gap:.4rem}.textmode-export-overlay__header-title-row{display:flex;align-items:center;justify-content:space-between;gap:.4rem}.textmode-export-overlay__header-links{display:inline-flex;align-items:center;gap:.3rem}.textmode-export-overlay__support-link{display:inline-flex;align-items:center;justify-content:center;padding:.2rem;border-radius:.45rem;border:1px solid transparent;color:#d7d7d7d1;background:transparent;text-decoration:none;line-height:0;transition:background .18s ease,color .18s ease,transform .18s ease,border-color .18s ease}.textmode-export-overlay__support-link:hover{color:#fff;background:#5a5a5a4d;border-color:#c8c8c824}.textmode-export-overlay__support-link:focus-visible{outline:none;border-color:var(--overlay-border-focus);box-shadow:var(--overlay-focus-shadow)}.textmode-export-overlay__support-icon,.textmode-export-overlay__link-icon{display:block;width:1rem;height:1rem}.textmode-export-overlay__stack{display:flex;flex-direction:column;gap:var(--overlay-stack-gap)}.textmode-export-overlay__stack--dense{gap:.3rem}.textmode-export-overlay__stack--compact{gap:.45rem}.textmode-export-overlay__section{display:flex;flex-direction:column;gap:.4rem}.textmode-export-overlay__title{font-size:.92rem;font-weight:600}.textmode-export-overlay__divider{width:100%;height:1px;background:#ffffff29;margin-top:.25rem}.textmode-export-overlay__label{font-weight:500;opacity:.9}.textmode-export-overlay__checkbox{display:flex;align-items:center;gap:.5rem}.textmode-export-overlay__checkbox input[type=checkbox]{width:1rem;height:1rem;accent-color:rgba(100,100,100,.9)}.textmode-export-overlay__row{display:flex;gap:.6rem;flex-wrap:wrap;align-items:flex-start;width:100%}.textmode-export-overlay__field{display:flex;flex-direction:column;gap:.3rem;flex:1 1 120px;min-width:120px}.textmode-export-overlay__field--compact{flex:1 1 100px;min-width:100px}.textmode-export-overlay__field--dense{flex:1 1 90px;min-width:90px}.textmode-export-overlay__field--channel{flex:1 1 0;min-width:0}.textmode-export-overlay__field--full{width:100%;flex:1 1 100%}.textmode-export-overlay__input,.textmode-export-overlay select.textmode-export-overlay__input,.textmode-export-overlay input.textmode-export-overlay__input{width:100%;padding:.35rem .5rem;border-radius:.4rem;border:1px solid var(--overlay-border-strong);background:var(--overlay-surface);color:var(--overlay-text);font:inherit;line-height:1.35;transition:border-color .18s ease,box-shadow .18s ease,background .18s ease}.textmode-export-overlay select.textmode-export-overlay__input{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-image:url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='rgba(200, 200, 200, 0.74)' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");background-repeat:no-repeat;background-position:right .5rem center;background-size:1rem;padding-right:2rem}.textmode-export-overlay__input:focus{outline:none;border-color:var(--overlay-border-focus);box-shadow:var(--overlay-focus-shadow);background:#2d2f42eb}.textmode-export-overlay__input::placeholder{color:var(--overlay-muted);opacity:.7}.textmode-export-overlay__muted{font-size:.75rem;opacity:.7;display:block}.textmode-export-overlay__button{display:inline-flex;align-items:center;justify-content:center;gap:.35rem;border-radius:.45rem;border:none;font-weight:600;padding:.45rem .7rem;cursor:pointer;transition:background .2s ease,transform .2s ease,box-shadow .2s ease}.textmode-export-overlay__button--primary{background:#505050;color:#fff}.textmode-export-overlay__button--secondary{background:#606060;color:#fff}.textmode-export-overlay__button--full{width:100%}.textmode-export-overlay__button:hover:not(:disabled){transform:translateY(-1px);box-shadow:0 7px 18px #00000073}.textmode-export-overlay__button--primary:hover:not(:disabled){background:#404040}.textmode-export-overlay__button--secondary:hover:not(:disabled){background:#4a4a4a}.textmode-export-overlay__button:disabled{cursor:default;opacity:.55;transform:none;box-shadow:none}.textmode-export-overlay__status{display:flex;flex-direction:column;gap:.25rem;padding:.45rem .55rem;border-radius:.45rem;border:1px solid rgba(110,110,110,.22);background:#4646462e}.textmode-export-overlay__status--gif{background:#5050501f;border-color:#78787840}.textmode-export-overlay__status--video{background:#4646461f;border-color:#6e6e6e40}.textmode-export-overlay__status-title{font-weight:600;font-size:.75rem;opacity:.85;text-transform:uppercase;letter-spacing:.04em}.textmode-export-overlay__status-value{font-size:.82rem;color:#dedede;transition:color .18s ease}.textmode-export-overlay__status-value--neutral{color:#cfcfcf}.textmode-export-overlay__status-value--active{color:#f5f5f5}.textmode-export-overlay__status-value--alert{color:#b8b8b8}.textmode-export-number-input,.textmode-export-overlay .textmode-export-number-input{display:flex;align-items:stretch;width:100%;background:var(--overlay-surface);border:1px solid var(--overlay-border-strong);border-radius:.4rem;overflow:hidden;transition:border-color .18s ease,box-shadow .18s ease,background .18s ease;position:relative}.textmode-export-number-input:focus-within{border-color:var(--overlay-border-focus);box-shadow:var(--overlay-focus-shadow)}.textmode-export-number-input.is-disabled{opacity:.55}.textmode-export-number-input__field{flex:1 1 auto;min-width:0;border:none;background:transparent;color:var(--overlay-text);font:inherit;padding:.35rem .5rem;-webkit-appearance:textfield;-moz-appearance:textfield;appearance:textfield}.textmode-export-number-input__field::-webkit-outer-spin-button,.textmode-export-number-input__field::-webkit-inner-spin-button{-webkit-appearance:none;margin:0}.textmode-export-number-input__field:focus{outline:none}.textmode-export-number-input__controls{display:flex;flex-direction:column;border-left:1px solid rgba(255,255,255,.12);min-width:1.6rem}.textmode-export-number-input__control{display:flex;align-items:center;justify-content:center;width:100%;flex:1;border:none;background:#32323299;color:#d0d0d0;font-size:.68rem;line-height:1;cursor:pointer;transition:background .15s ease,color .15s ease;padding:0}.textmode-export-number-input__control:hover:not(:disabled){background:#5a5a5ad9;color:#fff}.textmode-export-number-input__control:disabled{cursor:default;opacity:.4;background:#28282880;color:#c8c8c866}.textmode-export-number-input:focus-within .textmode-export-number-input__control{background:#3c3c3cbf;color:#e8e8e8}.textmode-export-number-input__display{position:absolute;top:0;right:0;bottom:0;left:0;display:flex;align-items:center;padding:.4rem .55rem;pointer-events:none;color:#f8fafc;opacity:0;transition:opacity .14s ease}.textmode-export-number-input__display--visible{opacity:1}.textmode-export-range-input{position:relative;width:100%}.textmode-export-range-input.is-disabled{opacity:.55}.textmode-export-range-input__field{width:100%;height:1.4rem;padding:0;margin:0;background:transparent;cursor:pointer;-moz-appearance:none;appearance:none;-webkit-appearance:none}.textmode-export-range-input__field::-webkit-slider-thumb{width:12px;height:12px;margin-top:-3.5px;-webkit-appearance:none;border-radius:50%;background:#a0a0a0;border:2px solid #303030;box-shadow:0 0 0 2px #00000059}.textmode-export-range-input__field::-webkit-slider-runnable-track{height:5px;border-radius:999px;background:linear-gradient(90deg,#8c8c8cd9,#646464a6)}.textmode-export-range-input__field::-moz-range-thumb{width:12px;height:12px;border-radius:50%;background:#a0a0a0;border:2px solid #303030;margin-top:-3.5px}.textmode-export-range-input__field::-moz-range-track{height:5px;border-radius:999px;background:linear-gradient(90deg,#8c8c8cd9,#646464a6)}.textmode-export-range-input__tooltip{position:absolute;top:-1.5rem;left:0;transform:translate(-50%);padding:.2rem .35rem;border-radius:.35rem;background:#1e1e1ee0;color:#f8fafc;font-size:.68rem;line-height:1;white-space:nowrap;pointer-events:none;opacity:0;transition:opacity .15s ease}.textmode-export-range-input__tooltip--visible{opacity:1}}`;
1730
+ class Xe {
1731
+ constructor(r, t, e, a, o) {
1732
+ p(this, "_textmodifier");
1733
+ p(this, "_state");
1734
+ p(this, "_events");
1735
+ p(this, "_exportService");
1736
+ p(this, "_clipboardService");
1737
+ p(this, "_definitions");
1738
+ p(this, "_formats", /* @__PURE__ */ new Map());
1739
+ p(this, "_eventUnsubscribers", []);
1740
+ p(this, "_shadowHost");
1741
+ p(this, "_shadowRoot");
1742
+ p(this, "_overlayElement");
1743
+ p(this, "_optionsContainer");
1744
+ p(this, "_copyButtonContainer");
1745
+ p(this, "_positionService");
1746
+ p(this, "_header", new gt());
1747
+ p(this, "_formatField", new O({ label: "export format", labelFor: "textmode-export-format", variant: "full" }));
1748
+ p(this, "_formatSelect", new st({ id: "textmode-export-format", options: [] }));
1749
+ p(this, "_exportButton", new Vt({ label: "download file", fullWidth: !0, variant: "primary" }));
1750
+ p(this, "_copyButton", new Vt({ label: "copy to clipboard", fullWidth: !0, variant: "primary" }));
1751
+ p(this, "_currentFormat");
1752
+ p(this, "_currentBlade");
1753
+ p(this, "_handleFormatSelectChange", () => {
1754
+ this._handleFormatChange(this._formatSelect.value);
1676
1755
  });
1677
- };
1678
- _handleCopyClickSafe = () => {
1679
- this._handleCopyClick().catch((t) => {
1680
- console.error("[textmode-export] Copy failed", t);
1756
+ p(this, "_handleExportClickSafe", () => {
1757
+ this._handleExportClick().catch((r) => {
1758
+ console.error("[textmode-export] Export failed", r);
1759
+ });
1681
1760
  });
1682
- };
1683
- constructor(t, e, r, a, i) {
1684
- this._textmodifier = t, this._state = r, this._events = a, this._exportService = new Be(e, a), this._clipboardService = new ke(e), this._definitions = i, this._currentFormat = r.snapshot.format, this._initializeFormatMap(), this._registerEventHandlers();
1761
+ p(this, "_handleCopyClickSafe", () => {
1762
+ this._handleCopyClick().catch((r) => {
1763
+ console.error("[textmode-export] Copy failed", r);
1764
+ });
1765
+ });
1766
+ this._textmodifier = r, this._state = e, this._events = a, this._exportService = new De(t, a), this._clipboardService = new Oe(t), this._definitions = o, this._currentFormat = e.snapshot.format, this._initializeFormatMap(), this._registerEventHandlers();
1685
1767
  }
1686
1768
  $mount() {
1687
- this._createOverlay(), this._renderStaticContent(), this._positionService = new Ie(this._textmodifier, this._shadowHost), this._positionService.bind(), this._switchFormat(this._currentFormat);
1769
+ this._createOverlay(), this._renderStaticContent(), this._positionService = new Ve(this._textmodifier, this._shadowHost), this._positionService.bind(), this._switchFormat(this._currentFormat);
1688
1770
  }
1689
1771
  show() {
1690
1772
  this._shadowHost && (this._shadowHost.style.display = "");
@@ -1699,104 +1781,108 @@ class Re {
1699
1781
  return !!this._shadowHost && this._shadowHost.style.display !== "none";
1700
1782
  }
1701
1783
  $dispose() {
1784
+ var r, t;
1702
1785
  this._formatSelect.isMounted() && this._formatSelect.selectElement.removeEventListener("change", this._handleFormatSelectChange), this._exportButton.isMounted() && this._exportButton.buttonElement.removeEventListener("click", this._handleExportClickSafe), this._copyButton.isMounted() && this._copyButton.buttonElement.removeEventListener("click", this._handleCopyClickSafe);
1703
- for (const t of this._eventUnsubscribers) t();
1786
+ for (const e of this._eventUnsubscribers) e();
1704
1787
  this._eventUnsubscribers.length = 0, this._events.$clear();
1705
- for (const t of this._formats.values()) t.blade.destroy();
1706
- this._formats.clear(), this._currentBlade = void 0, this._shadowHost?.isConnected && this._shadowHost.remove(), this._positionService?.dispose();
1788
+ for (const e of this._formats.values()) e.blade.destroy();
1789
+ this._formats.clear(), this._currentBlade = void 0, (r = this._shadowHost) != null && r.isConnected && this._shadowHost.remove(), (t = this._positionService) == null || t.dispose();
1707
1790
  }
1708
1791
  _initializeFormatMap() {
1709
- for (const t of this._definitions) {
1710
- const e = t.createBlade();
1711
- this._formats.set(t.format, { definition: t, blade: e, initialized: !1 });
1792
+ for (const r of this._definitions) {
1793
+ const t = r.createBlade();
1794
+ this._formats.set(r.format, { definition: r, blade: t, initialized: !1 });
1712
1795
  }
1713
1796
  }
1714
1797
  _createOverlay() {
1715
1798
  this._shadowHost = document.createElement("div"), this._shadowHost.dataset.plugin = "textmode-export-overlay-host", this._shadowHost.style.cssText = "position: absolute; top: 0; left: 0; pointer-events: none; z-index: 2147483647;", this._shadowRoot = this._shadowHost.attachShadow({ mode: "open" });
1716
- const t = document.createElement("style");
1717
- t.textContent = Te, this._shadowRoot.appendChild(t), this._overlayElement = document.createElement("div"), this._overlayElement.dataset.plugin = "textmode-export-overlay", this._overlayElement.classList.add(b.root, b.stack), this._shadowRoot.appendChild(this._overlayElement), document.body.appendChild(this._shadowHost);
1799
+ const r = document.createElement("style");
1800
+ r.textContent = Je, this._shadowRoot.appendChild(r), this._overlayElement = document.createElement("div"), this._overlayElement.dataset.plugin = "textmode-export-overlay", this._overlayElement.classList.add(b.root, b.stack), this._shadowRoot.appendChild(this._overlayElement), document.body.appendChild(this._shadowHost);
1718
1801
  }
1719
1802
  _renderStaticContent() {
1720
1803
  this._header.mount(this._overlayElement);
1721
- const t = document.createElement("div");
1722
- t.classList.add(b.section), this._overlayElement.appendChild(t), this._formatField.mount(t), this._prepareFormatOptions(), this._formatSelect.mount(this._formatField.root), this._formatSelect.selectElement.addEventListener("change", this._handleFormatSelectChange), this._optionsContainer = document.createElement("div"), this._optionsContainer.classList.add(b.stack, b.stackCompact), this._overlayElement.appendChild(this._optionsContainer), this._exportButton.mount(this._overlayElement), this._exportButton.buttonElement.addEventListener("click", this._handleExportClickSafe), this._copyButtonContainer = document.createElement("div"), this._copyButtonContainer.classList.add(b.stack, b.stackDense), this._overlayElement.appendChild(this._copyButtonContainer), this._copyButton.mount(this._copyButtonContainer), this._copyButton.buttonElement.dataset.defaultLabel = "copy to clipboard", this._copyButton.buttonElement.addEventListener("click", this._handleCopyClickSafe);
1804
+ const r = document.createElement("div");
1805
+ r.classList.add(b.section), this._overlayElement.appendChild(r), this._formatField.mount(r), this._prepareFormatOptions(), this._formatSelect.mount(this._formatField.root), this._formatSelect.selectElement.addEventListener("change", this._handleFormatSelectChange), this._optionsContainer = document.createElement("div"), this._optionsContainer.classList.add(b.stack, b.stackCompact), this._overlayElement.appendChild(this._optionsContainer), this._exportButton.mount(this._overlayElement), this._exportButton.buttonElement.addEventListener("click", this._handleExportClickSafe), this._copyButtonContainer = document.createElement("div"), this._copyButtonContainer.classList.add(b.stack, b.stackDense), this._overlayElement.appendChild(this._copyButtonContainer), this._copyButton.mount(this._copyButtonContainer), this._copyButton.buttonElement.dataset.defaultLabel = "copy to clipboard", this._copyButton.buttonElement.addEventListener("click", this._handleCopyClickSafe);
1723
1806
  }
1724
1807
  _prepareFormatOptions() {
1725
- const t = this._definitions.map((e) => ({ value: e.format, label: e.label }));
1726
- this._formatSelect.update({ options: t, defaultValue: this._currentFormat });
1808
+ const r = this._definitions.map((t) => ({ value: t.format, label: t.label }));
1809
+ this._formatSelect.update({ options: r, defaultValue: this._currentFormat });
1727
1810
  }
1728
1811
  _registerEventHandlers() {
1729
- this._eventUnsubscribers.push(this._events.$on("export:request", ({ format: t }) => {
1730
- t === this._currentFormat && (this._state.$set({ isBusy: !0, error: void 0 }), this._updateExportButton());
1731
- }), this._events.$on("export:success", ({ format: t }) => {
1732
- if (t === this._currentFormat) {
1733
- const e = { isBusy: !1 };
1734
- t === "gif" && (e.gifProgress = void 0), t === "video" && (e.videoProgress = void 0), this._state.$set(e), this._updateExportButton();
1812
+ this._eventUnsubscribers.push(this._events.$on("export:request", ({ format: r }) => {
1813
+ r === this._currentFormat && (this._state.$set({ isBusy: !0, error: void 0 }), this._updateExportButton());
1814
+ }), this._events.$on("export:success", ({ format: r }) => {
1815
+ if (r === this._currentFormat) {
1816
+ const t = { isBusy: !1 };
1817
+ r === "gif" && (t.gifProgress = void 0), r === "video" && (t.videoProgress = void 0), this._state.$set(t), this._updateExportButton();
1735
1818
  }
1736
- }), this._events.$on("export:error", ({ format: t, error: e }) => {
1737
- t === this._currentFormat && (this._state.$set({ isBusy: !1, error: e }), this._updateExportButton());
1738
- }), this._events.$on("export:progress", ({ format: t, progress: e }) => {
1739
- if (e) {
1740
- if (t === "gif" && this._currentBlade?.blade instanceof ut) {
1741
- const r = e;
1742
- this._state.$set({ gifProgress: r }), this._currentBlade.blade.handleProgress(r);
1743
- } else if (t === "video" && this._currentBlade?.blade instanceof pt) {
1744
- const r = e;
1745
- this._state.$set({ videoProgress: r }), this._currentBlade.blade.handleProgress(r);
1819
+ }), this._events.$on("export:error", ({ format: r, error: t }) => {
1820
+ r === this._currentFormat && (this._state.$set({ isBusy: !1, error: t }), this._updateExportButton());
1821
+ }), this._events.$on("export:progress", ({ format: r, progress: t }) => {
1822
+ var e, a;
1823
+ if (t) {
1824
+ if (r === "gif" && ((e = this._currentBlade) == null ? void 0 : e.blade) instanceof bt) {
1825
+ const o = t;
1826
+ this._state.$set({ gifProgress: o }), this._currentBlade.blade.handleProgress(o);
1827
+ } else if (r === "video" && ((a = this._currentBlade) == null ? void 0 : a.blade) instanceof vt) {
1828
+ const o = t;
1829
+ this._state.$set({ videoProgress: o }), this._currentBlade.blade.handleProgress(o);
1746
1830
  }
1747
1831
  this._updateExportButton();
1748
1832
  }
1749
1833
  }));
1750
1834
  }
1751
- _handleFormatChange(t) {
1752
- this._currentFormat = t, this._state.$set({ format: t }), this._switchFormat(t), this._events.$emit("format:change", { format: t });
1835
+ _handleFormatChange(r) {
1836
+ this._currentFormat = r, this._state.$set({ format: r }), this._switchFormat(r), this._events.$emit("format:change", { format: r });
1753
1837
  }
1754
- _switchFormat(t) {
1755
- const e = this._formats.get(t);
1756
- if (!e) throw new Error(`Unknown export format: ${t}`);
1757
- this._currentBlade && this._currentBlade.blade.unmount(), this._optionsContainer.innerHTML = "", e.blade.mount(this._optionsContainer), e.initialized || (e.blade.reset(), e.initialized = !0), this._currentBlade = e, this._formatSelect.value = t, this._updateCopyButtonState(), this._updateExportButton(), this._positionService?.scheduleUpdate();
1838
+ _switchFormat(r) {
1839
+ var e;
1840
+ const t = this._formats.get(r);
1841
+ if (!t) throw new Error(`Unknown export format: ${r}`);
1842
+ this._currentBlade && this._currentBlade.blade.unmount(), this._optionsContainer.innerHTML = "", t.blade.mount(this._optionsContainer), t.initialized || (t.blade.reset(), t.initialized = !0), this._currentBlade = t, this._formatSelect.value = r, this._updateCopyButtonState(), this._updateExportButton(), (e = this._positionService) == null || e.scheduleUpdate();
1758
1843
  }
1759
1844
  _updateCopyButtonState() {
1760
- const t = this._currentBlade?.definition.supportsClipboard ?? !1;
1761
- this._copyButtonContainer.style.display = t ? "flex" : "none", this._copyButton.setDisabled(!t);
1845
+ var t;
1846
+ const r = ((t = this._currentBlade) == null ? void 0 : t.definition.supportsClipboard) ?? !1;
1847
+ this._copyButtonContainer.style.display = r ? "flex" : "none", this._copyButton.setDisabled(!r);
1762
1848
  }
1763
1849
  async _handleExportClick() {
1764
1850
  if (!this._currentBlade) return;
1765
- const t = this._currentBlade.definition.format, e = this._currentBlade.blade.getOptions();
1851
+ const r = this._currentBlade.definition.format, t = this._currentBlade.blade.getOptions();
1766
1852
  if (this._currentBlade.blade.validate()) {
1767
- if (t === "gif") {
1768
- const r = this._currentBlade.blade;
1769
- if (r.isRecording()) return;
1770
- r.setRecordingState("recording");
1853
+ if (r === "gif") {
1854
+ const e = this._currentBlade.blade;
1855
+ if (e.isRecording()) return;
1856
+ e.setRecordingState("recording");
1771
1857
  try {
1772
- await this._exportService.$requestExport("gif", e, { onGIFProgress: (a) => {
1773
- r.setRecordingState(a.state, a);
1858
+ await this._exportService.$requestExport("gif", t, { onGIFProgress: (a) => {
1859
+ e.setRecordingState(a.state, a);
1774
1860
  } });
1775
1861
  } catch (a) {
1776
- throw r.setRecordingState("error"), a;
1862
+ throw e.setRecordingState("error"), a;
1777
1863
  }
1778
1864
  return void window.setTimeout(() => {
1779
- r.setRecordingState("idle"), this._updateExportButton();
1865
+ e.setRecordingState("idle"), this._updateExportButton();
1780
1866
  }, 1600);
1781
1867
  }
1782
- if (t === "video") {
1783
- const r = this._currentBlade.blade;
1784
- if (r.isRecording()) return;
1785
- r.setRecordingState("recording");
1868
+ if (r === "video") {
1869
+ const e = this._currentBlade.blade;
1870
+ if (e.isRecording()) return;
1871
+ e.setRecordingState("recording");
1786
1872
  try {
1787
- await this._exportService.$requestExport("video", e, { onVideoProgress: (a) => {
1788
- r.setRecordingState(a.state, a);
1873
+ await this._exportService.$requestExport("video", t, { onVideoProgress: (a) => {
1874
+ e.setRecordingState(a.state, a);
1789
1875
  } });
1790
1876
  } catch (a) {
1791
- throw r.setRecordingState("error"), a;
1877
+ throw e.setRecordingState("error"), a;
1792
1878
  }
1793
1879
  return void window.setTimeout(() => {
1794
- r.setRecordingState("idle"), this._updateExportButton();
1880
+ e.setRecordingState("idle"), this._updateExportButton();
1795
1881
  }, 1600);
1796
1882
  }
1797
1883
  this._exportButton.setDisabled(!0), this._exportButton.setLabel("exporting…");
1798
1884
  try {
1799
- await this._exportService.$requestExport(t, e);
1885
+ await this._exportService.$requestExport(r, t);
1800
1886
  } finally {
1801
1887
  this._exportButton.setDisabled(!1), this._exportButton.setLabel("download file");
1802
1888
  }
@@ -1804,18 +1890,21 @@ class Re {
1804
1890
  }
1805
1891
  async _handleCopyClick() {
1806
1892
  if (!this._currentBlade || !this._currentBlade.definition.supportsClipboard) return;
1807
- const t = this._currentBlade.definition.format, e = this._currentBlade.blade.getOptions(), r = this._copyButton.buttonElement.dataset.defaultLabel ?? "copy to clipboard";
1893
+ const r = this._currentBlade.definition.format, t = this._currentBlade.blade.getOptions(), e = this._copyButton.buttonElement.dataset.defaultLabel ?? "copy to clipboard";
1808
1894
  this._copyButton.setDisabled(!0), this._copyButton.setLabel("copying…");
1809
1895
  try {
1810
- switch (t) {
1896
+ switch (r) {
1811
1897
  case "txt":
1812
- await this._clipboardService.$copy("txt", e);
1898
+ await this._clipboardService.$copy("txt", t);
1899
+ break;
1900
+ case "json":
1901
+ await this._clipboardService.$copy("json", t);
1813
1902
  break;
1814
1903
  case "svg":
1815
- await this._clipboardService.$copy("svg", e);
1904
+ await this._clipboardService.$copy("svg", t);
1816
1905
  break;
1817
1906
  case "image":
1818
- await this._clipboardService.$copy("image", e);
1907
+ await this._clipboardService.$copy("image", t);
1819
1908
  break;
1820
1909
  default:
1821
1910
  return;
@@ -1825,103 +1914,106 @@ class Re {
1825
1914
  console.error("[textmode-export] Failed to copy to clipboard", a), this._copyButton.setLabel("copy failed!");
1826
1915
  } finally {
1827
1916
  window.setTimeout(() => {
1828
- this._copyButton.setLabel(r), this._copyButton.setDisabled(!1);
1917
+ this._copyButton.setLabel(e), this._copyButton.setDisabled(!1);
1829
1918
  }, 1200);
1830
1919
  }
1831
1920
  }
1832
1921
  _updateExportButton() {
1833
1922
  if (!this._currentBlade) return;
1834
- const t = this._currentBlade.definition.format;
1835
- if (t === "gif" && this._currentBlade.blade instanceof ut) {
1836
- const r = this._currentBlade.blade, a = this._state.snapshot.gifProgress;
1837
- if (r.isRecording()) if (this._exportButton.setDisabled(!0), a?.totalFrames) {
1838
- const i = a.frameIndex ?? 0, s = a.state === "encoding" ? "encoding" : "recording";
1839
- this._exportButton.setLabel(`${s} ${i}/${a.totalFrames}`);
1923
+ const r = this._currentBlade.definition.format;
1924
+ if (r === "gif" && this._currentBlade.blade instanceof bt) {
1925
+ const e = this._currentBlade.blade, a = this._state.snapshot.gifProgress;
1926
+ if (e.isRecording()) if (this._exportButton.setDisabled(!0), a == null ? void 0 : a.totalFrames) {
1927
+ const o = a.frameIndex ?? 0, s = a.state === "encoding" ? "encoding" : "recording";
1928
+ this._exportButton.setLabel(`${s} ${o}/${a.totalFrames}`);
1840
1929
  } else {
1841
- const i = a?.state === "encoding" ? "encoding" : "recording";
1842
- this._exportButton.setLabel(`${i}…`);
1930
+ const o = (a == null ? void 0 : a.state) === "encoding" ? "encoding" : "recording";
1931
+ this._exportButton.setLabel(`${o}…`);
1843
1932
  }
1844
1933
  else this._exportButton.setDisabled(!1), this._exportButton.setLabel("start recording");
1845
1934
  return;
1846
1935
  }
1847
- if (t === "video" && this._currentBlade.blade instanceof pt) {
1848
- const r = this._currentBlade.blade, a = this._state.snapshot.videoProgress;
1849
- if (r.isRecording()) if (this._exportButton.setDisabled(!0), a?.totalFrames) {
1850
- const i = a.frameIndex ?? 0;
1851
- this._exportButton.setLabel(`recording ${i}/${a.totalFrames} frames`);
1936
+ if (r === "video" && this._currentBlade.blade instanceof vt) {
1937
+ const e = this._currentBlade.blade, a = this._state.snapshot.videoProgress;
1938
+ if (e.isRecording()) if (this._exportButton.setDisabled(!0), a == null ? void 0 : a.totalFrames) {
1939
+ const o = a.frameIndex ?? 0;
1940
+ this._exportButton.setLabel(`recording ${o}/${a.totalFrames} frames`);
1852
1941
  } else this._exportButton.setLabel("recording…");
1853
1942
  else this._exportButton.setDisabled(!1), this._exportButton.setLabel("start recording");
1854
1943
  return;
1855
1944
  }
1856
- const e = this._state.snapshot.isBusy;
1857
- this._exportButton.setDisabled(e), this._exportButton.setLabel(e ? "exporting…" : "download file");
1858
- }
1859
- }
1860
- class Ue {
1861
- _listeners = {};
1862
- _getPool(t) {
1863
- const e = this._listeners[t];
1864
- if (e) return e;
1865
- const r = /* @__PURE__ */ new Set();
1866
- return this._listeners[t] = r, r;
1867
- }
1868
- $on(t, e) {
1869
- const r = this._getPool(t);
1870
- return r.add(e), () => {
1871
- r.delete(e), r.size === 0 && delete this._listeners[t];
1945
+ const t = this._state.snapshot.isBusy;
1946
+ this._exportButton.setDisabled(t), this._exportButton.setLabel(t ? "exporting…" : "download file");
1947
+ }
1948
+ }
1949
+ class Ye {
1950
+ constructor() {
1951
+ p(this, "_listeners", {});
1952
+ }
1953
+ _getPool(r) {
1954
+ const t = this._listeners[r];
1955
+ if (t) return t;
1956
+ const e = /* @__PURE__ */ new Set();
1957
+ return this._listeners[r] = e, e;
1958
+ }
1959
+ $on(r, t) {
1960
+ const e = this._getPool(r);
1961
+ return e.add(t), () => {
1962
+ e.delete(t), e.size === 0 && delete this._listeners[r];
1872
1963
  };
1873
1964
  }
1874
- $emit(t, e) {
1875
- const r = this._listeners[t];
1876
- if (r) for (const a of [...r]) try {
1877
- a(e);
1878
- } catch (i) {
1879
- console.error("[textmode-export] Event handler failed", i);
1965
+ $emit(r, t) {
1966
+ const e = this._listeners[r];
1967
+ if (e) for (const a of [...e]) try {
1968
+ a(t);
1969
+ } catch (o) {
1970
+ console.error("[textmode-export] Event handler failed", o);
1880
1971
  }
1881
1972
  }
1882
1973
  $clear() {
1883
- for (const t of Object.keys(this._listeners)) delete this._listeners[t];
1974
+ for (const r of Object.keys(this._listeners)) delete this._listeners[r];
1884
1975
  }
1885
1976
  }
1886
- class Ne {
1887
- _state;
1888
- _listeners = /* @__PURE__ */ new Set();
1889
- constructor(t) {
1890
- this._state = t;
1977
+ class Qe {
1978
+ constructor(r) {
1979
+ p(this, "_state");
1980
+ p(this, "_listeners", /* @__PURE__ */ new Set());
1981
+ this._state = r;
1891
1982
  }
1892
1983
  get snapshot() {
1893
1984
  return Object.freeze({ ...this._state });
1894
1985
  }
1895
- $set(t) {
1896
- this._state = Object.assign({}, this._state, t);
1897
- const e = this.snapshot;
1898
- for (const r of [...this._listeners]) try {
1899
- r(e);
1986
+ $set(r) {
1987
+ this._state = Object.assign({}, this._state, r);
1988
+ const t = this.snapshot;
1989
+ for (const e of [...this._listeners]) try {
1990
+ e(t);
1900
1991
  } catch (a) {
1901
1992
  console.error("[textmode-export] State listener failed", a);
1902
1993
  }
1903
1994
  }
1904
- $subscribe(t) {
1905
- return this._listeners.add(t), t(this.snapshot), () => {
1906
- this._listeners.delete(t);
1995
+ $subscribe(r) {
1996
+ return this._listeners.add(r), r(this.snapshot), () => {
1997
+ this._listeners.delete(r);
1907
1998
  };
1908
1999
  }
1909
- $reset(t) {
1910
- this._state = t;
1911
- const e = this.snapshot;
1912
- for (const r of [...this._listeners]) r(e);
2000
+ $reset(r) {
2001
+ this._state = r;
2002
+ const t = this.snapshot;
2003
+ for (const e of [...this._listeners]) e(t);
1913
2004
  }
1914
2005
  }
1915
- const Ge = (n) => ({ format: n, isBusy: !1 });
1916
- class Gt extends O {
1917
- props;
1918
- checkbox;
1919
- labelElement;
1920
- handleChange = () => {
1921
- this.props.defaultChecked = this.checkbox.checked;
1922
- };
2006
+ const Ke = (i) => ({ format: i, isBusy: !1 });
2007
+ class nt extends T {
1923
2008
  constructor(t) {
1924
- super(), this.props = t;
2009
+ super();
2010
+ p(this, "props");
2011
+ p(this, "checkbox");
2012
+ p(this, "labelElement");
2013
+ p(this, "handleChange", () => {
2014
+ this.props.defaultChecked = this.checkbox.checked;
2015
+ });
2016
+ this.props = t;
1925
2017
  }
1926
2018
  render() {
1927
2019
  this.labelElement = document.createElement("label"), this.labelElement.classList.add(b.checkbox), this.checkbox = document.createElement("input"), this.checkbox.type = "checkbox", this.props.id && (this.checkbox.id = this.props.id), this.checkbox.checked = !!this.props.defaultChecked, this.checkbox.addEventListener("change", this.handleChange);
@@ -1944,14 +2036,15 @@ class Gt extends O {
1944
2036
  this.props = t, t.id && (this.checkbox.id = t.id, this.labelElement.htmlFor = t.id), this.checkbox.checked = !!t.defaultChecked, this.labelElement.lastElementChild && (this.labelElement.lastElementChild.textContent = t.label);
1945
2037
  }
1946
2038
  }
1947
- class ze extends O {
1948
- props;
1949
- input;
1950
- handleInput = () => {
1951
- this.props.defaultValue = this.input.value;
1952
- };
2039
+ class Ze extends T {
1953
2040
  constructor(t) {
1954
- super(), this.props = t;
2041
+ super();
2042
+ p(this, "props");
2043
+ p(this, "input");
2044
+ p(this, "handleInput", () => {
2045
+ this.props.defaultValue = this.input.value;
2046
+ });
2047
+ this.props = t;
1955
2048
  }
1956
2049
  render() {
1957
2050
  return this.input = document.createElement("input"), this.input.type = "text", this.input.classList.add(b.input), this.props.id && (this.input.id = this.props.id), this.props.maxLength !== void 0 && (this.input.maxLength = this.props.maxLength), this.props.defaultValue !== void 0 && (this.input.value = this.props.defaultValue), this.input.addEventListener("input", this.handleInput), this.input;
@@ -1972,16 +2065,16 @@ class ze extends O {
1972
2065
  this.props = t, t.id && (this.input.id = t.id), t.maxLength !== void 0 && (this.input.maxLength = t.maxLength), t.defaultValue !== void 0 && (this.input.value = t.defaultValue);
1973
2066
  }
1974
2067
  }
1975
- class We extends Y {
1976
- trailingSpaces = this._manageComponent(new Gt({ label: "preserve trailing spaces", defaultChecked: !1 }));
1977
- emptyCharacter = this._manageComponent(new ze({ id: "textmode-export-empty-character", defaultValue: " ", maxLength: 1 }));
2068
+ class tr extends J {
1978
2069
  constructor(t) {
1979
2070
  super(t);
2071
+ p(this, "trailingSpaces", this._manageComponent(new nt({ label: "preserve trailing spaces", defaultChecked: !1 })));
2072
+ p(this, "emptyCharacter", this._manageComponent(new Ze({ id: "textmode-export-empty-character", defaultValue: " ", maxLength: 1 })));
1980
2073
  }
1981
2074
  render() {
1982
2075
  const t = document.createElement("div");
1983
2076
  t.classList.add(b.stack), this.trailingSpaces.mount(t);
1984
- const e = new P({ label: "empty character", labelFor: "textmode-export-empty-character", variant: "full" });
2077
+ const e = new O({ label: "empty character", labelFor: "textmode-export-empty-character", variant: "full" });
1985
2078
  return e.mount(t), this.emptyCharacter.mount(e.root), t;
1986
2079
  }
1987
2080
  getOptions() {
@@ -1999,25 +2092,53 @@ class We extends Y {
1999
2092
  this.trailingSpaces.checked = t.preserveTrailingSpaces ?? !1, this.emptyCharacter.value = t.emptyCharacter ?? " ";
2000
2093
  }
2001
2094
  }
2002
- class qe extends Y {
2003
- formatSelect = this._manageComponent(new mt({ id: "textmode-export-image-format", options: [{ value: "png", label: `PNG (${lt.png})` }, { value: "jpg", label: `JPG (${lt.jpg})` }, { value: "webp", label: `WEBP (${lt.webp})` }], defaultValue: "png" }));
2004
- scaleInput = this._manageComponent(new G({ defaultValue: "1", attributes: { min: "0.1", step: "0.1" } }));
2095
+ class er extends J {
2096
+ constructor(t) {
2097
+ super(t);
2098
+ p(this, "prettyPrint", this._manageComponent(new nt({ id: "textmode-export-json-pretty", label: "pretty print", defaultChecked: !0 })));
2099
+ p(this, "includeMetadata", this._manageComponent(new nt({ id: "textmode-export-json-metadata", label: "include metadata", defaultChecked: !0 })));
2100
+ p(this, "colorMode", this._manageComponent(new st({ id: "textmode-export-json-color-mode", options: [{ value: "hex", label: "hex" }, { value: "rgba", label: "rgba" }], defaultValue: "hex" })));
2101
+ }
2102
+ render() {
2103
+ const t = document.createElement("div");
2104
+ t.classList.add(b.stack), this.prettyPrint.mount(t), this.includeMetadata.mount(t);
2105
+ const e = new O({ label: "color mode", labelFor: "textmode-export-json-color-mode", variant: "full" });
2106
+ return e.mount(t), this.colorMode.mount(e.root), t;
2107
+ }
2108
+ getOptions() {
2109
+ return { pretty: this.prettyPrint.checked, includeMetadata: this.includeMetadata.checked, colorMode: this.colorMode.value };
2110
+ }
2111
+ reset() {
2112
+ this.applyDefaults();
2113
+ }
2114
+ validate() {
2115
+ return !0;
2116
+ }
2117
+ applyDefaults() {
2118
+ const t = this._config.defaultOptions ?? {};
2119
+ this.prettyPrint.checked = typeof t.pretty == "number" ? t.pretty > 0 : t.pretty ?? !0, this.includeMetadata.checked = t.includeMetadata ?? !0, this.colorMode.value = t.colorMode ?? "hex";
2120
+ }
2121
+ }
2122
+ class rr extends J {
2005
2123
  constructor(t) {
2006
2124
  super(t);
2125
+ p(this, "formatSelect", this._manageComponent(new st({ id: "textmode-export-image-format", options: [{ value: "png", label: `PNG (${pt.png})` }, { value: "jpg", label: `JPG (${pt.jpg})` }, { value: "webp", label: `WEBP (${pt.webp})` }], defaultValue: "png" })));
2126
+ p(this, "scaleInput", this._manageComponent(new z({ defaultValue: "1", attributes: { min: "0.1", step: "0.1" } })));
2007
2127
  }
2008
2128
  render() {
2009
2129
  const t = document.createElement("div");
2010
2130
  t.classList.add(b.stack);
2011
- const e = new j("row");
2131
+ const e = new Y("row");
2012
2132
  e.mount(t);
2013
- const r = new P({ label: "image format", labelFor: "textmode-export-image-format", variant: "compact" });
2014
- r.mount(e.root), this.formatSelect.mount(r.root);
2015
- const a = new P({ label: "scale", labelFor: "textmode-export-image-scale", variant: "dense" });
2016
- return a.mount(e.root), this.scaleInput.mount(a.root), this.scaleInput.inputElement.id = "textmode-export-image-scale", t;
2133
+ const a = new O({ label: "image format", labelFor: "textmode-export-image-format", variant: "compact" });
2134
+ a.mount(e.root), this.formatSelect.mount(a.root);
2135
+ const o = new O({ label: "scale", labelFor: "textmode-export-image-scale", variant: "dense" });
2136
+ return o.mount(e.root), this.scaleInput.mount(o.root), this.scaleInput.inputElement.id = "textmode-export-image-scale", t;
2017
2137
  }
2018
2138
  getOptions() {
2139
+ var e;
2019
2140
  const t = Number.parseFloat(this.scaleInput.value);
2020
- return { format: this.formatSelect.value, scale: Number.isFinite(t) ? t : this._config.defaultOptions?.scale ?? 1 };
2141
+ return { format: this.formatSelect.value, scale: Number.isFinite(t) ? t : ((e = this._config.defaultOptions) == null ? void 0 : e.scale) ?? 1 };
2021
2142
  }
2022
2143
  reset() {
2023
2144
  this.applyDefaults(), this.scaleInput.refresh();
@@ -2033,22 +2154,22 @@ class qe extends Y {
2033
2154
  this.scaleInput.value = String(e);
2034
2155
  }
2035
2156
  }
2036
- class He extends Y {
2037
- includeBackground = this._manageComponent(new Gt({ id: "textmode-export-svg-include-backgrounds", label: "include cell backgrounds", defaultChecked: !0 }));
2038
- drawMode = this._manageComponent(new mt({ id: "textmode-export-svg-draw-mode", options: [{ value: "fill", label: "fill" }, { value: "stroke", label: "stroke" }], defaultValue: "fill" }));
2039
- strokeWidth = this._manageComponent(new G({ defaultValue: "1", attributes: { min: "0", step: "0.1" } }));
2157
+ class ar extends J {
2040
2158
  constructor(t) {
2041
2159
  super(t);
2160
+ p(this, "includeBackground", this._manageComponent(new nt({ id: "textmode-export-svg-include-backgrounds", label: "include cell backgrounds", defaultChecked: !0 })));
2161
+ p(this, "drawMode", this._manageComponent(new st({ id: "textmode-export-svg-draw-mode", options: [{ value: "fill", label: "fill" }, { value: "stroke", label: "stroke" }], defaultValue: "fill" })));
2162
+ p(this, "strokeWidth", this._manageComponent(new z({ defaultValue: "1", attributes: { min: "0", step: "0.1" } })));
2042
2163
  }
2043
2164
  render() {
2044
2165
  const t = document.createElement("div");
2045
2166
  t.classList.add(b.stack), this.includeBackground.mount(t);
2046
- const e = new j("row");
2167
+ const e = new Y("row");
2047
2168
  e.mount(t);
2048
- const r = new P({ label: "draw mode", labelFor: "textmode-export-svg-draw-mode", variant: "compact" });
2049
- r.mount(e.root), this.drawMode.mount(r.root);
2050
- const a = new P({ label: "stroke width", labelFor: "textmode-export-svg-stroke-width", variant: "compact" });
2051
- return a.mount(e.root), this.strokeWidth.mount(a.root), this.strokeWidth.inputElement.id = "textmode-export-svg-stroke-width", this.drawMode.selectElement.addEventListener("change", () => this.updateStrokeControls()), this.updateStrokeControls(), t;
2169
+ const a = new O({ label: "draw mode", labelFor: "textmode-export-svg-draw-mode", variant: "compact" });
2170
+ a.mount(e.root), this.drawMode.mount(a.root);
2171
+ const o = new O({ label: "stroke width", labelFor: "textmode-export-svg-stroke-width", variant: "compact" });
2172
+ return o.mount(e.root), this.strokeWidth.mount(o.root), this.strokeWidth.inputElement.id = "textmode-export-svg-stroke-width", this.drawMode.selectElement.addEventListener("change", () => this.updateStrokeControls()), this.updateStrokeControls(), t;
2052
2173
  }
2053
2174
  getOptions() {
2054
2175
  return { includeBackgroundRectangles: this.includeBackground.checked, drawMode: this.drawMode.value, strokeWidth: Number.parseFloat(this.strokeWidth.value) };
@@ -2071,35 +2192,39 @@ class He extends Y {
2071
2192
  this.strokeWidth.value = String(e), this.strokeWidth.refresh();
2072
2193
  }
2073
2194
  }
2074
- const je = [{ format: "txt", label: "plain text (.txt)", supportsClipboard: !0, createBlade: () => new We({ format: "txt", label: "plain text (.txt)", supportsClipboard: !0, defaultOptions: { preserveTrailingSpaces: !1, emptyCharacter: " " } }) }, { format: "image", label: "image (.png / .jpg / .webp)", supportsClipboard: !0, createBlade: () => new qe({ format: "image", label: "image (.png / .jpg / .webp)", supportsClipboard: !0, defaultOptions: { format: "png", scale: 1 } }) }, { format: "svg", label: "vector (.svg)", supportsClipboard: !0, createBlade: () => new He({ format: "svg", label: "vector (.svg)", supportsClipboard: !0, defaultOptions: { includeBackgroundRectangles: !0, drawMode: "fill", strokeWidth: 1 } }) }, { format: "gif", label: "animated GIF (.gif)", supportsClipboard: !1, createBlade: () => new ut({ format: "gif", label: "animated GIF (.gif)", supportsClipboard: !1, defaultOptions: { frameCount: 300, frameRate: 60, scale: 1, repeat: 0 } }) }, { format: "video", label: "video (.webm)", supportsClipboard: !1, createBlade: () => new pt({ format: "video", label: "video (.webm)", supportsClipboard: !1, defaultOptions: { frameCount: 480, frameRate: 60, quality: 0.7 } }) }];
2075
- function Qe() {
2076
- return je;
2195
+ const or = [{ format: "txt", label: "plain text (.txt)", supportsClipboard: !0, createBlade: () => new tr({ format: "txt", label: "plain text (.txt)", supportsClipboard: !0, defaultOptions: { preserveTrailingSpaces: !1, emptyCharacter: " " } }) }, { format: "json", label: "layer data (.json)", supportsClipboard: !0, createBlade: () => new er({ format: "json", label: "layer data (.json)", supportsClipboard: !0, defaultOptions: { pretty: !0, includeMetadata: !0, colorMode: "hex" } }) }, { format: "image", label: "image (.png / .jpg / .webp)", supportsClipboard: !0, createBlade: () => new rr({ format: "image", label: "image (.png / .jpg / .webp)", supportsClipboard: !0, defaultOptions: { format: "png", scale: 1 } }) }, { format: "svg", label: "vector (.svg)", supportsClipboard: !0, createBlade: () => new ar({ format: "svg", label: "vector (.svg)", supportsClipboard: !0, defaultOptions: { includeBackgroundRectangles: !0, drawMode: "fill", strokeWidth: 1 } }) }, { format: "gif", label: "animated GIF (.gif)", supportsClipboard: !1, createBlade: () => new bt({ format: "gif", label: "animated GIF (.gif)", supportsClipboard: !1, defaultOptions: { frameCount: 300, frameRate: 60, scale: 1, repeat: 0 } }) }, { format: "video", label: "video (.webm)", supportsClipboard: !1, createBlade: () => new vt({ format: "video", label: "video (.webm)", supportsClipboard: !1, defaultOptions: { frameCount: 480, frameRate: 60, quality: 0.7 } }) }];
2196
+ function ir() {
2197
+ return or;
2077
2198
  }
2078
- function Xe(n, t) {
2079
- const e = Qe(), r = e[0]?.format, a = new Ne(Ge(r)), i = new Ue(), s = new Re(n, t, a, i, e);
2199
+ function nr(i, r) {
2200
+ var d;
2201
+ const t = ir(), e = (d = t[0]) == null ? void 0 : d.format, a = new Qe(Ke(e)), o = new Ye(), s = new Xe(i, r, a, o, t);
2080
2202
  return s.$mount(), s;
2081
2203
  }
2082
- const zt = { name: "textmode.export", version: "1.2.1", async install(n, t) {
2083
- const e = { saveCanvas: async (l = {}) => new bt().$saveImage(n.canvas, l), copyCanvas: async (l = {}) => new bt().$copyImageToClipboard(n.canvas, l), saveSVG: (l = {}) => {
2084
- new gt().$saveSVG(n, l);
2085
- }, saveStrings: (l = {}) => {
2086
- new vt().$saveTXT(n, l);
2087
- }, toSVG: (l = {}) => new gt().$generateSVG(n, l), toString: (l = {}) => new vt().$generateTXT(n, l), saveGIF: async (l = {}) => new fe(n, t.registerPostDrawHook).$saveGIF(l), saveWEBM: async (l = {}) => new Ee(n, t.registerPostDrawHook).$saveWEBM(l) }, r = Xe(n, e), a = { show: () => r.show(), hide: () => r.hide(), toggle: () => r.toggle(), isVisible: () => r.isVisible() }, i = { ...e, exportOverlay: a }, s = n;
2088
- Object.assign(s, i), s._exportOverlayController = r;
2089
- }, async uninstall(n) {
2090
- const t = n;
2091
- t._exportOverlayController?.$dispose(), delete t._exportOverlayController;
2092
- const r = ["exportOverlay", "saveCanvas", "copyCanvas", "saveSVG", "saveStrings", "toSVG", "toString", "saveGIF", "saveWEBM"];
2093
- for (const a of r) delete t[a];
2094
- } }, Ye = (n = {}) => {
2095
- const t = n.overlay ?? !0, e = { ...zt }, r = e.install;
2096
- return e.install = async (a, i) => {
2204
+ const Jt = { name: "textmode.export", version: "1.2.1", async install(i, r) {
2205
+ const t = { saveCanvas: async (d = {}) => new Et().$saveImage(i.canvas, d), copyCanvas: async (d = {}) => new Et().$copyImageToClipboard(i.canvas, d), saveSVG: (d = {}) => {
2206
+ new Ct().$saveSVG(i, d);
2207
+ }, saveStrings: (d = {}) => {
2208
+ new kt().$saveTXT(i, d);
2209
+ }, toSVG: (d = {}) => new Ct().$generateSVG(i, d), toString: (d = {}) => new kt().$generateTXT(i, d), toJSON: (d = {}) => new mt().$generateJSONData(i, d), toJSONString: (d = {}) => new mt().$generateJSONString(i, d), saveJSON: (d = {}) => {
2210
+ new mt().$saveJSON(i, d);
2211
+ }, saveGIF: async (d = {}) => new Ce(i, r.registerPostDrawHook).$saveGIF(d), saveWEBM: async (d = {}) => new $e(i, r.registerPostDrawHook).$saveWEBM(d) }, e = nr(i, t), a = { show: () => e.show(), hide: () => e.hide(), toggle: () => e.toggle(), isVisible: () => e.isVisible() }, o = { ...t, exportOverlay: a }, s = i;
2212
+ Object.assign(s, o), s._exportOverlayController = e;
2213
+ }, async uninstall(i) {
2214
+ const r = i, t = r._exportOverlayController;
2215
+ t == null || t.$dispose(), delete r._exportOverlayController;
2216
+ const e = ["exportOverlay", "saveCanvas", "copyCanvas", "saveSVG", "saveStrings", "toSVG", "toString", "toJSON", "toJSONString", "saveJSON", "saveGIF", "saveWEBM"];
2217
+ for (const a of e) delete r[a];
2218
+ } }, sr = (i = {}) => {
2219
+ const r = i.overlay ?? !0, t = { ...Jt }, e = t.install;
2220
+ return t.install = async (a, o) => {
2221
+ var d;
2097
2222
  const s = a;
2098
- await r.call(e, s, i), t || s.exportOverlay?.hide();
2099
- }, e;
2223
+ await e.call(t, s, o), r || ((d = s.exportOverlay) == null || d.hide());
2224
+ }, t;
2100
2225
  };
2101
- typeof window < "u" && (window.ExportPlugin = zt, window.createTextmodeExportPlugin = Ye);
2226
+ typeof window < "u" && (window.ExportPlugin = Jt, window.createTextmodeExportPlugin = sr);
2102
2227
  export {
2103
- zt as ExportPlugin,
2104
- Ye as createTextmodeExportPlugin
2228
+ Jt as ExportPlugin,
2229
+ sr as createTextmodeExportPlugin
2105
2230
  };