{"version":3,"file":"index.cjs","sources":["../src/background-color.ts"],"sourcesContent":["import '@tiptap/extension-text-style'\n\nimport { Extension } from '@tiptap/core'\n\nexport type BackgroundColorOptions = {\n  types: string[],\n}\n\ndeclare module '@tiptap/core' {\n  interface Commands<ReturnType> {\n    backgroundColor: {\n      /**\n       * Set the text background color\n       */\n      setBackgroundColor: (backgroundColor: string) => ReturnType,\n      /**\n       * Unset the text background color\n       */\n      unsetBackgroundColor: () => ReturnType,\n    }\n  }\n}\n\nexport const BackgroundColor = Extension.create<BackgroundColorOptions>({\n  name: 'backgroundColor',\n\n  addOptions() {\n    return {\n      types: ['textStyle'],\n    }\n  },\n\n  addGlobalAttributes() {\n    return [\n      {\n        types: this.options.types,\n        attributes: {\n          backgroundColor: {\n            default: null,\n            parseHTML: element => element.style.backgroundColor?.replace(/['\"]+/g, ''),\n            renderHTML: attributes => {\n              if (!attributes.backgroundColor) {\n                return {}\n              }\n\n              return {\n                style: `background-color: ${attributes.backgroundColor}`,\n              }\n            },\n          },\n        },\n      },\n    ]\n  },\n\n  addCommands() {\n    return {\n      setBackgroundColor: backgroundColor => ({ chain }) => {\n        return chain()\n          .setMark('textStyle', { backgroundColor })\n          .run()\n      },\n      unsetBackgroundColor: () => ({ chain }) => {\n        return chain()\n          .setMark('textStyle', { backgroundColor: null })\n          .removeEmptyTextStyle()\n          .run()\n      },\n    }\n  },\n})\n"],"names":["Extension"],"mappings":";;;;;;;AAuBa,MAAA,eAAe,GAAGA,cAAS,CAAC,MAAM,CAAyB;AACtE,IAAA,IAAI,EAAE,iBAAiB;IAEvB,UAAU,GAAA;QACR,OAAO;YACL,KAAK,EAAE,CAAC,WAAW,CAAC;SACrB,CAAA;KACF;IAED,mBAAmB,GAAA;QACjB,OAAO;AACL,YAAA;AACE,gBAAA,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;AACzB,gBAAA,UAAU,EAAE;AACV,oBAAA,eAAe,EAAE;AACf,wBAAA,OAAO,EAAE,IAAI;w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