"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 list_style_position_exports = {};
__export(list_style_position_exports, {
  createListStylePositionDecorationPlugin: () => createListStylePositionDecorationPlugin
});
module.exports = __toCommonJS(list_style_position_exports);
var import_v1 = require("./../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_state = require("./../../tiptap/pm/state.js");
var import_view = require("./../../tiptap/pm/view.js");
var import_is_inline_text_only = require("../transaction-predicates/is-inline-text-only.js");
var import_only_changes_unrelated_attrs = require("../transaction-predicates/only-changes-unrelated-attrs.js");
const RELEVANT_ATTRS = /* @__PURE__ */ new Set(["textStyle"]);
const createListStylePositionDecorationPlugin = () => {
  const key = new import_state.PluginKey("list-style-position");
  return new import_state.Plugin({
    key,
    state: {
      init: (_config, state) => buildListStylePositionDecorations(state.doc),
      apply: (tr, prev) => {
        if (!tr.docChanged) {
          return prev;
        }
        if ((0, import_is_inline_text_only.isInlineTextOnly)(tr)) {
          return prev.map(tr.mapping, tr.doc);
        }
        if ((0, import_only_changes_unrelated_attrs.onlyChangesUnrelatedAttrs)(tr, RELEVANT_ATTRS)) {
          return prev;
        }
        return buildListStylePositionDecorations(tr.doc);
      }
    },
    props: {
      decorations(state) {
        return key.getState(state);
      }
    }
  });
};
const buildListStylePositionDecorations = (doc) => {
  const decorations = [];
  doc.descendants((node, pos) => {
    if (node.isTextblock) {
      return false;
    }
    if (node.type.name !== import_v1.Node_Type.LIST_ITEM) {
      return;
    }
    if (node.attrs.textStyle.textAlignment === import_v1.TextStyle_TextAlignment.CENTER) {
      decorations.push(
        import_view.Decoration.node(pos, pos + node.nodeSize, {
          "data-list-style-position": "inside"
        })
      );
    }
  });
  return import_view.DecorationSet.create(doc, decorations);
};
//# sourceMappingURL=list-style-position.js.map
