"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});require("./shared-config.cjs.js");let A=null,p=null,s=null,R=[],D=!1,I=null,V=0,j=0,C=0,$=0,N=1,T=null;const W='[data-theme="dark"], .dark, .editora-theme-dark',B=(e,t)=>{const r=a=>{a.key!=="Escape"||!e.isConnected||(a.preventDefault(),a.stopPropagation(),t())};return document.addEventListener("keydown",r,!0),()=>{document.removeEventListener("keydown",r,!0)}},X=()=>{if(typeof document>"u"||document.getElementById("rte-media-dialog-styles"))return;const e=document.createElement("style");e.id="rte-media-dialog-styles",e.textContent=`
    .rte-media-overlay {
      --rte-media-overlay-bg: rgba(15, 23, 36, 0.56);
      --rte-media-bg: #ffffff;
      --rte-media-text: #101828;
      --rte-media-muted: #5f6b7d;
      --rte-media-border: #d6dbe4;
      --rte-media-surface: #f7f9fc;
      --rte-media-surface-hover: #eef2f7;
      --rte-media-accent: #1f75fe;
      --rte-media-accent-hover: #165fd6;
      --rte-media-danger: #dc3545;
      --rte-media-danger-hover: #b92735;
      --rte-media-ring: rgba(31, 117, 254, 0.18);
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: var(--rte-media-overlay-bg);
      backdrop-filter: blur(2px);
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 99999;
      padding: 16px;
      box-sizing: border-box;
    }

    .rte-media-overlay.rte-ui-theme-dark {
      --rte-media-overlay-bg: rgba(2, 8, 20, 0.72);
      --rte-media-bg: #202938;
      --rte-media-text: #e8effc;
      --rte-media-muted: #a5b1c5;
      --rte-media-border: #49566c;
      --rte-media-surface: #2a3444;
      --rte-media-surface-hover: #344256;
      --rte-media-accent: #58a6ff;
      --rte-media-accent-hover: #4598f4;
      --rte-media-danger: #ff7b72;
      --rte-media-danger-hover: #ff645b;
      --rte-media-ring: rgba(88, 166, 255, 0.22);
    }

    .rte-media-dialog {
      width: min(92vw, 640px);
      max-height: 90vh;
      display: flex;
      flex-direction: column;
      overflow: hidden;
      background: var(--rte-media-bg);
      color: var(--rte-media-text);
      border: 1px solid var(--rte-media-border);
      border-radius: 12px;
      box-shadow: 0 24px 48px rgba(10, 15, 24, 0.28);
    }

    .rte-media-dialog.rte-media-dialog-compact {
      width: min(92vw, 520px);
    }

    .rte-media-header {
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 16px 20px;
      border-bottom: 1px solid var(--rte-media-border);
      background: linear-gradient(180deg, rgba(127, 154, 195, 0.08) 0%, rgba(127, 154, 195, 0) 100%);
    }

    .rte-media-title {
      margin: 0;
      font-size: 18px;
      font-weight: 600;
      color: var(--rte-media-text);
    }

    .rte-media-close-btn {
      width: 32px;
      height: 32px;
      border: none;
      border-radius: 8px;
      background: transparent;
      color: var(--rte-media-muted);
      font-size: 24px;
      line-height: 1;
      cursor: pointer;
      transition: background-color 0.16s ease, color 0.16s ease;
    }

    .rte-media-close-btn:hover {
      background: var(--rte-media-surface-hover);
      color: var(--rte-media-text);
    }

    .rte-media-tabs {
      display: grid;
      grid-template-columns: 1fr 1fr;
      border-bottom: 1px solid var(--rte-media-border);
      gap: 0;
    }

    .rte-media-tab {
      border: none;
      border-right: 1px solid var(--rte-media-border);
      padding: 12px 14px;
      background: var(--rte-media-surface);
      color: var(--rte-media-muted);
      font-size: 14px;
      font-weight: 600;
      cursor: pointer;
      transition: background-color 0.16s ease, color 0.16s ease;
    }

    .rte-media-tab:last-child {
      border-right: none;
    }

    .rte-media-tab:hover {
      background: var(--rte-media-surface-hover);
      color: var(--rte-media-text);
    }

    .rte-media-tab.active {
      background: var(--rte-media-accent);
      color: #fff;
    }

    .rte-media-body {
      padding: 20px;
      overflow-y: auto;
      flex: 1;
    }

    .rte-media-field {
      margin-bottom: 16px;
    }

    .rte-media-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px;
      margin-bottom: 16px;
    }

    .rte-media-label {
      display: block;
      margin-bottom: 8px;
      color: var(--rte-media-text);
      font-size: 14px;
      font-weight: 600;
    }

    .rte-media-input,
    .rte-media-textarea {
      width: 100%;
      box-sizing: border-box;
      padding: 10px 12px;
      border: 1px solid var(--rte-media-border);
      border-radius: 8px;
      background: var(--rte-media-surface);
      color: var(--rte-media-text);
      font-size: 14px;
      transition: border-color 0.16s ease, box-shadow 0.16s ease;
    }

    .rte-media-input::placeholder,
    .rte-media-textarea::placeholder {
      color: var(--rte-media-muted);
    }

    .rte-media-input:focus,
    .rte-media-textarea:focus {
      outline: none;
      border-color: var(--rte-media-accent);
      box-shadow: 0 0 0 3px var(--rte-media-ring);
    }

    .rte-media-textarea {
      min-height: 92px;
      resize: vertical;
      font-family: inherit;
    }

    .rte-media-dropzone {
      border: 2px dashed var(--rte-media-border);
      border-radius: 12px;
      padding: 36px 18px;
      text-align: center;
      cursor: pointer;
      background: var(--rte-media-surface);
      transition: border-color 0.16s ease, background-color 0.16s ease;
    }

    .rte-media-dropzone:hover,
    .rte-media-dropzone.is-dragover {
      border-color: var(--rte-media-accent);
      background: var(--rte-media-surface-hover);
    }

    .rte-media-dropzone-icon {
      font-size: 40px;
      margin-bottom: 10px;
      line-height: 1;
    }

    .rte-media-dropzone-title {
      margin: 0 0 8px 0;
      font-size: 16px;
      font-weight: 600;
      color: var(--rte-media-text);
    }

    .rte-media-muted {
      margin: 0 0 8px 0;
      color: var(--rte-media-muted);
      font-size: 14px;
    }

    .rte-media-hint {
      margin: 0;
      color: var(--rte-media-muted);
      font-size: 12px;
    }

    .rte-media-progress {
      margin-top: 16px;
    }

    .rte-media-progress-track {
      height: 8px;
      border-radius: 999px;
      background: var(--rte-media-surface);
      overflow: hidden;
      border: 1px solid var(--rte-media-border);
    }

    .rte-media-progress-bar {
      height: 100%;
      width: 0;
      background: var(--rte-media-accent);
      transition: width 0.3s ease;
    }

    .rte-media-progress-text {
      margin-top: 8px;
      text-align: center;
      color: var(--rte-media-muted);
      font-size: 13px;
    }

    .rte-media-preview {
      border: 1px solid var(--rte-media-border);
      border-radius: 10px;
      padding: 10px;
      text-align: center;
      background: var(--rte-media-surface);
    }

    .rte-media-preview img,
    .rte-media-preview video {
      max-width: 100%;
      max-height: 240px;
    }

    .rte-media-helper {
      margin-top: 8px;
      margin-bottom: 0;
      font-size: 12px;
      color: var(--rte-media-muted);
      line-height: 1.5;
    }

    .rte-media-footer {
      display: flex;
      justify-content: flex-end;
      gap: 10px;
      padding: 16px 20px;
      border-top: 1px solid var(--rte-media-border);
      background: var(--rte-media-surface);
    }

    .rte-media-footer.rte-media-footer-spread {
      justify-content: space-between;
      align-items: center;
    }

    .rte-media-btn {
      border-radius: 8px;
      border: 1px solid transparent;
      padding: 10px 16px;
      font-size: 14px;
      font-weight: 600;
      cursor: pointer;
      transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
    }

    .rte-media-btn-secondary {
      background: var(--rte-media-bg);
      border-color: var(--rte-media-border);
      color: var(--rte-media-text);
    }

    .rte-media-btn-secondary:hover {
      background: var(--rte-media-surface-hover);
    }

    .rte-media-btn-primary {
      background: var(--rte-media-accent);
      color: #fff;
    }

    .rte-media-btn-primary:hover {
      background: var(--rte-media-accent-hover);
    }

    .rte-media-btn-primary:disabled {
      opacity: 0.55;
      cursor: not-allowed;
    }

    .rte-media-btn-danger {
      background: var(--rte-media-danger);
      color: #fff;
    }

    .rte-media-btn-danger:hover {
      background: var(--rte-media-danger-hover);
    }

    .rte-media-checkbox-label {
      display: inline-flex;
      align-items: center;
      gap: 8px;
      color: var(--rte-media-text);
      font-size: 14px;
      cursor: pointer;
    }

    .rte-media-checkbox-label input {
      accent-color: var(--rte-media-accent);
    }

    .rte-media-actions {
      display: flex;
      gap: 10px;
    }

    .rte-media-spacer {
      flex: 1;
    }

    .media-floating-toolbar {
      --rte-media-toolbar-bg: #ffffff;
      --rte-media-toolbar-border: #d6dbe4;
      --rte-media-toolbar-text: #344054;
      --rte-media-toolbar-hover-bg: #f3f6fb;
      --rte-media-toolbar-hover-text: #101828;
      --rte-media-toolbar-active-bg: #e6edf7;
      --rte-media-toolbar-separator: #d9e1eb;
      --rte-media-toolbar-danger-hover-bg: #fee2e2;
      --rte-media-toolbar-danger-hover-text: #b42318;
      position: absolute;
      display: none;
      align-items: center;
      gap: 2px;
      padding: 4px;
      border: 1px solid var(--rte-media-toolbar-border);
      border-radius: 8px;
      background: var(--rte-media-toolbar-bg);
      color: var(--rte-media-toolbar-text);
      box-shadow: 0 10px 24px rgba(15, 23, 36, 0.18);
      z-index: 10000;
      pointer-events: auto;
      backdrop-filter: blur(6px);
    }

    .media-floating-toolbar.rte-ui-theme-dark,
    ${W} .media-floating-toolbar {
      --rte-media-toolbar-bg: #24303f;
      --rte-media-toolbar-border: #4a5a71;
      --rte-media-toolbar-text: #d9e6fb;
      --rte-media-toolbar-hover-bg: #33445a;
      --rte-media-toolbar-hover-text: #f4f8ff;
      --rte-media-toolbar-active-bg: #415875;
      --rte-media-toolbar-separator: #566884;
      --rte-media-toolbar-danger-hover-bg: #5f2a32;
      --rte-media-toolbar-danger-hover-text: #ffd7d5;
      box-shadow: 0 16px 30px rgba(2, 8, 20, 0.42);
    }

    .media-floating-toolbar-btn {
      width: 30px;
      height: 30px;
      border: none;
      border-radius: 6px;
      background: transparent;
      color: inherit;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      transition: background-color 0.16s ease, color 0.16s ease, transform 0.12s ease;
    }

    .media-floating-toolbar-btn:hover {
      background: var(--rte-media-toolbar-hover-bg);
      color: var(--rte-media-toolbar-hover-text);
    }

    .media-floating-toolbar-btn:active {
      background: var(--rte-media-toolbar-active-bg);
      transform: scale(0.96);
    }

    .media-floating-toolbar-btn.btn-remove:hover {
      background: var(--rte-media-toolbar-danger-hover-bg);
      color: var(--rte-media-toolbar-danger-hover-text);
    }

    .media-floating-toolbar-separator {
      width: 1px;
      height: 20px;
      margin: 0 2px;
      background: var(--rte-media-toolbar-separator);
    }
  `,document.head.appendChild(e)},Y=()=>{const e=window.getSelection();if(!e||e.rangeCount===0)return null;const t=e.anchorNode;return(t instanceof HTMLElement?t:t?.parentElement)?.closest(".rte-content, .editora-content")||null},Z=e=>{if(e)return e;const t=Y();if(t)return t;if(T)return T;const r=document.activeElement;return r?r.closest(".rte-content, .editora-content")||r:null},O=e=>{const t=Z(e);return t?!!t.closest(W):!1},_=e=>{X();const t=document.createElement("div");return t.className="rte-media-overlay",O(e)&&t.classList.add("rte-ui-theme-dark"),t},H=(e=!1)=>{const t=document.createElement("div");return t.className=e?"rte-media-dialog rte-media-dialog-compact":"rte-media-dialog",t.setAttribute("role","dialog"),t.setAttribute("aria-modal","true"),t},F=(e,t)=>{const r=window.getSelection();r&&r.rangeCount>0&&(A=r.getRangeAt(0).cloneRange());const a=_(t),i=H();let o="upload",d="",l="",c="",g="";const v=()=>{i.innerHTML=`
      <div class="rte-media-header">
        <h2 class="rte-media-title">Insert ${e==="image"?"Image":"Video"}</h2>
        <button class="close-btn rte-media-close-btn" type="button" aria-label="Close">×</button>
      </div>

      <div class="rte-media-tabs">
        <button class="tab-upload rte-media-tab ${o==="upload"?"active":""}" type="button">Upload</button>
        <button class="tab-url rte-media-tab ${o==="url"?"active":""}" type="button">URL</button>
      </div>

      <div class="rte-media-body">
        ${o==="upload"?`
          <div id="upload-section">
            <div class="dropzone rte-media-dropzone">
              <div class="rte-media-dropzone-icon">📁</div>
              <p class="rte-media-dropzone-title">Drag and drop your ${e} here</p>
              <p class="rte-media-muted">or click to browse</p>
              <p class="rte-media-hint">Max file size: 50MB</p>
            </div>
            <input type="file" id="file-input" accept="${e==="image"?"image/*":"video/*"}" style="display: none;">
            <div id="upload-progress" class="rte-media-progress" style="display: none;">
              <div class="rte-media-progress-track">
                <div id="progress-bar" class="rte-media-progress-bar"></div>
              </div>
              <p id="progress-text" class="rte-media-progress-text">Uploading...</p>
            </div>
          </div>
        `:`
          <div id="url-section">
            <div class="rte-media-field">
              <label class="rte-media-label">URL</label>
              <input type="text" id="url-input" class="rte-media-input" placeholder="https://example.com/${e}.${e==="image"?"jpg":"mp4"}" value="${d}">
            </div>
            ${e==="image"?`
              <div class="rte-media-field">
                <label class="rte-media-label">Alt Text (for accessibility)</label>
                <input type="text" id="alt-input" class="rte-media-input" placeholder="Describe the image" value="${g}">
              </div>
            `:""}
            <div class="rte-media-grid">
              <div class="rte-media-field">
                <label class="rte-media-label">Width (px)</label>
                <input type="number" id="width-input" class="rte-media-input" placeholder="Auto" value="${l}">
              </div>
              <div class="rte-media-field">
                <label class="rte-media-label">Height (px)</label>
                <input type="number" id="height-input" class="rte-media-input" placeholder="Auto" value="${c}">
              </div>
            </div>
            ${d?`
              <div class="rte-media-field">
                <label class="rte-media-label">Preview</label>
                <div class="rte-media-preview">
                  ${e==="image"?`<img src="${d}" alt="Preview">`:`<video src="${d}" controls></video>`}
                </div>
              </div>
            `:""}
          </div>
        `}
      </div>

      <div class="rte-media-footer">
        <button class="cancel-btn rte-media-btn rte-media-btn-secondary" type="button">Cancel</button>
        <button id="insert-btn" class="rte-media-btn rte-media-btn-primary" type="button" ${!d&&o==="url"?"disabled":""}>Insert</button>
      </div>
    `};v(),a.appendChild(i),document.body.appendChild(a);let k=()=>{};const h=()=>{k(),a.parentNode&&a.parentNode.removeChild(a)};k=B(a,h);const L=()=>{if(!d)return;const n=e==="image"?document.createElement("img"):document.createElement("video");n.src=d,n.setAttribute("data-media-type",e),e==="image"&&g&&(n.alt=g),l&&(n.style.width=`${l}px`,n.setAttribute("width",l)),c&&(n.style.height=`${c}px`,n.setAttribute("height",c)),e==="video"&&(n.controls=!0),!l&&!c?n.style.cssText="max-width: 100%; height: auto; display: block; margin: 1em 0; cursor: pointer;":n.style.cssText=`display: block; margin: 1em 0; cursor: pointer; ${l?`width: ${l}px;`:"max-width: 100%;"} ${c?`height: ${c}px;`:"height: auto;"}`,A&&(A.deleteContents(),A.insertNode(n)),h()},x=async n=>{const b=i.querySelector("#upload-progress"),u=i.querySelector("#progress-bar"),y=i.querySelector("#progress-text");if(b&&u&&y){b.style.display="block";let q=0;const f=setInterval(()=>{q+=Math.random()*30,q>90&&(q=90),u.style.width=`${q}%`},200);try{const w=new FileReader;w.onload=()=>{clearInterval(f),u.style.width="100%",y.textContent="Upload complete",setTimeout(()=>{d=w.result,o="url",v(),m()},500)},w.readAsDataURL(n)}catch{clearInterval(f),y.textContent="Upload failed"}}},m=()=>{const n=i.querySelector(".close-btn"),b=i.querySelector(".cancel-btn"),u=i.querySelector("#insert-btn"),y=i.querySelector(".tab-upload"),q=i.querySelector(".tab-url");if(n?.addEventListener("click",h),b?.addEventListener("click",h),u?.addEventListener("click",L),y?.addEventListener("click",()=>{o="upload",v(),m()}),q?.addEventListener("click",()=>{o="url",v(),m()}),o==="upload"){const f=i.querySelector(".dropzone"),w=i.querySelector("#file-input");f?.addEventListener("click",()=>w?.click()),f?.addEventListener("dragover",S=>{S.preventDefault(),f.classList.add("is-dragover")}),f?.addEventListener("dragleave",()=>{f.classList.remove("is-dragover")}),f?.addEventListener("drop",S=>{S.preventDefault(),f.classList.remove("is-dragover");const z=S.dataTransfer?.files[0];z&&x(z)}),w?.addEventListener("change",S=>{const z=S.target.files?.[0];z&&x(z)})}if(o==="url"){const f=i.querySelector("#url-input"),w=i.querySelector("#alt-input"),S=i.querySelector("#width-input"),z=i.querySelector("#height-input");f?.addEventListener("input",()=>{d=f.value,v(),m()}),w?.addEventListener("input",()=>{g=w.value}),S?.addEventListener("input",()=>{l=S.value}),z?.addEventListener("input",()=>{c=z.value})}};m(),a.addEventListener("click",n=>{n.target===a&&h()})},K=()=>{["nw","ne","sw","se"].forEach(t=>{const r=document.createElement("div");r.className=`media-resize-handle-${t}`,r.style.cssText=`
      position: fixed;
      width: 10px;
      height: 10px;
      background: #007bff;
      border: 2px solid white;
      border-radius: 50%;
      cursor: ${t}-resize;
      z-index: 10001;
      display: none;
      box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    `,r.setAttribute("data-position",t),document.body.appendChild(r),R.push(r)})},M=()=>{if(!p){R.forEach(r=>r.style.display="none");return}const e=p.getBoundingClientRect(),t={nw:{x:e.left-5,y:e.top-5},ne:{x:e.right-5,y:e.top-5},sw:{x:e.left-5,y:e.bottom-5},se:{x:e.right-5,y:e.bottom-5}};R.forEach(r=>{const a=r.getAttribute("data-position"),i=t[a];r.style.left=`${i.x}px`,r.style.top=`${i.y}px`,r.style.display="block"})},J=e=>{const t=_(e),r=H(!0);r.innerHTML=`
    <div class="rte-media-header">
      <h2 class="rte-media-title">Edit Alt Text</h2>
      <button class="close-btn rte-media-close-btn" type="button" aria-label="Close">×</button>
    </div>
    <div class="rte-media-body">
      <label class="rte-media-label">Alternative Text (for accessibility)</label>
      <textarea id="alt-text-input" class="rte-media-textarea" placeholder="Describe the image for screen readers...">${e.alt||""}</textarea>
      <p class="rte-media-helper">Good alt text is descriptive and concise. It helps users with visual impairments understand your content.</p>
    </div>
    <div class="rte-media-footer">
      <button class="cancel-btn rte-media-btn rte-media-btn-secondary" type="button">Cancel</button>
      <button class="save-btn rte-media-btn rte-media-btn-primary" type="button">Save</button>
    </div>
  `,t.appendChild(r),document.body.appendChild(t);const a=r.querySelector("#alt-text-input"),i=r.querySelector(".close-btn"),o=r.querySelector(".cancel-btn"),d=r.querySelector(".save-btn");let l=()=>{};const c=()=>{l(),t.parentNode&&t.parentNode.removeChild(t)};l=B(t,c),i.addEventListener("click",c),o.addEventListener("click",c),t.addEventListener("click",g=>{g.target===t&&c()}),d.addEventListener("click",()=>{e.alt=a.value,c()}),a.focus(),a.select()},Q=e=>{const t=e.closest("a"),r=t?.getAttribute("href")||"",a=t?.getAttribute("target")||"_self",i=t?.getAttribute("title")||"",o=_(e),d=H(!0);d.innerHTML=`
    <div class="rte-media-header">
      <h2 class="rte-media-title">${t?"Edit Link":"Add Link"}</h2>
      <button class="close-btn rte-media-close-btn" type="button" aria-label="Close">×</button>
    </div>
    <div class="rte-media-body">
      <div class="rte-media-field">
        <label class="rte-media-label">URL</label>
        <input id="link-url" type="url" class="rte-media-input" value="${r}" placeholder="https://example.com" />
      </div>
      <div class="rte-media-field">
        <label class="rte-media-label">Title (tooltip)</label>
        <input id="link-title" type="text" class="rte-media-input" value="${i}" placeholder="Optional tooltip text" />
      </div>
      <label class="rte-media-checkbox-label">
        <input id="link-target" type="checkbox" ${a==="_blank"?"checked":""} />
        Open in new window/tab
      </label>
    </div>
    <div class="rte-media-footer rte-media-footer-spread">
      ${t?'<button class="remove-link-btn rte-media-btn rte-media-btn-danger" type="button">Remove Link</button>':'<span class="rte-media-spacer"></span>'}
      <div class="rte-media-actions">
        <button class="cancel-btn rte-media-btn rte-media-btn-secondary" type="button">Cancel</button>
        <button class="save-btn rte-media-btn rte-media-btn-primary" type="button">Save</button>
      </div>
    </div>
  `,o.appendChild(d),document.body.appendChild(o);const l=d.querySelector("#link-url"),c=d.querySelector("#link-title"),g=d.querySelector("#link-target"),v=d.querySelector(".close-btn"),k=d.querySelector(".cancel-btn"),h=d.querySelector(".save-btn"),L=d.querySelector(".remove-link-btn");let x=()=>{};const m=()=>{x(),o.parentNode&&o.parentNode.removeChild(o)};x=B(o,m),v.addEventListener("click",m),k.addEventListener("click",m),o.addEventListener("click",n=>{n.target===o&&m()}),h.addEventListener("click",()=>{const n=l.value.trim();if(n){const b=n.startsWith("http")?n:`https://${n}`;if(t)t.setAttribute("href",b),t.setAttribute("target",g.checked?"_blank":"_self"),g.checked?t.setAttribute("rel","noopener noreferrer"):t.removeAttribute("rel"),c.value.trim()?t.setAttribute("title",c.value.trim()):t.removeAttribute("title");else{const u=document.createElement("a");u.href=b,u.target=g.checked?"_blank":"_self",g.checked&&(u.rel="noopener noreferrer"),c.value.trim()&&(u.title=c.value.trim()),e.replaceWith(u),u.appendChild(e)}m(),s&&p&&U(p)}}),L?.addEventListener("click",()=>{t&&confirm("Remove link from this media?")&&(t.replaceWith(e),m(),s&&p&&U(p))}),l.focus()},ee=e=>{const t=_(e),r=H();let a="url",i=e.src;const o=()=>{r.innerHTML=`
      <div class="rte-media-header">
        <h2 class="rte-media-title">Replace Image</h2>
        <button class="close-btn rte-media-close-btn" type="button" aria-label="Close">×</button>
      </div>

      <div class="rte-media-tabs">
        <button class="tab-upload rte-media-tab ${a==="upload"?"active":""}" type="button">Upload</button>
        <button class="tab-url rte-media-tab ${a==="url"?"active":""}" type="button">URL</button>
      </div>

      <div class="rte-media-body">
        ${a==="upload"?`
          <div id="upload-section">
            <div class="dropzone rte-media-dropzone">
              <div class="rte-media-dropzone-icon">📁</div>
              <p class="rte-media-dropzone-title">Drag and drop your image here</p>
              <p class="rte-media-muted">or click to browse</p>
            </div>
            <input type="file" id="file-input" accept="image/*" style="display: none;">
            <div id="upload-progress" class="rte-media-progress" style="display: none;">
              <div class="rte-media-progress-track">
                <div id="progress-bar" class="rte-media-progress-bar"></div>
              </div>
              <p id="progress-text" class="rte-media-progress-text">Uploading...</p>
            </div>
          </div>
        `:`
          <div id="url-section">
            <div class="rte-media-field">
              <label class="rte-media-label">Image URL</label>
              <input type="text" id="url-input" class="rte-media-input" placeholder="https://example.com/image.jpg" value="${i}">
            </div>
            ${i?`
              <div class="rte-media-field">
                <label class="rte-media-label">Preview</label>
                <div class="rte-media-preview">
                  <img src="${i}" alt="Preview" onerror="this.parentElement.innerHTML='<p class=&quot;rte-media-muted&quot;>Failed to load image</p>'">
                </div>
              </div>
            `:""}
          </div>
        `}
      </div>

      <div class="rte-media-footer">
        <button class="cancel-btn rte-media-btn rte-media-btn-secondary" type="button">Cancel</button>
        <button id="replace-btn" class="rte-media-btn rte-media-btn-primary" type="button" ${!i&&a==="url"?"disabled":""}>Replace</button>
      </div>
    `};o(),t.appendChild(r),document.body.appendChild(t);let d=()=>{};const l=()=>{d(),t.parentNode&&t.parentNode.removeChild(t)};d=B(t,l);const c=()=>{i&&(e.src=i,l())},g=async k=>{const h=r.querySelector("#upload-progress"),L=r.querySelector("#progress-bar"),x=r.querySelector("#progress-text");if(h&&L&&x){h.style.display="block";let m=0;const n=setInterval(()=>{m+=Math.random()*30,m>90&&(m=90),L.style.width=`${m}%`},200);try{const b=new FileReader;b.onload=()=>{clearInterval(n),L.style.width="100%",x.textContent="Upload complete",setTimeout(()=>{i=b.result,a="url",o(),v()},500)},b.readAsDataURL(k)}catch{clearInterval(n),x.textContent="Upload failed"}}},v=()=>{const k=r.querySelector(".close-btn"),h=r.querySelector(".cancel-btn"),L=r.querySelector("#replace-btn"),x=r.querySelector(".tab-upload"),m=r.querySelector(".tab-url");if(k?.addEventListener("click",l),h?.addEventListener("click",l),L?.addEventListener("click",c),x?.addEventListener("click",()=>{a="upload",o(),v()}),m?.addEventListener("click",()=>{a="url",o(),v()}),a==="upload"){const n=r.querySelector(".dropzone"),b=r.querySelector("#file-input");n?.addEventListener("click",()=>b?.click()),n?.addEventListener("dragover",u=>{u.preventDefault(),n.classList.add("is-dragover")}),n?.addEventListener("dragleave",()=>{n.classList.remove("is-dragover")}),n?.addEventListener("drop",u=>{u.preventDefault(),n.classList.remove("is-dragover");const y=u.dataTransfer?.files[0];y&&g(y)}),b?.addEventListener("change",u=>{const y=u.target.files?.[0];y&&g(y)})}if(a==="url"){const n=r.querySelector("#url-input");n?.addEventListener("input",()=>{i=n.value,o(),v()})}};v(),t.addEventListener("click",k=>{k.target===t&&l()})},E=()=>{if(!s||!p)return;const e=s.offsetHeight||40,t=p.offsetTop,r=p.offsetLeft,a=p.offsetWidth,i=t-e-8,o=r+a/2-(s.offsetWidth||120)/2;s.style.top=`${i}px`,s.style.left=`${o}px`,setTimeout(()=>{s&&(s.style.display="flex")},100)},U=e=>{s&&(s._cleanup&&s._cleanup(),s.remove());const t=e.parentElement;if(t){const l=t.style.position;(!l||l==="static")&&(t.style.position="relative",t._originalPosition=l),s=document.createElement("div"),s.className="media-floating-toolbar",O(e)&&s.classList.add("rte-ui-theme-dark"),t.insertBefore(s,t.firstChild),E()}const r=s;if(!r)return;const a=e.tagName==="IMG",i=e.closest("a");r.innerHTML=`
    <button class="media-floating-toolbar-btn btn-align-left" title="Align Left" type="button">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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></svg>
    </button>
    <button class="media-floating-toolbar-btn btn-align-center" title="Align Center" type="button">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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></svg>
    </button>
    <button class="media-floating-toolbar-btn btn-align-right" title="Align Right" type="button">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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></svg>
    </button>
    <div class="media-floating-toolbar-separator" aria-hidden="true"></div>
    ${a?`
    <button class="media-floating-toolbar-btn btn-alt" title="Edit Alt Text" type="button">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"></path></svg>
    </button>`:""}
    <button class="media-floating-toolbar-btn btn-link" title="${i?"Edit/Remove Link":"Add Link"}" type="button">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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></svg>
    </button>
    ${a?`
    <button class="media-floating-toolbar-btn btn-replace" title="Replace Image" type="button">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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></svg>
    </button>`:""}
    <div class="media-floating-toolbar-separator" aria-hidden="true"></div>
    <button class="media-floating-toolbar-btn btn-remove" title="Remove" type="button">
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><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></svg>
    </button>
  `,setTimeout(()=>{E()},0);const o=()=>E();let d=e.parentElement;for(;d;)d.addEventListener("scroll",o),d=d.parentElement;window.addEventListener("scroll",o),window.addEventListener("resize",o),r._cleanup=()=>{let l=e.parentElement;for(;l;)l.removeEventListener("scroll",o),l=l.parentElement;window.removeEventListener("scroll",o),window.removeEventListener("resize",o)},r.querySelector(".btn-align-left")?.addEventListener("click",()=>{e.style.display="block",e.style.marginLeft="0",e.style.marginRight="auto",E()}),r.querySelector(".btn-align-center")?.addEventListener("click",()=>{e.style.display="block",e.style.marginLeft="auto",e.style.marginRight="auto",E()}),r.querySelector(".btn-align-right")?.addEventListener("click",()=>{e.style.display="block",e.style.marginLeft="auto",e.style.marginRight="0",E()}),r.querySelector(".btn-alt")?.addEventListener("click",()=>{e.tagName==="IMG"&&J(e)}),r.querySelector(".btn-link")?.addEventListener("click",()=>{Q(e)}),r.querySelector(".btn-replace")?.addEventListener("click",()=>{e.tagName==="IMG"&&ee(e)}),r.querySelector(".btn-resize")?.addEventListener("click",()=>{const l=prompt("Enter width in pixels:",String(e.width||e.offsetWidth));if(l&&!isNaN(parseInt(l))){const c=parseInt(l);e.style.width=`${c}px`,e.setAttribute("width",String(c)),M(),E()}}),r.querySelector(".btn-remove")?.addEventListener("click",()=>{confirm("Remove this media?")&&(e.remove(),s&&(s._cleanup&&s._cleanup(),s.remove(),s=null),p=null,M())}),r._cleanup=()=>{window.removeEventListener("scroll",E),window.removeEventListener("resize",E)}},G=e=>{T=e||null,K(),document.addEventListener("click",t=>{const r=t.target;if(r.tagName==="IMG"||r.tagName==="VIDEO"){const a=r;let i=!1;if(T?i=T.contains(a):i=!!a.closest('[contenteditable="true"]'),i){t.preventDefault(),t.stopPropagation(),p=a,p.style.display="block",U(a),M();return}}if(!r.closest(".btn-link, .btn-resize, .btn-remove")&&s&&!r.closest("button")){if(s._cleanup&&s._cleanup(),s.remove(),s=null,p&&p.parentElement){const a=p.parentElement;a._originalPosition!==void 0&&(a.style.position=a._originalPosition,delete a._originalPosition)}p=null,M()}}),R.forEach(t=>{t.addEventListener("mousedown",r=>{if(!p)return;r.preventDefault(),r.stopPropagation(),D=!0,I=t.getAttribute("data-position"),V=r.clientX,j=r.clientY;const a=p.getBoundingClientRect();C=a.width,$=a.height,N=C/$,document.body.style.userSelect="none",document.body.style.cursor=`${I}-resize`})}),document.addEventListener("mousemove",t=>{if(!D||!p||!I)return;const r=t.clientX-V,a=t.clientY-j;let i=C,o=$;switch(I){case"se":i=C+r,o=$+a;break;case"sw":i=C-r,o=$+a;break;case"ne":i=C+r,o=$-a;break;case"nw":i=C-r,o=$-a;break}Math.abs(r)>Math.abs(a)?o=i/N:i=o*N,i=Math.max(50,i),o=Math.max(50,o),p.style.width=`${i}px`,p.style.height=`${o}px`,p.setAttribute("width",String(Math.round(i))),p.setAttribute("height",String(Math.round(o))),M(),E()}),document.addEventListener("mouseup",()=>{D&&(D=!1,I=null,document.body.style.userSelect="",document.body.style.cursor="")}),window.addEventListener("scroll",M),window.addEventListener("resize",M)};typeof window<"u"&&!window.__mediaManagerInitialized&&(window.__mediaManagerInitialized=!0,G());const te=()=>({name:"image",initialize:e=>{const t=e?.editorElement;G(t)},toolbar:[{label:"Image",command:"insertImage",icon:'<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>'},{label:"Video",command:"insertVideo",icon:'<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>'}],commands:{insertImage:(e,t)=>{const r=t?.contentElement instanceof HTMLElement?t.contentElement:void 0;return F("image",r),!0},insertVideo:(e,t)=>{const r=t?.contentElement instanceof HTMLElement?t.contentElement:void 0;return F("video",r),!0}},keymap:{"Mod-Shift-i":"insertImage"}}),re={apiEndpoints:{upload:"/media/upload",library:"/media/library",delete:"/media/library"},maxFileSize:10*1024*1024,allowedTypes:["image/jpeg","image/png","image/gif","video/mp4","video/webm"],headers:{}};let P={...re};function ae(e){P={...P,...e}}function ie(){return{...P}}exports.MediaManagerPlugin=te;exports.getMediaManagerConfig=ie;exports.setMediaManagerConfig=ae;
