{"version":3,"sources":["../src/index.ts","../src/text-align.ts"],"sourcesContent":["import { TextAlign } from './text-align.js'\n\nexport * from './text-align.js'\n\nexport default TextAlign\n","import { Extension } from '@tiptap/core'\n\nexport interface TextAlignOptions {\n  /**\n   * The types where the text align attribute can be applied.\n   * @default []\n   * @example ['heading', 'paragraph']\n   */\n  types: string[]\n\n  /**\n   * The alignments which are allowed.\n   * @default ['left', 'center', 'right', 'justify']\n   * @example ['left', 'right']\n   */\n  alignments: string[]\n\n  /**\n   * The default alignment.\n   * @default null\n   * @example 'center'\n   */\n  defaultAlignment: string | null\n}\n\ndeclare module '@tiptap/core' {\n  interface Commands<ReturnType> {\n    textAlign: {\n      /**\n       * Set the text align attribute\n       * @param alignment The alignment\n       * @example editor.commands.setTextAlign('left')\n       */\n      setTextAlign: (alignment: string) => ReturnType\n      /**\n       * Unset the text align attribute\n       * @example editor.commands.unsetTextAlign()\n       */\n      unsetTextAlign: () => ReturnType\n      /**\n       * Toggle the text align attribute\n       * @param alignment The alignment\n       * @example editor.commands.toggleTextAlign('right')\n       */\n      toggleTextAlign: (alignment: string) => ReturnType\n    }\n  }\n}\n\n/**\n * This extension allows you to align text.\n * @see https://www.tiptap.dev/api/extensions/text-align\n */\nexport const TextAlign = Extension.create<TextAlignOptions>({\n  name: 'textAlign',\n\n  addOptions() {\n    return {\n      types: [],\n      alignments: ['left', 'center', 'right', 'justify'],\n      defaultAlignment: null,\n    }\n  },\n\n  addGlobalAttributes() {\n    return [\n      {\n        types: this.options.types,\n        attributes: {\n          textAlign: {\n            default: this.options.defaultAlignment,\n            parseHTML: element => {\n              const alignment = element.style.textAlign\n\n              return this.options.alignments.includes(alignment) ? alignment : this.options.defaultAlignment\n            },\n            renderHTML: attributes => {\n              if (!attributes.textAlign) {\n                return {}\n              }\n\n              return { style: `text-align: ${attributes.textAlign}` }\n            },\n          },\n        },\n      },\n    ]\n  },\n\n  addCommands() {\n    return {\n      setTextAlign:\n        (alignment: string) =>\n        ({ commands }) => {\n          if (!this.options.alignments.includes(alignment)) {\n            return false\n          }\n\n          return this.options.types\n            .map(type => commands.updateAttributes(type, { textAlign: alignment }))\n            .some(response => response)\n        },\n\n      unsetTextAlign:\n        () =>\n        ({ commands }) => {\n          return this.options.types.map(type => commands.resetAttributes(type, 'textAlign')).some(response => response)\n        },\n\n      toggleTextAlign:\n        alignment =>\n        ({ editor, commands }) => {\n          if (!this.options.alignments.includes(alignment)) {\n            return false\n          }\n\n          if (editor.isActive({ textAlign: alignment })) {\n            return commands.unsetTextAlign()\n          }\n          return commands.setTextAlign(alignment)\n        },\n    }\n  },\n\n  addKeyboardShortcuts() {\n    return {\n      'Mod-Shift-l': () => this.editor.commands.setTextAlign('left'),\n      'Mod-Shift-e': () => this.editor.commands.setTextAlign('center'),\n      'Mod-Shift-r': () => this.editor.commands.setTextAlign('right'),\n      'Mod-Shift-j': () => this.editor.commands.setTextAlign('justify'),\n    }\n  },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA0B;AAqDnB,IAAM,YAAY,sBAAU,OAAyB;AAAA,EAC1D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,OAAO,CAAC;AAAA,MACR,YAAY,CAAC,QAAQ,UAAU,SAAS,SAAS;AAAA,MACjD,kBAAkB;AAAA,IACpB;AAAA,EACF;AAAA,EAEA,sBAAsB;AACpB,WAAO;AAAA,MACL;AAAA,QACE,OAAO,KAAK,QAAQ;AAAA,QACpB,YAAY;AAAA,UACV,WAAW;AAAA,YACT,SAAS,KAAK,QAAQ;AAAA,YACtB,WAAW,aAAW;AACpB,oBAAM,YAAY,QAAQ,MAAM;AAEhC,qBAAO,KAAK,QAAQ,WAAW,SAAS,SAAS,IAAI,YAAY,KAAK,QAAQ;AAAA,YAChF;AAAA,YACA,YAAY,gBAAc;AACxB,kBAAI,CAAC,WAAW,WAAW;AACzB,uBAAO,CAAC;AAAA,cACV;AAEA,qB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