"use strict";

// packages/block-editor/src/hooks/cross-origin-isolation.js
var import_hooks = require("@wordpress/hooks");
var import_compose = require("@wordpress/compose");
var import_jsx_runtime = require("react/jsx-runtime");
function addCrossOriginAttributes(el) {
  if (!el.hasAttribute("crossorigin")) {
    el.setAttribute("crossorigin", "anonymous");
  }
  if (el.nodeName === "IFRAME" && !el.hasAttribute("credentialless")) {
    if (el.getAttribute("src")?.startsWith("blob:")) {
      return;
    }
    el.setAttribute("credentialless", "");
    const origSrc = el.getAttribute("src") || "";
    el.setAttribute("src", "");
    el.setAttribute("src", origSrc);
  }
}
if (window.crossOriginIsolated) {
  let startObservingBody = function() {
    if (document.body) {
      observer.observe(document.body, {
        childList: true,
        attributes: true,
        subtree: true
      });
    } else if (document.readyState === "loading") {
      document.addEventListener("DOMContentLoaded", () => {
        if (document.body) {
          observer.observe(document.body, {
            childList: true,
            attributes: true,
            subtree: true
          });
        }
      });
    }
  };
  startObservingBody2 = startObservingBody;
  const observer = new window.MutationObserver((mutations) => {
    mutations.forEach((mutation) => {
      [mutation.addedNodes, mutation.target].forEach((value) => {
        const nodes = value instanceof window.NodeList ? value : [value];
        nodes.forEach((node) => {
          const el = node;
          if (!el.querySelectorAll) {
            return;
          }
          el.querySelectorAll(
            "img,source,script,video,link,iframe"
          ).forEach((v) => {
            addCrossOriginAttributes(v);
          });
          if (el.nodeName === "IFRAME") {
            const iframeNode = el;
            const isEmbedSandboxIframe = iframeNode.classList.contains(
              "components-sandbox"
            );
            if (!isEmbedSandboxIframe) {
              iframeNode.addEventListener("load", () => {
                try {
                  if (iframeNode.contentDocument && iframeNode.contentDocument.body) {
                    observer.observe(
                      iframeNode.contentDocument,
                      {
                        childList: true,
                        attributes: true,
                        subtree: true
                      }
                    );
                  }
                } catch (e) {
                }
              });
            }
          }
          if ([
            "IMG",
            "SOURCE",
            "SCRIPT",
            "VIDEO",
            "LINK",
            "IFRAME"
          ].includes(el.nodeName)) {
            addCrossOriginAttributes(el);
          }
        });
      });
    });
  });
  startObservingBody();
}
var startObservingBody2;
if (window.crossOriginIsolated) {
  const supportsCredentialless = "credentialless" in window.HTMLIFrameElement.prototype;
  const disableEmbedPreviews = (0, import_compose.createHigherOrderComponent)(
    (BlockEdit) => function DisableEmbedPreviews(props) {
      if ("core/embed" !== props.name) {
        return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlockEdit, { ...props });
      }
      const previewable = supportsCredentialless && !["facebook", "smugmug"].includes(
        props.attributes.providerNameSlug
      );
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
        BlockEdit,
        {
          ...props,
          attributes: { ...props.attributes, previewable }
        }
      );
    },
    "withDisabledEmbedPreview"
  );
  (0, import_hooks.addFilter)(
    "editor.BlockEdit",
    "media-experiments/disable-embed-previews",
    disableEmbedPreviews
  );
}
//# sourceMappingURL=cross-origin-isolation.cjs.map
