"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/block-editor/src/components/rich-text/get-rich-text-values.js
var get_rich_text_values_exports = {};
__export(get_rich_text_values_exports, {
  getRichTextValues: () => getRichTextValues
});
module.exports = __toCommonJS(get_rich_text_values_exports);
var import_element = require("@wordpress/element");
var import_blocks = require("@wordpress/blocks");
var import_rich_text = require("@wordpress/rich-text");
var import_inner_blocks = __toESM(require("../inner-blocks"));
var import_content = require("./content");
var import_jsx_runtime = (
  // Instead of letting save elements use `useInnerBlocksProps.save`,
  // force them to use InnerBlocks.Content instead so we can intercept
  // a single component.
  require("react/jsx-runtime")
);
function addValuesForElement(element, values, innerBlocks) {
  if (null === element || void 0 === element || false === element) {
    return;
  }
  if (Array.isArray(element)) {
    return addValuesForElements(element, values, innerBlocks);
  }
  switch (typeof element) {
    case "string":
    case "number":
      return;
  }
  const { type, props } = element;
  switch (type) {
    case import_element.StrictMode:
    case import_element.Fragment:
      return addValuesForElements(props.children, values, innerBlocks);
    case import_element.RawHTML:
      return;
    case import_inner_blocks.default.Content:
      return addValuesForBlocks(values, innerBlocks);
    case import_content.Content:
      values.push(props.value);
      return;
  }
  switch (typeof type) {
    case "string":
      if (typeof props.children !== "undefined") {
        return addValuesForElements(
          props.children,
          values,
          innerBlocks
        );
      }
      return;
    case "function":
      const el = type.prototype && typeof type.prototype.render === "function" ? new type(props).render() : type(props);
      return addValuesForElement(el, values, innerBlocks);
  }
}
function addValuesForElements(children, ...args) {
  children = Array.isArray(children) ? children : [children];
  for (let i = 0; i < children.length; i++) {
    addValuesForElement(children[i], ...args);
  }
}
function addValuesForBlocks(values, blocks) {
  for (let i = 0; i < blocks.length; i++) {
    const { name, attributes, innerBlocks } = blocks[i];
    const saveElement = (0, import_blocks.getSaveElement)(
      name,
      attributes,
      /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_inner_blocks.default.Content, {})
    );
    addValuesForElement(saveElement, values, innerBlocks);
  }
}
function getRichTextValues(blocks = []) {
  import_blocks.__unstableGetBlockProps.skipFilters = true;
  const values = [];
  addValuesForBlocks(values, blocks);
  import_blocks.__unstableGetBlockProps.skipFilters = false;
  return values.map(
    (value) => value instanceof import_rich_text.RichTextData ? value : import_rich_text.RichTextData.fromHTMLString(value)
  );
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  getRichTextValues
});
//# sourceMappingURL=get-rich-text-values.js.map
