{"version":3,"sources":["../../src/color/plugin/with-font-color.ts","../../src/color/plugin/font-color-editor.ts","../../src/color/options.ts"],"sourcesContent":["import { colord } from 'colord'\nimport { Editor } from '@editablejs/models'\nimport { Editable, RenderLeafProps, Hotkey } from '@editablejs/editor'\nimport { FONTCOLOR_KEY } from '../constants'\nimport { FontColorEditor } from './font-color-editor'\nimport { FontColor } from '../interfaces/font-color'\nimport { FontColorHotkey, FontColorOptions, setOptions } from '../options'\n\nconst defaultHotkeys: FontColorHotkey = {}\n\nexport const withFontColor = <T extends Editable>(editor: T, options: FontColorOptions = {}) => {\n  const newEditor = editor as T & FontColorEditor\n\n  setOptions(newEditor, options)\n\n  newEditor.toggleFontColor = (color: string) => {\n    editor.normalizeSelection(selection => {\n      if (editor.selection !== selection) editor.selection = selection\n      const { defaultColor } = FontColorEditor.getOptions(editor)\n      if (defaultColor && colord(color).toRgbString() === colord(defaultColor).toRgbString()) {\n        Editor.removeMark(editor, FONTCOLOR_KEY)\n      } else {\n        Editor.addMark(editor, FONTCOLOR_KEY, color)\n      }\n    })\n  }\n\n  const { renderLeaf } = newEditor\n\n  newEditor.renderLeaf = ({ attributes, children, text }: RenderLeafProps) => {\n    const style: typeof attributes.style = attributes.style ?? {}\n    if (FontColor.isFontColor(text)) {\n      style.color = text.fontColor\n    }\n    return renderLeaf({ attributes: Object.assign({}, attributes, { style }), children, text })\n  }\n\n  const { onKeydown } = newEditor\n\n  const hotkeys: FontColorHotkey = Object.assign({}, defaultHotkeys, options.hotkey)\n  newEditor.onKeydown = (e: KeyboardEvent) => {\n    const value = Hotkey.match(hotkeys, e)\n    if (value) {\n      e.preventDefault()\n      newEditor.toggleFontColor(value)\n      return\n    }\n    onKeydown(e)\n  }\n  return newEditor\n}\n","import { Editor } from '@editablejs/models'\nimport { FONTCOLOR_KEY } from '../constants'\nimport { FontColor } from '../interfaces/font-color'\nimport { getOptions } from '../options'\n\nexport interface FontColorEditor extends Editor {\n  toggleFontColor: (color: string) => void\n}\n\nexport const FontColorEditor = {\n  isFontColorEditor: (editor: Editor): editor is FontColorEditor => {\n    return !!(editor as FontColorEditor).toggleFontColor\n  },\n\n  isFontColor: (editor: Editor, value: any): value is FontColor => {\n    return FontColor.isFontColor(value)\n  },\n\n  queryActive: (editor: Editor) => {\n    const marks = Editor.marks(editor) as Partial<FontColor>\n    return marks[FONTCOLOR_KEY] ?? null\n  },\n\n  toggle: (editor: Editor, size: string) => {\n    if (FontColorEditor.isFontColorEditor(editor)) editor.toggleFontColor(size)\n  },\n\n  getOptions,\n}\n","import { Editor } from '@editablejs/models'\n\nexport type FontColorHotkey = Record<string, string | ((e: KeyboardEvent) => boolean)>\n\nexport interface FontColorOptions {\n  hotkey?: FontColorHotkey\n  defaultColor?: string\n}\n\nconst FONTCOLOR_OPTIONS = new WeakMap<Editor, FontColorOptions>()\n\nexport const getOptions = (editor: Editor): FontColorOptions => {\n  return FONTCOLOR_OPTIONS.get(editor) ?? {}\n}\n\nexport const setOptions = (editor: Editor, options: FontColorOptions) => {\n  FONTCOLOR_OPTIONS.set(editor, options)\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,UAAAA,eAAc;AACvB,SAAoC,cAAc;;;ACFlD,SAAS,cAAc;;;ACSvB,IAAM,oBAAoB,oBAAI,QAAkC;AAEzD,IAAM,aAAa,CAAC,WAAqC;AAC9D,SAAO,kBAAkB,IAAI,MAAM,KAAK,CAAC;AAC3C;AAEO,IAAM,aAAa,CAAC,QAAgB,YAA8B;AACvE,oBAAkB,IAAI,QAAQ,OAAO;AACvC;;;ADRO,IAAM,kBAAkB;AAAA,EAC7B,mBAAmB,CAAC,WAA8C;AAChE,WAAO,CAAC,CAAE,OAA2B;AAAA,EACvC;AAAA,EAEA,aAAa,CAAC,QAAgB,UAAmC;AAC/D,WAAO,UAAU,YAAY,KAAK;AAAA,EACpC;AAAA,EAEA,aAAa,CAAC,WAAmB;AAC/B,UAAM,QAAQ,OAAO,MAAM,MAAM;AACjC,WAAO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