var g = Object.defineProperty;
var U = (r, t, e) => t in r ? g(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e;
var c = (r, t, e) => U(r, typeof t != "symbol" ? t + "" : t, e);
import { Q as b } from "./index-U54PFR25.js";
const w = b.import("blots/block/embed"), p = b.import("formats/link"), f = ["height", "width"], E = new Set(f), l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map(), h = [/(?:youtube\.com\/watch\?(?:.*&)?v=|youtu\.be\/)([a-z0-9_-]+)/i, /youtube\.com\/embed\/([a-z0-9_-]+)/i, /youtube\.com\/shorts\/([a-z0-9_-]+)/i], A = /vimeo\.com\/(?:video\/)?(\d+)/i;
function m(r) {
  if (u.has(r)) return u.get(r) ?? null;
  const t = p.sanitize(r), e = !t || t === "about:blank" ? null : t;
  return u.set(r, e), e;
}
function z(r) {
  const t = r.trim();
  return t ? h.some((e) => e.test(t)) ? !0 : A.test(t) : !1;
}
const N = (r) => {
  const t = r.trim(), e = l.get(t);
  if (e) return e;
  for (const s of h) {
    const i = s.exec(t);
    if (i != null && i[1]) {
      const a = `https://www.youtube.com/embed/${i[1]}`;
      return l.set(t, a), a;
    }
  }
  const o = A.exec(t);
  if (o != null && o[1]) {
    const s = `https://player.vimeo.com/video/${o[1]}`;
    return l.set(t, s), s;
  }
  return l.set(t, t), t;
}, n = class n extends w {
  static create(t) {
    const e = N(t), o = m(e) ?? m(t) ?? "about:blank", s = super.create(o);
    return s.setAttribute("frameborder", "0"), s.setAttribute("allowfullscreen", "true"), s.setAttribute("loading", "lazy"), s.setAttribute("src", o), s;
  }
  static formats(t) {
    return f.reduce((e, o) => (t.hasAttribute(o) && (e[o] = t.getAttribute(o)), e), {});
  }
  static value(t) {
    return t.getAttribute("src") ?? "";
  }
  format(t, e) {
    if (E.has(t)) {
      e ? this.domNode.setAttribute(t, e) : this.domNode.removeAttribute(t);
      return;
    }
    super.format(t, e);
  }
  html() {
    const t = n.value(this.domNode), e = this.domNode.getAttribute("width"), o = this.domNode.getAttribute("height"), s = this.domNode.getAttribute("style"), i = this.domNode.getAttribute("loading");
    return `<iframe ${['class="ql-video"', 'frameborder="0"', 'allowfullscreen="true"', `src="${t}"`, e ? `width="${e}"` : "", o ? `height="${o}"` : "", s ? `style="${s}"` : "", i ? `loading="${i}"` : ""].filter(Boolean).join(" ")}></iframe>`;
  }
};
c(n, "blotName", "video"), c(n, "className", "ql-video"), c(n, "tagName", "IFRAME");
let d = n;
export {
  d as default,
  z as isVideoUrl,
  N as normalizeVideoUrl
};
