@tiptap/extension-invisible-characters 3.30.2 → 3.30.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/invisible-characters.ts","../src/plugin/InvisibleCharactersPlugin.ts","../src/plugin/reducers.ts","../src/plugin/style.ts","../src/plugin/utils/create-style-tag.ts","../src/plugin/utils/get-updated-ranges.ts","../src/plugin/utils/create-decoration-widget.ts","../src/plugin/InvisibleNode.ts","../src/plugin/invisible-characters/hardBreak.ts","../src/plugin/invisible-characters/paragraph.ts","../src/plugin/utils/text-between.ts","../src/plugin/InvisibleCharacter.ts","../src/plugin/invisible-characters/space.ts"],"sourcesContent":["import { InvisibleCharacters } from './invisible-characters.js'\n\nexport * from './invisible-characters.js'\nexport * from './plugin/invisible-characters/hardBreak.js'\nexport * from './plugin/invisible-characters/paragraph.js'\nexport * from './plugin/invisible-characters/space.js'\nexport * from './plugin/InvisibleCharacter.js'\nexport * from './plugin/InvisibleNode.js'\nexport * from './types.js'\n\nexport default InvisibleCharacters\n","import { Extension } from '@tiptap/core'\n\nimport { InvisibleCharactersPlugin, InvisibleCharactersPluginKey } from './plugin/index.js'\nimport { HardBreakNode } from './plugin/invisible-characters/hardBreak.js'\nimport { ParagraphNode } from './plugin/invisible-characters/paragraph.js'\nimport { SpaceCharacter } from './plugin/invisible-characters/space.js'\nimport type { InvisibleCharactersOptions } from './types.js'\n\nexport { HardBreakNode, ParagraphNode, SpaceCharacter }\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n invisibleCharacters: {\n /**\n * Show invisible characters\n */\n showInvisibleCharacters: (show?: boolean) => ReturnType\n\n /**\n * Hide invisible characters\n */\n hideInvisibleCharacters: () => ReturnType\n\n /**\n * Toggle invisible characters\n */\n toggleInvisibleCharacters: () => ReturnType\n }\n }\n}\n\nexport const InvisibleCharacters = Extension.create<InvisibleCharactersOptions>({\n name: 'invisibleCharacters',\n\n addOptions() {\n return {\n visible: true,\n builders: [new SpaceCharacter(), new ParagraphNode(), new HardBreakNode()],\n injectCSS: true,\n injectNonce: undefined,\n }\n },\n\n addProseMirrorPlugins() {\n return [InvisibleCharactersPlugin(this.editor.state, this.options)]\n },\n\n addStorage() {\n return {\n visibility: () => this.options.visible,\n }\n },\n\n onBeforeCreate() {\n this.storage.visibility = () => {\n return InvisibleCharactersPluginKey.getState(this.editor.state)?.visible\n }\n },\n\n addCommands() {\n return {\n showInvisibleCharacters:\n (visibility = true) =>\n ({ dispatch, tr }) => {\n if (dispatch) {\n tr.setMeta('setInvisibleCharactersVisible', visibility)\n }\n\n return true\n },\n hideInvisibleCharacters:\n () =>\n ({ dispatch, tr }) => {\n if (dispatch) {\n tr.setMeta('setInvisibleCharactersVisible', false)\n }\n\n return true\n },\n toggleInvisibleCharacters:\n () =>\n ({ dispatch, tr, state }) => {\n const visibility = !InvisibleCharactersPluginKey.getState(state)?.visible\n\n if (dispatch) {\n tr.setMeta('setInvisibleCharactersVisible', visibility)\n }\n\n return true\n },\n }\n },\n})\n\nexport default InvisibleCharacters\n","import type { EditorState } from '@tiptap/pm/state'\nimport { AllSelection, Plugin, PluginKey } from '@tiptap/pm/state'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport type { InvisibleCharactersOptions, PluginState } from '../types.js'\nimport { stateReducer } from './reducers.js'\nimport { style } from './style.js'\nimport { createStyleTag } from './utils/create-style-tag.js'\nimport { getUpdatedRanges } from './utils/get-updated-ranges.js'\n\nexport const InvisibleCharactersPluginKey = new PluginKey<PluginState>('invisibleCharacters')\n\nexport const InvisibleCharactersPlugin = (\n state: EditorState,\n options: InvisibleCharactersOptions,\n) => {\n const key = InvisibleCharactersPluginKey\n const emptyDecorationSet = DecorationSet.create(state.doc, [])\n\n const addDecorationsBetweenPositions = (\n from: number,\n to: number,\n editorState: EditorState,\n decorations: DecorationSet,\n ) => {\n return options.builders\n .sort((builderA, builderB) => {\n if (builderA.priority > builderB.priority) {\n return 1\n }\n\n return -1\n })\n .reduce((newDecos, builder) => {\n return builder.createDecoration(from, to, editorState.doc, newDecos)\n }, decorations)\n }\n\n return new Plugin({\n key,\n\n state: {\n init: () => {\n const { $from, $to } = new AllSelection(state.doc)\n\n if (options.injectCSS && document) {\n createStyleTag(style, options.injectNonce)\n }\n\n return {\n visible: options.visible,\n decorations: addDecorationsBetweenPositions(\n $from.pos,\n $to.pos,\n state,\n DecorationSet.empty,\n ),\n }\n },\n apply: (tr, pluginState, _, currentState) => {\n const newPluginState = stateReducer(\n pluginState,\n tr.getMeta('setInvisibleCharactersVisible'),\n )\n\n const decorations = getUpdatedRanges(tr).reduce(\n (nextDecorations, [from, to]) => {\n return addDecorationsBetweenPositions(from, to, currentState, nextDecorations)\n },\n newPluginState.decorations.map(tr.mapping, tr.doc),\n )\n\n return {\n ...newPluginState,\n decorations,\n }\n },\n },\n\n props: {\n decorations(editorState) {\n const pluginState = this.getState(editorState)\n\n const visible = pluginState?.visible\n const decorations = pluginState?.decorations\n\n return visible ? decorations : emptyDecorationSet\n },\n },\n })\n}\n\nexport default InvisibleCharactersPlugin\n","import type { PluginState } from '../types.js'\n\nexport const stateReducer = (state: PluginState, visible: boolean): PluginState => {\n if (visible === undefined) {\n return state\n }\n\n return { ...state, visible }\n}\n\nexport default stateReducer\n","export const style = `.tiptap-invisible-character {\n height: 0;\n padding: 0;\n pointer-events: none;\n user-select: none;\n width: 0;\n}\n\n.tiptap-invisible-character::before {\n caret-color: inherit;\n color: #aaa;\n display: inline-block;\n font-style: normal;\n font-weight: 400;\n line-height: 1em;\n width: 0;\n}\n\n.tiptap-invisible-character--space::before {\n content: '·'\n}\n\n.tiptap-invisible-character--break::before {\n content: '¬'\n}\n\n.tiptap-invisible-character--paragraph::before {\n content: '¶'\n}\n\n.tiptap-invisible-character + img.ProseMirror-separator {\n height: 0 !important;\n pointer-events: none;\n user-select: none;\n width: 0 !important;\n}\n\n.is-empty[data-placeholder].has-focus > .tiptap-invisible-character {\n display: none;\n}\n`\n\nexport default style\n","export const createStyleTag = (style: string, nonce?: string): HTMLStyleElement => {\n const tiptapStyleTag = <HTMLStyleElement>(\n document.querySelector('style[data-tiptap-extension-invisible-characters-style]')\n )\n\n if (tiptapStyleTag !== null) {\n return tiptapStyleTag\n }\n\n const styleNode = document.createElement('style')\n\n if (nonce) {\n styleNode.setAttribute('nonce', nonce)\n }\n\n styleNode.setAttribute('data-tiptap-extension-invisible-characters-style', '')\n styleNode.innerHTML = style\n document.getElementsByTagName('head')[0].appendChild(styleNode)\n\n return styleNode\n}\n\nexport default createStyleTag\n","import type { Transaction } from '@tiptap/pm/state'\n\ntype StepRange = [from: number, to: number]\n\nexport const getUpdatedRanges = ({ mapping }: Transaction): StepRange[] => {\n const ranges: StepRange[] = []\n\n mapping.maps.forEach((stepMap, i) => {\n stepMap.forEach((_oldStart, _oldEnd, newStart, newEnd) => {\n ranges.push([mapping.slice(i + 1).map(newStart), mapping.slice(i + 1).map(newEnd)])\n })\n })\n\n return ranges\n}\n\nexport default getUpdatedRanges\n","import { Decoration } from '@tiptap/pm/view'\n\nexport const createDecorationWidget = (pos: number, type: string, content?: string) => {\n const createElement = () => {\n const newElement = document.createElement('span')\n\n newElement.classList.add('tiptap-invisible-character')\n newElement.classList.add(`tiptap-invisible-character--${type}`)\n\n if (content) {\n newElement.textContent = content\n }\n\n return newElement\n }\n\n return Decoration.widget(pos, createElement, {\n key: type,\n marks: [],\n side: 1000,\n })\n}\n\nexport default createDecorationWidget\n","import type { Node } from '@tiptap/pm/model'\nimport type { DecorationSet } from '@tiptap/pm/view'\n\nimport { createDecorationWidget } from './utils/create-decoration-widget.js'\n\nexport interface InvisibleNodeOptions {\n content?: string\n position?: (node: Node, pos: number) => number\n predicate: (value: Node) => boolean\n priority?: number\n type: string\n}\n\n/** Default position for nodes is always at the end of the node */\nconst defaultPosition = (node: Node, pos: number) => pos + node.nodeSize - 1\n\nexport class InvisibleNode {\n predicate: (value: Node) => boolean\n\n position: (node: Node, pos: number) => number\n\n content?: string\n\n type: string\n\n priority: number\n\n constructor(options: InvisibleNodeOptions) {\n this.predicate = options.predicate\n this.type = options.type\n this.position = options.position || defaultPosition\n this.content = options.content\n this.priority = options.priority || 100\n }\n\n createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet) {\n let newDecorations = decorations\n\n doc.nodesBetween(from, to, (node, pos) => {\n if (this.test(node)) {\n const decorationPosition = this.position(node, pos)\n const oldDecorations = newDecorations.find(\n decorationPosition,\n decorationPosition,\n spec => spec.key === this.type,\n )\n\n newDecorations = newDecorations\n .remove(oldDecorations)\n .add(doc, [createDecorationWidget(decorationPosition, this.type, this.content)])\n }\n })\n return newDecorations\n }\n\n test(value: Node) {\n return this.predicate(value)\n }\n}\n\nexport default InvisibleNode\n","import { InvisibleNode } from '../InvisibleNode.js'\n\nexport class HardBreakNode extends InvisibleNode {\n constructor() {\n super({\n type: 'break',\n predicate: node => node.type === node.type.schema.nodes.hardBreak,\n })\n }\n}\n\nexport default HardBreakNode\n","import { InvisibleNode } from '../InvisibleNode.js'\n\nexport class ParagraphNode extends InvisibleNode {\n constructor() {\n super({\n type: 'paragraph',\n predicate: node => node.type === node.type.schema.nodes.paragraph,\n })\n }\n}\n\nexport default ParagraphNode\n","import type { Node } from '@tiptap/pm/model'\n\nimport type { Position } from '../../types.js'\n\nexport const textBetween = (from: number, to: number, doc: Node) => {\n const positions: Position[] = []\n\n doc.nodesBetween(from, to, (node, pos) => {\n if (node.isText) {\n const offset = Math.max(from, pos) - pos\n\n positions.push({\n pos: pos + offset,\n text: node.text?.slice(offset, to - pos) || '',\n })\n }\n })\n\n return positions\n}\n\nexport default textBetween\n","import type { Node } from '@tiptap/pm/model'\nimport type { DecorationSet } from '@tiptap/pm/view'\n\nimport { createDecorationWidget } from './utils/create-decoration-widget.js'\nimport { textBetween } from './utils/text-between.js'\n\nexport interface InvisibleCharacterOptions {\n type: string\n predicate: (value: string) => boolean\n priority?: number\n content?: string\n}\n\nexport class InvisibleCharacter {\n predicate: (value: string) => boolean\n\n content?: string\n\n type: string\n\n priority: number\n\n constructor(options: InvisibleCharacterOptions) {\n this.predicate = options.predicate\n this.type = options.type\n this.content = options.content\n this.priority = options.priority || 100\n }\n\n createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet) {\n const textContent = textBetween(from, to, doc)\n\n return textContent.reduce((oldDecorations, currentPosition) => {\n return currentPosition.text.split('').reduce((innerDecorations, char, i) => {\n return this.test(char)\n ? innerDecorations.add(doc, [\n createDecorationWidget(currentPosition.pos + i, this.type, this.content),\n ])\n : innerDecorations\n }, oldDecorations)\n }, decorations)\n }\n\n test(value: string) {\n return this.predicate(value)\n }\n}\n\nexport default InvisibleCharacter\n","import { InvisibleCharacter } from '../InvisibleCharacter.js'\n\nexport class SpaceCharacter extends InvisibleCharacter {\n constructor() {\n super({\n type: 'space',\n predicate: (char: string) => char === ' ',\n })\n }\n}\n\nexport default SpaceCharacter\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA0B;;;ACC1B,mBAAgD;AAChD,kBAA8B;;;ACAvB,IAAM,eAAe,CAAC,OAAoB,YAAkC;AACjF,MAAI,YAAY,QAAW;AACzB,WAAO;AAAA,EACT;AAEA,SAAO,EAAE,GAAG,OAAO,QAAQ;AAC7B;;;ACRO,IAAM,QAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAd,IAAM,iBAAiB,CAACA,QAAe,UAAqC;AACjF,QAAM,iBACJ,SAAS,cAAc,yDAAyD;AAGlF,MAAI,mBAAm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,IAAI,eAAe,GAAG,IAAI,cAAc,GAAG,IAAI,cAAc,CAAC;AAAA,MACzE,WAAW;AAAA,MACX,aAAa;AAAA,IACf;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO,CAAC,0BAA0B,KAAK,OAAO,OAAO,KAAK,OAAO,CAAC;AAAA,EACpE;AAAA,EAEA,aAAa;AACX,WAAO;AAAA,MACL,YAAY,MAAM,KAAK,QAAQ;AAAA,IACjC;AAAA,EACF;AAAA,EAEA,iBAAiB;AACf,SAAK,QAAQ,aAAa,MAAM;AAtDpC;AAuDM,cAAO,kCAA6B,SAAS,KAAK,OAAO,KAAK,MAAvD,mBAA0D;AAAA,IACnE;AAAA,EACF;AAAA,EAEA,cAAc;AACZ,WAAO;AAAA,MACL,yBACE,CAAC,aAAa,SACd,CAAC,EAAE,UAAU,GAAG,MAAM;AACpB,YAAI,UAAU;AACZ,aAAG,QAAQ,iCAAiC,UAAU;AAAA,QACxD;AAEA,eAAO;AAAA,MACT;AAAA,MACF,yBACE,MACA,CAAC,EAAE,UAAU,GAAG,MAAM;AACpB,YAAI,UAAU;AACZ,aAAG,QAAQ,iCAAiC,KAAK;AAAA,QACnD;AAEA,eAAO;AAAA,MACT;AAAA,MACF,2BACE,MACA,CAAC,EAAE,UAAU,IAAI,MAAM,MAAM;AAjFrC;AAkFU,cAAM,aAAa,GAAC,kCAA6B,SAAS,KAAK,MAA3C,mBAA8C;AAElE,YAAI,UAAU;AACZ,aAAG,QAAQ,iCAAiC,UAAU;AAAA,QACxD;AAEA,eAAO;AAAA,MACT;AAAA,IACJ;AAAA,EACF;AACF,CAAC;;;ADlFD,IAAO,gBAAQ;","names":["style","import_view"]}
1
+ {"version":3,"file":"index.cjs","names":["PluginKey","DecorationSet","Plugin","AllSelection","Decoration","Extension"],"sources":["../src/plugin/reducers.ts","../src/plugin/style.ts","../src/plugin/utils/create-style-tag.ts","../src/plugin/utils/get-updated-ranges.ts","../src/plugin/InvisibleCharactersPlugin.ts","../src/plugin/utils/create-decoration-widget.ts","../src/plugin/InvisibleNode.ts","../src/plugin/invisible-characters/hardBreak.ts","../src/plugin/invisible-characters/paragraph.ts","../src/plugin/utils/text-between.ts","../src/plugin/InvisibleCharacter.ts","../src/plugin/invisible-characters/space.ts","../src/invisible-characters.ts","../src/index.ts"],"sourcesContent":["import type { PluginState } from '../types.js'\n\nexport const stateReducer = (state: PluginState, visible: boolean): PluginState => {\n if (visible === undefined) {\n return state\n }\n\n return { ...state, visible }\n}\n\nexport default stateReducer\n","export const style = `.tiptap-invisible-character {\n height: 0;\n padding: 0;\n pointer-events: none;\n user-select: none;\n width: 0;\n}\n\n.tiptap-invisible-character::before {\n caret-color: inherit;\n color: #aaa;\n display: inline-block;\n font-style: normal;\n font-weight: 400;\n line-height: 1em;\n width: 0;\n}\n\n.tiptap-invisible-character--space::before {\n content: '·'\n}\n\n.tiptap-invisible-character--break::before {\n content: '¬'\n}\n\n.tiptap-invisible-character--paragraph::before {\n content: '¶'\n}\n\n.tiptap-invisible-character + img.ProseMirror-separator {\n height: 0 !important;\n pointer-events: none;\n user-select: none;\n width: 0 !important;\n}\n\n.is-empty[data-placeholder].has-focus > .tiptap-invisible-character {\n display: none;\n}\n`\n\nexport default style\n","export const createStyleTag = (style: string, nonce?: string): HTMLStyleElement => {\n const tiptapStyleTag = <HTMLStyleElement>(\n document.querySelector('style[data-tiptap-extension-invisible-characters-style]')\n )\n\n if (tiptapStyleTag !== null) {\n return tiptapStyleTag\n }\n\n const styleNode = document.createElement('style')\n\n if (nonce) {\n styleNode.setAttribute('nonce', nonce)\n }\n\n styleNode.setAttribute('data-tiptap-extension-invisible-characters-style', '')\n styleNode.innerHTML = style\n document.getElementsByTagName('head')[0].appendChild(styleNode)\n\n return styleNode\n}\n\nexport default createStyleTag\n","import type { Transaction } from '@tiptap/pm/state'\n\ntype StepRange = [from: number, to: number]\n\nexport const getUpdatedRanges = ({ mapping }: Transaction): StepRange[] => {\n const ranges: StepRange[] = []\n\n mapping.maps.forEach((stepMap, i) => {\n stepMap.forEach((_oldStart, _oldEnd, newStart, newEnd) => {\n ranges.push([mapping.slice(i + 1).map(newStart), mapping.slice(i + 1).map(newEnd)])\n })\n })\n\n return ranges\n}\n\nexport default getUpdatedRanges\n","import type { EditorState } from '@tiptap/pm/state'\nimport { AllSelection, Plugin, PluginKey } from '@tiptap/pm/state'\nimport { DecorationSet } from '@tiptap/pm/view'\n\nimport type { InvisibleCharactersOptions, PluginState } from '../types.js'\nimport { stateReducer } from './reducers.js'\nimport { style } from './style.js'\nimport { createStyleTag } from './utils/create-style-tag.js'\nimport { getUpdatedRanges } from './utils/get-updated-ranges.js'\n\nexport const InvisibleCharactersPluginKey = new PluginKey<PluginState>('invisibleCharacters')\n\nexport const InvisibleCharactersPlugin = (\n state: EditorState,\n options: InvisibleCharactersOptions,\n) => {\n const key = InvisibleCharactersPluginKey\n const emptyDecorationSet = DecorationSet.create(state.doc, [])\n\n const addDecorationsBetweenPositions = (\n from: number,\n to: number,\n editorState: EditorState,\n decorations: DecorationSet,\n ) => {\n return options.builders\n .sort((builderA, builderB) => {\n if (builderA.priority > builderB.priority) {\n return 1\n }\n\n return -1\n })\n .reduce((newDecos, builder) => {\n return builder.createDecoration(from, to, editorState.doc, newDecos)\n }, decorations)\n }\n\n return new Plugin({\n key,\n\n state: {\n init: () => {\n const { $from, $to } = new AllSelection(state.doc)\n\n if (options.injectCSS && document) {\n createStyleTag(style, options.injectNonce)\n }\n\n return {\n visible: options.visible,\n decorations: addDecorationsBetweenPositions(\n $from.pos,\n $to.pos,\n state,\n DecorationSet.empty,\n ),\n }\n },\n apply: (tr, pluginState, _, currentState) => {\n const newPluginState = stateReducer(\n pluginState,\n tr.getMeta('setInvisibleCharactersVisible'),\n )\n\n const decorations = getUpdatedRanges(tr).reduce(\n (nextDecorations, [from, to]) => {\n return addDecorationsBetweenPositions(from, to, currentState, nextDecorations)\n },\n newPluginState.decorations.map(tr.mapping, tr.doc),\n )\n\n return {\n ...newPluginState,\n decorations,\n }\n },\n },\n\n props: {\n decorations(editorState) {\n const pluginState = this.getState(editorState)\n\n const visible = pluginState?.visible\n const decorations = pluginState?.decorations\n\n return visible ? decorations : emptyDecorationSet\n },\n },\n })\n}\n\nexport default InvisibleCharactersPlugin\n","import { Decoration } from '@tiptap/pm/view'\n\nexport const createDecorationWidget = (pos: number, type: string, content?: string) => {\n const createElement = () => {\n const newElement = document.createElement('span')\n\n newElement.classList.add('tiptap-invisible-character')\n newElement.classList.add(`tiptap-invisible-character--${type}`)\n\n if (content) {\n newElement.textContent = content\n }\n\n return newElement\n }\n\n return Decoration.widget(pos, createElement, {\n key: type,\n marks: [],\n side: 1000,\n })\n}\n\nexport default createDecorationWidget\n","import type { Node } from '@tiptap/pm/model'\nimport type { DecorationSet } from '@tiptap/pm/view'\n\nimport { createDecorationWidget } from './utils/create-decoration-widget.js'\n\nexport interface InvisibleNodeOptions {\n content?: string\n position?: (node: Node, pos: number) => number\n predicate: (value: Node) => boolean\n priority?: number\n type: string\n}\n\n/** Default position for nodes is always at the end of the node */\nconst defaultPosition = (node: Node, pos: number) => pos + node.nodeSize - 1\n\nexport class InvisibleNode {\n predicate: (value: Node) => boolean\n\n position: (node: Node, pos: number) => number\n\n content?: string\n\n type: string\n\n priority: number\n\n constructor(options: InvisibleNodeOptions) {\n this.predicate = options.predicate\n this.type = options.type\n this.position = options.position || defaultPosition\n this.content = options.content\n this.priority = options.priority || 100\n }\n\n createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet) {\n let newDecorations = decorations\n\n doc.nodesBetween(from, to, (node, pos) => {\n if (this.test(node)) {\n const decorationPosition = this.position(node, pos)\n const oldDecorations = newDecorations.find(\n decorationPosition,\n decorationPosition,\n spec => spec.key === this.type,\n )\n\n newDecorations = newDecorations\n .remove(oldDecorations)\n .add(doc, [createDecorationWidget(decorationPosition, this.type, this.content)])\n }\n })\n return newDecorations\n }\n\n test(value: Node) {\n return this.predicate(value)\n }\n}\n\nexport default InvisibleNode\n","import { InvisibleNode } from '../InvisibleNode.js'\n\nexport class HardBreakNode extends InvisibleNode {\n constructor() {\n super({\n type: 'break',\n predicate: node => node.type === node.type.schema.nodes.hardBreak,\n })\n }\n}\n\nexport default HardBreakNode\n","import { InvisibleNode } from '../InvisibleNode.js'\n\nexport class ParagraphNode extends InvisibleNode {\n constructor() {\n super({\n type: 'paragraph',\n predicate: node => node.type === node.type.schema.nodes.paragraph,\n })\n }\n}\n\nexport default ParagraphNode\n","import type { Node } from '@tiptap/pm/model'\n\nimport type { Position } from '../../types.js'\n\nexport const textBetween = (from: number, to: number, doc: Node) => {\n const positions: Position[] = []\n\n doc.nodesBetween(from, to, (node, pos) => {\n if (node.isText) {\n const offset = Math.max(from, pos) - pos\n\n positions.push({\n pos: pos + offset,\n text: node.text?.slice(offset, to - pos) || '',\n })\n }\n })\n\n return positions\n}\n\nexport default textBetween\n","import type { Node } from '@tiptap/pm/model'\nimport type { DecorationSet } from '@tiptap/pm/view'\n\nimport { createDecorationWidget } from './utils/create-decoration-widget.js'\nimport { textBetween } from './utils/text-between.js'\n\nexport interface InvisibleCharacterOptions {\n type: string\n predicate: (value: string) => boolean\n priority?: number\n content?: string\n}\n\nexport class InvisibleCharacter {\n predicate: (value: string) => boolean\n\n content?: string\n\n type: string\n\n priority: number\n\n constructor(options: InvisibleCharacterOptions) {\n this.predicate = options.predicate\n this.type = options.type\n this.content = options.content\n this.priority = options.priority || 100\n }\n\n createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet) {\n const textContent = textBetween(from, to, doc)\n\n return textContent.reduce((oldDecorations, currentPosition) => {\n return currentPosition.text.split('').reduce((innerDecorations, char, i) => {\n return this.test(char)\n ? innerDecorations.add(doc, [\n createDecorationWidget(currentPosition.pos + i, this.type, this.content),\n ])\n : innerDecorations\n }, oldDecorations)\n }, decorations)\n }\n\n test(value: string) {\n return this.predicate(value)\n }\n}\n\nexport default InvisibleCharacter\n","import { InvisibleCharacter } from '../InvisibleCharacter.js'\n\nexport class SpaceCharacter extends InvisibleCharacter {\n constructor() {\n super({\n type: 'space',\n predicate: (char: string) => char === ' ',\n })\n }\n}\n\nexport default SpaceCharacter\n","import { Extension } from '@tiptap/core'\n\nimport { InvisibleCharactersPlugin, InvisibleCharactersPluginKey } from './plugin/index.js'\nimport { HardBreakNode } from './plugin/invisible-characters/hardBreak.js'\nimport { ParagraphNode } from './plugin/invisible-characters/paragraph.js'\nimport { SpaceCharacter } from './plugin/invisible-characters/space.js'\nimport type { InvisibleCharactersOptions } from './types.js'\n\nexport { HardBreakNode, ParagraphNode, SpaceCharacter }\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n invisibleCharacters: {\n /**\n * Show invisible characters\n */\n showInvisibleCharacters: (show?: boolean) => ReturnType\n\n /**\n * Hide invisible characters\n */\n hideInvisibleCharacters: () => ReturnType\n\n /**\n * Toggle invisible characters\n */\n toggleInvisibleCharacters: () => ReturnType\n }\n }\n}\n\nexport const InvisibleCharacters = Extension.create<InvisibleCharactersOptions>({\n name: 'invisibleCharacters',\n\n addOptions() {\n return {\n visible: true,\n builders: [new SpaceCharacter(), new ParagraphNode(), new HardBreakNode()],\n injectCSS: true,\n injectNonce: undefined,\n }\n },\n\n addProseMirrorPlugins() {\n return [InvisibleCharactersPlugin(this.editor.state, this.options)]\n },\n\n addStorage() {\n return {\n visibility: () => this.options.visible,\n }\n },\n\n onBeforeCreate() {\n this.storage.visibility = () => {\n return InvisibleCharactersPluginKey.getState(this.editor.state)?.visible\n }\n },\n\n addCommands() {\n return {\n showInvisibleCharacters:\n (visibility = true) =>\n ({ dispatch, tr }) => {\n if (dispatch) {\n tr.setMeta('setInvisibleCharactersVisible', visibility)\n }\n\n return true\n },\n hideInvisibleCharacters:\n () =>\n ({ dispatch, tr }) => {\n if (dispatch) {\n tr.setMeta('setInvisibleCharactersVisible', false)\n }\n\n return true\n },\n toggleInvisibleCharacters:\n () =>\n ({ dispatch, tr, state }) => {\n const visibility = !InvisibleCharactersPluginKey.getState(state)?.visible\n\n if (dispatch) {\n tr.setMeta('setInvisibleCharactersVisible', visibility)\n }\n\n return true\n },\n }\n },\n})\n\nexport default InvisibleCharacters\n","import { InvisibleCharacters } from './invisible-characters.js'\n\nexport * from './invisible-characters.js'\nexport * from './plugin/invisible-characters/hardBreak.js'\nexport * from './plugin/invisible-characters/paragraph.js'\nexport * from './plugin/invisible-characters/space.js'\nexport * from './plugin/InvisibleCharacter.js'\nexport * from './plugin/InvisibleNode.js'\nexport * from './types.js'\n\nexport default InvisibleCharacters\n"],"mappings":";;;;;;;;AAEA,MAAa,gBAAgB,OAAoB,YAAkC;CACjF,IAAI,YAAY,KAAA,GACd,OAAO;CAGT,OAAO;EAAE,GAAG;EAAO;CAAQ;AAC7B;;;ACRA,MAAa,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACArB,MAAa,kBAAkB,OAAe,UAAqC;CACjF,MAAM,iBACJ,SAAS,cAAc,yDAAyD;CAGlF,IAAI,mBAAmB,MACrB,OAAO;CAGT,MAAM,YAAY,SAAS,cAAc,OAAO;CAEhD,IAAI,OACF,UAAU,aAAa,SAAS,KAAK;CAGvC,UAAU,aAAa,oDAAoD,EAAE;CAC7E,UAAU,YAAY;CACtB,SAAS,qBAAqB,MAAM,CAAC,CAAC,EAAE,CAAC,YAAY,SAAS;CAE9D,OAAO;AACT;;;AChBA,MAAa,oBAAoB,EAAE,cAAwC;CACzE,MAAM,SAAsB,CAAC;CAE7B,QAAQ,KAAK,SAAS,SAAS,MAAM;EACnC,QAAQ,SAAS,WAAW,SAAS,UAAU,WAAW;GACxD,OAAO,KAAK,CAAC,QAAQ,MAAM,IAAI,CAAC,CAAC,CAAC,IAAI,QAAQ,GAAG,QAAQ,MAAM,IAAI,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC;EACpF,CAAC;CACH,CAAC;CAED,OAAO;AACT;;;ACJA,MAAa,+BAA+B,IAAIA,iBAAAA,UAAuB,qBAAqB;AAE5F,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AU,OAAmC;CAC9E,MAAM;CAEN,aAAa;EACX,OAAO;GACL,SAAS;GACT,UAAU;IAAC,IAAI,eAAe;IAAG,IAAI,cAAc;IAAG,IAAI,cAAc;GAAC;GACzE,WAAW;GACX,aAAa,KAAA;EACf;CACF;CAEA,wBAAwB;EACtB,OAAO,CAAC,0BAA0B,KAAK,OAAO,OAAO,KAAK,OAAO,CAAC;CACpE;CAEA,aAAa;EACX,OAAO,EACL,kBAAkB,KAAK,QAAQ,QACjC;CACF;CAEA,iBAAiB;EACf,KAAK,QAAQ,mBAAmB;;GAC9B,QAAA,wBAAO,6BAA6B,SAAS,KAAK,OAAO,KAAK,OAAA,QAAA,0BAAA,KAAA,IAAA,KAAA,IAAA,sBAAG;EACnE;CACF;CAEA,cAAc;EACZ,OAAO;GACL,0BACG,aAAa,UACb,EAAE,UAAU,SAAS;IACpB,IAAI,UACF,GAAG,QAAQ,iCAAiC,UAAU;IAGxD,OAAO;GACT;GACF,gCAEG,EAAE,UAAU,SAAS;IACpB,IAAI,UACF,GAAG,QAAQ,iCAAiC,KAAK;IAGnD,OAAO;GACT;GACF,kCAEG,EAAE,UAAU,IAAI,YAAY;;IAC3B,MAAM,aAAa,GAAA,yBAAC,6BAA6B,SAAS,KAAK,OAAA,QAAA,2BAAA,KAAA,IAAA,KAAA,IAAA,uBAAG;IAElE,IAAI,UACF,GAAG,QAAQ,iCAAiC,UAAU;IAGxD,OAAO;GACT;EACJ;CACF;AACF,CAAC;;;AClFD,IAAA,cAAe"}
package/dist/index.d.cts CHANGED
@@ -1,97 +1,104 @@
1
- import { Extension } from '@tiptap/core';
2
- import { DecorationSet } from '@tiptap/pm/view';
3
- import { Node } from '@tiptap/pm/model';
4
-
1
+ import { Extension } from "@tiptap/core";
2
+ import { Node } from "@tiptap/pm/model";
3
+ import { DecorationSet } from "@tiptap/pm/view";
4
+ //#region src/plugin/InvisibleNode.d.ts
5
5
  interface InvisibleNodeOptions {
6
- content?: string;
7
- position?: (node: Node, pos: number) => number;
8
- predicate: (value: Node) => boolean;
9
- priority?: number;
10
- type: string;
6
+ content?: string;
7
+ position?: (node: Node, pos: number) => number;
8
+ predicate: (value: Node) => boolean;
9
+ priority?: number;
10
+ type: string;
11
11
  }
12
12
  declare class InvisibleNode {
13
- predicate: (value: Node) => boolean;
14
- position: (node: Node, pos: number) => number;
15
- content?: string;
16
- type: string;
17
- priority: number;
18
- constructor(options: InvisibleNodeOptions);
19
- createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet): DecorationSet;
20
- test(value: Node): boolean;
13
+ predicate: (value: Node) => boolean;
14
+ position: (node: Node, pos: number) => number;
15
+ content?: string;
16
+ type: string;
17
+ priority: number;
18
+ constructor(options: InvisibleNodeOptions);
19
+ createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet): DecorationSet;
20
+ test(value: Node): boolean;
21
21
  }
22
-
22
+ //#endregion
23
+ //#region src/plugin/invisible-characters/hardBreak.d.ts
23
24
  declare class HardBreakNode extends InvisibleNode {
24
- constructor();
25
+ constructor();
25
26
  }
26
-
27
+ //#endregion
28
+ //#region src/plugin/invisible-characters/paragraph.d.ts
27
29
  declare class ParagraphNode extends InvisibleNode {
28
- constructor();
30
+ constructor();
29
31
  }
30
-
32
+ //#endregion
33
+ //#region src/plugin/InvisibleCharacter.d.ts
31
34
  interface InvisibleCharacterOptions {
32
- type: string;
33
- predicate: (value: string) => boolean;
34
- priority?: number;
35
- content?: string;
35
+ type: string;
36
+ predicate: (value: string) => boolean;
37
+ priority?: number;
38
+ content?: string;
36
39
  }
37
40
  declare class InvisibleCharacter {
38
- predicate: (value: string) => boolean;
39
- content?: string;
40
- type: string;
41
- priority: number;
42
- constructor(options: InvisibleCharacterOptions);
43
- createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet): DecorationSet;
44
- test(value: string): boolean;
41
+ predicate: (value: string) => boolean;
42
+ content?: string;
43
+ type: string;
44
+ priority: number;
45
+ constructor(options: InvisibleCharacterOptions);
46
+ createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet): DecorationSet;
47
+ test(value: string): boolean;
45
48
  }
46
-
49
+ //#endregion
50
+ //#region src/plugin/invisible-characters/space.d.ts
47
51
  declare class SpaceCharacter extends InvisibleCharacter {
48
- constructor();
52
+ constructor();
49
53
  }
50
-
54
+ //#endregion
55
+ //#region src/types.d.ts
51
56
  interface InvisibleCharactersOptions {
52
- visible: boolean;
53
- builders: Array<InvisibleCharacter | InvisibleNode>;
54
- injectCSS: boolean;
55
- injectNonce: string | undefined;
57
+ visible: boolean;
58
+ builders: Array<InvisibleCharacter | InvisibleNode>;
59
+ injectCSS: boolean;
60
+ injectNonce: string | undefined;
56
61
  }
57
62
  interface Position {
58
- pos: number;
59
- text: string;
63
+ pos: number;
64
+ text: string;
60
65
  }
61
66
  interface PluginState {
62
- visible: boolean;
63
- decorations: DecorationSet;
67
+ visible: boolean;
68
+ decorations: DecorationSet;
64
69
  }
65
70
  interface InvisibleCharactersStorage {
66
- /**
67
- * Get whether the invisible characters are shown or not
68
- */
69
- visibility: () => boolean;
71
+ /**
72
+ * Get whether the invisible characters are shown or not
73
+ */
74
+ visibility: () => boolean;
70
75
  }
71
76
  declare module '@tiptap/core' {
72
- interface Storage {
73
- invisibleCharacters: InvisibleCharactersStorage;
74
- }
77
+ interface Storage {
78
+ invisibleCharacters: InvisibleCharactersStorage;
79
+ }
75
80
  }
76
-
81
+ //#endregion
82
+ //#region src/invisible-characters.d.ts
77
83
  declare module '@tiptap/core' {
78
- interface Commands<ReturnType> {
79
- invisibleCharacters: {
80
- /**
81
- * Show invisible characters
82
- */
83
- showInvisibleCharacters: (show?: boolean) => ReturnType;
84
- /**
85
- * Hide invisible characters
86
- */
87
- hideInvisibleCharacters: () => ReturnType;
88
- /**
89
- * Toggle invisible characters
90
- */
91
- toggleInvisibleCharacters: () => ReturnType;
92
- };
93
- }
84
+ interface Commands<ReturnType> {
85
+ invisibleCharacters: {
86
+ /**
87
+ * Show invisible characters
88
+ */
89
+ showInvisibleCharacters: (show?: boolean) => ReturnType;
90
+ /**
91
+ * Hide invisible characters
92
+ */
93
+ hideInvisibleCharacters: () => ReturnType;
94
+ /**
95
+ * Toggle invisible characters
96
+ */
97
+ toggleInvisibleCharacters: () => ReturnType;
98
+ };
99
+ }
94
100
  }
95
101
  declare const InvisibleCharacters: Extension<InvisibleCharactersOptions, any>;
96
-
97
- export { HardBreakNode, InvisibleCharacter, type InvisibleCharacterOptions, InvisibleCharacters, type InvisibleCharactersOptions, type InvisibleCharactersStorage, InvisibleNode, type InvisibleNodeOptions, ParagraphNode, type PluginState, type Position, SpaceCharacter, InvisibleCharacters as default };
102
+ //#endregion
103
+ export { HardBreakNode, InvisibleCharacter, InvisibleCharacterOptions, InvisibleCharacters, InvisibleCharacters as default, InvisibleCharactersOptions, InvisibleCharactersStorage, InvisibleNode, InvisibleNodeOptions, ParagraphNode, PluginState, Position, SpaceCharacter };
104
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/plugin/InvisibleNode.ts","../src/plugin/invisible-characters/hardBreak.ts","../src/plugin/invisible-characters/paragraph.ts","../src/plugin/InvisibleCharacter.ts","../src/plugin/invisible-characters/space.ts","../src/types.ts","../src/invisible-characters.ts"],"mappings":";;;;UAKiB;EACf;EACA,YAAY,MAAM,MAAM;EACxB,YAAY,OAAO;EACnB;EACA;;cAMW;EACX,YAAY,OAAO;EAEnB,WAAW,MAAM,MAAM;EAEvB;EAEA;EAEA;EAEY,YAAA,SAAS;EAQrB,iBAAiB,cAAc,YAAY,KAAK,MAAM,aAAa,gBAAa;EAoBhF,KAAK,OAAO;;;;cCrDD,sBAAsB;EAAA;;;;cCAtB,sBAAsB;EAAA;;;;UCIlB;EACf;EACA,YAAY;EACZ;EACA;;cAGW;EACX,YAAY;EAEZ;EAEA;EAEA;EAEY,YAAA,SAAS;EAOrB,iBAAiB,cAAc,YAAY,KAAK,MAAM,aAAa,gBAAa;EAchF,KAAK;;;;cCzCM,uBAAuB;EAAA;;;;UCGnB;EACf;EACA,UAAU,MAAM,qBAAqB;EACrC;EACA;;UAGe;EACf;EACA;;UAGe;EACf;EACA,aAAa;;UAGE;;;;EAIf;;;YAIU;IACR,qBAAqB;;;;;;YCpBb,SAAS;IACjB;;;;MAIE,0BAA0B,mBAAmB;;;;MAK7C,+BAA+B;;;;MAK/B,iCAAiC;;;;cAK1B,qBAAmB,UAAA"}
package/dist/index.d.ts CHANGED
@@ -1,97 +1,104 @@
1
- import { Extension } from '@tiptap/core';
2
- import { DecorationSet } from '@tiptap/pm/view';
3
- import { Node } from '@tiptap/pm/model';
4
-
1
+ import { Extension } from "@tiptap/core";
2
+ import { DecorationSet } from "@tiptap/pm/view";
3
+ import { Node } from "@tiptap/pm/model";
4
+ //#region src/plugin/InvisibleNode.d.ts
5
5
  interface InvisibleNodeOptions {
6
- content?: string;
7
- position?: (node: Node, pos: number) => number;
8
- predicate: (value: Node) => boolean;
9
- priority?: number;
10
- type: string;
6
+ content?: string;
7
+ position?: (node: Node, pos: number) => number;
8
+ predicate: (value: Node) => boolean;
9
+ priority?: number;
10
+ type: string;
11
11
  }
12
12
  declare class InvisibleNode {
13
- predicate: (value: Node) => boolean;
14
- position: (node: Node, pos: number) => number;
15
- content?: string;
16
- type: string;
17
- priority: number;
18
- constructor(options: InvisibleNodeOptions);
19
- createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet): DecorationSet;
20
- test(value: Node): boolean;
13
+ predicate: (value: Node) => boolean;
14
+ position: (node: Node, pos: number) => number;
15
+ content?: string;
16
+ type: string;
17
+ priority: number;
18
+ constructor(options: InvisibleNodeOptions);
19
+ createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet): DecorationSet;
20
+ test(value: Node): boolean;
21
21
  }
22
-
22
+ //#endregion
23
+ //#region src/plugin/invisible-characters/hardBreak.d.ts
23
24
  declare class HardBreakNode extends InvisibleNode {
24
- constructor();
25
+ constructor();
25
26
  }
26
-
27
+ //#endregion
28
+ //#region src/plugin/invisible-characters/paragraph.d.ts
27
29
  declare class ParagraphNode extends InvisibleNode {
28
- constructor();
30
+ constructor();
29
31
  }
30
-
32
+ //#endregion
33
+ //#region src/plugin/InvisibleCharacter.d.ts
31
34
  interface InvisibleCharacterOptions {
32
- type: string;
33
- predicate: (value: string) => boolean;
34
- priority?: number;
35
- content?: string;
35
+ type: string;
36
+ predicate: (value: string) => boolean;
37
+ priority?: number;
38
+ content?: string;
36
39
  }
37
40
  declare class InvisibleCharacter {
38
- predicate: (value: string) => boolean;
39
- content?: string;
40
- type: string;
41
- priority: number;
42
- constructor(options: InvisibleCharacterOptions);
43
- createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet): DecorationSet;
44
- test(value: string): boolean;
41
+ predicate: (value: string) => boolean;
42
+ content?: string;
43
+ type: string;
44
+ priority: number;
45
+ constructor(options: InvisibleCharacterOptions);
46
+ createDecoration(from: number, to: number, doc: Node, decorations: DecorationSet): DecorationSet;
47
+ test(value: string): boolean;
45
48
  }
46
-
49
+ //#endregion
50
+ //#region src/plugin/invisible-characters/space.d.ts
47
51
  declare class SpaceCharacter extends InvisibleCharacter {
48
- constructor();
52
+ constructor();
49
53
  }
50
-
54
+ //#endregion
55
+ //#region src/types.d.ts
51
56
  interface InvisibleCharactersOptions {
52
- visible: boolean;
53
- builders: Array<InvisibleCharacter | InvisibleNode>;
54
- injectCSS: boolean;
55
- injectNonce: string | undefined;
57
+ visible: boolean;
58
+ builders: Array<InvisibleCharacter | InvisibleNode>;
59
+ injectCSS: boolean;
60
+ injectNonce: string | undefined;
56
61
  }
57
62
  interface Position {
58
- pos: number;
59
- text: string;
63
+ pos: number;
64
+ text: string;
60
65
  }
61
66
  interface PluginState {
62
- visible: boolean;
63
- decorations: DecorationSet;
67
+ visible: boolean;
68
+ decorations: DecorationSet;
64
69
  }
65
70
  interface InvisibleCharactersStorage {
66
- /**
67
- * Get whether the invisible characters are shown or not
68
- */
69
- visibility: () => boolean;
71
+ /**
72
+ * Get whether the invisible characters are shown or not
73
+ */
74
+ visibility: () => boolean;
70
75
  }
71
76
  declare module '@tiptap/core' {
72
- interface Storage {
73
- invisibleCharacters: InvisibleCharactersStorage;
74
- }
77
+ interface Storage {
78
+ invisibleCharacters: InvisibleCharactersStorage;
79
+ }
75
80
  }
76
-
81
+ //#endregion
82
+ //#region src/invisible-characters.d.ts
77
83
  declare module '@tiptap/core' {
78
- interface Commands<ReturnType> {
79
- invisibleCharacters: {
80
- /**
81
- * Show invisible characters
82
- */
83
- showInvisibleCharacters: (show?: boolean) => ReturnType;
84
- /**
85
- * Hide invisible characters
86
- */
87
- hideInvisibleCharacters: () => ReturnType;
88
- /**
89
- * Toggle invisible characters
90
- */
91
- toggleInvisibleCharacters: () => ReturnType;
92
- };
93
- }
84
+ interface Commands<ReturnType> {
85
+ invisibleCharacters: {
86
+ /**
87
+ * Show invisible characters
88
+ */
89
+ showInvisibleCharacters: (show?: boolean) => ReturnType;
90
+ /**
91
+ * Hide invisible characters
92
+ */
93
+ hideInvisibleCharacters: () => ReturnType;
94
+ /**
95
+ * Toggle invisible characters
96
+ */
97
+ toggleInvisibleCharacters: () => ReturnType;
98
+ };
99
+ }
94
100
  }
95
101
  declare const InvisibleCharacters: Extension<InvisibleCharactersOptions, any>;
96
-
97
- export { HardBreakNode, InvisibleCharacter, type InvisibleCharacterOptions, InvisibleCharacters, type InvisibleCharactersOptions, type InvisibleCharactersStorage, InvisibleNode, type InvisibleNodeOptions, ParagraphNode, type PluginState, type Position, SpaceCharacter, InvisibleCharacters as default };
102
+ //#endregion
103
+ export { HardBreakNode, InvisibleCharacter, InvisibleCharacterOptions, InvisibleCharacters, InvisibleCharacters as default, InvisibleCharactersOptions, InvisibleCharactersStorage, InvisibleNode, InvisibleNodeOptions, ParagraphNode, PluginState, Position, SpaceCharacter };
104
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/plugin/InvisibleNode.ts","../src/plugin/invisible-characters/hardBreak.ts","../src/plugin/invisible-characters/paragraph.ts","../src/plugin/InvisibleCharacter.ts","../src/plugin/invisible-characters/space.ts","../src/types.ts","../src/invisible-characters.ts"],"mappings":";;;;UAKiB;EACf;EACA,YAAY,MAAM,MAAM;EACxB,YAAY,OAAO;EACnB;EACA;;cAMW;EACX,YAAY,OAAO;EAEnB,WAAW,MAAM,MAAM;EAEvB;EAEA;EAEA;EAEY,YAAA,SAAS;EAQrB,iBAAiB,cAAc,YAAY,KAAK,MAAM,aAAa,gBAAa;EAoBhF,KAAK,OAAO;;;;cCrDD,sBAAsB;EAAA;;;;cCAtB,sBAAsB;EAAA;;;;UCIlB;EACf;EACA,YAAY;EACZ;EACA;;cAGW;EACX,YAAY;EAEZ;EAEA;EAEA;EAEY,YAAA,SAAS;EAOrB,iBAAiB,cAAc,YAAY,KAAK,MAAM,aAAa,gBAAa;EAchF,KAAK;;;;cCzCM,uBAAuB;EAAA;;;;UCGnB;EACf;EACA,UAAU,MAAM,qBAAqB;EACrC;EACA;;UAGe;EACf;EACA;;UAGe;EACf;EACA,aAAa;;UAGE;;;;EAIf;;;YAIU;IACR,qBAAqB;;;;;;YCpBb,SAAS;IACjB;;;;MAIE,0BAA0B,mBAAmB;;;;MAK7C,+BAA+B;;;;MAK/B,iCAAiC;;;;cAK1B,qBAAmB,UAAA"}