{"version":3,"sources":["../../src/size/plugin/with-font-size.ts","../../src/size/options.ts","../../src/size/plugin/font-size-editor.ts"],"sourcesContent":["import { Editable, RenderLeafProps, Hotkey } from '@editablejs/editor'\nimport { Editor } from '@editablejs/models'\nimport { FONTSIZE_KEY } from '../constants'\nimport { FontSize } from '../interfaces/font-size'\nimport { FontSizeHotkey, FontSizeOptions, setOptions } from '../options'\nimport { FontSizeEditor } from './font-size-editor'\n\nconst defaultHotkeys: FontSizeHotkey = {}\n\nexport const withFontSize = <T extends Editable>(editor: T, options: FontSizeOptions = {}) => {\n  const newEditor = editor as T & FontSizeEditor\n\n  setOptions(newEditor, options)\n\n  newEditor.toggleFontSize = (size: string) => {\n    editor.normalizeSelection(selection => {\n      if (editor.selection !== selection) editor.selection = selection\n      const { defaultSize } = FontSizeEditor.getOptions(editor)\n      if (defaultSize && size === defaultSize) {\n        Editor.removeMark(editor, FONTSIZE_KEY)\n      } else {\n        Editor.addMark(editor, FONTSIZE_KEY, size)\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 (FontSize.isFontSize(text)) {\n      style.fontSize = text.fontSize\n    }\n    return renderLeaf({ attributes: Object.assign({}, attributes, { style }), children, text })\n  }\n\n  const { onKeydown } = newEditor\n\n  const hotkeys: FontSizeHotkey = 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.toggleFontSize(value)\n      return\n    }\n    onKeydown(e)\n  }\n\n  return newEditor\n}\n","import { Editor } from '@editablejs/models'\n\nexport type FontSizeHotkey = Record<string, string | ((e: KeyboardEvent) => boolean)>\n\nexport interface FontSizeOptions {\n  hotkey?: FontSizeHotkey\n  defaultSize?: string\n}\n\nconst FONTSIZE_OPTIONS = new WeakMap<Editor, FontSizeOptions>()\n\nexport const getOptions = (editor: Editor): FontSizeOptions => {\n  return FONTSIZE_OPTIONS.get(editor) ?? {}\n}\n\nexport const setOptions = (editor: Editor, options: FontSizeOptions) => {\n  FONTSIZE_OPTIONS.set(editor, options)\n}\n","import { Editor } from '@editablejs/models'\nimport { FONTSIZE_KEY } from '../constants'\nimport { FontSize } from '../interfaces/font-size'\nimport { getOptions } from '../options'\n\nexport interface FontSizeEditor extends Editor {\n  toggleFontSize: (size: string) => void\n}\n\nexport const FontSizeEditor = {\n  isFontSizeEditor: (editor: Editor): editor is FontSizeEditor => {\n    return !!(editor as FontSizeEditor).toggleFontSize\n  },\n\n  isFontSize: (editor: Editor, node: any): node is FontSize => {\n    return FontSize.isFontSize(node)\n  },\n\n  queryActive: (editor: Editor) => {\n    const marks = Editor.marks(editor) as Partial<FontSize>\n    return marks[FONTSIZE_KEY] ?? null\n  },\n\n  toggle: (editor: Editor, size: string) => {\n    if (FontSizeEditor.isFontSizeEditor(editor)) editor.toggleFontSize(size)\n  },\n\n  getOptions,\n}\n"],"mappings":";;;;;;AAAA,SAAoC,cAAc;AAClD,SAAS,UAAAA,eAAc;;;ACQvB,IAAM,mBAAmB,oBAAI,QAAiC;AAEvD,IAAM,aAAa,CAAC,WAAoC;AAC7D,SAAO,iBAAiB,IAAI,MAAM,KAAK,CAAC;AAC1C;AAEO,IAAM,aAAa,CAAC,QAAgB,YAA6B;AACtE,mBAAiB,IAAI,QAAQ,OAAO;AACtC;;;ACjBA,SAAS,cAAc;AAShB,IAAM,iBAAiB;AAAA,EAC5B,kBAAkB,CAAC,WAA6C;AAC9D,WAAO,CAAC,CAAE,OAA0B;AAAA,EACtC;AAAA,EAEA,YAAY,CAAC,QAAgB,SAAgC;AAC3D,WAAO,SAAS,WAAW,IAAI;AAAA,EACjC;AAAA,EAEA,aAAa,CAAC,WAAmB;AAC/B,UAAM,QAAQ,OAAO,MAAM,MAAM;AACjC,WAAO,MAAM,iBAAiB;AAAA,EAChC;AAAA,EAEA,Q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