textmode.export.js 1.2.2 → 1.3.0-beta.1

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