"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 normalizeTypographyDown_exports = {};
__export(normalizeTypographyDown_exports, {
  normalizeTypographyDown: () => normalizeTypographyDown,
  shallowMergeTypographies: () => shallowMergeTypographies
});
module.exports = __toCommonJS(normalizeTypographyDown_exports);
var import_slate = require("slate");
var import_controls = require("@makeswift/controls");
var import__ = require(".");
function shallowMergeTypographies(commonTypography, typography) {
  const devices = [
    ...new Set(
      commonTypography?.style.map((node) => node.deviceId).concat(typography?.style.map((node) => node.deviceId) ?? [])
    )
  ];
  return {
    id: commonTypography?.id ?? typography?.id,
    style: devices.map((deviceId) => {
      const commonDevice = commonTypography?.style.find((s) => s.deviceId === deviceId);
      const existingDeviceStyle = typography?.style.find((s) => s.deviceId === deviceId);
      return {
        deviceId,
        value: (0, import_controls.shallowMerge)(existingDeviceStyle?.value ?? {}, commonDevice?.value ?? {})
      };
    })
  };
}
function normalizeTypographyDown(editor, entry) {
  const [normalizationNode, normalizationPath] = entry;
  if (import_slate.Element.isElement(normalizationNode) && normalizationNode.typography != null && normalizationNode.children.length) {
    import_slate.Editor.withoutNormalizing(editor, () => {
      import_slate.Transforms.unsetNodes(editor, import__.TYPOGRAPHY_KEY, { at: normalizationPath });
      for (let i = 0; i < normalizationNode.children.length; i++) {
        const resultingTypography = shallowMergeTypographies(
          normalizationNode.typography,
          normalizationNode.children.at(i)?.typography
        );
        import_slate.Transforms.setNodes(
          editor,
          { typography: resultingTypography },
          { at: [...normalizationPath, i] }
        );
      }
    });
    return true;
  }
  return false;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  normalizeTypographyDown,
  shallowMergeTypographies
});
//# sourceMappingURL=normalizeTypographyDown.js.map