@editora/plugins 1.0.23 → 1.2.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.
@@ -0,0 +1,1841 @@
1
+ "use strict";const gt=require("./shared-config.cjs.js"),Vi=require("./dialogHelpers-BxSQ7A6M.js"),kt=require("./confirmDialog-D3S8BhIM.js"),_e=require("./historyHelpers-Cu8Pk7m1.js"),ft=require("./escapeHtml-D2Zh82pD.js"),Rt=require("./notify-BkbzMopb.js"),Ke={upload:"/media/upload",library:"/media/library",delete:"/media/library"},Ki=["image/jpeg","image/png","image/gif","image/webp","image/avif","video/mp4","video/webm","video/ogg","audio/mpeg","audio/wav","audio/ogg","audio/mp4","audio/aac","audio/webm"],Gi=10*1024*1024,Yi={apiEndpoints:{...Ke},maxFileSize:Gi,allowedTypes:[...Ki],headers:{}};let $e={...Yi};function Xi(t){$e={...$e,...t,apiEndpoints:{...Ke,...$e.apiEndpoints,...t.apiEndpoints}}}function Ge(){return{...$e,apiEndpoints:{...Ke,...$e.apiEndpoints}}}function F(t){const e=Ge();return t?{...e,...t,apiEndpoints:{...e.apiEndpoints,...t.apiEndpoints},headers:{...e.headers,...t.headers}}:e}function at(t,e=Ge()){const i=e.apiUrl??gt.getGlobalApiConfig().apiUrl;return gt.buildApiUrl(i,(e.apiEndpoints??Ke)[t])}function Zi(t=Ge()){return{...gt.getGlobalApiHeaders(),...t.headers||{}}}class $ extends Error{constructor(e,i,r){super(i),this.name=e==="aborted"?"AbortError":"MediaUploadError",this.code=e,this.status=r}}const Ye=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";let Qi=0;const Et=()=>`media-${Date.now().toString(36)}-${(Qi++).toString(36)}`,At=()=>({name:"base64",upload(t,{signal:e,onProgress:i}={}){return new Promise((r,n)=>{if(e?.aborted){n(new $("aborted","Upload cancelled"));return}const o=new FileReader,a=()=>o.abort();e?.addEventListener("abort",a,{once:!0});const s=()=>e?.removeEventListener("abort",a);o.onprogress=l=>{l.lengthComputable&&i?.({loaded:l.loaded,total:l.total,fraction:l.loaded/l.total})},o.onload=()=>{s(),i?.({loaded:t.size,total:t.size,fraction:1}),r({id:Et(),name:t.name,type:je(t.type),src:o.result,size:t.size,mime:t.type,createdAt:Date.now(),metadata:{}})},o.onerror=()=>{s(),n(new $("network",`Couldn't read ${t.name||"the file"}.`))},o.onabort=()=>{s(),n(new $("aborted","Upload cancelled"))},o.readAsDataURL(t)})}}),ii=t=>({name:"callback",async upload(e,i={}){if(i.signal?.aborted)throw new $("aborted","Upload cancelled");const r=new Promise((a,s)=>{i.signal?.addEventListener("abort",()=>s(new $("aborted","Upload cancelled")),{once:!0})});let n;try{n=await Promise.race([t(e,i),r])}catch(a){throw a instanceof $?a:new $("server",a instanceof Error&&a.message?a.message:`Couldn't upload ${e.name||"the file"}.`)}const o=typeof n=="string"?{url:n}:n;if(!o||typeof o.url!="string"||!o.url)throw new $("invalid-response","The upload finished, but the server sent back no URL.");return{id:o.id??Et(),name:o.name??e.name,type:je(e.type),src:o.url,size:e.size,width:o.width,height:o.height,mime:e.type,createdAt:Date.now(),metadata:{},thumbnailUrl:o.thumbnailUrl}}}),Ji="editora-media-library",st="items",Dt=60,er=8*1024*1024,tr=240,ir=()=>{const t=new Map;return{all:async()=>[...t.values()],put:async e=>{t.set(e.id,e)},remove:async e=>{t.delete(e)}}},rr=t=>new Promise((e,i)=>{t.onsuccess=()=>e(t.result),t.onerror=()=>i(t.error)}),nr=()=>{if(typeof indexedDB>"u")return null;let t=null;const e=()=>t??=new Promise((r,n)=>{const o=indexedDB.open(Ji,1);o.onupgradeneeded=()=>o.result.createObjectStore(st,{keyPath:"id"}),o.onsuccess=()=>r(o.result),o.onerror=()=>n(o.error),o.onblocked=()=>n(new Error("blocked"))}),i=async(r,n)=>{const o=await e();return rr(n(o.transaction(st,r).objectStore(st)))};return{all:()=>i("readonly",r=>r.getAll()),put:async r=>{await i("readwrite",n=>n.put(r))},remove:async r=>{await i("readwrite",n=>n.delete(r))}}},or=()=>{const t=nr(),e=ir();if(!t)return e;let i=!1;const r=async n=>{if(!i)try{return await n(t)}catch{i=!0}return n(e)};return{all:()=>r(n=>n.all()),put:n=>r(o=>o.put(n)),remove:n=>r(o=>o.remove(n))}};let ar=null;const ue=()=>ar??=or(),sr=t=>new Promise(e=>{if(typeof document>"u"||typeof Image>"u")return e(null);const i=new Image,r=window.setTimeout(()=>e(null),4e3);i.onload=()=>{window.clearTimeout(r);try{const n=Math.min(1,tr/Math.max(i.naturalWidth,i.naturalHeight,1));if(n>=1)return e(null);const o=document.createElement("canvas");o.width=Math.max(1,Math.round(i.naturalWidth*n)),o.height=Math.max(1,Math.round(i.naturalHeight*n));const a=o.getContext("2d");if(!a)return e(null);a.drawImage(i,0,0,o.width,o.height),e(o.toDataURL("image/jpeg",.8))}catch{e(null)}},i.onerror=()=>{window.clearTimeout(r),e(null)},i.src=t}),lr=async t=>{if(t.src.length>er||t.type==="file")return;const e={...t,metadata:{...t.metadata,local:!0}};try{await ue().put(e);const i=await ue().all();if(i.length>Dt){const r=i.sort((n,o)=>n.createdAt-o.createdAt).slice(0,i.length-Dt);await Promise.all(r.map(n=>ue().remove(n.id)))}t.type==="image"&&!t.thumbnailUrl&&sr(t.src).then(r=>r?ue().put({...e,thumbnailUrl:r}):void 0).catch(()=>{})}catch{}},ri=Symbol("editora.localLibrary"),dr=t=>t[ri]===!0,cr=t=>typeof t.list=="function"?t:{[ri]:!0,name:t.name,upload:async(i,r)=>{const n=await t.upload(i,r);return await lr(n),n},async list(i={}){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;return{items:n.slice((a-1)*o,a*o),total:n.length}},async update(i,r){const n=(await ue().all()).find(o=>o.id===i);n&&await ue().put({...n,...r.name!==void 0?{name:r.name}:{},...r.alt!==void 0?{alt:r.alt}:{}})},delete:i=>ue().remove(i)},Pe=t=>{const e=typeof t=="string"?Number(t):t;return typeof e=="number"&&Number.isFinite(e)&&e>0?e:void 0},Nt=(t,e)=>{const i=t?.url??t?.src??t?.location;if(typeof i!="string"||!i)throw new $("invalid-response","The upload finished, but the server sent back no URL.");const r=t.mimeType??t.mime??t.mime_type??e?.type??"";return{id:String(t.id??Et()),name:t.name??t.originalName??t.original_filename??t.filename??e?.name??"",type:e?.type?je(e.type):t.type==="image"||t.type==="video"||t.type==="audio"||t.type==="file"?t.type:je(r),src:i,size:Pe(t.size)??e?.size??0,width:Pe(t.width),height:Pe(t.height),duration:Pe(t.duration),mime:r,createdAt:t.createdAt&&Date.parse(t.createdAt)||Date.now(),metadata:t.metadata&&typeof t.metadata=="object"?t.metadata:{},thumbnailUrl:t.thumbnailUrl??t.thumbnail_url??void 0,alt:typeof(t.alt??t.alt_text)=="string"?t.alt??t.alt_text:void 0}},Ut=t=>{try{const e=JSON.parse(t.responseText),i=e?.error??e?.message;if(typeof i=="string"&&i)return i;if(i?.message)return String(i.message)}catch{}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}).`},ni=t=>{const e=()=>t.headers?.()??{},i=(o,a)=>`${o.replace(/\/$/,"")}/${encodeURIComponent(a)}`,r=async(o,a)=>{let s;try{s=await fetch(o,{credentials:t.withCredentials?"include":"same-origin",...a,headers:{...e(),...a.headers}})}catch(l){throw l?.name==="AbortError"?new $("aborted","Request cancelled"):new $("network","Couldn't reach the media server.")}if(!s.ok)throw new $("server",Ut({status:s.status,responseText:await s.text()}),s.status);return s},n={name:"rest",upload(o,{signal:a,onProgress:s}={}){return new Promise((l,c)=>{if(a?.aborted){c(new $("aborted","Upload cancelled"));return}const d=new XMLHttpRequest;d.open("POST",t.uploadUrl),d.withCredentials=!!t.withCredentials;for(const[y,x]of Object.entries(e()))y.toLowerCase()!=="content-type"&&d.setRequestHeader(y,x);const u=()=>d.abort();a?.addEventListener("abort",u,{once:!0});const h=()=>a?.removeEventListener("abort",u);d.upload.onprogress=y=>{y.lengthComputable&&s?.({loaded:y.loaded,total:y.total,fraction:y.total?y.loaded/y.total:0})},d.onload=()=>{if(h(),d.status<200||d.status>=300){c(new $("server",Ut(d),d.status));return}try{const y=Nt(JSON.parse(d.responseText),o);s?.({loaded:o.size,total:o.size,fraction:1}),l(y)}catch(y){c(y instanceof $?y:new $("invalid-response","The server answered, but not in a form the editor can read."))}},d.onerror=()=>{h(),c(new $("network","Couldn't reach the media server. Check your connection and try again."))},d.ontimeout=d.onerror,d.onabort=()=>{h(),c(new $("aborted","Upload cancelled"))};const b=new FormData;b.append(t.fieldName||"file",o,o.name),d.send(b)})}};if(t.libraryUrl){const o=t.libraryUrl;n.list=async(s={},l={})=>{const c=new URLSearchParams;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);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??[];return{items:h.map(b=>Nt(b)),total:Number(u?.total??h.length)}},n.update=async(s,l)=>{const c={};l.name!==void 0&&(c.title=l.name),l.alt!==void 0&&(c.alt_text=l.alt),await r(i(o,s),{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)})};const a=t.deleteUrl||o;n.delete=async s=>{await r(i(a,s),{method:"DELETE"})}}return n},oi=(t=F())=>{const e=pr(t);return t.localLibrary===!1?e:cr(e)},pr=t=>{if(t.provider)return t.provider;if(t.uploadHandler)return ii(t.uploadHandler);const e=at("upload",t);return e?ni({uploadUrl:e,libraryUrl:at("library",t),deleteUrl:at("delete",t),headers:()=>Zi(t),withCredentials:t.withCredentials,fieldName:t.uploadFieldName}):At()},ai='[data-theme="dark"], .dark, .editora-theme-dark',Ce=()=>{if(typeof document>"u"||document.getElementById("rte-media-dialog-styles"))return;const t=document.createElement("style");t.id="rte-media-dialog-styles",t.textContent=`
2
+ .rte-media-overlay {
3
+ --rte-media-overlay-bg: rgba(15, 23, 36, 0.56);
4
+ --rte-media-bg: #ffffff;
5
+ --rte-media-text: #101828;
6
+ --rte-media-muted: #5f6b7d;
7
+ --rte-media-border: #d6dbe4;
8
+ --rte-media-surface: #f7f9fc;
9
+ --rte-media-surface-hover: #eef2f7;
10
+ --rte-media-accent: #1560e8;
11
+ --rte-media-primary: #101828;
12
+ --rte-media-primary-hover: #2a3345;
13
+ --rte-media-primary-text: #ffffff;
14
+ --rte-media-accent-hover: #165fd6;
15
+ --rte-media-danger: #dc3545;
16
+ --rte-media-danger-hover: #b92735;
17
+ --rte-media-danger-text: #b92735;
18
+ --rte-media-ring: rgba(31, 117, 254, 0.18);
19
+ position: fixed;
20
+ top: 0;
21
+ left: 0;
22
+ right: 0;
23
+ bottom: 0;
24
+ background: var(--rte-media-overlay-bg);
25
+ backdrop-filter: blur(2px);
26
+ display: flex;
27
+ align-items: center;
28
+ justify-content: center;
29
+ z-index: 99999;
30
+ padding: 16px;
31
+ box-sizing: border-box;
32
+ }
33
+
34
+ .rte-media-overlay.rte-ui-theme-dark {
35
+ --rte-media-overlay-bg: rgba(2, 8, 20, 0.72);
36
+ --rte-media-bg: #202938;
37
+ --rte-media-text: #e8effc;
38
+ --rte-media-muted: #a5b1c5;
39
+ --rte-media-border: #49566c;
40
+ --rte-media-surface: #2a3444;
41
+ --rte-media-surface-hover: #344256;
42
+ --rte-media-accent: #1f6feb;
43
+ --rte-media-accent-hover: #4598f4;
44
+ --rte-media-primary: #e8effc;
45
+ --rte-media-primary-hover: #ffffff;
46
+ --rte-media-primary-text: #101828;
47
+ --rte-media-danger: #ff7b72;
48
+ --rte-media-danger-hover: #ff645b;
49
+ --rte-media-danger-text: #ffa39d;
50
+ --rte-media-ring: rgba(88, 166, 255, 0.22);
51
+ }
52
+
53
+ .rte-media-dialog {
54
+ width: min(92vw, 640px);
55
+ max-height: 90vh;
56
+ display: flex;
57
+ flex-direction: column;
58
+ overflow: hidden;
59
+ background: var(--rte-media-bg);
60
+ color: var(--rte-media-text);
61
+ border: 1px solid var(--rte-media-border);
62
+ border-radius: 12px;
63
+ box-shadow: 0 24px 48px rgba(10, 15, 24, 0.28);
64
+ }
65
+
66
+ .rte-media-dialog.rte-media-dialog-compact {
67
+ width: min(92vw, 520px);
68
+ }
69
+
70
+ .rte-media-header {
71
+ display: flex;
72
+ align-items: center;
73
+ justify-content: space-between;
74
+ padding: 16px 20px;
75
+ border-bottom: 1px solid var(--rte-media-border);
76
+ background: linear-gradient(180deg, rgba(127, 154, 195, 0.08) 0%, rgba(127, 154, 195, 0) 100%);
77
+ }
78
+
79
+ .rte-media-title {
80
+ margin: 0;
81
+ font-size: 18px;
82
+ font-weight: 600;
83
+ color: var(--rte-media-text);
84
+ }
85
+
86
+ .rte-media-close-btn {
87
+ width: 32px;
88
+ height: 32px;
89
+ border: none;
90
+ border-radius: 8px;
91
+ background: transparent;
92
+ color: var(--rte-media-muted);
93
+ font-size: 24px;
94
+ line-height: 1;
95
+ cursor: pointer;
96
+ transition: background-color 0.16s ease, color 0.16s ease;
97
+ }
98
+
99
+ .rte-media-close-btn:hover {
100
+ background: var(--rte-media-surface-hover);
101
+ color: var(--rte-media-text);
102
+ }
103
+
104
+ .rte-media-tabs {
105
+ display: grid;
106
+ grid-template-columns: 1fr 1fr;
107
+ border-bottom: 1px solid var(--rte-media-border);
108
+ gap: 0;
109
+ }
110
+
111
+ .rte-media-tab {
112
+ border: none;
113
+ border-right: 1px solid var(--rte-media-border);
114
+ padding: 12px 14px;
115
+ background: var(--rte-media-surface);
116
+ color: var(--rte-media-muted);
117
+ font-size: 14px;
118
+ font-weight: 600;
119
+ cursor: pointer;
120
+ transition: background-color 0.16s ease, color 0.16s ease;
121
+ }
122
+
123
+ .rte-media-tab:last-child {
124
+ border-right: none;
125
+ }
126
+
127
+ .rte-media-tab:hover {
128
+ background: var(--rte-media-surface-hover);
129
+ color: var(--rte-media-text);
130
+ }
131
+
132
+ .rte-media-tab.active {
133
+ background: var(--rte-media-accent);
134
+ color: #fff;
135
+ }
136
+
137
+ .rte-media-body {
138
+ padding: 20px;
139
+ overflow-y: auto;
140
+ flex: 1;
141
+ }
142
+
143
+ .rte-media-field {
144
+ margin-bottom: 16px;
145
+ }
146
+
147
+ .rte-media-grid {
148
+ display: grid;
149
+ grid-template-columns: 1fr 1fr;
150
+ gap: 12px;
151
+ margin-bottom: 16px;
152
+ }
153
+
154
+ .rte-media-label {
155
+ display: block;
156
+ margin-bottom: 8px;
157
+ color: var(--rte-media-text);
158
+ font-size: 14px;
159
+ font-weight: 600;
160
+ }
161
+
162
+ .rte-media-input,
163
+ .rte-media-textarea {
164
+ width: 100%;
165
+ box-sizing: border-box;
166
+ padding: 10px 12px;
167
+ border: 1px solid var(--rte-media-border);
168
+ border-radius: 8px;
169
+ background: var(--rte-media-surface);
170
+ color: var(--rte-media-text);
171
+ font-size: 14px;
172
+ transition: border-color 0.16s ease, box-shadow 0.16s ease;
173
+ }
174
+
175
+ .rte-media-input::placeholder,
176
+ .rte-media-textarea::placeholder {
177
+ color: var(--rte-media-muted);
178
+ }
179
+
180
+ .rte-media-input:focus,
181
+ .rte-media-textarea:focus {
182
+ outline: none;
183
+ border-color: var(--rte-media-accent);
184
+ box-shadow: 0 0 0 3px var(--rte-media-ring);
185
+ }
186
+
187
+ .rte-media-textarea {
188
+ min-height: 92px;
189
+ resize: vertical;
190
+ font-family: inherit;
191
+ }
192
+
193
+ .rte-media-dropzone {
194
+ border: 2px dashed var(--rte-media-border);
195
+ border-radius: 12px;
196
+ padding: 36px 18px;
197
+ text-align: center;
198
+ cursor: pointer;
199
+ background: var(--rte-media-surface);
200
+ transition: border-color 0.16s ease, background-color 0.16s ease;
201
+ }
202
+
203
+ .rte-media-dropzone:hover,
204
+ .rte-media-dropzone.is-dragover {
205
+ border-color: var(--rte-media-accent);
206
+ background: var(--rte-media-surface-hover);
207
+ }
208
+
209
+ .rte-media-dropzone-icon {
210
+ font-size: 40px;
211
+ margin-bottom: 10px;
212
+ line-height: 1;
213
+ }
214
+
215
+ .rte-media-dropzone-title {
216
+ margin: 0 0 8px 0;
217
+ font-size: 16px;
218
+ font-weight: 600;
219
+ color: var(--rte-media-text);
220
+ }
221
+
222
+ .rte-media-muted {
223
+ margin: 0 0 8px 0;
224
+ color: var(--rte-media-muted);
225
+ font-size: 14px;
226
+ }
227
+
228
+ .rte-media-hint {
229
+ margin: 0;
230
+ color: var(--rte-media-muted);
231
+ font-size: 12px;
232
+ }
233
+
234
+ .rte-media-progress {
235
+ margin-top: 16px;
236
+ }
237
+
238
+ .rte-media-progress-track {
239
+ height: 8px;
240
+ border-radius: 999px;
241
+ background: var(--rte-media-surface);
242
+ overflow: hidden;
243
+ border: 1px solid var(--rte-media-border);
244
+ }
245
+
246
+ .rte-media-progress-bar {
247
+ height: 100%;
248
+ width: 0;
249
+ background: var(--rte-media-accent);
250
+ transition: width 0.3s ease;
251
+ }
252
+
253
+ .rte-media-progress-text {
254
+ margin-top: 8px;
255
+ text-align: center;
256
+ color: var(--rte-media-muted);
257
+ font-size: 13px;
258
+ }
259
+
260
+ .rte-media-progress-actions {
261
+ display: flex;
262
+ justify-content: center;
263
+ margin-top: 10px;
264
+ }
265
+
266
+ .rte-media-error {
267
+ margin: 12px 0 0;
268
+ padding: 8px 12px;
269
+ border: 1px solid var(--rte-media-danger);
270
+ border-radius: 8px;
271
+ color: var(--rte-media-danger);
272
+ font-size: 13px;
273
+ line-height: 1.4;
274
+ }
275
+
276
+ .rte-media-error[hidden] {
277
+ display: none;
278
+ }
279
+
280
+ .rte-media-preview {
281
+ border: 1px solid var(--rte-media-border);
282
+ border-radius: 10px;
283
+ padding: 10px;
284
+ text-align: center;
285
+ background: var(--rte-media-surface);
286
+ }
287
+
288
+ .rte-media-preview img,
289
+ .rte-media-preview video {
290
+ max-width: 100%;
291
+ max-height: 240px;
292
+ }
293
+
294
+ .rte-media-helper {
295
+ margin-top: 8px;
296
+ margin-bottom: 0;
297
+ font-size: 12px;
298
+ color: var(--rte-media-muted);
299
+ line-height: 1.5;
300
+ }
301
+
302
+ .rte-media-footer {
303
+ display: flex;
304
+ justify-content: flex-end;
305
+ gap: 10px;
306
+ padding: 16px 20px;
307
+ border-top: 1px solid var(--rte-media-border);
308
+ background: var(--rte-media-surface);
309
+ }
310
+
311
+ .rte-media-footer.rte-media-footer-spread {
312
+ justify-content: space-between;
313
+ align-items: center;
314
+ }
315
+
316
+ .rte-media-btn {
317
+ border-radius: 8px;
318
+ border: 1px solid transparent;
319
+ padding: 10px 16px;
320
+ font-size: 14px;
321
+ font-weight: 600;
322
+ cursor: pointer;
323
+ transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
324
+ }
325
+
326
+ .rte-media-btn-secondary {
327
+ background: var(--rte-media-bg);
328
+ border-color: var(--rte-media-border);
329
+ color: var(--rte-media-text);
330
+ }
331
+
332
+ .rte-media-btn-secondary:hover {
333
+ background: var(--rte-media-surface-hover);
334
+ }
335
+
336
+ .rte-media-btn-primary {
337
+ background: var(--rte-media-primary);
338
+ color: var(--rte-media-primary-text);
339
+ }
340
+
341
+ .rte-media-btn-primary:hover {
342
+ background: var(--rte-media-primary-hover);
343
+ }
344
+
345
+ .rte-media-btn-primary:disabled {
346
+ opacity: 0.55;
347
+ cursor: not-allowed;
348
+ }
349
+
350
+ .rte-media-btn-danger {
351
+ background: var(--rte-media-danger);
352
+ color: #fff;
353
+ }
354
+
355
+ .rte-media-btn-danger:hover {
356
+ background: var(--rte-media-danger-hover);
357
+ }
358
+
359
+ .rte-media-checkbox-label {
360
+ display: inline-flex;
361
+ align-items: center;
362
+ gap: 8px;
363
+ color: var(--rte-media-text);
364
+ font-size: 14px;
365
+ cursor: pointer;
366
+ }
367
+
368
+ .rte-media-checkbox-label input {
369
+ accent-color: var(--rte-media-accent);
370
+ }
371
+
372
+ .rte-media-actions {
373
+ display: flex;
374
+ gap: 10px;
375
+ }
376
+
377
+ .rte-media-spacer {
378
+ flex: 1;
379
+ }
380
+
381
+
382
+ /* ── The media picker ─────────────────────────────────────────────── */
383
+ .rte-media-dialog.rte-mp {
384
+ width: min(96vw, 980px);
385
+ height: min(88vh, 640px);
386
+ max-height: none;
387
+ position: relative;
388
+ border-radius: 16px;
389
+ }
390
+
391
+ .rte-mp-header {
392
+ display: flex;
393
+ align-items: center;
394
+ gap: 12px;
395
+ padding: 12px 16px;
396
+ border-bottom: 1px solid var(--rte-media-border);
397
+ }
398
+
399
+ .rte-mp-header .rte-media-title {
400
+ font-size: 16px;
401
+ flex: none;
402
+ }
403
+
404
+ .rte-mp-search {
405
+ flex: 1;
406
+ min-width: 0;
407
+ display: flex;
408
+ align-items: center;
409
+ gap: 8px;
410
+ height: 34px;
411
+ padding: 0 10px;
412
+ border: 1px solid var(--rte-media-border);
413
+ border-radius: 8px;
414
+ background: var(--rte-media-surface);
415
+ color: var(--rte-media-muted);
416
+ }
417
+
418
+ .rte-mp-search:focus-within {
419
+ border-color: var(--rte-media-accent);
420
+ box-shadow: 0 0 0 3px var(--rte-media-ring);
421
+ }
422
+
423
+ .rte-mp-search input {
424
+ flex: 1;
425
+ min-width: 0;
426
+ border: 0;
427
+ outline: 0;
428
+ background: transparent;
429
+ color: var(--rte-media-text);
430
+ font-size: 14px;
431
+ }
432
+
433
+ .rte-mp-search[hidden] {
434
+ display: none;
435
+ }
436
+
437
+ .rte-mp-spacer {
438
+ flex: 1;
439
+ }
440
+
441
+ .rte-mp-body {
442
+ flex: 1;
443
+ min-height: 0;
444
+ display: grid;
445
+ grid-template-columns: 168px minmax(0, 1fr) 272px;
446
+ }
447
+
448
+ .rte-mp.no-details .rte-mp-body {
449
+ grid-template-columns: 168px minmax(0, 1fr);
450
+ }
451
+
452
+ .rte-mp-nav {
453
+ display: flex;
454
+ flex-direction: column;
455
+ gap: 2px;
456
+ padding: 12px 8px;
457
+ border-right: 1px solid var(--rte-media-border);
458
+ background: var(--rte-media-surface);
459
+ }
460
+
461
+ .rte-mp-nav-item {
462
+ display: flex;
463
+ align-items: center;
464
+ gap: 10px;
465
+ width: 100%;
466
+ padding: 8px 10px;
467
+ border: 0;
468
+ border-radius: 8px;
469
+ background: transparent;
470
+ color: var(--rte-media-muted);
471
+ font-size: 14px;
472
+ text-align: left;
473
+ cursor: pointer;
474
+ }
475
+
476
+ .rte-mp-nav-item:hover {
477
+ background: var(--rte-media-surface-hover);
478
+ color: var(--rte-media-text);
479
+ }
480
+
481
+ .rte-mp-nav-item[aria-selected="true"] {
482
+ background: var(--rte-media-ring);
483
+ color: var(--rte-media-text);
484
+ font-weight: 600;
485
+ }
486
+
487
+ .rte-mp-nav-item[aria-selected="true"] svg {
488
+ color: var(--rte-media-accent);
489
+ }
490
+
491
+ .rte-mp-nav-item:focus-visible,
492
+ .rte-mp-chip:focus-visible,
493
+ .rte-mp-tile:focus-visible,
494
+ .rte-mp-icon-btn:focus-visible {
495
+ outline: 2px solid var(--rte-media-accent);
496
+ outline-offset: 2px;
497
+ }
498
+
499
+ .rte-mp-badge {
500
+ margin-left: auto;
501
+ min-width: 18px;
502
+ padding: 0 6px;
503
+ border-radius: 999px;
504
+ background: var(--rte-media-accent);
505
+ color: #fff;
506
+ font-size: 11px;
507
+ line-height: 18px;
508
+ text-align: center;
509
+ }
510
+
511
+ .rte-mp-main {
512
+ min-width: 0;
513
+ min-height: 0;
514
+ display: flex;
515
+ flex-direction: column;
516
+ }
517
+
518
+ .rte-mp-view {
519
+ flex: 1;
520
+ min-height: 0;
521
+ display: flex;
522
+ flex-direction: column;
523
+ }
524
+
525
+ .rte-mp-view[hidden] {
526
+ display: none;
527
+ }
528
+
529
+ .rte-mp-toolbar {
530
+ display: flex;
531
+ flex-wrap: wrap;
532
+ gap: 8px;
533
+ padding: 14px 16px 0;
534
+ }
535
+
536
+ .rte-mp-chip {
537
+ padding: 6px 16px;
538
+ border: 1px solid var(--rte-media-border);
539
+ border-radius: 999px;
540
+ background: transparent;
541
+ color: var(--rte-media-muted);
542
+ font-size: 13px;
543
+ cursor: pointer;
544
+ }
545
+
546
+ .rte-mp-chip:hover {
547
+ background: var(--rte-media-surface-hover);
548
+ }
549
+
550
+ .rte-mp-chip[aria-pressed="true"] {
551
+ background: var(--rte-media-text);
552
+ border-color: var(--rte-media-text);
553
+ color: var(--rte-media-bg);
554
+ }
555
+
556
+ .rte-mp-scroll {
557
+ flex: 1;
558
+ min-height: 0;
559
+ overflow: auto;
560
+ padding: 12px 16px 16px;
561
+ }
562
+
563
+ .rte-mp-grid {
564
+ display: grid;
565
+ grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
566
+ gap: 10px;
567
+ }
568
+
569
+ .rte-mp-tile {
570
+ position: relative;
571
+ aspect-ratio: 1;
572
+ border: 0;
573
+ border-radius: 12px;
574
+ overflow: hidden;
575
+ background: var(--rte-media-surface-hover);
576
+ color: var(--rte-media-muted);
577
+ cursor: pointer;
578
+ box-shadow: inset 0 0 0 1px var(--rte-media-border);
579
+ transition: box-shadow 0.12s ease, transform 0.12s ease;
580
+ }
581
+
582
+ .rte-mp-tile:hover {
583
+ box-shadow: inset 0 0 0 1px var(--rte-media-muted);
584
+ }
585
+
586
+ .rte-mp-tile[aria-selected="true"],
587
+ .rte-mp-tile.is-selected {
588
+ box-shadow: inset 0 0 0 3px var(--rte-media-accent);
589
+ }
590
+
591
+ .rte-mp-tile-pick {
592
+ position: absolute;
593
+ inset: 0;
594
+ border: 0;
595
+ background: transparent;
596
+ cursor: pointer;
597
+ border-radius: inherit;
598
+ }
599
+
600
+ .rte-mp-tile-pick:focus-visible {
601
+ outline: 2px solid var(--rte-media-accent);
602
+ outline-offset: -4px;
603
+ }
604
+
605
+ .rte-mp-tile img,
606
+ .rte-mp-tile video {
607
+ position: absolute;
608
+ inset: 0;
609
+ width: 100%;
610
+ height: 100%;
611
+ object-fit: cover;
612
+ display: block;
613
+ pointer-events: none;
614
+ }
615
+
616
+ .rte-mp-tile img.rte-mp-fade {
617
+ opacity: 0;
618
+ transition: opacity 0.2s ease;
619
+ }
620
+
621
+ .rte-mp-tile img.rte-mp-fade.is-loaded {
622
+ opacity: 1;
623
+ }
624
+
625
+ .rte-mp-tile img.is-broken {
626
+ display: none;
627
+ }
628
+
629
+ .rte-mp-tile-name {
630
+ position: absolute;
631
+ left: 0;
632
+ right: 0;
633
+ bottom: 0;
634
+ padding: 14px 8px 6px;
635
+ background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.62) 100%);
636
+ color: #fff;
637
+ font-size: 12px;
638
+ text-align: left;
639
+ white-space: nowrap;
640
+ overflow: hidden;
641
+ text-overflow: ellipsis;
642
+ opacity: 0;
643
+ transition: opacity 0.12s ease;
644
+ }
645
+
646
+ .rte-mp-tile:hover .rte-mp-tile-name,
647
+ .rte-mp-tile:focus-visible .rte-mp-tile-name,
648
+ .rte-mp-tile:focus-within .rte-mp-tile-name,
649
+ .rte-mp-tile.is-selected .rte-mp-tile-name,
650
+ .rte-mp-tile[aria-selected="true"] .rte-mp-tile-name {
651
+ opacity: 1;
652
+ }
653
+
654
+ .rte-mp-tile-check {
655
+ position: absolute;
656
+ top: 8px;
657
+ right: 8px;
658
+ width: 22px;
659
+ height: 22px;
660
+ display: none;
661
+ align-items: center;
662
+ justify-content: center;
663
+ border-radius: 50%;
664
+ background: var(--rte-media-accent);
665
+ color: #fff;
666
+ }
667
+
668
+ .rte-mp-tile[aria-selected="true"] .rte-mp-tile-check,
669
+ .rte-mp-tile.is-selected .rte-mp-tile-check {
670
+ display: flex;
671
+ }
672
+
673
+ .rte-mp-tile-kind {
674
+ position: absolute;
675
+ left: 8px;
676
+ top: 8px;
677
+ width: 24px;
678
+ height: 24px;
679
+ display: flex;
680
+ align-items: center;
681
+ justify-content: center;
682
+ border-radius: 50%;
683
+ background: rgba(0, 0, 0, 0.55);
684
+ color: #fff;
685
+ }
686
+
687
+ .rte-mp-tile-icon {
688
+ position: absolute;
689
+ inset: 0;
690
+ display: flex;
691
+ align-items: center;
692
+ justify-content: center;
693
+ }
694
+
695
+ .rte-mp-tile.is-skeleton {
696
+ cursor: default;
697
+ animation: rte-mp-pulse 1.2s ease-in-out infinite;
698
+ }
699
+
700
+ @keyframes rte-mp-pulse {
701
+ 50% { opacity: 0.55; }
702
+ }
703
+
704
+ .rte-mp-tile.is-uploading,
705
+ .rte-mp-tile.is-failed {
706
+ cursor: default;
707
+ }
708
+
709
+ .rte-mp-progress {
710
+ position: absolute;
711
+ left: 0;
712
+ right: 0;
713
+ bottom: 0;
714
+ height: 4px;
715
+ background: rgba(0, 0, 0, 0.35);
716
+ }
717
+
718
+ .rte-mp-progress > span {
719
+ display: block;
720
+ height: 100%;
721
+ width: 0;
722
+ background: var(--rte-media-accent);
723
+ transition: width 0.15s ease;
724
+ }
725
+
726
+ .rte-mp-tile-status {
727
+ position: absolute;
728
+ inset: 0;
729
+ display: flex;
730
+ flex-direction: column;
731
+ align-items: center;
732
+ justify-content: center;
733
+ gap: 6px;
734
+ padding: 8px;
735
+ background: rgba(0, 0, 0, 0.45);
736
+ color: #fff;
737
+ font-size: 12px;
738
+ text-align: center;
739
+ line-height: 1.3;
740
+ }
741
+
742
+ .rte-mp-tile.is-failed .rte-mp-tile-status {
743
+ background: rgba(120, 20, 28, 0.82);
744
+ }
745
+
746
+ .rte-mp-tile-actions {
747
+ position: absolute;
748
+ top: 6px;
749
+ right: 6px;
750
+ display: flex;
751
+ gap: 4px;
752
+ }
753
+
754
+ .rte-mp-icon-btn {
755
+ width: 26px;
756
+ height: 26px;
757
+ display: inline-flex;
758
+ align-items: center;
759
+ justify-content: center;
760
+ border: 0;
761
+ border-radius: 50%;
762
+ background: rgba(0, 0, 0, 0.62);
763
+ color: #fff;
764
+ cursor: pointer;
765
+ }
766
+
767
+ .rte-mp-icon-btn:hover {
768
+ background: rgba(0, 0, 0, 0.82);
769
+ }
770
+
771
+ .rte-mp-more {
772
+ display: block;
773
+ margin: 14px auto 0;
774
+ }
775
+
776
+ .rte-mp-empty,
777
+ .rte-mp-error {
778
+ display: flex;
779
+ flex-direction: column;
780
+ align-items: center;
781
+ justify-content: center;
782
+ gap: 8px;
783
+ min-height: 240px;
784
+ padding: 24px;
785
+ text-align: center;
786
+ color: var(--rte-media-muted);
787
+ }
788
+
789
+ .rte-mp-empty strong,
790
+ .rte-mp-error strong {
791
+ color: var(--rte-media-text);
792
+ font-size: 15px;
793
+ }
794
+
795
+ .rte-mp-error {
796
+ color: var(--rte-media-danger);
797
+ }
798
+
799
+ .rte-mp-dropzone {
800
+ display: flex;
801
+ flex-direction: column;
802
+ align-items: center;
803
+ justify-content: center;
804
+ gap: 4px;
805
+ padding: 28px 16px;
806
+ border: 2px dashed var(--rte-media-border);
807
+ border-radius: 14px;
808
+ background: var(--rte-media-surface);
809
+ color: var(--rte-media-muted);
810
+ text-align: center;
811
+ cursor: pointer;
812
+ transition: border-color 0.12s ease, background 0.12s ease;
813
+ }
814
+
815
+ .rte-mp-dropzone:hover,
816
+ .rte-mp-dropzone.is-dragover {
817
+ border-color: var(--rte-media-accent);
818
+ background: var(--rte-media-ring);
819
+ }
820
+
821
+ .rte-mp-dropzone:focus-visible {
822
+ outline: 2px solid var(--rte-media-accent);
823
+ outline-offset: 2px;
824
+ }
825
+
826
+ .rte-mp-dropzone strong {
827
+ color: var(--rte-media-text);
828
+ font-size: 15px;
829
+ }
830
+
831
+ .rte-mp-dropzone-icon {
832
+ color: var(--rte-media-accent);
833
+ margin-bottom: 4px;
834
+ }
835
+
836
+ .rte-mp-queue {
837
+ margin: 16px 0 0;
838
+ padding: 0;
839
+ list-style: none;
840
+ }
841
+
842
+ .rte-mp-drop-veil {
843
+ position: absolute;
844
+ inset: 0;
845
+ z-index: 5;
846
+ display: none;
847
+ align-items: center;
848
+ justify-content: center;
849
+ border-radius: inherit;
850
+ background: var(--rte-media-ring);
851
+ border: 3px dashed var(--rte-media-accent);
852
+ color: var(--rte-media-accent);
853
+ font-size: 18px;
854
+ font-weight: 600;
855
+ pointer-events: none;
856
+ }
857
+
858
+ .rte-mp.is-dropping .rte-mp-drop-veil {
859
+ display: flex;
860
+ }
861
+
862
+ .rte-mp-form {
863
+ display: flex;
864
+ flex-direction: column;
865
+ gap: 14px;
866
+ padding: 16px;
867
+ overflow: auto;
868
+ }
869
+
870
+ .rte-mp-details {
871
+ min-height: 0;
872
+ overflow: auto;
873
+ padding: 16px;
874
+ border-left: 1px solid var(--rte-media-border);
875
+ background: var(--rte-media-surface);
876
+ display: flex;
877
+ flex-direction: column;
878
+ gap: 12px;
879
+ }
880
+
881
+ .rte-mp-details[hidden] {
882
+ display: none;
883
+ }
884
+
885
+ .rte-mp-preview {
886
+ border-radius: 10px;
887
+ overflow: hidden;
888
+ background: var(--rte-media-surface-hover);
889
+ box-shadow: inset 0 0 0 1px var(--rte-media-border);
890
+ display: flex;
891
+ align-items: center;
892
+ justify-content: center;
893
+ min-height: 110px;
894
+ }
895
+
896
+ .rte-mp-preview img,
897
+ .rte-mp-preview video {
898
+ display: block;
899
+ max-width: 100%;
900
+ max-height: 200px;
901
+ }
902
+
903
+ .rte-mp-meta-name {
904
+ margin: 0;
905
+ font-size: 14px;
906
+ font-weight: 600;
907
+ color: var(--rte-media-text);
908
+ word-break: break-word;
909
+ }
910
+
911
+ .rte-mp-meta {
912
+ margin: 2px 0 0;
913
+ font-size: 12px;
914
+ color: var(--rte-media-muted);
915
+ }
916
+
917
+ .rte-mp-hint {
918
+ margin: 4px 0 0;
919
+ font-size: 12px;
920
+ color: var(--rte-media-muted);
921
+ }
922
+
923
+ .rte-mp-hint.is-warning {
924
+ color: var(--rte-media-danger-text);
925
+ }
926
+
927
+ .rte-mp-embed-status {
928
+ display: flex;
929
+ align-items: center;
930
+ gap: 8px;
931
+ margin: 0;
932
+ min-height: 22px;
933
+ font-size: 13px;
934
+ }
935
+
936
+ .rte-mp-embed-status.is-ok {
937
+ color: var(--rte-media-text);
938
+ }
939
+
940
+ .rte-mp-embed-status.is-ok svg {
941
+ color: var(--rte-media-accent);
942
+ }
943
+
944
+ .rte-mp-embed-status.is-error {
945
+ color: var(--rte-media-danger-text);
946
+ }
947
+
948
+ .rte-mp-suggest {
949
+ display: inline-flex;
950
+ align-items: center;
951
+ gap: 6px;
952
+ margin-left: auto;
953
+ padding: 2px 8px;
954
+ border: 1px solid var(--rte-media-border);
955
+ border-radius: 999px;
956
+ background: transparent;
957
+ color: var(--rte-media-text);
958
+ font-size: 12px;
959
+ cursor: pointer;
960
+ }
961
+
962
+ .rte-mp-suggest:hover {
963
+ background: var(--rte-media-surface-hover);
964
+ }
965
+
966
+ .rte-mp-suggest:disabled {
967
+ opacity: 0.6;
968
+ cursor: progress;
969
+ }
970
+
971
+ .rte-mp-suggest:focus-visible {
972
+ outline: 2px solid var(--rte-media-accent);
973
+ outline-offset: 2px;
974
+ }
975
+
976
+
977
+ .rte-mp-viewtools {
978
+ display: flex;
979
+ align-items: center;
980
+ gap: 8px;
981
+ margin-left: auto;
982
+ }
983
+
984
+ .rte-mp-viewtools[hidden] {
985
+ display: none;
986
+ }
987
+
988
+ .rte-mp-sort {
989
+ height: 34px;
990
+ padding: 0 8px 0 12px;
991
+ border: 1px solid var(--rte-media-border);
992
+ border-radius: 8px;
993
+ background: var(--rte-media-bg);
994
+ color: var(--rte-media-text);
995
+ font-size: 14px;
996
+ }
997
+
998
+ .rte-mp-sort:focus-visible,
999
+ .rte-mp-iconbtn:focus-visible {
1000
+ outline: 2px solid var(--rte-media-accent);
1001
+ outline-offset: 2px;
1002
+ }
1003
+
1004
+ .rte-mp-layout {
1005
+ display: flex;
1006
+ gap: 4px;
1007
+ }
1008
+
1009
+ .rte-mp-iconbtn {
1010
+ width: 34px;
1011
+ height: 34px;
1012
+ display: inline-flex;
1013
+ align-items: center;
1014
+ justify-content: center;
1015
+ border: 1px solid var(--rte-media-border);
1016
+ border-radius: 8px;
1017
+ background: transparent;
1018
+ color: var(--rte-media-muted);
1019
+ cursor: pointer;
1020
+ }
1021
+
1022
+ .rte-mp-iconbtn:hover {
1023
+ background: var(--rte-media-surface-hover);
1024
+ }
1025
+
1026
+ .rte-mp-iconbtn[aria-pressed="true"] {
1027
+ border-color: var(--rte-media-text);
1028
+ background: var(--rte-media-surface-hover);
1029
+ color: var(--rte-media-text);
1030
+ }
1031
+
1032
+ .rte-mp-tile-duration {
1033
+ position: absolute;
1034
+ right: 8px;
1035
+ bottom: 8px;
1036
+ z-index: 1;
1037
+ padding: 2px 6px;
1038
+ border-radius: 6px;
1039
+ background: rgba(0, 0, 0, 0.64);
1040
+ color: #fff;
1041
+ font-size: 11px;
1042
+ font-variant-numeric: tabular-nums;
1043
+ }
1044
+
1045
+ .rte-mp-tile.has-duration .rte-mp-tile-name {
1046
+ padding-right: 58px;
1047
+ }
1048
+
1049
+ .rte-mp-tile-meta {
1050
+ display: none;
1051
+ }
1052
+
1053
+ /* A file going up: an outline where it will land, the preview faded, and how far it has got. */
1054
+ .rte-mp-tile.is-uploading {
1055
+ background: var(--rte-media-surface);
1056
+ box-shadow: none;
1057
+ }
1058
+
1059
+ .rte-mp-tile.is-uploading::after {
1060
+ content: "";
1061
+ position: absolute;
1062
+ inset: 0;
1063
+ border: 1.5px dashed var(--rte-media-border);
1064
+ border-radius: inherit;
1065
+ pointer-events: none;
1066
+ }
1067
+
1068
+ .rte-mp-tile.is-uploading img,
1069
+ .rte-mp-tile.is-uploading video {
1070
+ opacity: 0.22;
1071
+ }
1072
+
1073
+ .rte-mp-tile.is-uploading .rte-mp-tile-status {
1074
+ background: transparent;
1075
+ color: var(--rte-media-text);
1076
+ font-weight: 600;
1077
+ }
1078
+
1079
+ .rte-mp-tile.is-uploading .rte-mp-progress {
1080
+ left: 12px;
1081
+ right: 12px;
1082
+ bottom: 12px;
1083
+ border-radius: 2px;
1084
+ background: var(--rte-media-border);
1085
+ }
1086
+
1087
+ .rte-mp-drop-hint {
1088
+ margin: 18px 0 0;
1089
+ text-align: center;
1090
+ font-size: 13px;
1091
+ color: var(--rte-media-muted);
1092
+ }
1093
+
1094
+ /* The list layout: a row for each file, with the picture small at the start. */
1095
+ .rte-mp-grid.is-list {
1096
+ grid-template-columns: minmax(0, 1fr);
1097
+ gap: 4px;
1098
+ }
1099
+
1100
+ .rte-mp-grid.is-list .rte-mp-tile {
1101
+ aspect-ratio: auto;
1102
+ height: 56px;
1103
+ display: flex;
1104
+ align-items: center;
1105
+ gap: 12px;
1106
+ padding-left: 68px;
1107
+ border-radius: 10px;
1108
+ background: transparent;
1109
+ box-shadow: none;
1110
+ color: var(--rte-media-text);
1111
+ }
1112
+
1113
+ .rte-mp-grid.is-list .rte-mp-tile:hover {
1114
+ background: var(--rte-media-surface-hover);
1115
+ box-shadow: none;
1116
+ }
1117
+
1118
+ .rte-mp-grid.is-list .rte-mp-tile[aria-selected="true"] {
1119
+ background: var(--rte-media-ring);
1120
+ box-shadow: inset 0 0 0 2px var(--rte-media-accent);
1121
+ }
1122
+
1123
+ .rte-mp-grid.is-list .rte-mp-tile img,
1124
+ .rte-mp-grid.is-list .rte-mp-tile video {
1125
+ right: auto;
1126
+ width: 56px;
1127
+ border-radius: 10px;
1128
+ }
1129
+
1130
+ .rte-mp-grid.is-list .rte-mp-tile-icon {
1131
+ right: auto;
1132
+ width: 56px;
1133
+ }
1134
+
1135
+ .rte-mp-grid.is-list .rte-mp-tile-name {
1136
+ position: static;
1137
+ flex: 1;
1138
+ min-width: 0;
1139
+ padding: 0 !important;
1140
+ background: none;
1141
+ color: var(--rte-media-text);
1142
+ font-size: 14px;
1143
+ opacity: 1;
1144
+ }
1145
+
1146
+ .rte-mp-grid.is-list .rte-mp-tile-meta {
1147
+ display: block;
1148
+ padding-right: 44px;
1149
+ font-size: 12px;
1150
+ color: var(--rte-media-muted);
1151
+ white-space: nowrap;
1152
+ }
1153
+
1154
+ .rte-mp-grid.is-list .rte-mp-tile-check {
1155
+ top: 50%;
1156
+ transform: translateY(-50%);
1157
+ }
1158
+
1159
+ .rte-mp-grid.is-list .rte-mp-tile-kind,
1160
+ .rte-mp-grid.is-list .rte-mp-tile-duration {
1161
+ display: none;
1162
+ }
1163
+
1164
+ .rte-mp-actions {
1165
+ display: flex;
1166
+ flex-wrap: wrap;
1167
+ gap: 8px;
1168
+ }
1169
+
1170
+ .rte-mp-actions .rte-mp-action {
1171
+ display: inline-flex;
1172
+ align-items: center;
1173
+ gap: 6px;
1174
+ margin: 0;
1175
+ padding: 6px 12px;
1176
+ border-radius: 8px;
1177
+ font-size: 13px;
1178
+ font-weight: 600;
1179
+ }
1180
+ .rte-mp-label-row {
1181
+ display: flex;
1182
+ align-items: center;
1183
+ gap: 8px;
1184
+ }
1185
+
1186
+ .rte-mp-footer {
1187
+ display: flex;
1188
+ align-items: center;
1189
+ gap: 10px;
1190
+ padding: 12px 16px;
1191
+ border-top: 1px solid var(--rte-media-border);
1192
+ }
1193
+
1194
+ .rte-mp-count {
1195
+ flex: 1;
1196
+ font-size: 13px;
1197
+ color: var(--rte-media-muted);
1198
+ }
1199
+
1200
+ .rte-mp-sr {
1201
+ position: absolute;
1202
+ width: 1px;
1203
+ height: 1px;
1204
+ overflow: hidden;
1205
+ clip: rect(0 0 0 0);
1206
+ white-space: nowrap;
1207
+ }
1208
+
1209
+ @media (max-width: 860px) {
1210
+ .rte-mp-body,
1211
+ .rte-mp.no-details .rte-mp-body {
1212
+ grid-template-columns: minmax(0, 1fr);
1213
+ grid-template-rows: auto minmax(0, 1fr) auto;
1214
+ }
1215
+
1216
+ .rte-mp-nav {
1217
+ flex-direction: row;
1218
+ padding: 8px;
1219
+ border-right: 0;
1220
+ border-bottom: 1px solid var(--rte-media-border);
1221
+ overflow-x: auto;
1222
+ }
1223
+
1224
+ .rte-mp-nav-item {
1225
+ width: auto;
1226
+ white-space: nowrap;
1227
+ }
1228
+
1229
+ .rte-mp-details {
1230
+ box-sizing: border-box;
1231
+ max-height: min(30vh, 220px);
1232
+ padding: 12px 16px;
1233
+ border-left: 0;
1234
+ border-top: 1px solid var(--rte-media-border);
1235
+ display: grid;
1236
+ grid-template-columns: 96px minmax(0, 1fr);
1237
+ align-items: start;
1238
+ gap: 10px 12px;
1239
+ }
1240
+
1241
+ .rte-mp-details[hidden] {
1242
+ display: none;
1243
+ }
1244
+
1245
+ .rte-mp-details > * {
1246
+ grid-column: 1 / -1;
1247
+ }
1248
+
1249
+ .rte-mp-details > .rte-mp-preview {
1250
+ grid-column: 1;
1251
+ min-height: 64px;
1252
+ }
1253
+
1254
+ .rte-mp-details > .rte-mp-preview + div {
1255
+ grid-column: 2;
1256
+ }
1257
+
1258
+ .rte-mp-details textarea {
1259
+ min-height: 0;
1260
+ height: 48px;
1261
+ }
1262
+
1263
+ .rte-mp-preview img,
1264
+ .rte-mp-preview video {
1265
+ max-height: 96px;
1266
+ }
1267
+ }
1268
+
1269
+ @media (max-width: 520px) {
1270
+ .rte-media-overlay {
1271
+ padding: 0;
1272
+ align-items: flex-end;
1273
+ }
1274
+
1275
+ .rte-media-dialog.rte-mp {
1276
+ width: 100vw;
1277
+ height: 94vh;
1278
+ border-radius: 16px 16px 0 0;
1279
+ }
1280
+
1281
+ .rte-mp-header {
1282
+ flex-wrap: wrap;
1283
+ }
1284
+
1285
+ .rte-mp-search {
1286
+ order: 3;
1287
+ flex-basis: 100%;
1288
+ max-width: none;
1289
+ }
1290
+
1291
+ .rte-mp-grid {
1292
+ grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
1293
+ }
1294
+ }
1295
+
1296
+ @media (prefers-reduced-motion: reduce) {
1297
+ .rte-mp-tile,
1298
+ .rte-mp-tile img.rte-mp-fade,
1299
+ .rte-mp-progress > span,
1300
+ .rte-mp-dropzone {
1301
+ transition: none;
1302
+ }
1303
+
1304
+ .rte-mp-tile.is-skeleton {
1305
+ animation: none;
1306
+ }
1307
+ }
1308
+
1309
+ .media-floating-toolbar {
1310
+ --rte-media-toolbar-bg: #ffffff;
1311
+ --rte-media-toolbar-border: #d6dbe4;
1312
+ --rte-media-toolbar-text: #344054;
1313
+ --rte-media-toolbar-hover-bg: #f3f6fb;
1314
+ --rte-media-toolbar-hover-text: #101828;
1315
+ --rte-media-toolbar-active-bg: #e6edf7;
1316
+ --rte-media-toolbar-separator: #d9e1eb;
1317
+ --rte-media-toolbar-danger-hover-bg: #fee2e2;
1318
+ --rte-media-toolbar-danger-hover-text: #b42318;
1319
+ position: fixed;
1320
+ display: none;
1321
+ align-items: center;
1322
+ gap: 2px;
1323
+ padding: 4px;
1324
+ border: 1px solid var(--rte-media-toolbar-border);
1325
+ border-radius: 8px;
1326
+ background: var(--rte-media-toolbar-bg);
1327
+ color: var(--rte-media-toolbar-text);
1328
+ box-shadow: 0 10px 24px rgba(15, 23, 36, 0.18);
1329
+ z-index: 10000;
1330
+ pointer-events: auto;
1331
+ backdrop-filter: blur(6px);
1332
+ }
1333
+
1334
+ .media-floating-toolbar.rte-ui-theme-dark,
1335
+ ${ai} .media-floating-toolbar {
1336
+ --rte-media-toolbar-bg: #24303f;
1337
+ --rte-media-toolbar-border: #4a5a71;
1338
+ --rte-media-toolbar-text: #d9e6fb;
1339
+ --rte-media-toolbar-hover-bg: #33445a;
1340
+ --rte-media-toolbar-hover-text: #f4f8ff;
1341
+ --rte-media-toolbar-active-bg: #415875;
1342
+ --rte-media-toolbar-separator: #566884;
1343
+ --rte-media-toolbar-danger-hover-bg: #5f2a32;
1344
+ --rte-media-toolbar-danger-hover-text: #ffd7d5;
1345
+ box-shadow: 0 16px 30px rgba(2, 8, 20, 0.42);
1346
+ }
1347
+
1348
+ .media-floating-toolbar-btn {
1349
+ width: 30px;
1350
+ height: 30px;
1351
+ border: none;
1352
+ border-radius: 6px;
1353
+ background: transparent;
1354
+ color: inherit;
1355
+ display: inline-flex;
1356
+ align-items: center;
1357
+ justify-content: center;
1358
+ cursor: pointer;
1359
+ transition: background-color 0.16s ease, color 0.16s ease, transform 0.12s ease;
1360
+ }
1361
+
1362
+ .media-floating-toolbar-btn:hover {
1363
+ background: var(--rte-media-toolbar-hover-bg);
1364
+ color: var(--rte-media-toolbar-hover-text);
1365
+ }
1366
+
1367
+ .media-floating-toolbar-btn:active {
1368
+ background: var(--rte-media-toolbar-active-bg);
1369
+ transform: scale(0.96);
1370
+ }
1371
+
1372
+ .media-floating-toolbar-btn.btn-remove:hover {
1373
+ background: var(--rte-media-toolbar-danger-hover-bg);
1374
+ color: var(--rte-media-toolbar-danger-hover-text);
1375
+ }
1376
+
1377
+ /* While editing, an embedded player does not take the mouse: a click on it selects its figure instead. */
1378
+ [contenteditable="true"] figure.rte-embed iframe {
1379
+ pointer-events: none;
1380
+ }
1381
+
1382
+ .media-resize-handle {
1383
+ position: fixed;
1384
+ width: 12px;
1385
+ height: 12px;
1386
+ margin: -6px 0 0 -6px;
1387
+ box-sizing: border-box;
1388
+ background: #1f6feb;
1389
+ border: 2px solid #fff;
1390
+ border-radius: 50%;
1391
+ z-index: 10001;
1392
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
1393
+ touch-action: none;
1394
+ }
1395
+
1396
+ /* A finger needs more to hold on to than a mouse does. */
1397
+ @media (pointer: coarse) {
1398
+ .media-resize-handle {
1399
+ width: 24px;
1400
+ height: 24px;
1401
+ margin: -12px 0 0 -12px;
1402
+ }
1403
+ }
1404
+
1405
+ .rte-mp-pending {
1406
+ position: fixed;
1407
+ z-index: 10000;
1408
+ display: none;
1409
+ flex-direction: column;
1410
+ align-items: center;
1411
+ justify-content: center;
1412
+ gap: 8px;
1413
+ box-sizing: border-box;
1414
+ border-radius: 8px;
1415
+ background-color: rgba(127, 127, 127, 0.22);
1416
+ background-size: cover;
1417
+ background-position: center;
1418
+ color: #fff;
1419
+ font: 13px/1.4 system-ui, sans-serif;
1420
+ overflow: hidden;
1421
+ }
1422
+
1423
+ .rte-mp-pending::before {
1424
+ content: "";
1425
+ position: absolute;
1426
+ inset: 0;
1427
+ background: rgba(0, 0, 0, 0.45);
1428
+ }
1429
+
1430
+ .rte-mp-pending > * {
1431
+ position: relative;
1432
+ }
1433
+
1434
+ .rte-mp-pending .rte-mp-icon-btn {
1435
+ position: absolute;
1436
+ top: 8px;
1437
+ right: 8px;
1438
+ }
1439
+
1440
+ .rte-mp-pending-bar {
1441
+ width: 60%;
1442
+ max-width: 220px;
1443
+ height: 4px;
1444
+ border-radius: 999px;
1445
+ background: rgba(255, 255, 255, 0.35);
1446
+ overflow: hidden;
1447
+ }
1448
+
1449
+ .rte-mp-pending-bar > span {
1450
+ display: block;
1451
+ width: 0;
1452
+ height: 100%;
1453
+ background: #fff;
1454
+ transition: width 0.15s ease;
1455
+ }
1456
+
1457
+ /* The picture the upload stands in for shows through the shade. */
1458
+ .rte-mp-pending-label {
1459
+ text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
1460
+ }
1461
+
1462
+ .media-resize-label {
1463
+ position: fixed;
1464
+ z-index: 10002;
1465
+ padding: 2px 8px;
1466
+ border-radius: 6px;
1467
+ background: rgba(15, 23, 36, 0.86);
1468
+ color: #fff;
1469
+ font: 12px/1.6 system-ui, sans-serif;
1470
+ pointer-events: none;
1471
+ }
1472
+
1473
+ .media-floating-toolbar-btn[aria-pressed="true"] {
1474
+ background: var(--rte-media-toolbar-active-bg);
1475
+ color: var(--rte-media-toolbar-hover-text);
1476
+ }
1477
+
1478
+ .media-floating-toolbar-btn:focus-visible,
1479
+ .media-size-menu-item:focus-visible {
1480
+ outline: 2px solid #1f6feb;
1481
+ outline-offset: 1px;
1482
+ }
1483
+
1484
+ .media-size-menu {
1485
+ position: absolute;
1486
+ top: calc(100% + 6px);
1487
+ left: 0;
1488
+ min-width: 150px;
1489
+ padding: 4px;
1490
+ display: flex;
1491
+ flex-direction: column;
1492
+ border: 1px solid var(--rte-media-toolbar-border);
1493
+ border-radius: 8px;
1494
+ background: var(--rte-media-toolbar-bg);
1495
+ box-shadow: 0 10px 24px rgba(15, 23, 36, 0.18);
1496
+ }
1497
+
1498
+ .media-size-menu-item {
1499
+ padding: 7px 10px;
1500
+ border: 0;
1501
+ border-radius: 6px;
1502
+ background: transparent;
1503
+ color: var(--rte-media-toolbar-text);
1504
+ font-size: 13px;
1505
+ text-align: left;
1506
+ cursor: pointer;
1507
+ }
1508
+
1509
+ .media-size-menu-item:hover {
1510
+ background: var(--rte-media-toolbar-hover-bg);
1511
+ color: var(--rte-media-toolbar-hover-text);
1512
+ }
1513
+
1514
+ .media-floating-toolbar-separator {
1515
+ width: 1px;
1516
+ height: 20px;
1517
+ margin: 0 2px;
1518
+ background: var(--rte-media-toolbar-separator);
1519
+ }
1520
+ `,document.head.appendChild(t)},Xe=(t,e)=>{const i=r=>{if(r.key!=="Escape"||!t.isConnected)return;const n=document.querySelectorAll(".rte-media-overlay");n.length>1&&n[n.length-1]!==t||(r.preventDefault(),r.stopPropagation(),e())};return document.addEventListener("keydown",i,!0),()=>{document.removeEventListener("keydown",i,!0)}},ur=()=>{const t=window.getSelection();if(!t||t.rangeCount===0)return null;const e=t.anchorNode;return(e instanceof HTMLElement?e:e?.parentElement)?.closest(".rte-content, .editora-content")||null},si=t=>{if(t)return t;const e=ur();if(e)return e;const i=document.activeElement;return i?i.closest(".rte-content, .editora-content")||i:null},li=t=>{const e=si(t);return e?!!e.closest(ai):!1},Ze=t=>{Ce();const e=document.createElement("div");return Vi.initDialogOverlay(e),e.className="rte-media-overlay",li(t)&&e.classList.add("rte-ui-theme-dark"),e},hr=(t,e)=>{t?.addEventListener("keydown",i=>{(i.key==="Enter"||i.key===" ")&&(i.preventDefault(),e?.click())})},Qe=(t=!1)=>{const e=document.createElement("div");return e.className=t?"rte-media-dialog rte-media-dialog-compact":"rte-media-dialog",e.setAttribute("role","dialog"),e.setAttribute("aria-modal","true"),e},bt=()=>({rotation:0,flipH:!1,flipV:!1,crop:null,maxWidth:null,format:"keep",quality:.85}),mr=t=>t.rotation===0&&!t.flipH&&!t.flipV&&t.crop===null&&t.maxWidth===null,Ct=(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=>{const e=Math.min(1,Math.max(0,t.width)),i=Math.min(1,Math.max(0,t.height));return{x:Math.min(1-e,X(t.x)),y:Math.min(1-i,X(t.y)),width:e,height:i}},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)},Pt=(t,e)=>({...t,rotation:(t.rotation+e*90+360)%360,crop:t.crop?gr(t.crop,e):null}),Ht=(t,e)=>{const r=t.rotation===90||t.rotation===270?e==="h"?"v":"h":e;return{...t,flipH:r==="h"?!t.flipH:t.flipH,flipV:r==="v"?!t.flipV:t.flipV,crop:t.crop?fr(t.crop,e):null}},di=(t,e,i)=>{if(!t)return{x:0,y:0,width:e,height:i};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)));return{x:r,y:n,width:Math.max(1,Math.min(e-r,Math.round(t.width*e))),height:Math.max(1,Math.min(i-n,Math.round(t.height*i)))}},ci=(t,e,i)=>{if(!i||t<=i)return{width:t,height:e};const r=i/t;return{width:i,height:Math.max(1,Math.round(e*r))}},br=(t,e,i,r)=>{const n=e/i,o=t>=n?1:t/n,a=t>=n?n/t:1,s=r?r.x+r.width/2:.5,l=r?r.y+r.height/2:.5;return Re({x:s-o/2,y:l-a/2,width:o,height:a})},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",pi=(t,e)=>`${(t||"image").replace(/\.[^./\\]+$/,"").replace(/-edited$/,"")||"image"}-edited.${xr(e)}`,vr=.04,Ot=(t,e,i)=>Re({...t,x:t.x+e,y:t.y+i}),Bt=(t,e,i,r,n=null,o=vr)=>{const a=e.includes("e"),s=e.includes("w"),l=e.includes("s"),c=e.includes("n");let d=t.x,u=t.x+t.width,h=t.y,b=t.y+t.height;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};const y=(a||s)&&(c||l);let x=u-d,v=b-h;if(y){x>=v*n?v=x/n:x=v*n;const C={w:a?1-d:u,h:l?1-h:b},N=Math.min(1,C.w/x,C.h/v);x*=N,v*=N;const O=Math.max(1,o/x,o/v);x*=O,v*=O;const Z=a?d:u-x,oe=l?h:b-v;return Re({x:Z,y:oe,width:x,height:v})}const E=t.x+t.width/2,R=t.y+t.height/2;if(c||l){x=v*n;const C={w:2*Math.min(E,1-E),h:l?1-h:b},N=Math.min(1,C.w/x,C.h/v);x*=N,v*=N;const O=Math.max(1,o/x,o/v);return x*=O,v*=O,Re({x:E-x/2,y:l?h:b-v,width:x,height:v})}v=x/n;const g={w:a?1-d:u,h:2*Math.min(R,1-R)},M=Math.min(1,g.w/x,g.h/v);x*=M,v*=M;const z=Math.max(1,o/x,o/v);return x*=z,v*=z,Re({x:a?d:u-x,y:R-v/2,width:x,height:v})},yr=(t,e,i)=>t*i/e,Je={createCanvas:(t,e)=>{const i=document.createElement("canvas");return i.width=t,i.height=e,i}};class Ae extends Error{constructor(e,i){super(i),this.code=e,this.name="ImageEditError"}}const wr=16e6,ui=t=>new Promise((e,i)=>{const r=new Image;!t.startsWith("data:")&&!t.startsWith("blob:")&&(r.crossOrigin="anonymous"),r.onload=()=>e(r),r.onerror=()=>i(new Ae(t.startsWith("data:")||t.startsWith("blob:")?"load":"cors",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.")),r.src=t}),hi=(t,e,i,r,n,o=Je)=>{const a=Ct(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");if(!l)throw new Ae("canvas","This browser can't edit images.");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},xt=(t,e,i,r,n,o=Je)=>{const a=Ct(e,i,r.rotation),s=di(r.crop,a.width,a.height),l=ci(s.width,s.height,r.maxWidth);if(l.width*l.height>wr)throw new Ae("too-large","This image is too large to edit in the browser. Resize it first.");const c=hi(t,e,i,r,1,o),d=o.createCanvas(l.width,l.height),u=d.getContext("2d");if(!u)throw new Ae("canvas","This browser can't edit images.");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},vt=(t,e,i)=>new Promise((r,n)=>{t.toBlob(o=>o?r(o):n(new Ae("encode","The picture couldn't be saved in this format.")),e,i)}),kr=t=>new Promise(e=>{if(typeof document>"u"||typeof URL>"u"||typeof URL.createObjectURL!="function")return e(void 0);const i=t.type.startsWith("video/")?"video":t.type.startsWith("audio/")?"audio":null;if(!i)return e(void 0);const r=document.createElement(i),n=URL.createObjectURL(t),o=s=>{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)},a=window.setTimeout(()=>o(),3e3);r.preload="metadata",r.onloadedmetadata=()=>o(r.duration),r.onerror=()=>o(),r.src=n}),mi=t=>{const e=Math.max(0,Math.round(t)),i=Math.floor(e/3600),r=Math.floor(e%3600/60),n=e%60;return i?`${i}:${String(r).padStart(2,"0")}:${String(n).padStart(2,"0")}`:`${r}:${String(n).padStart(2,"0")}`},gi=t=>{if(!t)return null;const e=t===!0?{}:t;return{maxWidth:e.maxWidth??2048,quality:e.quality??.85,format:e.format??"keep"}},fi=t=>t==="image/jpeg"||t==="image/png"||t==="image/webp",Er={...Je,load:async t=>{const e=URL.createObjectURL(t);try{const i=await ui(e);return{source:i,width:i.naturalWidth,height:i.naturalHeight}}finally{URL.revokeObjectURL(e)}}},Ar=async(t,e,i=Er)=>{if(!fi(t.type))return t;try{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;if(!l&&!c)return t;const d={...bt(),maxWidth:l?e.maxWidth:null,format:a,quality:e.quality},u=xt(r,n,o,d,t.type,i),h=await vt(u,s,e.quality);return h.type&&h.type!==s&&!c||!l&&h.size>=t.size?t:new File([h],pi(t.name,h.type||s).replace("-edited",""),{type:h.type||s})}catch{return t}},yt=t=>t>=1024*1024?`${Math.round(t/(1024*1024)*10)/10} MB`:`${Math.max(1,Math.round(t/1024))} KB`,Cr=t=>yt(t),bi=(t,e)=>{if(!e||e.length===0)return!0;const i=t.toLowerCase();return e.some(r=>{const n=r.toLowerCase();return n==="*/*"||n===i||n.endsWith("/*")&&i.startsWith(n.slice(0,-1))})},Lr=(t,e)=>{const r=(F(e).allowedTypes??[]).filter(n=>n.startsWith(`${t}/`)||n==="*/*");return r.length?r.join(","):`${t}/*`},xi=(t,e)=>{if(e.maxFileSize&&t.size>e.maxFileSize)throw new $("too-large",`${t.name||"This file"} is ${yt(t.size)}. The limit is ${yt(e.maxFileSize)}.`)},vi=(t,e)=>{if(e.allowedTypes&&!bi(t.type,e.allowedTypes))throw new $("type-not-allowed",`${t.name||"This file"} isn't a type that can be uploaded here.`);gi(e.optimizeImages)&&fi(t.type)||xi(t,e)},yi=async(t,e={})=>{const i=F(e.config);vi(t,i);const r=gi(i.optimizeImages),n=r?await Ar(t,r):t;xi(n,i);const o={signal:e.signal,onProgress:e.onProgress},a=kr(n),s=async l=>{if(l.duration===void 0){const c=await a;c!==void 0&&(l.duration=c)}return l};try{return await s(await oi(i).upload(n,o))}catch(l){if(Ye(l)||!i.fallbackToBase64)throw l;return s(await At().upload(n,o))}},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={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>'),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>'),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>'),search:D('<circle cx="11" cy="11" r="7"></circle><path d="m21 21-4.3-4.3"></path>'),close:D('<path d="M18 6 6 18"></path><path d="m6 6 12 12"></path>'),check:D('<path d="m5 12.5 4.5 4.5L19 7.5"></path>',14),play:D('<path d="M8 5.5v13l11-6.5z" fill="currentColor"></path>',16),trash:D('<path d="M3 6h18"></path><path d="M8 6V4h8v2"></path><path d="m6 6 1 14h10l1-14"></path>',16),alert:D('<circle cx="12" cy="12" r="9"></circle><path d="M12 8v5"></path><path d="M12 16.5v.01"></path>',20),retry:D('<path d="M3 12a9 9 0 1 0 3-6.7"></path><path d="M3 4v5h5"></path>',16),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),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),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>'),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>'),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),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),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),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),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),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)},Mr=["nw","n","ne","e","se","s","sw","w"],He=.01;class Sr{constructor(e,i){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=>{if(!this.rect||r.pointerType==="mouse"&&r.button!==0)return;const o=r.target.dataset.handle;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}},this.onPointerMove=r=>{const{drag:n}=this;if(!n)return;const o=this.element.getBoundingClientRect();if(!o.width||!o.height)return;const a=(r.clientX-n.x)/o.width,s=(r.clientY-n.y)/o.height;this.change(n.mode==="move"?Ot(n.start,a,s):Bt(n.start,n.mode,a,s,this.aspect))},this.onPointerUp=r=>{this.drag&&(this.drag=null,this.box.hasPointerCapture?.(r.pointerId)&&this.box.releasePointerCapture(r.pointerId),this.rect&&this.announce(this.describe(this.rect)))},this.onKeyDown=r=>{if(!this.rect||r.ctrlKey||r.metaKey||r.altKey)return;const o={ArrowLeft:[-He,0],ArrowRight:[He,0],ArrowUp:[0,-He],ArrowDown:[0,He]}[r.key];if(!o)return;r.preventDefault();const a=r.shiftKey?Bt(this.rect,"se",o[0],o[1],this.aspect):Ot(this.rect,o[0],o[1]);this.change(a),this.announce(this.describe(a))},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;for(const r of Mr){const n=document.createElement("div");n.className=`rte-ie-handle rte-ie-handle-${r}`,n.dataset.handle=r,n.setAttribute("aria-hidden","true"),this.box.append(n)}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)}get current(){return this.rect}setImageSize(e,i){this.imageWidth=e,this.imageHeight=i}setAspect(e){this.aspect=e===null?null:yr(e,this.imageWidth,this.imageHeight)}setRect(e){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}%`)}focus(){this.box.focus({preventScroll:!0})}change(e){this.setRect(e),this.onChange(e)}describe(e){const i=Math.round(e.width*this.imageWidth),r=Math.round(e.height*this.imageHeight);return`${i} by ${r} pixels, ${Math.round(e.x*this.imageWidth)} from the left, ${Math.round(e.y*this.imageHeight)} from the top`}dispose(){this.drag=null,this.element.remove()}}const Tr=()=>{if(typeof document>"u"||document.getElementById("rte-image-editor-styles"))return;const t=document.createElement("style");t.id="rte-image-editor-styles",t.textContent=`
1521
+ .rte-media-dialog.rte-ie {
1522
+ width: min(96vw, 980px);
1523
+ height: min(90vh, 700px);
1524
+ max-height: none;
1525
+ }
1526
+
1527
+ .rte-ie-body {
1528
+ flex: 1;
1529
+ min-height: 0;
1530
+ display: grid;
1531
+ grid-template-columns: minmax(0, 1fr) 300px;
1532
+ }
1533
+
1534
+ .rte-ie-stage {
1535
+ position: relative;
1536
+ min-width: 0;
1537
+ min-height: 0;
1538
+ display: flex;
1539
+ align-items: center;
1540
+ justify-content: center;
1541
+ padding: 16px;
1542
+ overflow: auto;
1543
+ background-color: var(--rte-media-surface-hover);
1544
+ background-image:
1545
+ linear-gradient(45deg, rgba(127, 127, 127, 0.16) 25%, transparent 25%, transparent 75%, rgba(127, 127, 127, 0.16) 75%),
1546
+ linear-gradient(45deg, rgba(127, 127, 127, 0.16) 25%, transparent 25%, transparent 75%, rgba(127, 127, 127, 0.16) 75%);
1547
+ background-size: 16px 16px;
1548
+ background-position: 0 0, 8px 8px;
1549
+ }
1550
+
1551
+ .rte-ie-canvas-wrap {
1552
+ position: relative;
1553
+ flex: none;
1554
+ line-height: 0;
1555
+ box-shadow: 0 2px 18px rgba(0, 0, 0, 0.3);
1556
+ }
1557
+
1558
+ .rte-ie-canvas-wrap canvas {
1559
+ display: block;
1560
+ }
1561
+
1562
+ .rte-ie-status {
1563
+ color: var(--rte-media-muted);
1564
+ font-size: 14px;
1565
+ text-align: center;
1566
+ max-width: 360px;
1567
+ }
1568
+
1569
+ .rte-ie-status.is-error {
1570
+ color: var(--rte-media-danger-text);
1571
+ }
1572
+
1573
+ .rte-ie-crop-layer {
1574
+ position: absolute;
1575
+ inset: 0;
1576
+ overflow: hidden;
1577
+ pointer-events: none;
1578
+ }
1579
+
1580
+ .rte-ie-crop-layer[hidden] {
1581
+ display: none;
1582
+ }
1583
+
1584
+ .rte-ie-crop {
1585
+ position: absolute;
1586
+ box-sizing: border-box;
1587
+ border: 2px solid #fff;
1588
+ /* The shade over what will be cut away. */
1589
+ box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.55);
1590
+ background-image:
1591
+ linear-gradient(rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.45)),
1592
+ linear-gradient(rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.45)),
1593
+ linear-gradient(90deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.45)),
1594
+ linear-gradient(90deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0.45));
1595
+ background-size: 100% 1px, 100% 1px, 1px 100%, 1px 100%;
1596
+ background-position: 0 33.33%, 0 66.66%, 33.33% 0, 66.66% 0;
1597
+ background-repeat: no-repeat;
1598
+ cursor: move;
1599
+ pointer-events: auto;
1600
+ touch-action: none;
1601
+ }
1602
+
1603
+ .rte-ie-crop:focus-visible {
1604
+ outline: 2px solid #1f6feb;
1605
+ outline-offset: 2px;
1606
+ }
1607
+
1608
+ .rte-ie-handle {
1609
+ position: absolute;
1610
+ width: 14px;
1611
+ height: 14px;
1612
+ box-sizing: border-box;
1613
+ background: #fff;
1614
+ border: 2px solid #1f6feb;
1615
+ border-radius: 50%;
1616
+ margin: -7px 0 0 -7px;
1617
+ }
1618
+
1619
+ @media (pointer: coarse) {
1620
+ .rte-ie-handle {
1621
+ width: 24px;
1622
+ height: 24px;
1623
+ margin: -12px 0 0 -12px;
1624
+ }
1625
+ }
1626
+
1627
+ .rte-ie-handle-nw { left: 0; top: 0; cursor: nwse-resize; }
1628
+ .rte-ie-handle-n { left: 50%; top: 0; cursor: ns-resize; }
1629
+ .rte-ie-handle-ne { left: 100%; top: 0; cursor: nesw-resize; }
1630
+ .rte-ie-handle-e { left: 100%; top: 50%; cursor: ew-resize; }
1631
+ .rte-ie-handle-se { left: 100%; top: 100%; cursor: nwse-resize; }
1632
+ .rte-ie-handle-s { left: 50%; top: 100%; cursor: ns-resize; }
1633
+ .rte-ie-handle-sw { left: 0; top: 100%; cursor: nesw-resize; }
1634
+ .rte-ie-handle-w { left: 0; top: 50%; cursor: ew-resize; }
1635
+
1636
+ .rte-ie-panel {
1637
+ min-height: 0;
1638
+ overflow: auto;
1639
+ padding: 14px 16px;
1640
+ border-left: 1px solid var(--rte-media-border);
1641
+ display: flex;
1642
+ flex-direction: column;
1643
+ gap: 18px;
1644
+ }
1645
+
1646
+ .rte-ie-section {
1647
+ border: 0;
1648
+ padding: 0;
1649
+ margin: 0;
1650
+ min-width: 0;
1651
+ }
1652
+
1653
+ .rte-ie-section > legend {
1654
+ padding: 0;
1655
+ margin-bottom: 8px;
1656
+ font-size: 12px;
1657
+ font-weight: 600;
1658
+ letter-spacing: 0.04em;
1659
+ text-transform: uppercase;
1660
+ color: var(--rte-media-muted);
1661
+ }
1662
+
1663
+ .rte-ie-grid {
1664
+ display: grid;
1665
+ grid-template-columns: 1fr 1fr;
1666
+ gap: 8px;
1667
+ }
1668
+
1669
+ .rte-ie-tool {
1670
+ display: flex;
1671
+ align-items: center;
1672
+ gap: 8px;
1673
+ padding: 8px 10px;
1674
+ border: 1px solid var(--rte-media-border);
1675
+ border-radius: 8px;
1676
+ background: transparent;
1677
+ color: var(--rte-media-text);
1678
+ font-size: 13px;
1679
+ cursor: pointer;
1680
+ }
1681
+
1682
+ .rte-ie-tool:hover {
1683
+ background: var(--rte-media-surface-hover);
1684
+ }
1685
+
1686
+ .rte-ie-tool[aria-pressed="true"] {
1687
+ background: var(--rte-media-text);
1688
+ border-color: var(--rte-media-text);
1689
+ color: var(--rte-media-bg);
1690
+ }
1691
+
1692
+ .rte-ie-tool:focus-visible,
1693
+ .rte-ie-select:focus-visible {
1694
+ outline: 2px solid var(--rte-media-accent);
1695
+ outline-offset: 2px;
1696
+ }
1697
+
1698
+ .rte-ie-tool:disabled {
1699
+ opacity: 0.5;
1700
+ cursor: not-allowed;
1701
+ }
1702
+
1703
+ .rte-ie-chips {
1704
+ display: flex;
1705
+ flex-wrap: wrap;
1706
+ gap: 6px;
1707
+ }
1708
+
1709
+ .rte-ie-chips .rte-ie-tool {
1710
+ padding: 4px 10px;
1711
+ border-radius: 999px;
1712
+ }
1713
+
1714
+ .rte-ie-row {
1715
+ display: flex;
1716
+ align-items: center;
1717
+ gap: 8px;
1718
+ margin-top: 8px;
1719
+ }
1720
+
1721
+ .rte-ie-row label {
1722
+ font-size: 13px;
1723
+ color: var(--rte-media-muted);
1724
+ flex: none;
1725
+ }
1726
+
1727
+ .rte-ie-row input[type="number"],
1728
+ .rte-ie-select {
1729
+ flex: 1;
1730
+ min-width: 0;
1731
+ height: 34px;
1732
+ padding: 0 8px;
1733
+ border: 1px solid var(--rte-media-border);
1734
+ border-radius: 8px;
1735
+ background: var(--rte-media-bg);
1736
+ color: var(--rte-media-text);
1737
+ font-size: 14px;
1738
+ }
1739
+
1740
+ .rte-ie-row input[type="range"] {
1741
+ flex: 1;
1742
+ accent-color: var(--rte-media-accent);
1743
+ }
1744
+
1745
+ .rte-ie-quality {
1746
+ min-width: 3ch;
1747
+ text-align: right;
1748
+ font-size: 13px;
1749
+ color: var(--rte-media-muted);
1750
+ }
1751
+
1752
+ .rte-ie-summary {
1753
+ margin: 0;
1754
+ padding: 10px 12px;
1755
+ border-radius: 8px;
1756
+ background: var(--rte-media-surface);
1757
+ font-size: 13px;
1758
+ line-height: 1.5;
1759
+ color: var(--rte-media-muted);
1760
+ }
1761
+
1762
+ .rte-ie-summary strong {
1763
+ color: var(--rte-media-text);
1764
+ }
1765
+
1766
+ .rte-ie-footer-error {
1767
+ flex: 1;
1768
+ margin: 0;
1769
+ font-size: 13px;
1770
+ color: var(--rte-media-danger-text);
1771
+ }
1772
+
1773
+ @media (max-width: 760px) {
1774
+ .rte-ie-body {
1775
+ grid-template-columns: minmax(0, 1fr);
1776
+ grid-template-rows: minmax(240px, 1.1fr) minmax(0, 1fr);
1777
+ }
1778
+
1779
+ .rte-ie-panel {
1780
+ border-left: 0;
1781
+ border-top: 1px solid var(--rte-media-border);
1782
+ }
1783
+ }
1784
+
1785
+ @media (max-width: 520px) {
1786
+ .rte-media-overlay {
1787
+ padding: 0;
1788
+ align-items: flex-end;
1789
+ }
1790
+
1791
+ .rte-media-dialog.rte-ie {
1792
+ width: 100vw;
1793
+ height: 96vh;
1794
+ border-radius: 16px 16px 0 0;
1795
+ }
1796
+ }
1797
+ `,document.head.appendChild(t)},zr={load:async t=>{const e=await ui(t);return{source:e,width:e.naturalWidth,height:e.naturalHeight}},canvas:Je},Ir=[{id:"none",label:"None",shape:{kind:"none"}},{id:"free",label:"Free",shape:{kind:"free"}},{id:"original",label:"Original",shape:{kind:"original"}},{id:"1:1",label:"1:1",shape:{kind:"ratio",id:"1:1",ratio:1}},{id:"4:3",label:"4:3",shape:{kind:"ratio",id:"4:3",ratio:4/3}},{id:"3:2",label:"3:2",shape:{kind:"ratio",id:"3:2",ratio:3/2}},{id:"16:9",label:"16:9",shape:{kind:"ratio",id:"16:9",ratio:16/9}}],$r=[null,2048,1600,1200,800],Rr=[["keep","Same as original"],["image/jpeg","JPEG"],["image/webp","WebP"],["image/png","PNG"]],Oe=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>`,Be={rotateLeft:Oe('<path d="M3 12a9 9 0 1 1 3 6.7"></path><path d="M3 5v7h7"></path>'),rotateRight:Oe('<path d="M21 12a9 9 0 1 0-3 6.7"></path><path d="M21 5v7h-7"></path>'),flipH:Oe('<path d="M12 3v18"></path><path d="M8 7 3 17h5z"></path><path d="m16 7 5 10h-5z"></path>'),flipV:Oe('<path d="M3 12h18"></path><path d="m7 8 10-5v5z"></path><path d="m7 16 10 5v-5z"></path>')},Dr={jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",webp:"image/webp",gif:"image/gif",avif:"image/avif"},Nr=(t,e)=>{const i=/^data:([^;,]+)/.exec(t);if(i)return i[1];const r=/\.([a-z0-9]+)(?:[?#]|$)/i.exec(t)?.[1]??/\.([a-z0-9]+)$/i.exec(e)?.[1];return Dr[r?.toLowerCase()??""]??"image/png"},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)=>{const r=document.createElement(t);return e&&(r.className=e),i!==void 0&&(r.textContent=i),r},wi=t=>{const e=t.deps??zr;F(t.config);const i=Nr(t.src,t.name);Ce(),Tr();let r=bt(),n={kind:"none"},o=null,a=!1,s=0,l;const c=new AbortController,d=Ze(t.contextElement),u=Qe();u.classList.add("rte-ie");const h=A("div","rte-media-header"),b=A("h2","rte-media-title","Edit Image"),y=A("button","close-btn rte-media-close-btn");y.type="button",y.setAttribute("aria-label","Close"),y.innerHTML=T.close,h.append(b,y);const x=A("div","rte-ie-stage"),v=A("p","rte-ie-status","Opening the image…");v.setAttribute("role","status");const E=A("div","rte-ie-canvas-wrap");E.hidden=!0;const R=A("div","rte-mp-sr");R.setAttribute("aria-live","polite");const g=new Sr(f=>{r={...r,crop:f},L()},f=>R.textContent=f);x.append(v,E,R);const M=A("div","rte-ie-panel"),z=f=>{const k=A("fieldset","rte-ie-section");return k.append(A("legend",void 0,f)),k},C=(f,k="")=>{const I=A("button","rte-ie-tool");return I.type="button",I.innerHTML=`${k}<span></span>`,I.querySelector("span").textContent=f,I},N=z("Orientation"),O=A("div","rte-ie-grid"),Z=C("Rotate left",Be.rotateLeft),oe=C("Rotate right",Be.rotateRight),Q=C("Flip horizontal",Be.flipH),P=C("Flip vertical",Be.flipV);O.append(Z,oe,Q,P),N.append(O);const Le=z("Crop"),J=A("div","rte-ie-chips");J.setAttribute("role","group"),J.setAttribute("aria-label","Crop shape");const ee=new Map;for(const f of Ir){const k=C(f.label);k.dataset.shape=f.id,k.addEventListener("click",()=>Ue(f.shape)),ee.set(f.id,k),J.append(k)}Le.append(J);const he=z("Size"),Me=A("div","rte-ie-row"),ae=A("label",void 0,"Max width");ae.htmlFor="ie-width";const H=A("input");H.type="number",H.id="ie-width",H.min="16",H.step="1",H.placeholder="Original",Me.append(ae,H,A("span","rte-ie-quality","px"));const me=A("div","rte-ie-chips");me.style.marginTop="8px";const fe=new Map;for(const f of $r){const k=C(f===null?"Original":String(f));k.addEventListener("click",()=>m(f)),fe.set(f,k),me.append(k)}he.append(Me,me);const Se=z("Save as"),be=A("div","rte-ie-row");be.style.marginTop="0";const Te=A("label",void 0,"Format");Te.htmlFor="ie-format";const K=A("select","rte-ie-select");K.id="ie-format";for(const[f,k]of Rr){const I=A("option",void 0,k);I.value=f,K.append(I)}be.append(Te,K);const se=A("div","rte-ie-row"),te=A("label",void 0,"Quality");te.htmlFor="ie-quality";const U=A("input");U.type="range",U.id="ie-quality",U.min="40",U.max="100",U.step="1",U.value=String(Math.round(r.quality*100));const ge=A("output","rte-ie-quality");ge.htmlFor="ie-quality",se.append(te,U,ge),Se.append(be,se);const q=A("p","rte-ie-summary");q.setAttribute("aria-live","polite"),M.append(N,Le,he,Se,q);const ie=A("div","rte-ie-body");ie.append(x,M);const Ne=A("div","rte-media-footer"),xe=A("button","rte-media-btn rte-media-btn-secondary","Restore original");xe.type="button",xe.hidden=!t.canRestore;const W=A("p","rte-ie-footer-error");W.setAttribute("role","alert"),W.hidden=!0;const re=A("button","cancel-btn rte-media-btn rte-media-btn-secondary","Cancel");re.type="button";const G=A("button","rte-media-btn rte-media-btn-primary","Apply");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);const ve=()=>!mr(r)||r.format!=="keep"||r.quality!==bt().quality,B=()=>o?Ct(o.width,o.height,r.rotation):{width:1,height:1},le=()=>n.kind==="ratio"?n.ratio:n.kind==="original"?B().width/B().height:null,ze=(f,k)=>({x:f.x+f.width*(1-k)/2,y:f.y+f.height*(1-k)/2,width:f.width*k,height:f.height*k});function Ue(f){if(n=f,f.kind==="none")r={...r,crop:null},g.setRect(null);else if(f.kind==="free")g.setAspect(null),r={...r,crop:r.crop??{x:.1,y:.1,width:.8,height:.8}},g.setRect(r.crop);else{const k=le();g.setAspect(k);const I=B();r={...r,crop:ze(br(k,I.width,I.height,r.crop??void 0),.9)},g.setRect(r.crop)}L()}function m(f){r={...r,maxWidth:f},H.value=f===null?"":String(f),L()}function w(f){const k=f.rotation!==r.rotation;r=f,n.kind==="ratio"&&k&&(n={...n,ratio:1/n.ratio}),g.setImageSize(B().width,B().height),g.setAspect(le()),g.setRect(r.crop),S(),L()}function S(){if(!o)return;const f=B(),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=hi(o.source,o.width,o.height,r,pe,e.canvas);E.replaceChildren(ye,g.element),g.setImageSize(f.width,f.height)}function L(){for(const[k,I]of ee){const pe=k==="original"?n.kind==="original":k==="none"?n.kind==="none":k==="free"?n.kind==="free":n.kind==="ratio"&&n.id===k;I.setAttribute("aria-pressed",String(pe))}for(const[k,I]of fe)I.setAttribute("aria-pressed",String(r.maxWidth===k));const f=ke(r.format,i);se.hidden=f==="image/png",ge.textContent=`${Math.round(r.quality*100)}`;for(const k of[Z,oe,Q,P,H,K,U,...ee.values(),...fe.values()])k.disabled=!o||a;G.disabled=!o||a||!ve(),G.textContent=a?"Saving…":"Apply",de()}function de(){if(!o)return;s++,clearTimeout(l);const f=di(r.crop,B().width,B().height),k=ci(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`;if(!ve()){q.innerHTML="",q.textContent=`${o.width} × ${o.height} px. Nothing changed yet.${I}`;return}q.innerHTML=`${pe}, working out the file size…`;const ye=s;l=setTimeout(async()=>{try{const we=xt(o.source,o.width,o.height,r,i,e.canvas),ji=await vt(we,ke(r.format,i),r.quality);if(ye!==s)return;q.innerHTML=`${pe}, about <strong>${Ur(ji.size)}</strong>.`,I&&q.append(I)}catch(we){if(ye!==s)return;q.textContent=we instanceof Error?we.message:"Couldn't prepare the picture."}},300)}function ce(){clearTimeout(l),s++,c.abort(),It(),g.dispose(),$t?.disconnect(),d.remove()}async function _i(){if(!(!o||a||!ve())){a=!0,W.hidden=!0,L();try{const f=xt(o.source,o.width,o.height,r,i,e.canvas),k=await vt(f,ke(r.format,i),r.quality),I=k.type||ke(r.format,i),pe=new File([k],pi(t.name,I),{type:I}),ye=await yi(pe,{config:t.config,signal:c.signal,onProgress:({fraction:we})=>G.textContent=`Saving… ${Math.round(we*100)}%`});ce(),t.onApply({item:ye,width:f.width,height:f.height})}catch(f){if(Ye(f))return;a=!1,W.textContent=f instanceof Error&&f.message?f.message:"Couldn't save the picture.",W.hidden=!1,L()}}}let It=()=>{};It=Xe(d,ce),y.addEventListener("click",ce),re.addEventListener("click",ce),d.addEventListener("click",f=>{f.target===d&&ce()}),G.addEventListener("click",()=>{_i()}),xe.addEventListener("click",()=>{ce(),t.onRestore?.()}),Z.addEventListener("click",()=>w(Pt(r,-1))),oe.addEventListener("click",()=>w(Pt(r,1))),Q.addEventListener("click",()=>w(Ht(r,"h"))),P.addEventListener("click",()=>w(Ht(r,"v"))),H.addEventListener("input",()=>{const f=parseInt(H.value,10);r={...r,maxWidth:Number.isFinite(f)&&f>0?f:null},L()}),K.addEventListener("change",()=>{r={...r,format:K.value},L()}),U.addEventListener("input",()=>{r={...r,quality:Number(U.value)/100},L()});const $t=typeof ResizeObserver>"u"?null:new ResizeObserver(()=>S());L(),e.load(t.src).then(f=>{d.isConnected&&(o=f,v.hidden=!0,E.hidden=!1,g.setImageSize(B().width,B().height),S(),$t?.observe(x),L(),q.textContent=`${f.width} × ${f.height} px. Nothing changed yet.`,Z.focus({preventScroll:!0}))}).catch(f=>{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="")})},ki=t=>typeof F(t).generateAltText=="function",Pr=t=>{const e=(typeof t=="string"?t:"").replace(/\s+/g," ").trim().replace(/^["'“”]+|["'“”]+$/g,"").trim();return e.length>500?`${e.slice(0,497).trimEnd()}…`:e},Ei=t=>{const e=F(t.config).generateAltText;let i=null;const r=document.createElement("button");r.type="button",r.className="rte-mp-suggest";const n=t.label??"Suggest";r.innerHTML=`${T.sparkle}<span></span>`,r.querySelector("span").textContent=n,r.setAttribute("aria-label","Suggest alt text");const o=document.createElement("p");o.className="rte-mp-hint",o.setAttribute("role","status"),o.hidden=!0;const a=(l,c=!1)=>{o.hidden=!l,o.textContent=l,o.classList.toggle("is-warning",c),o.setAttribute("role",c?"alert":"status")},s=r.querySelector("span");return r.addEventListener("click",async()=>{if(!e||i)return;i=new AbortController;const l=i;r.disabled=!0,s.textContent="Describing…",a("");try{const c=Pr(await e(t.image(),{signal:l.signal}));if(l.signal.aborted)return;if(!c)throw new Error("No description came back.");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.")}catch(c){if(l.signal.aborted)return;a(c instanceof Error&&c.message?c.message:"Couldn't suggest a description.",!0)}finally{i===l&&(i=null),r.disabled=!1,s.textContent=n}}),{button:r,status:o,abort:()=>i?.abort()}},p=(t,e)=>{const i=document.createElement(t);return e&&(i.className=e),i},Hr=t=>t.startsWith("data:")||t.startsWith("blob:")||t.includes("#")?t:`${t}#t=0.1`,Lt=(t,e)=>{const i=e??(t.type==="image"?t.thumbnailUrl||t.src:t.thumbnailUrl);if(i){const n=p("img");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}if(t.type==="video"){const n=p("video");return n.src=Hr(e??t.src),n.preload="metadata",n.muted=!0,n.setAttribute("playsinline",""),n.setAttribute("aria-hidden","true"),n}const r=p("span","rte-mp-tile-icon");return r.innerHTML=t.type==="audio"?T.audio:T.photo,r},Ai=(t="video")=>{const e=p("span","rte-mp-tile-kind");return e.innerHTML=t==="audio"?T.note:T.play,e},Ci=()=>{const t=p("span","rte-mp-tile-check");return t.innerHTML=T.check,t},Or=t=>{const e=p("span","rte-mp-tile-duration");return e.textContent=mi(t),e},Li=t=>{const e=p("span","rte-mp-tile-name");return e.textContent=t,e},Br=t=>{const e=p("div","rte-mp-tile");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(Lt(t)),(t.type==="video"||t.type==="audio")&&e.append(Ai(t.type)),(t.type==="video"||t.type==="audio")&&t.duration&&(e.classList.add("has-duration"),e.append(Or(t.duration))),e.append(Li(t.name),Fr(t),Ci()),e},Fr=t=>{const e=p("span","rte-mp-tile-meta"),i=t.mime.split("/")[1]?.toUpperCase()??t.type;return e.textContent=[i,Mi(t.size),t.duration?mi(t.duration):""].filter(Boolean).join(" · "),e},Mi=t=>t?t>=1024*1024?`${Math.round(t/(1024*1024)*10)/10} MB`:`${Math.max(1,Math.round(t/1024))} KB`:"";class qr{constructor(e,i){this.selection=e,this.options=i,this.element=p("aside","rte-mp-details"),this.alts=new Map,this.captions=new Map,this.shown=null,this.suggest=null,this.suggestButton=null,this.element.setAttribute("aria-label","Details"),this.element.hidden=!0}dispose(){this.suggest?.abort(),this.suggest=null}altFor(e){if(e.type!=="image")return;const i=this.alts.get(e.id);return i?i.decorative?"":i.text||void 0:e.alt||this.options.defaultAlt||void 0}captionFor(e){return this.options.captions===!1?void 0:(this.captions.get(e.id)??(typeof e.metadata?.caption=="string"?e.metadata.caption:"")).trim()||void 0}show(e){if(e&&this.shown?.id===e.id&&this.element.contains(document.activeElement))return;if(this.shown=e,this.suggest?.abort(),this.suggest=null,this.suggestButton=null,this.element.replaceChildren(),!e){this.element.hidden=!0;return}this.element.hidden=!1;const i=p("div","rte-mp-preview");i.append(this.previewMedia(e)),this.element.append(i);const r=p("div"),n=p("p","rte-mp-meta-name");n.textContent=e.name;const o=p("p","rte-mp-meta");if(this.element.append(r),r.append(n,o),this.fillMeta(o,e),this.selection.size>1){const a=p("p","rte-mp-hint");a.textContent=`${this.selection.size} items selected. Choose one of them to describe it.`,this.element.append(a)}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)){const a=p("button","rte-media-btn rte-media-btn-secondary");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)}}previewMedia(e){if(e.type==="audio"){const r=p("audio");return r.src=e.src,r.controls=!0,r.preload="none",r.style.width="100%",r}if(e.type==="video"){const r=p("video");return r.src=e.src,r.controls=!0,r.preload="metadata",r.setAttribute("playsinline",""),r}return Lt({...e,thumbnailUrl:e.src})}fillMeta(e,i){const r=(n,o)=>{const a=[n&&o?`${n} × ${o}`:"",Mi(i.size),i.mime.split("/")[1]?.toUpperCase()??""];e.textContent=a.filter(Boolean).join(" · ")};if(r(i.width,i.height),i.type==="image"&&!(i.width&&i.height)&&typeof Image<"u"){const n=new Image;n.onload=()=>{this.shown===i&&e.isConnected&&r(n.naturalWidth,n.naturalHeight)},n.src=i.src}}actions(e){const i=p("div","rte-mp-actions"),r=p("button","rte-media-btn rte-media-btn-secondary rte-mp-action");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);const n=this.suggestButton;return n&&i.append(n),i}captionField(e){const i=p("div","rte-media-field"),r=p("label","rte-media-label");r.htmlFor="detail-caption",r.textContent="Caption";const n=p("input","rte-media-input");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}altField(e){const i=this.alts.get(e.id)??{text:e.alt||this.options.defaultAlt||"",decorative:!1},r=p("div","rte-media-field"),n=p("div","rte-mp-label-row"),o=p("label","rte-media-label");o.htmlFor="detail-alt",o.textContent="Alt text",n.append(o);const a=p("textarea","rte-media-textarea");a.id="detail-alt",a.rows=3,a.placeholder="Describe the image",a.value=i.text,a.disabled=i.decorative;const s=p("p","rte-mp-hint"),l=p("label","rte-media-checkbox-label"),c=p("input");c.type="checkbox",c.id="detail-decorative",c.checked=i.decorative,l.append(c,document.createTextNode("This image is decorative"));const d=()=>{const h=!c.checked&&!a.value.trim();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."},u=()=>{this.alts.set(e.id,{text:a.value,decorative:c.checked}),a.disabled=c.checked,d()};if(a.addEventListener("input",u),c.addEventListener("change",u),d(),r.append(n,a,s,l),ki(this.options.config)){const h=Ei({config:this.options.config,image:()=>({src:e.src,name:e.name}),label:this.options.onEdit?"Alt":void 0,input:a,onFilled:()=>{c.checked=!1,u()}});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)}return r}}const Wr=new Set(["youtube.com","m.youtube.com","music.youtube.com","youtube-nocookie.com"]),_r=/^[\w-]{11}$/,jr=/^[\w-]{10,64}$/,Vr=t=>{if(!t)return null;if(/^\d+$/.test(t))return Number(t);const e=/^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s)?$/.exec(t);return!e||!(e[1]||e[2]||e[3])?null:Number(e[1]??0)*3600+Number(e[2]??0)*60+Number(e[3]??0)},Kr={id:"youtube",label:"YouTube video",parse(t){const e=t.hostname.replace(/^www\./,"").toLowerCase();let i=null,r;if(e==="youtu.be")i=t.pathname.split("/").filter(Boolean)[0]??null;else if(Wr.has(e)){const[o,a]=t.pathname.split("/").filter(Boolean);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")){const s=t.searchParams.get("list");return jr.test(s)?{src:`https://www.youtube-nocookie.com/embed/videoseries?list=${encodeURIComponent(s)}`,id:`list:${s}`}:null}}if(!i||!_r.test(i))return null;const n=Vr(t.searchParams.get("t")??t.searchParams.get("start"));return{src:`https://www.youtube-nocookie.com/embed/${i}${n?`?start=${n}`:""}`,id:i,aspectRatio:r}}},Gr={id:"vimeo",label:"Vimeo video",parse(t){const e=t.hostname.replace(/^www\./,"").toLowerCase();if(e!=="vimeo.com"&&e!=="player.vimeo.com")return null;const i=t.pathname.split("/").filter(Boolean),r=i.findIndex(s=>/^\d{5,12}$/.test(s));if(r===-1)return null;const n=i[r],o=i[r+1]??t.searchParams.get("h"),a=new URLSearchParams({dnt:"1"});return o&&/^[a-f0-9]{6,20}$/i.test(o)&&a.set("h",o),{src:`https://player.vimeo.com/video/${n}?${a}`,id:n}}},Yr=[Kr,Gr],Xr=t=>/<iframe\b[^>]*?\bsrc\s*=\s*["']([^"']+)["']/i.exec(t)?.[1]??null,Si=(t,e=[])=>{const i=(Xr(t)??t).trim();if(!i||/\s/.test(i))return null;let r;try{r=new URL(/^[a-z][a-z0-9+.-]*:/i.test(i)?i:`https://${i}`)}catch{return null}if(r.protocol!=="https:"&&r.protocol!=="http:")return null;for(const n of[...e,...Yr]){const o=n.parse(r);if(o)return/^https:\/\/[^\s]+$/.test(o.src)?{provider:n.id,label:n.label,src:o.src,id:o.id,aspectRatio:o.aspectRatio??16/9}:null}return null};class Zr{constructor(e,i,r){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;const n=p("div","rte-mp-form"),o=(s,l,c,d)=>{const u=p("div","rte-media-field"),h=p("label","rte-media-label");return h.htmlFor=c,h.textContent=s,l.id=c,Object.assign(l,d),u.append(h,l),u},a=p("p","rte-mp-hint");a.textContent="Paste a link to a YouTube or Vimeo video, or the embed code the site gives you.",n.append(a,o("Video link",this.urlInput,"embed-url",{type:"text",placeholder:"https://www.youtube.com/watch?v=…"}),o("Title (for screen readers)",this.titleInput,"embed-title",{type:"text",placeholder:"What the video is about"})),this.status.setAttribute("role","status"),n.append(this.status),this.element.append(n),this.renderStatus(),this.urlInput.addEventListener("input",()=>{this.parsed=Si(this.urlInput.value,this.providers),this.renderStatus(),this.onChange()}),this.urlInput.addEventListener("keydown",s=>{s.key==="Enter"&&this.parsed&&(s.preventDefault(),this.onSubmit())})}get spec(){return this.parsed}get title(){return this.titleInput.value.trim()}focus(){this.urlInput.focus({preventScroll:!0})}renderStatus(){const e=this.urlInput.value.trim();if(this.status.className="rte-mp-embed-status",this.status.replaceChildren(),!!e)if(this.parsed){this.status.classList.add("is-ok"),this.status.innerHTML=`<span aria-hidden="true">${T.embed}</span>`;const i=p("span");i.textContent=`${this.parsed.label} found. It loads when you insert it.`,this.status.append(i)}else 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."}}const Qr={image:{one:"image",many:"images"},video:{one:"video",many:"videos"},audio:{one:"audio file",many:"audio files"}},qe=(t,e=!1)=>t.length===1?Qr[t[0]][e?"many":"one"]:e?"items":"item",Ft=(t,e)=>(t.type==="image"||t.type==="video"||t.type==="audio")&&e.includes(t.type),Ti=(t,e="li")=>{const i=p(e,"rte-mp-tile");i.dataset.upload=t.id;const r=t.file.type.startsWith("video/")?"video":t.file.type.startsWith("audio/")?"audio":"image";return i.append(Lt({type:r,src:"",thumbnailUrl:void 0},t.previewUrl)),(r==="video"||r==="audio")&&i.append(Ai(r)),i},zi=(t,e,i)=>{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());const r=o=>{const a=p("div","rte-mp-tile-status"),s=p("span");return s.textContent=o,a.append(s),a},n=(o,a,s)=>{const l=p("button","rte-mp-icon-btn");return l.type="button",l.setAttribute("aria-label",`${o} ${e.file.name}`),l.innerHTML=a,l.addEventListener("click",s),l};if(e.status==="queued"||e.status==="uploading"){const o=Math.round(e.fraction*100),a=r(e.status==="queued"?"Waiting…":`Uploading ${o}%`);a.setAttribute("role","status");const s=p("div","rte-mp-progress");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));const l=p("span");l.style.width=`${o}%`,s.append(l);const c=p("div","rte-mp-tile-actions");return c.append(n("Cancel upload of",T.close,()=>i.remove(e.id))),t.append(a,s,c),!0}if(e.status==="error"){const o=r(e.error??"Couldn't upload this file.");o.setAttribute("role","alert");const a=p("div","rte-mp-tile-actions");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}return!1},Jr=24,en=300,qt=[{id:"all",label:"All"},{id:"image",label:"Images"},{id:"video",label:"Video"},{id:"audio",label:"Audio"}];class Wt{constructor(e,i,r={}){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=new Map,this.toolbar=p("div","rte-mp-toolbar"),this.lastClicked=null,this.onKeyDown=n=>{const o=n.target.closest(".rte-mp-tile[data-id]");if(!o)return;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=>{const b=a[Math.min(Math.max(h,0),a.length-1)];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))};switch(n.key){case"ArrowRight":n.preventDefault(),u(s+1);break;case"ArrowLeft":n.preventDefault(),u(s-1);break;case"ArrowDown":n.preventDefault(),u(s+l);break;case"ArrowUp":n.preventDefault(),u(s-l);break;case"Home":n.preventDefault(),u(n.ctrlKey?0:s-s%l);break;case"End":n.preventDefault(),u(n.ctrlKey?a.length-1:s-s%l+l-1);break;case" ":n.preventDefault(),d.toggle(c),this.lastClicked=c.id,this.ctx.setActive(d.has(c.id)?c:d.items.at(-1)??null);break;case"Enter":n.preventDefault(),this.ctx.commit(d.size?void 0:[c]);break;case"a":case"A":(n.metaKey||n.ctrlKey)&&(n.preventDefault(),d.all(this.items),this.ctx.setActive(c));break}},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){this.toolbar.setAttribute("role","group"),this.toolbar.setAttribute("aria-label","Show");for(const{id:n,label:o}of qt){const a=p("button","rte-mp-chip");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)}this.element.append(this.toolbar)}this.element.append(this.scroll),this.content.addEventListener("keydown",this.onKeyDown)}activate(){(!this.loaded||this.stale)&&this.reload()}markStale(){this.stale=!0}get kinds(){return this.options.kinds?this.options.kinds:this.filter==="all"?this.ctx.allowedKinds:[this.filter]}setFilter(e){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())}setSort(e){e!==this.sort&&(this.sort=e,this.reload())}setLayout(e){this.layout=e,this.content.querySelector(".rte-mp-grid")?.classList.toggle("is-list",e==="list")}addUploaded(e){if(this.loaded){if(this.sort!=="newest"||this.search||!Ft(e,this.kinds)){this.stale=!0,this.element.hidden||this.reload();return}this.items.some(i=>i.id===e.id)||(this.items.unshift(e),this.total+=1,this.render())}}syncPending(){const e=this.options.queue?.(),i=(e?.entries??[]).filter(n=>n.status!=="done"&&!n.item),r=this.content.querySelector(".rte-mp-grid");if(e){if(!r&&i.length){this.render();return}for(const[n,o]of this.pending)i.some(a=>a.id===n)||(o.remove(),this.pending.delete(n));r&&(i.forEach((n,o)=>{let a=this.pending.get(n.id);a||(a=Ti(n,"div"),a.setAttribute("role","group"),a.setAttribute("aria-label",n.file.name),this.pending.set(n.id,a)),zi(a,n,e),r.children[o]!==a&&r.insertBefore(a,r.children[o]??null)}),i.length===0&&this.items.length===0&&this.loaded&&!this.loading&&this.render())}}setSearch(e){clearTimeout(this.searchTimer),this.searchTimer=setTimeout(()=>{e!==this.search&&(this.search=e,this.reload())},en)}dispose(){clearTimeout(this.searchTimer),this.controller?.abort(),this.observer?.disconnect()}syncSelection(){this.content.querySelectorAll(".rte-mp-tile[data-id]").forEach(e=>{e.setAttribute("aria-selected",String(this.ctx.selection.has(e.dataset.id)))})}focusGrid(){const e=this.tiles()[0];this.tiles().forEach(r=>r.tabIndex=-1);const i=this.content.querySelector('.rte-mp-tile[aria-selected="true"]')??e;i&&(i.tabIndex=0,i.focus({preventScroll:!0}))}async deleteItem(e){const{provider:i}=this.ctx;if(!i.delete||!await kt.confirmAction(`Delete ${e.name} from the library? Documents that use it will lose the picture.`,{title:"Delete from library",confirmText:"Delete",danger:!0,context:this.element}))return!1;try{await i.delete(e.id)}catch(n){return this.ctx.announce(n instanceof Error?n.message:"Couldn't delete the file."),!1}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}async reload(){this.controller?.abort(),this.items=[],this.total=0,this.page=0,this.failed=null,this.stale=!1,await this.loadPage()}async loadPage(){const e=this.options.source??this.ctx.provider;if(!e.list)return;const i=new AbortController;this.controller=i,this.loading=!0,this.render();try{const r=await e.list({page:this.page+1,limit:Jr,search:this.search||void 0,type:this.kinds.length===1?this.kinds[0]:void 0,sort:this.options.sortable===!1||this.sort==="newest"?void 0:this.sort},{signal:i.signal});if(i!==this.controller)return;this.page+=1,this.total=r.total;const n=new Set(this.items.map(o=>o.id));this.items.push(...r.items.filter(o=>Ft(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")}catch(r){if(i!==this.controller||Ye(r))return;this.failed=r instanceof Error&&r.message?r.message:"Couldn't load your media.",this.loaded=!0}finally{i===this.controller&&(this.loading=!1,this.render())}}tiles(){return[...this.content.querySelectorAll(".rte-mp-tile[data-id]")]}render(){this.observer?.disconnect();const e=document.activeElement instanceof HTMLElement?document.activeElement.dataset.id:void 0;this.focusId=e&&this.content.contains(document.activeElement)?e:null,this.content.replaceChildren(),this.pending.clear();const i=(this.options.queue?.()?.entries??[]).some(s=>s.status!=="done"&&!s.item),r=this.items.length>0||i;if(this.failed&&!r){this.content.append(this.errorBlock(this.failed));return}if(!r&&this.loading){const s=p("div","rte-mp-grid");s.setAttribute("aria-busy","true");for(let l=0;l<12;l++)s.append(p("div","rte-mp-tile is-skeleton"));this.content.append(s);return}if(!r){this.content.append(this.emptyBlock());return}const n=p("div","rte-mp-grid");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");for(const s of this.items){const l=Br(s);l.addEventListener("click",c=>this.onTileClick(c,s)),l.addEventListener("dblclick",()=>this.ctx.commit([s])),n.append(l)}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){const s=p("p","rte-mp-drop-hint");s.textContent="Drop files anywhere in this window to upload",this.content.append(s)}const o=this.tiles(),a=o.find(s=>s.dataset.id===this.focusId)??o.find(s=>s.getAttribute("aria-selected")==="true")??o[0];a&&(a.tabIndex=0),this.focusId&&a&&a.focus({preventScroll:!0}),this.syncSelection()}moreButton(){const e=p("button","rte-media-btn rte-media-btn-secondary rte-mp-more");return e.type="button",e.textContent=this.loading?"Loading…":"Load more",e.addEventListener("click",()=>{this.loadPage()}),!this.loading&&typeof IntersectionObserver<"u"&&(this.observer=new IntersectionObserver(i=>{i.some(r=>r.isIntersecting)&&!this.loading&&this.loadPage()},{root:this.scroll,rootMargin:"200px"}),this.observer.observe(e)),e}emptyBlock(){const e=p("div","rte-mp-empty"),i=!!this.search;e.innerHTML=`<span aria-hidden="true">${T.photo}</span>`;const r=p("strong"),n=qt.find(a=>a.id===this.filter)?.label.toLowerCase();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");const o=p("span");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){const a=p("button","rte-media-btn rte-media-btn-primary");a.type="button",a.textContent="Upload files",a.addEventListener("click",this.onUpload),e.append(a)}return e}errorBlock(e,i=!1){const r=p("div","rte-mp-error");r.setAttribute("role","alert"),i&&(r.style.minHeight="0"),r.innerHTML=`<span aria-hidden="true">${T.alert}</span>`;const n=p("strong");n.textContent=e;const o=p("button","rte-media-btn rte-media-btn-secondary");return o.type="button",o.textContent="Try again",o.addEventListener("click",()=>{this.items.length?this.loadPage():this.reload()}),r.append(n,o),r}onTileClick(e,i){const{selection:r}=this.ctx;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)}columns(e){if(e.length<2)return 1;const i=e[0].offsetTop,r=e.findIndex(n=>n.offsetTop!==i);return r===-1?e.length:Math.max(r,1)}}class tn{constructor(e,i=()=>{}){this.multiple=e,this.onChange=i,this.chosen=new Map}get items(){return[...this.chosen.values()]}get size(){return this.chosen.size}has(e){return this.chosen.has(e)}only(e){this.chosen=new Map([[e.id,e]]),this.onChange()}toggle(e){if(!this.multiple){this.only(e);return}this.chosen.has(e.id)?this.chosen.delete(e.id):this.chosen.set(e.id,e),this.onChange()}range(e,i,r){if(!this.multiple)return;const n=e.findIndex(a=>a.id===i),o=e.findIndex(a=>a.id===r);if(!(n===-1||o===-1)){for(const a of e.slice(Math.min(n,o),Math.max(n,o)+1))this.chosen.set(a.id,a);this.onChange()}}all(e){this.multiple&&(e.forEach(i=>this.chosen.set(i.id,i)),this.onChange())}remove(e){this.chosen.delete(e)&&this.onChange()}clear(){this.chosen.size!==0&&(this.chosen.clear(),this.onChange())}}const rn=(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,nn=(t,e)=>({id:`stock-${e.id}`,name:e.description?.trim()||e.author||`Photo ${e.id}`,type:"image",src:e.url,thumbnailUrl:e.thumbnailUrl,size:0,width:e.width,height:e.height,mime:"image/jpeg",createdAt:0,alt:e.description?.trim()||void 0,metadata:{stock:!0,caption:rn(t,e),sourceUrl:e.sourceUrl,author:e.author}}),on=t=>({async list(e={},i={}){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=>nn(t,l)),s=(r-1)*n+a.length;return{items:a,total:o.total??s+(a.length>=n?1:0)}}});let an=0;const sn=t=>{if(!(typeof URL>"u"||typeof URL.createObjectURL!="function")&&/^(image|video)\//.test(t.type))try{return URL.createObjectURL(t)}catch{return}};class Ii{constructor(e){this.options=e,this.list=[],this.controllers=new Map}get entries(){return this.list}get active(){return this.list.filter(e=>e.status==="queued"||e.status==="uploading").length}add(e){const i=[...e].map(r=>({id:`upload-${++an}`,file:r,status:"queued",fraction:0,previewUrl:sn(r)}));return this.list.push(...i),this.options.onChange(),this.pump(),i}retry(e){const i=this.find(e);!i||i.status!=="error"||(i.status="queued",i.error=void 0,i.fraction=0,this.options.onChange(),this.pump())}remove(e){const i=this.list.findIndex(n=>n.id===e);if(i===-1)return;const[r]=this.list.splice(i,1);this.controllers.get(e)?.abort(),this.controllers.delete(e),r.previewUrl&&URL.revokeObjectURL?.(r.previewUrl),this.options.onChange(),this.pump()}dispose(){this.controllers.forEach(e=>e.abort()),this.controllers.clear(),this.list.forEach(e=>e.previewUrl&&URL.revokeObjectURL?.(e.previewUrl)),this.list.length=0}find(e){return this.list.find(i=>i.id===e)}pump(){const e=this.options.concurrency??3;let i=this.list.filter(r=>r.status==="uploading").length;for(const r of this.list){if(i>=e)break;r.status==="queued"&&(i++,this.run(r))}}async run(e){const i=new AbortController;this.controllers.set(e.id,i),e.status="uploading",e.fraction=0,this.options.onChange();try{const r=await yi(e.file,{config:this.options.config,signal:i.signal,onProgress:({fraction:n})=>{e.fraction=n,this.options.onChange()}});if(!this.list.includes(e))return;e.status="done",e.fraction=1,e.item=r}catch(r){if(!this.list.includes(e)||Ye(r))return;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"))}finally{this.controllers.delete(e.id),this.list.includes(e)&&this.options.onChange(),this.pump()}}}class ln{constructor(e,i,r=()=>{}){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=new Map,this.selectedOnce=new Set,this.queue=new Ii({config:e.config,onChange:()=>{this.sync(),this.onQueueChange()}}),this.element.setAttribute("role","tabpanel"),this.element.id="rte-mp-panel-upload",this.element.hidden=!0;const n=F(e.config).maxFileSize,o=e.allowedKinds,a=o.length===1?qe(o):"file",s=n?` Max file size: ${Cr(n)}`:"";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=`
1798
+ <span class="rte-mp-dropzone-icon" aria-hidden="true">${T.upload.replace('width="18" height="18"','width="30" height="30"')}</span>
1799
+ <strong>Drag and drop your ${e.selection.multiple?o.length===1?qe(o,!0):"files":a} here</strong>
1800
+ <span>or click to browse</span>
1801
+ ${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=>{c.preventDefault(),this.dropzone.classList.add("is-dragover")}),this.dropzone.addEventListener("dragleave",()=>this.dropzone.classList.remove("is-dragover")),this.dropzone.addEventListener("drop",()=>this.dropzone.classList.remove("is-dragover")),this.input.addEventListener("change",()=>{this.input.files?.length&&this.add([...this.input.files]),this.input.value=""}),this.list.setAttribute("role","list"),this.list.setAttribute("aria-label","Uploads"),this.list.hidden=!0;const l=p("div","rte-mp-scroll");l.append(this.dropzone,this.input,this.list),this.element.append(l)}add(e){const i=this.ctx.selection.multiple?e:e.slice(0,1);i.length&&this.queue.add(i)}focusDropzone(){this.dropzone.focus({preventScroll:!0})}syncSelection(){this.tiles.forEach((e,i)=>{const r=this.queue.entries.find(o=>o.id===i),n=!!(r?.item&&this.ctx.selection.has(r.item.id));e.classList.toggle("is-selected",n),e.querySelector(".rte-mp-tile-pick")?.setAttribute("aria-pressed",String(n))})}dispose(){this.queue.dispose()}sync(){const e=this.queue.entries;this.list.hidden=e.length===0;for(const[i,r]of this.tiles)e.some(n=>n.id===i)||(r.remove(),this.tiles.delete(i));e.forEach((i,r)=>{let n=this.tiles.get(i.id);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)}),this.syncSelection()}createTile(e){return Ti(e)}update(e,i){if(!zi(e,i,this.queue)&&i.item){const r=i.item,n=p("button","rte-mp-tile-pick");n.type="button",n.setAttribute("aria-label",r.name),n.setAttribute("aria-pressed","false"),n.addEventListener("click",()=>{this.ctx.selection.toggle(r),this.ctx.setActive(this.ctx.selection.has(r.id)?r:this.ctx.selection.items.at(-1)??null)}),n.addEventListener("dblclick",()=>this.ctx.commit([r])),e.append(Li(r.name),Ci(),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`))}}}const dn=/\.(mp4|webm|ogv|ogg|mov|m4v)(\?|#|$)/i,cn=/\.(mp3|wav|m4a|aac|oga|opus|flac)(\?|#|$)/i,_t=(t,e)=>cn.test(t)||t.startsWith("data:audio/")?"audio":dn.test(t)?"video":/\.(jpe?g|png|gif|webp|avif|svg|bmp)(\?|#|$)/i.test(t)||t.startsWith("data:image/")?"image":e;class pn{constructor(e,i,r,n,o,a=e[0]??"image"){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;const s=p("div","rte-mp-form"),l=a==="audio"?"clip":a,c=(h,b,y,x={})=>{const v=p("div","rte-media-field"),E=p("label","rte-media-label");return E.htmlFor=y,E.textContent=h,b.id=y,Object.assign(b,x),v.append(E,b),v},d=a==="video"?"mp4":a==="audio"?"mp3":"jpg";s.append(c("URL",this.urlInput,"url-input",{type:"text",placeholder:`https://example.com/${l}.${d}`,value:i}),...e.includes("image")?[c("Alt Text (for accessibility)",this.altInput,"alt-input",{type:"text",placeholder:"Describe the image",value:r??""})]:[]);const u=p("div","rte-media-grid");u.append(c("Width (px)",this.widthInput,"width-input",{type:"number",placeholder:"Auto"}),c("Height (px)",this.heightInput,"height-input",{type:"number",placeholder:"Auto"})),s.append(u,this.previewBox),this.previewBox.hidden=!0,this.element.append(s),this.urlInput.addEventListener("input",()=>{this.onChange(),clearTimeout(this.previewTimer),this.previewTimer=setTimeout(()=>this.renderPreview(),400)}),this.urlInput.addEventListener("keydown",h=>{h.key==="Enter"&&this.url&&(h.preventDefault(),this.onSubmit())}),i&&this.renderPreview()}get url(){return this.urlInput.value.trim()}focus(){this.urlInput.focus({preventScroll:!0})}spec(){if(!this.url)return null;const e=_t(this.url,this.preferred);return{src:this.url,type:e,alt:e==="image"&&this.altInput.value?this.altInput.value:void 0,width:this.widthInput.value||void 0,height:this.heightInput.value||void 0}}dispose(){clearTimeout(this.previewTimer)}renderPreview(){const e=this.url;if(!e){this.previewBox.hidden=!0,this.previewBox.replaceChildren();return}const i=this.previewBox.querySelector("img, video, audio"),r=_t(e,this.preferred),n=r==="image"?"img":r==="video"?"video":"audio";if(i&&i.tagName.toLowerCase()===n)i.setAttribute("src",e);else{const o=p("span","rte-media-label");o.textContent="Preview";const a=p("div","rte-media-preview"),s=p(r==="image"?"img":r==="video"?"video":"audio");s.setAttribute("src",e),s instanceof HTMLImageElement?s.alt="Preview":s.controls=!0,a.append(s),this.previewBox.replaceChildren(o,a)}this.previewBox.hidden=!1}}const lt={library:{label:"Library",icon:T.library,className:"tab-library"},stock:{label:"Stock photos",icon:T.stock,className:"tab-stock"},upload:{label:"Upload",icon:T.upload,className:"tab-upload"},url:{label:"From URL",icon:T.link,className:"tab-url"},embed:{label:"Embed",icon:T.embed,className:"tab-embed"}},$i=["image","video","audio"],jt=(t,e)=>{const i=new Set(t.map(n=>n.type)),r=i.size===1?i.values().next().value:null;return r&&$i.includes(r)?qe([r],e>1):e>1?"items":"item"},Ri=t=>{const{mode:e}=t,i=F(t.config),r=oi(i),n=e==="insert"?$i:["image"],o=e==="insert"?i.stockProvider:void 0,a=e==="insert",s=typeof r.list=="function",l=[...s?["library"]:[],...o?["stock"]:[],"upload","url",...a?["embed"]:[]],c=s&&dr(r);let d=e==="replace"&&(!s||c)?"url":c?l.find(m=>m!=="library"):l[0],u=!1;const h=Ze(t.contextElement),b=Qe();b.classList.add("rte-mp","no-details");const y=p("div","rte-mp-sr");y.setAttribute("aria-live","polite"),y.setAttribute("role","status");const x=new tn(e==="insert",()=>G());let v=null,E=null;const R={get kinds(){return E?.kinds??n},allowedKinds:n,config:t.config,provider:r,selection:x,setActive:m=>{v=m,O.show(m),re()},commit:m=>W(m),announce:m=>{y.textContent="",window.setTimeout(()=>y.textContent=m,30)}},g=new ln(R,m=>E?.addUploaded(m),()=>E?.syncPending());E=s?new Wt(R,()=>ie("upload"),{pills:e==="insert"?{filter:t.kinds.length===1?t.kinds[0]:"all"}:void 0,queue:()=>g.queue,dropHint:!0}):null;const M=o?new Wt(R,()=>{},{id:"stock",source:on(o),emptyTitle:`Search ${o.name}`,emptyHint:`Photos from ${o.name} will show up here.`,offerUpload:!1,kinds:["image"],sortable:!1}):null,z={library:E,stock:M},C=new pn(n,t.initialUrl??"",t.initialAlt,()=>re(),()=>W(),t.kinds[0]??"image"),N=a?new Zr(i.embedProviders??[],()=>re(),()=>W()):null,O=new qr(x,{defaultAlt:t.initialAlt,config:t.config,captions:i.wrapInFigure!==!1,canDelete:m=>!!(E&&r.delete&&!m.metadata?.stock),onDelete:m=>{E?.deleteItem(m).then(w=>{if(!w)return;const S=g.queue.entries.find(L=>L.item?.id===m.id);S&&g.queue.remove(S.id),R.setActive(x.items.at(-1)??null)})},onEdit:m=>wi({src:m.src,name:m.name,config:t.config,contextElement:b,onApply:({item:w})=>{x.remove(m.id),E?.addUploaded(w),e==="insert"?x.toggle(w):x.only(w),R.setActive(w),R.announce(`${w.name} saved`)}})}),Z=p("div","rte-mp-header"),oe=p("h2","rte-media-title");oe.textContent=e==="insert"?"Media":t.title,b.setAttribute("aria-label",t.title);const Q=p("label","rte-mp-search"),P=p("input");P.type="search",P.id="mp-search",P.placeholder="Search by name",P.setAttribute("aria-label","Search the library"),Q.insertAdjacentHTML("afterbegin",T.search),Q.append(P),Q.hidden=!(s||o);const Le={},J=p("div","rte-mp-viewtools"),ee=p("select","rte-mp-sort");ee.setAttribute("aria-label","Sort by");for(const[m,w]of[["newest","Newest"],["oldest","Oldest"],["name","Name"]]){const S=p("option");S.value=m,S.textContent=w,ee.append(S)}const he=p("div","rte-mp-layout");he.setAttribute("role","group"),he.setAttribute("aria-label","Layout");const Me=new Map;for(const[m,w,S]of[["grid","Grid",T.grid],["list","List",T.list]]){const L=p("button","rte-mp-iconbtn");L.type="button",L.setAttribute("aria-label",`${w} view`),L.setAttribute("aria-pressed",String(m==="grid")),L.innerHTML=S,L.addEventListener("click",()=>{E?.setLayout(m),Me.forEach((de,ce)=>de.setAttribute("aria-pressed",String(ce===m)))}),Me.set(m,L),he.append(L)}ee.addEventListener("change",()=>E?.setSort(ee.value)),J.append(ee,he),J.hidden=!E;const ae=p("button","close-btn rte-media-close-btn");ae.type="button",ae.setAttribute("aria-label","Close"),ae.innerHTML=T.close,Z.append(oe,Q,J,ae);const H=p("div","rte-mp-nav");H.setAttribute("role","tablist"),H.setAttribute("aria-orientation","vertical"),H.setAttribute("aria-label","Where to get the media from");const me=new Map;for(const m of l){const w=p("button",`rte-mp-nav-item rte-media-tab ${lt[m].className}`);w.type="button",w.setAttribute("role","tab"),w.setAttribute("aria-controls",`rte-mp-panel-${m}`),w.innerHTML=`${lt[m].icon}<span></span>`,w.querySelector("span").textContent=lt[m].label,w.addEventListener("click",()=>{ie(m),w.focus()}),me.set(m,w),H.append(w)}H.addEventListener("keydown",m=>{const w={ArrowDown:1,ArrowRight:1,ArrowUp:-1,ArrowLeft:-1};if(!(m.key in w))return;m.preventDefault();const S=l[(l.indexOf(d)+w[m.key]+l.length)%l.length];ie(S),me.get(S)?.focus()});const fe=p("div","rte-mp-main"),Se={library:E?.element,stock:M?.element,upload:g.element,url:C.element,embed:N?.element};fe.append(...l.map(m=>Se[m]));const be=p("div","rte-mp-body");be.append(H,fe,O.element);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");se.type="button",se.textContent="Cancel";const te=p("button","gallery-btn rte-media-btn rte-media-btn-secondary");te.type="button",te.innerHTML=`${T.gallery}<span style="margin-left:6px">Insert as gallery</span>`,te.hidden=!0;const U=p("button","rte-media-btn rte-media-btn-primary");U.type="button",U.id="insert-btn",Te.append(K,se,te,U);const ge=p("div","rte-mp-drop-veil");ge.setAttribute("aria-hidden","true"),ge.textContent="Drop to upload",b.append(Z,be,Te,ge,y),h.append(b),document.body.append(h);const q=()=>d==="library"||d==="stock"||d==="upload";function ie(m){u=!0,Le[d]=P.value,d=m;for(const S of l){const L=S===m;Se[S].hidden=!L;const de=me.get(S);de.setAttribute("aria-selected",String(L)),de.tabIndex=L?0:-1}const w=z[m];Q.hidden=!w,J.hidden=m!=="library",w&&(P.value=Le[m]??"",P.setAttribute("aria-label",m==="stock"?`Search ${o.name}`:"Search the library"),P.placeholder=m==="stock"?`Search ${o.name}`:"Search by name",w.activate()),re()}function Ne(m){return m.map(w=>({src:w.src,type:w.type,alt:O.altFor(w),caption:O.captionFor(w)}))}function xe(){const m=N?.spec;return m?{src:m.src,type:"video",embed:m,title:N.title||void 0}:null}function W(m,w){let S;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&&(B(),t.onPick(S,w))}function re(){const m=d==="url"?C.url?1:0:d==="embed"?N?.spec?1:0:x.size,w=d==="embed"?"video":d==="url"?jt(C.spec()?[C.spec()]:[],1):jt(x.items,m);e==="replace"?U.textContent="Replace":U.textContent=m>1?`Insert ${m} ${w}`:m===1?`Insert ${w}`:"Insert",U.disabled=m===0;const S=x.size>=2&&x.items.every(de=>de.type==="image");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";const L=q()&&v!==null&&x.size>0;b.classList.toggle("no-details",!L),O.element.hidden=!L}function G(){x.size===0&&v&&(v=null,O.show(null)),E?.syncSelection(),M?.syncSelection(),g.syncSelection(),re()}let ve=()=>{};function B(){ve(),E?.dispose(),M?.dispose(),g.dispose(),C.dispose(),O.dispose(),h.remove()}ve=Xe(h,B),ae.addEventListener("click",B),se.addEventListener("click",B),U.addEventListener("click",()=>W()),te.addEventListener("click",()=>W(void 0,{gallery:!0})),h.addEventListener("click",m=>{m.target===h&&B()}),P.addEventListener("input",()=>z[d]?.setSearch(P.value.trim()));let le=0;const ze=m=>Array.from(m.dataTransfer?.types??[]).includes("Files");b.addEventListener("dragenter",m=>{ze(m)&&(le++,b.classList.add("is-dropping"))}),b.addEventListener("dragover",m=>{ze(m)&&m.preventDefault()}),b.addEventListener("dragleave",m=>{ze(m)&&(le=Math.max(0,le-1),le===0&&b.classList.remove("is-dropping"))}),b.addEventListener("drop",m=>{le=0,b.classList.remove("is-dropping");const w=Array.from(m.dataTransfer?.files??[]);w.length&&(m.preventDefault(),Ue(w))}),b.addEventListener("paste",m=>{const w=Array.from(m.clipboardData?.files??[]);w.length&&(m.preventDefault(),Ue(w))});function Ue(m){d!=="library"&&d!=="upload"&&ie(E?"library":"upload"),g.add(m)}ie(d),u=!1,c&&e==="insert"&&r.list({limit:1}).then(m=>{m.total>0&&!u&&h.isConnected&&(ie("library"),P.focus({preventScroll:!0}))},()=>{}),z[d]?P.focus({preventScroll:!0}):d==="upload"?g.focusDropzone():d==="embed"?N?.focus():C.focus()},Mt="rte-media",St="rte-embed",et="rte-gallery",De=`figure.${Mt}`,Vt={left:"1em auto 1em 0",center:"1em auto",right:"1em 0 1em auto"},Tt="720px",Di="display: table-caption; caption-side: bottom; padding-top: 0.5em; text-align: center; font-size: 0.875em; opacity: 0.75;",un="grid-column: 1 / -1; padding-top: 0.25em; text-align: center; font-size: 0.875em; opacity: 0.75;",zt=t=>t instanceof HTMLElement&&t.tagName==="IFRAME"&&!!t.closest(`figure.${St}`),dt=t=>t instanceof HTMLElement&&(t.tagName==="IMG"||t.tagName==="VIDEO"||t.tagName==="AUDIO"||zt(t)),Ve=t=>!!t.closest(`figure.${et}`),Ni=t=>(t.tagName==="IMG"||t.tagName==="VIDEO")&&!Ve(t),tt=t=>t.classList.contains(St)?"embed":t.classList.contains(et)?"gallery":"media",Ie=t=>{const e=t.parentElement;return e&&e.tagName==="A"&&e.children.length===1&&!e.textContent?.trim()?e:t},V=t=>t.closest(De),it=t=>t.querySelector(":scope > figcaption"),Ui=t=>{const i=V(t)?.getAttribute("data-align");if(i==="left"||i==="center"||i==="right")return i;const r=t.style;return r.marginLeft==="auto"&&r.marginRight==="auto"?"center":r.marginLeft==="auto"?"right":"left"},rt=(t,e)=>{t.classList.add(Mt),t.setAttribute("data-align",e);const i=tt(t);if(i!=="gallery"){if(i==="embed"){const r=t.style.maxWidth||Tt;t.style.cssText=`display: block; width: 100%; max-width: ${r}; margin: ${Vt[e]};`;return}t.style.cssText=`display: table; max-width: 100%; margin: ${Vt[e]};`}},Pi=t=>{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%"))},ne=t=>{t.getAttribute("contenteditable")!=="false"&&t.setAttribute("contenteditable","false");const e=it(t);e&&e.getAttribute("contenteditable")!=="true"&&e.setAttribute("contenteditable","true")},Kt=t=>{t.querySelectorAll(De).forEach(ne)},hn=(t,e="left")=>{const i=document.createElement("figure");return rt(i,e),Pi(t),i.append(t),ne(i),i},Hi=t=>{const e=V(t);if(e)return e;const i=Ie(t),r=Ui(t),n=document.createElement("figure");return rt(n,r),i.replaceWith(n),n.append(i),Pi(t),ne(n),n},mn=(t,e)=>{const i=Hi(t);tt(i)!=="gallery"&&rt(i,e)},nt=t=>tt(t)==="gallery"?un:Di,Oi=t=>{const e=Hi(t),i=it(e);if(i)return i.remove(),null;const r=document.createElement("figcaption");return r.style.cssText=nt(e),r.append(document.createElement("br")),e.append(r),ne(e),r},Bi=t=>{const e=t.parentElement;t.style.cssText||(t.style.cssText=e?nt(e):Di)},gn=(t,e)=>{if(zt(t)){const o=V(t);o&&(o.style.maxWidth=e===null?Tt:`${Math.max(1,Math.round(e))}px`);return}if(!Ni(t))return;if(e===null){t.removeAttribute("width"),t.removeAttribute("height"),t.style.removeProperty("width"),t.style.removeProperty("height");return}const i=t.getBoundingClientRect(),r=i.width&&i.height?i.height/i.width:null,n=Math.max(1,Math.round(e));if(t.style.width=`${n}px`,t.setAttribute("width",String(n)),r){const o=Math.round(n*r);t.style.height=`${o}px`,t.setAttribute("height",String(o))}},fn=[2,3,4,5],bn=3,xn="display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; object-fit: cover; max-width: 100%;",ot=t=>Math.min(5,Math.max(2,Math.round(t)||bn)),vn=t=>ot(Math.min(t,t>=5?3:t)),Fi=(t,e)=>{t.classList.add(et),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;`},yn=t=>ot(Number(t.getAttribute("data-columns"))),wn=(t,e)=>{Fi(t,ot(e))},kn=(t,e=vn(t.length))=>{const i=document.createElement("figure");i.classList.add("rte-media"),Fi(i,ot(e)),i.setAttribute("data-align","center");for(const n of t)n.style.cssText=xn,i.append(n);ne(i);const r=it(i);return r&&Bi(r),i},En=t=>[...t.querySelectorAll(":scope > img, :scope > a > img")],An=t=>{const e=t.closest(`figure.${et}`);return e?((t.parentElement?.tagName==="A"&&t.parentElement.children.length===1?t.parentElement:t).remove(),En(e).length===0?(e.remove(),!0):!1):!1},Cn="data-editora-embed",Ln="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen",Mn=(t,e={})=>{const i=document.createElement("figure");i.classList.add(Mt,St),i.setAttribute("data-provider",t.provider),i.style.maxWidth=e.maxWidth??Tt,rt(i,e.align??"center");const r=document.createElement("iframe");return r.src=t.src,r.title=e.title?.trim()||t.label,r.setAttribute("allow",Ln),r.setAttribute("allowfullscreen",""),r.setAttribute("loading","lazy"),r.setAttribute("frameborder","0"),r.setAttribute(Cn,"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},qi=t=>{if(t.type!=="image"&&t.type!=="video"&&t.type!=="audio")return null;const e=t.type==="image";if(t.type==="audio"){const r=document.createElement("audio");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}const i=document.createElement(e?"img":"video");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},Wi=(t,e)=>{if(t.embed)return Mn(t.embed,{align:e.align??"center",title:t.title});const i=qi(t);if(!i)return null;if(!e.figure)return i;const r=hn(i,e.align);if(t.caption){const n=document.createElement("figcaption");n.style.cssText=nt(r),n.textContent=t.caption,r.append(n),ne(r)}return r},Sn=new Set(["P","H1","H2","H3","H4","H5","H6"]),Gt=t=>!!t.textContent?.trim()||!!t.querySelector("img, video, figure, iframe, table, hr"),wt=(t,e,i)=>{t.deleteContents();let r=t.startContainer instanceof HTMLElement?t.startContainer:t.startContainer.parentElement;for(;r&&r!==e&&!Sn.has(r.tagName);)r=r.parentElement;if(!r||r===e||!e.contains(r)){const s=document.createDocumentFragment();i.forEach(c=>s.appendChild(c));const l=i[i.length-1];if(t.insertNode(s),l&&!l.nextSibling&&l.parentElement){const c=document.createElement("p");return c.innerHTML="<br>",l.after(c),c}return null}const n=document.createRange();n.setStart(t.startContainer,t.startOffset),n.setEnd(r,r.childNodes.length);const o=r.cloneNode(!1);o.removeAttribute("id"),o.append(n.extractContents()),Gt(o)||(o.innerHTML="<br>");const a=!Gt(r);return r.after(...i,o),a&&r.remove(),o},Yt=(t,e)=>{const{savedSelection:i}=e;if(t.length===0)return!1;const r=(i?(i.commonAncestorContainer instanceof HTMLElement?i.commonAncestorContainer:i.commonAncestorContainer.parentElement)?.closest('[contenteditable="true"]'):null)??si(e.contextElement)?.closest('[contenteditable="true"]')??null;if(!r)return!1;const n=r.innerHTML,o=t[t.length-1],a=t.some(d=>d.tagName==="FIGURE");let s=null;if(i&&r.contains(i.commonAncestorContainer))if(a)s=wt(i,r,t);else{const d=document.createDocumentFragment();t.forEach(u=>d.appendChild(u)),i.deleteContents(),i.insertNode(d)}else{const d=document.createRange();d.selectNodeContents(r),d.collapse(!1),a?s=wt(d,r,t):r.appendChild(t.reduce((u,h)=>(u.appendChild(h),u),document.createDocumentFragment()))}if(!o.isConnected)return!1;r.focus({preventScroll:!0});const l=window.getSelection();if(l){const d=document.createRange();s?d.setStart(s,0):d.setStartAfter(o),d.collapse(!0),l.removeAllRanges(),l.addRange(d)}_e.recordDomHistory(r,n);const c=t.some(d=>d.tagName==="IFRAME"||d.querySelector("iframe"));return r.dispatchEvent(c?new CustomEvent("input",{bubbles:!0,detail:{allowedTags:["iframe"]}}):new Event("input",{bubbles:!0})),!0},Tn=(t,e)=>{t.src=e.src,e.alt!==void 0&&(t.alt=e.alt)},ct=(t,e,i)=>{document.querySelectorAll(".rte-media-overlay").forEach(o=>o.remove());let r=null;const n=window.getSelection();n&&n.rangeCount>0&&(r=n.getRangeAt(0).cloneRange()),Ri({mode:"insert",kinds:[t],title:`Insert ${t==="image"?"Image":t==="video"?"Video":"Audio"}`,contextElement:e,config:i,onPick:(o,a)=>{const s=F(i).wrapInFigure!==!1;if(a?.gallery&&s&&o.length>1){const c=o.map(h=>qi(h)).filter(h=>h instanceof HTMLImageElement),d=kn(c),u=[...new Set(o.map(h=>h.caption).filter(h=>!!h))];if(u.length){const h=document.createElement("figcaption");h.style.cssText=nt(d),h.textContent=u.join(" · "),d.append(h),ne(d)}Yt([d],{savedSelection:r,contextElement:e});return}const l=o.map(c=>Wi(c,{figure:s})).filter(c=>c!==null);Yt(l,{savedSelection:r,contextElement:e})}})},zn=(t,e,i)=>{const r=Ze(t),n=Qe(!0);n.innerHTML=`
1802
+ <div class="rte-media-header">
1803
+ <h2 class="rte-media-title">Edit Alt Text</h2>
1804
+ <button class="close-btn rte-media-close-btn" type="button" aria-label="Close">×</button>
1805
+ </div>
1806
+ <div class="rte-media-body">
1807
+ <label class="rte-media-label">Alternative Text (for accessibility)</label>
1808
+ <textarea id="alt-text-input" class="rte-media-textarea" placeholder="Describe the image for screen readers...">${ft.escapeHtml(t.alt||"")}</textarea>
1809
+ <p class="rte-media-helper">Good alt text is descriptive and concise. It helps users with visual impairments understand your content.</p>
1810
+ </div>
1811
+ <div class="rte-media-footer">
1812
+ <button class="cancel-btn rte-media-btn rte-media-btn-secondary" type="button">Cancel</button>
1813
+ <button class="save-btn rte-media-btn rte-media-btn-primary" type="button">Save</button>
1814
+ </div>
1815
+ `,r.appendChild(n),document.body.appendChild(r);const o=n.querySelector("#alt-text-input");let a=()=>{};if(ki(i)){const h=Ei({config:i,image:()=>({src:t.currentSrc||t.src}),input:o});a=h.abort;const b=n.querySelector(".rte-media-label"),y=document.createElement("div");y.className="rte-mp-label-row",b.replaceWith(y),y.append(b,h.button),o.after(h.status)}const s=n.querySelector(".close-btn"),l=n.querySelector(".cancel-btn"),c=n.querySelector(".save-btn");let d=()=>{};const u=()=>{a(),d(),r.parentNode&&r.parentNode.removeChild(r)};d=Xe(r,u),s.addEventListener("click",u),l.addEventListener("click",u),r.addEventListener("click",h=>{h.target===r&&u()}),c.addEventListener("click",()=>{const h=t.alt!==o.value;t.alt=o.value,u(),h&&e?.()}),o.focus(),o.select()},pt="data-original-src",In=t=>!t.startsWith("data:")&&!t.startsWith("blob:"),$n=t=>{if(t.startsWith("data:")||t.startsWith("blob:"))return"image";try{const e=new URL(t,document.baseURI).pathname.split("/").filter(Boolean).pop();return e?decodeURIComponent(e):"image"}catch{return"image"}},Xt=(t,e)=>{t.src=e,t.removeAttribute("height"),t.style.removeProperty("height")},Rn=(t,e,i,r)=>{const n=t.currentSrc||t.src,o=t.getAttribute(pt);wi({src:n,name:$n(o??n),config:e,contextElement:t,canRestore:!!o,deps:r,onApply:({item:a})=>{!o&&In(n)&&t.setAttribute(pt,n),Xt(t,a.src),i()},onRestore:()=>{o&&(Xt(t,o),t.removeAttribute(pt),i())}})},Dn=(t,e)=>{const i=t.closest("a"),r=i?.getAttribute("href")||"",n=i?.getAttribute("target")||"_self",o=i?.getAttribute("title")||"",a=Ze(t),s=Qe(!0);s.innerHTML=`
1816
+ <div class="rte-media-header">
1817
+ <h2 class="rte-media-title">${i?"Edit Link":"Add Link"}</h2>
1818
+ <button class="close-btn rte-media-close-btn" type="button" aria-label="Close">×</button>
1819
+ </div>
1820
+ <div class="rte-media-body">
1821
+ <div class="rte-media-field">
1822
+ <label class="rte-media-label">URL</label>
1823
+ <input id="link-url" type="url" class="rte-media-input" value="${ft.escapeHtml(r)}" placeholder="https://example.com" />
1824
+ </div>
1825
+ <div class="rte-media-field">
1826
+ <label class="rte-media-label">Title (tooltip)</label>
1827
+ <input id="link-title" type="text" class="rte-media-input" value="${ft.escapeHtml(o)}" placeholder="Optional tooltip text" />
1828
+ </div>
1829
+ <label class="rte-media-checkbox-label">
1830
+ <input id="link-target" type="checkbox" ${n==="_blank"?"checked":""} />
1831
+ Open in new window/tab
1832
+ </label>
1833
+ </div>
1834
+ <div class="rte-media-footer rte-media-footer-spread">
1835
+ ${i?'<button class="remove-link-btn rte-media-btn rte-media-btn-danger" type="button">Remove Link</button>':'<span class="rte-media-spacer"></span>'}
1836
+ <div class="rte-media-actions">
1837
+ <button class="cancel-btn rte-media-btn rte-media-btn-secondary" type="button">Cancel</button>
1838
+ <button class="save-btn rte-media-btn rte-media-btn-primary" type="button">Save</button>
1839
+ </div>
1840
+ </div>
1841
+ `,a.appendChild(s),document.body.appendChild(a);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");let x=()=>{};const v=()=>{x(),a.parentNode&&a.parentNode.removeChild(a)};x=Xe(a,v),u.addEventListener("click",v),h.addEventListener("click",v),a.addEventListener("click",E=>{E.target===a&&v()}),b.addEventListener("click",()=>{const E=l.value.trim();if(E){const R=E.startsWith("http")?E:`https://${E}`;if(i)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");else{const g=document.createElement("a");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)}v(),e?.()}}),y?.addEventListener("click",async()=>{!i||!await kt.confirmAction("Remove link from this media?",{title:"Remove link",confirmText:"Remove link",danger:!0,context:t})||!i.isConnected||(i.replaceWith(t),v(),e?.())}),l.focus()},Nn=(t,e,i)=>{Ri({mode:"replace",kinds:["image"],title:"Replace Image",contextElement:t,config:e,initialUrl:t.src.startsWith("data:")?"":t.src,initialAlt:t.alt,onPick:([r])=>{r&&(Tn(t,r),i?.())}})},_=t=>`<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">${t}</svg>`,j={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>'),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>'),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>'),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>'),caption:_('<rect x="3" y="4" width="18" height="11" rx="2"></rect><line x1="7" y1="19" x2="17" y2="19"></line>'),edit:_('<path d="M6 2v14a2 2 0 0 0 2 2h14"></path><path d="M18 22V8a2 2 0 0 0-2-2H2"></path>'),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>'),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>'),alt:_('<path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"></path>'),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>'),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>'),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>')},Un=[{label:"Small",share:.25},{label:"Medium",share:.5},{label:"Large",share:.75},{label:"Full width",share:1},{label:"Original size",share:"original"}],Pn=t=>{const e=getComputedStyle(t),i=(parseFloat(e.paddingLeft)||0)+(parseFloat(e.paddingRight)||0);let r=t.clientWidth-i;const n=t.getBoundingClientRect();let o=Math.max(n.left,0),a=document.documentElement.clientWidth;for(let l=t.parentElement;l;l=l.parentElement){if(getComputedStyle(l).overflowX==="visible")continue;const c=l.getBoundingClientRect();o=Math.max(o,c.left),a=Math.min(a,c.right)}const s=a-o-i;return s>0&&(r=Math.min(r,s)),r};class Hn{constructor(e,i){this.media=e,this.hooks=i,this.menu=null,this.menuTrigger=null,this.lastButton=null,this.onKeyDown=g=>{if(g.key==="Escape"){g.preventDefault(),g.stopPropagation(),this.menu?this.closeMenu(!0):this.hooks.returnFocus();return}if(this.menu)return;const M=this.buttons(),z=M.indexOf(document.activeElement);if(z===-1)return;let C=-1;if(g.key==="ArrowRight")C=(z+1)%M.length;else if(g.key==="ArrowLeft")C=(z-1+M.length)%M.length;else if(g.key==="Home")C=0;else if(g.key==="End")C=M.length-1;else if(g.key==="ArrowDown"&&M[z].classList.contains("btn-size")){g.preventDefault(),this.openSizeMenu();return}else if(g.key==="ArrowDown"&&M[z].classList.contains("btn-columns")){g.preventDefault(),this.openColumnsMenu();return}else if(g.key==="Tab"){g.preventDefault(),this.hooks.returnFocus();return}else return;g.preventDefault(),M.forEach(N=>N.tabIndex=-1),M[C].tabIndex=0,M[C].focus()},Ce();const r=e.tagName==="IMG",n=e.tagName==="AUDIO",o=zt(e),a=Ve(e),s=!n&&!o,l=e.closest("a"),c=V(e),d=Ui(e),u=!!(c&&it(c)),h=o?"Embedded video":a?"Gallery":r?"Image":n?"Audio":"Video",b=document.createElement("div");b.className="media-floating-toolbar",b.setAttribute("role","toolbar"),b.setAttribute("aria-label",`${h} options`),li(e)&&b.classList.add("rte-ui-theme-dark");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>';b.innerHTML=[a?"":y("btn-align-left","Align left",j.left,d==="left"),a?"":y("btn-align-center","Align center",j.center,d==="center"),a?"":y("btn-align-right","Align right",j.right,d==="right"),a?y("btn-columns","Columns",j.columns,void 0,!0):n?"":y("btn-size","Size",j.size,void 0,!0),y("btn-caption",u?"Remove caption":"Add caption",j.caption,u),x,r?y("btn-edit","Edit image: crop, rotate, resize",j.edit):"",r?y("btn-alt","Edit alt text",j.alt):"",s?y("btn-link",l?"Edit or remove link":"Add link",j.link):"",r?y("btn-replace","Replace image",j.replace):"",x,y("btn-remove",a?"Remove picture":"Remove",j.remove),a?y("btn-remove-gallery","Remove gallery",j.removeAll):""].join(""),b.addEventListener("mousedown",g=>g.preventDefault()),b.addEventListener("keydown",this.onKeyDown),b.addEventListener("focusin",g=>{const M=g.target.closest(".media-floating-toolbar-btn");this.lastButton=[...M?.classList??[]].find(z=>z.startsWith("btn-"))??this.lastButton}),this.element=b,this.buttons()[0]?.setAttribute("tabindex","0"),document.body.appendChild(b);const v=(g,M)=>b.querySelector(g)?.addEventListener("click",M),E=g=>()=>{i.commit(e,()=>mn(e,g)),i.refresh()};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",()=>{let g=null;i.commit(e,()=>{g=Oi(e)}),i.refresh(),g&&i.focusCaption(g)}),v(".btn-edit",()=>this.viaDialog(g=>Rn(e,i.config?.(),g))),v(".btn-alt",()=>this.viaDialog(g=>zn(e,g,i.config?.()))),v(".btn-link",()=>this.viaDialog(g=>Dn(e,g))),v(".btn-replace",()=>this.viaDialog(g=>Nn(e,i.config?.(),g)));const R=async g=>{if(!await kt.confirmAction(g?"Remove this whole gallery?":"Remove this media?",{title:g?"Remove gallery":"Remove media",confirmText:"Remove",danger:!0,context:e})||!e.isConnected)return;if(a&&!g){i.commit(e,()=>An(e)),i.removed();return}const z=e.closest("a"),C=V(e)??(z&&z.children.length===1&&!z.textContent?.trim()?z:e);i.commit(e,()=>C.remove()),i.removed()};v(".btn-remove",()=>{R(!1)}),v(".btn-remove-gallery",()=>{R(!0)}),this.reposition()}buttons(){return[...this.element.querySelectorAll(":scope > .media-floating-toolbar-btn")]}focusFirst(){this.buttons()[0]?.focus()}currentButton(){const e=document.activeElement;return[...((e instanceof HTMLElement&&this.element.contains(e)?e:null)?.closest(".media-floating-toolbar-btn")??null)?.classList??[]].find(n=>n.startsWith("btn-"))??this.lastButton}focusButton(e){const i=this.element.querySelector(`.${e}`);i&&(this.buttons().forEach(r=>r.tabIndex=-1),i.tabIndex=0,i.focus())}viaDialog(e){const r=this.media.closest('[contenteditable="true"]')?.innerHTML??"";e(()=>{this.hooks.commit(this.media,()=>{},r),this.hooks.refresh()})}openSizeMenu(){const{media:e}=this,i=e.closest('[contenteditable="true"]'),r=i?Pn(i):0;this.openMenu(".btn-size","Size",Un.map(n=>({label:n.label,apply:()=>{const o=n.share==="original"?null:Math.max(50,Math.round(Math.min(r||1/0,(r||800)*n.share)));this.hooks.commit(e,()=>gn(e,o))}})))}openColumnsMenu(){const{media:e}=this,i=V(e);if(!i||tt(i)!=="gallery")return;const r=yn(i);this.openMenu(".btn-columns","Columns",fn.map(n=>({label:`${n} columns${n===r?" (current)":""}`,apply:()=>this.hooks.commit(e,()=>wn(i,n))})))}openMenu(e,i,r){const n=this.element.querySelector(e),o=document.createElement("div");o.className="media-size-menu",o.setAttribute("role","menu"),o.setAttribute("aria-label",i);for(const a of r){const s=document.createElement("button");s.type="button",s.className="media-size-menu-item",s.setAttribute("role","menuitem"),s.textContent=a.label,s.tabIndex=-1,s.addEventListener("click",()=>{a.apply(),this.closeMenu(!0),this.hooks.refresh()}),o.append(s)}o.addEventListener("keydown",a=>{const s=[...o.querySelectorAll("button")],l=s.indexOf(document.activeElement);if(a.key==="ArrowDown")s[(l+1)%s.length].focus();else if(a.key==="ArrowUp")s[(l-1+s.length)%s.length].focus();else if(a.key==="Home")s[0].focus();else if(a.key==="End")s[s.length-1].focus();else return;a.preventDefault(),a.stopPropagation()}),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()}closeMenu(e){if(!this.menu)return;this.menu.remove(),this.menu=null;const i=this.menuTrigger;this.menuTrigger=null,i?.setAttribute("aria-expanded","false"),e&&i?.focus()}reposition(){const{element:e,media:i}=this;if(!i.isConnected)return;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;let d=c<Math.max(l,0)?n.bottom+8:c;n.bottom>0&&n.top<window.innerHeight&&(d=Math.min(Math.max(d,8),Math.max(window.innerHeight-o-8,8)));const h=Math.min(Math.max(n.left+n.width/2-a/2,8),Math.max(window.innerWidth-a-8,8));e.style.top=`${Math.round(d)}px`,e.style.left=`${Math.round(h)}px`,e.style.display="flex"}contains(e){return e instanceof Node&&this.element.contains(e)}destroy(){this.element.remove()}}const Ee="data-rte-media-pending";let On=0;const Bn=()=>`pending-${Date.now().toString(36)}-${++On}`,Zt=t=>{if(!t.includes(Ee))return t;const e=document.createElement("template");return e.innerHTML=t,e.content.querySelectorAll(`[${Ee}]`).forEach(i=>i.remove()),e.innerHTML};class Fn{constructor(){this.pending=new Map,this.queues=[],this.entryIds=new Map}get count(){return this.pending.size}start(e,i,r,n){const o=F(n),a=[];for(const u of e)try{vi(u,o),a.push(u)}catch(h){Rt.notify(h instanceof Error?h.message:`Couldn't upload ${u.name}.`,"error")}if(a.length===0)return;Ce();const s=a.map(u=>this.createPending(u,i,n)),l=r&&i.contains(r.startContainer)?r:(()=>{const u=document.createRange();return u.selectNodeContents(i),u.collapse(!1),u})();wt(l,i,s.map(u=>u.placeholder)),i.dispatchEvent(new Event("input",{bubbles:!0}));const c=new Ii({config:n,onChange:()=>this.sync()});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=>{this.pending.set(u.id,u),document.body.appendChild(u.layer)}),this.sync(),this.ensureTimer()}sweep(e){let i=!1;return e.querySelectorAll(`[${Ee}]`).forEach(r=>{this.pending.has(r.getAttribute(Ee)??"")||(r.remove(),i=!0)}),i}dispose(){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()}createPending(e,i,r){const n=Bn(),o=document.createElement("figure");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);";const a=document.createElement("div");a.className="rte-mp-pending",a.setAttribute("role","status");const s=document.createElement("span"),l=document.createElement("div");l.className="rte-mp-pending-bar",l.append(s);const c=document.createElement("span");c.className="rte-mp-pending-label";const d=document.createElement("button");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",()=>{const u=[...this.entryIds.entries()].find(([,h])=>h.pending.id===n);u&&u[1].queue.remove(u[0])}),a.append(c,l,d),{id:n,file:e,host:i,placeholder:o,layer:a,bar:s,label:c,config:r}}sync(){for(const[e,{pending:i,queue:r}]of this.entryIds){const n=r.entries.find(o=>o.id===e);if(!n){this.finish(e,i,null);continue}this.show(i,n),n.status==="done"&&n.item?this.finish(e,i,n):n.status==="error"&&(Rt.notify(n.error??`Couldn't upload ${i.file.name}.`,"error"),this.finish(e,i,null))}}show(e,i){const r=Math.round(i.fraction*100);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)}position(e){const{placeholder:i,layer:r}=e;if(!i.isConnected){r.style.display="none";return}const n=i.getBoundingClientRect();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`}finish(e,i,r){this.entryIds.delete(e),this.pending.delete(i.id);const{placeholder:n,host:o}=i;if(r?.item&&n.isConnected){const a=F(i.config),s=Wi({src:r.item.src,type:r.item.type,alt:r.item.alt},{figure:a.wrapInFigure!==!1});if(s){const l=Zt(o.innerHTML);n.replaceWith(s),s.tagName==="FIGURE"&&ne(s),_e.recordDomHistory(o,l,Zt(o.innerHTML)),o.dispatchEvent(new Event("input",{bubbles:!0}))}}this.release(i,!1),this.pending.size===0&&this.stopTimer()}release(e,i){e.layer.remove(),e.placeholder.isConnected&&(i||e.placeholder.hasAttribute(Ee))&&e.placeholder.remove()}ensureTimer(){this.timer||(this.timer=setInterval(()=>this.pending.forEach(e=>this.position(e)),120))}stopTimer(){this.timer&&clearInterval(this.timer),this.timer=void 0}}const qn=["nw","ne","sw","se"],Qt=50;class Wn{constructor(e,i){this.onResized=e,this.onMoved=i,this.handles=new Map,this.label=document.createElement("div"),this.media=null,this.drag=null,Ce(),qn.forEach(r=>{const n=document.createElement("div");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)}),this.label.className="media-resize-label",this.label.setAttribute("aria-hidden","true"),this.label.style.display="none",document.body.appendChild(this.label)}show(e){this.media=e,this.update()}update(){if(!this.media||!this.media.isConnected){this.handles.forEach(r=>r.style.display="none");return}const e=this.media.getBoundingClientRect(),i={nw:[e.left,e.top],ne:[e.right,e.top],sw:[e.left,e.bottom],se:[e.right,e.bottom]};this.handles.forEach((r,n)=>{r.style.left=`${i[n][0]}px`,r.style.top=`${i[n][1]}px`,r.style.display="block"})}contains(e){return e instanceof Node&&[...this.handles.values()].some(i=>i===e)}destroy(){this.drag=null,document.body.style.userSelect="",this.handles.forEach(e=>e.remove()),this.handles.clear(),this.label.remove(),this.media=null}start(e,i,r){if(!this.media||e.pointerType==="mouse"&&e.button!==0)return;e.preventDefault(),e.stopPropagation(),r.setPointerCapture?.(e.pointerId);const n=this.media.getBoundingClientRect(),o=this.media.closest('[contenteditable="true"]');this.drag={corner:i,x:e.clientX,y:e.clientY,width:n.width,height:n.height,before:o?.innerHTML??""},document.body.style.userSelect="none"}move(e){const{drag:i,media:r}=this;if(!i||!r)return;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";let l=i.width+(a?n:-n),c=i.height+(s?o:-o);const d=i.width/i.height;Math.abs(n)>Math.abs(o)?c=l/d:l=c*d,l=Math.max(Qt,l),c=Math.max(Qt,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"}end(e,i){const{drag:r,media:n}=this;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)}}const We='[contenteditable="true"]',ut="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,_n="[data-editora-editor], editora-editor, .rte-editor, .editora-editor",jn=".rte-toolbar, .editora-toolbar",Vn='[data-command="insertImage"], [data-command="insertVideo"], [data-command="insertAudio"]',Jt=t=>{const i=t.closest(_n)?.querySelector(jn);return!i||!!i.querySelector(Vn)},ht=(t,e)=>Array.from(t?.files??[]).filter(i=>/^(image|video|audio)\//.test(i.type)&&bi(i.type,e)),Kn=t=>{if(t.getData("text/plain").trim())return!1;const e=t.getData("text/html");if(!e)return!0;const i=new DOMParser().parseFromString(e,"text/html").body;return!i.textContent?.trim()&&!i.querySelector("table")},ei=t=>!!(t&&t.matches(De)&&!t.hasAttribute("data-rte-media-pending")),Gn=(t,e)=>{let i=t;for(;i.nodeType!==Node.TEXT_NODE&&(e==="start"?i.firstChild:i.lastChild);)i=e==="start"?i.firstChild:i.lastChild;const r=document.createRange();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},Yn=(t,e)=>{let i=t;for(;i&&i.parentNode!==e;)i=i.parentNode;return i instanceof HTMLElement?i:null},ti=(t,e,i)=>{const r=document.createRange();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")},Xn=(t,e)=>{const i=document;if(i.caretRangeFromPoint)return i.caretRangeFromPoint(t,e);const r=i.caretPositionFromPoint?.(t,e);if(!r)return null;const n=document.createRange();return n.setStart(r.offsetNode,r.offset),n.collapse(!0),n};class Zn{constructor(){this.selected=null,this.toolbar=null,this.handles=null,this.uploads=new Fn,this.attached=!1,this.selectedAt=0,this.config=()=>{},this.onClick=e=>{const i=Fe(e.target);if(!i)return;const r=i.closest("figure.rte-embed"),n=r?.querySelector("iframe")??null;if(n&&r.closest(We)&&!i.closest("figcaption")){e.preventDefault(),e.stopPropagation(),this.select(n),this.placeNodeSelection(n);return}if(dt(i)&&i.closest(We)){if(i.tagName==="AUDIO"){this.select(i);return}if(!(i.tagName==="VIDEO"&&i.controls&&e.offsetY>i.clientHeight-44)){e.preventDefault(),e.stopPropagation(),this.select(i),this.placeNodeSelection(i);return}}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()},this.onFocusIn=e=>{const i=Y(e.target);i&&(Kt(i),this.uploads.sweep(i)&&i.dispatchEvent(new Event("input",{bubbles:!0})))},this.onSelectionChange=()=>{if(this.selected&&!this.selected.isConnected){this.deselect();return}const e=window.getSelection();if(!e||e.rangeCount===0)return;const i=e.getRangeAt(0),r=this.mediaInRange(i);if(r){this.selected!==r&&this.select(r);return}if(!this.selected)return;const n=Y(this.selected),o=i.commonAncestorContainer;!n||!n.contains(o)||V(this.selected)?.contains(o)||performance.now()-this.selectedAt<150||this.deselect()},this.onKeyDown=e=>{const i=Fe(e.target);if(this.toolbar?.contains(i))return;if(e.key==="Escape"&&this.selected&&!document.querySelector(".rte-media-overlay")){this.deselect();return}if(e.key==="F10"&&e.altKey&&this.selected){e.preventDefault(),this.toolbar?.focusFirst();return}this.arrowOntoMedia(e,i);const r=i?.closest("figure.rte-media > figcaption");if(!r)return;const n=r.parentElement,o=Y(r);if(o){if(e.key==="Enter"&&!e.shiftKey){e.preventDefault(),e.stopPropagation();const a=o.innerHTML,s=document.createElement("p");s.innerHTML="<br>",n.after(s),_e.recordDomHistory(o,a),o.dispatchEvent(new Event("input",{bubbles:!0}));const l=document.createRange();l.setStart(s,0),l.collapse(!0),window.getSelection()?.removeAllRanges(),window.getSelection()?.addRange(l)}else if(e.key==="Backspace"&&!r.textContent?.trim()){e.preventDefault(),e.stopPropagation();const a=n.querySelector(ut);if(!a)return;this.commit(a,()=>Oi(a)),this.select(a),this.returnFocus()}}},this.onPaste=e=>{const i=Fe(e.target),r=i?Y(i):null,n=e.clipboardData;if(!r||!n||!Jt(r))return;if(i?.closest("figure.rte-media > figcaption")){e.preventDefault(),e.stopPropagation();const c=n.getData("text/plain").replace(/\s*[\r\n]+\s*/g," ");c&&document.execCommand("insertText",!1,c);return}if(F(this.config()).uploadOnPaste===!1)return;const a=ht(n,void 0);if(a.length===0||!Kn(n))return;e.preventDefault(),e.stopPropagation();const s=window.getSelection(),l=s&&s.rangeCount>0&&r.contains(s.anchorNode)?s.getRangeAt(0):null;this.uploads.start(a,r,l,this.config())},this.onDragOver=e=>{this.wantsDrop(e)&&e.preventDefault()},this.onDrop=e=>{if(!this.wantsDrop(e))return;const i=Y(e.target);if(!i)return;e.preventDefault(),e.stopPropagation();let r=Xn(e.clientX,e.clientY);r&&!i.contains(r.startContainer)&&(r=null);const n=r?(r.startContainer instanceof HTMLElement?r.startContainer:r.startContainer.parentElement)?.closest(De):null;r&&n&&(r=document.createRange(),r.setStartAfter(n),r.collapse(!0)),this.uploads.start(ht(e.dataTransfer,void 0),i,r,this.config())},this.onViewportChange=()=>{this.selected&&(this.handles?.update(),this.toolbar?.reposition())}}setConfigSource(e){this.config=e}attach(){this.attached||typeof document>"u"||(this.attached=!0,Ce(),this.handles=new Wn((e,i)=>this.commit(e,()=>{},i),()=>this.toolbar?.reposition()),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))}detach(){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))}get isAttached(){return this.attached}get selection(){return this.selected}select(e){if(this.selected===e&&this.toolbar){this.onViewportChange();return}this.deselect(),this.selected=e,this.selectedAt=performance.now();const i=Y(e);i&&Kt(i),this.toolbar=new Hn(e,{config:()=>this.config(),commit:(r,n,o)=>this.commit(r,n,o),refresh:()=>this.refresh(),removed:()=>this.deselect(),returnFocus:()=>this.returnFocus(),focusCaption:r=>this.focusCaption(r)}),this.handles?.show(Ni(e)?e:null)}deselect(){this.toolbar?.destroy(),this.toolbar=null,this.selected=null,this.handles?.show(null)}refresh(){const e=this.selected;if(!e||!e.isConnected){this.deselect();return}const i=this.toolbar,r=document.activeElement,o=i?.contains(r)||r===document.body||r===null?i?.currentButton()??null:null;i?.destroy(),this.toolbar=null,this.selected=null,this.select(e),o&&this.toolbar?.focusButton(o)}placeNodeSelection(e){const i=Ve(e)?Ie(e):V(e)??Ie(e),r=window.getSelection();if(!r||!i.isConnected)return;const n=document.createRange();n.selectNode(i),r.removeAllRanges(),r.addRange(n)}returnFocus(){const e=this.selected,i=e?Y(e):null;if(!e||!i)return;i.focus({preventScroll:!0});const r=V(e)??Ie(e),n=document.createRange();n.selectNode(r);const o=window.getSelection();o?.removeAllRanges(),o?.addRange(n)}focusCaption(e){Bi(e),e.focus({preventScroll:!0});const i=document.createRange();i.selectNodeContents(e),i.collapse(!0);const r=window.getSelection();r?.removeAllRanges(),r?.addRange(i)}commit(e,i,r){const n=e.closest(We),o=r??n?.innerHTML??"";i(),n&&(_e.recordDomHistory(n,o),n.dispatchEvent(new Event("input",{bubbles:!0})))}mediaInRange(e){if(e.collapsed||e.startContainer!==e.endContainer||e.endOffset-e.startOffset!==1)return null;const i=e.startContainer.childNodes[e.startOffset];return!(i instanceof HTMLElement)||!Y(i)?null:dt(i)?i:i.matches(De)&&!i.hasAttribute("data-rte-media-pending")?i.querySelector(ut):i.tagName==="A"&&i.children.length===1&&dt(i.firstElementChild)?i.firstElementChild:null}arrowOntoMedia(e,i){const r=e.key==="ArrowRight"||e.key==="ArrowDown",n=e.key==="ArrowLeft"||e.key==="ArrowUp";if(!r&&!n||e.shiftKey||e.altKey||e.ctrlKey||e.metaKey||e.defaultPrevented)return;const o=i?Y(i):null,a=window.getSelection();if(!o||!a||a.rangeCount===0)return;const s=a.getRangeAt(0),l=(b,y)=>{e.preventDefault();const x=document.createRange();x.selectNode(b),a.removeAllRanges(),a.addRange(x);const v=b.querySelector(ut);v&&this.select(v)},c=this.mediaInRange(s);if(c){const y=V(c)??Ie(c),x=r?y.nextElementSibling:y.previousElementSibling;x&&(e.preventDefault(),a.removeAllRanges(),a.addRange(Gn(x,r?"start":"end")));return}if(!s.collapsed)return;const d=i?.closest("figure.rte-media > figcaption");if(d){n&&ti(s,d,"start")&&l(d.parentElement);return}const u=Yn(s.startContainer,o);if(!u||ei(u))return;const h=r?u.nextElementSibling:u.previousElementSibling;h&&ei(h)&&ti(s,u,r?"end":"start")&&l(h)}wantsDrop(e){const i=Fe(e.target);if(!i||i.closest(".rte-media-overlay"))return!1;const r=Y(i);if(!r||!Jt(r)||F(this.config()).uploadOnPaste===!1)return!1;const n=e.dataTransfer;return!n||!Array.from(n.types??[]).includes("Files")?!1:e.type==="dragover"||ht(n,void 0).length>0}}let Qn=null;const Jn=()=>Qn??=new Zn,eo='<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>',to='<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>',io='<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>',mt=t=>t?.contentElement instanceof HTMLElement?t.contentElement:void 0,ro=t=>{const e=Jn(),i=()=>{e.setConfigSource(()=>t),e.attach()};return typeof window<"u"&&i(),{name:"image",initialize:()=>{i()},destroy:()=>{e.detach()},toolbar:[{label:"Image",command:"insertImage",icon:eo},{label:"Video",command:"insertVideo",icon:to},...F(t).audio?[{label:"Audio",command:"insertAudio",icon:io}]:[]],commands:{insertImage:(r,n)=>(i(),ct("image",mt(n),t),!0),insertVideo:(r,n)=>(i(),ct("video",mt(n),t),!0),insertAudio:(r,n)=>(i(),ct("audio",mt(n),t),!0)},keymap:{"Mod-Shift-i":"insertImage"}}};exports.MediaManagerPlugin=ro;exports.MediaUploadError=$;exports.createBase64Provider=At;exports.createCallbackProvider=ii;exports.createRestProvider=ni;exports.getMediaManagerConfig=Ge;exports.parseEmbedUrl=Si;exports.setMediaManagerConfig=Xi;