@editora/plugins 1.0.22 → 1.1.0

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