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