// packages/block-editor/src/components/iframe/get-compatibility-styles.js
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;
}
export {
  getCompatibilityStyles
};
//# sourceMappingURL=get-compatibility-styles.js.map
