@editora/core 1.0.24 → 1.0.26

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 (30) hide show
  1. package/dist/{CodePlugin.native-BRBEIqY7.mjs → CodePlugin.native-DNJmRGdT.mjs} +107 -93
  2. package/dist/{CodePlugin.native-CPfKDrkr.mjs → CodePlugin.native-DhLs8BoM.mjs} +43 -29
  3. package/dist/CommentsPlugin.native-CxdTwTGE.mjs +2101 -0
  4. package/dist/{DocumentManagerPlugin.native-tZqIa9o5.mjs → DocumentManagerPlugin.native-CaBqCH-p.mjs} +4 -4
  5. package/dist/MediaManagerPlugin.native-0YFHZfsb.mjs +4823 -0
  6. package/dist/MediaManagerPlugin.native-mXWWARRX.mjs +4908 -0
  7. package/dist/confirmDialog-CNqPHT5x.mjs +92 -0
  8. package/dist/{documentManager-8gnG-uG_.mjs → documentManager-DHLCoWzw.mjs} +490 -509
  9. package/dist/editora.min.js +2 -2
  10. package/dist/editora.umd.js +2 -2
  11. package/dist/index-DHPPVQwx.js +12 -0
  12. package/dist/{index-BICrB5kg.mjs → index-gI4djib2.mjs} +11 -2
  13. package/dist/index.cjs.js +1 -1
  14. package/dist/index.esm.js +2 -2
  15. package/dist/plugin-loader.js +3 -3
  16. package/dist/shared-config-DuA34Iii.mjs +26 -0
  17. package/dist/webcomponent-core.js +11 -2
  18. package/dist/webcomponent-core.min.css +1 -1
  19. package/dist/webcomponent-core.min.js +19 -20
  20. package/dist/webcomponent.cjs.js +1 -1
  21. package/dist/webcomponent.esm.js +1 -1
  22. package/dist/webcomponent.js +82 -73
  23. package/dist/webcomponent.min.css +1 -1
  24. package/dist/webcomponent.min.js +3345 -1655
  25. package/package.json +12 -30
  26. package/dist/CommentsPlugin.native-DHCDUm9f.mjs +0 -809
  27. package/dist/MediaManagerPlugin.native-BjrEarV6.mjs +0 -1161
  28. package/dist/MediaManagerPlugin.native-CRi24Mrb.mjs +0 -1057
  29. package/dist/confirmDialog-BP8hZPpX.mjs +0 -112
  30. package/dist/index--wO0CZVN.js +0 -12
@@ -0,0 +1,4823 @@
1
+ import { g as ji, b as Vi, a as Ki } from "./shared-config-DuA34Iii.mjs";
2
+ import { i as Gi } from "./dialogHelpers-Dzn8DHoF.mjs";
3
+ import { c as Et } from "./confirmDialog-CNqPHT5x.mjs";
4
+ import { r as Ge } from "./historyHelpers-B0-4mq1E.mjs";
5
+ import { e as bt } from "./escapeHtml-CX8RelZ1.mjs";
6
+ import { n as Dt } from "./notify-DCQGpmq-.mjs";
7
+ const At = {
8
+ upload: "/media/upload",
9
+ library: "/media/library",
10
+ delete: "/media/library"
11
+ }, Yi = [
12
+ "image/jpeg",
13
+ "image/png",
14
+ "image/gif",
15
+ "image/webp",
16
+ "image/avif",
17
+ "video/mp4",
18
+ "video/webm",
19
+ "video/ogg",
20
+ "audio/mpeg",
21
+ "audio/wav",
22
+ "audio/ogg",
23
+ "audio/mp4",
24
+ "audio/aac",
25
+ "audio/webm"
26
+ ], Xi = 10 * 1024 * 1024, Zi = {
27
+ apiEndpoints: { ...At },
28
+ maxFileSize: Xi,
29
+ allowedTypes: [...Yi],
30
+ headers: {}
31
+ };
32
+ let Nt = { ...Zi };
33
+ function Ct() {
34
+ return { ...Nt, apiEndpoints: { ...At, ...Nt.apiEndpoints } };
35
+ }
36
+ function q(t) {
37
+ const e = Ct();
38
+ return t ? {
39
+ ...e,
40
+ ...t,
41
+ apiEndpoints: { ...e.apiEndpoints, ...t.apiEndpoints },
42
+ headers: { ...e.headers, ...t.headers }
43
+ } : e;
44
+ }
45
+ function lt(t, e = Ct()) {
46
+ var r, n;
47
+ const i = (r = e.apiUrl) != null ? r : ji().apiUrl;
48
+ return Vi(i, ((n = e.apiEndpoints) != null ? n : At)[t]);
49
+ }
50
+ function Qi(t = Ct()) {
51
+ return { ...Ki(), ...t.headers || {} };
52
+ }
53
+ class N extends Error {
54
+ constructor(e, i, r) {
55
+ super(i), this.name = e === "aborted" ? "AbortError" : "MediaUploadError", this.code = e, this.status = r;
56
+ }
57
+ }
58
+ const Ze = (t) => t instanceof Error && (t.name === "AbortError" || t.code === "aborted"), Ye = (t) => t.startsWith("image/") ? "image" : t.startsWith("video/") ? "video" : t.startsWith("audio/") ? "audio" : "file";
59
+ let Ji = 0;
60
+ const Lt = () => `media-${Date.now().toString(36)}-${(Ji++).toString(36)}`, ni = () => ({
61
+ name: "base64",
62
+ upload(t, { signal: e, onProgress: i } = {}) {
63
+ return new Promise((r, n) => {
64
+ if (e != null && e.aborted) {
65
+ n(new N("aborted", "Upload cancelled"));
66
+ return;
67
+ }
68
+ const o = new FileReader(), s = () => o.abort();
69
+ e == null || e.addEventListener("abort", s, { once: !0 });
70
+ const a = () => e == null ? void 0 : e.removeEventListener("abort", s);
71
+ o.onprogress = (l) => {
72
+ l.lengthComputable && (i == null || i({ loaded: l.loaded, total: l.total, fraction: l.loaded / l.total }));
73
+ }, o.onload = () => {
74
+ a(), i == null || i({ loaded: t.size, total: t.size, fraction: 1 }), r({
75
+ id: Lt(),
76
+ name: t.name,
77
+ type: Ye(t.type),
78
+ src: o.result,
79
+ size: t.size,
80
+ mime: t.type,
81
+ createdAt: Date.now(),
82
+ metadata: {}
83
+ });
84
+ }, o.onerror = () => {
85
+ a(), n(new N("network", `Couldn't read ${t.name || "the file"}.`));
86
+ }, o.onabort = () => {
87
+ a(), n(new N("aborted", "Upload cancelled"));
88
+ }, o.readAsDataURL(t);
89
+ });
90
+ }
91
+ }), er = (t) => ({
92
+ name: "callback",
93
+ async upload(e, i = {}) {
94
+ var s, a, l;
95
+ if ((s = i.signal) != null && s.aborted) throw new N("aborted", "Upload cancelled");
96
+ const r = new Promise((d, c) => {
97
+ var p;
98
+ (p = i.signal) == null || p.addEventListener("abort", () => c(new N("aborted", "Upload cancelled")), {
99
+ once: !0
100
+ });
101
+ });
102
+ let n;
103
+ try {
104
+ n = await Promise.race([t(e, i), r]);
105
+ } catch (d) {
106
+ throw d instanceof N ? d : new N(
107
+ "server",
108
+ d instanceof Error && d.message ? d.message : `Couldn't upload ${e.name || "the file"}.`
109
+ );
110
+ }
111
+ const o = typeof n == "string" ? { url: n } : n;
112
+ if (!o || typeof o.url != "string" || !o.url)
113
+ throw new N("invalid-response", "The upload finished, but the server sent back no URL.");
114
+ return {
115
+ id: (a = o.id) != null ? a : Lt(),
116
+ name: (l = o.name) != null ? l : e.name,
117
+ type: Ye(e.type),
118
+ src: o.url,
119
+ size: e.size,
120
+ width: o.width,
121
+ height: o.height,
122
+ mime: e.type,
123
+ createdAt: Date.now(),
124
+ metadata: {},
125
+ thumbnailUrl: o.thumbnailUrl
126
+ };
127
+ }
128
+ }), tr = "editora-media-library", dt = "items", Ut = 60, ir = 8 * 1024 * 1024, rr = 240, nr = () => {
129
+ const t = /* @__PURE__ */ new Map();
130
+ return {
131
+ all: async () => [...t.values()],
132
+ put: async (e) => {
133
+ t.set(e.id, e);
134
+ },
135
+ remove: async (e) => {
136
+ t.delete(e);
137
+ }
138
+ };
139
+ }, or = (t) => new Promise((e, i) => {
140
+ t.onsuccess = () => e(t.result), t.onerror = () => i(t.error);
141
+ }), ar = () => {
142
+ if (typeof indexedDB == "undefined") return null;
143
+ let t = null;
144
+ const e = () => t != null ? t : t = new Promise((r, n) => {
145
+ const o = indexedDB.open(tr, 1);
146
+ o.onupgradeneeded = () => o.result.createObjectStore(dt, { keyPath: "id" }), o.onsuccess = () => r(o.result), o.onerror = () => n(o.error), o.onblocked = () => n(new Error("blocked"));
147
+ }), i = async (r, n) => {
148
+ const o = await e();
149
+ return or(n(o.transaction(dt, r).objectStore(dt)));
150
+ };
151
+ return {
152
+ all: () => i("readonly", (r) => r.getAll()),
153
+ put: async (r) => {
154
+ await i("readwrite", (n) => n.put(r));
155
+ },
156
+ remove: async (r) => {
157
+ await i("readwrite", (n) => n.delete(r));
158
+ }
159
+ };
160
+ }, sr = () => {
161
+ const t = ar(), e = nr();
162
+ if (!t) return e;
163
+ let i = !1;
164
+ const r = async (n) => {
165
+ if (!i)
166
+ try {
167
+ return await n(t);
168
+ } catch (o) {
169
+ i = !0;
170
+ }
171
+ return n(e);
172
+ };
173
+ return {
174
+ all: () => r((n) => n.all()),
175
+ put: (n) => r((o) => o.put(n)),
176
+ remove: (n) => r((o) => o.remove(n))
177
+ };
178
+ };
179
+ let He = null;
180
+ const he = () => He != null ? He : He = sr(), lr = (t) => new Promise((e) => {
181
+ if (typeof document == "undefined" || typeof Image == "undefined") return e(null);
182
+ const i = new Image(), r = window.setTimeout(() => e(null), 4e3);
183
+ i.onload = () => {
184
+ window.clearTimeout(r);
185
+ try {
186
+ const n = Math.min(1, rr / Math.max(i.naturalWidth, i.naturalHeight, 1));
187
+ if (n >= 1) return e(null);
188
+ const o = document.createElement("canvas");
189
+ o.width = Math.max(1, Math.round(i.naturalWidth * n)), o.height = Math.max(1, Math.round(i.naturalHeight * n));
190
+ const s = o.getContext("2d");
191
+ if (!s) return e(null);
192
+ s.drawImage(i, 0, 0, o.width, o.height), e(o.toDataURL("image/jpeg", 0.8));
193
+ } catch (n) {
194
+ e(null);
195
+ }
196
+ }, i.onerror = () => {
197
+ window.clearTimeout(r), e(null);
198
+ }, i.src = t;
199
+ }), dr = async (t) => {
200
+ if (t.src.length > ir || t.type === "file") return;
201
+ const e = { ...t, metadata: { ...t.metadata, local: !0 } };
202
+ try {
203
+ await he().put(e);
204
+ const i = await he().all();
205
+ if (i.length > Ut) {
206
+ const r = i.sort((n, o) => n.createdAt - o.createdAt).slice(0, i.length - Ut);
207
+ await Promise.all(r.map((n) => he().remove(n.id)));
208
+ }
209
+ t.type === "image" && !t.thumbnailUrl && lr(t.src).then((r) => r ? he().put({ ...e, thumbnailUrl: r }) : void 0).catch(() => {
210
+ });
211
+ } catch (i) {
212
+ }
213
+ }, oi = /* @__PURE__ */ Symbol("editora.localLibrary"), cr = (t) => t[oi] === !0, pr = (t) => typeof t.list == "function" ? t : {
214
+ [oi]: !0,
215
+ name: t.name,
216
+ upload: async (i, r) => {
217
+ const n = await t.upload(i, r);
218
+ return await dr(n), n;
219
+ },
220
+ async list(i = {}) {
221
+ var a, l, d;
222
+ const r = ((a = i.search) != null ? a : "").trim().toLowerCase(), n = (await he().all()).filter((c) => {
223
+ var p;
224
+ return (!i.type || c.type === i.type) && (!r || `${c.name} ${(p = c.alt) != null ? p : ""}`.toLowerCase().includes(r));
225
+ }).sort((c, p) => i.sort === "oldest" ? c.createdAt - p.createdAt : i.sort === "name" ? c.name.localeCompare(p.name) : p.createdAt - c.createdAt), o = (l = i.limit) != null ? l : 24, s = (d = i.page) != null ? d : 1;
226
+ return { items: n.slice((s - 1) * o, s * o), total: n.length };
227
+ },
228
+ async update(i, r) {
229
+ const n = (await he().all()).find((o) => o.id === i);
230
+ n && await he().put({ ...n, ...r.name !== void 0 ? { name: r.name } : {}, ...r.alt !== void 0 ? { alt: r.alt } : {} });
231
+ },
232
+ delete: (i) => he().remove(i)
233
+ }, Fe = (t) => {
234
+ const e = typeof t == "string" ? Number(t) : t;
235
+ return typeof e == "number" && Number.isFinite(e) && e > 0 ? e : void 0;
236
+ }, Ot = (t, e) => {
237
+ var n, o, s, a, l, d, c, p, u, f, m, b, v, y, z, C, w, E;
238
+ const i = (o = (n = t == null ? void 0 : t.url) != null ? n : t == null ? void 0 : t.src) != null ? o : t == null ? void 0 : t.location;
239
+ if (typeof i != "string" || !i)
240
+ throw new N("invalid-response", "The upload finished, but the server sent back no URL.");
241
+ const r = (d = (l = (a = (s = t.mimeType) != null ? s : t.mime) != null ? a : t.mime_type) != null ? l : e == null ? void 0 : e.type) != null ? d : "";
242
+ return {
243
+ id: String((c = t.id) != null ? c : Lt()),
244
+ name: (b = (m = (f = (u = (p = t.name) != null ? p : t.originalName) != null ? u : t.original_filename) != null ? f : t.filename) != null ? m : e == null ? void 0 : e.name) != null ? b : "",
245
+ // What was sent is known better than what a server says it stored (a server that knows only images and
246
+ // videos files audio under one of them); a listing has no file, and goes by the server.
247
+ type: e != null && e.type ? Ye(e.type) : t.type === "image" || t.type === "video" || t.type === "audio" || t.type === "file" ? t.type : Ye(r),
248
+ src: i,
249
+ size: (y = (v = Fe(t.size)) != null ? v : e == null ? void 0 : e.size) != null ? y : 0,
250
+ width: Fe(t.width),
251
+ height: Fe(t.height),
252
+ duration: Fe(t.duration),
253
+ mime: r,
254
+ createdAt: t.createdAt && Date.parse(t.createdAt) || Date.now(),
255
+ metadata: t.metadata && typeof t.metadata == "object" ? t.metadata : {},
256
+ thumbnailUrl: (C = (z = t.thumbnailUrl) != null ? z : t.thumbnail_url) != null ? C : void 0,
257
+ alt: typeof ((w = t.alt) != null ? w : t.alt_text) == "string" ? (E = t.alt) != null ? E : t.alt_text : void 0
258
+ };
259
+ }, Bt = (t) => {
260
+ var e;
261
+ try {
262
+ const i = JSON.parse(t.responseText), r = (e = i == null ? void 0 : i.error) != null ? e : i == null ? void 0 : i.message;
263
+ if (typeof r == "string" && r) return r;
264
+ if (r != null && r.message) return String(r.message);
265
+ } catch (i) {
266
+ }
267
+ return t.status === 413 ? "The file is too large for the server." : t.status === 401 || t.status === 403 ? "You're not allowed to upload here." : `The server couldn't take the file (${t.status}).`;
268
+ }, ur = (t) => {
269
+ const e = () => {
270
+ var o, s;
271
+ return (s = (o = t.headers) == null ? void 0 : o.call(t)) != null ? s : {};
272
+ }, i = (o, s) => `${o.replace(/\/$/, "")}/${encodeURIComponent(s)}`, r = async (o, s) => {
273
+ let a;
274
+ try {
275
+ a = await fetch(o, {
276
+ credentials: t.withCredentials ? "include" : "same-origin",
277
+ ...s,
278
+ headers: { ...e(), ...s.headers }
279
+ });
280
+ } catch (l) {
281
+ throw (l == null ? void 0 : l.name) === "AbortError" ? new N("aborted", "Request cancelled") : new N("network", "Couldn't reach the media server.");
282
+ }
283
+ if (!a.ok)
284
+ throw new N("server", Bt({ status: a.status, responseText: await a.text() }), a.status);
285
+ return a;
286
+ }, n = {
287
+ name: "rest",
288
+ upload(o, { signal: s, onProgress: a } = {}) {
289
+ return new Promise((l, d) => {
290
+ if (s != null && s.aborted) {
291
+ d(new N("aborted", "Upload cancelled"));
292
+ return;
293
+ }
294
+ const c = new XMLHttpRequest();
295
+ c.open("POST", t.uploadUrl), c.withCredentials = !!t.withCredentials;
296
+ for (const [m, b] of Object.entries(e()))
297
+ m.toLowerCase() !== "content-type" && c.setRequestHeader(m, b);
298
+ const p = () => c.abort();
299
+ s == null || s.addEventListener("abort", p, { once: !0 });
300
+ const u = () => s == null ? void 0 : s.removeEventListener("abort", p);
301
+ c.upload.onprogress = (m) => {
302
+ m.lengthComputable && (a == null || a({ loaded: m.loaded, total: m.total, fraction: m.total ? m.loaded / m.total : 0 }));
303
+ }, c.onload = () => {
304
+ if (u(), c.status < 200 || c.status >= 300) {
305
+ d(new N("server", Bt(c), c.status));
306
+ return;
307
+ }
308
+ try {
309
+ const m = Ot(JSON.parse(c.responseText), o);
310
+ a == null || a({ loaded: o.size, total: o.size, fraction: 1 }), l(m);
311
+ } catch (m) {
312
+ d(
313
+ m instanceof N ? m : new N("invalid-response", "The server answered, but not in a form the editor can read.")
314
+ );
315
+ }
316
+ }, c.onerror = () => {
317
+ u(), d(new N("network", "Couldn't reach the media server. Check your connection and try again."));
318
+ }, c.ontimeout = c.onerror, c.onabort = () => {
319
+ u(), d(new N("aborted", "Upload cancelled"));
320
+ };
321
+ const f = new FormData();
322
+ f.append(t.fieldName || "file", o, o.name), c.send(f);
323
+ });
324
+ }
325
+ };
326
+ if (t.libraryUrl) {
327
+ const o = t.libraryUrl;
328
+ n.list = async (a = {}, l = {}) => {
329
+ var f, m;
330
+ const d = new URLSearchParams();
331
+ a.page && d.set("page", String(a.page)), a.limit && d.set("limit", String(a.limit)), a.search && d.set("q", a.search), a.type && d.set("type", a.type), a.sort && d.set("sort", a.sort), a.folderId && d.set("folder_id", a.folderId);
332
+ const c = d.toString() ? `${o}${o.includes("?") ? "&" : "?"}${d}` : o, p = await (await r(c, { signal: l.signal })).json(), u = Array.isArray(p) ? p : (f = p == null ? void 0 : p.items) != null ? f : [];
333
+ return { items: u.map((b) => Ot(b)), total: Number((m = p == null ? void 0 : p.total) != null ? m : u.length) };
334
+ }, n.update = async (a, l) => {
335
+ const d = {};
336
+ l.name !== void 0 && (d.title = l.name), l.alt !== void 0 && (d.alt_text = l.alt), await r(i(o, a), {
337
+ method: "PATCH",
338
+ headers: { "Content-Type": "application/json" },
339
+ body: JSON.stringify(d)
340
+ });
341
+ };
342
+ const s = t.deleteUrl || o;
343
+ n.delete = async (a) => {
344
+ await r(i(s, a), { method: "DELETE" });
345
+ };
346
+ }
347
+ return n;
348
+ }, ai = (t = q()) => {
349
+ const e = hr(t);
350
+ return t.localLibrary === !1 ? e : pr(e);
351
+ }, hr = (t) => {
352
+ if (t.provider) return t.provider;
353
+ if (t.uploadHandler) return er(t.uploadHandler);
354
+ const e = lt("upload", t);
355
+ return e ? ur({
356
+ uploadUrl: e,
357
+ libraryUrl: lt("library", t),
358
+ deleteUrl: lt("delete", t),
359
+ headers: () => Qi(t),
360
+ withCredentials: t.withCredentials,
361
+ fieldName: t.uploadFieldName
362
+ }) : ni();
363
+ }, si = '[data-theme="dark"], .dark, .editora-theme-dark', Me = () => {
364
+ if (typeof document == "undefined" || document.getElementById("rte-media-dialog-styles")) return;
365
+ const t = document.createElement("style");
366
+ t.id = "rte-media-dialog-styles", t.textContent = `
367
+ .rte-media-overlay {
368
+ --rte-media-overlay-bg: rgba(15, 23, 36, 0.56);
369
+ --rte-media-bg: #ffffff;
370
+ --rte-media-text: #101828;
371
+ --rte-media-muted: #5f6b7d;
372
+ --rte-media-border: #d6dbe4;
373
+ --rte-media-surface: #f7f9fc;
374
+ --rte-media-surface-hover: #eef2f7;
375
+ --rte-media-accent: #1560e8;
376
+ --rte-media-primary: #101828;
377
+ --rte-media-primary-hover: #2a3345;
378
+ --rte-media-primary-text: #ffffff;
379
+ --rte-media-accent-hover: #165fd6;
380
+ --rte-media-danger: #dc3545;
381
+ --rte-media-danger-hover: #b92735;
382
+ --rte-media-danger-text: #b92735;
383
+ --rte-media-ring: rgba(31, 117, 254, 0.18);
384
+ position: fixed;
385
+ top: 0;
386
+ left: 0;
387
+ right: 0;
388
+ bottom: 0;
389
+ background: var(--rte-media-overlay-bg);
390
+ backdrop-filter: blur(2px);
391
+ display: flex;
392
+ align-items: center;
393
+ justify-content: center;
394
+ z-index: 99999;
395
+ padding: 16px;
396
+ box-sizing: border-box;
397
+ }
398
+
399
+ .rte-media-overlay.rte-ui-theme-dark {
400
+ --rte-media-overlay-bg: rgba(2, 8, 20, 0.72);
401
+ --rte-media-bg: #202938;
402
+ --rte-media-text: #e8effc;
403
+ --rte-media-muted: #a5b1c5;
404
+ --rte-media-border: #49566c;
405
+ --rte-media-surface: #2a3444;
406
+ --rte-media-surface-hover: #344256;
407
+ --rte-media-accent: #1f6feb;
408
+ --rte-media-accent-hover: #4598f4;
409
+ --rte-media-primary: #e8effc;
410
+ --rte-media-primary-hover: #ffffff;
411
+ --rte-media-primary-text: #101828;
412
+ --rte-media-danger: #ff7b72;
413
+ --rte-media-danger-hover: #ff645b;
414
+ --rte-media-danger-text: #ffa39d;
415
+ --rte-media-ring: rgba(88, 166, 255, 0.22);
416
+ }
417
+
418
+ .rte-media-dialog {
419
+ width: min(92vw, 640px);
420
+ max-height: 90vh;
421
+ display: flex;
422
+ flex-direction: column;
423
+ overflow: hidden;
424
+ background: var(--rte-media-bg);
425
+ color: var(--rte-media-text);
426
+ border: 1px solid var(--rte-media-border);
427
+ border-radius: 12px;
428
+ box-shadow: 0 24px 48px rgba(10, 15, 24, 0.28);
429
+ }
430
+
431
+ .rte-media-dialog.rte-media-dialog-compact {
432
+ width: min(92vw, 520px);
433
+ }
434
+
435
+ .rte-media-header {
436
+ display: flex;
437
+ align-items: center;
438
+ justify-content: space-between;
439
+ padding: 16px 20px;
440
+ border-bottom: 1px solid var(--rte-media-border);
441
+ background: linear-gradient(180deg, rgba(127, 154, 195, 0.08) 0%, rgba(127, 154, 195, 0) 100%);
442
+ }
443
+
444
+ .rte-media-title {
445
+ margin: 0;
446
+ font-size: 18px;
447
+ font-weight: 600;
448
+ color: var(--rte-media-text);
449
+ }
450
+
451
+ .rte-media-close-btn {
452
+ width: 32px;
453
+ height: 32px;
454
+ border: none;
455
+ border-radius: 8px;
456
+ background: transparent;
457
+ color: var(--rte-media-muted);
458
+ font-size: 24px;
459
+ line-height: 1;
460
+ cursor: pointer;
461
+ transition: background-color 0.16s ease, color 0.16s ease;
462
+ }
463
+
464
+ .rte-media-close-btn:hover {
465
+ background: var(--rte-media-surface-hover);
466
+ color: var(--rte-media-text);
467
+ }
468
+
469
+ .rte-media-tabs {
470
+ display: grid;
471
+ grid-template-columns: 1fr 1fr;
472
+ border-bottom: 1px solid var(--rte-media-border);
473
+ gap: 0;
474
+ }
475
+
476
+ .rte-media-tab {
477
+ border: none;
478
+ border-right: 1px solid var(--rte-media-border);
479
+ padding: 12px 14px;
480
+ background: var(--rte-media-surface);
481
+ color: var(--rte-media-muted);
482
+ font-size: 14px;
483
+ font-weight: 600;
484
+ cursor: pointer;
485
+ transition: background-color 0.16s ease, color 0.16s ease;
486
+ }
487
+
488
+ .rte-media-tab:last-child {
489
+ border-right: none;
490
+ }
491
+
492
+ .rte-media-tab:hover {
493
+ background: var(--rte-media-surface-hover);
494
+ color: var(--rte-media-text);
495
+ }
496
+
497
+ .rte-media-tab.active {
498
+ background: var(--rte-media-accent);
499
+ color: #fff;
500
+ }
501
+
502
+ .rte-media-body {
503
+ padding: 20px;
504
+ overflow-y: auto;
505
+ flex: 1;
506
+ }
507
+
508
+ .rte-media-field {
509
+ margin-bottom: 16px;
510
+ }
511
+
512
+ .rte-media-grid {
513
+ display: grid;
514
+ grid-template-columns: 1fr 1fr;
515
+ gap: 12px;
516
+ margin-bottom: 16px;
517
+ }
518
+
519
+ .rte-media-label {
520
+ display: block;
521
+ margin-bottom: 8px;
522
+ color: var(--rte-media-text);
523
+ font-size: 14px;
524
+ font-weight: 600;
525
+ }
526
+
527
+ .rte-media-input,
528
+ .rte-media-textarea {
529
+ width: 100%;
530
+ box-sizing: border-box;
531
+ padding: 10px 12px;
532
+ border: 1px solid var(--rte-media-border);
533
+ border-radius: 8px;
534
+ background: var(--rte-media-surface);
535
+ color: var(--rte-media-text);
536
+ font-size: 14px;
537
+ transition: border-color 0.16s ease, box-shadow 0.16s ease;
538
+ }
539
+
540
+ .rte-media-input::placeholder,
541
+ .rte-media-textarea::placeholder {
542
+ color: var(--rte-media-muted);
543
+ }
544
+
545
+ .rte-media-input:focus,
546
+ .rte-media-textarea:focus {
547
+ outline: none;
548
+ border-color: var(--rte-media-accent);
549
+ box-shadow: 0 0 0 3px var(--rte-media-ring);
550
+ }
551
+
552
+ .rte-media-textarea {
553
+ min-height: 92px;
554
+ resize: vertical;
555
+ font-family: inherit;
556
+ }
557
+
558
+ .rte-media-dropzone {
559
+ border: 2px dashed var(--rte-media-border);
560
+ border-radius: 12px;
561
+ padding: 36px 18px;
562
+ text-align: center;
563
+ cursor: pointer;
564
+ background: var(--rte-media-surface);
565
+ transition: border-color 0.16s ease, background-color 0.16s ease;
566
+ }
567
+
568
+ .rte-media-dropzone:hover,
569
+ .rte-media-dropzone.is-dragover {
570
+ border-color: var(--rte-media-accent);
571
+ background: var(--rte-media-surface-hover);
572
+ }
573
+
574
+ .rte-media-dropzone-icon {
575
+ font-size: 40px;
576
+ margin-bottom: 10px;
577
+ line-height: 1;
578
+ }
579
+
580
+ .rte-media-dropzone-title {
581
+ margin: 0 0 8px 0;
582
+ font-size: 16px;
583
+ font-weight: 600;
584
+ color: var(--rte-media-text);
585
+ }
586
+
587
+ .rte-media-muted {
588
+ margin: 0 0 8px 0;
589
+ color: var(--rte-media-muted);
590
+ font-size: 14px;
591
+ }
592
+
593
+ .rte-media-hint {
594
+ margin: 0;
595
+ color: var(--rte-media-muted);
596
+ font-size: 12px;
597
+ }
598
+
599
+ .rte-media-progress {
600
+ margin-top: 16px;
601
+ }
602
+
603
+ .rte-media-progress-track {
604
+ height: 8px;
605
+ border-radius: 999px;
606
+ background: var(--rte-media-surface);
607
+ overflow: hidden;
608
+ border: 1px solid var(--rte-media-border);
609
+ }
610
+
611
+ .rte-media-progress-bar {
612
+ height: 100%;
613
+ width: 0;
614
+ background: var(--rte-media-accent);
615
+ transition: width 0.3s ease;
616
+ }
617
+
618
+ .rte-media-progress-text {
619
+ margin-top: 8px;
620
+ text-align: center;
621
+ color: var(--rte-media-muted);
622
+ font-size: 13px;
623
+ }
624
+
625
+ .rte-media-progress-actions {
626
+ display: flex;
627
+ justify-content: center;
628
+ margin-top: 10px;
629
+ }
630
+
631
+ .rte-media-error {
632
+ margin: 12px 0 0;
633
+ padding: 8px 12px;
634
+ border: 1px solid var(--rte-media-danger);
635
+ border-radius: 8px;
636
+ color: var(--rte-media-danger);
637
+ font-size: 13px;
638
+ line-height: 1.4;
639
+ }
640
+
641
+ .rte-media-error[hidden] {
642
+ display: none;
643
+ }
644
+
645
+ .rte-media-preview {
646
+ border: 1px solid var(--rte-media-border);
647
+ border-radius: 10px;
648
+ padding: 10px;
649
+ text-align: center;
650
+ background: var(--rte-media-surface);
651
+ }
652
+
653
+ .rte-media-preview img,
654
+ .rte-media-preview video {
655
+ max-width: 100%;
656
+ max-height: 240px;
657
+ }
658
+
659
+ .rte-media-helper {
660
+ margin-top: 8px;
661
+ margin-bottom: 0;
662
+ font-size: 12px;
663
+ color: var(--rte-media-muted);
664
+ line-height: 1.5;
665
+ }
666
+
667
+ .rte-media-footer {
668
+ display: flex;
669
+ justify-content: flex-end;
670
+ gap: 10px;
671
+ padding: 16px 20px;
672
+ border-top: 1px solid var(--rte-media-border);
673
+ background: var(--rte-media-surface);
674
+ }
675
+
676
+ .rte-media-footer.rte-media-footer-spread {
677
+ justify-content: space-between;
678
+ align-items: center;
679
+ }
680
+
681
+ .rte-media-btn {
682
+ border-radius: 8px;
683
+ border: 1px solid transparent;
684
+ padding: 10px 16px;
685
+ font-size: 14px;
686
+ font-weight: 600;
687
+ cursor: pointer;
688
+ transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
689
+ }
690
+
691
+ .rte-media-btn-secondary {
692
+ background: var(--rte-media-bg);
693
+ border-color: var(--rte-media-border);
694
+ color: var(--rte-media-text);
695
+ }
696
+
697
+ .rte-media-btn-secondary:hover {
698
+ background: var(--rte-media-surface-hover);
699
+ }
700
+
701
+ .rte-media-btn-primary {
702
+ background: var(--rte-media-primary);
703
+ color: var(--rte-media-primary-text);
704
+ }
705
+
706
+ .rte-media-btn-primary:hover {
707
+ background: var(--rte-media-primary-hover);
708
+ }
709
+
710
+ .rte-media-btn-primary:disabled {
711
+ opacity: 0.55;
712
+ cursor: not-allowed;
713
+ }
714
+
715
+ .rte-media-btn-danger {
716
+ background: var(--rte-media-danger);
717
+ color: #fff;
718
+ }
719
+
720
+ .rte-media-btn-danger:hover {
721
+ background: var(--rte-media-danger-hover);
722
+ }
723
+
724
+ .rte-media-checkbox-label {
725
+ display: inline-flex;
726
+ align-items: center;
727
+ gap: 8px;
728
+ color: var(--rte-media-text);
729
+ font-size: 14px;
730
+ cursor: pointer;
731
+ }
732
+
733
+ .rte-media-checkbox-label input {
734
+ accent-color: var(--rte-media-accent);
735
+ }
736
+
737
+ .rte-media-actions {
738
+ display: flex;
739
+ gap: 10px;
740
+ }
741
+
742
+ .rte-media-spacer {
743
+ flex: 1;
744
+ }
745
+
746
+
747
+ /* ── The media picker ─────────────────────────────────────────────── */
748
+ .rte-media-dialog.rte-mp {
749
+ width: min(96vw, 980px);
750
+ height: min(88vh, 640px);
751
+ max-height: none;
752
+ position: relative;
753
+ border-radius: 16px;
754
+ }
755
+
756
+ .rte-mp-header {
757
+ display: flex;
758
+ align-items: center;
759
+ gap: 12px;
760
+ padding: 12px 16px;
761
+ border-bottom: 1px solid var(--rte-media-border);
762
+ }
763
+
764
+ .rte-mp-header .rte-media-title {
765
+ font-size: 16px;
766
+ flex: none;
767
+ }
768
+
769
+ .rte-mp-search {
770
+ flex: 1;
771
+ min-width: 0;
772
+ display: flex;
773
+ align-items: center;
774
+ gap: 8px;
775
+ height: 34px;
776
+ padding: 0 10px;
777
+ border: 1px solid var(--rte-media-border);
778
+ border-radius: 8px;
779
+ background: var(--rte-media-surface);
780
+ color: var(--rte-media-muted);
781
+ }
782
+
783
+ .rte-mp-search:focus-within {
784
+ border-color: var(--rte-media-accent);
785
+ box-shadow: 0 0 0 3px var(--rte-media-ring);
786
+ }
787
+
788
+ .rte-mp-search input {
789
+ flex: 1;
790
+ min-width: 0;
791
+ border: 0;
792
+ outline: 0;
793
+ background: transparent;
794
+ color: var(--rte-media-text);
795
+ font-size: 14px;
796
+ }
797
+
798
+ .rte-mp-search[hidden] {
799
+ display: none;
800
+ }
801
+
802
+ .rte-mp-spacer {
803
+ flex: 1;
804
+ }
805
+
806
+ .rte-mp-body {
807
+ flex: 1;
808
+ min-height: 0;
809
+ display: grid;
810
+ grid-template-columns: 168px minmax(0, 1fr) 272px;
811
+ }
812
+
813
+ .rte-mp.no-details .rte-mp-body {
814
+ grid-template-columns: 168px minmax(0, 1fr);
815
+ }
816
+
817
+ .rte-mp-nav {
818
+ display: flex;
819
+ flex-direction: column;
820
+ gap: 2px;
821
+ padding: 12px 8px;
822
+ border-right: 1px solid var(--rte-media-border);
823
+ background: var(--rte-media-surface);
824
+ }
825
+
826
+ .rte-mp-nav-item {
827
+ display: flex;
828
+ align-items: center;
829
+ gap: 10px;
830
+ width: 100%;
831
+ padding: 8px 10px;
832
+ border: 0;
833
+ border-radius: 8px;
834
+ background: transparent;
835
+ color: var(--rte-media-muted);
836
+ font-size: 14px;
837
+ text-align: left;
838
+ cursor: pointer;
839
+ }
840
+
841
+ .rte-mp-nav-item:hover {
842
+ background: var(--rte-media-surface-hover);
843
+ color: var(--rte-media-text);
844
+ }
845
+
846
+ .rte-mp-nav-item[aria-selected="true"] {
847
+ background: var(--rte-media-ring);
848
+ color: var(--rte-media-text);
849
+ font-weight: 600;
850
+ }
851
+
852
+ .rte-mp-nav-item[aria-selected="true"] svg {
853
+ color: var(--rte-media-accent);
854
+ }
855
+
856
+ .rte-mp-nav-item:focus-visible,
857
+ .rte-mp-chip:focus-visible,
858
+ .rte-mp-tile:focus-visible,
859
+ .rte-mp-icon-btn:focus-visible {
860
+ outline: 2px solid var(--rte-media-accent);
861
+ outline-offset: 2px;
862
+ }
863
+
864
+ .rte-mp-badge {
865
+ margin-left: auto;
866
+ min-width: 18px;
867
+ padding: 0 6px;
868
+ border-radius: 999px;
869
+ background: var(--rte-media-accent);
870
+ color: #fff;
871
+ font-size: 11px;
872
+ line-height: 18px;
873
+ text-align: center;
874
+ }
875
+
876
+ .rte-mp-main {
877
+ min-width: 0;
878
+ min-height: 0;
879
+ display: flex;
880
+ flex-direction: column;
881
+ }
882
+
883
+ .rte-mp-view {
884
+ flex: 1;
885
+ min-height: 0;
886
+ display: flex;
887
+ flex-direction: column;
888
+ }
889
+
890
+ .rte-mp-view[hidden] {
891
+ display: none;
892
+ }
893
+
894
+ .rte-mp-toolbar {
895
+ display: flex;
896
+ flex-wrap: wrap;
897
+ gap: 8px;
898
+ padding: 14px 16px 0;
899
+ }
900
+
901
+ .rte-mp-chip {
902
+ padding: 6px 16px;
903
+ border: 1px solid var(--rte-media-border);
904
+ border-radius: 999px;
905
+ background: transparent;
906
+ color: var(--rte-media-muted);
907
+ font-size: 13px;
908
+ cursor: pointer;
909
+ }
910
+
911
+ .rte-mp-chip:hover {
912
+ background: var(--rte-media-surface-hover);
913
+ }
914
+
915
+ .rte-mp-chip[aria-pressed="true"] {
916
+ background: var(--rte-media-text);
917
+ border-color: var(--rte-media-text);
918
+ color: var(--rte-media-bg);
919
+ }
920
+
921
+ .rte-mp-scroll {
922
+ flex: 1;
923
+ min-height: 0;
924
+ overflow: auto;
925
+ padding: 12px 16px 16px;
926
+ }
927
+
928
+ .rte-mp-grid {
929
+ display: grid;
930
+ grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
931
+ gap: 10px;
932
+ }
933
+
934
+ .rte-mp-tile {
935
+ position: relative;
936
+ aspect-ratio: 1;
937
+ border: 0;
938
+ border-radius: 12px;
939
+ overflow: hidden;
940
+ background: var(--rte-media-surface-hover);
941
+ color: var(--rte-media-muted);
942
+ cursor: pointer;
943
+ box-shadow: inset 0 0 0 1px var(--rte-media-border);
944
+ transition: box-shadow 0.12s ease, transform 0.12s ease;
945
+ }
946
+
947
+ .rte-mp-tile:hover {
948
+ box-shadow: inset 0 0 0 1px var(--rte-media-muted);
949
+ }
950
+
951
+ .rte-mp-tile[aria-selected="true"],
952
+ .rte-mp-tile.is-selected {
953
+ box-shadow: inset 0 0 0 3px var(--rte-media-accent);
954
+ }
955
+
956
+ .rte-mp-tile-pick {
957
+ position: absolute;
958
+ inset: 0;
959
+ border: 0;
960
+ background: transparent;
961
+ cursor: pointer;
962
+ border-radius: inherit;
963
+ }
964
+
965
+ .rte-mp-tile-pick:focus-visible {
966
+ outline: 2px solid var(--rte-media-accent);
967
+ outline-offset: -4px;
968
+ }
969
+
970
+ .rte-mp-tile img,
971
+ .rte-mp-tile video {
972
+ position: absolute;
973
+ inset: 0;
974
+ width: 100%;
975
+ height: 100%;
976
+ object-fit: cover;
977
+ display: block;
978
+ pointer-events: none;
979
+ }
980
+
981
+ .rte-mp-tile img.rte-mp-fade {
982
+ opacity: 0;
983
+ transition: opacity 0.2s ease;
984
+ }
985
+
986
+ .rte-mp-tile img.rte-mp-fade.is-loaded {
987
+ opacity: 1;
988
+ }
989
+
990
+ .rte-mp-tile img.is-broken {
991
+ display: none;
992
+ }
993
+
994
+ .rte-mp-tile-name {
995
+ position: absolute;
996
+ left: 0;
997
+ right: 0;
998
+ bottom: 0;
999
+ padding: 14px 8px 6px;
1000
+ background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.62) 100%);
1001
+ color: #fff;
1002
+ font-size: 12px;
1003
+ text-align: left;
1004
+ white-space: nowrap;
1005
+ overflow: hidden;
1006
+ text-overflow: ellipsis;
1007
+ opacity: 0;
1008
+ transition: opacity 0.12s ease;
1009
+ }
1010
+
1011
+ .rte-mp-tile:hover .rte-mp-tile-name,
1012
+ .rte-mp-tile:focus-visible .rte-mp-tile-name,
1013
+ .rte-mp-tile:focus-within .rte-mp-tile-name,
1014
+ .rte-mp-tile.is-selected .rte-mp-tile-name,
1015
+ .rte-mp-tile[aria-selected="true"] .rte-mp-tile-name {
1016
+ opacity: 1;
1017
+ }
1018
+
1019
+ .rte-mp-tile-check {
1020
+ position: absolute;
1021
+ top: 8px;
1022
+ right: 8px;
1023
+ width: 22px;
1024
+ height: 22px;
1025
+ display: none;
1026
+ align-items: center;
1027
+ justify-content: center;
1028
+ border-radius: 50%;
1029
+ background: var(--rte-media-accent);
1030
+ color: #fff;
1031
+ }
1032
+
1033
+ .rte-mp-tile[aria-selected="true"] .rte-mp-tile-check,
1034
+ .rte-mp-tile.is-selected .rte-mp-tile-check {
1035
+ display: flex;
1036
+ }
1037
+
1038
+ .rte-mp-tile-kind {
1039
+ position: absolute;
1040
+ left: 8px;
1041
+ top: 8px;
1042
+ width: 24px;
1043
+ height: 24px;
1044
+ display: flex;
1045
+ align-items: center;
1046
+ justify-content: center;
1047
+ border-radius: 50%;
1048
+ background: rgba(0, 0, 0, 0.55);
1049
+ color: #fff;
1050
+ }
1051
+
1052
+ .rte-mp-tile-icon {
1053
+ position: absolute;
1054
+ inset: 0;
1055
+ display: flex;
1056
+ align-items: center;
1057
+ justify-content: center;
1058
+ }
1059
+
1060
+ .rte-mp-tile.is-skeleton {
1061
+ cursor: default;
1062
+ animation: rte-mp-pulse 1.2s ease-in-out infinite;
1063
+ }
1064
+
1065
+ @keyframes rte-mp-pulse {
1066
+ 50% { opacity: 0.55; }
1067
+ }
1068
+
1069
+ .rte-mp-tile.is-uploading,
1070
+ .rte-mp-tile.is-failed {
1071
+ cursor: default;
1072
+ }
1073
+
1074
+ .rte-mp-progress {
1075
+ position: absolute;
1076
+ left: 0;
1077
+ right: 0;
1078
+ bottom: 0;
1079
+ height: 4px;
1080
+ background: rgba(0, 0, 0, 0.35);
1081
+ }
1082
+
1083
+ .rte-mp-progress > span {
1084
+ display: block;
1085
+ height: 100%;
1086
+ width: 0;
1087
+ background: var(--rte-media-accent);
1088
+ transition: width 0.15s ease;
1089
+ }
1090
+
1091
+ .rte-mp-tile-status {
1092
+ position: absolute;
1093
+ inset: 0;
1094
+ display: flex;
1095
+ flex-direction: column;
1096
+ align-items: center;
1097
+ justify-content: center;
1098
+ gap: 6px;
1099
+ padding: 8px;
1100
+ background: rgba(0, 0, 0, 0.45);
1101
+ color: #fff;
1102
+ font-size: 12px;
1103
+ text-align: center;
1104
+ line-height: 1.3;
1105
+ }
1106
+
1107
+ .rte-mp-tile.is-failed .rte-mp-tile-status {
1108
+ background: rgba(120, 20, 28, 0.82);
1109
+ }
1110
+
1111
+ .rte-mp-tile-actions {
1112
+ position: absolute;
1113
+ top: 6px;
1114
+ right: 6px;
1115
+ display: flex;
1116
+ gap: 4px;
1117
+ }
1118
+
1119
+ .rte-mp-icon-btn {
1120
+ width: 26px;
1121
+ height: 26px;
1122
+ display: inline-flex;
1123
+ align-items: center;
1124
+ justify-content: center;
1125
+ border: 0;
1126
+ border-radius: 50%;
1127
+ background: rgba(0, 0, 0, 0.62);
1128
+ color: #fff;
1129
+ cursor: pointer;
1130
+ }
1131
+
1132
+ .rte-mp-icon-btn:hover {
1133
+ background: rgba(0, 0, 0, 0.82);
1134
+ }
1135
+
1136
+ .rte-mp-more {
1137
+ display: block;
1138
+ margin: 14px auto 0;
1139
+ }
1140
+
1141
+ .rte-mp-empty,
1142
+ .rte-mp-error {
1143
+ display: flex;
1144
+ flex-direction: column;
1145
+ align-items: center;
1146
+ justify-content: center;
1147
+ gap: 8px;
1148
+ min-height: 240px;
1149
+ padding: 24px;
1150
+ text-align: center;
1151
+ color: var(--rte-media-muted);
1152
+ }
1153
+
1154
+ .rte-mp-empty strong,
1155
+ .rte-mp-error strong {
1156
+ color: var(--rte-media-text);
1157
+ font-size: 15px;
1158
+ }
1159
+
1160
+ .rte-mp-error {
1161
+ color: var(--rte-media-danger);
1162
+ }
1163
+
1164
+ .rte-mp-dropzone {
1165
+ display: flex;
1166
+ flex-direction: column;
1167
+ align-items: center;
1168
+ justify-content: center;
1169
+ gap: 4px;
1170
+ padding: 28px 16px;
1171
+ border: 2px dashed var(--rte-media-border);
1172
+ border-radius: 14px;
1173
+ background: var(--rte-media-surface);
1174
+ color: var(--rte-media-muted);
1175
+ text-align: center;
1176
+ cursor: pointer;
1177
+ transition: border-color 0.12s ease, background 0.12s ease;
1178
+ }
1179
+
1180
+ .rte-mp-dropzone:hover,
1181
+ .rte-mp-dropzone.is-dragover {
1182
+ border-color: var(--rte-media-accent);
1183
+ background: var(--rte-media-ring);
1184
+ }
1185
+
1186
+ .rte-mp-dropzone:focus-visible {
1187
+ outline: 2px solid var(--rte-media-accent);
1188
+ outline-offset: 2px;
1189
+ }
1190
+
1191
+ .rte-mp-dropzone strong {
1192
+ color: var(--rte-media-text);
1193
+ font-size: 15px;
1194
+ }
1195
+
1196
+ .rte-mp-dropzone-icon {
1197
+ color: var(--rte-media-accent);
1198
+ margin-bottom: 4px;
1199
+ }
1200
+
1201
+ .rte-mp-queue {
1202
+ margin: 16px 0 0;
1203
+ padding: 0;
1204
+ list-style: none;
1205
+ }
1206
+
1207
+ .rte-mp-drop-veil {
1208
+ position: absolute;
1209
+ inset: 0;
1210
+ z-index: 5;
1211
+ display: none;
1212
+ align-items: center;
1213
+ justify-content: center;
1214
+ border-radius: inherit;
1215
+ background: var(--rte-media-ring);
1216
+ border: 3px dashed var(--rte-media-accent);
1217
+ color: var(--rte-media-accent);
1218
+ font-size: 18px;
1219
+ font-weight: 600;
1220
+ pointer-events: none;
1221
+ }
1222
+
1223
+ .rte-mp.is-dropping .rte-mp-drop-veil {
1224
+ display: flex;
1225
+ }
1226
+
1227
+ .rte-mp-form {
1228
+ display: flex;
1229
+ flex-direction: column;
1230
+ gap: 14px;
1231
+ padding: 16px;
1232
+ overflow: auto;
1233
+ }
1234
+
1235
+ .rte-mp-details {
1236
+ min-height: 0;
1237
+ overflow: auto;
1238
+ padding: 16px;
1239
+ border-left: 1px solid var(--rte-media-border);
1240
+ background: var(--rte-media-surface);
1241
+ display: flex;
1242
+ flex-direction: column;
1243
+ gap: 12px;
1244
+ }
1245
+
1246
+ .rte-mp-details[hidden] {
1247
+ display: none;
1248
+ }
1249
+
1250
+ .rte-mp-preview {
1251
+ border-radius: 10px;
1252
+ overflow: hidden;
1253
+ background: var(--rte-media-surface-hover);
1254
+ box-shadow: inset 0 0 0 1px var(--rte-media-border);
1255
+ display: flex;
1256
+ align-items: center;
1257
+ justify-content: center;
1258
+ min-height: 110px;
1259
+ }
1260
+
1261
+ .rte-mp-preview img,
1262
+ .rte-mp-preview video {
1263
+ display: block;
1264
+ max-width: 100%;
1265
+ max-height: 200px;
1266
+ }
1267
+
1268
+ .rte-mp-meta-name {
1269
+ margin: 0;
1270
+ font-size: 14px;
1271
+ font-weight: 600;
1272
+ color: var(--rte-media-text);
1273
+ word-break: break-word;
1274
+ }
1275
+
1276
+ .rte-mp-meta {
1277
+ margin: 2px 0 0;
1278
+ font-size: 12px;
1279
+ color: var(--rte-media-muted);
1280
+ }
1281
+
1282
+ .rte-mp-hint {
1283
+ margin: 4px 0 0;
1284
+ font-size: 12px;
1285
+ color: var(--rte-media-muted);
1286
+ }
1287
+
1288
+ .rte-mp-hint.is-warning {
1289
+ color: var(--rte-media-danger-text);
1290
+ }
1291
+
1292
+ .rte-mp-embed-status {
1293
+ display: flex;
1294
+ align-items: center;
1295
+ gap: 8px;
1296
+ margin: 0;
1297
+ min-height: 22px;
1298
+ font-size: 13px;
1299
+ }
1300
+
1301
+ .rte-mp-embed-status.is-ok {
1302
+ color: var(--rte-media-text);
1303
+ }
1304
+
1305
+ .rte-mp-embed-status.is-ok svg {
1306
+ color: var(--rte-media-accent);
1307
+ }
1308
+
1309
+ .rte-mp-embed-status.is-error {
1310
+ color: var(--rte-media-danger-text);
1311
+ }
1312
+
1313
+ .rte-mp-suggest {
1314
+ display: inline-flex;
1315
+ align-items: center;
1316
+ gap: 6px;
1317
+ margin-left: auto;
1318
+ padding: 2px 8px;
1319
+ border: 1px solid var(--rte-media-border);
1320
+ border-radius: 999px;
1321
+ background: transparent;
1322
+ color: var(--rte-media-text);
1323
+ font-size: 12px;
1324
+ cursor: pointer;
1325
+ }
1326
+
1327
+ .rte-mp-suggest:hover {
1328
+ background: var(--rte-media-surface-hover);
1329
+ }
1330
+
1331
+ .rte-mp-suggest:disabled {
1332
+ opacity: 0.6;
1333
+ cursor: progress;
1334
+ }
1335
+
1336
+ .rte-mp-suggest:focus-visible {
1337
+ outline: 2px solid var(--rte-media-accent);
1338
+ outline-offset: 2px;
1339
+ }
1340
+
1341
+
1342
+ .rte-mp-viewtools {
1343
+ display: flex;
1344
+ align-items: center;
1345
+ gap: 8px;
1346
+ margin-left: auto;
1347
+ }
1348
+
1349
+ .rte-mp-viewtools[hidden] {
1350
+ display: none;
1351
+ }
1352
+
1353
+ .rte-mp-sort {
1354
+ height: 34px;
1355
+ padding: 0 8px 0 12px;
1356
+ border: 1px solid var(--rte-media-border);
1357
+ border-radius: 8px;
1358
+ background: var(--rte-media-bg);
1359
+ color: var(--rte-media-text);
1360
+ font-size: 14px;
1361
+ }
1362
+
1363
+ .rte-mp-sort:focus-visible,
1364
+ .rte-mp-iconbtn:focus-visible {
1365
+ outline: 2px solid var(--rte-media-accent);
1366
+ outline-offset: 2px;
1367
+ }
1368
+
1369
+ .rte-mp-layout {
1370
+ display: flex;
1371
+ gap: 4px;
1372
+ }
1373
+
1374
+ .rte-mp-iconbtn {
1375
+ width: 34px;
1376
+ height: 34px;
1377
+ display: inline-flex;
1378
+ align-items: center;
1379
+ justify-content: center;
1380
+ border: 1px solid var(--rte-media-border);
1381
+ border-radius: 8px;
1382
+ background: transparent;
1383
+ color: var(--rte-media-muted);
1384
+ cursor: pointer;
1385
+ }
1386
+
1387
+ .rte-mp-iconbtn:hover {
1388
+ background: var(--rte-media-surface-hover);
1389
+ }
1390
+
1391
+ .rte-mp-iconbtn[aria-pressed="true"] {
1392
+ border-color: var(--rte-media-text);
1393
+ background: var(--rte-media-surface-hover);
1394
+ color: var(--rte-media-text);
1395
+ }
1396
+
1397
+ .rte-mp-tile-duration {
1398
+ position: absolute;
1399
+ right: 8px;
1400
+ bottom: 8px;
1401
+ z-index: 1;
1402
+ padding: 2px 6px;
1403
+ border-radius: 6px;
1404
+ background: rgba(0, 0, 0, 0.64);
1405
+ color: #fff;
1406
+ font-size: 11px;
1407
+ font-variant-numeric: tabular-nums;
1408
+ }
1409
+
1410
+ .rte-mp-tile.has-duration .rte-mp-tile-name {
1411
+ padding-right: 58px;
1412
+ }
1413
+
1414
+ .rte-mp-tile-meta {
1415
+ display: none;
1416
+ }
1417
+
1418
+ /* A file going up: an outline where it will land, the preview faded, and how far it has got. */
1419
+ .rte-mp-tile.is-uploading {
1420
+ background: var(--rte-media-surface);
1421
+ box-shadow: none;
1422
+ }
1423
+
1424
+ .rte-mp-tile.is-uploading::after {
1425
+ content: "";
1426
+ position: absolute;
1427
+ inset: 0;
1428
+ border: 1.5px dashed var(--rte-media-border);
1429
+ border-radius: inherit;
1430
+ pointer-events: none;
1431
+ }
1432
+
1433
+ .rte-mp-tile.is-uploading img,
1434
+ .rte-mp-tile.is-uploading video {
1435
+ opacity: 0.22;
1436
+ }
1437
+
1438
+ .rte-mp-tile.is-uploading .rte-mp-tile-status {
1439
+ background: transparent;
1440
+ color: var(--rte-media-text);
1441
+ font-weight: 600;
1442
+ }
1443
+
1444
+ .rte-mp-tile.is-uploading .rte-mp-progress {
1445
+ left: 12px;
1446
+ right: 12px;
1447
+ bottom: 12px;
1448
+ border-radius: 2px;
1449
+ background: var(--rte-media-border);
1450
+ }
1451
+
1452
+ .rte-mp-drop-hint {
1453
+ margin: 18px 0 0;
1454
+ text-align: center;
1455
+ font-size: 13px;
1456
+ color: var(--rte-media-muted);
1457
+ }
1458
+
1459
+ /* The list layout: a row for each file, with the picture small at the start. */
1460
+ .rte-mp-grid.is-list {
1461
+ grid-template-columns: minmax(0, 1fr);
1462
+ gap: 4px;
1463
+ }
1464
+
1465
+ .rte-mp-grid.is-list .rte-mp-tile {
1466
+ aspect-ratio: auto;
1467
+ height: 56px;
1468
+ display: flex;
1469
+ align-items: center;
1470
+ gap: 12px;
1471
+ padding-left: 68px;
1472
+ border-radius: 10px;
1473
+ background: transparent;
1474
+ box-shadow: none;
1475
+ color: var(--rte-media-text);
1476
+ }
1477
+
1478
+ .rte-mp-grid.is-list .rte-mp-tile:hover {
1479
+ background: var(--rte-media-surface-hover);
1480
+ box-shadow: none;
1481
+ }
1482
+
1483
+ .rte-mp-grid.is-list .rte-mp-tile[aria-selected="true"] {
1484
+ background: var(--rte-media-ring);
1485
+ box-shadow: inset 0 0 0 2px var(--rte-media-accent);
1486
+ }
1487
+
1488
+ .rte-mp-grid.is-list .rte-mp-tile img,
1489
+ .rte-mp-grid.is-list .rte-mp-tile video {
1490
+ right: auto;
1491
+ width: 56px;
1492
+ border-radius: 10px;
1493
+ }
1494
+
1495
+ .rte-mp-grid.is-list .rte-mp-tile-icon {
1496
+ right: auto;
1497
+ width: 56px;
1498
+ }
1499
+
1500
+ .rte-mp-grid.is-list .rte-mp-tile-name {
1501
+ position: static;
1502
+ flex: 1;
1503
+ min-width: 0;
1504
+ padding: 0 !important;
1505
+ background: none;
1506
+ color: var(--rte-media-text);
1507
+ font-size: 14px;
1508
+ opacity: 1;
1509
+ }
1510
+
1511
+ .rte-mp-grid.is-list .rte-mp-tile-meta {
1512
+ display: block;
1513
+ padding-right: 44px;
1514
+ font-size: 12px;
1515
+ color: var(--rte-media-muted);
1516
+ white-space: nowrap;
1517
+ }
1518
+
1519
+ .rte-mp-grid.is-list .rte-mp-tile-check {
1520
+ top: 50%;
1521
+ transform: translateY(-50%);
1522
+ }
1523
+
1524
+ .rte-mp-grid.is-list .rte-mp-tile-kind,
1525
+ .rte-mp-grid.is-list .rte-mp-tile-duration {
1526
+ display: none;
1527
+ }
1528
+
1529
+ .rte-mp-actions {
1530
+ display: flex;
1531
+ flex-wrap: wrap;
1532
+ gap: 8px;
1533
+ }
1534
+
1535
+ .rte-mp-actions .rte-mp-action {
1536
+ display: inline-flex;
1537
+ align-items: center;
1538
+ gap: 6px;
1539
+ margin: 0;
1540
+ padding: 6px 12px;
1541
+ border-radius: 8px;
1542
+ font-size: 13px;
1543
+ font-weight: 600;
1544
+ }
1545
+ .rte-mp-label-row {
1546
+ display: flex;
1547
+ align-items: center;
1548
+ gap: 8px;
1549
+ }
1550
+
1551
+ .rte-mp-footer {
1552
+ display: flex;
1553
+ align-items: center;
1554
+ gap: 10px;
1555
+ padding: 12px 16px;
1556
+ border-top: 1px solid var(--rte-media-border);
1557
+ }
1558
+
1559
+ .rte-mp-count {
1560
+ flex: 1;
1561
+ font-size: 13px;
1562
+ color: var(--rte-media-muted);
1563
+ }
1564
+
1565
+ .rte-mp-sr {
1566
+ position: absolute;
1567
+ width: 1px;
1568
+ height: 1px;
1569
+ overflow: hidden;
1570
+ clip: rect(0 0 0 0);
1571
+ white-space: nowrap;
1572
+ }
1573
+
1574
+ @media (max-width: 860px) {
1575
+ .rte-mp-body,
1576
+ .rte-mp.no-details .rte-mp-body {
1577
+ grid-template-columns: minmax(0, 1fr);
1578
+ grid-template-rows: auto minmax(0, 1fr) auto;
1579
+ }
1580
+
1581
+ .rte-mp-nav {
1582
+ flex-direction: row;
1583
+ padding: 8px;
1584
+ border-right: 0;
1585
+ border-bottom: 1px solid var(--rte-media-border);
1586
+ overflow-x: auto;
1587
+ }
1588
+
1589
+ .rte-mp-nav-item {
1590
+ width: auto;
1591
+ white-space: nowrap;
1592
+ }
1593
+
1594
+ .rte-mp-details {
1595
+ box-sizing: border-box;
1596
+ max-height: min(30vh, 220px);
1597
+ padding: 12px 16px;
1598
+ border-left: 0;
1599
+ border-top: 1px solid var(--rte-media-border);
1600
+ display: grid;
1601
+ grid-template-columns: 96px minmax(0, 1fr);
1602
+ align-items: start;
1603
+ gap: 10px 12px;
1604
+ }
1605
+
1606
+ .rte-mp-details[hidden] {
1607
+ display: none;
1608
+ }
1609
+
1610
+ .rte-mp-details > * {
1611
+ grid-column: 1 / -1;
1612
+ }
1613
+
1614
+ .rte-mp-details > .rte-mp-preview {
1615
+ grid-column: 1;
1616
+ min-height: 64px;
1617
+ }
1618
+
1619
+ .rte-mp-details > .rte-mp-preview + div {
1620
+ grid-column: 2;
1621
+ }
1622
+
1623
+ .rte-mp-details textarea {
1624
+ min-height: 0;
1625
+ height: 48px;
1626
+ }
1627
+
1628
+ .rte-mp-preview img,
1629
+ .rte-mp-preview video {
1630
+ max-height: 96px;
1631
+ }
1632
+ }
1633
+
1634
+ @media (max-width: 520px) {
1635
+ .rte-media-overlay {
1636
+ padding: 0;
1637
+ align-items: flex-end;
1638
+ }
1639
+
1640
+ .rte-media-dialog.rte-mp {
1641
+ width: 100vw;
1642
+ height: 94vh;
1643
+ border-radius: 16px 16px 0 0;
1644
+ }
1645
+
1646
+ .rte-mp-header {
1647
+ flex-wrap: wrap;
1648
+ }
1649
+
1650
+ .rte-mp-search {
1651
+ order: 3;
1652
+ flex-basis: 100%;
1653
+ max-width: none;
1654
+ }
1655
+
1656
+ .rte-mp-grid {
1657
+ grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
1658
+ }
1659
+ }
1660
+
1661
+ @media (prefers-reduced-motion: reduce) {
1662
+ .rte-mp-tile,
1663
+ .rte-mp-tile img.rte-mp-fade,
1664
+ .rte-mp-progress > span,
1665
+ .rte-mp-dropzone {
1666
+ transition: none;
1667
+ }
1668
+
1669
+ .rte-mp-tile.is-skeleton {
1670
+ animation: none;
1671
+ }
1672
+ }
1673
+
1674
+ .media-floating-toolbar {
1675
+ --rte-media-toolbar-bg: #ffffff;
1676
+ --rte-media-toolbar-border: #d6dbe4;
1677
+ --rte-media-toolbar-text: #344054;
1678
+ --rte-media-toolbar-hover-bg: #f3f6fb;
1679
+ --rte-media-toolbar-hover-text: #101828;
1680
+ --rte-media-toolbar-active-bg: #e6edf7;
1681
+ --rte-media-toolbar-separator: #d9e1eb;
1682
+ --rte-media-toolbar-danger-hover-bg: #fee2e2;
1683
+ --rte-media-toolbar-danger-hover-text: #b42318;
1684
+ position: fixed;
1685
+ display: none;
1686
+ align-items: center;
1687
+ gap: 2px;
1688
+ padding: 4px;
1689
+ border: 1px solid var(--rte-media-toolbar-border);
1690
+ border-radius: 8px;
1691
+ background: var(--rte-media-toolbar-bg);
1692
+ color: var(--rte-media-toolbar-text);
1693
+ box-shadow: 0 10px 24px rgba(15, 23, 36, 0.18);
1694
+ z-index: 10000;
1695
+ pointer-events: auto;
1696
+ backdrop-filter: blur(6px);
1697
+ }
1698
+
1699
+ .media-floating-toolbar.rte-ui-theme-dark,
1700
+ ${si} .media-floating-toolbar {
1701
+ --rte-media-toolbar-bg: #24303f;
1702
+ --rte-media-toolbar-border: #4a5a71;
1703
+ --rte-media-toolbar-text: #d9e6fb;
1704
+ --rte-media-toolbar-hover-bg: #33445a;
1705
+ --rte-media-toolbar-hover-text: #f4f8ff;
1706
+ --rte-media-toolbar-active-bg: #415875;
1707
+ --rte-media-toolbar-separator: #566884;
1708
+ --rte-media-toolbar-danger-hover-bg: #5f2a32;
1709
+ --rte-media-toolbar-danger-hover-text: #ffd7d5;
1710
+ box-shadow: 0 16px 30px rgba(2, 8, 20, 0.42);
1711
+ }
1712
+
1713
+ .media-floating-toolbar-btn {
1714
+ width: 30px;
1715
+ height: 30px;
1716
+ border: none;
1717
+ border-radius: 6px;
1718
+ background: transparent;
1719
+ color: inherit;
1720
+ display: inline-flex;
1721
+ align-items: center;
1722
+ justify-content: center;
1723
+ cursor: pointer;
1724
+ transition: background-color 0.16s ease, color 0.16s ease, transform 0.12s ease;
1725
+ }
1726
+
1727
+ .media-floating-toolbar-btn:hover {
1728
+ background: var(--rte-media-toolbar-hover-bg);
1729
+ color: var(--rte-media-toolbar-hover-text);
1730
+ }
1731
+
1732
+ .media-floating-toolbar-btn:active {
1733
+ background: var(--rte-media-toolbar-active-bg);
1734
+ transform: scale(0.96);
1735
+ }
1736
+
1737
+ .media-floating-toolbar-btn.btn-remove:hover {
1738
+ background: var(--rte-media-toolbar-danger-hover-bg);
1739
+ color: var(--rte-media-toolbar-danger-hover-text);
1740
+ }
1741
+
1742
+ /* While editing, an embedded player does not take the mouse: a click on it selects its figure instead. */
1743
+ [contenteditable="true"] figure.rte-embed iframe {
1744
+ pointer-events: none;
1745
+ }
1746
+
1747
+ .media-resize-handle {
1748
+ position: fixed;
1749
+ width: 12px;
1750
+ height: 12px;
1751
+ margin: -6px 0 0 -6px;
1752
+ box-sizing: border-box;
1753
+ background: #1f6feb;
1754
+ border: 2px solid #fff;
1755
+ border-radius: 50%;
1756
+ z-index: 10001;
1757
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
1758
+ touch-action: none;
1759
+ }
1760
+
1761
+ /* A finger needs more to hold on to than a mouse does. */
1762
+ @media (pointer: coarse) {
1763
+ .media-resize-handle {
1764
+ width: 24px;
1765
+ height: 24px;
1766
+ margin: -12px 0 0 -12px;
1767
+ }
1768
+ }
1769
+
1770
+ .rte-mp-pending {
1771
+ position: fixed;
1772
+ z-index: 10000;
1773
+ display: none;
1774
+ flex-direction: column;
1775
+ align-items: center;
1776
+ justify-content: center;
1777
+ gap: 8px;
1778
+ box-sizing: border-box;
1779
+ border-radius: 8px;
1780
+ background-color: rgba(127, 127, 127, 0.22);
1781
+ background-size: cover;
1782
+ background-position: center;
1783
+ color: #fff;
1784
+ font: 13px/1.4 system-ui, sans-serif;
1785
+ overflow: hidden;
1786
+ }
1787
+
1788
+ .rte-mp-pending::before {
1789
+ content: "";
1790
+ position: absolute;
1791
+ inset: 0;
1792
+ background: rgba(0, 0, 0, 0.45);
1793
+ }
1794
+
1795
+ .rte-mp-pending > * {
1796
+ position: relative;
1797
+ }
1798
+
1799
+ .rte-mp-pending .rte-mp-icon-btn {
1800
+ position: absolute;
1801
+ top: 8px;
1802
+ right: 8px;
1803
+ }
1804
+
1805
+ .rte-mp-pending-bar {
1806
+ width: 60%;
1807
+ max-width: 220px;
1808
+ height: 4px;
1809
+ border-radius: 999px;
1810
+ background: rgba(255, 255, 255, 0.35);
1811
+ overflow: hidden;
1812
+ }
1813
+
1814
+ .rte-mp-pending-bar > span {
1815
+ display: block;
1816
+ width: 0;
1817
+ height: 100%;
1818
+ background: #fff;
1819
+ transition: width 0.15s ease;
1820
+ }
1821
+
1822
+ /* The picture the upload stands in for shows through the shade. */
1823
+ .rte-mp-pending-label {
1824
+ text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
1825
+ }
1826
+
1827
+ .media-resize-label {
1828
+ position: fixed;
1829
+ z-index: 10002;
1830
+ padding: 2px 8px;
1831
+ border-radius: 6px;
1832
+ background: rgba(15, 23, 36, 0.86);
1833
+ color: #fff;
1834
+ font: 12px/1.6 system-ui, sans-serif;
1835
+ pointer-events: none;
1836
+ }
1837
+
1838
+ .media-floating-toolbar-btn[aria-pressed="true"] {
1839
+ background: var(--rte-media-toolbar-active-bg);
1840
+ color: var(--rte-media-toolbar-hover-text);
1841
+ }
1842
+
1843
+ .media-floating-toolbar-btn:focus-visible,
1844
+ .media-size-menu-item:focus-visible {
1845
+ outline: 2px solid #1f6feb;
1846
+ outline-offset: 1px;
1847
+ }
1848
+
1849
+ .media-size-menu {
1850
+ position: absolute;
1851
+ top: calc(100% + 6px);
1852
+ left: 0;
1853
+ min-width: 150px;
1854
+ padding: 4px;
1855
+ display: flex;
1856
+ flex-direction: column;
1857
+ border: 1px solid var(--rte-media-toolbar-border);
1858
+ border-radius: 8px;
1859
+ background: var(--rte-media-toolbar-bg);
1860
+ box-shadow: 0 10px 24px rgba(15, 23, 36, 0.18);
1861
+ }
1862
+
1863
+ .media-size-menu-item {
1864
+ padding: 7px 10px;
1865
+ border: 0;
1866
+ border-radius: 6px;
1867
+ background: transparent;
1868
+ color: var(--rte-media-toolbar-text);
1869
+ font-size: 13px;
1870
+ text-align: left;
1871
+ cursor: pointer;
1872
+ }
1873
+
1874
+ .media-size-menu-item:hover {
1875
+ background: var(--rte-media-toolbar-hover-bg);
1876
+ color: var(--rte-media-toolbar-hover-text);
1877
+ }
1878
+
1879
+ .media-floating-toolbar-separator {
1880
+ width: 1px;
1881
+ height: 20px;
1882
+ margin: 0 2px;
1883
+ background: var(--rte-media-toolbar-separator);
1884
+ }
1885
+ `, document.head.appendChild(t);
1886
+ }, Qe = (t, e) => {
1887
+ const i = (r) => {
1888
+ if (r.key !== "Escape" || !t.isConnected) return;
1889
+ const n = document.querySelectorAll(".rte-media-overlay");
1890
+ n.length > 1 && n[n.length - 1] !== t || (r.preventDefault(), r.stopPropagation(), e());
1891
+ };
1892
+ return document.addEventListener("keydown", i, !0), () => {
1893
+ document.removeEventListener("keydown", i, !0);
1894
+ };
1895
+ }, mr = () => {
1896
+ const t = window.getSelection();
1897
+ if (!t || t.rangeCount === 0) return null;
1898
+ const e = t.anchorNode, i = e instanceof HTMLElement ? e : e == null ? void 0 : e.parentElement;
1899
+ return (i == null ? void 0 : i.closest(".rte-content, .editora-content")) || null;
1900
+ }, li = (t) => {
1901
+ if (t) return t;
1902
+ const e = mr();
1903
+ if (e) return e;
1904
+ const i = document.activeElement;
1905
+ return i ? i.closest(".rte-content, .editora-content") || i : null;
1906
+ }, di = (t) => {
1907
+ const e = li(t);
1908
+ return e ? !!e.closest(si) : !1;
1909
+ }, Je = (t) => {
1910
+ Me();
1911
+ const e = document.createElement("div");
1912
+ return Gi(e), e.className = "rte-media-overlay", di(t) && e.classList.add("rte-ui-theme-dark"), e;
1913
+ }, gr = (t, e) => {
1914
+ t == null || t.addEventListener("keydown", (i) => {
1915
+ (i.key === "Enter" || i.key === " ") && (i.preventDefault(), e == null || e.click());
1916
+ });
1917
+ }, et = (t = !1) => {
1918
+ const e = document.createElement("div");
1919
+ return e.className = t ? "rte-media-dialog rte-media-dialog-compact" : "rte-media-dialog", e.setAttribute("role", "dialog"), e.setAttribute("aria-modal", "true"), e;
1920
+ }, xt = () => ({
1921
+ rotation: 0,
1922
+ flipH: !1,
1923
+ flipV: !1,
1924
+ crop: null,
1925
+ maxWidth: null,
1926
+ format: "keep",
1927
+ quality: 0.85
1928
+ }), fr = (t) => t.rotation === 0 && !t.flipH && !t.flipV && t.crop === null && t.maxWidth === null, Mt = (t, e, i) => i === 90 || i === 270 ? { width: e, height: t } : { width: t, height: e }, ee = (t) => Math.min(1, Math.max(0, t)), De = (t) => {
1929
+ const e = Math.min(1, Math.max(0, t.width)), i = Math.min(1, Math.max(0, t.height));
1930
+ return { x: Math.min(1 - e, ee(t.x)), y: Math.min(1 - i, ee(t.y)), width: e, height: i };
1931
+ }, br = (t, e) => e === 1 ? { x: 1 - (t.y + t.height), y: t.x, width: t.height, height: t.width } : { x: t.y, y: 1 - (t.x + t.width), width: t.height, height: t.width }, xr = (t, e) => e === "h" ? { ...t, x: 1 - (t.x + t.width) } : { ...t, y: 1 - (t.y + t.height) }, Ht = (t, e) => ({
1932
+ ...t,
1933
+ rotation: (t.rotation + e * 90 + 360) % 360,
1934
+ crop: t.crop ? br(t.crop, e) : null
1935
+ }), Ft = (t, e) => {
1936
+ const r = t.rotation === 90 || t.rotation === 270 ? e === "h" ? "v" : "h" : e;
1937
+ return {
1938
+ ...t,
1939
+ flipH: r === "h" ? !t.flipH : t.flipH,
1940
+ flipV: r === "v" ? !t.flipV : t.flipV,
1941
+ crop: t.crop ? xr(t.crop, e) : null
1942
+ };
1943
+ }, ci = (t, e, i) => {
1944
+ if (!t) return { x: 0, y: 0, width: e, height: i };
1945
+ const r = Math.min(e - 1, Math.max(0, Math.round(t.x * e))), n = Math.min(i - 1, Math.max(0, Math.round(t.y * i)));
1946
+ return {
1947
+ x: r,
1948
+ y: n,
1949
+ width: Math.max(1, Math.min(e - r, Math.round(t.width * e))),
1950
+ height: Math.max(1, Math.min(i - n, Math.round(t.height * i)))
1951
+ };
1952
+ }, pi = (t, e, i) => {
1953
+ if (!i || t <= i) return { width: t, height: e };
1954
+ const r = i / t;
1955
+ return { width: i, height: Math.max(1, Math.round(e * r)) };
1956
+ }, vr = (t, e, i, r) => {
1957
+ const n = e / i, o = t >= n ? 1 : t / n, s = t >= n ? n / t : 1, a = r ? r.x + r.width / 2 : 0.5, l = r ? r.y + r.height / 2 : 0.5;
1958
+ return De({ x: a - o / 2, y: l - s / 2, width: o, height: s });
1959
+ }, Ae = (t, e) => t !== "keep" ? t : e === "image/jpeg" || e === "image/webp" ? e : "image/png", yr = (t) => t === "image/jpeg" ? "jpg" : t === "image/webp" ? "webp" : "png", ui = (t, e) => `${(t || "image").replace(/\.[^./\\]+$/, "").replace(/-edited$/, "") || "image"}-edited.${yr(e)}`, wr = 0.04, Pt = (t, e, i) => De({ ...t, x: t.x + e, y: t.y + i }), qt = (t, e, i, r, n = null, o = wr) => {
1960
+ const s = e.includes("e"), a = e.includes("w"), l = e.includes("s"), d = e.includes("n");
1961
+ let c = t.x, p = t.x + t.width, u = t.y, f = t.y + t.height;
1962
+ if (s && (p = ee(p + i)), a && (c = ee(c + i)), l && (f = ee(f + r)), d && (u = ee(u + r)), p - c < o && (a ? c = p - o : s && (p = c + o)), f - u < o && (d ? u = f - o : l && (f = u + o)), c = ee(c), u = ee(u), p = Math.max(c, ee(p)), f = Math.max(u, ee(f)), n === null) return { x: c, y: u, width: p - c, height: f - u };
1963
+ const m = (s || a) && (d || l);
1964
+ let b = p - c, v = f - u;
1965
+ if (m) {
1966
+ b >= v * n ? v = b / n : b = v * n;
1967
+ const L = { w: s ? 1 - c : p, h: l ? 1 - u : f }, S = Math.min(1, L.w / b, L.h / v);
1968
+ b *= S, v *= S;
1969
+ const R = Math.max(1, o / b, o / v);
1970
+ b *= R, v *= R;
1971
+ const _ = s ? c : p - b, de = l ? u : f - v;
1972
+ return De({ x: _, y: de, width: b, height: v });
1973
+ }
1974
+ const y = t.x + t.width / 2, z = t.y + t.height / 2;
1975
+ if (d || l) {
1976
+ b = v * n;
1977
+ const L = { w: 2 * Math.min(y, 1 - y), h: l ? 1 - u : f }, S = Math.min(1, L.w / b, L.h / v);
1978
+ b *= S, v *= S;
1979
+ const R = Math.max(1, o / b, o / v);
1980
+ return b *= R, v *= R, De({ x: y - b / 2, y: l ? u : f - v, width: b, height: v });
1981
+ }
1982
+ v = b / n;
1983
+ const C = { w: s ? 1 - c : p, h: 2 * Math.min(z, 1 - z) }, w = Math.min(1, C.w / b, C.h / v);
1984
+ b *= w, v *= w;
1985
+ const E = Math.max(1, o / b, o / v);
1986
+ return b *= E, v *= E, De({ x: s ? c : p - b, y: z - v / 2, width: b, height: v });
1987
+ }, kr = (t, e, i) => t * i / e, tt = {
1988
+ createCanvas: (t, e) => {
1989
+ const i = document.createElement("canvas");
1990
+ return i.width = t, i.height = e, i;
1991
+ }
1992
+ };
1993
+ class Le extends Error {
1994
+ constructor(e, i) {
1995
+ super(i), this.code = e, this.name = "ImageEditError";
1996
+ }
1997
+ }
1998
+ const Er = 16e6, hi = (t) => new Promise((e, i) => {
1999
+ const r = new Image();
2000
+ !t.startsWith("data:") && !t.startsWith("blob:") && (r.crossOrigin = "anonymous"), r.onload = () => e(r), r.onerror = () => i(
2001
+ new Le(
2002
+ t.startsWith("data:") || t.startsWith("blob:") ? "load" : "cors",
2003
+ t.startsWith("data:") || t.startsWith("blob:") ? "This image couldn't be opened." : "This image couldn't be opened for editing. Its server may not allow it (CORS), or the address no longer works."
2004
+ )
2005
+ ), r.src = t;
2006
+ }), mi = (t, e, i, r, n, o = tt) => {
2007
+ const s = Mt(e, i, r.rotation), a = o.createCanvas(Math.max(1, Math.round(s.width * n)), Math.max(1, Math.round(s.height * n))), l = a.getContext("2d");
2008
+ if (!l) throw new Le("canvas", "This browser can't edit images.");
2009
+ return l.imageSmoothingQuality = "high", l.translate(a.width / 2, a.height / 2), l.rotate(r.rotation * Math.PI / 180), l.scale(r.flipH ? -1 : 1, r.flipV ? -1 : 1), l.drawImage(t, -e * n / 2, -i * n / 2, e * n, i * n), a;
2010
+ }, vt = (t, e, i, r, n, o = tt) => {
2011
+ const s = Mt(e, i, r.rotation), a = ci(r.crop, s.width, s.height), l = pi(a.width, a.height, r.maxWidth);
2012
+ if (l.width * l.height > Er)
2013
+ throw new Le("too-large", "This image is too large to edit in the browser. Resize it first.");
2014
+ const d = mi(t, e, i, r, 1, o), c = o.createCanvas(l.width, l.height), p = c.getContext("2d");
2015
+ if (!p) throw new Le("canvas", "This browser can't edit images.");
2016
+ return p.imageSmoothingQuality = "high", Ae(r.format, n) === "image/jpeg" && (p.fillStyle = "#ffffff", p.fillRect(0, 0, l.width, l.height)), p.drawImage(d, a.x, a.y, a.width, a.height, 0, 0, l.width, l.height), c;
2017
+ }, yt = (t, e, i) => new Promise((r, n) => {
2018
+ t.toBlob(
2019
+ (o) => o ? r(o) : n(new Le("encode", "The picture couldn't be saved in this format.")),
2020
+ e,
2021
+ i
2022
+ );
2023
+ }), Ar = (t) => new Promise((e) => {
2024
+ if (typeof document == "undefined" || typeof URL == "undefined" || typeof URL.createObjectURL != "function") return e(void 0);
2025
+ const i = t.type.startsWith("video/") ? "video" : t.type.startsWith("audio/") ? "audio" : null;
2026
+ if (!i) return e(void 0);
2027
+ const r = document.createElement(i), n = URL.createObjectURL(t), o = (a) => {
2028
+ var l;
2029
+ window.clearTimeout(s), r.removeAttribute("src"), (l = r.load) == null || l.call(r), URL.revokeObjectURL(n), e(a !== void 0 && Number.isFinite(a) && a > 0 ? Math.round(a) : void 0);
2030
+ }, s = window.setTimeout(() => o(), 3e3);
2031
+ r.preload = "metadata", r.onloadedmetadata = () => o(r.duration), r.onerror = () => o(), r.src = n;
2032
+ }), gi = (t) => {
2033
+ const e = Math.max(0, Math.round(t)), i = Math.floor(e / 3600), r = Math.floor(e % 3600 / 60), n = e % 60;
2034
+ return i ? `${i}:${String(r).padStart(2, "0")}:${String(n).padStart(2, "0")}` : `${r}:${String(n).padStart(2, "0")}`;
2035
+ }, fi = (t) => {
2036
+ var i, r, n;
2037
+ if (!t) return null;
2038
+ const e = t === !0 ? {} : t;
2039
+ return { maxWidth: (i = e.maxWidth) != null ? i : 2048, quality: (r = e.quality) != null ? r : 0.85, format: (n = e.format) != null ? n : "keep" };
2040
+ }, bi = (t) => t === "image/jpeg" || t === "image/png" || t === "image/webp", Cr = {
2041
+ ...tt,
2042
+ load: async (t) => {
2043
+ const e = URL.createObjectURL(t);
2044
+ try {
2045
+ const i = await hi(e);
2046
+ return { source: i, width: i.naturalWidth, height: i.naturalHeight };
2047
+ } finally {
2048
+ URL.revokeObjectURL(e);
2049
+ }
2050
+ }
2051
+ }, Lr = async (t, e, i = Cr) => {
2052
+ if (!bi(t.type)) return t;
2053
+ try {
2054
+ const { source: r, width: n, height: o } = await i.load(t), s = e.format === "webp" ? "image/webp" : e.format === "jpeg" ? "image/jpeg" : "keep", a = Ae(s, t.type), l = n > e.maxWidth, d = a !== t.type;
2055
+ if (!l && !d) return t;
2056
+ const c = { ...xt(), maxWidth: l ? e.maxWidth : null, format: s, quality: e.quality }, p = vt(r, n, o, c, t.type, i), u = await yt(p, a, e.quality);
2057
+ return u.type && u.type !== a && !d || !l && u.size >= t.size ? t : new File([u], ui(t.name, u.type || a).replace("-edited", ""), { type: u.type || a });
2058
+ } catch (r) {
2059
+ return t;
2060
+ }
2061
+ }, wt = (t) => t >= 1024 * 1024 ? `${Math.round(t / (1024 * 1024) * 10) / 10} MB` : `${Math.max(1, Math.round(t / 1024))} KB`, Mr = (t) => wt(t), xi = (t, e) => {
2062
+ if (!e || e.length === 0) return !0;
2063
+ const i = t.toLowerCase();
2064
+ return e.some((r) => {
2065
+ const n = r.toLowerCase();
2066
+ return n === "*/*" || n === i || n.endsWith("/*") && i.startsWith(n.slice(0, -1));
2067
+ });
2068
+ }, Sr = (t, e) => {
2069
+ var n;
2070
+ const r = ((n = q(e).allowedTypes) != null ? n : []).filter((o) => o.startsWith(`${t}/`) || o === "*/*");
2071
+ return r.length ? r.join(",") : `${t}/*`;
2072
+ }, vi = (t, e) => {
2073
+ if (e.maxFileSize && t.size > e.maxFileSize)
2074
+ throw new N(
2075
+ "too-large",
2076
+ `${t.name || "This file"} is ${wt(t.size)}. The limit is ${wt(e.maxFileSize)}.`
2077
+ );
2078
+ }, yi = (t, e) => {
2079
+ if (e.allowedTypes && !xi(t.type, e.allowedTypes))
2080
+ throw new N("type-not-allowed", `${t.name || "This file"} isn't a type that can be uploaded here.`);
2081
+ fi(e.optimizeImages) && bi(t.type) || vi(t, e);
2082
+ }, wi = async (t, e = {}) => {
2083
+ const i = q(e.config);
2084
+ yi(t, i);
2085
+ const r = fi(i.optimizeImages), n = r ? await Lr(t, r) : t;
2086
+ vi(n, i);
2087
+ const o = { signal: e.signal, onProgress: e.onProgress }, s = Ar(n), a = async (l) => {
2088
+ if (l.duration === void 0) {
2089
+ const d = await s;
2090
+ d !== void 0 && (l.duration = d);
2091
+ }
2092
+ return l;
2093
+ };
2094
+ try {
2095
+ return await a(await ai(i).upload(n, o));
2096
+ } catch (l) {
2097
+ if (Ze(l) || !i.fallbackToBase64) throw l;
2098
+ return a(await ni().upload(n, o));
2099
+ }
2100
+ }, U = (t, e = 18) => `<svg width="${e}" height="${e}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false">${t}</svg>`, $ = {
2101
+ library: U('<rect x="3" y="3" width="18" height="18" rx="3"></rect><circle cx="9" cy="9" r="1.6"></circle><path d="m21 15-4.5-4.5L6 21"></path>'),
2102
+ upload: U('<path d="M12 16V4"></path><path d="m7 9 5-5 5 5"></path><path d="M20 16v3a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2v-3"></path>'),
2103
+ link: U('<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path>'),
2104
+ search: U('<circle cx="11" cy="11" r="7"></circle><path d="m21 21-4.3-4.3"></path>'),
2105
+ close: U('<path d="M18 6 6 18"></path><path d="m6 6 12 12"></path>'),
2106
+ check: U('<path d="m5 12.5 4.5 4.5L19 7.5"></path>', 14),
2107
+ play: U('<path d="M8 5.5v13l11-6.5z" fill="currentColor"></path>', 16),
2108
+ trash: U('<path d="M3 6h18"></path><path d="M8 6V4h8v2"></path><path d="m6 6 1 14h10l1-14"></path>', 16),
2109
+ alert: U('<circle cx="12" cy="12" r="9"></circle><path d="M12 8v5"></path><path d="M12 16.5v.01"></path>', 20),
2110
+ retry: U('<path d="M3 12a9 9 0 1 0 3-6.7"></path><path d="M3 4v5h5"></path>', 16),
2111
+ audio: U('<path d="M9 18V6l10-2v12"></path><circle cx="6.5" cy="18" r="2.5"></circle><circle cx="16.5" cy="16" r="2.5"></circle>', 28),
2112
+ note: U('<path d="M9 18V6l10-2v12"></path><circle cx="6.5" cy="18" r="2.5" fill="currentColor"></circle><circle cx="16.5" cy="16" r="2.5" fill="currentColor"></circle>', 14),
2113
+ embed: U('<rect x="3" y="5" width="18" height="14" rx="3"></rect><path d="m10 9.5 4.5 2.5-4.5 2.5z" fill="currentColor"></path>'),
2114
+ stock: U('<rect x="3" y="3" width="18" height="18" rx="3"></rect><path d="M3 15 8 10l5 5 3-3 5 5"></path><circle cx="15.5" cy="8.5" r="1.5"></circle>'),
2115
+ edit: U('<path d="M12 20h9"></path><path d="M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z"></path>', 16),
2116
+ grid: U('<rect x="3" y="3" width="7" height="7" rx="1.5"></rect><rect x="14" y="3" width="7" height="7" rx="1.5"></rect><rect x="3" y="14" width="7" height="7" rx="1.5"></rect><rect x="14" y="14" width="7" height="7" rx="1.5"></rect>', 16),
2117
+ list: U('<path d="M8 6h13"></path><path d="M8 12h13"></path><path d="M8 18h13"></path><path d="M3 6h.01"></path><path d="M3 12h.01"></path><path d="M3 18h.01"></path>', 16),
2118
+ gallery: U('<rect x="3" y="3" width="8" height="8" rx="1.5"></rect><rect x="13" y="3" width="8" height="8" rx="1.5"></rect><rect x="3" y="13" width="8" height="8" rx="1.5"></rect><rect x="13" y="13" width="8" height="8" rx="1.5"></rect>', 16),
2119
+ sparkle: U('<path d="M12 3v4M12 17v4M3 12h4M17 12h4M6 6l2.5 2.5M15.5 15.5 18 18M18 6l-2.5 2.5M8.5 15.5 6 18"></path>', 16),
2120
+ photo: U('<rect x="3" y="3" width="18" height="18" rx="3"></rect><circle cx="9" cy="9" r="1.6"></circle><path d="m21 15-4.5-4.5L6 21"></path>', 28)
2121
+ }, Tr = ["nw", "n", "ne", "e", "se", "s", "sw", "w"], Pe = 0.01;
2122
+ class Ir {
2123
+ constructor(e, i) {
2124
+ this.onChange = e, this.announce = i, this.element = document.createElement("div"), this.box = document.createElement("div"), this.rect = null, this.aspect = null, this.imageWidth = 1, this.imageHeight = 1, this.drag = null, this.onPointerDown = (r) => {
2125
+ var s, a;
2126
+ if (!this.rect || r.pointerType === "mouse" && r.button !== 0) return;
2127
+ const o = r.target.dataset.handle;
2128
+ r.preventDefault(), (a = (s = this.box).setPointerCapture) == null || a.call(s, r.pointerId), this.box.focus({ preventScroll: !0 }), this.drag = { mode: o != null ? o : "move", x: r.clientX, y: r.clientY, start: this.rect };
2129
+ }, this.onPointerMove = (r) => {
2130
+ const { drag: n } = this;
2131
+ if (!n) return;
2132
+ const o = this.element.getBoundingClientRect();
2133
+ if (!o.width || !o.height) return;
2134
+ const s = (r.clientX - n.x) / o.width, a = (r.clientY - n.y) / o.height;
2135
+ this.change(n.mode === "move" ? Pt(n.start, s, a) : qt(n.start, n.mode, s, a, this.aspect));
2136
+ }, this.onPointerUp = (r) => {
2137
+ var n, o;
2138
+ this.drag && (this.drag = null, (o = (n = this.box).hasPointerCapture) != null && o.call(n, r.pointerId) && this.box.releasePointerCapture(r.pointerId), this.rect && this.announce(this.describe(this.rect)));
2139
+ }, this.onKeyDown = (r) => {
2140
+ if (!this.rect || r.ctrlKey || r.metaKey || r.altKey) return;
2141
+ const o = {
2142
+ ArrowLeft: [-Pe, 0],
2143
+ ArrowRight: [Pe, 0],
2144
+ ArrowUp: [0, -Pe],
2145
+ ArrowDown: [0, Pe]
2146
+ }[r.key];
2147
+ if (!o) return;
2148
+ r.preventDefault();
2149
+ const s = r.shiftKey ? qt(this.rect, "se", o[0], o[1], this.aspect) : Pt(this.rect, o[0], o[1]);
2150
+ this.change(s), this.announce(this.describe(s));
2151
+ }, this.element.className = "rte-ie-crop-layer", this.box.className = "rte-ie-crop", this.box.setAttribute("role", "group"), this.box.setAttribute("aria-label", "Crop area. Arrow keys move it, Shift and the arrow keys resize it."), this.box.tabIndex = 0;
2152
+ for (const r of Tr) {
2153
+ const n = document.createElement("div");
2154
+ n.className = `rte-ie-handle rte-ie-handle-${r}`, n.dataset.handle = r, n.setAttribute("aria-hidden", "true"), this.box.append(n);
2155
+ }
2156
+ this.element.append(this.box), this.element.hidden = !0, this.box.addEventListener("pointerdown", this.onPointerDown), this.box.addEventListener("pointermove", this.onPointerMove), this.box.addEventListener("pointerup", this.onPointerUp), this.box.addEventListener("pointercancel", this.onPointerUp), this.box.addEventListener("keydown", this.onKeyDown);
2157
+ }
2158
+ get current() {
2159
+ return this.rect;
2160
+ }
2161
+ /** The size of the picture the fractions are fractions of, in pixels. */
2162
+ setImageSize(e, i) {
2163
+ this.imageWidth = e, this.imageHeight = i;
2164
+ }
2165
+ /** A shape to keep (width / height in pixels), or `null` for any. */
2166
+ setAspect(e) {
2167
+ this.aspect = e === null ? null : kr(e, this.imageWidth, this.imageHeight);
2168
+ }
2169
+ setRect(e) {
2170
+ this.rect = e, this.element.hidden = e === null, e && (this.box.style.left = `${e.x * 100}%`, this.box.style.top = `${e.y * 100}%`, this.box.style.width = `${e.width * 100}%`, this.box.style.height = `${e.height * 100}%`);
2171
+ }
2172
+ focus() {
2173
+ this.box.focus({ preventScroll: !0 });
2174
+ }
2175
+ change(e) {
2176
+ this.setRect(e), this.onChange(e);
2177
+ }
2178
+ describe(e) {
2179
+ const i = Math.round(e.width * this.imageWidth), r = Math.round(e.height * this.imageHeight);
2180
+ return `${i} by ${r} pixels, ${Math.round(e.x * this.imageWidth)} from the left, ${Math.round(e.y * this.imageHeight)} from the top`;
2181
+ }
2182
+ dispose() {
2183
+ this.drag = null, this.element.remove();
2184
+ }
2185
+ }
2186
+ const zr = () => {
2187
+ if (typeof document == "undefined" || document.getElementById("rte-image-editor-styles")) return;
2188
+ const t = document.createElement("style");
2189
+ t.id = "rte-image-editor-styles", t.textContent = `
2190
+ .rte-media-dialog.rte-ie {
2191
+ width: min(96vw, 980px);
2192
+ height: min(90vh, 700px);
2193
+ max-height: none;
2194
+ }
2195
+
2196
+ .rte-ie-body {
2197
+ flex: 1;
2198
+ min-height: 0;
2199
+ display: grid;
2200
+ grid-template-columns: minmax(0, 1fr) 300px;
2201
+ }
2202
+
2203
+ .rte-ie-stage {
2204
+ position: relative;
2205
+ min-width: 0;
2206
+ min-height: 0;
2207
+ display: flex;
2208
+ align-items: center;
2209
+ justify-content: center;
2210
+ padding: 16px;
2211
+ overflow: auto;
2212
+ background-color: var(--rte-media-surface-hover);
2213
+ background-image:
2214
+ linear-gradient(45deg, rgba(127, 127, 127, 0.16) 25%, transparent 25%, transparent 75%, rgba(127, 127, 127, 0.16) 75%),
2215
+ linear-gradient(45deg, rgba(127, 127, 127, 0.16) 25%, transparent 25%, transparent 75%, rgba(127, 127, 127, 0.16) 75%);
2216
+ background-size: 16px 16px;
2217
+ background-position: 0 0, 8px 8px;
2218
+ }
2219
+
2220
+ .rte-ie-canvas-wrap {
2221
+ position: relative;
2222
+ flex: none;
2223
+ line-height: 0;
2224
+ box-shadow: 0 2px 18px rgba(0, 0, 0, 0.3);
2225
+ }
2226
+
2227
+ .rte-ie-canvas-wrap canvas {
2228
+ display: block;
2229
+ }
2230
+
2231
+ .rte-ie-status {
2232
+ color: var(--rte-media-muted);
2233
+ font-size: 14px;
2234
+ text-align: center;
2235
+ max-width: 360px;
2236
+ }
2237
+
2238
+ .rte-ie-status.is-error {
2239
+ color: var(--rte-media-danger-text);
2240
+ }
2241
+
2242
+ .rte-ie-crop-layer {
2243
+ position: absolute;
2244
+ inset: 0;
2245
+ overflow: hidden;
2246
+ pointer-events: none;
2247
+ }
2248
+
2249
+ .rte-ie-crop-layer[hidden] {
2250
+ display: none;
2251
+ }
2252
+
2253
+ .rte-ie-crop {
2254
+ position: absolute;
2255
+ box-sizing: border-box;
2256
+ border: 2px solid #fff;
2257
+ /* The shade over what will be cut away. */
2258
+ box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
2259
+ background-image:
2260
+ linear-gradient(rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.45)),
2261
+ linear-gradient(rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.45)),
2262
+ linear-gradient(90deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.45)),
2263
+ linear-gradient(90deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.45));
2264
+ background-size: 100% 1px, 100% 1px, 1px 100%, 1px 100%;
2265
+ background-position: 0 33.33%, 0 66.66%, 33.33% 0, 66.66% 0;
2266
+ background-repeat: no-repeat;
2267
+ cursor: move;
2268
+ pointer-events: auto;
2269
+ touch-action: none;
2270
+ }
2271
+
2272
+ .rte-ie-crop:focus-visible {
2273
+ outline: 2px solid #1f6feb;
2274
+ outline-offset: 2px;
2275
+ }
2276
+
2277
+ .rte-ie-handle {
2278
+ position: absolute;
2279
+ width: 14px;
2280
+ height: 14px;
2281
+ box-sizing: border-box;
2282
+ background: #fff;
2283
+ border: 2px solid #1f6feb;
2284
+ border-radius: 50%;
2285
+ margin: -7px 0 0 -7px;
2286
+ }
2287
+
2288
+ @media (pointer: coarse) {
2289
+ .rte-ie-handle {
2290
+ width: 24px;
2291
+ height: 24px;
2292
+ margin: -12px 0 0 -12px;
2293
+ }
2294
+ }
2295
+
2296
+ .rte-ie-handle-nw { left: 0; top: 0; cursor: nwse-resize; }
2297
+ .rte-ie-handle-n { left: 50%; top: 0; cursor: ns-resize; }
2298
+ .rte-ie-handle-ne { left: 100%; top: 0; cursor: nesw-resize; }
2299
+ .rte-ie-handle-e { left: 100%; top: 50%; cursor: ew-resize; }
2300
+ .rte-ie-handle-se { left: 100%; top: 100%; cursor: nwse-resize; }
2301
+ .rte-ie-handle-s { left: 50%; top: 100%; cursor: ns-resize; }
2302
+ .rte-ie-handle-sw { left: 0; top: 100%; cursor: nesw-resize; }
2303
+ .rte-ie-handle-w { left: 0; top: 50%; cursor: ew-resize; }
2304
+
2305
+ .rte-ie-panel {
2306
+ min-height: 0;
2307
+ overflow: auto;
2308
+ padding: 14px 16px;
2309
+ border-left: 1px solid var(--rte-media-border);
2310
+ display: flex;
2311
+ flex-direction: column;
2312
+ gap: 18px;
2313
+ }
2314
+
2315
+ .rte-ie-section {
2316
+ border: 0;
2317
+ padding: 0;
2318
+ margin: 0;
2319
+ min-width: 0;
2320
+ }
2321
+
2322
+ .rte-ie-section > legend {
2323
+ padding: 0;
2324
+ margin-bottom: 8px;
2325
+ font-size: 12px;
2326
+ font-weight: 600;
2327
+ letter-spacing: 0.04em;
2328
+ text-transform: uppercase;
2329
+ color: var(--rte-media-muted);
2330
+ }
2331
+
2332
+ .rte-ie-grid {
2333
+ display: grid;
2334
+ grid-template-columns: 1fr 1fr;
2335
+ gap: 8px;
2336
+ }
2337
+
2338
+ .rte-ie-tool {
2339
+ display: flex;
2340
+ align-items: center;
2341
+ gap: 8px;
2342
+ padding: 8px 10px;
2343
+ border: 1px solid var(--rte-media-border);
2344
+ border-radius: 8px;
2345
+ background: transparent;
2346
+ color: var(--rte-media-text);
2347
+ font-size: 13px;
2348
+ cursor: pointer;
2349
+ }
2350
+
2351
+ .rte-ie-tool:hover {
2352
+ background: var(--rte-media-surface-hover);
2353
+ }
2354
+
2355
+ .rte-ie-tool[aria-pressed="true"] {
2356
+ background: var(--rte-media-text);
2357
+ border-color: var(--rte-media-text);
2358
+ color: var(--rte-media-bg);
2359
+ }
2360
+
2361
+ .rte-ie-tool:focus-visible,
2362
+ .rte-ie-select:focus-visible {
2363
+ outline: 2px solid var(--rte-media-accent);
2364
+ outline-offset: 2px;
2365
+ }
2366
+
2367
+ .rte-ie-tool:disabled {
2368
+ opacity: 0.5;
2369
+ cursor: not-allowed;
2370
+ }
2371
+
2372
+ .rte-ie-chips {
2373
+ display: flex;
2374
+ flex-wrap: wrap;
2375
+ gap: 6px;
2376
+ }
2377
+
2378
+ .rte-ie-chips .rte-ie-tool {
2379
+ padding: 4px 10px;
2380
+ border-radius: 999px;
2381
+ }
2382
+
2383
+ .rte-ie-row {
2384
+ display: flex;
2385
+ align-items: center;
2386
+ gap: 8px;
2387
+ margin-top: 8px;
2388
+ }
2389
+
2390
+ .rte-ie-row label {
2391
+ font-size: 13px;
2392
+ color: var(--rte-media-muted);
2393
+ flex: none;
2394
+ }
2395
+
2396
+ .rte-ie-row input[type="number"],
2397
+ .rte-ie-select {
2398
+ flex: 1;
2399
+ min-width: 0;
2400
+ height: 34px;
2401
+ padding: 0 8px;
2402
+ border: 1px solid var(--rte-media-border);
2403
+ border-radius: 8px;
2404
+ background: var(--rte-media-bg);
2405
+ color: var(--rte-media-text);
2406
+ font-size: 14px;
2407
+ }
2408
+
2409
+ .rte-ie-row input[type="range"] {
2410
+ flex: 1;
2411
+ accent-color: var(--rte-media-accent);
2412
+ }
2413
+
2414
+ .rte-ie-quality {
2415
+ min-width: 3ch;
2416
+ text-align: right;
2417
+ font-size: 13px;
2418
+ color: var(--rte-media-muted);
2419
+ }
2420
+
2421
+ .rte-ie-summary {
2422
+ margin: 0;
2423
+ padding: 10px 12px;
2424
+ border-radius: 8px;
2425
+ background: var(--rte-media-surface);
2426
+ font-size: 13px;
2427
+ line-height: 1.5;
2428
+ color: var(--rte-media-muted);
2429
+ }
2430
+
2431
+ .rte-ie-summary strong {
2432
+ color: var(--rte-media-text);
2433
+ }
2434
+
2435
+ .rte-ie-footer-error {
2436
+ flex: 1;
2437
+ margin: 0;
2438
+ font-size: 13px;
2439
+ color: var(--rte-media-danger-text);
2440
+ }
2441
+
2442
+ @media (max-width: 760px) {
2443
+ .rte-ie-body {
2444
+ grid-template-columns: minmax(0, 1fr);
2445
+ grid-template-rows: minmax(240px, 1.1fr) minmax(0, 1fr);
2446
+ }
2447
+
2448
+ .rte-ie-panel {
2449
+ border-left: 0;
2450
+ border-top: 1px solid var(--rte-media-border);
2451
+ }
2452
+ }
2453
+
2454
+ @media (max-width: 520px) {
2455
+ .rte-media-overlay {
2456
+ padding: 0;
2457
+ align-items: flex-end;
2458
+ }
2459
+
2460
+ .rte-media-dialog.rte-ie {
2461
+ width: 100vw;
2462
+ height: 96vh;
2463
+ border-radius: 16px 16px 0 0;
2464
+ }
2465
+ }
2466
+ `, document.head.appendChild(t);
2467
+ }, $r = {
2468
+ load: async (t) => {
2469
+ const e = await hi(t);
2470
+ return { source: e, width: e.naturalWidth, height: e.naturalHeight };
2471
+ },
2472
+ canvas: tt
2473
+ }, Rr = [
2474
+ { id: "none", label: "None", shape: { kind: "none" } },
2475
+ { id: "free", label: "Free", shape: { kind: "free" } },
2476
+ { id: "original", label: "Original", shape: { kind: "original" } },
2477
+ { id: "1:1", label: "1:1", shape: { kind: "ratio", id: "1:1", ratio: 1 } },
2478
+ { id: "4:3", label: "4:3", shape: { kind: "ratio", id: "4:3", ratio: 4 / 3 } },
2479
+ { id: "3:2", label: "3:2", shape: { kind: "ratio", id: "3:2", ratio: 3 / 2 } },
2480
+ { id: "16:9", label: "16:9", shape: { kind: "ratio", id: "16:9", ratio: 16 / 9 } }
2481
+ ], Dr = [null, 2048, 1600, 1200, 800], Nr = [
2482
+ ["keep", "Same as original"],
2483
+ ["image/jpeg", "JPEG"],
2484
+ ["image/webp", "WebP"],
2485
+ ["image/png", "PNG"]
2486
+ ], qe = (t) => `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${t}</svg>`, We = {
2487
+ rotateLeft: qe('<path d="M3 12a9 9 0 1 1 3 6.7"></path><path d="M3 5v7h7"></path>'),
2488
+ rotateRight: qe('<path d="M21 12a9 9 0 1 0-3 6.7"></path><path d="M21 5v7h-7"></path>'),
2489
+ flipH: qe('<path d="M12 3v18"></path><path d="M8 7 3 17h5z"></path><path d="m16 7 5 10h-5z"></path>'),
2490
+ flipV: qe('<path d="M3 12h18"></path><path d="m7 8 10-5v5z"></path><path d="m7 16 10 5v-5z"></path>')
2491
+ }, Ur = { jpg: "image/jpeg", jpeg: "image/jpeg", png: "image/png", webp: "image/webp", gif: "image/gif", avif: "image/avif" }, Or = (t, e) => {
2492
+ var n, o, s, a, l;
2493
+ const i = /^data:([^;,]+)/.exec(t);
2494
+ if (i) return i[1];
2495
+ const r = (s = (n = /\.([a-z0-9]+)(?:[?#]|$)/i.exec(t)) == null ? void 0 : n[1]) != null ? s : (o = /\.([a-z0-9]+)$/i.exec(e)) == null ? void 0 : o[1];
2496
+ return (l = Ur[(a = r == null ? void 0 : r.toLowerCase()) != null ? a : ""]) != null ? l : "image/png";
2497
+ }, Br = (t) => t >= 1024 * 1024 ? `${Math.round(t / (1024 * 1024) * 10) / 10} MB` : `${Math.max(1, Math.round(t / 1024))} KB`, T = (t, e, i) => {
2498
+ const r = document.createElement(t);
2499
+ return e && (r.className = e), i !== void 0 && (r.textContent = i), r;
2500
+ }, ki = (t) => {
2501
+ var Rt;
2502
+ const e = (Rt = t.deps) != null ? Rt : $r;
2503
+ q(t.config);
2504
+ const i = Or(t.src, t.name);
2505
+ Me(), zr();
2506
+ let r = xt(), n = { kind: "none" }, o = null, s = !1, a = 0, l;
2507
+ const d = new AbortController(), c = Je(t.contextElement), p = et();
2508
+ p.classList.add("rte-ie");
2509
+ const u = T("div", "rte-media-header"), f = T("h2", "rte-media-title", "Edit Image"), m = T("button", "close-btn rte-media-close-btn");
2510
+ m.type = "button", m.setAttribute("aria-label", "Close"), m.innerHTML = $.close, u.append(f, m);
2511
+ const b = T("div", "rte-ie-stage"), v = T("p", "rte-ie-status", "Opening the image…");
2512
+ v.setAttribute("role", "status");
2513
+ const y = T("div", "rte-ie-canvas-wrap");
2514
+ y.hidden = !0;
2515
+ const z = T("div", "rte-mp-sr");
2516
+ z.setAttribute("aria-live", "polite");
2517
+ const C = new Ir(
2518
+ (x) => {
2519
+ r = { ...r, crop: x }, g();
2520
+ },
2521
+ (x) => z.textContent = x
2522
+ );
2523
+ b.append(v, y, z);
2524
+ const w = T("div", "rte-ie-panel"), E = (x) => {
2525
+ const A = T("fieldset", "rte-ie-section");
2526
+ return A.append(T("legend", void 0, x)), A;
2527
+ }, L = (x, A = "") => {
2528
+ const D = T("button", "rte-ie-tool");
2529
+ return D.type = "button", D.innerHTML = `${A}<span></span>`, D.querySelector("span").textContent = x, D;
2530
+ }, S = E("Orientation"), R = T("div", "rte-ie-grid"), _ = L("Rotate left", We.rotateLeft), de = L("Rotate right", We.rotateRight), te = L("Flip horizontal", We.flipH), B = L("Flip vertical", We.flipV);
2531
+ R.append(_, de, te, B), S.append(R);
2532
+ const Se = E("Crop"), ie = T("div", "rte-ie-chips");
2533
+ ie.setAttribute("role", "group"), ie.setAttribute("aria-label", "Crop shape");
2534
+ const re = /* @__PURE__ */ new Map();
2535
+ for (const x of Rr) {
2536
+ const A = L(x.label);
2537
+ A.dataset.shape = x.id, A.addEventListener("click", () => Oe(x.shape)), re.set(x.id, A), ie.append(A);
2538
+ }
2539
+ Se.append(ie);
2540
+ const me = E("Size"), Te = T("div", "rte-ie-row"), ce = T("label", void 0, "Max width");
2541
+ ce.htmlFor = "ie-width";
2542
+ const H = T("input");
2543
+ H.type = "number", H.id = "ie-width", H.min = "16", H.step = "1", H.placeholder = "Original", Te.append(ce, H, T("span", "rte-ie-quality", "px"));
2544
+ const ge = T("div", "rte-ie-chips");
2545
+ ge.style.marginTop = "8px";
2546
+ const xe = /* @__PURE__ */ new Map();
2547
+ for (const x of Dr) {
2548
+ const A = L(x === null ? "Original" : String(x));
2549
+ A.addEventListener("click", () => Be(x)), xe.set(x, A), ge.append(A);
2550
+ }
2551
+ me.append(Te, ge);
2552
+ const Ie = E("Save as"), ve = T("div", "rte-ie-row");
2553
+ ve.style.marginTop = "0";
2554
+ const ze = T("label", void 0, "Format");
2555
+ ze.htmlFor = "ie-format";
2556
+ const Z = T("select", "rte-ie-select");
2557
+ Z.id = "ie-format";
2558
+ for (const [x, A] of Nr) {
2559
+ const D = T("option", void 0, A);
2560
+ D.value = x, Z.append(D);
2561
+ }
2562
+ ve.append(ze, Z);
2563
+ const pe = T("div", "rte-ie-row"), ne = T("label", void 0, "Quality");
2564
+ ne.htmlFor = "ie-quality";
2565
+ const O = T("input");
2566
+ O.type = "range", O.id = "ie-quality", O.min = "40", O.max = "100", O.step = "1", O.value = String(Math.round(r.quality * 100));
2567
+ const fe = T("output", "rte-ie-quality");
2568
+ fe.htmlFor = "ie-quality", pe.append(ne, O, fe), Ie.append(ve, pe);
2569
+ const W = T("p", "rte-ie-summary");
2570
+ W.setAttribute("aria-live", "polite"), w.append(S, Se, me, Ie, W);
2571
+ const oe = T("div", "rte-ie-body");
2572
+ oe.append(b, w);
2573
+ const Ue = T("div", "rte-media-footer"), ye = T("button", "rte-media-btn rte-media-btn-secondary", "Restore original");
2574
+ ye.type = "button", ye.hidden = !t.canRestore;
2575
+ const j = T("p", "rte-ie-footer-error");
2576
+ j.setAttribute("role", "alert"), j.hidden = !0;
2577
+ const ae = T("button", "cancel-btn rte-media-btn rte-media-btn-secondary", "Cancel");
2578
+ ae.type = "button";
2579
+ const Q = T("button", "rte-media-btn rte-media-btn-primary", "Apply");
2580
+ Q.type = "button", Q.id = "apply-btn", Q.disabled = !0, Ue.append(ye, j, T("span", "rte-mp-spacer"), ae, Q), p.append(u, oe, Ue), c.append(p), document.body.append(c);
2581
+ const we = () => !fr(r) || r.format !== "keep" || r.quality !== xt().quality, F = () => o ? Mt(o.width, o.height, r.rotation) : { width: 1, height: 1 }, ue = () => n.kind === "ratio" ? n.ratio : n.kind === "original" ? F().width / F().height : null, $e = (x, A) => ({
2582
+ x: x.x + x.width * (1 - A) / 2,
2583
+ y: x.y + x.height * (1 - A) / 2,
2584
+ width: x.width * A,
2585
+ height: x.height * A
2586
+ });
2587
+ function Oe(x) {
2588
+ var A, D;
2589
+ if (n = x, x.kind === "none")
2590
+ r = { ...r, crop: null }, C.setRect(null);
2591
+ else if (x.kind === "free")
2592
+ C.setAspect(null), r = { ...r, crop: (A = r.crop) != null ? A : { x: 0.1, y: 0.1, width: 0.8, height: 0.8 } }, C.setRect(r.crop);
2593
+ else {
2594
+ const X = ue();
2595
+ C.setAspect(X);
2596
+ const se = F();
2597
+ r = { ...r, crop: $e(vr(X, se.width, se.height, (D = r.crop) != null ? D : void 0), 0.9) }, C.setRect(r.crop);
2598
+ }
2599
+ g();
2600
+ }
2601
+ function Be(x) {
2602
+ r = { ...r, maxWidth: x }, H.value = x === null ? "" : String(x), g();
2603
+ }
2604
+ function be(x) {
2605
+ const A = x.rotation !== r.rotation;
2606
+ r = x, n.kind === "ratio" && A && (n = { ...n, ratio: 1 / n.ratio }), C.setImageSize(F().width, F().height), C.setAspect(ue()), C.setRect(r.crop), ke(), g();
2607
+ }
2608
+ function ke() {
2609
+ if (!o) return;
2610
+ const x = F(), A = Math.max(160, (b.clientWidth || 520) - 32), D = Math.max(120, (b.clientHeight || 400) - 32), X = Math.min(1, A / x.width, D / x.height), se = mi(o.source, o.width, o.height, r, X, e.canvas);
2611
+ y.replaceChildren(se, C.element), C.setImageSize(x.width, x.height);
2612
+ }
2613
+ function g() {
2614
+ for (const [A, D] of re) {
2615
+ const X = A === "original" ? n.kind === "original" : A === "none" ? n.kind === "none" : A === "free" ? n.kind === "free" : n.kind === "ratio" && n.id === A;
2616
+ D.setAttribute("aria-pressed", String(X));
2617
+ }
2618
+ for (const [A, D] of xe) D.setAttribute("aria-pressed", String(r.maxWidth === A));
2619
+ const x = Ae(r.format, i);
2620
+ pe.hidden = x === "image/png", fe.textContent = `${Math.round(r.quality * 100)}`;
2621
+ for (const A of [_, de, te, B, H, Z, O, ...re.values(), ...xe.values()])
2622
+ A.disabled = !o || s;
2623
+ Q.disabled = !o || s || !we(), Q.textContent = s ? "Saving…" : "Apply", k();
2624
+ }
2625
+ function k() {
2626
+ if (!o) return;
2627
+ a++, clearTimeout(l);
2628
+ const x = ci(r.crop, F().width, F().height), A = pi(x.width, x.height, r.maxWidth), D = i === "image/gif" ? " A GIF is saved as a still picture." : "", X = `<strong>${A.width} × ${A.height}</strong> px`;
2629
+ if (!we()) {
2630
+ W.innerHTML = "", W.textContent = `${o.width} × ${o.height} px. Nothing changed yet.${D}`;
2631
+ return;
2632
+ }
2633
+ W.innerHTML = `${X}, working out the file size…`;
2634
+ const se = a;
2635
+ l = setTimeout(async () => {
2636
+ try {
2637
+ const Ee = vt(o.source, o.width, o.height, r, i, e.canvas), _i = await yt(Ee, Ae(r.format, i), r.quality);
2638
+ if (se !== a) return;
2639
+ W.innerHTML = `${X}, about <strong>${Br(_i.size)}</strong>.`, D && W.append(D);
2640
+ } catch (Ee) {
2641
+ if (se !== a) return;
2642
+ W.textContent = Ee instanceof Error ? Ee.message : "Couldn't prepare the picture.";
2643
+ }
2644
+ }, 300);
2645
+ }
2646
+ function M() {
2647
+ clearTimeout(l), a++, d.abort(), V(), C.dispose(), P == null || P.disconnect(), c.remove();
2648
+ }
2649
+ async function I() {
2650
+ if (!(!o || s || !we())) {
2651
+ s = !0, j.hidden = !0, g();
2652
+ try {
2653
+ const x = vt(o.source, o.width, o.height, r, i, e.canvas), A = await yt(x, Ae(r.format, i), r.quality), D = A.type || Ae(r.format, i), X = new File([A], ui(t.name, D), { type: D }), se = await wi(X, {
2654
+ config: t.config,
2655
+ signal: d.signal,
2656
+ onProgress: ({ fraction: Ee }) => Q.textContent = `Saving… ${Math.round(Ee * 100)}%`
2657
+ });
2658
+ M(), t.onApply({ item: se, width: x.width, height: x.height });
2659
+ } catch (x) {
2660
+ if (Ze(x)) return;
2661
+ s = !1, j.textContent = x instanceof Error && x.message ? x.message : "Couldn't save the picture.", j.hidden = !1, g();
2662
+ }
2663
+ }
2664
+ }
2665
+ let V = () => {
2666
+ };
2667
+ V = Qe(c, M), m.addEventListener("click", M), ae.addEventListener("click", M), c.addEventListener("click", (x) => {
2668
+ x.target === c && M();
2669
+ }), Q.addEventListener("click", () => {
2670
+ I();
2671
+ }), ye.addEventListener("click", () => {
2672
+ var x;
2673
+ M(), (x = t.onRestore) == null || x.call(t);
2674
+ }), _.addEventListener("click", () => be(Ht(r, -1))), de.addEventListener("click", () => be(Ht(r, 1))), te.addEventListener("click", () => be(Ft(r, "h"))), B.addEventListener("click", () => be(Ft(r, "v"))), H.addEventListener("input", () => {
2675
+ const x = parseInt(H.value, 10);
2676
+ r = { ...r, maxWidth: Number.isFinite(x) && x > 0 ? x : null }, g();
2677
+ }), Z.addEventListener("change", () => {
2678
+ r = { ...r, format: Z.value }, g();
2679
+ }), O.addEventListener("input", () => {
2680
+ r = { ...r, quality: Number(O.value) / 100 }, g();
2681
+ });
2682
+ const P = typeof ResizeObserver == "undefined" ? null : new ResizeObserver(() => ke());
2683
+ g(), e.load(t.src).then((x) => {
2684
+ c.isConnected && (o = x, v.hidden = !0, y.hidden = !1, C.setImageSize(F().width, F().height), ke(), P == null || P.observe(b), g(), W.textContent = `${x.width} × ${x.height} px. Nothing changed yet.`, _.focus({ preventScroll: !0 }));
2685
+ }).catch((x) => {
2686
+ c.isConnected && (v.classList.add("is-error"), v.setAttribute("role", "alert"), v.textContent = x instanceof Le || x instanceof Error ? x.message : "This image couldn't be opened.", W.textContent = "");
2687
+ });
2688
+ }, Ei = (t) => typeof q(t).generateAltText == "function", Hr = (t) => {
2689
+ const e = (typeof t == "string" ? t : "").replace(/\s+/g, " ").trim().replace(/^["'“”]+|["'“”]+$/g, "").trim();
2690
+ return e.length > 500 ? `${e.slice(0, 497).trimEnd()}…` : e;
2691
+ }, Ai = (t) => {
2692
+ var l;
2693
+ const e = q(t.config).generateAltText;
2694
+ let i = null;
2695
+ const r = document.createElement("button");
2696
+ r.type = "button", r.className = "rte-mp-suggest";
2697
+ const n = (l = t.label) != null ? l : "Suggest";
2698
+ r.innerHTML = `${$.sparkle}<span></span>`, r.querySelector("span").textContent = n, r.setAttribute("aria-label", "Suggest alt text");
2699
+ const o = document.createElement("p");
2700
+ o.className = "rte-mp-hint", o.setAttribute("role", "status"), o.hidden = !0;
2701
+ const s = (d, c = !1) => {
2702
+ o.hidden = !d, o.textContent = d, o.classList.toggle("is-warning", c), o.setAttribute("role", c ? "alert" : "status");
2703
+ }, a = r.querySelector("span");
2704
+ return r.addEventListener("click", async () => {
2705
+ var c;
2706
+ if (!e || i) return;
2707
+ i = new AbortController();
2708
+ const d = i;
2709
+ r.disabled = !0, a.textContent = "Describing…", s("");
2710
+ try {
2711
+ const p = Hr(await e(t.image(), { signal: d.signal }));
2712
+ if (d.signal.aborted) return;
2713
+ if (!p) throw new Error("No description came back.");
2714
+ t.input.value = p, t.input.dispatchEvent(new Event("input", { bubbles: !0 })), (c = t.onFilled) == null || c.call(t), s("Suggested for you. Read it and change it if it is not right.");
2715
+ } catch (p) {
2716
+ if (d.signal.aborted) return;
2717
+ s(p instanceof Error && p.message ? p.message : "Couldn't suggest a description.", !0);
2718
+ } finally {
2719
+ i === d && (i = null), r.disabled = !1, a.textContent = n;
2720
+ }
2721
+ }), { button: r, status: o, abort: () => i == null ? void 0 : i.abort() };
2722
+ }, h = (t, e) => {
2723
+ const i = document.createElement(t);
2724
+ return e && (i.className = e), i;
2725
+ }, Fr = (t) => t.startsWith("data:") || t.startsWith("blob:") || t.includes("#") ? t : `${t}#t=0.1`, St = (t, e) => {
2726
+ const i = e != null ? e : t.type === "image" ? t.thumbnailUrl || t.src : t.thumbnailUrl;
2727
+ if (i) {
2728
+ const n = h("img");
2729
+ return n.src = i, n.alt = "", n.loading = "lazy", n.decoding = "async", n.draggable = !1, n.classList.add("rte-mp-fade"), n.addEventListener("load", () => n.classList.add("is-loaded")), n.addEventListener("error", () => n.classList.add("is-broken")), n;
2730
+ }
2731
+ if (t.type === "video") {
2732
+ const n = h("video");
2733
+ return n.src = Fr(e != null ? e : t.src), n.preload = "metadata", n.muted = !0, n.setAttribute("playsinline", ""), n.setAttribute("aria-hidden", "true"), n;
2734
+ }
2735
+ const r = h("span", "rte-mp-tile-icon");
2736
+ return r.innerHTML = t.type === "audio" ? $.audio : $.photo, r;
2737
+ }, Ci = (t = "video") => {
2738
+ const e = h("span", "rte-mp-tile-kind");
2739
+ return e.innerHTML = t === "audio" ? $.note : $.play, e;
2740
+ }, Li = () => {
2741
+ const t = h("span", "rte-mp-tile-check");
2742
+ return t.innerHTML = $.check, t;
2743
+ }, Pr = (t) => {
2744
+ const e = h("span", "rte-mp-tile-duration");
2745
+ return e.textContent = gi(t), e;
2746
+ }, Mi = (t) => {
2747
+ const e = h("span", "rte-mp-tile-name");
2748
+ return e.textContent = t, e;
2749
+ }, qr = (t) => {
2750
+ const e = h("div", "rte-mp-tile");
2751
+ return e.setAttribute("role", "option"), e.setAttribute("aria-selected", "false"), e.setAttribute("aria-label", t.type === "video" || t.type === "audio" ? `${t.name}, ${t.type}` : t.name), e.tabIndex = -1, e.dataset.id = t.id, e.append(St(t)), (t.type === "video" || t.type === "audio") && e.append(Ci(t.type)), (t.type === "video" || t.type === "audio") && t.duration && (e.classList.add("has-duration"), e.append(Pr(t.duration))), e.append(Mi(t.name), Wr(t), Li()), e;
2752
+ }, Wr = (t) => {
2753
+ var r, n;
2754
+ const e = h("span", "rte-mp-tile-meta"), i = (n = (r = t.mime.split("/")[1]) == null ? void 0 : r.toUpperCase()) != null ? n : t.type;
2755
+ return e.textContent = [i, Si(t.size), t.duration ? gi(t.duration) : ""].filter(Boolean).join(" · "), e;
2756
+ }, Si = (t) => t ? t >= 1024 * 1024 ? `${Math.round(t / (1024 * 1024) * 10) / 10} MB` : `${Math.max(1, Math.round(t / 1024))} KB` : "";
2757
+ class _r {
2758
+ constructor(e, i) {
2759
+ this.selection = e, this.options = i, this.element = h("aside", "rte-mp-details"), this.alts = /* @__PURE__ */ new Map(), this.captions = /* @__PURE__ */ new Map(), this.shown = null, this.suggest = null, this.suggestButton = null, this.element.setAttribute("aria-label", "Details"), this.element.hidden = !0;
2760
+ }
2761
+ /** The dialog is closing: stop a suggestion that is still being waited for. */
2762
+ dispose() {
2763
+ var e;
2764
+ (e = this.suggest) == null || e.abort(), this.suggest = null;
2765
+ }
2766
+ /** The alt attribute for an item: `''` when marked decorative, the text, or nothing. */
2767
+ altFor(e) {
2768
+ if (e.type !== "image") return;
2769
+ const i = this.alts.get(e.id);
2770
+ return i ? i.decorative ? "" : i.text || void 0 : e.alt || this.options.defaultAlt || void 0;
2771
+ }
2772
+ /** The caption for an item: what was typed, else the one kept with it (a photo credit). */
2773
+ captionFor(e) {
2774
+ var n;
2775
+ if (this.options.captions === !1) return;
2776
+ const i = this.captions.get(e.id);
2777
+ return (i != null ? i : typeof ((n = e.metadata) == null ? void 0 : n.caption) == "string" ? e.metadata.caption : "").trim() || void 0;
2778
+ }
2779
+ show(e) {
2780
+ var s, a;
2781
+ if (e && ((s = this.shown) == null ? void 0 : s.id) === e.id && this.element.contains(document.activeElement)) return;
2782
+ if (this.shown = e, (a = this.suggest) == null || a.abort(), this.suggest = null, this.suggestButton = null, this.element.replaceChildren(), !e) {
2783
+ this.element.hidden = !0;
2784
+ return;
2785
+ }
2786
+ this.element.hidden = !1;
2787
+ const i = h("div", "rte-mp-preview");
2788
+ i.append(this.previewMedia(e)), this.element.append(i);
2789
+ const r = h("div"), n = h("p", "rte-mp-meta-name");
2790
+ n.textContent = e.name;
2791
+ const o = h("p", "rte-mp-meta");
2792
+ if (this.element.append(r), r.append(n, o), this.fillMeta(o, e), this.selection.size > 1) {
2793
+ const l = h("p", "rte-mp-hint");
2794
+ l.textContent = `${this.selection.size} items selected. Choose one of them to describe it.`, this.element.append(l);
2795
+ }
2796
+ if (e.type === "image" && this.element.append(this.altField(e)), e.type === "image" && this.options.onEdit && this.element.append(this.actions(e)), this.options.captions !== !1 && this.element.append(this.captionField(e)), this.options.canDelete(e)) {
2797
+ const l = h("button", "rte-media-btn rte-media-btn-secondary");
2798
+ l.type = "button", l.innerHTML = `${$.trash}<span style="margin-left:6px">Delete from library</span>`, l.addEventListener("click", () => this.options.onDelete(e)), this.element.append(l);
2799
+ }
2800
+ }
2801
+ previewMedia(e) {
2802
+ if (e.type === "audio") {
2803
+ const r = h("audio");
2804
+ return r.src = e.src, r.controls = !0, r.preload = "none", r.style.width = "100%", r;
2805
+ }
2806
+ if (e.type === "video") {
2807
+ const r = h("video");
2808
+ return r.src = e.src, r.controls = !0, r.preload = "metadata", r.setAttribute("playsinline", ""), r;
2809
+ }
2810
+ return St({ ...e, thumbnailUrl: e.src });
2811
+ }
2812
+ fillMeta(e, i) {
2813
+ const r = (n, o) => {
2814
+ var a, l;
2815
+ const s = [n && o ? `${n} × ${o}` : "", Si(i.size), (l = (a = i.mime.split("/")[1]) == null ? void 0 : a.toUpperCase()) != null ? l : ""];
2816
+ e.textContent = s.filter(Boolean).join(" · ");
2817
+ };
2818
+ if (r(i.width, i.height), i.type === "image" && !(i.width && i.height) && typeof Image != "undefined") {
2819
+ const n = new Image();
2820
+ n.onload = () => {
2821
+ this.shown === i && e.isConnected && r(n.naturalWidth, n.naturalHeight);
2822
+ }, n.src = i.src;
2823
+ }
2824
+ }
2825
+ /** Edit, and (when a service is configured) Alt: the two things to do with the picture itself. */
2826
+ actions(e) {
2827
+ const i = h("div", "rte-mp-actions"), r = h("button", "rte-media-btn rte-media-btn-secondary rte-mp-action");
2828
+ r.type = "button", r.innerHTML = `${$.edit}<span></span>`, r.querySelector("span").textContent = "Edit", r.setAttribute("aria-label", `Edit ${e.name}`), r.addEventListener("click", () => {
2829
+ var o, s;
2830
+ return (s = (o = this.options).onEdit) == null ? void 0 : s.call(o, e);
2831
+ }), i.append(r);
2832
+ const n = this.suggestButton;
2833
+ return n && i.append(n), i;
2834
+ }
2835
+ captionField(e) {
2836
+ var o, s;
2837
+ const i = h("div", "rte-media-field"), r = h("label", "rte-media-label");
2838
+ r.htmlFor = "detail-caption", r.textContent = "Caption";
2839
+ const n = h("input", "rte-media-input");
2840
+ return n.type = "text", n.id = "detail-caption", n.placeholder = "Shown under the media", n.value = (s = this.captions.get(e.id)) != null ? s : typeof ((o = e.metadata) == null ? void 0 : o.caption) == "string" ? e.metadata.caption : "", n.addEventListener("input", () => this.captions.set(e.id, n.value)), i.append(r, n), i;
2841
+ }
2842
+ altField(e) {
2843
+ var u;
2844
+ const i = (u = this.alts.get(e.id)) != null ? u : {
2845
+ text: e.alt || this.options.defaultAlt || "",
2846
+ decorative: !1
2847
+ }, r = h("div", "rte-media-field"), n = h("div", "rte-mp-label-row"), o = h("label", "rte-media-label");
2848
+ o.htmlFor = "detail-alt", o.textContent = "Alt text", n.append(o);
2849
+ const s = h("textarea", "rte-media-textarea");
2850
+ s.id = "detail-alt", s.rows = 3, s.placeholder = "Describe the image", s.value = i.text, s.disabled = i.decorative;
2851
+ const a = h("p", "rte-mp-hint"), l = h("label", "rte-media-checkbox-label"), d = h("input");
2852
+ d.type = "checkbox", d.id = "detail-decorative", d.checked = i.decorative, l.append(d, document.createTextNode("This image is decorative"));
2853
+ const c = () => {
2854
+ const f = !d.checked && !s.value.trim();
2855
+ a.classList.toggle("is-warning", f), a.textContent = d.checked ? "Screen readers will skip it." : f ? "Add a description so people who can't see the image know what it shows." : "Read aloud by screen readers and shown if the image does not load.";
2856
+ }, p = () => {
2857
+ this.alts.set(e.id, { text: s.value, decorative: d.checked }), s.disabled = d.checked, c();
2858
+ };
2859
+ if (s.addEventListener("input", p), d.addEventListener("change", p), c(), r.append(n, s, a, l), Ei(this.options.config)) {
2860
+ const f = Ai({
2861
+ config: this.options.config,
2862
+ image: () => ({ src: e.src, name: e.name }),
2863
+ label: this.options.onEdit ? "Alt" : void 0,
2864
+ input: s,
2865
+ // A description fills the field, so the picture is no longer decorative.
2866
+ onFilled: () => {
2867
+ d.checked = !1, p();
2868
+ }
2869
+ });
2870
+ this.suggest = f, this.options.onEdit ? (f.button.classList.add("rte-media-btn", "rte-media-btn-secondary", "rte-mp-action"), this.suggestButton = f.button) : n.append(f.button), a.after(f.status);
2871
+ }
2872
+ return r;
2873
+ }
2874
+ }
2875
+ const jr = /* @__PURE__ */ new Set(["youtube.com", "m.youtube.com", "music.youtube.com", "youtube-nocookie.com"]), Vr = /^[\w-]{11}$/, Kr = /^[\w-]{10,64}$/, Gr = (t) => {
2876
+ var i, r, n;
2877
+ if (!t) return null;
2878
+ if (/^\d+$/.test(t)) return Number(t);
2879
+ const e = /^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/.exec(t);
2880
+ return !e || !(e[1] || e[2] || e[3]) ? null : Number((i = e[1]) != null ? i : 0) * 3600 + Number((r = e[2]) != null ? r : 0) * 60 + Number((n = e[3]) != null ? n : 0);
2881
+ }, Yr = {
2882
+ id: "youtube",
2883
+ label: "YouTube video",
2884
+ parse(t) {
2885
+ var o, s;
2886
+ const e = t.hostname.replace(/^www\./, "").toLowerCase();
2887
+ let i = null, r;
2888
+ if (e === "youtu.be")
2889
+ i = (o = t.pathname.split("/").filter(Boolean)[0]) != null ? o : null;
2890
+ else if (jr.has(e)) {
2891
+ const [a, l] = t.pathname.split("/").filter(Boolean);
2892
+ if (a === "watch" ? i = t.searchParams.get("v") : a === "embed" || a === "v" || a === "live" ? i = l != null ? l : null : a === "shorts" && (i = l != null ? l : null, r = 9 / 16), !i && t.searchParams.get("list") && (a === "playlist" || a === "watch")) {
2893
+ const d = t.searchParams.get("list");
2894
+ return Kr.test(d) ? {
2895
+ src: `https://www.youtube-nocookie.com/embed/videoseries?list=${encodeURIComponent(d)}`,
2896
+ id: `list:${d}`
2897
+ } : null;
2898
+ }
2899
+ }
2900
+ if (!i || !Vr.test(i)) return null;
2901
+ const n = Gr((s = t.searchParams.get("t")) != null ? s : t.searchParams.get("start"));
2902
+ return {
2903
+ src: `https://www.youtube-nocookie.com/embed/${i}${n ? `?start=${n}` : ""}`,
2904
+ id: i,
2905
+ aspectRatio: r
2906
+ };
2907
+ }
2908
+ }, Xr = {
2909
+ id: "vimeo",
2910
+ label: "Vimeo video",
2911
+ parse(t) {
2912
+ var a;
2913
+ const e = t.hostname.replace(/^www\./, "").toLowerCase();
2914
+ if (e !== "vimeo.com" && e !== "player.vimeo.com") return null;
2915
+ const i = t.pathname.split("/").filter(Boolean), r = i.findIndex((l) => /^\d{5,12}$/.test(l));
2916
+ if (r === -1) return null;
2917
+ const n = i[r], o = (a = i[r + 1]) != null ? a : t.searchParams.get("h"), s = new URLSearchParams({ dnt: "1" });
2918
+ return o && /^[a-f0-9]{6,20}$/i.test(o) && s.set("h", o), { src: `https://player.vimeo.com/video/${n}?${s}`, id: n };
2919
+ }
2920
+ }, Zr = [Yr, Xr], Qr = (t) => {
2921
+ var e, i;
2922
+ return (i = (e = /<iframe\b[^>]*?\bsrc\s*=\s*["']([^"']+)["']/i.exec(t)) == null ? void 0 : e[1]) != null ? i : null;
2923
+ }, Jr = (t, e = []) => {
2924
+ var n, o;
2925
+ const i = ((n = Qr(t)) != null ? n : t).trim();
2926
+ if (!i || /\s/.test(i)) return null;
2927
+ let r;
2928
+ try {
2929
+ r = new URL(/^[a-z][a-z0-9+.-]*:/i.test(i) ? i : `https://${i}`);
2930
+ } catch (s) {
2931
+ return null;
2932
+ }
2933
+ if (r.protocol !== "https:" && r.protocol !== "http:") return null;
2934
+ for (const s of [...e, ...Zr]) {
2935
+ const a = s.parse(r);
2936
+ if (a)
2937
+ return /^https:\/\/[^\s]+$/.test(a.src) ? { provider: s.id, label: s.label, src: a.src, id: a.id, aspectRatio: (o = a.aspectRatio) != null ? o : 16 / 9 } : null;
2938
+ }
2939
+ return null;
2940
+ };
2941
+ class en {
2942
+ constructor(e, i, r) {
2943
+ this.providers = e, this.onChange = i, this.onSubmit = r, this.element = h("div", "rte-mp-view"), this.urlInput = h("input", "rte-media-input"), this.titleInput = h("input", "rte-media-input"), this.status = h("p", "rte-mp-embed-status"), this.parsed = null, this.element.setAttribute("role", "tabpanel"), this.element.id = "rte-mp-panel-embed", this.element.hidden = !0;
2944
+ const n = h("div", "rte-mp-form"), o = (a, l, d, c) => {
2945
+ const p = h("div", "rte-media-field"), u = h("label", "rte-media-label");
2946
+ return u.htmlFor = d, u.textContent = a, l.id = d, Object.assign(l, c), p.append(u, l), p;
2947
+ }, s = h("p", "rte-mp-hint");
2948
+ s.textContent = "Paste a link to a YouTube or Vimeo video, or the embed code the site gives you.", n.append(
2949
+ s,
2950
+ o("Video link", this.urlInput, "embed-url", { type: "text", placeholder: "https://www.youtube.com/watch?v=…" }),
2951
+ o("Title (for screen readers)", this.titleInput, "embed-title", { type: "text", placeholder: "What the video is about" })
2952
+ ), this.status.setAttribute("role", "status"), n.append(this.status), this.element.append(n), this.renderStatus(), this.urlInput.addEventListener("input", () => {
2953
+ this.parsed = Jr(this.urlInput.value, this.providers), this.renderStatus(), this.onChange();
2954
+ }), this.urlInput.addEventListener("keydown", (a) => {
2955
+ a.key === "Enter" && this.parsed && (a.preventDefault(), this.onSubmit());
2956
+ });
2957
+ }
2958
+ /** What would be embedded, or null while the link is empty or not one that can be. */
2959
+ get spec() {
2960
+ return this.parsed;
2961
+ }
2962
+ get title() {
2963
+ return this.titleInput.value.trim();
2964
+ }
2965
+ focus() {
2966
+ this.urlInput.focus({ preventScroll: !0 });
2967
+ }
2968
+ renderStatus() {
2969
+ const e = this.urlInput.value.trim();
2970
+ if (this.status.className = "rte-mp-embed-status", this.status.replaceChildren(), !!e)
2971
+ if (this.parsed) {
2972
+ this.status.classList.add("is-ok"), this.status.innerHTML = `<span aria-hidden="true">${$.embed}</span>`;
2973
+ const i = h("span");
2974
+ i.textContent = `${this.parsed.label} found. It loads when you insert it.`, this.status.append(i);
2975
+ } else
2976
+ this.status.classList.add("is-error"), this.status.textContent = "That isn't a link to a video this can embed. YouTube and Vimeo links work.";
2977
+ }
2978
+ }
2979
+ const tn = {
2980
+ image: { one: "image", many: "images" },
2981
+ video: { one: "video", many: "videos" },
2982
+ audio: { one: "audio file", many: "audio files" }
2983
+ }, Ve = (t, e = !1) => t.length === 1 ? tn[t[0]][e ? "many" : "one"] : e ? "items" : "item", Wt = (t, e) => (t.type === "image" || t.type === "video" || t.type === "audio") && e.includes(t.type), Ti = (t, e = "li") => {
2984
+ const i = h(e, "rte-mp-tile");
2985
+ i.dataset.upload = t.id;
2986
+ const r = t.file.type.startsWith("video/") ? "video" : t.file.type.startsWith("audio/") ? "audio" : "image";
2987
+ return i.append(St({ type: r, src: "", thumbnailUrl: void 0 }, t.previewUrl)), (r === "video" || r === "audio") && i.append(Ci(r)), i;
2988
+ }, Ii = (t, e, i) => {
2989
+ var o;
2990
+ t.classList.toggle("is-uploading", e.status === "uploading" || e.status === "queued"), t.classList.toggle("is-failed", e.status === "error"), t.querySelectorAll(".rte-mp-progress, .rte-mp-tile-status, .rte-mp-tile-pick, .rte-mp-tile-check, .rte-mp-tile-name, .rte-mp-tile-actions").forEach((s) => s.remove());
2991
+ const r = (s) => {
2992
+ const a = h("div", "rte-mp-tile-status"), l = h("span");
2993
+ return l.textContent = s, a.append(l), a;
2994
+ }, n = (s, a, l) => {
2995
+ const d = h("button", "rte-mp-icon-btn");
2996
+ return d.type = "button", d.setAttribute("aria-label", `${s} ${e.file.name}`), d.innerHTML = a, d.addEventListener("click", l), d;
2997
+ };
2998
+ if (e.status === "queued" || e.status === "uploading") {
2999
+ const s = Math.round(e.fraction * 100), a = r(e.status === "queued" ? "Waiting…" : `Uploading ${s}%`);
3000
+ a.setAttribute("role", "status");
3001
+ const l = h("div", "rte-mp-progress");
3002
+ l.setAttribute("role", "progressbar"), l.setAttribute("aria-label", `Uploading ${e.file.name}`), l.setAttribute("aria-valuemin", "0"), l.setAttribute("aria-valuemax", "100"), l.setAttribute("aria-valuenow", String(s));
3003
+ const d = h("span");
3004
+ d.style.width = `${s}%`, l.append(d);
3005
+ const c = h("div", "rte-mp-tile-actions");
3006
+ return c.append(n("Cancel upload of", $.close, () => i.remove(e.id))), t.append(a, l, c), !0;
3007
+ }
3008
+ if (e.status === "error") {
3009
+ const s = r((o = e.error) != null ? o : "Couldn't upload this file.");
3010
+ s.setAttribute("role", "alert");
3011
+ const a = h("div", "rte-mp-tile-actions");
3012
+ return e.retryable !== !1 && a.append(n("Retry", $.retry, () => i.retry(e.id))), a.append(n("Remove", $.close, () => i.remove(e.id))), t.append(s, a), !0;
3013
+ }
3014
+ return !1;
3015
+ }, rn = 24, nn = 300, _t = [
3016
+ { id: "all", label: "All" },
3017
+ { id: "image", label: "Images" },
3018
+ { id: "video", label: "Video" },
3019
+ { id: "audio", label: "Audio" }
3020
+ ];
3021
+ class jt {
3022
+ constructor(e, i, r = {}) {
3023
+ var n, o, s;
3024
+ if (this.ctx = e, this.onUpload = i, this.options = r, this.element = h("div", "rte-mp-view"), this.scroll = h("div", "rte-mp-scroll"), this.content = h("div"), this.items = [], this.total = 0, this.page = 0, this.loading = !1, this.failed = null, this.loaded = !1, this.stale = !1, this.search = "", this.controller = null, this.observer = null, this.focusId = null, this.sort = "newest", this.layout = "grid", this.pending = /* @__PURE__ */ new Map(), this.toolbar = h("div", "rte-mp-toolbar"), this.lastClicked = null, this.onKeyDown = (a) => {
3025
+ var b;
3026
+ const l = a.target.closest(".rte-mp-tile[data-id]");
3027
+ if (!l) return;
3028
+ const d = this.tiles(), c = d.indexOf(l), p = this.columns(d), u = this.items.find((v) => v.id === l.dataset.id), { selection: f } = this.ctx, m = (v) => {
3029
+ var z, C;
3030
+ const y = d[Math.min(Math.max(v, 0), d.length - 1)];
3031
+ y && (d.forEach((w) => w.tabIndex = -1), y.tabIndex = 0, y.focus(), (z = y.scrollIntoView) == null || z.call(y, { block: "nearest" }), a.shiftKey && f.multiple && f.range(this.items, (C = this.lastClicked) != null ? C : l.dataset.id, y.dataset.id));
3032
+ };
3033
+ switch (a.key) {
3034
+ case "ArrowRight":
3035
+ a.preventDefault(), m(c + 1);
3036
+ break;
3037
+ case "ArrowLeft":
3038
+ a.preventDefault(), m(c - 1);
3039
+ break;
3040
+ case "ArrowDown":
3041
+ a.preventDefault(), m(c + p);
3042
+ break;
3043
+ case "ArrowUp":
3044
+ a.preventDefault(), m(c - p);
3045
+ break;
3046
+ case "Home":
3047
+ a.preventDefault(), m(a.ctrlKey ? 0 : c - c % p);
3048
+ break;
3049
+ case "End":
3050
+ a.preventDefault(), m(a.ctrlKey ? d.length - 1 : c - c % p + p - 1);
3051
+ break;
3052
+ case " ":
3053
+ a.preventDefault(), f.toggle(u), this.lastClicked = u.id, this.ctx.setActive(f.has(u.id) ? u : (b = f.items.at(-1)) != null ? b : null);
3054
+ break;
3055
+ case "Enter":
3056
+ a.preventDefault(), this.ctx.commit(f.size ? void 0 : [u]);
3057
+ break;
3058
+ case "a":
3059
+ case "A":
3060
+ (a.metaKey || a.ctrlKey) && (a.preventDefault(), f.all(this.items), this.ctx.setActive(u));
3061
+ break;
3062
+ }
3063
+ }, this.filter = (o = (n = r.pills) == null ? void 0 : n.filter) != null ? o : "all", this.element.setAttribute("role", "tabpanel"), this.element.id = `rte-mp-panel-${(s = r.id) != null ? s : "library"}`, this.element.hidden = !0, this.scroll.append(this.content), r.pills) {
3064
+ this.toolbar.setAttribute("role", "group"), this.toolbar.setAttribute("aria-label", "Show");
3065
+ for (const { id: a, label: l } of _t) {
3066
+ const d = h("button", "rte-mp-chip");
3067
+ d.type = "button", d.dataset.filter = a, d.textContent = l, d.setAttribute("aria-pressed", String(a === this.filter)), d.addEventListener("click", () => this.setFilter(a)), this.toolbar.append(d);
3068
+ }
3069
+ this.element.append(this.toolbar);
3070
+ }
3071
+ this.element.append(this.scroll), this.content.addEventListener("keydown", this.onKeyDown);
3072
+ }
3073
+ /** The panel became the visible one. Loads on first sight, and again when uploads or deletions made it stale. */
3074
+ activate() {
3075
+ (!this.loaded || this.stale) && this.reload();
3076
+ }
3077
+ markStale() {
3078
+ this.stale = !0;
3079
+ }
3080
+ /** The kinds the grid lists: one when a filter is chosen, else everything the dialog takes. */
3081
+ get kinds() {
3082
+ return this.options.kinds ? this.options.kinds : this.filter === "all" ? this.ctx.allowedKinds : [this.filter];
3083
+ }
3084
+ setFilter(e) {
3085
+ e !== this.filter && (this.filter = e, this.toolbar.querySelectorAll(".rte-mp-chip").forEach((i) => i.setAttribute("aria-pressed", String(i.dataset.filter === e))), this.reload());
3086
+ }
3087
+ setSort(e) {
3088
+ e !== this.sort && (this.sort = e, this.reload());
3089
+ }
3090
+ setLayout(e) {
3091
+ var i;
3092
+ this.layout = e, (i = this.content.querySelector(".rte-mp-grid")) == null || i.classList.toggle("is-list", e === "list");
3093
+ }
3094
+ /** A file that has just been uploaded (or edited): at the top of the list without asking the server again. */
3095
+ addUploaded(e) {
3096
+ if (this.loaded) {
3097
+ if (this.sort !== "newest" || this.search || !Wt(e, this.kinds)) {
3098
+ this.stale = !0, this.element.hidden || this.reload();
3099
+ return;
3100
+ }
3101
+ this.items.some((i) => i.id === e.id) || (this.items.unshift(e), this.total += 1, this.render());
3102
+ }
3103
+ }
3104
+ /** Show the files that are going up as tiles at the start of the grid, updating them as they progress. */
3105
+ syncPending() {
3106
+ var n, o, s;
3107
+ const e = (o = (n = this.options).queue) == null ? void 0 : o.call(n), i = ((s = e == null ? void 0 : e.entries) != null ? s : []).filter((a) => a.status !== "done" && !a.item), r = this.content.querySelector(".rte-mp-grid");
3108
+ if (e) {
3109
+ if (!r && i.length) {
3110
+ this.render();
3111
+ return;
3112
+ }
3113
+ for (const [a, l] of this.pending)
3114
+ i.some((d) => d.id === a) || (l.remove(), this.pending.delete(a));
3115
+ r && (i.forEach((a, l) => {
3116
+ var c;
3117
+ let d = this.pending.get(a.id);
3118
+ d || (d = Ti(a, "div"), d.setAttribute("role", "group"), d.setAttribute("aria-label", a.file.name), this.pending.set(a.id, d)), Ii(d, a, e), r.children[l] !== d && r.insertBefore(d, (c = r.children[l]) != null ? c : null);
3119
+ }), i.length === 0 && this.items.length === 0 && this.loaded && !this.loading && this.render());
3120
+ }
3121
+ }
3122
+ setSearch(e) {
3123
+ clearTimeout(this.searchTimer), this.searchTimer = setTimeout(() => {
3124
+ e !== this.search && (this.search = e, this.reload());
3125
+ }, nn);
3126
+ }
3127
+ dispose() {
3128
+ var e, i;
3129
+ clearTimeout(this.searchTimer), (e = this.controller) == null || e.abort(), (i = this.observer) == null || i.disconnect();
3130
+ }
3131
+ /** Reflect the selection on the tiles without rebuilding them (which would lose the focus). */
3132
+ syncSelection() {
3133
+ this.content.querySelectorAll(".rte-mp-tile[data-id]").forEach((e) => {
3134
+ e.setAttribute("aria-selected", String(this.ctx.selection.has(e.dataset.id)));
3135
+ });
3136
+ }
3137
+ focusGrid() {
3138
+ var r;
3139
+ const e = this.tiles()[0];
3140
+ this.tiles().forEach((n) => n.tabIndex = -1);
3141
+ const i = (r = this.content.querySelector('.rte-mp-tile[aria-selected="true"]')) != null ? r : e;
3142
+ i && (i.tabIndex = 0, i.focus({ preventScroll: !0 }));
3143
+ }
3144
+ async deleteItem(e) {
3145
+ const { provider: i } = this.ctx;
3146
+ if (!i.delete || !await Et(`Delete ${e.name} from the library? Documents that use it will lose the picture.`, {
3147
+ title: "Delete from library",
3148
+ confirmText: "Delete",
3149
+ danger: !0,
3150
+ context: this.element
3151
+ })) return !1;
3152
+ try {
3153
+ await i.delete(e.id);
3154
+ } catch (n) {
3155
+ return this.ctx.announce(n instanceof Error ? n.message : "Couldn't delete the file."), !1;
3156
+ }
3157
+ return this.ctx.selection.remove(e.id), this.items = this.items.filter((n) => n.id !== e.id), this.total = Math.max(0, this.total - 1), this.render(), this.ctx.announce(`Deleted ${e.name}`), !0;
3158
+ }
3159
+ async reload() {
3160
+ var e;
3161
+ (e = this.controller) == null || e.abort(), this.items = [], this.total = 0, this.page = 0, this.failed = null, this.stale = !1, await this.loadPage();
3162
+ }
3163
+ async loadPage() {
3164
+ var r;
3165
+ const e = (r = this.options.source) != null ? r : this.ctx.provider;
3166
+ if (!e.list) return;
3167
+ const i = new AbortController();
3168
+ this.controller = i, this.loading = !0, this.render();
3169
+ try {
3170
+ const n = await e.list(
3171
+ {
3172
+ page: this.page + 1,
3173
+ limit: rn,
3174
+ search: this.search || void 0,
3175
+ type: this.kinds.length === 1 ? this.kinds[0] : void 0,
3176
+ sort: this.options.sortable === !1 || this.sort === "newest" ? void 0 : this.sort
3177
+ },
3178
+ { signal: i.signal }
3179
+ );
3180
+ if (i !== this.controller) return;
3181
+ this.page += 1, this.total = n.total;
3182
+ const o = new Set(this.items.map((s) => s.id));
3183
+ this.items.push(...n.items.filter((s) => Wt(s, this.kinds) && !o.has(s.id))), this.failed = null, this.loaded = !0, this.ctx.announce(this.items.length ? `${this.total} item${this.total === 1 ? "" : "s"}` : "No results");
3184
+ } catch (n) {
3185
+ if (i !== this.controller || Ze(n)) return;
3186
+ this.failed = n instanceof Error && n.message ? n.message : "Couldn't load your media.", this.loaded = !0;
3187
+ } finally {
3188
+ i === this.controller && (this.loading = !1, this.render());
3189
+ }
3190
+ }
3191
+ tiles() {
3192
+ return [...this.content.querySelectorAll(".rte-mp-tile[data-id]")];
3193
+ }
3194
+ render() {
3195
+ var a, l, d, c, p, u, f;
3196
+ (a = this.observer) == null || a.disconnect();
3197
+ const e = document.activeElement instanceof HTMLElement ? document.activeElement.dataset.id : void 0;
3198
+ this.focusId = e && this.content.contains(document.activeElement) ? e : null, this.content.replaceChildren(), this.pending.clear();
3199
+ const i = ((p = (c = (d = (l = this.options).queue) == null ? void 0 : d.call(l)) == null ? void 0 : c.entries) != null ? p : []).some((m) => m.status !== "done" && !m.item), r = this.items.length > 0 || i;
3200
+ if (this.failed && !r) {
3201
+ this.content.append(this.errorBlock(this.failed));
3202
+ return;
3203
+ }
3204
+ if (!r && this.loading) {
3205
+ const m = h("div", "rte-mp-grid");
3206
+ m.setAttribute("aria-busy", "true");
3207
+ for (let b = 0; b < 12; b++) m.append(h("div", "rte-mp-tile is-skeleton"));
3208
+ this.content.append(m);
3209
+ return;
3210
+ }
3211
+ if (!r) {
3212
+ this.content.append(this.emptyBlock());
3213
+ return;
3214
+ }
3215
+ const n = h("div", "rte-mp-grid");
3216
+ n.classList.toggle("is-list", this.layout === "list"), n.setAttribute("role", "listbox"), n.setAttribute("aria-label", "Media library"), this.ctx.selection.multiple && n.setAttribute("aria-multiselectable", "true");
3217
+ for (const m of this.items) {
3218
+ const b = qr(m);
3219
+ b.addEventListener("click", (v) => this.onTileClick(v, m)), b.addEventListener("dblclick", () => this.ctx.commit([m])), n.append(b);
3220
+ }
3221
+ if (this.content.append(n), this.syncPending(), this.failed && this.content.append(this.errorBlock(this.failed, !0)), (this.items.length < this.total || this.loading) && this.content.append(this.moreButton()), this.options.dropHint) {
3222
+ const m = h("p", "rte-mp-drop-hint");
3223
+ m.textContent = "Drop files anywhere in this window to upload", this.content.append(m);
3224
+ }
3225
+ const o = this.tiles(), s = (f = (u = o.find((m) => m.dataset.id === this.focusId)) != null ? u : o.find((m) => m.getAttribute("aria-selected") === "true")) != null ? f : o[0];
3226
+ s && (s.tabIndex = 0), this.focusId && s && s.focus({ preventScroll: !0 }), this.syncSelection();
3227
+ }
3228
+ moreButton() {
3229
+ const e = h("button", "rte-media-btn rte-media-btn-secondary rte-mp-more");
3230
+ return e.type = "button", e.textContent = this.loading ? "Loading…" : "Load more", e.addEventListener("click", () => {
3231
+ this.loadPage();
3232
+ }), !this.loading && typeof IntersectionObserver != "undefined" && (this.observer = new IntersectionObserver(
3233
+ (i) => {
3234
+ i.some((r) => r.isIntersecting) && !this.loading && this.loadPage();
3235
+ },
3236
+ { root: this.scroll, rootMargin: "200px" }
3237
+ ), this.observer.observe(e)), e;
3238
+ }
3239
+ emptyBlock() {
3240
+ var s, a, l;
3241
+ const e = h("div", "rte-mp-empty"), i = !!this.search;
3242
+ e.innerHTML = `<span aria-hidden="true">${$.photo}</span>`;
3243
+ const r = h("strong"), n = (s = _t.find((d) => d.id === this.filter)) == null ? void 0 : s.label.toLowerCase();
3244
+ r.textContent = i ? `No results for “${this.search}”` : (a = this.options.emptyTitle) != null ? a : this.filter !== "all" && !this.options.kinds ? `No ${n} in your library yet` : "Nothing in your library yet";
3245
+ const o = h("span");
3246
+ if (o.textContent = i ? "Try a different word." : (l = this.options.emptyHint) != null ? l : "Upload files and they will show up here.", e.append(r, o), !i && this.options.offerUpload !== !1) {
3247
+ const d = h("button", "rte-media-btn rte-media-btn-primary");
3248
+ d.type = "button", d.textContent = "Upload files", d.addEventListener("click", this.onUpload), e.append(d);
3249
+ }
3250
+ return e;
3251
+ }
3252
+ errorBlock(e, i = !1) {
3253
+ const r = h("div", "rte-mp-error");
3254
+ r.setAttribute("role", "alert"), i && (r.style.minHeight = "0"), r.innerHTML = `<span aria-hidden="true">${$.alert}</span>`;
3255
+ const n = h("strong");
3256
+ n.textContent = e;
3257
+ const o = h("button", "rte-media-btn rte-media-btn-secondary");
3258
+ return o.type = "button", o.textContent = "Try again", o.addEventListener("click", () => {
3259
+ this.items.length ? this.loadPage() : this.reload();
3260
+ }), r.append(n, o), r;
3261
+ }
3262
+ onTileClick(e, i) {
3263
+ var n;
3264
+ const { selection: r } = this.ctx;
3265
+ e.shiftKey && this.lastClicked && r.multiple ? r.range(this.items, this.lastClicked, i.id) : r.toggle(i), this.lastClicked = i.id, this.ctx.setActive(r.has(i.id) ? i : (n = r.items.at(-1)) != null ? n : null), this.tiles().forEach((o) => o.tabIndex = o.dataset.id === i.id ? 0 : -1);
3266
+ }
3267
+ columns(e) {
3268
+ if (e.length < 2) return 1;
3269
+ const i = e[0].offsetTop, r = e.findIndex((n) => n.offsetTop !== i);
3270
+ return r === -1 ? e.length : Math.max(r, 1);
3271
+ }
3272
+ }
3273
+ class on {
3274
+ constructor(e, i = () => {
3275
+ }) {
3276
+ this.multiple = e, this.onChange = i, this.chosen = /* @__PURE__ */ new Map();
3277
+ }
3278
+ get items() {
3279
+ return [...this.chosen.values()];
3280
+ }
3281
+ get size() {
3282
+ return this.chosen.size;
3283
+ }
3284
+ has(e) {
3285
+ return this.chosen.has(e);
3286
+ }
3287
+ /** Choose exactly this one. */
3288
+ only(e) {
3289
+ this.chosen = /* @__PURE__ */ new Map([[e.id, e]]), this.onChange();
3290
+ }
3291
+ toggle(e) {
3292
+ if (!this.multiple) {
3293
+ this.only(e);
3294
+ return;
3295
+ }
3296
+ this.chosen.has(e.id) ? this.chosen.delete(e.id) : this.chosen.set(e.id, e), this.onChange();
3297
+ }
3298
+ /** Choose everything between two items of `ordered`, inclusive, keeping what was already chosen. */
3299
+ range(e, i, r) {
3300
+ if (!this.multiple) return;
3301
+ const n = e.findIndex((s) => s.id === i), o = e.findIndex((s) => s.id === r);
3302
+ if (!(n === -1 || o === -1)) {
3303
+ for (const s of e.slice(Math.min(n, o), Math.max(n, o) + 1)) this.chosen.set(s.id, s);
3304
+ this.onChange();
3305
+ }
3306
+ }
3307
+ all(e) {
3308
+ this.multiple && (e.forEach((i) => this.chosen.set(i.id, i)), this.onChange());
3309
+ }
3310
+ remove(e) {
3311
+ this.chosen.delete(e) && this.onChange();
3312
+ }
3313
+ clear() {
3314
+ this.chosen.size !== 0 && (this.chosen.clear(), this.onChange());
3315
+ }
3316
+ }
3317
+ const an = (t, e) => {
3318
+ var i;
3319
+ return t.caption === !1 ? null : typeof t.caption == "function" ? ((i = t.caption(e)) == null ? void 0 : i.trim()) || null : e.author ? `Photo by ${e.author} on ${t.name}` : null;
3320
+ }, sn = (t, e) => {
3321
+ var i, r;
3322
+ return {
3323
+ id: `stock-${e.id}`,
3324
+ name: ((i = e.description) == null ? void 0 : i.trim()) || e.author || `Photo ${e.id}`,
3325
+ type: "image",
3326
+ src: e.url,
3327
+ thumbnailUrl: e.thumbnailUrl,
3328
+ size: 0,
3329
+ width: e.width,
3330
+ height: e.height,
3331
+ mime: "image/jpeg",
3332
+ createdAt: 0,
3333
+ alt: ((r = e.description) == null ? void 0 : r.trim()) || void 0,
3334
+ metadata: { stock: !0, caption: an(t, e), sourceUrl: e.sourceUrl, author: e.author }
3335
+ };
3336
+ }, ln = (t) => ({
3337
+ async list(e = {}, i = {}) {
3338
+ var l, d, c, p;
3339
+ const r = (l = e.page) != null ? l : 1, n = (d = e.limit) != null ? d : 24, o = await t.search({ search: (c = e.search) != null ? c : "", page: r, limit: n }, { signal: i.signal }), s = o.items.map((u) => sn(t, u)), a = (r - 1) * n + s.length;
3340
+ return { items: s, total: (p = o.total) != null ? p : a + (s.length >= n ? 1 : 0) };
3341
+ }
3342
+ });
3343
+ let dn = 0;
3344
+ const cn = (t) => {
3345
+ if (!(typeof URL == "undefined" || typeof URL.createObjectURL != "function") && /^(image|video)\//.test(t.type))
3346
+ try {
3347
+ return URL.createObjectURL(t);
3348
+ } catch (e) {
3349
+ return;
3350
+ }
3351
+ };
3352
+ class zi {
3353
+ constructor(e) {
3354
+ this.options = e, this.list = [], this.controllers = /* @__PURE__ */ new Map();
3355
+ }
3356
+ get entries() {
3357
+ return this.list;
3358
+ }
3359
+ get active() {
3360
+ return this.list.filter((e) => e.status === "queued" || e.status === "uploading").length;
3361
+ }
3362
+ add(e) {
3363
+ const i = [...e].map((r) => ({
3364
+ id: `upload-${++dn}`,
3365
+ file: r,
3366
+ status: "queued",
3367
+ fraction: 0,
3368
+ previewUrl: cn(r)
3369
+ }));
3370
+ return this.list.push(...i), this.options.onChange(), this.pump(), i;
3371
+ }
3372
+ retry(e) {
3373
+ const i = this.find(e);
3374
+ !i || i.status !== "error" || (i.status = "queued", i.error = void 0, i.fraction = 0, this.options.onChange(), this.pump());
3375
+ }
3376
+ /** Stop an upload and drop the entry; for one that has finished it just drops the entry. */
3377
+ remove(e) {
3378
+ var n, o;
3379
+ const i = this.list.findIndex((s) => s.id === e);
3380
+ if (i === -1) return;
3381
+ const [r] = this.list.splice(i, 1);
3382
+ (n = this.controllers.get(e)) == null || n.abort(), this.controllers.delete(e), r.previewUrl && ((o = URL.revokeObjectURL) == null || o.call(URL, r.previewUrl)), this.options.onChange(), this.pump();
3383
+ }
3384
+ /** The dialog is closing: stop everything that is still going. */
3385
+ dispose() {
3386
+ this.controllers.forEach((e) => e.abort()), this.controllers.clear(), this.list.forEach((e) => {
3387
+ var i;
3388
+ return e.previewUrl && ((i = URL.revokeObjectURL) == null ? void 0 : i.call(URL, e.previewUrl));
3389
+ }), this.list.length = 0;
3390
+ }
3391
+ find(e) {
3392
+ return this.list.find((i) => i.id === e);
3393
+ }
3394
+ pump() {
3395
+ var r;
3396
+ const e = (r = this.options.concurrency) != null ? r : 3;
3397
+ let i = this.list.filter((n) => n.status === "uploading").length;
3398
+ for (const n of this.list) {
3399
+ if (i >= e) break;
3400
+ n.status === "queued" && (i++, this.run(n));
3401
+ }
3402
+ }
3403
+ async run(e) {
3404
+ const i = new AbortController();
3405
+ this.controllers.set(e.id, i), e.status = "uploading", e.fraction = 0, this.options.onChange();
3406
+ try {
3407
+ const r = await wi(e.file, {
3408
+ config: this.options.config,
3409
+ signal: i.signal,
3410
+ onProgress: ({ fraction: n }) => {
3411
+ e.fraction = n, this.options.onChange();
3412
+ }
3413
+ });
3414
+ if (!this.list.includes(e)) return;
3415
+ e.status = "done", e.fraction = 1, e.item = r;
3416
+ } catch (r) {
3417
+ if (!this.list.includes(e) || Ze(r)) return;
3418
+ e.status = "error", e.error = r instanceof Error && r.message ? r.message : `Couldn't upload ${e.file.name}.`, e.retryable = !(r instanceof N && (r.code === "too-large" || r.code === "type-not-allowed"));
3419
+ } finally {
3420
+ this.controllers.delete(e.id), this.list.includes(e) && this.options.onChange(), this.pump();
3421
+ }
3422
+ }
3423
+ }
3424
+ class pn {
3425
+ constructor(e, i, r = () => {
3426
+ }) {
3427
+ this.ctx = e, this.onUploaded = i, this.onQueueChange = r, this.element = h("div", "rte-mp-view"), this.dropzone = h("div", "rte-mp-dropzone dropzone"), this.input = h("input"), this.list = h("ul", "rte-mp-grid rte-mp-queue"), this.tiles = /* @__PURE__ */ new Map(), this.selectedOnce = /* @__PURE__ */ new Set(), this.queue = new zi({
3428
+ config: e.config,
3429
+ onChange: () => {
3430
+ this.sync(), this.onQueueChange();
3431
+ }
3432
+ }), this.element.setAttribute("role", "tabpanel"), this.element.id = "rte-mp-panel-upload", this.element.hidden = !0;
3433
+ const n = q(e.config).maxFileSize, o = e.allowedKinds, s = o.length === 1 ? Ve(o) : "file", a = n ? ` Max file size: ${Mr(n)}` : "";
3434
+ this.dropzone.setAttribute("role", "button"), this.dropzone.tabIndex = 0, this.dropzone.setAttribute("aria-label", `Drag and drop your ${o.length === 1 ? Ve(o, !0) : "files"} here or click to browse.${a}`), this.dropzone.innerHTML = `
3435
+ <span class="rte-mp-dropzone-icon" aria-hidden="true">${$.upload.replace('width="18" height="18"', 'width="30" height="30"')}</span>
3436
+ <strong>Drag and drop your ${e.selection.multiple ? o.length === 1 ? Ve(o, !0) : "files" : s} here</strong>
3437
+ <span>or click to browse</span>
3438
+ ${n ? `<span class="rte-media-hint">${a.trim()}</span>` : ""}`, this.input.type = "file", this.input.id = "file-input", this.input.multiple = e.selection.multiple, this.input.style.display = "none", this.input.accept = [...new Set(o.flatMap((d) => Sr(d, e.config).split(",")))].join(","), this.input.setAttribute("aria-label", o.length === 1 ? `Choose ${o[0] === "image" ? "an image" : o[0] === "video" ? "a video" : "an audio"} file` : "Choose files"), this.dropzone.addEventListener("click", () => this.input.click()), gr(this.dropzone, this.input), this.dropzone.addEventListener("dragover", (d) => {
3439
+ d.preventDefault(), this.dropzone.classList.add("is-dragover");
3440
+ }), this.dropzone.addEventListener("dragleave", () => this.dropzone.classList.remove("is-dragover")), this.dropzone.addEventListener("drop", () => this.dropzone.classList.remove("is-dragover")), this.input.addEventListener("change", () => {
3441
+ var d;
3442
+ (d = this.input.files) != null && d.length && this.add([...this.input.files]), this.input.value = "";
3443
+ }), this.list.setAttribute("role", "list"), this.list.setAttribute("aria-label", "Uploads"), this.list.hidden = !0;
3444
+ const l = h("div", "rte-mp-scroll");
3445
+ l.append(this.dropzone, this.input, this.list), this.element.append(l);
3446
+ }
3447
+ /** Files from anywhere (drop on the dialog, paste, the chooser). */
3448
+ add(e) {
3449
+ const i = this.ctx.selection.multiple ? e : e.slice(0, 1);
3450
+ i.length && this.queue.add(i);
3451
+ }
3452
+ focusDropzone() {
3453
+ this.dropzone.focus({ preventScroll: !0 });
3454
+ }
3455
+ syncSelection() {
3456
+ this.tiles.forEach((e, i) => {
3457
+ var o;
3458
+ const r = this.queue.entries.find((s) => s.id === i), n = !!(r != null && r.item && this.ctx.selection.has(r.item.id));
3459
+ e.classList.toggle("is-selected", n), (o = e.querySelector(".rte-mp-tile-pick")) == null || o.setAttribute("aria-pressed", String(n));
3460
+ });
3461
+ }
3462
+ dispose() {
3463
+ this.queue.dispose();
3464
+ }
3465
+ sync() {
3466
+ const e = this.queue.entries;
3467
+ this.list.hidden = e.length === 0;
3468
+ for (const [i, r] of this.tiles)
3469
+ e.some((n) => n.id === i) || (r.remove(), this.tiles.delete(i));
3470
+ e.forEach((i, r) => {
3471
+ var o;
3472
+ let n = this.tiles.get(i.id);
3473
+ n || (n = this.createTile(i), this.tiles.set(i.id, n)), this.list.children[r] !== n && this.list.insertBefore(n, (o = this.list.children[r]) != null ? o : null), this.update(n, i);
3474
+ }), this.syncSelection();
3475
+ }
3476
+ createTile(e) {
3477
+ return Ti(e);
3478
+ }
3479
+ /** Bring one tile to the state of its entry without rebuilding it, so the preview image does not flicker. */
3480
+ update(e, i) {
3481
+ if (!Ii(e, i, this.queue) && i.item) {
3482
+ const r = i.item, n = h("button", "rte-mp-tile-pick");
3483
+ n.type = "button", n.setAttribute("aria-label", r.name), n.setAttribute("aria-pressed", "false"), n.addEventListener("click", () => {
3484
+ var o;
3485
+ this.ctx.selection.toggle(r), this.ctx.setActive(this.ctx.selection.has(r.id) ? r : (o = this.ctx.selection.items.at(-1)) != null ? o : null);
3486
+ }), n.addEventListener("dblclick", () => this.ctx.commit([r])), e.append(Mi(r.name), Li(), n), this.selectedOnce.has(i.id) || (this.selectedOnce.add(i.id), this.ctx.selection.toggle(r), this.ctx.setActive(r), this.onUploaded(r), this.ctx.announce(`${r.name} uploaded`));
3487
+ }
3488
+ }
3489
+ }
3490
+ const un = /\.(mp4|webm|ogv|ogg|mov|m4v)(\?|#|$)/i, hn = /\.(mp3|wav|m4a|aac|oga|opus|flac)(\?|#|$)/i, Vt = (t, e) => hn.test(t) || t.startsWith("data:audio/") ? "audio" : un.test(t) ? "video" : /\.(jpe?g|png|gif|webp|avif|svg|bmp)(\?|#|$)/i.test(t) || t.startsWith("data:image/") ? "image" : e;
3491
+ class mn {
3492
+ constructor(e, i, r, n, o, s = ((a) => (a = e[0]) != null ? a : "image")()) {
3493
+ this.kinds = e, this.initialUrl = i, this.initialAlt = r, this.onChange = n, this.onSubmit = o, this.preferred = s, this.element = h("div", "rte-mp-view"), this.urlInput = h("input", "rte-media-input"), this.altInput = h("input", "rte-media-input"), this.widthInput = h("input", "rte-media-input"), this.heightInput = h("input", "rte-media-input"), this.previewBox = h("div", "rte-media-field rte-media-preview-field"), this.element.setAttribute("role", "tabpanel"), this.element.id = "rte-mp-panel-url", this.element.hidden = !0;
3494
+ const l = h("div", "rte-mp-form"), d = s === "audio" ? "clip" : s, c = (f, m, b, v = {}) => {
3495
+ const y = h("div", "rte-media-field"), z = h("label", "rte-media-label");
3496
+ return z.htmlFor = b, z.textContent = f, m.id = b, Object.assign(m, v), y.append(z, m), y;
3497
+ }, p = s === "video" ? "mp4" : s === "audio" ? "mp3" : "jpg";
3498
+ l.append(
3499
+ c("URL", this.urlInput, "url-input", { type: "text", placeholder: `https://example.com/${d}.${p}`, value: i }),
3500
+ ...e.includes("image") ? [c("Alt Text (for accessibility)", this.altInput, "alt-input", { type: "text", placeholder: "Describe the image", value: r != null ? r : "" })] : []
3501
+ );
3502
+ const u = h("div", "rte-media-grid");
3503
+ u.append(
3504
+ c("Width (px)", this.widthInput, "width-input", { type: "number", placeholder: "Auto" }),
3505
+ c("Height (px)", this.heightInput, "height-input", { type: "number", placeholder: "Auto" })
3506
+ ), l.append(u, this.previewBox), this.previewBox.hidden = !0, this.element.append(l), this.urlInput.addEventListener("input", () => {
3507
+ this.onChange(), clearTimeout(this.previewTimer), this.previewTimer = setTimeout(() => this.renderPreview(), 400);
3508
+ }), this.urlInput.addEventListener("keydown", (f) => {
3509
+ f.key === "Enter" && this.url && (f.preventDefault(), this.onSubmit());
3510
+ }), i && this.renderPreview();
3511
+ }
3512
+ get url() {
3513
+ return this.urlInput.value.trim();
3514
+ }
3515
+ focus() {
3516
+ this.urlInput.focus({ preventScroll: !0 });
3517
+ }
3518
+ /** The element to insert, or null while there is no address. */
3519
+ spec() {
3520
+ if (!this.url) return null;
3521
+ const e = Vt(this.url, this.preferred);
3522
+ return {
3523
+ src: this.url,
3524
+ type: e,
3525
+ alt: e === "image" && this.altInput.value ? this.altInput.value : void 0,
3526
+ width: this.widthInput.value || void 0,
3527
+ height: this.heightInput.value || void 0
3528
+ };
3529
+ }
3530
+ dispose() {
3531
+ clearTimeout(this.previewTimer);
3532
+ }
3533
+ renderPreview() {
3534
+ const e = this.url;
3535
+ if (!e) {
3536
+ this.previewBox.hidden = !0, this.previewBox.replaceChildren();
3537
+ return;
3538
+ }
3539
+ const i = this.previewBox.querySelector("img, video, audio"), r = Vt(e, this.preferred), n = r === "image" ? "img" : r === "video" ? "video" : "audio";
3540
+ if (i && i.tagName.toLowerCase() === n)
3541
+ i.setAttribute("src", e);
3542
+ else {
3543
+ const o = h("span", "rte-media-label");
3544
+ o.textContent = "Preview";
3545
+ const s = h("div", "rte-media-preview"), a = h(r === "image" ? "img" : r === "video" ? "video" : "audio");
3546
+ a.setAttribute("src", e), a instanceof HTMLImageElement ? a.alt = "Preview" : a.controls = !0, s.append(a), this.previewBox.replaceChildren(o, s);
3547
+ }
3548
+ this.previewBox.hidden = !1;
3549
+ }
3550
+ }
3551
+ const ct = {
3552
+ library: { label: "Library", icon: $.library, className: "tab-library" },
3553
+ stock: { label: "Stock photos", icon: $.stock, className: "tab-stock" },
3554
+ upload: { label: "Upload", icon: $.upload, className: "tab-upload" },
3555
+ url: { label: "From URL", icon: $.link, className: "tab-url" },
3556
+ embed: { label: "Embed", icon: $.embed, className: "tab-embed" }
3557
+ }, $i = ["image", "video", "audio"], Kt = (t, e) => {
3558
+ const i = new Set(t.map((n) => n.type)), r = i.size === 1 ? i.values().next().value : null;
3559
+ return r && $i.includes(r) ? Ve([r], e > 1) : e > 1 ? "items" : "item";
3560
+ }, Ri = (t) => {
3561
+ var Be, be, ke;
3562
+ const { mode: e } = t, i = q(t.config), r = ai(i), n = e === "insert" ? $i : ["image"], o = e === "insert" ? i.stockProvider : void 0, s = e === "insert", a = typeof r.list == "function", l = [
3563
+ ...a ? ["library"] : [],
3564
+ ...o ? ["stock"] : [],
3565
+ "upload",
3566
+ "url",
3567
+ ...s ? ["embed"] : []
3568
+ ], d = a && cr(r);
3569
+ let c = e === "replace" && (!a || d) ? "url" : d ? l.find((g) => g !== "library") : l[0], p = !1;
3570
+ const u = Je(t.contextElement), f = et();
3571
+ f.classList.add("rte-mp", "no-details");
3572
+ const m = h("div", "rte-mp-sr");
3573
+ m.setAttribute("aria-live", "polite"), m.setAttribute("role", "status");
3574
+ const b = new on(e === "insert", () => Q());
3575
+ let v = null, y = null;
3576
+ const z = {
3577
+ get kinds() {
3578
+ var g;
3579
+ return (g = y == null ? void 0 : y.kinds) != null ? g : n;
3580
+ },
3581
+ allowedKinds: n,
3582
+ config: t.config,
3583
+ provider: r,
3584
+ selection: b,
3585
+ setActive: (g) => {
3586
+ v = g, R.show(g), ae();
3587
+ },
3588
+ commit: (g) => j(g),
3589
+ announce: (g) => {
3590
+ m.textContent = "", window.setTimeout(() => m.textContent = g, 30);
3591
+ }
3592
+ }, C = new pn(
3593
+ z,
3594
+ (g) => y == null ? void 0 : y.addUploaded(g),
3595
+ () => y == null ? void 0 : y.syncPending()
3596
+ );
3597
+ y = a ? new jt(z, () => oe("upload"), {
3598
+ pills: e === "insert" ? { filter: t.kinds.length === 1 ? t.kinds[0] : "all" } : void 0,
3599
+ queue: () => C.queue,
3600
+ dropHint: !0
3601
+ }) : null;
3602
+ const w = o ? new jt(z, () => {
3603
+ }, {
3604
+ id: "stock",
3605
+ source: ln(o),
3606
+ emptyTitle: `Search ${o.name}`,
3607
+ emptyHint: `Photos from ${o.name} will show up here.`,
3608
+ offerUpload: !1,
3609
+ kinds: ["image"],
3610
+ sortable: !1
3611
+ }) : null, E = { library: y, stock: w }, L = new mn(n, (Be = t.initialUrl) != null ? Be : "", t.initialAlt, () => ae(), () => j(), (be = t.kinds[0]) != null ? be : "image"), S = s ? new en((ke = i.embedProviders) != null ? ke : [], () => ae(), () => j()) : null, R = new _r(b, {
3612
+ defaultAlt: t.initialAlt,
3613
+ config: t.config,
3614
+ captions: i.wrapInFigure !== !1,
3615
+ // Only what is in the library can be deleted from it: not a stock photo, not a loose address.
3616
+ canDelete: (g) => {
3617
+ var k;
3618
+ return !!(y && r.delete && !((k = g.metadata) != null && k.stock));
3619
+ },
3620
+ onDelete: (g) => {
3621
+ y == null ? void 0 : y.deleteItem(g).then((k) => {
3622
+ var I;
3623
+ if (!k) return;
3624
+ const M = C.queue.entries.find((V) => {
3625
+ var P;
3626
+ return ((P = V.item) == null ? void 0 : P.id) === g.id;
3627
+ });
3628
+ M && C.queue.remove(M.id), z.setActive((I = b.items.at(-1)) != null ? I : null);
3629
+ });
3630
+ },
3631
+ onEdit: (g) => ki({
3632
+ src: g.src,
3633
+ name: g.name,
3634
+ config: t.config,
3635
+ contextElement: f,
3636
+ // The edited picture is a new file: it takes the place of the original in what is chosen.
3637
+ onApply: ({ item: k }) => {
3638
+ b.remove(g.id), y == null || y.addUploaded(k), e === "insert" ? b.toggle(k) : b.only(k), z.setActive(k), z.announce(`${k.name} saved`);
3639
+ }
3640
+ })
3641
+ }), _ = h("div", "rte-mp-header"), de = h("h2", "rte-media-title");
3642
+ de.textContent = e === "insert" ? "Media" : t.title, f.setAttribute("aria-label", t.title);
3643
+ const te = h("label", "rte-mp-search"), B = h("input");
3644
+ B.type = "search", B.id = "mp-search", B.placeholder = "Search by name", B.setAttribute("aria-label", "Search the library"), te.insertAdjacentHTML("afterbegin", $.search), te.append(B), te.hidden = !(a || o);
3645
+ const Se = {}, ie = h("div", "rte-mp-viewtools"), re = h("select", "rte-mp-sort");
3646
+ re.setAttribute("aria-label", "Sort by");
3647
+ for (const [g, k] of [["newest", "Newest"], ["oldest", "Oldest"], ["name", "Name"]]) {
3648
+ const M = h("option");
3649
+ M.value = g, M.textContent = k, re.append(M);
3650
+ }
3651
+ const me = h("div", "rte-mp-layout");
3652
+ me.setAttribute("role", "group"), me.setAttribute("aria-label", "Layout");
3653
+ const Te = /* @__PURE__ */ new Map();
3654
+ for (const [g, k, M] of [["grid", "Grid", $.grid], ["list", "List", $.list]]) {
3655
+ const I = h("button", "rte-mp-iconbtn");
3656
+ I.type = "button", I.setAttribute("aria-label", `${k} view`), I.setAttribute("aria-pressed", String(g === "grid")), I.innerHTML = M, I.addEventListener("click", () => {
3657
+ y == null || y.setLayout(g), Te.forEach((V, P) => V.setAttribute("aria-pressed", String(P === g)));
3658
+ }), Te.set(g, I), me.append(I);
3659
+ }
3660
+ re.addEventListener("change", () => y == null ? void 0 : y.setSort(re.value)), ie.append(re, me), ie.hidden = !y;
3661
+ const ce = h("button", "close-btn rte-media-close-btn");
3662
+ ce.type = "button", ce.setAttribute("aria-label", "Close"), ce.innerHTML = $.close, _.append(de, te, ie, ce);
3663
+ const H = h("div", "rte-mp-nav");
3664
+ H.setAttribute("role", "tablist"), H.setAttribute("aria-orientation", "vertical"), H.setAttribute("aria-label", "Where to get the media from");
3665
+ const ge = /* @__PURE__ */ new Map();
3666
+ for (const g of l) {
3667
+ const k = h("button", `rte-mp-nav-item rte-media-tab ${ct[g].className}`);
3668
+ k.type = "button", k.setAttribute("role", "tab"), k.setAttribute("aria-controls", `rte-mp-panel-${g}`), k.innerHTML = `${ct[g].icon}<span></span>`, k.querySelector("span").textContent = ct[g].label, k.addEventListener("click", () => {
3669
+ oe(g), k.focus();
3670
+ }), ge.set(g, k), H.append(k);
3671
+ }
3672
+ H.addEventListener("keydown", (g) => {
3673
+ var I;
3674
+ const k = { ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 };
3675
+ if (!(g.key in k)) return;
3676
+ g.preventDefault();
3677
+ const M = l[(l.indexOf(c) + k[g.key] + l.length) % l.length];
3678
+ oe(M), (I = ge.get(M)) == null || I.focus();
3679
+ });
3680
+ const xe = h("div", "rte-mp-main"), Ie = {
3681
+ library: y == null ? void 0 : y.element,
3682
+ stock: w == null ? void 0 : w.element,
3683
+ upload: C.element,
3684
+ url: L.element,
3685
+ embed: S == null ? void 0 : S.element
3686
+ };
3687
+ xe.append(...l.map((g) => Ie[g]));
3688
+ const ve = h("div", "rte-mp-body");
3689
+ ve.append(H, xe, R.element);
3690
+ const ze = h("div", "rte-mp-footer"), Z = h("span", "rte-mp-count"), pe = h("button", "cancel-btn rte-media-btn rte-media-btn-secondary");
3691
+ pe.type = "button", pe.textContent = "Cancel";
3692
+ const ne = h("button", "gallery-btn rte-media-btn rte-media-btn-secondary");
3693
+ ne.type = "button", ne.innerHTML = `${$.gallery}<span style="margin-left:6px">Insert as gallery</span>`, ne.hidden = !0;
3694
+ const O = h("button", "rte-media-btn rte-media-btn-primary");
3695
+ O.type = "button", O.id = "insert-btn", ze.append(Z, pe, ne, O);
3696
+ const fe = h("div", "rte-mp-drop-veil");
3697
+ fe.setAttribute("aria-hidden", "true"), fe.textContent = "Drop to upload", f.append(_, ve, ze, fe, m), u.append(f), document.body.append(u);
3698
+ const W = () => c === "library" || c === "stock" || c === "upload";
3699
+ function oe(g) {
3700
+ var M;
3701
+ p = !0, Se[c] = B.value, c = g;
3702
+ for (const I of l) {
3703
+ const V = I === g;
3704
+ Ie[I].hidden = !V;
3705
+ const P = ge.get(I);
3706
+ P.setAttribute("aria-selected", String(V)), P.tabIndex = V ? 0 : -1;
3707
+ }
3708
+ const k = E[g];
3709
+ te.hidden = !k, ie.hidden = g !== "library", k && (B.value = (M = Se[g]) != null ? M : "", B.setAttribute("aria-label", g === "stock" ? `Search ${o.name}` : "Search the library"), B.placeholder = g === "stock" ? `Search ${o.name}` : "Search by name", k.activate()), ae();
3710
+ }
3711
+ function Ue(g) {
3712
+ return g.map((k) => ({
3713
+ src: k.src,
3714
+ type: k.type,
3715
+ alt: R.altFor(k),
3716
+ caption: R.captionFor(k)
3717
+ }));
3718
+ }
3719
+ function ye() {
3720
+ const g = S == null ? void 0 : S.spec;
3721
+ return g ? { src: g.src, type: "video", embed: g, title: S.title || void 0 } : null;
3722
+ }
3723
+ function j(g, k) {
3724
+ let M;
3725
+ c === "url" && !g ? M = [L.spec()].filter((I) => !!I) : c === "embed" && !g ? M = [ye()].filter((I) => !!I) : M = Ue(g != null ? g : b.items), M.length !== 0 && (F(), t.onPick(M, k));
3726
+ }
3727
+ function ae() {
3728
+ const g = c === "url" ? L.url ? 1 : 0 : c === "embed" ? S != null && S.spec ? 1 : 0 : b.size, k = c === "embed" ? "video" : c === "url" ? Kt(L.spec() ? [L.spec()] : [], 1) : Kt(b.items, g);
3729
+ e === "replace" ? O.textContent = "Replace" : O.textContent = g > 1 ? `Insert ${g} ${k}` : g === 1 ? `Insert ${k}` : "Insert", O.disabled = g === 0;
3730
+ const M = b.size >= 2 && b.items.every((V) => V.type === "image");
3731
+ ne.hidden = !(e === "insert" && W() && M), c === "url" || c === "embed" ? Z.textContent = "" : Z.textContent = b.size ? `${b.size} selected` : e === "insert" ? "Select media to insert" : "Select an image";
3732
+ const I = W() && v !== null && b.size > 0;
3733
+ f.classList.toggle("no-details", !I), R.element.hidden = !I;
3734
+ }
3735
+ function Q() {
3736
+ b.size === 0 && v && (v = null, R.show(null)), y == null || y.syncSelection(), w == null || w.syncSelection(), C.syncSelection(), ae();
3737
+ }
3738
+ let we = () => {
3739
+ };
3740
+ function F() {
3741
+ we(), y == null || y.dispose(), w == null || w.dispose(), C.dispose(), L.dispose(), R.dispose(), u.remove();
3742
+ }
3743
+ we = Qe(u, F), ce.addEventListener("click", F), pe.addEventListener("click", F), O.addEventListener("click", () => j()), ne.addEventListener("click", () => j(void 0, { gallery: !0 })), u.addEventListener("click", (g) => {
3744
+ g.target === u && F();
3745
+ }), B.addEventListener("input", () => {
3746
+ var g;
3747
+ return (g = E[c]) == null ? void 0 : g.setSearch(B.value.trim());
3748
+ });
3749
+ let ue = 0;
3750
+ const $e = (g) => {
3751
+ var k, M;
3752
+ return Array.from((M = (k = g.dataTransfer) == null ? void 0 : k.types) != null ? M : []).includes("Files");
3753
+ };
3754
+ f.addEventListener("dragenter", (g) => {
3755
+ $e(g) && (ue++, f.classList.add("is-dropping"));
3756
+ }), f.addEventListener("dragover", (g) => {
3757
+ $e(g) && g.preventDefault();
3758
+ }), f.addEventListener("dragleave", (g) => {
3759
+ $e(g) && (ue = Math.max(0, ue - 1), ue === 0 && f.classList.remove("is-dropping"));
3760
+ }), f.addEventListener("drop", (g) => {
3761
+ var M, I;
3762
+ ue = 0, f.classList.remove("is-dropping");
3763
+ const k = Array.from((I = (M = g.dataTransfer) == null ? void 0 : M.files) != null ? I : []);
3764
+ k.length && (g.preventDefault(), Oe(k));
3765
+ }), f.addEventListener("paste", (g) => {
3766
+ var M, I;
3767
+ const k = Array.from((I = (M = g.clipboardData) == null ? void 0 : M.files) != null ? I : []);
3768
+ k.length && (g.preventDefault(), Oe(k));
3769
+ });
3770
+ function Oe(g) {
3771
+ c !== "library" && c !== "upload" && oe(y ? "library" : "upload"), C.add(g);
3772
+ }
3773
+ oe(c), p = !1, d && e === "insert" && r.list({ limit: 1 }).then(
3774
+ (g) => {
3775
+ g.total > 0 && !p && u.isConnected && (oe("library"), B.focus({ preventScroll: !0 }));
3776
+ },
3777
+ () => {
3778
+ }
3779
+ ), E[c] ? B.focus({ preventScroll: !0 }) : c === "upload" ? C.focusDropzone() : c === "embed" ? S == null || S.focus() : L.focus();
3780
+ }, Tt = "rte-media", It = "rte-embed", it = "rte-gallery", Ne = `figure.${Tt}`, Gt = {
3781
+ left: "1em auto 1em 0",
3782
+ center: "1em auto",
3783
+ right: "1em 0 1em auto"
3784
+ }, zt = "720px", Di = "display: table-caption; caption-side: bottom; padding-top: 0.5em; text-align: center; font-size: 0.875em; opacity: 0.75;", gn = "grid-column: 1 / -1; padding-top: 0.25em; text-align: center; font-size: 0.875em; opacity: 0.75;", $t = (t) => t instanceof HTMLElement && t.tagName === "IFRAME" && !!t.closest(`figure.${It}`), pt = (t) => t instanceof HTMLElement && (t.tagName === "IMG" || t.tagName === "VIDEO" || t.tagName === "AUDIO" || $t(t)), Xe = (t) => !!t.closest(`figure.${it}`), Ni = (t) => (t.tagName === "IMG" || t.tagName === "VIDEO") && !Xe(t), rt = (t) => t.classList.contains(It) ? "embed" : t.classList.contains(it) ? "gallery" : "media", Re = (t) => {
3785
+ var i;
3786
+ const e = t.parentElement;
3787
+ return e && e.tagName === "A" && e.children.length === 1 && !((i = e.textContent) != null && i.trim()) ? e : t;
3788
+ }, Y = (t) => t.closest(Ne), nt = (t) => t.querySelector(":scope > figcaption"), Ui = (t) => {
3789
+ const e = Y(t), i = e == null ? void 0 : e.getAttribute("data-align");
3790
+ if (i === "left" || i === "center" || i === "right") return i;
3791
+ const r = t.style;
3792
+ return r.marginLeft === "auto" && r.marginRight === "auto" ? "center" : r.marginLeft === "auto" ? "right" : "left";
3793
+ }, ot = (t, e) => {
3794
+ t.classList.add(Tt), t.setAttribute("data-align", e);
3795
+ const i = rt(t);
3796
+ if (i !== "gallery") {
3797
+ if (i === "embed") {
3798
+ const r = t.style.maxWidth || zt;
3799
+ t.style.cssText = `display: block; width: 100%; max-width: ${r}; margin: ${Gt[e]};`;
3800
+ return;
3801
+ }
3802
+ t.style.cssText = `display: table; max-width: 100%; margin: ${Gt[e]};`;
3803
+ }
3804
+ }, Oi = (t) => {
3805
+ t.tagName !== "IFRAME" && (t.style.removeProperty("margin"), t.style.removeProperty("margin-left"), t.style.removeProperty("margin-right"), t.style.display = "block", t.tagName !== "AUDIO" && !t.style.maxWidth && (t.style.maxWidth = "100%"));
3806
+ }, le = (t) => {
3807
+ t.getAttribute("contenteditable") !== "false" && t.setAttribute("contenteditable", "false");
3808
+ const e = nt(t);
3809
+ e && e.getAttribute("contenteditable") !== "true" && e.setAttribute("contenteditable", "true");
3810
+ }, Yt = (t) => {
3811
+ t.querySelectorAll(Ne).forEach(le);
3812
+ }, fn = (t, e = "left") => {
3813
+ const i = document.createElement("figure");
3814
+ return ot(i, e), Oi(t), i.append(t), le(i), i;
3815
+ }, Bi = (t) => {
3816
+ const e = Y(t);
3817
+ if (e) return e;
3818
+ const i = Re(t), r = Ui(t), n = document.createElement("figure");
3819
+ return ot(n, r), i.replaceWith(n), n.append(i), Oi(t), le(n), n;
3820
+ }, bn = (t, e) => {
3821
+ const i = Bi(t);
3822
+ rt(i) !== "gallery" && ot(i, e);
3823
+ }, at = (t) => rt(t) === "gallery" ? gn : Di, Hi = (t) => {
3824
+ const e = Bi(t), i = nt(e);
3825
+ if (i)
3826
+ return i.remove(), null;
3827
+ const r = document.createElement("figcaption");
3828
+ return r.style.cssText = at(e), r.append(document.createElement("br")), e.append(r), le(e), r;
3829
+ }, Fi = (t) => {
3830
+ const e = t.parentElement;
3831
+ t.style.cssText || (t.style.cssText = e ? at(e) : Di);
3832
+ }, xn = (t, e) => {
3833
+ if ($t(t)) {
3834
+ const o = Y(t);
3835
+ o && (o.style.maxWidth = e === null ? zt : `${Math.max(1, Math.round(e))}px`);
3836
+ return;
3837
+ }
3838
+ if (!Ni(t)) return;
3839
+ if (e === null) {
3840
+ t.removeAttribute("width"), t.removeAttribute("height"), t.style.removeProperty("width"), t.style.removeProperty("height");
3841
+ return;
3842
+ }
3843
+ const i = t.getBoundingClientRect(), r = i.width && i.height ? i.height / i.width : null, n = Math.max(1, Math.round(e));
3844
+ if (t.style.width = `${n}px`, t.setAttribute("width", String(n)), r) {
3845
+ const o = Math.round(n * r);
3846
+ t.style.height = `${o}px`, t.setAttribute("height", String(o));
3847
+ }
3848
+ }, vn = [2, 3, 4, 5], yn = 3, wn = "display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; max-width: 100%;", st = (t) => Math.min(5, Math.max(2, Math.round(t) || yn)), kn = (t) => st(Math.min(t, t >= 5 ? 3 : t)), Pi = (t, e) => {
3849
+ t.classList.add(it), t.setAttribute("data-columns", String(e)), t.style.cssText = `display: grid; grid-template-columns: repeat(${e}, minmax(0, 1fr)); gap: 8px; max-width: 100%; margin: 1em 0;`;
3850
+ }, En = (t) => st(Number(t.getAttribute("data-columns"))), An = (t, e) => {
3851
+ Pi(t, st(e));
3852
+ }, Cn = (t, e = kn(t.length)) => {
3853
+ const i = document.createElement("figure");
3854
+ i.classList.add("rte-media"), Pi(i, st(e)), i.setAttribute("data-align", "center");
3855
+ for (const n of t)
3856
+ n.style.cssText = wn, i.append(n);
3857
+ le(i);
3858
+ const r = nt(i);
3859
+ return r && Fi(r), i;
3860
+ }, Ln = (t) => [...t.querySelectorAll(":scope > img, :scope > a > img")], Mn = (t) => {
3861
+ var i;
3862
+ const e = t.closest(`figure.${it}`);
3863
+ return e ? ((((i = t.parentElement) == null ? void 0 : i.tagName) === "A" && t.parentElement.children.length === 1 ? t.parentElement : t).remove(), Ln(e).length === 0 ? (e.remove(), !0) : !1) : !1;
3864
+ }, Sn = "data-editora-embed", Tn = "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen", In = (t, e = {}) => {
3865
+ var n, o, s;
3866
+ const i = document.createElement("figure");
3867
+ i.classList.add(Tt, It), i.setAttribute("data-provider", t.provider), i.style.maxWidth = (n = e.maxWidth) != null ? n : zt, ot(i, (o = e.align) != null ? o : "center");
3868
+ const r = document.createElement("iframe");
3869
+ return r.src = t.src, r.title = ((s = e.title) == null ? void 0 : s.trim()) || t.label, r.setAttribute("allow", Tn), r.setAttribute("allowfullscreen", ""), r.setAttribute("loading", "lazy"), r.setAttribute("frameborder", "0"), r.setAttribute(Sn, "true"), r.style.cssText = `display: block; width: 100%; aspect-ratio: ${Number(t.aspectRatio.toFixed(4))}; border: 0;`, t.aspectRatio < 1 && !e.maxWidth && (i.style.maxWidth = "360px"), i.append(r), le(i), i;
3870
+ }, qi = (t) => {
3871
+ if (t.type !== "image" && t.type !== "video" && t.type !== "audio") return null;
3872
+ const e = t.type === "image";
3873
+ if (t.type === "audio") {
3874
+ const r = document.createElement("audio");
3875
+ return r.src = t.src, r.controls = !0, r.preload = "metadata", r.setAttribute("data-media-type", "audio"), r.style.cssText = "display: block; width: 320px; max-width: 100%;", r;
3876
+ }
3877
+ const i = document.createElement(e ? "img" : "video");
3878
+ return i.src = t.src, i.setAttribute("data-media-type", t.type), e && t.alt !== void 0 && (i.alt = t.alt), t.width && i.setAttribute("width", t.width), t.height && i.setAttribute("height", t.height), e || (i.controls = !0), !t.width && !t.height ? i.style.cssText = "max-width: 100%; height: auto; display: block; margin: 1em 0; cursor: pointer;" : i.style.cssText = `display: block; margin: 1em 0; cursor: pointer; ${t.width ? `width: ${t.width}px;` : "max-width: 100%;"} ${t.height ? `height: ${t.height}px;` : "height: auto;"}`, i;
3879
+ }, Wi = (t, e) => {
3880
+ var n;
3881
+ if (t.embed) return In(t.embed, { align: (n = e.align) != null ? n : "center", title: t.title });
3882
+ const i = qi(t);
3883
+ if (!i) return null;
3884
+ if (!e.figure) return i;
3885
+ const r = fn(i, e.align);
3886
+ if (t.caption) {
3887
+ const o = document.createElement("figcaption");
3888
+ o.style.cssText = at(r), o.textContent = t.caption, r.append(o), le(r);
3889
+ }
3890
+ return r;
3891
+ }, zn = /* @__PURE__ */ new Set(["P", "H1", "H2", "H3", "H4", "H5", "H6"]), Xt = (t) => {
3892
+ var e;
3893
+ return !!((e = t.textContent) != null && e.trim()) || !!t.querySelector("img, video, figure, iframe, table, hr");
3894
+ }, kt = (t, e, i) => {
3895
+ t.deleteContents();
3896
+ let r = t.startContainer instanceof HTMLElement ? t.startContainer : t.startContainer.parentElement;
3897
+ for (; r && r !== e && !zn.has(r.tagName); ) r = r.parentElement;
3898
+ if (!r || r === e || !e.contains(r)) {
3899
+ const a = document.createDocumentFragment();
3900
+ i.forEach((d) => a.appendChild(d));
3901
+ const l = i[i.length - 1];
3902
+ if (t.insertNode(a), l && !l.nextSibling && l.parentElement) {
3903
+ const d = document.createElement("p");
3904
+ return d.innerHTML = "<br>", l.after(d), d;
3905
+ }
3906
+ return null;
3907
+ }
3908
+ const n = document.createRange();
3909
+ n.setStart(t.startContainer, t.startOffset), n.setEnd(r, r.childNodes.length);
3910
+ const o = r.cloneNode(!1);
3911
+ o.removeAttribute("id"), o.append(n.extractContents()), Xt(o) || (o.innerHTML = "<br>");
3912
+ const s = !Xt(r);
3913
+ return r.after(...i, o), s && r.remove(), o;
3914
+ }, Zt = (t, e) => {
3915
+ var c, p, u, f;
3916
+ const { savedSelection: i } = e;
3917
+ if (t.length === 0) return !1;
3918
+ const r = (f = (u = i ? (c = i.commonAncestorContainer instanceof HTMLElement ? i.commonAncestorContainer : i.commonAncestorContainer.parentElement) == null ? void 0 : c.closest('[contenteditable="true"]') : null) != null ? u : (p = li(e.contextElement)) == null ? void 0 : p.closest('[contenteditable="true"]')) != null ? f : null;
3919
+ if (!r) return !1;
3920
+ const n = r.innerHTML, o = t[t.length - 1], s = t.some((m) => m.tagName === "FIGURE");
3921
+ let a = null;
3922
+ if (i && r.contains(i.commonAncestorContainer))
3923
+ if (s) a = kt(i, r, t);
3924
+ else {
3925
+ const m = document.createDocumentFragment();
3926
+ t.forEach((b) => m.appendChild(b)), i.deleteContents(), i.insertNode(m);
3927
+ }
3928
+ else {
3929
+ const m = document.createRange();
3930
+ m.selectNodeContents(r), m.collapse(!1), s ? a = kt(m, r, t) : r.appendChild(t.reduce((b, v) => (b.appendChild(v), b), document.createDocumentFragment()));
3931
+ }
3932
+ if (!o.isConnected) return !1;
3933
+ r.focus({ preventScroll: !0 });
3934
+ const l = window.getSelection();
3935
+ if (l) {
3936
+ const m = document.createRange();
3937
+ a ? m.setStart(a, 0) : m.setStartAfter(o), m.collapse(!0), l.removeAllRanges(), l.addRange(m);
3938
+ }
3939
+ Ge(r, n);
3940
+ const d = t.some((m) => m.tagName === "IFRAME" || m.querySelector("iframe"));
3941
+ return r.dispatchEvent(
3942
+ d ? new CustomEvent("input", { bubbles: !0, detail: { allowedTags: ["iframe"] } }) : new Event("input", { bubbles: !0 })
3943
+ ), !0;
3944
+ }, $n = (t, e) => {
3945
+ t.src = e.src, e.alt !== void 0 && (t.alt = e.alt);
3946
+ }, ut = (t, e, i) => {
3947
+ document.querySelectorAll(".rte-media-overlay").forEach((o) => o.remove());
3948
+ let r = null;
3949
+ const n = window.getSelection();
3950
+ n && n.rangeCount > 0 && (r = n.getRangeAt(0).cloneRange()), Ri({
3951
+ mode: "insert",
3952
+ kinds: [t],
3953
+ title: `Insert ${t === "image" ? "Image" : t === "video" ? "Video" : "Audio"}`,
3954
+ contextElement: e,
3955
+ config: i,
3956
+ onPick: (o, s) => {
3957
+ const a = q(i).wrapInFigure !== !1;
3958
+ if (s != null && s.gallery && a && o.length > 1) {
3959
+ const d = o.map((u) => qi(u)).filter((u) => u instanceof HTMLImageElement), c = Cn(d), p = [...new Set(o.map((u) => u.caption).filter((u) => !!u))];
3960
+ if (p.length) {
3961
+ const u = document.createElement("figcaption");
3962
+ u.style.cssText = at(c), u.textContent = p.join(" · "), c.append(u), le(c);
3963
+ }
3964
+ Zt([c], { savedSelection: r, contextElement: e });
3965
+ return;
3966
+ }
3967
+ const l = o.map((d) => Wi(d, { figure: a })).filter((d) => d !== null);
3968
+ Zt(l, { savedSelection: r, contextElement: e });
3969
+ }
3970
+ });
3971
+ }, Rn = (t, e, i) => {
3972
+ const r = Je(t), n = et(!0);
3973
+ n.innerHTML = `
3974
+ <div class="rte-media-header">
3975
+ <h2 class="rte-media-title">Edit Alt Text</h2>
3976
+ <button class="close-btn rte-media-close-btn" type="button" aria-label="Close">×</button>
3977
+ </div>
3978
+ <div class="rte-media-body">
3979
+ <label class="rte-media-label">Alternative Text (for accessibility)</label>
3980
+ <textarea id="alt-text-input" class="rte-media-textarea" placeholder="Describe the image for screen readers...">${bt(t.alt || "")}</textarea>
3981
+ <p class="rte-media-helper">Good alt text is descriptive and concise. It helps users with visual impairments understand your content.</p>
3982
+ </div>
3983
+ <div class="rte-media-footer">
3984
+ <button class="cancel-btn rte-media-btn rte-media-btn-secondary" type="button">Cancel</button>
3985
+ <button class="save-btn rte-media-btn rte-media-btn-primary" type="button">Save</button>
3986
+ </div>
3987
+ `, r.appendChild(n), document.body.appendChild(r);
3988
+ const o = n.querySelector("#alt-text-input");
3989
+ let s = () => {
3990
+ };
3991
+ if (Ei(i)) {
3992
+ const u = Ai({ config: i, image: () => ({ src: t.currentSrc || t.src }), input: o });
3993
+ s = u.abort;
3994
+ const f = n.querySelector(".rte-media-label"), m = document.createElement("div");
3995
+ m.className = "rte-mp-label-row", f.replaceWith(m), m.append(f, u.button), o.after(u.status);
3996
+ }
3997
+ const a = n.querySelector(".close-btn"), l = n.querySelector(".cancel-btn"), d = n.querySelector(".save-btn");
3998
+ let c = () => {
3999
+ };
4000
+ const p = () => {
4001
+ s(), c(), r.parentNode && r.parentNode.removeChild(r);
4002
+ };
4003
+ c = Qe(r, p), a.addEventListener("click", p), l.addEventListener("click", p), r.addEventListener("click", (u) => {
4004
+ u.target === r && p();
4005
+ }), d.addEventListener("click", () => {
4006
+ const u = t.alt !== o.value;
4007
+ t.alt = o.value, p(), u && (e == null || e());
4008
+ }), o.focus(), o.select();
4009
+ }, ht = "data-original-src", Dn = (t) => !t.startsWith("data:") && !t.startsWith("blob:"), Nn = (t) => {
4010
+ if (t.startsWith("data:") || t.startsWith("blob:")) return "image";
4011
+ try {
4012
+ const e = new URL(t, document.baseURI).pathname.split("/").filter(Boolean).pop();
4013
+ return e ? decodeURIComponent(e) : "image";
4014
+ } catch (e) {
4015
+ return "image";
4016
+ }
4017
+ }, Qt = (t, e) => {
4018
+ t.src = e, t.removeAttribute("height"), t.style.removeProperty("height");
4019
+ }, Un = (t, e, i, r) => {
4020
+ const n = t.currentSrc || t.src, o = t.getAttribute(ht);
4021
+ ki({
4022
+ src: n,
4023
+ name: Nn(o != null ? o : n),
4024
+ config: e,
4025
+ contextElement: t,
4026
+ canRestore: !!o,
4027
+ deps: r,
4028
+ onApply: ({ item: s }) => {
4029
+ !o && Dn(n) && t.setAttribute(ht, n), Qt(t, s.src), i();
4030
+ },
4031
+ onRestore: () => {
4032
+ o && (Qt(t, o), t.removeAttribute(ht), i());
4033
+ }
4034
+ });
4035
+ }, On = (t, e) => {
4036
+ const i = t.closest("a"), r = (i == null ? void 0 : i.getAttribute("href")) || "", n = (i == null ? void 0 : i.getAttribute("target")) || "_self", o = (i == null ? void 0 : i.getAttribute("title")) || "", s = Je(t), a = et(!0);
4037
+ a.innerHTML = `
4038
+ <div class="rte-media-header">
4039
+ <h2 class="rte-media-title">${i ? "Edit Link" : "Add Link"}</h2>
4040
+ <button class="close-btn rte-media-close-btn" type="button" aria-label="Close">×</button>
4041
+ </div>
4042
+ <div class="rte-media-body">
4043
+ <div class="rte-media-field">
4044
+ <label class="rte-media-label">URL</label>
4045
+ <input id="link-url" type="url" class="rte-media-input" value="${bt(r)}" placeholder="https://example.com" />
4046
+ </div>
4047
+ <div class="rte-media-field">
4048
+ <label class="rte-media-label">Title (tooltip)</label>
4049
+ <input id="link-title" type="text" class="rte-media-input" value="${bt(o)}" placeholder="Optional tooltip text" />
4050
+ </div>
4051
+ <label class="rte-media-checkbox-label">
4052
+ <input id="link-target" type="checkbox" ${n === "_blank" ? "checked" : ""} />
4053
+ Open in new window/tab
4054
+ </label>
4055
+ </div>
4056
+ <div class="rte-media-footer rte-media-footer-spread">
4057
+ ${i ? '<button class="remove-link-btn rte-media-btn rte-media-btn-danger" type="button">Remove Link</button>' : '<span class="rte-media-spacer"></span>'}
4058
+ <div class="rte-media-actions">
4059
+ <button class="cancel-btn rte-media-btn rte-media-btn-secondary" type="button">Cancel</button>
4060
+ <button class="save-btn rte-media-btn rte-media-btn-primary" type="button">Save</button>
4061
+ </div>
4062
+ </div>
4063
+ `, s.appendChild(a), document.body.appendChild(s);
4064
+ const l = a.querySelector("#link-url"), d = a.querySelector("#link-title"), c = a.querySelector("#link-target"), p = a.querySelector(".close-btn"), u = a.querySelector(".cancel-btn"), f = a.querySelector(".save-btn"), m = a.querySelector(".remove-link-btn");
4065
+ let b = () => {
4066
+ };
4067
+ const v = () => {
4068
+ b(), s.parentNode && s.parentNode.removeChild(s);
4069
+ };
4070
+ b = Qe(s, v), p.addEventListener("click", v), u.addEventListener("click", v), s.addEventListener("click", (y) => {
4071
+ y.target === s && v();
4072
+ }), f.addEventListener("click", () => {
4073
+ const y = l.value.trim();
4074
+ if (y) {
4075
+ const z = y.startsWith("http") ? y : `https://${y}`;
4076
+ if (i)
4077
+ i.setAttribute("href", z), i.setAttribute("target", c.checked ? "_blank" : "_self"), c.checked ? i.setAttribute("rel", "noopener noreferrer") : i.removeAttribute("rel"), d.value.trim() ? i.setAttribute("title", d.value.trim()) : i.removeAttribute("title");
4078
+ else {
4079
+ const C = document.createElement("a");
4080
+ C.href = z, C.target = c.checked ? "_blank" : "_self", c.checked && (C.rel = "noopener noreferrer"), d.value.trim() && (C.title = d.value.trim()), t.replaceWith(C), C.appendChild(t);
4081
+ }
4082
+ v(), e == null || e();
4083
+ }
4084
+ }), m == null || m.addEventListener("click", async () => {
4085
+ !i || !await Et("Remove link from this media?", {
4086
+ title: "Remove link",
4087
+ confirmText: "Remove link",
4088
+ danger: !0,
4089
+ context: t
4090
+ }) || !i.isConnected || (i.replaceWith(t), v(), e == null || e());
4091
+ }), l.focus();
4092
+ }, Bn = (t, e, i) => {
4093
+ Ri({
4094
+ mode: "replace",
4095
+ kinds: ["image"],
4096
+ title: "Replace Image",
4097
+ contextElement: t,
4098
+ config: e,
4099
+ initialUrl: t.src.startsWith("data:") ? "" : t.src,
4100
+ initialAlt: t.alt,
4101
+ onPick: ([r]) => {
4102
+ r && ($n(t, r), i == null || i());
4103
+ }
4104
+ });
4105
+ }, K = (t) => `<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">${t}</svg>`, G = {
4106
+ left: K('<line x1="17" y1="10" x2="3" y2="10"></line><line x1="21" y1="6" x2="3" y2="6"></line><line x1="21" y1="14" x2="3" y2="14"></line><line x1="17" y1="18" x2="3" y2="18"></line>'),
4107
+ center: K('<line x1="18" y1="10" x2="6" y2="10"></line><line x1="21" y1="6" x2="3" y2="6"></line><line x1="21" y1="14" x2="3" y2="14"></line><line x1="18" y1="18" x2="6" y2="18"></line>'),
4108
+ right: K('<line x1="21" y1="10" x2="7" y2="10"></line><line x1="21" y1="6" x2="3" y2="6"></line><line x1="21" y1="14" x2="3" y2="14"></line><line x1="21" y1="18" x2="7" y2="18"></line>'),
4109
+ size: K('<polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" y1="3" x2="14" y2="10"></line><line x1="3" y1="21" x2="10" y2="14"></line>'),
4110
+ caption: K('<rect x="3" y="4" width="18" height="11" rx="2"></rect><line x1="7" y1="19" x2="17" y2="19"></line>'),
4111
+ edit: K('<path d="M6 2v14a2 2 0 0 0 2 2h14"></path><path d="M18 22V8a2 2 0 0 0-2-2H2"></path>'),
4112
+ columns: K('<rect x="3" y="4" width="18" height="16" rx="2"></rect><line x1="9" y1="4" x2="9" y2="20"></line><line x1="15" y1="4" x2="15" y2="20"></line>'),
4113
+ removeAll: K('<rect x="3" y="3" width="8" height="8" rx="1"></rect><rect x="13" y="3" width="8" height="8" rx="1"></rect><rect x="3" y="13" width="8" height="8" rx="1"></rect><line x1="14" y1="14" x2="21" y2="21"></line><line x1="21" y1="14" x2="14" y2="21"></line>'),
4114
+ alt: K('<path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"></path>'),
4115
+ link: K('<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path>'),
4116
+ replace: K('<rect x="3" y="3" width="18" height="18" rx="2" ry="2"></rect><circle cx="8.5" cy="8.5" r="1.5"></circle><polyline points="21 15 16 10 5 21"></polyline>'),
4117
+ remove: K('<polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>')
4118
+ }, Hn = [
4119
+ { label: "Small", share: 0.25 },
4120
+ { label: "Medium", share: 0.5 },
4121
+ { label: "Large", share: 0.75 },
4122
+ { label: "Full width", share: 1 },
4123
+ { label: "Original size", share: "original" }
4124
+ ], Fn = (t) => {
4125
+ const e = getComputedStyle(t), i = (parseFloat(e.paddingLeft) || 0) + (parseFloat(e.paddingRight) || 0);
4126
+ let r = t.clientWidth - i;
4127
+ const n = t.getBoundingClientRect();
4128
+ let o = Math.max(n.left, 0), s = document.documentElement.clientWidth;
4129
+ for (let l = t.parentElement; l; l = l.parentElement) {
4130
+ if (getComputedStyle(l).overflowX === "visible") continue;
4131
+ const d = l.getBoundingClientRect();
4132
+ o = Math.max(o, d.left), s = Math.min(s, d.right);
4133
+ }
4134
+ const a = s - o - i;
4135
+ return a > 0 && (r = Math.min(r, a)), r;
4136
+ };
4137
+ class Pn {
4138
+ constructor(e, i) {
4139
+ var C;
4140
+ this.media = e, this.hooks = i, this.menu = null, this.menuTrigger = null, this.lastButton = null, this.onKeyDown = (w) => {
4141
+ if (w.key === "Escape") {
4142
+ w.preventDefault(), w.stopPropagation(), this.menu ? this.closeMenu(!0) : this.hooks.returnFocus();
4143
+ return;
4144
+ }
4145
+ if (this.menu) return;
4146
+ const E = this.buttons(), L = E.indexOf(document.activeElement);
4147
+ if (L === -1) return;
4148
+ let S = -1;
4149
+ if (w.key === "ArrowRight") S = (L + 1) % E.length;
4150
+ else if (w.key === "ArrowLeft") S = (L - 1 + E.length) % E.length;
4151
+ else if (w.key === "Home") S = 0;
4152
+ else if (w.key === "End") S = E.length - 1;
4153
+ else if (w.key === "ArrowDown" && E[L].classList.contains("btn-size")) {
4154
+ w.preventDefault(), this.openSizeMenu();
4155
+ return;
4156
+ } else if (w.key === "ArrowDown" && E[L].classList.contains("btn-columns")) {
4157
+ w.preventDefault(), this.openColumnsMenu();
4158
+ return;
4159
+ } else if (w.key === "Tab") {
4160
+ w.preventDefault(), this.hooks.returnFocus();
4161
+ return;
4162
+ } else return;
4163
+ w.preventDefault(), E.forEach((R) => R.tabIndex = -1), E[S].tabIndex = 0, E[S].focus();
4164
+ }, Me();
4165
+ const r = e.tagName === "IMG", n = e.tagName === "AUDIO", o = $t(e), s = Xe(e), a = !n && !o, l = e.closest("a"), d = Y(e), c = Ui(e), p = !!(d && nt(d)), u = o ? "Embedded video" : s ? "Gallery" : r ? "Image" : n ? "Audio" : "Video", f = document.createElement("div");
4166
+ f.className = "media-floating-toolbar", f.setAttribute("role", "toolbar"), f.setAttribute("aria-label", `${u} options`), di(e) && f.classList.add("rte-ui-theme-dark");
4167
+ const m = (w, E, L, S, R = !1) => `<button class="media-floating-toolbar-btn ${w}" title="${E}" aria-label="${E}" type="button" tabindex="-1"${S === void 0 ? "" : ` aria-pressed="${S}"`}${R ? ' aria-haspopup="menu" aria-expanded="false"' : ""}>${L}</button>`, b = '<div class="media-floating-toolbar-separator" aria-hidden="true"></div>';
4168
+ f.innerHTML = [
4169
+ s ? "" : m("btn-align-left", "Align left", G.left, c === "left"),
4170
+ s ? "" : m("btn-align-center", "Align center", G.center, c === "center"),
4171
+ s ? "" : m("btn-align-right", "Align right", G.right, c === "right"),
4172
+ s ? m("btn-columns", "Columns", G.columns, void 0, !0) : n ? "" : m("btn-size", "Size", G.size, void 0, !0),
4173
+ m("btn-caption", p ? "Remove caption" : "Add caption", G.caption, p),
4174
+ b,
4175
+ r ? m("btn-edit", "Edit image: crop, rotate, resize", G.edit) : "",
4176
+ r ? m("btn-alt", "Edit alt text", G.alt) : "",
4177
+ a ? m("btn-link", l ? "Edit or remove link" : "Add link", G.link) : "",
4178
+ r ? m("btn-replace", "Replace image", G.replace) : "",
4179
+ b,
4180
+ m("btn-remove", s ? "Remove picture" : "Remove", G.remove),
4181
+ s ? m("btn-remove-gallery", "Remove gallery", G.removeAll) : ""
4182
+ ].join(""), f.addEventListener("mousedown", (w) => w.preventDefault()), f.addEventListener("keydown", this.onKeyDown), f.addEventListener("focusin", (w) => {
4183
+ var L, S;
4184
+ const E = w.target.closest(".media-floating-toolbar-btn");
4185
+ this.lastButton = (S = [...(L = E == null ? void 0 : E.classList) != null ? L : []].find((R) => R.startsWith("btn-"))) != null ? S : this.lastButton;
4186
+ }), this.element = f, (C = this.buttons()[0]) == null || C.setAttribute("tabindex", "0"), document.body.appendChild(f);
4187
+ const v = (w, E) => {
4188
+ var L;
4189
+ return (L = f.querySelector(w)) == null ? void 0 : L.addEventListener("click", E);
4190
+ }, y = (w) => () => {
4191
+ i.commit(e, () => bn(e, w)), i.refresh();
4192
+ };
4193
+ v(".btn-align-left", y("left")), v(".btn-align-center", y("center")), v(".btn-align-right", y("right")), v(".btn-size", () => this.menu ? this.closeMenu(!0) : this.openSizeMenu()), v(".btn-columns", () => this.menu ? this.closeMenu(!0) : this.openColumnsMenu()), v(".btn-caption", () => {
4194
+ let w = null;
4195
+ i.commit(e, () => {
4196
+ w = Hi(e);
4197
+ }), i.refresh(), w && i.focusCaption(w);
4198
+ }), v(".btn-edit", () => this.viaDialog((w) => {
4199
+ var E;
4200
+ return Un(e, (E = i.config) == null ? void 0 : E.call(i), w);
4201
+ })), v(".btn-alt", () => this.viaDialog((w) => {
4202
+ var E;
4203
+ return Rn(e, w, (E = i.config) == null ? void 0 : E.call(i));
4204
+ })), v(".btn-link", () => this.viaDialog((w) => On(e, w))), v(
4205
+ ".btn-replace",
4206
+ () => this.viaDialog((w) => {
4207
+ var E;
4208
+ return Bn(e, (E = i.config) == null ? void 0 : E.call(i), w);
4209
+ })
4210
+ );
4211
+ const z = async (w) => {
4212
+ var R, _;
4213
+ if (!await Et(w ? "Remove this whole gallery?" : "Remove this media?", {
4214
+ title: w ? "Remove gallery" : "Remove media",
4215
+ confirmText: "Remove",
4216
+ danger: !0,
4217
+ context: e
4218
+ }) || !e.isConnected) return;
4219
+ if (s && !w) {
4220
+ i.commit(e, () => Mn(e)), i.removed();
4221
+ return;
4222
+ }
4223
+ const L = e.closest("a"), S = (_ = Y(e)) != null ? _ : L && L.children.length === 1 && !((R = L.textContent) != null && R.trim()) ? L : e;
4224
+ i.commit(e, () => S.remove()), i.removed();
4225
+ };
4226
+ v(".btn-remove", () => {
4227
+ z(!1);
4228
+ }), v(".btn-remove-gallery", () => {
4229
+ z(!0);
4230
+ }), this.reposition();
4231
+ }
4232
+ buttons() {
4233
+ return [...this.element.querySelectorAll(":scope > .media-floating-toolbar-btn")];
4234
+ }
4235
+ /** Move the focus into the toolbar, onto its first button. */
4236
+ focusFirst() {
4237
+ const e = this.buttons()[0];
4238
+ e == null || e.focus();
4239
+ }
4240
+ /** The `btn-*` class of the button the keyboard is on (inside the toolbar, or the one last used), if any. */
4241
+ currentButton() {
4242
+ var n, o, s;
4243
+ const e = document.activeElement, i = e instanceof HTMLElement && this.element.contains(e) ? e : null, r = (n = i == null ? void 0 : i.closest(".media-floating-toolbar-btn")) != null ? n : null;
4244
+ return (s = [...(o = r == null ? void 0 : r.classList) != null ? o : []].find((a) => a.startsWith("btn-"))) != null ? s : this.lastButton;
4245
+ }
4246
+ /** Put the focus back on a button of a freshly built toolbar. */
4247
+ focusButton(e) {
4248
+ const i = this.element.querySelector(`.${e}`);
4249
+ i && (this.buttons().forEach((r) => r.tabIndex = -1), i.tabIndex = 0, i.focus());
4250
+ }
4251
+ /** Open a dialog that edits the media itself; when it reports a change, record the result as one step. */
4252
+ viaDialog(e) {
4253
+ var n;
4254
+ const i = this.media.closest('[contenteditable="true"]'), r = (n = i == null ? void 0 : i.innerHTML) != null ? n : "";
4255
+ e(() => {
4256
+ this.hooks.commit(this.media, () => {
4257
+ }, r), this.hooks.refresh();
4258
+ });
4259
+ }
4260
+ openSizeMenu() {
4261
+ const { media: e } = this, i = e.closest('[contenteditable="true"]'), r = i ? Fn(i) : 0;
4262
+ this.openMenu(
4263
+ ".btn-size",
4264
+ "Size",
4265
+ Hn.map((n) => ({
4266
+ label: n.label,
4267
+ apply: () => {
4268
+ const o = n.share === "original" ? null : Math.max(50, Math.round(Math.min(r || 1 / 0, (r || 800) * n.share)));
4269
+ this.hooks.commit(e, () => xn(e, o));
4270
+ }
4271
+ }))
4272
+ );
4273
+ }
4274
+ openColumnsMenu() {
4275
+ const { media: e } = this, i = Y(e);
4276
+ if (!i || rt(i) !== "gallery") return;
4277
+ const r = En(i);
4278
+ this.openMenu(
4279
+ ".btn-columns",
4280
+ "Columns",
4281
+ vn.map((n) => ({
4282
+ label: `${n} columns${n === r ? " (current)" : ""}`,
4283
+ apply: () => this.hooks.commit(e, () => An(i, n))
4284
+ }))
4285
+ );
4286
+ }
4287
+ /** A menu of choices under a toolbar button: arrows move, Enter or Space chooses, Escape closes. */
4288
+ openMenu(e, i, r) {
4289
+ const n = this.element.querySelector(e), o = document.createElement("div");
4290
+ o.className = "media-size-menu", o.setAttribute("role", "menu"), o.setAttribute("aria-label", i);
4291
+ for (const s of r) {
4292
+ const a = document.createElement("button");
4293
+ a.type = "button", a.className = "media-size-menu-item", a.setAttribute("role", "menuitem"), a.textContent = s.label, a.tabIndex = -1, a.addEventListener("click", () => {
4294
+ s.apply(), this.closeMenu(!0), this.hooks.refresh();
4295
+ }), o.append(a);
4296
+ }
4297
+ o.addEventListener("keydown", (s) => {
4298
+ const a = [...o.querySelectorAll("button")], l = a.indexOf(document.activeElement);
4299
+ if (s.key === "ArrowDown") a[(l + 1) % a.length].focus();
4300
+ else if (s.key === "ArrowUp") a[(l - 1 + a.length) % a.length].focus();
4301
+ else if (s.key === "Home") a[0].focus();
4302
+ else if (s.key === "End") a[a.length - 1].focus();
4303
+ else return;
4304
+ s.preventDefault(), s.stopPropagation();
4305
+ }), this.element.append(o), o.style.left = `${n.offsetLeft}px`, this.menu = o, this.menuTrigger = n, n.setAttribute("aria-expanded", "true"), o.querySelector("button").focus();
4306
+ }
4307
+ closeMenu(e) {
4308
+ if (!this.menu) return;
4309
+ this.menu.remove(), this.menu = null;
4310
+ const i = this.menuTrigger;
4311
+ this.menuTrigger = null, i == null || i.setAttribute("aria-expanded", "false"), e && (i == null || i.focus());
4312
+ }
4313
+ reposition() {
4314
+ var f;
4315
+ const { element: e, media: i } = this;
4316
+ if (!i.isConnected) return;
4317
+ const n = (Xe(i) ? i : (f = Y(i)) != null ? f : i).getBoundingClientRect(), o = e.offsetHeight || 40, s = e.offsetWidth || 340, a = i.closest('[contenteditable="true"]'), l = a ? a.getBoundingClientRect().top : 0, d = n.top - o - 8;
4318
+ let c = d < Math.max(l, 0) ? n.bottom + 8 : d;
4319
+ n.bottom > 0 && n.top < window.innerHeight && (c = Math.min(Math.max(c, 8), Math.max(window.innerHeight - o - 8, 8)));
4320
+ const u = Math.min(Math.max(n.left + n.width / 2 - s / 2, 8), Math.max(window.innerWidth - s - 8, 8));
4321
+ e.style.top = `${Math.round(c)}px`, e.style.left = `${Math.round(u)}px`, e.style.display = "flex";
4322
+ }
4323
+ contains(e) {
4324
+ return e instanceof Node && this.element.contains(e);
4325
+ }
4326
+ destroy() {
4327
+ this.element.remove();
4328
+ }
4329
+ }
4330
+ const Ce = "data-rte-media-pending";
4331
+ let qn = 0;
4332
+ const Wn = () => `pending-${Date.now().toString(36)}-${++qn}`, Jt = (t) => {
4333
+ if (!t.includes(Ce)) return t;
4334
+ const e = document.createElement("template");
4335
+ return e.innerHTML = t, e.content.querySelectorAll(`[${Ce}]`).forEach((i) => i.remove()), e.innerHTML;
4336
+ };
4337
+ class _n {
4338
+ constructor() {
4339
+ this.pending = /* @__PURE__ */ new Map(), this.queues = [], this.entryIds = /* @__PURE__ */ new Map();
4340
+ }
4341
+ get count() {
4342
+ return this.pending.size;
4343
+ }
4344
+ /**
4345
+ * @param range where to put them (a pasted image goes at the caret), or null for the end of the editor
4346
+ */
4347
+ start(e, i, r, n) {
4348
+ const o = q(n), s = [];
4349
+ for (const p of e)
4350
+ try {
4351
+ yi(p, o), s.push(p);
4352
+ } catch (u) {
4353
+ Dt(u instanceof Error ? u.message : `Couldn't upload ${p.name}.`, "error");
4354
+ }
4355
+ if (s.length === 0) return;
4356
+ Me();
4357
+ const a = s.map((p) => this.createPending(p, i, n)), l = r && i.contains(r.startContainer) ? r : (() => {
4358
+ const p = document.createRange();
4359
+ return p.selectNodeContents(i), p.collapse(!1), p;
4360
+ })();
4361
+ kt(l, i, a.map((p) => p.placeholder)), i.dispatchEvent(new Event("input", { bubbles: !0 }));
4362
+ const d = new zi({ config: n, onChange: () => this.sync() });
4363
+ this.queues.push(d), d.add(a.map((p) => p.file)).forEach((p, u) => this.entryIds.set(p.id, { pending: a[u], queue: d })), a.forEach((p) => {
4364
+ this.pending.set(p.id, p), document.body.appendChild(p.layer);
4365
+ }), this.sync(), this.ensureTimer();
4366
+ }
4367
+ /**
4368
+ * Remove placeholders in an editor that no upload is working on: what a document that was saved (or a tab that
4369
+ * was closed) in the middle of an upload still holds. Returns whether any went.
4370
+ */
4371
+ sweep(e) {
4372
+ let i = !1;
4373
+ return e.querySelectorAll(`[${Ce}]`).forEach((r) => {
4374
+ var n;
4375
+ this.pending.has((n = r.getAttribute(Ce)) != null ? n : "") || (r.remove(), i = !0);
4376
+ }), i;
4377
+ }
4378
+ dispose() {
4379
+ this.queues.forEach((e) => e.dispose()), this.queues.length = 0, this.pending.forEach((e) => this.release(e, !0)), this.pending.clear(), this.entryIds.clear(), this.stopTimer();
4380
+ }
4381
+ createPending(e, i, r) {
4382
+ const n = Wn(), o = document.createElement("figure");
4383
+ o.className = "rte-media", o.setAttribute(Ce, n), o.setAttribute("contenteditable", "false"), o.style.cssText = "display: table; width: 100%; max-width: 360px; aspect-ratio: 16 / 10; margin: 1em 0; border-radius: 8px; background: rgba(127, 127, 127, 0.14);";
4384
+ const s = document.createElement("div");
4385
+ s.className = "rte-mp-pending", s.setAttribute("role", "status");
4386
+ const a = document.createElement("span"), l = document.createElement("div");
4387
+ l.className = "rte-mp-pending-bar", l.append(a);
4388
+ const d = document.createElement("span");
4389
+ d.className = "rte-mp-pending-label";
4390
+ const c = document.createElement("button");
4391
+ return c.type = "button", c.className = "rte-mp-icon-btn", c.setAttribute("aria-label", `Cancel upload of ${e.name}`), c.innerHTML = $.close, c.addEventListener("click", () => {
4392
+ const p = [...this.entryIds.entries()].find(([, u]) => u.pending.id === n);
4393
+ p && p[1].queue.remove(p[0]);
4394
+ }), s.append(d, l, c), { id: n, file: e, host: i, placeholder: o, layer: s, bar: a, label: d, config: r };
4395
+ }
4396
+ sync() {
4397
+ var e;
4398
+ for (const [i, { pending: r, queue: n }] of this.entryIds) {
4399
+ const o = n.entries.find((s) => s.id === i);
4400
+ if (!o) {
4401
+ this.finish(i, r, null);
4402
+ continue;
4403
+ }
4404
+ this.show(r, o), o.status === "done" && o.item ? this.finish(i, r, o) : o.status === "error" && (Dt((e = o.error) != null ? e : `Couldn't upload ${r.file.name}.`, "error"), this.finish(i, r, null));
4405
+ }
4406
+ }
4407
+ show(e, i) {
4408
+ const r = Math.round(i.fraction * 100);
4409
+ e.bar.style.width = `${r}%`, e.label.textContent = i.status === "queued" ? "Waiting…" : `Uploading ${r}%`, i.previewUrl && !e.layer.style.backgroundImage && e.file.type.startsWith("image/") && (e.layer.style.backgroundImage = `url("${i.previewUrl}")`), this.position(e);
4410
+ }
4411
+ position(e) {
4412
+ const { placeholder: i, layer: r } = e;
4413
+ if (!i.isConnected) {
4414
+ r.style.display = "none";
4415
+ return;
4416
+ }
4417
+ const n = i.getBoundingClientRect();
4418
+ r.style.display = "flex", r.style.left = `${n.left}px`, r.style.top = `${n.top}px`, r.style.width = `${n.width}px`, r.style.height = `${n.height}px`;
4419
+ }
4420
+ /** `entry` is the finished upload, or null when it was cancelled or failed. */
4421
+ finish(e, i, r) {
4422
+ this.entryIds.delete(e), this.pending.delete(i.id);
4423
+ const { placeholder: n, host: o } = i;
4424
+ if (r != null && r.item && n.isConnected) {
4425
+ const s = q(i.config), a = Wi(
4426
+ { src: r.item.src, type: r.item.type, alt: r.item.alt },
4427
+ { figure: s.wrapInFigure !== !1 }
4428
+ );
4429
+ if (a) {
4430
+ const l = Jt(o.innerHTML);
4431
+ n.replaceWith(a), a.tagName === "FIGURE" && le(a), Ge(o, l, Jt(o.innerHTML)), o.dispatchEvent(new Event("input", { bubbles: !0 }));
4432
+ }
4433
+ }
4434
+ this.release(i, !1), this.pending.size === 0 && this.stopTimer();
4435
+ }
4436
+ release(e, i) {
4437
+ e.layer.remove(), e.placeholder.isConnected && (i || e.placeholder.hasAttribute(Ce)) && e.placeholder.remove();
4438
+ }
4439
+ ensureTimer() {
4440
+ this.timer || (this.timer = setInterval(() => this.pending.forEach((e) => this.position(e)), 120));
4441
+ }
4442
+ stopTimer() {
4443
+ this.timer && clearInterval(this.timer), this.timer = void 0;
4444
+ }
4445
+ }
4446
+ const jn = ["nw", "ne", "sw", "se"], ei = 50;
4447
+ class Vn {
4448
+ constructor(e, i) {
4449
+ this.onResized = e, this.onMoved = i, this.handles = /* @__PURE__ */ new Map(), this.label = document.createElement("div"), this.media = null, this.drag = null, Me(), jn.forEach((r) => {
4450
+ const n = document.createElement("div");
4451
+ n.className = `media-resize-handle-${r} media-resize-handle`, n.setAttribute("data-position", r), n.setAttribute("aria-hidden", "true"), n.style.display = "none", n.style.cursor = `${r}-resize`, n.addEventListener("pointerdown", (o) => this.start(o, r, n)), n.addEventListener("pointermove", (o) => this.move(o)), n.addEventListener("pointerup", (o) => this.end(o, n)), n.addEventListener("pointercancel", (o) => this.end(o, n)), document.body.appendChild(n), this.handles.set(r, n);
4452
+ }), this.label.className = "media-resize-label", this.label.setAttribute("aria-hidden", "true"), this.label.style.display = "none", document.body.appendChild(this.label);
4453
+ }
4454
+ /** Put the handles around `media`, or take them away with `null`. */
4455
+ show(e) {
4456
+ this.media = e, this.update();
4457
+ }
4458
+ update() {
4459
+ if (!this.media || !this.media.isConnected) {
4460
+ this.handles.forEach((r) => r.style.display = "none");
4461
+ return;
4462
+ }
4463
+ const e = this.media.getBoundingClientRect(), i = {
4464
+ nw: [e.left, e.top],
4465
+ ne: [e.right, e.top],
4466
+ sw: [e.left, e.bottom],
4467
+ se: [e.right, e.bottom]
4468
+ };
4469
+ this.handles.forEach((r, n) => {
4470
+ r.style.left = `${i[n][0]}px`, r.style.top = `${i[n][1]}px`, r.style.display = "block";
4471
+ });
4472
+ }
4473
+ contains(e) {
4474
+ return e instanceof Node && [...this.handles.values()].some((i) => i === e);
4475
+ }
4476
+ destroy() {
4477
+ this.drag = null, document.body.style.userSelect = "", this.handles.forEach((e) => e.remove()), this.handles.clear(), this.label.remove(), this.media = null;
4478
+ }
4479
+ start(e, i, r) {
4480
+ var s, a;
4481
+ if (!this.media || e.pointerType === "mouse" && e.button !== 0) return;
4482
+ e.preventDefault(), e.stopPropagation(), (s = r.setPointerCapture) == null || s.call(r, e.pointerId);
4483
+ const n = this.media.getBoundingClientRect(), o = this.media.closest('[contenteditable="true"]');
4484
+ this.drag = {
4485
+ corner: i,
4486
+ x: e.clientX,
4487
+ y: e.clientY,
4488
+ width: n.width,
4489
+ height: n.height,
4490
+ before: (a = o == null ? void 0 : o.innerHTML) != null ? a : ""
4491
+ }, document.body.style.userSelect = "none";
4492
+ }
4493
+ move(e) {
4494
+ const { drag: i, media: r } = this;
4495
+ if (!i || !r) return;
4496
+ const n = e.clientX - i.x, o = e.clientY - i.y, s = i.corner === "ne" || i.corner === "se", a = i.corner === "sw" || i.corner === "se";
4497
+ let l = i.width + (s ? n : -n), d = i.height + (a ? o : -o);
4498
+ const c = i.width / i.height;
4499
+ Math.abs(n) > Math.abs(o) ? d = l / c : l = d * c, l = Math.max(ei, l), d = Math.max(ei, d), r.style.width = `${l}px`, r.style.height = `${d}px`, r.setAttribute("width", String(Math.round(l))), r.setAttribute("height", String(Math.round(d))), this.update(), this.onMoved(), this.label.textContent = `${Math.round(l)} × ${Math.round(d)}`, this.label.style.left = `${e.clientX + 14}px`, this.label.style.top = `${e.clientY + 14}px`, this.label.style.display = "block";
4500
+ }
4501
+ end(e, i) {
4502
+ var o;
4503
+ const { drag: r, media: n } = this;
4504
+ this.drag = null, document.body.style.userSelect = "", this.label.style.display = "none", (o = i.hasPointerCapture) != null && o.call(i, e.pointerId) && i.releasePointerCapture(e.pointerId), r && n && this.onResized(n, r.before);
4505
+ }
4506
+ }
4507
+ const Ke = '[contenteditable="true"]', mt = "img, video, audio, iframe", _e = (t) => t instanceof HTMLElement ? t : t instanceof Node ? t.parentElement : null, J = (t) => {
4508
+ var e, i;
4509
+ return (i = (e = t instanceof HTMLElement ? t : t == null ? void 0 : t.parentElement) == null ? void 0 : e.closest(Ke)) != null ? i : null;
4510
+ }, Kn = "[data-editora-editor], editora-editor, .rte-editor, .editora-editor", Gn = ".rte-toolbar, .editora-toolbar", Yn = '[data-command="insertImage"], [data-command="insertVideo"], [data-command="insertAudio"]', ti = (t) => {
4511
+ const e = t.closest(Kn), i = e == null ? void 0 : e.querySelector(Gn);
4512
+ return !i || !!i.querySelector(Yn);
4513
+ }, gt = (t, e) => {
4514
+ var i;
4515
+ return Array.from((i = t == null ? void 0 : t.files) != null ? i : []).filter(
4516
+ (r) => /^(image|video|audio)\//.test(r.type) && xi(r.type, e)
4517
+ );
4518
+ }, Xn = (t) => {
4519
+ var r;
4520
+ if (t.getData("text/plain").trim()) return !1;
4521
+ const e = t.getData("text/html");
4522
+ if (!e) return !0;
4523
+ const i = new DOMParser().parseFromString(e, "text/html").body;
4524
+ return !((r = i.textContent) != null && r.trim()) && !i.querySelector("table");
4525
+ }, ii = (t) => !!(t && t.matches(Ne) && !t.hasAttribute("data-rte-media-pending")), Zn = (t, e) => {
4526
+ var n;
4527
+ let i = t;
4528
+ for (; i.nodeType !== Node.TEXT_NODE && (e === "start" ? i.firstChild : i.lastChild); )
4529
+ i = e === "start" ? i.firstChild : i.lastChild;
4530
+ const r = document.createRange();
4531
+ return i.nodeType === Node.TEXT_NODE ? r.setStart(i, e === "start" ? 0 : ((n = i.textContent) != null ? n : "").length) : r.setStart(i, e === "start" ? 0 : i.childNodes.length), r.collapse(!0), r;
4532
+ }, Qn = (t, e) => {
4533
+ let i = t;
4534
+ for (; i && i.parentNode !== e; ) i = i.parentNode;
4535
+ return i instanceof HTMLElement ? i : null;
4536
+ }, ri = (t, e, i) => {
4537
+ const r = document.createRange();
4538
+ return i === "end" ? (r.setStart(t.endContainer, t.endOffset), r.setEnd(e, e.childNodes.length)) : (r.setStart(e, 0), r.setEnd(t.startContainer, t.startOffset)), r.toString() === "" && !r.cloneContents().querySelector("img, video, figure, table, hr");
4539
+ }, Jn = (t, e) => {
4540
+ var o;
4541
+ const i = document;
4542
+ if (i.caretRangeFromPoint) return i.caretRangeFromPoint(t, e);
4543
+ const r = (o = i.caretPositionFromPoint) == null ? void 0 : o.call(i, t, e);
4544
+ if (!r) return null;
4545
+ const n = document.createRange();
4546
+ return n.setStart(r.offsetNode, r.offset), n.collapse(!0), n;
4547
+ };
4548
+ class eo {
4549
+ constructor() {
4550
+ this.selected = null, this.toolbar = null, this.handles = null, this.uploads = new _n(), this.attached = !1, this.selectedAt = 0, this.config = () => {
4551
+ }, this.onClick = (e) => {
4552
+ var o, s, a, l;
4553
+ const i = _e(e.target);
4554
+ if (!i) return;
4555
+ const r = i.closest("figure.rte-embed"), n = (o = r == null ? void 0 : r.querySelector("iframe")) != null ? o : null;
4556
+ if (n && r.closest(Ke) && !i.closest("figcaption")) {
4557
+ e.preventDefault(), e.stopPropagation(), this.select(n), this.placeNodeSelection(n);
4558
+ return;
4559
+ }
4560
+ if (pt(i) && i.closest(Ke)) {
4561
+ if (i.tagName === "AUDIO") {
4562
+ this.select(i);
4563
+ return;
4564
+ }
4565
+ if (!(i.tagName === "VIDEO" && i.controls && e.offsetY > i.clientHeight - 44)) {
4566
+ e.preventDefault(), e.stopPropagation(), this.select(i), this.placeNodeSelection(i);
4567
+ return;
4568
+ }
4569
+ }
4570
+ (s = this.toolbar) != null && s.contains(i) || (a = this.handles) != null && a.contains(i) || i.closest(".rte-media-overlay") || i.closest(".rte-mp-pending") || i.closest("button") || this.selected && ((l = Y(this.selected)) != null && l.contains(i)) || this.deselect();
4571
+ }, this.onFocusIn = (e) => {
4572
+ const i = J(e.target);
4573
+ i && (Yt(i), this.uploads.sweep(i) && i.dispatchEvent(new Event("input", { bubbles: !0 })));
4574
+ }, this.onSelectionChange = () => {
4575
+ var s;
4576
+ if (this.selected && !this.selected.isConnected) {
4577
+ this.deselect();
4578
+ return;
4579
+ }
4580
+ const e = window.getSelection();
4581
+ if (!e || e.rangeCount === 0) return;
4582
+ const i = e.getRangeAt(0), r = this.mediaInRange(i);
4583
+ if (r) {
4584
+ this.selected !== r && this.select(r);
4585
+ return;
4586
+ }
4587
+ if (!this.selected) return;
4588
+ const n = J(this.selected), o = i.commonAncestorContainer;
4589
+ !n || !n.contains(o) || (s = Y(this.selected)) != null && s.contains(o) || performance.now() - this.selectedAt < 150 || this.deselect();
4590
+ }, this.onKeyDown = (e) => {
4591
+ var s, a, l, d, c;
4592
+ const i = _e(e.target);
4593
+ if ((s = this.toolbar) != null && s.contains(i)) return;
4594
+ if (e.key === "Escape" && this.selected && !document.querySelector(".rte-media-overlay")) {
4595
+ this.deselect();
4596
+ return;
4597
+ }
4598
+ if (e.key === "F10" && e.altKey && this.selected) {
4599
+ e.preventDefault(), (a = this.toolbar) == null || a.focusFirst();
4600
+ return;
4601
+ }
4602
+ this.arrowOntoMedia(e, i);
4603
+ const r = i == null ? void 0 : i.closest("figure.rte-media > figcaption");
4604
+ if (!r) return;
4605
+ const n = r.parentElement, o = J(r);
4606
+ if (o) {
4607
+ if (e.key === "Enter" && !e.shiftKey) {
4608
+ e.preventDefault(), e.stopPropagation();
4609
+ const p = o.innerHTML, u = document.createElement("p");
4610
+ u.innerHTML = "<br>", n.after(u), Ge(o, p), o.dispatchEvent(new Event("input", { bubbles: !0 }));
4611
+ const f = document.createRange();
4612
+ f.setStart(u, 0), f.collapse(!0), (l = window.getSelection()) == null || l.removeAllRanges(), (d = window.getSelection()) == null || d.addRange(f);
4613
+ } else if (e.key === "Backspace" && !((c = r.textContent) != null && c.trim())) {
4614
+ e.preventDefault(), e.stopPropagation();
4615
+ const p = n.querySelector(mt);
4616
+ if (!p) return;
4617
+ this.commit(p, () => Hi(p)), this.select(p), this.returnFocus();
4618
+ }
4619
+ }
4620
+ }, this.onPaste = (e) => {
4621
+ const i = _e(e.target), r = i ? J(i) : null, n = e.clipboardData;
4622
+ if (!r || !n || !ti(r)) return;
4623
+ if (i != null && i.closest("figure.rte-media > figcaption")) {
4624
+ e.preventDefault(), e.stopPropagation();
4625
+ const d = n.getData("text/plain").replace(/\s*[\r\n]+\s*/g, " ");
4626
+ d && document.execCommand("insertText", !1, d);
4627
+ return;
4628
+ }
4629
+ if (q(this.config()).uploadOnPaste === !1) return;
4630
+ const s = gt(n, void 0);
4631
+ if (s.length === 0 || !Xn(n)) return;
4632
+ e.preventDefault(), e.stopPropagation();
4633
+ const a = window.getSelection(), l = a && a.rangeCount > 0 && r.contains(a.anchorNode) ? a.getRangeAt(0) : null;
4634
+ this.uploads.start(s, r, l, this.config());
4635
+ }, this.onDragOver = (e) => {
4636
+ this.wantsDrop(e) && e.preventDefault();
4637
+ }, this.onDrop = (e) => {
4638
+ var o;
4639
+ if (!this.wantsDrop(e)) return;
4640
+ const i = J(e.target);
4641
+ if (!i) return;
4642
+ e.preventDefault(), e.stopPropagation();
4643
+ let r = Jn(e.clientX, e.clientY);
4644
+ r && !i.contains(r.startContainer) && (r = null);
4645
+ const n = r ? (o = r.startContainer instanceof HTMLElement ? r.startContainer : r.startContainer.parentElement) == null ? void 0 : o.closest(Ne) : null;
4646
+ r && n && (r = document.createRange(), r.setStartAfter(n), r.collapse(!0)), this.uploads.start(gt(e.dataTransfer, void 0), i, r, this.config());
4647
+ }, this.onViewportChange = () => {
4648
+ var e, i;
4649
+ this.selected && ((e = this.handles) == null || e.update(), (i = this.toolbar) == null || i.reposition());
4650
+ };
4651
+ }
4652
+ /** The settings of the plugin instance that most recently asked for the controller. */
4653
+ setConfigSource(e) {
4654
+ this.config = e;
4655
+ }
4656
+ attach() {
4657
+ this.attached || typeof document == "undefined" || (this.attached = !0, Me(), this.handles = new Vn(
4658
+ (e, i) => this.commit(e, () => {
4659
+ }, i),
4660
+ () => {
4661
+ var e;
4662
+ return (e = this.toolbar) == null ? void 0 : e.reposition();
4663
+ }
4664
+ ), document.addEventListener("click", this.onClick), document.addEventListener("keydown", this.onKeyDown, !0), document.addEventListener("paste", this.onPaste, !0), document.addEventListener("dragover", this.onDragOver, !0), document.addEventListener("drop", this.onDrop, !0), document.addEventListener("focusin", this.onFocusIn, !0), document.addEventListener("selectionchange", this.onSelectionChange), window.addEventListener("scroll", this.onViewportChange, !0), window.addEventListener("resize", this.onViewportChange));
4665
+ }
4666
+ detach() {
4667
+ var e;
4668
+ this.attached && (this.attached = !1, this.deselect(), this.uploads.dispose(), (e = this.handles) == null || e.destroy(), this.handles = null, document.removeEventListener("click", this.onClick), document.removeEventListener("keydown", this.onKeyDown, !0), document.removeEventListener("paste", this.onPaste, !0), document.removeEventListener("dragover", this.onDragOver, !0), document.removeEventListener("drop", this.onDrop, !0), document.removeEventListener("focusin", this.onFocusIn, !0), document.removeEventListener("selectionchange", this.onSelectionChange), window.removeEventListener("scroll", this.onViewportChange, !0), window.removeEventListener("resize", this.onViewportChange));
4669
+ }
4670
+ get isAttached() {
4671
+ return this.attached;
4672
+ }
4673
+ get selection() {
4674
+ return this.selected;
4675
+ }
4676
+ select(e) {
4677
+ var r;
4678
+ if (this.selected === e && this.toolbar) {
4679
+ this.onViewportChange();
4680
+ return;
4681
+ }
4682
+ this.deselect(), this.selected = e, this.selectedAt = performance.now();
4683
+ const i = J(e);
4684
+ i && Yt(i), this.toolbar = new Pn(e, {
4685
+ config: () => this.config(),
4686
+ commit: (n, o, s) => this.commit(n, o, s),
4687
+ refresh: () => this.refresh(),
4688
+ removed: () => this.deselect(),
4689
+ returnFocus: () => this.returnFocus(),
4690
+ focusCaption: (n) => this.focusCaption(n)
4691
+ }), (r = this.handles) == null || r.show(Ni(e) ? e : null);
4692
+ }
4693
+ deselect() {
4694
+ var e, i;
4695
+ (e = this.toolbar) == null || e.destroy(), this.toolbar = null, this.selected = null, (i = this.handles) == null || i.show(null);
4696
+ }
4697
+ /** Redraw the frame and the toolbar, rebuilding the toolbar so that it shows the media's current state. */
4698
+ refresh() {
4699
+ var s, a;
4700
+ const e = this.selected;
4701
+ if (!e || !e.isConnected) {
4702
+ this.deselect();
4703
+ return;
4704
+ }
4705
+ const i = this.toolbar, r = document.activeElement, o = ((i == null ? void 0 : i.contains(r)) || r === document.body || r === null) && (s = i == null ? void 0 : i.currentButton()) != null ? s : null;
4706
+ i == null || i.destroy(), this.toolbar = null, this.selected = null, this.select(e), o && ((a = this.toolbar) == null || a.focusButton(o));
4707
+ }
4708
+ /**
4709
+ * Make the media the browser's selection too (a node selection), so that what the browser does next agrees with
4710
+ * it. A click on media in an editor that has no focus is followed by the browser focusing the editor and putting
4711
+ * a caret at the start of its text; without this that looked like the end of the selection.
4712
+ */
4713
+ placeNodeSelection(e) {
4714
+ var o;
4715
+ const i = Xe(e) ? Re(e) : (o = Y(e)) != null ? o : Re(e), r = window.getSelection();
4716
+ if (!r || !i.isConnected) return;
4717
+ const n = document.createRange();
4718
+ n.selectNode(i), r.removeAllRanges(), r.addRange(n);
4719
+ }
4720
+ /** Give the editor back the focus, with the media still selected as a node (so Delete removes it). */
4721
+ returnFocus() {
4722
+ var s;
4723
+ const e = this.selected, i = e ? J(e) : null;
4724
+ if (!e || !i) return;
4725
+ i.focus({ preventScroll: !0 });
4726
+ const r = (s = Y(e)) != null ? s : Re(e), n = document.createRange();
4727
+ n.selectNode(r);
4728
+ const o = window.getSelection();
4729
+ o == null || o.removeAllRanges(), o == null || o.addRange(n);
4730
+ }
4731
+ focusCaption(e) {
4732
+ Fi(e), e.focus({ preventScroll: !0 });
4733
+ const i = document.createRange();
4734
+ i.selectNodeContents(e), i.collapse(!0);
4735
+ const r = window.getSelection();
4736
+ r == null || r.removeAllRanges(), r == null || r.addRange(i);
4737
+ }
4738
+ /** One undoable step for a change to the media, and the editor is told its content changed. */
4739
+ commit(e, i, r) {
4740
+ var s;
4741
+ const n = e.closest(Ke), o = (s = r != null ? r : n == null ? void 0 : n.innerHTML) != null ? s : "";
4742
+ i(), n && (Ge(n, o), n.dispatchEvent(new Event("input", { bubbles: !0 })));
4743
+ }
4744
+ mediaInRange(e) {
4745
+ if (e.collapsed || e.startContainer !== e.endContainer || e.endOffset - e.startOffset !== 1) return null;
4746
+ const i = e.startContainer.childNodes[e.startOffset];
4747
+ return !(i instanceof HTMLElement) || !J(i) ? null : pt(i) ? i : i.matches(Ne) && !i.hasAttribute("data-rte-media-pending") ? i.querySelector(mt) : i.tagName === "A" && i.children.length === 1 && pt(i.firstElementChild) ? i.firstElementChild : null;
4748
+ }
4749
+ /**
4750
+ * Arrow keys step onto media instead of over it. The browser's caret skips a figure (which is not editable), so
4751
+ * from the keyboard it could not be reached: the arrow at the edge of the block next to it selects it, the
4752
+ * next arrow carries on past it; from the start of its caption, up goes back to the media.
4753
+ */
4754
+ arrowOntoMedia(e, i) {
4755
+ const r = e.key === "ArrowRight" || e.key === "ArrowDown", n = e.key === "ArrowLeft" || e.key === "ArrowUp";
4756
+ if (!r && !n || e.shiftKey || e.altKey || e.ctrlKey || e.metaKey || e.defaultPrevented) return;
4757
+ const o = i ? J(i) : null, s = window.getSelection();
4758
+ if (!o || !s || s.rangeCount === 0) return;
4759
+ const a = s.getRangeAt(0), l = (f, m) => {
4760
+ e.preventDefault();
4761
+ const b = document.createRange();
4762
+ b.selectNode(f), s.removeAllRanges(), s.addRange(b);
4763
+ const v = f.querySelector(mt);
4764
+ v && this.select(v);
4765
+ }, d = this.mediaInRange(a);
4766
+ if (d) {
4767
+ const f = Y(d), m = f != null ? f : Re(d), b = r ? m.nextElementSibling : m.previousElementSibling;
4768
+ b && (e.preventDefault(), s.removeAllRanges(), s.addRange(Zn(b, r ? "start" : "end")));
4769
+ return;
4770
+ }
4771
+ if (!a.collapsed) return;
4772
+ const c = i == null ? void 0 : i.closest("figure.rte-media > figcaption");
4773
+ if (c) {
4774
+ n && ri(a, c, "start") && l(c.parentElement);
4775
+ return;
4776
+ }
4777
+ const p = Qn(a.startContainer, o);
4778
+ if (!p || ii(p)) return;
4779
+ const u = r ? p.nextElementSibling : p.previousElementSibling;
4780
+ u && ii(u) && ri(a, p, r ? "end" : "start") && l(u);
4781
+ }
4782
+ wantsDrop(e) {
4783
+ var o;
4784
+ const i = _e(e.target);
4785
+ if (!i || i.closest(".rte-media-overlay")) return !1;
4786
+ const r = J(i);
4787
+ if (!r || !ti(r) || q(this.config()).uploadOnPaste === !1) return !1;
4788
+ const n = e.dataTransfer;
4789
+ return !n || !Array.from((o = n.types) != null ? o : []).includes("Files") ? !1 : e.type === "dragover" || gt(n, void 0).length > 0;
4790
+ }
4791
+ }
4792
+ let je = null;
4793
+ const to = () => je != null ? je : je = new eo(), io = '<svg width="24px" height="24px" viewBox="0 0 32 32" enable-background="new 0 0 32 32"><g><rect fill="none" height="22" stroke="#000000" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="2" width="30" x="1" y="5"></rect><polygon fill="none" points="31,27 21,17 11,27" stroke="#000000" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="2"></polygon><polygon fill="none" points="18,20 9,11 1,19 1,27 11,27" stroke="#000000" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="2"></polygon><circle cx="19" cy="11" fill="none" r="2" stroke="#000000" stroke-linejoin="round" stroke-miterlimit="10" stroke-width="2"></circle></g></svg>', ro = '<svg width="24" height="24" focusable="false"><path d="M4 3h16c.6 0 1 .4 1 1v16c0 .6-.4 1-1 1H4a1 1 0 0 1-1-1V4c0-.6.4-1 1-1Zm1 2v14h14V5H5Zm4.8 2.6 5.6 4a.5.5 0 0 1 0 .8l-5.6 4A.5.5 0 0 1 9 16V8a.5.5 0 0 1 .8-.4Z" fill-rule="nonzero"></path></svg>', no = '<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" focusable="false"><path d="M9 18V6l10-2v12"></path><circle cx="6.5" cy="18" r="2.5"></circle><circle cx="16.5" cy="16" r="2.5"></circle></svg>', ft = (t) => (t == null ? void 0 : t.contentElement) instanceof HTMLElement ? t.contentElement : void 0, uo = (t) => {
4794
+ const e = to(), i = () => {
4795
+ e.setConfigSource(() => t), e.attach();
4796
+ };
4797
+ return typeof window != "undefined" && i(), {
4798
+ name: "image",
4799
+ initialize: () => {
4800
+ i();
4801
+ },
4802
+ destroy: () => {
4803
+ e.detach();
4804
+ },
4805
+ toolbar: [
4806
+ { label: "Image", command: "insertImage", icon: io },
4807
+ { label: "Video", command: "insertVideo", icon: ro },
4808
+ ...q(t).audio ? [{ label: "Audio", command: "insertAudio", icon: no }] : []
4809
+ ],
4810
+ commands: {
4811
+ insertImage: (r, n) => (i(), ut("image", ft(n), t), !0),
4812
+ insertVideo: (r, n) => (i(), ut("video", ft(n), t), !0),
4813
+ insertAudio: (r, n) => (i(), ut("audio", ft(n), t), !0)
4814
+ },
4815
+ keymap: {
4816
+ "Mod-Shift-i": "insertImage"
4817
+ }
4818
+ };
4819
+ };
4820
+ export {
4821
+ uo as MediaManagerPlugin
4822
+ };
4823
+ //# sourceMappingURL=MediaManagerPlugin.native-0YFHZfsb.mjs.map