{"version":3,"sources":["../../src/font-size/index.ts","../../src/text-style/index.ts","../../src/font-size/font-size.ts"],"sourcesContent":["import { FontSize } from './font-size.js'\n\nexport * from './font-size.js'\n\nexport default FontSize\n","import { Mark, mergeAttributes } from '@tiptap/core'\n\nimport type { TextStyleAttributes } from '../index.js'\n\nexport interface TextStyleOptions {\n /**\n * HTML attributes to add to the span element.\n * @default {}\n * @example { class: 'foo' }\n */\n HTMLAttributes: Record\n /**\n * When enabled, merges the styles of nested spans into the child span during HTML parsing.\n * This prioritizes the style of the child span.\n * Used when parsing content created in other editors.\n * (Fix for ProseMirror's default behavior.)\n * @default true\n */\n mergeNestedSpanStyles: boolean\n}\n\ndeclare module '@tiptap/core' {\n interface Commands {\n textStyle: {\n /**\n * Remove spans without inline style attributes.\n * @example editor.commands.removeEmptyTextStyle()\n */\n removeEmptyTextStyle: () => ReturnType\n /**\n * Toggle a text style\n * @param attributes The text style attributes\n * @example editor.commands.toggleTextStyle({ fontWeight: 'bold' })\n */\n toggleTextStyle: (attributes?: TextStyleAttributes) => ReturnType\n }\n }\n}\n\nconst MAX_FIND_CHILD_SPAN_DEPTH = 20\n\n/**\n * Returns all next child spans, either direct children or nested deeper\n * but won't traverse deeper into child spans found, will only go MAX_FIND_CHILD_SPAN_DEPTH levels deep (default: 20)\n */\nconst findChildSpans = (element: HTMLElement, depth = 0): HTMLElement[] => {\n const childSpans: HTMLElement[] = []\n\n if (!element.children.length || depth > MAX_FIND_CHILD_SPAN_DEPTH) {\n return childSpans\n }\n\n Array.from(element.children).forEach(child => {\n if (child.tagName === 'SPAN') {\n childSpans.push(child as HTMLElement)\n } else if (child.children.length) {\n childSpans.push(...findChildSpans(child as HTMLElement, depth + 1))\n }\n })\n\n return childSpans\n}\n\nconst mergeNestedSpanStyles = (element: HTMLElement) => {\n if (!element.children.length) {\n return\n }\n\n const childSpans = findChildSpans(element)\n\n if (!childSpans) {\n return\n }\n\n childSpans.forEach(childSpan => {\n const childStyle = childSpan.getAttribute('style')\n const closestParentSpanStyleOfChild = childSpan.parentElement?.closest('span')?.getAttribute('style')\n\n childSpan.setAttribute('style', `${closestParentSpanStyleOfChild};${childStyle}`)\n })\n}\n\n/**\n * This extension allows you to create text styles. It is required by default\n * for the `text-color` and `font-family` extensions.\n * @see https://www.tiptap.dev/api/marks/text-style\n */\nexport const TextStyle = Mark.create({\n name: 'textStyle',\n\n priority: 101,\n\n addOptions() {\n return {\n HTMLAttributes: {},\n mergeNestedSpanStyles: true,\n }\n },\n\n parseHTML() {\n return [\n {\n tag: 'span',\n consuming: false,\n getAttrs: element => {\n const hasStyles = (element as HTMLElement).hasAttribute('style')\n\n if (!hasStyles) {\n return false\n }\n\n if (this.options.mergeNestedSpanStyles) {\n mergeNestedSpanStyles(element)\n }\n\n return {}\n },\n },\n ]\n },\n\n renderHTML({ HTMLAttributes }) {\n return ['span', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0]\n },\n\n addCommands() {\n return {\n toggleTextStyle:\n attributes =>\n ({ commands }) => {\n return commands.toggleMark(this.name, attributes)\n },\n removeEmptyTextStyle:\n () =>\n ({ tr }) => {\n const { selection } = tr\n\n // Gather all of the nodes within the selection range.\n // We would need to go through each node individually\n // to check if it has any inline style attributes.\n // Otherwise, calling commands.unsetMark(this.name)\n // removes everything from all the nodes\n // within the selection range.\n tr.doc.nodesBetween(selection.from, selection.to, (node, pos) => {\n // Check if it's a paragraph element, if so, skip this node as we apply\n // the text style to inline text nodes only (span).\n if (node.isTextblock) {\n return true\n }\n\n // Check if the node has no inline style attributes.\n // Filter out non-`textStyle` marks.\n if (\n !node.marks\n .filter(mark => mark.type === this.type)\n .some(mark => Object.values(mark.attrs).some(value => !!value))\n ) {\n // Proceed with the removal of the `textStyle` mark for this node only\n tr.removeMark(pos, pos + node.nodeSize, this.type)\n }\n })\n\n return true\n },\n }\n },\n})\n","import '../text-style/index.js'\n\nimport { Extension } from '@tiptap/core'\n\nexport type FontSizeOptions = {\n /**\n * A list of node names where the font size can be applied.\n * @default ['textStyle']\n * @example ['heading', 'paragraph']\n */\n types: string[]\n}\n\ndeclare module '@tiptap/core' {\n interface Commands {\n fontSize: {\n /**\n * Set the font size\n * @param fontSize The font size\n * @example editor.commands.setFontSize('16px')\n */\n setFontSize: (fontSize: string) => ReturnType\n /**\n * Unset the font size\n * @example editor.commands.unsetFontSize()\n */\n unsetFontSize: () => ReturnType\n }\n }\n}\n\n// @ts-ignore because the module is not found during dts build\ndeclare module '@tiptap/extension-text-style' {\n interface TextStyleAttributes {\n fontSize?: string | null\n }\n}\n\n/**\n * This extension allows you to set a font size for text.\n * @see https://www.tiptap.dev/api/extensions/font-size\n */\nexport const FontSize = Extension.create({\n name: 'fontSize',\n\n addOptions() {\n return {\n types: ['textStyle'],\n }\n },\n\n addGlobalAttributes() {\n return [\n {\n types: this.options.types,\n attributes: {\n fontSize: {\n default: null,\n parseHTML: element => element.style.fontSize,\n renderHTML: attributes => {\n if (!attributes.fontSize) {\n return {}\n }\n\n return {\n style: `font-size: ${attributes.fontSize}`,\n }\n },\n },\n },\n },\n ]\n },\n\n addCommands() {\n return {\n setFontSize:\n fontSize =>\n ({ chain }) => {\n return chain().setMark('textStyle', { fontSize }).run()\n },\n unsetFontSize:\n () =>\n ({ chain }) => {\n return chain().setMark('textStyle', { fontSize: null }).removeEmptyTextStyle().run()\n },\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAAsC;AAuCtC,IAAM,4BAA4B;AAMlC,IAAM,iBAAiB,CAAC,SAAsB,QAAQ,MAAqB;AACzE,QAAM,aAA4B,CAAC;AAEnC,MAAI,CAAC,QAAQ,SAAS,UAAU,QAAQ,2BAA2B;AACjE,WAAO;AAAA,EACT;AAEA,QAAM,KAAK,QAAQ,QAAQ,EAAE,QAAQ,WAAS;AAC5C,QAAI,MAAM,YAAY,QAAQ;AAC5B,iBAAW,KAAK,KAAoB;AAAA,IACtC,WAAW,MAAM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