"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/iframe/get-compatibility-styles.js
var get_compatibility_styles_exports = {};
__export(get_compatibility_styles_exports, {
  getCompatibilityStyles: () => getCompatibilityStyles
});
module.exports = __toCommonJS(get_compatibility_styles_exports);
var compatibilityStyles = null;
function getCompatibilityStyles() {
  if (compatibilityStyles) {
    return compatibilityStyles;
  }
  compatibilityStyles = Array.from(document.styleSheets).reduce(
    (accumulator, styleSheet) => {
      try {
        styleSheet.cssRules;
      } catch (e) {
        return accumulator;
      }
      const { ownerNode, cssRules } = styleSheet;
      if (ownerNode === null) {
        return accumulator;
      }
      if (!cssRules) {
        return accumulator;
      }
      if (ownerNode.id.startsWith("wp-")) {
        return accumulator;
      }
      if (!ownerNode.id) {
        return accumulator;
      }
      function matchFromRules(_cssRules) {
        return Array.from(_cssRules).find(
          ({
            selectorText,
            conditionText,
            cssRules: __cssRules
          }) => {
            if (conditionText) {
              return matchFromRules(__cssRules);
            }
            return selectorText && (selectorText.includes(
              ".editor-styles-wrapper"
            ) || selectorText.includes(".wp-block"));
          }
        );
      }
      if (matchFromRules(cssRules)) {
        const isInline = ownerNode.tagName === "STYLE";
        if (isInline) {
          const mainStylesCssId = ownerNode.id.replace(
            "-inline-css",
            "-css"
          );
          const mainStylesElement = document.getElementById(mainStylesCssId);
          if (mainStylesElement) {
            accumulator.push(mainStylesElement.cloneNode(true));
          }
        }
        accumulator.push(ownerNode.cloneNode(true));
        if (!isInline) {
          const inlineStylesCssId = ownerNode.id.replace(
            "-css",
            "-inline-css"
          );
          const inlineStylesElement = document.getElementById(inlineStylesCssId);
          if (inlineStylesElement) {
            accumulator.push(
              inlineStylesElement.cloneNode(true)
            );
          }
        }
      }
      return accumulator;
    },
    []
  );
  return compatibilityStyles;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getCompatibilityStyles
});
//# sourceMappingURL=get-compatibility-styles.js.map
