{"version":3,"file":"index.cjs","names":["Mark","mergeAttributes","markInputRule","markPasteRule"],"sources":["../src/strike.ts","../src/index.ts"],"sourcesContent":["import { Mark, markInputRule, markPasteRule, mergeAttributes } from '@tiptap/core'\n\nexport interface StrikeOptions {\n  /**\n   * HTML attributes to add to the strike element.\n   * @default {}\n   * @example { class: 'foo' }\n   */\n  HTMLAttributes: Record<string, any>\n}\n\ndeclare module '@tiptap/core' {\n  interface Commands<ReturnType> {\n    strike: {\n      /**\n       * Set a strike mark\n       * @example editor.commands.setStrike()\n       */\n      setStrike: () => ReturnType\n      /**\n       * Toggle a strike mark\n       * @example editor.commands.toggleStrike()\n       */\n      toggleStrike: () => ReturnType\n      /**\n       * Unset a strike mark\n       * @example editor.commands.unsetStrike()\n       */\n      unsetStrike: () => ReturnType\n    }\n  }\n}\n\n/**\n * Matches a strike to a ~~strike~~ on input.\n */\nexport const inputRegex = /(?:^|\\s)(~~(?!\\s+~~)((?:[^~]+))~~(?!\\s+~~))$/\n\n/**\n * Matches a strike to a ~~strike~~ on paste.\n */\nexport const pasteRegex = /(?:^|\\s)(~~(?!\\s+~~)((?:[^~]+))~~(?!\\s+~~))/g\n\n/**\n * This extension allows you to create strike text.\n * @see https://www.tiptap.dev/api/marks/strike\n */\nexport const Strike = Mark.create<StrikeOptions>({\n  name: 'strike',\n\n  addOptions() {\n    return {\n      HTMLAttributes: {},\n    }\n  },\n\n  parseHTML() {\n    return [\n      {\n        tag: 's',\n      },\n      {\n        tag: 'del',\n      },\n      {\n        tag: 'strike',\n      },\n      {\n        style: 'text-decoration',\n        consuming: false,\n        getAttrs: style => ((style as string).includes('line-through') ? {} : false),\n      },\n    ]\n  },\n\n  renderHTML({ HTMLAttributes }) {\n    return ['s', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n  },\n\n  markdownTokenName: 'del',\n\n  parseMarkdown: (token, helpers) => {\n    // Convert 'del' token to strike mark\n    return helpers.applyMark('strike', helpers.parseInline(token.tokens || []))\n  },\n\n  renderMarkdown: (node, h) => {\n    return `~~${h.renderChildren(node)}~~`\n  },\n\n  addCommands() {\n    return {\n      setStrike:\n        () =>\n        ({ commands }) => {\n          return commands.setMark(this.name)\n        },\n      toggleStrike:\n        () =>\n        ({ commands }) => {\n          return commands.toggleMark(this.name)\n        },\n      unsetStrike:\n        () =>\n        ({ commands }) => {\n          return commands.unsetMark(this.name)\n        },\n    }\n  },\n\n  addKeyboardShortcuts() {\n    return {\n      'Mod-Shift-s': () => this.editor.commands.toggleStrike(),\n    }\n  },\n\n  addInputRules() {\n    return [\n      markInputRule({\n        find: inputRegex,\n        type: this.type,\n      }),\n    ]\n  },\n\n  addPasteRules() {\n    return [\n      markPasteRule({\n        find: pasteRegex,\n        type: this.type,\n      }),\n    ]\n  },\n})\n","import { Strike } from './strike.js'\n\nexport * from './strike.js'\n\nexport default Strike\n"],"mappings":";;;;;;;;;AAoCA,MAAa,aAAa;;;;AAK1B,MAAa,aAAa;;;;;AAM1B,MAAa,SAASA,aAAAA,KAAK,OAAsB;CAC/C,MAAM;CAEN,aAAa;EACX,OAAO,EACL,gBAAgB,CAAC,EACnB;CACF;CAEA,YAAY;EACV,OAAO;GACL,EACE,KAAK,IACP;GACA,EACE,KAAK,MACP;GACA,EACE,KAAK,SACP;GACA;IACE,OAAO;IACP,WAAW;IACX,WAAU,UAAW,MAAiB,SAAS,cAAc,IAAI,CAAC,IAAI;GACxE;EACF;CACF;CAEA,WAAW,EAAE,kBAAkB;EAC7B,OAAO;GAAC;IAAKC,GAAAA,aAAAA,gBAAAA,CAAgB,KAAK,QAAQ,gBAAgB,cAAc;GAAG;EAAC;CAC9E;CAEA,mBAAmB;CAEnB,gBAAgB,OAAO,YAAY;EAEjC,OAAO,QAAQ,UAAU,UAAU,QAAQ,YAAY,MAAM,UAAU,CAAC,CAAC,CAAC;CAC5E;CAEA,iBAAiB,MAAM,MAAM;EAC3B,OAAO,KAAK,EAAE,eAAe,IAAI,EAAE;CACrC;CAEA,cAAc;EACZ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