"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 document_style_exports = {};
__export(document_style_exports, {
  RicosDocumentStyle: () => RicosDocumentStyle
});
module.exports = __toCommonJS(document_style_exports);
var import_v1 = require("./../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_text_node_transformer = require("./../text-node-transformer.js");
var import_decorations = require("../decorations/index.js");
var import_text_style_transformer = require("../text-style-transformer.js");
var import_textual_theme = require("../textual-theme/textual-theme.js");
var import_node_style = require("./node-style.js");
var import_text_node_style = require("./text-node-style.js");
var import_text_style = require("./text-style.js");
class RicosDocumentStyle {
  constructor(documentStyle) {
    this.documentStyle = removeUnsupportedDocumentStyleDecorations(documentStyle);
  }
  static fromNode(node) {
    return new RicosDocumentStyle((0, import_text_node_transformer.toDocumentStyle)(node));
  }
  static isNodeTransformable(node) {
    return node.type === import_v1.Node_Type.PARAGRAPH || node.type === import_v1.Node_Type.HEADING;
  }
  /**
   * Extracts given decoration settings for specific node type from the current Document Style.
   */
  getDecoration(nodeType, decorationType) {
    return import_decorations.Decorations.of(this.documentStyle[nodeType]?.decorations || []).byType(decorationType);
  }
  getDecorations(node) {
    const documentStyleKey = (0, import_text_node_transformer.getDocumentStyleKey)(node);
    return import_decorations.Decorations.of(
      this.documentStyle[documentStyleKey]?.decorations || []
    ).toDecorationArray();
  }
  getTextStyle(nodeType) {
    return import_text_style.RicosTextStyle.of({ lineHeight: this.documentStyle[nodeType]?.lineHeight });
  }
  getNodeStyle(nodeType) {
    return import_node_style.RicosNodeStyle.of(this.documentStyle[nodeType]?.nodeStyle);
  }
  /**
   * Translates DocumentStyle to HTML style tag with CSS variable definitions
   */
  toStyleTag() {
    const theme = import_text_style_transformer.TextStyleTransformer.fromDocumentStyle(this.documentStyle).toTheme();
    return new import_textual_theme.RicosTextualTheme(theme).toStyleTag();
  }
  /**
   * Translates DocumentStyle entity to RichContent compatible DocumentStyle object
   */
  toContent() {
    return this.documentStyle;
  }
  /**
   * DocumentStyle modification
   */
  setStyle(nodeType, textNodeStyle) {
    const style = new import_text_node_style.RicosTextNodeStyle(this.documentStyle[nodeType] || { decorations: [] }).overrideWith(textNodeStyle).getTextNodeStyle();
    return new RicosDocumentStyle({ ...this.documentStyle, [nodeType]: style });
  }
  resetStyle(nodeType) {
    return new RicosDocumentStyle({ ...this.documentStyle, [nodeType]: {} });
  }
  /**
   * DocumentStyle modification
   */
  mergeWith(documentStyle) {
    return Object.entries(documentStyle).reduce(
      (acc, [key, style]) => acc.setStyle(key, style),
      new RicosDocumentStyle(this.documentStyle)
    );
  }
}
const unsupportedDocumentStyleDecorations = [import_v1.Decoration_Type.SKETCH];
const removeUnsupportedDocumentStyleDecorations = (documentStyle) => Object.entries(documentStyle || {}).reduce((acc, [key, style]) => {
  if (!style.decorations) {
    acc[key] = style;
    return acc;
  }
  acc[key] = {
    ...style,
    decorations: style.decorations.filter(
      (decoration) => !unsupportedDocumentStyleDecorations.includes(decoration.type)
    )
  };
  return acc;
}, {});
//# sourceMappingURL=document-style.js.map
