"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);
var gap_spacer_nodes_exports = {};
__export(gap_spacer_nodes_exports, {
  isBetweenFloatedNodes: () => isBetweenFloatedNodes,
  isBetweenFullWidthNodes: () => isBetweenFullWidthNodes,
  isCollapsedBetween: () => isCollapsedBetween,
  isListContainer: () => isListContainer,
  isNodeFloated: () => isNodeFloated,
  isNodeFullWidth: () => isNodeFullWidth,
  isNodeSpaced: () => isNodeSpaced,
  needsTopMargin: () => needsTopMargin,
  needsTopMarginForPmNode: () => needsTopMarginForPmNode
});
module.exports = __toCommonJS(gap_spacer_nodes_exports);
var import_ricos_content = require("./../../ricos-content/index.js");
var import_v1 = require("./../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_node_styles = require("./../../_shared/node-styles.js");
var import_pm_node_types = require("./../../_shared/pm-node-types.js");
const LIST_CONTAINER_TYPES = [
  import_v1.Node_Type.BULLETED_LIST,
  import_v1.Node_Type.CHECKBOX_LIST,
  import_v1.Node_Type.ORDERED_LIST
];
const CLOSED_FOR_SPACING_TYPES = [
  import_ricos_content.TIPTAP_FIGURE_TYPE,
  import_ricos_content.TIPTAP_LINK_BUTTON_TYPE,
  import_ricos_content.TIPTAP_ACTION_BUTTON_TYPE,
  import_v1.Node_Type.IMAGE,
  import_v1.Node_Type.VIDEO,
  import_v1.Node_Type.GALLERY,
  import_v1.Node_Type.DIVIDER,
  import_v1.Node_Type.HTML,
  import_v1.Node_Type.EMBED,
  import_v1.Node_Type.FILE,
  import_v1.Node_Type.GIF,
  import_v1.Node_Type.AUDIO,
  import_v1.Node_Type.POLL,
  import_v1.Node_Type.BUTTON,
  ...LIST_CONTAINER_TYPES,
  import_v1.Node_Type.LIST_ITEM,
  import_v1.Node_Type.LINK_PREVIEW,
  import_v1.Node_Type.APP_EMBED,
  import_v1.Node_Type.CODE_BLOCK,
  import_v1.Node_Type.BLOCKQUOTE,
  import_v1.Node_Type.TABLE,
  import_v1.Node_Type.TABLE_CELL,
  import_v1.Node_Type.LAYOUT,
  import_v1.Node_Type.LAYOUT_CELL,
  import_v1.Node_Type.COLLAPSIBLE_LIST,
  import_v1.Node_Type.COLLAPSIBLE_ITEM_BODY,
  import_v1.Node_Type.SHAPE,
  import_v1.Node_Type.SMART_BLOCK
];
const isNodeSpaced = (nodeType) => CLOSED_FOR_SPACING_TYPES.includes(nodeType);
const isListContainer = (nodeType) => !!nodeType && LIST_CONTAINER_TYPES.includes(nodeType);
const NODES_WITH_TOP_OVERFLOW = [
  import_v1.Node_Type.IMAGE,
  import_v1.Node_Type.SHAPE,
  import_v1.Node_Type.LAYOUT
];
const needsTopMargin = (nodeType) => nodeType ? NODES_WITH_TOP_OVERFLOW.includes(nodeType) : false;
const needsTopMarginForPmNode = (node) => {
  if (!node) {
    return false;
  }
  const nodeType = node.type.name;
  if (NODES_WITH_TOP_OVERFLOW.includes(nodeType)) {
    return true;
  }
  if (nodeType === import_ricos_content.TIPTAP_FIGURE_TYPE) {
    const firstChild = node.firstChild;
    return firstChild?.type.name === import_v1.Node_Type.IMAGE;
  }
  return false;
};
const isCollapsedBetween = (firstNodeType, secondNodeType, parentNodeType, options) => {
  const isEdgeNode = !firstNodeType || !secondNodeType;
  if (isEdgeNode && parentNodeType !== import_v1.Node_Type.LIST_ITEM) {
    return true;
  }
  if (options?.bothFullWidth) {
    return true;
  }
  return false;
};
const getNodeContainerData = (node) => {
  if ("attrs" in node && node.attrs) {
    if (node.type.name === import_pm_node_types.PmNodeType.FIGURE) {
      return node.firstChild?.attrs?.containerData;
    }
    return node.attrs.containerData;
  }
  if ("type" in node && "id" in node) {
    return (0, import_node_styles.getContainerData)(node);
  }
  return null;
};
const isNodeFloated = (node) => {
  if (!node) {
    return false;
  }
  const containerData = getNodeContainerData(node);
  const hasTextWrap = containerData?.textWrap ?? true;
  const isFloatableAlignment = containerData?.alignment === "LEFT" || containerData?.alignment === "RIGHT";
  return hasTextWrap && isFloatableAlignment;
};
const isBetweenFloatedNodes = (node1, node2) => isNodeFloated(node1) && isNodeFloated(node2);
const getNodeType = (node) => {
  if ("attrs" in node && node.type?.name) {
    if (node.type.name === import_pm_node_types.PmNodeType.FIGURE) {
      return node.firstChild?.type.name || node.type.name;
    }
    return node.type.name;
  }
  if ("type" in node && "id" in node) {
    return node.type;
  }
  return "";
};
const isNodeFullWidth = (node) => {
  if (!node) {
    return false;
  }
  const nodeType = getNodeType(node);
  if (nodeType === import_v1.Node_Type.LAYOUT) {
    return true;
  }
  const containerData = getNodeContainerData(node);
  return containerData?.width?.size === "FULL_WIDTH";
};
const isBetweenFullWidthNodes = (node1, node2) => isNodeFullWidth(node1) && isNodeFullWidth(node2);
//# sourceMappingURL=gap-spacer-nodes.js.map
