{"version":3,"file":"index.cjs","names":["Extension"],"sources":["../src/text-align.ts","../src/index.ts"],"sourcesContent":["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)\n                ? alignment\n                : 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\n            .map(type => commands.resetAttributes(type, 'textAlign'))\n            .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","import { TextAlign } from './text-align.js'\n\nexport * from './text-align.js'\n\nexport default TextAlign\n"],"mappings":";;;;;;;;;AAqDA,MAAa,kCAAYA,CAAAA,CAAAA,UAAU,OAAyB;CAC1D,MAAM;CAEN,aAAa;EACX,OAAO;GACL,OAAO,CAAC;GACR,YAAY;IAAC;IAAQ;IAAU;IAAS;GAAS;GACjD,kBAAkB;EACpB;CACF;CAEA,sBAAsB;EACpB,OAAO,CACL;GACE,OAAO,KAAK,QAAQ;GACpB,YAAY,EACV,WAAW;IACT,SAAS,KAAK,QAAQ;IACtB,YAAW,YAAW;KACpB,MAAM,YAAY,QAAQ,MAAM;KAEhC,OAAO,KAAK,QAAQ,WAAW,SAAS,SAAS,IAC7C,YACA,KAAK,QAAQ;IACnB;IACA,aAAY,eAAc;KACxB,IAAI,CAAC,WAAW,WACd,OAAO,CAAC;KAGV,OAAO,EAAE,OAAO,eAAe,WAAW,YAAY;IACxD;GACF,EACF;EACF,CACF;CACF;CAEA,cAAc;EACZ,OAAO;GACL,eACG,eACA,EAAE,eAAe;IAChB,IAAI,CAAC,KA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