textmode.export.js 1.3.0 → 1.4.0

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