@markput/react 0.10.1 → 0.11.0

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.
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["#map","#counter","#target","#store","signal","computed","alienSignal","alienComputed","alienEffect","getOrCreate","tokensToString","#scope","#subscribeParse","#subscribeUpdated","#initialized","#lastValue","#lastParser","#mousedownHandler","#pressedNode","#isPressed","#mousemoveHandler","#mouseupHandler","#selectionchangeHandler","#scope","#keydownHandler","#copyHandler","#handleCopy","#cutHandler","#scope","#syncDragTextContent","#syncTextContent","#syncMarkChildren","#keydownHandler","#handleBlockArrowLeftRight","#handleArrowUpDown","#handleDelete","#handleEnter","#beforeInputHandler","#handleBlockBeforeInput","#unsub","#reorder","#add","#delete","#duplicate","#scope","#focusinHandler","#focusoutHandler","#clickHandler","#recover","#keydownHandler","#handleDelete","#pasteHandler","#beforeInputHandler","#scope","#enableClose","#disableClose","#selectionChangeHandler","#focusinHandler","#focusoutHandler","#escHandler","#clickHandler","#blockIndex","#dragAction","#cleanupContainer","#emit","#cleanupGrip","#cleanupMenu","#map","#store","#token","#readOnly","#emitChange","styles","styles","styles","styles","styles","styles","styles"],"sources":["../../../core/src/shared/utils/shallow.ts","../../../core/src/shared/utils/cx.ts","../../../core/src/shared/utils/merge.ts","../../../core/src/shared/constants.ts","../../../core/src/shared/classes/MarkputHandler.ts","../../../core/src/shared/classes/KeyGenerator.ts","../../../core/src/shared/checkers/domGuards.ts","../../../core/src/features/caret/Caret.ts","../../../core/src/shared/escape.ts","../../../core/src/features/caret/TriggerFinder.ts","../../../core/src/shared/classes/NodeProxy.ts","../../../core/src/shared/signals/registry.ts","../../../core/src/shared/signals/alien-signals/system.ts","../../../core/src/shared/signals/alien-signals/index.ts","../../../core/src/shared/signals/signal.ts","../../../core/src/features/parsing/parser/constants.ts","../../../core/src/features/parsing/parser/core/MarkupDescriptor.ts","../../../core/src/features/parsing/parser/core/MarkupRegistry.ts","../../../core/src/features/parsing/parser/utils/getSegmentIndex.ts","../../../core/src/features/parsing/parser/core/Match.ts","../../../core/src/features/parsing/parser/core/PatternMatcher.ts","../../../core/src/features/parsing/parser/core/SegmentMatcher.ts","../../../core/src/features/parsing/parser/utils/createTextToken.ts","../../../core/src/features/parsing/parser/core/TreeBuilder.ts","../../../core/src/features/parsing/parser/utils/processTokens.ts","../../../core/src/features/parsing/parser/utils/annotate.ts","../../../core/src/features/parsing/parser/utils/toString.ts","../../../core/src/features/parsing/parser/Parser.ts","../../../core/src/features/parsing/parser/utils/denote.ts","../../../core/src/features/parsing/utils/findToken.ts","../../../core/src/features/parsing/preparsing/utils/findGap.ts","../../../core/src/features/parsing/preparsing/utils/getClosestIndexes.ts","../../../core/src/features/parsing/utils/valueParser.ts","../../../core/src/features/parsing/ParseFeature.ts","../../../core/src/features/navigation/navigation.ts","../../../core/src/features/selection/selectionHelpers.ts","../../../core/src/features/selection/TextSelectionFeature.ts","../../../core/src/features/arrownav/ArrowNavFeature.ts","../../../core/src/features/clipboard/pasteMarkup.ts","../../../core/src/features/clipboard/selectionToTokens.ts","../../../core/src/features/clipboard/CopyFeature.ts","../../../core/src/features/drag/operations.ts","../../../core/src/features/editing/utils/createNewSpan.ts","../../../core/src/features/editing/createRowContent.ts","../../../core/src/features/editing/utils/deleteMark.ts","../../../core/src/features/editable/isTextTokenSpan.ts","../../../core/src/features/editable/ContentEditableFeature.ts","../../../core/src/features/block-editing/rawPosition.ts","../../../core/src/features/block-editing/BlockEditFeature.ts","../../../core/src/features/drag/tokens.ts","../../../core/src/features/drag/DragFeature.ts","../../../core/src/shared/utils/dragUtils.ts","../../../core/src/features/drag/config.ts","../../../core/src/features/events/SystemListenerFeature.ts","../../../core/src/features/focus/FocusFeature.ts","../../../core/src/features/input/InputFeature.ts","../../../core/src/features/overlay/filterSuggestions.ts","../../../core/src/features/overlay/createMarkFromOverlay.ts","../../../core/src/features/overlay/OverlayFeature.ts","../../../core/src/features/overlay/suggestionNavigation.ts","../../../core/src/shared/utils/dataAttributes.ts","../../../core/src/features/slots/resolveOptionSlot.ts","../../../core/src/features/slots/resolveSlot.ts","../../../core/src/features/slots/createSlots.ts","../../../core/src/shared/utils/menuUtils.ts","../../../core/src/store/BlockStore.ts","../../../core/src/store/BlockRegistry.ts","../../../core/src/store/Store.ts","../../../core/src/features/mark/MarkHandler.ts","../src/lib/hooks/createUseHook.ts","../src/lib/providers/StoreContext.ts","../src/components/Popup/List.tsx","../src/components/Popup/ListItem.tsx","../src/components/Popup/Popup.tsx","../src/components/BlockMenu.tsx","../src/components/DragHandle.tsx","../src/components/DropIndicator.tsx","../src/lib/providers/TokenContext.ts","../src/components/Token.tsx","../src/components/Block.tsx","../src/components/Container.tsx","../src/lib/hooks/useOverlay.tsx","../src/components/Suggestions/Suggestions.tsx","../src/components/OverlayRenderer.tsx","../src/components/MarkedInput.tsx","../src/lib/hooks/useMark.tsx"],"sourcesContent":["export function shallow(objA: unknown, objB: unknown) {\n\tif (Object.is(objA, objB)) {\n\t\treturn true\n\t}\n\tif (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {\n\t\treturn false\n\t}\n\tconst keysA = Object.keys(objA)\n\tif (keysA.length !== Object.keys(objB).length) {\n\t\treturn false\n\t}\n\tfor (const key of keysA) {\n\t\tif (!Object.prototype.hasOwnProperty.call(objB, key)) {\n\t\t\treturn false\n\t\t}\n\t\tif (!Object.is(Reflect.get(objA, key), Reflect.get(objB, key))) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}","export function cx(...classes: (string | undefined | null | false)[]): string | undefined {\n\treturn classes.filter(Boolean).join(' ') || undefined\n}","export function merge<T extends object>(...objects: (T | undefined | null | false)[]): T | undefined {\n\t// oxlint-disable-next-line no-unsafe-argument, no-unsafe-call, no-unsafe-return, no-unsafe-type-assertion\n\tconst result = Object.assign({}, ...objects.filter(Boolean)) as T\n\treturn Object.keys(result).length > 0 ? result : undefined\n}","import type {Markup} from '../features/parsing/parser/types'\nimport type {CoreOption} from './types'\n\nexport interface DefaultOverlayConfig {\n\ttrigger?: string\n\tdata?: string[]\n}\n\nexport interface DefaultOption extends CoreOption {\n\toverlay?: DefaultOverlayConfig\n}\n\nexport const KEYBOARD = {\n\t// Navigation Keys\n\tUP: 'ArrowUp',\n\tDOWN: 'ArrowDown',\n\tLEFT: 'ArrowLeft',\n\tRIGHT: 'ArrowRight',\n\tEND: 'End',\n\tHOME: 'Home',\n\tPAGE_DOWN: 'PageDown',\n\tPAGE_UP: 'PageUp',\n\n\t// Whitespace Keys\n\tENTER: 'Enter',\n\tTAB: 'Tab',\n\tSPACE: ' ',\n\n\t// Editing Keys\n\tBACKSPACE: 'Backspace',\n\tDELETE: 'Delete',\n\tCOMMA: ',',\n\n\t// UI Keys\n\tESC: 'Escape',\n} as const\nexport type KEYBOARD = (typeof KEYBOARD)[keyof typeof KEYBOARD]\n\nexport const DEFAULT_OVERLAY_TRIGGER = '@'\n\nexport const DEFAULT_MARKUP: Markup = '@[__value__](__meta__)'\n\nexport const DEFAULT_OPTIONS: DefaultOption[] = [\n\t{\n\t\tmarkup: DEFAULT_MARKUP,\n\t\toverlay: {\n\t\t\ttrigger: DEFAULT_OVERLAY_TRIGGER,\n\t\t\tdata: [],\n\t\t},\n\t},\n]","import type {Store} from '../../store'\n\nexport class MarkputHandler {\n\tconstructor(private store: Store) {}\n\n\tget container() {\n\t\treturn this.store.refs.container\n\t}\n\n\tget overlay() {\n\t\treturn this.store.refs.overlay\n\t}\n\n\tfocus() {\n\t\tthis.store.nodes.focus.head?.focus()\n\t}\n}","export class KeyGenerator {\n\t#counter = 1\n\t#map = new WeakMap<object, number>()\n\n\tget(object: object) {\n\t\tif (this.#map.has(object)) return this.#map.get(object)\n\n\t\tthis.#map.set(object, this.#counter)\n\t\treturn this.#counter++\n\t}\n}","/** Type guard: checks if a value is an HTMLElement. */\nexport function isHtmlElement(el: unknown): el is HTMLElement {\n\treturn typeof HTMLElement !== 'undefined' && el instanceof HTMLElement\n}\n\n/** Type guard: checks if a value is a Text node. */\nexport function isTextNode(node: unknown): node is Text {\n\treturn node instanceof Text\n}\n\n/** Get the i-th child of an element as HTMLElement, or undefined if out of bounds or wrong type. */\nexport function childAt(parent: Element | null | undefined, index: number): HTMLElement | undefined {\n\tconst child = parent?.children[index]\n\treturn child instanceof HTMLElement ? child : undefined\n}\n\n/** Get all children of an element as HTMLElement[], filtering out non-HTML elements. */\nexport function htmlChildren(parent: Element | null | undefined): HTMLElement[] {\n\tif (!parent) return []\n\treturn Array.from(parent.children).filter((child): child is HTMLElement => child instanceof HTMLElement)\n}\n\n/** Get the first element child as HTMLElement, or null. */\nexport function firstHtmlChild(parent: Element | null | undefined): HTMLElement | null {\n\tconst child = parent?.firstElementChild\n\treturn child instanceof HTMLElement ? child : null\n}\n\n/** Get the last element child as HTMLElement, or null. */\nexport function lastHtmlChild(parent: Element | null | undefined): HTMLElement | null {\n\tconst child = parent?.lastElementChild\n\treturn child instanceof HTMLElement ? child : null\n}\n\n/** Safely narrow an event's target to HTMLElement. */\nexport function htmlTarget(event: {target: EventTarget | null}): HTMLElement | null {\n\tconst {target} = event\n\treturn target instanceof HTMLElement ? target : null\n}\n\n/** Safely narrow an event's target to Node. */\nexport function nodeTarget(event: {target: EventTarget | null}): Node | null {\n\tconst {target} = event\n\treturn target instanceof Node ? target : null\n}\n\n/** Get the next node from a TreeWalker as Text, or null. */\nexport function nextText(walker: TreeWalker): Text | null {\n\tconst node = walker.nextNode()\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- nodeType === 3 guarantees Text; instanceof Text breaks in test envs\n\treturn node?.nodeType === 3 ? (node as Text) : null\n}","import {nextText} from '../../shared/checkers'\n\n/** Firefox-only CaretPosition (absent from TypeScript DOM lib) */\ninterface CaretPosition {\n\treadonly offsetNode: Node\n\treadonly offset: number\n}\n\n/** Non-standard document caret APIs absent from TypeScript DOM lib */\ninterface DocumentWithCaretFromPoint {\n\tcaretRangeFromPoint?(x: number, y: number): Range | null\n\tcaretPositionFromPoint?(x: number, y: number): CaretPosition | null\n}\n\n//TODO refact caret\nexport class Caret {\n\tstatic get isSelectedPosition() {\n\t\tconst selection = window.getSelection()\n\t\tif (!selection) return\n\t\treturn selection.isCollapsed\n\t}\n\n\tstatic getCurrentPosition() {\n\t\treturn window.getSelection()?.anchorOffset ?? 0\n\t}\n\n\t//TODO get span from state?\n\tstatic getFocusedSpan() {\n\t\treturn window.getSelection()?.anchorNode?.textContent ?? ''\n\t}\n\n\tstatic getSelectedNode() {\n\t\tconst node = window.getSelection()?.anchorNode\n\t\tif (node && document.contains(node)) return node\n\t\tthrow new Error('Anchor node of selection is not exists!')\n\t}\n\n\t//TODO add the returned type: \"{left: CSSProperties[\"left\"], top: CSSProperties[\"top\"]}\"?\n\tstatic getAbsolutePosition() {\n\t\tconst rect = window.getSelection()?.getRangeAt(0).getBoundingClientRect()\n\t\tif (rect) return {left: rect.left, top: rect.top + rect.height + 1}\n\t\treturn {left: 0, top: 0}\n\t}\n\n\t/** Returns the raw DOMRect of the current caret position, or null if unavailable. */\n\tstatic getCaretRect(): DOMRect | null {\n\t\ttry {\n\t\t\tconst range = window.getSelection()?.getRangeAt(0)\n\t\t\treturn range?.getBoundingClientRect() ?? null\n\t\t} catch {\n\t\t\treturn null\n\t\t}\n\t}\n\n\t/**\n\t * Returns true if the caret is on the first visual line of the element.\n\t */\n\tstatic isCaretOnFirstLine(element: HTMLElement): boolean {\n\t\tconst caretRect = this.getCaretRect()\n\t\tif (!caretRect || caretRect.height === 0) return true\n\t\tconst elRect = element.getBoundingClientRect()\n\t\treturn caretRect.top < elRect.top + caretRect.height + 2\n\t}\n\n\t/**\n\t * Returns true if the caret is on the last visual line of the element.\n\t */\n\tstatic isCaretOnLastLine(element: HTMLElement): boolean {\n\t\tconst caretRect = this.getCaretRect()\n\t\tif (!caretRect || caretRect.height === 0) return true\n\t\tconst elRect = element.getBoundingClientRect()\n\t\treturn caretRect.bottom > elRect.bottom - caretRect.height - 2\n\t}\n\n\t/**\n\t * Positions the caret in `element` at the character closest to the given x coordinate.\n\t * `y` defaults to the vertical center of the element.\n\t */\n\tstatic setAtX(element: HTMLElement, x: number, y?: number): void {\n\t\tconst elRect = element.getBoundingClientRect()\n\t\tconst targetY = y ?? elRect.top + elRect.height / 2\n\n\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- non-standard DOM APIs not in TS lib\n\t\tconst caretDoc = document as unknown as DocumentWithCaretFromPoint\n\t\tconst caretPos = caretDoc.caretRangeFromPoint?.(x, targetY) ?? caretDoc.caretPositionFromPoint?.(x, targetY)\n\n\t\tif (!caretPos) return\n\n\t\tconst sel = window.getSelection()\n\t\tif (!sel) return\n\n\t\tlet domRange: Range\n\t\tif (caretPos instanceof Range) {\n\t\t\tdomRange = caretPos\n\t\t} else if ('offsetNode' in caretPos) {\n\t\t\t// Firefox CaretPosition\n\t\t\tdomRange = document.createRange()\n\t\t\tdomRange.setStart(caretPos.offsetNode, caretPos.offset)\n\t\t\tdomRange.collapse(true)\n\t\t} else {\n\t\t\treturn\n\t\t}\n\n\t\tif (!element.contains(domRange.startContainer)) {\n\t\t\t// Clicked outside: clamp to end\n\t\t\tthis.setIndex(element, Infinity)\n\t\t\treturn\n\t\t}\n\n\t\tsel.removeAllRanges()\n\t\tsel.addRange(domRange)\n\t}\n\n\tstatic trySetIndex(element: HTMLElement, offset: number) {\n\t\ttry {\n\t\t\tthis.setIndex(element, offset)\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t}\n\t}\n\n\t/**\n\t * Sets the caret at character `offset` within `element` by walking text nodes.\n\t * Use Infinity to position at the very end of all text.\n\t */\n\tstatic setIndex(element: HTMLElement, offset: number) {\n\t\tconst selection = window.getSelection()\n\t\tif (!selection) return\n\n\t\tconst walker = document.createTreeWalker(element, 4 /* NodeFilter.SHOW_TEXT */)\n\t\tlet node = nextText(walker)\n\t\tif (!node) return\n\n\t\tlet remaining = isFinite(offset) ? Math.max(0, offset) : Infinity\n\n\t\tfor (;;) {\n\t\t\tconst next = nextText(walker)\n\t\t\tif (!next || remaining <= node.length) {\n\t\t\t\tconst charOffset = isFinite(remaining) ? Math.min(remaining, node.length) : node.length\n\t\t\t\tconst range = document.createRange()\n\t\t\t\trange.setStart(node, charOffset)\n\t\t\t\trange.collapse(true)\n\t\t\t\tselection.removeAllRanges()\n\t\t\t\tselection.addRange(range)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tremaining -= node.length\n\t\t\tnode = next\n\t\t}\n\t}\n\n\tstatic getCaretIndex(element: HTMLElement) {\n\t\tlet position = 0\n\n\t\tconst selection = window.getSelection()\n\t\t// Check if there is a selection (i.e. cursor in place)\n\t\tif (!selection?.rangeCount) return position\n\n\t\t// Store the original range\n\t\tconst range = selection.getRangeAt(0)\n\t\t// Clone the range\n\t\tconst preCaretRange = range.cloneRange()\n\t\t// Select all textual contents from the contenteditable element\n\t\tpreCaretRange.selectNodeContents(element)\n\t\t// And set the range end to the original clicked position\n\t\tpreCaretRange.setEnd(range.endContainer, range.endOffset)\n\t\t// Return the text length from contenteditable start to the range end\n\t\tposition = preCaretRange.toString().length\n\n\t\treturn position\n\t}\n\n\tstatic setCaretToEnd(element: HTMLElement | null | undefined) {\n\t\tif (!element) return\n\t\tthis.setIndex(element, Infinity)\n\t}\n\n\tstatic getIndex() {\n\t\tconst selection = window.getSelection()\n\t\treturn selection?.anchorOffset ?? NaN\n\t}\n\n\tstatic setIndex1(offset: number) {\n\t\tconst selection = window.getSelection()\n\t\tif (!selection?.anchorNode || !selection.rangeCount) return\n\n\t\tconst range = selection.getRangeAt(0)\n\t\trange.setStart(range.startContainer.firstChild ?? range.startContainer, offset)\n\t\trange.setEnd(range.startContainer.firstChild ?? range.startContainer, offset)\n\t}\n\n\tsetCaretRightTo(element: HTMLElement, offset: number) {\n\t\tconst selection = window.getSelection()\n\t\tconst range = selection?.getRangeAt(0)\n\t\trange?.setStart(range.endContainer, offset)\n\t\trange?.setEnd(range.endContainer, offset)\n\t}\n}","// escape RegExp special characters to match RegExp.escape behavior\n// Escapes all characters that have special meaning in regular expressions\nexport const escape = (str: string): string => {\n\treturn str.replace(/[.*+?^${}()|[\\]\\\\\\\\]/g, '\\\\$&')\n}","import {escape} from '../../shared/escape'\nimport type {OverlayMatch} from '../../shared/types'\nimport {Caret} from './Caret'\n\n/** Regex to match word characters from the start of a string */\nconst wordRegex = new RegExp(/^\\w*/)\n\n/**\n * Function type for extracting trigger from option\n * @template T - Type of option\n * @param option - The option object\n * @param index - Index of option in array\n * @returns Trigger string or undefined\n */\ntype TriggerExtractor<T> = (option: T, index: number) => string | undefined\n\nexport class TriggerFinder {\n\tspan: string\n\tnode: Node\n\tdividedText: {left: string; right: string}\n\n\tconstructor() {\n\t\tconst caretPosition = Caret.getCurrentPosition()\n\t\tthis.node = Caret.getSelectedNode()\n\t\tthis.span = Caret.getFocusedSpan()\n\t\tthis.dividedText = this.getDividedTextBy(caretPosition)\n\t}\n\n\t/**\n\t * Find overlay match in text using provided options and trigger extractor.\n\t * @template T - Type of option objects\n\t * @param options - Array of options to search through\n\t * @param getTrigger - Function that extracts trigger from each option\n\t * @returns OverlayMatch with correct option type or undefined\n\t *\n\t * @example\n\t * // React usage\n\t * TriggerFinder.find(options, (opt) => opt.slotProps?.overlay?.trigger ?? '@')\n\t *\n\t * @example\n\t * // Other framework usage\n\t * TriggerFinder.find(vueOptions, (opt) => opt.overlay?.trigger ?? '@')\n\t */\n\tstatic find<T>(options: T[] | undefined, getTrigger: TriggerExtractor<T>): OverlayMatch<T> | undefined {\n\t\tif (!options) return\n\t\tif (!Caret.isSelectedPosition) return\n\t\ttry {\n\t\t\treturn new TriggerFinder().find(options, getTrigger)\n\t\t} catch {\n\t\t\treturn undefined\n\t\t}\n\t}\n\n\tgetDividedTextBy(position: number) {\n\t\treturn {left: this.span.slice(0, position), right: this.span.slice(position)}\n\t}\n\n\t/**\n\t * Find overlay match in provided options.\n\t * @template T - Type of option objects\n\t * @param options - Array of options\n\t * @param getTrigger - Function to extract trigger from each option\n\t */\n\tfind<T>(options: T[], getTrigger: TriggerExtractor<T>): OverlayMatch<T> | undefined {\n\t\tfor (let i = 0; i < options.length; i++) {\n\t\t\tconst option = options[i]\n\t\t\tconst trigger = getTrigger(option, i)\n\t\t\tif (!trigger) continue\n\n\t\t\tconst match = this.matchInTextVia(trigger)\n\t\t\tif (match)\n\t\t\t\treturn {\n\t\t\t\t\tvalue: match.word,\n\t\t\t\t\tsource: match.annotation,\n\t\t\t\t\tindex: match.index,\n\t\t\t\t\tspan: this.span,\n\t\t\t\t\tnode: this.node,\n\t\t\t\t\toption,\n\t\t\t\t}\n\t\t}\n\t}\n\n\tmatchInTextVia(trigger: string = '@') {\n\t\tconst rightMatch = this.matchRightPart()\n\t\tconst leftMatch = this.matchLeftPart(trigger)\n\t\tif (leftMatch)\n\t\t\treturn {\n\t\t\t\tword: leftMatch.word + rightMatch.word,\n\t\t\t\tannotation: leftMatch.annotation + rightMatch.word,\n\t\t\t\tindex: leftMatch.index,\n\t\t\t}\n\t}\n\n\tmatchRightPart() {\n\t\tconst {right} = this.dividedText\n\t\treturn {word: right.match(wordRegex)?.[0]}\n\t}\n\n\tmatchLeftPart(trigger: string) {\n\t\tconst regex = this.makeTriggerRegex(trigger)\n\t\tconst {left} = this.dividedText\n\t\tconst match = left.match(regex)\n\n\t\tif (!match) return\n\n\t\tconst [annotation, word] = match\n\t\treturn {word, annotation, index: match.index ?? 0}\n\t}\n\n\t//TODO new overlayMatch option if (isSpaceBeforeRequired) append space check for not first words '\\\\s'\n\tmakeTriggerRegex(trigger: string): RegExp {\n\t\tconst patten = escape(trigger) + '(\\\\w*)$'\n\t\treturn new RegExp(patten)\n\t}\n}","import {Caret} from '../../features/caret'\nimport type {Store} from '../../store'\nimport {isHtmlElement, firstHtmlChild, lastHtmlChild} from '../checkers'\n\nexport class NodeProxy {\n\t#target?: HTMLElement\n\t#store: Store\n\n\tget target(): HTMLElement | undefined {\n\t\treturn this.#target\n\t}\n\n\tset target(value: Node | HTMLElement | EventTarget | undefined | null) {\n\t\tthis.#target = isHtmlElement(value) ? value : undefined\n\t}\n\n\tget next() {\n\t\treturn new NodeProxy(this.target?.nextSibling, this.#store)\n\t}\n\n\tget prev() {\n\t\treturn new NodeProxy(this.target?.previousSibling, this.#store)\n\t}\n\n\tget isSpan() {\n\t\treturn this.index % 2 === 0\n\t}\n\n\tget isMark() {\n\t\treturn !this.isSpan\n\t}\n\n\tget isEditable() {\n\t\treturn this.target?.isContentEditable ?? false\n\t}\n\n\tget isCaretAtBeginning() {\n\t\tif (!this.target) return\n\n\t\tconst caretIndex = Caret.getCaretIndex(this.target)\n\t\treturn caretIndex === 0\n\t}\n\n\tget isCaretAtEnd() {\n\t\tif (!this.target) return\n\n\t\tconst caretIndex = Caret.getCaretIndex(this.target)\n\t\treturn caretIndex === this.target.textContent.length\n\t}\n\n\tget index() {\n\t\tif (!this.target?.parentElement) return -1\n\n\t\treturn [...this.target.parentElement.children].indexOf(this.target)\n\t}\n\n\tget caret() {\n\t\tif (this.target) return Caret.getCaretIndex(this.target)\n\t\treturn -1\n\t}\n\n\tset caret(value: number) {\n\t\tif (this.target) Caret.trySetIndex(this.target, value)\n\t}\n\n\tget length() {\n\t\treturn this.target?.textContent.length ?? -1\n\t}\n\n\tget content(): string {\n\t\treturn this.target?.textContent ?? ''\n\t}\n\n\tset content(value: string | undefined) {\n\t\tif (this.target) this.target.textContent = value ?? ''\n\t}\n\n\tget head() {\n\t\treturn firstHtmlChild(this.#store.refs.container ?? undefined)\n\t}\n\n\tget tail() {\n\t\treturn lastHtmlChild(this.#store.refs.container ?? undefined)\n\t}\n\n\tget isFocused() {\n\t\treturn this.target === document.activeElement\n\t}\n\n\tconstructor(target: Node | EventTarget | null | undefined, store: Store) {\n\t\tthis.target = target\n\t\tthis.#store = store\n\t}\n\n\tsetCaretToEnd() {\n\t\tCaret.setCaretToEnd(this.target)\n\t\treturn\n\t}\n\n\tfocus() {\n\t\tthis.target?.focus()\n\t\treturn\n\t}\n\n\tclear() {\n\t\tthis.target = undefined\n\t}\n}","export type UseHookFactory = (sig: unknown) => () => unknown\n\nlet _factory: UseHookFactory | undefined\n\nexport function setUseHookFactory(f: UseHookFactory): void {\n\t_factory = f\n}\n\nexport function getUseHookFactory(): UseHookFactory {\n\tif (!_factory) throw new Error('[markput] setUseHookFactory() must be called before using signal.use()')\n\treturn _factory\n}","export interface ReactiveNode {\n\tdeps?: Link\n\tdepsTail?: Link\n\tsubs?: Link\n\tsubsTail?: Link\n\tflags: ReactiveFlags\n}\n\nexport interface Link {\n\tversion: number\n\tdep: ReactiveNode\n\tsub: ReactiveNode\n\tprevSub: Link | undefined\n\tnextSub: Link | undefined\n\tprevDep: Link | undefined\n\tnextDep: Link | undefined\n}\n\ninterface Stack<T> {\n\tvalue: T\n\tprev: Stack<T> | undefined\n}\n\nexport const enum ReactiveFlags {\n\tNone = 0,\n\tMutable = 1,\n\tWatching = 2,\n\tRecursedCheck = 4,\n\tRecursed = 8,\n\tDirty = 16,\n\tPending = 32,\n}\n\nexport function createReactiveSystem({\n\tupdate,\n\tnotify,\n\tunwatched,\n}: {\n\tupdate(sub: ReactiveNode): boolean\n\tnotify(sub: ReactiveNode): void\n\tunwatched(sub: ReactiveNode): void\n}) {\n\treturn {\n\t\tlink,\n\t\tunlink,\n\t\tpropagate,\n\t\tcheckDirty,\n\t\tshallowPropagate,\n\t}\n\n\tfunction link(dep: ReactiveNode, sub: ReactiveNode, version: number): void {\n\t\tconst prevDep = sub.depsTail\n\t\tif (prevDep !== undefined && prevDep.dep === dep) {\n\t\t\treturn\n\t\t}\n\t\tconst nextDep = prevDep !== undefined ? prevDep.nextDep : sub.deps\n\t\tif (nextDep !== undefined && nextDep.dep === dep) {\n\t\t\tnextDep.version = version\n\t\t\tsub.depsTail = nextDep\n\t\t\treturn\n\t\t}\n\t\tconst prevSub = dep.subsTail\n\t\tif (prevSub !== undefined && prevSub.version === version && prevSub.sub === sub) {\n\t\t\treturn\n\t\t}\n\t\tconst newLink =\n\t\t\t(sub.depsTail =\n\t\t\tdep.subsTail =\n\t\t\t\t{\n\t\t\t\t\tversion,\n\t\t\t\t\tdep,\n\t\t\t\t\tsub,\n\t\t\t\t\tprevDep,\n\t\t\t\t\tnextDep,\n\t\t\t\t\tprevSub,\n\t\t\t\t\tnextSub: undefined,\n\t\t\t\t})\n\t\tif (nextDep !== undefined) {\n\t\t\tnextDep.prevDep = newLink\n\t\t}\n\t\tif (prevDep !== undefined) {\n\t\t\tprevDep.nextDep = newLink\n\t\t} else {\n\t\t\tsub.deps = newLink\n\t\t}\n\t\tif (prevSub !== undefined) {\n\t\t\tprevSub.nextSub = newLink\n\t\t} else {\n\t\t\tdep.subs = newLink\n\t\t}\n\t}\n\n\tfunction unlink(link: Link, sub = link.sub): Link | undefined {\n\t\tconst dep = link.dep\n\t\tconst prevDep = link.prevDep\n\t\tconst nextDep = link.nextDep\n\t\tconst nextSub = link.nextSub\n\t\tconst prevSub = link.prevSub\n\t\tif (nextDep !== undefined) {\n\t\t\tnextDep.prevDep = prevDep\n\t\t} else {\n\t\t\tsub.depsTail = prevDep\n\t\t}\n\t\tif (prevDep !== undefined) {\n\t\t\tprevDep.nextDep = nextDep\n\t\t} else {\n\t\t\tsub.deps = nextDep\n\t\t}\n\t\tif (nextSub !== undefined) {\n\t\t\tnextSub.prevSub = prevSub\n\t\t} else {\n\t\t\tdep.subsTail = prevSub\n\t\t}\n\t\tif (prevSub !== undefined) {\n\t\t\tprevSub.nextSub = nextSub\n\t\t} else if ((dep.subs = nextSub) === undefined) {\n\t\t\tunwatched(dep)\n\t\t}\n\t\treturn nextDep\n\t}\n\n\tfunction propagate(link: Link): void {\n\t\tlet next = link.nextSub\n\t\tlet stack: Stack<Link | undefined> | undefined\n\n\t\ttop: do {\n\t\t\tconst sub = link.sub\n\t\t\tlet flags = sub.flags\n\n\t\t\tif (\n\t\t\t\t!(\n\t\t\t\t\tflags &\n\t\t\t\t\t(ReactiveFlags.RecursedCheck | ReactiveFlags.Recursed | ReactiveFlags.Dirty | ReactiveFlags.Pending)\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tsub.flags = flags | ReactiveFlags.Pending\n\t\t\t} else if (!(flags & (ReactiveFlags.RecursedCheck | ReactiveFlags.Recursed))) {\n\t\t\t\tflags = ReactiveFlags.None\n\t\t\t} else if (!(flags & ReactiveFlags.RecursedCheck)) {\n\t\t\t\tsub.flags = (flags & ~ReactiveFlags.Recursed) | ReactiveFlags.Pending\n\t\t\t} else if (!(flags & (ReactiveFlags.Dirty | ReactiveFlags.Pending)) && isValidLink(link, sub)) {\n\t\t\t\tsub.flags = flags | (ReactiveFlags.Recursed | ReactiveFlags.Pending)\n\t\t\t\tflags &= ReactiveFlags.Mutable\n\t\t\t} else {\n\t\t\t\tflags = ReactiveFlags.None\n\t\t\t}\n\n\t\t\tif (flags & ReactiveFlags.Watching) {\n\t\t\t\tnotify(sub)\n\t\t\t}\n\n\t\t\tif (flags & ReactiveFlags.Mutable) {\n\t\t\t\tconst subSubs = sub.subs\n\t\t\t\tif (subSubs !== undefined) {\n\t\t\t\t\tconst nextSub = (link = subSubs).nextSub\n\t\t\t\t\tif (nextSub !== undefined) {\n\t\t\t\t\t\tstack = {value: next, prev: stack}\n\t\t\t\t\t\tnext = nextSub\n\t\t\t\t\t}\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ((link = next!) !== undefined) {\n\t\t\t\tnext = link.nextSub\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\twhile (stack !== undefined) {\n\t\t\t\tlink = stack.value!\n\t\t\t\tstack = stack.prev\n\t\t\t\tif (link !== undefined) {\n\t\t\t\t\tnext = link.nextSub\n\t\t\t\t\tcontinue top\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tbreak\n\t\t} while (true)\n\t}\n\n\tfunction checkDirty(link: Link, sub: ReactiveNode): boolean {\n\t\tlet stack: Stack<Link> | undefined\n\t\tlet checkDepth = 0\n\t\tlet dirty = false\n\n\t\ttop: do {\n\t\t\tconst dep = link.dep\n\t\t\tconst flags = dep.flags\n\n\t\t\tif (sub.flags & ReactiveFlags.Dirty) {\n\t\t\t\tdirty = true\n\t\t\t} else if (\n\t\t\t\t(flags & (ReactiveFlags.Mutable | ReactiveFlags.Dirty)) ===\n\t\t\t\t(ReactiveFlags.Mutable | ReactiveFlags.Dirty)\n\t\t\t) {\n\t\t\t\tif (update(dep)) {\n\t\t\t\t\tconst subs = dep.subs!\n\t\t\t\t\tif (subs.nextSub !== undefined) {\n\t\t\t\t\t\tshallowPropagate(subs)\n\t\t\t\t\t}\n\t\t\t\t\tdirty = true\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\t(flags & (ReactiveFlags.Mutable | ReactiveFlags.Pending)) ===\n\t\t\t\t(ReactiveFlags.Mutable | ReactiveFlags.Pending)\n\t\t\t) {\n\t\t\t\tif (link.nextSub !== undefined || link.prevSub !== undefined) {\n\t\t\t\t\tstack = {value: link, prev: stack}\n\t\t\t\t}\n\t\t\t\tlink = dep.deps!\n\t\t\t\tsub = dep\n\t\t\t\t++checkDepth\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (!dirty) {\n\t\t\t\tconst nextDep = link.nextDep\n\t\t\t\tif (nextDep !== undefined) {\n\t\t\t\t\tlink = nextDep\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\n\t\t\twhile (checkDepth--) {\n\t\t\t\tconst firstSub = sub.subs!\n\t\t\t\tconst hasMultipleSubs = firstSub.nextSub !== undefined\n\t\t\t\tif (hasMultipleSubs) {\n\t\t\t\t\tlink = stack!.value\n\t\t\t\t\tstack = stack!.prev\n\t\t\t\t} else {\n\t\t\t\t\tlink = firstSub\n\t\t\t\t}\n\t\t\t\tif (dirty) {\n\t\t\t\t\tif (update(sub)) {\n\t\t\t\t\t\tif (hasMultipleSubs) {\n\t\t\t\t\t\t\tshallowPropagate(firstSub)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsub = link.sub\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tdirty = false\n\t\t\t\t} else {\n\t\t\t\t\tsub.flags &= ~ReactiveFlags.Pending\n\t\t\t\t}\n\t\t\t\tsub = link.sub\n\t\t\t\tconst nextDep = link.nextDep\n\t\t\t\tif (nextDep !== undefined) {\n\t\t\t\t\tlink = nextDep\n\t\t\t\t\tcontinue top\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn dirty\n\t\t} while (true)\n\t}\n\n\tfunction shallowPropagate(link: Link): void {\n\t\tdo {\n\t\t\tconst sub = link.sub\n\t\t\tconst flags = sub.flags\n\t\t\tif ((flags & (ReactiveFlags.Pending | ReactiveFlags.Dirty)) === ReactiveFlags.Pending) {\n\t\t\t\tsub.flags = flags | ReactiveFlags.Dirty\n\t\t\t\tif ((flags & (ReactiveFlags.Watching | ReactiveFlags.RecursedCheck)) === ReactiveFlags.Watching) {\n\t\t\t\t\tnotify(sub)\n\t\t\t\t}\n\t\t\t}\n\t\t} while ((link = link.nextSub!) !== undefined)\n\t}\n\n\tfunction isValidLink(checkLink: Link, sub: ReactiveNode): boolean {\n\t\tlet link = sub.depsTail\n\t\twhile (link !== undefined) {\n\t\t\tif (link === checkLink) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tlink = link.prevDep\n\t\t}\n\t\treturn false\n\t}\n}","import {createReactiveSystem, ReactiveFlags, type ReactiveNode} from './system'\n\ninterface EffectNode extends ReactiveNode {\n\tfn(): void\n}\n\ninterface ComputedNode<T = any> extends ReactiveNode {\n\tvalue: T | undefined\n\tgetter: (previousValue?: T) => T\n}\n\ninterface SignalNode<T = any> extends ReactiveNode {\n\tcurrentValue: T\n\tpendingValue: T\n}\n\nlet cycle = 0\nlet batchDepth = 0\nlet notifyIndex = 0\nlet queuedLength = 0\nlet activeSub: ReactiveNode | undefined\n\nconst queued: (EffectNode | undefined)[] = []\nconst {link, unlink, propagate, checkDirty, shallowPropagate} = createReactiveSystem({\n\tupdate(node: SignalNode | ComputedNode): boolean {\n\t\tif (node.depsTail !== undefined) {\n\t\t\treturn updateComputed(node as ComputedNode)\n\t\t} else {\n\t\t\treturn updateSignal(node as SignalNode)\n\t\t}\n\t},\n\tnotify(effect: EffectNode) {\n\t\tlet insertIndex = queuedLength\n\t\tlet firstInsertedIndex = insertIndex\n\n\t\tdo {\n\t\t\tqueued[insertIndex++] = effect\n\t\t\teffect.flags &= ~ReactiveFlags.Watching\n\t\t\teffect = effect.subs?.sub as EffectNode\n\t\t\tif (effect === undefined || !(effect.flags & ReactiveFlags.Watching)) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t} while (true)\n\n\t\tqueuedLength = insertIndex\n\n\t\twhile (firstInsertedIndex < --insertIndex) {\n\t\t\tconst left = queued[firstInsertedIndex]\n\t\t\tqueued[firstInsertedIndex++] = queued[insertIndex]\n\t\t\tqueued[insertIndex] = left\n\t\t}\n\t},\n\tunwatched(node) {\n\t\tif (!(node.flags & ReactiveFlags.Mutable)) {\n\t\t\teffectScopeOper.call(node)\n\t\t} else if (node.depsTail !== undefined) {\n\t\t\tnode.depsTail = undefined\n\t\t\tnode.flags = ReactiveFlags.Mutable | ReactiveFlags.Dirty\n\t\t\tpurgeDeps(node)\n\t\t}\n\t},\n})\n\nexport function getActiveSub(): ReactiveNode | undefined {\n\treturn activeSub\n}\n\nexport function setActiveSub(sub?: ReactiveNode) {\n\tconst prevSub = activeSub\n\tactiveSub = sub\n\treturn prevSub\n}\n\nexport function getBatchDepth(): number {\n\treturn batchDepth\n}\n\nexport function startBatch() {\n\t++batchDepth\n}\n\nexport function endBatch() {\n\tif (!--batchDepth) {\n\t\tflush()\n\t}\n}\n\nexport function isSignal(fn: () => void): boolean {\n\treturn fn.name === 'bound ' + signalOper.name\n}\n\nexport function isComputed(fn: () => void): boolean {\n\treturn fn.name === 'bound ' + computedOper.name\n}\n\nexport function isEffect(fn: () => void): boolean {\n\treturn fn.name === 'bound ' + effectOper.name\n}\n\nexport function isEffectScope(fn: () => void): boolean {\n\treturn fn.name === 'bound ' + effectScopeOper.name\n}\n\nexport function signal<T>(): {\n\t(): T | undefined\n\t(value: T | undefined): void\n}\nexport function signal<T>(initialValue: T): {\n\t(): T\n\t(value: T): void\n}\nexport function signal<T>(initialValue?: T): {\n\t(): T | undefined\n\t(value: T | undefined): void\n} {\n\treturn signalOper.bind({\n\t\tcurrentValue: initialValue,\n\t\tpendingValue: initialValue,\n\t\tsubs: undefined,\n\t\tsubsTail: undefined,\n\t\tflags: ReactiveFlags.Mutable,\n\t}) as () => T | undefined\n}\n\nexport function computed<T>(getter: (previousValue?: T) => T): () => T {\n\treturn computedOper.bind({\n\t\tvalue: undefined,\n\t\tsubs: undefined,\n\t\tsubsTail: undefined,\n\t\tdeps: undefined,\n\t\tdepsTail: undefined,\n\t\tflags: ReactiveFlags.None,\n\t\tgetter: getter as (previousValue?: unknown) => unknown,\n\t}) as () => T\n}\n\nexport function effect(fn: () => void): () => void {\n\tconst e: EffectNode = {\n\t\tfn,\n\t\tsubs: undefined,\n\t\tsubsTail: undefined,\n\t\tdeps: undefined,\n\t\tdepsTail: undefined,\n\t\tflags: ReactiveFlags.Watching | ReactiveFlags.RecursedCheck,\n\t}\n\tconst prevSub = setActiveSub(e)\n\tif (prevSub !== undefined) {\n\t\tlink(e, prevSub, 0)\n\t}\n\ttry {\n\t\te.fn()\n\t} finally {\n\t\tactiveSub = prevSub\n\t\te.flags &= ~ReactiveFlags.RecursedCheck\n\t}\n\treturn effectOper.bind(e)\n}\n\nexport function effectScope(fn: () => void): () => void {\n\tconst e: ReactiveNode = {\n\t\tdeps: undefined,\n\t\tdepsTail: undefined,\n\t\tsubs: undefined,\n\t\tsubsTail: undefined,\n\t\tflags: ReactiveFlags.None,\n\t}\n\tconst prevSub = setActiveSub(e)\n\tif (prevSub !== undefined) {\n\t\tlink(e, prevSub, 0)\n\t}\n\ttry {\n\t\tfn()\n\t} finally {\n\t\tactiveSub = prevSub\n\t}\n\treturn effectScopeOper.bind(e)\n}\n\nexport function trigger(fn: () => void) {\n\tconst sub: ReactiveNode = {\n\t\tdeps: undefined,\n\t\tdepsTail: undefined,\n\t\tflags: ReactiveFlags.Watching,\n\t}\n\tconst prevSub = setActiveSub(sub)\n\ttry {\n\t\tfn()\n\t} finally {\n\t\tactiveSub = prevSub\n\t\tlet link = sub.deps\n\t\twhile (link !== undefined) {\n\t\t\tconst dep = link.dep\n\t\t\tlink = unlink(link, sub)\n\t\t\tconst subs = dep.subs\n\t\t\tif (subs !== undefined) {\n\t\t\t\tsub.flags = ReactiveFlags.None\n\t\t\t\tpropagate(subs)\n\t\t\t\tshallowPropagate(subs)\n\t\t\t}\n\t\t}\n\t\tif (!batchDepth) {\n\t\t\tflush()\n\t\t}\n\t}\n}\n\nfunction updateComputed(c: ComputedNode): boolean {\n\t++cycle\n\tc.depsTail = undefined\n\tc.flags = ReactiveFlags.Mutable | ReactiveFlags.RecursedCheck\n\tconst prevSub = setActiveSub(c)\n\ttry {\n\t\tconst oldValue = c.value\n\t\treturn oldValue !== (c.value = c.getter(oldValue))\n\t} finally {\n\t\tactiveSub = prevSub\n\t\tc.flags &= ~ReactiveFlags.RecursedCheck\n\t\tpurgeDeps(c)\n\t}\n}\n\nfunction updateSignal(s: SignalNode): boolean {\n\ts.flags = ReactiveFlags.Mutable\n\treturn s.currentValue !== (s.currentValue = s.pendingValue)\n}\n\nfunction run(e: EffectNode): void {\n\tconst flags = e.flags\n\tif (flags & ReactiveFlags.Dirty || (flags & ReactiveFlags.Pending && checkDirty(e.deps!, e))) {\n\t\t++cycle\n\t\te.depsTail = undefined\n\t\te.flags = ReactiveFlags.Watching | ReactiveFlags.RecursedCheck\n\t\tconst prevSub = setActiveSub(e)\n\t\ttry {\n\t\t\t;(e as EffectNode).fn()\n\t\t} finally {\n\t\t\tactiveSub = prevSub\n\t\t\te.flags &= ~ReactiveFlags.RecursedCheck\n\t\t\tpurgeDeps(e)\n\t\t}\n\t} else {\n\t\te.flags = ReactiveFlags.Watching\n\t}\n}\n\nfunction flush(): void {\n\ttry {\n\t\twhile (notifyIndex < queuedLength) {\n\t\t\tconst effect = queued[notifyIndex]!\n\t\t\tqueued[notifyIndex++] = undefined\n\t\t\trun(effect)\n\t\t}\n\t} finally {\n\t\twhile (notifyIndex < queuedLength) {\n\t\t\tconst effect = queued[notifyIndex]!\n\t\t\tqueued[notifyIndex++] = undefined\n\t\t\teffect.flags |= ReactiveFlags.Watching | ReactiveFlags.Recursed\n\t\t}\n\t\tnotifyIndex = 0\n\t\tqueuedLength = 0\n\t}\n}\n\nfunction computedOper<T>(this: ComputedNode<T>): T {\n\tconst flags = this.flags\n\tif (\n\t\tflags & ReactiveFlags.Dirty ||\n\t\t(flags & ReactiveFlags.Pending &&\n\t\t\t(checkDirty(this.deps!, this) || ((this.flags = flags & ~ReactiveFlags.Pending), false)))\n\t) {\n\t\tif (updateComputed(this)) {\n\t\t\tconst subs = this.subs\n\t\t\tif (subs !== undefined) {\n\t\t\t\tshallowPropagate(subs)\n\t\t\t}\n\t\t}\n\t} else if (!flags) {\n\t\tthis.flags = ReactiveFlags.Mutable | ReactiveFlags.RecursedCheck\n\t\tconst prevSub = setActiveSub(this)\n\t\ttry {\n\t\t\tthis.value = this.getter()\n\t\t} finally {\n\t\t\tactiveSub = prevSub\n\t\t\tthis.flags &= ~ReactiveFlags.RecursedCheck\n\t\t}\n\t}\n\tconst sub = activeSub\n\tif (sub !== undefined) {\n\t\tlink(this, sub, cycle)\n\t}\n\treturn this.value!\n}\n\nfunction signalOper<T>(this: SignalNode<T>, ...value: [T]): T | void {\n\tif (value.length) {\n\t\tif (this.pendingValue !== (this.pendingValue = value[0])) {\n\t\t\tthis.flags = ReactiveFlags.Mutable | ReactiveFlags.Dirty\n\t\t\tconst subs = this.subs\n\t\t\tif (subs !== undefined) {\n\t\t\t\tpropagate(subs)\n\t\t\t\tif (!batchDepth) {\n\t\t\t\t\tflush()\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif (this.flags & ReactiveFlags.Dirty) {\n\t\t\tif (updateSignal(this)) {\n\t\t\t\tconst subs = this.subs\n\t\t\t\tif (subs !== undefined) {\n\t\t\t\t\tshallowPropagate(subs)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlet sub = activeSub\n\t\twhile (sub !== undefined) {\n\t\t\tif (sub.flags & (ReactiveFlags.Mutable | ReactiveFlags.Watching)) {\n\t\t\t\tlink(this, sub, cycle)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tsub = sub.subs?.sub\n\t\t}\n\t\treturn this.currentValue\n\t}\n}\n\nfunction effectOper(this: EffectNode): void {\n\teffectScopeOper.call(this)\n}\n\nfunction effectScopeOper(this: ReactiveNode): void {\n\tthis.depsTail = undefined\n\tthis.flags = ReactiveFlags.None\n\tpurgeDeps(this)\n\tconst sub = this.subs\n\tif (sub !== undefined) {\n\t\tunlink(sub)\n\t}\n}\n\nfunction purgeDeps(sub: ReactiveNode) {\n\tconst depsTail = sub.depsTail\n\tlet dep = depsTail !== undefined ? depsTail.nextDep : sub.deps\n\twhile (dep !== undefined) {\n\t\tdep = unlink(dep, sub)\n\t}\n}","import {\n\tsignal as alienSignal,\n\teffect as alienEffect,\n\tcomputed as alienComputed,\n\tsetActiveSub,\n\tstartBatch,\n\tendBatch,\n} from './alien-signals'\nimport {getUseHookFactory} from './registry'\n\nexport {alienEffect as effect}\n\n// ---------------------------------------------------------------------------\n// Signal<T> — reactive state value\n// ---------------------------------------------------------------------------\n\nexport interface Signal<T> {\n\t(): T\n\t(value: T | undefined): void\n\tuse(): T\n}\n\n/**\n * Derives a plain-value object type from an object of signals.\n * `{ foo: Signal<string>, bar: Signal<number> }` → `{ foo: string, bar: number }`\n */\nexport type SignalValues<T> = {\n\t[K in keyof T]: T[K] extends Signal<infer V> | Computed<infer V> ? V : never\n}\n\ninterface SignalOptions<T> {\n\tequals?: false | ((a: T, b: T) => boolean)\n}\n\nexport function signal<T>(initial: T, opts?: SignalOptions<T>): Signal<T> {\n\tconst hasCustomEquals = opts?.equals !== undefined\n\n\t// When equals is `false` we box the value so every write creates a new reference.\n\t// When equals is a custom function we wrap the setter to compare manually.\n\t// oxlint-disable-next-line no-non-null-assertion, no-unnecessary-type-assertion -- opts is defined when hasCustomEquals is true; TS does not narrow opts from the boolean variable\n\tconst equalsOpt = hasCustomEquals ? opts!.equals : undefined\n\tif (hasCustomEquals && equalsOpt === false) {\n\t\tconst _default = initial\n\t\tconst hasDefault = initial !== undefined\n\t\tlet seq = 0\n\t\tconst inner = alienSignal<{v: T; seq: number} | undefined>(undefined)\n\n\t\tconst read = (): T => {\n\t\t\tconst box = inner()\n\t\t\tif (box === undefined) {\n\t\t\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- when hasDefault is false, T includes undefined so returning undefined is safe\n\t\t\t\treturn hasDefault ? _default : (undefined as T)\n\t\t\t}\n\t\t\treturn box.v\n\t\t}\n\n\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- callable matches Signal<T> interface but TS can't verify the overloaded call signature\n\t\tconst callable = function signalCallable(...args: [T | undefined] | []) {\n\t\t\tif (args.length) {\n\t\t\t\tif (args[0] === undefined) {\n\t\t\t\t\tif (hasDefault && inner() === undefined) return\n\t\t\t\t\tinner(undefined)\n\t\t\t\t} else {\n\t\t\t\t\tinner({v: args[0], seq: seq++})\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn read()\n\t\t\t}\n\t\t} as unknown as Signal<T>\n\n\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- UseHookFactory returns () => unknown; framework packages augment use() return type via module augmentation\n\t\tcallable.use = (() => getUseHookFactory()(callable)()) as Signal<T>['use']\n\t\treturn callable\n\t}\n\n\tif (hasCustomEquals && typeof equalsOpt === 'function') {\n\t\tconst equalsFn = equalsOpt\n\t\tconst _default = initial\n\t\tconst hasDefault = initial !== undefined\n\t\tconst inner = alienSignal<T | undefined>(undefined)\n\n\t\tconst read = (): T => {\n\t\t\tconst v = inner()\n\t\t\tif (v === undefined && hasDefault) return _default\n\t\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- when hasDefault is false, T includes undefined so the cast is safe\n\t\t\treturn v as T\n\t\t}\n\n\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- callable matches Signal<T> interface but TS can't verify the overloaded call signature\n\t\tconst callable = function signalCallable(...args: [T | undefined] | []) {\n\t\t\tif (args.length) {\n\t\t\t\tif (args[0] === undefined) {\n\t\t\t\t\tif (hasDefault && inner() === undefined) return\n\t\t\t\t\tinner(undefined)\n\t\t\t\t} else {\n\t\t\t\t\tif (!equalsFn(read(), args[0])) {\n\t\t\t\t\t\tinner(args[0])\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn read()\n\t\t\t}\n\t\t} as unknown as Signal<T>\n\n\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- UseHookFactory returns () => unknown; framework packages augment use() return type via module augmentation\n\t\tcallable.use = (() => getUseHookFactory()(callable)()) as Signal<T>['use']\n\t\treturn callable\n\t}\n\n\tconst _default = initial\n\tconst hasDefault = initial !== undefined\n\tconst inner = alienSignal<T | undefined>(undefined)\n\n\tconst read = (): T => {\n\t\tconst v = inner()\n\t\tif (v === undefined && hasDefault) return _default\n\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- when hasDefault is false, T includes undefined so the cast is safe\n\t\treturn v as T\n\t}\n\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- callable matches Signal<T> interface but TS can't verify the overloaded call signature\n\tconst callable = function signalCallable(...args: [T | undefined] | []) {\n\t\tif (args.length) {\n\t\t\tconst v = args[0]\n\t\t\tif (v === undefined && hasDefault) {\n\t\t\t\tif (inner() === undefined) return\n\t\t\t\tinner(undefined)\n\t\t\t} else {\n\t\t\t\tconst current = inner()\n\t\t\t\tconst effectiveCurrent = current === undefined && hasDefault ? _default : current\n\t\t\t\tif (effectiveCurrent !== v) {\n\t\t\t\t\tinner(v)\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\treturn read()\n\t\t}\n\t} as unknown as Signal<T>\n\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- UseHookFactory returns () => unknown; framework packages augment use() return type via module augmentation\n\tcallable.use = (() => getUseHookFactory()(callable)()) as Signal<T>['use']\n\treturn callable\n}\n\n// ---------------------------------------------------------------------------\n// Computed<T> — derived reactive value\n// ---------------------------------------------------------------------------\n\nexport interface Computed<T> {\n\t(): T\n\tuse(): T\n}\n\nexport function computed<T>(getter: (previousValue?: T) => T): Computed<T> {\n\tconst inner = alienComputed(getter)\n\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- callable matches Computed<T> interface but TS can't verify the call signature\n\tconst callable = function computedCallable(): T {\n\t\treturn inner()\n\t} as unknown as Computed<T>\n\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- UseHookFactory returns () => unknown; framework packages augment use() return type via module augmentation\n\tcallable.use = (() => getUseHookFactory()(callable)()) as Computed<T>['use']\n\n\treturn callable\n}\n\n// ---------------------------------------------------------------------------\n// Event<T> — unified reactive event primitive\n// ---------------------------------------------------------------------------\n\nexport interface Event<T = void> {\n\t/** Emit — always fires even when payload reference is unchanged. */\n\t(payload: T): void\n\t/** Read/subscribe — auto-tracks inside effects. Returns latest payload or undefined. */\n\tread(): T | undefined\n\t/** Framework hook bridge. */\n\tuse(): T | undefined\n}\n\nexport function event<T = void>(): Event<T> {\n\tlet seq = 0\n\tconst inner = alienSignal<{v: T; id: number} | undefined>(undefined)\n\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- callable matches Event<T> interface but TS can't verify the call signature\n\tconst callable = function eventCallable(payload: T) {\n\t\tinner({v: payload, id: ++seq})\n\t} as unknown as Event<T>\n\n\tcallable.read = () => {\n\t\tconst box = inner()\n\t\treturn box !== undefined ? box.v : undefined\n\t}\n\t// oxlint-disable-next-line no-unsafe-type-assertion, typescript-eslint/unbound-method -- callable.read is an arrow function (no this); getUseHookFactory returns () => unknown; cast to T | undefined is safe by Event<T> contract\n\tcallable.use = () => getUseHookFactory()(callable.read)() as T | undefined\n\n\treturn callable\n}\n\n// ---------------------------------------------------------------------------\n// watch() — skip-first-run helper for event subscriptions\n// ---------------------------------------------------------------------------\n\n/**\n * Creates an effect that skips its first execution.\n * Useful for subscribing to signals/events without firing on initial creation.\n * The callback receives `(newValue, oldValue)` on each subsequent run.\n *\n * Accepts a signal, event, or getter function as the dependency source:\n * watch(store.event.delete, (payload) => { ... })\n * watch(store.state.name, (next, prev) => { ... })\n * watch(() => computed(), (next, prev) => { ... }) // getter form still valid\n *\n * @param dep - dependency source (signal, event, or getter function)\n * @param fn - callback invoked on subsequent runs with (newValue, oldValue)\n * @returns dispose function\n */\nexport function watch<T>(dep: Signal<T>, fn: (newValue: T, oldValue: T | undefined) => void): () => void\nexport function watch<T>(dep: Event<T>, fn: (newValue: T, oldValue: T | undefined) => void): () => void\nexport function watch<T>(dep: () => T, fn: (newValue: T, oldValue: T | undefined) => void): () => void\nexport function watch<T>(\n\tdep: Signal<T> | Event<T> | (() => T),\n\tfn: (newValue: T, oldValue: T | undefined) => void\n): () => void {\n\tlet initialized = false\n\tlet oldValue: T | undefined\n\treturn alienEffect(() => {\n\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- Event<T> returns T | undefined before first emit, but watch skips the first run so callback always receives T\n\t\tconst newValue = ('read' in dep ? dep.read() : dep()) as T\n\t\tif (!initialized) {\n\t\t\tinitialized = true\n\t\t\toldValue = newValue\n\t\t\treturn\n\t\t}\n\t\tconst prev = oldValue\n\t\toldValue = newValue\n\t\tconst prevSub = setActiveSub(undefined)\n\t\ttry {\n\t\t\tfn(newValue, prev)\n\t\t} finally {\n\t\t\tsetActiveSub(prevSub)\n\t\t}\n\t})\n}\n\n// ---------------------------------------------------------------------------\n// batch() — defer effect flush until callback completes\n// ---------------------------------------------------------------------------\n\nexport function batch(fn: () => void): void {\n\tstartBatch()\n\ttry {\n\t\tfn()\n\t} finally {\n\t\tendBatch()\n\t}\n}","/**\n * Constants for ParserV2 - modern markup parser with nesting support\n *\n * This module contains the placeholder constants used by ParserV2.\n * Unlike the legacy Parser, ParserV2 supports:\n * - `__value__` - main content (replaces `__label__`)\n * - `__meta__` - metadata (replaces `__value__`)\n * - `__slot__` - nested content (new feature)\n *\n * For legacy Parser compatibility, see ../Parser/constants.ts\n * For Markup types, see ./types.ts\n */\nexport const PLACEHOLDER = {\n\tValue: '__value__',\n\tMeta: '__meta__',\n\tSlot: '__slot__',\n} as const\n\n/**\n * Gap types used in markup descriptors\n * Represents the content type in gaps between segments\n */\nexport const GAP_TYPE = {\n\tValue: 'value',\n\tMeta: 'meta',\n\tSlot: 'slot',\n} as const\n\nexport type GapType = (typeof GAP_TYPE)[keyof typeof GAP_TYPE]","import type {GapType} from '../constants'\nimport {GAP_TYPE, PLACEHOLDER} from '../constants'\nimport type {Markup} from '../types'\nimport type {SegmentDefinition} from './SegmentMatcher'\n\n/**\n * Descriptor for segment-based markup parsing\n * Converts markup templates into arrays of static or dynamic segments\n */\nexport interface MarkupDescriptor {\n\t/** Original markup template string */\n\tmarkup: Markup\n\t/** Index of this markup in the original markups array */\n\tindex: number\n\t/** Array of segment definitions (can be static strings or dynamic patterns) */\n\tsegments: SegmentDefinition[]\n\t/** Type of content in each gap between segments */\n\tgapTypes: GapType[]\n\t/** True if this markup contains a __slot__ placeholder */\n\thasSlot: boolean\n\t/** True if this markup contains exactly two __value__ placeholders */\n\thasTwoValues: boolean\n\t/** Global indices of segments in registry segments array (parallel to segments array) */\n\tsegmentGlobalIndices: number[]\n}\n\n/**\n * Creates a segment-based markup descriptor from a markup template\n *\n * Examples:\n * - `#[__value__]` -> segments: [\"#[\", \"]\"], gapTypes: [\"value\"]\n * - `#[__slot__]` -> segments: [\"#[\", \"]\"], gapTypes: [\"slot\"]\n * - `@[__value__](__meta__)` -> segments: [\"@[\", \"](\", \")\"], gapTypes: [\"value\", \"meta\"]\n * - `@[__slot__](__meta__)` -> segments: [\"@[\", \"](\", \")\"], gapTypes: [\"slot\", \"meta\"]\n * - `@[__value__](__slot__)` -> segments: [\"@[\", \"](\", \")\"], gapTypes: [\"value\", \"slot\"]\n * - `<__value__>__meta__</__value__>` -> segments: [{pattern: '<([^>]+)>'}, {pattern: '</([^>]+)>'}], gapTypes: [\"value\", \"meta\", \"value\"] (dynamic)\n * - `<__value__ __meta__>__slot__</__value__>` -> segments: [{pattern: '<([^> ]+) '}, \" \", {pattern: '>__slot__</([^>]+)>'}], gapTypes: [\"value\", \"meta\", \"slot\", \"value\"] (dynamic)\n */\nexport function createMarkupDescriptor(markup: Markup, index: number): MarkupDescriptor {\n\tconst {segments: rawSegments, gapTypes: rawGapTypes, counts, valueGapIndices} = scanMarkupStructure(markup)\n\n\tvalidateMarkup(counts, markup)\n\n\tconst hasTwoValues = counts.value === 2\n\n\tconst {segments, gapTypes} = hasTwoValues\n\t\t? convertTwoValuePattern(rawSegments, rawGapTypes, valueGapIndices)\n\t\t: {segments: rawSegments, gapTypes: rawGapTypes}\n\n\treturn {\n\t\tmarkup,\n\t\tindex,\n\t\tsegments,\n\t\tgapTypes,\n\t\thasSlot: counts.slot === 1,\n\t\thasTwoValues,\n\t\tsegmentGlobalIndices: Array.from({length: segments.length}), // Will be populated by MarkupRegistry\n\t}\n}\n\n/**\n * Maps placeholder types to their text representations\n */\nconst PLACEHOLDER_TEXT: Record<GapType, string> = {\n\t[GAP_TYPE.Value]: PLACEHOLDER.Value,\n\t[GAP_TYPE.Meta]: PLACEHOLDER.Meta,\n\t[GAP_TYPE.Slot]: PLACEHOLDER.Slot,\n} as const\n\n/**\n * Parses markup template into segments, gap types and placeholder counts\n */\nfunction scanMarkupStructure(markup: string) {\n\tconst segments: string[] = []\n\tconst gapTypes: GapType[] = []\n\tconst valueGapIndices: number[] = []\n\tconst counts: Record<GapType, number> = {\n\t\tvalue: 0,\n\t\tmeta: 0,\n\t\tslot: 0,\n\t}\n\n\t// Find all placeholders and sort by position\n\tconst placeholders: Array<{type: GapType; position: number}> = []\n\tconst placeholderTypes = [GAP_TYPE.Value, GAP_TYPE.Meta, GAP_TYPE.Slot] as const\n\n\tfor (const type of placeholderTypes) {\n\t\tconst text = PLACEHOLDER_TEXT[type]\n\t\tlet position = markup.indexOf(text)\n\t\twhile (position !== -1) {\n\t\t\tplaceholders.push({type, position})\n\t\t\tposition = markup.indexOf(text, position + text.length)\n\t\t}\n\t}\n\n\tplaceholders.sort((a, b) => a.position - b.position)\n\n\t// Process placeholders in order\n\tlet currentParsePosition = 0\n\tfor (const placeholder of placeholders) {\n\t\tconst segment = markup.substring(currentParsePosition, placeholder.position)\n\t\tif (segment.length > 0) {\n\t\t\tsegments.push(segment)\n\t\t}\n\n\t\tgapTypes.push(placeholder.type)\n\t\tcounts[placeholder.type]++\n\n\t\tif (placeholder.type === GAP_TYPE.Value) {\n\t\t\tvalueGapIndices.push(gapTypes.length - 1)\n\t\t}\n\n\t\tcurrentParsePosition = placeholder.position + PLACEHOLDER_TEXT[placeholder.type].length\n\t}\n\n\tconst finalSegment = markup.substring(currentParsePosition)\n\tif (finalSegment.length > 0) {\n\t\tsegments.push(finalSegment)\n\t}\n\n\treturn {\n\t\tsegments,\n\t\tgapTypes,\n\t\tcounts,\n\t\tvalueGapIndices,\n\t}\n}\n\n/**\n * Validates markup placeholder counts\n */\nfunction validateMarkup(counts: Record<GapType, number>, markup: string): void {\n\tconst rules = [\n\t\t{count: counts.value, max: 2, name: PLACEHOLDER.Value},\n\t\t{count: counts.meta, max: 1, name: PLACEHOLDER.Meta},\n\t\t{count: counts.slot, max: 1, name: PLACEHOLDER.Slot},\n\t]\n\n\tfor (const {count, max, name} of rules) {\n\t\tif (count > max) {\n\t\t\tthrow new Error(`Invalid markup: \"${markup}\". Max ${max} \"${name}\" placeholders, got ${count}`)\n\t\t}\n\t}\n\n\tif (counts.value === 0 && counts.slot === 0) {\n\t\tthrow new Error(\n\t\t\t`Invalid markup: \"${markup}\". Need at least one \"${PLACEHOLDER.Value}\" or \"${PLACEHOLDER.Slot}\"`\n\t\t)\n\t}\n}\n\n/**\n * Converts static segments around __value__ placeholders to dynamic patterns\n * For pattern like <__value__>__meta__</__value__>:\n * - Original: segments [\"<\", \">\", \"</\", \">\"], gapTypes [\"value\", \"meta\", \"value\"]\n * - Result: segments [['<', '>', exclusions], ['</', '>', exclusions]], gapTypes [\"meta\"]\n * Dynamic segments \"absorb\" the __value__ gaps they surround\n */\nfunction convertTwoValuePattern(\n\tsegments: string[],\n\tgapTypes: GapType[],\n\tvalueGapIndices: number[]\n): {segments: SegmentDefinition[]; gapTypes: GapType[]} {\n\tif (valueGapIndices.length !== 2) {\n\t\treturn {segments, gapTypes}\n\t}\n\n\tconst [firstValueGapIdx, secondValueGapIdx] = valueGapIndices\n\n\tconst newSegments: SegmentDefinition[] = []\n\n\tconst beforeFirst = segments[firstValueGapIdx]\n\tconst afterFirst = segments[firstValueGapIdx + 1]\n\tif (beforeFirst && afterFirst) {\n\t\tnewSegments.push(createDynamicDefinition(beforeFirst, afterFirst, segments[firstValueGapIdx + 2]))\n\t}\n\n\tfor (let i = firstValueGapIdx + 2; i < secondValueGapIdx; i++) {\n\t\tnewSegments.push(segments[i])\n\t}\n\n\tconst beforeSecond = segments[secondValueGapIdx]\n\tconst afterSecond = segments[secondValueGapIdx + 1]\n\tif (beforeSecond && afterSecond) {\n\t\tnewSegments.push(createDynamicDefinition(beforeSecond, afterSecond, segments[secondValueGapIdx + 2]))\n\t}\n\n\tconst filteredGapTypes = gapTypes.filter(type => type !== GAP_TYPE.Value)\n\n\treturn {segments: newSegments, gapTypes: filteredGapTypes}\n}\n\nfunction createDynamicDefinition(\n\tbeforeSegment: string,\n\tafterSegment: string,\n\tnextSegment?: string\n): [string, string, string] {\n\tif (!nextSegment) return [beforeSegment, afterSegment, '']\n\n\tconst firstChar = nextSegment.charAt(0)\n\tconst exclusion =\n\t\tfirstChar && !afterSegment.includes(firstChar) && !nextSegment.startsWith(beforeSegment) ? firstChar : ''\n\n\treturn [beforeSegment, afterSegment, exclusion]\n}","import type {Markup} from '../types'\nimport type {MarkupDescriptor} from './MarkupDescriptor'\nimport {createMarkupDescriptor} from './MarkupDescriptor'\nimport type {SegmentDefinition} from './SegmentMatcher'\n\nfunction getOrCreate<K, V>(map: Map<K, V[]>, key: K): V[] {\n\tlet arr = map.get(key)\n\tif (!arr) {\n\t\tarr = []\n\t\tmap.set(key, arr)\n\t}\n\treturn arr\n}\n\n/**\n * Registry for managing markup descriptors\n * Centralizes access to all markup patterns and their descriptors\n */\nexport class MarkupRegistry {\n\treadonly markups: (Markup | undefined)[]\n\treadonly descriptors: MarkupDescriptor[]\n\t/** Deduplicated list of unique segment definitions (static strings or dynamic patterns) */\n\treadonly segments: SegmentDefinition[] = []\n\t/** Map from first segment index to descriptors that start with this segment (for O(1) lookup) */\n\treadonly firstSegmentIndexMap: Map<number, MarkupDescriptor[]> = new Map()\n\n\tconstructor(markups: (Markup | undefined)[]) {\n\t\tthis.markups = markups\n\n\t\tconst segmentIndexMap = new Map<string, number>()\n\n\t\tthis.descriptors = markups\n\t\t\t.map((markup, index) => {\n\t\t\t\t// Skip undefined markups but preserve original indices\n\t\t\t\tif (markup === undefined) {\n\t\t\t\t\treturn null\n\t\t\t\t}\n\n\t\t\t\tconst descriptor = createMarkupDescriptor(markup, index)\n\n\t\t\t\t// Process segments and register them\n\t\t\t\tdescriptor.segments.forEach((segment, segmentIndex) => {\n\t\t\t\t\tthis.processSegment(descriptor, segment, segmentIndex, segmentIndexMap)\n\t\t\t\t})\n\n\t\t\t\tthis.addToFirstSegmentIndexMap(descriptor)\n\n\t\t\t\treturn descriptor\n\t\t\t})\n\t\t\t.filter((descriptor): descriptor is MarkupDescriptor => descriptor !== null)\n\t}\n\n\t/**\n\t * Adds a descriptor to the firstSegmentIndexMap using its first segment's global index\n\t */\n\tprivate addToFirstSegmentIndexMap(descriptor: MarkupDescriptor): void {\n\t\tconst firstSegmentIndex = descriptor.segmentGlobalIndices[0]\n\n\t\tgetOrCreate(this.firstSegmentIndexMap, firstSegmentIndex).push(descriptor)\n\t}\n\n\tprivate processSegment(\n\t\tdescriptor: MarkupDescriptor,\n\t\tsegment: SegmentDefinition,\n\t\tsegmentIndex: number,\n\t\tsegmentIndexMap: Map<string, number>\n\t): void {\n\t\tconst segmentKey = this.getSegmentKey(segment)\n\t\tif (!segmentKey) return\n\n\t\tconst globalIndex = this.registerSegment(segment, segmentKey, segmentIndexMap)\n\n\t\tdescriptor.segmentGlobalIndices[segmentIndex] = globalIndex\n\n\t\t// Register static parts of dynamic segments\n\t\tif (typeof segment !== 'string') {\n\t\t\tconst [before, after] = segment\n\t\t\tif (before) {\n\t\t\t\tthis.registerSegment(before, before, segmentIndexMap)\n\t\t\t}\n\t\t\tif (after) {\n\t\t\t\tthis.registerSegment(after, after, segmentIndexMap)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate registerSegment(\n\t\tsegment: SegmentDefinition,\n\t\tsegmentKey: string,\n\t\tsegmentIndexMap: Map<string, number>\n\t): number {\n\t\tconst existing = segmentIndexMap.get(segmentKey)\n\t\tif (existing !== undefined) return existing\n\t\tconst globalIndex = this.segments.length\n\t\tthis.segments.push(segment)\n\t\tsegmentIndexMap.set(segmentKey, globalIndex)\n\t\treturn globalIndex\n\t}\n\n\t/**\n\t * Gets a unique key for a segment definition\n\t * For static segments (strings), returns the string itself if non-empty\n\t * For dynamic segments (arrays), returns before|after|exclusions if before or after is non-empty\n\t * Returns empty string for segments that should be ignored\n\t */\n\tprivate getSegmentKey(segment: SegmentDefinition): string {\n\t\tif (typeof segment === 'string') {\n\t\t\treturn segment\n\t\t}\n\t\t// For dynamic segments, create a key from before+after+exclusions\n\t\tconst [before, after, exclusions] = segment\n\t\t// Only return a key if there's something to match (before or after is non-empty)\n\t\tif (before || after) {\n\t\t\treturn `${before}|${after}|${exclusions}`\n\t\t}\n\t\treturn ''\n\t}\n}","/**\n * Creates a value-specific index using djb2 hash algorithm for dynamic segments\n * For static segments, returns the base index directly to avoid unnecessary hashing\n *\n * @param baseIndex - The base index of the segment type\n * @param value - The actual value of the segment (optional, for dynamic segments only)\n * @returns Value-specific index for dynamic segments, or base index for static segments\n */\nexport function getSegmentIndex(baseIndex: number, value?: string): number {\n\tif (!value) {\n\t\treturn baseIndex\n\t}\n\n\tlet hash = 5381\n\tfor (let i = 0; i < value.length; i++) {\n\t\thash = (hash * 33) ^ value.charCodeAt(i)\n\t}\n\thash = hash >>> 0 // Unsigned 32-bit integer\n\n\treturn baseIndex * 1000000 + (hash & 0xfffff)\n}","import type {GapType} from '../constants'\nimport type {PositionRange} from '../types'\nimport {getSegmentIndex} from '../utils/getSegmentIndex'\nimport type {MarkupDescriptor} from './MarkupDescriptor'\nimport type {SegmentMatch} from './SegmentMatcher'\n\n/**\n * Unified match structure for pattern matching states\n *\n * Represents the state of a pattern matching process in the parser's state machine:\n * - Active: tracks progress through pattern segments (expectedSegmentIndex >= 0)\n * - Completed: all segments found, match is valid (expectedSegmentIndex = NaN)\n * - Invalid: match cannot be completed due to malformed segments (expectedSegmentIndex = -1)\n *\n * State detection:\n * - isCompleted: expectedSegmentIndex is NaN\n * - isInvalid: expectedSegmentIndex is -1\n * - isActive: expectedSegmentIndex >= 0 (not NaN and not -1)\n */\n\nexport class Match {\n\tpublic readonly gaps: Partial<Record<GapType, PositionRange>> = {}\n\t/** Captured value from first dynamic segment (for hasTwoValues patterns) */\n\tprivate captured?: string\n\n\t/**\n\t * Index of expected next segment:\n\t * - >= 0: active, waiting for segment at this index\n\t * - NaN: completed successfully\n\t * - -1: invalid, should be discarded\n\t */\n\tpublic expectedSegmentIndex: number\n\tpublic start: number\n\tpublic end: number\n\n\tconstructor(\n\t\tpublic readonly descriptor: MarkupDescriptor,\n\t\tfirstSegment: SegmentMatch\n\t) {\n\t\tthis.expectedSegmentIndex = 1\n\t\tthis.start = firstSegment.start\n\t\tthis.end = firstSegment.end\n\n\t\t// Auto-complete single segment patterns\n\t\tif (descriptor.segments.length === 1) {\n\t\t\tthis.expectedSegmentIndex = NaN\n\n\t\t\t//TODO need review it. before it was only value gap type\n\t\t\tconst gapType = descriptor.gapTypes[0] ?? 'value'\n\t\t\tif (gapType === 'slot') {\n\t\t\t\t// Slot-leading: real range resolved by PatternMatcher.resolveSlotLeadingMatches\n\t\t\t\tthis.gaps.slot = {start: this.start, end: this.start}\n\t\t\t} else {\n\t\t\t\tthis.gaps[gapType] = {start: this.start, end: this.end}\n\t\t\t}\n\t\t}\n\n\t\tif (descriptor.hasTwoValues && firstSegment.captured) {\n\t\t\tthis.captured = firstSegment.captured\n\t\t\tconst capturedStart = firstSegment.start + firstSegment.value.indexOf(firstSegment.captured)\n\t\t\tconst capturedEnd = capturedStart + firstSegment.captured.length\n\t\t\tthis.gaps.value = {start: capturedStart, end: capturedEnd}\n\t\t}\n\t}\n\n\t/**\n\t * Check if the match is invalid and should be discarded\n\t */\n\tget isInvalid(): boolean {\n\t\treturn this.expectedSegmentIndex === -1\n\t}\n\n\t/**\n\t * Check if the pattern is completed (computed property)\n\t */\n\tget isCompleted(): boolean {\n\t\treturn isNaN(this.expectedSegmentIndex)\n\t}\n\n\t/**\n\t * Check if the match is waiting for the last segment (high priority)\n\t */\n\tget isAwaitingLastSegment(): boolean {\n\t\treturn this.expectedSegmentIndex === this.descriptor.segments.length - 1\n\t}\n\n\t/**\n\t * Get the next expected segment index\n\t */\n\tget nextSegment(): number | undefined {\n\t\tif (this.isCompleted || this.isInvalid) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst baseIndex = this.descriptor.segmentGlobalIndices[this.expectedSegmentIndex]\n\t\tconst segmentDef = this.descriptor.segments[this.expectedSegmentIndex]\n\n\t\t// Only hash for hasTwoValues closing tags that need value-specific matching\n\t\tif (\n\t\t\ttypeof segmentDef === 'object' &&\n\t\t\tthis.descriptor.hasTwoValues &&\n\t\t\tthis.captured &&\n\t\t\tthis.isAwaitingLastSegment\n\t\t) {\n\t\t\tconst [before, after] = segmentDef\n\t\t\tconst value = before + this.captured + after\n\t\t\treturn getSegmentIndex(baseIndex, value)\n\t\t}\n\n\t\treturn baseIndex\n\t}\n\n\t/**\n\t * Update state with new segment by setting gap positions\n\t */\n\tprocessNext(segment: SegmentMatch): void {\n\t\tconst start = this.end\n\t\tconst end = segment.start\n\t\tconst gapType = this.descriptor.gapTypes[this.expectedSegmentIndex - 1]\n\n\t\t// VALIDATION: Next segment must start after previous segment ends\n\t\t// If not, this match is permanently invalid\n\t\tif (end < start) {\n\t\t\tthis.expectedSegmentIndex = -1\n\t\t\treturn\n\t\t}\n\n\t\tthis.gaps[gapType] = {start, end}\n\n\t\tthis.end = segment.end\n\t\tthis.expectedSegmentIndex++\n\n\t\t// Auto-complete if all segments are processed\n\t\tif (this.expectedSegmentIndex >= this.descriptor.segments.length) {\n\t\t\tthis.expectedSegmentIndex = NaN\n\t\t}\n\t}\n\n\t/**\n\t * Checks if this match conflicts with another match (overlaps and cannot nest properly)\n\t */\n\tconflictsWith(previousMatch?: Match | null): boolean {\n\t\t// No conflict if there's no previous match to conflict with\n\t\tif (!previousMatch) return false\n\n\t\t// No conflict if there's no overlap\n\t\tif (this.start >= previousMatch.end) return false\n\n\t\t// If there's overlap, check if it's valid nesting\n\t\tif (!previousMatch.descriptor.hasSlot) return true\n\t\tif (previousMatch.gaps.slot === undefined) return true\n\n\t\t// Valid nesting: this match is completely inside the slot section\n\t\treturn !(this.start >= previousMatch.gaps.slot.start && this.end <= previousMatch.gaps.slot.end)\n\t}\n}","/**\n * PatternMatcher - State Machine for Markup Pattern Recognition\n *\n * Implements a high-performance state machine that processes segments to identify\n * and match markup patterns. Manages Match objects representing parsing states\n * for different markup descriptors, handling gap positions and completion logic.\n *\n * Key features:\n * - State machine approach for pattern matching\n * - Position-based indexing for efficient lookups\n * - Processing order-based conflict resolution for overlapping matches\n * - Gap position management for nested content extraction\n */\n\nimport {getSegmentIndex} from '../utils/getSegmentIndex'\nimport type {MarkupDescriptor} from './MarkupDescriptor'\nimport type {MarkupRegistry} from './MarkupRegistry'\nimport {Match} from './Match'\nimport type {SegmentMatch} from './SegmentMatcher'\n\nfunction getOrCreate<K, V>(map: Map<K, V[]>, key: K): V[] {\n\tlet arr = map.get(key)\n\tif (!arr) {\n\t\tarr = []\n\t\tmap.set(key, arr)\n\t}\n\treturn arr\n}\n\n/**\n * Optimized parser using state machine approach\n */\nexport class PatternMatcher {\n\tprivate readonly pendingStates: Map<number, Match[]> = new Map()\n\tprivate readonly completingStates: Map<number, Match[]> = new Map()\n\tprivate readonly completedStates: Array<{position: number; match: Match}> = []\n\n\tconstructor(private readonly registry: MarkupRegistry) {}\n\n\t/** Main method that converts found segments into structured matches */\n\tprocess(segments: SegmentMatch[]): Match[] {\n\t\tthis.pendingStates.clear()\n\t\tthis.completingStates.clear()\n\t\tthis.completedStates.length = 0\n\n\t\tfor (const segment of segments) {\n\t\t\tthis.processWaitingStates(segment)\n\t\t\tthis.tryStartNewStates(segment)\n\t\t}\n\n\t\t//TODO need review it\n\t\tthis.resolveSlotLeadingMatches()\n\n\t\treturn this.completedStates.map(entry => entry.match)\n\t}\n\n\t/**\n\t * Process states waiting for this segment\n\t * Try states by priority until one is valid, keeping rejected states for later attempts\n\t * Process completing states first (higher priority), then pending states\n\t * Process only one state per call\n\t */\n\tprivate processWaitingStates(segment: SegmentMatch): void {\n\t\tconst match = this.dequeueWaitingMatch(segment)\n\t\tif (!match) return\n\n\t\tmatch.processNext(segment)\n\n\t\tif (match.isInvalid) return\n\n\t\tif (match.isCompleted) return this.addToCompleted(match)\n\n\t\tthis.addToWaiting(match)\n\t}\n\n\tprivate tryStartNewStates(segment: SegmentMatch): void {\n\t\tthis.registry.firstSegmentIndexMap.get(segment.index)?.forEach((descriptor: MarkupDescriptor) => {\n\t\t\tconst match = new Match(descriptor, segment)\n\n\t\t\tif (match.isInvalid) return\n\n\t\t\tif (match.isCompleted) return this.addToCompleted(match)\n\n\t\t\tthis.addToWaiting(match)\n\t\t})\n\t}\n\n\t/**\n\t * Gets the next waiting match for the given segment\n\t * Uses value-specific index for dynamic segments, base index for static segments\n\t */\n\tprivate dequeueWaitingMatch(segment: SegmentMatch): Match | undefined {\n\t\tconst index = segment.captured ? getSegmentIndex(segment.index, segment.value) : segment.index\n\n\t\tconst completingArray = this.completingStates.get(index)\n\t\tif (completingArray?.length) return completingArray.pop()\n\n\t\tconst pendingArray = this.pendingStates.get(index)\n\t\tif (pendingArray?.length) return pendingArray.pop()\n\t}\n\n\t/**\n\t * Adds a state to the waiting list for the next expected segment\n\t */\n\tprivate addToWaiting(match: Match): void {\n\t\tconst segmentIndex = match.nextSegment\n\t\tif (segmentIndex === undefined) return\n\t\tconst map = match.isAwaitingLastSegment ? this.completingStates : this.pendingStates\n\t\tgetOrCreate(map, segmentIndex).push(match)\n\t}\n\n\t/**\n\t * Resolves slot-leading single-segment matches by extending their start backwards.\n\t *\n\t * For patterns like `__slot__\\n\\n`, the segment `\\n\\n` is a suffix delimiter and\n\t * the slot content precedes it. After normal processing, such matches only cover\n\t * the delimiter. This pass extends each slot-leading match backwards to the end\n\t * of the previous slot-leading match (or input start), so that non-slot-leading\n\t * matches between them become nested children rather than siblings.\n\t */\n\tprivate resolveSlotLeadingMatches(): void {\n\t\tlet hasSlotLeading = false\n\t\tfor (const entry of this.completedStates) {\n\t\t\tif (this.isSlotLeading(entry.match)) {\n\t\t\t\thasSlotLeading = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif (!hasSlotLeading) return\n\n\t\t// Only slot-leading match boundaries matter — other matches become nested children\n\t\tlet boundary = 0\n\t\tfor (const entry of this.completedStates) {\n\t\t\tconst {match} = entry\n\t\t\tif (this.isSlotLeading(match)) {\n\t\t\t\tconst segmentStart = match.start\n\t\t\t\tmatch.start = boundary\n\t\t\t\tentry.position = boundary\n\t\t\t\tmatch.gaps.slot = {start: boundary, end: segmentStart}\n\t\t\t\tboundary = match.end\n\t\t\t}\n\t\t}\n\n\t\tthis.completedStates.sort((a, b) => a.position - b.position)\n\t}\n\n\tprivate isSlotLeading(match: Match): boolean {\n\t\treturn match.descriptor.segments.length === 1 && match.descriptor.hasSlot\n\t}\n\n\t/**\n\t * Add match to position-indexed array, replacing any existing match at the same position\n\t * Uses binary search to find insertion point and maintains sorted order\n\t * Relies on processing order to determine which match to keep\n\t */\n\tprivate addToCompleted(match: Match): void {\n\t\tconst position = match.start\n\n\t\t// Binary search to find the insertion point or existing position\n\t\tlet left = 0\n\t\tlet right = this.completedStates.length\n\n\t\twhile (left < right) {\n\t\t\tconst mid = Math.floor((left + right) / 2)\n\t\t\tif (this.completedStates[mid].position < position) {\n\t\t\t\tleft = mid + 1\n\t\t\t} else {\n\t\t\t\tright = mid\n\t\t\t}\n\t\t}\n\n\t\t// Check if we found an existing entry at this position\n\t\tif (left < this.completedStates.length && this.completedStates[left].position === position) {\n\t\t\t// Position exists - replace with the new match\n\t\t\tthis.completedStates[left].match = match\n\t\t} else {\n\t\t\t// New position - insert new entry at the correct position\n\t\t\tthis.completedStates.splice(left, 0, {position, match})\n\t\t}\n\t}\n}","import {escape} from '../../../../shared/escape'\n\n/**\n * Result of a segment match in the text\n */\nexport interface SegmentMatch {\n\t/** Index in the patterns array */\n\tindex: number\n\t/** Start position in text */\n\tstart: number\n\t/** End position in text (exclusive) */\n\tend: number\n\t/** Matched text */\n\tvalue: string\n\t/** Captured content from dynamic pattern (if any) */\n\tcaptured?: string\n}\n\n/**\n * Segment definition - can be a static string or a dynamic pattern\n * For dynamic patterns: [before, after, exclusions]\n */\nexport type SegmentDefinition = string | readonly [before: string, after: string, exclusions: string]\n\n/**\n * Internal representation of a segment with its regex pattern\n */\ninterface SegmentEntry {\n\t/** Original index in the segments array */\n\tindex: number\n\t/** Regex pattern for this segment (escaped static or dynamic pattern) */\n\tpattern: string\n\t/** Original definition for reference */\n\tdefinition: SegmentDefinition\n}\n\n/**\n * Computes regex pattern for dynamic segment using pre-computed exclusions\n */\nfunction computeDynamicPattern(before: string, after: string, exclusions: string): string {\n\tconst escapedBefore = escape(before)\n\tconst escapedAfter = escape(after)\n\tconst escapedDelimiters = escape(after + exclusions)\n\n\t// Non-greedy quantifier to stop at first occurrence of after\n\treturn `${escapedBefore}([^${escapedDelimiters}]+?)${escapedAfter}`\n}\n\ninterface StaticMatcher {\n\tregex: RegExp\n\ttoIndex: Map<string, number>\n}\n\ninterface DynamicMatcher {\n\tregex: RegExp\n\tentries: SegmentEntry[]\n\tindices: Set<number>\n}\n\n/**\n * Segment matcher using dual strategy for optimal performance\n */\nexport class SegmentMatcher {\n\tprivate static?: StaticMatcher\n\tprivate dynamic?: DynamicMatcher\n\n\tconstructor(segments: SegmentDefinition[]) {\n\t\tthis.initializeDual(segments)\n\t}\n\n\tprivate initializeDual(segments: SegmentDefinition[]) {\n\t\tconst statics: string[] = []\n\t\tconst dynamics: Array<{segment: SegmentDefinition; index: number}> = []\n\t\tconst staticToIndex = new Map<string, number>()\n\n\t\t// Separate segments and build static index map\n\t\tsegments.forEach((segment, index) => {\n\t\t\tif (typeof segment === 'string') {\n\t\t\t\tstatics.push(segment)\n\t\t\t\tstaticToIndex.set(segment, index)\n\t\t\t} else {\n\t\t\t\tdynamics.push({segment, index})\n\t\t\t}\n\t\t})\n\n\t\t// Create static matcher\n\t\tif (statics.length > 0) {\n\t\t\tconst sorted = [...statics].toSorted((a, b) => b.length - a.length)\n\t\t\tconst escaped = sorted.map(escape)\n\t\t\tthis.static = {\n\t\t\t\tregex: new RegExp(`(?:${escaped.join('|')})`, 'gu'),\n\t\t\t\ttoIndex: staticToIndex,\n\t\t\t}\n\t\t}\n\n\t\t// Create dynamic matcher\n\t\tif (dynamics.length > 0) {\n\t\t\tconst indices = new Set<number>()\n\t\t\tconst entries: SegmentEntry[] = []\n\n\t\t\tdynamics.forEach(({segment, index}) => {\n\t\t\t\tif (typeof segment === 'string') return\n\t\t\t\tconst [before, after, exclusions] = segment\n\t\t\t\tindices.add(index)\n\t\t\t\tconst pattern = computeDynamicPattern(before, after, exclusions)\n\t\t\t\tconst namedPattern = pattern.replace('(', `(?<content${index}>`)\n\t\t\t\tentries.push({index, pattern: namedPattern, definition: segment})\n\t\t\t})\n\n\t\t\t// Sort by pattern length (longest first) for optimal matching\n\t\t\tentries.sort((a, b) => {\n\t\t\t\tconst aLen = typeof a.definition === 'string' ? a.definition.length : a.pattern.length\n\t\t\t\tconst bLen = typeof b.definition === 'string' ? b.definition.length : b.pattern.length\n\t\t\t\treturn bLen - aLen\n\t\t\t})\n\n\t\t\tthis.dynamic = {\n\t\t\t\tentries,\n\t\t\t\tindices,\n\t\t\t\tregex: new RegExp(entries.map((e, i) => `(?<seg${i}>${e.pattern})`).join('|'), 'gu'),\n\t\t\t}\n\t\t}\n\t}\n\n\tsearch(text: string): SegmentMatch[] {\n\t\tconst results: SegmentMatch[] = []\n\t\tconst dynamicResults: SegmentMatch[] = []\n\n\t\t// Static segments\n\t\tif (this.static) {\n\t\t\tconst {regex, toIndex} = this.static\n\t\t\tfor (const match of text.matchAll(regex)) {\n\t\t\t\tconst index = toIndex.get(match[0])\n\t\t\t\tif (index !== undefined) {\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\tindex,\n\t\t\t\t\t\tstart: match.index,\n\t\t\t\t\t\tend: match.index + match[0].length,\n\t\t\t\t\t\tvalue: match[0],\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Dynamic segments\n\t\tif (this.dynamic) {\n\t\t\tconst {regex, entries, indices} = this.dynamic\n\t\t\tfor (const match of text.matchAll(regex)) {\n\t\t\t\tconst matchedText = match[0]\n\t\t\t\tconst start = match.index\n\n\t\t\t\tlet matchedIndex: number | undefined\n\t\t\t\tlet captured: string | undefined\n\n\t\t\t\tif (match.groups) {\n\t\t\t\t\tfor (let i = 0; i < entries.length; i++) {\n\t\t\t\t\t\tconst groupValue = match.groups[`seg${i}`]\n\t\t\t\t\t\t// oxlint-disable-next-line no-unnecessary-condition\n\t\t\t\t\t\tif (groupValue !== undefined) {\n\t\t\t\t\t\t\tmatchedIndex = entries[i].index\n\t\t\t\t\t\t\tif (indices.has(matchedIndex)) {\n\t\t\t\t\t\t\t\tcaptured = match.groups[`content${matchedIndex}`]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (matchedIndex !== undefined) {\n\t\t\t\t\tdynamicResults.push({\n\t\t\t\t\t\tindex: matchedIndex,\n\t\t\t\t\t\tstart,\n\t\t\t\t\t\tend: start + matchedText.length,\n\t\t\t\t\t\tvalue: matchedText,\n\t\t\t\t\t\tcaptured,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Filter overlapping static matches and merge\n\t\tconst finalResults = [...dynamicResults]\n\t\tfor (const staticMatch of results) {\n\t\t\tconst overlaps = dynamicResults.some(\n\t\t\t\tdynamic => staticMatch.start < dynamic.end && staticMatch.end > dynamic.start\n\t\t\t)\n\t\t\tif (!overlaps) {\n\t\t\t\tfinalResults.push(staticMatch)\n\t\t\t}\n\t\t}\n\n\t\tfinalResults.sort((a, b) => a.start - b.start)\n\t\treturn finalResults\n\t}\n}","import type {TextToken} from '../types'\n\n/**\n * Creates a text token for a range in the input\n *\n * @param input - Original input text\n * @param start - Start position (inclusive)\n * @param end - End position (exclusive)\n * @returns TextToken with extracted content and position\n */\nexport const createTextToken = (input: string, start = 0, end = input.length): TextToken => {\n\treturn {\n\t\ttype: 'text',\n\t\tcontent: input.substring(start, end),\n\t\tposition: {start, end},\n\t}\n}","import type {MarkToken, ParseOptions, PositionRange, TextToken, Token} from '../types'\nimport {createTextToken} from '../utils/createTextToken'\nimport type {Match} from './Match'\n\n/**\n * Parent context for tracking active nesting during tree building\n */\ninterface ParentContext {\n\tmatch: Match\n\ttoken: MarkToken\n\ttextPos: number // Current position for adding text tokens\n}\n\n/**\n * TreeBuilder - Optimized single-pass tree building algorithm\n *\n * Algorithm: Single-pass approach with direct token creation\n * - Processes matches in order, maintaining a stack of active parents\n * - Creates tokens directly without intermediate data structures\n * - Handles text gaps and nesting in a single traversal\n *\n * Key optimizations:\n * - Single pass through matches (no separate relationship building phase)\n * - Direct token creation eliminates intermediate allocations\n * - Stack-based parent tracking with O(D) memory where D is nesting depth\n * - No need for parent indices array or children lists\n * - Simpler algorithm that's easier to understand and maintain\n *\n * Complexity: O(M) where M is number of matches\n * Memory: O(D) for active parents stack where D is nesting depth (typically 3-5)\n */\nexport class TreeBuilder {\n\t// Instance fields - only what's needed for single pass\n\tprivate input!: string\n\tprivate readonly options: ParseOptions\n\n\tconstructor(options?: ParseOptions) {\n\t\tthis.options = options ?? {}\n\t}\n\n\t// ===== PUBLIC API =====\n\n\t/**\n\t * Builds nested token tree from pre-processed matches in a single pass\n\t *\n\t * Algorithm:\n\t * 1. Iterate through matches in order\n\t * 2. For each match:\n\t * - Close any parents whose content ends before this match\n\t * - Skip matches that conflict with the last accepted match\n\t * - Add text token before this match\n\t * - Create mark token and push to appropriate parent\n\t * - If match has nested content, push to active parents stack\n\t * 3. After all matches, close remaining parents and add final text\n\t *\n\t * Complexity: O(M) where M is number of matches\n\t * Memory: O(D) for active parents stack where D is nesting depth\n\t */\n\tpublic build(matches: Match[], input: string): Token[] {\n\t\tthis.input = input\n\n\t\tif (matches.length === 0) {\n\t\t\treturn this.filterTokens([this.createTextToken(0, input.length)])\n\t\t}\n\n\t\tconst tokens = this.buildSinglePass(matches)\n\t\treturn this.filterTokens(tokens)\n\t}\n\n\t// ===== SINGLE-PASS ALGORITHM =====\n\n\t/**\n\t * Builds token tree in a single pass through matches\n\t *\n\t * This is the core algorithm that processes matches sequentially,\n\t * maintaining a stack of active parents and creating tokens directly.\n\t */\n\tprivate buildSinglePass(matches: Match[]): Token[] {\n\t\tconst roots: Token[] = []\n\t\tconst parentStack: ParentContext[] = []\n\t\tlet lastAcceptedMatch: Match | null = null\n\t\tlet rootTextPos = 0\n\n\t\tfor (const match of matches) {\n\t\t\t// Skip conflicting matches\n\t\t\tif (lastAcceptedMatch && match.conflictsWith(lastAcceptedMatch)) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tlastAcceptedMatch = match\n\n\t\t\t// Close parents whose content ends before this match\n\t\t\twhile (parentStack.length > 0) {\n\t\t\t\tconst parent = parentStack[parentStack.length - 1]\n\t\t\t\tconst parentBounds = this.getContentBounds(parent.match)\n\n\t\t\t\tif (parentBounds.end <= match.start) {\n\t\t\t\t\t// Parent is complete - finalize it\n\t\t\t\t\tthis.finalizeParent(parent, parentBounds.end)\n\t\t\t\t\tparentStack.pop()\n\n\t\t\t\t\t// Add to appropriate container\n\t\t\t\t\tif (parentStack.length > 0) {\n\t\t\t\t\t\tparentStack[parentStack.length - 1].token.children.push(parent.token)\n\t\t\t\t\t} else {\n\t\t\t\t\t\troots.push(parent.token)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Determine where to add this match\n\t\t\tconst container = parentStack.length > 0 ? parentStack[parentStack.length - 1] : null\n\n\t\t\tif (container) {\n\t\t\t\t// Add text before this match within parent\n\t\t\t\tconst textToken = this.createTextToken(container.textPos, match.start)\n\t\t\t\tcontainer.token.children.push(textToken)\n\t\t\t\tcontainer.textPos = match.end\n\t\t\t} else {\n\t\t\t\t// Add text before this match at root level\n\t\t\t\tconst textToken = this.createTextToken(rootTextPos, match.start)\n\t\t\t\troots.push(textToken)\n\t\t\t\trootTextPos = match.end\n\t\t\t}\n\n\t\t\t// Create mark token for this match\n\t\t\tconst markToken = this.createMarkToken(match)\n\n\t\t\t// If match has children content, push to stack for processing children\n\t\t\tif (this.hasSlotContent(match)) {\n\t\t\t\tconst bounds = this.getContentBounds(match)\n\t\t\t\tparentStack.push({\n\t\t\t\t\tmatch,\n\t\t\t\t\ttoken: markToken,\n\t\t\t\t\ttextPos: bounds.start,\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\t// No nested content - add directly to container\n\t\t\t\tif (container) {\n\t\t\t\t\tcontainer.token.children.push(markToken)\n\t\t\t\t} else {\n\t\t\t\t\troots.push(markToken)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Close remaining parents\n\t\twhile (parentStack.length > 0) {\n\t\t\tconst parent = parentStack[parentStack.length - 1]\n\t\t\tparentStack.pop()\n\t\t\tconst parentBounds = this.getContentBounds(parent.match)\n\t\t\tthis.finalizeParent(parent, parentBounds.end)\n\n\t\t\tif (parentStack.length > 0) {\n\t\t\t\tparentStack[parentStack.length - 1].token.children.push(parent.token)\n\t\t\t} else {\n\t\t\t\troots.push(parent.token)\n\t\t\t}\n\t\t}\n\n\t\t// Add final text token at root level\n\t\troots.push(this.createTextToken(rootTextPos, this.input.length))\n\n\t\treturn roots\n\t}\n\n\t/**\n\t * Finalizes a parent token by adding final text token if needed\n\t */\n\tprivate finalizeParent(parent: ParentContext, endPos: number): void {\n\t\tparent.token.children.push(this.createTextToken(parent.textPos, endPos))\n\t}\n\n\t/**\n\t * Creates a mark token from a match (without children - those are added later)\n\t */\n\tprivate createMarkToken(match: Match): MarkToken {\n\t\t// Extract content using helper functions\n\t\tconst value = this.extractSubstring(match.gaps.value?.start, match.gaps.value?.end)\n\t\tconst slotStr = this.extractSubstring(match.gaps.slot?.start, match.gaps.slot?.end)\n\t\tconst metaStr = this.extractSubstring(match.gaps.meta?.start, match.gaps.meta?.end)\n\n\t\t// Convert empty strings to undefined for slot, but meta can be empty string\n\t\tconst slotContent = slotStr || undefined\n\t\tconst meta = match.gaps.meta !== undefined ? metaStr : undefined\n\n\t\treturn {\n\t\t\ttype: 'mark',\n\t\t\tcontent: this.input.substring(match.start, match.end),\n\t\t\tchildren: [], // Will be populated if match has slot content\n\t\t\tdescriptor: match.descriptor,\n\t\t\tvalue,\n\t\t\tmeta,\n\t\t\tposition: {start: match.start, end: match.end},\n\t\t\tslot: this.createSlotSourceInfo(match, slotContent),\n\t\t}\n\t}\n\n\t// ===== UTILITY METHODS =====\n\n\t/**\n\t * Gets the content boundaries for a match\n\t * Priority: nested content if present, otherwise value content\n\t */\n\tprivate getContentBounds(match: Match): PositionRange {\n\t\tif (match.gaps.slot) {\n\t\t\treturn match.gaps.slot\n\t\t}\n\t\tif (match.gaps.value) {\n\t\t\treturn match.gaps.value\n\t\t}\n\t\treturn {\n\t\t\tstart: match.start,\n\t\t\tend: match.start,\n\t\t}\n\t}\n\n\t/**\n\t * Checks if a match has children content capability\n\t */\n\tprivate hasSlotContent(match: Match): boolean {\n\t\treturn match.gaps.slot !== undefined\n\t}\n\n\t/**\n\t * Extracts substring safely, returns empty string if positions are undefined\n\t */\n\tprivate extractSubstring(start: number | undefined, end: number | undefined): string {\n\t\treturn start !== undefined && end !== undefined ? this.input.substring(start, end) : ''\n\t}\n\n\t/**\n\t * Creates a text token for a range in the input\n\t */\n\tprivate createTextToken(start: number, end: number): TextToken {\n\t\treturn createTextToken(this.input, start, end)\n\t}\n\n\t/**\n\t * Creates children source info object if children content exists\n\t */\n\tprivate createSlotSourceInfo(match: Match, slotContent: string | undefined): MarkToken['slot'] {\n\t\tif (!slotContent || match.gaps.slot === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn {\n\t\t\tcontent: slotContent,\n\t\t\tstart: match.gaps.slot.start,\n\t\t\tend: match.gaps.slot.end,\n\t\t}\n\t}\n\n\t// ===== TOKEN FILTERING. TODO: Is a hack =====\n\n\tprivate filterTokens(tokens: Token[]): Token[] {\n\t\tconst {marksOnly, skipEmptyText} = this.options\n\t\tif (!marksOnly && !skipEmptyText) return tokens\n\n\t\treturn tokens.filter(token => {\n\t\t\tif (token.type !== 'text') return true\n\t\t\tif (marksOnly) return false\n\t\t\tif (skipEmptyText && token.position.start === token.position.end) return false\n\t\t\treturn true\n\t\t})\n\t}\n}","import type {MarkToken, Token} from '../types'\n\n/**\n * Internal function to process tokens with a callback\n * @param tokens - Tokens to process\n * @param callback - Function to transform each MarkToken\n * @returns Transformed text\n */\nexport function processTokensWithCallback(tokens: Token[], callback: (mark: MarkToken) => string): string {\n\tlet result = ''\n\tfor (const token of tokens) {\n\t\tif (token.type === 'text') {\n\t\t\tresult += token.content\n\t\t} else {\n\t\t\t// For MarkToken with children, we need to decide:\n\t\t\t// - If we want to transform the mark itself AND its children\n\t\t\t// - Or transform children and include them in the mark's transformation\n\n\t\t\tif (token.children.length > 0) {\n\t\t\t\t// Recursively process children to get their transformed content\n\t\t\t\tconst processedChildren = processTokensWithCallback(token.children, callback)\n\n\t\t\t\t// Create a modified token with processed children as the value\n\t\t\t\t// This allows the callback to use the already-processed nested content\n\t\t\t\tconst modifiedToken: MarkToken = {\n\t\t\t\t\t...token,\n\t\t\t\t\tvalue: processedChildren,\n\t\t\t\t}\n\t\t\t\tresult += callback(modifiedToken)\n\t\t\t} else {\n\t\t\t\tresult += callback(token)\n\t\t\t}\n\t\t}\n\t}\n\treturn result\n}","import {PLACEHOLDER} from '../constants'\nimport type {Markup} from '../types'\n\n/**\n * Make annotation from the markup for ParserV2\n *\n * @param markup - Markup pattern with __value__, __meta__, and/or __slot__ placeholders\n * @param params - Object with optional value, meta, and slot strings\n * @returns Annotated string with placeholders replaced\n *\n * @example\n * ```typescript\n * annotate('@[__value__]', { value: 'Hello' }) // '@[Hello]'\n * annotate('@[__value__](__meta__)', { value: 'Hello', meta: 'world' }) // '@[Hello](world)'\n * annotate('@[__slot__]', { slot: 'content' }) // '@[content]'\n * ```\n */\nexport function annotate(\n\tmarkup: Markup,\n\tparams: {\n\t\tvalue?: string\n\t\tmeta?: string\n\t\tslot?: string\n\t}\n): string {\n\tlet annotation = markup as string\n\n\tif (params.value !== undefined) {\n\t\tannotation = annotation.replaceAll(PLACEHOLDER.Value, params.value)\n\t}\n\n\tif (params.meta !== undefined) {\n\t\tannotation = annotation.replaceAll(PLACEHOLDER.Meta, params.meta)\n\t}\n\n\tif (params.slot !== undefined) {\n\t\tannotation = annotation.replaceAll(PLACEHOLDER.Slot, params.slot)\n\t}\n\n\treturn annotation\n}","import type {Token} from '../types'\nimport {annotate} from './annotate'\n\n/**\n * Convert parsed tokens back to annotated string (inverse of `parse`).\n *\n * This function is useful for reconstructing annotated text from tokens,\n * similar to toString in text-manipulation/utils but for ParserV2\n *\n * @param tokens - Array of parsed tokens (from ParserV2.parse)\n * @returns Reconstructed annotated string\n *\n * @example\n * ```typescript\n * const markups = ['@[__value__](__meta__)', '#[__slot__]']\n * const tokens = new ParserV2(markups).parse('@[Hello](world) #[test]')\n * const result = toString(tokens)\n * // Returns: '@[Hello](world) #[test]'\n * ```\n */\nexport function toString(tokens: Token[]): string {\n\tlet result = ''\n\n\tfor (const token of tokens) {\n\t\tif (token.type === 'text') {\n\t\t\tresult += token.content\n\t\t\tcontinue\n\t\t}\n\n\t\tconst {markup, hasSlot} = token.descriptor\n\t\tconst slot = hasSlot ? (token.children.length > 0 ? toString(token.children) : token.slot?.content) : undefined\n\n\t\tresult += annotate(markup, {\n\t\t\tvalue: token.value,\n\t\t\tmeta: token.meta,\n\t\t\tslot,\n\t\t})\n\t}\n\n\treturn result\n}","import {MarkupRegistry} from './core/MarkupRegistry'\nimport {PatternMatcher} from './core/PatternMatcher'\nimport {SegmentMatcher} from './core/SegmentMatcher'\nimport {TreeBuilder} from './core/TreeBuilder'\nimport type {MarkToken, Markup, ParseOptions, Token} from './types'\nimport {createTextToken} from './utils/createTextToken'\nimport {processTokensWithCallback} from './utils/processTokens'\nimport {toString as tokensToString} from './utils/toString'\n\n/**\n * Parser - High-performance tree-based markup parser\n *\n * Parses text with markup patterns into a nested token tree structure.\n * Supports complex patterns with metadata, nesting, and HTML-like constructs.\n *\n * @example\n * ```typescript\n * const parser = new Parser(['@[__value__](__meta__)', '#[__slot__]'])\n * const tokens = parser.parse('Hello @[world](test) and #[tag]')\n * const text = parser.stringify(tokens)\n * ```\n */\nexport class Parser {\n\tprivate readonly registry: MarkupRegistry\n\tprivate readonly segmentMatcher: SegmentMatcher\n\tprivate readonly patternMatcher: PatternMatcher\n\tprivate readonly treeBuilder: TreeBuilder\n\tprivate readonly parseOptions: ParseOptions\n\n\t/**\n\t * Creates a new Parser instance with the specified markup patterns\n\t *\n\t * @param markups - Array of markup pattern strings with placeholders (can include undefined values):\n\t * - `__value__` - main content (plain text, no nesting)\n\t * - `__meta__` - metadata (plain text, no nesting)\n\t * - `__slot__` - content supporting nested structures\n\t * - `undefined` - skipped, but original array indices are preserved for descriptor matching\n\t * @param options - Optional parse options to control token output:\n\t * - `marksOnly` - return only MarkTokens, drop all TextTokens\n\t * - `skipEmptyText` - drop zero-length TextTokens (where start === end)\n\t *\n\t * @example\n\t * ```typescript\n\t * const parser = new Parser([\n\t * '@[__value__](__meta__)', // @[label](value) - descriptor.index = 0\n\t * undefined, // skipped\n\t * '#[__slot__]', // #[nested content] - descriptor.index = 2\n\t * '**__slot__**' // **bold text** - descriptor.index = 3\n\t * ])\n\t * ```\n\t */\n\tconstructor(markups: (Markup | undefined)[], options?: ParseOptions) {\n\t\tthis.registry = new MarkupRegistry(markups)\n\t\tthis.segmentMatcher = new SegmentMatcher(this.registry.segments)\n\t\tthis.patternMatcher = new PatternMatcher(this.registry)\n\t\tthis.parseOptions = options ?? {}\n\t\tthis.treeBuilder = new TreeBuilder(this.parseOptions)\n\t}\n\n\t/**\n\t * Parses text into tokens (static convenience method)\n\t *\n\t * @param value - Text to parse\n\t * @param options - Options with markup patterns and token filtering\n\t * @returns Array of tokens (TextToken and MarkToken)\n\t *\n\t * @example\n\t * ```typescript\n\t * const tokens = Parser.parse('Hello @[world]', {\n\t * markup: ['@[__value__]']\n\t * })\n\t * ```\n\t */\n\tstatic parse(value: string, options?: {markup: Markup[]} & ParseOptions): Token[] {\n\t\tconst markups = options?.markup\n\t\tif (!markups || markups.length === 0) {\n\t\t\treturn [createTextToken(value)]\n\t\t}\n\t\tconst {markup: _, ...parseOptions} = options\n\t\treturn new Parser(markups, parseOptions).parse(value)\n\t}\n\n\t/**\n\t * Converts tokens back to text (static convenience method)\n\t *\n\t * @param tokens - Array of tokens to convert\n\t * @returns Reconstructed text string\n\t *\n\t * @example\n\t * ```typescript\n\t * const text = Parser.stringify(tokens)\n\t * ```\n\t */\n\tstatic stringify(tokens: Token[]): string {\n\t\treturn tokensToString(tokens)\n\t}\n\n\t/**\n\t * Parses text into a nested token tree\n\t *\n\t * This is the main parsing method. It processes the input text through\n\t * three stages:\n\t * 1. Segment matching - finds all markup segments (O(N + M))\n\t * 2. Pattern matching - builds complete patterns from segments (O(M))\n\t * 3. Tree building - constructs nested token tree (O(M·D))\n\t *\n\t * @param value - Text to parse\n\t * @returns Array of tokens representing the parsed structure\n\t *\n\t * @example\n\t * ```typescript\n\t * const parser = new Parser(['@[__value__](__meta__)'])\n\t * const tokens = parser.parse('Hello @[world](test)')\n\t * // Returns: [\n\t * // TextToken('Hello '),\n\t * // MarkToken('@[world](test)', value='world', meta='test'),\n\t * // TextToken('')\n\t * // ]\n\t * ```\n\t */\n\tparse(value: string): Token[] {\n\t\tconst segments = this.segmentMatcher.search(value)\n\t\tconst matches = this.patternMatcher.process(segments)\n\t\treturn this.treeBuilder.build(matches, value)\n\t}\n\n\t/**\n\t * Converts tokens back to the original text\n\t *\n\t * This is the inverse operation of parse(). It reconstructs the original\n\t * text from a token tree, preserving all markup and structure.\n\t *\n\t * @param tokens - Array of tokens to convert\n\t * @returns Reconstructed text string\n\t *\n\t * @example\n\t * ```typescript\n\t * const text = 'Hello @[world](test)'\n\t * const tokens = parser.parse(text)\n\t * const reconstructed = parser.stringify(tokens)\n\t * console.log(reconstructed === text) // true\n\t * ```\n\t */\n\tstringify(tokens: Token[]): string {\n\t\treturn tokensToString(tokens)\n\t}\n\n\t/**\n\t * Transforms annotated text by processing all mark tokens with a callback\n\t *\n\t * This method parses the text, recursively processes all MarkTokens\n\t * (including nested ones) with the provided callback, and returns\n\t * the transformed text.\n\t *\n\t * @param value - Annotated text to process\n\t * @param callback - Function to transform each MarkToken\n\t * @returns Transformed text\n\t *\n\t * @example\n\t * ```typescript\n\t * // Extract all values\n\t * const text = '@[Hello](world) and #[tag]'\n\t * const result = parser.transform(text, mark => mark.value)\n\t * // Returns: 'Hello and tag'\n\t *\n\t * // Custom transformation\n\t * const result = parser.transform(text, mark =>\n\t * mark.meta ? `${mark.value}:${mark.meta}` : mark.value\n\t * )\n\t * // Returns: 'Hello:world and tag'\n\t * ```\n\t */\n\ttransform(value: string, callback: (mark: MarkToken) => string): string {\n\t\tconst tokens = this.parse(value)\n\t\treturn processTokensWithCallback(tokens, callback)\n\t}\n\n\t/**\n\t * Escapes markup segments in the given text using backslash\n\t *\n\t * This method uses the registry's unique segments and escapes them by adding\n\t * a backslash before each character of each segment, preventing them from being\n\t * parsed as markup when the text is processed again.\n\t *\n\t * @param text - Text to escape segments in\n\t * @returns Text with escaped segments\n\t *\n\t * @example\n\t * ```typescript\n\t * const parser = new Parser(['**__slot__**', '@[__value__]'])\n\t * const escaped = parser.escape('Hello **world** and @[user]')\n\t * // Returns: 'Hello \\*\\*world\\*\\* and \\@[user]'\n\t * ```\n\t */\n\tescape(text: string): string {\n\t\treturn this.registry.segments\n\t\t\t.filter((segment): segment is string => typeof segment === 'string')\n\t\t\t.toSorted((a, b) => b.length - a.length)\n\t\t\t.reduce((result, segment) => result.replaceAll(segment, segment.replace(/(.)/g, '\\\\$1')), text)\n\t}\n\n\t/**\n\t * Unescapes markup patterns in the given text\n\t *\n\t * This method removes escape characters from segments that were previously\n\t * escaped using escape(), allowing the patterns to be parsed normally.\n\t *\n\t * @param text - Text to unescape patterns in\n\t * @returns Text with unescaped patterns\n\t *\n\t * @example\n\t * ```typescript\n\t * const parser = new Parser(['**__slot__**', '@[__value__]'])\n\t * const unescaped = parser.unescape('Hello \\*\\*world\\*\\* and \\@[user]')\n\t * // Returns: 'Hello **world** and @[user]'\n\t * ```\n\t */\n\tunescape(text: string): string {\n\t\treturn text.replaceAll(/\\\\(.)/g, '$1')\n\t}\n}","import {Parser} from '../Parser'\nimport type {MarkToken, Markup} from '../types'\nimport {processTokensWithCallback} from './processTokens'\n\n/**\n * Transform annotated text to another text by recursively processing all tokens\n *\n * @param value - Annotated text to process\n * @param callback - Function to transform each MarkToken\n * @param markups - Array of markup patterns to parse\n * @returns Transformed text\n *\n * @example\n * ```typescript\n * const text = '@[Hello](world) and #[nested @[content]]'\n * const result = denote(text, mark => mark.value, ['@[__value__](__meta__)', '#[__slot__]'])\n * // Returns: 'Hello and nested content'\n * ```\n */\nexport function denote(value: string, callback: (mark: MarkToken) => string, markups: Markup[]): string {\n\tif (!markups.length) return value\n\n\tconst tokens = new Parser(markups).parse(value)\n\n\treturn processTokensWithCallback(tokens, callback)\n}","import type {MarkToken, Token} from '../parser/types'\n\nexport interface TokenContext {\n\tdepth: number\n\tparent?: MarkToken\n}\n\nexport function findToken(tokens: Token[], target: Token, depth = 0, parent?: MarkToken): TokenContext | undefined {\n\tfor (const token of tokens) {\n\t\tif (token === target) return {depth, parent}\n\t\tif (token.type === 'mark') {\n\t\t\tconst result = findToken(token.children, target, depth + 1, token)\n\t\t\tif (result) return result\n\t\t}\n\t}\n}","export type Gap = {left?: number; right?: number}\n\nexport function findGap(previous: string = '', current: string = ''): Gap {\n\tif (previous === current) return {}\n\n\tlet left: number | undefined\n\tfor (let i = 0; i < previous.length; i++) {\n\t\tif (previous[i] !== current[i]) {\n\t\t\tleft = i\n\t\t\tbreak\n\t\t}\n\t}\n\n\tlet right: number | undefined\n\tfor (let i = 1; i <= previous.length; i++) {\n\t\tif (previous.at(-i) !== current.at(-i)) {\n\t\t\tright = previous.length - i + 1\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn {left, right}\n}","export function getClosestIndexes(array: number[], target: number) {\n\tlet left = -1,\n\t\tright = array.length\n\twhile (right - left > 1) {\n\t\tconst middle = Math.round((left + right) / 2)\n\t\tif (array[middle] <= target) {\n\t\t\tleft = middle\n\t\t} else {\n\t\t\tright = middle\n\t\t}\n\t}\n\tif (array[left] == target) right = left\n\t// oxlint-disable-next-line no-unnecessary-condition\n\treturn [left, right].filter(v => array[v] !== undefined)\n}","import type {Store} from '../../../store/Store'\nimport type {Token} from '../parser/types'\nimport {findGap, getClosestIndexes} from '../preparsing'\n\nexport function getTokensByUI(store: Store): Token[] {\n\tconst {focus} = store.nodes\n\tconst parser = store.computed.parser()\n\tconst tokens = store.state.tokens()\n\n\tif (!parser) {\n\t\treturn tokens\n\t}\n\n\tconst parsed = parser.parse(focus.content)\n\n\tif (parsed.length === 1) return tokens\n\n\treturn tokens.toSpliced(focus.index, 1, ...parsed)\n}\n\nexport function getTokensByValue(store: Store): Token[] {\n\tconst value = store.state.value()\n\tconst ranges = getRangeMap(store)\n\tconst gap = findGap(store.state.previousValue(), value)\n\n\tif (!gap.left && !gap.right) {\n\t\tstore.state.previousValue(value)\n\t\treturn store.state.tokens()\n\t}\n\n\tstore.state.previousValue(value)\n\tconst tokens = store.state.tokens()\n\n\tif (\n\t\tgap.left !== undefined &&\n\t\tranges.includes(gap.left) &&\n\t\tgap.right !== undefined &&\n\t\tMath.abs(gap.left - gap.right) > 1\n\t) {\n\t\tconst updatedIndex = ranges.indexOf(gap.left)\n\t\tconst parsed = parseUnionLabels(store, updatedIndex - 1, updatedIndex)\n\t\treturn tokens.toSpliced(updatedIndex - 1, 2, ...parsed)\n\t}\n\tif (gap.left !== undefined) {\n\t\tconst [updatedIndex] = getClosestIndexes(ranges, gap.left)\n\t\tconst parsed = parseUnionLabels(store, updatedIndex)\n\t\tif (parsed.length === 1) return tokens\n\t\treturn tokens.toSpliced(updatedIndex, 1, ...parsed)\n\t}\n\tif (gap.right !== undefined) {\n\t\tconst [updatedIndex] = getClosestIndexes(ranges, gap.right)\n\t\tconst parsed = parseUnionLabels(store, updatedIndex)\n\t\tif (parsed.length === 1) return tokens\n\t\treturn tokens.toSpliced(updatedIndex, 1, ...parsed)\n\t}\n\treturn parseWithParser(store, value ?? '')\n}\n\nexport function parseUnionLabels(store: Store, ...indexes: number[]): Token[] {\n\tlet span = ''\n\tconst tokens = store.state.tokens()\n\tfor (const index of indexes) {\n\t\tconst token = tokens[index]\n\t\tspan += token.content\n\t}\n\n\treturn parseWithParser(store, span)\n}\n\nexport function getRangeMap(store: Store): number[] {\n\tlet position = 0\n\tconst tokens = store.state.tokens()\n\treturn tokens.map(token => {\n\t\tconst length = token.content.length\n\t\tposition += length\n\t\treturn position - length\n\t})\n}\n\nexport function parseWithParser(store: Store, value: string): Token[] {\n\tconst parser = store.computed.parser()\n\tif (!parser) {\n\t\treturn [\n\t\t\t{\n\t\t\t\ttype: 'text' as const,\n\t\t\t\tcontent: value,\n\t\t\t\tposition: {start: 0, end: value.length},\n\t\t\t},\n\t\t]\n\t}\n\n\treturn parser.parse(value)\n}","import {effectScope, watch} from '../../shared/signals/index.js'\nimport type {Store} from '../../store/Store'\nimport type {Parser} from './parser/Parser'\nimport {toString} from './parser/utils/toString'\nimport {getTokensByUI, getTokensByValue, parseWithParser} from './utils/valueParser'\n\nexport class ParseFeature {\n\t#scope?: () => void\n\t#initialized = false\n\t#lastValue: string | undefined\n\t#lastParser: Parser | undefined\n\n\tconstructor(private store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\t\tthis.sync()\n\t\tthis.#scope = effectScope(() => {\n\t\t\tthis.#subscribeParse()\n\t\t\tthis.#subscribeUpdated()\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t\tthis.#initialized = false\n\t}\n\n\tsync() {\n\t\tconst {store} = this\n\t\tconst inputValue = store.state.value() ?? store.state.defaultValue() ?? ''\n\t\tstore.state.tokens(parseWithParser(store, inputValue))\n\t\tstore.state.previousValue(inputValue)\n\t\tthis.#lastValue = store.state.value()\n\t\tthis.#lastParser = store.computed.parser()\n\t\tthis.#initialized = true\n\t}\n\n\thasChanged(): boolean {\n\t\tconst value = this.store.state.value()\n\t\tconst parser = this.store.computed.parser()\n\t\tif (this.#initialized && value === this.#lastValue && parser === this.#lastParser) return false\n\t\tthis.#lastValue = value\n\t\tthis.#lastParser = parser\n\t\treturn true\n\t}\n\n\t#subscribeParse() {\n\t\tconst {store} = this\n\n\t\twatch(store.event.parse, () => {\n\t\t\tif (store.state.recovery()) {\n\t\t\t\tconst text = toString(store.state.tokens())\n\t\t\t\tstore.state.tokens(parseWithParser(store, text))\n\t\t\t\tstore.state.previousValue(text)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tstore.state.tokens(store.nodes.focus.target ? getTokensByUI(store) : getTokensByValue(store))\n\t\t})\n\t}\n\n\t#subscribeUpdated() {\n\t\tconst {store} = this\n\n\t\twatch(store.event.updated, () => {\n\t\t\tif (!this.hasChanged()) return\n\t\t\tif (!store.state.recovery()) {\n\t\t\t\tstore.event.parse()\n\t\t\t}\n\t\t})\n\t}\n}","import type {Store} from '../../store'\nimport {Caret} from '../caret'\n\nexport function shiftFocusPrev(store: Store, event: KeyboardEvent): boolean {\n\tconst {focus} = store.nodes\n\tif ((focus.isMark && !focus.isEditable) || focus.isCaretAtBeginning) {\n\t\t// Walk back to the nearest focusable element (skip non-editable marks)\n\t\tlet prev = focus.prev\n\t\twhile (prev.target && prev.isMark && !prev.isEditable) {\n\t\t\tprev = prev.prev\n\t\t}\n\t\tif (!prev.target) return false\n\n\t\tevent.preventDefault()\n\t\tprev.target.focus()\n\t\t// After focusin fires, store.nodes.focus.target is updated to prev.target.\n\t\t// Set caret at the end of the newly focused element.\n\t\tCaret.setCaretToEnd(prev.target)\n\t\treturn true\n\t}\n\treturn false\n}\n\nexport function shiftFocusNext(store: Store, event: KeyboardEvent): boolean {\n\tconst {focus} = store.nodes\n\tif ((focus.isMark && !focus.isEditable) || focus.isCaretAtEnd) {\n\t\t// Walk forward to the nearest focusable element (skip non-editable marks)\n\t\tlet next = focus.next\n\t\twhile (next.target && next.isMark && !next.isEditable) {\n\t\t\tnext = next.next\n\t\t}\n\t\tif (!next.target) return false\n\n\t\tevent.preventDefault()\n\t\tnext.target.focus()\n\t\t// Set caret at the beginning of the newly focused element\n\t\tCaret.trySetIndex(next.target, 0)\n\t\treturn true\n\t}\n\treturn false\n}","import type {Store} from '../../store'\n\nexport function isFullSelection(store: Store): boolean {\n\tconst sel = window.getSelection()\n\tconst container = store.refs.container\n\tif (!sel?.rangeCount || !container?.firstChild || !container.lastChild) return false\n\n\ttry {\n\t\tconst range = sel.getRangeAt(0)\n\t\treturn (\n\t\t\tcontainer.contains(range.startContainer) &&\n\t\t\tcontainer.contains(range.endContainer) &&\n\t\t\trange.toString().length > 0\n\t\t)\n\t} catch {\n\t\treturn false\n\t}\n}\n\nexport function selectAllText(store: Store, event: KeyboardEvent): void {\n\tif ((event.ctrlKey || event.metaKey) && event.code === 'KeyA') {\n\t\t// In block/drag mode, let the browser handle Ctrl+A natively so it selects\n\t\t// text within the focused block only, not across all blocks.\n\t\tif (store.state.drag()) return\n\n\t\tevent.preventDefault()\n\n\t\tconst selection = window.getSelection()\n\t\tconst anchorNode = store.refs.container?.firstChild\n\t\tconst focusNode = store.refs.container?.lastChild\n\n\t\tif (!selection || !anchorNode || !focusNode) return\n\t\tselection.setBaseAndExtent(anchorNode, 0, focusNode, 1)\n\n\t\tstore.state.selecting('all')\n\t}\n}","import {nodeTarget} from '../../shared/checkers'\nimport {effectScope, effect} from '../../shared/signals/index.js'\nimport type {Store} from '../../store/Store'\n\nexport class TextSelectionFeature {\n\t#mousedownHandler?: (e: MouseEvent) => void\n\t#mousemoveHandler?: (e: MouseEvent) => void\n\t#mouseupHandler?: () => void\n\t#selectionchangeHandler?: () => void\n\t#scope?: () => void\n\t#pressedNode: Node | null = null\n\t#isPressed = false\n\n\tconstructor(private store: Store) {}\n\n\tenable() {\n\t\tif (this.#mousedownHandler) return\n\n\t\tthis.#mousedownHandler = e => {\n\t\t\tthis.#pressedNode = nodeTarget(e)\n\t\t\tthis.#isPressed = true\n\t\t}\n\n\t\tthis.#mousemoveHandler = e => {\n\t\t\tconst container = this.store.refs.container\n\t\t\tif (!container) return\n\t\t\tconst isPressed = this.#isPressed\n\t\t\tconst isNotInnerSome = !container.contains(this.#pressedNode) || this.#pressedNode !== e.target\n\t\t\tconst isInside = window.getSelection()?.containsNode(container, true)\n\n\t\t\tif (isPressed && isNotInnerSome && isInside) {\n\t\t\t\tif (this.store.state.selecting() !== 'drag') {\n\t\t\t\t\tthis.store.state.selecting('drag')\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.#mouseupHandler = () => {\n\t\t\tthis.#isPressed = false\n\t\t\tthis.#pressedNode = null\n\t\t\tif (this.store.state.selecting() === 'drag') {\n\t\t\t\tconst sel = window.getSelection()\n\t\t\t\tif (!sel || sel.isCollapsed) {\n\t\t\t\t\tthis.store.state.selecting(undefined)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.#selectionchangeHandler = () => {\n\t\t\tif (this.store.state.selecting() !== 'drag') return\n\t\t\tconst sel = window.getSelection()\n\t\t\tif (!sel || sel.isCollapsed) {\n\t\t\t\tthis.store.state.selecting(undefined)\n\t\t\t}\n\t\t}\n\n\t\tthis.#scope = effectScope(() => {\n\t\t\teffect(() => {\n\t\t\t\tconst value = this.store.state.selecting()\n\t\t\t\tif (value !== 'drag') return\n\t\t\t\tconst container = this.store.refs.container\n\t\t\t\tif (!container) return\n\t\t\t\tcontainer\n\t\t\t\t\t.querySelectorAll<HTMLElement>('[contenteditable=\"true\"]')\n\t\t\t\t\t.forEach(el => (el.contentEditable = 'false'))\n\t\t\t})\n\t\t})\n\n\t\tdocument.addEventListener('mousedown', this.#mousedownHandler)\n\t\tdocument.addEventListener('mousemove', this.#mousemoveHandler)\n\t\tdocument.addEventListener('mouseup', this.#mouseupHandler)\n\t\tdocument.addEventListener('selectionchange', this.#selectionchangeHandler)\n\t}\n\n\tdisable() {\n\t\tif (this.store.state.selecting() === 'drag') {\n\t\t\t// Set state before unsubscribing so ContentEditableFeature.sync() still fires\n\t\t\tthis.store.state.selecting(undefined)\n\t\t}\n\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\n\t\tif (this.#mousedownHandler) {\n\t\t\tdocument.removeEventListener('mousedown', this.#mousedownHandler)\n\t\t\tif (this.#mousemoveHandler) document.removeEventListener('mousemove', this.#mousemoveHandler)\n\t\t\tif (this.#mouseupHandler) document.removeEventListener('mouseup', this.#mouseupHandler)\n\t\t\tif (this.#selectionchangeHandler)\n\t\t\t\tdocument.removeEventListener('selectionchange', this.#selectionchangeHandler)\n\n\t\t\tthis.#mousedownHandler = undefined\n\t\t\tthis.#mousemoveHandler = undefined\n\t\t\tthis.#mouseupHandler = undefined\n\t\t\tthis.#selectionchangeHandler = undefined\n\t\t}\n\n\t\tthis.#pressedNode = null\n\t\tthis.#isPressed = false\n\t}\n}","import {KEYBOARD} from '../../shared/constants'\nimport type {Store} from '../../store/Store'\nimport {shiftFocusPrev, shiftFocusNext} from '../navigation'\nimport {selectAllText} from '../selection'\n\nexport class ArrowNavFeature {\n\t#keydownHandler?: (e: KeyboardEvent) => void\n\n\tconstructor(private store: Store) {}\n\n\tenable() {\n\t\tif (this.#keydownHandler) return\n\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tthis.#keydownHandler = e => {\n\t\t\tif (this.store.state.drag()) return\n\t\t\tif (!this.store.nodes.focus.target) return\n\n\t\t\tif (e.key === KEYBOARD.LEFT) {\n\t\t\t\tshiftFocusPrev(this.store, e)\n\t\t\t} else if (e.key === KEYBOARD.RIGHT) {\n\t\t\t\tshiftFocusNext(this.store, e)\n\t\t\t}\n\n\t\t\tselectAllText(this.store, e)\n\t\t}\n\n\t\tcontainer.addEventListener('keydown', this.#keydownHandler)\n\t}\n\n\tdisable() {\n\t\tconst container = this.store.refs.container\n\t\tif (!container || !this.#keydownHandler) return\n\n\t\tcontainer.removeEventListener('keydown', this.#keydownHandler)\n\t\tthis.#keydownHandler = undefined\n\t}\n}","/** Custom MIME type for markput markup syntax. */\nexport const MARKPUT_MIME = 'application/x-markput'\n\nconst pendingMarkupByContainer = new WeakMap<HTMLElement, string>()\n\n/**\n * Capture markup data from a paste event, scoped to a specific container.\n * Call this from the `paste` event handler — custom MIME types are readable\n * on ClipboardEvent.clipboardData but not reliably on InputEvent.dataTransfer.\n *\n * Scoping to the container prevents multiple editor instances from consuming\n * each other's clipboard data.\n */\nexport function captureMarkupPaste(event: ClipboardEvent, container: HTMLElement): void {\n\tconst raw = event.clipboardData?.getData(MARKPUT_MIME)\n\tif (raw) {\n\t\tpendingMarkupByContainer.set(container, raw)\n\t} else {\n\t\tpendingMarkupByContainer.delete(container)\n\t}\n}\n\n/**\n * Consume the pending markup data (if any) for the given container.\n * Returns undefined if no markup was captured or the data was already consumed.\n */\nexport function consumeMarkupPaste(container: HTMLElement): string | undefined {\n\tconst markup = pendingMarkupByContainer.get(container)\n\tpendingMarkupByContainer.delete(container)\n\treturn markup\n}\n\n/**\n * Clear the pending markup buffer for the given container. Useful for test cleanup.\n */\nexport function clearMarkupPaste(container: HTMLElement): void {\n\tpendingMarkupByContainer.delete(container)\n}","import type {Store} from '../../store'\nimport type {Token} from '../parsing'\n\n/**\n * Walk up the DOM from `node` until reaching a direct child of `container`.\n * Returns the index of that child in container.children, or -1 if not found.\n *\n * Works for both drag and non-drag modes:\n * - Non-drag: container children are Token-rendered elements (1:1 with tokens)\n * - Drag: container children are Block wrappers (1:1 with tokens)\n * - Nested marks: walks past inner mark elements to the top-level container child\n */\nfunction findContainerChildIndex(node: Node, container: HTMLElement): number {\n\tlet current: HTMLElement | null = node instanceof HTMLElement ? node : node.parentElement\n\twhile (current && current.parentElement !== container) {\n\t\tcurrent = current.parentElement\n\t}\n\tif (!current) return -1\n\treturn Array.from(container.children).indexOf(current)\n}\n\n/** Structural type shared by Range and StaticRange — only boundary properties are read. */\nexport interface RangeBoundary {\n\treadonly startContainer: Node\n\treadonly startOffset: number\n\treadonly endContainer: Node\n\treadonly endOffset: number\n}\n\n/**\n * Returns the character offset of a range boundary within a container child.\n * Walks all text nodes in document order to compute a cumulative character\n * offset, which correctly handles nested marks with multiple text nodes.\n * Falls back to 0 (start) or full text length (end) for out-of-child boundaries.\n *\n * Spec: selectionToTokens.spec.ts (unit) · Clipboard.react.spec.tsx (integration)\n */\nexport function getBoundaryOffset(range: RangeBoundary, child: Element, isStart: boolean): number {\n\tconst targetNode = isStart ? range.startContainer : range.endContainer\n\tconst targetOffset = isStart ? range.startOffset : range.endOffset\n\n\tif (!child.contains(targetNode)) {\n\t\treturn isStart ? 0 : child.textContent.length\n\t}\n\n\tlet charOffset = 0\n\tconst walker = document.createTreeWalker(child, NodeFilter.SHOW_TEXT)\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- SHOW_TEXT guarantees Text\n\tlet current = walker.nextNode() as Text | null\n\twhile (current) {\n\t\tif (current === targetNode) {\n\t\t\treturn charOffset + targetOffset\n\t\t}\n\t\tcharOffset += current.length\n\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- SHOW_TEXT guarantees Text\n\t\tcurrent = walker.nextNode() as Text | null\n\t}\n\n\treturn isStart ? 0 : child.textContent.length\n}\n\nexport interface SelectionTokenRange {\n\ttokens: Token[]\n\t/** Char offset within the first token where the selection starts. */\n\tstartOffset: number\n\t/** Char offset within the last token where the selection ends. */\n\tendOffset: number\n}\n\n/**\n * Map a browser Selection to the subset of tokens it covers.\n * Returns null if selection is collapsed, empty, or outside the container.\n */\nexport function selectionToTokens(store: Store): SelectionTokenRange | null {\n\tconst container = store.refs.container\n\tif (!container) return null\n\n\tconst sel = window.getSelection()\n\tif (!sel || sel.isCollapsed || !sel.rangeCount) return null\n\n\tconst range = sel.getRangeAt(0)\n\n\tif (!container.contains(range.startContainer) || !container.contains(range.endContainer)) {\n\t\treturn null\n\t}\n\n\tconst tokens = store.state.tokens()\n\n\tlet startIndex = findContainerChildIndex(range.startContainer, container)\n\tlet endIndex = findContainerChildIndex(range.endContainer, container)\n\n\tif (startIndex === -1 || endIndex === -1) return null\n\n\tif (startIndex > endIndex) {\n\t\t;[startIndex, endIndex] = [endIndex, startIndex]\n\t}\n\n\tconst startChild = container.children.item(startIndex)\n\tconst endChild = container.children.item(endIndex)\n\n\treturn {\n\t\ttokens: tokens.slice(startIndex, endIndex + 1),\n\t\tstartOffset: startChild ? getBoundaryOffset(range, startChild, true) : 0,\n\t\tendOffset: endChild ? getBoundaryOffset(range, endChild, false) : 0,\n\t}\n}","import type {Store} from '../../store'\nimport {toString} from '../parsing'\nimport type {Token} from '../parsing'\nimport {MARKPUT_MIME} from './pasteMarkup'\nimport {type SelectionTokenRange, selectionToTokens} from './selectionToTokens'\n\n/**\n * Trim boundary text tokens to the selected portion.\n * Mark tokens are always kept in full — partial mark selection expands to full mark.\n *\n * NOTE: Returned text tokens have stale `position` fields — the start/end positions\n * still reflect the original token, not the trimmed content. Only `content` is\n * authoritative on the returned tokens. `toString` is safe because it reads `content`\n * directly; do not use `position` on the returned tokens for any other purpose.\n */\nfunction trimBoundaryTokens({tokens, startOffset, endOffset}: SelectionTokenRange): Token[] {\n\tif (tokens.length === 0) return tokens\n\n\treturn tokens.map((token, i) => {\n\t\tif (token.type !== 'text') return token\n\n\t\tconst isFirst = i === 0\n\t\tconst isLast = i === tokens.length - 1\n\n\t\tif (isFirst && isLast) return {...token, content: token.content.slice(startOffset, endOffset)}\n\t\tif (isFirst) return {...token, content: token.content.slice(startOffset)}\n\t\tif (isLast) return {...token, content: token.content.slice(0, endOffset)}\n\t\treturn token\n\t})\n}\n\nexport class CopyFeature {\n\t#copyHandler?: (e: ClipboardEvent) => void\n\t#cutHandler?: (e: ClipboardEvent) => void\n\n\tconstructor(private store: Store) {}\n\n\tenable() {\n\t\tif (this.#copyHandler) return\n\n\t\tthis.#copyHandler = (e: ClipboardEvent) => {\n\t\t\tthis.#handleCopy(e)\n\t\t}\n\n\t\tthis.#cutHandler = (e: ClipboardEvent) => {\n\t\t\tif (!this.#handleCopy(e)) return\n\n\t\t\tconst result = selectionToTokens(this.store)\n\t\t\tif (!result || result.tokens.length === 0) return\n\n\t\t\tconst first = result.tokens[0]\n\t\t\tconst last = result.tokens[result.tokens.length - 1]\n\n\t\t\tconst rawStart = first.type === 'text' ? first.position.start + result.startOffset : first.position.start\n\t\t\tconst rawEnd = last.type === 'text' ? last.position.start + result.endOffset : last.position.end\n\n\t\t\tconst value = this.store.state.previousValue() ?? this.store.state.value() ?? ''\n\t\t\tif (rawStart === rawEnd) return\n\n\t\t\tconst newValue = value.slice(0, rawStart) + value.slice(rawEnd)\n\t\t\tthis.store.state.innerValue(newValue)\n\n\t\t\tconst newTokens = this.store.state.tokens()\n\t\t\tlet targetIdx = newTokens.findIndex(\n\t\t\t\tt => t.type === 'text' && rawStart >= t.position.start && rawStart <= t.position.end\n\t\t\t)\n\t\t\tif (targetIdx === -1) targetIdx = newTokens.length - 1\n\t\t\tconst caretWithinToken = rawStart - newTokens[targetIdx].position.start\n\n\t\t\tthis.store.state.recovery({\n\t\t\t\tanchor: this.store.nodes.focus,\n\t\t\t\tcaret: caretWithinToken,\n\t\t\t\tisNext: true,\n\t\t\t\tchildIndex: targetIdx - 2,\n\t\t\t})\n\t\t}\n\n\t\tconst container = this.store.refs.container\n\t\tcontainer?.addEventListener('copy', this.#copyHandler)\n\t\tcontainer?.addEventListener('cut', this.#cutHandler)\n\t}\n\n\tdisable() {\n\t\tconst container = this.store.refs.container\n\t\tif (this.#copyHandler) {\n\t\t\tcontainer?.removeEventListener('copy', this.#copyHandler)\n\t\t\tthis.#copyHandler = undefined\n\t\t}\n\t\tif (this.#cutHandler) {\n\t\t\tcontainer?.removeEventListener('cut', this.#cutHandler)\n\t\t\tthis.#cutHandler = undefined\n\t\t}\n\t}\n\n\t#handleCopy(e: ClipboardEvent): boolean {\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return false\n\n\t\tconst sel = window.getSelection()\n\t\tif (!sel || sel.isCollapsed || !sel.rangeCount) return false\n\n\t\tconst range = sel.getRangeAt(0)\n\t\tif (!container.contains(range.startContainer) || !container.contains(range.endContainer)) {\n\t\t\treturn false\n\t\t}\n\n\t\tconst result = selectionToTokens(this.store)\n\t\tif (!result) return false\n\n\t\t// text/plain: visual selected text\n\t\tconst plainText = range.toString()\n\n\t\t// text/html: rendered DOM HTML from the actual selection\n\t\tconst fragment = range.cloneContents()\n\t\tconst div = document.createElement('div')\n\t\tdiv.appendChild(fragment)\n\t\tconst html = div.innerHTML\n\n\t\t// application/x-markput: boundary text tokens trimmed to selected portion,\n\t\t// mark tokens always expanded to full markup syntax\n\t\tconst markup = toString(trimBoundaryTokens(result))\n\n\t\te.preventDefault()\n\t\te.clipboardData?.setData('text/plain', plainText)\n\t\te.clipboardData?.setData('text/html', html)\n\t\te.clipboardData?.setData(MARKPUT_MIME, markup)\n\t\treturn true\n\t}\n}","import type {MarkToken, Token} from '../parsing'\n\nfunction gapText(value: string, a: Token, b: Token): string {\n\treturn value.substring(a.position.end, b.position.start)\n}\n\nfunction isSlotLeadingMark(token: Token): token is MarkToken {\n\treturn token.type === 'mark' && token.descriptor.hasSlot && token.descriptor.segments.length === 1\n}\n\n/**\n * Returns whether two adjacent rows can be merged (Backspace/Delete).\n * Text rows merge when there's a gap between them.\n * Slot-leading mark rows of the same descriptor merge by removing the first mark's suffix.\n */\nexport function canMergeRows(a: Token, b: Token): boolean {\n\tif (a.type === 'text' && b.type === 'text' && b.position.start > a.position.end) return true\n\tif (isSlotLeadingMark(a) && isSlotLeadingMark(b) && a.descriptor === b.descriptor) return true\n\treturn false\n}\n\nexport function addDragRow(value: string, rows: Token[], afterIndex: number, newRowContent: string): string {\n\tif (rows.length === 0) return value + newRowContent\n\tif (value === '' || (rows.length === 1 && rows[0].type === 'text' && rows[0].content === ''))\n\t\treturn newRowContent + newRowContent\n\tif (afterIndex >= rows.length - 1) return value + newRowContent\n\n\tconst insertPos = rows[afterIndex + 1].position.start\n\treturn value.slice(0, insertPos) + newRowContent + value.slice(insertPos)\n}\n\nexport function deleteDragRow(value: string, rows: Token[], index: number): string {\n\tif (rows.length <= 1) return ''\n\n\tif (index >= rows.length - 1) {\n\t\treturn value.slice(0, rows[index - 1].position.end)\n\t}\n\n\treturn value.slice(0, rows[index].position.start) + value.slice(rows[index + 1].position.start)\n}\n\nexport function duplicateDragRow(value: string, rows: Token[], index: number): string {\n\tconst row = rows[index]\n\tconst rowText = value.substring(row.position.start, row.position.end)\n\n\tif (index >= rows.length - 1) return value + rowText\n\n\tconst next = rows[index + 1]\n\tconst gap = gapText(value, row, next)\n\treturn value.slice(0, next.position.start) + rowText + gap + value.slice(next.position.start)\n}\n\n/**\n * Returns the raw-value position of the join point between row[index-1] and row[index]\n * for use as the caret position after a merge.\n */\nexport function getMergeDragRowJoinPos(rows: Token[], index: number): number {\n\tif (index <= 0 || index >= rows.length) return 0\n\tconst prev = rows[index - 1]\n\tif (isSlotLeadingMark(prev) && prev.slot) return prev.slot.end\n\treturn prev.position.end\n}\n\n/**\n * Merges row[index] into row[index - 1] by removing the boundary between them.\n * For text rows: removes the gap between them.\n * For slot-leading marks: removes the first mark's literal suffix, merging slot content.\n */\nexport function mergeDragRows(value: string, rows: Token[], index: number): string {\n\tif (index <= 0 || index >= rows.length) return value\n\tconst prev = rows[index - 1]\n\tconst curr = rows[index]\n\tif (isSlotLeadingMark(prev) && isSlotLeadingMark(curr)) {\n\t\tconst slotEnd = prev.slot ? prev.slot.end : prev.position.end\n\t\treturn value.slice(0, slotEnd) + value.slice(curr.position.start)\n\t}\n\treturn value.slice(0, prev.position.end) + value.slice(curr.position.start)\n}\n\n/**\n * Reorders rows by moving the row at `sourceIndex` to `targetIndex`.\n * Gaps between adjacent rows are extracted from the original value and preserved.\n */\nexport function reorderDragRows(value: string, rows: Token[], sourceIndex: number, targetIndex: number): string {\n\tif (sourceIndex === targetIndex || sourceIndex === targetIndex - 1) return value\n\tif (rows.length < 2) return value\n\tif (sourceIndex < 0 || sourceIndex >= rows.length) return value\n\tif (targetIndex < 0 || targetIndex > rows.length) return value\n\n\tconst texts = rows.map(row => value.substring(row.position.start, row.position.end))\n\tconst gaps = rows.slice(0, -1).map((row, i) => gapText(value, row, rows[i + 1]))\n\n\tconst [movedText] = texts.splice(sourceIndex, 1)\n\t// Remove the gap associated with the source position\n\tconst gapIndex = sourceIndex < gaps.length ? sourceIndex : sourceIndex - 1\n\tgaps.splice(gapIndex, 1)\n\n\tconst insertAt = targetIndex > sourceIndex ? targetIndex - 1 : targetIndex\n\ttexts.splice(insertAt, 0, movedText)\n\t// Insert a gap for the new position (use '' — marks are self-delimiting)\n\tif (insertAt < texts.length - 1) {\n\t\tgaps.splice(insertAt, 0, '')\n\t}\n\n\tconst parts: string[] = []\n\tfor (let i = 0; i < texts.length; i++) {\n\t\tparts.push(texts[i])\n\t\tif (i < gaps.length) {\n\t\t\tparts.push(gaps[i])\n\t\t}\n\t}\n\n\treturn parts.join('')\n}","export function createNewSpan(span: string, annotation: string, index: number, source: string) {\n\treturn span.slice(0, index) + annotation + span.slice(index + source.length)\n}","import type {CoreOption} from '../../shared/types'\nimport {annotate} from '../parsing'\n\nexport function createRowContent(options: CoreOption[]): string {\n\tconst firstOption = options[0]\n\tif (!firstOption.markup) return '\\n'\n\treturn annotate(firstOption.markup, {value: '', slot: '', meta: ''})\n}","import {childAt} from '../../../shared/checkers'\nimport type {Store} from '../../../store'\nimport {toString} from '../../parsing'\n\nexport function deleteMark(place: 'prev' | 'self' | 'next', store: Store) {\n\tconst placeMap = {\n\t\tprev: 2,\n\t\tself: 1,\n\t\tnext: 0,\n\t}\n\tconst placeIndex = placeMap[place]\n\tconst {focus} = store.nodes\n\tconst targetIndex = Math.max(0, focus.index - placeIndex)\n\n\tconst tokens = store.state.tokens()\n\tconst spliced = tokens.splice(focus.index - placeIndex, 3)\n\tconst span1 = spliced.at(0)\n\tconst span2 = spliced.at(2)\n\tconst content1 = span1?.content ?? ''\n\tconst content2 = span2?.content ?? ''\n\tstore.state.tokens(\n\t\ttokens.toSpliced(focus.index - placeIndex, 0, {\n\t\t\ttype: 'text',\n\t\t\tcontent: content1 + content2,\n\t\t\tposition: {\n\t\t\t\tstart: span1?.position.start ?? 0,\n\t\t\t\tend: span2?.position.end ?? (content1 + content2).length,\n\t\t\t},\n\t\t})\n\t)\n\n\tlet caretAnchor = focus\n\tfor (let i = 0; i < placeIndex; i++) {\n\t\tcaretAnchor = caretAnchor.prev\n\t}\n\tconst caret = caretAnchor.length\n\n\tstore.state.recovery({anchor: caretAnchor.prev, caret})\n\n\tstore.state.onChange()?.(toString(store.state.tokens()))\n\n\tqueueMicrotask(() => {\n\t\tconst target = childAt(store.refs.container, targetIndex)\n\t\tif (!target) return\n\t\tstore.nodes.focus.target = target\n\t\ttarget.focus()\n\t\tstore.nodes.focus.caret = caret\n\t})\n}","export function isTextTokenSpan(el: HTMLElement): boolean {\n\treturn (\n\t\tel.tagName === 'SPAN' &&\n\t\t(el.attributes.length === 0 || (el.attributes.length === 1 && el.hasAttribute('contenteditable')))\n\t)\n}","import {childAt} from '../../shared/checkers'\nimport {effectScope, effect, watch} from '../../shared/signals/index.js'\nimport type {Store} from '../../store/Store'\nimport type {Token} from '../parsing'\nimport {isTextTokenSpan} from './isTextTokenSpan'\n\nexport class ContentEditableFeature {\n\t#scope?: () => void\n\n\tconstructor(private store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\n\t\tthis.#scope = effectScope(() => {\n\t\t\teffect(() => {\n\t\t\t\tthis.store.state.readOnly()\n\t\t\t\tthis.sync()\n\t\t\t})\n\t\t\teffect(() => {\n\t\t\t\tif (this.store.state.selecting() === undefined) this.sync()\n\t\t\t})\n\t\t\twatch(this.store.event.sync, () => {\n\t\t\t\tthis.sync()\n\t\t\t})\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t}\n\n\tsync() {\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tconst readOnly = this.store.state.readOnly()\n\t\tconst value = readOnly ? 'false' : 'true'\n\t\tconst children = container.children\n\t\tconst isDrag = !!this.store.state.drag()\n\n\t\tif (isDrag) {\n\t\t\t// In drag mode, only set contentEditable on text rows (DragMark divs).\n\t\t\t// Mark rows get tabIndex for focusability but are not contentEditable.\n\t\t\tconst tokens = this.store.state.tokens()\n\t\t\tfor (let i = 0; i < tokens.length && i < children.length; i++) {\n\t\t\t\tconst el = childAt(container, i)\n\t\t\t\tif (!el) continue\n\t\t\t\tif (tokens[i].type === 'mark') {\n\t\t\t\t\tif (!readOnly) el.tabIndex = 0\n\t\t\t\t} else {\n\t\t\t\t\tel.contentEditable = value\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// In non-drag mode, even-indexed children are text spans (odd are marks).\n\t\t\tfor (let i = 0; i < children.length; i += 2) {\n\t\t\t\tconst el = childAt(container, i)\n\t\t\t\tif (el) el.contentEditable = value\n\t\t\t}\n\t\t}\n\n\t\t// Sync textContent for all text spans (including nested)\n\t\tconst tokens = this.store.state.tokens()\n\t\tif (isDrag) {\n\t\t\tthis.#syncDragTextContent(tokens, container, readOnly)\n\t\t} else {\n\t\t\tthis.#syncTextContent(tokens, container)\n\t\t}\n\t}\n\n\t#syncTextContent(tokens: Token[], parent: HTMLElement) {\n\t\tfor (let i = 0; i < tokens.length; i++) {\n\t\t\tconst token = tokens[i]\n\t\t\tconst el = childAt(parent, i)\n\t\t\tif (!el) continue\n\t\t\tif (token.type === 'text') {\n\t\t\t\tif (el.textContent !== token.content) {\n\t\t\t\t\tel.textContent = token.content\n\t\t\t\t}\n\t\t\t} else if (token.children.length > 0) {\n\t\t\t\tthis.#syncMarkChildren(token.children, el)\n\t\t\t}\n\t\t}\n\t}\n\n\t#syncMarkChildren(tokens: Token[], parent: HTMLElement, editable?: string) {\n\t\t// Walk direct children and match to tokens sequentially.\n\t\t// Text tokens render as <span> (no attributes, or only contenteditable).\n\t\t// Mark tokens render as elements with attributes (classes, data-*, etc).\n\t\t// Skip any extra mark-component elements (inputs, buttons, etc.)\n\t\tconst children = parent.children\n\t\tlet childIdx = 0\n\n\t\tfor (const token of tokens) {\n\t\t\tif (token.type === 'text') {\n\t\t\t\t// Find next text-token span (bare or with only contenteditable)\n\t\t\t\twhile (childIdx < children.length) {\n\t\t\t\t\tconst el = childAt(parent, childIdx)\n\t\t\t\t\tif (el && isTextTokenSpan(el)) break\n\t\t\t\t\tchildIdx++\n\t\t\t\t}\n\t\t\t\tconst el = childAt(parent, childIdx)\n\t\t\t\tif (el) {\n\t\t\t\t\tif (el.textContent !== token.content) {\n\t\t\t\t\t\tel.textContent = token.content\n\t\t\t\t\t}\n\t\t\t\t\tif (editable !== undefined) el.contentEditable = editable\n\t\t\t\t\tchildIdx++\n\t\t\t\t}\n\t\t\t} else if (token.children.length > 0) {\n\t\t\t\t// Find next element with attributes (mark element)\n\t\t\t\twhile (childIdx < children.length) {\n\t\t\t\t\tconst el = childAt(parent, childIdx)\n\t\t\t\t\tif (el && !isTextTokenSpan(el)) break\n\t\t\t\t\tchildIdx++\n\t\t\t\t}\n\t\t\t\tconst el = childAt(parent, childIdx)\n\t\t\t\tif (el) {\n\t\t\t\t\tthis.#syncMarkChildren(token.children, el, editable)\n\t\t\t\t\tchildIdx++\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t#syncDragTextContent(tokens: Token[], container: HTMLElement, readOnly: boolean) {\n\t\tconst editable = readOnly ? 'false' : 'true'\n\t\tfor (let ri = 0; ri < tokens.length; ri++) {\n\t\t\tconst token = tokens[ri]\n\t\t\tconst blockEl = childAt(container, ri)\n\t\t\tif (!blockEl) continue\n\n\t\t\tif (token.type === 'mark') {\n\t\t\t\tif (token.children.length > 0) {\n\t\t\t\t\t// In Vue, mark rows are wrapped in DragMark (has data-testid).\n\t\t\t\t\t// In React, mark rows render directly as the mark element.\n\t\t\t\t\tconst hasDragWrapper = blockEl.hasAttribute('data-testid')\n\t\t\t\t\tconst markEl = hasDragWrapper ? childAt(blockEl, readOnly ? 0 : 1) : blockEl\n\t\t\t\t\tif (markEl) {\n\t\t\t\t\t\tthis.#syncMarkChildren(token.children, markEl, editable)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// Text row: DragMark div with side panel offset\n\t\t\tconst offset = readOnly ? 0 : 1\n\t\t\tconst el = childAt(blockEl, offset)\n\t\t\tif (!el) continue\n\t\t\tif (el.textContent !== token.content) {\n\t\t\t\tel.textContent = token.content\n\t\t\t}\n\t\t}\n\t}\n}","import {isHtmlElement, isTextNode, nextText} from '../../shared/checkers'\nimport {Caret} from '../caret'\nimport {isTextTokenSpan} from '../editable'\nimport type {MarkToken, Token} from '../parsing'\n\nexport function getCaretRawPosInBlock(blockDiv: HTMLElement, token: Token): number {\n\tconst selection = window.getSelection()\n\tif (!selection?.rangeCount) return token.position.end\n\n\tconst {focusNode, focusOffset} = selection\n\tif (!focusNode) return token.position.end\n\n\treturn getDomRawPos(focusNode, focusOffset, blockDiv, token)\n}\n\nexport function setCaretAtRawPos(blockDiv: HTMLElement, token: Token, rawAbsolutePos: number): void {\n\tconst sel = window.getSelection()\n\tif (!sel) return\n\n\tif (token.type === 'mark') {\n\t\tif (setCaretInMarkAtRawPos(blockDiv, token, rawAbsolutePos)) return\n\t\tCaret.setCaretToEnd(blockDiv)\n\t\treturn\n\t}\n\n\tconst offsetWithinToken = rawAbsolutePos - token.position.start\n\tconst walker = document.createTreeWalker(blockDiv, 4)\n\tconst textNode = nextText(walker)\n\tif (textNode) {\n\t\tconst charOffset = Math.min(offsetWithinToken, textNode.length)\n\t\tconst range = document.createRange()\n\t\trange.setStart(textNode, charOffset)\n\t\trange.collapse(true)\n\t\tsel.removeAllRanges()\n\t\tsel.addRange(range)\n\t\treturn\n\t}\n\n\tCaret.setCaretToEnd(blockDiv)\n}\n\nexport function getDomRawPos(node: Node, offset: number, blockDiv: HTMLElement, token: Token): number {\n\tif (node === blockDiv) {\n\t\tconst sel = window.getSelection()\n\t\tif (sel?.focusNode && sel.focusNode !== blockDiv) {\n\t\t\treturn getDomRawPos(sel.focusNode, sel.focusOffset, blockDiv, token)\n\t\t}\n\t\treturn token.position.end\n\t}\n\n\tif (node.nodeType === Node.TEXT_NODE && node.parentElement === blockDiv) {\n\t\tif (token.type === 'mark') {\n\t\t\treturn getDomRawPosInMark(node, offset, blockDiv, token)\n\t\t}\n\t\treturn token.position.start + Math.min(offset, token.content.length)\n\t}\n\n\tlet child: Node | null = node.nodeType === Node.ELEMENT_NODE ? node : node.parentElement\n\twhile (child && child.parentElement !== blockDiv) {\n\t\tchild = child.parentElement\n\t}\n\tif (!child) return token.position.end\n\n\tif (token.type === 'mark') {\n\t\treturn getDomRawPosInMark(node, offset, blockDiv, token)\n\t}\n\n\treturn token.position.start + Math.min(offset, token.content.length)\n}\n\nexport function getDomRawPosInMark(node: Node, offset: number, markElement: HTMLElement, markToken: MarkToken): number {\n\tif (markToken.children.length === 0) {\n\t\tif (offset === 0) return markToken.position.start\n\t\tconst nestedLen = markToken.slot?.content.length ?? markToken.value.length\n\t\tif (nestedLen > 0 && offset >= nestedLen) {\n\t\t\tif (markToken.content.endsWith('\\n\\n') && markToken.slot) {\n\t\t\t\treturn markToken.slot.end\n\t\t\t}\n\t\t\treturn markToken.position.end\n\t\t}\n\t\treturn (markToken.slot?.start ?? markToken.position.start) + Math.min(offset, nestedLen)\n\t}\n\n\tlet tokenIdx = 0\n\tfor (const childNode of Array.from(markElement.childNodes)) {\n\t\tif (tokenIdx >= markToken.children.length) break\n\t\tconst tokenChild = markToken.children[tokenIdx]\n\n\t\tif (isHtmlElement(childNode) && tokenChild.type === 'text') {\n\t\t\tif (!isTextTokenSpan(childNode)) continue\n\t\t\tif (node === childNode) {\n\t\t\t\tconst charOffset = offset === 0 ? 0 : tokenChild.content.length\n\t\t\t\treturn tokenChild.position.start + Math.min(charOffset, tokenChild.content.length)\n\t\t\t}\n\t\t\tif (childNode.contains(node)) {\n\t\t\t\treturn tokenChild.position.start + Math.min(offset, tokenChild.content.length)\n\t\t\t}\n\t\t\ttokenIdx++\n\t\t} else if (isTextNode(childNode) && tokenChild.type === 'text') {\n\t\t\tif (node === childNode) {\n\t\t\t\treturn tokenChild.position.start + Math.min(offset, tokenChild.content.length)\n\t\t\t}\n\t\t\ttokenIdx++\n\t\t} else if (isHtmlElement(childNode) && tokenChild.type === 'mark') {\n\t\t\tif (childNode === node || childNode.contains(node)) {\n\t\t\t\treturn getDomRawPosInMark(node, offset, childNode, tokenChild)\n\t\t\t}\n\t\t\ttokenIdx++\n\t\t}\n\t}\n\n\treturn markToken.slot?.end ?? markToken.position.end\n}\n\nfunction setCaretInMarkAtRawPos(markElement: HTMLElement, markToken: MarkToken, rawAbsolutePos: number): boolean {\n\tconst sel = window.getSelection()\n\tif (!sel) return false\n\n\tlet tokenIdx = 0\n\tfor (const childNode of Array.from(markElement.childNodes)) {\n\t\tif (tokenIdx >= markToken.children.length) break\n\t\tconst tokenChild = markToken.children[tokenIdx]\n\n\t\tif (isHtmlElement(childNode) && tokenChild.type === 'text') {\n\t\t\tif (!isTextTokenSpan(childNode)) continue\n\t\t\tif (rawAbsolutePos >= tokenChild.position.start && rawAbsolutePos <= tokenChild.position.end) {\n\t\t\t\tconst rawTextNode = childNode.firstChild\n\t\t\t\tconst textNode = isTextNode(rawTextNode) ? rawTextNode : null\n\t\t\t\tconst offset = rawAbsolutePos - tokenChild.position.start\n\t\t\t\tif (textNode) {\n\t\t\t\t\tconst range = document.createRange()\n\t\t\t\t\trange.setStart(textNode, Math.min(offset, textNode.length))\n\t\t\t\t\trange.collapse(true)\n\t\t\t\t\tsel.removeAllRanges()\n\t\t\t\t\tsel.addRange(range)\n\t\t\t\t} else {\n\t\t\t\t\tconst range = document.createRange()\n\t\t\t\t\trange.setStart(childNode, 0)\n\t\t\t\t\trange.collapse(true)\n\t\t\t\t\tsel.removeAllRanges()\n\t\t\t\t\tsel.addRange(range)\n\t\t\t\t}\n\t\t\t\treturn true\n\t\t\t}\n\t\t\ttokenIdx++\n\t\t} else if (isTextNode(childNode) && tokenChild.type === 'text') {\n\t\t\tif (rawAbsolutePos >= tokenChild.position.start && rawAbsolutePos <= tokenChild.position.end) {\n\t\t\t\tconst offset = Math.min(rawAbsolutePos - tokenChild.position.start, childNode.length)\n\t\t\t\tconst range = document.createRange()\n\t\t\t\trange.setStart(childNode, offset)\n\t\t\t\trange.collapse(true)\n\t\t\t\tsel.removeAllRanges()\n\t\t\t\tsel.addRange(range)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\ttokenIdx++\n\t\t} else if (isHtmlElement(childNode) && tokenChild.type === 'mark') {\n\t\t\tconst nextChild = tokenIdx + 1 < markToken.children.length ? markToken.children[tokenIdx + 1] : null\n\t\t\tconst atBoundary =\n\t\t\t\trawAbsolutePos === tokenChild.position.end && nextChild?.position.start === rawAbsolutePos\n\t\t\tif (\n\t\t\t\t!atBoundary &&\n\t\t\t\trawAbsolutePos >= tokenChild.position.start &&\n\t\t\t\trawAbsolutePos <= tokenChild.position.end\n\t\t\t) {\n\t\t\t\treturn setCaretInMarkAtRawPos(childNode, tokenChild, rawAbsolutePos)\n\t\t\t}\n\t\t\ttokenIdx++\n\t\t}\n\t}\n\n\treturn false\n}","import {childAt, htmlChildren, isHtmlElement} from '../../shared/checkers'\nimport {KEYBOARD} from '../../shared/constants'\nimport type {Store} from '../../store/Store'\nimport {Caret} from '../caret'\nimport {consumeMarkupPaste} from '../clipboard'\nimport {addDragRow, getMergeDragRowJoinPos, mergeDragRows, canMergeRows} from '../drag/operations'\nimport {createRowContent} from '../editing'\nimport type {Token} from '../parsing'\nimport {getCaretRawPosInBlock, getDomRawPos, setCaretAtRawPos} from './rawPosition'\n\nfunction isTextLikeRow(token: Token): boolean {\n\tif (token.type === 'text') return true\n\treturn token.descriptor.hasSlot && token.descriptor.segments.length === 1\n}\n\nexport class BlockEditFeature {\n\t#keydownHandler?: (e: KeyboardEvent) => void\n\t#beforeInputHandler?: (e: InputEvent) => void\n\n\tconstructor(private store: Store) {}\n\n\tenable() {\n\t\tif (this.#keydownHandler) return\n\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tthis.#keydownHandler = e => {\n\t\t\tif (!this.store.state.drag()) return\n\n\t\t\tif (e.key === KEYBOARD.LEFT || e.key === KEYBOARD.RIGHT) {\n\t\t\t\tthis.#handleBlockArrowLeftRight(e, e.key === KEYBOARD.LEFT ? 'left' : 'right')\n\t\t\t} else if (e.key === KEYBOARD.UP || e.key === KEYBOARD.DOWN) {\n\t\t\t\tthis.#handleArrowUpDown(e)\n\t\t\t}\n\n\t\t\tthis.#handleDelete(e)\n\t\t\tthis.#handleEnter(e)\n\t\t}\n\n\t\tthis.#beforeInputHandler = e => {\n\t\t\tif (!this.store.state.drag()) return\n\t\t\tif (e.defaultPrevented) return\n\t\t\tthis.#handleBlockBeforeInput(e)\n\t\t}\n\n\t\tcontainer.addEventListener('keydown', this.#keydownHandler)\n\t\tcontainer.addEventListener('beforeinput', this.#beforeInputHandler, true)\n\t}\n\n\tdisable() {\n\t\tconst container = this.store.refs.container\n\t\tif (!container || !this.#keydownHandler) return\n\n\t\tcontainer.removeEventListener('keydown', this.#keydownHandler)\n\t\tif (this.#beforeInputHandler) container.removeEventListener('beforeinput', this.#beforeInputHandler, true)\n\n\t\tthis.#keydownHandler = undefined\n\t\tthis.#beforeInputHandler = undefined\n\t}\n\n\t#handleDelete(event: KeyboardEvent) {\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tconst blockDivs = htmlChildren(container)\n\t\tconst blockIndex = blockDivs.findIndex(\n\t\t\tdiv => div === document.activeElement || div.contains(document.activeElement)\n\t\t)\n\t\tif (blockIndex === -1) return\n\n\t\tconst rows = this.store.state.tokens()\n\t\tif (blockIndex >= rows.length) return\n\n\t\tconst token = rows[blockIndex]\n\t\tconst value = this.store.state.previousValue() ?? this.store.state.value() ?? ''\n\t\tif (!this.store.state.onChange()) return\n\n\t\tif (event.key === KEYBOARD.BACKSPACE) {\n\t\t\tconst blockDiv = blockDivs[blockIndex]\n\t\t\tconst caretAtStart = Caret.getCaretIndex(blockDiv) === 0\n\n\t\t\tconst blockText = 'content' in token ? token.content : ''\n\t\t\tif (blockText === '') {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tconst newValue =\n\t\t\t\t\trows.length <= 1\n\t\t\t\t\t\t? ''\n\t\t\t\t\t\t: (() => {\n\t\t\t\t\t\t\t\tif (blockIndex >= rows.length - 1)\n\t\t\t\t\t\t\t\t\treturn value.slice(0, rows[blockIndex - 1].position.end)\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\tvalue.slice(0, rows[blockIndex].position.start) +\n\t\t\t\t\t\t\t\t\tvalue.slice(rows[blockIndex + 1].position.start)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t})()\n\t\t\t\tthis.store.state.innerValue(newValue)\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\tconst targetIndex = Math.max(0, blockIndex - 1)\n\t\t\t\t\tconst target = childAt(container, targetIndex)\n\t\t\t\t\tif (target) {\n\t\t\t\t\t\ttarget.focus()\n\t\t\t\t\t\tCaret.setCaretToEnd(target)\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (caretAtStart && blockIndex > 0) {\n\t\t\t\tconst prevToken = rows[blockIndex - 1]\n\t\t\t\tconst currToken = rows[blockIndex]\n\t\t\t\tif (canMergeRows(prevToken, currToken)) {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tconst joinPos = getMergeDragRowJoinPos(rows, blockIndex)\n\t\t\t\t\tconst newValue = mergeDragRows(value, rows, blockIndex)\n\t\t\t\t\tthis.store.state.innerValue(newValue)\n\t\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\t\tconst target = childAt(container, blockIndex - 1)\n\t\t\t\t\t\tif (target) {\n\t\t\t\t\t\t\ttarget.focus()\n\t\t\t\t\t\t\tconst updatedRows = this.store.state.tokens()\n\t\t\t\t\t\t\tconst updatedToken = updatedRows[blockIndex - 1]\n\t\t\t\t\t\t\tsetCaretAtRawPos(target, updatedToken, joinPos)\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tevent.preventDefault()\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\tconst target = blockDivs[blockIndex - 1]\n\t\t\t\t\ttarget.focus()\n\t\t\t\t\tif (prevToken.type !== 'mark') Caret.setCaretToEnd(target)\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tif (event.key === KEYBOARD.DELETE) {\n\t\t\tconst blockDiv = blockDivs[blockIndex]\n\t\t\tconst caretIndex = Caret.getCaretIndex(blockDiv)\n\t\t\tconst caretAtEnd = caretIndex === blockDiv.textContent.length\n\t\t\tconst caretAtStart = caretIndex === 0\n\n\t\t\tif (caretAtStart && blockIndex > 0) {\n\t\t\t\tconst prevToken = rows[blockIndex - 1]\n\t\t\t\tconst currToken = rows[blockIndex]\n\t\t\t\tif (canMergeRows(prevToken, currToken)) {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tconst joinPos = getMergeDragRowJoinPos(rows, blockIndex)\n\t\t\t\t\tconst newValue = mergeDragRows(value, rows, blockIndex)\n\t\t\t\t\tthis.store.state.innerValue(newValue)\n\t\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\t\tconst target = childAt(container, blockIndex - 1)\n\t\t\t\t\t\tif (target) {\n\t\t\t\t\t\t\ttarget.focus()\n\t\t\t\t\t\t\tconst updatedRows = this.store.state.tokens()\n\t\t\t\t\t\t\tconst updatedToken = updatedRows[blockIndex - 1]\n\t\t\t\t\t\t\tsetCaretAtRawPos(target, updatedToken, joinPos)\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tevent.preventDefault()\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\tconst target = blockDivs[blockIndex - 1]\n\t\t\t\t\ttarget.focus()\n\t\t\t\t\tif (prevToken.type !== 'mark') Caret.setCaretToEnd(target)\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (caretAtEnd && blockIndex < rows.length - 1) {\n\t\t\t\tconst currToken = rows[blockIndex]\n\t\t\t\tconst nextToken = rows[blockIndex + 1]\n\t\t\t\tif (canMergeRows(currToken, nextToken)) {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tconst joinPos = getMergeDragRowJoinPos(rows, blockIndex + 1)\n\t\t\t\t\tconst newValue = mergeDragRows(value, rows, blockIndex + 1)\n\t\t\t\t\tthis.store.state.innerValue(newValue)\n\t\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\t\tconst target = childAt(container, blockIndex)\n\t\t\t\t\t\tif (target) {\n\t\t\t\t\t\t\ttarget.focus()\n\t\t\t\t\t\t\tconst updatedRows = this.store.state.tokens()\n\t\t\t\t\t\t\tconst updatedToken = updatedRows[blockIndex]\n\t\t\t\t\t\t\tsetCaretAtRawPos(target, updatedToken, joinPos)\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tevent.preventDefault()\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\tconst target = blockDivs[blockIndex + 1]\n\t\t\t\t\ttarget.focus()\n\t\t\t\t\tCaret.trySetIndex(target, 0)\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\t#handleEnter(event: KeyboardEvent) {\n\t\tif (event.key !== KEYBOARD.ENTER) return\n\t\tif (event.shiftKey) return\n\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tconst activeElement = document.activeElement\n\t\tif (!isHtmlElement(activeElement) || !container.contains(activeElement)) return\n\n\t\tevent.preventDefault()\n\n\t\tconst blockDivs = htmlChildren(container)\n\t\tlet blockIndex = -1\n\t\tfor (let i = 0; i < blockDivs.length; i++) {\n\t\t\tif (blockDivs[i] === activeElement || blockDivs[i].contains(activeElement)) {\n\t\t\t\tblockIndex = i\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif (blockIndex === -1) return\n\n\t\tconst rows = this.store.state.tokens()\n\t\tconst token = rows[blockIndex]\n\t\tconst blockDiv = blockDivs[blockIndex]\n\t\tconst value = this.store.state.previousValue() ?? this.store.state.value() ?? ''\n\n\t\tif (!this.store.state.onChange()) return\n\n\t\tconst newRowContent = createRowContent(this.store.state.options())\n\n\t\tif (!isTextLikeRow(token)) {\n\t\t\tconst newValue = addDragRow(value, rows, blockIndex, newRowContent)\n\t\t\tthis.store.state.innerValue(newValue)\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tconst newBlockIndex = blockIndex + 1\n\t\t\t\tif (newBlockIndex < container.children.length) {\n\t\t\t\t\tconst newBlockEl = childAt(container, newBlockIndex)\n\t\t\t\t\tif (newBlockEl) {\n\t\t\t\t\t\tnewBlockEl.focus()\n\t\t\t\t\t\tCaret.trySetIndex(newBlockEl, 0)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t\treturn\n\t\t}\n\n\t\tconst absolutePos = getCaretRawPosInBlock(blockDiv, token)\n\t\tconst newValue = value.slice(0, absolutePos) + newRowContent + value.slice(absolutePos)\n\t\tthis.store.state.innerValue(newValue)\n\n\t\tqueueMicrotask(() => {\n\t\t\tconst newBlockIndex = blockIndex + 1\n\t\t\tif (newBlockIndex < container.children.length) {\n\t\t\t\tconst newBlockEl = childAt(container, newBlockIndex)\n\t\t\t\tif (newBlockEl) {\n\t\t\t\t\tnewBlockEl.focus()\n\t\t\t\t\tCaret.trySetIndex(newBlockEl, 0)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\t#handleBlockArrowLeftRight(event: KeyboardEvent, direction: 'left' | 'right'): boolean {\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return false\n\n\t\tconst activeElement = document.activeElement\n\t\tif (!isHtmlElement(activeElement) || !container.contains(activeElement)) return false\n\n\t\tconst blockDivs = htmlChildren(container)\n\t\tconst blockIndex = blockDivs.findIndex(div => div === activeElement || div.contains(activeElement))\n\t\tif (blockIndex === -1) return false\n\n\t\tconst blockDiv = blockDivs[blockIndex]\n\n\t\tif (direction === 'left') {\n\t\t\tif (Caret.getCaretIndex(blockDiv) !== 0) return false\n\t\t\tif (blockIndex === 0) return true\n\t\t\tevent.preventDefault()\n\t\t\tconst prevBlock = blockDivs[blockIndex - 1]\n\t\t\tprevBlock.focus()\n\t\t\tCaret.setCaretToEnd(prevBlock)\n\t\t\treturn true\n\t\t}\n\n\t\tconst caretIndex = Caret.getCaretIndex(blockDiv)\n\t\tconst textLen = blockDiv.textContent.length\n\t\tif (caretIndex !== textLen) return false\n\t\tif (blockIndex >= blockDivs.length - 1) return true\n\t\tevent.preventDefault()\n\t\tconst nextBlock = blockDivs[blockIndex + 1]\n\t\tnextBlock.focus()\n\t\tCaret.trySetIndex(nextBlock, 0)\n\t\treturn true\n\t}\n\n\t#handleArrowUpDown(event: KeyboardEvent) {\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tconst activeElement = document.activeElement\n\t\tif (!isHtmlElement(activeElement) || !container.contains(activeElement)) return\n\n\t\tconst blockDivs = htmlChildren(container)\n\t\tconst blockIndex = blockDivs.findIndex(div => div === activeElement || div.contains(activeElement))\n\t\tif (blockIndex === -1) return\n\n\t\tconst blockDiv = blockDivs[blockIndex]\n\n\t\tif (event.key === KEYBOARD.UP) {\n\t\t\tif (!Caret.isCaretOnFirstLine(blockDiv)) return\n\t\t\tif (blockIndex === 0) return\n\n\t\t\tevent.preventDefault()\n\t\t\tconst caretRect = Caret.getCaretRect()\n\t\t\tconst caretX = caretRect?.left ?? blockDiv.getBoundingClientRect().left\n\t\t\tconst prevBlockDiv = blockDivs[blockIndex - 1]\n\t\t\tprevBlockDiv.focus()\n\t\t\tconst prevRect = prevBlockDiv.getBoundingClientRect()\n\t\t\tCaret.setAtX(prevBlockDiv, caretX, prevRect.bottom - 4)\n\t\t} else if (event.key === KEYBOARD.DOWN) {\n\t\t\tif (!Caret.isCaretOnLastLine(blockDiv)) return\n\t\t\tif (blockIndex >= blockDivs.length - 1) return\n\n\t\t\tevent.preventDefault()\n\t\t\tconst caretRect = Caret.getCaretRect()\n\t\t\tconst caretX = caretRect?.left ?? blockDiv.getBoundingClientRect().left\n\t\t\tconst nextBlockDiv = blockDivs[blockIndex + 1]\n\t\t\tnextBlockDiv.focus()\n\t\t\tconst nextRect = nextBlockDiv.getBoundingClientRect()\n\t\t\tCaret.setAtX(nextBlockDiv, caretX, nextRect.top + 4)\n\t\t}\n\t}\n\n\t#handleBlockBeforeInput(event: InputEvent) {\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tconst activeElement = document.activeElement\n\t\tif (!isHtmlElement(activeElement) || !container.contains(activeElement)) return\n\n\t\tconst blockDivs = htmlChildren(container)\n\t\tconst blockIndex = blockDivs.findIndex(div => div === activeElement || div.contains(activeElement))\n\t\tif (blockIndex === -1) return\n\n\t\tconst blockDiv = blockDivs[blockIndex]\n\t\tconst rows = this.store.state.tokens()\n\t\tif (blockIndex >= rows.length) return\n\n\t\tconst token = rows[blockIndex]\n\t\tconst value = this.store.state.previousValue() ?? this.store.state.value() ?? ''\n\n\t\tconst focusAndSetCaret = (newRawPos: number) => {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tconst target = childAt(container, blockIndex)\n\t\t\t\tif (!target) return\n\t\t\t\ttarget.focus()\n\t\t\t\tconst updatedRows = this.store.state.tokens()\n\t\t\t\tconst updatedToken = updatedRows[blockIndex]\n\t\t\t\tsetCaretAtRawPos(target, updatedToken, newRawPos)\n\t\t\t})\n\t\t}\n\n\t\tswitch (event.inputType) {\n\t\t\tcase 'insertText': {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tconst data = event.data ?? ''\n\t\t\t\tconst ranges = event.getTargetRanges()\n\t\t\t\tlet rawFrom: number\n\t\t\t\tlet rawTo: number\n\t\t\t\tif (ranges.length > 0) {\n\t\t\t\t\tconst rawStart = getDomRawPos(ranges[0].startContainer, ranges[0].startOffset, blockDiv, token)\n\t\t\t\t\tconst rawEnd = getDomRawPos(ranges[0].endContainer, ranges[0].endOffset, blockDiv, token)\n\t\t\t\t\t;[rawFrom, rawTo] = rawStart <= rawEnd ? [rawStart, rawEnd] : [rawEnd, rawStart]\n\t\t\t\t} else {\n\t\t\t\t\trawFrom = rawTo = getCaretRawPosInBlock(blockDiv, token)\n\t\t\t\t}\n\t\t\t\tthis.store.state.innerValue(value.slice(0, rawFrom) + data + value.slice(rawTo))\n\t\t\t\tfocusAndSetCaret(rawFrom + data.length)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'insertFromPaste':\n\t\t\tcase 'insertReplacementText': {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tconst markup = this.store.refs.container ? consumeMarkupPaste(this.store.refs.container) : undefined\n\t\t\t\tconst pasteData = markup ?? event.dataTransfer?.getData('text/plain') ?? ''\n\t\t\t\tconst ranges = event.getTargetRanges()\n\t\t\t\tlet rawFrom: number\n\t\t\t\tlet rawTo: number\n\t\t\t\tif (ranges.length > 0) {\n\t\t\t\t\tconst rawStart = getDomRawPos(ranges[0].startContainer, ranges[0].startOffset, blockDiv, token)\n\t\t\t\t\tconst rawEnd = getDomRawPos(ranges[0].endContainer, ranges[0].endOffset, blockDiv, token)\n\t\t\t\t\t;[rawFrom, rawTo] = rawStart <= rawEnd ? [rawStart, rawEnd] : [rawEnd, rawStart]\n\t\t\t\t} else {\n\t\t\t\t\trawFrom = rawTo = getCaretRawPosInBlock(blockDiv, token)\n\t\t\t\t}\n\t\t\t\tthis.store.state.innerValue(value.slice(0, rawFrom) + pasteData + value.slice(rawTo))\n\t\t\t\tfocusAndSetCaret(rawFrom + pasteData.length)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'deleteContentBackward':\n\t\t\tcase 'deleteContentForward':\n\t\t\tcase 'deleteWordBackward':\n\t\t\tcase 'deleteWordForward':\n\t\t\tcase 'deleteSoftLineBackward':\n\t\t\tcase 'deleteSoftLineForward': {\n\t\t\t\tconst ranges = event.getTargetRanges()\n\t\t\t\tif (!ranges.length) return\n\t\t\t\tconst rawStart = getDomRawPos(ranges[0].startContainer, ranges[0].startOffset, blockDiv, token)\n\t\t\t\tconst rawEnd = getDomRawPos(ranges[0].endContainer, ranges[0].endOffset, blockDiv, token)\n\t\t\t\tconst [rawFrom, rawTo] = rawStart <= rawEnd ? [rawStart, rawEnd] : [rawEnd, rawStart]\n\t\t\t\tif (rawFrom === rawTo) return\n\t\t\t\tevent.preventDefault()\n\t\t\t\tthis.store.state.innerValue(value.slice(0, rawFrom) + value.slice(rawTo))\n\t\t\t\tfocusAndSetCaret(rawFrom)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n}","import type {Token} from '../parsing'\n\nexport const EMPTY_TEXT_TOKEN: Token = {type: 'text', content: '', position: {start: 0, end: 0}}","import {childAt} from '../../shared/checkers'\nimport {watch} from '../../shared/signals'\nimport type {Store} from '../../store/Store'\nimport {createRowContent} from '../editing'\nimport {addDragRow, deleteDragRow, duplicateDragRow, reorderDragRows} from './operations'\nimport {EMPTY_TEXT_TOKEN} from './tokens'\n\nexport class DragFeature {\n\tconstructor(private store: Store) {}\n\n\t#unsub?: () => void\n\n\tenable() {\n\t\tthis.#unsub = watch(this.store.event.dragAction, action => {\n\t\t\tswitch (action.type) {\n\t\t\t\tcase 'reorder':\n\t\t\t\t\tthis.#reorder(action.source, action.target)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'add':\n\t\t\t\t\tthis.#add(action.afterIndex)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'delete':\n\t\t\t\t\tthis.#delete(action.index)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'duplicate':\n\t\t\t\t\tthis.#duplicate(action.index)\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#unsub?.()\n\t\tthis.#unsub = undefined\n\t}\n\n\t#reorder(sourceIndex: number, targetIndex: number) {\n\t\tconst value = this.store.state.value()\n\t\tif (value == null || !this.store.state.onChange()) return\n\t\tconst rows = this.store.state.tokens()\n\t\tconst newValue = reorderDragRows(value, rows, sourceIndex, targetIndex)\n\t\tif (newValue !== value) this.store.state.innerValue(newValue)\n\t}\n\n\t#add(afterIndex: number) {\n\t\tconst value = this.store.state.value()\n\t\tif (value == null || !this.store.state.onChange()) return\n\t\tconst rawRows = this.store.state.tokens()\n\t\tconst rows = rawRows.length > 0 ? rawRows : [EMPTY_TEXT_TOKEN]\n\t\tconst newRowContent = createRowContent(this.store.state.options())\n\t\tthis.store.state.innerValue(addDragRow(value, rows, afterIndex, newRowContent))\n\t\tqueueMicrotask(() => {\n\t\t\tconst container = this.store.refs.container\n\t\t\tif (!container) return\n\t\t\tconst target = childAt(container, afterIndex + 1)\n\t\t\ttarget?.focus()\n\t\t})\n\t}\n\n\t#delete(index: number) {\n\t\tconst value = this.store.state.value()\n\t\tif (value == null || !this.store.state.onChange()) return\n\t\tconst rows = this.store.state.tokens()\n\t\tthis.store.state.innerValue(deleteDragRow(value, rows, index))\n\t}\n\n\t#duplicate(index: number) {\n\t\tconst value = this.store.state.value()\n\t\tif (value == null || !this.store.state.onChange()) return\n\t\tconst rows = this.store.state.tokens()\n\t\tthis.store.state.innerValue(duplicateDragRow(value, rows, index))\n\t}\n}","export function getDragDropPosition(clientY: number, rect: DOMRect): 'before' | 'after' {\n\treturn clientY < rect.top + rect.height / 2 ? 'before' : 'after'\n}\n\nexport function parseDragSourceIndex(dataTransfer: DataTransfer): number | null {\n\tconst index = parseInt(dataTransfer.getData('text/plain'), 10)\n\treturn isNaN(index) ? null : index\n}\n\nexport function getDragTargetIndex(blockIndex: number, position: 'before' | 'after'): number {\n\treturn position === 'before' ? blockIndex : blockIndex + 1\n}","export function getAlwaysShowHandleDrag(drag: boolean | {alwaysShowHandle: boolean}): boolean {\n\treturn typeof drag === 'object' && !!drag.alwaysShowHandle\n}","import {batch, effectScope, watch} from '../../shared/signals/index.js'\nimport type {Store} from '../../store/Store'\nimport {createNewSpan} from '../editing'\nimport {annotate, findToken, parseWithParser, toString} from '../parsing'\n\nexport class SystemListenerFeature {\n\t#scope?: () => void\n\n\tconstructor(private store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\n\t\tthis.#scope = effectScope(() => {\n\t\t\twatch(this.store.event.change, () => {\n\t\t\t\tconst onChange = this.store.state.onChange()\n\t\t\t\tconst {focus} = this.store.nodes\n\n\t\t\t\t// Programmatic mark change or non-editable focus (e.g. a checkbox):\n\t\t\t\t// the token was already mutated in-place by MarkHandler — serialize it\n\t\t\t\t// directly and force a re-render without reading stale DOM content.\n\t\t\t\tif (!focus.target || !focus.target.isContentEditable) {\n\t\t\t\t\tconst tokens = this.store.state.tokens()\n\t\t\t\t\tconst serialized = toString(tokens)\n\t\t\t\t\tonChange?.(serialized)\n\t\t\t\t\tthis.store.state.previousValue(serialized)\n\t\t\t\t\tthis.store.state.tokens([...tokens])\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// User typed in a contentEditable element: sync DOM content → token state.\n\t\t\t\tconst tokens = this.store.state.tokens()\n\t\t\t\tconst token = tokens[focus.index]\n\t\t\t\tif (token.type === 'text') {\n\t\t\t\t\ttoken.content = focus.content\n\t\t\t\t} else {\n\t\t\t\t\ttoken.value = focus.content\n\t\t\t\t}\n\n\t\t\t\tonChange?.(toString(tokens))\n\t\t\t\tthis.store.event.parse()\n\t\t\t})\n\n\t\t\twatch(this.store.event.delete, payload => {\n\t\t\t\tconst {token} = payload\n\t\t\t\tconst tokens = this.store.state.tokens()\n\t\t\t\tif (!findToken(tokens, token)) return\n\n\t\t\t\tconst value = toString(tokens)\n\t\t\t\tconst nextValue = value.slice(0, token.position.start) + value.slice(token.position.end)\n\t\t\t\tthis.store.state.innerValue(nextValue)\n\t\t\t})\n\n\t\t\twatch(this.store.state.innerValue, newValue => {\n\t\t\t\tif (newValue === undefined) return\n\t\t\t\tconst newTokens = parseWithParser(this.store, newValue)\n\t\t\t\tbatch(() => {\n\t\t\t\t\tthis.store.state.tokens(newTokens)\n\t\t\t\t\tthis.store.state.previousValue(newValue)\n\t\t\t\t})\n\t\t\t\tthis.store.state.onChange()?.(newValue)\n\t\t\t})\n\n\t\t\twatch(this.store.event.select, event => {\n\t\t\t\tconst Mark = this.store.state.Mark()\n\t\t\t\tconst onChange = this.store.state.onChange()\n\t\t\t\tconst {\n\t\t\t\t\tmark,\n\t\t\t\t\tmatch: {option, span, index, source},\n\t\t\t\t} = event\n\n\t\t\t\tconst markup = option.markup\n\t\t\t\tif (!markup) return\n\n\t\t\t\tconst annotation =\n\t\t\t\t\tmark.type === 'mark'\n\t\t\t\t\t\t? annotate(markup, {\n\t\t\t\t\t\t\t\tvalue: mark.value,\n\t\t\t\t\t\t\t\tmeta: mark.meta,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: annotate(markup, {\n\t\t\t\t\t\t\t\tvalue: mark.content,\n\t\t\t\t\t\t\t})\n\n\t\t\t\tconst newSpan = createNewSpan(span, annotation, index, source)\n\n\t\t\t\tthis.store.state.recovery(\n\t\t\t\t\tMark\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tcaret: 0,\n\t\t\t\t\t\t\t\tanchor: this.store.nodes.input.next,\n\t\t\t\t\t\t\t\tisNext: true,\n\t\t\t\t\t\t\t\tchildIndex: this.store.nodes.input.index,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {caret: index + annotation.length, anchor: this.store.nodes.input}\n\t\t\t\t)\n\n\t\t\t\tif (this.store.nodes.input.target) {\n\t\t\t\t\tthis.store.nodes.input.content = newSpan\n\t\t\t\t\tconst tokens = this.store.state.tokens()\n\t\t\t\t\tconst inputToken = tokens[this.store.nodes.input.index]\n\t\t\t\t\tif (inputToken.type === 'text') {\n\t\t\t\t\t\tinputToken.content = newSpan\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.store.nodes.focus.target = this.store.nodes.input.target\n\t\t\t\t\tthis.store.nodes.input.clear()\n\t\t\t\t\tonChange?.(toString(tokens))\n\t\t\t\t\tthis.store.event.parse()\n\t\t\t\t}\n\t\t\t})\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t}\n}","import {childAt, firstHtmlChild, isHtmlElement} from '../../shared/checkers'\nimport {watch} from '../../shared/signals/index.js'\nimport type {Store} from '../../store/Store'\n\nexport class FocusFeature {\n\t#focusinHandler?: (e: FocusEvent) => void\n\t#focusoutHandler?: () => void\n\t#clickHandler?: () => void\n\n\tconstructor(private store: Store) {}\n\n\tenable() {\n\t\tif (this.#focusinHandler) return\n\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tthis.#focusinHandler = e => {\n\t\t\tconst target = isHtmlElement(e.target) ? e.target : undefined\n\t\t\tthis.store.nodes.focus.target = target\n\t\t}\n\n\t\tthis.#focusoutHandler = () => {\n\t\t\tthis.store.nodes.focus.target = undefined\n\t\t}\n\n\t\tthis.#clickHandler = () => {\n\t\t\tconst tokens = this.store.state.tokens()\n\t\t\tif (tokens.length === 1 && tokens[0].type === 'text' && tokens[0].content === '') {\n\t\t\t\tconst container = this.store.refs.container\n\t\t\t\tconst element = container ? firstHtmlChild(container) : null\n\t\t\t\telement?.focus()\n\t\t\t}\n\t\t}\n\n\t\tcontainer.addEventListener('focusin', this.#focusinHandler)\n\t\tcontainer.addEventListener('focusout', this.#focusoutHandler)\n\t\tcontainer.addEventListener('click', this.#clickHandler)\n\n\t\twatch(this.store.event.recoverFocus, () => {\n\t\t\tthis.#recover()\n\t\t})\n\n\t\twatch(this.store.event.afterTokensRendered, () => {\n\t\t\tthis.store.event.sync()\n\t\t\tif (!this.store.state.Mark()) return\n\t\t\tthis.store.event.recoverFocus()\n\t\t})\n\t}\n\n\tdisable() {\n\t\tconst container = this.store.refs.container\n\t\tif (!container || !this.#focusinHandler) return\n\n\t\tcontainer.removeEventListener('focusin', this.#focusinHandler)\n\t\tif (this.#focusoutHandler) container.removeEventListener('focusout', this.#focusoutHandler)\n\t\tif (this.#clickHandler) container.removeEventListener('click', this.#clickHandler)\n\n\t\tthis.#focusinHandler = undefined\n\t\tthis.#focusoutHandler = undefined\n\t\tthis.#clickHandler = undefined\n\t}\n\n\t#recover() {\n\t\tconst recovery = this.store.state.recovery()\n\t\tif (!recovery) return\n\n\t\tconst {anchor, caret, isNext} = recovery\n\t\tconst isStale = !anchor.target || !anchor.target.isConnected\n\t\tlet target: HTMLElement | undefined\n\n\t\t// eslint-disable-next-line switch-exhaustiveness-check\n\t\tswitch (true) {\n\t\t\tcase isNext && isStale: {\n\t\t\t\tconst container = this.store.refs.container\n\t\t\t\t// After re-parse, text at childIndex splits into [text, mark, text]\n\t\t\t\t// Focus the text span after the mark (childIndex + 2)\n\t\t\t\tconst targetChild =\n\t\t\t\t\trecovery.childIndex != null ? childAt(container, recovery.childIndex + 2) : undefined\n\t\t\t\ttarget = targetChild ?? this.store.nodes.focus.tail ?? undefined\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase isNext:\n\t\t\t\ttarget = anchor.prev.target\n\t\t\t\tbreak\n\t\t\tcase isStale:\n\t\t\t\ttarget = this.store.nodes.focus.head ?? undefined\n\t\t\t\tbreak\n\t\t\tdefault:\n\t\t\t\ttarget = anchor.next.target\n\t\t}\n\n\t\tthis.store.nodes.focus.target = target\n\t\ttarget?.focus()\n\t\tqueueMicrotask(() => {\n\t\t\tif (!target?.isConnected) return\n\t\t\tthis.store.nodes.focus.target = target\n\t\t\tthis.store.nodes.focus.caret = caret\n\t\t})\n\t\tthis.store.state.recovery(undefined)\n\t}\n}","import {isHtmlElement} from '../../shared/checkers'\nimport type {NodeProxy} from '../../shared/classes'\nimport {KEYBOARD} from '../../shared/constants'\nimport type {Store} from '../../store/Store'\nimport {captureMarkupPaste, consumeMarkupPaste, getBoundaryOffset} from '../clipboard'\nimport {deleteMark} from '../editing/utils/deleteMark'\nimport {isFullSelection} from '../selection'\n\nexport class InputFeature {\n\t#keydownHandler?: (e: KeyboardEvent) => void\n\t#pasteHandler?: (e: ClipboardEvent) => void\n\t#beforeInputHandler?: (e: InputEvent) => void\n\n\tconstructor(private store: Store) {}\n\n\tenable() {\n\t\tif (this.#keydownHandler) return\n\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tthis.#keydownHandler = e => {\n\t\t\tif (!this.store.state.drag()) {\n\t\t\t\tthis.#handleDelete(e)\n\t\t\t}\n\t\t}\n\n\t\tthis.#pasteHandler = e => {\n\t\t\tconst c = this.store.refs.container\n\t\t\tif (c) captureMarkupPaste(e, c)\n\t\t\thandlePaste(this.store, e)\n\t\t}\n\n\t\tthis.#beforeInputHandler = e => {\n\t\t\thandleBeforeInput(this.store, e)\n\t\t}\n\n\t\tcontainer.addEventListener('keydown', this.#keydownHandler)\n\t\tcontainer.addEventListener('paste', this.#pasteHandler)\n\t\tcontainer.addEventListener('beforeinput', this.#beforeInputHandler, true)\n\t}\n\n\tdisable() {\n\t\tconst container = this.store.refs.container\n\t\tif (!container || !this.#keydownHandler) return\n\n\t\tcontainer.removeEventListener('keydown', this.#keydownHandler)\n\t\tif (this.#pasteHandler) container.removeEventListener('paste', this.#pasteHandler)\n\t\tif (this.#beforeInputHandler) container.removeEventListener('beforeinput', this.#beforeInputHandler, true)\n\n\t\tthis.#keydownHandler = undefined\n\t\tthis.#pasteHandler = undefined\n\t\tthis.#beforeInputHandler = undefined\n\t}\n\n\t#handleDelete(event: KeyboardEvent) {\n\t\tconst {focus} = this.store.nodes\n\n\t\tif (event.key !== KEYBOARD.DELETE && event.key !== KEYBOARD.BACKSPACE) return\n\n\t\tif (focus.isMark) {\n\t\t\tif (focus.isEditable) {\n\t\t\t\tif (event.key === KEYBOARD.BACKSPACE && !focus.isCaretAtBeginning) return\n\t\t\t\tif (event.key === KEYBOARD.DELETE && !focus.isCaretAtEnd) return\n\t\t\t}\n\t\t\tevent.preventDefault()\n\t\t\tdeleteMark('self', this.store)\n\t\t\treturn\n\t\t}\n\n\t\tif (event.key === KEYBOARD.BACKSPACE) {\n\t\t\tif (focus.isSpan && focus.isCaretAtBeginning && focus.prev.target) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tdeleteMark('prev', this.store)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tif (event.key === KEYBOARD.DELETE) {\n\t\t\tif (focus.isSpan && focus.isCaretAtEnd && focus.next.target) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tdeleteMark('next', this.store)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tif (focus.isSpan && focus.isEditable && window.getSelection()?.isCollapsed) {\n\t\t\tconst content = focus.content\n\t\t\tconst caret = focus.caret\n\t\t\tif (event.key === KEYBOARD.BACKSPACE && caret > 0) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tfocus.content = content.slice(0, caret - 1) + content.slice(caret)\n\t\t\t\tfocus.caret = caret - 1\n\t\t\t\tthis.store.event.change()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (event.key === KEYBOARD.DELETE && caret >= 0 && caret < content.length) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tfocus.content = content.slice(0, caret) + content.slice(caret + 1)\n\t\t\t\tfocus.caret = caret\n\t\t\t\tthis.store.event.change()\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function handleBeforeInput(store: Store, event: InputEvent): void {\n\tconst selecting = store.state.selecting()\n\tif (selecting === 'all' && isFullSelection(store)) {\n\t\tif (event.inputType === 'insertFromPaste') {\n\t\t\tevent.preventDefault()\n\t\t\treturn\n\t\t}\n\t\tevent.preventDefault()\n\t\tconst newContent = event.inputType.startsWith('delete') ? '' : (event.data ?? '')\n\t\treplaceAllContentWith(store, newContent)\n\t\treturn\n\t}\n\tif (selecting === 'all') store.state.selecting(undefined)\n\n\tif (store.state.drag()) return\n\n\tconst {focus} = store.nodes\n\tif (!focus.target || !focus.isEditable) return\n\n\tif (\n\t\t(event.inputType === 'insertFromPaste' || event.inputType === 'insertReplacementText') &&\n\t\thandleMarkputSpanPaste(store, focus, event)\n\t) {\n\t\treturn\n\t}\n\n\tif (applySpanInput(focus, event)) {\n\t\tstore.event.change()\n\t}\n}\n\nfunction handleMarkputSpanPaste(store: Store, focus: NodeProxy, event: InputEvent): boolean {\n\tconst container = store.refs.container\n\tif (!container) return false\n\tconst markup = consumeMarkupPaste(container)\n\tif (!markup) return false\n\n\tevent.preventDefault()\n\n\tconst tokens = store.state.tokens()\n\tconst token = tokens[focus.index]\n\tconst offset = focus.caret\n\tconst currentValue = store.state.previousValue() ?? store.state.value() ?? ''\n\n\tconst ranges = event.getTargetRanges()\n\tconst childElement = container.children[focus.index]\n\tlet rawInsertPos: number\n\tlet rawEndPos: number\n\tif (ranges.length > 0) {\n\t\tconst cumStart = getBoundaryOffset(ranges[0], childElement, true)\n\t\tconst cumEnd = getBoundaryOffset(ranges[0], childElement, false)\n\t\trawInsertPos = token.position.start + cumStart\n\t\trawEndPos = token.position.start + cumEnd\n\t} else {\n\t\trawInsertPos = token.position.start + offset\n\t\trawEndPos = token.position.start + offset\n\t}\n\n\tconst caretPos = rawInsertPos + markup.length\n\tconst newValue = currentValue.slice(0, rawInsertPos) + markup + currentValue.slice(rawEndPos)\n\tstore.state.innerValue(newValue)\n\n\tconst newTokens = store.state.tokens()\n\tlet targetIdx = newTokens.findIndex(\n\t\tt => t.type === 'text' && caretPos >= t.position.start && caretPos <= t.position.end\n\t)\n\tif (targetIdx === -1) targetIdx = newTokens.length - 1\n\tconst caretWithinToken = caretPos - newTokens[targetIdx].position.start\n\n\tstore.state.recovery({\n\t\tanchor: store.nodes.focus,\n\t\tcaret: caretWithinToken,\n\t\tisNext: true,\n\t\tchildIndex: targetIdx - 2,\n\t})\n\treturn true\n}\n\nexport function applySpanInput(focus: NodeProxy, event: InputEvent): boolean {\n\tconst offset = focus.caret\n\tconst content = focus.content\n\tlet newContent: string\n\tlet newCaret: number\n\n\tswitch (event.inputType) {\n\t\tcase 'insertText': {\n\t\t\tevent.preventDefault()\n\t\t\tconst data = event.data ?? ''\n\t\t\tnewContent = content.slice(0, offset) + data + content.slice(offset)\n\t\t\tnewCaret = offset + data.length\n\t\t\tbreak\n\t\t}\n\t\tcase 'deleteContentBackward':\n\t\tcase 'deleteContentForward':\n\t\tcase 'deleteWordBackward':\n\t\tcase 'deleteWordForward':\n\t\tcase 'deleteSoftLineBackward':\n\t\tcase 'deleteSoftLineForward': {\n\t\t\tconst ranges = event.getTargetRanges()\n\t\t\tlet startOffset: number\n\t\t\tlet endOffset: number\n\t\t\tif (ranges.length > 0 && ranges[0].startOffset !== ranges[0].endOffset) {\n\t\t\t\tstartOffset = ranges[0].startOffset\n\t\t\t\tendOffset = ranges[0].endOffset\n\t\t\t} else {\n\t\t\t\tif (event.inputType === 'deleteContentBackward' && offset > 0) {\n\t\t\t\t\tstartOffset = offset - 1\n\t\t\t\t\tendOffset = offset\n\t\t\t\t} else if (event.inputType === 'deleteContentForward' && offset < content.length) {\n\t\t\t\t\tstartOffset = offset\n\t\t\t\t\tendOffset = offset + 1\n\t\t\t\t} else {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t}\n\t\t\tevent.preventDefault()\n\t\t\tnewContent = content.slice(0, startOffset) + content.slice(endOffset)\n\t\t\tnewCaret = startOffset\n\t\t\tbreak\n\t\t}\n\t\tcase 'insertFromPaste':\n\t\tcase 'insertReplacementText': {\n\t\t\tconst text = event.dataTransfer?.getData('text/plain') ?? ''\n\t\t\tconst ranges = event.getTargetRanges()\n\t\t\tconst start = ranges[0]?.startOffset ?? offset\n\t\t\tconst end = ranges[0]?.endOffset ?? offset\n\t\t\tevent.preventDefault()\n\t\t\tnewContent = content.slice(0, start) + text + content.slice(end)\n\t\t\tnewCaret = start + text.length\n\t\t\tbreak\n\t\t}\n\t\tdefault:\n\t\t\treturn false\n\t}\n\n\tfocus.content = newContent\n\tfocus.caret = newCaret\n\treturn true\n}\n\nexport function handlePaste(store: Store, event: ClipboardEvent): void {\n\tconst selecting = store.state.selecting()\n\tif (selecting !== 'all' || !isFullSelection(store)) {\n\t\tif (selecting === 'all') store.state.selecting(undefined)\n\t\treturn\n\t}\n\n\tevent.preventDefault()\n\tconst markup = store.refs.container ? consumeMarkupPaste(store.refs.container) : undefined\n\tconst newContent = markup ?? event.clipboardData?.getData('text/plain') ?? ''\n\treplaceAllContentWith(store, newContent)\n}\n\nexport function replaceAllContentWith(store: Store, newContent: string): void {\n\tstore.nodes.focus.target = null\n\tstore.state.selecting(undefined)\n\n\tstore.state.onChange()?.(newContent)\n\n\tif (store.state.value() === undefined) {\n\t\tstore.state.tokens(\n\t\t\tstore.computed.parser()?.parse(newContent) ?? [\n\t\t\t\t{\n\t\t\t\t\ttype: 'text' as const,\n\t\t\t\t\tcontent: newContent,\n\t\t\t\t\tposition: {start: 0, end: newContent.length},\n\t\t\t\t},\n\t\t\t]\n\t\t)\n\t}\n\n\tqueueMicrotask(() => {\n\t\tconst rawFirstChild = store.refs.container?.firstChild\n\t\tconst firstChild = isHtmlElement(rawFirstChild) ? rawFirstChild : null\n\t\tif (firstChild) {\n\t\t\tstore.state.recovery({\n\t\t\t\tanchor: store.nodes.focus,\n\t\t\t\tcaret: newContent.length,\n\t\t\t})\n\t\t\tfirstChild.focus()\n\t\t}\n\t})\n}","export function filterSuggestions(data: string[], search: string): string[] {\n\tconst query = search.toLowerCase()\n\treturn data.filter(s => s.toLowerCase().includes(query))\n}","import type {OverlayMatch} from '../../shared/types'\nimport type {MarkToken} from '../parsing'\n\nexport function createMarkFromOverlay(match: OverlayMatch, value: string, meta?: string): MarkToken {\n\tconst markup = match.option.markup\n\tif (!markup) throw new Error('createMarkFromOverlay: option.markup is required')\n\treturn {\n\t\ttype: 'mark',\n\t\tvalue,\n\t\tmeta,\n\t\tcontent: '',\n\t\tposition: {\n\t\t\tstart: match.index,\n\t\t\tend: match.index + match.span.length,\n\t\t},\n\t\tdescriptor: {\n\t\t\tmarkup,\n\t\t\tindex: 0,\n\t\t\tsegments: [],\n\t\t\tgapTypes: [],\n\t\t\thasSlot: false,\n\t\t\thasTwoValues: false,\n\t\t\tsegmentGlobalIndices: [],\n\t\t},\n\t\tchildren: [],\n\t\tslot: undefined,\n\t}\n}","import {KEYBOARD} from '../../shared/constants'\nimport {effectScope, watch} from '../../shared/signals/index.js'\nimport type {OverlayTrigger} from '../../shared/types'\nimport type {Store} from '../../store/Store'\nimport {TriggerFinder} from '../caret'\n\nexport class OverlayFeature {\n\t#scope?: () => void\n\t#selectionChangeHandler?: () => void\n\t#focusinHandler?: (e: FocusEvent) => void\n\t#focusoutHandler?: (e: FocusEvent) => void\n\t#escHandler?: (e: KeyboardEvent) => void\n\t#clickHandler?: (e: MouseEvent) => void\n\n\tconstructor(private store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\n\t\tthis.store.state.overlayTrigger(option => option.overlay?.trigger)\n\n\t\tthis.#scope = effectScope(() => {\n\t\t\twatch(this.store.event.clearOverlay, () => {\n\t\t\t\tthis.store.state.overlayMatch(undefined)\n\t\t\t})\n\n\t\t\twatch(this.store.event.checkOverlay, () => {\n\t\t\t\tconst getTrigger = this.store.state.overlayTrigger()\n\t\t\t\tif (!getTrigger) return\n\t\t\t\tconst match = TriggerFinder.find(this.store.state.options(), getTrigger)\n\t\t\t\tthis.store.state.overlayMatch(match)\n\t\t\t})\n\n\t\t\twatch(this.store.event.change, () => {\n\t\t\t\tconst showOverlayOn = this.store.state.showOverlayOn()\n\t\t\t\tconst type: OverlayTrigger = 'change'\n\n\t\t\t\tif (showOverlayOn === type || (Array.isArray(showOverlayOn) && showOverlayOn.includes(type))) {\n\t\t\t\t\tthis.store.event.checkOverlay()\n\t\t\t\t}\n\t\t\t})\n\n\t\t\twatch(this.store.state.overlayMatch, match => {\n\t\t\t\tif (match) {\n\t\t\t\t\tthis.store.nodes.input.target = this.store.nodes.focus.target\n\t\t\t\t\tthis.#enableClose()\n\t\t\t\t} else {\n\t\t\t\t\tthis.#disableClose()\n\t\t\t\t}\n\t\t\t})\n\t\t})\n\n\t\tconst selectionChangeHandler = () => {\n\t\t\tconst showOverlayOn = this.store.state.showOverlayOn()\n\t\t\tconst type: OverlayTrigger = 'selectionChange'\n\n\t\t\tif (showOverlayOn === type || (Array.isArray(showOverlayOn) && showOverlayOn.includes(type))) {\n\t\t\t\tthis.store.event.checkOverlay()\n\t\t\t}\n\t\t}\n\t\tthis.#selectionChangeHandler = selectionChangeHandler\n\n\t\tthis.#focusinHandler = () => {\n\t\t\tdocument.addEventListener('selectionchange', selectionChangeHandler)\n\t\t}\n\n\t\tthis.#focusoutHandler = () => {\n\t\t\tdocument.removeEventListener('selectionchange', selectionChangeHandler)\n\t\t}\n\n\t\tconst container = this.store.refs.container\n\t\tif (container) {\n\t\t\tcontainer.addEventListener('focusin', this.#focusinHandler)\n\t\t\tcontainer.addEventListener('focusout', this.#focusoutHandler)\n\t\t}\n\t}\n\n\tdisable() {\n\t\tconst container = this.store.refs.container\n\n\t\tif (container && this.#focusinHandler) {\n\t\t\tcontainer.removeEventListener('focusin', this.#focusinHandler)\n\t\t\tif (this.#focusoutHandler) container.removeEventListener('focusout', this.#focusoutHandler)\n\t\t}\n\n\t\tif (this.#selectionChangeHandler) {\n\t\t\tdocument.removeEventListener('selectionchange', this.#selectionChangeHandler)\n\t\t}\n\n\t\tthis.#disableClose()\n\n\t\tthis.store.state.overlayTrigger(undefined)\n\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t\tthis.#selectionChangeHandler = undefined\n\t\tthis.#focusinHandler = undefined\n\t\tthis.#focusoutHandler = undefined\n\t}\n\n\t#enableClose() {\n\t\tif (this.#escHandler) return\n\n\t\tthis.#escHandler = e => {\n\t\t\tif (e.key === KEYBOARD.ESC) {\n\t\t\t\tthis.store.event.clearOverlay()\n\t\t\t}\n\t\t}\n\n\t\tthis.#clickHandler = e => {\n\t\t\tconst target = e.target instanceof HTMLElement ? e.target : null\n\t\t\tif (this.store.refs.overlay?.contains(target)) return\n\t\t\tif (this.store.refs.container?.contains(target)) return\n\t\t\tthis.store.event.clearOverlay()\n\t\t}\n\n\t\twindow.addEventListener('keydown', this.#escHandler)\n\t\tdocument.addEventListener('click', this.#clickHandler, true)\n\t}\n\n\t#disableClose() {\n\t\tif (this.#escHandler) {\n\t\t\twindow.removeEventListener('keydown', this.#escHandler)\n\t\t\tif (this.#clickHandler) document.removeEventListener('click', this.#clickHandler, true)\n\t\t\tthis.#escHandler = undefined\n\t\t\tthis.#clickHandler = undefined\n\t\t}\n\t}\n}","import {KEYBOARD} from '../../shared/constants'\n\nexport type NavigationAction = 'up' | 'down' | 'select' | 'none'\n\nexport interface NavigationResult {\n\taction: NavigationAction\n\tindex: number\n}\n\nexport function navigateSuggestions(key: string, activeIndex: number, length: number): NavigationResult {\n\tif (length === 0) return {action: 'none', index: activeIndex}\n\n\tconst hasActive = !isNaN(activeIndex)\n\n\tswitch (key) {\n\t\tcase KEYBOARD.UP:\n\t\t\treturn {action: 'up', index: hasActive ? (length + ((activeIndex - 1) % length)) % length : 0}\n\t\tcase KEYBOARD.DOWN:\n\t\t\treturn {action: 'down', index: hasActive ? (activeIndex + 1) % length : 0}\n\t\tcase KEYBOARD.ENTER:\n\t\t\treturn hasActive ? {action: 'select', index: activeIndex} : {action: 'none', index: activeIndex}\n\t\tdefault:\n\t\t\treturn {action: 'none', index: activeIndex}\n\t}\n}","/**\n * Converts object with camelCase data attribute keys to kebab-case data-* attributes\n *\n * Takes keys like 'dataUserId' and converts to 'data-user-id'\n *\n * @param obj - Object potentially containing camelCase data attribute keys\n * @returns New object with converted data attributes\n *\n * @example\n * convertDataAttrs({ dataUserId: '123', dataUserName: 'John', className: 'test' })\n * // Returns: { 'data-user-id': '123', 'data-user-name': 'John', className: 'test' }\n *\n * convertDataAttrs({ dataTestId * @example\n: 'test', dataFoo: 'bar' })\n * // Returns: { 'data-test-id': 'test', 'data-foo': 'bar' }\n */\nexport function convertDataAttrs(obj: Record<string, unknown> | undefined): Record<string, unknown> {\n\tif (!obj) return {}\n\n\treturn Object.fromEntries(\n\t\tObject.entries(obj).map(([key, value]) => {\n\t\t\tif (key.startsWith('data') && key.length > 4 && key[4] === key[4].toUpperCase()) {\n\t\t\t\tconst kebab = key\n\t\t\t\t\t.slice(4)\n\t\t\t\t\t.replace(/([a-z0-9])([A-Z])/g, '$1-$2')\n\t\t\t\t\t.toLowerCase()\n\t\t\t\treturn [`data-${kebab}`, value]\n\t\t\t}\n\t\t\treturn [key, value]\n\t\t})\n\t)\n}","export function resolveOptionSlot<T extends object>(optionConfig: T | ((base: T) => T) | undefined, baseProps: T): T {\n\tif (optionConfig !== undefined) {\n\t\treturn typeof optionConfig === 'function' ? optionConfig(baseProps) : optionConfig\n\t}\n\treturn baseProps\n}","import type {CoreOption, CoreSlotProps, CoreSlots} from '../../shared/types'\nimport {convertDataAttrs} from '../../shared/utils/dataAttributes'\nimport type {Token} from '../parsing'\nimport {resolveOptionSlot} from './resolveOptionSlot'\n\nexport type SlotName = 'container' | 'block' | 'span'\n\nconst defaultSlots: Record<SlotName, string> = {\n\tcontainer: 'div',\n\tblock: 'div',\n\tspan: 'span',\n}\n\nexport function resolveSlot(slotName: SlotName, slots: unknown): unknown {\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- `slots` is `CoreSlots | undefined` at runtime; typed as unknown for Vue Ref<T> cross-framework compat\n\treturn (slots as CoreSlots | undefined)?.[slotName] ?? defaultSlots[slotName]\n}\n\nexport function resolveSlotProps(slotName: SlotName, slotProps: unknown): Record<string, unknown> | undefined {\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- `slotProps` is `CoreSlotProps | undefined` at runtime; typed as unknown for Vue Ref<T> cross-framework compat\n\tconst props = (slotProps as CoreSlotProps | undefined)?.[slotName]\n\treturn props ? convertDataAttrs(props) : undefined\n}\n\ntype SlotProp = Record<string, unknown> | ((base: Record<string, unknown>) => Record<string, unknown>)\n\n/**\n * Internal view of a framework-specific Option for slot resolution.\n * Framework Option types (React, Vue) extend CoreOption with these properties.\n */\nexport interface SlotOption extends Omit<CoreOption, 'overlay'> {\n\tMark?: unknown\n\tmark?: SlotProp\n\tOverlay?: unknown\n\toverlay?: SlotProp\n}\n\nexport function resolveOverlaySlot(globalComponent: unknown, option?: SlotOption, defaultComponent?: unknown) {\n\tconst Component = option?.Overlay ?? globalComponent ?? defaultComponent\n\tif (!Component)\n\t\tthrow new Error(\n\t\t\t'No overlay component found. Provide either option.Overlay, global Overlay, or a defaultComponent.'\n\t\t)\n\tconst props = resolveOptionSlot<Record<string, unknown>>(option?.overlay, {})\n\treturn [Component, props] as const\n}\n\nexport function resolveMarkSlot(\n\ttoken: Token,\n\ttokenOptions: SlotOption[] | undefined,\n\tGlobalMark: unknown,\n\tGlobalSpan: unknown\n) {\n\tif (token.type === 'text') {\n\t\treturn [GlobalSpan ?? 'span', GlobalSpan ? {value: token.content} : {}] as const\n\t}\n\tconst option = tokenOptions?.[token.descriptor.index]\n\tconst baseProps = {value: token.value, meta: token.meta}\n\tconst props = resolveOptionSlot(option?.mark, baseProps)\n\tconst Component = option?.Mark ?? GlobalMark\n\tif (!Component) throw new Error('No mark component found. Provide either option.Mark or global Mark.')\n\treturn [Component, props] as const\n}","import type {Signal} from '../../shared/signals'\nimport type {CoreOption, CoreSlotProps, CoreSlots} from '../../shared/types'\nimport type {Token} from '../parsing'\nimport {resolveMarkSlot, resolveOverlaySlot, resolveSlot, resolveSlotProps} from './resolveSlot'\nimport type {SlotName} from './resolveSlot'\nimport type {MarkSlot, OverlaySlot, Slot} from './types'\n\nfunction createNamedSlot(\n\tslots: Signal<CoreSlots | undefined>,\n\tslotProps: Signal<CoreSlotProps | undefined>,\n\tname: SlotName\n): Slot {\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- framework packages augment Slot with typed overloads; core satisfies the base interface\n\treturn {\n\t\tuse: () => [resolveSlot(name, slots.use()), resolveSlotProps(name, slotProps.use())] as const,\n\t\tget: () => [resolveSlot(name, slots()), resolveSlotProps(name, slotProps())] as const,\n\t} as unknown as Slot\n}\n\nfunction createOverlaySlot(overlay: Signal<unknown>): OverlaySlot {\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- framework packages augment OverlaySlot with typed overloads; core satisfies the base interface\n\treturn {\n\t\tuse: (option?: CoreOption, defaultComponent?: unknown) =>\n\t\t\tresolveOverlaySlot(overlay.use(), option, defaultComponent),\n\t\tget: (option?: CoreOption, defaultComponent?: unknown) =>\n\t\t\tresolveOverlaySlot(overlay(), option, defaultComponent),\n\t} as unknown as OverlaySlot\n}\n\nfunction createMarkSlot(options: Signal<CoreOption[]>, mark: Signal<unknown>, span: Signal<unknown>): MarkSlot {\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- framework packages augment MarkSlot with typed overloads; core satisfies the base interface\n\treturn {\n\t\tuse: (token: Token) => resolveMarkSlot(token, options(), mark.use(), span.use()),\n\t\tget: (token: Token) => resolveMarkSlot(token, options(), mark(), span()),\n\t} as unknown as MarkSlot\n}\n\nexport interface SlotSignals {\n\tslots: Signal<CoreSlots | undefined>\n\tslotProps: Signal<CoreSlotProps | undefined>\n\tOverlay: Signal<unknown>\n\toptions: Signal<CoreOption[]>\n\tMark: Signal<unknown>\n\tSpan: Signal<unknown>\n}\n\nexport function createSlots(signals: SlotSignals) {\n\treturn {\n\t\tcontainer: createNamedSlot(signals.slots, signals.slotProps, 'container'),\n\t\tblock: createNamedSlot(signals.slots, signals.slotProps, 'block'),\n\t\tspan: createNamedSlot(signals.slots, signals.slotProps, 'span'),\n\t\toverlay: createOverlaySlot(signals.Overlay),\n\t\tmark: createMarkSlot(signals.options, signals.Mark, signals.Span),\n\t}\n}","/**\n * Returns true when `target` is outside `element` (i.e. not contained by it).\n * Useful for closing a menu when the user clicks outside of it.\n */\nexport function isClickOutside(target: EventTarget | null, element: Element | null): boolean {\n\treturn !!element && !element.contains(target instanceof Node ? target : null)\n}\n\n/**\n * Returns true when the keyboard event is the Escape key.\n */\nexport function isEscapeKey(e: KeyboardEvent): boolean {\n\treturn e.key === 'Escape'\n}","import {signal} from '../shared/signals'\nimport type {DragAction, DragActions} from '../shared/types'\nimport {getDragDropPosition, getDragTargetIndex, parseDragSourceIndex} from '../shared/utils/dragUtils'\nimport {isClickOutside, isEscapeKey} from '../shared/utils/menuUtils'\n\nexport type DropPosition = 'before' | 'after' | null\n\nexport class BlockStore {\n\treadonly refs = {\n\t\tcontainer: null as HTMLElement | null,\n\t}\n\n\treadonly state = {\n\t\tisHovered: signal(false),\n\t\tisDragging: signal(false),\n\t\tdropPosition: signal<DropPosition>(null),\n\t\tmenuOpen: signal(false),\n\t\tmenuPosition: signal({top: 0, left: 0}),\n\t}\n\n\t#blockIndex = 0\n\t#dragAction: DragActions['dragAction'] | null = null\n\t#cleanupContainer?: () => void\n\t#cleanupGrip?: () => void\n\t#cleanupMenu?: () => void\n\n\tattachContainer(el: HTMLElement | null, blockIndex: number, actions: DragActions) {\n\t\tthis.#blockIndex = blockIndex\n\t\tthis.#dragAction = actions.dragAction\n\t\tif (el === this.refs.container) return\n\t\tthis.#cleanupContainer?.()\n\t\tthis.refs.container = el\n\t\tif (!el) return\n\n\t\tconst onMouseEnter = () => this.state.isHovered(true)\n\t\tconst onMouseLeave = () => this.state.isHovered(false)\n\t\tconst onDragOver = (e: DragEvent) => {\n\t\t\tif (!e.dataTransfer) return\n\t\t\te.preventDefault()\n\t\t\te.dataTransfer.dropEffect = 'move'\n\t\t\tthis.state.dropPosition(getDragDropPosition(e.clientY, el.getBoundingClientRect()))\n\t\t}\n\t\tconst onDragLeave = (e: DragEvent) => {\n\t\t\tconst ct = e.currentTarget\n\t\t\tif (ct instanceof Node && ct.contains(e.relatedTarget instanceof Node ? e.relatedTarget : null)) return\n\t\t\tthis.state.dropPosition(null)\n\t\t}\n\t\tconst onDrop = (e: DragEvent) => {\n\t\t\tif (!e.dataTransfer) return\n\t\t\te.preventDefault()\n\t\t\tconst sourceIndex = parseDragSourceIndex(e.dataTransfer)\n\t\t\tif (sourceIndex === null) return\n\t\t\tconst targetIndex = getDragTargetIndex(this.#blockIndex, this.state.dropPosition() ?? 'after')\n\t\t\tthis.state.dropPosition(null)\n\t\t\tthis.#emit({type: 'reorder', source: sourceIndex, target: targetIndex})\n\t\t}\n\n\t\tel.addEventListener('mouseenter', onMouseEnter)\n\t\tel.addEventListener('mouseleave', onMouseLeave)\n\t\tel.addEventListener('dragover', onDragOver)\n\t\tel.addEventListener('dragleave', onDragLeave)\n\t\tel.addEventListener('drop', onDrop)\n\t\tthis.#cleanupContainer = () => {\n\t\t\tel.removeEventListener('mouseenter', onMouseEnter)\n\t\t\tel.removeEventListener('mouseleave', onMouseLeave)\n\t\t\tel.removeEventListener('dragover', onDragOver)\n\t\t\tel.removeEventListener('dragleave', onDragLeave)\n\t\t\tel.removeEventListener('drop', onDrop)\n\t\t}\n\t}\n\n\tattachGrip(el: HTMLButtonElement | null, blockIndex: number, actions: DragActions) {\n\t\tthis.#blockIndex = blockIndex\n\t\tthis.#dragAction = actions.dragAction\n\t\tthis.#cleanupGrip?.()\n\t\tif (!el) return\n\n\t\tconst onDragStart = (e: DragEvent) => {\n\t\t\tif (!e.dataTransfer) return\n\t\t\te.dataTransfer.effectAllowed = 'move'\n\t\t\te.dataTransfer.setData('text/plain', String(this.#blockIndex))\n\t\t\tthis.state.isDragging(true)\n\t\t\tif (this.refs.container) e.dataTransfer.setDragImage(this.refs.container, 0, 0)\n\t\t}\n\t\tconst onDragEnd = () => {\n\t\t\tthis.state.isDragging(false)\n\t\t\tthis.state.dropPosition(null)\n\t\t}\n\t\tconst onClick = (e: MouseEvent) => {\n\t\t\te.preventDefault()\n\t\t\tconst rect = el.getBoundingClientRect()\n\t\t\tthis.state.menuPosition({top: rect.bottom + 4, left: rect.left})\n\t\t\tthis.state.menuOpen(true)\n\t\t}\n\n\t\tel.addEventListener('dragstart', onDragStart)\n\t\tel.addEventListener('dragend', onDragEnd)\n\t\tel.addEventListener('click', onClick)\n\t\tthis.#cleanupGrip = () => {\n\t\t\tel.removeEventListener('dragstart', onDragStart)\n\t\t\tel.removeEventListener('dragend', onDragEnd)\n\t\t\tel.removeEventListener('click', onClick)\n\t\t}\n\t}\n\n\tattachMenu(el: HTMLElement | null) {\n\t\tthis.#cleanupMenu?.()\n\t\tif (!el) return\n\n\t\tconst onMouseDown = (e: MouseEvent) => {\n\t\t\tif (isClickOutside(e.target, el)) this.closeMenu()\n\t\t}\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (isEscapeKey(e)) this.closeMenu()\n\t\t}\n\t\tdocument.addEventListener('mousedown', onMouseDown)\n\t\tdocument.addEventListener('keydown', onKeyDown)\n\t\tthis.#cleanupMenu = () => {\n\t\t\tdocument.removeEventListener('mousedown', onMouseDown)\n\t\t\tdocument.removeEventListener('keydown', onKeyDown)\n\t\t}\n\t}\n\n\tcloseMenu = () => this.state.menuOpen(false)\n\taddBlock = () => {\n\t\tthis.#emit({type: 'add', afterIndex: this.#blockIndex})\n\t\tthis.closeMenu()\n\t}\n\tdeleteBlock = () => {\n\t\tthis.#emit({type: 'delete', index: this.#blockIndex})\n\t\tthis.closeMenu()\n\t}\n\tduplicateBlock = () => {\n\t\tthis.#emit({type: 'duplicate', index: this.#blockIndex})\n\t\tthis.closeMenu()\n\t}\n\n\t#emit(action: DragAction) {\n\t\tthis.#dragAction?.(action)\n\t}\n}","import {BlockStore} from './BlockStore'\n\nexport class BlockRegistry {\n\treadonly #map = new WeakMap<object, BlockStore>()\n\n\tget(token: object): BlockStore {\n\t\tlet store = this.#map.get(token)\n\t\tif (!store) {\n\t\t\tstore = new BlockStore()\n\t\t\tthis.#map.set(token, store)\n\t\t}\n\t\treturn store\n\t}\n}","import {ArrowNavFeature} from '../features/arrownav'\nimport {BlockEditFeature} from '../features/block-editing'\nimport {CopyFeature} from '../features/clipboard'\nimport {DragFeature} from '../features/drag'\nimport {ContentEditableFeature} from '../features/editable'\nimport {SystemListenerFeature} from '../features/events'\nimport {FocusFeature} from '../features/focus'\nimport {InputFeature} from '../features/input'\nimport {OverlayFeature} from '../features/overlay'\nimport {Parser} from '../features/parsing'\nimport type {Token} from '../features/parsing'\nimport {ParseFeature} from '../features/parsing/ParseFeature'\nimport {TextSelectionFeature} from '../features/selection'\nimport {createSlots} from '../features/slots'\nimport {KeyGenerator, MarkputHandler, NodeProxy} from '../shared/classes'\nimport {DEFAULT_OPTIONS} from '../shared/constants'\nimport {signal, computed, event, batch, watch} from '../shared/signals'\nimport type {SignalValues} from '../shared/signals'\nimport type {\n\tCoreOption,\n\tOverlayMatch,\n\tOverlayTrigger,\n\tRecovery,\n\tCSSProperties,\n\tCoreSlots,\n\tCoreSlotProps,\n\tDragAction,\n} from '../shared/types'\nimport {cx} from '../shared/utils/cx'\nimport {merge} from '../shared/utils/merge'\nimport {shallow} from '../shared/utils/shallow'\nimport {BlockRegistry} from './BlockRegistry'\n\nimport styles from '../../styles.module.css'\n\nexport type {DragAction} from '../shared/types'\n\nexport class Store {\n\treadonly key = new KeyGenerator()\n\treadonly blocks = new BlockRegistry()\n\n\treadonly nodes = {\n\t\tfocus: new NodeProxy(undefined, this),\n\t\tinput: new NodeProxy(undefined, this),\n\t}\n\n\treadonly state = {\n\t\t// Data\n\t\ttokens: signal<Token[]>([]),\n\t\tvalue: signal<string | undefined>(undefined),\n\t\tdefaultValue: signal<string | undefined>(undefined),\n\t\tpreviousValue: signal<string | undefined>(undefined),\n\t\tinnerValue: signal<string | undefined>(undefined),\n\t\trecovery: signal<Recovery | undefined>(undefined),\n\n\t\t// Selection\n\t\tselecting: signal<'drag' | 'all' | undefined>(undefined),\n\t\tdrag: signal<boolean | {alwaysShowHandle: boolean}>(false),\n\n\t\t// Overlay\n\t\toverlayMatch: signal<OverlayMatch | undefined>(undefined),\n\t\toverlayTrigger: signal<((option: CoreOption) => string | undefined) | undefined>(undefined),\n\t\tshowOverlayOn: signal<OverlayTrigger>('change'),\n\n\t\t// Callbacks\n\t\tonChange: signal<((value: string) => void) | undefined>(undefined),\n\n\t\t// Config\n\t\toptions: signal<CoreOption[]>(DEFAULT_OPTIONS),\n\t\treadOnly: signal<boolean>(false),\n\n\t\t// Component overrides\n\t\tSpan: signal<unknown>(undefined),\n\t\tMark: signal<unknown>(undefined),\n\t\tOverlay: signal<unknown>(undefined),\n\n\t\t// Styling\n\t\tclassName: signal<string | undefined>(undefined),\n\t\tstyle: signal<CSSProperties | undefined>(undefined, {equals: shallow}),\n\n\t\t// Slot system\n\t\tslots: signal<CoreSlots | undefined>(undefined),\n\t\tslotProps: signal<CoreSlotProps | undefined>(undefined),\n\t}\n\n\treadonly computed = {\n\t\thasMark: computed(() => {\n\t\t\tconst Mark = this.state.Mark()\n\t\t\tif (Mark) return true\n\t\t\treturn this.state.options().some(opt => 'Mark' in opt && opt.Mark != null)\n\t\t}),\n\t\tparser: computed(() => {\n\t\t\tif (!this.computed.hasMark()) return\n\n\t\t\tconst markups = this.state.options().map(opt => opt.markup)\n\t\t\tif (!markups.some(Boolean)) return\n\n\t\t\tconst isDrag = !!this.state.drag()\n\t\t\treturn new Parser(markups, isDrag ? {skipEmptyText: true} : undefined)\n\t\t}),\n\t\tcontainerClass: computed(() =>\n\t\t\tcx(styles.Container, this.state.className(), this.state.slotProps()?.container?.className)\n\t\t),\n\t\tcontainerStyle: computed(prev => {\n\t\t\tconst next = merge(this.state.style(), this.state.slotProps()?.container?.style)\n\t\t\treturn prev && shallow(prev, next) ? prev : next\n\t\t}),\n\t}\n\n\treadonly slot = createSlots({\n\t\tslots: this.state.slots,\n\t\tslotProps: this.state.slotProps,\n\t\tOverlay: this.state.Overlay,\n\t\toptions: this.state.options,\n\t\tMark: this.state.Mark,\n\t\tSpan: this.state.Span,\n\t})\n\n\treadonly event = {\n\t\t/** Fires after user input or programmatic mark change — triggers serialization, `onChange`, and re-parse */\n\t\tchange: event(),\n\t\t/** Triggers a re-parse of tokens from the current content */\n\t\tparse: event(),\n\t\t/** Removes a mark token from editor content */\n\t\tdelete: event<{token: Token}>(),\n\t\t/** Fires when the user selects an overlay option — annotates markup into the current input span */\n\t\tselect: event<{mark: Token; match: OverlayMatch}>(),\n\t\t/** Dismisses the overlay by clearing the current `overlayMatch` */\n\t\tclearOverlay: event(),\n\t\t/** Probes the caret/text position for overlay trigger patterns and shows overlay if matched */\n\t\tcheckOverlay: event(),\n\t\t/** Syncs `contentEditable` attributes and `textContent` of child elements to match token state */\n\t\tsync: event(),\n\t\t/** Restores the caret position after a DOM re-render using the saved recovery state */\n\t\trecoverFocus: event(),\n\t\t/** Dispatches drag-mode row operations (reorder, add, delete, duplicate) */\n\t\tdragAction: event<DragAction>(),\n\t\t/** Signals the framework component has received new props — triggers conditional re-parse if value/options changed */\n\t\tupdated: event(),\n\t\t/** Fires after the framework has committed new token elements to the DOM — kicks off sync and focus recovery */\n\t\tafterTokensRendered: event(),\n\t\t/** Lifecycle: editor component added to the DOM — enables all features */\n\t\tmounted: event(),\n\t\t/** Lifecycle: editor component removed from the DOM — disables all features and cleans up subscriptions */\n\t\tunmounted: event(),\n\t}\n\n\treadonly refs = {\n\t\tcontainer: null as HTMLDivElement | null,\n\t\toverlay: null as HTMLElement | null,\n\t}\n\n\treadonly handler = new MarkputHandler(this)\n\n\treadonly features = {\n\t\toverlay: new OverlayFeature(this),\n\t\tfocus: new FocusFeature(this),\n\t\tinput: new InputFeature(this),\n\t\tblockEditing: new BlockEditFeature(this),\n\t\tarrowNav: new ArrowNavFeature(this),\n\t\tsystem: new SystemListenerFeature(this),\n\t\ttextSelection: new TextSelectionFeature(this),\n\t\tcontentEditable: new ContentEditableFeature(this),\n\t\tdrag: new DragFeature(this),\n\t\tcopy: new CopyFeature(this),\n\t\tparse: new ParseFeature(this),\n\t}\n\n\tconstructor() {\n\t\twatch(this.event.mounted, () => Object.values(this.features).forEach(f => f.enable()))\n\t\twatch(this.event.unmounted, () => Object.values(this.features).forEach(f => f.disable()))\n\t}\n\n\tsetState(values: Partial<SignalValues<typeof this.state>>): void {\n\t\tbatch(() => {\n\t\t\tconst state = this.state\n\t\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- heterogeneous signal map: per-key types verified by SignalValues<T> at the call site\n\t\t\tfor (const key of Object.keys(values) as (keyof typeof this.state)[]) {\n\t\t\t\tif (!(key in state)) continue\n\t\t\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- heterogeneous signal map: per-key types verified by SignalValues<T> at the call site\n\t\t\t\tstate[key](values[key] as never)\n\t\t\t}\n\t\t})\n\t}\n}","import type {Store} from '../../store'\nimport type {MarkToken, Token} from '../parsing'\nimport {findToken} from '../parsing'\n\nexport interface RefAccessor<T> {\n\tcurrent: T | null\n}\n\nexport class MarkHandler<T extends HTMLElement = HTMLElement> {\n\treadonly ref: RefAccessor<T>\n\treadonly #store: Store\n\treadonly #token: MarkToken\n\t#readOnly?: boolean\n\n\tconstructor(param: {ref: RefAccessor<T>; store: Store; token: MarkToken}) {\n\t\tthis.ref = param.ref\n\t\tthis.#store = param.store\n\t\tthis.#token = param.token\n\t}\n\n\tget readOnly() {\n\t\treturn this.#readOnly\n\t}\n\n\tset readOnly(value: boolean | undefined) {\n\t\tthis.#readOnly = value\n\t}\n\n\tget content() {\n\t\treturn this.#token.content\n\t}\n\n\tset content(value: string) {\n\t\tthis.#token.content = value\n\t\tthis.#emitChange()\n\t}\n\n\tget value() {\n\t\treturn this.#token.value\n\t}\n\n\tset value(v: string | undefined) {\n\t\tthis.#token.value = v ?? ''\n\t\tthis.#emitChange()\n\t}\n\n\tget meta() {\n\t\treturn this.#token.meta\n\t}\n\n\tset meta(v: string | undefined) {\n\t\tthis.#token.meta = v\n\t\tthis.#emitChange()\n\t}\n\n\tget slot(): string | undefined {\n\t\treturn this.#token.slot?.content\n\t}\n\n\tget depth(): number {\n\t\treturn findToken(this.#store.state.tokens(), this.#token)?.depth ?? 0\n\t}\n\n\tget hasChildren(): boolean {\n\t\treturn this.#token.children.some(child => child.type === 'mark')\n\t}\n\n\tget parent(): MarkToken | undefined {\n\t\treturn findToken(this.#store.state.tokens(), this.#token)?.parent\n\t}\n\n\tget tokens(): Token[] {\n\t\treturn this.#token.children\n\t}\n\n\tchange = (props: {content: string; value?: string; meta?: string}) => {\n\t\tthis.#token.content = props.content\n\t\tthis.#token.value = props.value ?? ''\n\t\tif (props.meta !== undefined) {\n\t\t\tthis.#token.meta = props.meta\n\t\t}\n\t\tthis.#emitChange()\n\t}\n\n\tremove = () => this.#store.event.delete({token: this.#token})\n\n\t#emitChange(): void {\n\t\tthis.#store.event.change()\n\t}\n}","import {setUseHookFactory, watch} from '@markput/core'\nimport {useSyncExternalStore} from 'react'\n\nsetUseHookFactory((sig: unknown) => {\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- sig is a Signal callable; cast to {(): unknown} to invoke it without a generic parameter\n\tconst s = sig as {(): unknown}\n\tconst subscribe = (cb: () => void) => watch(s, cb)\n\tconst getSnapshot = () => s()\n\treturn () => useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n})","import type {CoreOption, Store, Token} from '@markput/core'\nimport type {ComponentType, ElementType} from 'react'\nimport {createContext, useContext} from 'react'\n\nimport type {MarkProps, OverlayProps} from '../../types'\n\ndeclare module '@markput/core' {\n\tinterface MarkSlot {\n\t\tuse(token: Token): readonly [ComponentType<MarkProps>, MarkProps]\n\t}\n\tinterface OverlaySlot {\n\t\tuse(option?: CoreOption, defaultComponent?: unknown): readonly [ComponentType<OverlayProps>, OverlayProps]\n\t}\n\tinterface Slot {\n\t\tuse(): readonly [ElementType, Record<string, unknown> | undefined]\n\t}\n}\n\nexport const StoreContext = createContext<Store | undefined>(undefined)\nStoreContext.displayName = 'StoreContext'\n\nexport function useStore(): Store {\n\tconst store = useContext(StoreContext)\n\tif (store === undefined) {\n\t\tthrow new Error('Store not found. Make sure to wrap component in StoreContext.')\n\t}\n\treturn store\n}","import type {ReactNode} from 'react'\n\nimport styles from '@markput/core/styles.module.css'\n\nexport const List = ({children}: {children: ReactNode}) => <ul className={styles.PopupList}>{children}</ul>","import {cx} from '@markput/core'\nimport type {MouseEvent, ReactNode} from 'react'\nimport {useEffect, useRef} from 'react'\n\nimport styles from '@markput/core/styles.module.css'\n\nexport const ListItem = ({\n\tonClick,\n\tonMouseDown,\n\tactive,\n\tchildren,\n}: {\n\tonClick?: (e: MouseEvent<HTMLLIElement>) => void\n\tonMouseDown?: (e: MouseEvent<HTMLLIElement>) => void\n\tactive?: boolean\n\tchildren: ReactNode\n}) => {\n\tconst ref = useRef<HTMLLIElement>(null)\n\n\tuseEffect(() => {\n\t\tif (active) ref.current?.scrollIntoView(false)\n\t}, [active])\n\n\treturn (\n\t\t<li\n\t\t\tref={ref}\n\t\t\tclassName={cx(styles.PopupItem, active && styles.PopupItemActive)}\n\t\t\tonClick={onClick}\n\t\t\tonMouseDown={onMouseDown}\n\t\t>\n\t\t\t{children}\n\t\t</li>\n\t)\n}","import type {CSSProperties, ReactNode, Ref} from 'react'\n\nimport styles from '@markput/core/styles.module.css'\n\nexport const Popup = ({ref, style, children}: {ref?: Ref<HTMLElement>; style?: CSSProperties; children: ReactNode}) => {\n\t// oxlint-disable-next-line no-unsafe-type-assertion\n\tconst divRef = ref as Ref<HTMLDivElement> | undefined\n\treturn (\n\t\t<div ref={divRef} className={styles.Popup} style={style}>\n\t\t\t{children}\n\t\t</div>\n\t)\n}","import {cx} from '@markput/core'\nimport type {Token} from '@markput/core'\nimport {memo} from 'react'\n\nimport {useStore} from '../lib/providers/StoreContext'\nimport {List} from './Popup/List'\nimport {ListItem} from './Popup/ListItem'\nimport {Popup} from './Popup/Popup'\n\nimport styles from '@markput/core/styles.module.css'\n\nexport const BlockMenu = memo(({token}: {token: Token}) => {\n\tconst store = useStore()\n\tconst blockStore = store.blocks.get(token)\n\tconst menuOpen = blockStore.state.menuOpen.use()\n\tconst menuPosition = blockStore.state.menuPosition.use()\n\n\tif (!menuOpen) return null\n\n\treturn (\n\t\t<Popup\n\t\t\tref={(el: HTMLDivElement | null) => blockStore.attachMenu(el)}\n\t\t\tstyle={{top: menuPosition.top, left: menuPosition.left}}\n\t\t>\n\t\t\t<List>\n\t\t\t\t<ListItem onClick={() => blockStore.addBlock()}>\n\t\t\t\t\t<span className={cx(styles.Icon, styles.IconAdd)} />\n\t\t\t\t\t<span>Add below</span>\n\t\t\t\t</ListItem>\n\t\t\t\t<ListItem onClick={() => blockStore.duplicateBlock()}>\n\t\t\t\t\t<span className={cx(styles.Icon, styles.IconDuplicate)} />\n\t\t\t\t\t<span>Duplicate</span>\n\t\t\t\t</ListItem>\n\t\t\t\t<ListItem onClick={() => blockStore.deleteBlock()}>\n\t\t\t\t\t<span className={cx(styles.Icon, styles.IconTrash)} />\n\t\t\t\t\t<span>Delete</span>\n\t\t\t\t</ListItem>\n\t\t\t</List>\n\t\t</Popup>\n\t)\n})\n\nBlockMenu.displayName = 'BlockMenu'","import {cx, getAlwaysShowHandleDrag} from '@markput/core'\nimport type {Token as TokenType} from '@markput/core'\nimport {memo, useMemo} from 'react'\n\nimport {useStore} from '../lib/providers/StoreContext'\n\nimport styles from '@markput/core/styles.module.css'\n\nconst iconGrip = `${styles.Icon} ${styles.IconGrip}`\n\nexport const DragHandle = memo(({token, blockIndex}: {token: TokenType; blockIndex: number}) => {\n\tconst store = useStore()\n\tconst readOnly = store.state.readOnly.use()\n\tconst drag = store.state.drag.use()\n\tconst blockStore = store.blocks.get(token)\n\tconst isDragging = blockStore.state.isDragging.use()\n\tconst isHovered = blockStore.state.isHovered.use()\n\tconst alwaysShowHandle = useMemo(() => getAlwaysShowHandleDrag(drag), [drag])\n\n\tif (readOnly) return null\n\n\treturn (\n\t\t<div\n\t\t\tclassName={cx(\n\t\t\t\tstyles.SidePanel,\n\t\t\t\talwaysShowHandle ? styles.SidePanelAlways : isHovered && !isDragging && styles.SidePanelVisible\n\t\t\t)}\n\t\t>\n\t\t\t<button\n\t\t\t\tref={(el: HTMLButtonElement | null) => blockStore.attachGrip(el, blockIndex, store.event)}\n\t\t\t\ttype=\"button\"\n\t\t\t\tdraggable\n\t\t\t\tclassName={cx(styles.GripButton, isDragging && styles.GripButtonDragging)}\n\t\t\t\taria-label=\"Drag to reorder or click for options\"\n\t\t\t>\n\t\t\t\t<span className={iconGrip} />\n\t\t\t</button>\n\t\t</div>\n\t)\n})\n\nDragHandle.displayName = 'DragHandle'","import type {Token as TokenType} from '@markput/core'\nimport {memo} from 'react'\n\nimport {useStore} from '../lib/providers/StoreContext'\n\nimport styles from '@markput/core/styles.module.css'\n\nexport const DropIndicator = memo(({token, position}: {token: TokenType; position: 'before' | 'after'}) => {\n\tconst blockStore = useStore().blocks.get(token)\n\tconst dropPosition = blockStore.state.dropPosition.use()\n\n\tif (dropPosition !== position) return null\n\n\treturn <div className={styles.DropIndicator} style={position === 'before' ? {top: -1} : {bottom: -1}} />\n})\n\nDropIndicator.displayName = 'DropIndicator'","import type {Token} from '@markput/core'\nimport {createContext, useContext} from 'react'\n\nexport const TokenContext = createContext<Token | undefined>(undefined)\nTokenContext.displayName = 'TokenProvider'\n\nexport function useToken(): Token {\n\tconst value = useContext(TokenContext)\n\tif (value === undefined) {\n\t\tthrow new Error('Token not found. Make sure to wrap component in TokenContext.Provider.')\n\t}\n\treturn value\n}","import type {Token as TokenType} from '@markput/core'\nimport {memo} from 'react'\n\nimport {useStore} from '../lib/providers/StoreContext'\nimport {TokenContext} from '../lib/providers/TokenContext'\n\nexport const Token = memo(({mark}: {mark: TokenType}) => {\n\tconst store = useStore()\n\tconst [Component, props] = store.slot.mark.use(mark)\n\n\tconst children =\n\t\tmark.type === 'mark' && mark.children.length > 0\n\t\t\t? mark.children.map(child => <Token key={store.key.get(child)} mark={child} />)\n\t\t\t: undefined\n\n\treturn (\n\t\t<TokenContext value={mark}>\n\t\t\t<Component children={children} {...props} />\n\t\t</TokenContext>\n\t)\n})\n\nToken.displayName = 'Token'","import type {Token as TokenType} from '@markput/core'\nimport {memo} from 'react'\n\nimport {useStore} from '../lib/providers/StoreContext'\nimport {BlockMenu} from './BlockMenu'\nimport {DragHandle} from './DragHandle'\nimport {DropIndicator} from './DropIndicator'\nimport {Token} from './Token'\n\nimport styles from '@markput/core/styles.module.css'\n\ninterface BlockProps {\n\ttoken: TokenType\n\tblockIndex: number\n}\n\nexport const Block = memo(({token, blockIndex}: BlockProps) => {\n\tconst store = useStore()\n\tconst [ContainerComponent, containerProps] = store.slot.block.use()\n\n\tconst blockStore = store.blocks.get(token)\n\tconst isDragging = blockStore.state.isDragging.use()\n\n\treturn (\n\t\t<ContainerComponent\n\t\t\tref={(el: HTMLElement | null) => blockStore.attachContainer(el, blockIndex, store.event)}\n\t\t\tdata-testid=\"block\"\n\t\t\t{...containerProps}\n\t\t\tclassName={styles.Block}\n\t\t\tstyle={{opacity: isDragging ? 0.4 : 1}}\n\t\t>\n\t\t\t<DropIndicator token={token} position=\"before\" />\n\n\t\t\t<DragHandle token={token} blockIndex={blockIndex} />\n\n\t\t\t<Token mark={token} />\n\n\t\t\t<DropIndicator token={token} position=\"after\" />\n\n\t\t\t<BlockMenu token={token} />\n\t\t</ContainerComponent>\n\t)\n})\n\nBlock.displayName = 'Block'","import {memo, useLayoutEffect} from 'react'\n\nimport {useStore} from '../lib/providers/StoreContext'\nimport {Block} from './Block'\nimport {Token} from './Token'\n\nexport const Container = memo(() => {\n\tconst store = useStore()\n\tconst drag = store.state.drag.use()\n\tconst tokens = store.state.tokens.use()\n\n\tuseLayoutEffect(() => {\n\t\tstore.event.afterTokensRendered()\n\t}, [tokens])\n\n\tconst className = store.computed.containerClass.use()\n\tconst style = store.computed.containerStyle.use()\n\tconst readOnly = store.state.readOnly.use()\n\tconst key = store.key\n\tconst refs = store.refs\n\n\tconst [ContainerComponent, containerProps] = store.slot.container.use()\n\n\tconst containerStyle = drag && !readOnly ? (style ? {paddingLeft: 24, ...style} : {paddingLeft: 24}) : style\n\n\treturn (\n\t\t<ContainerComponent\n\t\t\tref={(el: HTMLDivElement | null) => (refs.container = el)}\n\t\t\t{...containerProps}\n\t\t\tclassName={className}\n\t\t\tstyle={containerStyle}\n\t\t>\n\t\t\t{drag\n\t\t\t\t? tokens.map((t, i) => <Block key={key.get(t)} token={t} blockIndex={i} />)\n\t\t\t\t: tokens.map(t => <Token key={key.get(t)} mark={t} />)}\n\t\t</ContainerComponent>\n\t)\n})\n\nContainer.displayName = 'Container'","import type {OverlayMatch} from '@markput/core'\nimport {Caret, createMarkFromOverlay} from '@markput/core'\nimport type {RefObject} from 'react'\nimport {useCallback, useMemo} from 'react'\n\nimport type {Option} from '../../types'\nimport {useStore} from '../providers/StoreContext'\n\nexport interface OverlayHandler {\n\tstyle: {\n\t\tleft: number\n\t\ttop: number\n\t}\n\tclose: () => void\n\tselect: (value: {value: string; meta?: string}) => void\n\tmatch: OverlayMatch<Option>\n\tref: RefObject<HTMLElement | null>\n}\n\nexport function useOverlay(): OverlayHandler {\n\tconst store = useStore()\n\tconst match = store.state.overlayMatch.use()\n\tif (!match) throw new Error('useOverlay requires an active overlay match')\n\tconst style = useMemo(() => Caret.getAbsolutePosition(), [match])\n\n\tconst close = useCallback(() => store.event.clearOverlay(), [])\n\tconst select = useCallback(\n\t\t(value: {value: string; meta?: string}) => {\n\t\t\tconst mark = createMarkFromOverlay(match, value.value, value.meta)\n\t\t\tstore.event.select({mark, match})\n\t\t\tstore.event.clearOverlay()\n\t\t},\n\t\t[match]\n\t)\n\n\tconst ref = useMemo(\n\t\t(): RefObject<HTMLElement | null> => ({\n\t\t\tget current() {\n\t\t\t\treturn store.refs.overlay\n\t\t\t},\n\t\t\tset current(v: HTMLElement | null) {\n\t\t\t\tstore.refs.overlay = v\n\t\t\t},\n\t\t}),\n\t\t[]\n\t)\n\n\treturn {match, style, select, close, ref}\n}","import {filterSuggestions, navigateSuggestions} from '@markput/core'\nimport {useEffect, useMemo, useRef, useState} from 'react'\n\nimport {useOverlay} from '../../lib/hooks/useOverlay'\nimport {useStore} from '../../lib/providers/StoreContext'\nimport {List} from '../Popup/List'\nimport {ListItem} from '../Popup/ListItem'\nimport {Popup} from '../Popup/Popup'\n\nexport const Suggestions = () => {\n\tconst store = useStore()\n\tconst {match, select, style, ref} = useOverlay()\n\tconst [active, setActive] = useState(NaN)\n\tconst data = match.option.overlay?.data ?? []\n\tconst filtered = useMemo(() => filterSuggestions(data, match.value), [match.value, data])\n\tconst length = filtered.length\n\n\t// Refs let the handler always read the latest values without re-registering\n\t// the listener on every keypress (which happened when `active` was a dep).\n\tconst activeRef = useRef(active)\n\tactiveRef.current = active\n\tconst filteredRef = useRef(filtered)\n\tfilteredRef.current = filtered\n\n\tuseEffect(() => {\n\t\tconst container = store.refs.container\n\t\tif (!container) return\n\n\t\tconst handler = (event: KeyboardEvent) => {\n\t\t\tconst result = navigateSuggestions(event.key, activeRef.current, length)\n\t\t\tswitch (result.action) {\n\t\t\t\tcase 'up':\n\t\t\t\tcase 'down':\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tsetActive(result.index)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'select': {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tconst suggestion = filteredRef.current[result.index]\n\t\t\t\t\tselect({value: suggestion, meta: result.index.toString()})\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'none':\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tcontainer.addEventListener('keydown', handler)\n\t\treturn () => container.removeEventListener('keydown', handler)\n\t}, [length, select])\n\n\tif (!filtered.length) return null\n\n\treturn (\n\t\t<Popup ref={ref} style={style}>\n\t\t\t<List>\n\t\t\t\t{filtered.map((suggestion, index) => (\n\t\t\t\t\t<ListItem\n\t\t\t\t\t\tkey={suggestion}\n\t\t\t\t\t\tactive={index === active}\n\t\t\t\t\t\tonClick={() => select({value: suggestion, meta: index.toString()})}\n\t\t\t\t\t>\n\t\t\t\t\t\t{suggestion}\n\t\t\t\t\t</ListItem>\n\t\t\t\t))}\n\t\t\t</List>\n\t\t</Popup>\n\t)\n}","import {memo, useMemo} from 'react'\n\nimport {useStore} from '../lib/providers/StoreContext'\nimport {Suggestions} from './Suggestions'\n\nexport const OverlayRenderer = memo(() => {\n\tconst store = useStore()\n\tconst overlayMatch = store.state.overlayMatch.use()\n\tconst key = useMemo(() => (overlayMatch ? store.key.get(overlayMatch.option) : undefined), [overlayMatch])\n\n\tconst [Overlay, props] = store.slot.overlay.use(overlayMatch?.option, Suggestions)\n\n\tif (!key) return\n\n\treturn <Overlay key={key} {...props} />\n})\n\nOverlayRenderer.displayName = 'OverlayRenderer'","import type {CoreOption, MarkputHandler, OverlayTrigger} from '@markput/core'\nimport {Store} from '@markput/core'\nimport type {ComponentType, CSSProperties, Ref} from 'react'\nimport {useEffect, useImperativeHandle, useLayoutEffect, useState} from 'react'\n\n// oxlint-disable-next-line no-unassigned-import -- side-effect import: registers the React useHook factory via setUseHookFactory\nimport '../lib/hooks/createUseHook'\nimport {StoreContext} from '../lib/providers/StoreContext'\nimport type {MarkProps, Option, OverlayProps, SlotProps, Slots} from '../types'\nimport {Container} from './Container'\nimport {OverlayRenderer} from './OverlayRenderer'\n\n/**\n * Props for MarkedInput component.\n *\n * @template TMarkProps - Type of props for the global Mark component\n * @template TOverlayProps - Type of props for the global Overlay component\n *\n * @example\n * ```tsx\n * <MarkedInput<ChipProps>\n * Mark={Chip}\n * options={[{\n * markup: '@[__value__]',\n * mark: { label: 'Click me' }\n * }]}\n * />\n * ```\n */\nexport interface MarkedInputProps<TMarkProps = MarkProps, TOverlayProps extends CoreOption['overlay'] = OverlayProps> {\n\t/** Ref to handler */\n\tref?: Ref<MarkputHandler>\n\t/** Global component used for rendering text tokens (default: built-in Span) */\n\tSpan?: ComponentType<MarkProps>\n\t/** Global component used for rendering markups (fallback for option.Mark) */\n\tMark?: ComponentType<TMarkProps>\n\t/** Global component used for rendering overlays (fallback for option.Overlay) */\n\tOverlay?: ComponentType<TOverlayProps>\n\t/**\n\t * Configuration options for markups and overlays.\n\t * Each option can specify its own component via option.Mark or option.Overlay.\n\t * Falls back to global Mark/Overlay components when not specified.\n\t */\n\toptions?: Option<TMarkProps, TOverlayProps>[]\n\t/** Additional classes */\n\tclassName?: string\n\t/** Additional style */\n\tstyle?: CSSProperties\n\t/**\n\t * Override internal components using slots\n\t * @example slots={{ container: 'div', span: 'span' }}\n\t */\n\tslots?: Slots\n\t/**\n\t * Props to pass to slot components\n\t * @example slotProps={{ container: { onKeyDown: handler }, span: { className: 'custom' } }}\n\t */\n\tslotProps?: SlotProps\n\t/**\n\t * Events that trigger overlay display\n\t * @default 'change'\n\t */\n\tshowOverlayOn?: OverlayTrigger\n\t/** Annotated text with markups */\n\tvalue?: string\n\t/** Initial value for uncontrolled mode */\n\tdefaultValue?: string\n\t/** Change event handler */\n\tonChange?: (value: string) => void\n\t/** Read-only mode */\n\treadOnly?: boolean\n\t/** Enable drag mode: each individual token (mark or text) becomes its own draggable row.\n\t * One mark per row, one text fragment per row.\n\t * Adjacent marks need no separator; adjacent text rows are separated by `\\n\\n`.\n\t */\n\tdrag?: boolean | {alwaysShowHandle: boolean}\n}\n\nexport function MarkedInput<TMarkProps = MarkProps, TOverlayProps extends CoreOption['overlay'] = OverlayProps>(\n\tprops: MarkedInputProps<TMarkProps, TOverlayProps>\n) {\n\tconst [store] = useState(() => new Store())\n\tstore.setState(props)\n\n\tuseLayoutEffect(() => store.event.mounted())\n\tuseLayoutEffect(() => store.event.updated())\n\tuseEffect(() => () => store.event.unmounted(), [store])\n\n\tuseImperativeHandle(props.ref, () => store.handler, [store])\n\n\treturn (\n\t\t<StoreContext value={store}>\n\t\t\t<Container />\n\t\t\t<OverlayRenderer />\n\t\t</StoreContext>\n\t)\n}","import type {MarkOptions, MarkToken} from '@markput/core'\nimport {MarkHandler} from '@markput/core'\nimport {useEffect, useMemo, useRef} from 'react'\n\nimport {useStore} from '../providers/StoreContext'\nimport {useToken} from '../providers/TokenContext'\n\nexport const useMark = <T extends HTMLElement = HTMLElement>(options: MarkOptions = {}): MarkHandler<T> => {\n\tconst store = useStore()\n\tconst token = useToken()\n\tif (token.type !== 'mark') throw new Error('useMark must be called within a mark token context')\n\tconst ref = useRef<T>(null)\n\n\tconst mark = useMemo(() => new MarkHandler<T>({ref, store, token}), [store, token])\n\n\tuseUncontrolledInit(ref, options, token)\n\n\tconst readOnly = store.state.readOnly.use()\n\tuseEffect(() => {\n\t\tmark.readOnly = readOnly\n\t}, [mark, readOnly])\n\n\treturn mark\n}\n\nfunction useUncontrolledInit(ref: {readonly current: HTMLElement | null}, options: MarkOptions, token: MarkToken) {\n\tuseEffect(() => {\n\t\tif (!options.controlled && ref.current) ref.current.textContent = token.content\n\t}, [])\n}"],"mappings":";;;;;AAAA,SAAgB,QAAQ,MAAe,MAAe;AACrD,KAAI,OAAO,GAAG,MAAM,KAAK,CACxB,QAAO;AAER,KAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,OAAO,SAAS,YAAY,SAAS,KACrF,QAAO;CAER,MAAM,QAAQ,OAAO,KAAK,KAAK;AAC/B,KAAI,MAAM,WAAW,OAAO,KAAK,KAAK,CAAC,OACtC,QAAO;AAER,MAAK,MAAM,OAAO,OAAO;AACxB,MAAI,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,IAAI,CACnD,QAAO;AAER,MAAI,CAAC,OAAO,GAAG,QAAQ,IAAI,MAAM,IAAI,EAAE,QAAQ,IAAI,MAAM,IAAI,CAAC,CAC7D,QAAO;;AAGT,QAAO;;;;ACnBR,SAAgB,GAAG,GAAG,SAAoE;AACzF,QAAO,QAAQ,OAAO,QAAQ,CAAC,KAAK,IAAI,IAAI,KAAA;;;;ACD7C,SAAgB,MAAwB,GAAG,SAA0D;CAEpG,MAAM,SAAS,OAAO,OAAO,EAAE,EAAE,GAAG,QAAQ,OAAO,QAAQ,CAAC;AAC5D,QAAO,OAAO,KAAK,OAAO,CAAC,SAAS,IAAI,SAAS,KAAA;;;;ACSlD,MAAa,WAAW;CAEvB,IAAI;CACJ,MAAM;CACN,MAAM;CACN,OAAO;CACP,KAAK;CACL,MAAM;CACN,WAAW;CACX,SAAS;CAGT,OAAO;CACP,KAAK;CACL,OAAO;CAGP,WAAW;CACX,QAAQ;CACR,OAAO;CAGP,KAAK;CACL;AAOD,MAAa,kBAAmC,CAC/C;CACC,QAJoC;CAKpC,SAAS;EACR,SAAA;EACA,MAAM,EAAE;EACR;CACD,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AkB;EACtC;AAEF,gBAAgB,cAAc;;;AC6D9B,SAAgB,YACf,OACC;CACD,MAAM,CAAC,SAAS,eAAe,IAAI,OAAO,CAAC;AAC3C,OAAM,SAAS,MAAM;AAErB,uBAAsB,MAAM,MAAM,SAAS,CAAC;AAC5C,uBAAsB,MAAM,MAAM,SAAS,CAAC;AAC5C,uBAAsB,MAAM,MAAM,WAAW,EAAE,CAAC,MAAM,CAAC;AAEvD,qBAAoB,MAAM,WAAW,MAAM,SAAS,CAAC,MAAM,CAAC;AAE5D,QACC,qBAAC,cAAD;EAAc,OAAO;YAArB,CACC,oBAAC,WAAD,EAAa,CAAA,EACb,oBAAC,iBAAD,EAAmB,CAAA,CACL;;;;;ACvFjB,MAAa,WAAgD,UAAuB,EAAE,KAAqB;CAC1G,MAAM,QAAQ,UAAU;CACxB,MAAM,QAAQ,UAAU;AACxB,KAAI,MAAM,SAAS,OAAQ,OAAM,IAAI,MAAM,qDAAqD;CAChG,MAAM,MAAM,OAAU,KAAK;CAE3B,MAAM,OAAO,cAAc,IAAI,YAAe;EAAC;EAAK;EAAO;EAAM,CAAC,EAAE,CAAC,OAAO,MAAM,CAAC;AAEnF,qBAAoB,KAAK,SAAS,MAAM;CAExC,MAAM,WAAW,MAAM,MAAM,SAAS,KAAK;AAC3C,iBAAgB;AACf,OAAK,WAAW;IACd,CAAC,MAAM,SAAS,CAAC;AAEpB,QAAO;;AAGR,SAAS,oBAAoB,KAA6C,SAAsB,OAAkB;AACjH,iBAAgB;AACf,MAAI,CAAC,QAAQ,cAAc,IAAI,QAAS,KAAI,QAAQ,cAAc,MAAM;IACtE,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","names":["#map","#counter","#store","#target","getOrCreate","tokensToString","#scope","#subscribeParse","#subscribeReactiveParse","#scope","#pressedNode","#isPressed","#scope","#scope","#handleCopy","#scope","#syncDragTextContent","#syncTextContent","#syncMarkChildren","#scope","#handleBlockArrowLeftRight","#handleArrowUpDown","#handleDelete","#handleEnter","#handleBlockBeforeInput","#unsub","#reorder","#add","#delete","#duplicate","#scope","#scope","#recover","#scope","#handleDelete","#scope","#blockIndex","#dragAction","#cleanupContainer","#emit","#cleanupGrip","#cleanupMenu","#map","#store","#token","#readOnly","#emitChange","#tokenInfo","styles","styles","styles","styles","styles","styles","styles"],"sources":["../../../core/src/shared/utils/shallow.ts","../../../core/src/shared/utils/cx.ts","../../../core/src/shared/utils/merge.ts","../../../core/src/shared/constants.ts","../../../core/src/shared/classes/MarkputHandler.ts","../../../core/src/shared/classes/KeyGenerator.ts","../../../core/src/shared/checkers/domGuards.ts","../../../core/src/features/caret/Caret.ts","../../../core/src/shared/escape.ts","../../../core/src/features/caret/TriggerFinder.ts","../../../core/src/shared/classes/NodeProxy.ts","../../../core/src/shared/signals/alien-signals/system.ts","../../../core/src/shared/signals/signal.ts","../../../core/src/features/parsing/parser/constants.ts","../../../core/src/features/parsing/parser/core/MarkupDescriptor.ts","../../../core/src/features/parsing/parser/core/MarkupRegistry.ts","../../../core/src/features/parsing/parser/utils/getSegmentIndex.ts","../../../core/src/features/parsing/parser/core/Match.ts","../../../core/src/features/parsing/parser/core/PatternMatcher.ts","../../../core/src/features/parsing/parser/core/SegmentMatcher.ts","../../../core/src/features/parsing/parser/utils/createTextToken.ts","../../../core/src/features/parsing/parser/core/TreeBuilder.ts","../../../core/src/features/parsing/parser/utils/processTokens.ts","../../../core/src/features/parsing/parser/utils/annotate.ts","../../../core/src/features/parsing/parser/utils/toString.ts","../../../core/src/features/parsing/parser/Parser.ts","../../../core/src/features/parsing/parser/utils/denote.ts","../../../core/src/features/parsing/utils/findToken.ts","../../../core/src/features/parsing/preparsing/utils/findGap.ts","../../../core/src/features/parsing/preparsing/utils/getClosestIndexes.ts","../../../core/src/features/parsing/utils/valueParser.ts","../../../core/src/features/parsing/ParseFeature.ts","../../../core/src/features/navigation/navigation.ts","../../../core/src/features/selection/selectionHelpers.ts","../../../core/src/features/selection/TextSelectionFeature.ts","../../../core/src/features/arrownav/ArrowNavFeature.ts","../../../core/src/features/clipboard/pasteMarkup.ts","../../../core/src/features/clipboard/selectionToTokens.ts","../../../core/src/features/clipboard/CopyFeature.ts","../../../core/src/features/drag/operations.ts","../../../core/src/features/editing/utils/createNewSpan.ts","../../../core/src/features/editing/createRowContent.ts","../../../core/src/features/editing/utils/deleteMark.ts","../../../core/src/features/editable/isTextTokenSpan.ts","../../../core/src/features/editable/ContentEditableFeature.ts","../../../core/src/features/block-editing/rawPosition.ts","../../../core/src/features/block-editing/BlockEditFeature.ts","../../../core/src/features/drag/tokens.ts","../../../core/src/features/drag/DragFeature.ts","../../../core/src/shared/utils/dragUtils.ts","../../../core/src/features/drag/config.ts","../../../core/src/features/events/SystemListenerFeature.ts","../../../core/src/features/focus/FocusFeature.ts","../../../core/src/features/input/InputFeature.ts","../../../core/src/features/overlay/filterSuggestions.ts","../../../core/src/features/overlay/createMarkFromOverlay.ts","../../../core/src/features/overlay/OverlayFeature.ts","../../../core/src/features/overlay/suggestionNavigation.ts","../../../core/src/shared/utils/dataAttributes.ts","../../../core/src/features/slots/resolveOptionSlot.ts","../../../core/src/features/slots/resolveSlot.ts","../../../core/src/shared/utils/menuUtils.ts","../../../core/src/store/BlockStore.ts","../../../core/src/store/BlockRegistry.ts","../../../core/src/store/Store.ts","../../../core/src/features/mark/MarkHandler.ts","../src/lib/providers/StoreContext.ts","../src/lib/hooks/useMarkput.ts","../src/components/Popup/List.tsx","../src/components/Popup/ListItem.tsx","../src/components/Popup/Popup.tsx","../src/components/BlockMenu.tsx","../src/components/DragHandle.tsx","../src/components/DropIndicator.tsx","../src/lib/providers/TokenContext.ts","../src/components/Token.tsx","../src/components/Block.tsx","../src/components/Container.tsx","../src/lib/hooks/useOverlay.tsx","../src/components/Suggestions/Suggestions.tsx","../src/components/OverlayRenderer.tsx","../src/components/MarkedInput.tsx","../src/lib/hooks/useMark.tsx"],"sourcesContent":["export function shallow(objA: unknown, objB: unknown) {\n\tif (Object.is(objA, objB)) {\n\t\treturn true\n\t}\n\tif (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) {\n\t\treturn false\n\t}\n\tconst keysA = Object.keys(objA)\n\tif (keysA.length !== Object.keys(objB).length) {\n\t\treturn false\n\t}\n\tfor (const key of keysA) {\n\t\tif (!Object.prototype.hasOwnProperty.call(objB, key)) {\n\t\t\treturn false\n\t\t}\n\t\tif (!Object.is(Reflect.get(objA, key), Reflect.get(objB, key))) {\n\t\t\treturn false\n\t\t}\n\t}\n\treturn true\n}","export function cx(...classes: (string | undefined | null | false)[]): string | undefined {\n\treturn classes.filter(Boolean).join(' ') || undefined\n}","export function merge<T extends object>(...objects: (T | undefined | null | false)[]): T | undefined {\n\t// oxlint-disable-next-line no-unsafe-argument, no-unsafe-call, no-unsafe-return, no-unsafe-type-assertion\n\tconst result = Object.assign({}, ...objects.filter(Boolean)) as T\n\treturn Object.keys(result).length > 0 ? result : undefined\n}","import type {Markup} from '../features/parsing/parser/types'\nimport type {CoreOption} from './types'\n\nexport interface DefaultOverlayConfig {\n\ttrigger?: string\n\tdata?: string[]\n}\n\nexport interface DefaultOption extends CoreOption {\n\toverlay?: DefaultOverlayConfig\n}\n\nexport const KEYBOARD = {\n\t// Navigation Keys\n\tUP: 'ArrowUp',\n\tDOWN: 'ArrowDown',\n\tLEFT: 'ArrowLeft',\n\tRIGHT: 'ArrowRight',\n\tEND: 'End',\n\tHOME: 'Home',\n\tPAGE_DOWN: 'PageDown',\n\tPAGE_UP: 'PageUp',\n\n\t// Whitespace Keys\n\tENTER: 'Enter',\n\tTAB: 'Tab',\n\tSPACE: ' ',\n\n\t// Editing Keys\n\tBACKSPACE: 'Backspace',\n\tDELETE: 'Delete',\n\tCOMMA: ',',\n\n\t// UI Keys\n\tESC: 'Escape',\n} as const\nexport type KEYBOARD = (typeof KEYBOARD)[keyof typeof KEYBOARD]\n\nexport const DEFAULT_OVERLAY_TRIGGER = '@'\n\nexport const DEFAULT_MARKUP: Markup = '@[__value__](__meta__)'\n\nexport const DEFAULT_OPTIONS: DefaultOption[] = [\n\t{\n\t\tmarkup: DEFAULT_MARKUP,\n\t\toverlay: {\n\t\t\ttrigger: DEFAULT_OVERLAY_TRIGGER,\n\t\t\tdata: [],\n\t\t},\n\t},\n]","import type {Store} from '../../store'\n\nexport class MarkputHandler {\n\tconstructor(private readonly store: Store) {}\n\n\tget container() {\n\t\treturn this.store.refs.container\n\t}\n\n\tget overlay() {\n\t\treturn this.store.refs.overlay\n\t}\n\n\tfocus() {\n\t\tthis.store.nodes.focus.head?.focus()\n\t}\n}","export class KeyGenerator {\n\t#counter = 1\n\treadonly #map = new WeakMap<object, number>()\n\n\tget(object: object) {\n\t\tif (this.#map.has(object)) return this.#map.get(object)\n\n\t\tthis.#map.set(object, this.#counter)\n\t\treturn this.#counter++\n\t}\n}","/** Type guard: checks if a value is an HTMLElement. */\nexport function isHtmlElement(el: unknown): el is HTMLElement {\n\treturn typeof HTMLElement !== 'undefined' && el instanceof HTMLElement\n}\n\n/** Type guard: checks if a value is a Text node. */\nexport function isTextNode(node: unknown): node is Text {\n\treturn node instanceof Text\n}\n\n/** Get the i-th child of an element as HTMLElement, or undefined if out of bounds or wrong type. */\nexport function childAt(parent: Element | null | undefined, index: number): HTMLElement | undefined {\n\tconst child = parent?.children[index]\n\treturn child instanceof HTMLElement ? child : undefined\n}\n\n/** Get all children of an element as HTMLElement[], filtering out non-HTML elements. */\nexport function htmlChildren(parent: Element | null | undefined): HTMLElement[] {\n\tif (!parent) return []\n\treturn Array.from(parent.children).filter((child): child is HTMLElement => child instanceof HTMLElement)\n}\n\n/** Get the first element child as HTMLElement, or null. */\nexport function firstHtmlChild(parent: Element | null | undefined): HTMLElement | null {\n\tconst child = parent?.firstElementChild\n\treturn child instanceof HTMLElement ? child : null\n}\n\n/** Get the last element child as HTMLElement, or null. */\nexport function lastHtmlChild(parent: Element | null | undefined): HTMLElement | null {\n\tconst child = parent?.lastElementChild\n\treturn child instanceof HTMLElement ? child : null\n}\n\n/** Safely narrow an event's target to HTMLElement. */\nexport function htmlTarget(event: {target: EventTarget | null}): HTMLElement | null {\n\tconst {target} = event\n\treturn target instanceof HTMLElement ? target : null\n}\n\n/** Safely narrow an event's target to Node. */\nexport function nodeTarget(event: {target: EventTarget | null}): Node | null {\n\tconst {target} = event\n\treturn target instanceof Node ? target : null\n}\n\n/** Get the next node from a TreeWalker as Text, or null. */\nexport function nextText(walker: TreeWalker): Text | null {\n\tconst node = walker.nextNode()\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- nodeType === 3 guarantees Text; instanceof Text breaks in test envs\n\treturn node?.nodeType === 3 ? (node as Text) : null\n}","import {nextText} from '../../shared/checkers'\n\n/** Firefox-only CaretPosition (absent from TypeScript DOM lib) */\ninterface CaretPosition {\n\treadonly offsetNode: Node\n\treadonly offset: number\n}\n\n/** Non-standard document caret APIs absent from TypeScript DOM lib */\ninterface DocumentWithCaretFromPoint {\n\tcaretRangeFromPoint?(x: number, y: number): Range | null\n\tcaretPositionFromPoint?(x: number, y: number): CaretPosition | null\n}\n\n//TODO refact caret\nexport class Caret {\n\tstatic get isSelectedPosition() {\n\t\tconst selection = window.getSelection()\n\t\tif (!selection) return\n\t\treturn selection.isCollapsed\n\t}\n\n\tstatic getCurrentPosition() {\n\t\treturn window.getSelection()?.anchorOffset ?? 0\n\t}\n\n\t//TODO get span from state?\n\tstatic getFocusedSpan() {\n\t\treturn window.getSelection()?.anchorNode?.textContent ?? ''\n\t}\n\n\tstatic getSelectedNode() {\n\t\tconst node = window.getSelection()?.anchorNode\n\t\tif (node && document.contains(node)) return node\n\t\tthrow new Error('Anchor node of selection is not exists!')\n\t}\n\n\t//TODO add the returned type: \"{left: CSSProperties[\"left\"], top: CSSProperties[\"top\"]}\"?\n\tstatic getAbsolutePosition() {\n\t\tconst rect = window.getSelection()?.getRangeAt(0).getBoundingClientRect()\n\t\tif (rect) return {left: rect.left, top: rect.top + rect.height + 1}\n\t\treturn {left: 0, top: 0}\n\t}\n\n\t/** Returns the raw DOMRect of the current caret position, or null if unavailable. */\n\tstatic getCaretRect(): DOMRect | null {\n\t\ttry {\n\t\t\tconst range = window.getSelection()?.getRangeAt(0)\n\t\t\treturn range?.getBoundingClientRect() ?? null\n\t\t} catch {\n\t\t\treturn null\n\t\t}\n\t}\n\n\t/**\n\t * Returns true if the caret is on the first visual line of the element.\n\t */\n\tstatic isCaretOnFirstLine(element: HTMLElement): boolean {\n\t\tconst caretRect = this.getCaretRect()\n\t\tif (!caretRect || caretRect.height === 0) return true\n\t\tconst elRect = element.getBoundingClientRect()\n\t\treturn caretRect.top < elRect.top + caretRect.height + 2\n\t}\n\n\t/**\n\t * Returns true if the caret is on the last visual line of the element.\n\t */\n\tstatic isCaretOnLastLine(element: HTMLElement): boolean {\n\t\tconst caretRect = this.getCaretRect()\n\t\tif (!caretRect || caretRect.height === 0) return true\n\t\tconst elRect = element.getBoundingClientRect()\n\t\treturn caretRect.bottom > elRect.bottom - caretRect.height - 2\n\t}\n\n\t/**\n\t * Positions the caret in `element` at the character closest to the given x coordinate.\n\t * `y` defaults to the vertical center of the element.\n\t */\n\tstatic setAtX(element: HTMLElement, x: number, y?: number): void {\n\t\tconst elRect = element.getBoundingClientRect()\n\t\tconst targetY = y ?? elRect.top + elRect.height / 2\n\n\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- non-standard DOM APIs not in TS lib\n\t\tconst caretDoc = document as unknown as DocumentWithCaretFromPoint\n\t\tconst caretPos = caretDoc.caretRangeFromPoint?.(x, targetY) ?? caretDoc.caretPositionFromPoint?.(x, targetY)\n\n\t\tif (!caretPos) return\n\n\t\tconst sel = window.getSelection()\n\t\tif (!sel) return\n\n\t\tlet domRange: Range\n\t\tif (caretPos instanceof Range) {\n\t\t\tdomRange = caretPos\n\t\t} else if ('offsetNode' in caretPos) {\n\t\t\t// Firefox CaretPosition\n\t\t\tdomRange = document.createRange()\n\t\t\tdomRange.setStart(caretPos.offsetNode, caretPos.offset)\n\t\t\tdomRange.collapse(true)\n\t\t} else {\n\t\t\treturn\n\t\t}\n\n\t\tif (!element.contains(domRange.startContainer)) {\n\t\t\t// Clicked outside: clamp to end\n\t\t\tthis.setIndex(element, Infinity)\n\t\t\treturn\n\t\t}\n\n\t\tsel.removeAllRanges()\n\t\tsel.addRange(domRange)\n\t}\n\n\tstatic trySetIndex(element: HTMLElement, offset: number) {\n\t\ttry {\n\t\t\tthis.setIndex(element, offset)\n\t\t} catch (e) {\n\t\t\tconsole.error(e)\n\t\t}\n\t}\n\n\t/**\n\t * Sets the caret at character `offset` within `element` by walking text nodes.\n\t * Use Infinity to position at the very end of all text.\n\t */\n\tstatic setIndex(element: HTMLElement, offset: number) {\n\t\tconst selection = window.getSelection()\n\t\tif (!selection) return\n\n\t\tconst walker = document.createTreeWalker(element, 4 /* NodeFilter.SHOW_TEXT */)\n\t\tlet node = nextText(walker)\n\t\tif (!node) return\n\n\t\tlet remaining = isFinite(offset) ? Math.max(0, offset) : Infinity\n\n\t\tfor (;;) {\n\t\t\tconst next = nextText(walker)\n\t\t\tif (!next || remaining <= node.length) {\n\t\t\t\tconst charOffset = isFinite(remaining) ? Math.min(remaining, node.length) : node.length\n\t\t\t\tconst range = document.createRange()\n\t\t\t\trange.setStart(node, charOffset)\n\t\t\t\trange.collapse(true)\n\t\t\t\tselection.removeAllRanges()\n\t\t\t\tselection.addRange(range)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tremaining -= node.length\n\t\t\tnode = next\n\t\t}\n\t}\n\n\tstatic getCaretIndex(element: HTMLElement) {\n\t\tlet position = 0\n\n\t\tconst selection = window.getSelection()\n\t\t// Check if there is a selection (i.e. cursor in place)\n\t\tif (!selection?.rangeCount) return position\n\n\t\t// Store the original range\n\t\tconst range = selection.getRangeAt(0)\n\t\t// Clone the range\n\t\tconst preCaretRange = range.cloneRange()\n\t\t// Select all textual contents from the contenteditable element\n\t\tpreCaretRange.selectNodeContents(element)\n\t\t// And set the range end to the original clicked position\n\t\tpreCaretRange.setEnd(range.endContainer, range.endOffset)\n\t\t// Return the text length from contenteditable start to the range end\n\t\tposition = preCaretRange.toString().length\n\n\t\treturn position\n\t}\n\n\tstatic setCaretToEnd(element: HTMLElement | null | undefined) {\n\t\tif (!element) return\n\t\tthis.setIndex(element, Infinity)\n\t}\n\n\tstatic getIndex() {\n\t\tconst selection = window.getSelection()\n\t\treturn selection?.anchorOffset ?? NaN\n\t}\n\n\tstatic setIndex1(offset: number) {\n\t\tconst selection = window.getSelection()\n\t\tif (!selection?.anchorNode || !selection.rangeCount) return\n\n\t\tconst range = selection.getRangeAt(0)\n\t\trange.setStart(range.startContainer.firstChild ?? range.startContainer, offset)\n\t\trange.setEnd(range.startContainer.firstChild ?? range.startContainer, offset)\n\t}\n\n\tsetCaretRightTo(element: HTMLElement, offset: number) {\n\t\tconst selection = window.getSelection()\n\t\tconst range = selection?.getRangeAt(0)\n\t\trange?.setStart(range.endContainer, offset)\n\t\trange?.setEnd(range.endContainer, offset)\n\t}\n}","// escape RegExp special characters to match RegExp.escape behavior\n// Escapes all characters that have special meaning in regular expressions\nexport const escape = (str: string): string => {\n\treturn str.replace(/[.*+?^${}()|[\\]\\\\\\\\]/g, '\\\\$&')\n}","import {escape} from '../../shared/escape'\nimport type {OverlayMatch} from '../../shared/types'\nimport {Caret} from './Caret'\n\n/** Regex to match word characters from the start of a string */\nconst wordRegex = new RegExp(/^\\w*/)\n\n/**\n * Function type for extracting trigger from option\n * @template T - Type of option\n * @param option - The option object\n * @param index - Index of option in array\n * @returns Trigger string or undefined\n */\ntype TriggerExtractor<T> = (option: T, index: number) => string | undefined\n\nexport class TriggerFinder {\n\tspan: string\n\tnode: Node\n\tdividedText: {left: string; right: string}\n\n\tconstructor() {\n\t\tconst caretPosition = Caret.getCurrentPosition()\n\t\tthis.node = Caret.getSelectedNode()\n\t\tthis.span = Caret.getFocusedSpan()\n\t\tthis.dividedText = this.getDividedTextBy(caretPosition)\n\t}\n\n\t/**\n\t * Find overlay match in text using provided options and trigger extractor.\n\t * @template T - Type of option objects\n\t * @param options - Array of options to search through\n\t * @param getTrigger - Function that extracts trigger from each option\n\t * @returns OverlayMatch with correct option type or undefined\n\t *\n\t * @example\n\t * // React usage\n\t * TriggerFinder.find(options, (opt) => opt.slotProps?.overlay?.trigger ?? '@')\n\t *\n\t * @example\n\t * // Other framework usage\n\t * TriggerFinder.find(vueOptions, (opt) => opt.overlay?.trigger ?? '@')\n\t */\n\tstatic find<T>(options: T[] | undefined, getTrigger: TriggerExtractor<T>): OverlayMatch<T> | undefined {\n\t\tif (!options) return\n\t\tif (!Caret.isSelectedPosition) return\n\t\ttry {\n\t\t\treturn new TriggerFinder().find(options, getTrigger)\n\t\t} catch {\n\t\t\treturn undefined\n\t\t}\n\t}\n\n\tgetDividedTextBy(position: number) {\n\t\treturn {left: this.span.slice(0, position), right: this.span.slice(position)}\n\t}\n\n\t/**\n\t * Find overlay match in provided options.\n\t * @template T - Type of option objects\n\t * @param options - Array of options\n\t * @param getTrigger - Function to extract trigger from each option\n\t */\n\tfind<T>(options: T[], getTrigger: TriggerExtractor<T>): OverlayMatch<T> | undefined {\n\t\tfor (let i = 0; i < options.length; i++) {\n\t\t\tconst option = options[i]\n\t\t\tconst trigger = getTrigger(option, i)\n\t\t\tif (!trigger) continue\n\n\t\t\tconst match = this.matchInTextVia(trigger)\n\t\t\tif (match)\n\t\t\t\treturn {\n\t\t\t\t\tvalue: match.word,\n\t\t\t\t\tsource: match.annotation,\n\t\t\t\t\tindex: match.index,\n\t\t\t\t\tspan: this.span,\n\t\t\t\t\tnode: this.node,\n\t\t\t\t\toption,\n\t\t\t\t}\n\t\t}\n\t}\n\n\tmatchInTextVia(trigger: string = '@') {\n\t\tconst rightMatch = this.matchRightPart()\n\t\tconst leftMatch = this.matchLeftPart(trigger)\n\t\tif (leftMatch)\n\t\t\treturn {\n\t\t\t\tword: leftMatch.word + rightMatch.word,\n\t\t\t\tannotation: leftMatch.annotation + rightMatch.word,\n\t\t\t\tindex: leftMatch.index,\n\t\t\t}\n\t}\n\n\tmatchRightPart() {\n\t\tconst {right} = this.dividedText\n\t\treturn {word: right.match(wordRegex)?.[0]}\n\t}\n\n\tmatchLeftPart(trigger: string) {\n\t\tconst regex = this.makeTriggerRegex(trigger)\n\t\tconst {left} = this.dividedText\n\t\tconst match = left.match(regex)\n\n\t\tif (!match) return\n\n\t\tconst [annotation, word] = match\n\t\treturn {word, annotation, index: match.index ?? 0}\n\t}\n\n\t//TODO new overlayMatch option if (isSpaceBeforeRequired) append space check for not first words '\\\\s'\n\tmakeTriggerRegex(trigger: string): RegExp {\n\t\tconst patten = escape(trigger) + '(\\\\w*)$'\n\t\treturn new RegExp(patten)\n\t}\n}","import {Caret} from '../../features/caret'\nimport type {Store} from '../../store'\nimport {isHtmlElement, firstHtmlChild, lastHtmlChild} from '../checkers'\n\nexport class NodeProxy {\n\t#target?: HTMLElement\n\treadonly #store: Store\n\n\tget target(): HTMLElement | undefined {\n\t\treturn this.#target\n\t}\n\n\tset target(value: Node | HTMLElement | EventTarget | undefined | null) {\n\t\tthis.#target = isHtmlElement(value) ? value : undefined\n\t}\n\n\tget next() {\n\t\treturn new NodeProxy(this.target?.nextSibling, this.#store)\n\t}\n\n\tget prev() {\n\t\treturn new NodeProxy(this.target?.previousSibling, this.#store)\n\t}\n\n\tget isSpan() {\n\t\treturn this.index % 2 === 0\n\t}\n\n\tget isMark() {\n\t\treturn !this.isSpan\n\t}\n\n\tget isEditable() {\n\t\treturn this.target?.isContentEditable ?? false\n\t}\n\n\tget isCaretAtBeginning() {\n\t\tif (!this.target) return false\n\n\t\tconst caretIndex = Caret.getCaretIndex(this.target)\n\t\treturn caretIndex === 0\n\t}\n\n\tget isCaretAtEnd() {\n\t\tif (!this.target) return false\n\n\t\tconst caretIndex = Caret.getCaretIndex(this.target)\n\t\treturn caretIndex === this.target.textContent.length\n\t}\n\n\tget index() {\n\t\tif (!this.target?.parentElement) return -1\n\n\t\treturn [...this.target.parentElement.children].indexOf(this.target)\n\t}\n\n\tget caret() {\n\t\tif (this.target) return Caret.getCaretIndex(this.target)\n\t\treturn -1\n\t}\n\n\tset caret(value: number) {\n\t\tif (this.target) Caret.trySetIndex(this.target, value)\n\t}\n\n\tget length() {\n\t\treturn this.target?.textContent.length ?? -1\n\t}\n\n\tget content(): string {\n\t\treturn this.target?.textContent ?? ''\n\t}\n\n\tset content(value: string | undefined) {\n\t\tif (this.target) this.target.textContent = value ?? ''\n\t}\n\n\tget head() {\n\t\treturn firstHtmlChild(this.#store.refs.container ?? undefined)\n\t}\n\n\tget tail() {\n\t\treturn lastHtmlChild(this.#store.refs.container ?? undefined)\n\t}\n\n\tget isFocused() {\n\t\treturn this.target === document.activeElement\n\t}\n\n\tconstructor(target: Node | EventTarget | null | undefined, store: Store) {\n\t\tthis.target = target\n\t\tthis.#store = store\n\t}\n\n\tsetCaretToEnd() {\n\t\tCaret.setCaretToEnd(this.target)\n\t\treturn\n\t}\n\n\tfocus() {\n\t\tthis.target?.focus()\n\t\treturn\n\t}\n\n\tclear() {\n\t\tthis.target = undefined\n\t}\n}","export interface ReactiveNode {\n\tdeps?: Link\n\tdepsTail?: Link\n\tsubs?: Link\n\tsubsTail?: Link\n\tflags: ReactiveFlags\n}\n\nexport interface Link {\n\tversion: number\n\tdep: ReactiveNode\n\tsub: ReactiveNode\n\tprevSub: Link | undefined\n\tnextSub: Link | undefined\n\tprevDep: Link | undefined\n\tnextDep: Link | undefined\n}\n\ninterface Stack<T> {\n\tvalue: T\n\tprev: Stack<T> | undefined\n}\n\nexport const enum ReactiveFlags {\n\tNone = 0,\n\tMutable = 1,\n\tWatching = 2,\n\tRecursedCheck = 4,\n\tRecursed = 8,\n\tDirty = 16,\n\tPending = 32,\n}\n\nexport function createReactiveSystem({\n\tupdate,\n\tnotify,\n\tunwatched,\n}: {\n\tupdate(sub: ReactiveNode): boolean\n\tnotify(sub: ReactiveNode): void\n\tunwatched(sub: ReactiveNode): void\n}) {\n\treturn {\n\t\tlink,\n\t\tunlink,\n\t\tpropagate,\n\t\tcheckDirty,\n\t\tshallowPropagate,\n\t}\n\n\tfunction link(dep: ReactiveNode, sub: ReactiveNode, version: number): void {\n\t\tconst prevDep = sub.depsTail\n\t\tif (prevDep !== undefined && prevDep.dep === dep) {\n\t\t\treturn\n\t\t}\n\t\tconst nextDep = prevDep !== undefined ? prevDep.nextDep : sub.deps\n\t\tif (nextDep !== undefined && nextDep.dep === dep) {\n\t\t\tnextDep.version = version\n\t\t\tsub.depsTail = nextDep\n\t\t\treturn\n\t\t}\n\t\tconst prevSub = dep.subsTail\n\t\tif (prevSub !== undefined && prevSub.version === version && prevSub.sub === sub) {\n\t\t\treturn\n\t\t}\n\t\tconst newLink =\n\t\t\t(sub.depsTail =\n\t\t\tdep.subsTail =\n\t\t\t\t{\n\t\t\t\t\tversion,\n\t\t\t\t\tdep,\n\t\t\t\t\tsub,\n\t\t\t\t\tprevDep,\n\t\t\t\t\tnextDep,\n\t\t\t\t\tprevSub,\n\t\t\t\t\tnextSub: undefined,\n\t\t\t\t})\n\t\tif (nextDep !== undefined) {\n\t\t\tnextDep.prevDep = newLink\n\t\t}\n\t\tif (prevDep !== undefined) {\n\t\t\tprevDep.nextDep = newLink\n\t\t} else {\n\t\t\tsub.deps = newLink\n\t\t}\n\t\tif (prevSub !== undefined) {\n\t\t\tprevSub.nextSub = newLink\n\t\t} else {\n\t\t\tdep.subs = newLink\n\t\t}\n\t}\n\n\tfunction unlink(link: Link, sub = link.sub): Link | undefined {\n\t\tconst dep = link.dep\n\t\tconst prevDep = link.prevDep\n\t\tconst nextDep = link.nextDep\n\t\tconst nextSub = link.nextSub\n\t\tconst prevSub = link.prevSub\n\t\tif (nextDep !== undefined) {\n\t\t\tnextDep.prevDep = prevDep\n\t\t} else {\n\t\t\tsub.depsTail = prevDep\n\t\t}\n\t\tif (prevDep !== undefined) {\n\t\t\tprevDep.nextDep = nextDep\n\t\t} else {\n\t\t\tsub.deps = nextDep\n\t\t}\n\t\tif (nextSub !== undefined) {\n\t\t\tnextSub.prevSub = prevSub\n\t\t} else {\n\t\t\tdep.subsTail = prevSub\n\t\t}\n\t\tif (prevSub !== undefined) {\n\t\t\tprevSub.nextSub = nextSub\n\t\t} else if ((dep.subs = nextSub) === undefined) {\n\t\t\tunwatched(dep)\n\t\t}\n\t\treturn nextDep\n\t}\n\n\tfunction propagate(link: Link): void {\n\t\tlet next = link.nextSub\n\t\tlet stack: Stack<Link | undefined> | undefined\n\n\t\ttop: do {\n\t\t\tconst sub = link.sub\n\t\t\tlet flags = sub.flags\n\n\t\t\tif (\n\t\t\t\t!(\n\t\t\t\t\tflags &\n\t\t\t\t\t(ReactiveFlags.RecursedCheck | ReactiveFlags.Recursed | ReactiveFlags.Dirty | ReactiveFlags.Pending)\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tsub.flags = flags | ReactiveFlags.Pending\n\t\t\t} else if (!(flags & (ReactiveFlags.RecursedCheck | ReactiveFlags.Recursed))) {\n\t\t\t\tflags = ReactiveFlags.None\n\t\t\t} else if (!(flags & ReactiveFlags.RecursedCheck)) {\n\t\t\t\tsub.flags = (flags & ~ReactiveFlags.Recursed) | ReactiveFlags.Pending\n\t\t\t} else if (!(flags & (ReactiveFlags.Dirty | ReactiveFlags.Pending)) && isValidLink(link, sub)) {\n\t\t\t\tsub.flags = flags | (ReactiveFlags.Recursed | ReactiveFlags.Pending)\n\t\t\t\tflags &= ReactiveFlags.Mutable\n\t\t\t} else {\n\t\t\t\tflags = ReactiveFlags.None\n\t\t\t}\n\n\t\t\tif (flags & ReactiveFlags.Watching) {\n\t\t\t\tnotify(sub)\n\t\t\t}\n\n\t\t\tif (flags & ReactiveFlags.Mutable) {\n\t\t\t\tconst subSubs = sub.subs\n\t\t\t\tif (subSubs !== undefined) {\n\t\t\t\t\tconst nextSub = (link = subSubs).nextSub\n\t\t\t\t\tif (nextSub !== undefined) {\n\t\t\t\t\t\tstack = {value: next, prev: stack}\n\t\t\t\t\t\tnext = nextSub\n\t\t\t\t\t}\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif ((link = next!) !== undefined) {\n\t\t\t\tnext = link.nextSub\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\twhile (stack !== undefined) {\n\t\t\t\tlink = stack.value!\n\t\t\t\tstack = stack.prev\n\t\t\t\tif (link !== undefined) {\n\t\t\t\t\tnext = link.nextSub\n\t\t\t\t\tcontinue top\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tbreak\n\t\t} while (true)\n\t}\n\n\tfunction checkDirty(link: Link, sub: ReactiveNode): boolean {\n\t\tlet stack: Stack<Link> | undefined\n\t\tlet checkDepth = 0\n\t\tlet dirty = false\n\n\t\ttop: do {\n\t\t\tconst dep = link.dep\n\t\t\tconst flags = dep.flags\n\n\t\t\tif (sub.flags & ReactiveFlags.Dirty) {\n\t\t\t\tdirty = true\n\t\t\t} else if (\n\t\t\t\t(flags & (ReactiveFlags.Mutable | ReactiveFlags.Dirty)) ===\n\t\t\t\t(ReactiveFlags.Mutable | ReactiveFlags.Dirty)\n\t\t\t) {\n\t\t\t\tif (update(dep)) {\n\t\t\t\t\tconst subs = dep.subs!\n\t\t\t\t\tif (subs.nextSub !== undefined) {\n\t\t\t\t\t\tshallowPropagate(subs)\n\t\t\t\t\t}\n\t\t\t\t\tdirty = true\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\t(flags & (ReactiveFlags.Mutable | ReactiveFlags.Pending)) ===\n\t\t\t\t(ReactiveFlags.Mutable | ReactiveFlags.Pending)\n\t\t\t) {\n\t\t\t\tif (link.nextSub !== undefined || link.prevSub !== undefined) {\n\t\t\t\t\tstack = {value: link, prev: stack}\n\t\t\t\t}\n\t\t\t\tlink = dep.deps!\n\t\t\t\tsub = dep\n\t\t\t\t++checkDepth\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif (!dirty) {\n\t\t\t\tconst nextDep = link.nextDep\n\t\t\t\tif (nextDep !== undefined) {\n\t\t\t\t\tlink = nextDep\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t}\n\n\t\t\twhile (checkDepth--) {\n\t\t\t\tconst firstSub = sub.subs!\n\t\t\t\tconst hasMultipleSubs = firstSub.nextSub !== undefined\n\t\t\t\tif (hasMultipleSubs) {\n\t\t\t\t\tlink = stack!.value\n\t\t\t\t\tstack = stack!.prev\n\t\t\t\t} else {\n\t\t\t\t\tlink = firstSub\n\t\t\t\t}\n\t\t\t\tif (dirty) {\n\t\t\t\t\tif (update(sub)) {\n\t\t\t\t\t\tif (hasMultipleSubs) {\n\t\t\t\t\t\t\tshallowPropagate(firstSub)\n\t\t\t\t\t\t}\n\t\t\t\t\t\tsub = link.sub\n\t\t\t\t\t\tcontinue\n\t\t\t\t\t}\n\t\t\t\t\tdirty = false\n\t\t\t\t} else {\n\t\t\t\t\tsub.flags &= ~ReactiveFlags.Pending\n\t\t\t\t}\n\t\t\t\tsub = link.sub\n\t\t\t\tconst nextDep = link.nextDep\n\t\t\t\tif (nextDep !== undefined) {\n\t\t\t\t\tlink = nextDep\n\t\t\t\t\tcontinue top\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn dirty\n\t\t} while (true)\n\t}\n\n\tfunction shallowPropagate(link: Link): void {\n\t\tdo {\n\t\t\tconst sub = link.sub\n\t\t\tconst flags = sub.flags\n\t\t\tif ((flags & (ReactiveFlags.Pending | ReactiveFlags.Dirty)) === ReactiveFlags.Pending) {\n\t\t\t\tsub.flags = flags | ReactiveFlags.Dirty\n\t\t\t\tif ((flags & (ReactiveFlags.Watching | ReactiveFlags.RecursedCheck)) === ReactiveFlags.Watching) {\n\t\t\t\t\tnotify(sub)\n\t\t\t\t}\n\t\t\t}\n\t\t} while ((link = link.nextSub!) !== undefined)\n\t}\n\n\tfunction isValidLink(checkLink: Link, sub: ReactiveNode): boolean {\n\t\tlet link = sub.depsTail\n\t\twhile (link !== undefined) {\n\t\t\tif (link === checkLink) {\n\t\t\t\treturn true\n\t\t\t}\n\t\t\tlink = link.prevDep\n\t\t}\n\t\treturn false\n\t}\n}","// oxlint-disable typescript/no-explicit-any -- reactive node interfaces need flexible generic defaults\nimport {createReactiveSystem, ReactiveFlags, type ReactiveNode} from './alien-signals/system'\n\n// ---------------------------------------------------------------------------\n// Node types\n// ---------------------------------------------------------------------------\n\ninterface SignalNode<T = any> extends ReactiveNode {\n\tcurrentValue: T\n\tpendingValue: T\n\tdefaultValue: T | undefined\n\thasDefault: boolean\n\tequalsFn: ((a: T, b: T) => boolean) | undefined\n\tisReadonly: boolean\n}\n\ninterface ComputedNode<T = any> extends ReactiveNode {\n\tvalue: T | undefined\n\tgetter: (previousValue?: T) => T\n\tequalsFn: ((a: T, b: T) => boolean) | undefined\n}\n\ninterface EffectNode extends ReactiveNode {\n\tfn(): void | (() => void)\n\tcleanup?: () => void\n}\n\ninterface EventNode<T = any> extends ReactiveNode {\n\tpayload: T | undefined\n\tseq: number\n}\n\n// ---------------------------------------------------------------------------\n// Module state\n// ---------------------------------------------------------------------------\n\nlet cycle = 0\nlet batchDepth = 0\nlet notifyIndex = 0\nlet queuedLength = 0\nlet activeSub: ReactiveNode | undefined\nlet mutableScope = false\n\nconst queued: (EffectNode | undefined)[] = []\n\n// ---------------------------------------------------------------------------\n// Reactive system\n// ---------------------------------------------------------------------------\n\nconst {link, unlink, propagate, checkDirty, shallowPropagate} = createReactiveSystem({\n\tupdate(node: SignalNode | ComputedNode | EventNode): boolean {\n\t\tif ('getter' in node) {\n\t\t\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- discriminated by runtime property check\n\t\t\treturn updateComputed(node)\n\t\t}\n\t\tif ('seq' in node) {\n\t\t\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- discriminated by runtime property check\n\t\t\treturn updateEvent(node)\n\t\t}\n\t\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- discriminated by runtime property check\n\t\treturn updateSignal(node)\n\t},\n\tnotify(effect: EffectNode) {\n\t\tlet insertIndex = queuedLength\n\t\tlet firstInsertedIndex = insertIndex\n\n\t\tdo {\n\t\t\tqueued[insertIndex++] = effect\n\t\t\teffect.flags &= ~ReactiveFlags.Watching\n\t\t\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- subs chain is always an EffectNode here\n\t\t\teffect = effect.subs?.sub as EffectNode\n\t\t\t// oxlint-disable-next-line typescript/no-unnecessary-condition -- cast from sub?: ReactiveNode can be undefined\n\t\t\tif (effect === undefined || !(effect.flags & ReactiveFlags.Watching)) {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\t// oxlint-disable-next-line typescript/no-unnecessary-condition, no-constant-condition -- intentional infinite loop with break\n\t\t} while (true)\n\n\t\tqueuedLength = insertIndex\n\n\t\twhile (firstInsertedIndex < --insertIndex) {\n\t\t\tconst left = queued[firstInsertedIndex]\n\t\t\tqueued[firstInsertedIndex++] = queued[insertIndex]\n\t\t\tqueued[insertIndex] = left\n\t\t}\n\t},\n\tunwatched(node) {\n\t\tif (!(node.flags & ReactiveFlags.Mutable)) {\n\t\t\tif ('fn' in node) {\n\t\t\t\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- discriminated by runtime 'fn' in node check\n\t\t\t\tconst e = node as EffectNode\n\t\t\t\tif (e.cleanup !== undefined) {\n\t\t\t\t\te.cleanup()\n\t\t\t\t\te.cleanup = undefined\n\t\t\t\t}\n\t\t\t}\n\t\t\teffectScopeOper.call(node)\n\t\t} else if (node.depsTail !== undefined) {\n\t\t\tnode.depsTail = undefined\n\t\t\tnode.flags = ReactiveFlags.Mutable | ReactiveFlags.Dirty\n\t\t\tpurgeDeps(node)\n\t\t}\n\t},\n})\n\n// ---------------------------------------------------------------------------\n// Internal helpers\n// ---------------------------------------------------------------------------\n\nfunction setActiveSub(sub?: ReactiveNode) {\n\tconst prevSub = activeSub\n\tactiveSub = sub\n\treturn prevSub\n}\n\nfunction updateSignal(s: SignalNode): boolean {\n\ts.flags = ReactiveFlags.Mutable\n\treturn s.currentValue !== (s.currentValue = s.pendingValue)\n}\n\nfunction updateComputed(c: ComputedNode): boolean {\n\t++cycle\n\tc.depsTail = undefined\n\tc.flags = ReactiveFlags.Mutable | ReactiveFlags.RecursedCheck\n\tconst prevSub = setActiveSub(c)\n\ttry {\n\t\tconst oldValue = c.value\n\t\tconst newValue = c.getter(oldValue)\n\t\tif (c.equalsFn !== undefined && oldValue !== undefined && c.equalsFn(oldValue, newValue)) {\n\t\t\treturn false\n\t\t}\n\t\treturn oldValue !== (c.value = newValue)\n\t} finally {\n\t\tactiveSub = prevSub\n\t\tc.flags &= ~ReactiveFlags.RecursedCheck\n\t\tpurgeDeps(c)\n\t}\n}\n\nfunction updateEvent(e: EventNode): boolean {\n\te.flags = ReactiveFlags.Mutable\n\treturn true\n}\n\nfunction run(e: EffectNode): void {\n\tconst flags = e.flags\n\t// oxlint-disable-next-line typescript/no-non-null-assertion -- deps is guaranteed present when Pending\n\tif (flags & ReactiveFlags.Dirty || (flags & ReactiveFlags.Pending && checkDirty(e.deps!, e))) {\n\t\tif (e.cleanup !== undefined) {\n\t\t\te.cleanup()\n\t\t\te.cleanup = undefined\n\t\t}\n\t\t++cycle\n\t\te.depsTail = undefined\n\t\te.flags = ReactiveFlags.Watching | ReactiveFlags.RecursedCheck\n\t\tconst prevSub = setActiveSub(e)\n\t\ttry {\n\t\t\tconst result = e.fn()\n\t\t\tif (typeof result === 'function') {\n\t\t\t\te.cleanup = result as () => void\n\t\t\t}\n\t\t} finally {\n\t\t\tactiveSub = prevSub\n\t\t\te.flags &= ~ReactiveFlags.RecursedCheck\n\t\t\tpurgeDeps(e)\n\t\t}\n\t} else {\n\t\te.flags = ReactiveFlags.Watching\n\t}\n}\n\nfunction flush(): void {\n\ttry {\n\t\twhile (notifyIndex < queuedLength) {\n\t\t\t// oxlint-disable-next-line typescript/no-non-null-assertion -- index < queuedLength guarantees non-undefined\n\t\t\tconst effect = queued[notifyIndex]!\n\t\t\tqueued[notifyIndex++] = undefined\n\t\t\trun(effect)\n\t\t}\n\t} finally {\n\t\twhile (notifyIndex < queuedLength) {\n\t\t\t// oxlint-disable-next-line typescript/no-non-null-assertion -- index < queuedLength guarantees non-undefined\n\t\t\tconst effect = queued[notifyIndex]!\n\t\t\tqueued[notifyIndex++] = undefined\n\t\t\teffect.flags |= ReactiveFlags.Watching | ReactiveFlags.Recursed\n\t\t}\n\t\tnotifyIndex = 0\n\t\tqueuedLength = 0\n\t}\n}\n\nfunction purgeDeps(sub: ReactiveNode) {\n\tconst depsTail = sub.depsTail\n\tlet dep = depsTail !== undefined ? depsTail.nextDep : sub.deps\n\twhile (dep !== undefined) {\n\t\tdep = unlink(dep, sub)\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Oper functions (bound to nodes)\n// ---------------------------------------------------------------------------\n\nfunction signalOper<T>(this: SignalNode<T>, ...value: [T | undefined] | []): T | void {\n\tif (value.length) {\n\t\tif (this.isReadonly && !mutableScope) return\n\t\tconst v = value[0]\n\t\tif (v === undefined) {\n\t\t\tconst isAtDefault = this.hasDefault\n\t\t\t\t? this.pendingValue === undefined || this.pendingValue === this.defaultValue\n\t\t\t\t: this.pendingValue === undefined\n\t\t\tif (isAtDefault) return\n\t\t\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- undefined is valid for T when reverting to default\n\t\t\tthis.pendingValue = undefined as T\n\t\t} else {\n\t\t\tconst current = this.pendingValue\n\t\t\tconst effectiveCurrent = current === undefined && this.hasDefault ? this.defaultValue : current\n\t\t\tif (this.equalsFn !== undefined) {\n\t\t\t\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- effectiveCurrent is T when equalsFn is defined and either current !== undefined or hasDefault\n\t\t\t\tif (this.equalsFn(effectiveCurrent as T, v)) return\n\t\t\t} else {\n\t\t\t\tif (effectiveCurrent === v) return\n\t\t\t}\n\t\t\tthis.pendingValue = v\n\t\t}\n\t\tthis.flags = ReactiveFlags.Mutable | ReactiveFlags.Dirty\n\t\tconst subs = this.subs\n\t\tif (subs !== undefined) {\n\t\t\tpropagate(subs)\n\t\t\tif (!batchDepth) {\n\t\t\t\tflush()\n\t\t\t}\n\t\t}\n\t} else {\n\t\tif (this.flags & ReactiveFlags.Dirty) {\n\t\t\tif (updateSignal(this)) {\n\t\t\t\tconst subs = this.subs\n\t\t\t\tif (subs !== undefined) {\n\t\t\t\t\tshallowPropagate(subs)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// Walk to the nearest subscriber with Mutable or Watching flags.\n\t\t// Needed when activeSub is a non-tracking scope node (e.g. effectScope with flags: None)\n\t\t// rather than a computed/effect. computedOper/eventReadOper can link directly because they\n\t\t// are only called inside reactive contexts that guarantee a valid subscriber, but signals\n\t\t// may be read in broader scopes.\n\t\tlet sub = activeSub\n\t\twhile (sub !== undefined) {\n\t\t\tif (sub.flags & (ReactiveFlags.Mutable | ReactiveFlags.Watching)) {\n\t\t\t\tlink(this, sub, cycle)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tsub = sub.subs?.sub\n\t\t}\n\t\tconst v = this.currentValue\n\t\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- defaultValue is T when hasDefault is true\n\t\tif (v === undefined && this.hasDefault) return this.defaultValue as T\n\t\treturn v\n\t}\n}\n\nfunction computedOper<T>(this: ComputedNode<T>): T {\n\tconst flags = this.flags\n\t// oxlint-disable-next-line typescript/no-non-null-assertion -- deps is guaranteed present when Pending\n\tconst deps = this.deps!\n\tif (\n\t\tflags & ReactiveFlags.Dirty ||\n\t\t(flags & ReactiveFlags.Pending &&\n\t\t\t// oxlint-disable-next-line typescript/no-unnecessary-condition -- comma expr with false is intentional for side effect\n\t\t\t(checkDirty(deps, this) || ((this.flags = flags & ~ReactiveFlags.Pending), false)))\n\t) {\n\t\tif (updateComputed(this)) {\n\t\t\tconst subs = this.subs\n\t\t\tif (subs !== undefined) {\n\t\t\t\tshallowPropagate(subs)\n\t\t\t}\n\t\t}\n\t} else if (!flags) {\n\t\tthis.flags = ReactiveFlags.Mutable | ReactiveFlags.RecursedCheck\n\t\tconst prevSub = setActiveSub(this)\n\t\ttry {\n\t\t\tthis.value = this.getter()\n\t\t} finally {\n\t\t\tactiveSub = prevSub\n\t\t\tthis.flags &= ~ReactiveFlags.RecursedCheck\n\t\t}\n\t}\n\tconst sub = activeSub\n\tif (sub !== undefined) {\n\t\tlink(this, sub, cycle)\n\t}\n\t// oxlint-disable-next-line typescript/no-non-null-assertion -- value is always set before read\n\treturn this.value!\n}\n\nfunction eventReadOper<T>(this: EventNode<T>): T | undefined {\n\tif (this.flags & ReactiveFlags.Dirty) {\n\t\tupdateEvent(this)\n\t}\n\tconst sub = activeSub\n\tif (sub !== undefined) {\n\t\tlink(this, sub, cycle)\n\t}\n\treturn this.payload\n}\n\nfunction effectOper(this: EffectNode): void {\n\tif (this.cleanup !== undefined) {\n\t\tthis.cleanup()\n\t\tthis.cleanup = undefined\n\t}\n\teffectScopeOper.call(this)\n}\n\nfunction effectScopeOper(this: ReactiveNode): void {\n\tthis.depsTail = undefined\n\tthis.flags = ReactiveFlags.None\n\tpurgeDeps(this)\n\tconst sub = this.subs\n\tif (sub !== undefined) {\n\t\tunlink(sub)\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// Signal<T> — reactive state value\n// ---------------------------------------------------------------------------\n\nexport interface Signal<T> {\n\t(): T\n\t(value: T | undefined): void\n}\n\nexport type SignalValues<T> = {\n\t[K in keyof T]: T[K] extends Signal<infer V> | Computed<infer V> ? V : T[K]\n}\n\nexport function isReactive(fn: unknown): fn is Signal<unknown> | Computed<unknown> {\n\tif (typeof fn !== 'function') return false\n\tconst name = (fn as {name: string}).name\n\treturn name === 'bound ' + signalOper.name || name === 'bound ' + computedOper.name\n}\n\ninterface SignalOptions<T> {\n\tequals?: (a: T, b: T) => boolean\n\treadonly?: boolean\n}\n\nexport function signal<T>(initial: T, opts?: SignalOptions<T>): Signal<T> {\n\tconst node: SignalNode<T> = {\n\t\tcurrentValue: initial,\n\t\tpendingValue: initial,\n\t\tdefaultValue: initial,\n\t\thasDefault: initial !== undefined,\n\t\tequalsFn: opts?.equals ?? undefined,\n\t\tisReadonly: !!opts?.readonly,\n\t\tsubs: undefined,\n\t\tsubsTail: undefined,\n\t\tflags: ReactiveFlags.Mutable,\n\t}\n\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- callable matches Signal<T> interface but TS can't verify the overloaded call signature\n\treturn (signalOper as (this: SignalNode<T>, ...value: [T | undefined] | []) => T | void).bind(\n\t\tnode\n\t) as unknown as Signal<T>\n}\n\n// ---------------------------------------------------------------------------\n// Computed<T> — derived reactive value\n// ---------------------------------------------------------------------------\n\nexport interface Computed<T> {\n\t(): T\n}\n\ninterface ComputedOptions<T> {\n\tequals?: (a: T, b: T) => boolean\n}\n\nexport function computed<T>(getter: (previousValue?: T) => T, opts?: ComputedOptions<T>): Computed<T> {\n\tconst node: ComputedNode<T> = {\n\t\tvalue: undefined,\n\t\tsubs: undefined,\n\t\tsubsTail: undefined,\n\t\tdeps: undefined,\n\t\tdepsTail: undefined,\n\t\tflags: ReactiveFlags.None,\n\t\tgetter: getter as (previousValue?: T) => T,\n\t\tequalsFn: opts?.equals ?? undefined,\n\t}\n\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- callable matches Computed<T> interface but TS can't verify the call signature\n\treturn (computedOper as (this: ComputedNode<T>) => T).bind(node) as unknown as Computed<T>\n}\n\n// ---------------------------------------------------------------------------\n// Event<T> — unified reactive event primitive\n// ---------------------------------------------------------------------------\n\nexport interface Event<T = void> {\n\t(payload: T): void\n\tread(): T | undefined\n}\n\nexport function event<T = void>(): Event<T> {\n\tconst node: EventNode<T> = {\n\t\tpayload: undefined,\n\t\tseq: 0,\n\t\tsubs: undefined,\n\t\tsubsTail: undefined,\n\t\tflags: ReactiveFlags.Mutable,\n\t}\n\n\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- callable matches Event<T> interface but TS can't verify the call signature\n\tconst callable = function eventCallable(payload: T) {\n\t\tnode.payload = payload\n\t\tnode.seq++\n\t\tnode.flags = ReactiveFlags.Mutable | ReactiveFlags.Dirty\n\t\tconst subs = node.subs\n\t\tif (subs !== undefined) {\n\t\t\tpropagate(subs)\n\t\t\tif (!batchDepth) {\n\t\t\t\tflush()\n\t\t\t}\n\t\t}\n\t} as unknown as Event<T>\n\n\tcallable.read = (eventReadOper as (this: EventNode<T>) => T | undefined).bind(node)\n\n\treturn callable\n}\n\n// ---------------------------------------------------------------------------\n// effect() / effectScope()\n// ---------------------------------------------------------------------------\n\nexport {alienEffect as effect}\n\nfunction alienEffect(fn: () => void | (() => void)): () => void {\n\tconst e: EffectNode = {\n\t\tfn,\n\t\tcleanup: undefined,\n\t\tsubs: undefined,\n\t\tsubsTail: undefined,\n\t\tdeps: undefined,\n\t\tdepsTail: undefined,\n\t\tflags: ReactiveFlags.Watching | ReactiveFlags.RecursedCheck,\n\t}\n\tconst prevSub = setActiveSub(e)\n\tif (prevSub !== undefined) {\n\t\tlink(e, prevSub, 0)\n\t}\n\ttry {\n\t\tconst result = e.fn()\n\t\tif (typeof result === 'function') {\n\t\t\te.cleanup = result as () => void\n\t\t}\n\t} finally {\n\t\tactiveSub = prevSub\n\t\te.flags &= ~ReactiveFlags.RecursedCheck\n\t}\n\treturn effectOper.bind(e)\n}\n\nexport function effectScope(fn: () => void): () => void {\n\tconst e: ReactiveNode = {\n\t\tdeps: undefined,\n\t\tdepsTail: undefined,\n\t\tsubs: undefined,\n\t\tsubsTail: undefined,\n\t\tflags: ReactiveFlags.None,\n\t}\n\tconst prevSub = setActiveSub(e)\n\tif (prevSub !== undefined) {\n\t\tlink(e, prevSub, 0)\n\t}\n\ttry {\n\t\tfn()\n\t} finally {\n\t\tactiveSub = prevSub\n\t}\n\treturn effectScopeOper.bind(e)\n}\n\n// ---------------------------------------------------------------------------\n// watch() — skip-first-run helper for event subscriptions\n// ---------------------------------------------------------------------------\n\nexport function watch<T>(dep: Signal<T>, fn: (newValue: T, oldValue: T | undefined) => void): () => void\nexport function watch<T>(dep: Event<T>, fn: (newValue: T, oldValue: T | undefined) => void): () => void\nexport function watch<T>(dep: () => T, fn: (newValue: T, oldValue: T | undefined) => void): () => void\nexport function watch<T>(\n\tdep: Signal<T> | Event<T> | (() => T),\n\tfn: (newValue: T, oldValue: T | undefined) => void\n): () => void {\n\tlet initialized = false\n\tlet oldValue: T | undefined\n\treturn alienEffect(() => {\n\t\t// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Event<T> returns T | undefined before first emit, but watch skips the first run so callback always receives T\n\t\tconst newValue = ('read' in dep ? dep.read() : dep()) as T\n\t\tif (!initialized) {\n\t\t\tinitialized = true\n\t\t\toldValue = newValue\n\t\t\treturn\n\t\t}\n\t\tconst prev = oldValue\n\t\toldValue = newValue\n\t\tuntracked(() => fn(newValue, prev))\n\t})\n}\n\n// ---------------------------------------------------------------------------\n// batch() — defer effect flush until callback completes\n// ---------------------------------------------------------------------------\n\ninterface BatchOptions {\n\tmutable?: boolean\n}\n\nexport function batch(fn: () => void, opts?: BatchOptions): void {\n\tconst prevMutable = mutableScope\n\tif (opts?.mutable) mutableScope = true\n\t++batchDepth\n\ttry {\n\t\tfn()\n\t} finally {\n\t\tif (!--batchDepth) {\n\t\t\tflush()\n\t\t}\n\t\tmutableScope = prevMutable\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// trigger() — re-run code that reads signals and propagate the result\n// ---------------------------------------------------------------------------\n\nexport function trigger(fn: () => void) {\n\tconst sub: ReactiveNode = {\n\t\tdeps: undefined,\n\t\tdepsTail: undefined,\n\t\tflags: ReactiveFlags.Watching,\n\t}\n\tconst prevSub = setActiveSub(sub)\n\ttry {\n\t\tfn()\n\t} finally {\n\t\tactiveSub = prevSub\n\t\tlet dep = sub.deps\n\t\twhile (dep !== undefined) {\n\t\t\tconst subs = dep.dep.subs\n\t\t\tdep = unlink(dep, sub)\n\t\t\tif (subs !== undefined) {\n\t\t\t\tsub.flags = ReactiveFlags.None\n\t\t\t\tpropagate(subs)\n\t\t\t\tshallowPropagate(subs)\n\t\t\t}\n\t\t}\n\t\tif (!batchDepth) {\n\t\t\tflush()\n\t\t}\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// untracked() — run a function without tracking reactive dependencies\n// ---------------------------------------------------------------------------\n\nexport function untracked<T>(fn: () => T): T {\n\tconst prev = setActiveSub(undefined)\n\ttry {\n\t\treturn fn()\n\t} finally {\n\t\tsetActiveSub(prev)\n\t}\n}\n\n// ---------------------------------------------------------------------------\n// listen() — scope-aware DOM event listener\n// ---------------------------------------------------------------------------\n\nexport function listen<K extends keyof WindowEventMap>(\n\ttarget: Window,\n\tevent: K,\n\thandler: (e: WindowEventMap[K]) => void,\n\toptions?: boolean | AddEventListenerOptions\n): () => void\nexport function listen<K extends keyof DocumentEventMap>(\n\ttarget: Document,\n\tevent: K,\n\thandler: (e: DocumentEventMap[K]) => void,\n\toptions?: boolean | AddEventListenerOptions\n): () => void\nexport function listen<K extends keyof HTMLElementEventMap>(\n\ttarget: HTMLElement,\n\tevent: K,\n\thandler: (e: HTMLElementEventMap[K]) => void,\n\toptions?: boolean | AddEventListenerOptions\n): () => void\nexport function listen(\n\ttarget: EventTarget,\n\tevent: string,\n\thandler: EventListenerOrEventListenerObject,\n\toptions?: boolean | AddEventListenerOptions\n): () => void\nexport function listen(\n\ttarget: EventTarget,\n\tevent: string,\n\thandler: EventListenerOrEventListenerObject,\n\toptions?: boolean | AddEventListenerOptions\n): () => void {\n\treturn alienEffect(() => {\n\t\ttarget.addEventListener(event, handler, options)\n\t\treturn () => target.removeEventListener(event, handler, options)\n\t})\n}","/**\n * Constants for ParserV2 - modern markup parser with nesting support\n *\n * This module contains the placeholder constants used by ParserV2.\n * Unlike the legacy Parser, ParserV2 supports:\n * - `__value__` - main content (replaces `__label__`)\n * - `__meta__` - metadata (replaces `__value__`)\n * - `__slot__` - nested content (new feature)\n *\n * For legacy Parser compatibility, see ../Parser/constants.ts\n * For Markup types, see ./types.ts\n */\nexport const PLACEHOLDER = {\n\tValue: '__value__',\n\tMeta: '__meta__',\n\tSlot: '__slot__',\n} as const\n\n/**\n * Gap types used in markup descriptors\n * Represents the content type in gaps between segments\n */\nexport const GAP_TYPE = {\n\tValue: 'value',\n\tMeta: 'meta',\n\tSlot: 'slot',\n} as const\n\nexport type GapType = (typeof GAP_TYPE)[keyof typeof GAP_TYPE]","import type {GapType} from '../constants'\nimport {GAP_TYPE, PLACEHOLDER} from '../constants'\nimport type {Markup} from '../types'\nimport type {SegmentDefinition} from './SegmentMatcher'\n\n/**\n * Descriptor for segment-based markup parsing\n * Converts markup templates into arrays of static or dynamic segments\n */\nexport interface MarkupDescriptor {\n\t/** Original markup template string */\n\tmarkup: Markup\n\t/** Index of this markup in the original markups array */\n\tindex: number\n\t/** Array of segment definitions (can be static strings or dynamic patterns) */\n\tsegments: SegmentDefinition[]\n\t/** Type of content in each gap between segments */\n\tgapTypes: GapType[]\n\t/** True if this markup contains a __slot__ placeholder */\n\thasSlot: boolean\n\t/** True if this markup contains exactly two __value__ placeholders */\n\thasTwoValues: boolean\n\t/** Global indices of segments in registry segments array (parallel to segments array) */\n\tsegmentGlobalIndices: number[]\n}\n\n/**\n * Creates a segment-based markup descriptor from a markup template\n *\n * Examples:\n * - `#[__value__]` -> segments: [\"#[\", \"]\"], gapTypes: [\"value\"]\n * - `#[__slot__]` -> segments: [\"#[\", \"]\"], gapTypes: [\"slot\"]\n * - `@[__value__](__meta__)` -> segments: [\"@[\", \"](\", \")\"], gapTypes: [\"value\", \"meta\"]\n * - `@[__slot__](__meta__)` -> segments: [\"@[\", \"](\", \")\"], gapTypes: [\"slot\", \"meta\"]\n * - `@[__value__](__slot__)` -> segments: [\"@[\", \"](\", \")\"], gapTypes: [\"value\", \"slot\"]\n * - `<__value__>__meta__</__value__>` -> segments: [{pattern: '<([^>]+)>'}, {pattern: '</([^>]+)>'}], gapTypes: [\"value\", \"meta\", \"value\"] (dynamic)\n * - `<__value__ __meta__>__slot__</__value__>` -> segments: [{pattern: '<([^> ]+) '}, \" \", {pattern: '>__slot__</([^>]+)>'}], gapTypes: [\"value\", \"meta\", \"slot\", \"value\"] (dynamic)\n */\nexport function createMarkupDescriptor(markup: Markup, index: number): MarkupDescriptor {\n\tconst {segments: rawSegments, gapTypes: rawGapTypes, counts, valueGapIndices} = scanMarkupStructure(markup)\n\n\tvalidateMarkup(counts, markup)\n\n\tconst hasTwoValues = counts.value === 2\n\n\tconst {segments, gapTypes} = hasTwoValues\n\t\t? convertTwoValuePattern(rawSegments, rawGapTypes, valueGapIndices)\n\t\t: {segments: rawSegments, gapTypes: rawGapTypes}\n\n\treturn {\n\t\tmarkup,\n\t\tindex,\n\t\tsegments,\n\t\tgapTypes,\n\t\thasSlot: counts.slot === 1,\n\t\thasTwoValues,\n\t\tsegmentGlobalIndices: Array.from({length: segments.length}), // Will be populated by MarkupRegistry\n\t}\n}\n\n/**\n * Maps placeholder types to their text representations\n */\nconst PLACEHOLDER_TEXT: Record<GapType, string> = {\n\t[GAP_TYPE.Value]: PLACEHOLDER.Value,\n\t[GAP_TYPE.Meta]: PLACEHOLDER.Meta,\n\t[GAP_TYPE.Slot]: PLACEHOLDER.Slot,\n} as const\n\n/**\n * Parses markup template into segments, gap types and placeholder counts\n */\nfunction scanMarkupStructure(markup: string) {\n\tconst segments: string[] = []\n\tconst gapTypes: GapType[] = []\n\tconst valueGapIndices: number[] = []\n\tconst counts: Record<GapType, number> = {\n\t\tvalue: 0,\n\t\tmeta: 0,\n\t\tslot: 0,\n\t}\n\n\t// Find all placeholders and sort by position\n\tconst placeholders: Array<{type: GapType; position: number}> = []\n\tconst placeholderTypes = [GAP_TYPE.Value, GAP_TYPE.Meta, GAP_TYPE.Slot] as const\n\n\tfor (const type of placeholderTypes) {\n\t\tconst text = PLACEHOLDER_TEXT[type]\n\t\tlet position = markup.indexOf(text)\n\t\twhile (position !== -1) {\n\t\t\tplaceholders.push({type, position})\n\t\t\tposition = markup.indexOf(text, position + text.length)\n\t\t}\n\t}\n\n\tplaceholders.sort((a, b) => a.position - b.position)\n\n\t// Process placeholders in order\n\tlet currentParsePosition = 0\n\tfor (const placeholder of placeholders) {\n\t\tconst segment = markup.substring(currentParsePosition, placeholder.position)\n\t\tif (segment.length > 0) {\n\t\t\tsegments.push(segment)\n\t\t}\n\n\t\tgapTypes.push(placeholder.type)\n\t\tcounts[placeholder.type]++\n\n\t\tif (placeholder.type === GAP_TYPE.Value) {\n\t\t\tvalueGapIndices.push(gapTypes.length - 1)\n\t\t}\n\n\t\tcurrentParsePosition = placeholder.position + PLACEHOLDER_TEXT[placeholder.type].length\n\t}\n\n\tconst finalSegment = markup.substring(currentParsePosition)\n\tif (finalSegment.length > 0) {\n\t\tsegments.push(finalSegment)\n\t}\n\n\treturn {\n\t\tsegments,\n\t\tgapTypes,\n\t\tcounts,\n\t\tvalueGapIndices,\n\t}\n}\n\n/**\n * Validates markup placeholder counts\n */\nfunction validateMarkup(counts: Record<GapType, number>, markup: string): void {\n\tconst rules = [\n\t\t{count: counts.value, max: 2, name: PLACEHOLDER.Value},\n\t\t{count: counts.meta, max: 1, name: PLACEHOLDER.Meta},\n\t\t{count: counts.slot, max: 1, name: PLACEHOLDER.Slot},\n\t]\n\n\tfor (const {count, max, name} of rules) {\n\t\tif (count > max) {\n\t\t\tthrow new Error(`Invalid markup: \"${markup}\". Max ${max} \"${name}\" placeholders, got ${count}`)\n\t\t}\n\t}\n\n\tif (counts.value === 0 && counts.slot === 0) {\n\t\tthrow new Error(\n\t\t\t`Invalid markup: \"${markup}\". Need at least one \"${PLACEHOLDER.Value}\" or \"${PLACEHOLDER.Slot}\"`\n\t\t)\n\t}\n}\n\n/**\n * Converts static segments around __value__ placeholders to dynamic patterns\n * For pattern like <__value__>__meta__</__value__>:\n * - Original: segments [\"<\", \">\", \"</\", \">\"], gapTypes [\"value\", \"meta\", \"value\"]\n * - Result: segments [['<', '>', exclusions], ['</', '>', exclusions]], gapTypes [\"meta\"]\n * Dynamic segments \"absorb\" the __value__ gaps they surround\n */\nfunction convertTwoValuePattern(\n\tsegments: string[],\n\tgapTypes: GapType[],\n\tvalueGapIndices: number[]\n): {segments: SegmentDefinition[]; gapTypes: GapType[]} {\n\tif (valueGapIndices.length !== 2) {\n\t\treturn {segments, gapTypes}\n\t}\n\n\tconst [firstValueGapIdx, secondValueGapIdx] = valueGapIndices\n\n\tconst newSegments: SegmentDefinition[] = []\n\n\tconst beforeFirst = segments[firstValueGapIdx]\n\tconst afterFirst = segments[firstValueGapIdx + 1]\n\tif (beforeFirst && afterFirst) {\n\t\tnewSegments.push(createDynamicDefinition(beforeFirst, afterFirst, segments[firstValueGapIdx + 2]))\n\t}\n\n\tfor (let i = firstValueGapIdx + 2; i < secondValueGapIdx; i++) {\n\t\tnewSegments.push(segments[i])\n\t}\n\n\tconst beforeSecond = segments[secondValueGapIdx]\n\tconst afterSecond = segments[secondValueGapIdx + 1]\n\tif (beforeSecond && afterSecond) {\n\t\tnewSegments.push(createDynamicDefinition(beforeSecond, afterSecond, segments[secondValueGapIdx + 2]))\n\t}\n\n\tconst filteredGapTypes = gapTypes.filter(type => type !== GAP_TYPE.Value)\n\n\treturn {segments: newSegments, gapTypes: filteredGapTypes}\n}\n\nfunction createDynamicDefinition(\n\tbeforeSegment: string,\n\tafterSegment: string,\n\tnextSegment?: string\n): [string, string, string] {\n\tif (!nextSegment) return [beforeSegment, afterSegment, '']\n\n\tconst firstChar = nextSegment.charAt(0)\n\tconst exclusion =\n\t\tfirstChar && !afterSegment.includes(firstChar) && !nextSegment.startsWith(beforeSegment) ? firstChar : ''\n\n\treturn [beforeSegment, afterSegment, exclusion]\n}","import type {Markup} from '../types'\nimport type {MarkupDescriptor} from './MarkupDescriptor'\nimport {createMarkupDescriptor} from './MarkupDescriptor'\nimport type {SegmentDefinition} from './SegmentMatcher'\n\nfunction getOrCreate<K, V>(map: Map<K, V[]>, key: K): V[] {\n\tlet arr = map.get(key)\n\tif (!arr) {\n\t\tarr = []\n\t\tmap.set(key, arr)\n\t}\n\treturn arr\n}\n\n/**\n * Registry for managing markup descriptors\n * Centralizes access to all markup patterns and their descriptors\n */\nexport class MarkupRegistry {\n\treadonly markups: (Markup | undefined)[]\n\treadonly descriptors: MarkupDescriptor[]\n\t/** Deduplicated list of unique segment definitions (static strings or dynamic patterns) */\n\treadonly segments: SegmentDefinition[] = []\n\t/** Map from first segment index to descriptors that start with this segment (for O(1) lookup) */\n\treadonly firstSegmentIndexMap: Map<number, MarkupDescriptor[]> = new Map()\n\n\tconstructor(markups: (Markup | undefined)[]) {\n\t\tthis.markups = markups\n\n\t\tconst segmentIndexMap = new Map<string, number>()\n\n\t\tthis.descriptors = markups\n\t\t\t.map((markup, index) => {\n\t\t\t\t// Skip undefined markups but preserve original indices\n\t\t\t\tif (markup === undefined) {\n\t\t\t\t\treturn null\n\t\t\t\t}\n\n\t\t\t\tconst descriptor = createMarkupDescriptor(markup, index)\n\n\t\t\t\t// Process segments and register them\n\t\t\t\tdescriptor.segments.forEach((segment, segmentIndex) => {\n\t\t\t\t\tthis.processSegment(descriptor, segment, segmentIndex, segmentIndexMap)\n\t\t\t\t})\n\n\t\t\t\tthis.addToFirstSegmentIndexMap(descriptor)\n\n\t\t\t\treturn descriptor\n\t\t\t})\n\t\t\t.filter((descriptor): descriptor is MarkupDescriptor => descriptor !== null)\n\t}\n\n\t/**\n\t * Adds a descriptor to the firstSegmentIndexMap using its first segment's global index\n\t */\n\tprivate addToFirstSegmentIndexMap(descriptor: MarkupDescriptor): void {\n\t\tconst firstSegmentIndex = descriptor.segmentGlobalIndices[0]\n\n\t\tgetOrCreate(this.firstSegmentIndexMap, firstSegmentIndex).push(descriptor)\n\t}\n\n\tprivate processSegment(\n\t\tdescriptor: MarkupDescriptor,\n\t\tsegment: SegmentDefinition,\n\t\tsegmentIndex: number,\n\t\tsegmentIndexMap: Map<string, number>\n\t): void {\n\t\tconst segmentKey = this.getSegmentKey(segment)\n\t\tif (!segmentKey) return\n\n\t\tconst globalIndex = this.registerSegment(segment, segmentKey, segmentIndexMap)\n\n\t\tdescriptor.segmentGlobalIndices[segmentIndex] = globalIndex\n\n\t\t// Register static parts of dynamic segments\n\t\tif (typeof segment !== 'string') {\n\t\t\tconst [before, after] = segment\n\t\t\tif (before) {\n\t\t\t\tthis.registerSegment(before, before, segmentIndexMap)\n\t\t\t}\n\t\t\tif (after) {\n\t\t\t\tthis.registerSegment(after, after, segmentIndexMap)\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate registerSegment(\n\t\tsegment: SegmentDefinition,\n\t\tsegmentKey: string,\n\t\tsegmentIndexMap: Map<string, number>\n\t): number {\n\t\tconst existing = segmentIndexMap.get(segmentKey)\n\t\tif (existing !== undefined) return existing\n\t\tconst globalIndex = this.segments.length\n\t\tthis.segments.push(segment)\n\t\tsegmentIndexMap.set(segmentKey, globalIndex)\n\t\treturn globalIndex\n\t}\n\n\t/**\n\t * Gets a unique key for a segment definition\n\t * For static segments (strings), returns the string itself if non-empty\n\t * For dynamic segments (arrays), returns before|after|exclusions if before or after is non-empty\n\t * Returns empty string for segments that should be ignored\n\t */\n\tprivate getSegmentKey(segment: SegmentDefinition): string {\n\t\tif (typeof segment === 'string') {\n\t\t\treturn segment\n\t\t}\n\t\t// For dynamic segments, create a key from before+after+exclusions\n\t\tconst [before, after, exclusions] = segment\n\t\t// Only return a key if there's something to match (before or after is non-empty)\n\t\tif (before || after) {\n\t\t\treturn `${before}|${after}|${exclusions}`\n\t\t}\n\t\treturn ''\n\t}\n}","/**\n * Creates a value-specific index using djb2 hash algorithm for dynamic segments\n * For static segments, returns the base index directly to avoid unnecessary hashing\n *\n * @param baseIndex - The base index of the segment type\n * @param value - The actual value of the segment (optional, for dynamic segments only)\n * @returns Value-specific index for dynamic segments, or base index for static segments\n */\nexport function getSegmentIndex(baseIndex: number, value?: string): number {\n\tif (!value) {\n\t\treturn baseIndex\n\t}\n\n\tlet hash = 5381\n\tfor (let i = 0; i < value.length; i++) {\n\t\thash = (hash * 33) ^ value.charCodeAt(i)\n\t}\n\thash = hash >>> 0 // Unsigned 32-bit integer\n\n\treturn baseIndex * 1000000 + (hash & 0xfffff)\n}","import type {GapType} from '../constants'\nimport type {PositionRange} from '../types'\nimport {getSegmentIndex} from '../utils/getSegmentIndex'\nimport type {MarkupDescriptor} from './MarkupDescriptor'\nimport type {SegmentMatch} from './SegmentMatcher'\n\n/**\n * Unified match structure for pattern matching states\n *\n * Represents the state of a pattern matching process in the parser's state machine:\n * - Active: tracks progress through pattern segments (expectedSegmentIndex >= 0)\n * - Completed: all segments found, match is valid (expectedSegmentIndex = NaN)\n * - Invalid: match cannot be completed due to malformed segments (expectedSegmentIndex = -1)\n *\n * State detection:\n * - isCompleted: expectedSegmentIndex is NaN\n * - isInvalid: expectedSegmentIndex is -1\n * - isActive: expectedSegmentIndex >= 0 (not NaN and not -1)\n */\n\nexport class Match {\n\tpublic readonly gaps: Partial<Record<GapType, PositionRange>> = {}\n\t/** Captured value from first dynamic segment (for hasTwoValues patterns) */\n\tprivate readonly captured?: string\n\n\t/**\n\t * Index of expected next segment:\n\t * - >= 0: active, waiting for segment at this index\n\t * - NaN: completed successfully\n\t * - -1: invalid, should be discarded\n\t */\n\tpublic expectedSegmentIndex: number\n\tpublic start: number\n\tpublic end: number\n\n\tconstructor(\n\t\tpublic readonly descriptor: MarkupDescriptor,\n\t\tfirstSegment: SegmentMatch\n\t) {\n\t\tthis.expectedSegmentIndex = 1\n\t\tthis.start = firstSegment.start\n\t\tthis.end = firstSegment.end\n\n\t\t// Auto-complete single segment patterns\n\t\tif (descriptor.segments.length === 1) {\n\t\t\tthis.expectedSegmentIndex = NaN\n\n\t\t\t//TODO need review it. before it was only value gap type\n\t\t\tconst gapType = descriptor.gapTypes[0] ?? 'value'\n\t\t\tif (gapType === 'slot') {\n\t\t\t\t// Slot-leading: real range resolved by PatternMatcher.resolveSlotLeadingMatches\n\t\t\t\tthis.gaps.slot = {start: this.start, end: this.start}\n\t\t\t} else {\n\t\t\t\tthis.gaps[gapType] = {start: this.start, end: this.end}\n\t\t\t}\n\t\t}\n\n\t\tif (descriptor.hasTwoValues && firstSegment.captured) {\n\t\t\tthis.captured = firstSegment.captured\n\t\t\tconst capturedStart = firstSegment.start + firstSegment.value.indexOf(firstSegment.captured)\n\t\t\tconst capturedEnd = capturedStart + firstSegment.captured.length\n\t\t\tthis.gaps.value = {start: capturedStart, end: capturedEnd}\n\t\t}\n\t}\n\n\t/**\n\t * Check if the match is invalid and should be discarded\n\t */\n\tget isInvalid(): boolean {\n\t\treturn this.expectedSegmentIndex === -1\n\t}\n\n\t/**\n\t * Check if the pattern is completed (computed property)\n\t */\n\tget isCompleted(): boolean {\n\t\treturn isNaN(this.expectedSegmentIndex)\n\t}\n\n\t/**\n\t * Check if the match is waiting for the last segment (high priority)\n\t */\n\tget isAwaitingLastSegment(): boolean {\n\t\treturn this.expectedSegmentIndex === this.descriptor.segments.length - 1\n\t}\n\n\t/**\n\t * Get the next expected segment index\n\t */\n\tget nextSegment(): number | undefined {\n\t\tif (this.isCompleted || this.isInvalid) {\n\t\t\treturn undefined\n\t\t}\n\n\t\tconst baseIndex = this.descriptor.segmentGlobalIndices[this.expectedSegmentIndex]\n\t\tconst segmentDef = this.descriptor.segments[this.expectedSegmentIndex]\n\n\t\t// Only hash for hasTwoValues closing tags that need value-specific matching\n\t\tif (\n\t\t\ttypeof segmentDef === 'object' &&\n\t\t\tthis.descriptor.hasTwoValues &&\n\t\t\tthis.captured &&\n\t\t\tthis.isAwaitingLastSegment\n\t\t) {\n\t\t\tconst [before, after] = segmentDef\n\t\t\tconst value = before + this.captured + after\n\t\t\treturn getSegmentIndex(baseIndex, value)\n\t\t}\n\n\t\treturn baseIndex\n\t}\n\n\t/**\n\t * Update state with new segment by setting gap positions\n\t */\n\tprocessNext(segment: SegmentMatch): void {\n\t\tconst start = this.end\n\t\tconst end = segment.start\n\t\tconst gapType = this.descriptor.gapTypes[this.expectedSegmentIndex - 1]\n\n\t\t// VALIDATION: Next segment must start after previous segment ends\n\t\t// If not, this match is permanently invalid\n\t\tif (end < start) {\n\t\t\tthis.expectedSegmentIndex = -1\n\t\t\treturn\n\t\t}\n\n\t\tthis.gaps[gapType] = {start, end}\n\n\t\tthis.end = segment.end\n\t\tthis.expectedSegmentIndex++\n\n\t\t// Auto-complete if all segments are processed\n\t\tif (this.expectedSegmentIndex >= this.descriptor.segments.length) {\n\t\t\tthis.expectedSegmentIndex = NaN\n\t\t}\n\t}\n\n\t/**\n\t * Checks if this match conflicts with another match (overlaps and cannot nest properly)\n\t */\n\tconflictsWith(previousMatch?: Match | null): boolean {\n\t\t// No conflict if there's no previous match to conflict with\n\t\tif (!previousMatch) return false\n\n\t\t// No conflict if there's no overlap\n\t\tif (this.start >= previousMatch.end) return false\n\n\t\t// If there's overlap, check if it's valid nesting\n\t\tif (!previousMatch.descriptor.hasSlot) return true\n\t\tif (previousMatch.gaps.slot === undefined) return true\n\n\t\t// Valid nesting: this match is completely inside the slot section\n\t\treturn !(this.start >= previousMatch.gaps.slot.start && this.end <= previousMatch.gaps.slot.end)\n\t}\n}","/**\n * PatternMatcher - State Machine for Markup Pattern Recognition\n *\n * Implements a high-performance state machine that processes segments to identify\n * and match markup patterns. Manages Match objects representing parsing states\n * for different markup descriptors, handling gap positions and completion logic.\n *\n * Key features:\n * - State machine approach for pattern matching\n * - Position-based indexing for efficient lookups\n * - Processing order-based conflict resolution for overlapping matches\n * - Gap position management for nested content extraction\n */\n\nimport {getSegmentIndex} from '../utils/getSegmentIndex'\nimport type {MarkupDescriptor} from './MarkupDescriptor'\nimport type {MarkupRegistry} from './MarkupRegistry'\nimport {Match} from './Match'\nimport type {SegmentMatch} from './SegmentMatcher'\n\nfunction getOrCreate<K, V>(map: Map<K, V[]>, key: K): V[] {\n\tlet arr = map.get(key)\n\tif (!arr) {\n\t\tarr = []\n\t\tmap.set(key, arr)\n\t}\n\treturn arr\n}\n\n/**\n * Optimized parser using state machine approach\n */\nexport class PatternMatcher {\n\tprivate readonly pendingStates: Map<number, Match[]> = new Map()\n\tprivate readonly completingStates: Map<number, Match[]> = new Map()\n\tprivate readonly completedStates: Array<{position: number; match: Match}> = []\n\n\tconstructor(private readonly registry: MarkupRegistry) {}\n\n\t/** Main method that converts found segments into structured matches */\n\tprocess(segments: SegmentMatch[]): Match[] {\n\t\tthis.pendingStates.clear()\n\t\tthis.completingStates.clear()\n\t\tthis.completedStates.length = 0\n\n\t\tfor (const segment of segments) {\n\t\t\tthis.processWaitingStates(segment)\n\t\t\tthis.tryStartNewStates(segment)\n\t\t}\n\n\t\t//TODO need review it\n\t\tthis.resolveSlotLeadingMatches()\n\n\t\treturn this.completedStates.map(entry => entry.match)\n\t}\n\n\t/**\n\t * Process states waiting for this segment\n\t * Try states by priority until one is valid, keeping rejected states for later attempts\n\t * Process completing states first (higher priority), then pending states\n\t * Process only one state per call\n\t */\n\tprivate processWaitingStates(segment: SegmentMatch): void {\n\t\tconst match = this.dequeueWaitingMatch(segment)\n\t\tif (!match) return\n\n\t\tmatch.processNext(segment)\n\n\t\tif (match.isInvalid) return\n\n\t\tif (match.isCompleted) return this.addToCompleted(match)\n\n\t\tthis.addToWaiting(match)\n\t}\n\n\tprivate tryStartNewStates(segment: SegmentMatch): void {\n\t\tthis.registry.firstSegmentIndexMap.get(segment.index)?.forEach((descriptor: MarkupDescriptor) => {\n\t\t\tconst match = new Match(descriptor, segment)\n\n\t\t\tif (match.isInvalid) return\n\n\t\t\tif (match.isCompleted) return this.addToCompleted(match)\n\n\t\t\tthis.addToWaiting(match)\n\t\t})\n\t}\n\n\t/**\n\t * Gets the next waiting match for the given segment\n\t * Uses value-specific index for dynamic segments, base index for static segments\n\t */\n\tprivate dequeueWaitingMatch(segment: SegmentMatch): Match | undefined {\n\t\tconst index = segment.captured ? getSegmentIndex(segment.index, segment.value) : segment.index\n\n\t\tconst completingArray = this.completingStates.get(index)\n\t\tif (completingArray?.length) return completingArray.pop()\n\n\t\tconst pendingArray = this.pendingStates.get(index)\n\t\tif (pendingArray?.length) return pendingArray.pop()\n\t}\n\n\t/**\n\t * Adds a state to the waiting list for the next expected segment\n\t */\n\tprivate addToWaiting(match: Match): void {\n\t\tconst segmentIndex = match.nextSegment\n\t\tif (segmentIndex === undefined) return\n\t\tconst map = match.isAwaitingLastSegment ? this.completingStates : this.pendingStates\n\t\tgetOrCreate(map, segmentIndex).push(match)\n\t}\n\n\t/**\n\t * Resolves slot-leading single-segment matches by extending their start backwards.\n\t *\n\t * For patterns like `__slot__\\n\\n`, the segment `\\n\\n` is a suffix delimiter and\n\t * the slot content precedes it. After normal processing, such matches only cover\n\t * the delimiter. This pass extends each slot-leading match backwards to the end\n\t * of the previous slot-leading match (or input start), so that non-slot-leading\n\t * matches between them become nested children rather than siblings.\n\t */\n\tprivate resolveSlotLeadingMatches(): void {\n\t\tlet hasSlotLeading = false\n\t\tfor (const entry of this.completedStates) {\n\t\t\tif (this.isSlotLeading(entry.match)) {\n\t\t\t\thasSlotLeading = true\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif (!hasSlotLeading) return\n\n\t\t// Only slot-leading match boundaries matter — other matches become nested children\n\t\tlet boundary = 0\n\t\tfor (const entry of this.completedStates) {\n\t\t\tconst {match} = entry\n\t\t\tif (this.isSlotLeading(match)) {\n\t\t\t\tconst segmentStart = match.start\n\t\t\t\tmatch.start = boundary\n\t\t\t\tentry.position = boundary\n\t\t\t\tmatch.gaps.slot = {start: boundary, end: segmentStart}\n\t\t\t\tboundary = match.end\n\t\t\t}\n\t\t}\n\n\t\tthis.completedStates.sort((a, b) => a.position - b.position)\n\t}\n\n\tprivate isSlotLeading(match: Match): boolean {\n\t\treturn match.descriptor.segments.length === 1 && match.descriptor.hasSlot\n\t}\n\n\t/**\n\t * Add match to position-indexed array, replacing any existing match at the same position\n\t * Uses binary search to find insertion point and maintains sorted order\n\t * Relies on processing order to determine which match to keep\n\t */\n\tprivate addToCompleted(match: Match): void {\n\t\tconst position = match.start\n\n\t\t// Binary search to find the insertion point or existing position\n\t\tlet left = 0\n\t\tlet right = this.completedStates.length\n\n\t\twhile (left < right) {\n\t\t\tconst mid = Math.floor((left + right) / 2)\n\t\t\tif (this.completedStates[mid].position < position) {\n\t\t\t\tleft = mid + 1\n\t\t\t} else {\n\t\t\t\tright = mid\n\t\t\t}\n\t\t}\n\n\t\t// Check if we found an existing entry at this position\n\t\tif (left < this.completedStates.length && this.completedStates[left].position === position) {\n\t\t\t// Position exists - replace with the new match\n\t\t\tthis.completedStates[left].match = match\n\t\t} else {\n\t\t\t// New position - insert new entry at the correct position\n\t\t\tthis.completedStates.splice(left, 0, {position, match})\n\t\t}\n\t}\n}","import {escape} from '../../../../shared/escape'\n\n/**\n * Result of a segment match in the text\n */\nexport interface SegmentMatch {\n\t/** Index in the patterns array */\n\tindex: number\n\t/** Start position in text */\n\tstart: number\n\t/** End position in text (exclusive) */\n\tend: number\n\t/** Matched text */\n\tvalue: string\n\t/** Captured content from dynamic pattern (if any) */\n\tcaptured?: string\n}\n\n/**\n * Segment definition - can be a static string or a dynamic pattern\n * For dynamic patterns: [before, after, exclusions]\n */\nexport type SegmentDefinition = string | readonly [before: string, after: string, exclusions: string]\n\n/**\n * Internal representation of a segment with its regex pattern\n */\ninterface SegmentEntry {\n\t/** Original index in the segments array */\n\tindex: number\n\t/** Regex pattern for this segment (escaped static or dynamic pattern) */\n\tpattern: string\n\t/** Original definition for reference */\n\tdefinition: SegmentDefinition\n}\n\n/**\n * Computes regex pattern for dynamic segment using pre-computed exclusions\n */\nfunction computeDynamicPattern(before: string, after: string, exclusions: string): string {\n\tconst escapedBefore = escape(before)\n\tconst escapedAfter = escape(after)\n\tconst escapedDelimiters = escape(after + exclusions)\n\n\t// Non-greedy quantifier to stop at first occurrence of after\n\treturn `${escapedBefore}([^${escapedDelimiters}]+?)${escapedAfter}`\n}\n\ninterface StaticMatcher {\n\tregex: RegExp\n\ttoIndex: Map<string, number>\n}\n\ninterface DynamicMatcher {\n\tregex: RegExp\n\tentries: SegmentEntry[]\n\tindices: Set<number>\n}\n\n/**\n * Segment matcher using dual strategy for optimal performance\n */\nexport class SegmentMatcher {\n\tprivate static?: StaticMatcher\n\tprivate dynamic?: DynamicMatcher\n\n\tconstructor(segments: SegmentDefinition[]) {\n\t\tthis.initializeDual(segments)\n\t}\n\n\tprivate initializeDual(segments: SegmentDefinition[]) {\n\t\tconst statics: string[] = []\n\t\tconst dynamics: Array<{segment: SegmentDefinition; index: number}> = []\n\t\tconst staticToIndex = new Map<string, number>()\n\n\t\t// Separate segments and build static index map\n\t\tsegments.forEach((segment, index) => {\n\t\t\tif (typeof segment === 'string') {\n\t\t\t\tstatics.push(segment)\n\t\t\t\tstaticToIndex.set(segment, index)\n\t\t\t} else {\n\t\t\t\tdynamics.push({segment, index})\n\t\t\t}\n\t\t})\n\n\t\t// Create static matcher\n\t\tif (statics.length > 0) {\n\t\t\tconst sorted = [...statics].toSorted((a, b) => b.length - a.length)\n\t\t\tconst escaped = sorted.map(escape)\n\t\t\tthis.static = {\n\t\t\t\tregex: new RegExp(`(?:${escaped.join('|')})`, 'gu'),\n\t\t\t\ttoIndex: staticToIndex,\n\t\t\t}\n\t\t}\n\n\t\t// Create dynamic matcher\n\t\tif (dynamics.length > 0) {\n\t\t\tconst indices = new Set<number>()\n\t\t\tconst entries: SegmentEntry[] = []\n\n\t\t\tdynamics.forEach(({segment, index}) => {\n\t\t\t\tif (typeof segment === 'string') return\n\t\t\t\tconst [before, after, exclusions] = segment\n\t\t\t\tindices.add(index)\n\t\t\t\tconst pattern = computeDynamicPattern(before, after, exclusions)\n\t\t\t\tconst namedPattern = pattern.replace('(', `(?<content${index}>`)\n\t\t\t\tentries.push({index, pattern: namedPattern, definition: segment})\n\t\t\t})\n\n\t\t\t// Sort by pattern length (longest first) for optimal matching\n\t\t\tentries.sort((a, b) => {\n\t\t\t\tconst aLen = typeof a.definition === 'string' ? a.definition.length : a.pattern.length\n\t\t\t\tconst bLen = typeof b.definition === 'string' ? b.definition.length : b.pattern.length\n\t\t\t\treturn bLen - aLen\n\t\t\t})\n\n\t\t\tthis.dynamic = {\n\t\t\t\tentries,\n\t\t\t\tindices,\n\t\t\t\tregex: new RegExp(entries.map((e, i) => `(?<seg${i}>${e.pattern})`).join('|'), 'gu'),\n\t\t\t}\n\t\t}\n\t}\n\n\tsearch(text: string): SegmentMatch[] {\n\t\tconst results: SegmentMatch[] = []\n\t\tconst dynamicResults: SegmentMatch[] = []\n\n\t\t// Static segments\n\t\tif (this.static) {\n\t\t\tconst {regex, toIndex} = this.static\n\t\t\tfor (const match of text.matchAll(regex)) {\n\t\t\t\tconst index = toIndex.get(match[0])\n\t\t\t\tif (index !== undefined) {\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\tindex,\n\t\t\t\t\t\tstart: match.index,\n\t\t\t\t\t\tend: match.index + match[0].length,\n\t\t\t\t\t\tvalue: match[0],\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Dynamic segments\n\t\tif (this.dynamic) {\n\t\t\tconst {regex, entries, indices} = this.dynamic\n\t\t\tfor (const match of text.matchAll(regex)) {\n\t\t\t\tconst matchedText = match[0]\n\t\t\t\tconst start = match.index\n\n\t\t\t\tlet matchedIndex: number | undefined\n\t\t\t\tlet captured: string | undefined\n\n\t\t\t\tif (match.groups) {\n\t\t\t\t\tfor (let i = 0; i < entries.length; i++) {\n\t\t\t\t\t\tconst groupValue = match.groups[`seg${i}`]\n\t\t\t\t\t\t// oxlint-disable-next-line no-unnecessary-condition\n\t\t\t\t\t\tif (groupValue !== undefined) {\n\t\t\t\t\t\t\tmatchedIndex = entries[i].index\n\t\t\t\t\t\t\tif (indices.has(matchedIndex)) {\n\t\t\t\t\t\t\t\tcaptured = match.groups[`content${matchedIndex}`]\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tbreak\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (matchedIndex !== undefined) {\n\t\t\t\t\tdynamicResults.push({\n\t\t\t\t\t\tindex: matchedIndex,\n\t\t\t\t\t\tstart,\n\t\t\t\t\t\tend: start + matchedText.length,\n\t\t\t\t\t\tvalue: matchedText,\n\t\t\t\t\t\tcaptured,\n\t\t\t\t\t})\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Filter overlapping static matches and merge\n\t\tconst finalResults = [...dynamicResults]\n\t\tfor (const staticMatch of results) {\n\t\t\tconst overlaps = dynamicResults.some(\n\t\t\t\tdynamic => staticMatch.start < dynamic.end && staticMatch.end > dynamic.start\n\t\t\t)\n\t\t\tif (!overlaps) {\n\t\t\t\tfinalResults.push(staticMatch)\n\t\t\t}\n\t\t}\n\n\t\tfinalResults.sort((a, b) => a.start - b.start)\n\t\treturn finalResults\n\t}\n}","import type {TextToken} from '../types'\n\n/**\n * Creates a text token for a range in the input\n *\n * @param input - Original input text\n * @param start - Start position (inclusive)\n * @param end - End position (exclusive)\n * @returns TextToken with extracted content and position\n */\nexport const createTextToken = (input: string, start = 0, end = input.length): TextToken => {\n\treturn {\n\t\ttype: 'text',\n\t\tcontent: input.substring(start, end),\n\t\tposition: {start, end},\n\t}\n}","import type {MarkToken, ParseOptions, PositionRange, TextToken, Token} from '../types'\nimport {createTextToken} from '../utils/createTextToken'\nimport type {Match} from './Match'\n\n/**\n * Parent context for tracking active nesting during tree building\n */\ninterface ParentContext {\n\tmatch: Match\n\ttoken: MarkToken\n\ttextPos: number // Current position for adding text tokens\n}\n\n/**\n * TreeBuilder - Optimized single-pass tree building algorithm\n *\n * Algorithm: Single-pass approach with direct token creation\n * - Processes matches in order, maintaining a stack of active parents\n * - Creates tokens directly without intermediate data structures\n * - Handles text gaps and nesting in a single traversal\n *\n * Key optimizations:\n * - Single pass through matches (no separate relationship building phase)\n * - Direct token creation eliminates intermediate allocations\n * - Stack-based parent tracking with O(D) memory where D is nesting depth\n * - No need for parent indices array or children lists\n * - Simpler algorithm that's easier to understand and maintain\n *\n * Complexity: O(M) where M is number of matches\n * Memory: O(D) for active parents stack where D is nesting depth (typically 3-5)\n */\nexport class TreeBuilder {\n\t// Instance fields - only what's needed for single pass\n\tprivate input!: string\n\tprivate readonly options: ParseOptions\n\n\tconstructor(options?: ParseOptions) {\n\t\tthis.options = options ?? {}\n\t}\n\n\t// ===== PUBLIC API =====\n\n\t/**\n\t * Builds nested token tree from pre-processed matches in a single pass\n\t *\n\t * Algorithm:\n\t * 1. Iterate through matches in order\n\t * 2. For each match:\n\t * - Close any parents whose content ends before this match\n\t * - Skip matches that conflict with the last accepted match\n\t * - Add text token before this match\n\t * - Create mark token and push to appropriate parent\n\t * - If match has nested content, push to active parents stack\n\t * 3. After all matches, close remaining parents and add final text\n\t *\n\t * Complexity: O(M) where M is number of matches\n\t * Memory: O(D) for active parents stack where D is nesting depth\n\t */\n\tpublic build(matches: Match[], input: string): Token[] {\n\t\tthis.input = input\n\n\t\tif (matches.length === 0) {\n\t\t\treturn this.filterTokens([this.createTextToken(0, input.length)])\n\t\t}\n\n\t\tconst tokens = this.buildSinglePass(matches)\n\t\treturn this.filterTokens(tokens)\n\t}\n\n\t// ===== SINGLE-PASS ALGORITHM =====\n\n\t/**\n\t * Builds token tree in a single pass through matches\n\t *\n\t * This is the core algorithm that processes matches sequentially,\n\t * maintaining a stack of active parents and creating tokens directly.\n\t */\n\tprivate buildSinglePass(matches: Match[]): Token[] {\n\t\tconst roots: Token[] = []\n\t\tconst parentStack: ParentContext[] = []\n\t\tlet lastAcceptedMatch: Match | null = null\n\t\tlet rootTextPos = 0\n\n\t\tfor (const match of matches) {\n\t\t\t// Skip conflicting matches\n\t\t\tif (lastAcceptedMatch && match.conflictsWith(lastAcceptedMatch)) {\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tlastAcceptedMatch = match\n\n\t\t\t// Close parents whose content ends before this match\n\t\t\twhile (parentStack.length > 0) {\n\t\t\t\tconst parent = parentStack[parentStack.length - 1]\n\t\t\t\tconst parentBounds = this.getContentBounds(parent.match)\n\n\t\t\t\tif (parentBounds.end <= match.start) {\n\t\t\t\t\t// Parent is complete - finalize it\n\t\t\t\t\tthis.finalizeParent(parent, parentBounds.end)\n\t\t\t\t\tparentStack.pop()\n\n\t\t\t\t\t// Add to appropriate container\n\t\t\t\t\tif (parentStack.length > 0) {\n\t\t\t\t\t\tparentStack[parentStack.length - 1].token.children.push(parent.token)\n\t\t\t\t\t} else {\n\t\t\t\t\t\troots.push(parent.token)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Determine where to add this match\n\t\t\tconst container = parentStack.length > 0 ? parentStack[parentStack.length - 1] : null\n\n\t\t\tif (container) {\n\t\t\t\t// Add text before this match within parent\n\t\t\t\tconst textToken = this.createTextToken(container.textPos, match.start)\n\t\t\t\tcontainer.token.children.push(textToken)\n\t\t\t\tcontainer.textPos = match.end\n\t\t\t} else {\n\t\t\t\t// Add text before this match at root level\n\t\t\t\tconst textToken = this.createTextToken(rootTextPos, match.start)\n\t\t\t\troots.push(textToken)\n\t\t\t\trootTextPos = match.end\n\t\t\t}\n\n\t\t\t// Create mark token for this match\n\t\t\tconst markToken = this.createMarkToken(match)\n\n\t\t\t// If match has children content, push to stack for processing children\n\t\t\tif (this.hasSlotContent(match)) {\n\t\t\t\tconst bounds = this.getContentBounds(match)\n\t\t\t\tparentStack.push({\n\t\t\t\t\tmatch,\n\t\t\t\t\ttoken: markToken,\n\t\t\t\t\ttextPos: bounds.start,\n\t\t\t\t})\n\t\t\t} else {\n\t\t\t\t// No nested content - add directly to container\n\t\t\t\tif (container) {\n\t\t\t\t\tcontainer.token.children.push(markToken)\n\t\t\t\t} else {\n\t\t\t\t\troots.push(markToken)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Close remaining parents\n\t\twhile (parentStack.length > 0) {\n\t\t\tconst parent = parentStack[parentStack.length - 1]\n\t\t\tparentStack.pop()\n\t\t\tconst parentBounds = this.getContentBounds(parent.match)\n\t\t\tthis.finalizeParent(parent, parentBounds.end)\n\n\t\t\tif (parentStack.length > 0) {\n\t\t\t\tparentStack[parentStack.length - 1].token.children.push(parent.token)\n\t\t\t} else {\n\t\t\t\troots.push(parent.token)\n\t\t\t}\n\t\t}\n\n\t\t// Add final text token at root level\n\t\troots.push(this.createTextToken(rootTextPos, this.input.length))\n\n\t\treturn roots\n\t}\n\n\t/**\n\t * Finalizes a parent token by adding final text token if needed\n\t */\n\tprivate finalizeParent(parent: ParentContext, endPos: number): void {\n\t\tparent.token.children.push(this.createTextToken(parent.textPos, endPos))\n\t}\n\n\t/**\n\t * Creates a mark token from a match (without children - those are added later)\n\t */\n\tprivate createMarkToken(match: Match): MarkToken {\n\t\t// Extract content using helper functions\n\t\tconst value = this.extractSubstring(match.gaps.value?.start, match.gaps.value?.end)\n\t\tconst slotStr = this.extractSubstring(match.gaps.slot?.start, match.gaps.slot?.end)\n\t\tconst metaStr = this.extractSubstring(match.gaps.meta?.start, match.gaps.meta?.end)\n\n\t\t// Convert empty strings to undefined for slot, but meta can be empty string\n\t\tconst slotContent = slotStr || undefined\n\t\tconst meta = match.gaps.meta !== undefined ? metaStr : undefined\n\n\t\treturn {\n\t\t\ttype: 'mark',\n\t\t\tcontent: this.input.substring(match.start, match.end),\n\t\t\tchildren: [], // Will be populated if match has slot content\n\t\t\tdescriptor: match.descriptor,\n\t\t\tvalue,\n\t\t\tmeta,\n\t\t\tposition: {start: match.start, end: match.end},\n\t\t\tslot: this.createSlotSourceInfo(match, slotContent),\n\t\t}\n\t}\n\n\t// ===== UTILITY METHODS =====\n\n\t/**\n\t * Gets the content boundaries for a match\n\t * Priority: nested content if present, otherwise value content\n\t */\n\tprivate getContentBounds(match: Match): PositionRange {\n\t\tif (match.gaps.slot) {\n\t\t\treturn match.gaps.slot\n\t\t}\n\t\tif (match.gaps.value) {\n\t\t\treturn match.gaps.value\n\t\t}\n\t\treturn {\n\t\t\tstart: match.start,\n\t\t\tend: match.start,\n\t\t}\n\t}\n\n\t/**\n\t * Checks if a match has children content capability\n\t */\n\tprivate hasSlotContent(match: Match): boolean {\n\t\treturn match.gaps.slot !== undefined\n\t}\n\n\t/**\n\t * Extracts substring safely, returns empty string if positions are undefined\n\t */\n\tprivate extractSubstring(start: number | undefined, end: number | undefined): string {\n\t\treturn start !== undefined && end !== undefined ? this.input.substring(start, end) : ''\n\t}\n\n\t/**\n\t * Creates a text token for a range in the input\n\t */\n\tprivate createTextToken(start: number, end: number): TextToken {\n\t\treturn createTextToken(this.input, start, end)\n\t}\n\n\t/**\n\t * Creates children source info object if children content exists\n\t */\n\tprivate createSlotSourceInfo(match: Match, slotContent: string | undefined): MarkToken['slot'] {\n\t\tif (!slotContent || match.gaps.slot === undefined) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn {\n\t\t\tcontent: slotContent,\n\t\t\tstart: match.gaps.slot.start,\n\t\t\tend: match.gaps.slot.end,\n\t\t}\n\t}\n\n\t// ===== TOKEN FILTERING. TODO: Is a hack =====\n\n\tprivate filterTokens(tokens: Token[]): Token[] {\n\t\tconst {marksOnly, skipEmptyText} = this.options\n\t\tif (!marksOnly && !skipEmptyText) return tokens\n\n\t\treturn tokens.filter(token => {\n\t\t\tif (token.type !== 'text') return true\n\t\t\tif (marksOnly) return false\n\t\t\tif (skipEmptyText && token.position.start === token.position.end) return false\n\t\t\treturn true\n\t\t})\n\t}\n}","import type {MarkToken, Token} from '../types'\n\n/**\n * Internal function to process tokens with a callback\n * @param tokens - Tokens to process\n * @param callback - Function to transform each MarkToken\n * @returns Transformed text\n */\nexport function processTokensWithCallback(tokens: Token[], callback: (mark: MarkToken) => string): string {\n\tlet result = ''\n\tfor (const token of tokens) {\n\t\tif (token.type === 'text') {\n\t\t\tresult += token.content\n\t\t} else {\n\t\t\t// For MarkToken with children, we need to decide:\n\t\t\t// - If we want to transform the mark itself AND its children\n\t\t\t// - Or transform children and include them in the mark's transformation\n\n\t\t\tif (token.children.length > 0) {\n\t\t\t\t// Recursively process children to get their transformed content\n\t\t\t\tconst processedChildren = processTokensWithCallback(token.children, callback)\n\n\t\t\t\t// Create a modified token with processed children as the value\n\t\t\t\t// This allows the callback to use the already-processed nested content\n\t\t\t\tconst modifiedToken: MarkToken = {\n\t\t\t\t\t...token,\n\t\t\t\t\tvalue: processedChildren,\n\t\t\t\t}\n\t\t\t\tresult += callback(modifiedToken)\n\t\t\t} else {\n\t\t\t\tresult += callback(token)\n\t\t\t}\n\t\t}\n\t}\n\treturn result\n}","import {PLACEHOLDER} from '../constants'\nimport type {Markup} from '../types'\n\n/**\n * Make annotation from the markup for ParserV2\n *\n * @param markup - Markup pattern with __value__, __meta__, and/or __slot__ placeholders\n * @param params - Object with optional value, meta, and slot strings\n * @returns Annotated string with placeholders replaced\n *\n * @example\n * ```typescript\n * annotate('@[__value__]', { value: 'Hello' }) // '@[Hello]'\n * annotate('@[__value__](__meta__)', { value: 'Hello', meta: 'world' }) // '@[Hello](world)'\n * annotate('@[__slot__]', { slot: 'content' }) // '@[content]'\n * ```\n */\nexport function annotate(\n\tmarkup: Markup,\n\tparams: {\n\t\tvalue?: string\n\t\tmeta?: string\n\t\tslot?: string\n\t}\n): string {\n\tlet annotation = markup as string\n\n\tif (params.value !== undefined) {\n\t\tannotation = annotation.replaceAll(PLACEHOLDER.Value, params.value)\n\t}\n\n\tif (params.meta !== undefined) {\n\t\tannotation = annotation.replaceAll(PLACEHOLDER.Meta, params.meta)\n\t}\n\n\tif (params.slot !== undefined) {\n\t\tannotation = annotation.replaceAll(PLACEHOLDER.Slot, params.slot)\n\t}\n\n\treturn annotation\n}","import type {Token} from '../types'\nimport {annotate} from './annotate'\n\n/**\n * Convert parsed tokens back to annotated string (inverse of `parse`).\n *\n * This function is useful for reconstructing annotated text from tokens,\n * similar to toString in text-manipulation/utils but for ParserV2\n *\n * @param tokens - Array of parsed tokens (from ParserV2.parse)\n * @returns Reconstructed annotated string\n *\n * @example\n * ```typescript\n * const markups = ['@[__value__](__meta__)', '#[__slot__]']\n * const tokens = new ParserV2(markups).parse('@[Hello](world) #[test]')\n * const result = toString(tokens)\n * // Returns: '@[Hello](world) #[test]'\n * ```\n */\nexport function toString(tokens: Token[]): string {\n\tlet result = ''\n\n\tfor (const token of tokens) {\n\t\tif (token.type === 'text') {\n\t\t\tresult += token.content\n\t\t\tcontinue\n\t\t}\n\n\t\tconst {markup, hasSlot} = token.descriptor\n\t\tconst slot = hasSlot ? (token.children.length > 0 ? toString(token.children) : token.slot?.content) : undefined\n\n\t\tresult += annotate(markup, {\n\t\t\tvalue: token.value,\n\t\t\tmeta: token.meta,\n\t\t\tslot,\n\t\t})\n\t}\n\n\treturn result\n}","import {MarkupRegistry} from './core/MarkupRegistry'\nimport {PatternMatcher} from './core/PatternMatcher'\nimport {SegmentMatcher} from './core/SegmentMatcher'\nimport {TreeBuilder} from './core/TreeBuilder'\nimport type {MarkToken, Markup, ParseOptions, Token} from './types'\nimport {createTextToken} from './utils/createTextToken'\nimport {processTokensWithCallback} from './utils/processTokens'\nimport {toString as tokensToString} from './utils/toString'\n\n/**\n * Parser - High-performance tree-based markup parser\n *\n * Parses text with markup patterns into a nested token tree structure.\n * Supports complex patterns with metadata, nesting, and HTML-like constructs.\n *\n * @example\n * ```typescript\n * const parser = new Parser(['@[__value__](__meta__)', '#[__slot__]'])\n * const tokens = parser.parse('Hello @[world](test) and #[tag]')\n * const text = parser.stringify(tokens)\n * ```\n */\nexport class Parser {\n\tprivate readonly registry: MarkupRegistry\n\tprivate readonly segmentMatcher: SegmentMatcher\n\tprivate readonly patternMatcher: PatternMatcher\n\tprivate readonly treeBuilder: TreeBuilder\n\tprivate readonly parseOptions: ParseOptions\n\n\t/**\n\t * Creates a new Parser instance with the specified markup patterns\n\t *\n\t * @param markups - Array of markup pattern strings with placeholders (can include undefined values):\n\t * - `__value__` - main content (plain text, no nesting)\n\t * - `__meta__` - metadata (plain text, no nesting)\n\t * - `__slot__` - content supporting nested structures\n\t * - `undefined` - skipped, but original array indices are preserved for descriptor matching\n\t * @param options - Optional parse options to control token output:\n\t * - `marksOnly` - return only MarkTokens, drop all TextTokens\n\t * - `skipEmptyText` - drop zero-length TextTokens (where start === end)\n\t *\n\t * @example\n\t * ```typescript\n\t * const parser = new Parser([\n\t * '@[__value__](__meta__)', // @[label](value) - descriptor.index = 0\n\t * undefined, // skipped\n\t * '#[__slot__]', // #[nested content] - descriptor.index = 2\n\t * '**__slot__**' // **bold text** - descriptor.index = 3\n\t * ])\n\t * ```\n\t */\n\tconstructor(markups: (Markup | undefined)[], options?: ParseOptions) {\n\t\tthis.registry = new MarkupRegistry(markups)\n\t\tthis.segmentMatcher = new SegmentMatcher(this.registry.segments)\n\t\tthis.patternMatcher = new PatternMatcher(this.registry)\n\t\tthis.parseOptions = options ?? {}\n\t\tthis.treeBuilder = new TreeBuilder(this.parseOptions)\n\t}\n\n\t/**\n\t * Parses text into tokens (static convenience method)\n\t *\n\t * @param value - Text to parse\n\t * @param options - Options with markup patterns and token filtering\n\t * @returns Array of tokens (TextToken and MarkToken)\n\t *\n\t * @example\n\t * ```typescript\n\t * const tokens = Parser.parse('Hello @[world]', {\n\t * markup: ['@[__value__]']\n\t * })\n\t * ```\n\t */\n\tstatic parse(value: string, options?: {markup: Markup[]} & ParseOptions): Token[] {\n\t\tconst markups = options?.markup\n\t\tif (!markups || markups.length === 0) {\n\t\t\treturn [createTextToken(value)]\n\t\t}\n\t\tconst {markup: _, ...parseOptions} = options\n\t\treturn new Parser(markups, parseOptions).parse(value)\n\t}\n\n\t/**\n\t * Converts tokens back to text (static convenience method)\n\t *\n\t * @param tokens - Array of tokens to convert\n\t * @returns Reconstructed text string\n\t *\n\t * @example\n\t * ```typescript\n\t * const text = Parser.stringify(tokens)\n\t * ```\n\t */\n\tstatic stringify(tokens: Token[]): string {\n\t\treturn tokensToString(tokens)\n\t}\n\n\t/**\n\t * Parses text into a nested token tree\n\t *\n\t * This is the main parsing method. It processes the input text through\n\t * three stages:\n\t * 1. Segment matching - finds all markup segments (O(N + M))\n\t * 2. Pattern matching - builds complete patterns from segments (O(M))\n\t * 3. Tree building - constructs nested token tree (O(M·D))\n\t *\n\t * @param value - Text to parse\n\t * @returns Array of tokens representing the parsed structure\n\t *\n\t * @example\n\t * ```typescript\n\t * const parser = new Parser(['@[__value__](__meta__)'])\n\t * const tokens = parser.parse('Hello @[world](test)')\n\t * // Returns: [\n\t * // TextToken('Hello '),\n\t * // MarkToken('@[world](test)', value='world', meta='test'),\n\t * // TextToken('')\n\t * // ]\n\t * ```\n\t */\n\tparse(value: string): Token[] {\n\t\tconst segments = this.segmentMatcher.search(value)\n\t\tconst matches = this.patternMatcher.process(segments)\n\t\treturn this.treeBuilder.build(matches, value)\n\t}\n\n\t/**\n\t * Converts tokens back to the original text\n\t *\n\t * This is the inverse operation of parse(). It reconstructs the original\n\t * text from a token tree, preserving all markup and structure.\n\t *\n\t * @param tokens - Array of tokens to convert\n\t * @returns Reconstructed text string\n\t *\n\t * @example\n\t * ```typescript\n\t * const text = 'Hello @[world](test)'\n\t * const tokens = parser.parse(text)\n\t * const reconstructed = parser.stringify(tokens)\n\t * console.log(reconstructed === text) // true\n\t * ```\n\t */\n\tstringify(tokens: Token[]): string {\n\t\treturn tokensToString(tokens)\n\t}\n\n\t/**\n\t * Transforms annotated text by processing all mark tokens with a callback\n\t *\n\t * This method parses the text, recursively processes all MarkTokens\n\t * (including nested ones) with the provided callback, and returns\n\t * the transformed text.\n\t *\n\t * @param value - Annotated text to process\n\t * @param callback - Function to transform each MarkToken\n\t * @returns Transformed text\n\t *\n\t * @example\n\t * ```typescript\n\t * // Extract all values\n\t * const text = '@[Hello](world) and #[tag]'\n\t * const result = parser.transform(text, mark => mark.value)\n\t * // Returns: 'Hello and tag'\n\t *\n\t * // Custom transformation\n\t * const result = parser.transform(text, mark =>\n\t * mark.meta ? `${mark.value}:${mark.meta}` : mark.value\n\t * )\n\t * // Returns: 'Hello:world and tag'\n\t * ```\n\t */\n\ttransform(value: string, callback: (mark: MarkToken) => string): string {\n\t\tconst tokens = this.parse(value)\n\t\treturn processTokensWithCallback(tokens, callback)\n\t}\n\n\t/**\n\t * Escapes markup segments in the given text using backslash\n\t *\n\t * This method uses the registry's unique segments and escapes them by adding\n\t * a backslash before each character of each segment, preventing them from being\n\t * parsed as markup when the text is processed again.\n\t *\n\t * @param text - Text to escape segments in\n\t * @returns Text with escaped segments\n\t *\n\t * @example\n\t * ```typescript\n\t * const parser = new Parser(['**__slot__**', '@[__value__]'])\n\t * const escaped = parser.escape('Hello **world** and @[user]')\n\t * // Returns: 'Hello \\*\\*world\\*\\* and \\@[user]'\n\t * ```\n\t */\n\tescape(text: string): string {\n\t\treturn this.registry.segments\n\t\t\t.filter((segment): segment is string => typeof segment === 'string')\n\t\t\t.toSorted((a, b) => b.length - a.length)\n\t\t\t.reduce((result, segment) => result.replaceAll(segment, segment.replace(/(.)/g, '\\\\$1')), text)\n\t}\n\n\t/**\n\t * Unescapes markup patterns in the given text\n\t *\n\t * This method removes escape characters from segments that were previously\n\t * escaped using escape(), allowing the patterns to be parsed normally.\n\t *\n\t * @param text - Text to unescape patterns in\n\t * @returns Text with unescaped patterns\n\t *\n\t * @example\n\t * ```typescript\n\t * const parser = new Parser(['**__slot__**', '@[__value__]'])\n\t * const unescaped = parser.unescape('Hello \\*\\*world\\*\\* and \\@[user]')\n\t * // Returns: 'Hello **world** and @[user]'\n\t * ```\n\t */\n\tunescape(text: string): string {\n\t\treturn text.replaceAll(/\\\\(.)/g, '$1')\n\t}\n}","import {Parser} from '../Parser'\nimport type {MarkToken, Markup} from '../types'\nimport {processTokensWithCallback} from './processTokens'\n\n/**\n * Transform annotated text to another text by recursively processing all tokens\n *\n * @param value - Annotated text to process\n * @param callback - Function to transform each MarkToken\n * @param markups - Array of markup patterns to parse\n * @returns Transformed text\n *\n * @example\n * ```typescript\n * const text = '@[Hello](world) and #[nested @[content]]'\n * const result = denote(text, mark => mark.value, ['@[__value__](__meta__)', '#[__slot__]'])\n * // Returns: 'Hello and nested content'\n * ```\n */\nexport function denote(value: string, callback: (mark: MarkToken) => string, markups: Markup[]): string {\n\tif (!markups.length) return value\n\n\tconst tokens = new Parser(markups).parse(value)\n\n\treturn processTokensWithCallback(tokens, callback)\n}","import type {MarkToken, Token} from '../parser/types'\n\nexport interface TokenContext {\n\tdepth: number\n\tparent?: MarkToken\n}\n\nexport function findToken(tokens: Token[], target: Token, depth = 0, parent?: MarkToken): TokenContext | undefined {\n\tfor (const token of tokens) {\n\t\tif (token === target) return {depth, parent}\n\t\tif (token.type === 'mark') {\n\t\t\tconst result = findToken(token.children, target, depth + 1, token)\n\t\t\tif (result) return result\n\t\t}\n\t}\n}","export type Gap = {left?: number; right?: number}\n\nexport function findGap(previous: string = '', current: string = ''): Gap {\n\tif (previous === current) return {}\n\n\tlet left: number | undefined\n\tfor (let i = 0; i < previous.length; i++) {\n\t\tif (previous[i] !== current[i]) {\n\t\t\tleft = i\n\t\t\tbreak\n\t\t}\n\t}\n\n\tlet right: number | undefined\n\tfor (let i = 1; i <= previous.length; i++) {\n\t\tif (previous.at(-i) !== current.at(-i)) {\n\t\t\tright = previous.length - i + 1\n\t\t\tbreak\n\t\t}\n\t}\n\n\treturn {left, right}\n}","export function getClosestIndexes(array: number[], target: number) {\n\tlet left = -1,\n\t\tright = array.length\n\twhile (right - left > 1) {\n\t\tconst middle = Math.round((left + right) / 2)\n\t\tif (array[middle] <= target) {\n\t\t\tleft = middle\n\t\t} else {\n\t\t\tright = middle\n\t\t}\n\t}\n\tif (array[left] == target) right = left\n\t// oxlint-disable-next-line no-unnecessary-condition\n\treturn [left, right].filter(v => array[v] !== undefined)\n}","import type {Store} from '../../../store/Store'\nimport type {Token} from '../parser/types'\nimport {findGap, getClosestIndexes} from '../preparsing'\n\nexport function getTokensByUI(store: Store): Token[] {\n\tconst {focus} = store.nodes\n\tconst parser = store.computed.parser()\n\tconst tokens = store.state.tokens()\n\tif (!parser) return tokens\n\tconst parsed = parser.parse(focus.content)\n\tif (parsed.length <= 1) return tokens\n\treturn tokens.toSpliced(focus.index, 1, ...parsed)\n}\n\nexport function computeTokensFromValue(store: Store): Token[] {\n\tconst value = store.props.value()\n\tconst previousValue = store.state.previousValue()\n\tconst gap = findGap(previousValue, value)\n\n\tif (!gap.left && !gap.right) {\n\t\tstore.state.previousValue(value)\n\t\treturn store.state.tokens()\n\t}\n\n\t// Full value replacement — incremental diff won't work, re-parse from scratch\n\tif (gap.left === 0 && previousValue !== undefined && gap.right !== undefined && gap.right >= previousValue.length) {\n\t\tstore.state.previousValue(value)\n\t\treturn parseWithParser(store, value ?? '')\n\t}\n\n\tstore.state.previousValue(value)\n\tconst ranges = getRangeMap(store)\n\tconst tokens = store.state.tokens()\n\n\tif (\n\t\tgap.left !== undefined &&\n\t\tranges.includes(gap.left) &&\n\t\tgap.right !== undefined &&\n\t\tMath.abs(gap.left - gap.right) > 1\n\t) {\n\t\tconst updatedIndex = ranges.indexOf(gap.left)\n\t\tif (updatedIndex > 0) {\n\t\t\tconst parsed = parseUnionLabels(store, updatedIndex - 1, updatedIndex)\n\t\t\treturn tokens.toSpliced(updatedIndex - 1, 2, ...parsed)\n\t\t}\n\t}\n\tif (gap.left !== undefined) {\n\t\tconst [updatedIndex] = getClosestIndexes(ranges, gap.left)\n\t\tconst parsed = parseUnionLabels(store, updatedIndex)\n\t\tif (parsed.length === 1) return tokens\n\t\treturn tokens.toSpliced(updatedIndex, 1, ...parsed)\n\t}\n\tif (gap.right !== undefined) {\n\t\tconst [updatedIndex] = getClosestIndexes(ranges, gap.right)\n\t\tconst parsed = parseUnionLabels(store, updatedIndex)\n\t\tif (parsed.length === 1) return tokens\n\t\treturn tokens.toSpliced(updatedIndex, 1, ...parsed)\n\t}\n\treturn parseWithParser(store, value ?? '')\n}\n\nexport function parseUnionLabels(store: Store, ...indexes: number[]): Token[] {\n\tlet span = ''\n\tconst tokens = store.state.tokens()\n\tfor (const index of indexes) {\n\t\tconst token = tokens[index]\n\t\tspan += token.content\n\t}\n\n\treturn parseWithParser(store, span)\n}\n\nexport function getRangeMap(store: Store): number[] {\n\tlet position = 0\n\tconst tokens = store.state.tokens()\n\treturn tokens.map(token => {\n\t\tconst length = token.content.length\n\t\tposition += length\n\t\treturn position - length\n\t})\n}\n\nexport function parseWithParser(store: Store, value: string): Token[] {\n\tconst parser = store.computed.parser()\n\tif (!parser) {\n\t\treturn [\n\t\t\t{\n\t\t\t\ttype: 'text' as const,\n\t\t\t\tcontent: value,\n\t\t\t\tposition: {start: 0, end: value.length},\n\t\t\t},\n\t\t]\n\t}\n\n\treturn parser.parse(value)\n}","import {computed, effectScope, watch} from '../../shared/signals/index.js'\nimport type {Store} from '../../store/Store'\nimport {toString} from './parser/utils/toString'\nimport {getTokensByUI, computeTokensFromValue, parseWithParser} from './utils/valueParser'\n\nexport class ParseFeature {\n\t#scope?: () => void\n\n\tconstructor(private readonly store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\t\tthis.sync()\n\t\tthis.#scope = effectScope(() => {\n\t\t\tthis.#subscribeParse()\n\t\t\tthis.#subscribeReactiveParse()\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t}\n\n\tsync() {\n\t\tconst {store} = this\n\t\tconst inputValue = store.props.value() ?? store.props.defaultValue() ?? ''\n\t\tstore.state.tokens(parseWithParser(store, inputValue))\n\t\tstore.state.previousValue(inputValue)\n\t}\n\n\t#subscribeParse() {\n\t\tconst {store} = this\n\n\t\twatch(store.event.parse, () => {\n\t\t\tif (store.state.recovery()) {\n\t\t\t\tconst text = toString(store.state.tokens())\n\t\t\t\tstore.state.tokens(parseWithParser(store, text))\n\t\t\t\tstore.state.previousValue(text)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tstore.state.tokens(store.nodes.focus.target ? getTokensByUI(store) : computeTokensFromValue(store))\n\t\t})\n\t}\n\n\t#subscribeReactiveParse() {\n\t\tconst {store} = this\n\n\t\tconst deps = computed(() => [store.props.value(), store.computed.parser()] as const)\n\n\t\twatch(deps, () => {\n\t\t\tif (!store.state.recovery()) {\n\t\t\t\tstore.event.parse()\n\t\t\t}\n\t\t})\n\t}\n}","import type {Store} from '../../store'\nimport {Caret} from '../caret'\n\nexport function shiftFocusPrev(store: Store, event: KeyboardEvent): boolean {\n\tconst {focus} = store.nodes\n\tif ((focus.isMark && !focus.isEditable) || focus.isCaretAtBeginning) {\n\t\t// Walk back to the nearest focusable element (skip non-editable marks)\n\t\tlet prev = focus.prev\n\t\twhile (prev.target && prev.isMark && !prev.isEditable) {\n\t\t\tprev = prev.prev\n\t\t}\n\t\tif (!prev.target) return false\n\n\t\tevent.preventDefault()\n\t\tprev.target.focus()\n\t\t// After focusin fires, store.nodes.focus.target is updated to prev.target.\n\t\t// Set caret at the end of the newly focused element.\n\t\tCaret.setCaretToEnd(prev.target)\n\t\treturn true\n\t}\n\treturn false\n}\n\nexport function shiftFocusNext(store: Store, event: KeyboardEvent): boolean {\n\tconst {focus} = store.nodes\n\tif ((focus.isMark && !focus.isEditable) || focus.isCaretAtEnd) {\n\t\t// Walk forward to the nearest focusable element (skip non-editable marks)\n\t\tlet next = focus.next\n\t\twhile (next.target && next.isMark && !next.isEditable) {\n\t\t\tnext = next.next\n\t\t}\n\t\tif (!next.target) return false\n\n\t\tevent.preventDefault()\n\t\tnext.target.focus()\n\t\t// Set caret at the beginning of the newly focused element\n\t\tCaret.trySetIndex(next.target, 0)\n\t\treturn true\n\t}\n\treturn false\n}","import type {Store} from '../../store'\n\nexport function isFullSelection(store: Store): boolean {\n\tconst sel = window.getSelection()\n\tconst container = store.refs.container\n\tif (!sel?.rangeCount || !container?.firstChild || !container.lastChild) return false\n\n\ttry {\n\t\tconst range = sel.getRangeAt(0)\n\t\treturn (\n\t\t\tcontainer.contains(range.startContainer) &&\n\t\t\tcontainer.contains(range.endContainer) &&\n\t\t\trange.toString().length > 0\n\t\t)\n\t} catch {\n\t\treturn false\n\t}\n}\n\nexport function selectAllText(store: Store, event: KeyboardEvent): void {\n\tif ((event.ctrlKey || event.metaKey) && event.code === 'KeyA') {\n\t\t// In block mode, let the browser handle Ctrl+A natively so it selects\n\t\t// text within the focused block only, not across all blocks.\n\t\tif (store.computed.isBlock()) return\n\n\t\tevent.preventDefault()\n\n\t\tconst selection = window.getSelection()\n\t\tconst anchorNode = store.refs.container?.firstChild\n\t\tconst focusNode = store.refs.container?.lastChild\n\n\t\tif (!selection || !anchorNode || !focusNode) return\n\t\tselection.setBaseAndExtent(anchorNode, 0, focusNode, 1)\n\n\t\tstore.state.selecting('all')\n\t}\n}","import {nodeTarget} from '../../shared/checkers'\nimport {effectScope, effect, listen} from '../../shared/signals/index.js'\nimport type {Store} from '../../store/Store'\n\nexport class TextSelectionFeature {\n\t#scope?: () => void\n\t#pressedNode: Node | null = null\n\t#isPressed = false\n\n\tconstructor(private readonly store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\n\t\tthis.#scope = effectScope(() => {\n\t\t\tlisten(document, 'mousedown', e => {\n\t\t\t\tthis.#pressedNode = nodeTarget(e)\n\t\t\t\tthis.#isPressed = true\n\t\t\t})\n\n\t\t\tlisten(document, 'mousemove', e => {\n\t\t\t\tconst container = this.store.refs.container\n\t\t\t\tif (!container) return\n\t\t\t\tconst isPressed = this.#isPressed\n\t\t\t\tconst isNotInnerSome = !container.contains(this.#pressedNode) || this.#pressedNode !== e.target\n\t\t\t\tconst isInside = window.getSelection()?.containsNode(container, true)\n\n\t\t\t\tif (isPressed && isNotInnerSome && isInside) {\n\t\t\t\t\tif (this.store.state.selecting() !== 'drag') {\n\t\t\t\t\t\tthis.store.state.selecting('drag')\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tlisten(document, 'mouseup', () => {\n\t\t\t\tthis.#isPressed = false\n\t\t\t\tthis.#pressedNode = null\n\t\t\t\tif (this.store.state.selecting() === 'drag') {\n\t\t\t\t\tconst sel = window.getSelection()\n\t\t\t\t\tif (!sel || sel.isCollapsed) {\n\t\t\t\t\t\tthis.store.state.selecting(undefined)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tlisten(document, 'selectionchange', () => {\n\t\t\t\tif (this.store.state.selecting() !== 'drag') return\n\t\t\t\tconst sel = window.getSelection()\n\t\t\t\tif (!sel || sel.isCollapsed) {\n\t\t\t\t\tthis.store.state.selecting(undefined)\n\t\t\t\t}\n\t\t\t})\n\n\t\t\teffect(() => {\n\t\t\t\tconst value = this.store.state.selecting()\n\t\t\t\tif (value !== 'drag') return\n\t\t\t\tconst container = this.store.refs.container\n\t\t\t\tif (!container) return\n\t\t\t\tcontainer\n\t\t\t\t\t.querySelectorAll<HTMLElement>('[contenteditable=\"true\"]')\n\t\t\t\t\t.forEach(el => (el.contentEditable = 'false'))\n\t\t\t})\n\t\t})\n\t}\n\n\tdisable() {\n\t\tif (this.store.state.selecting() === 'drag') {\n\t\t\tthis.store.state.selecting(undefined)\n\t\t}\n\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t\tthis.#pressedNode = null\n\t\tthis.#isPressed = false\n\t}\n}","import {KEYBOARD} from '../../shared/constants'\nimport {effectScope, listen} from '../../shared/signals/index.js'\nimport type {Store} from '../../store/Store'\nimport {shiftFocusPrev, shiftFocusNext} from '../navigation'\nimport {selectAllText} from '../selection'\n\nexport class ArrowNavFeature {\n\t#scope?: () => void\n\n\tconstructor(private readonly store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tthis.#scope = effectScope(() => {\n\t\t\tlisten(container, 'keydown', e => {\n\t\t\t\tif (this.store.computed.isBlock()) return\n\t\t\t\tif (!this.store.nodes.focus.target) return\n\n\t\t\t\tif (e.key === KEYBOARD.LEFT) {\n\t\t\t\t\tshiftFocusPrev(this.store, e)\n\t\t\t\t} else if (e.key === KEYBOARD.RIGHT) {\n\t\t\t\t\tshiftFocusNext(this.store, e)\n\t\t\t\t}\n\n\t\t\t\tselectAllText(this.store, e)\n\t\t\t})\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t}\n}","/** Custom MIME type for markput markup syntax. */\nexport const MARKPUT_MIME = 'application/x-markput'\n\nconst pendingMarkupByContainer = new WeakMap<HTMLElement, string>()\n\n/**\n * Capture markup data from a paste event, scoped to a specific container.\n * Call this from the `paste` event handler — custom MIME types are readable\n * on ClipboardEvent.clipboardData but not reliably on InputEvent.dataTransfer.\n *\n * Scoping to the container prevents multiple editor instances from consuming\n * each other's clipboard data.\n */\nexport function captureMarkupPaste(event: ClipboardEvent, container: HTMLElement): void {\n\tconst raw = event.clipboardData?.getData(MARKPUT_MIME)\n\tif (raw) {\n\t\tpendingMarkupByContainer.set(container, raw)\n\t} else {\n\t\tpendingMarkupByContainer.delete(container)\n\t}\n}\n\n/**\n * Consume the pending markup data (if any) for the given container.\n * Returns undefined if no markup was captured or the data was already consumed.\n */\nexport function consumeMarkupPaste(container: HTMLElement): string | undefined {\n\tconst markup = pendingMarkupByContainer.get(container)\n\tpendingMarkupByContainer.delete(container)\n\treturn markup\n}\n\n/**\n * Clear the pending markup buffer for the given container. Useful for test cleanup.\n */\nexport function clearMarkupPaste(container: HTMLElement): void {\n\tpendingMarkupByContainer.delete(container)\n}","import type {Store} from '../../store'\nimport type {Token} from '../parsing'\n\n/**\n * Walk up the DOM from `node` until reaching a direct child of `container`.\n * Returns the index of that child in container.children, or -1 if not found.\n *\n * Works for both drag and non-drag modes:\n * - Non-drag: container children are Token-rendered elements (1:1 with tokens)\n * - Drag: container children are Block wrappers (1:1 with tokens)\n * - Nested marks: walks past inner mark elements to the top-level container child\n */\nfunction findContainerChildIndex(node: Node, container: HTMLElement): number {\n\tlet current: HTMLElement | null = node instanceof HTMLElement ? node : node.parentElement\n\twhile (current && current.parentElement !== container) {\n\t\tcurrent = current.parentElement\n\t}\n\tif (!current) return -1\n\treturn Array.from(container.children).indexOf(current)\n}\n\n/** Structural type shared by Range and StaticRange — only boundary properties are read. */\nexport interface RangeBoundary {\n\treadonly startContainer: Node\n\treadonly startOffset: number\n\treadonly endContainer: Node\n\treadonly endOffset: number\n}\n\n/**\n * Returns the character offset of a range boundary within a container child.\n * Walks all text nodes in document order to compute a cumulative character\n * offset, which correctly handles nested marks with multiple text nodes.\n * Falls back to 0 (start) or full text length (end) for out-of-child boundaries.\n *\n * Spec: selectionToTokens.spec.ts (unit) · Clipboard.react.spec.tsx (integration)\n */\nexport function getBoundaryOffset(range: RangeBoundary, child: Element, isStart: boolean): number {\n\tconst targetNode = isStart ? range.startContainer : range.endContainer\n\tconst targetOffset = isStart ? range.startOffset : range.endOffset\n\n\tif (!child.contains(targetNode)) {\n\t\treturn isStart ? 0 : child.textContent.length\n\t}\n\n\tlet charOffset = 0\n\tconst walker = document.createTreeWalker(child, NodeFilter.SHOW_TEXT)\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- SHOW_TEXT guarantees Text\n\tlet current = walker.nextNode() as Text | null\n\twhile (current) {\n\t\tif (current === targetNode) {\n\t\t\treturn charOffset + targetOffset\n\t\t}\n\t\tcharOffset += current.length\n\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- SHOW_TEXT guarantees Text\n\t\tcurrent = walker.nextNode() as Text | null\n\t}\n\n\treturn isStart ? 0 : child.textContent.length\n}\n\nexport interface SelectionTokenRange {\n\ttokens: Token[]\n\t/** Char offset within the first token where the selection starts. */\n\tstartOffset: number\n\t/** Char offset within the last token where the selection ends. */\n\tendOffset: number\n}\n\n/**\n * Map a browser Selection to the subset of tokens it covers.\n * Returns null if selection is collapsed, empty, or outside the container.\n */\nexport function selectionToTokens(store: Store): SelectionTokenRange | null {\n\tconst container = store.refs.container\n\tif (!container) return null\n\n\tconst sel = window.getSelection()\n\tif (!sel || sel.isCollapsed || !sel.rangeCount) return null\n\n\tconst range = sel.getRangeAt(0)\n\n\tif (!container.contains(range.startContainer) || !container.contains(range.endContainer)) {\n\t\treturn null\n\t}\n\n\tconst tokens = store.state.tokens()\n\n\tlet startIndex = findContainerChildIndex(range.startContainer, container)\n\tlet endIndex = findContainerChildIndex(range.endContainer, container)\n\n\tif (startIndex === -1 || endIndex === -1) return null\n\n\tif (startIndex > endIndex) {\n\t\t;[startIndex, endIndex] = [endIndex, startIndex]\n\t}\n\n\tconst startChild = container.children.item(startIndex)\n\tconst endChild = container.children.item(endIndex)\n\n\treturn {\n\t\ttokens: tokens.slice(startIndex, endIndex + 1),\n\t\tstartOffset: startChild ? getBoundaryOffset(range, startChild, true) : 0,\n\t\tendOffset: endChild ? getBoundaryOffset(range, endChild, false) : 0,\n\t}\n}","import {effectScope, listen} from '../../shared/signals/index.js'\nimport type {Store} from '../../store'\nimport {toString} from '../parsing'\nimport type {Token} from '../parsing'\nimport {MARKPUT_MIME} from './pasteMarkup'\nimport {type SelectionTokenRange, selectionToTokens} from './selectionToTokens'\n\n/**\n * Trim boundary text tokens to the selected portion.\n * Mark tokens are always kept in full — partial mark selection expands to full mark.\n *\n * NOTE: Returned text tokens have stale `position` fields — the start/end positions\n * still reflect the original token, not the trimmed content. Only `content` is\n * authoritative on the returned tokens. `toString` is safe because it reads `content`\n * directly; do not use `position` on the returned tokens for any other purpose.\n */\nfunction trimBoundaryTokens({tokens, startOffset, endOffset}: SelectionTokenRange): Token[] {\n\tif (tokens.length === 0) return tokens\n\n\treturn tokens.map((token, i) => {\n\t\tif (token.type !== 'text') return token\n\n\t\tconst isFirst = i === 0\n\t\tconst isLast = i === tokens.length - 1\n\n\t\tif (isFirst && isLast) return {...token, content: token.content.slice(startOffset, endOffset)}\n\t\tif (isFirst) return {...token, content: token.content.slice(startOffset)}\n\t\tif (isLast) return {...token, content: token.content.slice(0, endOffset)}\n\t\treturn token\n\t})\n}\n\nexport class CopyFeature {\n\t#scope?: () => void\n\n\tconstructor(private readonly store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tthis.#scope = effectScope(() => {\n\t\t\tlisten(container, 'copy', e => {\n\t\t\t\tthis.#handleCopy(e)\n\t\t\t})\n\n\t\t\tlisten(container, 'cut', e => {\n\t\t\t\tif (!this.#handleCopy(e)) return\n\n\t\t\t\tconst result = selectionToTokens(this.store)\n\t\t\t\tif (!result || result.tokens.length === 0) return\n\n\t\t\t\tconst first = result.tokens[0]\n\t\t\t\tconst last = result.tokens[result.tokens.length - 1]\n\n\t\t\t\tconst rawStart =\n\t\t\t\t\tfirst.type === 'text' ? first.position.start + result.startOffset : first.position.start\n\t\t\t\tconst rawEnd = last.type === 'text' ? last.position.start + result.endOffset : last.position.end\n\n\t\t\t\tconst value = this.store.computed.currentValue()\n\t\t\t\tif (rawStart === rawEnd) return\n\n\t\t\t\tconst newValue = value.slice(0, rawStart) + value.slice(rawEnd)\n\t\t\t\tthis.store.state.innerValue(newValue)\n\n\t\t\t\tconst newTokens = this.store.state.tokens()\n\t\t\t\tlet targetIdx = newTokens.findIndex(\n\t\t\t\t\tt => t.type === 'text' && rawStart >= t.position.start && rawStart <= t.position.end\n\t\t\t\t)\n\t\t\t\tif (targetIdx === -1) targetIdx = newTokens.length - 1\n\t\t\t\tconst caretWithinToken = rawStart - newTokens[targetIdx].position.start\n\n\t\t\t\tthis.store.state.recovery({\n\t\t\t\t\tanchor: this.store.nodes.focus,\n\t\t\t\t\tcaret: caretWithinToken,\n\t\t\t\t\tisNext: true,\n\t\t\t\t\tchildIndex: targetIdx - 2,\n\t\t\t\t})\n\t\t\t})\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t}\n\n\t#handleCopy(e: ClipboardEvent): boolean {\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return false\n\n\t\tconst sel = window.getSelection()\n\t\tif (!sel || sel.isCollapsed || !sel.rangeCount) return false\n\n\t\tconst range = sel.getRangeAt(0)\n\t\tif (!container.contains(range.startContainer) || !container.contains(range.endContainer)) {\n\t\t\treturn false\n\t\t}\n\n\t\tconst result = selectionToTokens(this.store)\n\t\tif (!result) return false\n\n\t\t// text/plain: visual selected text\n\t\tconst plainText = range.toString()\n\n\t\t// text/html: rendered DOM HTML from the actual selection\n\t\tconst fragment = range.cloneContents()\n\t\tconst div = document.createElement('div')\n\t\tdiv.appendChild(fragment)\n\t\tconst html = div.innerHTML\n\n\t\t// application/x-markput: boundary text tokens trimmed to selected portion,\n\t\t// mark tokens always expanded to full markup syntax\n\t\tconst markup = toString(trimBoundaryTokens(result))\n\n\t\te.preventDefault()\n\t\te.clipboardData?.setData('text/plain', plainText)\n\t\te.clipboardData?.setData('text/html', html)\n\t\te.clipboardData?.setData(MARKPUT_MIME, markup)\n\t\treturn true\n\t}\n}","import type {MarkToken, Token} from '../parsing'\n\nfunction gapText(value: string, a: Token, b: Token): string {\n\treturn value.substring(a.position.end, b.position.start)\n}\n\nfunction isSlotLeadingMark(token: Token): token is MarkToken {\n\treturn token.type === 'mark' && token.descriptor.hasSlot && token.descriptor.segments.length === 1\n}\n\n/**\n * Returns whether two adjacent rows can be merged (Backspace/Delete).\n * Text rows merge when there's a gap between them.\n * Slot-leading mark rows of the same descriptor merge by removing the first mark's suffix.\n */\nexport function canMergeRows(a: Token, b: Token): boolean {\n\tif (a.type === 'text' && b.type === 'text' && b.position.start > a.position.end) return true\n\tif (isSlotLeadingMark(a) && isSlotLeadingMark(b) && a.descriptor === b.descriptor) return true\n\treturn false\n}\n\nexport function addDragRow(value: string, rows: Token[], afterIndex: number, newRowContent: string): string {\n\tif (rows.length === 0) return value + newRowContent\n\tif (value === '' || (rows.length === 1 && rows[0].type === 'text' && rows[0].content === ''))\n\t\treturn newRowContent + newRowContent\n\tif (afterIndex >= rows.length - 1) return value + newRowContent\n\n\tconst insertPos = rows[afterIndex + 1].position.start\n\treturn value.slice(0, insertPos) + newRowContent + value.slice(insertPos)\n}\n\nexport function deleteDragRow(value: string, rows: Token[], index: number): string {\n\tif (rows.length <= 1) return ''\n\n\tif (index >= rows.length - 1) {\n\t\treturn value.slice(0, rows[index - 1].position.end)\n\t}\n\n\treturn value.slice(0, rows[index].position.start) + value.slice(rows[index + 1].position.start)\n}\n\nexport function duplicateDragRow(value: string, rows: Token[], index: number): string {\n\tconst row = rows[index]\n\tconst rowText = value.substring(row.position.start, row.position.end)\n\n\tif (index >= rows.length - 1) return value + rowText\n\n\tconst next = rows[index + 1]\n\tconst gap = gapText(value, row, next)\n\treturn value.slice(0, next.position.start) + rowText + gap + value.slice(next.position.start)\n}\n\n/**\n * Returns the raw-value position of the join point between row[index-1] and row[index]\n * for use as the caret position after a merge.\n */\nexport function getMergeDragRowJoinPos(rows: Token[], index: number): number {\n\tif (index <= 0 || index >= rows.length) return 0\n\tconst prev = rows[index - 1]\n\tif (isSlotLeadingMark(prev) && prev.slot) return prev.slot.end\n\treturn prev.position.end\n}\n\n/**\n * Merges row[index] into row[index - 1] by removing the boundary between them.\n * For text rows: removes the gap between them.\n * For slot-leading marks: removes the first mark's literal suffix, merging slot content.\n */\nexport function mergeDragRows(value: string, rows: Token[], index: number): string {\n\tif (index <= 0 || index >= rows.length) return value\n\tconst prev = rows[index - 1]\n\tconst curr = rows[index]\n\tif (isSlotLeadingMark(prev) && isSlotLeadingMark(curr)) {\n\t\tconst slotEnd = prev.slot ? prev.slot.end : prev.position.end\n\t\treturn value.slice(0, slotEnd) + value.slice(curr.position.start)\n\t}\n\treturn value.slice(0, prev.position.end) + value.slice(curr.position.start)\n}\n\n/**\n * Reorders rows by moving the row at `sourceIndex` to `targetIndex`.\n * Gaps between adjacent rows are extracted from the original value and preserved.\n */\nexport function reorderDragRows(value: string, rows: Token[], sourceIndex: number, targetIndex: number): string {\n\tif (sourceIndex === targetIndex || sourceIndex === targetIndex - 1) return value\n\tif (rows.length < 2) return value\n\tif (sourceIndex < 0 || sourceIndex >= rows.length) return value\n\tif (targetIndex < 0 || targetIndex > rows.length) return value\n\n\tconst texts = rows.map(row => value.substring(row.position.start, row.position.end))\n\tconst gaps = rows.slice(0, -1).map((row, i) => gapText(value, row, rows[i + 1]))\n\n\tconst [movedText] = texts.splice(sourceIndex, 1)\n\t// Remove the gap associated with the source position\n\tconst gapIndex = sourceIndex < gaps.length ? sourceIndex : sourceIndex - 1\n\tgaps.splice(gapIndex, 1)\n\n\tconst insertAt = targetIndex > sourceIndex ? targetIndex - 1 : targetIndex\n\ttexts.splice(insertAt, 0, movedText)\n\t// Insert a gap for the new position (use '' — marks are self-delimiting)\n\tif (insertAt < texts.length - 1) {\n\t\tgaps.splice(insertAt, 0, '')\n\t}\n\n\tconst parts: string[] = []\n\tfor (let i = 0; i < texts.length; i++) {\n\t\tparts.push(texts[i])\n\t\tif (i < gaps.length) {\n\t\t\tparts.push(gaps[i])\n\t\t}\n\t}\n\n\treturn parts.join('')\n}","export function createNewSpan(span: string, annotation: string, index: number, source: string) {\n\treturn span.slice(0, index) + annotation + span.slice(index + source.length)\n}","import type {CoreOption} from '../../shared/types'\nimport {annotate} from '../parsing'\n\nexport function createRowContent(options: CoreOption[]): string {\n\tconst firstOption = options[0]\n\tif (!firstOption.markup) return '\\n'\n\treturn annotate(firstOption.markup, {value: '', slot: '', meta: ''})\n}","import {childAt} from '../../../shared/checkers'\nimport type {Store} from '../../../store'\n\nexport function deleteMark(place: 'prev' | 'self' | 'next', store: Store) {\n\tconst placeMap = {\n\t\tprev: 2,\n\t\tself: 1,\n\t\tnext: 0,\n\t}\n\tconst placeIndex = placeMap[place]\n\tconst {focus} = store.nodes\n\tconst targetIndex = Math.max(0, focus.index - placeIndex)\n\n\tconst tokens = store.state.tokens()\n\tconst spliced = tokens.splice(focus.index - placeIndex, 3)\n\tconst span1 = spliced.at(0)\n\tconst span2 = spliced.at(2)\n\tconst content1 = span1?.content ?? ''\n\tconst content2 = span2?.content ?? ''\n\tstore.state.tokens(\n\t\ttokens.toSpliced(focus.index - placeIndex, 0, {\n\t\t\ttype: 'text',\n\t\t\tcontent: content1 + content2,\n\t\t\tposition: {\n\t\t\t\tstart: span1?.position.start ?? 0,\n\t\t\t\tend: span2?.position.end ?? (content1 + content2).length,\n\t\t\t},\n\t\t})\n\t)\n\n\tlet caretAnchor = focus\n\tfor (let i = 0; i < placeIndex; i++) {\n\t\tcaretAnchor = caretAnchor.prev\n\t}\n\tconst caret = caretAnchor.length\n\n\tstore.state.recovery({anchor: caretAnchor.prev, caret})\n\n\tstore.event.change()\n\n\tqueueMicrotask(() => {\n\t\tconst target = childAt(store.refs.container, targetIndex)\n\t\tif (!target) return\n\t\tstore.nodes.focus.target = target\n\t\ttarget.focus()\n\t\tstore.nodes.focus.caret = caret\n\t})\n}","export function isTextTokenSpan(el: HTMLElement): boolean {\n\treturn (\n\t\tel.tagName === 'SPAN' &&\n\t\t(el.attributes.length === 0 || (el.attributes.length === 1 && el.hasAttribute('contenteditable')))\n\t)\n}","import {childAt} from '../../shared/checkers'\nimport {effectScope, effect, watch} from '../../shared/signals/index.js'\nimport type {Store} from '../../store/Store'\nimport type {Token} from '../parsing'\nimport {isTextTokenSpan} from './isTextTokenSpan'\n\nexport class ContentEditableFeature {\n\t#scope?: () => void\n\n\tconstructor(private readonly store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\n\t\tthis.#scope = effectScope(() => {\n\t\t\teffect(() => {\n\t\t\t\tthis.store.props.readOnly()\n\t\t\t\tthis.sync()\n\t\t\t})\n\t\t\teffect(() => {\n\t\t\t\tif (this.store.state.selecting() === undefined) this.sync()\n\t\t\t})\n\t\t\twatch(this.store.event.sync, () => {\n\t\t\t\tthis.sync()\n\t\t\t})\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t}\n\n\tsync() {\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tconst readOnly = this.store.props.readOnly()\n\t\tconst value = readOnly ? 'false' : 'true'\n\t\tconst children = container.children\n\t\tconst isBlock = this.store.computed.isBlock()\n\n\t\tif (isBlock) {\n\t\t\t// In block mode, only set contentEditable on text rows (DragMark divs).\n\t\t\t// Mark rows get tabIndex for focusability but are not contentEditable.\n\t\t\tconst tokens = this.store.state.tokens()\n\t\t\tfor (let i = 0; i < tokens.length && i < children.length; i++) {\n\t\t\t\tconst el = childAt(container, i)\n\t\t\t\tif (!el) continue\n\t\t\t\tif (tokens[i].type === 'mark') {\n\t\t\t\t\tif (!readOnly) el.tabIndex = 0\n\t\t\t\t} else {\n\t\t\t\t\tel.contentEditable = value\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\t// In inline mode, even-indexed children are text spans (odd are marks).\n\t\t\tfor (let i = 0; i < children.length; i += 2) {\n\t\t\t\tconst el = childAt(container, i)\n\t\t\t\tif (el) el.contentEditable = value\n\t\t\t}\n\t\t}\n\n\t\t// Sync textContent for all text spans (including nested)\n\t\tconst tokens = this.store.state.tokens()\n\t\tif (isBlock) {\n\t\t\tthis.#syncDragTextContent(tokens, container, readOnly)\n\t\t} else {\n\t\t\tthis.#syncTextContent(tokens, container)\n\t\t}\n\t}\n\n\t#syncTextContent(tokens: Token[], parent: HTMLElement) {\n\t\tfor (let i = 0; i < tokens.length; i++) {\n\t\t\tconst token = tokens[i]\n\t\t\tconst el = childAt(parent, i)\n\t\t\tif (!el) continue\n\t\t\tif (token.type === 'text') {\n\t\t\t\tif (el.textContent !== token.content) {\n\t\t\t\t\tel.textContent = token.content\n\t\t\t\t}\n\t\t\t} else if (token.children.length > 0) {\n\t\t\t\tthis.#syncMarkChildren(token.children, el)\n\t\t\t}\n\t\t}\n\t}\n\n\t#syncMarkChildren(tokens: Token[], parent: HTMLElement, editable?: string) {\n\t\t// Walk direct children and match to tokens sequentially.\n\t\t// Text tokens render as <span> (no attributes, or only contenteditable).\n\t\t// Mark tokens render as elements with attributes (classes, data-*, etc).\n\t\t// Skip any extra mark-component elements (inputs, buttons, etc.)\n\t\tconst children = parent.children\n\t\tlet childIdx = 0\n\n\t\tfor (const token of tokens) {\n\t\t\tif (token.type === 'text') {\n\t\t\t\t// Find next text-token span (bare or with only contenteditable)\n\t\t\t\twhile (childIdx < children.length) {\n\t\t\t\t\tconst el = childAt(parent, childIdx)\n\t\t\t\t\tif (el && isTextTokenSpan(el)) break\n\t\t\t\t\tchildIdx++\n\t\t\t\t}\n\t\t\t\tconst el = childAt(parent, childIdx)\n\t\t\t\tif (el) {\n\t\t\t\t\tif (el.textContent !== token.content) {\n\t\t\t\t\t\tel.textContent = token.content\n\t\t\t\t\t}\n\t\t\t\t\tif (editable !== undefined) el.contentEditable = editable\n\t\t\t\t\tchildIdx++\n\t\t\t\t}\n\t\t\t} else if (token.children.length > 0) {\n\t\t\t\t// Find next element with attributes (mark element)\n\t\t\t\twhile (childIdx < children.length) {\n\t\t\t\t\tconst el = childAt(parent, childIdx)\n\t\t\t\t\tif (el && !isTextTokenSpan(el)) break\n\t\t\t\t\tchildIdx++\n\t\t\t\t}\n\t\t\t\tconst el = childAt(parent, childIdx)\n\t\t\t\tif (el) {\n\t\t\t\t\tthis.#syncMarkChildren(token.children, el, editable)\n\t\t\t\t\tchildIdx++\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t#syncDragTextContent(tokens: Token[], container: HTMLElement, readOnly: boolean) {\n\t\tconst editable = readOnly ? 'false' : 'true'\n\t\tfor (let ri = 0; ri < tokens.length; ri++) {\n\t\t\tconst token = tokens[ri]\n\t\t\tconst blockEl = childAt(container, ri)\n\t\t\tif (!blockEl) continue\n\n\t\t\tif (token.type === 'mark') {\n\t\t\t\tif (token.children.length > 0) {\n\t\t\t\t\t// In Vue, mark rows are wrapped in DragMark (has data-testid).\n\t\t\t\t\t// In React, mark rows render directly as the mark element.\n\t\t\t\t\tconst hasDragWrapper = blockEl.hasAttribute('data-testid')\n\t\t\t\t\tconst markEl = hasDragWrapper ? childAt(blockEl, readOnly ? 0 : 1) : blockEl\n\t\t\t\t\tif (markEl) {\n\t\t\t\t\t\tthis.#syncMarkChildren(token.children, markEl, editable)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\t// Text row: DragMark div with side panel offset\n\t\t\tconst offset = readOnly ? 0 : 1\n\t\t\tconst el = childAt(blockEl, offset)\n\t\t\tif (!el) continue\n\t\t\tif (el.textContent !== token.content) {\n\t\t\t\tel.textContent = token.content\n\t\t\t}\n\t\t}\n\t}\n}","import {isHtmlElement, isTextNode, nextText} from '../../shared/checkers'\nimport {Caret} from '../caret'\nimport {isTextTokenSpan} from '../editable'\nimport type {MarkToken, Token} from '../parsing'\n\nexport function getCaretRawPosInBlock(blockDiv: HTMLElement, token: Token): number {\n\tconst selection = window.getSelection()\n\tif (!selection?.rangeCount) return token.position.end\n\n\tconst {focusNode, focusOffset} = selection\n\tif (!focusNode) return token.position.end\n\n\treturn getDomRawPos(focusNode, focusOffset, blockDiv, token)\n}\n\nexport function setCaretAtRawPos(blockDiv: HTMLElement, token: Token, rawAbsolutePos: number): void {\n\tconst sel = window.getSelection()\n\tif (!sel) return\n\n\tif (token.type === 'mark') {\n\t\tif (setCaretInMarkAtRawPos(blockDiv, token, rawAbsolutePos)) return\n\t\tCaret.setCaretToEnd(blockDiv)\n\t\treturn\n\t}\n\n\tconst offsetWithinToken = rawAbsolutePos - token.position.start\n\tconst walker = document.createTreeWalker(blockDiv, 4)\n\tconst textNode = nextText(walker)\n\tif (textNode) {\n\t\tconst charOffset = Math.min(offsetWithinToken, textNode.length)\n\t\tconst range = document.createRange()\n\t\trange.setStart(textNode, charOffset)\n\t\trange.collapse(true)\n\t\tsel.removeAllRanges()\n\t\tsel.addRange(range)\n\t\treturn\n\t}\n\n\tCaret.setCaretToEnd(blockDiv)\n}\n\nexport function getDomRawPos(node: Node, offset: number, blockDiv: HTMLElement, token: Token): number {\n\tif (node === blockDiv) {\n\t\tconst sel = window.getSelection()\n\t\tif (sel?.focusNode && sel.focusNode !== blockDiv) {\n\t\t\treturn getDomRawPos(sel.focusNode, sel.focusOffset, blockDiv, token)\n\t\t}\n\t\treturn token.position.end\n\t}\n\n\tif (node.nodeType === Node.TEXT_NODE && node.parentElement === blockDiv) {\n\t\tif (token.type === 'mark') {\n\t\t\treturn getDomRawPosInMark(node, offset, blockDiv, token)\n\t\t}\n\t\treturn token.position.start + Math.min(offset, token.content.length)\n\t}\n\n\tlet child: Node | null = node.nodeType === Node.ELEMENT_NODE ? node : node.parentElement\n\twhile (child && child.parentElement !== blockDiv) {\n\t\tchild = child.parentElement\n\t}\n\tif (!child) return token.position.end\n\n\tif (token.type === 'mark') {\n\t\treturn getDomRawPosInMark(node, offset, blockDiv, token)\n\t}\n\n\treturn token.position.start + Math.min(offset, token.content.length)\n}\n\nexport function getDomRawPosInMark(node: Node, offset: number, markElement: HTMLElement, markToken: MarkToken): number {\n\tif (markToken.children.length === 0) {\n\t\tif (offset === 0) return markToken.position.start\n\t\tconst nestedLen = markToken.slot?.content.length ?? markToken.value.length\n\t\tif (nestedLen > 0 && offset >= nestedLen) {\n\t\t\tif (markToken.content.endsWith('\\n\\n') && markToken.slot) {\n\t\t\t\treturn markToken.slot.end\n\t\t\t}\n\t\t\treturn markToken.position.end\n\t\t}\n\t\treturn (markToken.slot?.start ?? markToken.position.start) + Math.min(offset, nestedLen)\n\t}\n\n\tlet tokenIdx = 0\n\tfor (const childNode of Array.from(markElement.childNodes)) {\n\t\tif (tokenIdx >= markToken.children.length) break\n\t\tconst tokenChild = markToken.children[tokenIdx]\n\n\t\tif (isHtmlElement(childNode) && tokenChild.type === 'text') {\n\t\t\tif (!isTextTokenSpan(childNode)) continue\n\t\t\tif (node === childNode) {\n\t\t\t\tconst charOffset = offset === 0 ? 0 : tokenChild.content.length\n\t\t\t\treturn tokenChild.position.start + Math.min(charOffset, tokenChild.content.length)\n\t\t\t}\n\t\t\tif (childNode.contains(node)) {\n\t\t\t\treturn tokenChild.position.start + Math.min(offset, tokenChild.content.length)\n\t\t\t}\n\t\t\ttokenIdx++\n\t\t} else if (isTextNode(childNode) && tokenChild.type === 'text') {\n\t\t\tif (node === childNode) {\n\t\t\t\treturn tokenChild.position.start + Math.min(offset, tokenChild.content.length)\n\t\t\t}\n\t\t\ttokenIdx++\n\t\t} else if (isHtmlElement(childNode) && tokenChild.type === 'mark') {\n\t\t\tif (childNode === node || childNode.contains(node)) {\n\t\t\t\treturn getDomRawPosInMark(node, offset, childNode, tokenChild)\n\t\t\t}\n\t\t\ttokenIdx++\n\t\t}\n\t}\n\n\treturn markToken.slot?.end ?? markToken.position.end\n}\n\nfunction setCaretInMarkAtRawPos(markElement: HTMLElement, markToken: MarkToken, rawAbsolutePos: number): boolean {\n\tconst sel = window.getSelection()\n\tif (!sel) return false\n\n\tlet tokenIdx = 0\n\tfor (const childNode of Array.from(markElement.childNodes)) {\n\t\tif (tokenIdx >= markToken.children.length) break\n\t\tconst tokenChild = markToken.children[tokenIdx]\n\n\t\tif (isHtmlElement(childNode) && tokenChild.type === 'text') {\n\t\t\tif (!isTextTokenSpan(childNode)) continue\n\t\t\tif (rawAbsolutePos >= tokenChild.position.start && rawAbsolutePos <= tokenChild.position.end) {\n\t\t\t\tconst rawTextNode = childNode.firstChild\n\t\t\t\tconst textNode = isTextNode(rawTextNode) ? rawTextNode : null\n\t\t\t\tconst offset = rawAbsolutePos - tokenChild.position.start\n\t\t\t\tif (textNode) {\n\t\t\t\t\tconst range = document.createRange()\n\t\t\t\t\trange.setStart(textNode, Math.min(offset, textNode.length))\n\t\t\t\t\trange.collapse(true)\n\t\t\t\t\tsel.removeAllRanges()\n\t\t\t\t\tsel.addRange(range)\n\t\t\t\t} else {\n\t\t\t\t\tconst range = document.createRange()\n\t\t\t\t\trange.setStart(childNode, 0)\n\t\t\t\t\trange.collapse(true)\n\t\t\t\t\tsel.removeAllRanges()\n\t\t\t\t\tsel.addRange(range)\n\t\t\t\t}\n\t\t\t\treturn true\n\t\t\t}\n\t\t\ttokenIdx++\n\t\t} else if (isTextNode(childNode) && tokenChild.type === 'text') {\n\t\t\tif (rawAbsolutePos >= tokenChild.position.start && rawAbsolutePos <= tokenChild.position.end) {\n\t\t\t\tconst offset = Math.min(rawAbsolutePos - tokenChild.position.start, childNode.length)\n\t\t\t\tconst range = document.createRange()\n\t\t\t\trange.setStart(childNode, offset)\n\t\t\t\trange.collapse(true)\n\t\t\t\tsel.removeAllRanges()\n\t\t\t\tsel.addRange(range)\n\t\t\t\treturn true\n\t\t\t}\n\t\t\ttokenIdx++\n\t\t} else if (isHtmlElement(childNode) && tokenChild.type === 'mark') {\n\t\t\tconst nextChild = tokenIdx + 1 < markToken.children.length ? markToken.children[tokenIdx + 1] : null\n\t\t\tconst atBoundary =\n\t\t\t\trawAbsolutePos === tokenChild.position.end && nextChild?.position.start === rawAbsolutePos\n\t\t\tif (\n\t\t\t\t!atBoundary &&\n\t\t\t\trawAbsolutePos >= tokenChild.position.start &&\n\t\t\t\trawAbsolutePos <= tokenChild.position.end\n\t\t\t) {\n\t\t\t\treturn setCaretInMarkAtRawPos(childNode, tokenChild, rawAbsolutePos)\n\t\t\t}\n\t\t\ttokenIdx++\n\t\t}\n\t}\n\n\treturn false\n}","import {childAt, htmlChildren, isHtmlElement} from '../../shared/checkers'\nimport {KEYBOARD} from '../../shared/constants'\nimport {effectScope, listen} from '../../shared/signals/index.js'\nimport type {Store} from '../../store/Store'\nimport {Caret} from '../caret'\nimport {consumeMarkupPaste} from '../clipboard'\nimport {addDragRow, getMergeDragRowJoinPos, mergeDragRows, canMergeRows} from '../drag/operations'\nimport {createRowContent} from '../editing'\nimport type {Token} from '../parsing'\nimport {getCaretRawPosInBlock, getDomRawPos, setCaretAtRawPos} from './rawPosition'\n\nfunction isTextLikeRow(token: Token): boolean {\n\tif (token.type === 'text') return true\n\treturn token.descriptor.hasSlot && token.descriptor.segments.length === 1\n}\n\nexport class BlockEditFeature {\n\t#scope?: () => void\n\n\tconstructor(private readonly store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tthis.#scope = effectScope(() => {\n\t\t\tlisten(container, 'keydown', e => {\n\t\t\t\tif (!this.store.computed.isBlock()) return\n\n\t\t\t\tif (e.key === KEYBOARD.LEFT || e.key === KEYBOARD.RIGHT) {\n\t\t\t\t\tthis.#handleBlockArrowLeftRight(e, e.key === KEYBOARD.LEFT ? 'left' : 'right')\n\t\t\t\t} else if (e.key === KEYBOARD.UP || e.key === KEYBOARD.DOWN) {\n\t\t\t\t\tthis.#handleArrowUpDown(e)\n\t\t\t\t}\n\n\t\t\t\tthis.#handleDelete(e)\n\t\t\t\tthis.#handleEnter(e)\n\t\t\t})\n\n\t\t\tlisten(\n\t\t\t\tcontainer,\n\t\t\t\t'beforeinput',\n\t\t\t\te => {\n\t\t\t\t\tif (!this.store.computed.isBlock()) return\n\t\t\t\t\tif (e.defaultPrevented) return\n\t\t\t\t\tthis.#handleBlockBeforeInput(e)\n\t\t\t\t},\n\t\t\t\ttrue\n\t\t\t)\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t}\n\n\t#handleDelete(event: KeyboardEvent) {\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tconst blockDivs = htmlChildren(container)\n\t\tconst blockIndex = blockDivs.findIndex(\n\t\t\tdiv => div === document.activeElement || div.contains(document.activeElement)\n\t\t)\n\t\tif (blockIndex === -1) return\n\n\t\tconst rows = this.store.state.tokens()\n\t\tif (blockIndex >= rows.length) return\n\n\t\tconst token = rows[blockIndex]\n\t\tconst value = this.store.computed.currentValue()\n\t\tif (!this.store.props.onChange()) return\n\n\t\tif (event.key === KEYBOARD.BACKSPACE) {\n\t\t\tconst blockDiv = blockDivs[blockIndex]\n\t\t\tconst caretAtStart = Caret.getCaretIndex(blockDiv) === 0\n\n\t\t\tconst blockText = 'content' in token ? token.content : ''\n\t\t\tif (blockText === '') {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tconst newValue =\n\t\t\t\t\trows.length <= 1\n\t\t\t\t\t\t? ''\n\t\t\t\t\t\t: (() => {\n\t\t\t\t\t\t\t\tif (blockIndex >= rows.length - 1)\n\t\t\t\t\t\t\t\t\treturn value.slice(0, rows[blockIndex - 1].position.end)\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\tvalue.slice(0, rows[blockIndex].position.start) +\n\t\t\t\t\t\t\t\t\tvalue.slice(rows[blockIndex + 1].position.start)\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t})()\n\t\t\t\tthis.store.state.innerValue(newValue)\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\tconst targetIndex = Math.max(0, blockIndex - 1)\n\t\t\t\t\tconst target = childAt(container, targetIndex)\n\t\t\t\t\tif (target) {\n\t\t\t\t\t\ttarget.focus()\n\t\t\t\t\t\tCaret.setCaretToEnd(target)\n\t\t\t\t\t}\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (caretAtStart && blockIndex > 0) {\n\t\t\t\tconst prevToken = rows[blockIndex - 1]\n\t\t\t\tconst currToken = rows[blockIndex]\n\t\t\t\tif (canMergeRows(prevToken, currToken)) {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tconst joinPos = getMergeDragRowJoinPos(rows, blockIndex)\n\t\t\t\t\tconst newValue = mergeDragRows(value, rows, blockIndex)\n\t\t\t\t\tthis.store.state.innerValue(newValue)\n\t\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\t\tconst target = childAt(container, blockIndex - 1)\n\t\t\t\t\t\tif (target) {\n\t\t\t\t\t\t\ttarget.focus()\n\t\t\t\t\t\t\tconst updatedRows = this.store.state.tokens()\n\t\t\t\t\t\t\tconst updatedToken = updatedRows[blockIndex - 1]\n\t\t\t\t\t\t\tsetCaretAtRawPos(target, updatedToken, joinPos)\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tevent.preventDefault()\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\tconst target = blockDivs[blockIndex - 1]\n\t\t\t\t\ttarget.focus()\n\t\t\t\t\tif (prevToken.type !== 'mark') Caret.setCaretToEnd(target)\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tif (event.key === KEYBOARD.DELETE) {\n\t\t\tconst blockDiv = blockDivs[blockIndex]\n\t\t\tconst caretIndex = Caret.getCaretIndex(blockDiv)\n\t\t\tconst caretAtEnd = caretIndex === blockDiv.textContent.length\n\t\t\tconst caretAtStart = caretIndex === 0\n\n\t\t\tif (caretAtStart && blockIndex > 0) {\n\t\t\t\tconst prevToken = rows[blockIndex - 1]\n\t\t\t\tconst currToken = rows[blockIndex]\n\t\t\t\tif (canMergeRows(prevToken, currToken)) {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tconst joinPos = getMergeDragRowJoinPos(rows, blockIndex)\n\t\t\t\t\tconst newValue = mergeDragRows(value, rows, blockIndex)\n\t\t\t\t\tthis.store.state.innerValue(newValue)\n\t\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\t\tconst target = childAt(container, blockIndex - 1)\n\t\t\t\t\t\tif (target) {\n\t\t\t\t\t\t\ttarget.focus()\n\t\t\t\t\t\t\tconst updatedRows = this.store.state.tokens()\n\t\t\t\t\t\t\tconst updatedToken = updatedRows[blockIndex - 1]\n\t\t\t\t\t\t\tsetCaretAtRawPos(target, updatedToken, joinPos)\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tevent.preventDefault()\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\tconst target = blockDivs[blockIndex - 1]\n\t\t\t\t\ttarget.focus()\n\t\t\t\t\tif (prevToken.type !== 'mark') Caret.setCaretToEnd(target)\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif (caretAtEnd && blockIndex < rows.length - 1) {\n\t\t\t\tconst currToken = rows[blockIndex]\n\t\t\t\tconst nextToken = rows[blockIndex + 1]\n\t\t\t\tif (canMergeRows(currToken, nextToken)) {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tconst joinPos = getMergeDragRowJoinPos(rows, blockIndex + 1)\n\t\t\t\t\tconst newValue = mergeDragRows(value, rows, blockIndex + 1)\n\t\t\t\t\tthis.store.state.innerValue(newValue)\n\t\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\t\tconst target = childAt(container, blockIndex)\n\t\t\t\t\t\tif (target) {\n\t\t\t\t\t\t\ttarget.focus()\n\t\t\t\t\t\t\tconst updatedRows = this.store.state.tokens()\n\t\t\t\t\t\t\tconst updatedToken = updatedRows[blockIndex]\n\t\t\t\t\t\t\tsetCaretAtRawPos(target, updatedToken, joinPos)\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tevent.preventDefault()\n\t\t\t\tqueueMicrotask(() => {\n\t\t\t\t\tconst target = blockDivs[blockIndex + 1]\n\t\t\t\t\ttarget.focus()\n\t\t\t\t\tCaret.trySetIndex(target, 0)\n\t\t\t\t})\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n\n\t#handleEnter(event: KeyboardEvent) {\n\t\tif (event.key !== KEYBOARD.ENTER) return\n\t\tif (event.shiftKey) return\n\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tconst activeElement = document.activeElement\n\t\tif (!isHtmlElement(activeElement) || !container.contains(activeElement)) return\n\n\t\tevent.preventDefault()\n\n\t\tconst blockDivs = htmlChildren(container)\n\t\tlet blockIndex = -1\n\t\tfor (let i = 0; i < blockDivs.length; i++) {\n\t\t\tif (blockDivs[i] === activeElement || blockDivs[i].contains(activeElement)) {\n\t\t\t\tblockIndex = i\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif (blockIndex === -1) return\n\n\t\tconst rows = this.store.state.tokens()\n\t\tconst token = rows[blockIndex]\n\t\tconst blockDiv = blockDivs[blockIndex]\n\t\tconst value = this.store.computed.currentValue()\n\n\t\tif (!this.store.props.onChange()) return\n\n\t\tconst newRowContent = createRowContent(this.store.props.options())\n\n\t\tif (!isTextLikeRow(token)) {\n\t\t\tconst newValue = addDragRow(value, rows, blockIndex, newRowContent)\n\t\t\tthis.store.state.innerValue(newValue)\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tconst newBlockIndex = blockIndex + 1\n\t\t\t\tif (newBlockIndex < container.children.length) {\n\t\t\t\t\tconst newBlockEl = childAt(container, newBlockIndex)\n\t\t\t\t\tif (newBlockEl) {\n\t\t\t\t\t\tnewBlockEl.focus()\n\t\t\t\t\t\tCaret.trySetIndex(newBlockEl, 0)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\t\t\treturn\n\t\t}\n\n\t\tconst absolutePos = getCaretRawPosInBlock(blockDiv, token)\n\t\tconst newValue = value.slice(0, absolutePos) + newRowContent + value.slice(absolutePos)\n\t\tthis.store.state.innerValue(newValue)\n\n\t\tqueueMicrotask(() => {\n\t\t\tconst newBlockIndex = blockIndex + 1\n\t\t\tif (newBlockIndex < container.children.length) {\n\t\t\t\tconst newBlockEl = childAt(container, newBlockIndex)\n\t\t\t\tif (newBlockEl) {\n\t\t\t\t\tnewBlockEl.focus()\n\t\t\t\t\tCaret.trySetIndex(newBlockEl, 0)\n\t\t\t\t}\n\t\t\t}\n\t\t})\n\t}\n\n\t#handleBlockArrowLeftRight(event: KeyboardEvent, direction: 'left' | 'right'): boolean {\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return false\n\n\t\tconst activeElement = document.activeElement\n\t\tif (!isHtmlElement(activeElement) || !container.contains(activeElement)) return false\n\n\t\tconst blockDivs = htmlChildren(container)\n\t\tconst blockIndex = blockDivs.findIndex(div => div === activeElement || div.contains(activeElement))\n\t\tif (blockIndex === -1) return false\n\n\t\tconst blockDiv = blockDivs[blockIndex]\n\n\t\tif (direction === 'left') {\n\t\t\tif (Caret.getCaretIndex(blockDiv) !== 0) return false\n\t\t\tif (blockIndex === 0) return true\n\t\t\tevent.preventDefault()\n\t\t\tconst prevBlock = blockDivs[blockIndex - 1]\n\t\t\tprevBlock.focus()\n\t\t\tCaret.setCaretToEnd(prevBlock)\n\t\t\treturn true\n\t\t}\n\n\t\tconst caretIndex = Caret.getCaretIndex(blockDiv)\n\t\tconst textLen = blockDiv.textContent.length\n\t\tif (caretIndex !== textLen) return false\n\t\tif (blockIndex >= blockDivs.length - 1) return true\n\t\tevent.preventDefault()\n\t\tconst nextBlock = blockDivs[blockIndex + 1]\n\t\tnextBlock.focus()\n\t\tCaret.trySetIndex(nextBlock, 0)\n\t\treturn true\n\t}\n\n\t#handleArrowUpDown(event: KeyboardEvent) {\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tconst activeElement = document.activeElement\n\t\tif (!isHtmlElement(activeElement) || !container.contains(activeElement)) return\n\n\t\tconst blockDivs = htmlChildren(container)\n\t\tconst blockIndex = blockDivs.findIndex(div => div === activeElement || div.contains(activeElement))\n\t\tif (blockIndex === -1) return\n\n\t\tconst blockDiv = blockDivs[blockIndex]\n\n\t\tif (event.key === KEYBOARD.UP) {\n\t\t\tif (!Caret.isCaretOnFirstLine(blockDiv)) return\n\t\t\tif (blockIndex === 0) return\n\n\t\t\tevent.preventDefault()\n\t\t\tconst caretRect = Caret.getCaretRect()\n\t\t\tconst caretX = caretRect?.left ?? blockDiv.getBoundingClientRect().left\n\t\t\tconst prevBlockDiv = blockDivs[blockIndex - 1]\n\t\t\tprevBlockDiv.focus()\n\t\t\tconst prevRect = prevBlockDiv.getBoundingClientRect()\n\t\t\tCaret.setAtX(prevBlockDiv, caretX, prevRect.bottom - 4)\n\t\t} else if (event.key === KEYBOARD.DOWN) {\n\t\t\tif (!Caret.isCaretOnLastLine(blockDiv)) return\n\t\t\tif (blockIndex >= blockDivs.length - 1) return\n\n\t\t\tevent.preventDefault()\n\t\t\tconst caretRect = Caret.getCaretRect()\n\t\t\tconst caretX = caretRect?.left ?? blockDiv.getBoundingClientRect().left\n\t\t\tconst nextBlockDiv = blockDivs[blockIndex + 1]\n\t\t\tnextBlockDiv.focus()\n\t\t\tconst nextRect = nextBlockDiv.getBoundingClientRect()\n\t\t\tCaret.setAtX(nextBlockDiv, caretX, nextRect.top + 4)\n\t\t}\n\t}\n\n\t#handleBlockBeforeInput(event: InputEvent) {\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tconst activeElement = document.activeElement\n\t\tif (!isHtmlElement(activeElement) || !container.contains(activeElement)) return\n\n\t\tconst blockDivs = htmlChildren(container)\n\t\tconst blockIndex = blockDivs.findIndex(div => div === activeElement || div.contains(activeElement))\n\t\tif (blockIndex === -1) return\n\n\t\tconst blockDiv = blockDivs[blockIndex]\n\t\tconst rows = this.store.state.tokens()\n\t\tif (blockIndex >= rows.length) return\n\n\t\tconst token = rows[blockIndex]\n\t\tconst value = this.store.computed.currentValue()\n\n\t\tconst focusAndSetCaret = (newRawPos: number) => {\n\t\t\tqueueMicrotask(() => {\n\t\t\t\tconst target = childAt(container, blockIndex)\n\t\t\t\tif (!target) return\n\t\t\t\ttarget.focus()\n\t\t\t\tconst updatedRows = this.store.state.tokens()\n\t\t\t\tconst updatedToken = updatedRows[blockIndex]\n\t\t\t\tsetCaretAtRawPos(target, updatedToken, newRawPos)\n\t\t\t})\n\t\t}\n\n\t\tswitch (event.inputType) {\n\t\t\tcase 'insertText': {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tconst data = event.data ?? ''\n\t\t\t\tconst ranges = event.getTargetRanges()\n\t\t\t\tlet rawFrom: number\n\t\t\t\tlet rawTo: number\n\t\t\t\tif (ranges.length > 0) {\n\t\t\t\t\tconst rawStart = getDomRawPos(ranges[0].startContainer, ranges[0].startOffset, blockDiv, token)\n\t\t\t\t\tconst rawEnd = getDomRawPos(ranges[0].endContainer, ranges[0].endOffset, blockDiv, token)\n\t\t\t\t\t;[rawFrom, rawTo] = rawStart <= rawEnd ? [rawStart, rawEnd] : [rawEnd, rawStart]\n\t\t\t\t} else {\n\t\t\t\t\trawFrom = rawTo = getCaretRawPosInBlock(blockDiv, token)\n\t\t\t\t}\n\t\t\t\tthis.store.state.innerValue(value.slice(0, rawFrom) + data + value.slice(rawTo))\n\t\t\t\tfocusAndSetCaret(rawFrom + data.length)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'insertFromPaste':\n\t\t\tcase 'insertReplacementText': {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tconst markup = this.store.refs.container ? consumeMarkupPaste(this.store.refs.container) : undefined\n\t\t\t\tconst pasteData = markup ?? event.dataTransfer?.getData('text/plain') ?? ''\n\t\t\t\tconst ranges = event.getTargetRanges()\n\t\t\t\tlet rawFrom: number\n\t\t\t\tlet rawTo: number\n\t\t\t\tif (ranges.length > 0) {\n\t\t\t\t\tconst rawStart = getDomRawPos(ranges[0].startContainer, ranges[0].startOffset, blockDiv, token)\n\t\t\t\t\tconst rawEnd = getDomRawPos(ranges[0].endContainer, ranges[0].endOffset, blockDiv, token)\n\t\t\t\t\t;[rawFrom, rawTo] = rawStart <= rawEnd ? [rawStart, rawEnd] : [rawEnd, rawStart]\n\t\t\t\t} else {\n\t\t\t\t\trawFrom = rawTo = getCaretRawPosInBlock(blockDiv, token)\n\t\t\t\t}\n\t\t\t\tthis.store.state.innerValue(value.slice(0, rawFrom) + pasteData + value.slice(rawTo))\n\t\t\t\tfocusAndSetCaret(rawFrom + pasteData.length)\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase 'deleteContentBackward':\n\t\t\tcase 'deleteContentForward':\n\t\t\tcase 'deleteWordBackward':\n\t\t\tcase 'deleteWordForward':\n\t\t\tcase 'deleteSoftLineBackward':\n\t\t\tcase 'deleteSoftLineForward': {\n\t\t\t\tconst ranges = event.getTargetRanges()\n\t\t\t\tif (!ranges.length) return\n\t\t\t\tconst rawStart = getDomRawPos(ranges[0].startContainer, ranges[0].startOffset, blockDiv, token)\n\t\t\t\tconst rawEnd = getDomRawPos(ranges[0].endContainer, ranges[0].endOffset, blockDiv, token)\n\t\t\t\tconst [rawFrom, rawTo] = rawStart <= rawEnd ? [rawStart, rawEnd] : [rawEnd, rawStart]\n\t\t\t\tif (rawFrom === rawTo) return\n\t\t\t\tevent.preventDefault()\n\t\t\t\tthis.store.state.innerValue(value.slice(0, rawFrom) + value.slice(rawTo))\n\t\t\t\tfocusAndSetCaret(rawFrom)\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t}\n}","import type {Token} from '../parsing'\n\nexport const EMPTY_TEXT_TOKEN: Token = {type: 'text', content: '', position: {start: 0, end: 0}}","import {childAt} from '../../shared/checkers'\nimport {watch} from '../../shared/signals'\nimport type {Store} from '../../store/Store'\nimport {createRowContent} from '../editing'\nimport {addDragRow, deleteDragRow, duplicateDragRow, reorderDragRows} from './operations'\nimport {EMPTY_TEXT_TOKEN} from './tokens'\n\nexport class DragFeature {\n\tconstructor(private readonly store: Store) {}\n\n\t#unsub?: () => void\n\n\tenable() {\n\t\tif (this.#unsub) return\n\n\t\tthis.#unsub = watch(this.store.event.dragAction, action => {\n\t\t\tswitch (action.type) {\n\t\t\t\tcase 'reorder':\n\t\t\t\t\tthis.#reorder(action.source, action.target)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'add':\n\t\t\t\t\tthis.#add(action.afterIndex)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'delete':\n\t\t\t\t\tthis.#delete(action.index)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'duplicate':\n\t\t\t\t\tthis.#duplicate(action.index)\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#unsub?.()\n\t\tthis.#unsub = undefined\n\t}\n\n\t#reorder(sourceIndex: number, targetIndex: number) {\n\t\tconst value = this.store.props.value()\n\t\tif (value == null || !this.store.props.onChange()) return\n\t\tconst rows = this.store.state.tokens()\n\t\tconst newValue = reorderDragRows(value, rows, sourceIndex, targetIndex)\n\t\tif (newValue !== value) this.store.state.innerValue(newValue)\n\t}\n\n\t#add(afterIndex: number) {\n\t\tconst value = this.store.props.value()\n\t\tif (value == null || !this.store.props.onChange()) return\n\t\tconst rawRows = this.store.state.tokens()\n\t\tconst rows = rawRows.length > 0 ? rawRows : [EMPTY_TEXT_TOKEN]\n\t\tconst newRowContent = createRowContent(this.store.props.options())\n\t\tthis.store.state.innerValue(addDragRow(value, rows, afterIndex, newRowContent))\n\t\tqueueMicrotask(() => {\n\t\t\tconst container = this.store.refs.container\n\t\t\tif (!container) return\n\t\t\tconst target = childAt(container, afterIndex + 1)\n\t\t\ttarget?.focus()\n\t\t})\n\t}\n\n\t#delete(index: number) {\n\t\tconst value = this.store.props.value()\n\t\tif (value == null || !this.store.props.onChange()) return\n\t\tconst rows = this.store.state.tokens()\n\t\tthis.store.state.innerValue(deleteDragRow(value, rows, index))\n\t}\n\n\t#duplicate(index: number) {\n\t\tconst value = this.store.props.value()\n\t\tif (value == null || !this.store.props.onChange()) return\n\t\tconst rows = this.store.state.tokens()\n\t\tthis.store.state.innerValue(duplicateDragRow(value, rows, index))\n\t}\n}","export function getDragDropPosition(clientY: number, rect: DOMRect): 'before' | 'after' {\n\treturn clientY < rect.top + rect.height / 2 ? 'before' : 'after'\n}\n\nexport function parseDragSourceIndex(dataTransfer: DataTransfer): number | null {\n\tconst index = parseInt(dataTransfer.getData('text/plain'), 10)\n\treturn isNaN(index) ? null : index\n}\n\nexport function getDragTargetIndex(blockIndex: number, position: 'before' | 'after'): number {\n\treturn position === 'before' ? blockIndex : blockIndex + 1\n}","import type {DraggableConfig} from '../../shared/types'\n\nexport function getAlwaysShowHandle(draggable: boolean | DraggableConfig): boolean {\n\treturn typeof draggable === 'object' && !!draggable.alwaysShowHandle\n}","import {batch, effectScope, watch} from '../../shared/signals/index.js'\nimport type {Store} from '../../store/Store'\nimport {createNewSpan} from '../editing'\nimport {annotate, findToken, parseWithParser, toString} from '../parsing'\n\nexport class SystemListenerFeature {\n\t#scope?: () => void\n\n\tconstructor(private readonly store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\n\t\tthis.#scope = effectScope(() => {\n\t\t\twatch(this.store.event.change, () => {\n\t\t\t\tconst onChange = this.store.props.onChange()\n\t\t\t\tconst {focus} = this.store.nodes\n\n\t\t\t\t// Programmatic mark change or non-editable focus (e.g. a checkbox):\n\t\t\t\t// the token was already mutated in-place by MarkHandler — serialize it\n\t\t\t\t// directly and force a re-render without reading stale DOM content.\n\t\t\t\tif (!focus.target || !focus.target.isContentEditable) {\n\t\t\t\t\tconst tokens = this.store.state.tokens()\n\t\t\t\t\tconst serialized = toString(tokens)\n\t\t\t\t\tonChange?.(serialized)\n\t\t\t\t\tthis.store.state.previousValue(serialized)\n\t\t\t\t\tthis.store.bumpTokens()\n\t\t\t\t\treturn\n\t\t\t\t}\n\n\t\t\t\t// User typed in a contentEditable element: sync DOM content → token state.\n\t\t\t\tconst tokens = this.store.state.tokens()\n\t\t\t\tif (focus.index >= tokens.length) return\n\t\t\t\tconst token = tokens[focus.index]\n\t\t\t\tif (token.type === 'text') {\n\t\t\t\t\ttoken.content = focus.content\n\t\t\t\t} else {\n\t\t\t\t\ttoken.value = focus.content\n\t\t\t\t}\n\n\t\t\t\tonChange?.(toString(tokens))\n\t\t\t\tthis.store.event.parse()\n\t\t\t})\n\n\t\t\twatch(this.store.event.delete, payload => {\n\t\t\t\tconst {token} = payload\n\t\t\t\tconst tokens = this.store.state.tokens()\n\t\t\t\tif (!findToken(tokens, token)) return\n\n\t\t\t\tconst value = toString(tokens)\n\t\t\t\tconst nextValue = value.slice(0, token.position.start) + value.slice(token.position.end)\n\t\t\t\tthis.store.state.innerValue(nextValue)\n\t\t\t})\n\n\t\t\twatch(this.store.state.innerValue, newValue => {\n\t\t\t\tif (newValue === undefined) return\n\t\t\t\tconst newTokens = parseWithParser(this.store, newValue)\n\t\t\t\tbatch(() => {\n\t\t\t\t\tthis.store.state.tokens(newTokens)\n\t\t\t\t\tthis.store.state.previousValue(newValue)\n\t\t\t\t})\n\t\t\t\tthis.store.props.onChange()?.(newValue)\n\t\t\t})\n\n\t\t\twatch(this.store.event.select, event => {\n\t\t\t\tconst Mark = this.store.props.Mark()\n\t\t\t\tconst onChange = this.store.props.onChange()\n\t\t\t\tconst {\n\t\t\t\t\tmark,\n\t\t\t\t\tmatch: {option, span, index, source},\n\t\t\t\t} = event\n\n\t\t\t\tconst markup = option.markup\n\t\t\t\tif (!markup) return\n\n\t\t\t\tconst annotation =\n\t\t\t\t\tmark.type === 'mark'\n\t\t\t\t\t\t? annotate(markup, {\n\t\t\t\t\t\t\t\tvalue: mark.value,\n\t\t\t\t\t\t\t\tmeta: mark.meta,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t: annotate(markup, {\n\t\t\t\t\t\t\t\tvalue: mark.content,\n\t\t\t\t\t\t\t})\n\n\t\t\t\tconst newSpan = createNewSpan(span, annotation, index, source)\n\n\t\t\t\tthis.store.state.recovery(\n\t\t\t\t\tMark\n\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\tcaret: 0,\n\t\t\t\t\t\t\t\tanchor: this.store.nodes.input.next,\n\t\t\t\t\t\t\t\tisNext: true,\n\t\t\t\t\t\t\t\tchildIndex: this.store.nodes.input.index,\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t: {caret: index + annotation.length, anchor: this.store.nodes.input}\n\t\t\t\t)\n\n\t\t\t\tif (this.store.nodes.input.target) {\n\t\t\t\t\tthis.store.nodes.input.content = newSpan\n\t\t\t\t\tconst tokens = this.store.state.tokens()\n\t\t\t\t\tconst inputToken = tokens[this.store.nodes.input.index]\n\t\t\t\t\tif (inputToken.type === 'text') {\n\t\t\t\t\t\tinputToken.content = newSpan\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.store.nodes.focus.target = this.store.nodes.input.target\n\t\t\t\t\tthis.store.nodes.input.clear()\n\t\t\t\t\tonChange?.(toString(tokens))\n\t\t\t\t\tthis.store.event.parse()\n\t\t\t\t}\n\t\t\t})\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t}\n}","import {childAt, firstHtmlChild, isHtmlElement} from '../../shared/checkers'\nimport {effectScope, watch, listen} from '../../shared/signals/index.js'\nimport type {Store} from '../../store/Store'\n\nexport class FocusFeature {\n\t#scope?: () => void\n\n\tconstructor(private readonly store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tthis.#scope = effectScope(() => {\n\t\t\tlisten(container, 'focusin', e => {\n\t\t\t\tconst target = isHtmlElement(e.target) ? e.target : undefined\n\t\t\t\tthis.store.nodes.focus.target = target\n\t\t\t})\n\n\t\t\tlisten(container, 'focusout', () => {\n\t\t\t\tthis.store.nodes.focus.target = undefined\n\t\t\t})\n\n\t\t\tlisten(container, 'click', () => {\n\t\t\t\tconst tokens = this.store.state.tokens()\n\t\t\t\tif (tokens.length === 1 && tokens[0].type === 'text' && tokens[0].content === '') {\n\t\t\t\t\tconst container = this.store.refs.container\n\t\t\t\t\tconst element = container ? firstHtmlChild(container) : null\n\t\t\t\t\telement?.focus()\n\t\t\t\t}\n\t\t\t})\n\n\t\t\twatch(this.store.event.recoverFocus, () => {\n\t\t\t\tthis.#recover()\n\t\t\t})\n\n\t\t\twatch(this.store.event.afterTokensRendered, () => {\n\t\t\t\tthis.store.event.sync()\n\t\t\t\tif (!this.store.props.Mark()) return\n\t\t\t\tthis.store.event.recoverFocus()\n\t\t\t})\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t\tthis.store.nodes.focus.clear()\n\t}\n\n\t#recover() {\n\t\tconst recovery = this.store.state.recovery()\n\t\tif (!recovery) return\n\n\t\tconst {anchor, caret, isNext} = recovery\n\t\tconst isStale = !anchor.target || !anchor.target.isConnected\n\t\tlet target: HTMLElement | undefined\n\n\t\t// eslint-disable-next-line switch-exhaustiveness-check\n\t\tswitch (true) {\n\t\t\tcase isNext && isStale: {\n\t\t\t\tconst container = this.store.refs.container\n\t\t\t\t// After re-parse, text at childIndex splits into [text, mark, text]\n\t\t\t\t// Focus the text span after the mark (childIndex + 2)\n\t\t\t\tconst targetChild =\n\t\t\t\t\trecovery.childIndex != null ? childAt(container, recovery.childIndex + 2) : undefined\n\t\t\t\ttarget = targetChild ?? this.store.nodes.focus.tail ?? undefined\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tcase isNext:\n\t\t\t\ttarget = anchor.prev.target\n\t\t\t\tbreak\n\t\t\tcase isStale:\n\t\t\t\ttarget = this.store.nodes.focus.head ?? undefined\n\t\t\t\tbreak\n\t\t\tdefault:\n\t\t\t\ttarget = anchor.next.target\n\t\t}\n\n\t\tthis.store.nodes.focus.target = target\n\t\ttarget?.focus()\n\t\tqueueMicrotask(() => {\n\t\t\tif (!target?.isConnected) return\n\t\t\tthis.store.nodes.focus.target = target\n\t\t\tthis.store.nodes.focus.caret = caret\n\t\t})\n\t\tthis.store.state.recovery(undefined)\n\t}\n}","import {isHtmlElement} from '../../shared/checkers'\nimport type {NodeProxy} from '../../shared/classes'\nimport {KEYBOARD} from '../../shared/constants'\nimport {effectScope, listen} from '../../shared/signals/index.js'\nimport type {Store} from '../../store/Store'\nimport {captureMarkupPaste, consumeMarkupPaste, getBoundaryOffset} from '../clipboard'\nimport {deleteMark} from '../editing/utils/deleteMark'\nimport {isFullSelection} from '../selection'\n\nexport class InputFeature {\n\t#scope?: () => void\n\n\tconstructor(private readonly store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\n\t\tconst container = this.store.refs.container\n\t\tif (!container) return\n\n\t\tthis.#scope = effectScope(() => {\n\t\t\tlisten(container, 'keydown', e => {\n\t\t\t\tif (!this.store.computed.isBlock()) {\n\t\t\t\t\tthis.#handleDelete(e)\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tlisten(container, 'paste', e => {\n\t\t\t\tconst c = this.store.refs.container\n\t\t\t\tif (c) captureMarkupPaste(e, c)\n\t\t\t\thandlePaste(this.store, e)\n\t\t\t})\n\n\t\t\tlisten(\n\t\t\t\tcontainer,\n\t\t\t\t'beforeinput',\n\t\t\t\te => {\n\t\t\t\t\thandleBeforeInput(this.store, e)\n\t\t\t\t},\n\t\t\t\ttrue\n\t\t\t)\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t}\n\n\t#handleDelete(event: KeyboardEvent) {\n\t\tconst {focus} = this.store.nodes\n\n\t\tif (event.key !== KEYBOARD.DELETE && event.key !== KEYBOARD.BACKSPACE) return\n\n\t\tif (focus.isMark) {\n\t\t\tif (focus.isEditable) {\n\t\t\t\tif (event.key === KEYBOARD.BACKSPACE && !focus.isCaretAtBeginning) return\n\t\t\t\tif (event.key === KEYBOARD.DELETE && !focus.isCaretAtEnd) return\n\t\t\t}\n\t\t\tevent.preventDefault()\n\t\t\tdeleteMark('self', this.store)\n\t\t\treturn\n\t\t}\n\n\t\tif (event.key === KEYBOARD.BACKSPACE) {\n\t\t\tif (focus.isSpan && focus.isCaretAtBeginning && focus.prev.target) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tdeleteMark('prev', this.store)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tif (event.key === KEYBOARD.DELETE) {\n\t\t\tif (focus.isSpan && focus.isCaretAtEnd && focus.next.target) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tdeleteMark('next', this.store)\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\n\t\tif (focus.isSpan && focus.isEditable && window.getSelection()?.isCollapsed) {\n\t\t\tconst content = focus.content\n\t\t\tconst caret = focus.caret\n\t\t\tif (event.key === KEYBOARD.BACKSPACE && caret > 0) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tfocus.content = content.slice(0, caret - 1) + content.slice(caret)\n\t\t\t\tfocus.caret = caret - 1\n\t\t\t\tthis.store.event.change()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (event.key === KEYBOARD.DELETE && caret >= 0 && caret < content.length) {\n\t\t\t\tevent.preventDefault()\n\t\t\t\tfocus.content = content.slice(0, caret) + content.slice(caret + 1)\n\t\t\t\tfocus.caret = caret\n\t\t\t\tthis.store.event.change()\n\t\t\t\treturn\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function handleBeforeInput(store: Store, event: InputEvent): void {\n\tconst selecting = store.state.selecting()\n\tif (selecting === 'all' && isFullSelection(store)) {\n\t\tif (event.inputType === 'insertFromPaste') {\n\t\t\tevent.preventDefault()\n\t\t\treturn\n\t\t}\n\t\tevent.preventDefault()\n\t\tconst newContent = event.inputType.startsWith('delete') ? '' : (event.data ?? '')\n\t\treplaceAllContentWith(store, newContent)\n\t\treturn\n\t}\n\tif (selecting === 'all') store.state.selecting(undefined)\n\n\tif (store.computed.isBlock()) return\n\n\tconst {focus} = store.nodes\n\tif (!focus.target || !focus.isEditable) return\n\n\tif (\n\t\t(event.inputType === 'insertFromPaste' || event.inputType === 'insertReplacementText') &&\n\t\thandleMarkputSpanPaste(store, focus, event)\n\t) {\n\t\treturn\n\t}\n\n\tif (applySpanInput(focus, event)) {\n\t\tstore.event.change()\n\t}\n}\n\nfunction handleMarkputSpanPaste(store: Store, focus: NodeProxy, event: InputEvent): boolean {\n\tconst container = store.refs.container\n\tif (!container) return false\n\tconst markup = consumeMarkupPaste(container)\n\tif (!markup) return false\n\n\tevent.preventDefault()\n\n\tconst tokens = store.state.tokens()\n\tconst token = tokens[focus.index]\n\tconst offset = focus.caret\n\tconst currentValue = store.computed.currentValue()\n\n\tconst ranges = event.getTargetRanges()\n\tconst childElement = container.children[focus.index]\n\tlet rawInsertPos: number\n\tlet rawEndPos: number\n\tif (ranges.length > 0) {\n\t\tconst cumStart = getBoundaryOffset(ranges[0], childElement, true)\n\t\tconst cumEnd = getBoundaryOffset(ranges[0], childElement, false)\n\t\trawInsertPos = token.position.start + cumStart\n\t\trawEndPos = token.position.start + cumEnd\n\t} else {\n\t\trawInsertPos = token.position.start + offset\n\t\trawEndPos = token.position.start + offset\n\t}\n\n\tconst caretPos = rawInsertPos + markup.length\n\tconst newValue = currentValue.slice(0, rawInsertPos) + markup + currentValue.slice(rawEndPos)\n\tstore.state.innerValue(newValue)\n\n\tconst newTokens = store.state.tokens()\n\tlet targetIdx = newTokens.findIndex(\n\t\tt => t.type === 'text' && caretPos >= t.position.start && caretPos <= t.position.end\n\t)\n\tif (targetIdx === -1) targetIdx = newTokens.length - 1\n\tconst caretWithinToken = caretPos - newTokens[targetIdx].position.start\n\n\tstore.state.recovery({\n\t\tanchor: store.nodes.focus,\n\t\tcaret: caretWithinToken,\n\t\tisNext: true,\n\t\tchildIndex: targetIdx - 2,\n\t})\n\treturn true\n}\n\nexport function applySpanInput(focus: NodeProxy, event: InputEvent): boolean {\n\tconst offset = focus.caret\n\tconst content = focus.content\n\tlet newContent: string\n\tlet newCaret: number\n\n\tswitch (event.inputType) {\n\t\tcase 'insertText': {\n\t\t\tevent.preventDefault()\n\t\t\tconst data = event.data ?? ''\n\t\t\tnewContent = content.slice(0, offset) + data + content.slice(offset)\n\t\t\tnewCaret = offset + data.length\n\t\t\tbreak\n\t\t}\n\t\tcase 'deleteContentBackward':\n\t\tcase 'deleteContentForward':\n\t\tcase 'deleteWordBackward':\n\t\tcase 'deleteWordForward':\n\t\tcase 'deleteSoftLineBackward':\n\t\tcase 'deleteSoftLineForward': {\n\t\t\tconst ranges = event.getTargetRanges()\n\t\t\tlet startOffset: number\n\t\t\tlet endOffset: number\n\t\t\tif (ranges.length > 0 && ranges[0].startOffset !== ranges[0].endOffset) {\n\t\t\t\tstartOffset = ranges[0].startOffset\n\t\t\t\tendOffset = ranges[0].endOffset\n\t\t\t} else {\n\t\t\t\tif (event.inputType === 'deleteContentBackward' && offset > 0) {\n\t\t\t\t\tstartOffset = offset - 1\n\t\t\t\t\tendOffset = offset\n\t\t\t\t} else if (event.inputType === 'deleteContentForward' && offset < content.length) {\n\t\t\t\t\tstartOffset = offset\n\t\t\t\t\tendOffset = offset + 1\n\t\t\t\t} else {\n\t\t\t\t\treturn false\n\t\t\t\t}\n\t\t\t}\n\t\t\tevent.preventDefault()\n\t\t\tnewContent = content.slice(0, startOffset) + content.slice(endOffset)\n\t\t\tnewCaret = startOffset\n\t\t\tbreak\n\t\t}\n\t\tcase 'insertFromPaste':\n\t\tcase 'insertReplacementText': {\n\t\t\tconst text = event.dataTransfer?.getData('text/plain') ?? ''\n\t\t\tconst ranges = event.getTargetRanges()\n\t\t\tconst start = ranges[0]?.startOffset ?? offset\n\t\t\tconst end = ranges[0]?.endOffset ?? offset\n\t\t\tevent.preventDefault()\n\t\t\tnewContent = content.slice(0, start) + text + content.slice(end)\n\t\t\tnewCaret = start + text.length\n\t\t\tbreak\n\t\t}\n\t\tdefault:\n\t\t\treturn false\n\t}\n\n\tfocus.content = newContent\n\tfocus.caret = newCaret\n\treturn true\n}\n\nexport function handlePaste(store: Store, event: ClipboardEvent): void {\n\tconst selecting = store.state.selecting()\n\tif (selecting !== 'all' || !isFullSelection(store)) {\n\t\tif (selecting === 'all') store.state.selecting(undefined)\n\t\treturn\n\t}\n\n\tevent.preventDefault()\n\tconst markup = store.refs.container ? consumeMarkupPaste(store.refs.container) : undefined\n\tconst newContent = markup ?? event.clipboardData?.getData('text/plain') ?? ''\n\treplaceAllContentWith(store, newContent)\n}\n\nexport function replaceAllContentWith(store: Store, newContent: string): void {\n\tstore.nodes.focus.target = null\n\tstore.state.selecting(undefined)\n\tstore.state.previousValue(newContent)\n\n\tstore.props.onChange()?.(newContent)\n\n\tif (store.props.value() === undefined) {\n\t\tstore.state.tokens(\n\t\t\tstore.computed.parser()?.parse(newContent) ?? [\n\t\t\t\t{\n\t\t\t\t\ttype: 'text' as const,\n\t\t\t\t\tcontent: newContent,\n\t\t\t\t\tposition: {start: 0, end: newContent.length},\n\t\t\t\t},\n\t\t\t]\n\t\t)\n\t}\n\n\tqueueMicrotask(() => {\n\t\tconst rawFirstChild = store.refs.container?.firstChild\n\t\tconst firstChild = isHtmlElement(rawFirstChild) ? rawFirstChild : null\n\t\tif (firstChild) {\n\t\t\tstore.state.recovery({\n\t\t\t\tanchor: store.nodes.focus,\n\t\t\t\tcaret: newContent.length,\n\t\t\t})\n\t\t\tfirstChild.focus()\n\t\t}\n\t})\n}","export function filterSuggestions(data: string[], search: string): string[] {\n\tconst query = search.toLowerCase()\n\treturn data.filter(s => s.toLowerCase().includes(query))\n}","import type {OverlayMatch} from '../../shared/types'\nimport type {MarkToken} from '../parsing'\n\nexport function createMarkFromOverlay(match: OverlayMatch, value: string, meta?: string): MarkToken {\n\tconst markup = match.option.markup\n\tif (!markup) throw new Error('createMarkFromOverlay: option.markup is required')\n\treturn {\n\t\ttype: 'mark',\n\t\tvalue,\n\t\tmeta,\n\t\tcontent: '',\n\t\tposition: {\n\t\t\tstart: match.index,\n\t\t\tend: match.index + match.span.length,\n\t\t},\n\t\tdescriptor: {\n\t\t\tmarkup,\n\t\t\tindex: 0,\n\t\t\tsegments: [],\n\t\t\tgapTypes: [],\n\t\t\thasSlot: false,\n\t\t\thasTwoValues: false,\n\t\t\tsegmentGlobalIndices: [],\n\t\t},\n\t\tchildren: [],\n\t\tslot: undefined,\n\t}\n}","import {KEYBOARD} from '../../shared/constants'\nimport {effectScope, effect, watch, listen} from '../../shared/signals/index.js'\nimport type {OverlayTrigger} from '../../shared/types'\nimport type {Store} from '../../store/Store'\nimport {TriggerFinder} from '../caret'\n\nexport class OverlayFeature {\n\t#scope?: () => void\n\n\tconstructor(private readonly store: Store) {}\n\n\tenable() {\n\t\tif (this.#scope) return\n\n\t\tthis.#scope = effectScope(() => {\n\t\t\twatch(this.store.event.clearOverlay, () => {\n\t\t\t\tthis.store.state.overlayMatch(undefined)\n\t\t\t})\n\n\t\t\twatch(this.store.event.checkOverlay, () => {\n\t\t\t\tconst match = TriggerFinder.find(this.store.props.options(), option => option.overlay?.trigger)\n\t\t\t\tthis.store.state.overlayMatch(match)\n\t\t\t})\n\n\t\t\twatch(this.store.event.change, () => {\n\t\t\t\tconst showOverlayOn = this.store.props.showOverlayOn()\n\t\t\t\tconst type: OverlayTrigger = 'change'\n\n\t\t\t\tif (showOverlayOn === type || (Array.isArray(showOverlayOn) && showOverlayOn.includes(type))) {\n\t\t\t\t\tthis.store.event.checkOverlay()\n\t\t\t\t}\n\t\t\t})\n\n\t\t\t// Overlay match tracking + conditional close handlers\n\t\t\teffect(() => {\n\t\t\t\tconst match = this.store.state.overlayMatch()\n\t\t\t\tif (match) {\n\t\t\t\t\tthis.store.nodes.input.target = this.store.nodes.focus.target\n\n\t\t\t\t\tlisten(window, 'keydown', e => {\n\t\t\t\t\t\tif (e.key === KEYBOARD.ESC) {\n\t\t\t\t\t\t\tthis.store.event.clearOverlay()\n\t\t\t\t\t\t}\n\t\t\t\t\t})\n\n\t\t\t\t\tlisten(\n\t\t\t\t\t\tdocument,\n\t\t\t\t\t\t'click',\n\t\t\t\t\t\te => {\n\t\t\t\t\t\t\tconst target = e.target instanceof HTMLElement ? e.target : null\n\t\t\t\t\t\t\tif (this.store.refs.overlay?.contains(target)) return\n\t\t\t\t\t\t\tif (this.store.refs.container?.contains(target)) return\n\t\t\t\t\t\t\tthis.store.event.clearOverlay()\n\t\t\t\t\t\t},\n\t\t\t\t\t\ttrue\n\t\t\t\t\t)\n\t\t\t\t}\n\t\t\t})\n\n\t\t\t// Focus-based selection change tracking\n\t\t\tconst selectionChangeHandler = () => {\n\t\t\t\tconst container = this.store.refs.container\n\t\t\t\tif (!container?.contains(document.activeElement)) return\n\n\t\t\t\tconst showOverlayOn = this.store.props.showOverlayOn()\n\t\t\t\tconst type: OverlayTrigger = 'selectionChange'\n\n\t\t\t\tif (showOverlayOn === type || (Array.isArray(showOverlayOn) && showOverlayOn.includes(type))) {\n\t\t\t\t\tthis.store.event.checkOverlay()\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlisten(document, 'selectionchange', selectionChangeHandler)\n\t\t})\n\t}\n\n\tdisable() {\n\t\tthis.#scope?.()\n\t\tthis.#scope = undefined\n\t}\n}","import {KEYBOARD} from '../../shared/constants'\n\nexport type NavigationAction = 'up' | 'down' | 'select' | 'none'\n\nexport interface NavigationResult {\n\taction: NavigationAction\n\tindex: number\n}\n\nexport function navigateSuggestions(key: string, activeIndex: number, length: number): NavigationResult {\n\tif (length === 0) return {action: 'none', index: activeIndex}\n\n\tconst hasActive = !isNaN(activeIndex)\n\n\tswitch (key) {\n\t\tcase KEYBOARD.UP:\n\t\t\treturn {action: 'up', index: hasActive ? (length + ((activeIndex - 1) % length)) % length : 0}\n\t\tcase KEYBOARD.DOWN:\n\t\t\treturn {action: 'down', index: hasActive ? (activeIndex + 1) % length : 0}\n\t\tcase KEYBOARD.ENTER:\n\t\t\treturn hasActive ? {action: 'select', index: activeIndex} : {action: 'none', index: activeIndex}\n\t\tdefault:\n\t\t\treturn {action: 'none', index: activeIndex}\n\t}\n}","/**\n * Converts object with camelCase data attribute keys to kebab-case data-* attributes\n *\n * Takes keys like 'dataUserId' and converts to 'data-user-id'\n *\n * @param obj - Object potentially containing camelCase data attribute keys\n * @returns New object with converted data attributes\n *\n * @example\n * convertDataAttrs({ dataUserId: '123', dataUserName: 'John', className: 'test' })\n * // Returns: { 'data-user-id': '123', 'data-user-name': 'John', className: 'test' }\n *\n * convertDataAttrs({ dataTestId * @example\n: 'test', dataFoo: 'bar' })\n * // Returns: { 'data-test-id': 'test', 'data-foo': 'bar' }\n */\nexport function convertDataAttrs(obj: Record<string, unknown> | undefined): Record<string, unknown> {\n\tif (!obj) return {}\n\n\treturn Object.fromEntries(\n\t\tObject.entries(obj).map(([key, value]) => {\n\t\t\tif (key.startsWith('data') && key.length > 4 && key[4] === key[4].toUpperCase()) {\n\t\t\t\tconst kebab = key\n\t\t\t\t\t.slice(4)\n\t\t\t\t\t.replace(/([a-z0-9])([A-Z])/g, '$1-$2')\n\t\t\t\t\t.toLowerCase()\n\t\t\t\treturn [`data-${kebab}`, value]\n\t\t\t}\n\t\t\treturn [key, value]\n\t\t})\n\t)\n}","export function resolveOptionSlot<T extends object>(optionConfig: T | ((base: T) => T) | undefined, baseProps: T): T {\n\tif (optionConfig !== undefined) {\n\t\treturn typeof optionConfig === 'function' ? optionConfig(baseProps) : optionConfig\n\t}\n\treturn baseProps\n}","import type {CoreOption, CoreSlotProps, CoreSlots} from '../../shared/types'\nimport {convertDataAttrs} from '../../shared/utils/dataAttributes'\nimport type {Token} from '../parsing'\nimport {resolveOptionSlot} from './resolveOptionSlot'\n\nexport type SlotName = 'container' | 'block' | 'span'\n\nconst defaultSlots: Record<SlotName, string> = {\n\tcontainer: 'div',\n\tblock: 'div',\n\tspan: 'span',\n}\n\nexport function resolveSlot(slotName: SlotName, slots: unknown): unknown {\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- `slots` is `CoreSlots | undefined` at runtime; typed as unknown for Vue Ref<T> cross-framework compat\n\treturn (slots as CoreSlots | undefined)?.[slotName] ?? defaultSlots[slotName]\n}\n\nexport function resolveSlotProps(slotName: SlotName, slotProps: unknown): Record<string, unknown> | undefined {\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- `slotProps` is `CoreSlotProps | undefined` at runtime; typed as unknown for Vue Ref<T> cross-framework compat\n\tconst props = (slotProps as CoreSlotProps | undefined)?.[slotName]\n\treturn props ? convertDataAttrs(props) : undefined\n}\n\ntype SlotProp = Record<string, unknown> | ((base: Record<string, unknown>) => Record<string, unknown>)\n\n/**\n * Internal view of a framework-specific Option for slot resolution.\n * Framework Option types (React, Vue) extend CoreOption with these properties.\n */\nexport interface SlotOption extends Omit<CoreOption, 'overlay'> {\n\tMark?: unknown\n\tmark?: SlotProp\n\tOverlay?: unknown\n\toverlay?: SlotProp\n}\n\nexport function resolveOverlaySlot(globalComponent: unknown, option?: SlotOption, defaultComponent?: unknown) {\n\tconst Component = option?.Overlay ?? globalComponent ?? defaultComponent\n\tif (!Component)\n\t\tthrow new Error(\n\t\t\t'No overlay component found. Provide either option.Overlay, global Overlay, or a defaultComponent.'\n\t\t)\n\tconst props = resolveOptionSlot<Record<string, unknown>>(option?.overlay, {})\n\treturn [Component, props] as const\n}\n\nexport function resolveMarkSlot(\n\ttoken: Token,\n\ttokenOptions: SlotOption[] | undefined,\n\tGlobalMark: unknown,\n\tGlobalSpan: unknown\n) {\n\tif (token.type === 'text') {\n\t\treturn [GlobalSpan ?? 'span', GlobalSpan ? {value: token.content} : {}] as const\n\t}\n\tconst option = tokenOptions?.[token.descriptor.index]\n\tconst baseProps = {value: token.value, meta: token.meta}\n\tconst props = resolveOptionSlot(option?.mark, baseProps)\n\tconst Component = option?.Mark ?? GlobalMark\n\tif (!Component) throw new Error('No mark component found. Provide either option.Mark or global Mark.')\n\treturn [Component, props] as const\n}","/**\n * Returns true when `target` is outside `element` (i.e. not contained by it).\n * Useful for closing a menu when the user clicks outside of it.\n */\nexport function isClickOutside(target: EventTarget | null, element: Element | null): boolean {\n\treturn !!element && !element.contains(target instanceof Node ? target : null)\n}\n\n/**\n * Returns true when the keyboard event is the Escape key.\n */\nexport function isEscapeKey(e: KeyboardEvent): boolean {\n\treturn e.key === 'Escape'\n}","import {signal} from '../shared/signals'\nimport type {DragAction, DragActions} from '../shared/types'\nimport {getDragDropPosition, getDragTargetIndex, parseDragSourceIndex} from '../shared/utils/dragUtils'\nimport {isClickOutside, isEscapeKey} from '../shared/utils/menuUtils'\n\nexport type DropPosition = 'before' | 'after' | null\n\nexport class BlockStore {\n\treadonly refs = {\n\t\tcontainer: null as HTMLElement | null,\n\t}\n\n\treadonly state = {\n\t\tisHovered: signal(false),\n\t\tisDragging: signal(false),\n\t\tdropPosition: signal<DropPosition>(null),\n\t\tmenuOpen: signal(false),\n\t\tmenuPosition: signal({top: 0, left: 0}),\n\t}\n\n\t#blockIndex = 0\n\t#dragAction: DragActions['dragAction'] | null = null\n\t#cleanupContainer?: () => void\n\t#cleanupGrip?: () => void\n\t#cleanupMenu?: () => void\n\n\tattachContainer(el: HTMLElement | null, blockIndex: number, actions: DragActions) {\n\t\tthis.#blockIndex = blockIndex\n\t\tthis.#dragAction = actions.dragAction\n\t\tif (el === this.refs.container) return\n\t\tthis.#cleanupContainer?.()\n\t\tthis.refs.container = el\n\t\tif (!el) return\n\n\t\tconst onMouseEnter = () => this.state.isHovered(true)\n\t\tconst onMouseLeave = () => this.state.isHovered(false)\n\t\tconst onDragOver = (e: DragEvent) => {\n\t\t\tif (!e.dataTransfer) return\n\t\t\te.preventDefault()\n\t\t\te.dataTransfer.dropEffect = 'move'\n\t\t\tthis.state.dropPosition(getDragDropPosition(e.clientY, el.getBoundingClientRect()))\n\t\t}\n\t\tconst onDragLeave = (e: DragEvent) => {\n\t\t\tconst ct = e.currentTarget\n\t\t\tif (ct instanceof Node && ct.contains(e.relatedTarget instanceof Node ? e.relatedTarget : null)) return\n\t\t\tthis.state.dropPosition(null)\n\t\t}\n\t\tconst onDrop = (e: DragEvent) => {\n\t\t\tif (!e.dataTransfer) return\n\t\t\te.preventDefault()\n\t\t\tconst sourceIndex = parseDragSourceIndex(e.dataTransfer)\n\t\t\tif (sourceIndex === null) return\n\t\t\tconst targetIndex = getDragTargetIndex(this.#blockIndex, this.state.dropPosition() ?? 'after')\n\t\t\tthis.state.dropPosition(null)\n\t\t\tthis.#emit({type: 'reorder', source: sourceIndex, target: targetIndex})\n\t\t}\n\n\t\tel.addEventListener('mouseenter', onMouseEnter)\n\t\tel.addEventListener('mouseleave', onMouseLeave)\n\t\tel.addEventListener('dragover', onDragOver)\n\t\tel.addEventListener('dragleave', onDragLeave)\n\t\tel.addEventListener('drop', onDrop)\n\t\tthis.#cleanupContainer = () => {\n\t\t\tel.removeEventListener('mouseenter', onMouseEnter)\n\t\t\tel.removeEventListener('mouseleave', onMouseLeave)\n\t\t\tel.removeEventListener('dragover', onDragOver)\n\t\t\tel.removeEventListener('dragleave', onDragLeave)\n\t\t\tel.removeEventListener('drop', onDrop)\n\t\t}\n\t}\n\n\tattachGrip(el: HTMLButtonElement | null, blockIndex: number, actions: DragActions) {\n\t\tthis.#blockIndex = blockIndex\n\t\tthis.#dragAction = actions.dragAction\n\t\tthis.#cleanupGrip?.()\n\t\tif (!el) return\n\n\t\tconst onDragStart = (e: DragEvent) => {\n\t\t\tif (!e.dataTransfer) return\n\t\t\te.dataTransfer.effectAllowed = 'move'\n\t\t\te.dataTransfer.setData('text/plain', String(this.#blockIndex))\n\t\t\tthis.state.isDragging(true)\n\t\t\tif (this.refs.container) e.dataTransfer.setDragImage(this.refs.container, 0, 0)\n\t\t}\n\t\tconst onDragEnd = () => {\n\t\t\tthis.state.isDragging(false)\n\t\t\tthis.state.dropPosition(null)\n\t\t}\n\t\tconst onClick = (e: MouseEvent) => {\n\t\t\te.preventDefault()\n\t\t\tconst rect = el.getBoundingClientRect()\n\t\t\tthis.state.menuPosition({top: rect.bottom + 4, left: rect.left})\n\t\t\tthis.state.menuOpen(true)\n\t\t}\n\n\t\tel.addEventListener('dragstart', onDragStart)\n\t\tel.addEventListener('dragend', onDragEnd)\n\t\tel.addEventListener('click', onClick)\n\t\tthis.#cleanupGrip = () => {\n\t\t\tel.removeEventListener('dragstart', onDragStart)\n\t\t\tel.removeEventListener('dragend', onDragEnd)\n\t\t\tel.removeEventListener('click', onClick)\n\t\t}\n\t}\n\n\tattachMenu(el: HTMLElement | null) {\n\t\tthis.#cleanupMenu?.()\n\t\tif (!el) return\n\n\t\tconst onMouseDown = (e: MouseEvent) => {\n\t\t\tif (isClickOutside(e.target, el)) this.closeMenu()\n\t\t}\n\t\tconst onKeyDown = (e: KeyboardEvent) => {\n\t\t\tif (isEscapeKey(e)) this.closeMenu()\n\t\t}\n\t\tdocument.addEventListener('mousedown', onMouseDown)\n\t\tdocument.addEventListener('keydown', onKeyDown)\n\t\tthis.#cleanupMenu = () => {\n\t\t\tdocument.removeEventListener('mousedown', onMouseDown)\n\t\t\tdocument.removeEventListener('keydown', onKeyDown)\n\t\t}\n\t}\n\n\tcloseMenu = () => this.state.menuOpen(false)\n\taddBlock = () => {\n\t\tthis.#emit({type: 'add', afterIndex: this.#blockIndex})\n\t\tthis.closeMenu()\n\t}\n\tdeleteBlock = () => {\n\t\tthis.#emit({type: 'delete', index: this.#blockIndex})\n\t\tthis.closeMenu()\n\t}\n\tduplicateBlock = () => {\n\t\tthis.#emit({type: 'duplicate', index: this.#blockIndex})\n\t\tthis.closeMenu()\n\t}\n\n\t#emit(action: DragAction) {\n\t\tthis.#dragAction?.(action)\n\t}\n}","import {BlockStore} from './BlockStore'\n\nexport class BlockRegistry {\n\treadonly #map = new WeakMap<object, BlockStore>()\n\n\tget(token: object): BlockStore {\n\t\tlet store = this.#map.get(token)\n\t\tif (!store) {\n\t\t\tstore = new BlockStore()\n\t\t\tthis.#map.set(token, store)\n\t\t}\n\t\treturn store\n\t}\n}","import {ArrowNavFeature} from '../features/arrownav'\nimport {BlockEditFeature} from '../features/block-editing'\nimport {CopyFeature} from '../features/clipboard'\nimport {DragFeature} from '../features/drag'\nimport {ContentEditableFeature} from '../features/editable'\nimport {SystemListenerFeature} from '../features/events'\nimport {FocusFeature} from '../features/focus'\nimport {InputFeature} from '../features/input'\nimport {OverlayFeature} from '../features/overlay'\nimport {Parser} from '../features/parsing'\nimport type {Token} from '../features/parsing'\nimport {ParseFeature} from '../features/parsing/ParseFeature'\nimport {TextSelectionFeature} from '../features/selection'\nimport {resolveMarkSlot, resolveOverlaySlot, resolveSlot, resolveSlotProps} from '../features/slots'\nimport type {MarkSlot, OverlaySlot} from '../features/slots'\nimport {KeyGenerator, MarkputHandler, NodeProxy} from '../shared/classes'\nimport {DEFAULT_OPTIONS} from '../shared/constants'\nimport {signal, computed, event, batch, watch} from '../shared/signals'\nimport type {SignalValues, Computed} from '../shared/signals'\nimport type {\n\tCoreOption,\n\tOverlayMatch,\n\tOverlayTrigger,\n\tRecovery,\n\tCSSProperties,\n\tCoreSlots,\n\tCoreSlotProps,\n\tDragAction,\n\tDraggableConfig,\n} from '../shared/types'\nimport {cx} from '../shared/utils/cx'\nimport {merge} from '../shared/utils/merge'\nimport {shallow} from '../shared/utils/shallow'\nimport {BlockRegistry} from './BlockRegistry'\n\nimport styles from '../../styles.module.css'\n\nexport type {DragAction} from '../shared/types'\n\nconst DRAG_HANDLE_WIDTH = 24\n\nfunction buildContainerProps(\n\tisDraggableBlock: boolean,\n\treadOnly: boolean,\n\tclassName: string | undefined,\n\tstyle: CSSProperties | undefined,\n\tslotProps: CoreSlotProps | undefined\n): {className: string | undefined; style?: CSSProperties; [key: string]: unknown} {\n\tconst containerSlotProps = slotProps?.container\n\tconst baseStyle = merge(style, containerSlotProps?.style)\n\tconst mergedStyle = isDraggableBlock && !readOnly ? {paddingLeft: DRAG_HANDLE_WIDTH, ...baseStyle} : baseStyle\n\n\tconst {className: _, style: __, ...otherSlotProps} = resolveSlotProps('container', slotProps) ?? {}\n\n\treturn {\n\t\tclassName: cx(styles.Container, className, containerSlotProps?.className),\n\t\tstyle: mergedStyle,\n\t\t...otherSlotProps,\n\t}\n}\n\nexport class Store {\n\treadonly key = new KeyGenerator()\n\treadonly blocks = new BlockRegistry()\n\n\treadonly nodes = {\n\t\tfocus: new NodeProxy(undefined, this),\n\t\tinput: new NodeProxy(undefined, this),\n\t}\n\n\treadonly props = {\n\t\tvalue: signal<string | undefined>(undefined, {readonly: true}),\n\t\tdefaultValue: signal<string | undefined>(undefined, {readonly: true}),\n\n\t\tonChange: signal<((value: string) => void) | undefined>(undefined, {readonly: true}),\n\n\t\toptions: signal<CoreOption[]>(DEFAULT_OPTIONS, {readonly: true}),\n\t\treadOnly: signal<boolean>(false, {readonly: true}),\n\n\t\tlayout: signal<'inline' | 'block'>('inline', {readonly: true}),\n\t\tdraggable: signal<boolean | DraggableConfig>(false, {readonly: true}),\n\n\t\tshowOverlayOn: signal<OverlayTrigger>('change', {readonly: true}),\n\n\t\tSpan: signal<unknown>(undefined, {readonly: true}),\n\t\tMark: signal<unknown>(undefined, {readonly: true}),\n\t\tOverlay: signal<unknown>(undefined, {readonly: true}),\n\n\t\tclassName: signal<string | undefined>(undefined, {readonly: true}),\n\t\tstyle: signal<CSSProperties | undefined>(undefined, {equals: shallow, readonly: true}),\n\n\t\tslots: signal<CoreSlots | undefined>(undefined, {readonly: true}),\n\t\tslotProps: signal<CoreSlotProps | undefined>(undefined, {readonly: true}),\n\t}\n\n\treadonly state = {\n\t\t// Data\n\t\ttokens: signal<Token[]>([]),\n\t\tpreviousValue: signal<string | undefined>(undefined),\n\t\tinnerValue: signal<string | undefined>(undefined),\n\t\trecovery: signal<Recovery | undefined>(undefined),\n\n\t\t// Selection\n\t\tselecting: signal<'drag' | 'all' | undefined>(undefined),\n\n\t\t// Overlay (internally managed by OverlayFeature)\n\t\toverlayMatch: signal<OverlayMatch | undefined>(undefined),\n\t}\n\n\treadonly computed: {\n\t\thasMark: Computed<boolean>\n\t\tisBlock: Computed<boolean>\n\t\tisDraggable: Computed<boolean>\n\t\tparser: Computed<Parser | undefined>\n\t\tcurrentValue: Computed<string>\n\t\tcontainerComponent: Computed<unknown>\n\t\tcontainerProps: Computed<{className: string | undefined; style?: CSSProperties; [key: string]: unknown}>\n\t\tblockComponent: Computed<unknown>\n\t\tblockProps: Computed<Record<string, unknown> | undefined>\n\t\tspanComponent: Computed<unknown>\n\t\tspanProps: Computed<Record<string, unknown> | undefined>\n\t\toverlay: OverlaySlot\n\t\tmark: MarkSlot\n\t} = {\n\t\thasMark: computed(() => {\n\t\t\tconst Mark = this.props.Mark()\n\t\t\tif (Mark) return true\n\t\t\treturn this.props.options().some(opt => 'Mark' in opt && opt.Mark != null)\n\t\t}),\n\t\tisBlock: computed(() => this.props.layout() === 'block'),\n\t\tisDraggable: computed(() => !!this.props.draggable()),\n\t\tparser: computed(() => {\n\t\t\tif (!this.computed.hasMark()) return\n\n\t\t\tconst markups = this.props.options().map(opt => opt.markup)\n\t\t\tif (!markups.some(Boolean)) return\n\n\t\t\treturn new Parser(markups, this.computed.isBlock() ? {skipEmptyText: true} : undefined)\n\t\t}),\n\t\tcurrentValue: computed(() => this.state.previousValue() ?? this.props.value() ?? ''),\n\t\tcontainerComponent: computed(() => resolveSlot('container', this.props.slots())),\n\t\tcontainerProps: computed(\n\t\t\t() =>\n\t\t\t\tbuildContainerProps(\n\t\t\t\t\tthis.computed.isDraggable() && this.computed.isBlock(),\n\t\t\t\t\tthis.props.readOnly(),\n\t\t\t\t\tthis.props.className(),\n\t\t\t\t\tthis.props.style(),\n\t\t\t\t\tthis.props.slotProps()\n\t\t\t\t),\n\t\t\t{equals: shallow}\n\t\t),\n\t\tblockComponent: computed(() => resolveSlot('block', this.props.slots())),\n\t\tblockProps: computed(() => resolveSlotProps('block', this.props.slotProps())),\n\t\tspanComponent: computed(() => resolveSlot('span', this.props.slots())),\n\t\tspanProps: computed(() => resolveSlotProps('span', this.props.slotProps())),\n\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- framework packages augment OverlaySlot with typed overloads; core satisfies the base interface\n\t\toverlay: computed(() => {\n\t\t\tconst Overlay = this.props.Overlay()\n\t\t\treturn (option?: CoreOption, defaultComponent?: unknown) =>\n\t\t\t\tresolveOverlaySlot(Overlay, option, defaultComponent)\n\t\t}) as unknown as OverlaySlot,\n\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- framework packages augment MarkSlot with typed overloads; core satisfies the base interface\n\t\tmark: computed(() => {\n\t\t\tconst options = this.props.options()\n\t\t\tconst Mark = this.props.Mark()\n\t\t\tconst Span = this.props.Span()\n\t\t\treturn (token: Token) => resolveMarkSlot(token, options, Mark, Span)\n\t\t}) as unknown as MarkSlot,\n\t}\n\n\treadonly event = {\n\t\t/** Fires after user input or programmatic mark change — triggers serialization, `onChange`, and re-parse */\n\t\tchange: event(),\n\t\t/** Triggers a re-parse of tokens from the current content */\n\t\tparse: event(),\n\t\t/** Removes a mark token from editor content */\n\t\tdelete: event<{token: Token}>(),\n\t\t/** Fires when the user selects an overlay option — annotates markup into the current input span */\n\t\tselect: event<{mark: Token; match: OverlayMatch}>(),\n\t\t/** Dismisses the overlay by clearing the current `overlayMatch` */\n\t\tclearOverlay: event(),\n\t\t/** Probes the caret/text position for overlay trigger patterns and shows overlay if matched */\n\t\tcheckOverlay: event(),\n\t\t/** Syncs `contentEditable` attributes and `textContent` of child elements to match token state */\n\t\tsync: event(),\n\t\t/** Restores the caret position after a DOM re-render using the saved recovery state */\n\t\trecoverFocus: event(),\n\t\t/** Dispatches drag-mode row operations (reorder, add, delete, duplicate) */\n\t\tdragAction: event<DragAction>(),\n\t\t/** Signals the framework component has received new props — triggers conditional re-parse if value/options changed */\n\t\tupdated: event(),\n\t\t/** Fires after the framework has committed new token elements to the DOM — kicks off sync and focus recovery */\n\t\tafterTokensRendered: event(),\n\t\t/** Lifecycle: editor component added to the DOM — enables all features */\n\t\tmounted: event(),\n\t\t/** Lifecycle: editor component removed from the DOM — disables all features and cleans up subscriptions */\n\t\tunmounted: event(),\n\t}\n\n\treadonly refs = {\n\t\tcontainer: null as HTMLDivElement | null,\n\t\toverlay: null as HTMLElement | null,\n\t}\n\n\treadonly handler = new MarkputHandler(this)\n\n\treadonly features = {\n\t\toverlay: new OverlayFeature(this),\n\t\tfocus: new FocusFeature(this),\n\t\tinput: new InputFeature(this),\n\t\tblockEditing: new BlockEditFeature(this),\n\t\tarrowNav: new ArrowNavFeature(this),\n\t\tsystem: new SystemListenerFeature(this),\n\t\ttextSelection: new TextSelectionFeature(this),\n\t\tcontentEditable: new ContentEditableFeature(this),\n\t\tdrag: new DragFeature(this),\n\t\tcopy: new CopyFeature(this),\n\t\tparse: new ParseFeature(this),\n\t}\n\n\tconstructor() {\n\t\twatch(this.event.mounted, () => Object.values(this.features).forEach(f => f.enable()))\n\t\twatch(this.event.unmounted, () => Object.values(this.features).forEach(f => f.disable()))\n\t}\n\n\tsetProps(values: Partial<SignalValues<typeof this.props>>): void {\n\t\tbatch(\n\t\t\t() => {\n\t\t\t\tconst props = this.props\n\t\t\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- heterogeneous signal map: per-key types verified by SignalValues<T> at the call site\n\t\t\t\tfor (const key of Object.keys(values) as (keyof typeof this.props)[]) {\n\t\t\t\t\tif (!(key in props)) continue\n\t\t\t\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- heterogeneous signal map: per-key types verified by SignalValues<T> at the call site\n\t\t\t\t\tprops[key](values[key] as never)\n\t\t\t\t}\n\t\t\t},\n\t\t\t{mutable: true}\n\t\t)\n\t}\n\n\tbumpTokens(): void {\n\t\tthis.state.tokens([...this.state.tokens()])\n\t}\n}","import type {Store} from '../../store'\nimport type {MarkToken, Token} from '../parsing'\nimport {findToken} from '../parsing'\n\nexport interface RefAccessor<T> {\n\tcurrent: T | null\n}\n\nexport class MarkHandler<T extends HTMLElement = HTMLElement> {\n\treadonly ref: RefAccessor<T>\n\treadonly #store: Store\n\treadonly #token: MarkToken\n\t#readOnly?: boolean\n\n\tconstructor(param: {ref: RefAccessor<T>; store: Store; token: MarkToken}) {\n\t\tthis.ref = param.ref\n\t\tthis.#store = param.store\n\t\tthis.#token = param.token\n\t}\n\n\tget readOnly() {\n\t\treturn this.#readOnly\n\t}\n\n\tset readOnly(value: boolean | undefined) {\n\t\tthis.#readOnly = value\n\t}\n\n\tget content() {\n\t\treturn this.#token.content\n\t}\n\n\tset content(value: string) {\n\t\tthis.#token.content = value\n\t\tthis.#emitChange()\n\t}\n\n\tget value() {\n\t\treturn this.#token.value\n\t}\n\n\tset value(v: string | undefined) {\n\t\tthis.#token.value = v ?? ''\n\t\tthis.#emitChange()\n\t}\n\n\tget meta() {\n\t\treturn this.#token.meta\n\t}\n\n\tset meta(v: string | undefined) {\n\t\tthis.#token.meta = v\n\t\tthis.#emitChange()\n\t}\n\n\tget slot(): string | undefined {\n\t\treturn this.#token.slot?.content\n\t}\n\n\tget #tokenInfo() {\n\t\treturn findToken(this.#store.state.tokens(), this.#token)\n\t}\n\n\tget depth(): number {\n\t\treturn this.#tokenInfo?.depth ?? 0\n\t}\n\n\tget hasChildren(): boolean {\n\t\treturn this.#token.children.some(child => child.type === 'mark')\n\t}\n\n\tget parent(): MarkToken | undefined {\n\t\treturn this.#tokenInfo?.parent\n\t}\n\n\tget tokens(): Token[] {\n\t\treturn this.#token.children\n\t}\n\n\tchange = (props: {content: string; value?: string; meta?: string}) => {\n\t\tthis.#token.content = props.content\n\t\tthis.#token.value = props.value ?? ''\n\t\tif (props.meta !== undefined) {\n\t\t\tthis.#token.meta = props.meta\n\t\t}\n\t\tthis.#emitChange()\n\t}\n\n\tremove = () => this.#store.event.delete({token: this.#token})\n\n\t#emitChange(): void {\n\t\tthis.#store.event.change()\n\t}\n}","import type {Store} from '@markput/core'\nimport {createContext, useContext} from 'react'\n\nexport const StoreContext = createContext<Store | undefined>(undefined)\nStoreContext.displayName = 'StoreContext'\n\nexport function useStore(): Store {\n\tconst store = useContext(StoreContext)\n\tif (store === undefined) {\n\t\tthrow new Error('Store not found. Make sure to wrap component in StoreContext.')\n\t}\n\treturn store\n}","import {computed, watch, isReactive} from '@markput/core'\nimport type {Signal, Computed, SignalValues, Store} from '@markput/core'\nimport {useSyncExternalStore, useRef} from 'react'\n\nimport {useStore} from '../providers/StoreContext'\n\ntype Selectable<T> = Signal<T> | Computed<T>\ntype ObjectSelector = Record<string, Selectable<unknown> | unknown>\n\ntype StableRef = {\n\tderived: Computed<unknown>\n\tsubscribe: (cb: () => void) => () => void\n\tgetSnapshot: () => unknown\n}\n\nexport function useMarkput<T>(selector: (store: Store) => Selectable<T>): T\nexport function useMarkput<R extends ObjectSelector>(selector: (store: Store) => R): SignalValues<R>\nexport function useMarkput(selector: (store: Store) => Selectable<unknown> | ObjectSelector): unknown {\n\tconst store = useStore()\n\n\t// Holds stable computed + subscribe + snapshot — created once, never recreated.\n\tconst stableRef = useRef<StableRef | null>(null)\n\n\tif (stableRef.current === null) {\n\t\tconst target = selector(store)\n\n\t\tconst derived = computed((): unknown => {\n\t\t\tif (typeof target === 'function') {\n\t\t\t\treturn target()\n\t\t\t}\n\t\t\tconst out: Record<string, unknown> = {}\n\t\t\tfor (const k in target) {\n\t\t\t\tconst val = target[k]\n\t\t\t\tout[k] = isReactive(val) ? (val as () => unknown)() : val\n\t\t\t}\n\t\t\treturn out\n\t\t})\n\n\t\tstableRef.current = {\n\t\t\tderived,\n\t\t\tsubscribe: cb => watch(derived, cb),\n\t\t\tgetSnapshot: () => derived(),\n\t\t}\n\t}\n\n\tconst {subscribe, getSnapshot} = stableRef.current\n\treturn useSyncExternalStore(subscribe, getSnapshot, getSnapshot)\n}","import type {ReactNode} from 'react'\n\nimport styles from '@markput/core/styles.module.css'\n\nexport const List = ({children}: {children: ReactNode}) => <ul className={styles.PopupList}>{children}</ul>","import {cx} from '@markput/core'\nimport type {MouseEvent, ReactNode} from 'react'\nimport {useEffect, useRef} from 'react'\n\nimport styles from '@markput/core/styles.module.css'\n\nexport const ListItem = ({\n\tonClick,\n\tonMouseDown,\n\tactive,\n\tchildren,\n}: {\n\tonClick?: (e: MouseEvent<HTMLLIElement>) => void\n\tonMouseDown?: (e: MouseEvent<HTMLLIElement>) => void\n\tactive?: boolean\n\tchildren: ReactNode\n}) => {\n\tconst ref = useRef<HTMLLIElement>(null)\n\n\tuseEffect(() => {\n\t\tif (active) ref.current?.scrollIntoView(false)\n\t}, [active])\n\n\treturn (\n\t\t<li\n\t\t\tref={ref}\n\t\t\tclassName={cx(styles.PopupItem, active && styles.PopupItemActive)}\n\t\t\tonClick={onClick}\n\t\t\tonMouseDown={onMouseDown}\n\t\t>\n\t\t\t{children}\n\t\t</li>\n\t)\n}","import type {CSSProperties, ReactNode, Ref} from 'react'\n\nimport styles from '@markput/core/styles.module.css'\n\nexport const Popup = ({ref, style, children}: {ref?: Ref<HTMLElement>; style?: CSSProperties; children: ReactNode}) => {\n\t// oxlint-disable-next-line no-unsafe-type-assertion\n\tconst divRef = ref as Ref<HTMLDivElement> | undefined\n\treturn (\n\t\t<div ref={divRef} className={styles.Popup} style={style}>\n\t\t\t{children}\n\t\t</div>\n\t)\n}","import {cx} from '@markput/core'\nimport type {Token} from '@markput/core'\nimport {memo} from 'react'\n\nimport {useMarkput} from '../lib/hooks/useMarkput'\nimport {useStore} from '../lib/providers/StoreContext'\nimport {List} from './Popup/List'\nimport {ListItem} from './Popup/ListItem'\nimport {Popup} from './Popup/Popup'\n\nimport styles from '@markput/core/styles.module.css'\n\nexport const BlockMenu = memo(({token}: {token: Token}) => {\n\tconst store = useStore()\n\tconst blockStore = store.blocks.get(token)\n\tconst {menuOpen, menuPosition} = useMarkput(() => ({\n\t\tmenuOpen: blockStore.state.menuOpen,\n\t\tmenuPosition: blockStore.state.menuPosition,\n\t}))\n\n\tif (!menuOpen) return null\n\n\treturn (\n\t\t<Popup\n\t\t\tref={(el: HTMLDivElement | null) => blockStore.attachMenu(el)}\n\t\t\tstyle={{top: menuPosition.top, left: menuPosition.left}}\n\t\t>\n\t\t\t<List>\n\t\t\t\t<ListItem onClick={() => blockStore.addBlock()}>\n\t\t\t\t\t<span className={cx(styles.Icon, styles.IconAdd)} />\n\t\t\t\t\t<span>Add below</span>\n\t\t\t\t</ListItem>\n\t\t\t\t<ListItem onClick={() => blockStore.duplicateBlock()}>\n\t\t\t\t\t<span className={cx(styles.Icon, styles.IconDuplicate)} />\n\t\t\t\t\t<span>Duplicate</span>\n\t\t\t\t</ListItem>\n\t\t\t\t<ListItem onClick={() => blockStore.deleteBlock()}>\n\t\t\t\t\t<span className={cx(styles.Icon, styles.IconTrash)} />\n\t\t\t\t\t<span>Delete</span>\n\t\t\t\t</ListItem>\n\t\t\t</List>\n\t\t</Popup>\n\t)\n})\n\nBlockMenu.displayName = 'BlockMenu'","import {cx, getAlwaysShowHandle} from '@markput/core'\nimport type {Token as TokenType} from '@markput/core'\nimport {memo, useMemo} from 'react'\n\nimport {useMarkput} from '../lib/hooks/useMarkput'\nimport {useStore} from '../lib/providers/StoreContext'\n\nimport styles from '@markput/core/styles.module.css'\n\nconst iconGrip = `${styles.Icon} ${styles.IconGrip}`\n\nexport const DragHandle = memo(({token, blockIndex}: {token: TokenType; blockIndex: number}) => {\n\tconst store = useStore()\n\tconst blockStore = store.blocks.get(token)\n\n\tconst {readOnly, draggable} = useMarkput(s => ({\n\t\treadOnly: s.props.readOnly,\n\t\tdraggable: s.props.draggable,\n\t}))\n\tconst isDragging = useMarkput(() => blockStore.state.isDragging)\n\tconst isHovered = useMarkput(() => blockStore.state.isHovered)\n\tconst alwaysShowHandle = useMemo(() => getAlwaysShowHandle(draggable), [draggable])\n\n\tif (readOnly) return null\n\n\treturn (\n\t\t<div\n\t\t\tclassName={cx(\n\t\t\t\tstyles.SidePanel,\n\t\t\t\talwaysShowHandle ? styles.SidePanelAlways : isHovered && !isDragging && styles.SidePanelVisible\n\t\t\t)}\n\t\t>\n\t\t\t<button\n\t\t\t\tref={(el: HTMLButtonElement | null) => blockStore.attachGrip(el, blockIndex, store.event)}\n\t\t\t\ttype=\"button\"\n\t\t\t\tdraggable\n\t\t\t\tclassName={cx(styles.GripButton, isDragging && styles.GripButtonDragging)}\n\t\t\t\taria-label=\"Drag to reorder or click for options\"\n\t\t\t>\n\t\t\t\t<span className={iconGrip} />\n\t\t\t</button>\n\t\t</div>\n\t)\n})\n\nDragHandle.displayName = 'DragHandle'","import type {Token as TokenType} from '@markput/core'\nimport {memo} from 'react'\n\nimport {useMarkput} from '../lib/hooks/useMarkput'\nimport {useStore} from '../lib/providers/StoreContext'\n\nimport styles from '@markput/core/styles.module.css'\n\nexport const DropIndicator = memo(({token, position}: {token: TokenType; position: 'before' | 'after'}) => {\n\tconst blockStore = useStore().blocks.get(token)\n\tconst dropPosition = useMarkput(() => blockStore.state.dropPosition)\n\n\tif (dropPosition !== position) return null\n\n\treturn <div className={styles.DropIndicator} style={position === 'before' ? {top: -1} : {bottom: -1}} />\n})\n\nDropIndicator.displayName = 'DropIndicator'","import type {Token} from '@markput/core'\nimport {createContext, useContext} from 'react'\n\nexport const TokenContext = createContext<Token | undefined>(undefined)\nTokenContext.displayName = 'TokenProvider'\n\nexport function useToken(): Token {\n\tconst value = useContext(TokenContext)\n\tif (value === undefined) {\n\t\tthrow new Error('Token not found. Make sure to wrap component in TokenContext.Provider.')\n\t}\n\treturn value\n}","import type {Token as TokenType} from '@markput/core'\nimport type {ComponentType} from 'react'\nimport {memo} from 'react'\n\nimport {useMarkput} from '../lib/hooks/useMarkput'\nimport {useStore} from '../lib/providers/StoreContext'\nimport {TokenContext} from '../lib/providers/TokenContext'\nimport type {MarkProps} from '../types'\n\nexport const Token = memo(({mark}: {mark: TokenType}) => {\n\tconst store = useStore()\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- MarkSlot returns [unknown, unknown] in core; React-specific type asserted here\n\tconst resolveMarkSlot = useMarkput(s => s.computed.mark) as (\n\t\ttoken: TokenType\n\t) => readonly [ComponentType<MarkProps>, MarkProps]\n\tconst [Component, props] = resolveMarkSlot(mark)\n\n\tconst children =\n\t\tmark.type === 'mark' && mark.children.length > 0\n\t\t\t? mark.children.map(child => <Token key={store.key.get(child)} mark={child} />)\n\t\t\t: undefined\n\n\treturn (\n\t\t<TokenContext value={mark}>\n\t\t\t<Component children={children} {...props} />\n\t\t</TokenContext>\n\t)\n})\n\nToken.displayName = 'Token'","import type {Token as TokenType} from '@markput/core'\nimport {cx} from '@markput/core'\nimport type {CSSProperties, ElementType} from 'react'\nimport {memo} from 'react'\n\nimport {useMarkput} from '../lib/hooks/useMarkput'\nimport {useStore} from '../lib/providers/StoreContext'\nimport {BlockMenu} from './BlockMenu'\nimport {DragHandle} from './DragHandle'\nimport {DropIndicator} from './DropIndicator'\nimport {Token} from './Token'\n\nimport styles from '@markput/core/styles.module.css'\n\ninterface BlockProps {\n\ttoken: TokenType\n\tblockIndex: number\n}\n\nexport const Block = memo(({token, blockIndex}: BlockProps) => {\n\tconst store = useStore()\n\tconst blockStore = store.blocks.get(token)\n\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- blockComponent returns unknown in core; React ElementType asserted here\n\tconst Component = useMarkput(s => s.computed.blockComponent) as ElementType\n\tconst slotProps = useMarkput(s => s.computed.blockProps)\n\tconst isDragging = useMarkput(() => blockStore.state.isDragging)\n\n\treturn (\n\t\t<Component\n\t\t\tref={(el: HTMLElement | null) => blockStore.attachContainer(el, blockIndex, store.event)}\n\t\t\tdata-testid=\"block\"\n\t\t\t{...slotProps}\n\t\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- slotProps.className is raw and needs casting to string\n\t\t\tclassName={cx(styles.Block, slotProps?.className as string | undefined)}\n\t\t\t// oxlint-disable-next-line no-unsafe-type-assertion -- slotProps.style is raw and needs casting to CSSProperties\n\t\t\tstyle={{opacity: isDragging ? 0.4 : 1, ...(slotProps?.style as CSSProperties | undefined)}}\n\t\t>\n\t\t\t<DropIndicator token={token} position=\"before\" />\n\n\t\t\t<DragHandle token={token} blockIndex={blockIndex} />\n\n\t\t\t<Token mark={token} />\n\n\t\t\t<DropIndicator token={token} position=\"after\" />\n\n\t\t\t<BlockMenu token={token} />\n\t\t</Component>\n\t)\n})\n\nBlock.displayName = 'Block'","import type {ElementType} from 'react'\nimport {memo, useLayoutEffect} from 'react'\n\nimport {useMarkput} from '../lib/hooks/useMarkput'\nimport {Block} from './Block'\nimport {Token} from './Token'\n\nexport const Container = memo(() => {\n\tconst {layout, tokens, key, refs, event} = useMarkput(s => ({\n\t\tlayout: s.props.layout,\n\t\ttokens: s.state.tokens,\n\t\tkey: s.key,\n\t\trefs: s.refs,\n\t\tevent: s.event,\n\t}))\n\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- containerComponent returns unknown in core; React ElementType asserted here\n\tconst Component = useMarkput(s => s.computed.containerComponent) as ElementType\n\tconst props = useMarkput(s => s.computed.containerProps)\n\n\tuseLayoutEffect(() => {\n\t\tevent.afterTokensRendered()\n\t}, [tokens, event])\n\n\treturn (\n\t\t<Component ref={(el: HTMLDivElement | null) => (refs.container = el)} {...props}>\n\t\t\t{layout === 'block'\n\t\t\t\t? tokens.map((t, i) => <Block key={key.get(t)} token={t} blockIndex={i} />)\n\t\t\t\t: tokens.map(t => <Token key={key.get(t)} mark={t} />)}\n\t\t</Component>\n\t)\n})\n\nContainer.displayName = 'Container'","import type {OverlayMatch} from '@markput/core'\nimport {Caret, createMarkFromOverlay} from '@markput/core'\nimport type {RefObject} from 'react'\nimport {useCallback, useMemo} from 'react'\n\nimport type {Option} from '../../types'\nimport {useStore} from '../providers/StoreContext'\nimport {useMarkput} from './useMarkput'\n\nexport interface OverlayHandler {\n\tstyle: {\n\t\tleft: number\n\t\ttop: number\n\t}\n\tclose: () => void\n\tselect: (value: {value: string; meta?: string}) => void\n\tmatch: OverlayMatch<Option> | undefined\n\tref: RefObject<HTMLElement | null>\n}\n\nexport function useOverlay(): OverlayHandler {\n\tconst store = useStore()\n\tconst match = useMarkput(s => s.state.overlayMatch)\n\n\tconst style = useMemo(() => {\n\t\tif (!match) return {left: 0, top: 0}\n\t\treturn Caret.getAbsolutePosition()\n\t}, [match])\n\n\tconst close = useCallback(() => store.event.clearOverlay(), [])\n\tconst select = useCallback(\n\t\t(value: {value: string; meta?: string}) => {\n\t\t\tif (!match) return\n\t\t\tconst mark = createMarkFromOverlay(match, value.value, value.meta)\n\t\t\tstore.event.select({mark, match})\n\t\t\tstore.event.clearOverlay()\n\t\t},\n\t\t[match]\n\t)\n\n\tconst ref = useMemo(\n\t\t(): RefObject<HTMLElement | null> => ({\n\t\t\tget current() {\n\t\t\t\treturn store.refs.overlay\n\t\t\t},\n\t\t\tset current(v: HTMLElement | null) {\n\t\t\t\tstore.refs.overlay = v\n\t\t\t},\n\t\t}),\n\t\t[]\n\t)\n\n\treturn {match, style, select, close, ref}\n}","import {filterSuggestions, navigateSuggestions} from '@markput/core'\nimport {useEffect, useMemo, useRef, useState} from 'react'\n\nimport {useOverlay} from '../../lib/hooks/useOverlay'\nimport {useStore} from '../../lib/providers/StoreContext'\nimport {List} from '../Popup/List'\nimport {ListItem} from '../Popup/ListItem'\nimport {Popup} from '../Popup/Popup'\n\nexport const Suggestions = () => {\n\tconst store = useStore()\n\tconst {match, select, style, ref} = useOverlay()\n\tconst [active, setActive] = useState(NaN)\n\tconst data = match?.option.overlay?.data ?? []\n\tconst filtered = useMemo(() => (match ? filterSuggestions(data, match.value) : []), [match, data])\n\tconst length = filtered.length\n\n\t// Refs let the handler always read the latest values without re-registering\n\t// the listener on every keypress (which happened when `active` was a dep).\n\tconst activeRef = useRef(active)\n\tactiveRef.current = active\n\tconst filteredRef = useRef(filtered)\n\tfilteredRef.current = filtered\n\n\tuseEffect(() => {\n\t\tconst container = store.refs.container\n\t\tif (!container) return\n\n\t\tconst handler = (event: KeyboardEvent) => {\n\t\t\tconst result = navigateSuggestions(event.key, activeRef.current, length)\n\t\t\tswitch (result.action) {\n\t\t\t\tcase 'up':\n\t\t\t\tcase 'down':\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tsetActive(result.index)\n\t\t\t\t\tbreak\n\t\t\t\tcase 'select': {\n\t\t\t\t\tevent.preventDefault()\n\t\t\t\t\tconst suggestion = filteredRef.current[result.index]\n\t\t\t\t\tselect({value: suggestion, meta: result.index.toString()})\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\tcase 'none':\n\t\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\n\t\tcontainer.addEventListener('keydown', handler)\n\t\treturn () => container.removeEventListener('keydown', handler)\n\t}, [length, select])\n\n\tif (!filtered.length) return null\n\n\treturn (\n\t\t<Popup ref={ref} style={style}>\n\t\t\t<List>\n\t\t\t\t{filtered.map((suggestion, index) => (\n\t\t\t\t\t<ListItem\n\t\t\t\t\t\tkey={suggestion}\n\t\t\t\t\t\tactive={index === active}\n\t\t\t\t\t\tonClick={() => select({value: suggestion, meta: index.toString()})}\n\t\t\t\t\t>\n\t\t\t\t\t\t{suggestion}\n\t\t\t\t\t</ListItem>\n\t\t\t\t))}\n\t\t\t</List>\n\t\t</Popup>\n\t)\n}","import type {CoreOption} from '@markput/core'\nimport type {ComponentType} from 'react'\nimport {memo, useMemo} from 'react'\n\nimport {useMarkput} from '../lib/hooks/useMarkput'\nimport {useStore} from '../lib/providers/StoreContext'\nimport type {OverlayProps} from '../types'\nimport {Suggestions} from './Suggestions'\n\nexport const OverlayRenderer = memo(() => {\n\tconst store = useStore()\n\tconst overlayMatch = useMarkput(s => s.state.overlayMatch)\n\tconst key = useMemo(() => (overlayMatch ? store.key.get(overlayMatch.option) : undefined), [overlayMatch])\n\n\t// oxlint-disable-next-line no-unsafe-type-assertion -- OverlaySlot returns [unknown, unknown] in core; React-specific type asserted here\n\tconst resolveOverlay = useMarkput(s => s.computed.overlay) as (\n\t\toption?: CoreOption,\n\t\tdefaultComponent?: unknown\n\t) => readonly [ComponentType<OverlayProps>, OverlayProps]\n\tconst [Overlay, props] = resolveOverlay(overlayMatch?.option, Suggestions)\n\n\tif (!key) return\n\n\treturn <Overlay key={key} {...props} />\n})\n\nOverlayRenderer.displayName = 'OverlayRenderer'","import type {CoreOption, DraggableConfig, MarkputHandler, OverlayTrigger} from '@markput/core'\nimport {Store} from '@markput/core'\nimport type {ComponentType, CSSProperties, Ref} from 'react'\nimport {useImperativeHandle, useLayoutEffect, useState} from 'react'\n\nimport {StoreContext} from '../lib/providers/StoreContext'\nimport type {MarkProps, Option, OverlayProps, SlotProps, Slots} from '../types'\nimport {Container} from './Container'\nimport {OverlayRenderer} from './OverlayRenderer'\n\n/**\n * Props for MarkedInput component.\n *\n * @template TMarkProps - Type of props for the global Mark component\n * @template TOverlayProps - Type of props for the global Overlay component\n *\n * @example\n * ```tsx\n * <MarkedInput<ChipProps>\n * Mark={Chip}\n * options={[{\n * markup: '@[__value__]',\n * mark: { label: 'Click me' }\n * }]}\n * />\n * ```\n */\nexport interface MarkedInputProps<TMarkProps = MarkProps, TOverlayProps extends CoreOption['overlay'] = OverlayProps> {\n\t/** Ref to handler */\n\tref?: Ref<MarkputHandler>\n\t/** Global component used for rendering text tokens (default: built-in Span) */\n\tSpan?: ComponentType<MarkProps>\n\t/** Global component used for rendering markups (fallback for option.Mark) */\n\tMark?: ComponentType<TMarkProps>\n\t/** Global component used for rendering overlays (fallback for option.Overlay) */\n\tOverlay?: ComponentType<TOverlayProps>\n\t/**\n\t * Configuration options for markups and overlays.\n\t * Each option can specify its own component via option.Mark or option.Overlay.\n\t * Falls back to global Mark/Overlay components when not specified.\n\t */\n\toptions?: Option<TMarkProps, TOverlayProps>[]\n\t/** Additional classes */\n\tclassName?: string\n\t/** Additional style */\n\tstyle?: CSSProperties\n\t/**\n\t * Override internal components using slots\n\t * @example slots={{ container: 'div', span: 'span' }}\n\t */\n\tslots?: Slots\n\t/**\n\t * Props to pass to slot components\n\t * @example slotProps={{ container: { onKeyDown: handler }, span: { className: 'custom' } }}\n\t */\n\tslotProps?: SlotProps\n\t/**\n\t * Events that trigger overlay display\n\t * @default 'change'\n\t */\n\tshowOverlayOn?: OverlayTrigger\n\t/** Annotated text with markups */\n\tvalue?: string\n\t/** Initial value for uncontrolled mode */\n\tdefaultValue?: string\n\t/** Change event handler */\n\tonChange?: (value: string) => void\n\t/** Read-only mode */\n\treadOnly?: boolean\n\t/** Layout mode: 'inline' renders tokens in a single flow, 'block' stacks each token as its own row.\n\t * @default 'inline'\n\t */\n\tlayout?: 'inline' | 'block'\n\t/** Enable drag interaction on block rows. Only effective when layout='block'.\n\t * @default false\n\t */\n\tdraggable?: boolean | DraggableConfig\n}\n\nexport function MarkedInput<TMarkProps = MarkProps, TOverlayProps extends CoreOption['overlay'] = OverlayProps>(\n\tprops: MarkedInputProps<TMarkProps, TOverlayProps>\n) {\n\tconst [store] = useState(() => new Store())\n\tstore.setProps(props)\n\n\tuseLayoutEffect(() => {\n\t\tstore.event.mounted()\n\t\treturn () => store.event.unmounted()\n\t}, [])\n\tuseLayoutEffect(() => store.event.updated())\n\n\tuseImperativeHandle(props.ref, () => store.handler, [store])\n\n\treturn (\n\t\t<StoreContext value={store}>\n\t\t\t<Container />\n\t\t\t<OverlayRenderer />\n\t\t</StoreContext>\n\t)\n}","import type {MarkOptions, MarkToken} from '@markput/core'\nimport {MarkHandler} from '@markput/core'\nimport {useEffect, useMemo, useRef} from 'react'\n\nimport {useStore} from '../providers/StoreContext'\nimport {useToken} from '../providers/TokenContext'\nimport {useMarkput} from './useMarkput'\n\nexport const useMark = <T extends HTMLElement = HTMLElement>(options: MarkOptions = {}): MarkHandler<T> => {\n\tconst store = useStore()\n\tconst token = useToken()\n\tif (token.type !== 'mark') throw new Error('useMark must be called within a mark token context')\n\tconst ref = useRef<T>(null)\n\n\tconst mark = useMemo(() => new MarkHandler<T>({ref, store, token}), [store, token])\n\n\tuseUncontrolledInit(ref, options, token)\n\n\tconst readOnly = useMarkput(s => s.props.readOnly)\n\tuseEffect(() => {\n\t\tmark.readOnly = readOnly\n\t}, [mark, readOnly])\n\n\treturn mark\n}\n\nfunction useUncontrolledInit(ref: {readonly current: HTMLElement | null}, options: MarkOptions, token: MarkToken) {\n\tuseEffect(() => {\n\t\tif (!options.controlled && ref.current) ref.current.textContent = token.content\n\t}, [])\n}"],"mappings":";;;;;AAAA,SAAgB,QAAQ,MAAe,MAAe;AACrD,KAAI,OAAO,GAAG,MAAM,KAAK,CACxB,QAAO;AAER,KAAI,OAAO,SAAS,YAAY,SAAS,QAAQ,OAAO,SAAS,YAAY,SAAS,KACrF,QAAO;CAER,MAAM,QAAQ,OAAO,KAAK,KAAK;AAC/B,KAAI,MAAM,WAAW,OAAO,KAAK,KAAK,CAAC,OACtC,QAAO;AAER,MAAK,MAAM,OAAO,OAAO;AACxB,MAAI,CAAC,OAAO,UAAU,eAAe,KAAK,MAAM,IAAI,CACnD,QAAO;AAER,MAAI,CAAC,OAAO,GAAG,QAAQ,IAAI,MAAM,IAAI,EAAE,QAAQ,IAAI,MAAM,IAAI,CAAC,CAC7D,QAAO;;AAGT,QAAO;;;;ACnBR,SAAgB,GAAG,GAAG,SAAoE;AACzF,QAAO,QAAQ,OAAO,QAAQ,CAAC,KAAK,IAAI,IAAI,KAAA;;;;ACD7C,SAAgB,MAAwB,GAAG,SAA0D;CAEpG,MAAM,SAAS,OAAO,OAAO,EAAE,EAAE,GAAG,QAAQ,OAAO,QAAQ,CAAC;AAC5D,QAAO,OAAO,KAAK,OAAO,CAAC,SAAS,IAAI,SAAS,KAAA;;;;ACSlD,MAAa,WAAW;CAEvB,IAAI;CACJ,MAAM;CACN,MAAM;CACN,OAA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